@kweaver-ai/kweaver-sdk 0.4.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/bin/kweaver.js +9 -0
- package/dist/api/agent-chat.d.ts +69 -0
- package/dist/api/agent-chat.js +379 -0
- package/dist/api/agent-list.d.ts +12 -0
- package/dist/api/agent-list.js +33 -0
- package/dist/api/context-loader.d.ts +115 -0
- package/dist/api/context-loader.js +259 -0
- package/dist/api/conversations.d.ts +24 -0
- package/dist/api/conversations.js +64 -0
- package/dist/api/knowledge-networks.d.ts +57 -0
- package/dist/api/knowledge-networks.js +158 -0
- package/dist/api/ontology-query.d.ts +75 -0
- package/dist/api/ontology-query.js +238 -0
- package/dist/api/semantic-search.d.ts +12 -0
- package/dist/api/semantic-search.js +34 -0
- package/dist/auth/oauth.d.ts +75 -0
- package/dist/auth/oauth.js +417 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +79 -0
- package/dist/client.d.ts +95 -0
- package/dist/client.js +104 -0
- package/dist/commands/agent-chat.d.ts +12 -0
- package/dist/commands/agent-chat.js +193 -0
- package/dist/commands/agent.d.ts +28 -0
- package/dist/commands/agent.js +431 -0
- package/dist/commands/auth.d.ts +9 -0
- package/dist/commands/auth.js +201 -0
- package/dist/commands/bkn.d.ts +70 -0
- package/dist/commands/bkn.js +1371 -0
- package/dist/commands/call.d.ts +14 -0
- package/dist/commands/call.js +151 -0
- package/dist/commands/context-loader.d.ts +1 -0
- package/dist/commands/context-loader.js +383 -0
- package/dist/commands/token.d.ts +2 -0
- package/dist/commands/token.js +24 -0
- package/dist/config/store.d.ts +77 -0
- package/dist/config/store.js +380 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +44 -0
- package/dist/kweaver.d.ts +146 -0
- package/dist/kweaver.js +184 -0
- package/dist/resources/agents.d.ts +37 -0
- package/dist/resources/agents.js +60 -0
- package/dist/resources/bkn.d.ts +45 -0
- package/dist/resources/bkn.js +86 -0
- package/dist/resources/context-loader.d.ts +15 -0
- package/dist/resources/context-loader.js +32 -0
- package/dist/resources/conversations.d.ts +11 -0
- package/dist/resources/conversations.js +17 -0
- package/dist/resources/knowledge-networks.d.ts +65 -0
- package/dist/resources/knowledge-networks.js +167 -0
- package/dist/ui/ChatApp.d.ts +16 -0
- package/dist/ui/ChatApp.js +248 -0
- package/dist/ui/MarkdownBlock.d.ts +5 -0
- package/dist/ui/MarkdownBlock.js +137 -0
- package/dist/ui/display-text.d.ts +1 -0
- package/dist/ui/display-text.js +1 -0
- package/dist/utils/browser.d.ts +1 -0
- package/dist/utils/browser.js +20 -0
- package/dist/utils/display-text.d.ts +3 -0
- package/dist/utils/display-text.js +46 -0
- package/dist/utils/http.d.ts +17 -0
- package/dist/utils/http.js +72 -0
- package/package.json +62 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { HttpError } from "../utils/http.js";
|
|
2
|
+
function buildHeaders(accessToken, businessDomain) {
|
|
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
|
+
}
|
|
12
|
+
export async function objectTypeQuery(options) {
|
|
13
|
+
const { baseUrl, accessToken, knId, otId, body, businessDomain = "bd_public", includeTypeInfo, includeLogicParams, excludeSystemProperties, } = options;
|
|
14
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
15
|
+
const url = new URL(`${base}/api/ontology-query/v1/knowledge-networks/${encodeURIComponent(knId)}/object-types/${encodeURIComponent(otId)}`);
|
|
16
|
+
if (includeTypeInfo !== undefined) {
|
|
17
|
+
url.searchParams.set("include_type_info", String(includeTypeInfo));
|
|
18
|
+
}
|
|
19
|
+
if (includeLogicParams !== undefined) {
|
|
20
|
+
url.searchParams.set("include_logic_params", String(includeLogicParams));
|
|
21
|
+
}
|
|
22
|
+
if (excludeSystemProperties?.length) {
|
|
23
|
+
for (const p of excludeSystemProperties) {
|
|
24
|
+
url.searchParams.append("exclude_system_properties", p);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const headers = {
|
|
28
|
+
...buildHeaders(accessToken, businessDomain),
|
|
29
|
+
"content-type": "application/json",
|
|
30
|
+
"X-HTTP-Method-Override": "GET",
|
|
31
|
+
};
|
|
32
|
+
const response = await fetch(url.toString(), {
|
|
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;
|
|
42
|
+
}
|
|
43
|
+
export async function objectTypeProperties(options) {
|
|
44
|
+
const { baseUrl, accessToken, knId, otId, body, businessDomain = "bd_public", excludeSystemProperties, } = options;
|
|
45
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
46
|
+
const url = new URL(`${base}/api/ontology-query/v1/knowledge-networks/${encodeURIComponent(knId)}/object-types/${encodeURIComponent(otId)}/properties`);
|
|
47
|
+
if (excludeSystemProperties?.length) {
|
|
48
|
+
for (const p of excludeSystemProperties) {
|
|
49
|
+
url.searchParams.append("exclude_system_properties", p);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const headers = {
|
|
53
|
+
...buildHeaders(accessToken, businessDomain),
|
|
54
|
+
"content-type": "application/json",
|
|
55
|
+
"X-HTTP-Method-Override": "GET",
|
|
56
|
+
};
|
|
57
|
+
const response = await fetch(url.toString(), {
|
|
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;
|
|
67
|
+
}
|
|
68
|
+
export async function subgraph(options) {
|
|
69
|
+
const { baseUrl, accessToken, knId, body, businessDomain = "bd_public", includeLogicParams, excludeSystemProperties, queryType, } = options;
|
|
70
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
71
|
+
const url = new URL(`${base}/api/ontology-query/v1/knowledge-networks/${encodeURIComponent(knId)}/subgraph`);
|
|
72
|
+
if (includeLogicParams !== undefined) {
|
|
73
|
+
url.searchParams.set("include_logic_params", String(includeLogicParams));
|
|
74
|
+
}
|
|
75
|
+
if (excludeSystemProperties?.length) {
|
|
76
|
+
for (const p of excludeSystemProperties) {
|
|
77
|
+
url.searchParams.append("exclude_system_properties", p);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (queryType !== undefined && queryType !== "") {
|
|
81
|
+
url.searchParams.set("query_type", queryType);
|
|
82
|
+
}
|
|
83
|
+
const headers = {
|
|
84
|
+
...buildHeaders(accessToken, businessDomain),
|
|
85
|
+
"content-type": "application/json",
|
|
86
|
+
};
|
|
87
|
+
const response = await fetch(url.toString(), {
|
|
88
|
+
method: "POST",
|
|
89
|
+
headers,
|
|
90
|
+
body,
|
|
91
|
+
});
|
|
92
|
+
const responseBody = await response.text();
|
|
93
|
+
if (!response.ok) {
|
|
94
|
+
throw new HttpError(response.status, response.statusText, responseBody);
|
|
95
|
+
}
|
|
96
|
+
return responseBody;
|
|
97
|
+
}
|
|
98
|
+
export async function actionTypeQuery(options) {
|
|
99
|
+
const { baseUrl, accessToken, knId, atId, body, businessDomain = "bd_public", includeTypeInfo, excludeSystemProperties, } = options;
|
|
100
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
101
|
+
const url = new URL(`${base}/api/ontology-query/v1/knowledge-networks/${encodeURIComponent(knId)}/action-types/${encodeURIComponent(atId)}/`);
|
|
102
|
+
if (includeTypeInfo !== undefined) {
|
|
103
|
+
url.searchParams.set("include_type_info", String(includeTypeInfo));
|
|
104
|
+
}
|
|
105
|
+
if (excludeSystemProperties?.length) {
|
|
106
|
+
for (const p of excludeSystemProperties) {
|
|
107
|
+
url.searchParams.append("exclude_system_properties", p);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const headers = {
|
|
111
|
+
...buildHeaders(accessToken, businessDomain),
|
|
112
|
+
"content-type": "application/json",
|
|
113
|
+
"X-HTTP-Method-Override": "GET",
|
|
114
|
+
};
|
|
115
|
+
const response = await fetch(url.toString(), {
|
|
116
|
+
method: "POST",
|
|
117
|
+
headers,
|
|
118
|
+
body,
|
|
119
|
+
});
|
|
120
|
+
const responseBody = await response.text();
|
|
121
|
+
if (!response.ok) {
|
|
122
|
+
throw new HttpError(response.status, response.statusText, responseBody);
|
|
123
|
+
}
|
|
124
|
+
return responseBody;
|
|
125
|
+
}
|
|
126
|
+
export async function actionTypeExecute(options) {
|
|
127
|
+
const { baseUrl, accessToken, knId, atId, body, businessDomain = "bd_public" } = options;
|
|
128
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
129
|
+
const url = `${base}/api/ontology-query/v1/knowledge-networks/${encodeURIComponent(knId)}/action-types/${encodeURIComponent(atId)}/execute`;
|
|
130
|
+
const headers = {
|
|
131
|
+
...buildHeaders(accessToken, businessDomain),
|
|
132
|
+
"content-type": "application/json",
|
|
133
|
+
};
|
|
134
|
+
const response = await fetch(url, {
|
|
135
|
+
method: "POST",
|
|
136
|
+
headers,
|
|
137
|
+
body,
|
|
138
|
+
});
|
|
139
|
+
const responseBody = await response.text();
|
|
140
|
+
if (!response.ok) {
|
|
141
|
+
throw new HttpError(response.status, response.statusText, responseBody);
|
|
142
|
+
}
|
|
143
|
+
return responseBody;
|
|
144
|
+
}
|
|
145
|
+
export async function actionExecutionGet(options) {
|
|
146
|
+
const { baseUrl, accessToken, knId, executionId, businessDomain = "bd_public" } = options;
|
|
147
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
148
|
+
const url = `${base}/api/ontology-query/v1/knowledge-networks/${encodeURIComponent(knId)}/action-executions/${encodeURIComponent(executionId)}`;
|
|
149
|
+
const response = await fetch(url, {
|
|
150
|
+
method: "GET",
|
|
151
|
+
headers: buildHeaders(accessToken, businessDomain),
|
|
152
|
+
});
|
|
153
|
+
const body = await response.text();
|
|
154
|
+
if (!response.ok) {
|
|
155
|
+
throw new HttpError(response.status, response.statusText, body);
|
|
156
|
+
}
|
|
157
|
+
return body;
|
|
158
|
+
}
|
|
159
|
+
export async function actionLogsList(options) {
|
|
160
|
+
const { baseUrl, accessToken, knId, businessDomain = "bd_public", actionTypeId, status, triggerType, startTimeFrom, startTimeTo, limit, needTotal, searchAfter, } = options;
|
|
161
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
162
|
+
const url = new URL(`${base}/api/ontology-query/v1/knowledge-networks/${encodeURIComponent(knId)}/action-logs`);
|
|
163
|
+
if (actionTypeId !== undefined && actionTypeId !== "") {
|
|
164
|
+
url.searchParams.set("action_type_id", actionTypeId);
|
|
165
|
+
}
|
|
166
|
+
if (status !== undefined && status !== "") {
|
|
167
|
+
url.searchParams.set("status", status);
|
|
168
|
+
}
|
|
169
|
+
if (triggerType !== undefined && triggerType !== "") {
|
|
170
|
+
url.searchParams.set("trigger_type", triggerType);
|
|
171
|
+
}
|
|
172
|
+
if (startTimeFrom !== undefined) {
|
|
173
|
+
url.searchParams.set("start_time_from", String(startTimeFrom));
|
|
174
|
+
}
|
|
175
|
+
if (startTimeTo !== undefined) {
|
|
176
|
+
url.searchParams.set("start_time_to", String(startTimeTo));
|
|
177
|
+
}
|
|
178
|
+
if (limit !== undefined) {
|
|
179
|
+
url.searchParams.set("limit", String(limit));
|
|
180
|
+
}
|
|
181
|
+
if (needTotal !== undefined) {
|
|
182
|
+
url.searchParams.set("need_total", String(needTotal));
|
|
183
|
+
}
|
|
184
|
+
if (searchAfter !== undefined && searchAfter !== "") {
|
|
185
|
+
url.searchParams.set("search_after", searchAfter);
|
|
186
|
+
}
|
|
187
|
+
const response = await fetch(url.toString(), {
|
|
188
|
+
method: "GET",
|
|
189
|
+
headers: buildHeaders(accessToken, businessDomain),
|
|
190
|
+
});
|
|
191
|
+
const body = await response.text();
|
|
192
|
+
if (!response.ok) {
|
|
193
|
+
throw new HttpError(response.status, response.statusText, body);
|
|
194
|
+
}
|
|
195
|
+
return body;
|
|
196
|
+
}
|
|
197
|
+
export async function actionLogGet(options) {
|
|
198
|
+
const { baseUrl, accessToken, knId, logId, businessDomain = "bd_public", resultsLimit, resultsOffset, resultsStatus, } = options;
|
|
199
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
200
|
+
const url = new URL(`${base}/api/ontology-query/v1/knowledge-networks/${encodeURIComponent(knId)}/action-logs/${encodeURIComponent(logId)}`);
|
|
201
|
+
if (resultsLimit !== undefined) {
|
|
202
|
+
url.searchParams.set("results_limit", String(resultsLimit));
|
|
203
|
+
}
|
|
204
|
+
if (resultsOffset !== undefined) {
|
|
205
|
+
url.searchParams.set("results_offset", String(resultsOffset));
|
|
206
|
+
}
|
|
207
|
+
if (resultsStatus !== undefined) {
|
|
208
|
+
url.searchParams.set("results_status", resultsStatus);
|
|
209
|
+
}
|
|
210
|
+
const response = await fetch(url.toString(), {
|
|
211
|
+
method: "GET",
|
|
212
|
+
headers: buildHeaders(accessToken, businessDomain),
|
|
213
|
+
});
|
|
214
|
+
const body = await response.text();
|
|
215
|
+
if (!response.ok) {
|
|
216
|
+
throw new HttpError(response.status, response.statusText, body);
|
|
217
|
+
}
|
|
218
|
+
return body;
|
|
219
|
+
}
|
|
220
|
+
export async function actionLogCancel(options) {
|
|
221
|
+
const { baseUrl, accessToken, knId, logId, body = "{}", businessDomain = "bd_public" } = options;
|
|
222
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
223
|
+
const url = `${base}/api/ontology-query/v1/knowledge-networks/${encodeURIComponent(knId)}/action-logs/${encodeURIComponent(logId)}/cancel`;
|
|
224
|
+
const headers = {
|
|
225
|
+
...buildHeaders(accessToken, businessDomain),
|
|
226
|
+
"content-type": "application/json",
|
|
227
|
+
};
|
|
228
|
+
const response = await fetch(url, {
|
|
229
|
+
method: "POST",
|
|
230
|
+
headers,
|
|
231
|
+
body,
|
|
232
|
+
});
|
|
233
|
+
const responseBody = await response.text();
|
|
234
|
+
if (!response.ok) {
|
|
235
|
+
throw new HttpError(response.status, response.statusText, responseBody);
|
|
236
|
+
}
|
|
237
|
+
return responseBody;
|
|
238
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface SemanticSearchOptions {
|
|
2
|
+
baseUrl: string;
|
|
3
|
+
accessToken: string;
|
|
4
|
+
knId: string;
|
|
5
|
+
query: string;
|
|
6
|
+
businessDomain?: string;
|
|
7
|
+
mode?: string;
|
|
8
|
+
rerankAction?: string;
|
|
9
|
+
maxConcepts?: number;
|
|
10
|
+
returnQueryUnderstanding?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare function semanticSearch(options: SemanticSearchOptions): Promise<string>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { HttpError } from "../utils/http.js";
|
|
2
|
+
function buildHeaders(accessToken, businessDomain) {
|
|
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
|
+
}
|
|
13
|
+
export async function semanticSearch(options) {
|
|
14
|
+
const { baseUrl, accessToken, knId, query, businessDomain = "bd_public", mode = "keyword_vector_retrieval", rerankAction = "default", maxConcepts = 10, returnQueryUnderstanding = false, } = options;
|
|
15
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
16
|
+
const url = `${base}/api/agent-retrieval/v1/kn/semantic-search`;
|
|
17
|
+
const response = await fetch(url, {
|
|
18
|
+
method: "POST",
|
|
19
|
+
headers: buildHeaders(accessToken, businessDomain),
|
|
20
|
+
body: JSON.stringify({
|
|
21
|
+
kn_id: knId,
|
|
22
|
+
query,
|
|
23
|
+
mode,
|
|
24
|
+
rerank_action: rerankAction,
|
|
25
|
+
max_concepts: maxConcepts,
|
|
26
|
+
return_query_understanding: returnQueryUnderstanding,
|
|
27
|
+
}),
|
|
28
|
+
});
|
|
29
|
+
const body = await response.text();
|
|
30
|
+
if (!response.ok) {
|
|
31
|
+
throw new HttpError(response.status, response.statusText, body);
|
|
32
|
+
}
|
|
33
|
+
return body;
|
|
34
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { type CallbackSession, type ClientConfig, type TokenConfig } from "../config/store.js";
|
|
2
|
+
interface RegisterClientOptions {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
clientName: string;
|
|
5
|
+
redirectUri: string;
|
|
6
|
+
logoutRedirectUri: string;
|
|
7
|
+
lang?: string;
|
|
8
|
+
product?: string;
|
|
9
|
+
xForwardedPrefix?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function normalizeBaseUrl(value: string): string;
|
|
12
|
+
export declare function getAuthorizationSuccessMessage(): string;
|
|
13
|
+
export declare function registerClient(options: RegisterClientOptions): Promise<ClientConfig>;
|
|
14
|
+
export interface EnsureClientOptions {
|
|
15
|
+
baseUrl: string;
|
|
16
|
+
port: number;
|
|
17
|
+
clientName: string;
|
|
18
|
+
forceRegister: boolean;
|
|
19
|
+
host?: string;
|
|
20
|
+
redirectUriOverride?: string;
|
|
21
|
+
lang?: string;
|
|
22
|
+
product?: string;
|
|
23
|
+
xForwardedPrefix?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface EnsuredClientConfig {
|
|
26
|
+
client: ClientConfig;
|
|
27
|
+
created: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface AuthRedirectConfig {
|
|
30
|
+
redirectUri: string;
|
|
31
|
+
logoutRedirectUri: string;
|
|
32
|
+
listenHost: string;
|
|
33
|
+
listenPort: number;
|
|
34
|
+
callbackPath: string;
|
|
35
|
+
}
|
|
36
|
+
export declare function buildAuthRedirectConfig(options: {
|
|
37
|
+
port: number;
|
|
38
|
+
host?: string;
|
|
39
|
+
redirectUriOverride?: string;
|
|
40
|
+
}): AuthRedirectConfig;
|
|
41
|
+
export declare function ensureClientConfig(options: EnsureClientOptions): Promise<EnsuredClientConfig>;
|
|
42
|
+
export declare function buildAuthorizationUrl(client: ClientConfig, state?: string): string;
|
|
43
|
+
/**
|
|
44
|
+
* Call the platform's end-session endpoint so the server invalidates the session.
|
|
45
|
+
* Best-effort: failures are ignored so local logout still proceeds.
|
|
46
|
+
*/
|
|
47
|
+
export declare function callLogoutEndpoint(client: ClientConfig, token: TokenConfig | null): Promise<void>;
|
|
48
|
+
export declare function refreshAccessToken(client: ClientConfig, refreshToken: string): Promise<TokenConfig>;
|
|
49
|
+
export declare function ensureValidToken(): Promise<TokenConfig>;
|
|
50
|
+
export interface AuthLoginOptions {
|
|
51
|
+
baseUrl: string;
|
|
52
|
+
port: number;
|
|
53
|
+
clientName: string;
|
|
54
|
+
open: boolean;
|
|
55
|
+
forceRegister: boolean;
|
|
56
|
+
host?: string;
|
|
57
|
+
redirectUriOverride?: string;
|
|
58
|
+
lang?: string;
|
|
59
|
+
product?: string;
|
|
60
|
+
xForwardedPrefix?: string;
|
|
61
|
+
}
|
|
62
|
+
export declare function login(options: AuthLoginOptions): Promise<{
|
|
63
|
+
client: ClientConfig;
|
|
64
|
+
token: TokenConfig;
|
|
65
|
+
authorizationUrl: string;
|
|
66
|
+
callback: CallbackSession;
|
|
67
|
+
created: boolean;
|
|
68
|
+
}>;
|
|
69
|
+
export declare function getStoredAuthSummary(baseUrl?: string): {
|
|
70
|
+
client: ClientConfig | null;
|
|
71
|
+
token: TokenConfig | null;
|
|
72
|
+
callback: CallbackSession | null;
|
|
73
|
+
};
|
|
74
|
+
export declare function formatHttpError(error: unknown): string;
|
|
75
|
+
export {};
|