@kweaver-ai/kweaver-sdk 0.4.13 → 0.4.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -31,6 +31,18 @@ export KWEAVER_BASE_URL=https://your-kweaver-instance.com
31
31
  export KWEAVER_TOKEN=your-token
32
32
  ```
33
33
 
34
+ ### Business domain (platform)
35
+
36
+ Set or verify **before** calling list/query APIs that scope by tenant. DIP deployments often need a UUID, not only `bd_public`.
37
+
38
+ ```bash
39
+ kweaver config show
40
+ kweaver config list-bd
41
+ kweaver config set-bd <uuid>
42
+ ```
43
+
44
+ After `kweaver auth login`, the CLI may auto-select a domain when none is saved yet. Override with `KWEAVER_BUSINESS_DOMAIN` or `-bd` / `--biz-domain` on commands. See [`../../skills/kweaver-core/references/config.md`](../../skills/kweaver-core/references/config.md).
45
+
34
46
  ### Simple API (recommended)
35
47
 
36
48
  ```typescript
@@ -130,8 +142,8 @@ kweaver auth login <url> [--alias name] [-u user] [-p pass] [--playwright] [--in
130
142
  kweaver auth login <url> --client-id ID --client-secret S --refresh-token T (headless login)
131
143
  kweaver auth export [url|alias] [--json] (export command to run on a headless host)
132
144
  kweaver auth status/list/use/delete/logout
145
+ kweaver config show / list-bd / set-bd <value> # platform business domain — after login
133
146
  kweaver token
134
- kweaver config show / set-bd <value>
135
147
  kweaver ds list/get/delete/tables/connect
136
148
  kweaver ds import-csv <ds_id> --files <glob> [--table-prefix <p>] [--batch-size 500]
137
149
  kweaver dataview list/find/get/query/delete
package/README.zh.md CHANGED
@@ -31,6 +31,18 @@ export KWEAVER_BASE_URL=https://your-kweaver-instance.com
31
31
  export KWEAVER_TOKEN=your-token
32
32
  ```
33
33
 
34
+ ### 业务域(平台配置)
35
+
36
+ 在调用依赖租户范围的接口前,应先确认业务域;DIP 环境通常使用 **UUID**,不能长期只依赖默认 `bd_public`。
37
+
38
+ ```bash
39
+ kweaver config show
40
+ kweaver config list-bd
41
+ kweaver config set-bd <uuid>
42
+ ```
43
+
44
+ `kweaver auth login` 成功后,若尚未配置,CLI 可能自动选择业务域。也可用环境变量 `KWEAVER_BUSINESS_DOMAIN` 或各命令的 `-bd` / `--biz-domain` 覆盖。详见 [`../../skills/kweaver-core/references/config.md`](../../skills/kweaver-core/references/config.md)。
45
+
34
46
  ### 简洁 API(推荐)
35
47
 
36
48
  ```typescript
@@ -119,6 +131,7 @@ kweaver auth login <url> [--alias name] [-u user] [-p pass] [--playwright] [--in
119
131
  kweaver auth login <url> --client-id ID --client-secret S --refresh-token T (无浏览器登录)
120
132
  kweaver auth export [url|alias] [--json] (导出在无浏览器机器上运行的命令)
121
133
  kweaver auth status/list/use/delete/logout
134
+ kweaver config show / list-bd / set-bd <value> # 平台业务域,登录后优先
122
135
  kweaver token
123
136
  kweaver ds list/get/delete/tables/connect
124
137
  kweaver dataview list/find/get/query/delete
@@ -0,0 +1,20 @@
1
+ /** One business domain entry from GET /api/business-system/v1/business-domain */
2
+ export interface BusinessDomain {
3
+ id: string;
4
+ name?: string;
5
+ description?: string;
6
+ creator?: string;
7
+ products?: string[];
8
+ create_time?: string;
9
+ }
10
+ export interface ListBusinessDomainsOptions {
11
+ baseUrl: string;
12
+ accessToken: string;
13
+ /** When true, skip TLS verification (matches `--insecure` login). */
14
+ tlsInsecure?: boolean;
15
+ }
16
+ /**
17
+ * List business domains for the authenticated user. Does not send x-business-domain
18
+ * (the endpoint returns all domains the user can access).
19
+ */
20
+ export declare function listBusinessDomains(options: ListBusinessDomainsOptions): Promise<BusinessDomain[]>;
@@ -0,0 +1,54 @@
1
+ import { HttpError } from "../utils/http.js";
2
+ async function withTlsInsecure(tlsInsecure, fn) {
3
+ if (!tlsInsecure) {
4
+ return fn();
5
+ }
6
+ const prev = process.env.NODE_TLS_REJECT_UNAUTHORIZED;
7
+ process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
8
+ try {
9
+ return await fn();
10
+ }
11
+ finally {
12
+ if (prev === undefined) {
13
+ delete process.env.NODE_TLS_REJECT_UNAUTHORIZED;
14
+ }
15
+ else {
16
+ process.env.NODE_TLS_REJECT_UNAUTHORIZED = prev;
17
+ }
18
+ }
19
+ }
20
+ /**
21
+ * List business domains for the authenticated user. Does not send x-business-domain
22
+ * (the endpoint returns all domains the user can access).
23
+ */
24
+ export async function listBusinessDomains(options) {
25
+ const { baseUrl, accessToken, tlsInsecure } = options;
26
+ const base = baseUrl.replace(/\/+$/, "");
27
+ const url = `${base}/api/business-system/v1/business-domain`;
28
+ return withTlsInsecure(tlsInsecure, async () => {
29
+ const response = await fetch(url, {
30
+ method: "GET",
31
+ headers: {
32
+ accept: "application/json, text/plain, */*",
33
+ authorization: `Bearer ${accessToken}`,
34
+ token: accessToken,
35
+ },
36
+ });
37
+ const body = await response.text();
38
+ if (!response.ok) {
39
+ throw new HttpError(response.status, response.statusText, body);
40
+ }
41
+ const data = JSON.parse(body);
42
+ if (!Array.isArray(data)) {
43
+ throw new Error("Business domain list response was not a JSON array.");
44
+ }
45
+ return data.map((item) => {
46
+ const row = item;
47
+ const id = row.id;
48
+ if (typeof id !== "string" || id.length === 0) {
49
+ throw new Error("Business domain entry missing string id.");
50
+ }
51
+ return item;
52
+ });
53
+ });
54
+ }
@@ -12,11 +12,17 @@ export interface ListMessagesOptions {
12
12
  businessDomain?: string;
13
13
  limit?: number;
14
14
  }
15
+ export interface GetTracesOptions {
16
+ baseUrl: string;
17
+ accessToken: string;
18
+ conversationId: string;
19
+ }
15
20
  /**
16
21
  * List conversations for an agent.
17
22
  * Returns empty array on 404 (endpoint may not be available in all deployments).
18
23
  */
19
24
  export declare function listConversations(opts: ListConversationsOptions): Promise<string>;
25
+ export declare function getTracesByConversation(opts: GetTracesOptions): Promise<string>;
20
26
  /**
21
27
  * List messages for a conversation.
22
28
  * Returns empty array on 404 (endpoint may not be available in all deployments).
@@ -34,6 +34,27 @@ export async function listConversations(opts) {
34
34
  }
35
35
  return body || "[]";
36
36
  }
37
+ function buildTracesUrl(baseUrl, conversationId) {
38
+ const base = baseUrl.replace(/\/+$/, "");
39
+ return `${base}/api/agent-observability/v1/traces/by-conversation?conversation_id=${conversationId}`;
40
+ }
41
+ export async function getTracesByConversation(opts) {
42
+ const { baseUrl, accessToken, conversationId } = opts;
43
+ const url = buildTracesUrl(baseUrl, conversationId);
44
+ const response = await fetch(url, {
45
+ method: "GET",
46
+ headers: {
47
+ accept: "application/json",
48
+ authorization: `Bearer ${accessToken}`,
49
+ token: accessToken,
50
+ },
51
+ });
52
+ const body = await response.text();
53
+ if (!response.ok) {
54
+ throw new Error(`getTracesByConversation failed: HTTP ${response.status} ${response.statusText} — ${body.slice(0, 200)}`);
55
+ }
56
+ return body || "{}";
57
+ }
37
58
  /**
38
59
  * List messages for a conversation.
39
60
  * Returns empty array on 404 (endpoint may not be available in all deployments).
@@ -20,6 +20,28 @@ export interface GetVegaCatalogOptions {
20
20
  businessDomain?: string;
21
21
  }
22
22
  export declare function getVegaCatalog(options: GetVegaCatalogOptions): Promise<string>;
23
+ export interface CreateVegaCatalogOptions {
24
+ baseUrl: string;
25
+ accessToken: string;
26
+ body: string;
27
+ businessDomain?: string;
28
+ }
29
+ export declare function createVegaCatalog(options: CreateVegaCatalogOptions): Promise<string>;
30
+ export interface UpdateVegaCatalogOptions {
31
+ baseUrl: string;
32
+ accessToken: string;
33
+ id: string;
34
+ body: string;
35
+ businessDomain?: string;
36
+ }
37
+ export declare function updateVegaCatalog(options: UpdateVegaCatalogOptions): Promise<string>;
38
+ export interface DeleteVegaCatalogsOptions {
39
+ baseUrl: string;
40
+ accessToken: string;
41
+ ids: string;
42
+ businessDomain?: string;
43
+ }
44
+ export declare function deleteVegaCatalogs(options: DeleteVegaCatalogsOptions): Promise<string>;
23
45
  export interface VegaCatalogHealthStatusOptions {
24
46
  baseUrl: string;
25
47
  accessToken: string;
@@ -78,14 +100,28 @@ export interface QueryVegaResourceDataOptions {
78
100
  businessDomain?: string;
79
101
  }
80
102
  export declare function queryVegaResourceData(options: QueryVegaResourceDataOptions): Promise<string>;
81
- export interface PreviewVegaResourceOptions {
103
+ export interface CreateVegaResourceOptions {
104
+ baseUrl: string;
105
+ accessToken: string;
106
+ body: string;
107
+ businessDomain?: string;
108
+ }
109
+ export declare function createVegaResource(options: CreateVegaResourceOptions): Promise<string>;
110
+ export interface UpdateVegaResourceOptions {
82
111
  baseUrl: string;
83
112
  accessToken: string;
84
113
  id: string;
85
- limit?: number;
114
+ body: string;
115
+ businessDomain?: string;
116
+ }
117
+ export declare function updateVegaResource(options: UpdateVegaResourceOptions): Promise<string>;
118
+ export interface DeleteVegaResourcesOptions {
119
+ baseUrl: string;
120
+ accessToken: string;
121
+ ids: string;
86
122
  businessDomain?: string;
87
123
  }
88
- export declare function previewVegaResource(options: PreviewVegaResourceOptions): Promise<string>;
124
+ export declare function deleteVegaResources(options: DeleteVegaResourcesOptions): Promise<string>;
89
125
  export interface ListVegaConnectorTypesOptions {
90
126
  baseUrl: string;
91
127
  accessToken: string;
@@ -99,6 +135,36 @@ export interface GetVegaConnectorTypeOptions {
99
135
  businessDomain?: string;
100
136
  }
101
137
  export declare function getVegaConnectorType(options: GetVegaConnectorTypeOptions): Promise<string>;
138
+ export interface RegisterVegaConnectorTypeOptions {
139
+ baseUrl: string;
140
+ accessToken: string;
141
+ body: string;
142
+ businessDomain?: string;
143
+ }
144
+ export declare function registerVegaConnectorType(options: RegisterVegaConnectorTypeOptions): Promise<string>;
145
+ export interface UpdateVegaConnectorTypeOptions {
146
+ baseUrl: string;
147
+ accessToken: string;
148
+ type: string;
149
+ body: string;
150
+ businessDomain?: string;
151
+ }
152
+ export declare function updateVegaConnectorType(options: UpdateVegaConnectorTypeOptions): Promise<string>;
153
+ export interface DeleteVegaConnectorTypeOptions {
154
+ baseUrl: string;
155
+ accessToken: string;
156
+ type: string;
157
+ businessDomain?: string;
158
+ }
159
+ export declare function deleteVegaConnectorType(options: DeleteVegaConnectorTypeOptions): Promise<string>;
160
+ export interface SetVegaConnectorTypeEnabledOptions {
161
+ baseUrl: string;
162
+ accessToken: string;
163
+ type: string;
164
+ enabled: boolean;
165
+ businessDomain?: string;
166
+ }
167
+ export declare function setVegaConnectorTypeEnabled(options: SetVegaConnectorTypeEnabledOptions): Promise<string>;
102
168
  export interface ListVegaDiscoverTasksOptions {
103
169
  baseUrl: string;
104
170
  accessToken: string;
@@ -108,3 +174,10 @@ export interface ListVegaDiscoverTasksOptions {
108
174
  businessDomain?: string;
109
175
  }
110
176
  export declare function listVegaDiscoverTasks(options: ListVegaDiscoverTasksOptions): Promise<string>;
177
+ export interface GetVegaDiscoverTaskOptions {
178
+ baseUrl: string;
179
+ accessToken: string;
180
+ id: string;
181
+ businessDomain?: string;
182
+ }
183
+ export declare function getVegaDiscoverTask(options: GetVegaDiscoverTaskOptions): Promise<string>;
package/dist/api/vega.js CHANGED
@@ -61,11 +61,52 @@ export async function getVegaCatalog(options) {
61
61
  }
62
62
  return body;
63
63
  }
64
+ export async function createVegaCatalog(options) {
65
+ const { baseUrl, accessToken, body: requestBody, businessDomain = "bd_public" } = options;
66
+ const base = baseUrl.replace(/\/+$/, "");
67
+ const url = `${base}${VEGA_BASE}/catalogs`;
68
+ const response = await fetch(url, {
69
+ method: "POST",
70
+ headers: { ...buildHeaders(accessToken, businessDomain), "content-type": "application/json" },
71
+ body: requestBody,
72
+ });
73
+ const body = await response.text();
74
+ if (!response.ok)
75
+ throw new HttpError(response.status, response.statusText, body);
76
+ return body;
77
+ }
78
+ export async function updateVegaCatalog(options) {
79
+ const { baseUrl, accessToken, id, body: requestBody, businessDomain = "bd_public" } = options;
80
+ const base = baseUrl.replace(/\/+$/, "");
81
+ const url = `${base}${VEGA_BASE}/catalogs/${encodeURIComponent(id)}`;
82
+ const response = await fetch(url, {
83
+ method: "PUT",
84
+ headers: { ...buildHeaders(accessToken, businessDomain), "content-type": "application/json" },
85
+ body: requestBody,
86
+ });
87
+ const body = await response.text();
88
+ if (!response.ok)
89
+ throw new HttpError(response.status, response.statusText, body);
90
+ return body;
91
+ }
92
+ export async function deleteVegaCatalogs(options) {
93
+ const { baseUrl, accessToken, ids, businessDomain = "bd_public" } = options;
94
+ const base = baseUrl.replace(/\/+$/, "");
95
+ const url = `${base}${VEGA_BASE}/catalogs/${ids}`;
96
+ const response = await fetch(url, {
97
+ method: "DELETE",
98
+ headers: buildHeaders(accessToken, businessDomain),
99
+ });
100
+ const body = await response.text();
101
+ if (!response.ok)
102
+ throw new HttpError(response.status, response.statusText, body);
103
+ return body;
104
+ }
64
105
  export async function vegaCatalogHealthStatus(options) {
65
106
  const { baseUrl, accessToken, ids, businessDomain = "bd_public", } = options;
66
107
  const base = baseUrl.replace(/\/+$/, "");
67
- const url = new URL(`${base}${VEGA_BASE}/catalogs/health-status`);
68
- url.searchParams.set("ids", ids);
108
+ // ids go in the path segment: GET /catalogs/{ids}/health-status
109
+ const url = new URL(`${base}${VEGA_BASE}/catalogs/${ids}/health-status`);
69
110
  const response = await fetch(url.toString(), {
70
111
  method: "GET",
71
112
  headers: buildHeaders(accessToken, businessDomain),
@@ -189,19 +230,45 @@ export async function queryVegaResourceData(options) {
189
230
  }
190
231
  return body;
191
232
  }
192
- export async function previewVegaResource(options) {
193
- const { baseUrl, accessToken, id, limit = 50, businessDomain = "bd_public", } = options;
233
+ export async function createVegaResource(options) {
234
+ const { baseUrl, accessToken, body: requestBody, businessDomain = "bd_public" } = options;
194
235
  const base = baseUrl.replace(/\/+$/, "");
195
- const url = new URL(`${base}${VEGA_BASE}/resources/${encodeURIComponent(id)}/preview`);
196
- url.searchParams.set("limit", String(limit));
197
- const response = await fetch(url.toString(), {
198
- method: "GET",
236
+ const url = `${base}${VEGA_BASE}/resources`;
237
+ const response = await fetch(url, {
238
+ method: "POST",
239
+ headers: { ...buildHeaders(accessToken, businessDomain), "content-type": "application/json" },
240
+ body: requestBody,
241
+ });
242
+ const body = await response.text();
243
+ if (!response.ok)
244
+ throw new HttpError(response.status, response.statusText, body);
245
+ return body;
246
+ }
247
+ export async function updateVegaResource(options) {
248
+ const { baseUrl, accessToken, id, body: requestBody, businessDomain = "bd_public" } = options;
249
+ const base = baseUrl.replace(/\/+$/, "");
250
+ const url = `${base}${VEGA_BASE}/resources/${encodeURIComponent(id)}`;
251
+ const response = await fetch(url, {
252
+ method: "PUT",
253
+ headers: { ...buildHeaders(accessToken, businessDomain), "content-type": "application/json" },
254
+ body: requestBody,
255
+ });
256
+ const body = await response.text();
257
+ if (!response.ok)
258
+ throw new HttpError(response.status, response.statusText, body);
259
+ return body;
260
+ }
261
+ export async function deleteVegaResources(options) {
262
+ const { baseUrl, accessToken, ids, businessDomain = "bd_public" } = options;
263
+ const base = baseUrl.replace(/\/+$/, "");
264
+ const url = `${base}${VEGA_BASE}/resources/${ids}`;
265
+ const response = await fetch(url, {
266
+ method: "DELETE",
199
267
  headers: buildHeaders(accessToken, businessDomain),
200
268
  });
201
269
  const body = await response.text();
202
- if (!response.ok) {
270
+ if (!response.ok)
203
271
  throw new HttpError(response.status, response.statusText, body);
204
- }
205
272
  return body;
206
273
  }
207
274
  export async function listVegaConnectorTypes(options) {
@@ -232,6 +299,61 @@ export async function getVegaConnectorType(options) {
232
299
  }
233
300
  return body;
234
301
  }
302
+ export async function registerVegaConnectorType(options) {
303
+ const { baseUrl, accessToken, body: requestBody, businessDomain = "bd_public" } = options;
304
+ const base = baseUrl.replace(/\/+$/, "");
305
+ const url = `${base}${VEGA_BASE}/connector-types`;
306
+ const response = await fetch(url, {
307
+ method: "POST",
308
+ headers: { ...buildHeaders(accessToken, businessDomain), "content-type": "application/json" },
309
+ body: requestBody,
310
+ });
311
+ const body = await response.text();
312
+ if (!response.ok)
313
+ throw new HttpError(response.status, response.statusText, body);
314
+ return body;
315
+ }
316
+ export async function updateVegaConnectorType(options) {
317
+ const { baseUrl, accessToken, type, body: requestBody, businessDomain = "bd_public" } = options;
318
+ const base = baseUrl.replace(/\/+$/, "");
319
+ const url = `${base}${VEGA_BASE}/connector-types/${encodeURIComponent(type)}`;
320
+ const response = await fetch(url, {
321
+ method: "PUT",
322
+ headers: { ...buildHeaders(accessToken, businessDomain), "content-type": "application/json" },
323
+ body: requestBody,
324
+ });
325
+ const body = await response.text();
326
+ if (!response.ok)
327
+ throw new HttpError(response.status, response.statusText, body);
328
+ return body;
329
+ }
330
+ export async function deleteVegaConnectorType(options) {
331
+ const { baseUrl, accessToken, type, businessDomain = "bd_public" } = options;
332
+ const base = baseUrl.replace(/\/+$/, "");
333
+ const url = `${base}${VEGA_BASE}/connector-types/${encodeURIComponent(type)}`;
334
+ const response = await fetch(url, {
335
+ method: "DELETE",
336
+ headers: buildHeaders(accessToken, businessDomain),
337
+ });
338
+ const body = await response.text();
339
+ if (!response.ok)
340
+ throw new HttpError(response.status, response.statusText, body);
341
+ return body;
342
+ }
343
+ export async function setVegaConnectorTypeEnabled(options) {
344
+ const { baseUrl, accessToken, type, enabled, businessDomain = "bd_public" } = options;
345
+ const base = baseUrl.replace(/\/+$/, "");
346
+ const url = `${base}${VEGA_BASE}/connector-types/${encodeURIComponent(type)}/enabled`;
347
+ const response = await fetch(url, {
348
+ method: "POST",
349
+ headers: { ...buildHeaders(accessToken, businessDomain), "content-type": "application/json" },
350
+ body: JSON.stringify({ enabled }),
351
+ });
352
+ const body = await response.text();
353
+ if (!response.ok)
354
+ throw new HttpError(response.status, response.statusText, body);
355
+ return body;
356
+ }
235
357
  export async function listVegaDiscoverTasks(options) {
236
358
  const { baseUrl, accessToken, status, limit, offset, businessDomain = "bd_public", } = options;
237
359
  const base = baseUrl.replace(/\/+$/, "");
@@ -252,3 +374,16 @@ export async function listVegaDiscoverTasks(options) {
252
374
  }
253
375
  return body;
254
376
  }
377
+ export async function getVegaDiscoverTask(options) {
378
+ const { baseUrl, accessToken, id, businessDomain = "bd_public" } = options;
379
+ const base = baseUrl.replace(/\/+$/, "");
380
+ const url = `${base}${VEGA_BASE}/discover-tasks/${encodeURIComponent(id)}`;
381
+ const response = await fetch(url, {
382
+ method: "GET",
383
+ headers: buildHeaders(accessToken, businessDomain),
384
+ });
385
+ const body = await response.text();
386
+ if (!response.ok)
387
+ throw new HttpError(response.status, response.statusText, body);
388
+ return body;
389
+ }
@@ -60,6 +60,15 @@ export declare function refreshTokenLogin(baseUrl: string, options: {
60
60
  * Persists the new token to ~/.kweaver/ and returns it.
61
61
  */
62
62
  export declare function refreshAccessToken(token: TokenConfig): Promise<TokenConfig>;
63
+ /**
64
+ * Resolve a usable access token for the current platform.
65
+ *
66
+ * **Default behavior** (saved `~/.kweaver/` session from OAuth2 code login): when the access
67
+ * token is expired or near expiry, automatically exchanges the saved **refresh_token** for a new
68
+ * access token (OAuth2 `refresh_token` grant) and persists it. No extra flags are required.
69
+ *
70
+ * Static env `KWEAVER_TOKEN` bypasses refresh (see implementation).
71
+ */
63
72
  export declare function ensureValidToken(opts?: {
64
73
  forceRefresh?: boolean;
65
74
  }): Promise<TokenConfig>;
@@ -592,6 +592,15 @@ export async function refreshAccessToken(token) {
592
592
  saveTokenConfig(newToken);
593
593
  return newToken;
594
594
  }
595
+ /**
596
+ * Resolve a usable access token for the current platform.
597
+ *
598
+ * **Default behavior** (saved `~/.kweaver/` session from OAuth2 code login): when the access
599
+ * token is expired or near expiry, automatically exchanges the saved **refresh_token** for a new
600
+ * access token (OAuth2 `refresh_token` grant) and persists it. No extra flags are required.
601
+ *
602
+ * Static env `KWEAVER_TOKEN` bypasses refresh (see implementation).
603
+ */
595
604
  export async function ensureValidToken(opts) {
596
605
  const envToken = process.env.KWEAVER_TOKEN;
597
606
  const envBaseUrl = process.env.KWEAVER_BASE_URL;
package/dist/cli.js CHANGED
@@ -77,11 +77,12 @@ Usage:
77
77
  kweaver bkn action-log list|get|cancel <kn-id> ...
78
78
 
79
79
  kweaver config set-bd <value>
80
+ kweaver config list-bd
80
81
  kweaver config show
81
82
 
82
83
  kweaver vega health|stats|inspect
83
84
  kweaver vega catalog list|get|health|test-connection|discover|resources [options]
84
- kweaver vega resource list|get|query|preview [options]
85
+ kweaver vega resource list|get|query [options]
85
86
  kweaver vega connector-type list|get [options]
86
87
 
87
88
  kweaver context-loader config set|use|list|remove|show [options]
@@ -25,6 +25,11 @@ export interface AgentHistoryOptions {
25
25
  pretty: boolean;
26
26
  }
27
27
  export declare function parseAgentHistoryArgs(args: string[]): AgentHistoryOptions;
28
+ export interface AgentTraceOptions {
29
+ conversationId: string;
30
+ pretty: boolean;
31
+ }
32
+ export declare function parseAgentTraceArgs(args: string[]): AgentTraceOptions;
28
33
  export declare function runAgentCommand(args: string[]): Promise<number>;
29
34
  export interface AgentGetOptions {
30
35
  agentId: string;
@@ -1,7 +1,7 @@
1
1
  import { ensureValidToken, formatHttpError, with401RefreshRetry } from "../auth/oauth.js";
2
2
  import { runAgentChatCommand } from "./agent-chat.js";
3
3
  import { listAgents, getAgent, getAgentByKey, createAgent, updateAgent, deleteAgent, publishAgent, unpublishAgent, } from "../api/agent-list.js";
4
- import { listConversations, listMessages } from "../api/conversations.js";
4
+ import { listConversations, listMessages, getTracesByConversation } from "../api/conversations.js";
5
5
  import { formatCallOutput } from "./call.js";
6
6
  import { resolveBusinessDomain } from "../config/store.js";
7
7
  function readStringField(value, ...keys) {
@@ -212,6 +212,29 @@ export function parseAgentHistoryArgs(args) {
212
212
  businessDomain = resolveBusinessDomain();
213
213
  return { conversationId, businessDomain, limit, pretty };
214
214
  }
215
+ export function parseAgentTraceArgs(args) {
216
+ const conversationId = args[0];
217
+ if (!conversationId || conversationId.startsWith("-")) {
218
+ throw new Error("Missing conversation_id");
219
+ }
220
+ let pretty = true;
221
+ for (let i = 1; i < args.length; i += 1) {
222
+ const arg = args[i];
223
+ if (arg === "--help" || arg === "-h") {
224
+ throw new Error("help");
225
+ }
226
+ if (arg === "--pretty") {
227
+ pretty = true;
228
+ continue;
229
+ }
230
+ if (arg === "--compact") {
231
+ pretty = false;
232
+ continue;
233
+ }
234
+ throw new Error(`Unsupported agent trace argument: ${arg}`);
235
+ }
236
+ return { conversationId, pretty };
237
+ }
215
238
  export async function runAgentCommand(args) {
216
239
  const [subcommand, ...rest] = args;
217
240
  if (!subcommand || subcommand === "--help" || subcommand === "-h") {
@@ -231,7 +254,8 @@ Subcommands:
231
254
  chat <agent_id> Start interactive chat with an agent
232
255
  chat <agent_id> -m "message" Send a single message (non-interactive)
233
256
  sessions <agent_id> List all conversations for an agent
234
- history <conversation_id> Show message history for a conversation`);
257
+ history <conversation_id> Show message history for a conversation
258
+ trace <conversation_id> Get trace data for a conversation`);
235
259
  return Promise.resolve(0);
236
260
  }
237
261
  const dispatch = async () => {
@@ -245,6 +269,8 @@ Subcommands:
245
269
  return runAgentSessionsCommand(rest);
246
270
  if (subcommand === "history")
247
271
  return runAgentHistoryCommand(rest);
272
+ if (subcommand === "trace")
273
+ return runAgentTraceCommand(rest);
248
274
  if (subcommand === "get-by-key")
249
275
  return runAgentGetByKeyCommand(rest);
250
276
  if (subcommand === "create")
@@ -345,6 +371,18 @@ Options:
345
371
  return 0;
346
372
  }
347
373
  }
374
+ if (subcommand === "trace") {
375
+ if (rest.length === 1 && (rest[0] === "--help" || rest[0] === "-h")) {
376
+ console.log(`kweaver agent trace <conversation_id> [options]
377
+
378
+ Get trace data for a conversation.
379
+
380
+ Options:
381
+ --pretty Pretty-print JSON output (default)
382
+ --compact Compact JSON output`);
383
+ return 0;
384
+ }
385
+ }
348
386
  try {
349
387
  return await with401RefreshRetry(async () => {
350
388
  const code = await dispatch();
@@ -571,6 +609,40 @@ Options:
571
609
  return 1;
572
610
  }
573
611
  }
612
+ async function runAgentTraceCommand(args) {
613
+ let options;
614
+ try {
615
+ options = parseAgentTraceArgs(args);
616
+ }
617
+ catch (error) {
618
+ if (error instanceof Error && error.message === "help") {
619
+ console.log(`kweaver agent trace <conversation_id> [options]
620
+
621
+ Get trace data for a conversation.
622
+
623
+ Options:
624
+ --pretty Pretty-print JSON output (default)
625
+ --compact Compact JSON output`);
626
+ return 0;
627
+ }
628
+ console.error(formatHttpError(error));
629
+ return 1;
630
+ }
631
+ try {
632
+ const token = await ensureValidToken();
633
+ const body = await getTracesByConversation({
634
+ baseUrl: token.baseUrl,
635
+ accessToken: token.accessToken,
636
+ conversationId: options.conversationId,
637
+ });
638
+ console.log(formatCallOutput(body, options.pretty));
639
+ return 0;
640
+ }
641
+ catch (error) {
642
+ console.error(formatHttpError(error));
643
+ return 1;
644
+ }
645
+ }
574
646
  // ── Get by key ───────────────────────────────────────────────────────────────
575
647
  async function runAgentGetByKeyCommand(args) {
576
648
  const key = args[0];
@@ -1,4 +1,4 @@
1
- import { clearPlatformSession, deletePlatform, getConfigDir, getCurrentPlatform, getPlatformAlias, hasPlatform, listPlatforms, loadClientConfig, loadTokenConfig, resolvePlatformIdentifier, setCurrentPlatform, setPlatformAlias, } from "../config/store.js";
1
+ import { autoSelectBusinessDomain, clearPlatformSession, deletePlatform, getConfigDir, getCurrentPlatform, getPlatformAlias, hasPlatform, listPlatforms, loadClientConfig, loadTokenConfig, resolvePlatformIdentifier, setCurrentPlatform, setPlatformAlias, } from "../config/store.js";
2
2
  import { buildCopyCommand, formatHttpError, normalizeBaseUrl, oauth2Login, playwrightLogin, refreshTokenLogin, } from "../auth/oauth.js";
3
3
  export async function runAuthCommand(args) {
4
4
  const target = args[0];
@@ -115,6 +115,10 @@ Login options:
115
115
  if (token.expiresAt) {
116
116
  console.log(`Token expires at: ${token.expiresAt}`);
117
117
  }
118
+ const selectedBd = await autoSelectBusinessDomain(normalizedTarget, token.accessToken, {
119
+ tlsInsecure: token.tlsInsecure,
120
+ });
121
+ console.log(`Business domain: ${selectedBd}`);
118
122
  return 0;
119
123
  }
120
124
  catch (error) {