@kweaver-ai/kweaver-sdk 0.5.1 → 0.5.2
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 +6 -1
- package/README.zh.md +5 -0
- package/dist/api/agent-chat.d.ts +1 -1
- package/dist/api/agent-chat.js +4 -4
- package/dist/api/agent-list.d.ts +35 -0
- package/dist/api/agent-list.js +86 -12
- package/dist/api/bkn-backend.d.ts +60 -0
- package/dist/api/bkn-backend.js +103 -10
- package/dist/api/conversations.d.ts +6 -3
- package/dist/api/conversations.js +26 -27
- package/dist/api/dataflow.js +1 -10
- package/dist/api/datasources.js +1 -10
- package/dist/api/dataviews.js +1 -10
- package/dist/api/headers.d.ts +9 -0
- package/dist/api/headers.js +25 -0
- package/dist/api/knowledge-networks.d.ts +41 -0
- package/dist/api/knowledge-networks.js +69 -22
- package/dist/api/ontology-query.d.ts +14 -1
- package/dist/api/ontology-query.js +63 -49
- package/dist/api/semantic-search.js +2 -12
- package/dist/api/skills.d.ts +141 -0
- package/dist/api/skills.js +216 -0
- package/dist/api/vega.d.ts +63 -0
- package/dist/api/vega.js +130 -10
- package/dist/auth/oauth.d.ts +5 -1
- package/dist/auth/oauth.js +293 -94
- package/dist/cli.js +28 -4
- package/dist/client.d.ts +3 -0
- package/dist/client.js +4 -0
- package/dist/commands/agent.d.ts +33 -1
- package/dist/commands/agent.js +721 -49
- package/dist/commands/auth.js +156 -33
- package/dist/commands/bkn-ops.d.ts +77 -0
- package/dist/commands/bkn-ops.js +1056 -0
- package/dist/commands/bkn-query.d.ts +14 -0
- package/dist/commands/bkn-query.js +370 -0
- package/dist/commands/bkn-schema.d.ts +135 -0
- package/dist/commands/bkn-schema.js +1461 -0
- package/dist/commands/bkn-utils.d.ts +36 -0
- package/dist/commands/bkn-utils.js +102 -0
- package/dist/commands/bkn.d.ts +7 -113
- package/dist/commands/bkn.js +175 -2429
- package/dist/commands/dataview.d.ts +7 -0
- package/dist/commands/dataview.js +38 -2
- package/dist/commands/ds.d.ts +1 -0
- package/dist/commands/ds.js +8 -1
- package/dist/commands/import-csv.d.ts +2 -0
- package/dist/commands/import-csv.js +3 -2
- package/dist/commands/skill.d.ts +26 -0
- package/dist/commands/skill.js +524 -0
- package/dist/commands/vega.js +371 -14
- package/dist/config/jwt.d.ts +6 -0
- package/dist/config/jwt.js +21 -0
- package/dist/config/store.d.ts +37 -5
- package/dist/config/store.js +363 -30
- package/dist/index.d.ts +6 -1
- package/dist/index.js +5 -1
- package/dist/resources/bkn.d.ts +4 -0
- package/dist/resources/bkn.js +4 -0
- package/dist/resources/conversations.d.ts +5 -2
- package/dist/resources/conversations.js +17 -3
- package/dist/resources/skills.d.ts +47 -0
- package/dist/resources/skills.js +47 -0
- package/dist/resources/vega.d.ts +11 -0
- package/dist/resources/vega.js +37 -1
- package/package.json +1 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared HTTP header builder for all KWeaver API calls.
|
|
3
|
+
*
|
|
4
|
+
* Supports optional x-account-id / x-account-type headers read from
|
|
5
|
+
* environment variables KWEAVER_ACCOUNT_ID and KWEAVER_ACCOUNT_TYPE.
|
|
6
|
+
* These are required by older platform versions (e.g. dip-poc.aishu.cn)
|
|
7
|
+
* that do not infer account info from the token automatically.
|
|
8
|
+
*/
|
|
9
|
+
export function buildHeaders(accessToken, businessDomain) {
|
|
10
|
+
const headers = {
|
|
11
|
+
accept: "application/json, text/plain, */*",
|
|
12
|
+
"accept-language": "zh-cn",
|
|
13
|
+
authorization: `Bearer ${accessToken}`,
|
|
14
|
+
token: accessToken,
|
|
15
|
+
"x-business-domain": businessDomain,
|
|
16
|
+
"x-language": "zh-cn",
|
|
17
|
+
};
|
|
18
|
+
const accountId = process.env.KWEAVER_ACCOUNT_ID;
|
|
19
|
+
const accountType = process.env.KWEAVER_ACCOUNT_TYPE;
|
|
20
|
+
if (accountId)
|
|
21
|
+
headers["x-account-id"] = accountId;
|
|
22
|
+
if (accountType)
|
|
23
|
+
headers["x-account-type"] = accountType;
|
|
24
|
+
return headers;
|
|
25
|
+
}
|
|
@@ -55,6 +55,43 @@ 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 GetActionTypeOptions {
|
|
59
|
+
baseUrl: string;
|
|
60
|
+
accessToken: string;
|
|
61
|
+
knId: string;
|
|
62
|
+
atId: string;
|
|
63
|
+
businessDomain?: string;
|
|
64
|
+
branch?: string;
|
|
65
|
+
}
|
|
66
|
+
export declare function getActionType(options: GetActionTypeOptions): Promise<string>;
|
|
67
|
+
export interface CreateActionTypesOptions {
|
|
68
|
+
baseUrl: string;
|
|
69
|
+
accessToken: string;
|
|
70
|
+
knId: string;
|
|
71
|
+
body: string;
|
|
72
|
+
businessDomain?: string;
|
|
73
|
+
branch?: string;
|
|
74
|
+
}
|
|
75
|
+
export declare function createActionTypes(options: CreateActionTypesOptions): Promise<string>;
|
|
76
|
+
export interface UpdateActionTypeOptions {
|
|
77
|
+
baseUrl: string;
|
|
78
|
+
accessToken: string;
|
|
79
|
+
knId: string;
|
|
80
|
+
atId: string;
|
|
81
|
+
body: string;
|
|
82
|
+
businessDomain?: string;
|
|
83
|
+
branch?: string;
|
|
84
|
+
}
|
|
85
|
+
export declare function updateActionType(options: UpdateActionTypeOptions): Promise<string>;
|
|
86
|
+
export interface DeleteActionTypesOptions {
|
|
87
|
+
baseUrl: string;
|
|
88
|
+
accessToken: string;
|
|
89
|
+
knId: string;
|
|
90
|
+
atIds: string;
|
|
91
|
+
businessDomain?: string;
|
|
92
|
+
branch?: string;
|
|
93
|
+
}
|
|
94
|
+
export declare function deleteActionTypes(options: DeleteActionTypesOptions): Promise<void>;
|
|
58
95
|
export interface GetObjectTypeOptions {
|
|
59
96
|
baseUrl: string;
|
|
60
97
|
accessToken: string;
|
|
@@ -80,6 +117,7 @@ export interface UpdateObjectTypeOptions {
|
|
|
80
117
|
otId: string;
|
|
81
118
|
body: string;
|
|
82
119
|
businessDomain?: string;
|
|
120
|
+
branch?: string;
|
|
83
121
|
}
|
|
84
122
|
export declare function updateObjectType(options: UpdateObjectTypeOptions): Promise<string>;
|
|
85
123
|
export interface DeleteObjectTypesOptions {
|
|
@@ -88,6 +126,7 @@ export interface DeleteObjectTypesOptions {
|
|
|
88
126
|
knId: string;
|
|
89
127
|
otIds: string;
|
|
90
128
|
businessDomain?: string;
|
|
129
|
+
branch?: string;
|
|
91
130
|
}
|
|
92
131
|
export declare function deleteObjectTypes(options: DeleteObjectTypesOptions): Promise<void>;
|
|
93
132
|
export interface GetRelationTypeOptions {
|
|
@@ -115,6 +154,7 @@ export interface UpdateRelationTypeOptions {
|
|
|
115
154
|
rtId: string;
|
|
116
155
|
body: string;
|
|
117
156
|
businessDomain?: string;
|
|
157
|
+
branch?: string;
|
|
118
158
|
}
|
|
119
159
|
export declare function updateRelationType(options: UpdateRelationTypeOptions): Promise<string>;
|
|
120
160
|
export interface DeleteRelationTypesOptions {
|
|
@@ -123,6 +163,7 @@ export interface DeleteRelationTypesOptions {
|
|
|
123
163
|
knId: string;
|
|
124
164
|
rtIds: string;
|
|
125
165
|
businessDomain?: string;
|
|
166
|
+
branch?: string;
|
|
126
167
|
}
|
|
127
168
|
export declare function deleteRelationTypes(options: DeleteRelationTypesOptions): Promise<void>;
|
|
128
169
|
export interface BuildKnowledgeNetworkOptions {
|
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
import { HttpError } from "../utils/http.js";
|
|
2
|
-
|
|
3
|
-
return {
|
|
4
|
-
accept: "application/json, text/plain, */*",
|
|
5
|
-
"accept-language": "zh-cn",
|
|
6
|
-
authorization: `Bearer ${accessToken}`,
|
|
7
|
-
token: accessToken,
|
|
8
|
-
"x-business-domain": businessDomain,
|
|
9
|
-
"x-language": "zh-cn",
|
|
10
|
-
};
|
|
11
|
-
}
|
|
2
|
+
import { buildHeaders } from "./headers.js";
|
|
12
3
|
export async function listKnowledgeNetworks(options) {
|
|
13
4
|
const { baseUrl, accessToken, businessDomain = "bd_public", offset = 0, limit = 50, sort = "update_time", direction = "desc", name_pattern, tag, } = options;
|
|
14
5
|
const base = baseUrl.replace(/\/+$/, "");
|
|
@@ -156,6 +147,58 @@ export async function listActionTypes(options) {
|
|
|
156
147
|
}
|
|
157
148
|
return body;
|
|
158
149
|
}
|
|
150
|
+
export async function getActionType(options) {
|
|
151
|
+
const { baseUrl, accessToken, knId, atId, businessDomain = "bd_public", branch = "main" } = options;
|
|
152
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
153
|
+
const url = new URL(`${base}/api/ontology-manager/v1/knowledge-networks/${encodeURIComponent(knId)}/action-types/${encodeURIComponent(atId)}`);
|
|
154
|
+
url.searchParams.set("branch", branch);
|
|
155
|
+
const response = await fetch(url.toString(), { method: "GET", headers: buildHeaders(accessToken, businessDomain) });
|
|
156
|
+
const body = await response.text();
|
|
157
|
+
if (!response.ok)
|
|
158
|
+
throw new HttpError(response.status, response.statusText, body);
|
|
159
|
+
return body;
|
|
160
|
+
}
|
|
161
|
+
export async function createActionTypes(options) {
|
|
162
|
+
const { baseUrl, accessToken, knId, body, businessDomain = "bd_public", branch = "main" } = options;
|
|
163
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
164
|
+
const url = new URL(`${base}/api/ontology-manager/v1/knowledge-networks/${encodeURIComponent(knId)}/action-types`);
|
|
165
|
+
url.searchParams.set("branch", branch);
|
|
166
|
+
const response = await fetch(url.toString(), {
|
|
167
|
+
method: "POST",
|
|
168
|
+
headers: { ...buildHeaders(accessToken, businessDomain), "content-type": "application/json" },
|
|
169
|
+
body,
|
|
170
|
+
});
|
|
171
|
+
const responseBody = await response.text();
|
|
172
|
+
if (!response.ok)
|
|
173
|
+
throw new HttpError(response.status, response.statusText, responseBody);
|
|
174
|
+
return responseBody;
|
|
175
|
+
}
|
|
176
|
+
export async function updateActionType(options) {
|
|
177
|
+
const { baseUrl, accessToken, knId, atId, body, businessDomain = "bd_public", branch = "main" } = options;
|
|
178
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
179
|
+
const url = new URL(`${base}/api/ontology-manager/v1/knowledge-networks/${encodeURIComponent(knId)}/action-types/${encodeURIComponent(atId)}`);
|
|
180
|
+
url.searchParams.set("branch", branch);
|
|
181
|
+
const response = await fetch(url.toString(), {
|
|
182
|
+
method: "PUT",
|
|
183
|
+
headers: { ...buildHeaders(accessToken, businessDomain), "content-type": "application/json" },
|
|
184
|
+
body,
|
|
185
|
+
});
|
|
186
|
+
const responseBody = await response.text();
|
|
187
|
+
if (!response.ok)
|
|
188
|
+
throw new HttpError(response.status, response.statusText, responseBody);
|
|
189
|
+
return responseBody;
|
|
190
|
+
}
|
|
191
|
+
export async function deleteActionTypes(options) {
|
|
192
|
+
const { baseUrl, accessToken, knId, atIds, businessDomain = "bd_public", branch = "main" } = options;
|
|
193
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
194
|
+
const url = new URL(`${base}/api/ontology-manager/v1/knowledge-networks/${encodeURIComponent(knId)}/action-types/${encodeURIComponent(atIds)}`);
|
|
195
|
+
url.searchParams.set("branch", branch);
|
|
196
|
+
const response = await fetch(url.toString(), { method: "DELETE", headers: buildHeaders(accessToken, businessDomain) });
|
|
197
|
+
if (!response.ok) {
|
|
198
|
+
const body = await response.text();
|
|
199
|
+
throw new HttpError(response.status, response.statusText, body);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
159
202
|
export async function getObjectType(options) {
|
|
160
203
|
const { baseUrl, accessToken, knId, otId, businessDomain = "bd_public", branch = "main", } = options;
|
|
161
204
|
const base = baseUrl.replace(/\/+$/, "");
|
|
@@ -191,10 +234,11 @@ export async function createObjectTypes(options) {
|
|
|
191
234
|
return responseBody;
|
|
192
235
|
}
|
|
193
236
|
export async function updateObjectType(options) {
|
|
194
|
-
const { baseUrl, accessToken, knId, otId, body, businessDomain = "bd_public", } = options;
|
|
237
|
+
const { baseUrl, accessToken, knId, otId, body, businessDomain = "bd_public", branch = "main", } = options;
|
|
195
238
|
const base = baseUrl.replace(/\/+$/, "");
|
|
196
|
-
const url = `${base}/api/ontology-manager/v1/knowledge-networks/${encodeURIComponent(knId)}/object-types/${encodeURIComponent(otId)}
|
|
197
|
-
|
|
239
|
+
const url = new URL(`${base}/api/ontology-manager/v1/knowledge-networks/${encodeURIComponent(knId)}/object-types/${encodeURIComponent(otId)}`);
|
|
240
|
+
url.searchParams.set("branch", branch);
|
|
241
|
+
const response = await fetch(url.toString(), {
|
|
198
242
|
method: "PUT",
|
|
199
243
|
headers: {
|
|
200
244
|
...buildHeaders(accessToken, businessDomain),
|
|
@@ -209,10 +253,11 @@ export async function updateObjectType(options) {
|
|
|
209
253
|
return responseBody;
|
|
210
254
|
}
|
|
211
255
|
export async function deleteObjectTypes(options) {
|
|
212
|
-
const { baseUrl, accessToken, knId, otIds, businessDomain = "bd_public", } = options;
|
|
256
|
+
const { baseUrl, accessToken, knId, otIds, businessDomain = "bd_public", branch = "main", } = options;
|
|
213
257
|
const base = baseUrl.replace(/\/+$/, "");
|
|
214
|
-
const url = `${base}/api/ontology-manager/v1/knowledge-networks/${encodeURIComponent(knId)}/object-types/${encodeURIComponent(otIds)}
|
|
215
|
-
|
|
258
|
+
const url = new URL(`${base}/api/ontology-manager/v1/knowledge-networks/${encodeURIComponent(knId)}/object-types/${encodeURIComponent(otIds)}`);
|
|
259
|
+
url.searchParams.set("branch", branch);
|
|
260
|
+
const response = await fetch(url.toString(), {
|
|
216
261
|
method: "DELETE",
|
|
217
262
|
headers: buildHeaders(accessToken, businessDomain),
|
|
218
263
|
});
|
|
@@ -256,10 +301,11 @@ export async function createRelationTypes(options) {
|
|
|
256
301
|
return responseBody;
|
|
257
302
|
}
|
|
258
303
|
export async function updateRelationType(options) {
|
|
259
|
-
const { baseUrl, accessToken, knId, rtId, body, businessDomain = "bd_public", } = options;
|
|
304
|
+
const { baseUrl, accessToken, knId, rtId, body, businessDomain = "bd_public", branch = "main", } = options;
|
|
260
305
|
const base = baseUrl.replace(/\/+$/, "");
|
|
261
|
-
const url = `${base}/api/ontology-manager/v1/knowledge-networks/${encodeURIComponent(knId)}/relation-types/${encodeURIComponent(rtId)}
|
|
262
|
-
|
|
306
|
+
const url = new URL(`${base}/api/ontology-manager/v1/knowledge-networks/${encodeURIComponent(knId)}/relation-types/${encodeURIComponent(rtId)}`);
|
|
307
|
+
url.searchParams.set("branch", branch);
|
|
308
|
+
const response = await fetch(url.toString(), {
|
|
263
309
|
method: "PUT",
|
|
264
310
|
headers: {
|
|
265
311
|
...buildHeaders(accessToken, businessDomain),
|
|
@@ -274,10 +320,11 @@ export async function updateRelationType(options) {
|
|
|
274
320
|
return responseBody;
|
|
275
321
|
}
|
|
276
322
|
export async function deleteRelationTypes(options) {
|
|
277
|
-
const { baseUrl, accessToken, knId, rtIds, businessDomain = "bd_public", } = options;
|
|
323
|
+
const { baseUrl, accessToken, knId, rtIds, businessDomain = "bd_public", branch = "main", } = options;
|
|
278
324
|
const base = baseUrl.replace(/\/+$/, "");
|
|
279
|
-
const url = `${base}/api/ontology-manager/v1/knowledge-networks/${encodeURIComponent(knId)}/relation-types/${encodeURIComponent(rtIds)}
|
|
280
|
-
|
|
325
|
+
const url = new URL(`${base}/api/ontology-manager/v1/knowledge-networks/${encodeURIComponent(knId)}/relation-types/${encodeURIComponent(rtIds)}`);
|
|
326
|
+
url.searchParams.set("branch", branch);
|
|
327
|
+
const response = await fetch(url.toString(), {
|
|
281
328
|
method: "DELETE",
|
|
282
329
|
headers: buildHeaders(accessToken, businessDomain),
|
|
283
330
|
});
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetch with timeout + retry for idempotent (read-only) ontology-query endpoints.
|
|
3
|
+
* Retries on 5xx, 429, and transient network errors with exponential backoff.
|
|
4
|
+
*/
|
|
5
|
+
export declare function fetchWithRetry(url: string, init: RequestInit): Promise<string>;
|
|
1
6
|
export interface OntologyQueryBaseOptions {
|
|
2
7
|
baseUrl: string;
|
|
3
8
|
accessToken: string;
|
|
@@ -36,7 +41,15 @@ export interface ActionTypeQueryOptions extends OntologyQueryBaseOptions {
|
|
|
36
41
|
excludeSystemProperties?: string[];
|
|
37
42
|
}
|
|
38
43
|
export declare function actionTypeQuery(options: ActionTypeQueryOptions): Promise<string>;
|
|
39
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* Action-type execute: POST (has side effects).
|
|
46
|
+
*
|
|
47
|
+
* The request body must include `_instance_identities` — an array of objects
|
|
48
|
+
* identifying which instances the action operates on:
|
|
49
|
+
* ```json
|
|
50
|
+
* {"_instance_identities": [{"<primary_key>": "<value>"}], ...otherParams}
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
40
53
|
export interface ActionTypeExecuteOptions extends OntologyQueryBaseOptions {
|
|
41
54
|
atId: string;
|
|
42
55
|
body: string;
|
|
@@ -1,13 +1,63 @@
|
|
|
1
1
|
import { HttpError } from "../utils/http.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
import { buildHeaders } from "./headers.js";
|
|
3
|
+
const QUERY_TIMEOUT_MS = 30_000;
|
|
4
|
+
const QUERY_MAX_RETRIES = 2;
|
|
5
|
+
const QUERY_RETRY_BASE_MS = 500;
|
|
6
|
+
function isRetryableStatus(status) {
|
|
7
|
+
return status >= 500 || status === 429;
|
|
8
|
+
}
|
|
9
|
+
function isRetryableNetworkError(error) {
|
|
10
|
+
if (error instanceof HttpError)
|
|
11
|
+
return isRetryableStatus(error.status);
|
|
12
|
+
if (!(error instanceof Error))
|
|
13
|
+
return false;
|
|
14
|
+
if (error.name === "AbortError" || error.name === "TimeoutError")
|
|
15
|
+
return true;
|
|
16
|
+
const msg = error.message.toLowerCase();
|
|
17
|
+
const cause = "cause" in error && error.cause instanceof Error ? error.cause.message.toLowerCase() : "";
|
|
18
|
+
const combined = `${msg} ${cause}`;
|
|
19
|
+
return ["fetch failed", "econnreset", "econnrefused", "etimedout", "socket hang up", "network socket disconnected"].some((t) => combined.includes(t));
|
|
20
|
+
}
|
|
21
|
+
async function fetchWithTimeout(url, init) {
|
|
22
|
+
const controller = new AbortController();
|
|
23
|
+
const timer = setTimeout(() => controller.abort(), QUERY_TIMEOUT_MS);
|
|
24
|
+
try {
|
|
25
|
+
return await fetch(url, { ...init, signal: controller.signal });
|
|
26
|
+
}
|
|
27
|
+
finally {
|
|
28
|
+
clearTimeout(timer);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Fetch with timeout + retry for idempotent (read-only) ontology-query endpoints.
|
|
33
|
+
* Retries on 5xx, 429, and transient network errors with exponential backoff.
|
|
34
|
+
*/
|
|
35
|
+
export async function fetchWithRetry(url, init) {
|
|
36
|
+
let lastError;
|
|
37
|
+
for (let attempt = 0; attempt <= QUERY_MAX_RETRIES; attempt++) {
|
|
38
|
+
try {
|
|
39
|
+
const response = await fetchWithTimeout(url, init);
|
|
40
|
+
const body = await response.text();
|
|
41
|
+
if (!response.ok) {
|
|
42
|
+
if (attempt < QUERY_MAX_RETRIES && isRetryableStatus(response.status)) {
|
|
43
|
+
lastError = new HttpError(response.status, response.statusText, body);
|
|
44
|
+
await new Promise((r) => setTimeout(r, QUERY_RETRY_BASE_MS * 2 ** attempt));
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
throw new HttpError(response.status, response.statusText, body);
|
|
48
|
+
}
|
|
49
|
+
return body;
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
lastError = error;
|
|
53
|
+
if (attempt < QUERY_MAX_RETRIES && isRetryableNetworkError(error)) {
|
|
54
|
+
await new Promise((r) => setTimeout(r, QUERY_RETRY_BASE_MS * 2 ** attempt));
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
throw lastError;
|
|
11
61
|
}
|
|
12
62
|
export async function objectTypeQuery(options) {
|
|
13
63
|
const { baseUrl, accessToken, knId, otId, body, businessDomain = "bd_public", includeTypeInfo, includeLogicParams, excludeSystemProperties, } = options;
|
|
@@ -29,16 +79,7 @@ export async function objectTypeQuery(options) {
|
|
|
29
79
|
"content-type": "application/json",
|
|
30
80
|
"X-HTTP-Method-Override": "GET",
|
|
31
81
|
};
|
|
32
|
-
|
|
33
|
-
method: "POST",
|
|
34
|
-
headers,
|
|
35
|
-
body,
|
|
36
|
-
});
|
|
37
|
-
const responseBody = await response.text();
|
|
38
|
-
if (!response.ok) {
|
|
39
|
-
throw new HttpError(response.status, response.statusText, responseBody);
|
|
40
|
-
}
|
|
41
|
-
return responseBody;
|
|
82
|
+
return fetchWithRetry(url.toString(), { method: "POST", headers, body });
|
|
42
83
|
}
|
|
43
84
|
export async function objectTypeProperties(options) {
|
|
44
85
|
const { baseUrl, accessToken, knId, otId, body, businessDomain = "bd_public", excludeSystemProperties, } = options;
|
|
@@ -54,16 +95,7 @@ export async function objectTypeProperties(options) {
|
|
|
54
95
|
"content-type": "application/json",
|
|
55
96
|
"X-HTTP-Method-Override": "GET",
|
|
56
97
|
};
|
|
57
|
-
|
|
58
|
-
method: "POST",
|
|
59
|
-
headers,
|
|
60
|
-
body,
|
|
61
|
-
});
|
|
62
|
-
const responseBody = await response.text();
|
|
63
|
-
if (!response.ok) {
|
|
64
|
-
throw new HttpError(response.status, response.statusText, responseBody);
|
|
65
|
-
}
|
|
66
|
-
return responseBody;
|
|
98
|
+
return fetchWithRetry(url.toString(), { method: "POST", headers, body });
|
|
67
99
|
}
|
|
68
100
|
export async function subgraph(options) {
|
|
69
101
|
const { baseUrl, accessToken, knId, body, businessDomain = "bd_public", includeLogicParams, excludeSystemProperties, queryType, } = options;
|
|
@@ -85,16 +117,7 @@ export async function subgraph(options) {
|
|
|
85
117
|
"content-type": "application/json",
|
|
86
118
|
"X-HTTP-Method-Override": "GET",
|
|
87
119
|
};
|
|
88
|
-
|
|
89
|
-
method: "POST",
|
|
90
|
-
headers,
|
|
91
|
-
body,
|
|
92
|
-
});
|
|
93
|
-
const responseBody = await response.text();
|
|
94
|
-
if (!response.ok) {
|
|
95
|
-
throw new HttpError(response.status, response.statusText, responseBody);
|
|
96
|
-
}
|
|
97
|
-
return responseBody;
|
|
120
|
+
return fetchWithRetry(url.toString(), { method: "POST", headers, body });
|
|
98
121
|
}
|
|
99
122
|
export async function actionTypeQuery(options) {
|
|
100
123
|
const { baseUrl, accessToken, knId, atId, body, businessDomain = "bd_public", includeTypeInfo, excludeSystemProperties, } = options;
|
|
@@ -113,16 +136,7 @@ export async function actionTypeQuery(options) {
|
|
|
113
136
|
"content-type": "application/json",
|
|
114
137
|
"X-HTTP-Method-Override": "GET",
|
|
115
138
|
};
|
|
116
|
-
|
|
117
|
-
method: "POST",
|
|
118
|
-
headers,
|
|
119
|
-
body,
|
|
120
|
-
});
|
|
121
|
-
const responseBody = await response.text();
|
|
122
|
-
if (!response.ok) {
|
|
123
|
-
throw new HttpError(response.status, response.statusText, responseBody);
|
|
124
|
-
}
|
|
125
|
-
return responseBody;
|
|
139
|
+
return fetchWithRetry(url.toString(), { method: "POST", headers, body });
|
|
126
140
|
}
|
|
127
141
|
export async function actionTypeExecute(options) {
|
|
128
142
|
const { baseUrl, accessToken, knId, atId, body, businessDomain = "bd_public" } = options;
|
|
@@ -1,22 +1,12 @@
|
|
|
1
1
|
import { HttpError } from "../utils/http.js";
|
|
2
|
-
|
|
3
|
-
return {
|
|
4
|
-
accept: "application/json, text/plain, */*",
|
|
5
|
-
"accept-language": "zh-cn",
|
|
6
|
-
authorization: `Bearer ${accessToken}`,
|
|
7
|
-
token: accessToken,
|
|
8
|
-
"x-business-domain": businessDomain,
|
|
9
|
-
"x-language": "zh-cn",
|
|
10
|
-
"content-type": "application/json",
|
|
11
|
-
};
|
|
12
|
-
}
|
|
2
|
+
import { buildHeaders } from "./headers.js";
|
|
13
3
|
export async function semanticSearch(options) {
|
|
14
4
|
const { baseUrl, accessToken, knId, query, businessDomain = "bd_public", mode = "keyword_vector_retrieval", rerankAction = "default", maxConcepts = 10, returnQueryUnderstanding = false, } = options;
|
|
15
5
|
const base = baseUrl.replace(/\/+$/, "");
|
|
16
6
|
const url = `${base}/api/agent-retrieval/v1/kn/semantic-search`;
|
|
17
7
|
const response = await fetch(url, {
|
|
18
8
|
method: "POST",
|
|
19
|
-
headers: buildHeaders(accessToken, businessDomain),
|
|
9
|
+
headers: { ...buildHeaders(accessToken, businessDomain), "content-type": "application/json" },
|
|
20
10
|
body: JSON.stringify({
|
|
21
11
|
kn_id: knId,
|
|
22
12
|
query,
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
export type SkillStatus = "unpublish" | "published" | "offline";
|
|
2
|
+
export type SkillFileType = "zip" | "content";
|
|
3
|
+
export interface SkillSummary {
|
|
4
|
+
skill_id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
version?: string;
|
|
8
|
+
status?: SkillStatus;
|
|
9
|
+
source?: string;
|
|
10
|
+
create_user?: string;
|
|
11
|
+
create_time?: number;
|
|
12
|
+
update_user?: string;
|
|
13
|
+
update_time?: number;
|
|
14
|
+
business_domain_id?: string;
|
|
15
|
+
category?: string;
|
|
16
|
+
category_name?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface SkillInfo extends SkillSummary {
|
|
19
|
+
dependencies?: Record<string, unknown>;
|
|
20
|
+
extend_info?: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
export interface SkillFileSummary {
|
|
23
|
+
rel_path: string;
|
|
24
|
+
file_type?: string;
|
|
25
|
+
size?: number;
|
|
26
|
+
mime_type?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface SkillContentIndex {
|
|
29
|
+
skill_id: string;
|
|
30
|
+
url: string;
|
|
31
|
+
files: SkillFileSummary[];
|
|
32
|
+
status?: SkillStatus;
|
|
33
|
+
}
|
|
34
|
+
export interface SkillFileReadResult {
|
|
35
|
+
skill_id: string;
|
|
36
|
+
rel_path: string;
|
|
37
|
+
url: string;
|
|
38
|
+
mime_type?: string;
|
|
39
|
+
file_type?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface RegisterSkillResult {
|
|
42
|
+
skill_id: string;
|
|
43
|
+
name: string;
|
|
44
|
+
description?: string;
|
|
45
|
+
version?: string;
|
|
46
|
+
status?: SkillStatus;
|
|
47
|
+
files?: string[];
|
|
48
|
+
}
|
|
49
|
+
export interface DeleteSkillResult {
|
|
50
|
+
skill_id: string;
|
|
51
|
+
deleted: boolean;
|
|
52
|
+
}
|
|
53
|
+
export interface UpdateSkillStatusResult {
|
|
54
|
+
skill_id: string;
|
|
55
|
+
status: SkillStatus;
|
|
56
|
+
}
|
|
57
|
+
export interface SkillListResult {
|
|
58
|
+
total_count?: number;
|
|
59
|
+
total?: number;
|
|
60
|
+
page?: number;
|
|
61
|
+
page_size?: number;
|
|
62
|
+
total_page?: number;
|
|
63
|
+
total_pages?: number;
|
|
64
|
+
has_next?: boolean;
|
|
65
|
+
has_prev?: boolean;
|
|
66
|
+
data: SkillSummary[];
|
|
67
|
+
}
|
|
68
|
+
export interface SkillApiBaseOptions {
|
|
69
|
+
baseUrl: string;
|
|
70
|
+
accessToken: string;
|
|
71
|
+
businessDomain?: string;
|
|
72
|
+
}
|
|
73
|
+
export interface ListSkillsOptions extends SkillApiBaseOptions {
|
|
74
|
+
page?: number;
|
|
75
|
+
pageSize?: number;
|
|
76
|
+
sortBy?: "create_time" | "update_time" | "name";
|
|
77
|
+
sortOrder?: "asc" | "desc";
|
|
78
|
+
all?: boolean;
|
|
79
|
+
name?: string;
|
|
80
|
+
status?: SkillStatus;
|
|
81
|
+
source?: string;
|
|
82
|
+
createUser?: string;
|
|
83
|
+
}
|
|
84
|
+
export interface ListSkillMarketOptions extends SkillApiBaseOptions {
|
|
85
|
+
page?: number;
|
|
86
|
+
pageSize?: number;
|
|
87
|
+
sortBy?: "create_time" | "update_time" | "name";
|
|
88
|
+
sortOrder?: "asc" | "desc";
|
|
89
|
+
all?: boolean;
|
|
90
|
+
name?: string;
|
|
91
|
+
source?: string;
|
|
92
|
+
}
|
|
93
|
+
export interface GetSkillOptions extends SkillApiBaseOptions {
|
|
94
|
+
skillId: string;
|
|
95
|
+
}
|
|
96
|
+
export interface RegisterSkillContentOptions extends SkillApiBaseOptions {
|
|
97
|
+
content: string;
|
|
98
|
+
source?: string;
|
|
99
|
+
extendInfo?: Record<string, unknown>;
|
|
100
|
+
}
|
|
101
|
+
export interface RegisterSkillZipOptions extends SkillApiBaseOptions {
|
|
102
|
+
filename: string;
|
|
103
|
+
bytes: Uint8Array;
|
|
104
|
+
source?: string;
|
|
105
|
+
extendInfo?: Record<string, unknown>;
|
|
106
|
+
}
|
|
107
|
+
export interface UpdateSkillStatusOptions extends SkillApiBaseOptions {
|
|
108
|
+
skillId: string;
|
|
109
|
+
status: SkillStatus;
|
|
110
|
+
}
|
|
111
|
+
export interface ReadSkillFileOptions extends SkillApiBaseOptions {
|
|
112
|
+
skillId: string;
|
|
113
|
+
relPath: string;
|
|
114
|
+
}
|
|
115
|
+
export interface DownloadSkillOptions extends SkillApiBaseOptions {
|
|
116
|
+
skillId: string;
|
|
117
|
+
}
|
|
118
|
+
export interface DownloadedSkillArchive {
|
|
119
|
+
fileName: string;
|
|
120
|
+
bytes: Uint8Array;
|
|
121
|
+
}
|
|
122
|
+
export interface InstallSkillArchiveOptions {
|
|
123
|
+
bytes: Uint8Array;
|
|
124
|
+
directory: string;
|
|
125
|
+
force?: boolean;
|
|
126
|
+
}
|
|
127
|
+
export declare function listSkills(options: ListSkillsOptions): Promise<SkillListResult>;
|
|
128
|
+
export declare function listSkillMarket(options: ListSkillMarketOptions): Promise<SkillListResult>;
|
|
129
|
+
export declare function getSkill(options: GetSkillOptions): Promise<SkillInfo>;
|
|
130
|
+
export declare function deleteSkill(options: GetSkillOptions): Promise<DeleteSkillResult>;
|
|
131
|
+
export declare function updateSkillStatus(options: UpdateSkillStatusOptions): Promise<UpdateSkillStatusResult>;
|
|
132
|
+
export declare function registerSkillContent(options: RegisterSkillContentOptions): Promise<RegisterSkillResult>;
|
|
133
|
+
export declare function registerSkillZip(options: RegisterSkillZipOptions): Promise<RegisterSkillResult>;
|
|
134
|
+
export declare function getSkillContentIndex(options: GetSkillOptions): Promise<SkillContentIndex>;
|
|
135
|
+
export declare function fetchSkillContent(options: GetSkillOptions): Promise<string>;
|
|
136
|
+
export declare function readSkillFile(options: ReadSkillFileOptions): Promise<SkillFileReadResult>;
|
|
137
|
+
export declare function fetchSkillFile(options: ReadSkillFileOptions): Promise<Uint8Array>;
|
|
138
|
+
export declare function downloadSkill(options: DownloadSkillOptions): Promise<DownloadedSkillArchive>;
|
|
139
|
+
export declare function installSkillArchive(options: InstallSkillArchiveOptions): {
|
|
140
|
+
directory: string;
|
|
141
|
+
};
|