@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/client.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getCurrentPlatform, loadTokenConfig, } from "./config/store.js";
|
|
2
|
+
import { ensureValidToken } from "./auth/oauth.js";
|
|
2
3
|
import { AgentsResource } from "./resources/agents.js";
|
|
3
4
|
import { ConversationsResource } from "./resources/conversations.js";
|
|
4
5
|
import { ContextLoaderResource } from "./resources/context-loader.js";
|
|
@@ -46,20 +47,37 @@ export class KWeaverClient {
|
|
|
46
47
|
/** Conversation and message history. */
|
|
47
48
|
conversations;
|
|
48
49
|
constructor(opts = {}) {
|
|
49
|
-
const envUrl = process.env.KWEAVER_BASE_URL;
|
|
50
|
-
const envToken = process.env.KWEAVER_TOKEN;
|
|
51
50
|
const envDomain = process.env.KWEAVER_BUSINESS_DOMAIN;
|
|
52
|
-
|
|
53
|
-
let
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
let baseUrl;
|
|
52
|
+
let accessToken;
|
|
53
|
+
if (opts.config) {
|
|
54
|
+
// config: true — read exclusively from ~/.kweaver/, ignore env vars
|
|
56
55
|
const platform = getCurrentPlatform();
|
|
57
|
-
if (platform) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
if (!platform) {
|
|
57
|
+
throw new Error("No active platform. Run `kweaver auth login` first.");
|
|
58
|
+
}
|
|
59
|
+
const stored = loadTokenConfig(platform);
|
|
60
|
+
if (!stored?.accessToken) {
|
|
61
|
+
throw new Error(`No token for ${platform}. Run \`kweaver auth login\` first.`);
|
|
62
|
+
}
|
|
63
|
+
baseUrl = opts.baseUrl ?? platform;
|
|
64
|
+
accessToken = opts.accessToken ?? stored.accessToken;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
// Default: explicit > env > saved config
|
|
68
|
+
const envUrl = process.env.KWEAVER_BASE_URL;
|
|
69
|
+
const envToken = process.env.KWEAVER_TOKEN;
|
|
70
|
+
baseUrl = opts.baseUrl ?? envUrl;
|
|
71
|
+
accessToken = opts.accessToken ?? envToken;
|
|
72
|
+
if (!baseUrl || !accessToken) {
|
|
73
|
+
const platform = getCurrentPlatform();
|
|
74
|
+
if (platform) {
|
|
75
|
+
const stored = loadTokenConfig(platform);
|
|
76
|
+
if (!baseUrl)
|
|
77
|
+
baseUrl = platform;
|
|
78
|
+
if (!accessToken && stored)
|
|
79
|
+
accessToken = stored.accessToken;
|
|
80
|
+
}
|
|
63
81
|
}
|
|
64
82
|
}
|
|
65
83
|
if (!baseUrl) {
|
|
@@ -71,13 +89,47 @@ export class KWeaverClient {
|
|
|
71
89
|
"Pass it explicitly, set KWEAVER_TOKEN, or run `kweaver auth login`.");
|
|
72
90
|
}
|
|
73
91
|
this._baseUrl = baseUrl.replace(/\/+$/, "");
|
|
74
|
-
|
|
92
|
+
// Strip "Bearer " prefix if present — callers (env vars, config files) may
|
|
93
|
+
// include it, but API helpers always add their own "Bearer " prefix.
|
|
94
|
+
this._accessToken = accessToken.replace(/^Bearer\s+/i, "");
|
|
75
95
|
this._businessDomain = opts.businessDomain ?? envDomain ?? "bd_public";
|
|
76
96
|
this.knowledgeNetworks = new KnowledgeNetworksResource(this);
|
|
77
97
|
this.agents = new AgentsResource(this);
|
|
78
98
|
this.bkn = new BknResource(this);
|
|
79
99
|
this.conversations = new ConversationsResource(this);
|
|
80
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Async factory that auto-refreshes expired or revoked tokens.
|
|
103
|
+
*
|
|
104
|
+
* Reads credentials from `~/.kweaver/` and refreshes the access token
|
|
105
|
+
* if it has expired or been revoked (using the saved refresh token).
|
|
106
|
+
* If the initial token fails with 401, forces a refresh and retries.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* const client = await KWeaverClient.connect();
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
static async connect(opts = {}) {
|
|
114
|
+
// Try with current token first
|
|
115
|
+
let token = await ensureValidToken();
|
|
116
|
+
const client = new KWeaverClient({
|
|
117
|
+
baseUrl: token.baseUrl,
|
|
118
|
+
accessToken: token.accessToken,
|
|
119
|
+
...opts,
|
|
120
|
+
});
|
|
121
|
+
// Quick probe — if the token was revoked server-side, force refresh
|
|
122
|
+
try {
|
|
123
|
+
const probe = await fetch(`${token.baseUrl.replace(/\/+$/, "")}/api/ontology-manager/v1/knowledge-networks?limit=1`, { headers: { authorization: `Bearer ${token.accessToken}`, token: token.accessToken } });
|
|
124
|
+
if (probe.status === 401) {
|
|
125
|
+
throw new Error("Access token revoked. Run `kweaver auth login` to re-authenticate.");
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
// Network error — return client as-is, let the caller deal with it
|
|
130
|
+
}
|
|
131
|
+
return client;
|
|
132
|
+
}
|
|
81
133
|
/** @internal — used by resource classes to build API call options. */
|
|
82
134
|
base() {
|
|
83
135
|
return {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ensureValidToken, formatHttpError } from "../auth/oauth.js";
|
|
2
2
|
import { fetchAgentInfo, sendChatRequest } from "../api/agent-chat.js";
|
|
3
|
+
import { resolveBusinessDomain } from "../config/store.js";
|
|
3
4
|
function formatCliArg(value) {
|
|
4
5
|
if (/^[A-Za-z0-9_./:=+-]+$/.test(value)) {
|
|
5
6
|
return value;
|
|
@@ -42,7 +43,7 @@ export function parseChatArgs(args) {
|
|
|
42
43
|
let conversationId;
|
|
43
44
|
let stream;
|
|
44
45
|
let verbose = false;
|
|
45
|
-
let businessDomain = "
|
|
46
|
+
let businessDomain = "";
|
|
46
47
|
for (let i = 0; i < args.length; i += 1) {
|
|
47
48
|
const arg = args[i];
|
|
48
49
|
if (arg === "-m" || arg === "--message") {
|
|
@@ -104,6 +105,8 @@ export function parseChatArgs(args) {
|
|
|
104
105
|
if (!agentId) {
|
|
105
106
|
throw new Error("Missing agent_id. Usage: kweaver agent chat <agent_id> [-m \"message\"]");
|
|
106
107
|
}
|
|
108
|
+
if (!businessDomain)
|
|
109
|
+
businessDomain = resolveBusinessDomain();
|
|
107
110
|
return { agentId, version, message, conversationId, stream, verbose, businessDomain };
|
|
108
111
|
}
|
|
109
112
|
export async function runAgentChatCommand(args) {
|
package/dist/commands/agent.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { ensureValidToken, formatHttpError } from "../auth/oauth.js";
|
|
2
|
+
import { HttpError } from "../utils/http.js";
|
|
2
3
|
import { runAgentChatCommand } from "./agent-chat.js";
|
|
3
|
-
import { listAgents, getAgent } from "../api/agent-list.js";
|
|
4
|
+
import { listAgents, getAgent, getAgentByKey, createAgent, updateAgent, deleteAgent, publishAgent, unpublishAgent, } from "../api/agent-list.js";
|
|
4
5
|
import { listConversations, listMessages } from "../api/conversations.js";
|
|
5
6
|
import { formatCallOutput } from "./call.js";
|
|
7
|
+
import { resolveBusinessDomain } from "../config/store.js";
|
|
6
8
|
function readStringField(value, ...keys) {
|
|
7
9
|
for (const key of keys) {
|
|
8
10
|
const candidate = value[key];
|
|
@@ -48,7 +50,7 @@ export function parseAgentListArgs(args) {
|
|
|
48
50
|
let category_id = "";
|
|
49
51
|
let custom_space_id = "";
|
|
50
52
|
let is_to_square = 1;
|
|
51
|
-
let businessDomain = "
|
|
53
|
+
let businessDomain = "";
|
|
52
54
|
let pretty = true;
|
|
53
55
|
let verbose = false;
|
|
54
56
|
for (let i = 0; i < args.length; i += 1) {
|
|
@@ -113,6 +115,8 @@ export function parseAgentListArgs(args) {
|
|
|
113
115
|
}
|
|
114
116
|
throw new Error(`Unsupported agent list argument: ${arg}`);
|
|
115
117
|
}
|
|
118
|
+
if (!businessDomain)
|
|
119
|
+
businessDomain = resolveBusinessDomain();
|
|
116
120
|
return {
|
|
117
121
|
name,
|
|
118
122
|
offset,
|
|
@@ -130,7 +134,7 @@ export function parseAgentSessionsArgs(args) {
|
|
|
130
134
|
if (!agentId || agentId.startsWith("-")) {
|
|
131
135
|
throw new Error("Missing agent_id");
|
|
132
136
|
}
|
|
133
|
-
let businessDomain = "
|
|
137
|
+
let businessDomain = "";
|
|
134
138
|
let limit;
|
|
135
139
|
let pretty = true;
|
|
136
140
|
for (let i = 1; i < args.length; i += 1) {
|
|
@@ -163,6 +167,8 @@ export function parseAgentSessionsArgs(args) {
|
|
|
163
167
|
}
|
|
164
168
|
throw new Error(`Unsupported agent sessions argument: ${arg}`);
|
|
165
169
|
}
|
|
170
|
+
if (!businessDomain)
|
|
171
|
+
businessDomain = resolveBusinessDomain();
|
|
166
172
|
return { agentId, businessDomain, limit, pretty };
|
|
167
173
|
}
|
|
168
174
|
export function parseAgentHistoryArgs(args) {
|
|
@@ -170,7 +176,7 @@ export function parseAgentHistoryArgs(args) {
|
|
|
170
176
|
if (!conversationId || conversationId.startsWith("-")) {
|
|
171
177
|
throw new Error("Missing conversation_id");
|
|
172
178
|
}
|
|
173
|
-
let businessDomain = "
|
|
179
|
+
let businessDomain = "";
|
|
174
180
|
let limit;
|
|
175
181
|
let pretty = true;
|
|
176
182
|
for (let i = 1; i < args.length; i += 1) {
|
|
@@ -203,32 +209,58 @@ export function parseAgentHistoryArgs(args) {
|
|
|
203
209
|
}
|
|
204
210
|
throw new Error(`Unsupported agent history argument: ${arg}`);
|
|
205
211
|
}
|
|
212
|
+
if (!businessDomain)
|
|
213
|
+
businessDomain = resolveBusinessDomain();
|
|
206
214
|
return { conversationId, businessDomain, limit, pretty };
|
|
207
215
|
}
|
|
208
|
-
export function runAgentCommand(args) {
|
|
216
|
+
export async function runAgentCommand(args) {
|
|
209
217
|
const [subcommand, ...rest] = args;
|
|
210
218
|
if (!subcommand || subcommand === "--help" || subcommand === "-h") {
|
|
211
219
|
console.log(`kweaver agent
|
|
212
220
|
|
|
213
221
|
Subcommands:
|
|
222
|
+
list [options] List published agents
|
|
223
|
+
get <agent_id> [--verbose] Get agent details
|
|
224
|
+
get-by-key <key> Get agent by key
|
|
225
|
+
create --name <n> --profile <p> Create a new agent
|
|
226
|
+
[--key <key>] [--product-key <pk>] [--system-prompt <sp>]
|
|
227
|
+
[--llm-id <id>] [--llm-max-tokens <n>]
|
|
228
|
+
update <agent_id> --name <n> ... Update an existing agent
|
|
229
|
+
delete <agent_id> [-y] Delete an agent
|
|
230
|
+
publish <agent_id> Publish an agent
|
|
231
|
+
unpublish <agent_id> Unpublish an agent
|
|
214
232
|
chat <agent_id> Start interactive chat with an agent
|
|
215
233
|
chat <agent_id> -m "message" Send a single message (non-interactive)
|
|
216
|
-
[--conversation-id id] Continue an existing conversation
|
|
217
|
-
[-cid id] Short alias for --conversation-id
|
|
218
|
-
[--session-id id] Alias for --conversation-id
|
|
219
|
-
[-conversation_id id] Compatibility alias for reference examples
|
|
220
|
-
[--version value] Resolve agent key from a specific version (default: v0)
|
|
221
|
-
[--stream] [--no-stream] Enable or disable streaming (default: stream in interactive, no-stream in -m mode)
|
|
222
|
-
[--verbose] Print request details to stderr
|
|
223
|
-
[-bd|--biz-domain value] Override x-business-domain (default: bd_public)
|
|
224
|
-
list [options] List published agents
|
|
225
|
-
get <agent_id> [--verbose] Get agent details
|
|
226
234
|
sessions <agent_id> List all conversations for an agent
|
|
227
|
-
|
|
228
|
-
history <conversation_id> Show message history for a conversation
|
|
229
|
-
[--limit n] [-bd domain] [--pretty]`);
|
|
235
|
+
history <conversation_id> Show message history for a conversation`);
|
|
230
236
|
return Promise.resolve(0);
|
|
231
237
|
}
|
|
238
|
+
const dispatch = async () => {
|
|
239
|
+
if (subcommand === "chat")
|
|
240
|
+
return runAgentChatCommand(rest);
|
|
241
|
+
if (subcommand === "get")
|
|
242
|
+
return runAgentGetCommand(rest);
|
|
243
|
+
if (subcommand === "list")
|
|
244
|
+
return runAgentListCommand(rest);
|
|
245
|
+
if (subcommand === "sessions")
|
|
246
|
+
return runAgentSessionsCommand(rest);
|
|
247
|
+
if (subcommand === "history")
|
|
248
|
+
return runAgentHistoryCommand(rest);
|
|
249
|
+
if (subcommand === "get-by-key")
|
|
250
|
+
return runAgentGetByKeyCommand(rest);
|
|
251
|
+
if (subcommand === "create")
|
|
252
|
+
return runAgentCreateCommand(rest);
|
|
253
|
+
if (subcommand === "update")
|
|
254
|
+
return runAgentUpdateCommand(rest);
|
|
255
|
+
if (subcommand === "delete")
|
|
256
|
+
return runAgentDeleteCommand(rest);
|
|
257
|
+
if (subcommand === "publish")
|
|
258
|
+
return runAgentPublishCommand(rest);
|
|
259
|
+
if (subcommand === "unpublish")
|
|
260
|
+
return runAgentUnpublishCommand(rest);
|
|
261
|
+
return -1;
|
|
262
|
+
};
|
|
263
|
+
// Show subcommand-specific help inline (no retry needed)
|
|
232
264
|
if (subcommand === "chat") {
|
|
233
265
|
if (rest.length === 1 && (rest[0] === "--help" || rest[0] === "-h")) {
|
|
234
266
|
console.log(`kweaver agent chat <agent_id> [-m "message"] [options]
|
|
@@ -266,9 +298,8 @@ Options:
|
|
|
266
298
|
--verbose, -v Show full JSON response
|
|
267
299
|
-bd, --biz-domain <value> Business domain (default: bd_public)
|
|
268
300
|
--pretty Pretty-print JSON output (default)`);
|
|
269
|
-
return
|
|
301
|
+
return 0;
|
|
270
302
|
}
|
|
271
|
-
return runAgentGetCommand(rest);
|
|
272
303
|
}
|
|
273
304
|
if (subcommand === "list") {
|
|
274
305
|
if (rest.length === 1 && (rest[0] === "--help" || rest[0] === "-h")) {
|
|
@@ -286,9 +317,8 @@ Options:
|
|
|
286
317
|
--verbose, -v Show full JSON response
|
|
287
318
|
-bd, --biz-domain <value> Business domain (default: bd_public)
|
|
288
319
|
--pretty Pretty-print JSON output (applies to both modes)`);
|
|
289
|
-
return
|
|
320
|
+
return 0;
|
|
290
321
|
}
|
|
291
|
-
return runAgentListCommand(rest);
|
|
292
322
|
}
|
|
293
323
|
if (subcommand === "sessions") {
|
|
294
324
|
if (rest.length === 1 && (rest[0] === "--help" || rest[0] === "-h")) {
|
|
@@ -300,9 +330,8 @@ Options:
|
|
|
300
330
|
--limit <n> Max conversations to return
|
|
301
331
|
-bd, --biz-domain <value> Business domain (default: bd_public)
|
|
302
332
|
--pretty Pretty-print JSON output (default)`);
|
|
303
|
-
return
|
|
333
|
+
return 0;
|
|
304
334
|
}
|
|
305
|
-
return runAgentSessionsCommand(rest);
|
|
306
335
|
}
|
|
307
336
|
if (subcommand === "history") {
|
|
308
337
|
if (rest.length === 1 && (rest[0] === "--help" || rest[0] === "-h")) {
|
|
@@ -314,19 +343,38 @@ Options:
|
|
|
314
343
|
--limit <n> Max messages to return
|
|
315
344
|
-bd, --biz-domain <value> Business domain (default: bd_public)
|
|
316
345
|
--pretty Pretty-print JSON output (default)`);
|
|
317
|
-
return
|
|
346
|
+
return 0;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
try {
|
|
350
|
+
const code = await dispatch();
|
|
351
|
+
if (code === -1) {
|
|
352
|
+
console.error(`Unknown agent subcommand: ${subcommand}`);
|
|
353
|
+
return 1;
|
|
354
|
+
}
|
|
355
|
+
return code;
|
|
356
|
+
}
|
|
357
|
+
catch (error) {
|
|
358
|
+
if (error instanceof HttpError && error.status === 401) {
|
|
359
|
+
try {
|
|
360
|
+
await ensureValidToken({ forceRefresh: true });
|
|
361
|
+
return await dispatch();
|
|
362
|
+
}
|
|
363
|
+
catch (retryError) {
|
|
364
|
+
console.error(formatHttpError(retryError));
|
|
365
|
+
return 1;
|
|
366
|
+
}
|
|
318
367
|
}
|
|
319
|
-
|
|
368
|
+
console.error(formatHttpError(error));
|
|
369
|
+
return 1;
|
|
320
370
|
}
|
|
321
|
-
console.error(`Unknown agent subcommand: ${subcommand}`);
|
|
322
|
-
return Promise.resolve(1);
|
|
323
371
|
}
|
|
324
372
|
export function parseAgentGetArgs(args) {
|
|
325
373
|
const agentId = args[0];
|
|
326
374
|
if (!agentId || agentId.startsWith("-")) {
|
|
327
375
|
throw new Error("Missing agent_id. Usage: kweaver agent get <agent_id> [options]");
|
|
328
376
|
}
|
|
329
|
-
let businessDomain = "
|
|
377
|
+
let businessDomain = "";
|
|
330
378
|
let pretty = true;
|
|
331
379
|
let verbose = false;
|
|
332
380
|
for (let i = 1; i < args.length; i += 1) {
|
|
@@ -352,6 +400,8 @@ export function parseAgentGetArgs(args) {
|
|
|
352
400
|
}
|
|
353
401
|
throw new Error(`Unsupported agent get argument: ${arg}`);
|
|
354
402
|
}
|
|
403
|
+
if (!businessDomain)
|
|
404
|
+
businessDomain = resolveBusinessDomain();
|
|
355
405
|
return { agentId, businessDomain, pretty, verbose };
|
|
356
406
|
}
|
|
357
407
|
function formatSimpleAgentGet(text, pretty) {
|
|
@@ -530,3 +580,267 @@ Options:
|
|
|
530
580
|
return 1;
|
|
531
581
|
}
|
|
532
582
|
}
|
|
583
|
+
// ── Get by key ───────────────────────────────────────────────────────────────
|
|
584
|
+
async function runAgentGetByKeyCommand(args) {
|
|
585
|
+
const key = args[0];
|
|
586
|
+
if (!key || key.startsWith("-")) {
|
|
587
|
+
console.error("Usage: kweaver agent get-by-key <key>");
|
|
588
|
+
return 1;
|
|
589
|
+
}
|
|
590
|
+
try {
|
|
591
|
+
const token = await ensureValidToken();
|
|
592
|
+
const body = await getAgentByKey({
|
|
593
|
+
baseUrl: token.baseUrl,
|
|
594
|
+
accessToken: token.accessToken,
|
|
595
|
+
key,
|
|
596
|
+
});
|
|
597
|
+
console.log(formatCallOutput(body, true));
|
|
598
|
+
return 0;
|
|
599
|
+
}
|
|
600
|
+
catch (error) {
|
|
601
|
+
console.error(formatHttpError(error));
|
|
602
|
+
return 1;
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
// ── Create ───────────────────────────────────────────────────────────────────
|
|
606
|
+
async function runAgentCreateCommand(args) {
|
|
607
|
+
let name = "";
|
|
608
|
+
let profile = "";
|
|
609
|
+
let key = "";
|
|
610
|
+
let productKey = "DIP";
|
|
611
|
+
let systemPrompt = "";
|
|
612
|
+
let llmId = "";
|
|
613
|
+
let llmMaxTokens = 4096;
|
|
614
|
+
let businessDomain = "";
|
|
615
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
616
|
+
const arg = args[i];
|
|
617
|
+
if (arg === "--help" || arg === "-h") {
|
|
618
|
+
console.log(`kweaver agent create --name <name> --profile <profile> [options]
|
|
619
|
+
|
|
620
|
+
Create a new agent.
|
|
621
|
+
|
|
622
|
+
Required:
|
|
623
|
+
--name <text> Agent name (max 50)
|
|
624
|
+
--profile <text> Agent description (max 500)
|
|
625
|
+
|
|
626
|
+
Optional:
|
|
627
|
+
--key <text> Agent unique key (auto-generated if omitted)
|
|
628
|
+
--product-key <text> Product key: DIP, AnyShare, ChatBI (default: DIP)
|
|
629
|
+
--system-prompt <text> System prompt
|
|
630
|
+
--llm-id <id> LLM model ID (required for public API)
|
|
631
|
+
--llm-max-tokens <n> LLM max tokens (default: 4096)
|
|
632
|
+
-bd, --biz-domain <val> Business domain (default: bd_public)`);
|
|
633
|
+
return 0;
|
|
634
|
+
}
|
|
635
|
+
if (arg === "--name") {
|
|
636
|
+
name = args[++i] ?? "";
|
|
637
|
+
continue;
|
|
638
|
+
}
|
|
639
|
+
if (arg === "--profile") {
|
|
640
|
+
profile = args[++i] ?? "";
|
|
641
|
+
continue;
|
|
642
|
+
}
|
|
643
|
+
if (arg === "--key") {
|
|
644
|
+
key = args[++i] ?? "";
|
|
645
|
+
continue;
|
|
646
|
+
}
|
|
647
|
+
if (arg === "--product-key") {
|
|
648
|
+
productKey = args[++i] ?? "DIP";
|
|
649
|
+
continue;
|
|
650
|
+
}
|
|
651
|
+
if (arg === "--system-prompt") {
|
|
652
|
+
systemPrompt = args[++i] ?? "";
|
|
653
|
+
continue;
|
|
654
|
+
}
|
|
655
|
+
if (arg === "--llm-id") {
|
|
656
|
+
llmId = args[++i] ?? "";
|
|
657
|
+
continue;
|
|
658
|
+
}
|
|
659
|
+
if (arg === "--llm-max-tokens") {
|
|
660
|
+
llmMaxTokens = parseInt(args[++i] ?? "4096", 10);
|
|
661
|
+
continue;
|
|
662
|
+
}
|
|
663
|
+
if (arg === "-bd" || arg === "--biz-domain") {
|
|
664
|
+
businessDomain = args[++i] ?? "bd_public";
|
|
665
|
+
continue;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
if (!businessDomain)
|
|
669
|
+
businessDomain = resolveBusinessDomain();
|
|
670
|
+
if (!name) {
|
|
671
|
+
console.error("--name is required");
|
|
672
|
+
return 1;
|
|
673
|
+
}
|
|
674
|
+
if (!profile) {
|
|
675
|
+
console.error("--profile is required");
|
|
676
|
+
return 1;
|
|
677
|
+
}
|
|
678
|
+
const config = {
|
|
679
|
+
input: { fields: [{ name: "user_input", type: "string", desc: "" }] },
|
|
680
|
+
output: { default_format: "markdown" },
|
|
681
|
+
system_prompt: systemPrompt,
|
|
682
|
+
};
|
|
683
|
+
if (llmId) {
|
|
684
|
+
config.llms = [{ is_default: true, llm_config: { id: llmId, name: llmId, max_tokens: llmMaxTokens } }];
|
|
685
|
+
}
|
|
686
|
+
const payload = {
|
|
687
|
+
name,
|
|
688
|
+
profile,
|
|
689
|
+
avatar_type: 1,
|
|
690
|
+
avatar: "icon-dip-agent-default",
|
|
691
|
+
product_key: productKey,
|
|
692
|
+
config,
|
|
693
|
+
};
|
|
694
|
+
if (key)
|
|
695
|
+
payload.key = key;
|
|
696
|
+
try {
|
|
697
|
+
const token = await ensureValidToken();
|
|
698
|
+
const body = await createAgent({
|
|
699
|
+
baseUrl: token.baseUrl,
|
|
700
|
+
accessToken: token.accessToken,
|
|
701
|
+
businessDomain,
|
|
702
|
+
body: JSON.stringify(payload),
|
|
703
|
+
});
|
|
704
|
+
console.log(body);
|
|
705
|
+
return 0;
|
|
706
|
+
}
|
|
707
|
+
catch (error) {
|
|
708
|
+
console.error(formatHttpError(error));
|
|
709
|
+
return 1;
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
// ── Update ───────────────────────────────────────────────────────────────────
|
|
713
|
+
async function runAgentUpdateCommand(args) {
|
|
714
|
+
const agentId = args[0];
|
|
715
|
+
if (!agentId || agentId.startsWith("-")) {
|
|
716
|
+
console.error("Usage: kweaver agent update <agent_id> [--name <n>] [--profile <p>] [--system-prompt <sp>]");
|
|
717
|
+
return 1;
|
|
718
|
+
}
|
|
719
|
+
try {
|
|
720
|
+
const token = await ensureValidToken();
|
|
721
|
+
const currentRaw = await getAgent({
|
|
722
|
+
baseUrl: token.baseUrl,
|
|
723
|
+
accessToken: token.accessToken,
|
|
724
|
+
agentId,
|
|
725
|
+
});
|
|
726
|
+
const current = JSON.parse(currentRaw);
|
|
727
|
+
for (let i = 1; i < args.length; i += 1) {
|
|
728
|
+
const arg = args[i];
|
|
729
|
+
if (arg === "--name") {
|
|
730
|
+
current.name = args[++i] ?? current.name;
|
|
731
|
+
continue;
|
|
732
|
+
}
|
|
733
|
+
if (arg === "--profile") {
|
|
734
|
+
current.profile = args[++i] ?? current.profile;
|
|
735
|
+
continue;
|
|
736
|
+
}
|
|
737
|
+
if (arg === "--system-prompt") {
|
|
738
|
+
const config = (current.config ?? {});
|
|
739
|
+
config.system_prompt = args[++i] ?? "";
|
|
740
|
+
current.config = config;
|
|
741
|
+
continue;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
const body = await updateAgent({
|
|
745
|
+
baseUrl: token.baseUrl,
|
|
746
|
+
accessToken: token.accessToken,
|
|
747
|
+
agentId,
|
|
748
|
+
body: JSON.stringify({
|
|
749
|
+
name: current.name,
|
|
750
|
+
profile: current.profile,
|
|
751
|
+
avatar_type: current.avatar_type,
|
|
752
|
+
avatar: current.avatar,
|
|
753
|
+
product_key: current.product_key,
|
|
754
|
+
config: current.config,
|
|
755
|
+
}),
|
|
756
|
+
});
|
|
757
|
+
if (body)
|
|
758
|
+
console.log(body);
|
|
759
|
+
else
|
|
760
|
+
console.log("Updated.");
|
|
761
|
+
return 0;
|
|
762
|
+
}
|
|
763
|
+
catch (error) {
|
|
764
|
+
console.error(formatHttpError(error));
|
|
765
|
+
return 1;
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
// ── Delete ───────────────────────────────────────────────────────────────────
|
|
769
|
+
async function runAgentDeleteCommand(args) {
|
|
770
|
+
const agentId = args[0];
|
|
771
|
+
if (!agentId || agentId.startsWith("-")) {
|
|
772
|
+
console.error("Usage: kweaver agent delete <agent_id> [-y]");
|
|
773
|
+
return 1;
|
|
774
|
+
}
|
|
775
|
+
const autoConfirm = args.includes("-y") || args.includes("--yes");
|
|
776
|
+
if (!autoConfirm) {
|
|
777
|
+
process.stdout.write(`Delete agent ${agentId}? [y/N] `);
|
|
778
|
+
const answer = await new Promise((resolve) => {
|
|
779
|
+
process.stdin.setEncoding("utf8");
|
|
780
|
+
process.stdin.once("data", (data) => resolve(String(data).trim().toLowerCase()));
|
|
781
|
+
});
|
|
782
|
+
if (answer !== "y" && answer !== "yes") {
|
|
783
|
+
console.log("Cancelled.");
|
|
784
|
+
return 0;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
try {
|
|
788
|
+
const token = await ensureValidToken();
|
|
789
|
+
await deleteAgent({
|
|
790
|
+
baseUrl: token.baseUrl,
|
|
791
|
+
accessToken: token.accessToken,
|
|
792
|
+
agentId,
|
|
793
|
+
});
|
|
794
|
+
console.log(`Deleted agent ${agentId}.`);
|
|
795
|
+
return 0;
|
|
796
|
+
}
|
|
797
|
+
catch (error) {
|
|
798
|
+
console.error(formatHttpError(error));
|
|
799
|
+
return 1;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
// ── Publish ──────────────────────────────────────────────────────────────────
|
|
803
|
+
async function runAgentPublishCommand(args) {
|
|
804
|
+
const agentId = args[0];
|
|
805
|
+
if (!agentId || agentId.startsWith("-")) {
|
|
806
|
+
console.error("Usage: kweaver agent publish <agent_id>");
|
|
807
|
+
return 1;
|
|
808
|
+
}
|
|
809
|
+
try {
|
|
810
|
+
const token = await ensureValidToken();
|
|
811
|
+
const body = await publishAgent({
|
|
812
|
+
baseUrl: token.baseUrl,
|
|
813
|
+
accessToken: token.accessToken,
|
|
814
|
+
agentId,
|
|
815
|
+
body: JSON.stringify({ agent_id: agentId }),
|
|
816
|
+
});
|
|
817
|
+
console.log(body);
|
|
818
|
+
return 0;
|
|
819
|
+
}
|
|
820
|
+
catch (error) {
|
|
821
|
+
console.error(formatHttpError(error));
|
|
822
|
+
return 1;
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
// ── Unpublish ────────────────────────────────────────────────────────────────
|
|
826
|
+
async function runAgentUnpublishCommand(args) {
|
|
827
|
+
const agentId = args[0];
|
|
828
|
+
if (!agentId || agentId.startsWith("-")) {
|
|
829
|
+
console.error("Usage: kweaver agent unpublish <agent_id>");
|
|
830
|
+
return 1;
|
|
831
|
+
}
|
|
832
|
+
try {
|
|
833
|
+
const token = await ensureValidToken();
|
|
834
|
+
await unpublishAgent({
|
|
835
|
+
baseUrl: token.baseUrl,
|
|
836
|
+
accessToken: token.accessToken,
|
|
837
|
+
agentId,
|
|
838
|
+
});
|
|
839
|
+
console.log(`Unpublished agent ${agentId}.`);
|
|
840
|
+
return 0;
|
|
841
|
+
}
|
|
842
|
+
catch (error) {
|
|
843
|
+
console.error(formatHttpError(error));
|
|
844
|
+
return 1;
|
|
845
|
+
}
|
|
846
|
+
}
|
package/dist/commands/auth.d.ts
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
import type { CallbackSession, ClientConfig, TokenConfig } from "../config/store.js";
|
|
2
|
-
export declare function getClientProvisioningMessage(created: boolean): string;
|
|
3
|
-
export declare function formatAuthStatusSummary(input: {
|
|
4
|
-
client: ClientConfig;
|
|
5
|
-
token: TokenConfig | null;
|
|
6
|
-
callback: CallbackSession | null;
|
|
7
|
-
isCurrent?: boolean;
|
|
8
|
-
}): string[];
|
|
9
1
|
export declare function runAuthCommand(args: string[]): Promise<number>;
|