@kweaver-ai/kweaver-sdk 0.8.1 → 0.8.2

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 (183) hide show
  1. package/README.md +19 -5
  2. package/README.zh.md +19 -5
  3. package/dist/agent-providers/index.d.ts +7 -0
  4. package/dist/agent-providers/index.js +5 -0
  5. package/dist/agent-providers/prompt-template.d.ts +62 -0
  6. package/dist/agent-providers/prompt-template.js +105 -0
  7. package/dist/agent-providers/prompts/rubric-judge-v1.prompt.md +51 -0
  8. package/dist/agent-providers/prompts/within-trace-synthesizer-v1.prompt.md +60 -0
  9. package/dist/agent-providers/providers/claude-code-subprocess.d.ts +74 -0
  10. package/dist/agent-providers/providers/claude-code-subprocess.js +259 -0
  11. package/dist/agent-providers/providers/stub.d.ts +47 -0
  12. package/dist/agent-providers/providers/stub.js +77 -0
  13. package/dist/agent-providers/registry.d.ts +45 -0
  14. package/dist/agent-providers/registry.js +77 -0
  15. package/dist/agent-providers/types.d.ts +91 -0
  16. package/dist/agent-providers/types.js +25 -0
  17. package/dist/api/agent-chat.js +8 -6
  18. package/dist/api/context-loader.d.ts +1 -0
  19. package/dist/api/semantic-search.d.ts +5 -0
  20. package/dist/api/semantic-search.js +5 -0
  21. package/dist/api/skills.d.ts +75 -2
  22. package/dist/api/skills.js +108 -12
  23. package/dist/api/trace.d.ts +5 -0
  24. package/dist/api/trace.js +4 -0
  25. package/dist/cli.js +7 -5
  26. package/dist/commands/agent/mode.d.ts +6 -0
  27. package/dist/commands/agent/mode.js +75 -0
  28. package/dist/commands/agent.js +101 -29
  29. package/dist/commands/context-loader.js +608 -38
  30. package/dist/commands/skill.d.ts +21 -1
  31. package/dist/commands/skill.js +389 -1
  32. package/dist/commands/trace.d.ts +26 -1
  33. package/dist/commands/trace.js +515 -15
  34. package/dist/index.d.ts +2 -2
  35. package/dist/index.js +1 -1
  36. package/dist/resources/bkn.d.ts +5 -0
  37. package/dist/resources/bkn.js +5 -0
  38. package/dist/resources/skills.d.ts +17 -1
  39. package/dist/resources/skills.js +32 -1
  40. package/dist/trace-ai/diagnose/agent-binding.d.ts +67 -0
  41. package/dist/trace-ai/diagnose/agent-binding.js +257 -0
  42. package/dist/trace-ai/diagnose/builtin-rules/tool-retry-intent-mismatch.yaml +68 -0
  43. package/dist/trace-ai/diagnose/index.d.ts +32 -0
  44. package/dist/trace-ai/diagnose/index.js +246 -0
  45. package/dist/trace-ai/diagnose/output-schema-converter.d.ts +24 -0
  46. package/dist/trace-ai/diagnose/output-schema-converter.js +81 -0
  47. package/dist/trace-ai/diagnose/query-extractor.d.ts +14 -0
  48. package/dist/trace-ai/diagnose/query-extractor.js +45 -0
  49. package/dist/trace-ai/diagnose/report-assembler.d.ts +31 -0
  50. package/dist/{trace-core → trace-ai}/diagnose/report-assembler.js +19 -9
  51. package/dist/trace-ai/diagnose/report-markdown.d.ts +18 -0
  52. package/dist/trace-ai/diagnose/report-markdown.js +192 -0
  53. package/dist/{trace-core → trace-ai}/diagnose/rule-loader.js +42 -8
  54. package/dist/{trace-core → trace-ai}/diagnose/schemas.d.ts +77 -2
  55. package/dist/trace-ai/diagnose/schemas.js +154 -0
  56. package/dist/trace-ai/diagnose/signal-probe.d.ts +17 -0
  57. package/dist/trace-ai/diagnose/signal-probe.js +39 -0
  58. package/dist/trace-ai/diagnose/synthesizer-agent.d.ts +40 -0
  59. package/dist/trace-ai/diagnose/synthesizer-agent.js +158 -0
  60. package/dist/{trace-core → trace-ai}/diagnose/trace-shaper.js +1 -0
  61. package/dist/{trace-core → trace-ai}/diagnose/types.d.ts +55 -6
  62. package/dist/trace-ai/eval-set/assertion-evaluator.d.ts +29 -0
  63. package/dist/trace-ai/eval-set/assertion-evaluator.js +100 -0
  64. package/dist/trace-ai/eval-set/builder.d.ts +36 -0
  65. package/dist/trace-ai/eval-set/builder.js +126 -0
  66. package/dist/trace-ai/eval-set/index.d.ts +15 -0
  67. package/dist/trace-ai/eval-set/index.js +10 -0
  68. package/dist/trace-ai/eval-set/output-writer.d.ts +27 -0
  69. package/dist/trace-ai/eval-set/output-writer.js +126 -0
  70. package/dist/trace-ai/eval-set/query-picker.d.ts +37 -0
  71. package/dist/trace-ai/eval-set/query-picker.js +147 -0
  72. package/dist/trace-ai/eval-set/redactor.d.ts +42 -0
  73. package/dist/trace-ai/eval-set/redactor.js +133 -0
  74. package/dist/trace-ai/eval-set/rubric-templates/answer-match-reference.prompt.md +19 -0
  75. package/dist/trace-ai/eval-set/schemas.d.ts +136 -0
  76. package/dist/trace-ai/eval-set/schemas.js +130 -0
  77. package/dist/trace-ai/eval-set/semantic-match-provider.d.ts +33 -0
  78. package/dist/trace-ai/eval-set/semantic-match-provider.js +51 -0
  79. package/dist/trace-ai/eval-set/test-runner.d.ts +34 -0
  80. package/dist/trace-ai/eval-set/test-runner.js +153 -0
  81. package/dist/trace-ai/eval-set/types.d.ts +46 -0
  82. package/dist/trace-ai/eval-set/types.js +8 -0
  83. package/dist/trace-ai/exp/bundle-writer.d.ts +10 -0
  84. package/dist/trace-ai/exp/bundle-writer.js +54 -0
  85. package/dist/trace-ai/exp/claude-binary.d.ts +5 -0
  86. package/dist/trace-ai/exp/claude-binary.js +30 -0
  87. package/dist/trace-ai/exp/coordinator.d.ts +45 -0
  88. package/dist/trace-ai/exp/coordinator.js +203 -0
  89. package/dist/trace-ai/exp/eval-runner.d.ts +14 -0
  90. package/dist/trace-ai/exp/eval-runner.js +47 -0
  91. package/dist/trace-ai/exp/exp-store/abort-signal.d.ts +3 -0
  92. package/dist/trace-ai/exp/exp-store/abort-signal.js +27 -0
  93. package/dist/trace-ai/exp/exp-store/candidate-lineage-yaml.d.ts +4 -0
  94. package/dist/trace-ai/exp/exp-store/candidate-lineage-yaml.js +37 -0
  95. package/dist/trace-ai/exp/exp-store/events-jsonl.d.ts +17 -0
  96. package/dist/trace-ai/exp/exp-store/events-jsonl.js +60 -0
  97. package/dist/trace-ai/exp/exp-store/exp-registry.d.ts +6 -0
  98. package/dist/trace-ai/exp/exp-store/exp-registry.js +41 -0
  99. package/dist/trace-ai/exp/exp-store/index.d.ts +46 -0
  100. package/dist/trace-ai/exp/exp-store/index.js +59 -0
  101. package/dist/trace-ai/exp/exp-store/lock.d.ts +3 -0
  102. package/dist/trace-ai/exp/exp-store/lock.js +73 -0
  103. package/dist/trace-ai/exp/exp-store/mission-md.d.ts +3 -0
  104. package/dist/trace-ai/exp/exp-store/mission-md.js +37 -0
  105. package/dist/trace-ai/exp/exp-store/readme-template.d.ts +5 -0
  106. package/dist/trace-ai/exp/exp-store/readme-template.js +25 -0
  107. package/dist/trace-ai/exp/exp-store/round-yaml.d.ts +3 -0
  108. package/dist/trace-ai/exp/exp-store/round-yaml.js +33 -0
  109. package/dist/trace-ai/exp/index.d.ts +8 -0
  110. package/dist/trace-ai/exp/index.js +238 -0
  111. package/dist/trace-ai/exp/info.d.ts +35 -0
  112. package/dist/trace-ai/exp/info.js +120 -0
  113. package/dist/trace-ai/exp/patch/agent-config.d.ts +1 -0
  114. package/dist/trace-ai/exp/patch/agent-config.js +26 -0
  115. package/dist/trace-ai/exp/patch/index.d.ts +2 -0
  116. package/dist/trace-ai/exp/patch/index.js +13 -0
  117. package/dist/trace-ai/exp/patch/skill.d.ts +1 -0
  118. package/dist/trace-ai/exp/patch/skill.js +24 -0
  119. package/dist/trace-ai/exp/providers/synthesizer-client.d.ts +14 -0
  120. package/dist/trace-ai/exp/providers/synthesizer-client.js +39 -0
  121. package/dist/trace-ai/exp/providers/triage-client.d.ts +19 -0
  122. package/dist/trace-ai/exp/providers/triage-client.js +51 -0
  123. package/dist/trace-ai/exp/schemas.d.ts +147 -0
  124. package/dist/trace-ai/exp/schemas.js +50 -0
  125. package/dist/trace-ai/exp/scoring.d.ts +2 -0
  126. package/dist/trace-ai/exp/scoring.js +46 -0
  127. package/dist/trace-ai/scan/aggregator.d.ts +20 -0
  128. package/dist/trace-ai/scan/aggregator.js +26 -0
  129. package/dist/trace-ai/scan/artifacts/paths.d.ts +12 -0
  130. package/dist/trace-ai/scan/artifacts/paths.js +18 -0
  131. package/dist/trace-ai/scan/artifacts/writer.d.ts +67 -0
  132. package/dist/trace-ai/scan/artifacts/writer.js +96 -0
  133. package/dist/trace-ai/scan/batched-rubric.d.ts +55 -0
  134. package/dist/trace-ai/scan/batched-rubric.js +159 -0
  135. package/dist/trace-ai/scan/cross-trace-synthesizer.d.ts +24 -0
  136. package/dist/trace-ai/scan/cross-trace-synthesizer.js +93 -0
  137. package/dist/trace-ai/scan/index.d.ts +31 -0
  138. package/dist/trace-ai/scan/index.js +390 -0
  139. package/dist/trace-ai/scan/prompts/builtin/cross-trace-synthesizer-v1.prompt.md +44 -0
  140. package/dist/trace-ai/scan/prompts/builtin/rubric-judge-batch-v1.prompt.md +44 -0
  141. package/dist/trace-ai/scan/runner.d.ts +25 -0
  142. package/dist/trace-ai/scan/runner.js +42 -0
  143. package/dist/trace-ai/scan/sampler.d.ts +18 -0
  144. package/dist/trace-ai/scan/sampler.js +81 -0
  145. package/dist/trace-ai/scan/scan-summary-markdown.d.ts +2 -0
  146. package/dist/trace-ai/scan/scan-summary-markdown.js +71 -0
  147. package/dist/trace-ai/scan/scan-summary-schema.d.ts +73 -0
  148. package/dist/trace-ai/scan/scan-summary-schema.js +61 -0
  149. package/dist/trace-ai/scan/single-agent-validator.d.ts +23 -0
  150. package/dist/trace-ai/scan/single-agent-validator.js +42 -0
  151. package/dist/trace-ai/scan/traces-list-parser.d.ts +15 -0
  152. package/dist/trace-ai/scan/traces-list-parser.js +46 -0
  153. package/package.json +2 -2
  154. package/dist/trace-core/diagnose/index.d.ts +0 -9
  155. package/dist/trace-core/diagnose/index.js +0 -104
  156. package/dist/trace-core/diagnose/report-assembler.d.ts +0 -12
  157. package/dist/trace-core/diagnose/schemas.js +0 -94
  158. package/dist/trace-core/diagnose/signal-probe.d.ts +0 -5
  159. package/dist/trace-core/diagnose/signal-probe.js +0 -21
  160. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/excessive-tool-calls-per-turn.d.ts +0 -0
  161. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/excessive-tool-calls-per-turn.js +0 -0
  162. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/excessive-tool-calls-per-turn.yaml +0 -0
  163. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/llm-response-truncated-no-continue.d.ts +0 -0
  164. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/llm-response-truncated-no-continue.js +0 -0
  165. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/llm-response-truncated-no-continue.yaml +0 -0
  166. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/register.d.ts +0 -0
  167. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/register.js +0 -0
  168. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/retrieval-empty-no-fallback.d.ts +0 -0
  169. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/retrieval-empty-no-fallback.js +0 -0
  170. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/retrieval-empty-no-fallback.yaml +0 -0
  171. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/tool-error-swallowed.d.ts +0 -0
  172. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/tool-error-swallowed.js +0 -0
  173. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/tool-error-swallowed.yaml +0 -0
  174. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/tool-loop-no-state-change.d.ts +0 -0
  175. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/tool-loop-no-state-change.js +0 -0
  176. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/tool-loop-no-state-change.yaml +0 -0
  177. /package/dist/{trace-core → trace-ai}/diagnose/predicate-registry.d.ts +0 -0
  178. /package/dist/{trace-core → trace-ai}/diagnose/predicate-registry.js +0 -0
  179. /package/dist/{trace-core → trace-ai}/diagnose/rule-loader.d.ts +0 -0
  180. /package/dist/{trace-core → trace-ai}/diagnose/synthesizer-template.d.ts +0 -0
  181. /package/dist/{trace-core → trace-ai}/diagnose/synthesizer-template.js +0 -0
  182. /package/dist/{trace-core → trace-ai}/diagnose/trace-shaper.d.ts +0 -0
  183. /package/dist/{trace-core → trace-ai}/diagnose/types.js +0 -0
@@ -1,6 +1,7 @@
1
1
  import { ensureValidToken, formatHttpError, with401RefreshRetry } from "../auth/oauth.js";
2
2
  import { runAgentChatCommand } from "./agent-chat.js";
3
3
  import { runAgentSkillCommand } from "./agent-members.js";
4
+ import { AGENT_MODE_HELP, applyAgentModeToConfig, normalizeAgentConfigInput, parseAgentMode, } from "./agent/mode.js";
4
5
  import { listAgents, getAgent, getAgentByKey, createAgent, updateAgent, deleteAgent, publishAgent, unpublishAgent, listPersonalAgents, listPublishedAgentTemplates, getPublishedAgentTemplate, listAgentCategories, } from "../api/agent-list.js";
5
6
  import { listConversations, listMessages, getTracesByConversation } from "../api/conversations.js";
6
7
  import { fetchAgentInfo } from "../api/agent-chat.js";
@@ -47,21 +48,21 @@ export async function resolveLlmName(options) {
47
48
  }
48
49
  }
49
50
  /**
50
- * 生成带时间戳的文件路径
51
- * @param path 用户提供的路径
52
- * @returns 带时间戳的文件路径
51
+ * Generate a timestamped file path.
52
+ * @param path User-provided output path.
53
+ * @returns The timestamped file path.
53
54
  */
54
55
  function generateTimestampedPath(path) {
55
56
  const timestamp = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
56
- // 如果路径以 / 结尾,视为目录,在目录下生成文件
57
+ // Treat paths ending in / as directories.
57
58
  if (path.endsWith("/")) {
58
59
  return join(path, `agent-config-${timestamp}.json`);
59
60
  }
60
- // 在文件名中插入时间戳:config.json -> config-2025-01-15T12-30-45.json
61
+ // Insert the timestamp before the extension: config.json -> config-2025-01-15T12-30-45.json.
61
62
  const ext = extname(path);
62
63
  const base = basename(path, ext);
63
64
  const dir = dirname(path);
64
- // 如果 dir ".",说明没有目录前缀,直接返回带时间戳的文件名
65
+ // No directory prefix was provided, so return only the timestamped file name.
65
66
  if (dir === ".") {
66
67
  return `${base}-${timestamp}${ext}`;
67
68
  }
@@ -549,7 +550,7 @@ Subcommands:
549
550
  get-by-key <key> Get agent by key
550
551
  create --name <n> --profile <p> Create a new agent
551
552
  [--key <key>] [--product-key <pk>] [--system-prompt <sp>]
552
- [--llm-id <id>] [--llm-max-tokens <n>]
553
+ [--llm-id <id>] [--llm-max-tokens <n>] [--mode <mode>]
553
554
  update <agent_id> [options] Update an existing agent
554
555
  delete <agent_id> [-y] Delete an agent
555
556
  publish <agent_id> Publish an agent
@@ -653,7 +654,8 @@ Options:
653
654
  --profile <text> Agent description (max 500)
654
655
  --system-prompt <text> System prompt
655
656
  --knowledge-network-id <id> Business knowledge network ID to configure
656
- --config-path <path> Path to config file (read from file instead of API)`);
657
+ --config-path <path> Path to config object file, or full agent JSON with config
658
+ ${AGENT_MODE_HELP}`);
657
659
  return 0;
658
660
  }
659
661
  }
@@ -891,12 +893,12 @@ Options:
891
893
  businessDomain: options.businessDomain,
892
894
  });
893
895
  if (body) {
894
- // 如果指定了 --save-config,保存 config 到文件(带时间戳)
896
+ // Save only the agent config object when --save-config is provided.
895
897
  if (options.saveConfig) {
896
898
  const parsed = JSON.parse(body);
897
899
  const config = parsed.config ?? {};
898
900
  const timestampedPath = generateTimestampedPath(options.saveConfig);
899
- // 确保目录存在
901
+ // Ensure the output directory exists.
900
902
  const dir = dirname(timestampedPath);
901
903
  await fs.mkdir(dir, { recursive: true });
902
904
  await fs.writeFile(timestampedPath, JSON.stringify(config, null, 2), "utf-8");
@@ -1146,6 +1148,7 @@ async function runAgentCreateCommand(args) {
1146
1148
  let llmMaxTokens = 4096;
1147
1149
  let businessDomain = "";
1148
1150
  let configStr = "";
1151
+ let explicitMode;
1149
1152
  for (let i = 0; i < args.length; i += 1) {
1150
1153
  const arg = args[i];
1151
1154
  if (arg === "--help" || arg === "-h") {
@@ -1163,6 +1166,7 @@ Optional:
1163
1166
  --system-prompt <text> System prompt
1164
1167
  --llm-id <id> LLM model ID (required for public API)
1165
1168
  --llm-max-tokens <n> LLM max tokens (default: 4096)
1169
+ ${AGENT_MODE_HELP}
1166
1170
  --config <json|path> Full config object as JSON string or file path (overrides individual config options)
1167
1171
  -bd, --biz-domain <val> Business domain (default: bd_public)`);
1168
1172
  return 0;
@@ -1195,6 +1199,17 @@ Optional:
1195
1199
  llmMaxTokens = parseInt(args[++i] ?? "4096", 10);
1196
1200
  continue;
1197
1201
  }
1202
+ if (arg === "--mode") {
1203
+ const value = args[++i] ?? "";
1204
+ try {
1205
+ explicitMode = parseAgentMode(value);
1206
+ }
1207
+ catch (error) {
1208
+ console.error(error instanceof Error ? error.message : String(error));
1209
+ return 1;
1210
+ }
1211
+ continue;
1212
+ }
1198
1213
  if (arg === "--config") {
1199
1214
  configStr = args[++i] ?? "";
1200
1215
  continue;
@@ -1241,13 +1256,19 @@ Optional:
1241
1256
  system_prompt: systemPrompt,
1242
1257
  };
1243
1258
  }
1259
+ try {
1260
+ applyAgentModeToConfig(config, explicitMode);
1261
+ }
1262
+ catch (error) {
1263
+ console.error(error instanceof Error ? error.message : String(error));
1264
+ return 1;
1265
+ }
1244
1266
  const payload = {
1245
1267
  name,
1246
1268
  profile,
1247
1269
  avatar_type: 1,
1248
1270
  avatar: "icon-dip-agent-default",
1249
1271
  product_key: productKey,
1250
- product_name: "DIP",
1251
1272
  config,
1252
1273
  };
1253
1274
  if (key)
@@ -1276,41 +1297,77 @@ Optional:
1276
1297
  // ── Update ───────────────────────────────────────────────────────────────────
1277
1298
  async function runAgentUpdateCommand(args) {
1278
1299
  const agentId = args[0];
1300
+ if (agentId === "--help" || agentId === "-h") {
1301
+ console.log(`kweaver agent update <agent_id> [options]
1302
+
1303
+ Update an existing agent.
1304
+
1305
+ Options:
1306
+ --name <text> Agent name
1307
+ --profile <text> Agent description
1308
+ --system-prompt <text> System prompt
1309
+ --knowledge-network-id <id> Knowledge network ID
1310
+ --config-path <path> Read config object from file, or full agent JSON with config
1311
+ ${AGENT_MODE_HELP}`);
1312
+ return 0;
1313
+ }
1279
1314
  if (!agentId || agentId.startsWith("-")) {
1280
- console.error("Usage: kweaver agent update <agent_id> [--name <n>] [--profile <p>] [--system-prompt <sp>] [--knowledge-network-id <id> [--config-path <path>]]");
1315
+ console.error("Usage: kweaver agent update <agent_id> [--name <n>] [--profile <p>] [--system-prompt <sp>] [--mode <mode>] [--knowledge-network-id <id> [--config-path <path>]]");
1281
1316
  return 1;
1282
1317
  }
1283
1318
  let knowledgeNetworkId = null;
1284
1319
  let configPath = null;
1285
- try {
1286
- const token = await ensureValidToken();
1287
- let current;
1288
- let configFromFile = null;
1289
- // 如果指定了 --config-path,从文件读取配置
1290
- if (args.includes("--config-path")) {
1291
- const configPathIndex = args.indexOf("--config-path");
1292
- configPath = args[configPathIndex + 1] ?? "";
1320
+ let explicitMode;
1321
+ for (let i = 1; i < args.length; i += 1) {
1322
+ const arg = args[i];
1323
+ if (arg === "--mode") {
1324
+ const value = args[++i] ?? "";
1325
+ try {
1326
+ explicitMode = parseAgentMode(value);
1327
+ }
1328
+ catch (error) {
1329
+ console.error(error instanceof Error ? error.message : String(error));
1330
+ return 1;
1331
+ }
1332
+ continue;
1333
+ }
1334
+ if (arg === "--config-path") {
1335
+ configPath = args[++i] ?? "";
1293
1336
  if (!configPath || configPath.startsWith("-")) {
1294
1337
  console.error("Missing value for --config-path flag");
1295
1338
  return 1;
1296
1339
  }
1340
+ continue;
1341
+ }
1342
+ }
1343
+ try {
1344
+ let current;
1345
+ let configFromFile = null;
1346
+ // Read config from file before fetching the current agent so invalid local config fails early.
1347
+ if (configPath) {
1297
1348
  try {
1298
1349
  const fileContent = await fs.readFile(configPath, "utf-8");
1299
- configFromFile = JSON.parse(fileContent);
1350
+ configFromFile = normalizeAgentConfigInput(JSON.parse(fileContent));
1351
+ if (!explicitMode) {
1352
+ applyAgentModeToConfig(configFromFile);
1353
+ }
1300
1354
  }
1301
1355
  catch (error) {
1302
- console.error(`Failed to read config from ${configPath}: ${error}`);
1356
+ console.error(error instanceof Error && error.message.startsWith("config.mode")
1357
+ ? error.message
1358
+ : `Failed to read config from ${configPath}: ${error}`);
1303
1359
  return 1;
1304
1360
  }
1305
1361
  }
1306
- // 从API获取当前 agent 配置
1362
+ const token = await ensureValidToken();
1363
+ // Fetch the current agent for read-modify-write updates.
1307
1364
  const currentRaw = await getAgent({
1308
1365
  baseUrl: token.baseUrl,
1309
1366
  accessToken: token.accessToken,
1310
1367
  agentId,
1311
1368
  });
1312
1369
  current = JSON.parse(currentRaw);
1313
- // 如果从文件读取了 config,合并到 current
1370
+ // Replace only current.config when a config file was provided.
1314
1371
  if (configFromFile) {
1315
1372
  current.config = configFromFile;
1316
1373
  }
@@ -1324,6 +1381,14 @@ async function runAgentUpdateCommand(args) {
1324
1381
  current.profile = args[++i] ?? current.profile;
1325
1382
  continue;
1326
1383
  }
1384
+ if (arg === "--mode") {
1385
+ i += 1;
1386
+ continue;
1387
+ }
1388
+ if (arg === "--config-path") {
1389
+ i += 1;
1390
+ continue;
1391
+ }
1327
1392
  if (arg === "--system-prompt") {
1328
1393
  const config = (current.config ?? {});
1329
1394
  config.system_prompt = args[++i] ?? "";
@@ -1339,21 +1404,28 @@ async function runAgentUpdateCommand(args) {
1339
1404
  continue;
1340
1405
  }
1341
1406
  }
1342
- // 如果指定了 --knowledge-network-id,更新 data_source.knowledge_network
1407
+ // Update config.data_source.knowledge_network when requested.
1343
1408
  if (knowledgeNetworkId) {
1344
1409
  const config = (current.config ?? {});
1345
1410
  const dataSource = (config.data_source ?? {});
1346
- // 获取知识网络名称(如果需要的话,可以查询BKN获取)
1347
1411
  const knowledgeNetwork = [
1348
1412
  {
1349
1413
  knowledge_network_id: knowledgeNetworkId,
1350
- knowledge_network_name: "", // 可选:通过BKN API获取名称
1351
1414
  },
1352
1415
  ];
1353
1416
  dataSource.knowledge_network = knowledgeNetwork;
1354
1417
  config.data_source = dataSource;
1355
1418
  current.config = config;
1356
1419
  }
1420
+ const config = (current.config ?? {});
1421
+ try {
1422
+ applyAgentModeToConfig(config, explicitMode);
1423
+ }
1424
+ catch (error) {
1425
+ console.error(error instanceof Error ? error.message : String(error));
1426
+ return 1;
1427
+ }
1428
+ current.config = config;
1357
1429
  const body = await updateAgent({
1358
1430
  baseUrl: token.baseUrl,
1359
1431
  accessToken: token.accessToken,
@@ -1601,12 +1673,12 @@ Options:
1601
1673
  businessDomain: options.businessDomain,
1602
1674
  });
1603
1675
  if (body) {
1604
- // 如果指定了 --save-config,保存 config 到文件(带时间戳)
1676
+ // Save only the template config object when --save-config is provided.
1605
1677
  if (options.saveConfig) {
1606
1678
  const parsed = JSON.parse(body);
1607
1679
  const config = parsed.config ?? {};
1608
1680
  const timestampedPath = generateTimestampedPath(options.saveConfig);
1609
- // 确保目录存在
1681
+ // Ensure the output directory exists.
1610
1682
  const dir = dirname(timestampedPath);
1611
1683
  await fs.mkdir(dir, { recursive: true });
1612
1684
  await fs.writeFile(timestampedPath, JSON.stringify(config, null, 2), "utf-8");