@kweaver-ai/kweaver-sdk 0.4.1 → 0.4.4
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/dist/api/agent-list.d.ts +44 -0
- package/dist/api/agent-list.js +104 -14
- package/dist/api/bkn-backend.d.ts +16 -0
- package/dist/api/bkn-backend.js +46 -0
- package/dist/api/ontology-query.d.ts +1 -1
- package/dist/api/ontology-query.js +1 -0
- package/dist/api/vega.d.ts +110 -0
- package/dist/api/vega.js +254 -0
- package/dist/auth/oauth.d.ts +9 -73
- package/dist/auth/oauth.js +98 -342
- package/dist/cli.js +12 -0
- package/dist/client.d.ts +19 -0
- package/dist/client.js +65 -13
- package/dist/commands/agent-chat.js +4 -1
- package/dist/commands/agent.js +343 -29
- package/dist/commands/auth.d.ts +0 -8
- package/dist/commands/auth.js +59 -80
- package/dist/commands/bkn.d.ts +16 -0
- package/dist/commands/bkn.js +422 -70
- package/dist/commands/call.js +43 -7
- package/dist/commands/config.d.ts +1 -0
- package/dist/commands/config.js +52 -0
- package/dist/commands/context-loader.js +46 -40
- package/dist/commands/ds.js +29 -13
- package/dist/commands/vega.d.ts +1 -0
- package/dist/commands/vega.js +684 -0
- package/dist/config/store.d.ts +12 -25
- package/dist/config/store.js +43 -42
- package/dist/index.d.ts +4 -3
- package/dist/index.js +1 -1
- package/dist/resources/agents.d.ts +83 -9
- package/dist/resources/agents.js +46 -10
- package/dist/resources/knowledge-networks.js +2 -3
- package/package.json +10 -1
package/dist/config/store.d.ts
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
export interface ClientConfig {
|
|
2
|
-
baseUrl: string;
|
|
3
|
-
clientId: string;
|
|
4
|
-
clientSecret: string;
|
|
5
|
-
redirectUri: string;
|
|
6
|
-
logoutRedirectUri: string;
|
|
7
|
-
scope: string;
|
|
8
|
-
lang?: string;
|
|
9
|
-
product?: string;
|
|
10
|
-
xForwardedPrefix?: string;
|
|
11
|
-
}
|
|
12
1
|
export interface TokenConfig {
|
|
13
2
|
baseUrl: string;
|
|
14
3
|
accessToken: string;
|
|
@@ -20,14 +9,6 @@ export interface TokenConfig {
|
|
|
20
9
|
idToken?: string;
|
|
21
10
|
obtainedAt: string;
|
|
22
11
|
}
|
|
23
|
-
export interface CallbackSession {
|
|
24
|
-
baseUrl: string;
|
|
25
|
-
redirectUri: string;
|
|
26
|
-
code: string;
|
|
27
|
-
state: string;
|
|
28
|
-
scope?: string;
|
|
29
|
-
receivedAt: string;
|
|
30
|
-
}
|
|
31
12
|
/** Single context-loader entry (named kn_id). */
|
|
32
13
|
export interface ContextLoaderEntry {
|
|
33
14
|
name: string;
|
|
@@ -51,12 +32,8 @@ export declare function setPlatformAlias(baseUrl: string, alias: string): void;
|
|
|
51
32
|
export declare function deletePlatformAlias(baseUrl: string): void;
|
|
52
33
|
export declare function getPlatformAlias(baseUrl: string): string | null;
|
|
53
34
|
export declare function resolvePlatformIdentifier(value: string): string | null;
|
|
54
|
-
export declare function loadClientConfig(baseUrl?: string): ClientConfig | null;
|
|
55
|
-
export declare function saveClientConfig(config: ClientConfig): void;
|
|
56
35
|
export declare function loadTokenConfig(baseUrl?: string): TokenConfig | null;
|
|
57
36
|
export declare function saveTokenConfig(config: TokenConfig): void;
|
|
58
|
-
export declare function loadCallbackSession(baseUrl?: string): CallbackSession | null;
|
|
59
|
-
export declare function saveCallbackSession(session: CallbackSession): void;
|
|
60
37
|
export declare function loadContextLoaderConfig(baseUrl?: string): ContextLoaderConfig | null;
|
|
61
38
|
export declare function saveContextLoaderConfig(baseUrl: string, config: ContextLoaderConfig): void;
|
|
62
39
|
export interface CurrentContextLoaderKn {
|
|
@@ -69,9 +46,19 @@ export declare function setCurrentContextLoader(baseUrl: string, name: string):
|
|
|
69
46
|
export declare function removeContextLoaderEntry(baseUrl: string, name: string): void;
|
|
70
47
|
export declare function hasPlatform(baseUrl: string): boolean;
|
|
71
48
|
/**
|
|
72
|
-
* Remove token
|
|
73
|
-
* Keeps client config so the same app registration can be reused.
|
|
49
|
+
* Remove token for a platform so the next auth will do a full login.
|
|
74
50
|
*/
|
|
75
51
|
export declare function clearPlatformSession(baseUrl: string): void;
|
|
76
52
|
export declare function deletePlatform(baseUrl: string): void;
|
|
77
53
|
export declare function listPlatforms(): PlatformSummary[];
|
|
54
|
+
/** Per-platform config (not auth — general settings). */
|
|
55
|
+
export interface PlatformConfig {
|
|
56
|
+
businessDomain?: string;
|
|
57
|
+
}
|
|
58
|
+
export declare function loadPlatformBusinessDomain(baseUrl: string): string | null;
|
|
59
|
+
export declare function savePlatformBusinessDomain(baseUrl: string, businessDomain: string): void;
|
|
60
|
+
/**
|
|
61
|
+
* Resolve businessDomain: env var > per-platform config > "bd_public".
|
|
62
|
+
* If baseUrl is omitted, uses the current platform.
|
|
63
|
+
*/
|
|
64
|
+
export declare function resolveBusinessDomain(baseUrl?: string): string;
|
package/dist/config/store.js
CHANGED
|
@@ -175,19 +175,6 @@ export function resolvePlatformIdentifier(value) {
|
|
|
175
175
|
}
|
|
176
176
|
return normalized;
|
|
177
177
|
}
|
|
178
|
-
export function loadClientConfig(baseUrl) {
|
|
179
|
-
ensureStoreReady();
|
|
180
|
-
const targetBaseUrl = baseUrl ?? getCurrentPlatform();
|
|
181
|
-
if (!targetBaseUrl) {
|
|
182
|
-
return null;
|
|
183
|
-
}
|
|
184
|
-
return readJsonFile(getPlatformFile(targetBaseUrl, "client.json"));
|
|
185
|
-
}
|
|
186
|
-
export function saveClientConfig(config) {
|
|
187
|
-
ensureStoreReady();
|
|
188
|
-
ensurePlatformDir(config.baseUrl);
|
|
189
|
-
writeJsonFile(getPlatformFile(config.baseUrl, "client.json"), config);
|
|
190
|
-
}
|
|
191
178
|
export function loadTokenConfig(baseUrl) {
|
|
192
179
|
ensureStoreReady();
|
|
193
180
|
const targetBaseUrl = baseUrl ?? getCurrentPlatform();
|
|
@@ -201,19 +188,6 @@ export function saveTokenConfig(config) {
|
|
|
201
188
|
ensurePlatformDir(config.baseUrl);
|
|
202
189
|
writeJsonFile(getPlatformFile(config.baseUrl, "token.json"), config);
|
|
203
190
|
}
|
|
204
|
-
export function loadCallbackSession(baseUrl) {
|
|
205
|
-
ensureStoreReady();
|
|
206
|
-
const targetBaseUrl = baseUrl ?? getCurrentPlatform();
|
|
207
|
-
if (!targetBaseUrl) {
|
|
208
|
-
return null;
|
|
209
|
-
}
|
|
210
|
-
return readJsonFile(getPlatformFile(targetBaseUrl, "callback.json"));
|
|
211
|
-
}
|
|
212
|
-
export function saveCallbackSession(session) {
|
|
213
|
-
ensureStoreReady();
|
|
214
|
-
ensurePlatformDir(session.baseUrl);
|
|
215
|
-
writeJsonFile(getPlatformFile(session.baseUrl, "callback.json"), session);
|
|
216
|
-
}
|
|
217
191
|
function migrateLegacyContextLoader(raw) {
|
|
218
192
|
const leg = raw;
|
|
219
193
|
if (leg?.knId && !Array.isArray(raw.configs)) {
|
|
@@ -258,8 +232,8 @@ export function getCurrentContextLoaderKn(baseUrl) {
|
|
|
258
232
|
const targetBaseUrl = baseUrl ?? getCurrentPlatform();
|
|
259
233
|
if (!targetBaseUrl)
|
|
260
234
|
return null;
|
|
261
|
-
const
|
|
262
|
-
if (!
|
|
235
|
+
const token = loadTokenConfig(targetBaseUrl);
|
|
236
|
+
if (!token?.baseUrl)
|
|
263
237
|
return null;
|
|
264
238
|
const config = loadContextLoaderConfig(targetBaseUrl);
|
|
265
239
|
if (!config)
|
|
@@ -268,7 +242,7 @@ export function getCurrentContextLoaderKn(baseUrl) {
|
|
|
268
242
|
if (!entry)
|
|
269
243
|
return null;
|
|
270
244
|
return {
|
|
271
|
-
mcpUrl: buildMcpUrl(
|
|
245
|
+
mcpUrl: buildMcpUrl(token.baseUrl),
|
|
272
246
|
knId: entry.knId,
|
|
273
247
|
};
|
|
274
248
|
}
|
|
@@ -320,22 +294,17 @@ export function removeContextLoaderEntry(baseUrl, name) {
|
|
|
320
294
|
}
|
|
321
295
|
export function hasPlatform(baseUrl) {
|
|
322
296
|
ensureStoreReady();
|
|
323
|
-
return existsSync(getPlatformFile(baseUrl, "
|
|
297
|
+
return existsSync(getPlatformFile(baseUrl, "token.json"));
|
|
324
298
|
}
|
|
325
299
|
/**
|
|
326
|
-
* Remove token
|
|
327
|
-
* Keeps client config so the same app registration can be reused.
|
|
300
|
+
* Remove token for a platform so the next auth will do a full login.
|
|
328
301
|
*/
|
|
329
302
|
export function clearPlatformSession(baseUrl) {
|
|
330
303
|
ensureStoreReady();
|
|
331
304
|
const tokenFile = getPlatformFile(baseUrl, "token.json");
|
|
332
|
-
const callbackFile = getPlatformFile(baseUrl, "callback.json");
|
|
333
305
|
if (existsSync(tokenFile)) {
|
|
334
306
|
rmSync(tokenFile, { force: true });
|
|
335
307
|
}
|
|
336
|
-
if (existsSync(callbackFile)) {
|
|
337
|
-
rmSync(callbackFile, { force: true });
|
|
338
|
-
}
|
|
339
308
|
}
|
|
340
309
|
export function deletePlatform(baseUrl) {
|
|
341
310
|
ensureStoreReady();
|
|
@@ -364,17 +333,49 @@ export function listPlatforms() {
|
|
|
364
333
|
if (!statSync(dirPath).isDirectory()) {
|
|
365
334
|
continue;
|
|
366
335
|
}
|
|
367
|
-
const
|
|
368
|
-
if (!
|
|
336
|
+
const token = readJsonFile(join(dirPath, "token.json"));
|
|
337
|
+
if (!token?.baseUrl) {
|
|
369
338
|
continue;
|
|
370
339
|
}
|
|
371
340
|
items.push({
|
|
372
|
-
baseUrl:
|
|
373
|
-
hasToken:
|
|
374
|
-
isCurrent:
|
|
375
|
-
alias: getPlatformAlias(
|
|
341
|
+
baseUrl: token.baseUrl,
|
|
342
|
+
hasToken: true,
|
|
343
|
+
isCurrent: token.baseUrl === currentPlatform,
|
|
344
|
+
alias: getPlatformAlias(token.baseUrl) ?? undefined,
|
|
376
345
|
});
|
|
377
346
|
}
|
|
378
347
|
items.sort((a, b) => a.baseUrl.localeCompare(b.baseUrl));
|
|
379
348
|
return items;
|
|
380
349
|
}
|
|
350
|
+
function loadPlatformConfig(baseUrl) {
|
|
351
|
+
ensureStoreReady();
|
|
352
|
+
return readJsonFile(getPlatformFile(baseUrl, "config.json"));
|
|
353
|
+
}
|
|
354
|
+
function savePlatformConfig(baseUrl, config) {
|
|
355
|
+
ensureStoreReady();
|
|
356
|
+
ensurePlatformDir(baseUrl);
|
|
357
|
+
writeJsonFile(getPlatformFile(baseUrl, "config.json"), config);
|
|
358
|
+
}
|
|
359
|
+
export function loadPlatformBusinessDomain(baseUrl) {
|
|
360
|
+
return loadPlatformConfig(baseUrl)?.businessDomain ?? null;
|
|
361
|
+
}
|
|
362
|
+
export function savePlatformBusinessDomain(baseUrl, businessDomain) {
|
|
363
|
+
const existing = loadPlatformConfig(baseUrl) ?? {};
|
|
364
|
+
savePlatformConfig(baseUrl, { ...existing, businessDomain });
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Resolve businessDomain: env var > per-platform config > "bd_public".
|
|
368
|
+
* If baseUrl is omitted, uses the current platform.
|
|
369
|
+
*/
|
|
370
|
+
export function resolveBusinessDomain(baseUrl) {
|
|
371
|
+
const fromEnv = process.env.KWEAVER_BUSINESS_DOMAIN;
|
|
372
|
+
if (fromEnv)
|
|
373
|
+
return fromEnv;
|
|
374
|
+
const targetUrl = baseUrl ?? getCurrentPlatform();
|
|
375
|
+
if (targetUrl) {
|
|
376
|
+
const fromConfig = loadPlatformBusinessDomain(targetUrl);
|
|
377
|
+
if (fromConfig)
|
|
378
|
+
return fromConfig;
|
|
379
|
+
}
|
|
380
|
+
return "bd_public";
|
|
381
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -31,8 +31,8 @@ export type { OntologyQueryBaseOptions, ObjectTypeQueryOptions, ObjectTypeProper
|
|
|
31
31
|
export { objectTypeQuery, objectTypeProperties, subgraph, actionTypeQuery, actionTypeExecute, actionExecutionGet, actionLogsList, actionLogGet, actionLogCancel, } from "./api/ontology-query.js";
|
|
32
32
|
export type { SendChatRequestOptions, SendChatRequestStreamCallbacks, ChatResult, ProgressItem, AgentInfo, } from "./api/agent-chat.js";
|
|
33
33
|
export { sendChatRequest, sendChatRequestStream, fetchAgentInfo, buildChatUrl, buildAgentInfoUrl, extractText, } from "./api/agent-chat.js";
|
|
34
|
-
export type { ListAgentsOptions } from "./api/agent-list.js";
|
|
35
|
-
export { listAgents } from "./api/agent-list.js";
|
|
34
|
+
export type { ListAgentsOptions, GetAgentOptions, GetAgentByKeyOptions, CreateAgentOptions, UpdateAgentOptions, DeleteAgentOptions, PublishAgentOptions, UnpublishAgentOptions, } from "./api/agent-list.js";
|
|
35
|
+
export { listAgents, getAgent, getAgentByKey, createAgent, updateAgent, deleteAgent, publishAgent, unpublishAgent, } from "./api/agent-list.js";
|
|
36
36
|
export type { ListConversationsOptions, ListMessagesOptions } from "./api/conversations.js";
|
|
37
37
|
export { listConversations, listMessages } from "./api/conversations.js";
|
|
38
38
|
export type { SemanticSearchOptions } from "./api/semantic-search.js";
|
|
@@ -45,9 +45,10 @@ export type { KWeaverClientOptions, ClientContext } from "./client.js";
|
|
|
45
45
|
export { KWeaverClient } from "./client.js";
|
|
46
46
|
export { KnowledgeNetworksResource } from "./resources/knowledge-networks.js";
|
|
47
47
|
export { AgentsResource } from "./resources/agents.js";
|
|
48
|
+
export type { AgentConfig, AgentInput, AgentInputField, AgentOutput, AgentLlmConfig, AgentLlmItem, CreateAgentBody, UpdateAgentBody, } from "./resources/agents.js";
|
|
48
49
|
export { BknResource } from "./resources/bkn.js";
|
|
49
50
|
export { ConversationsResource } from "./resources/conversations.js";
|
|
50
51
|
export { ContextLoaderResource } from "./resources/context-loader.js";
|
|
51
52
|
export { HttpError, NetworkRequestError, fetchTextOrThrow } from "./utils/http.js";
|
|
52
|
-
export type {
|
|
53
|
+
export type { TokenConfig, ContextLoaderEntry, ContextLoaderConfig, } from "./config/store.js";
|
|
53
54
|
export { getConfigDir, getCurrentPlatform } from "./config/store.js";
|
package/dist/index.js
CHANGED
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
export { listKnowledgeNetworks, getKnowledgeNetwork, createKnowledgeNetwork, updateKnowledgeNetwork, deleteKnowledgeNetwork, listObjectTypes, listRelationTypes, listActionTypes, } from "./api/knowledge-networks.js";
|
|
29
29
|
export { objectTypeQuery, objectTypeProperties, subgraph, actionTypeQuery, actionTypeExecute, actionExecutionGet, actionLogsList, actionLogGet, actionLogCancel, } from "./api/ontology-query.js";
|
|
30
30
|
export { sendChatRequest, sendChatRequestStream, fetchAgentInfo, buildChatUrl, buildAgentInfoUrl, extractText, } from "./api/agent-chat.js";
|
|
31
|
-
export { listAgents } from "./api/agent-list.js";
|
|
31
|
+
export { listAgents, getAgent, getAgentByKey, createAgent, updateAgent, deleteAgent, publishAgent, unpublishAgent, } from "./api/agent-list.js";
|
|
32
32
|
export { listConversations, listMessages } from "./api/conversations.js";
|
|
33
33
|
export { semanticSearch } from "./api/semantic-search.js";
|
|
34
34
|
export { knSearch, knSchemaSearch, queryObjectInstance, queryInstanceSubgraph, getLogicPropertiesValues, getActionInfo, formatMissingInputParamsHint, validateCondition, validateInstanceIdentity, validateInstanceIdentities, } from "./api/context-loader.js";
|
|
@@ -1,5 +1,76 @@
|
|
|
1
1
|
import type { ChatResult, SendChatRequestStreamCallbacks } from "../api/agent-chat.js";
|
|
2
2
|
import type { ClientContext } from "../client.js";
|
|
3
|
+
export interface AgentLlmConfig {
|
|
4
|
+
id?: string;
|
|
5
|
+
name: string;
|
|
6
|
+
model_type?: string;
|
|
7
|
+
temperature?: number;
|
|
8
|
+
top_p?: number;
|
|
9
|
+
top_k?: number;
|
|
10
|
+
frequency_penalty?: number;
|
|
11
|
+
presence_penalty?: number;
|
|
12
|
+
max_tokens: number;
|
|
13
|
+
}
|
|
14
|
+
export interface AgentLlmItem {
|
|
15
|
+
is_default: boolean;
|
|
16
|
+
llm_config: AgentLlmConfig;
|
|
17
|
+
}
|
|
18
|
+
export interface AgentInputField {
|
|
19
|
+
name: string;
|
|
20
|
+
type?: string;
|
|
21
|
+
desc?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface AgentInput {
|
|
24
|
+
fields: AgentInputField[];
|
|
25
|
+
rewrite?: Record<string, unknown>;
|
|
26
|
+
augment?: Record<string, unknown>;
|
|
27
|
+
}
|
|
28
|
+
export interface AgentOutput {
|
|
29
|
+
variables?: Record<string, unknown>;
|
|
30
|
+
default_format?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface AgentConfig {
|
|
33
|
+
input: AgentInput;
|
|
34
|
+
output: AgentOutput;
|
|
35
|
+
system_prompt?: string;
|
|
36
|
+
dolphin?: string;
|
|
37
|
+
is_dolphin_mode?: number;
|
|
38
|
+
data_source?: Record<string, unknown>;
|
|
39
|
+
skills?: Record<string, unknown>;
|
|
40
|
+
llms?: AgentLlmItem[];
|
|
41
|
+
opening_remark_config?: Record<string, unknown>;
|
|
42
|
+
preset_questions?: Array<{
|
|
43
|
+
question: string;
|
|
44
|
+
}>;
|
|
45
|
+
memory?: {
|
|
46
|
+
is_enabled: boolean;
|
|
47
|
+
};
|
|
48
|
+
related_question?: {
|
|
49
|
+
is_enabled: boolean;
|
|
50
|
+
};
|
|
51
|
+
plan_mode?: {
|
|
52
|
+
is_enabled: boolean;
|
|
53
|
+
};
|
|
54
|
+
conversation_history_config?: Record<string, unknown>;
|
|
55
|
+
[key: string]: unknown;
|
|
56
|
+
}
|
|
57
|
+
export interface CreateAgentBody {
|
|
58
|
+
name: string;
|
|
59
|
+
profile: string;
|
|
60
|
+
avatar_type?: number;
|
|
61
|
+
avatar?: string;
|
|
62
|
+
product_key?: string;
|
|
63
|
+
key?: string;
|
|
64
|
+
config: AgentConfig;
|
|
65
|
+
}
|
|
66
|
+
export interface UpdateAgentBody {
|
|
67
|
+
name: string;
|
|
68
|
+
profile: string;
|
|
69
|
+
avatar_type: number;
|
|
70
|
+
avatar: string;
|
|
71
|
+
product_key: string;
|
|
72
|
+
config: AgentConfig;
|
|
73
|
+
}
|
|
3
74
|
export declare class AgentsResource {
|
|
4
75
|
private readonly ctx;
|
|
5
76
|
constructor(ctx: ClientContext);
|
|
@@ -9,26 +80,29 @@ export declare class AgentsResource {
|
|
|
9
80
|
offset?: number;
|
|
10
81
|
limit?: number;
|
|
11
82
|
}): Promise<unknown[]>;
|
|
12
|
-
|
|
83
|
+
get(agentId: string): Promise<unknown>;
|
|
84
|
+
getByKey(key: string): Promise<unknown>;
|
|
85
|
+
create(body: CreateAgentBody): Promise<{
|
|
86
|
+
id: string;
|
|
87
|
+
version: string;
|
|
88
|
+
}>;
|
|
89
|
+
update(agentId: string, body: UpdateAgentBody): Promise<void>;
|
|
90
|
+
delete(agentId: string): Promise<void>;
|
|
91
|
+
publish(agentId: string, opts?: {
|
|
92
|
+
business_domain_id?: string;
|
|
93
|
+
}): Promise<unknown>;
|
|
94
|
+
unpublish(agentId: string): Promise<void>;
|
|
13
95
|
info(agentId: string, version?: string): Promise<{
|
|
14
96
|
id: string;
|
|
15
97
|
key: string;
|
|
16
98
|
version: string;
|
|
17
99
|
}>;
|
|
18
|
-
/**
|
|
19
|
-
* Send a single message and return the full response.
|
|
20
|
-
* Automatically resolves the agent key/version before sending.
|
|
21
|
-
*/
|
|
22
100
|
chat(agentId: string, message: string, opts?: {
|
|
23
101
|
conversationId?: string;
|
|
24
102
|
version?: string;
|
|
25
103
|
stream?: boolean;
|
|
26
104
|
verbose?: boolean;
|
|
27
105
|
}): Promise<ChatResult>;
|
|
28
|
-
/**
|
|
29
|
-
* Send a message with streaming callbacks.
|
|
30
|
-
* Automatically resolves the agent key/version before sending.
|
|
31
|
-
*/
|
|
32
106
|
stream(agentId: string, message: string, callbacks: SendChatRequestStreamCallbacks, opts?: {
|
|
33
107
|
conversationId?: string;
|
|
34
108
|
version?: string;
|
package/dist/resources/agents.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { listAgents } from "../api/agent-list.js";
|
|
1
|
+
import { listAgents, getAgent, getAgentByKey, createAgent, updateAgent, deleteAgent, publishAgent, unpublishAgent, } from "../api/agent-list.js";
|
|
2
2
|
import { fetchAgentInfo, sendChatRequest, sendChatRequestStream, } from "../api/agent-chat.js";
|
|
3
|
+
// ── AgentsResource ───────────────────────────────────────────────────────────
|
|
3
4
|
export class AgentsResource {
|
|
4
5
|
ctx;
|
|
5
6
|
constructor(ctx) {
|
|
6
7
|
this.ctx = ctx;
|
|
7
8
|
}
|
|
9
|
+
// ── List (published agents) ──────────────────────────────────────────────
|
|
8
10
|
async list(opts = {}) {
|
|
9
11
|
const { keyword, ...rest } = opts;
|
|
10
12
|
const raw = await listAgents({ ...this.ctx.base(), name: keyword, ...rest });
|
|
@@ -16,15 +18,52 @@ export class AgentsResource {
|
|
|
16
18
|
: [];
|
|
17
19
|
return items;
|
|
18
20
|
}
|
|
19
|
-
|
|
21
|
+
// ── Get by ID ────────────────────────────────────────────────────────────
|
|
22
|
+
async get(agentId) {
|
|
23
|
+
const raw = await getAgent({ ...this.ctx.base(), agentId });
|
|
24
|
+
return JSON.parse(raw);
|
|
25
|
+
}
|
|
26
|
+
// ── Get by key ───────────────────────────────────────────────────────────
|
|
27
|
+
async getByKey(key) {
|
|
28
|
+
const raw = await getAgentByKey({ ...this.ctx.base(), key });
|
|
29
|
+
return JSON.parse(raw);
|
|
30
|
+
}
|
|
31
|
+
// ── Create ───────────────────────────────────────────────────────────────
|
|
32
|
+
async create(body) {
|
|
33
|
+
// Apply defaults for required fields the user may omit
|
|
34
|
+
const payload = {
|
|
35
|
+
avatar_type: body.avatar_type ?? 1,
|
|
36
|
+
avatar: body.avatar ?? "icon-dip-agent-default",
|
|
37
|
+
product_key: body.product_key ?? "DIP",
|
|
38
|
+
...body,
|
|
39
|
+
};
|
|
40
|
+
const raw = await createAgent({ ...this.ctx.base(), body: JSON.stringify(payload) });
|
|
41
|
+
return JSON.parse(raw);
|
|
42
|
+
}
|
|
43
|
+
// ── Update ───────────────────────────────────────────────────────────────
|
|
44
|
+
async update(agentId, body) {
|
|
45
|
+
await updateAgent({ ...this.ctx.base(), agentId, body: JSON.stringify(body) });
|
|
46
|
+
}
|
|
47
|
+
// ── Delete ───────────────────────────────────────────────────────────────
|
|
48
|
+
async delete(agentId) {
|
|
49
|
+
await deleteAgent({ ...this.ctx.base(), agentId });
|
|
50
|
+
}
|
|
51
|
+
// ── Publish ──────────────────────────────────────────────────────────────
|
|
52
|
+
async publish(agentId, opts = {}) {
|
|
53
|
+
const body = JSON.stringify({ agent_id: agentId, ...opts });
|
|
54
|
+
const raw = await publishAgent({ ...this.ctx.base(), agentId, body });
|
|
55
|
+
return JSON.parse(raw);
|
|
56
|
+
}
|
|
57
|
+
// ── Unpublish ────────────────────────────────────────────────────────────
|
|
58
|
+
async unpublish(agentId) {
|
|
59
|
+
await unpublishAgent({ ...this.ctx.base(), agentId });
|
|
60
|
+
}
|
|
61
|
+
// ── Agent info (resolve key/version) ─────────────────────────────────────
|
|
20
62
|
async info(agentId, version = "v0") {
|
|
21
63
|
const info = await fetchAgentInfo({ ...this.ctx.base(), agentId, version });
|
|
22
64
|
return info;
|
|
23
65
|
}
|
|
24
|
-
|
|
25
|
-
* Send a single message and return the full response.
|
|
26
|
-
* Automatically resolves the agent key/version before sending.
|
|
27
|
-
*/
|
|
66
|
+
// ── Chat (single-shot) ──────────────────────────────────────────────────
|
|
28
67
|
async chat(agentId, message, opts = {}) {
|
|
29
68
|
const { version = "v0", stream = false, conversationId, verbose } = opts;
|
|
30
69
|
const info = await fetchAgentInfo({ ...this.ctx.base(), agentId, version });
|
|
@@ -39,10 +78,7 @@ export class AgentsResource {
|
|
|
39
78
|
verbose,
|
|
40
79
|
});
|
|
41
80
|
}
|
|
42
|
-
|
|
43
|
-
* Send a message with streaming callbacks.
|
|
44
|
-
* Automatically resolves the agent key/version before sending.
|
|
45
|
-
*/
|
|
81
|
+
// ── Stream ──────────────────────────────────────────────────────────────
|
|
46
82
|
async stream(agentId, message, callbacks, opts = {}) {
|
|
47
83
|
const { version = "v0", conversationId, verbose } = opts;
|
|
48
84
|
const info = await fetchAgentInfo({ ...this.ctx.base(), agentId, version });
|
|
@@ -8,9 +8,8 @@ export class KnowledgeNetworksResource {
|
|
|
8
8
|
async list(opts = {}) {
|
|
9
9
|
const raw = await listKnowledgeNetworks({ ...this.ctx.base(), ...opts });
|
|
10
10
|
const parsed = JSON.parse(raw);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
: parsed;
|
|
11
|
+
// API returns { entries: [...] }
|
|
12
|
+
const data = parsed?.entries ?? parsed?.data ?? parsed;
|
|
14
13
|
return Array.isArray(data) ? data : [];
|
|
15
14
|
}
|
|
16
15
|
async get(knId, opts = {}) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kweaver-ai/kweaver-sdk",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"description": "KWeaver TypeScript SDK — CLI tool and programmatic API for knowledge networks and Decision Agents.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -53,7 +53,16 @@
|
|
|
53
53
|
"tsx": "^4.20.5",
|
|
54
54
|
"typescript": "^5.9.3"
|
|
55
55
|
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"playwright": ">=1.40.0"
|
|
58
|
+
},
|
|
59
|
+
"peerDependenciesMeta": {
|
|
60
|
+
"playwright": {
|
|
61
|
+
"optional": true
|
|
62
|
+
}
|
|
63
|
+
},
|
|
56
64
|
"dependencies": {
|
|
65
|
+
"@kweaver-ai/bkn": "^0.1.0",
|
|
57
66
|
"ink": "^6.8.0",
|
|
58
67
|
"ink-spinner": "^5.0.0",
|
|
59
68
|
"ink-text-input": "^6.0.0",
|