@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.
Files changed (64) hide show
  1. package/bin/kweaver.js +9 -0
  2. package/dist/api/agent-chat.d.ts +69 -0
  3. package/dist/api/agent-chat.js +379 -0
  4. package/dist/api/agent-list.d.ts +12 -0
  5. package/dist/api/agent-list.js +33 -0
  6. package/dist/api/context-loader.d.ts +115 -0
  7. package/dist/api/context-loader.js +259 -0
  8. package/dist/api/conversations.d.ts +24 -0
  9. package/dist/api/conversations.js +64 -0
  10. package/dist/api/knowledge-networks.d.ts +57 -0
  11. package/dist/api/knowledge-networks.js +158 -0
  12. package/dist/api/ontology-query.d.ts +75 -0
  13. package/dist/api/ontology-query.js +238 -0
  14. package/dist/api/semantic-search.d.ts +12 -0
  15. package/dist/api/semantic-search.js +34 -0
  16. package/dist/auth/oauth.d.ts +75 -0
  17. package/dist/auth/oauth.js +417 -0
  18. package/dist/cli.d.ts +1 -0
  19. package/dist/cli.js +79 -0
  20. package/dist/client.d.ts +95 -0
  21. package/dist/client.js +104 -0
  22. package/dist/commands/agent-chat.d.ts +12 -0
  23. package/dist/commands/agent-chat.js +193 -0
  24. package/dist/commands/agent.d.ts +28 -0
  25. package/dist/commands/agent.js +431 -0
  26. package/dist/commands/auth.d.ts +9 -0
  27. package/dist/commands/auth.js +201 -0
  28. package/dist/commands/bkn.d.ts +70 -0
  29. package/dist/commands/bkn.js +1371 -0
  30. package/dist/commands/call.d.ts +14 -0
  31. package/dist/commands/call.js +151 -0
  32. package/dist/commands/context-loader.d.ts +1 -0
  33. package/dist/commands/context-loader.js +383 -0
  34. package/dist/commands/token.d.ts +2 -0
  35. package/dist/commands/token.js +24 -0
  36. package/dist/config/store.d.ts +77 -0
  37. package/dist/config/store.js +380 -0
  38. package/dist/index.d.ts +53 -0
  39. package/dist/index.js +44 -0
  40. package/dist/kweaver.d.ts +146 -0
  41. package/dist/kweaver.js +184 -0
  42. package/dist/resources/agents.d.ts +37 -0
  43. package/dist/resources/agents.js +60 -0
  44. package/dist/resources/bkn.d.ts +45 -0
  45. package/dist/resources/bkn.js +86 -0
  46. package/dist/resources/context-loader.d.ts +15 -0
  47. package/dist/resources/context-loader.js +32 -0
  48. package/dist/resources/conversations.d.ts +11 -0
  49. package/dist/resources/conversations.js +17 -0
  50. package/dist/resources/knowledge-networks.d.ts +65 -0
  51. package/dist/resources/knowledge-networks.js +167 -0
  52. package/dist/ui/ChatApp.d.ts +16 -0
  53. package/dist/ui/ChatApp.js +248 -0
  54. package/dist/ui/MarkdownBlock.d.ts +5 -0
  55. package/dist/ui/MarkdownBlock.js +137 -0
  56. package/dist/ui/display-text.d.ts +1 -0
  57. package/dist/ui/display-text.js +1 -0
  58. package/dist/utils/browser.d.ts +1 -0
  59. package/dist/utils/browser.js +20 -0
  60. package/dist/utils/display-text.d.ts +3 -0
  61. package/dist/utils/display-text.js +46 -0
  62. package/dist/utils/http.d.ts +17 -0
  63. package/dist/utils/http.js +72 -0
  64. package/package.json +62 -0
@@ -0,0 +1,12 @@
1
+ export interface ChatArgs {
2
+ agentId: string;
3
+ version: string;
4
+ message?: string;
5
+ conversationId?: string;
6
+ stream?: boolean;
7
+ verbose: boolean;
8
+ businessDomain: string;
9
+ }
10
+ export declare function buildContinueCommand(args: string[], conversationId: string): string;
11
+ export declare function parseChatArgs(args: string[]): ChatArgs;
12
+ export declare function runAgentChatCommand(args: string[]): Promise<number>;
@@ -0,0 +1,193 @@
1
+ import { ensureValidToken, formatHttpError } from "../auth/oauth.js";
2
+ import { fetchAgentInfo, sendChatRequest } from "../api/agent-chat.js";
3
+ function formatCliArg(value) {
4
+ if (/^[A-Za-z0-9_./:=+-]+$/.test(value)) {
5
+ return value;
6
+ }
7
+ return JSON.stringify(value);
8
+ }
9
+ export function buildContinueCommand(args, conversationId) {
10
+ const filteredArgs = [];
11
+ for (let i = 0; i < args.length; i += 1) {
12
+ const arg = args[i];
13
+ if (arg === "-m" || arg === "--message") {
14
+ filteredArgs.push(arg, "{你的下一轮问题}");
15
+ i += 1;
16
+ continue;
17
+ }
18
+ if (arg === "--conversation-id" ||
19
+ arg === "-cid" ||
20
+ arg === "--conversation_id" ||
21
+ arg === "-conversation-id" ||
22
+ arg === "-conversation_id" ||
23
+ arg === "--session-id") {
24
+ i += 1;
25
+ continue;
26
+ }
27
+ filteredArgs.push(arg);
28
+ }
29
+ return [
30
+ "kweaver",
31
+ "agent",
32
+ "chat",
33
+ ...filteredArgs.map((arg) => formatCliArg(arg)),
34
+ "-cid",
35
+ formatCliArg(conversationId),
36
+ ].join(" ");
37
+ }
38
+ export function parseChatArgs(args) {
39
+ let agentId;
40
+ let version = "v0";
41
+ let message;
42
+ let conversationId;
43
+ let stream;
44
+ let verbose = false;
45
+ let businessDomain = "bd_public";
46
+ for (let i = 0; i < args.length; i += 1) {
47
+ const arg = args[i];
48
+ if (arg === "-m" || arg === "--message") {
49
+ message = args[i + 1];
50
+ if (!message || message.startsWith("-")) {
51
+ throw new Error("Missing value for message flag");
52
+ }
53
+ i += 1;
54
+ continue;
55
+ }
56
+ if (arg === "--version" ||
57
+ arg === "-version") {
58
+ version = args[i + 1] ?? "";
59
+ if (!version || version.startsWith("-")) {
60
+ throw new Error("Missing value for version flag");
61
+ }
62
+ i += 1;
63
+ continue;
64
+ }
65
+ if (arg === "--conversation-id" ||
66
+ arg === "-cid" ||
67
+ arg === "--conversation_id" ||
68
+ arg === "-conversation-id" ||
69
+ arg === "-conversation_id" ||
70
+ arg === "--session-id") {
71
+ conversationId = args[i + 1];
72
+ if (!conversationId || conversationId.startsWith("-")) {
73
+ throw new Error("Missing value for conversation-id flag");
74
+ }
75
+ i += 1;
76
+ continue;
77
+ }
78
+ if (arg === "--stream") {
79
+ stream = true;
80
+ continue;
81
+ }
82
+ if (arg === "--no-stream") {
83
+ stream = false;
84
+ continue;
85
+ }
86
+ if (arg === "--verbose" || arg === "-v") {
87
+ verbose = true;
88
+ continue;
89
+ }
90
+ if (arg === "-bd" || arg === "--biz-domain") {
91
+ businessDomain = args[i + 1] ?? "";
92
+ if (!businessDomain || businessDomain.startsWith("-")) {
93
+ throw new Error("Missing value for biz-domain flag");
94
+ }
95
+ i += 1;
96
+ continue;
97
+ }
98
+ if (!arg.startsWith("-") && !agentId) {
99
+ agentId = arg;
100
+ continue;
101
+ }
102
+ throw new Error(`Unsupported argument: ${arg}`);
103
+ }
104
+ if (!agentId) {
105
+ throw new Error("Missing agent_id. Usage: kweaver agent chat <agent_id> [-m \"message\"]");
106
+ }
107
+ return { agentId, version, message, conversationId, stream, verbose, businessDomain };
108
+ }
109
+ export async function runAgentChatCommand(args) {
110
+ const originalArgs = [...args];
111
+ let chatArgs;
112
+ try {
113
+ chatArgs = parseChatArgs(args);
114
+ }
115
+ catch (error) {
116
+ console.error(formatHttpError(error));
117
+ return 1;
118
+ }
119
+ let token;
120
+ try {
121
+ token = await ensureValidToken();
122
+ }
123
+ catch (error) {
124
+ console.error(formatHttpError(error));
125
+ return 1;
126
+ }
127
+ const isInteractive = chatArgs.message === undefined;
128
+ const stream = chatArgs.stream ?? (isInteractive ? true : false);
129
+ let agentInfo;
130
+ try {
131
+ agentInfo = await fetchAgentInfo({
132
+ baseUrl: token.baseUrl,
133
+ accessToken: token.accessToken,
134
+ agentId: chatArgs.agentId,
135
+ version: chatArgs.version,
136
+ businessDomain: chatArgs.businessDomain,
137
+ });
138
+ }
139
+ catch (error) {
140
+ console.error(formatHttpError(error));
141
+ return 1;
142
+ }
143
+ if (isInteractive) {
144
+ return runTui(chatArgs, agentInfo, token);
145
+ }
146
+ try {
147
+ const result = await sendChatRequest({
148
+ baseUrl: token.baseUrl,
149
+ accessToken: token.accessToken,
150
+ agentId: agentInfo.id,
151
+ agentKey: agentInfo.key,
152
+ agentVersion: agentInfo.version,
153
+ query: chatArgs.message ?? "",
154
+ conversationId: chatArgs.conversationId,
155
+ stream,
156
+ verbose: chatArgs.verbose,
157
+ businessDomain: chatArgs.businessDomain,
158
+ });
159
+ if (result.text && !stream) {
160
+ console.log(result.text);
161
+ }
162
+ if (result.conversationId && chatArgs.message !== undefined) {
163
+ console.error("");
164
+ console.error("To continue this conversation, rerun the command with --conversation-id:");
165
+ console.error(buildContinueCommand(originalArgs, result.conversationId));
166
+ }
167
+ if (result.conversationId && chatArgs.verbose) {
168
+ console.error(`conversation_id: ${result.conversationId}`);
169
+ }
170
+ return 0;
171
+ }
172
+ catch (error) {
173
+ console.error(formatHttpError(error));
174
+ return 1;
175
+ }
176
+ }
177
+ async function runTui(chatArgs, agentInfo, _token) {
178
+ const { createElement } = await import("react");
179
+ const { render } = await import("ink");
180
+ const { ChatApp } = await import("../ui/ChatApp.js");
181
+ const app = render(createElement(ChatApp, {
182
+ getToken: ensureValidToken,
183
+ agentId: agentInfo.id,
184
+ agentKey: agentInfo.key,
185
+ agentVersion: agentInfo.version,
186
+ businessDomain: chatArgs.businessDomain,
187
+ verbose: chatArgs.verbose,
188
+ initialConversationId: chatArgs.conversationId,
189
+ stream: chatArgs.stream ?? true,
190
+ }));
191
+ await app.waitUntilExit();
192
+ return 0;
193
+ }
@@ -0,0 +1,28 @@
1
+ export interface AgentListOptions {
2
+ name: string;
3
+ offset: number;
4
+ limit: number;
5
+ category_id: string;
6
+ custom_space_id: string;
7
+ is_to_square: number;
8
+ businessDomain: string;
9
+ pretty: boolean;
10
+ verbose: boolean;
11
+ }
12
+ export declare function formatSimpleAgentList(text: string, pretty: boolean): string;
13
+ export declare function parseAgentListArgs(args: string[]): AgentListOptions;
14
+ export interface AgentSessionsOptions {
15
+ agentId: string;
16
+ businessDomain: string;
17
+ limit?: number;
18
+ pretty: boolean;
19
+ }
20
+ export declare function parseAgentSessionsArgs(args: string[]): AgentSessionsOptions;
21
+ export interface AgentHistoryOptions {
22
+ conversationId: string;
23
+ businessDomain: string;
24
+ limit?: number;
25
+ pretty: boolean;
26
+ }
27
+ export declare function parseAgentHistoryArgs(args: string[]): AgentHistoryOptions;
28
+ export declare function runAgentCommand(args: string[]): Promise<number>;
@@ -0,0 +1,431 @@
1
+ import { ensureValidToken, formatHttpError } from "../auth/oauth.js";
2
+ import { runAgentChatCommand } from "./agent-chat.js";
3
+ import { listAgents } from "../api/agent-list.js";
4
+ import { listConversations, listMessages } from "../api/conversations.js";
5
+ import { formatCallOutput } from "./call.js";
6
+ function readStringField(value, ...keys) {
7
+ for (const key of keys) {
8
+ const candidate = value[key];
9
+ if (typeof candidate === "string") {
10
+ return candidate;
11
+ }
12
+ }
13
+ return "";
14
+ }
15
+ function extractListEntries(data) {
16
+ if (Array.isArray(data)) {
17
+ return data.filter((entry) => typeof entry === "object" && entry !== null && !Array.isArray(entry));
18
+ }
19
+ if (typeof data !== "object" || data === null) {
20
+ return [];
21
+ }
22
+ const record = data;
23
+ for (const key of ["entries", "items", "list", "records", "data"]) {
24
+ const candidate = record[key];
25
+ if (Array.isArray(candidate)) {
26
+ return candidate.filter((entry) => typeof entry === "object" && entry !== null && !Array.isArray(entry));
27
+ }
28
+ }
29
+ if (typeof record.data === "object" && record.data !== null) {
30
+ return extractListEntries(record.data);
31
+ }
32
+ return [];
33
+ }
34
+ export function formatSimpleAgentList(text, pretty) {
35
+ const parsed = JSON.parse(text);
36
+ const entries = extractListEntries(parsed);
37
+ const simplified = entries.map((entry) => ({
38
+ name: readStringField(entry, "name", "agent_name", "title"),
39
+ id: readStringField(entry, "id", "agent_id", "key"),
40
+ description: readStringField(entry, "description", "comment", "summary", "intro"),
41
+ }));
42
+ return JSON.stringify(simplified, null, pretty ? 2 : 0);
43
+ }
44
+ export function parseAgentListArgs(args) {
45
+ let name = "";
46
+ let offset = 0;
47
+ let limit = 50;
48
+ let category_id = "";
49
+ let custom_space_id = "";
50
+ let is_to_square = 1;
51
+ let businessDomain = "bd_public";
52
+ let pretty = true;
53
+ let verbose = false;
54
+ for (let i = 0; i < args.length; i += 1) {
55
+ const arg = args[i];
56
+ if (arg === "--help" || arg === "-h") {
57
+ throw new Error("help");
58
+ }
59
+ if (arg === "--name") {
60
+ name = args[i + 1] ?? "";
61
+ i += 1;
62
+ continue;
63
+ }
64
+ if (arg === "--offset") {
65
+ offset = parseInt(args[i + 1] ?? "0", 10);
66
+ if (Number.isNaN(offset) || offset < 0)
67
+ offset = 0;
68
+ i += 1;
69
+ continue;
70
+ }
71
+ if (arg === "--limit") {
72
+ limit = parseInt(args[i + 1] ?? "50", 10);
73
+ if (Number.isNaN(limit) || limit < 1)
74
+ limit = 50;
75
+ i += 1;
76
+ continue;
77
+ }
78
+ if (arg === "--category-id") {
79
+ category_id = args[i + 1] ?? "";
80
+ i += 1;
81
+ continue;
82
+ }
83
+ if (arg === "--custom-space-id") {
84
+ custom_space_id = args[i + 1] ?? "";
85
+ i += 1;
86
+ continue;
87
+ }
88
+ if (arg === "--is-to-square") {
89
+ is_to_square = parseInt(args[i + 1] ?? "1", 10);
90
+ if (Number.isNaN(is_to_square))
91
+ is_to_square = 1;
92
+ i += 1;
93
+ continue;
94
+ }
95
+ if (arg === "-bd" || arg === "--biz-domain") {
96
+ businessDomain = args[i + 1] ?? "bd_public";
97
+ if (!businessDomain || businessDomain.startsWith("-")) {
98
+ throw new Error("Missing value for biz-domain flag");
99
+ }
100
+ i += 1;
101
+ continue;
102
+ }
103
+ if (arg === "--pretty") {
104
+ pretty = true;
105
+ continue;
106
+ }
107
+ if (arg === "--verbose" || arg === "-v") {
108
+ verbose = true;
109
+ continue;
110
+ }
111
+ if (arg === "--simple") {
112
+ continue;
113
+ }
114
+ throw new Error(`Unsupported agent list argument: ${arg}`);
115
+ }
116
+ return {
117
+ name,
118
+ offset,
119
+ limit,
120
+ category_id,
121
+ custom_space_id,
122
+ is_to_square,
123
+ businessDomain,
124
+ pretty,
125
+ verbose,
126
+ };
127
+ }
128
+ export function parseAgentSessionsArgs(args) {
129
+ const agentId = args[0];
130
+ if (!agentId || agentId.startsWith("-")) {
131
+ throw new Error("Missing agent_id");
132
+ }
133
+ let businessDomain = "bd_public";
134
+ let limit;
135
+ let pretty = true;
136
+ for (let i = 1; i < args.length; i += 1) {
137
+ const arg = args[i];
138
+ if (arg === "--help" || arg === "-h") {
139
+ throw new Error("help");
140
+ }
141
+ if (arg === "-bd" || arg === "--biz-domain") {
142
+ businessDomain = args[i + 1] ?? "bd_public";
143
+ if (!businessDomain || businessDomain.startsWith("-")) {
144
+ throw new Error("Missing value for biz-domain flag");
145
+ }
146
+ i += 1;
147
+ continue;
148
+ }
149
+ if (arg === "--limit") {
150
+ limit = parseInt(args[i + 1] ?? "0", 10);
151
+ if (Number.isNaN(limit) || limit < 1)
152
+ limit = undefined;
153
+ i += 1;
154
+ continue;
155
+ }
156
+ if (arg === "--pretty") {
157
+ pretty = true;
158
+ continue;
159
+ }
160
+ if (arg === "--compact") {
161
+ pretty = false;
162
+ continue;
163
+ }
164
+ throw new Error(`Unsupported agent sessions argument: ${arg}`);
165
+ }
166
+ return { agentId, businessDomain, limit, pretty };
167
+ }
168
+ export function parseAgentHistoryArgs(args) {
169
+ const conversationId = args[0];
170
+ if (!conversationId || conversationId.startsWith("-")) {
171
+ throw new Error("Missing conversation_id");
172
+ }
173
+ let businessDomain = "bd_public";
174
+ let limit;
175
+ let pretty = true;
176
+ for (let i = 1; i < args.length; i += 1) {
177
+ const arg = args[i];
178
+ if (arg === "--help" || arg === "-h") {
179
+ throw new Error("help");
180
+ }
181
+ if (arg === "-bd" || arg === "--biz-domain") {
182
+ businessDomain = args[i + 1] ?? "bd_public";
183
+ if (!businessDomain || businessDomain.startsWith("-")) {
184
+ throw new Error("Missing value for biz-domain flag");
185
+ }
186
+ i += 1;
187
+ continue;
188
+ }
189
+ if (arg === "--limit") {
190
+ limit = parseInt(args[i + 1] ?? "0", 10);
191
+ if (Number.isNaN(limit) || limit < 1)
192
+ limit = undefined;
193
+ i += 1;
194
+ continue;
195
+ }
196
+ if (arg === "--pretty") {
197
+ pretty = true;
198
+ continue;
199
+ }
200
+ if (arg === "--compact") {
201
+ pretty = false;
202
+ continue;
203
+ }
204
+ throw new Error(`Unsupported agent history argument: ${arg}`);
205
+ }
206
+ return { conversationId, businessDomain, limit, pretty };
207
+ }
208
+ export function runAgentCommand(args) {
209
+ const [subcommand, ...rest] = args;
210
+ if (!subcommand || subcommand === "--help" || subcommand === "-h") {
211
+ console.log(`kweaver agent
212
+
213
+ Subcommands:
214
+ chat <agent_id> Start interactive chat with an agent
215
+ 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
+ sessions <agent_id> List all conversations for an agent
226
+ [--limit n] [-bd domain] [--pretty]
227
+ history <conversation_id> Show message history for a conversation
228
+ [--limit n] [-bd domain] [--pretty]`);
229
+ return Promise.resolve(0);
230
+ }
231
+ if (subcommand === "chat") {
232
+ if (rest.length === 1 && (rest[0] === "--help" || rest[0] === "-h")) {
233
+ console.log(`kweaver agent chat <agent_id> [-m "message"] [options]
234
+
235
+ Interactive mode (default when -m is omitted):
236
+ kweaver agent chat <agent_id>
237
+ Type your message and press Enter. Type 'exit', 'quit', or 'q' to quit.
238
+
239
+ Non-interactive mode:
240
+ kweaver agent chat <agent_id> -m "your message"
241
+ kweaver agent chat <agent_id> -m "continue" --conversation-id <id>
242
+
243
+ Options:
244
+ -m, --message <text> Single message (non-interactive)
245
+ --conversation-id <id> Continue existing conversation
246
+ -cid <id> Short alias for --conversation-id
247
+ --session-id <id> Alias for --conversation-id
248
+ -conversation_id <id> Compatibility alias for reference examples
249
+ --version <value> Agent version used to resolve the agent key (default: v0)
250
+ --stream Enable streaming (default in interactive)
251
+ --no-stream Disable streaming (default with -m)
252
+ --verbose, -v Print request details to stderr
253
+ -bd, --biz-domain <value> Override x-business-domain (default: bd_public)`);
254
+ return Promise.resolve(0);
255
+ }
256
+ return runAgentChatCommand(rest);
257
+ }
258
+ if (subcommand === "list") {
259
+ if (rest.length === 1 && (rest[0] === "--help" || rest[0] === "-h")) {
260
+ console.log(`kweaver agent list [options]
261
+
262
+ List published agents from the agent-factory API.
263
+
264
+ Options:
265
+ --name <text> Filter by name
266
+ --offset <n> Pagination offset (default: 0)
267
+ --limit <n> Max items to return (default: 50)
268
+ --category-id <id> Filter by category
269
+ --custom-space-id <id> Filter by custom space
270
+ --is-to-square <0|1> Is to square (default: 1)
271
+ --verbose, -v Show full JSON response
272
+ -bd, --biz-domain <value> Business domain (default: bd_public)
273
+ --pretty Pretty-print JSON output (applies to both modes)`);
274
+ return Promise.resolve(0);
275
+ }
276
+ return runAgentListCommand(rest);
277
+ }
278
+ if (subcommand === "sessions") {
279
+ if (rest.length === 1 && (rest[0] === "--help" || rest[0] === "-h")) {
280
+ console.log(`kweaver agent sessions <agent_id> [options]
281
+
282
+ List all conversations for an agent.
283
+
284
+ Options:
285
+ --limit <n> Max conversations to return
286
+ -bd, --biz-domain <value> Business domain (default: bd_public)
287
+ --pretty Pretty-print JSON output (default)`);
288
+ return Promise.resolve(0);
289
+ }
290
+ return runAgentSessionsCommand(rest);
291
+ }
292
+ if (subcommand === "history") {
293
+ if (rest.length === 1 && (rest[0] === "--help" || rest[0] === "-h")) {
294
+ console.log(`kweaver agent history <conversation_id> [options]
295
+
296
+ Show message history for a conversation.
297
+
298
+ Options:
299
+ --limit <n> Max messages to return
300
+ -bd, --biz-domain <value> Business domain (default: bd_public)
301
+ --pretty Pretty-print JSON output (default)`);
302
+ return Promise.resolve(0);
303
+ }
304
+ return runAgentHistoryCommand(rest);
305
+ }
306
+ console.error(`Unknown agent subcommand: ${subcommand}`);
307
+ return Promise.resolve(1);
308
+ }
309
+ async function runAgentListCommand(args) {
310
+ let options;
311
+ try {
312
+ options = parseAgentListArgs(args);
313
+ }
314
+ catch (error) {
315
+ if (error instanceof Error && error.message === "help") {
316
+ console.log(`kweaver agent list [options]
317
+
318
+ List published agents from the agent-factory API.
319
+
320
+ Options:
321
+ --name <text> Filter by name
322
+ --offset <n> Pagination offset (default: 0)
323
+ --limit <n> Max items to return (default: 50)
324
+ --category-id <id> Filter by category
325
+ --custom-space-id <id> Filter by custom space
326
+ --is-to-square <0|1> Is to square (default: 1)
327
+ --verbose, -v Show full JSON response
328
+ -bd, --biz-domain <value> Business domain (default: bd_public)
329
+ --pretty Pretty-print JSON output (applies to both modes)`);
330
+ return 0;
331
+ }
332
+ console.error(formatHttpError(error));
333
+ return 1;
334
+ }
335
+ try {
336
+ const token = await ensureValidToken();
337
+ const body = await listAgents({
338
+ baseUrl: token.baseUrl,
339
+ accessToken: token.accessToken,
340
+ businessDomain: options.businessDomain,
341
+ name: options.name,
342
+ offset: options.offset,
343
+ limit: options.limit,
344
+ category_id: options.category_id,
345
+ custom_space_id: options.custom_space_id,
346
+ is_to_square: options.is_to_square,
347
+ });
348
+ if (body) {
349
+ console.log(options.verbose ? formatCallOutput(body, options.pretty) : formatSimpleAgentList(body, options.pretty));
350
+ }
351
+ return 0;
352
+ }
353
+ catch (error) {
354
+ console.error(formatHttpError(error));
355
+ return 1;
356
+ }
357
+ }
358
+ async function runAgentSessionsCommand(args) {
359
+ let options;
360
+ try {
361
+ options = parseAgentSessionsArgs(args);
362
+ }
363
+ catch (error) {
364
+ if (error instanceof Error && error.message === "help") {
365
+ console.log(`kweaver agent sessions <agent_id> [options]
366
+
367
+ List all conversations for an agent.
368
+
369
+ Options:
370
+ --limit <n> Max conversations to return
371
+ -bd, --biz-domain <value> Business domain (default: bd_public)
372
+ --pretty Pretty-print JSON output (default)`);
373
+ return 0;
374
+ }
375
+ console.error(formatHttpError(error));
376
+ return 1;
377
+ }
378
+ try {
379
+ const token = await ensureValidToken();
380
+ const body = await listConversations({
381
+ baseUrl: token.baseUrl,
382
+ accessToken: token.accessToken,
383
+ agentId: options.agentId,
384
+ businessDomain: options.businessDomain,
385
+ limit: options.limit,
386
+ });
387
+ console.log(formatCallOutput(body, options.pretty));
388
+ return 0;
389
+ }
390
+ catch (error) {
391
+ console.error(formatHttpError(error));
392
+ return 1;
393
+ }
394
+ }
395
+ async function runAgentHistoryCommand(args) {
396
+ let options;
397
+ try {
398
+ options = parseAgentHistoryArgs(args);
399
+ }
400
+ catch (error) {
401
+ if (error instanceof Error && error.message === "help") {
402
+ console.log(`kweaver agent history <conversation_id> [options]
403
+
404
+ Show message history for a conversation.
405
+
406
+ Options:
407
+ --limit <n> Max messages to return
408
+ -bd, --biz-domain <value> Business domain (default: bd_public)
409
+ --pretty Pretty-print JSON output (default)`);
410
+ return 0;
411
+ }
412
+ console.error(formatHttpError(error));
413
+ return 1;
414
+ }
415
+ try {
416
+ const token = await ensureValidToken();
417
+ const body = await listMessages({
418
+ baseUrl: token.baseUrl,
419
+ accessToken: token.accessToken,
420
+ conversationId: options.conversationId,
421
+ businessDomain: options.businessDomain,
422
+ limit: options.limit,
423
+ });
424
+ console.log(formatCallOutput(body, options.pretty));
425
+ return 0;
426
+ }
427
+ catch (error) {
428
+ console.error(formatHttpError(error));
429
+ return 1;
430
+ }
431
+ }
@@ -0,0 +1,9 @@
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
+ export declare function runAuthCommand(args: string[]): Promise<number>;