@kweaver-ai/kweaver-sdk 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/README.md +25 -2
  2. package/README.zh.md +24 -1
  3. package/dist/api/agent-chat.d.ts +8 -2
  4. package/dist/api/agent-chat.js +150 -44
  5. package/dist/api/agent-list.d.ts +35 -0
  6. package/dist/api/agent-list.js +95 -21
  7. package/dist/api/bkn-backend.d.ts +60 -0
  8. package/dist/api/bkn-backend.js +103 -10
  9. package/dist/api/business-domains.js +9 -5
  10. package/dist/api/context-loader.js +4 -1
  11. package/dist/api/conversations.d.ts +6 -3
  12. package/dist/api/conversations.js +29 -35
  13. package/dist/api/dataflow.js +1 -10
  14. package/dist/api/dataflow2.d.ts +95 -0
  15. package/dist/api/dataflow2.js +80 -0
  16. package/dist/api/datasources.js +1 -10
  17. package/dist/api/dataviews.js +1 -10
  18. package/dist/api/headers.d.ts +11 -0
  19. package/dist/api/headers.js +30 -0
  20. package/dist/api/knowledge-networks.d.ts +41 -0
  21. package/dist/api/knowledge-networks.js +69 -22
  22. package/dist/api/ontology-query.d.ts +14 -1
  23. package/dist/api/ontology-query.js +63 -49
  24. package/dist/api/semantic-search.js +2 -12
  25. package/dist/api/skills.d.ts +141 -0
  26. package/dist/api/skills.js +208 -0
  27. package/dist/api/vega.d.ts +54 -7
  28. package/dist/api/vega.js +112 -25
  29. package/dist/auth/oauth.d.ts +5 -1
  30. package/dist/auth/oauth.js +351 -95
  31. package/dist/cli.js +49 -5
  32. package/dist/client.d.ts +12 -0
  33. package/dist/client.js +52 -8
  34. package/dist/commands/agent.d.ts +33 -1
  35. package/dist/commands/agent.js +721 -49
  36. package/dist/commands/auth.js +226 -55
  37. package/dist/commands/bkn-ops.d.ts +77 -0
  38. package/dist/commands/bkn-ops.js +1056 -0
  39. package/dist/commands/bkn-query.d.ts +14 -0
  40. package/dist/commands/bkn-query.js +370 -0
  41. package/dist/commands/bkn-schema.d.ts +135 -0
  42. package/dist/commands/bkn-schema.js +1483 -0
  43. package/dist/commands/bkn-utils.d.ts +36 -0
  44. package/dist/commands/bkn-utils.js +102 -0
  45. package/dist/commands/bkn.d.ts +7 -113
  46. package/dist/commands/bkn.js +175 -2429
  47. package/dist/commands/call.js +8 -5
  48. package/dist/commands/dataflow.d.ts +1 -0
  49. package/dist/commands/dataflow.js +251 -0
  50. package/dist/commands/dataview.d.ts +7 -0
  51. package/dist/commands/dataview.js +38 -2
  52. package/dist/commands/ds.d.ts +1 -0
  53. package/dist/commands/ds.js +8 -1
  54. package/dist/commands/explore-bkn.d.ts +79 -0
  55. package/dist/commands/explore-bkn.js +273 -0
  56. package/dist/commands/explore-chat.d.ts +3 -0
  57. package/dist/commands/explore-chat.js +193 -0
  58. package/dist/commands/explore-vega.d.ts +3 -0
  59. package/dist/commands/explore-vega.js +71 -0
  60. package/dist/commands/explore.d.ts +9 -0
  61. package/dist/commands/explore.js +258 -0
  62. package/dist/commands/import-csv.d.ts +2 -0
  63. package/dist/commands/import-csv.js +3 -2
  64. package/dist/commands/skill.d.ts +26 -0
  65. package/dist/commands/skill.js +524 -0
  66. package/dist/commands/vega.js +372 -117
  67. package/dist/config/jwt.d.ts +6 -0
  68. package/dist/config/jwt.js +21 -0
  69. package/dist/config/no-auth.d.ts +3 -0
  70. package/dist/config/no-auth.js +5 -0
  71. package/dist/config/store.d.ts +45 -5
  72. package/dist/config/store.js +385 -30
  73. package/dist/index.d.ts +6 -1
  74. package/dist/index.js +5 -1
  75. package/dist/kweaver.d.ts +5 -0
  76. package/dist/kweaver.js +32 -2
  77. package/dist/resources/bkn.d.ts +4 -0
  78. package/dist/resources/bkn.js +6 -3
  79. package/dist/resources/conversations.d.ts +5 -2
  80. package/dist/resources/conversations.js +17 -3
  81. package/dist/resources/knowledge-networks.js +3 -8
  82. package/dist/resources/skills.d.ts +47 -0
  83. package/dist/resources/skills.js +47 -0
  84. package/dist/resources/vega.d.ts +11 -6
  85. package/dist/resources/vega.js +37 -10
  86. package/dist/templates/explorer/app.js +136 -0
  87. package/dist/templates/explorer/bkn.js +747 -0
  88. package/dist/templates/explorer/chat.js +980 -0
  89. package/dist/templates/explorer/dashboard.js +82 -0
  90. package/dist/templates/explorer/index.html +35 -0
  91. package/dist/templates/explorer/style.css +2440 -0
  92. package/dist/templates/explorer/vega.js +291 -0
  93. package/dist/utils/http.d.ts +3 -0
  94. package/dist/utils/http.js +37 -1
  95. package/package.json +9 -5
@@ -1,15 +1,42 @@
1
1
  import { ensureValidToken, formatHttpError, with401RefreshRetry } from "../auth/oauth.js";
2
2
  import { runAgentChatCommand } from "./agent-chat.js";
3
- import { listAgents, getAgent, getAgentByKey, createAgent, updateAgent, deleteAgent, publishAgent, unpublishAgent, } from "../api/agent-list.js";
3
+ import { listAgents, getAgent, getAgentByKey, createAgent, updateAgent, deleteAgent, publishAgent, unpublishAgent, listPersonalAgents, listPublishedAgentTemplates, getPublishedAgentTemplate, listAgentCategories, } from "../api/agent-list.js";
4
4
  import { listConversations, listMessages, getTracesByConversation } from "../api/conversations.js";
5
+ import { fetchAgentInfo } from "../api/agent-chat.js";
5
6
  import { formatCallOutput } from "./call.js";
6
7
  import { resolveBusinessDomain } from "../config/store.js";
8
+ import { promises as fs } from "fs";
9
+ import { join, dirname, basename, extname } from "path";
10
+ /**
11
+ * 生成带时间戳的文件路径
12
+ * @param path 用户提供的路径
13
+ * @returns 带时间戳的文件路径
14
+ */
15
+ function generateTimestampedPath(path) {
16
+ const timestamp = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
17
+ // 如果路径以 / 结尾,视为目录,在目录下生成文件
18
+ if (path.endsWith("/")) {
19
+ return join(path, `agent-config-${timestamp}.json`);
20
+ }
21
+ // 在文件名中插入时间戳:config.json -> config-2025-01-15T12-30-45.json
22
+ const ext = extname(path);
23
+ const base = basename(path, ext);
24
+ const dir = dirname(path);
25
+ // 如果 dir 是 ".",说明没有目录前缀,直接返回带时间戳的文件名
26
+ if (dir === ".") {
27
+ return `${base}-${timestamp}${ext}`;
28
+ }
29
+ return join(dir, `${base}-${timestamp}${ext}`);
30
+ }
7
31
  function readStringField(value, ...keys) {
8
32
  for (const key of keys) {
9
33
  const candidate = value[key];
10
34
  if (typeof candidate === "string") {
11
35
  return candidate;
12
36
  }
37
+ if (typeof candidate === "number") {
38
+ return String(candidate);
39
+ }
13
40
  }
14
41
  return "";
15
42
  }
@@ -37,11 +64,192 @@ export function formatSimpleAgentList(text, pretty) {
37
64
  const entries = extractListEntries(parsed);
38
65
  const simplified = entries.map((entry) => ({
39
66
  name: readStringField(entry, "name", "agent_name", "title"),
40
- id: readStringField(entry, "id", "agent_id", "key"),
41
- description: readStringField(entry, "description", "comment", "summary", "intro"),
67
+ id: readStringField(entry, "tpl_id", "id", "agent_id", "key"),
68
+ description: readStringField(entry, "description", "comment", "summary", "intro", "profile"),
42
69
  }));
43
70
  return JSON.stringify(simplified, null, pretty ? 2 : 0);
44
71
  }
72
+ export function parseAgentTemplateGetArgs(args) {
73
+ const templateId = args[0];
74
+ if (!templateId || templateId.startsWith("-")) {
75
+ throw new Error("Missing template_id. Usage: kweaver agent template-get <template_id> [options]");
76
+ }
77
+ let businessDomain = "";
78
+ let pretty = true;
79
+ let verbose = false;
80
+ let saveConfig = null;
81
+ for (let i = 1; i < args.length; i += 1) {
82
+ const arg = args[i];
83
+ if (arg === "--help" || arg === "-h") {
84
+ throw new Error("help");
85
+ }
86
+ if (arg === "-bd" || arg === "--biz-domain") {
87
+ businessDomain = args[i + 1] ?? "bd_public";
88
+ if (!businessDomain || businessDomain.startsWith("-")) {
89
+ throw new Error("Missing value for biz-domain flag");
90
+ }
91
+ i += 1;
92
+ continue;
93
+ }
94
+ if (arg === "--pretty") {
95
+ pretty = true;
96
+ continue;
97
+ }
98
+ if (arg === "--verbose" || arg === "-v") {
99
+ verbose = true;
100
+ continue;
101
+ }
102
+ if (arg === "--save-config") {
103
+ saveConfig = args[i + 1] ?? "";
104
+ if (!saveConfig || saveConfig.startsWith("-")) {
105
+ throw new Error("Missing value for save-config flag");
106
+ }
107
+ i += 1;
108
+ continue;
109
+ }
110
+ throw new Error(`Unsupported agent template-get argument: ${arg}`);
111
+ }
112
+ if (!businessDomain)
113
+ businessDomain = resolveBusinessDomain();
114
+ return { templateId, businessDomain, pretty, verbose, saveConfig };
115
+ }
116
+ export function parseAgentTemplateListArgs(args) {
117
+ let category_id = "";
118
+ let name = "";
119
+ let pagination_marker_str = "";
120
+ let size = 48;
121
+ let businessDomain = "";
122
+ let pretty = true;
123
+ let verbose = false;
124
+ for (let i = 0; i < args.length; i += 1) {
125
+ const arg = args[i];
126
+ if (arg === "--help" || arg === "-h") {
127
+ throw new Error("help");
128
+ }
129
+ if (arg === "--category-id") {
130
+ category_id = args[i + 1] ?? "";
131
+ i += 1;
132
+ continue;
133
+ }
134
+ if (arg === "--name") {
135
+ name = args[i + 1] ?? "";
136
+ i += 1;
137
+ continue;
138
+ }
139
+ if (arg === "--pagination-marker") {
140
+ pagination_marker_str = args[i + 1] ?? "";
141
+ i += 1;
142
+ continue;
143
+ }
144
+ if (arg === "--size") {
145
+ size = parseInt(args[i + 1] ?? "48", 10);
146
+ if (Number.isNaN(size) || size < 1)
147
+ size = 48;
148
+ i += 1;
149
+ continue;
150
+ }
151
+ if (arg === "-bd" || arg === "--biz-domain") {
152
+ businessDomain = args[i + 1] ?? "bd_public";
153
+ if (!businessDomain || businessDomain.startsWith("-")) {
154
+ throw new Error("Missing value for biz-domain flag");
155
+ }
156
+ i += 1;
157
+ continue;
158
+ }
159
+ if (arg === "--pretty") {
160
+ pretty = true;
161
+ continue;
162
+ }
163
+ if (arg === "--verbose" || arg === "-v") {
164
+ verbose = true;
165
+ continue;
166
+ }
167
+ throw new Error(`Unsupported agent template-list argument: ${arg}`);
168
+ }
169
+ if (!businessDomain)
170
+ businessDomain = resolveBusinessDomain();
171
+ return {
172
+ category_id,
173
+ name,
174
+ pagination_marker_str,
175
+ size,
176
+ businessDomain,
177
+ pretty,
178
+ verbose,
179
+ };
180
+ }
181
+ export function parseAgentPersonalListArgs(args) {
182
+ let name = "";
183
+ let pagination_marker_str = "";
184
+ let publish_status = "";
185
+ let publish_to_be = "";
186
+ let size = 48;
187
+ let businessDomain = "";
188
+ let pretty = true;
189
+ let verbose = false;
190
+ for (let i = 0; i < args.length; i += 1) {
191
+ const arg = args[i];
192
+ if (arg === "--help" || arg === "-h") {
193
+ throw new Error("help");
194
+ }
195
+ if (arg === "--name") {
196
+ name = args[i + 1] ?? "";
197
+ i += 1;
198
+ continue;
199
+ }
200
+ if (arg === "--pagination-marker") {
201
+ pagination_marker_str = args[i + 1] ?? "";
202
+ i += 1;
203
+ continue;
204
+ }
205
+ if (arg === "--publish-status") {
206
+ publish_status = args[i + 1] ?? "";
207
+ i += 1;
208
+ continue;
209
+ }
210
+ if (arg === "--publish-to-be") {
211
+ publish_to_be = args[i + 1] ?? "";
212
+ i += 1;
213
+ continue;
214
+ }
215
+ if (arg === "--size") {
216
+ size = parseInt(args[i + 1] ?? "48", 10);
217
+ if (Number.isNaN(size) || size < 1)
218
+ size = 48;
219
+ i += 1;
220
+ continue;
221
+ }
222
+ if (arg === "-bd" || arg === "--biz-domain") {
223
+ businessDomain = args[i + 1] ?? "bd_public";
224
+ if (!businessDomain || businessDomain.startsWith("-")) {
225
+ throw new Error("Missing value for biz-domain flag");
226
+ }
227
+ i += 1;
228
+ continue;
229
+ }
230
+ if (arg === "--pretty") {
231
+ pretty = true;
232
+ continue;
233
+ }
234
+ if (arg === "--verbose" || arg === "-v") {
235
+ verbose = true;
236
+ continue;
237
+ }
238
+ throw new Error(`Unsupported agent personal-list argument: ${arg}`);
239
+ }
240
+ if (!businessDomain)
241
+ businessDomain = resolveBusinessDomain();
242
+ return {
243
+ name,
244
+ pagination_marker_str,
245
+ publish_status,
246
+ publish_to_be,
247
+ size,
248
+ businessDomain,
249
+ pretty,
250
+ verbose,
251
+ };
252
+ }
45
253
  export function parseAgentListArgs(args) {
46
254
  let name = "";
47
255
  let offset = 0;
@@ -171,14 +379,20 @@ export function parseAgentSessionsArgs(args) {
171
379
  return { agentId, businessDomain, limit, pretty };
172
380
  }
173
381
  export function parseAgentHistoryArgs(args) {
174
- const conversationId = args[0];
175
- if (!conversationId || conversationId.startsWith("-")) {
382
+ const firstArg = args[0];
383
+ // Check if first arg is a flag (no conversationId provided)
384
+ if (!firstArg || firstArg.startsWith("-")) {
176
385
  throw new Error("Missing conversation_id");
177
386
  }
178
387
  let businessDomain = "";
179
- let limit = 30;
180
388
  let pretty = true;
181
- for (let i = 1; i < args.length; i += 1) {
389
+ let limit = 30;
390
+ // Determine where to start parsing options (after agentId and conversationId, or after just conversationId)
391
+ let optionStartIndex = 1;
392
+ if (args[1] && !args[1].startsWith("-")) {
393
+ optionStartIndex = 2;
394
+ }
395
+ for (let i = optionStartIndex; i < args.length; i += 1) {
182
396
  const arg = args[i];
183
397
  if (arg === "--help" || arg === "-h") {
184
398
  throw new Error("help");
@@ -191,13 +405,6 @@ export function parseAgentHistoryArgs(args) {
191
405
  i += 1;
192
406
  continue;
193
407
  }
194
- if (arg === "--limit") {
195
- limit = parseInt(args[i + 1] ?? "30", 10);
196
- if (Number.isNaN(limit) || limit < 1)
197
- limit = 30;
198
- i += 1;
199
- continue;
200
- }
201
408
  if (arg === "--pretty") {
202
409
  pretty = true;
203
410
  continue;
@@ -206,19 +413,33 @@ export function parseAgentHistoryArgs(args) {
206
413
  pretty = false;
207
414
  continue;
208
415
  }
416
+ if (arg === "--limit") {
417
+ limit = parseInt(args[i + 1] ?? "30", 10);
418
+ if (Number.isNaN(limit) || limit < 1)
419
+ limit = 30;
420
+ i += 1;
421
+ continue;
422
+ }
209
423
  throw new Error(`Unsupported agent history argument: ${arg}`);
210
424
  }
211
425
  if (!businessDomain)
212
426
  businessDomain = resolveBusinessDomain();
213
- return { conversationId, businessDomain, limit, pretty };
427
+ // If we have two non-flag args, treat as agentId and conversationId
428
+ const finalAgentId = optionStartIndex === 2 ? args[0] : undefined;
429
+ const finalConversationId = optionStartIndex === 2 ? args[1] : args[0];
430
+ return { agentId: finalAgentId, conversationId: finalConversationId, businessDomain, pretty, limit };
214
431
  }
215
432
  export function parseAgentTraceArgs(args) {
216
- const conversationId = args[0];
433
+ const agentId = args[0];
434
+ if (!agentId || agentId.startsWith("-")) {
435
+ throw new Error("Missing agent_id");
436
+ }
437
+ const conversationId = args[1];
217
438
  if (!conversationId || conversationId.startsWith("-")) {
218
439
  throw new Error("Missing conversation_id");
219
440
  }
220
441
  let pretty = true;
221
- for (let i = 1; i < args.length; i += 1) {
442
+ for (let i = 2; i < args.length; i += 1) {
222
443
  const arg = args[i];
223
444
  if (arg === "--help" || arg === "-h") {
224
445
  throw new Error("help");
@@ -233,7 +454,7 @@ export function parseAgentTraceArgs(args) {
233
454
  }
234
455
  throw new Error(`Unsupported agent trace argument: ${arg}`);
235
456
  }
236
- return { conversationId, pretty };
457
+ return { agentId, conversationId, pretty };
237
458
  }
238
459
  export async function runAgentCommand(args) {
239
460
  const [subcommand, ...rest] = args;
@@ -242,19 +463,23 @@ export async function runAgentCommand(args) {
242
463
 
243
464
  Subcommands:
244
465
  list [options] List published agents
466
+ personal-list [options] List personal space agents
467
+ category-list [options] List agent categories
468
+ template-list [options] List published agent templates
469
+ template-get <tpl_id> Get published agent template details
245
470
  get <agent_id> [--verbose] Get agent details
246
471
  get-by-key <key> Get agent by key
247
472
  create --name <n> --profile <p> Create a new agent
248
473
  [--key <key>] [--product-key <pk>] [--system-prompt <sp>]
249
474
  [--llm-id <id>] [--llm-max-tokens <n>]
250
- update <agent_id> --name <n> ... Update an existing agent
475
+ update <agent_id> [options] Update an existing agent
251
476
  delete <agent_id> [-y] Delete an agent
252
477
  publish <agent_id> Publish an agent
253
478
  unpublish <agent_id> Unpublish an agent
254
479
  chat <agent_id> Start interactive chat with an agent
255
480
  chat <agent_id> -m "message" Send a single message (non-interactive)
256
481
  sessions <agent_id> List all conversations for an agent
257
- history <conversation_id> Show message history for a conversation
482
+ history <agent_id> <conversation_id> Show message history for a conversation
258
483
  trace <conversation_id> Get trace data for a conversation`);
259
484
  return Promise.resolve(0);
260
485
  }
@@ -265,6 +490,14 @@ Subcommands:
265
490
  return runAgentGetCommand(rest);
266
491
  if (subcommand === "list")
267
492
  return runAgentListCommand(rest);
493
+ if (subcommand === "personal-list")
494
+ return runAgentPersonalListCommand(rest);
495
+ if (subcommand === "category-list")
496
+ return runAgentCategoryListCommand(rest);
497
+ if (subcommand === "template-list")
498
+ return runAgentTemplateListCommand(rest);
499
+ if (subcommand === "template-get")
500
+ return runAgentTemplateGetCommand(rest);
268
501
  if (subcommand === "sessions")
269
502
  return runAgentSessionsCommand(rest);
270
503
  if (subcommand === "history")
@@ -322,7 +555,23 @@ Get agent details from the agent-factory API.
322
555
  Options:
323
556
  --verbose, -v Show full JSON response
324
557
  -bd, --biz-domain <value> Business domain (default: bd_public)
325
- --pretty Pretty-print JSON output (default)`);
558
+ --pretty Pretty-print JSON output (default)
559
+ --save-config <path> Save config to file with timestamp (output: <path-with-timestamp>)`);
560
+ return 0;
561
+ }
562
+ }
563
+ if (subcommand === "update") {
564
+ if (rest.length === 1 && (rest[0] === "--help" || rest[0] === "-h")) {
565
+ console.log(`kweaver agent update <agent_id> [options]
566
+
567
+ Update an existing agent.
568
+
569
+ Options:
570
+ --name <text> Agent name (max 50)
571
+ --profile <text> Agent description (max 500)
572
+ --system-prompt <text> System prompt
573
+ --knowledge-network-id <id> Business knowledge network ID to configure
574
+ --config-path <path> Path to config file (read from file instead of API)`);
326
575
  return 0;
327
576
  }
328
577
  }
@@ -345,6 +594,67 @@ Options:
345
594
  return 0;
346
595
  }
347
596
  }
597
+ if (subcommand === "personal-list") {
598
+ if (rest.length === 1 && (rest[0] === "--help" || rest[0] === "-h")) {
599
+ console.log(`kweaver agent personal-list [options]
600
+
601
+ List personal space agents from the agent-factory API.
602
+
603
+ Options:
604
+ --name <text> Filter by name
605
+ --pagination-marker <str> Pagination marker
606
+ --publish-status <status> Filter by publish status
607
+ --publish-to-be <value> Publish to be filter
608
+ --size <n> Max items to return (default: 48)
609
+ --verbose, -v Show full JSON response
610
+ -bd, --biz-domain <value> Business domain (default: bd_public)
611
+ --pretty Pretty-print JSON output (default)`);
612
+ return 0;
613
+ }
614
+ }
615
+ if (subcommand === "category-list") {
616
+ if (rest.length === 1 && (rest[0] === "--help" || rest[0] === "-h")) {
617
+ console.log(`kweaver agent category-list [options]
618
+
619
+ List agent categories from the agent-factory API.
620
+
621
+ Options:
622
+ --verbose, -v Show full JSON response
623
+ -bd, --biz-domain <value> Business domain (default: bd_public)
624
+ --pretty Pretty-print JSON output (default)`);
625
+ return 0;
626
+ }
627
+ }
628
+ if (subcommand === "template-list") {
629
+ if (rest.length === 1 && (rest[0] === "--help" || rest[0] === "-h")) {
630
+ console.log(`kweaver agent template-list [options]
631
+
632
+ List published agent templates from the agent-factory API.
633
+
634
+ Options:
635
+ --category-id <id> Filter by category
636
+ --name <text> Filter by name
637
+ --pagination-marker <str> Pagination marker
638
+ --size <n> Max items to return (default: 48)
639
+ --verbose, -v Show full JSON response
640
+ -bd, --biz-domain <value> Business domain (default: bd_public)
641
+ --pretty Pretty-print JSON output (default)`);
642
+ return 0;
643
+ }
644
+ }
645
+ if (subcommand === "template-get") {
646
+ if (rest.length === 1 && (rest[0] === "--help" || rest[0] === "-h")) {
647
+ console.log(`kweaver agent template-get <template_id> [options]
648
+
649
+ Get published agent template details from the agent-factory API.
650
+
651
+ Options:
652
+ --verbose, -v Show full JSON response
653
+ -bd, --biz-domain <value> Business domain (default: bd_public)
654
+ --pretty Pretty-print JSON output (default)`);
655
+ return 0;
656
+ }
657
+ }
348
658
  if (subcommand === "sessions") {
349
659
  if (rest.length === 1 && (rest[0] === "--help" || rest[0] === "-h")) {
350
660
  console.log(`kweaver agent sessions <agent_id> [options]
@@ -360,12 +670,11 @@ Options:
360
670
  }
361
671
  if (subcommand === "history") {
362
672
  if (rest.length === 1 && (rest[0] === "--help" || rest[0] === "-h")) {
363
- console.log(`kweaver agent history <conversation_id> [options]
673
+ console.log(`kweaver agent history <agent_id> <conversation_id> [options]
364
674
 
365
- Show message history for a conversation.
675
+ Show conversation detail (messages) for an agent.
366
676
 
367
677
  Options:
368
- --limit <n> Max messages to return (default: 30)
369
678
  -bd, --biz-domain <value> Business domain (default: bd_public)
370
679
  --pretty Pretty-print JSON output (default)`);
371
680
  return 0;
@@ -373,7 +682,7 @@ Options:
373
682
  }
374
683
  if (subcommand === "trace") {
375
684
  if (rest.length === 1 && (rest[0] === "--help" || rest[0] === "-h")) {
376
- console.log(`kweaver agent trace <conversation_id> [options]
685
+ console.log(`kweaver agent trace <agent_id> <conversation_id> [options]
377
686
 
378
687
  Get trace data for a conversation.
379
688
 
@@ -406,6 +715,7 @@ export function parseAgentGetArgs(args) {
406
715
  let businessDomain = "";
407
716
  let pretty = true;
408
717
  let verbose = false;
718
+ let saveConfig = null;
409
719
  for (let i = 1; i < args.length; i += 1) {
410
720
  const arg = args[i];
411
721
  if (arg === "--help" || arg === "-h") {
@@ -427,11 +737,19 @@ export function parseAgentGetArgs(args) {
427
737
  verbose = true;
428
738
  continue;
429
739
  }
740
+ if (arg === "--save-config") {
741
+ saveConfig = args[i + 1] ?? "";
742
+ if (!saveConfig || saveConfig.startsWith("-")) {
743
+ throw new Error("Missing value for save-config flag");
744
+ }
745
+ i += 1;
746
+ continue;
747
+ }
430
748
  throw new Error(`Unsupported agent get argument: ${arg}`);
431
749
  }
432
750
  if (!businessDomain)
433
751
  businessDomain = resolveBusinessDomain();
434
- return { agentId, businessDomain, pretty, verbose };
752
+ return { agentId, businessDomain, pretty, verbose, saveConfig };
435
753
  }
436
754
  function formatSimpleAgentGet(text, pretty) {
437
755
  const parsed = JSON.parse(text);
@@ -448,6 +766,16 @@ function formatSimpleAgentGet(text, pretty) {
448
766
  };
449
767
  return JSON.stringify(simplified, null, pretty ? 2 : 0);
450
768
  }
769
+ function formatSimpleAgentTemplateGet(text, pretty) {
770
+ const parsed = JSON.parse(text);
771
+ const simplified = {
772
+ id: readStringField(parsed, "tpl_id", "id"),
773
+ name: readStringField(parsed, "name", "agent_name", "title"),
774
+ description: readStringField(parsed, "profile", "description", "comment", "summary", "intro"),
775
+ config: parsed.config ?? {},
776
+ };
777
+ return JSON.stringify(simplified, null, pretty ? 2 : 0);
778
+ }
451
779
  async function runAgentGetCommand(args) {
452
780
  let options;
453
781
  try {
@@ -462,7 +790,8 @@ Get agent details from the agent-factory API.
462
790
  Options:
463
791
  --verbose, -v Show full JSON response
464
792
  -bd, --biz-domain <value> Business domain (default: bd_public)
465
- --pretty Pretty-print JSON output (default)`);
793
+ --pretty Pretty-print JSON output (default)
794
+ --save-config <path> Save config to file with timestamp (output: <path-with-timestamp>)`);
466
795
  return 0;
467
796
  }
468
797
  console.error(formatHttpError(error));
@@ -477,6 +806,18 @@ Options:
477
806
  businessDomain: options.businessDomain,
478
807
  });
479
808
  if (body) {
809
+ // 如果指定了 --save-config,保存 config 到文件(带时间戳)
810
+ if (options.saveConfig) {
811
+ const parsed = JSON.parse(body);
812
+ const config = parsed.config ?? {};
813
+ const timestampedPath = generateTimestampedPath(options.saveConfig);
814
+ // 确保目录存在
815
+ const dir = dirname(timestampedPath);
816
+ await fs.mkdir(dir, { recursive: true });
817
+ await fs.writeFile(timestampedPath, JSON.stringify(config, null, 2), "utf-8");
818
+ console.log(timestampedPath);
819
+ return 0;
820
+ }
480
821
  console.log(options.verbose ? formatCallOutput(body, options.pretty) : formatSimpleAgentGet(body, options.pretty));
481
822
  }
482
823
  return 0;
@@ -557,12 +898,28 @@ Options:
557
898
  }
558
899
  try {
559
900
  const token = await ensureValidToken();
901
+ let agentKey;
902
+ try {
903
+ const agentInfo = await fetchAgentInfo({
904
+ baseUrl: token.baseUrl,
905
+ accessToken: token.accessToken,
906
+ agentId: options.agentId,
907
+ version: "v0",
908
+ businessDomain: options.businessDomain,
909
+ });
910
+ agentKey = agentInfo.key;
911
+ }
912
+ catch {
913
+ // If fetchAgentInfo fails (e.g., in tests with mock fetch), use agentId as agentKey
914
+ agentKey = options.agentId;
915
+ }
560
916
  const body = await listConversations({
561
917
  baseUrl: token.baseUrl,
562
918
  accessToken: token.accessToken,
563
- agentId: options.agentId,
919
+ agentKey: agentKey,
564
920
  businessDomain: options.businessDomain,
565
- limit: options.limit,
921
+ page: 1,
922
+ size: options.limit ?? 30,
566
923
  });
567
924
  console.log(formatCallOutput(body, options.pretty));
568
925
  return 0;
@@ -579,12 +936,11 @@ async function runAgentHistoryCommand(args) {
579
936
  }
580
937
  catch (error) {
581
938
  if (error instanceof Error && error.message === "help") {
582
- console.log(`kweaver agent history <conversation_id> [options]
939
+ console.log(`kweaver agent history <agent_id> <conversation_id> [options]
583
940
 
584
- Show message history for a conversation.
941
+ Show conversation detail (messages) for an agent.
585
942
 
586
943
  Options:
587
- --limit <n> Max messages to return (default: 30)
588
944
  -bd, --biz-domain <value> Business domain (default: bd_public)
589
945
  --pretty Pretty-print JSON output (default)`);
590
946
  return 0;
@@ -594,12 +950,29 @@ Options:
594
950
  }
595
951
  try {
596
952
  const token = await ensureValidToken();
953
+ // Use agentKey from options.agentId if provided, otherwise use conversationId as fallback
954
+ // This allows both "history <agent_id> <conversation_id>" and "history <conversation_id>" formats
955
+ let agentKey;
956
+ if (options.agentId) {
957
+ const agentInfo = await fetchAgentInfo({
958
+ baseUrl: token.baseUrl,
959
+ accessToken: token.accessToken,
960
+ agentId: options.agentId,
961
+ version: "v0",
962
+ businessDomain: options.businessDomain,
963
+ });
964
+ agentKey = agentInfo.key;
965
+ }
966
+ else {
967
+ // When no agentId provided, use conversationId as agentKey (for testing/backward compatibility)
968
+ agentKey = options.conversationId;
969
+ }
597
970
  const body = await listMessages({
598
971
  baseUrl: token.baseUrl,
599
972
  accessToken: token.accessToken,
973
+ agentKey: agentKey,
600
974
  conversationId: options.conversationId,
601
975
  businessDomain: options.businessDomain,
602
- limit: options.limit,
603
976
  });
604
977
  console.log(formatCallOutput(body, options.pretty));
605
978
  return 0;
@@ -616,7 +989,7 @@ async function runAgentTraceCommand(args) {
616
989
  }
617
990
  catch (error) {
618
991
  if (error instanceof Error && error.message === "help") {
619
- console.log(`kweaver agent trace <conversation_id> [options]
992
+ console.log(`kweaver agent trace <agent_id> <conversation_id> [options]
620
993
 
621
994
  Get trace data for a conversation.
622
995
 
@@ -633,6 +1006,7 @@ Options:
633
1006
  const body = await getTracesByConversation({
634
1007
  baseUrl: token.baseUrl,
635
1008
  accessToken: token.accessToken,
1009
+ agentId: options.agentId,
636
1010
  conversationId: options.conversationId,
637
1011
  });
638
1012
  console.log(formatCallOutput(body, options.pretty));
@@ -670,11 +1044,12 @@ async function runAgentCreateCommand(args) {
670
1044
  let name = "";
671
1045
  let profile = "";
672
1046
  let key = "";
673
- let productKey = "DIP";
1047
+ let productKey = "dip";
674
1048
  let systemPrompt = "";
675
1049
  let llmId = "";
676
1050
  let llmMaxTokens = 4096;
677
1051
  let businessDomain = "";
1052
+ let configStr = "";
678
1053
  for (let i = 0; i < args.length; i += 1) {
679
1054
  const arg = args[i];
680
1055
  if (arg === "--help" || arg === "-h") {
@@ -682,16 +1057,17 @@ async function runAgentCreateCommand(args) {
682
1057
 
683
1058
  Create a new agent.
684
1059
 
685
- Required:
1060
+ Required (when --config is not provided):
686
1061
  --name <text> Agent name (max 50)
687
1062
  --profile <text> Agent description (max 500)
688
1063
 
689
1064
  Optional:
690
1065
  --key <text> Agent unique key (auto-generated if omitted)
691
- --product-key <text> Product key: DIP, AnyShare, ChatBI (default: DIP)
1066
+ --product-key <text> Product key: dip, AnyShare, ChatBI (default: dip)
692
1067
  --system-prompt <text> System prompt
693
1068
  --llm-id <id> LLM model ID (required for public API)
694
1069
  --llm-max-tokens <n> LLM max tokens (default: 4096)
1070
+ --config <json|path> Full config object as JSON string or file path (overrides individual config options)
695
1071
  -bd, --biz-domain <val> Business domain (default: bd_public)`);
696
1072
  return 0;
697
1073
  }
@@ -708,7 +1084,7 @@ Optional:
708
1084
  continue;
709
1085
  }
710
1086
  if (arg === "--product-key") {
711
- productKey = args[++i] ?? "DIP";
1087
+ productKey = args[++i] ?? "dip";
712
1088
  continue;
713
1089
  }
714
1090
  if (arg === "--system-prompt") {
@@ -723,6 +1099,10 @@ Optional:
723
1099
  llmMaxTokens = parseInt(args[++i] ?? "4096", 10);
724
1100
  continue;
725
1101
  }
1102
+ if (arg === "--config") {
1103
+ configStr = args[++i] ?? "";
1104
+ continue;
1105
+ }
726
1106
  if (arg === "-bd" || arg === "--biz-domain") {
727
1107
  businessDomain = args[++i] ?? "bd_public";
728
1108
  continue;
@@ -738,13 +1118,35 @@ Optional:
738
1118
  console.error("--profile is required");
739
1119
  return 1;
740
1120
  }
741
- const config = {
742
- input: { fields: [{ name: "user_input", type: "string", desc: "" }] },
743
- output: { default_format: "markdown" },
744
- system_prompt: systemPrompt,
745
- };
746
- if (llmId) {
747
- config.llms = [{ is_default: true, llm_config: { id: llmId, name: llmId, max_tokens: llmMaxTokens } }];
1121
+ let config;
1122
+ if (configStr) {
1123
+ // Use provided config - check if it's a file path or JSON string
1124
+ try {
1125
+ // Try to read as file first
1126
+ const fileContent = await fs.readFile(configStr, "utf-8");
1127
+ config = JSON.parse(fileContent);
1128
+ }
1129
+ catch {
1130
+ // Not a file, try as JSON string
1131
+ try {
1132
+ config = JSON.parse(configStr);
1133
+ }
1134
+ catch (error) {
1135
+ console.error("Invalid JSON or file path for --config option");
1136
+ return 1;
1137
+ }
1138
+ }
1139
+ }
1140
+ else {
1141
+ // Build config from individual options
1142
+ config = {
1143
+ input: { fields: [{ name: "user_input", type: "string", desc: "" }] },
1144
+ output: { default_format: "markdown" },
1145
+ system_prompt: systemPrompt,
1146
+ };
1147
+ if (llmId) {
1148
+ config.llms = [{ is_default: true, llm_config: { id: llmId, name: llmId, max_tokens: llmMaxTokens } }];
1149
+ }
748
1150
  }
749
1151
  const payload = {
750
1152
  name,
@@ -752,6 +1154,7 @@ Optional:
752
1154
  avatar_type: 1,
753
1155
  avatar: "icon-dip-agent-default",
754
1156
  product_key: productKey,
1157
+ product_name: "DIP",
755
1158
  config,
756
1159
  };
757
1160
  if (key)
@@ -776,17 +1179,43 @@ Optional:
776
1179
  async function runAgentUpdateCommand(args) {
777
1180
  const agentId = args[0];
778
1181
  if (!agentId || agentId.startsWith("-")) {
779
- console.error("Usage: kweaver agent update <agent_id> [--name <n>] [--profile <p>] [--system-prompt <sp>]");
1182
+ console.error("Usage: kweaver agent update <agent_id> [--name <n>] [--profile <p>] [--system-prompt <sp>] [--knowledge-network-id <id> [--config-path <path>]]");
780
1183
  return 1;
781
1184
  }
1185
+ let knowledgeNetworkId = null;
1186
+ let configPath = null;
782
1187
  try {
783
1188
  const token = await ensureValidToken();
1189
+ let current;
1190
+ let configFromFile = null;
1191
+ // 如果指定了 --config-path,从文件读取配置
1192
+ if (args.includes("--config-path")) {
1193
+ const configPathIndex = args.indexOf("--config-path");
1194
+ configPath = args[configPathIndex + 1] ?? "";
1195
+ if (!configPath || configPath.startsWith("-")) {
1196
+ console.error("Missing value for --config-path flag");
1197
+ return 1;
1198
+ }
1199
+ try {
1200
+ const fileContent = await fs.readFile(configPath, "utf-8");
1201
+ configFromFile = JSON.parse(fileContent);
1202
+ }
1203
+ catch (error) {
1204
+ console.error(`Failed to read config from ${configPath}: ${error}`);
1205
+ return 1;
1206
+ }
1207
+ }
1208
+ // 从API获取当前 agent 配置
784
1209
  const currentRaw = await getAgent({
785
1210
  baseUrl: token.baseUrl,
786
1211
  accessToken: token.accessToken,
787
1212
  agentId,
788
1213
  });
789
- const current = JSON.parse(currentRaw);
1214
+ current = JSON.parse(currentRaw);
1215
+ // 如果从文件读取了 config,合并到 current 中
1216
+ if (configFromFile) {
1217
+ current.config = configFromFile;
1218
+ }
790
1219
  for (let i = 1; i < args.length; i += 1) {
791
1220
  const arg = args[i];
792
1221
  if (arg === "--name") {
@@ -803,6 +1232,29 @@ async function runAgentUpdateCommand(args) {
803
1232
  current.config = config;
804
1233
  continue;
805
1234
  }
1235
+ if (arg === "--knowledge-network-id") {
1236
+ knowledgeNetworkId = args[++i] ?? "";
1237
+ if (!knowledgeNetworkId || knowledgeNetworkId.startsWith("-")) {
1238
+ console.error("Missing value for --knowledge-network-id flag");
1239
+ return 1;
1240
+ }
1241
+ continue;
1242
+ }
1243
+ }
1244
+ // 如果指定了 --knowledge-network-id,更新 data_source.knowledge_network
1245
+ if (knowledgeNetworkId) {
1246
+ const config = (current.config ?? {});
1247
+ const dataSource = (config.data_source ?? {});
1248
+ // 获取知识网络名称(如果需要的话,可以查询BKN获取)
1249
+ const knowledgeNetwork = [
1250
+ {
1251
+ knowledge_network_id: knowledgeNetworkId,
1252
+ knowledge_network_name: "", // 可选:通过BKN API获取名称
1253
+ },
1254
+ ];
1255
+ dataSource.knowledge_network = knowledgeNetwork;
1256
+ config.data_source = dataSource;
1257
+ current.config = config;
806
1258
  }
807
1259
  const body = await updateAgent({
808
1260
  baseUrl: token.baseUrl,
@@ -866,16 +1318,35 @@ async function runAgentDeleteCommand(args) {
866
1318
  async function runAgentPublishCommand(args) {
867
1319
  const agentId = args[0];
868
1320
  if (!agentId || agentId.startsWith("-")) {
869
- console.error("Usage: kweaver agent publish <agent_id>");
1321
+ console.error("Usage: kweaver agent publish <agent_id> [--category-id <id>]");
870
1322
  return 1;
871
1323
  }
1324
+ let categoryId = "";
1325
+ for (let i = 1; i < args.length; i += 1) {
1326
+ const arg = args[i];
1327
+ if (arg === "--category-id") {
1328
+ categoryId = args[i + 1] ?? "";
1329
+ i += 1;
1330
+ continue;
1331
+ }
1332
+ if (arg === "--help" || arg === "-h") {
1333
+ console.log(`kweaver agent publish <agent_id> [options]
1334
+
1335
+ Publish an agent.
1336
+
1337
+ Options:
1338
+ --category-id <id> Category ID for the agent
1339
+ -bd, --biz-domain <value> Business domain (default: bd_public)`);
1340
+ return 0;
1341
+ }
1342
+ }
872
1343
  try {
873
1344
  const token = await ensureValidToken();
874
1345
  const body = await publishAgent({
875
1346
  baseUrl: token.baseUrl,
876
1347
  accessToken: token.accessToken,
877
1348
  agentId,
878
- body: JSON.stringify({ agent_id: agentId }),
1349
+ categoryId,
879
1350
  });
880
1351
  console.log(body);
881
1352
  return 0;
@@ -907,3 +1378,204 @@ async function runAgentUnpublishCommand(args) {
907
1378
  return 1;
908
1379
  }
909
1380
  }
1381
+ // ── Personal List ─────────────────────────────────────────────────────────────
1382
+ async function runAgentPersonalListCommand(args) {
1383
+ let options;
1384
+ try {
1385
+ options = parseAgentPersonalListArgs(args);
1386
+ }
1387
+ catch (error) {
1388
+ if (error instanceof Error && error.message === "help") {
1389
+ console.log(`kweaver agent personal-list [options]
1390
+
1391
+ List personal space agents from the agent-factory API.
1392
+
1393
+ Options:
1394
+ --name <text> Filter by name
1395
+ --pagination-marker <str> Pagination marker
1396
+ --publish-status <status> Filter by publish status
1397
+ --publish-to-be <value> Publish to be filter
1398
+ --size <n> Max items to return (default: 48)
1399
+ --verbose, -v Show full JSON response
1400
+ -bd, --biz-domain <value> Business domain (default: bd_public)
1401
+ --pretty Pretty-print JSON output (default)`);
1402
+ return 0;
1403
+ }
1404
+ console.error(formatHttpError(error));
1405
+ return 1;
1406
+ }
1407
+ try {
1408
+ const token = await ensureValidToken();
1409
+ const body = await listPersonalAgents({
1410
+ baseUrl: token.baseUrl,
1411
+ accessToken: token.accessToken,
1412
+ businessDomain: options.businessDomain,
1413
+ name: options.name,
1414
+ pagination_marker_str: options.pagination_marker_str,
1415
+ publish_status: options.publish_status,
1416
+ publish_to_be: options.publish_to_be,
1417
+ size: options.size,
1418
+ });
1419
+ if (body) {
1420
+ console.log(options.verbose ? formatCallOutput(body, options.pretty) : formatSimpleAgentList(body, options.pretty));
1421
+ }
1422
+ return 0;
1423
+ }
1424
+ catch (error) {
1425
+ console.error(formatHttpError(error));
1426
+ return 1;
1427
+ }
1428
+ }
1429
+ // ── Template List ─────────────────────────────────────────────────────────────
1430
+ async function runAgentTemplateListCommand(args) {
1431
+ let options;
1432
+ try {
1433
+ options = parseAgentTemplateListArgs(args);
1434
+ }
1435
+ catch (error) {
1436
+ if (error instanceof Error && error.message === "help") {
1437
+ console.log(`kweaver agent template-list [options]
1438
+
1439
+ List published agent templates from the agent-factory API.
1440
+
1441
+ Options:
1442
+ --category-id <id> Filter by category
1443
+ --name <text> Filter by name
1444
+ --pagination-marker <str> Pagination marker
1445
+ --size <n> Max items to return (default: 48)
1446
+ --verbose, -v Show full JSON response
1447
+ -bd, --biz-domain <value> Business domain (default: bd_public)
1448
+ --pretty Pretty-print JSON output (default)`);
1449
+ return 0;
1450
+ }
1451
+ console.error(formatHttpError(error));
1452
+ return 1;
1453
+ }
1454
+ try {
1455
+ const token = await ensureValidToken();
1456
+ const body = await listPublishedAgentTemplates({
1457
+ baseUrl: token.baseUrl,
1458
+ accessToken: token.accessToken,
1459
+ businessDomain: options.businessDomain,
1460
+ category_id: options.category_id,
1461
+ name: options.name,
1462
+ pagination_marker_str: options.pagination_marker_str,
1463
+ size: options.size,
1464
+ });
1465
+ if (body) {
1466
+ console.log(options.verbose ? formatCallOutput(body, options.pretty) : formatSimpleAgentList(body, options.pretty));
1467
+ }
1468
+ return 0;
1469
+ }
1470
+ catch (error) {
1471
+ console.error(formatHttpError(error));
1472
+ return 1;
1473
+ }
1474
+ }
1475
+ // ── Template Get ─────────────────────────────────────────────────────────────
1476
+ async function runAgentTemplateGetCommand(args) {
1477
+ let options;
1478
+ try {
1479
+ options = parseAgentTemplateGetArgs(args);
1480
+ }
1481
+ catch (error) {
1482
+ if (error instanceof Error && error.message === "help") {
1483
+ console.log(`kweaver agent template-get <template_id> [options]
1484
+
1485
+ Get published agent template details from the agent-factory API.
1486
+
1487
+ Options:
1488
+ --verbose, -v Show full JSON response
1489
+ -bd, --biz-domain <value> Business domain (default: bd_public)
1490
+ --pretty Pretty-print JSON output (default)
1491
+ --save-config <path> Save config to file with timestamp (output: <path-with-timestamp>)`);
1492
+ return 0;
1493
+ }
1494
+ console.error(formatHttpError(error));
1495
+ return 1;
1496
+ }
1497
+ try {
1498
+ const token = await ensureValidToken();
1499
+ const body = await getPublishedAgentTemplate({
1500
+ baseUrl: token.baseUrl,
1501
+ accessToken: token.accessToken,
1502
+ templateId: options.templateId,
1503
+ businessDomain: options.businessDomain,
1504
+ });
1505
+ if (body) {
1506
+ // 如果指定了 --save-config,保存 config 到文件(带时间戳)
1507
+ if (options.saveConfig) {
1508
+ const parsed = JSON.parse(body);
1509
+ const config = parsed.config ?? {};
1510
+ const timestampedPath = generateTimestampedPath(options.saveConfig);
1511
+ // 确保目录存在
1512
+ const dir = dirname(timestampedPath);
1513
+ await fs.mkdir(dir, { recursive: true });
1514
+ await fs.writeFile(timestampedPath, JSON.stringify(config, null, 2), "utf-8");
1515
+ console.log(timestampedPath);
1516
+ return 0;
1517
+ }
1518
+ console.log(options.verbose ? formatCallOutput(body, options.pretty) : formatSimpleAgentTemplateGet(body, options.pretty));
1519
+ }
1520
+ return 0;
1521
+ }
1522
+ catch (error) {
1523
+ console.error(formatHttpError(error));
1524
+ return 1;
1525
+ }
1526
+ }
1527
+ // ── Category List ───────────────────────────────────────────────────────────
1528
+ async function runAgentCategoryListCommand(args) {
1529
+ let businessDomain = "";
1530
+ let pretty = true;
1531
+ let verbose = false;
1532
+ for (let i = 0; i < args.length; i += 1) {
1533
+ const arg = args[i];
1534
+ if (arg === "--help" || arg === "-h") {
1535
+ console.log(`kweaver agent category-list [options]
1536
+
1537
+ List agent categories from the agent-factory API.
1538
+
1539
+ Options:
1540
+ --verbose, -v Show full JSON response
1541
+ -bd, --biz-domain <value> Business domain (default: bd_public)
1542
+ --pretty Pretty-print JSON output (default)`);
1543
+ return 0;
1544
+ }
1545
+ if (arg === "-bd" || arg === "--biz-domain") {
1546
+ businessDomain = args[i + 1] ?? "bd_public";
1547
+ if (!businessDomain || businessDomain.startsWith("-")) {
1548
+ throw new Error("Missing value for biz-domain flag");
1549
+ }
1550
+ i += 1;
1551
+ continue;
1552
+ }
1553
+ if (arg === "--pretty") {
1554
+ pretty = true;
1555
+ continue;
1556
+ }
1557
+ if (arg === "--verbose" || arg === "-v") {
1558
+ verbose = true;
1559
+ continue;
1560
+ }
1561
+ throw new Error(`Unsupported agent category-list argument: ${arg}`);
1562
+ }
1563
+ if (!businessDomain)
1564
+ businessDomain = resolveBusinessDomain();
1565
+ try {
1566
+ const token = await ensureValidToken();
1567
+ const body = await listAgentCategories({
1568
+ baseUrl: token.baseUrl,
1569
+ accessToken: token.accessToken,
1570
+ businessDomain,
1571
+ });
1572
+ if (body) {
1573
+ console.log(verbose ? formatCallOutput(body, pretty) : formatCallOutput(body, pretty));
1574
+ }
1575
+ return 0;
1576
+ }
1577
+ catch (error) {
1578
+ console.error(formatHttpError(error));
1579
+ return 1;
1580
+ }
1581
+ }