@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.
- package/README.md +19 -5
- package/README.zh.md +19 -5
- package/dist/agent-providers/index.d.ts +7 -0
- package/dist/agent-providers/index.js +5 -0
- package/dist/agent-providers/prompt-template.d.ts +62 -0
- package/dist/agent-providers/prompt-template.js +105 -0
- package/dist/agent-providers/prompts/rubric-judge-v1.prompt.md +51 -0
- package/dist/agent-providers/prompts/within-trace-synthesizer-v1.prompt.md +60 -0
- package/dist/agent-providers/providers/claude-code-subprocess.d.ts +74 -0
- package/dist/agent-providers/providers/claude-code-subprocess.js +259 -0
- package/dist/agent-providers/providers/stub.d.ts +47 -0
- package/dist/agent-providers/providers/stub.js +77 -0
- package/dist/agent-providers/registry.d.ts +45 -0
- package/dist/agent-providers/registry.js +77 -0
- package/dist/agent-providers/types.d.ts +91 -0
- package/dist/agent-providers/types.js +25 -0
- package/dist/api/agent-chat.js +8 -6
- package/dist/api/context-loader.d.ts +1 -0
- package/dist/api/semantic-search.d.ts +5 -0
- package/dist/api/semantic-search.js +5 -0
- package/dist/api/skills.d.ts +75 -2
- package/dist/api/skills.js +108 -12
- package/dist/api/trace.d.ts +5 -0
- package/dist/api/trace.js +4 -0
- package/dist/cli.js +7 -5
- package/dist/commands/agent/mode.d.ts +6 -0
- package/dist/commands/agent/mode.js +75 -0
- package/dist/commands/agent.js +101 -29
- package/dist/commands/context-loader.js +608 -38
- package/dist/commands/skill.d.ts +21 -1
- package/dist/commands/skill.js +389 -1
- package/dist/commands/trace.d.ts +26 -1
- package/dist/commands/trace.js +515 -15
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/resources/bkn.d.ts +5 -0
- package/dist/resources/bkn.js +5 -0
- package/dist/resources/skills.d.ts +17 -1
- package/dist/resources/skills.js +32 -1
- package/dist/trace-ai/diagnose/agent-binding.d.ts +67 -0
- package/dist/trace-ai/diagnose/agent-binding.js +257 -0
- package/dist/trace-ai/diagnose/builtin-rules/tool-retry-intent-mismatch.yaml +68 -0
- package/dist/trace-ai/diagnose/index.d.ts +32 -0
- package/dist/trace-ai/diagnose/index.js +246 -0
- package/dist/trace-ai/diagnose/output-schema-converter.d.ts +24 -0
- package/dist/trace-ai/diagnose/output-schema-converter.js +81 -0
- package/dist/trace-ai/diagnose/query-extractor.d.ts +14 -0
- package/dist/trace-ai/diagnose/query-extractor.js +45 -0
- package/dist/trace-ai/diagnose/report-assembler.d.ts +31 -0
- package/dist/{trace-core → trace-ai}/diagnose/report-assembler.js +19 -9
- package/dist/trace-ai/diagnose/report-markdown.d.ts +18 -0
- package/dist/trace-ai/diagnose/report-markdown.js +192 -0
- package/dist/{trace-core → trace-ai}/diagnose/rule-loader.js +42 -8
- package/dist/{trace-core → trace-ai}/diagnose/schemas.d.ts +77 -2
- package/dist/trace-ai/diagnose/schemas.js +154 -0
- package/dist/trace-ai/diagnose/signal-probe.d.ts +17 -0
- package/dist/trace-ai/diagnose/signal-probe.js +39 -0
- package/dist/trace-ai/diagnose/synthesizer-agent.d.ts +40 -0
- package/dist/trace-ai/diagnose/synthesizer-agent.js +158 -0
- package/dist/{trace-core → trace-ai}/diagnose/trace-shaper.js +1 -0
- package/dist/{trace-core → trace-ai}/diagnose/types.d.ts +55 -6
- package/dist/trace-ai/eval-set/assertion-evaluator.d.ts +29 -0
- package/dist/trace-ai/eval-set/assertion-evaluator.js +100 -0
- package/dist/trace-ai/eval-set/builder.d.ts +36 -0
- package/dist/trace-ai/eval-set/builder.js +126 -0
- package/dist/trace-ai/eval-set/index.d.ts +15 -0
- package/dist/trace-ai/eval-set/index.js +10 -0
- package/dist/trace-ai/eval-set/output-writer.d.ts +27 -0
- package/dist/trace-ai/eval-set/output-writer.js +126 -0
- package/dist/trace-ai/eval-set/query-picker.d.ts +37 -0
- package/dist/trace-ai/eval-set/query-picker.js +147 -0
- package/dist/trace-ai/eval-set/redactor.d.ts +42 -0
- package/dist/trace-ai/eval-set/redactor.js +133 -0
- package/dist/trace-ai/eval-set/rubric-templates/answer-match-reference.prompt.md +19 -0
- package/dist/trace-ai/eval-set/schemas.d.ts +136 -0
- package/dist/trace-ai/eval-set/schemas.js +130 -0
- package/dist/trace-ai/eval-set/semantic-match-provider.d.ts +33 -0
- package/dist/trace-ai/eval-set/semantic-match-provider.js +51 -0
- package/dist/trace-ai/eval-set/test-runner.d.ts +34 -0
- package/dist/trace-ai/eval-set/test-runner.js +153 -0
- package/dist/trace-ai/eval-set/types.d.ts +46 -0
- package/dist/trace-ai/eval-set/types.js +8 -0
- package/dist/trace-ai/exp/bundle-writer.d.ts +10 -0
- package/dist/trace-ai/exp/bundle-writer.js +54 -0
- package/dist/trace-ai/exp/claude-binary.d.ts +5 -0
- package/dist/trace-ai/exp/claude-binary.js +30 -0
- package/dist/trace-ai/exp/coordinator.d.ts +45 -0
- package/dist/trace-ai/exp/coordinator.js +203 -0
- package/dist/trace-ai/exp/eval-runner.d.ts +14 -0
- package/dist/trace-ai/exp/eval-runner.js +47 -0
- package/dist/trace-ai/exp/exp-store/abort-signal.d.ts +3 -0
- package/dist/trace-ai/exp/exp-store/abort-signal.js +27 -0
- package/dist/trace-ai/exp/exp-store/candidate-lineage-yaml.d.ts +4 -0
- package/dist/trace-ai/exp/exp-store/candidate-lineage-yaml.js +37 -0
- package/dist/trace-ai/exp/exp-store/events-jsonl.d.ts +17 -0
- package/dist/trace-ai/exp/exp-store/events-jsonl.js +60 -0
- package/dist/trace-ai/exp/exp-store/exp-registry.d.ts +6 -0
- package/dist/trace-ai/exp/exp-store/exp-registry.js +41 -0
- package/dist/trace-ai/exp/exp-store/index.d.ts +46 -0
- package/dist/trace-ai/exp/exp-store/index.js +59 -0
- package/dist/trace-ai/exp/exp-store/lock.d.ts +3 -0
- package/dist/trace-ai/exp/exp-store/lock.js +73 -0
- package/dist/trace-ai/exp/exp-store/mission-md.d.ts +3 -0
- package/dist/trace-ai/exp/exp-store/mission-md.js +37 -0
- package/dist/trace-ai/exp/exp-store/readme-template.d.ts +5 -0
- package/dist/trace-ai/exp/exp-store/readme-template.js +25 -0
- package/dist/trace-ai/exp/exp-store/round-yaml.d.ts +3 -0
- package/dist/trace-ai/exp/exp-store/round-yaml.js +33 -0
- package/dist/trace-ai/exp/index.d.ts +8 -0
- package/dist/trace-ai/exp/index.js +238 -0
- package/dist/trace-ai/exp/info.d.ts +35 -0
- package/dist/trace-ai/exp/info.js +120 -0
- package/dist/trace-ai/exp/patch/agent-config.d.ts +1 -0
- package/dist/trace-ai/exp/patch/agent-config.js +26 -0
- package/dist/trace-ai/exp/patch/index.d.ts +2 -0
- package/dist/trace-ai/exp/patch/index.js +13 -0
- package/dist/trace-ai/exp/patch/skill.d.ts +1 -0
- package/dist/trace-ai/exp/patch/skill.js +24 -0
- package/dist/trace-ai/exp/providers/synthesizer-client.d.ts +14 -0
- package/dist/trace-ai/exp/providers/synthesizer-client.js +39 -0
- package/dist/trace-ai/exp/providers/triage-client.d.ts +19 -0
- package/dist/trace-ai/exp/providers/triage-client.js +51 -0
- package/dist/trace-ai/exp/schemas.d.ts +147 -0
- package/dist/trace-ai/exp/schemas.js +50 -0
- package/dist/trace-ai/exp/scoring.d.ts +2 -0
- package/dist/trace-ai/exp/scoring.js +46 -0
- package/dist/trace-ai/scan/aggregator.d.ts +20 -0
- package/dist/trace-ai/scan/aggregator.js +26 -0
- package/dist/trace-ai/scan/artifacts/paths.d.ts +12 -0
- package/dist/trace-ai/scan/artifacts/paths.js +18 -0
- package/dist/trace-ai/scan/artifacts/writer.d.ts +67 -0
- package/dist/trace-ai/scan/artifacts/writer.js +96 -0
- package/dist/trace-ai/scan/batched-rubric.d.ts +55 -0
- package/dist/trace-ai/scan/batched-rubric.js +159 -0
- package/dist/trace-ai/scan/cross-trace-synthesizer.d.ts +24 -0
- package/dist/trace-ai/scan/cross-trace-synthesizer.js +93 -0
- package/dist/trace-ai/scan/index.d.ts +31 -0
- package/dist/trace-ai/scan/index.js +390 -0
- package/dist/trace-ai/scan/prompts/builtin/cross-trace-synthesizer-v1.prompt.md +44 -0
- package/dist/trace-ai/scan/prompts/builtin/rubric-judge-batch-v1.prompt.md +44 -0
- package/dist/trace-ai/scan/runner.d.ts +25 -0
- package/dist/trace-ai/scan/runner.js +42 -0
- package/dist/trace-ai/scan/sampler.d.ts +18 -0
- package/dist/trace-ai/scan/sampler.js +81 -0
- package/dist/trace-ai/scan/scan-summary-markdown.d.ts +2 -0
- package/dist/trace-ai/scan/scan-summary-markdown.js +71 -0
- package/dist/trace-ai/scan/scan-summary-schema.d.ts +73 -0
- package/dist/trace-ai/scan/scan-summary-schema.js +61 -0
- package/dist/trace-ai/scan/single-agent-validator.d.ts +23 -0
- package/dist/trace-ai/scan/single-agent-validator.js +42 -0
- package/dist/trace-ai/scan/traces-list-parser.d.ts +15 -0
- package/dist/trace-ai/scan/traces-list-parser.js +46 -0
- package/package.json +2 -2
- package/dist/trace-core/diagnose/index.d.ts +0 -9
- package/dist/trace-core/diagnose/index.js +0 -104
- package/dist/trace-core/diagnose/report-assembler.d.ts +0 -12
- package/dist/trace-core/diagnose/schemas.js +0 -94
- package/dist/trace-core/diagnose/signal-probe.d.ts +0 -5
- package/dist/trace-core/diagnose/signal-probe.js +0 -21
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/excessive-tool-calls-per-turn.d.ts +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/excessive-tool-calls-per-turn.js +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/excessive-tool-calls-per-turn.yaml +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/llm-response-truncated-no-continue.d.ts +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/llm-response-truncated-no-continue.js +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/llm-response-truncated-no-continue.yaml +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/register.d.ts +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/register.js +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/retrieval-empty-no-fallback.d.ts +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/retrieval-empty-no-fallback.js +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/retrieval-empty-no-fallback.yaml +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/tool-error-swallowed.d.ts +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/tool-error-swallowed.js +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/tool-error-swallowed.yaml +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/tool-loop-no-state-change.d.ts +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/tool-loop-no-state-change.js +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/tool-loop-no-state-change.yaml +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/predicate-registry.d.ts +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/predicate-registry.js +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/rule-loader.d.ts +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/synthesizer-template.d.ts +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/synthesizer-template.js +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/trace-shaper.d.ts +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/types.js +0 -0
package/dist/commands/agent.js
CHANGED
|
@@ -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
|
-
//
|
|
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
|
-
//
|
|
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
|
|
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
|
-
//
|
|
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
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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");
|