@kweaver-ai/kweaver-sdk 0.5.1 → 0.6.0
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 +25 -2
- package/README.zh.md +24 -1
- package/dist/api/agent-chat.d.ts +8 -2
- package/dist/api/agent-chat.js +150 -44
- package/dist/api/agent-list.d.ts +35 -0
- package/dist/api/agent-list.js +95 -21
- package/dist/api/bkn-backend.d.ts +60 -0
- package/dist/api/bkn-backend.js +103 -10
- package/dist/api/business-domains.js +9 -5
- package/dist/api/context-loader.js +4 -1
- package/dist/api/conversations.d.ts +6 -3
- package/dist/api/conversations.js +29 -35
- package/dist/api/dataflow.js +1 -10
- package/dist/api/dataflow2.d.ts +95 -0
- package/dist/api/dataflow2.js +80 -0
- package/dist/api/datasources.js +1 -10
- package/dist/api/dataviews.js +1 -10
- package/dist/api/headers.d.ts +11 -0
- package/dist/api/headers.js +30 -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 +208 -0
- package/dist/api/vega.d.ts +54 -7
- package/dist/api/vega.js +112 -25
- package/dist/auth/oauth.d.ts +5 -1
- package/dist/auth/oauth.js +351 -95
- package/dist/cli.js +49 -5
- package/dist/client.d.ts +12 -0
- package/dist/client.js +52 -8
- package/dist/commands/agent.d.ts +33 -1
- package/dist/commands/agent.js +721 -49
- package/dist/commands/auth.js +226 -55
- 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 +1483 -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/call.js +8 -5
- package/dist/commands/dataflow.d.ts +1 -0
- package/dist/commands/dataflow.js +251 -0
- 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/explore-bkn.d.ts +79 -0
- package/dist/commands/explore-bkn.js +273 -0
- package/dist/commands/explore-chat.d.ts +3 -0
- package/dist/commands/explore-chat.js +193 -0
- package/dist/commands/explore-vega.d.ts +3 -0
- package/dist/commands/explore-vega.js +71 -0
- package/dist/commands/explore.d.ts +9 -0
- package/dist/commands/explore.js +258 -0
- 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 +372 -117
- package/dist/config/jwt.d.ts +6 -0
- package/dist/config/jwt.js +21 -0
- package/dist/config/no-auth.d.ts +3 -0
- package/dist/config/no-auth.js +5 -0
- package/dist/config/store.d.ts +45 -5
- package/dist/config/store.js +385 -30
- package/dist/index.d.ts +6 -1
- package/dist/index.js +5 -1
- package/dist/kweaver.d.ts +5 -0
- package/dist/kweaver.js +32 -2
- package/dist/resources/bkn.d.ts +4 -0
- package/dist/resources/bkn.js +6 -3
- package/dist/resources/conversations.d.ts +5 -2
- package/dist/resources/conversations.js +17 -3
- package/dist/resources/knowledge-networks.js +3 -8
- package/dist/resources/skills.d.ts +47 -0
- package/dist/resources/skills.js +47 -0
- package/dist/resources/vega.d.ts +11 -6
- package/dist/resources/vega.js +37 -10
- package/dist/templates/explorer/app.js +136 -0
- package/dist/templates/explorer/bkn.js +747 -0
- package/dist/templates/explorer/chat.js +980 -0
- package/dist/templates/explorer/dashboard.js +82 -0
- package/dist/templates/explorer/index.html +35 -0
- package/dist/templates/explorer/style.css +2440 -0
- package/dist/templates/explorer/vega.js +291 -0
- package/dist/utils/http.d.ts +3 -0
- package/dist/utils/http.js +37 -1
- package/package.json +9 -5
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { HttpError } from "../utils/http.js";
|
|
2
|
+
import { buildHeaders } from "./headers.js";
|
|
3
|
+
async function parseJsonOrThrow(response) {
|
|
4
|
+
const body = await response.text();
|
|
5
|
+
if (!response.ok) {
|
|
6
|
+
throw new HttpError(response.status, response.statusText, body);
|
|
7
|
+
}
|
|
8
|
+
return JSON.parse(body);
|
|
9
|
+
}
|
|
10
|
+
export async function listDataflows(options) {
|
|
11
|
+
const { baseUrl, accessToken, businessDomain = "bd_public" } = options;
|
|
12
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
13
|
+
const url = `${base}/api/automation/v2/dags?type=data-flow&page=0&limit=-1`;
|
|
14
|
+
const response = await fetch(url, {
|
|
15
|
+
method: "GET",
|
|
16
|
+
headers: buildHeaders(accessToken, businessDomain),
|
|
17
|
+
});
|
|
18
|
+
return parseJsonOrThrow(response);
|
|
19
|
+
}
|
|
20
|
+
export async function runDataflowWithFile(options) {
|
|
21
|
+
const { baseUrl, accessToken, businessDomain = "bd_public", dagId, fileName, fileBytes } = options;
|
|
22
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
23
|
+
const url = `${base}/api/automation/v2/dataflow-doc/trigger/${encodeURIComponent(dagId)}`;
|
|
24
|
+
const form = new FormData();
|
|
25
|
+
form.set("file", new Blob([fileBytes]), fileName);
|
|
26
|
+
const response = await fetch(url, {
|
|
27
|
+
method: "POST",
|
|
28
|
+
headers: buildHeaders(accessToken, businessDomain),
|
|
29
|
+
body: form,
|
|
30
|
+
});
|
|
31
|
+
return parseJsonOrThrow(response);
|
|
32
|
+
}
|
|
33
|
+
export async function runDataflowWithRemoteUrl(options) {
|
|
34
|
+
const { baseUrl, accessToken, businessDomain = "bd_public", dagId, url, name } = options;
|
|
35
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
36
|
+
const endpoint = `${base}/api/automation/v2/dataflow-doc/trigger/${encodeURIComponent(dagId)}`;
|
|
37
|
+
const response = await fetch(endpoint, {
|
|
38
|
+
method: "POST",
|
|
39
|
+
headers: {
|
|
40
|
+
...buildHeaders(accessToken, businessDomain),
|
|
41
|
+
"content-type": "application/json",
|
|
42
|
+
},
|
|
43
|
+
body: JSON.stringify({
|
|
44
|
+
source_from: "remote",
|
|
45
|
+
url,
|
|
46
|
+
name,
|
|
47
|
+
}),
|
|
48
|
+
});
|
|
49
|
+
return parseJsonOrThrow(response);
|
|
50
|
+
}
|
|
51
|
+
export async function listDataflowRuns(options) {
|
|
52
|
+
const { baseUrl, accessToken, businessDomain = "bd_public", dagId, page = 0, limit = 100, sortBy, order, startTime, endTime, } = options;
|
|
53
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
54
|
+
const url = new URL(`${base}/api/automation/v2/dag/${encodeURIComponent(dagId)}/results`);
|
|
55
|
+
url.searchParams.set("page", String(page));
|
|
56
|
+
url.searchParams.set("limit", String(limit));
|
|
57
|
+
if (sortBy)
|
|
58
|
+
url.searchParams.set("sortBy", sortBy);
|
|
59
|
+
if (order)
|
|
60
|
+
url.searchParams.set("order", order);
|
|
61
|
+
if (startTime != null)
|
|
62
|
+
url.searchParams.set("start_time", String(startTime));
|
|
63
|
+
if (endTime != null)
|
|
64
|
+
url.searchParams.set("end_time", String(endTime));
|
|
65
|
+
const response = await fetch(url.toString(), {
|
|
66
|
+
method: "GET",
|
|
67
|
+
headers: buildHeaders(accessToken, businessDomain),
|
|
68
|
+
});
|
|
69
|
+
return parseJsonOrThrow(response);
|
|
70
|
+
}
|
|
71
|
+
export async function getDataflowLogsPage(options) {
|
|
72
|
+
const { baseUrl, accessToken, businessDomain = "bd_public", dagId, instanceId, page, limit = 10 } = options;
|
|
73
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
74
|
+
const url = `${base}/api/automation/v2/dag/${encodeURIComponent(dagId)}/result/${encodeURIComponent(instanceId)}?page=${page}&limit=${limit}`;
|
|
75
|
+
const response = await fetch(url, {
|
|
76
|
+
method: "GET",
|
|
77
|
+
headers: buildHeaders(accessToken, businessDomain),
|
|
78
|
+
});
|
|
79
|
+
return parseJsonOrThrow(response);
|
|
80
|
+
}
|
package/dist/api/datasources.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { HttpError } from "../utils/http.js";
|
|
2
2
|
import { encryptPassword } from "../utils/crypto.js";
|
|
3
|
+
import { buildHeaders } from "./headers.js";
|
|
3
4
|
const HTTPS_PROTOCOLS = new Set(["maxcompute", "anyshare7", "opensearch"]);
|
|
4
5
|
function connectProtocol(dsType) {
|
|
5
6
|
return HTTPS_PROTOCOLS.has(dsType) ? "https" : "jdbc";
|
|
@@ -18,16 +19,6 @@ function makeBinData(type, host, port, database, account, password, schema) {
|
|
|
18
19
|
}
|
|
19
20
|
return d;
|
|
20
21
|
}
|
|
21
|
-
function buildHeaders(accessToken, businessDomain) {
|
|
22
|
-
return {
|
|
23
|
-
accept: "application/json, text/plain, */*",
|
|
24
|
-
"accept-language": "zh-cn",
|
|
25
|
-
authorization: `Bearer ${accessToken}`,
|
|
26
|
-
token: accessToken,
|
|
27
|
-
"x-business-domain": businessDomain,
|
|
28
|
-
"x-language": "zh-cn",
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
22
|
export async function testDatasource(options) {
|
|
32
23
|
const { baseUrl, accessToken, type, host, port, database, account, password, schema, businessDomain = "bd_public", } = options;
|
|
33
24
|
const base = baseUrl.replace(/\/+$/, "");
|
package/dist/api/dataviews.js
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { HttpError } from "../utils/http.js";
|
|
3
|
-
|
|
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
|
-
}
|
|
3
|
+
import { buildHeaders } from "./headers.js";
|
|
13
4
|
function extractViewId(data) {
|
|
14
5
|
if (Array.isArray(data) && data.length > 0) {
|
|
15
6
|
const item = data[0];
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
* When accessToken is the no-auth sentinel, `authorization` and `token` are omitted.
|
|
10
|
+
*/
|
|
11
|
+
export declare function buildHeaders(accessToken: string, businessDomain: string): Record<string, string>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { isNoAuth } from "../config/no-auth.js";
|
|
2
|
+
/**
|
|
3
|
+
* Shared HTTP header builder for all KWeaver API calls.
|
|
4
|
+
*
|
|
5
|
+
* Supports optional x-account-id / x-account-type headers read from
|
|
6
|
+
* environment variables KWEAVER_ACCOUNT_ID and KWEAVER_ACCOUNT_TYPE.
|
|
7
|
+
* These are required by older platform versions (e.g. dip-poc.aishu.cn)
|
|
8
|
+
* that do not infer account info from the token automatically.
|
|
9
|
+
*
|
|
10
|
+
* When accessToken is the no-auth sentinel, `authorization` and `token` are omitted.
|
|
11
|
+
*/
|
|
12
|
+
export function buildHeaders(accessToken, businessDomain) {
|
|
13
|
+
const headers = {
|
|
14
|
+
accept: "application/json, text/plain, */*",
|
|
15
|
+
"accept-language": "zh-cn",
|
|
16
|
+
"x-business-domain": businessDomain,
|
|
17
|
+
"x-language": "zh-cn",
|
|
18
|
+
};
|
|
19
|
+
if (!isNoAuth(accessToken)) {
|
|
20
|
+
headers.authorization = `Bearer ${accessToken}`;
|
|
21
|
+
headers.token = accessToken;
|
|
22
|
+
}
|
|
23
|
+
const accountId = process.env.KWEAVER_ACCOUNT_ID;
|
|
24
|
+
const accountType = process.env.KWEAVER_ACCOUNT_TYPE;
|
|
25
|
+
if (accountId)
|
|
26
|
+
headers["x-account-id"] = accountId;
|
|
27
|
+
if (accountType)
|
|
28
|
+
headers["x-account-type"] = accountType;
|
|
29
|
+
return headers;
|
|
30
|
+
}
|
|
@@ -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,
|