@kweaver-ai/kweaver-sdk 0.4.0 → 0.4.1
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 +139 -0
- package/README.zh.md +139 -0
- package/dist/api/agent-list.d.ts +7 -0
- package/dist/api/agent-list.js +21 -2
- package/dist/api/datasources.d.ts +73 -0
- package/dist/api/datasources.js +218 -0
- package/dist/api/dataviews.d.ts +20 -0
- package/dist/api/dataviews.js +72 -0
- package/dist/api/knowledge-networks.d.ts +84 -0
- package/dist/api/knowledge-networks.js +167 -0
- package/dist/cli.js +9 -0
- package/dist/commands/agent.d.ts +7 -0
- package/dist/commands/agent.js +102 -1
- package/dist/commands/bkn.d.ts +6 -0
- package/dist/commands/bkn.js +784 -23
- package/dist/commands/context-loader.js +4 -4
- package/dist/commands/ds.d.ts +7 -0
- package/dist/commands/ds.js +283 -0
- package/dist/resources/bkn.d.ts +12 -0
- package/dist/resources/bkn.js +12 -0
- package/dist/resources/knowledge-networks.js +17 -55
- package/dist/utils/crypto.d.ts +10 -0
- package/dist/utils/crypto.js +31 -0
- package/package.json +3 -2
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { HttpError } from "../utils/http.js";
|
|
3
|
+
function buildHeaders(accessToken, businessDomain) {
|
|
4
|
+
return {
|
|
5
|
+
accept: "application/json, text/plain, */*",
|
|
6
|
+
"accept-language": "zh-cn",
|
|
7
|
+
authorization: `Bearer ${accessToken}`,
|
|
8
|
+
token: accessToken,
|
|
9
|
+
"x-business-domain": businessDomain,
|
|
10
|
+
"x-language": "zh-cn",
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function extractViewId(data) {
|
|
14
|
+
if (Array.isArray(data) && data.length > 0) {
|
|
15
|
+
const item = data[0];
|
|
16
|
+
if (typeof item === "string")
|
|
17
|
+
return item;
|
|
18
|
+
if (item && typeof item === "object" && "id" in item) {
|
|
19
|
+
return String(item.id ?? "");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (data && typeof data === "object" && "id" in data) {
|
|
23
|
+
return String(data.id ?? "");
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
export async function createDataView(options) {
|
|
28
|
+
const { baseUrl, accessToken, name, datasourceId, table, fields = [], businessDomain = "bd_public", } = options;
|
|
29
|
+
const viewId = createHash("md5").update(`${datasourceId}:${table}`).digest("hex").slice(0, 35);
|
|
30
|
+
const body = JSON.stringify([
|
|
31
|
+
{
|
|
32
|
+
id: viewId,
|
|
33
|
+
name,
|
|
34
|
+
technical_name: table,
|
|
35
|
+
type: "atomic",
|
|
36
|
+
query_type: "SQL",
|
|
37
|
+
data_source_id: datasourceId,
|
|
38
|
+
group_id: datasourceId,
|
|
39
|
+
fields,
|
|
40
|
+
},
|
|
41
|
+
]);
|
|
42
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
43
|
+
const url = `${base}/api/mdl-data-model/v1/data-views`;
|
|
44
|
+
const response = await fetch(url, {
|
|
45
|
+
method: "POST",
|
|
46
|
+
headers: {
|
|
47
|
+
...buildHeaders(accessToken, businessDomain),
|
|
48
|
+
"content-type": "application/json",
|
|
49
|
+
},
|
|
50
|
+
body,
|
|
51
|
+
});
|
|
52
|
+
const responseBody = await response.text();
|
|
53
|
+
if (!response.ok) {
|
|
54
|
+
throw new HttpError(response.status, response.statusText, responseBody);
|
|
55
|
+
}
|
|
56
|
+
const createdId = extractViewId(JSON.parse(responseBody));
|
|
57
|
+
return createdId ?? viewId;
|
|
58
|
+
}
|
|
59
|
+
export async function getDataView(options) {
|
|
60
|
+
const { baseUrl, accessToken, id, businessDomain = "bd_public", } = options;
|
|
61
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
62
|
+
const url = `${base}/api/mdl-data-model/v1/data-views/${encodeURIComponent(id)}`;
|
|
63
|
+
const response = await fetch(url, {
|
|
64
|
+
method: "GET",
|
|
65
|
+
headers: buildHeaders(accessToken, businessDomain),
|
|
66
|
+
});
|
|
67
|
+
const body = await response.text();
|
|
68
|
+
if (!response.ok) {
|
|
69
|
+
throw new HttpError(response.status, response.statusText, body);
|
|
70
|
+
}
|
|
71
|
+
return body;
|
|
72
|
+
}
|
|
@@ -55,3 +55,87 @@ export interface ListSchemaTypesOptions {
|
|
|
55
55
|
export declare function listObjectTypes(options: ListSchemaTypesOptions): Promise<string>;
|
|
56
56
|
export declare function listRelationTypes(options: ListSchemaTypesOptions): Promise<string>;
|
|
57
57
|
export declare function listActionTypes(options: ListSchemaTypesOptions): Promise<string>;
|
|
58
|
+
export interface GetObjectTypeOptions {
|
|
59
|
+
baseUrl: string;
|
|
60
|
+
accessToken: string;
|
|
61
|
+
knId: string;
|
|
62
|
+
otId: string;
|
|
63
|
+
businessDomain?: string;
|
|
64
|
+
branch?: string;
|
|
65
|
+
}
|
|
66
|
+
export declare function getObjectType(options: GetObjectTypeOptions): Promise<string>;
|
|
67
|
+
export interface CreateObjectTypesOptions {
|
|
68
|
+
baseUrl: string;
|
|
69
|
+
accessToken: string;
|
|
70
|
+
knId: string;
|
|
71
|
+
body: string;
|
|
72
|
+
businessDomain?: string;
|
|
73
|
+
branch?: string;
|
|
74
|
+
}
|
|
75
|
+
export declare function createObjectTypes(options: CreateObjectTypesOptions): Promise<string>;
|
|
76
|
+
export interface UpdateObjectTypeOptions {
|
|
77
|
+
baseUrl: string;
|
|
78
|
+
accessToken: string;
|
|
79
|
+
knId: string;
|
|
80
|
+
otId: string;
|
|
81
|
+
body: string;
|
|
82
|
+
businessDomain?: string;
|
|
83
|
+
}
|
|
84
|
+
export declare function updateObjectType(options: UpdateObjectTypeOptions): Promise<string>;
|
|
85
|
+
export interface DeleteObjectTypesOptions {
|
|
86
|
+
baseUrl: string;
|
|
87
|
+
accessToken: string;
|
|
88
|
+
knId: string;
|
|
89
|
+
otIds: string;
|
|
90
|
+
businessDomain?: string;
|
|
91
|
+
}
|
|
92
|
+
export declare function deleteObjectTypes(options: DeleteObjectTypesOptions): Promise<void>;
|
|
93
|
+
export interface GetRelationTypeOptions {
|
|
94
|
+
baseUrl: string;
|
|
95
|
+
accessToken: string;
|
|
96
|
+
knId: string;
|
|
97
|
+
rtId: string;
|
|
98
|
+
businessDomain?: string;
|
|
99
|
+
branch?: string;
|
|
100
|
+
}
|
|
101
|
+
export declare function getRelationType(options: GetRelationTypeOptions): Promise<string>;
|
|
102
|
+
export interface CreateRelationTypesOptions {
|
|
103
|
+
baseUrl: string;
|
|
104
|
+
accessToken: string;
|
|
105
|
+
knId: string;
|
|
106
|
+
body: string;
|
|
107
|
+
businessDomain?: string;
|
|
108
|
+
branch?: string;
|
|
109
|
+
}
|
|
110
|
+
export declare function createRelationTypes(options: CreateRelationTypesOptions): Promise<string>;
|
|
111
|
+
export interface UpdateRelationTypeOptions {
|
|
112
|
+
baseUrl: string;
|
|
113
|
+
accessToken: string;
|
|
114
|
+
knId: string;
|
|
115
|
+
rtId: string;
|
|
116
|
+
body: string;
|
|
117
|
+
businessDomain?: string;
|
|
118
|
+
}
|
|
119
|
+
export declare function updateRelationType(options: UpdateRelationTypeOptions): Promise<string>;
|
|
120
|
+
export interface DeleteRelationTypesOptions {
|
|
121
|
+
baseUrl: string;
|
|
122
|
+
accessToken: string;
|
|
123
|
+
knId: string;
|
|
124
|
+
rtIds: string;
|
|
125
|
+
businessDomain?: string;
|
|
126
|
+
}
|
|
127
|
+
export declare function deleteRelationTypes(options: DeleteRelationTypesOptions): Promise<void>;
|
|
128
|
+
export interface BuildKnowledgeNetworkOptions {
|
|
129
|
+
baseUrl: string;
|
|
130
|
+
accessToken: string;
|
|
131
|
+
knId: string;
|
|
132
|
+
businessDomain?: string;
|
|
133
|
+
}
|
|
134
|
+
export declare function buildKnowledgeNetwork(options: BuildKnowledgeNetworkOptions): Promise<void>;
|
|
135
|
+
export interface GetBuildStatusOptions {
|
|
136
|
+
baseUrl: string;
|
|
137
|
+
accessToken: string;
|
|
138
|
+
knId: string;
|
|
139
|
+
businessDomain?: string;
|
|
140
|
+
}
|
|
141
|
+
export declare function getBuildStatus(options: GetBuildStatusOptions): Promise<string>;
|
|
@@ -156,3 +156,170 @@ export async function listActionTypes(options) {
|
|
|
156
156
|
}
|
|
157
157
|
return body;
|
|
158
158
|
}
|
|
159
|
+
export async function getObjectType(options) {
|
|
160
|
+
const { baseUrl, accessToken, knId, otId, businessDomain = "bd_public", branch = "main", } = options;
|
|
161
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
162
|
+
const url = new URL(`${base}/api/ontology-manager/v1/knowledge-networks/${encodeURIComponent(knId)}/object-types/${encodeURIComponent(otId)}`);
|
|
163
|
+
url.searchParams.set("branch", branch);
|
|
164
|
+
const response = await fetch(url.toString(), {
|
|
165
|
+
method: "GET",
|
|
166
|
+
headers: buildHeaders(accessToken, businessDomain),
|
|
167
|
+
});
|
|
168
|
+
const body = await response.text();
|
|
169
|
+
if (!response.ok) {
|
|
170
|
+
throw new HttpError(response.status, response.statusText, body);
|
|
171
|
+
}
|
|
172
|
+
return body;
|
|
173
|
+
}
|
|
174
|
+
export async function createObjectTypes(options) {
|
|
175
|
+
const { baseUrl, accessToken, knId, body, businessDomain = "bd_public", branch = "main", } = options;
|
|
176
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
177
|
+
const url = new URL(`${base}/api/ontology-manager/v1/knowledge-networks/${encodeURIComponent(knId)}/object-types`);
|
|
178
|
+
url.searchParams.set("branch", branch);
|
|
179
|
+
const response = await fetch(url.toString(), {
|
|
180
|
+
method: "POST",
|
|
181
|
+
headers: {
|
|
182
|
+
...buildHeaders(accessToken, businessDomain),
|
|
183
|
+
"content-type": "application/json",
|
|
184
|
+
},
|
|
185
|
+
body,
|
|
186
|
+
});
|
|
187
|
+
const responseBody = await response.text();
|
|
188
|
+
if (!response.ok) {
|
|
189
|
+
throw new HttpError(response.status, response.statusText, responseBody);
|
|
190
|
+
}
|
|
191
|
+
return responseBody;
|
|
192
|
+
}
|
|
193
|
+
export async function updateObjectType(options) {
|
|
194
|
+
const { baseUrl, accessToken, knId, otId, body, businessDomain = "bd_public", } = options;
|
|
195
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
196
|
+
const url = `${base}/api/ontology-manager/v1/knowledge-networks/${encodeURIComponent(knId)}/object-types/${encodeURIComponent(otId)}`;
|
|
197
|
+
const response = await fetch(url, {
|
|
198
|
+
method: "PUT",
|
|
199
|
+
headers: {
|
|
200
|
+
...buildHeaders(accessToken, businessDomain),
|
|
201
|
+
"content-type": "application/json",
|
|
202
|
+
},
|
|
203
|
+
body,
|
|
204
|
+
});
|
|
205
|
+
const responseBody = await response.text();
|
|
206
|
+
if (!response.ok) {
|
|
207
|
+
throw new HttpError(response.status, response.statusText, responseBody);
|
|
208
|
+
}
|
|
209
|
+
return responseBody;
|
|
210
|
+
}
|
|
211
|
+
export async function deleteObjectTypes(options) {
|
|
212
|
+
const { baseUrl, accessToken, knId, otIds, businessDomain = "bd_public", } = options;
|
|
213
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
214
|
+
const url = `${base}/api/ontology-manager/v1/knowledge-networks/${encodeURIComponent(knId)}/object-types/${encodeURIComponent(otIds)}`;
|
|
215
|
+
const response = await fetch(url, {
|
|
216
|
+
method: "DELETE",
|
|
217
|
+
headers: buildHeaders(accessToken, businessDomain),
|
|
218
|
+
});
|
|
219
|
+
if (!response.ok) {
|
|
220
|
+
const body = await response.text();
|
|
221
|
+
throw new HttpError(response.status, response.statusText, body);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
export async function getRelationType(options) {
|
|
225
|
+
const { baseUrl, accessToken, knId, rtId, businessDomain = "bd_public", branch = "main", } = options;
|
|
226
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
227
|
+
const url = new URL(`${base}/api/ontology-manager/v1/knowledge-networks/${encodeURIComponent(knId)}/relation-types/${encodeURIComponent(rtId)}`);
|
|
228
|
+
url.searchParams.set("branch", branch);
|
|
229
|
+
const response = await fetch(url.toString(), {
|
|
230
|
+
method: "GET",
|
|
231
|
+
headers: buildHeaders(accessToken, businessDomain),
|
|
232
|
+
});
|
|
233
|
+
const body = await response.text();
|
|
234
|
+
if (!response.ok) {
|
|
235
|
+
throw new HttpError(response.status, response.statusText, body);
|
|
236
|
+
}
|
|
237
|
+
return body;
|
|
238
|
+
}
|
|
239
|
+
export async function createRelationTypes(options) {
|
|
240
|
+
const { baseUrl, accessToken, knId, body, businessDomain = "bd_public", branch = "main", } = options;
|
|
241
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
242
|
+
const url = new URL(`${base}/api/ontology-manager/v1/knowledge-networks/${encodeURIComponent(knId)}/relation-types`);
|
|
243
|
+
url.searchParams.set("branch", branch);
|
|
244
|
+
const response = await fetch(url.toString(), {
|
|
245
|
+
method: "POST",
|
|
246
|
+
headers: {
|
|
247
|
+
...buildHeaders(accessToken, businessDomain),
|
|
248
|
+
"content-type": "application/json",
|
|
249
|
+
},
|
|
250
|
+
body,
|
|
251
|
+
});
|
|
252
|
+
const responseBody = await response.text();
|
|
253
|
+
if (!response.ok) {
|
|
254
|
+
throw new HttpError(response.status, response.statusText, responseBody);
|
|
255
|
+
}
|
|
256
|
+
return responseBody;
|
|
257
|
+
}
|
|
258
|
+
export async function updateRelationType(options) {
|
|
259
|
+
const { baseUrl, accessToken, knId, rtId, body, businessDomain = "bd_public", } = options;
|
|
260
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
261
|
+
const url = `${base}/api/ontology-manager/v1/knowledge-networks/${encodeURIComponent(knId)}/relation-types/${encodeURIComponent(rtId)}`;
|
|
262
|
+
const response = await fetch(url, {
|
|
263
|
+
method: "PUT",
|
|
264
|
+
headers: {
|
|
265
|
+
...buildHeaders(accessToken, businessDomain),
|
|
266
|
+
"content-type": "application/json",
|
|
267
|
+
},
|
|
268
|
+
body,
|
|
269
|
+
});
|
|
270
|
+
const responseBody = await response.text();
|
|
271
|
+
if (!response.ok) {
|
|
272
|
+
throw new HttpError(response.status, response.statusText, responseBody);
|
|
273
|
+
}
|
|
274
|
+
return responseBody;
|
|
275
|
+
}
|
|
276
|
+
export async function deleteRelationTypes(options) {
|
|
277
|
+
const { baseUrl, accessToken, knId, rtIds, businessDomain = "bd_public", } = options;
|
|
278
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
279
|
+
const url = `${base}/api/ontology-manager/v1/knowledge-networks/${encodeURIComponent(knId)}/relation-types/${encodeURIComponent(rtIds)}`;
|
|
280
|
+
const response = await fetch(url, {
|
|
281
|
+
method: "DELETE",
|
|
282
|
+
headers: buildHeaders(accessToken, businessDomain),
|
|
283
|
+
});
|
|
284
|
+
if (!response.ok) {
|
|
285
|
+
const body = await response.text();
|
|
286
|
+
throw new HttpError(response.status, response.statusText, body);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
export async function buildKnowledgeNetwork(options) {
|
|
290
|
+
const { baseUrl, accessToken, knId, businessDomain = "bd_public", } = options;
|
|
291
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
292
|
+
const url = `${base}/api/ontology-manager/v1/knowledge-networks/${encodeURIComponent(knId)}/jobs`;
|
|
293
|
+
const body = JSON.stringify({
|
|
294
|
+
name: `sdk_build_${knId.slice(0, 8)}`,
|
|
295
|
+
job_type: "full",
|
|
296
|
+
});
|
|
297
|
+
const response = await fetch(url, {
|
|
298
|
+
method: "POST",
|
|
299
|
+
headers: {
|
|
300
|
+
...buildHeaders(accessToken, businessDomain),
|
|
301
|
+
"content-type": "application/json",
|
|
302
|
+
},
|
|
303
|
+
body,
|
|
304
|
+
});
|
|
305
|
+
if (!response.ok) {
|
|
306
|
+
const responseBody = await response.text();
|
|
307
|
+
throw new HttpError(response.status, response.statusText, responseBody);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
export async function getBuildStatus(options) {
|
|
311
|
+
const { baseUrl, accessToken, knId, businessDomain = "bd_public", } = options;
|
|
312
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
313
|
+
const url = new URL(`${base}/api/ontology-manager/v1/knowledge-networks/${encodeURIComponent(knId)}/jobs`);
|
|
314
|
+
url.searchParams.set("limit", "1");
|
|
315
|
+
url.searchParams.set("direction", "desc");
|
|
316
|
+
const response = await fetch(url.toString(), {
|
|
317
|
+
method: "GET",
|
|
318
|
+
headers: buildHeaders(accessToken, businessDomain),
|
|
319
|
+
});
|
|
320
|
+
const body = await response.text();
|
|
321
|
+
if (!response.ok) {
|
|
322
|
+
throw new HttpError(response.status, response.statusText, body);
|
|
323
|
+
}
|
|
324
|
+
return body;
|
|
325
|
+
}
|
package/dist/cli.js
CHANGED
|
@@ -3,6 +3,7 @@ import { runAuthCommand } from "./commands/auth.js";
|
|
|
3
3
|
import { runKnCommand } from "./commands/bkn.js";
|
|
4
4
|
import { runCallCommand } from "./commands/call.js";
|
|
5
5
|
import { runContextLoaderCommand } from "./commands/context-loader.js";
|
|
6
|
+
import { runDsCommand } from "./commands/ds.js";
|
|
6
7
|
import { runTokenCommand } from "./commands/token.js";
|
|
7
8
|
function printHelp() {
|
|
8
9
|
console.log(`kweaver
|
|
@@ -20,6 +21,10 @@ Usage:
|
|
|
20
21
|
kweaver call <url> [-X METHOD] [-H "Name: value"] [-d BODY] [--pretty] [--verbose] [-bd value]
|
|
21
22
|
kweaver agent chat <agent_id> [-m "message"] [--version value] [--conversation-id id] [--stream] [--no-stream] [--verbose] [-bd value]
|
|
22
23
|
kweaver agent list [options]
|
|
24
|
+
kweaver agent get <agent_id> [options]
|
|
25
|
+
kweaver ds list [options]
|
|
26
|
+
kweaver ds get <id>
|
|
27
|
+
kweaver ds connect <db_type> <host> <port> <database> --account X --password Y
|
|
23
28
|
kweaver bkn list [options]
|
|
24
29
|
kweaver bkn get <kn-id> [options]
|
|
25
30
|
kweaver bkn search <kn-id> <query> [options]
|
|
@@ -33,6 +38,7 @@ Commands:
|
|
|
33
38
|
auth Login, list, inspect, and switch saved platform auth profiles
|
|
34
39
|
token Print the current access token, refreshing it first if needed
|
|
35
40
|
call Call an API with curl-style flags and auto-injected token headers
|
|
41
|
+
ds Manage datasources (list, get, delete, tables, connect)
|
|
36
42
|
agent Chat with a KWeaver agent (agent chat <id>), list published agents (agent list)
|
|
37
43
|
bkn Business knowledge network (list/get/create/update/delete/export/stats; object-type, subgraph, action-type, action-log)
|
|
38
44
|
context-loader Call context-loader MCP (tools, resources, prompts; kn-search, query-*, etc.)
|
|
@@ -50,6 +56,9 @@ export async function run(argv) {
|
|
|
50
56
|
if (command === "call" || command === "curl") {
|
|
51
57
|
return runCallCommand(rest);
|
|
52
58
|
}
|
|
59
|
+
if (command === "ds") {
|
|
60
|
+
return runDsCommand(rest);
|
|
61
|
+
}
|
|
53
62
|
if (command === "token") {
|
|
54
63
|
return runTokenCommand(rest);
|
|
55
64
|
}
|
package/dist/commands/agent.d.ts
CHANGED
|
@@ -26,3 +26,10 @@ export interface AgentHistoryOptions {
|
|
|
26
26
|
}
|
|
27
27
|
export declare function parseAgentHistoryArgs(args: string[]): AgentHistoryOptions;
|
|
28
28
|
export declare function runAgentCommand(args: string[]): Promise<number>;
|
|
29
|
+
export interface AgentGetOptions {
|
|
30
|
+
agentId: string;
|
|
31
|
+
businessDomain: string;
|
|
32
|
+
pretty: boolean;
|
|
33
|
+
verbose: boolean;
|
|
34
|
+
}
|
|
35
|
+
export declare function parseAgentGetArgs(args: string[]): AgentGetOptions;
|
package/dist/commands/agent.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ensureValidToken, formatHttpError } from "../auth/oauth.js";
|
|
2
2
|
import { runAgentChatCommand } from "./agent-chat.js";
|
|
3
|
-
import { listAgents } from "../api/agent-list.js";
|
|
3
|
+
import { listAgents, getAgent } from "../api/agent-list.js";
|
|
4
4
|
import { listConversations, listMessages } from "../api/conversations.js";
|
|
5
5
|
import { formatCallOutput } from "./call.js";
|
|
6
6
|
function readStringField(value, ...keys) {
|
|
@@ -222,6 +222,7 @@ Subcommands:
|
|
|
222
222
|
[--verbose] Print request details to stderr
|
|
223
223
|
[-bd|--biz-domain value] Override x-business-domain (default: bd_public)
|
|
224
224
|
list [options] List published agents
|
|
225
|
+
get <agent_id> [--verbose] Get agent details
|
|
225
226
|
sessions <agent_id> List all conversations for an agent
|
|
226
227
|
[--limit n] [-bd domain] [--pretty]
|
|
227
228
|
history <conversation_id> Show message history for a conversation
|
|
@@ -255,6 +256,20 @@ Options:
|
|
|
255
256
|
}
|
|
256
257
|
return runAgentChatCommand(rest);
|
|
257
258
|
}
|
|
259
|
+
if (subcommand === "get") {
|
|
260
|
+
if (rest.length === 1 && (rest[0] === "--help" || rest[0] === "-h")) {
|
|
261
|
+
console.log(`kweaver agent get <agent_id> [options]
|
|
262
|
+
|
|
263
|
+
Get agent details from the agent-factory API.
|
|
264
|
+
|
|
265
|
+
Options:
|
|
266
|
+
--verbose, -v Show full JSON response
|
|
267
|
+
-bd, --biz-domain <value> Business domain (default: bd_public)
|
|
268
|
+
--pretty Pretty-print JSON output (default)`);
|
|
269
|
+
return Promise.resolve(0);
|
|
270
|
+
}
|
|
271
|
+
return runAgentGetCommand(rest);
|
|
272
|
+
}
|
|
258
273
|
if (subcommand === "list") {
|
|
259
274
|
if (rest.length === 1 && (rest[0] === "--help" || rest[0] === "-h")) {
|
|
260
275
|
console.log(`kweaver agent list [options]
|
|
@@ -306,6 +321,92 @@ Options:
|
|
|
306
321
|
console.error(`Unknown agent subcommand: ${subcommand}`);
|
|
307
322
|
return Promise.resolve(1);
|
|
308
323
|
}
|
|
324
|
+
export function parseAgentGetArgs(args) {
|
|
325
|
+
const agentId = args[0];
|
|
326
|
+
if (!agentId || agentId.startsWith("-")) {
|
|
327
|
+
throw new Error("Missing agent_id. Usage: kweaver agent get <agent_id> [options]");
|
|
328
|
+
}
|
|
329
|
+
let businessDomain = "bd_public";
|
|
330
|
+
let pretty = true;
|
|
331
|
+
let verbose = false;
|
|
332
|
+
for (let i = 1; i < args.length; i += 1) {
|
|
333
|
+
const arg = args[i];
|
|
334
|
+
if (arg === "--help" || arg === "-h") {
|
|
335
|
+
throw new Error("help");
|
|
336
|
+
}
|
|
337
|
+
if (arg === "-bd" || arg === "--biz-domain") {
|
|
338
|
+
businessDomain = args[i + 1] ?? "bd_public";
|
|
339
|
+
if (!businessDomain || businessDomain.startsWith("-")) {
|
|
340
|
+
throw new Error("Missing value for biz-domain flag");
|
|
341
|
+
}
|
|
342
|
+
i += 1;
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
if (arg === "--pretty") {
|
|
346
|
+
pretty = true;
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
if (arg === "--verbose" || arg === "-v") {
|
|
350
|
+
verbose = true;
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
throw new Error(`Unsupported agent get argument: ${arg}`);
|
|
354
|
+
}
|
|
355
|
+
return { agentId, businessDomain, pretty, verbose };
|
|
356
|
+
}
|
|
357
|
+
function formatSimpleAgentGet(text, pretty) {
|
|
358
|
+
const parsed = JSON.parse(text);
|
|
359
|
+
const config = parsed.config ?? {};
|
|
360
|
+
const ds = config.data_source ?? {};
|
|
361
|
+
const kg = ds.kg ?? [];
|
|
362
|
+
const knIds = parsed.kn_ids ?? kg.map((k) => String(k.kg_id ?? "")).filter(Boolean);
|
|
363
|
+
const simplified = {
|
|
364
|
+
id: parsed.id,
|
|
365
|
+
name: parsed.name,
|
|
366
|
+
description: parsed.profile ?? parsed.description ?? "",
|
|
367
|
+
status: parsed.status,
|
|
368
|
+
kn_ids: knIds,
|
|
369
|
+
};
|
|
370
|
+
return JSON.stringify(simplified, null, pretty ? 2 : 0);
|
|
371
|
+
}
|
|
372
|
+
async function runAgentGetCommand(args) {
|
|
373
|
+
let options;
|
|
374
|
+
try {
|
|
375
|
+
options = parseAgentGetArgs(args);
|
|
376
|
+
}
|
|
377
|
+
catch (error) {
|
|
378
|
+
if (error instanceof Error && error.message === "help") {
|
|
379
|
+
console.log(`kweaver agent get <agent_id> [options]
|
|
380
|
+
|
|
381
|
+
Get agent details from the agent-factory API.
|
|
382
|
+
|
|
383
|
+
Options:
|
|
384
|
+
--verbose, -v Show full JSON response
|
|
385
|
+
-bd, --biz-domain <value> Business domain (default: bd_public)
|
|
386
|
+
--pretty Pretty-print JSON output (default)`);
|
|
387
|
+
return 0;
|
|
388
|
+
}
|
|
389
|
+
console.error(formatHttpError(error));
|
|
390
|
+
return 1;
|
|
391
|
+
}
|
|
392
|
+
try {
|
|
393
|
+
const token = await ensureValidToken();
|
|
394
|
+
const body = await getAgent({
|
|
395
|
+
baseUrl: token.baseUrl,
|
|
396
|
+
accessToken: token.accessToken,
|
|
397
|
+
agentId: options.agentId,
|
|
398
|
+
businessDomain: options.businessDomain,
|
|
399
|
+
});
|
|
400
|
+
if (body) {
|
|
401
|
+
console.log(options.verbose ? formatCallOutput(body, options.pretty) : formatSimpleAgentGet(body, options.pretty));
|
|
402
|
+
}
|
|
403
|
+
return 0;
|
|
404
|
+
}
|
|
405
|
+
catch (error) {
|
|
406
|
+
console.error(formatHttpError(error));
|
|
407
|
+
return 1;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
309
410
|
async function runAgentListCommand(args) {
|
|
310
411
|
let options;
|
|
311
412
|
try {
|
package/dist/commands/bkn.d.ts
CHANGED
|
@@ -60,6 +60,12 @@ export interface KnActionTypeExecuteOptions {
|
|
|
60
60
|
timeout: number;
|
|
61
61
|
}
|
|
62
62
|
export declare function parseKnActionTypeExecuteArgs(args: string[]): KnActionTypeExecuteOptions;
|
|
63
|
+
export declare function parseKnBuildArgs(args: string[]): {
|
|
64
|
+
knId: string;
|
|
65
|
+
wait: boolean;
|
|
66
|
+
timeout: number;
|
|
67
|
+
businessDomain: string;
|
|
68
|
+
};
|
|
63
69
|
export declare function parseKnSearchArgs(args: string[]): {
|
|
64
70
|
knId: string;
|
|
65
71
|
query: string;
|