-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathconfig.ts
More file actions
44 lines (35 loc) · 1.17 KB
/
config.ts
File metadata and controls
44 lines (35 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { getProfileData } from '@/handlers/auth/fs'
import { getValidAssistantTokens } from './tokenRefresh'
export interface A2AConfig {
baseUrl: string
agentId: string
extensions: string
bearerToken: string
}
export type A2ASessionConfig = Omit<A2AConfig, 'extensions'>
const AGENT_ID = 'grafana_assistant_k6_studio'
const REMOTE_TOOL_EXTENSION =
'https://grafana.com/extensions/remote-tool-execution/v1'
const TOKEN_STREAMING_EXTENSION =
'https://grafana.com/extensions/token-streaming/v1'
export async function getA2AConfig(): Promise<A2AConfig> {
const profile = await getProfileData()
const stackId = profile.profiles.currentStack
if (!stackId) {
throw new Error(
'No Grafana Cloud stack selected. Please sign in to Grafana Cloud first.'
)
}
const tokens = await getValidAssistantTokens(stackId)
if (!tokens) {
throw new Error(
'Not authenticated with Grafana Assistant. Please connect to Grafana Assistant first.'
)
}
return {
baseUrl: `${tokens.apiEndpoint}/api/cli/v1/a2a`,
agentId: AGENT_ID,
extensions: [REMOTE_TOOL_EXTENSION, TOKEN_STREAMING_EXTENSION].join(', '),
bearerToken: tokens.accessToken,
}
}