jinzd-ai-cli 0.4.180 → 0.4.181
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{batch-OJJI6TKB.js → batch-DG5STMLZ.js} +2 -2
- package/dist/{chunk-WY2DDJTH.js → chunk-4VB6UP4W.js} +1 -1
- package/dist/{chunk-2TWARH5X.js → chunk-5LK7H45B.js} +331 -22
- package/dist/{chunk-FQHEXIYP.js → chunk-6SY45V62.js} +2 -2
- package/dist/{chunk-KRU4DFRH.js → chunk-CPZ7KG3Y.js} +1 -1
- package/dist/{chunk-H7TXZO6D.js → chunk-D4ZTYYBU.js} +1 -1
- package/dist/{chunk-YDI22R3P.js → chunk-D774AWKW.js} +1 -1
- package/dist/{chunk-7WFMYFHC.js → chunk-ORXPLVM7.js} +3 -3
- package/dist/{chunk-2UGK2RXK.js → chunk-P2VFMUR5.js} +1 -1
- package/dist/{chunk-ZUUXMR6Z.js → chunk-ZWQ36YFI.js} +1 -1
- package/dist/{ci-EBN6VQ2Z.js → ci-UXVUG3LC.js} +3 -3
- package/dist/{constants-FGPUBYCX.js → constants-5DFFSPWI.js} +1 -1
- package/dist/{doctor-cli-C54OKMG2.js → doctor-cli-GQBR6RI6.js} +5 -5
- package/dist/electron-server.js +380 -182
- package/dist/{hub-YVNTGDKW.js → hub-N75OQVNY.js} +1 -1
- package/dist/index.js +100 -317
- package/dist/{run-tests-QFTKAWW6.js → run-tests-673ABQQE.js} +2 -2
- package/dist/{run-tests-BUII3HBU.js → run-tests-HZVKHQ33.js} +1 -1
- package/dist/{server-I6Y5TP2Z.js → server-RCUIX4R5.js} +4 -4
- package/dist/{server-KT6GRCM7.js → server-SLDE3AML.js} +77 -167
- package/dist/{task-orchestrator-6RLY5JAL.js → task-orchestrator-42D5LBAX.js} +4 -4
- package/package.json +1 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
ToolRegistry
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-ORXPLVM7.js";
|
|
5
5
|
import "./chunk-HDSKW7Q3.js";
|
|
6
6
|
import "./chunk-ZWVIDFGY.js";
|
|
7
|
-
import "./chunk-
|
|
7
|
+
import "./chunk-D4ZTYYBU.js";
|
|
8
8
|
import {
|
|
9
9
|
runTool
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-4VB6UP4W.js";
|
|
11
11
|
import {
|
|
12
12
|
getDangerLevel,
|
|
13
13
|
schemaToJsonSchema
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
import "./chunk-TZQHYZKT.js";
|
|
16
16
|
import {
|
|
17
17
|
VERSION
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-CPZ7KG3Y.js";
|
|
19
19
|
import "./chunk-4BKXL7SM.js";
|
|
20
20
|
import "./chunk-MM3F43H6.js";
|
|
21
21
|
import "./chunk-KHYD3WXE.js";
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
loadDevState,
|
|
22
22
|
persistToolRound,
|
|
23
23
|
setupProxy
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-6SY45V62.js";
|
|
25
25
|
import {
|
|
26
26
|
ToolExecutor,
|
|
27
27
|
ToolRegistry,
|
|
@@ -39,20 +39,29 @@ import {
|
|
|
39
39
|
spawnAgentContext,
|
|
40
40
|
truncateOutput,
|
|
41
41
|
undoStack
|
|
42
|
-
} from "./chunk-
|
|
42
|
+
} from "./chunk-ORXPLVM7.js";
|
|
43
43
|
import "./chunk-HDSKW7Q3.js";
|
|
44
44
|
import "./chunk-ZWVIDFGY.js";
|
|
45
|
-
import "./chunk-
|
|
45
|
+
import "./chunk-D4ZTYYBU.js";
|
|
46
46
|
import {
|
|
47
47
|
SessionManager,
|
|
48
48
|
getContentText
|
|
49
49
|
} from "./chunk-RIVZNS3K.js";
|
|
50
50
|
import {
|
|
51
|
+
BudgetWarner,
|
|
51
52
|
CONTENT_ONLY_STREAM_REMINDER,
|
|
53
|
+
ContextPressureMonitor,
|
|
54
|
+
EmptyResponseGuard,
|
|
55
|
+
FreeRoundTracker,
|
|
52
56
|
HALLUCINATION_CORRECTION_MESSAGE,
|
|
53
57
|
ProviderRegistry,
|
|
54
58
|
TEE_FINAL_USER_NUDGE,
|
|
55
59
|
TOOL_CALL_REMINDER,
|
|
60
|
+
accumulateUsage,
|
|
61
|
+
buildRoundBudgetHint,
|
|
62
|
+
buildRoundsExhaustedPrompt,
|
|
63
|
+
buildUserStopMessage,
|
|
64
|
+
consumeToolCallStream,
|
|
56
65
|
detectMetaNarration,
|
|
57
66
|
detectPseudoToolCalls,
|
|
58
67
|
detectsHallucinatedFileOp,
|
|
@@ -60,17 +69,18 @@ import {
|
|
|
60
69
|
hadPreviousWriteToolCalls,
|
|
61
70
|
looksLikeDocumentBody,
|
|
62
71
|
stripPseudoToolCalls,
|
|
63
|
-
stripToolCallReminder
|
|
64
|
-
|
|
72
|
+
stripToolCallReminder,
|
|
73
|
+
summarizeRecentTools
|
|
74
|
+
} from "./chunk-5LK7H45B.js";
|
|
65
75
|
import {
|
|
66
76
|
runTool
|
|
67
|
-
} from "./chunk-
|
|
77
|
+
} from "./chunk-4VB6UP4W.js";
|
|
68
78
|
import {
|
|
69
79
|
getDangerLevel
|
|
70
80
|
} from "./chunk-HIU2SH4V.js";
|
|
71
81
|
import {
|
|
72
82
|
ConfigManager
|
|
73
|
-
} from "./chunk-
|
|
83
|
+
} from "./chunk-P2VFMUR5.js";
|
|
74
84
|
import "./chunk-TZQHYZKT.js";
|
|
75
85
|
import {
|
|
76
86
|
AGENTIC_BEHAVIOR_GUIDELINE,
|
|
@@ -90,7 +100,7 @@ import {
|
|
|
90
100
|
SKILLS_DIR_NAME,
|
|
91
101
|
VERSION,
|
|
92
102
|
buildUserIdentityPrompt
|
|
93
|
-
} from "./chunk-
|
|
103
|
+
} from "./chunk-CPZ7KG3Y.js";
|
|
94
104
|
import {
|
|
95
105
|
formatGitContextForPrompt,
|
|
96
106
|
getGitContext,
|
|
@@ -516,8 +526,6 @@ function loadMemoryContent(configDir) {
|
|
|
516
526
|
import { existsSync as existsSync3, readFileSync as readFileSync3, appendFileSync, writeFileSync, mkdirSync, readdirSync, statSync, createWriteStream, unlinkSync } from "fs";
|
|
517
527
|
import { join as join2, resolve, dirname } from "path";
|
|
518
528
|
import { execSync } from "child_process";
|
|
519
|
-
var FREE_ROUND_TOOLS = /* @__PURE__ */ new Set(["write_todos"]);
|
|
520
|
-
var MAX_CONSECUTIVE_FREE_ROUNDS = 5;
|
|
521
529
|
var SessionHandler = class _SessionHandler {
|
|
522
530
|
ws;
|
|
523
531
|
config;
|
|
@@ -1002,15 +1010,7 @@ var SessionHandler = class _SessionHandler {
|
|
|
1002
1010
|
const autoPauseIntervalRaw = this.config.get("autoPauseInterval");
|
|
1003
1011
|
const autoPauseInterval = typeof autoPauseIntervalRaw === "number" ? autoPauseIntervalRaw : 50;
|
|
1004
1012
|
const { stable: toolStable, volatile: toolVolatile } = this.buildSystemPrompt();
|
|
1005
|
-
const
|
|
1006
|
-
- Every ${autoPauseInterval} rounds the user will be asked whether to continue \u2014 use this as a natural checkpoint to report progress.` : "";
|
|
1007
|
-
const roundBudgetHint = `
|
|
1008
|
-
|
|
1009
|
-
[Tool Round Budget]
|
|
1010
|
-
You have a maximum of ${maxToolRounds} tool call rounds for this task. Plan efficiently:
|
|
1011
|
-
- Prefer batch operations (e.g. global find-and-replace) over repetitive single edits.
|
|
1012
|
-
- Prioritize the most critical tasks first in case rounds run out.
|
|
1013
|
-
- When remaining rounds are low, focus on completing the current task and summarizing.${pauseHint}`;
|
|
1013
|
+
const roundBudgetHint = buildRoundBudgetHint({ maxToolRounds, autoPauseInterval });
|
|
1014
1014
|
const systemPrompt = toolStable + TOOL_CALL_REMINDER + roundBudgetHint + (mcpBudgetNote ? `
|
|
1015
1015
|
|
|
1016
1016
|
${mcpBudgetNote}` : "");
|
|
@@ -1018,18 +1018,11 @@ ${mcpBudgetNote}` : "");
|
|
|
1018
1018
|
const modelParams = this.getModelParams();
|
|
1019
1019
|
const roundUsage = { inputTokens: 0, outputTokens: 0, cacheCreationTokens: 0, cacheReadTokens: 0 };
|
|
1020
1020
|
const supportsStreamingTools = typeof provider.chatWithToolsStream === "function";
|
|
1021
|
-
let consecutiveFreeRounds = 0;
|
|
1022
1021
|
const roundToolHistory = [];
|
|
1023
|
-
const
|
|
1024
|
-
const
|
|
1025
|
-
const
|
|
1026
|
-
const
|
|
1027
|
-
const warnCriticalEff = Math.min(warnCriticalAt, warnLowEff - 1);
|
|
1028
|
-
let warnedNote = false;
|
|
1029
|
-
let warnedLow = false;
|
|
1030
|
-
let warnedCritical = false;
|
|
1031
|
-
let emptyResponseRetries = 0;
|
|
1032
|
-
let warnedCtx80 = false;
|
|
1022
|
+
const budgetWarner = new BudgetWarner(maxToolRounds);
|
|
1023
|
+
const emptyGuard = new EmptyResponseGuard();
|
|
1024
|
+
const ctxMonitor = new ContextPressureMonitor();
|
|
1025
|
+
const freeRounds = new FreeRoundTracker();
|
|
1033
1026
|
const ac = new AbortController();
|
|
1034
1027
|
this.abortController = ac;
|
|
1035
1028
|
try {
|
|
@@ -1037,27 +1030,12 @@ ${mcpBudgetNote}` : "");
|
|
|
1037
1030
|
if (ac.signal.aborted) break;
|
|
1038
1031
|
this.toolExecutor.setRoundInfo(round + 1, maxToolRounds);
|
|
1039
1032
|
this.send({ type: "round_progress", current: round + 1, total: maxToolRounds });
|
|
1040
|
-
const
|
|
1041
|
-
if (
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
});
|
|
1047
|
-
this.send({ type: "info", message: `\u{1F6A8} Critical: ${roundsLeft} rounds remaining` });
|
|
1048
|
-
} else if (!warnedLow && roundsLeft <= warnLowEff) {
|
|
1049
|
-
warnedLow = true;
|
|
1050
|
-
extraMessages.push({
|
|
1051
|
-
role: "user",
|
|
1052
|
-
content: `\u26A0\uFE0F Budget warning: Only ${roundsLeft} tool rounds remaining. Prioritize completing the most critical task. If you cannot finish everything, summarize what's done and what remains.`
|
|
1053
|
-
});
|
|
1054
|
-
this.send({ type: "info", message: `\u26A0\uFE0F Low budget: ${roundsLeft} rounds remaining` });
|
|
1055
|
-
} else if (!warnedNote && roundsLeft <= warnNoteAt) {
|
|
1056
|
-
warnedNote = true;
|
|
1057
|
-
extraMessages.push({
|
|
1058
|
-
role: "user",
|
|
1059
|
-
content: `\u{1F4CA} Budget note: ${roundsLeft} tool rounds remaining out of ${maxToolRounds}. Plan your remaining work efficiently \u2014 use batch operations (e.g., replaceAll) when possible.`
|
|
1060
|
-
});
|
|
1033
|
+
const budgetWarning = budgetWarner.check(maxToolRounds - round);
|
|
1034
|
+
if (budgetWarning) {
|
|
1035
|
+
extraMessages.push({ role: "user", content: budgetWarning.injectMessage });
|
|
1036
|
+
if (budgetWarning.displayMessage) {
|
|
1037
|
+
this.send({ type: "info", message: budgetWarning.displayMessage });
|
|
1038
|
+
}
|
|
1061
1039
|
}
|
|
1062
1040
|
if (this.userInterjection) {
|
|
1063
1041
|
const msg = this.userInterjection;
|
|
@@ -1068,11 +1046,11 @@ ${mcpBudgetNote}` : "");
|
|
|
1068
1046
|
const ctxWindow = this.getContextWindowSize();
|
|
1069
1047
|
if (ctxWindow > 0) {
|
|
1070
1048
|
const reqTokens = this.estimateRequestTokens(systemPrompt, extraMessages);
|
|
1071
|
-
const
|
|
1072
|
-
if (
|
|
1049
|
+
const pressure = ctxMonitor.check(reqTokens, ctxWindow);
|
|
1050
|
+
if (pressure.action === "abort") {
|
|
1073
1051
|
this.send({
|
|
1074
1052
|
type: "response_done",
|
|
1075
|
-
content: `\u26A0 Context at ${Math.round(
|
|
1053
|
+
content: `\u26A0 Context at ${Math.round(pressure.ratio * 100)}% of ${ctxWindow.toLocaleString()} tokens \u2014 aborting before API rejection.
|
|
1076
1054
|
|
|
1077
1055
|
Too much tool output accumulated this turn. Your work so far is preserved.
|
|
1078
1056
|
|
|
@@ -1085,16 +1063,12 @@ Too much tool output accumulated this turn. Your work so far is preserved.
|
|
|
1085
1063
|
this.addWebSessionUsage(roundUsage);
|
|
1086
1064
|
session.addTokenUsage(roundUsage);
|
|
1087
1065
|
return;
|
|
1088
|
-
} else if (
|
|
1089
|
-
warnedCtx80 = true;
|
|
1066
|
+
} else if (pressure.action === "warn") {
|
|
1090
1067
|
this.send({
|
|
1091
1068
|
type: "info",
|
|
1092
|
-
message: `\u26A0 Context at ${Math.round(
|
|
1093
|
-
});
|
|
1094
|
-
extraMessages.push({
|
|
1095
|
-
role: "user",
|
|
1096
|
-
content: `\u26A0\uFE0F Context pressure: ~${Math.round(reqRatio * 100)}% of the ${ctxWindow.toLocaleString()}-token context window is used. Avoid reading more files or running broad scans. Finish the current critical step, then produce a final summary. Every unnecessary tool call now risks breaking the conversation.`
|
|
1069
|
+
message: `\u26A0 Context at ${Math.round(pressure.ratio * 100)}% \u2014 asking AI to wrap up`
|
|
1097
1070
|
});
|
|
1071
|
+
extraMessages.push({ role: "user", content: pressure.injectMessage });
|
|
1098
1072
|
}
|
|
1099
1073
|
}
|
|
1100
1074
|
const chatRequest = {
|
|
@@ -1142,37 +1116,29 @@ Details: ${errMsg.split("\n")[0]}
|
|
|
1142
1116
|
throw providerErr;
|
|
1143
1117
|
}
|
|
1144
1118
|
if (ac.signal.aborted) break;
|
|
1145
|
-
|
|
1146
|
-
roundUsage.inputTokens += result.usage.inputTokens;
|
|
1147
|
-
roundUsage.outputTokens += result.usage.outputTokens;
|
|
1148
|
-
roundUsage.cacheCreationTokens += result.usage.cacheCreationTokens ?? 0;
|
|
1149
|
-
roundUsage.cacheReadTokens += result.usage.cacheReadTokens ?? 0;
|
|
1150
|
-
}
|
|
1119
|
+
accumulateUsage(roundUsage, result.usage);
|
|
1151
1120
|
const hasToolCalls = !!(result.toolCalls && result.toolCalls.length > 0);
|
|
1152
1121
|
const contentBlank = !result.content || result.content.trim() === "";
|
|
1153
1122
|
if (!hasToolCalls && contentBlank) {
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
this.send({
|
|
1157
|
-
|
|
1158
|
-
message: "\u26A0 AI returned an empty response. Nudging to continue..."
|
|
1159
|
-
});
|
|
1160
|
-
extraMessages.push({
|
|
1161
|
-
role: "user",
|
|
1162
|
-
content: "Your previous response was empty \u2014 no text and no tool calls. This usually means the context window is nearly full. Please either: (1) continue the task by calling the next tool you need, or (2) give a concise final text summary of what has been accomplished so far and what remains. Do NOT repeat earlier long outputs."
|
|
1163
|
-
});
|
|
1123
|
+
const decision = emptyGuard.onEmpty(round < maxToolRounds - 1, result.finishReason);
|
|
1124
|
+
if (decision.action === "nudge") {
|
|
1125
|
+
this.send({ type: "info", message: decision.displayMessage });
|
|
1126
|
+
extraMessages.push({ role: "user", content: decision.injectMessage });
|
|
1164
1127
|
continue;
|
|
1165
1128
|
}
|
|
1166
1129
|
this.send({
|
|
1167
1130
|
type: "response_done",
|
|
1168
|
-
content:
|
|
1131
|
+
content: `${decision.displayMessage}
|
|
1132
|
+
|
|
1133
|
+
${decision.hint}
|
|
1134
|
+
Try: /compact to reduce context, /clear to reset, or switch to a larger-context model.`,
|
|
1169
1135
|
usage: roundUsage
|
|
1170
1136
|
});
|
|
1171
1137
|
this.addWebSessionUsage(roundUsage);
|
|
1172
1138
|
session.addTokenUsage(roundUsage);
|
|
1173
1139
|
return;
|
|
1174
1140
|
}
|
|
1175
|
-
|
|
1141
|
+
emptyGuard.onNonEmpty();
|
|
1176
1142
|
if (result.content && !result.toolCalls) {
|
|
1177
1143
|
const hasWriteTools = toolDefs.some((t) => t.name === "write_file" || t.name === "edit_file");
|
|
1178
1144
|
const alreadyWrote = hadPreviousWriteToolCalls(extraMessages);
|
|
@@ -1252,7 +1218,7 @@ ${systemPromptVolatile}` : systemPrompt;
|
|
|
1252
1218
|
assistantContent: teeResult.content,
|
|
1253
1219
|
reasoningContent: reasoningContent2
|
|
1254
1220
|
});
|
|
1255
|
-
|
|
1221
|
+
freeRounds.apply(result.toolCalls.map((tc) => tc.name));
|
|
1256
1222
|
continue;
|
|
1257
1223
|
}
|
|
1258
1224
|
const toolResults = await this.toolExecutor.executeAll(result.toolCalls);
|
|
@@ -1263,14 +1229,8 @@ ${systemPromptVolatile}` : systemPrompt;
|
|
|
1263
1229
|
assistantContent: result.content,
|
|
1264
1230
|
reasoningContent
|
|
1265
1231
|
});
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
consecutiveFreeRounds++;
|
|
1269
|
-
if (consecutiveFreeRounds <= MAX_CONSECUTIVE_FREE_ROUNDS) {
|
|
1270
|
-
round--;
|
|
1271
|
-
}
|
|
1272
|
-
} else {
|
|
1273
|
-
consecutiveFreeRounds = 0;
|
|
1232
|
+
if (freeRounds.apply(result.toolCalls.map((tc) => tc.name))) {
|
|
1233
|
+
round--;
|
|
1274
1234
|
}
|
|
1275
1235
|
if (this.userInterjection) {
|
|
1276
1236
|
const msg = this.userInterjection;
|
|
@@ -1282,12 +1242,7 @@ ${systemPromptVolatile}` : systemPrompt;
|
|
|
1282
1242
|
const effectiveRound = round + 1;
|
|
1283
1243
|
const remaining = maxToolRounds - effectiveRound;
|
|
1284
1244
|
if (autoPauseInterval > 0 && effectiveRound > 0 && effectiveRound % autoPauseInterval === 0 && remaining > 0 && !ac.signal.aborted) {
|
|
1285
|
-
const
|
|
1286
|
-
const toolCounts = /* @__PURE__ */ new Map();
|
|
1287
|
-
for (const rh of recentHistory) {
|
|
1288
|
-
for (const t of rh.tools) toolCounts.set(t, (toolCounts.get(t) || 0) + 1);
|
|
1289
|
-
}
|
|
1290
|
-
const toolSummary = [...toolCounts.entries()].sort((a, b) => b[1] - a[1]).map(([name, count]) => count > 1 ? `${name}\xD7${count}` : name).join(", ");
|
|
1245
|
+
const toolSummary = summarizeRecentTools(roundToolHistory, autoPauseInterval);
|
|
1291
1246
|
const requestId = `pause_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
|
|
1292
1247
|
const pauseResp = await new Promise((resolve3) => {
|
|
1293
1248
|
this.pendingAutoPause.set(requestId, resolve3);
|
|
@@ -1302,10 +1257,7 @@ ${systemPromptVolatile}` : systemPrompt;
|
|
|
1302
1257
|
if (ac.signal.aborted) break;
|
|
1303
1258
|
if (pauseResp.action === "stop") {
|
|
1304
1259
|
this.send({ type: "info", message: `\u23F8 Stopped by user at ${effectiveRound}/${maxToolRounds}` });
|
|
1305
|
-
extraMessages.push({
|
|
1306
|
-
role: "user",
|
|
1307
|
-
content: `The user has stopped the task at round ${effectiveRound}/${maxToolRounds}. Do not call any more tools. Summarize what has been completed and what remains.`
|
|
1308
|
-
});
|
|
1260
|
+
extraMessages.push({ role: "user", content: buildUserStopMessage(effectiveRound, maxToolRounds) });
|
|
1309
1261
|
break;
|
|
1310
1262
|
} else if (pauseResp.action === "redirect" && pauseResp.message) {
|
|
1311
1263
|
this.send({ type: "info", message: `\u26A1 Redirect: "${pauseResp.message}"` });
|
|
@@ -1316,13 +1268,7 @@ ${systemPromptVolatile}` : systemPrompt;
|
|
|
1316
1268
|
try {
|
|
1317
1269
|
const summaryExtra = [
|
|
1318
1270
|
...extraMessages,
|
|
1319
|
-
{
|
|
1320
|
-
role: "user",
|
|
1321
|
-
content: `You have used all ${maxToolRounds} tool call rounds. Do not call any more tools. Summarize in text:
|
|
1322
|
-
1. What work has been completed so far
|
|
1323
|
-
2. What tasks remain unfinished
|
|
1324
|
-
3. What the user can do next`
|
|
1325
|
-
}
|
|
1271
|
+
{ role: "user", content: buildRoundsExhaustedPrompt(maxToolRounds) }
|
|
1326
1272
|
];
|
|
1327
1273
|
const summaryResult = await provider.chatWithTools(
|
|
1328
1274
|
{
|
|
@@ -1509,69 +1455,33 @@ This fresh stream has NO tools. Produce ONLY the document body: start with a mar
|
|
|
1509
1455
|
});
|
|
1510
1456
|
return { content: fullContent, summary, isError };
|
|
1511
1457
|
}
|
|
1512
|
-
/**
|
|
1458
|
+
/**
|
|
1459
|
+
* Consume streaming tool call events and forward to client.
|
|
1460
|
+
*
|
|
1461
|
+
* v0.4.181: 委托给 core/agent-loop 的统一消费器(与 REPL 同一实现)。
|
|
1462
|
+
* Web 端由此获得三个此前只在 REPL 修过的行为:内联 <think> 折叠
|
|
1463
|
+
* (MiniMax 推理泄漏不再渲染进浏览器)、截断 JSON 自动修复、
|
|
1464
|
+
* 工具调用按 event.index 键累积(稀疏 index 不错位)。
|
|
1465
|
+
*/
|
|
1513
1466
|
async consumeToolStream(streamGen, ac) {
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
this.send({ type: "text_delta", delta: event.delta });
|
|
1526
|
-
break;
|
|
1527
|
-
case "thinking_start":
|
|
1528
|
-
this.send({ type: "thinking_start" });
|
|
1529
|
-
break;
|
|
1530
|
-
case "thinking_delta":
|
|
1531
|
-
this.send({ type: "thinking_delta", delta: event.delta });
|
|
1532
|
-
break;
|
|
1533
|
-
case "thinking_end":
|
|
1534
|
-
this.send({ type: "thinking_end" });
|
|
1535
|
-
break;
|
|
1536
|
-
case "tool_call_start":
|
|
1537
|
-
toolArgBuffers.set(event.index, "");
|
|
1538
|
-
this.send({ type: "info", message: `\u2699 Streaming: ${event.name}...` });
|
|
1539
|
-
toolCalls.push({ id: event.id, name: event.name, arguments: {} });
|
|
1540
|
-
break;
|
|
1541
|
-
case "tool_call_delta": {
|
|
1542
|
-
const buf = (toolArgBuffers.get(event.index) ?? "") + event.argumentsDelta;
|
|
1543
|
-
toolArgBuffers.set(event.index, buf);
|
|
1544
|
-
break;
|
|
1545
|
-
}
|
|
1546
|
-
case "tool_call_end": {
|
|
1547
|
-
const tc = toolCalls.find((_, i) => i === event.index);
|
|
1548
|
-
const argStr = toolArgBuffers.get(event.index) ?? "{}";
|
|
1549
|
-
if (tc) {
|
|
1550
|
-
try {
|
|
1551
|
-
tc.arguments = JSON.parse(argStr);
|
|
1552
|
-
} catch {
|
|
1553
|
-
tc.arguments = { _raw: argStr };
|
|
1554
|
-
}
|
|
1555
|
-
}
|
|
1556
|
-
break;
|
|
1557
|
-
}
|
|
1558
|
-
case "done":
|
|
1559
|
-
if (event.usage) usage = event.usage;
|
|
1560
|
-
if (event.rawContent) rawContent = event.rawContent;
|
|
1561
|
-
if (event.reasoningContent) reasoningContent = event.reasoningContent;
|
|
1562
|
-
break;
|
|
1563
|
-
}
|
|
1564
|
-
}
|
|
1565
|
-
if (toolCalls.length > 0) {
|
|
1566
|
-
if (rawContent) {
|
|
1567
|
-
toolCalls._rawContent = rawContent;
|
|
1568
|
-
}
|
|
1569
|
-
if (textContent) {
|
|
1570
|
-
toolCalls._streamedText = textContent;
|
|
1571
|
-
}
|
|
1572
|
-
return { toolCalls, usage, reasoningContent };
|
|
1467
|
+
const result = await consumeToolCallStream(streamGen, {
|
|
1468
|
+
signal: ac.signal,
|
|
1469
|
+
onText: (visible) => this.send({ type: "text_delta", delta: visible }),
|
|
1470
|
+
onThinkingStart: () => this.send({ type: "thinking_start" }),
|
|
1471
|
+
onThinkingDelta: (delta) => this.send({ type: "thinking_delta", delta }),
|
|
1472
|
+
onThinkingEnd: () => this.send({ type: "thinking_end" }),
|
|
1473
|
+
onToolCallStart: (_index, _id, name) => this.send({ type: "info", message: `\u2699 Streaming: ${name}...` }),
|
|
1474
|
+
onWarn: (message) => this.send({ type: "info", message: `\u26A0 ${message}` })
|
|
1475
|
+
});
|
|
1476
|
+
if (result.toolCalls.length > 0) {
|
|
1477
|
+
return { toolCalls: result.toolCalls, usage: result.usage, reasoningContent: result.reasoningContent };
|
|
1573
1478
|
}
|
|
1574
|
-
return {
|
|
1479
|
+
return {
|
|
1480
|
+
content: result.textContent,
|
|
1481
|
+
usage: result.usage,
|
|
1482
|
+
reasoningContent: result.reasoningContent,
|
|
1483
|
+
finishReason: result.finishReason
|
|
1484
|
+
};
|
|
1575
1485
|
}
|
|
1576
1486
|
// ── Commands ─────────────────────────────────────────────────────
|
|
1577
1487
|
async handleCommand(name, args) {
|
|
@@ -2577,7 +2487,7 @@ ${undoResults.map((r) => ` \u2022 ${r}`).join("\n")}` });
|
|
|
2577
2487
|
case "test": {
|
|
2578
2488
|
this.send({ type: "info", message: "\u{1F9EA} Running tests..." });
|
|
2579
2489
|
try {
|
|
2580
|
-
const { executeTests } = await import("./run-tests-
|
|
2490
|
+
const { executeTests } = await import("./run-tests-673ABQQE.js");
|
|
2581
2491
|
const argStr = args.join(" ").trim();
|
|
2582
2492
|
let testArgs = {};
|
|
2583
2493
|
if (argStr) {
|
|
@@ -3,20 +3,20 @@ import {
|
|
|
3
3
|
ToolRegistry,
|
|
4
4
|
googleSearchContext,
|
|
5
5
|
truncateOutput
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-ORXPLVM7.js";
|
|
7
7
|
import "./chunk-HDSKW7Q3.js";
|
|
8
8
|
import "./chunk-ZWVIDFGY.js";
|
|
9
|
-
import "./chunk-
|
|
9
|
+
import "./chunk-D4ZTYYBU.js";
|
|
10
10
|
import {
|
|
11
11
|
runTool
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-4VB6UP4W.js";
|
|
13
13
|
import {
|
|
14
14
|
getDangerLevel
|
|
15
15
|
} from "./chunk-HIU2SH4V.js";
|
|
16
16
|
import "./chunk-TZQHYZKT.js";
|
|
17
17
|
import {
|
|
18
18
|
SUBAGENT_ALLOWED_TOOLS
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-CPZ7KG3Y.js";
|
|
20
20
|
import "./chunk-4BKXL7SM.js";
|
|
21
21
|
import "./chunk-MM3F43H6.js";
|
|
22
22
|
import "./chunk-KHYD3WXE.js";
|