snow-ai 0.5.27 → 0.5.28
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 +5 -1
- package/bundle/cli.mjs +1446 -346
- package/bundle/package.json +1 -1
- package/package.json +1 -1
package/bundle/cli.mjs
CHANGED
|
@@ -1421,7 +1421,7 @@ var require_react_development = __commonJS({
|
|
|
1421
1421
|
}
|
|
1422
1422
|
return dispatcher.useContext(Context);
|
|
1423
1423
|
}
|
|
1424
|
-
function
|
|
1424
|
+
function useState58(initialState) {
|
|
1425
1425
|
var dispatcher = resolveDispatcher();
|
|
1426
1426
|
return dispatcher.useState(initialState);
|
|
1427
1427
|
}
|
|
@@ -1433,7 +1433,7 @@ var require_react_development = __commonJS({
|
|
|
1433
1433
|
var dispatcher = resolveDispatcher();
|
|
1434
1434
|
return dispatcher.useRef(initialValue);
|
|
1435
1435
|
}
|
|
1436
|
-
function
|
|
1436
|
+
function useEffect52(create3, deps) {
|
|
1437
1437
|
var dispatcher = resolveDispatcher();
|
|
1438
1438
|
return dispatcher.useEffect(create3, deps);
|
|
1439
1439
|
}
|
|
@@ -2216,7 +2216,7 @@ var require_react_development = __commonJS({
|
|
|
2216
2216
|
exports2.useContext = useContext13;
|
|
2217
2217
|
exports2.useDebugValue = useDebugValue;
|
|
2218
2218
|
exports2.useDeferredValue = useDeferredValue;
|
|
2219
|
-
exports2.useEffect =
|
|
2219
|
+
exports2.useEffect = useEffect52;
|
|
2220
2220
|
exports2.useId = useId;
|
|
2221
2221
|
exports2.useImperativeHandle = useImperativeHandle2;
|
|
2222
2222
|
exports2.useInsertionEffect = useInsertionEffect;
|
|
@@ -2224,7 +2224,7 @@ var require_react_development = __commonJS({
|
|
|
2224
2224
|
exports2.useMemo = useMemo30;
|
|
2225
2225
|
exports2.useReducer = useReducer8;
|
|
2226
2226
|
exports2.useRef = useRef14;
|
|
2227
|
-
exports2.useState =
|
|
2227
|
+
exports2.useState = useState58;
|
|
2228
2228
|
exports2.useSyncExternalStore = useSyncExternalStore;
|
|
2229
2229
|
exports2.useTransition = useTransition;
|
|
2230
2230
|
exports2.version = ReactVersion;
|
|
@@ -9928,9 +9928,9 @@ var require_react_reconciler_development = __commonJS({
|
|
|
9928
9928
|
module2.exports = function $$$reconciler($$$hostConfig) {
|
|
9929
9929
|
var exports3 = {};
|
|
9930
9930
|
"use strict";
|
|
9931
|
-
var
|
|
9931
|
+
var React91 = require_react();
|
|
9932
9932
|
var Scheduler2 = require_scheduler();
|
|
9933
|
-
var ReactSharedInternals =
|
|
9933
|
+
var ReactSharedInternals = React91.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
9934
9934
|
var suppressWarning = false;
|
|
9935
9935
|
function setSuppressWarning(newSuppressWarning) {
|
|
9936
9936
|
{
|
|
@@ -42484,7 +42484,7 @@ var require_lib3 = __commonJS({
|
|
|
42484
42484
|
var gitHosts = require_git_host_info2();
|
|
42485
42485
|
var GitHost = module2.exports = require_git_host2();
|
|
42486
42486
|
var LRU = require_lru_cache2();
|
|
42487
|
-
var
|
|
42487
|
+
var parseUrl2 = require_parse_url();
|
|
42488
42488
|
var cache4 = new LRU({ max: 1e3 });
|
|
42489
42489
|
var protocols = {
|
|
42490
42490
|
"git+ssh:": { name: "sshurl" },
|
|
@@ -42509,13 +42509,13 @@ var require_lib3 = __commonJS({
|
|
|
42509
42509
|
}
|
|
42510
42510
|
return cache4.get(key);
|
|
42511
42511
|
};
|
|
42512
|
-
module2.exports.parseUrl =
|
|
42512
|
+
module2.exports.parseUrl = parseUrl2;
|
|
42513
42513
|
function fromUrl(giturl, opts) {
|
|
42514
42514
|
if (!giturl) {
|
|
42515
42515
|
return;
|
|
42516
42516
|
}
|
|
42517
42517
|
const correctedUrl = isGitHubShorthand(giturl) ? `github:${giturl}` : giturl;
|
|
42518
|
-
const parsed =
|
|
42518
|
+
const parsed = parseUrl2(correctedUrl, protocols);
|
|
42519
42519
|
if (!parsed) {
|
|
42520
42520
|
return;
|
|
42521
42521
|
}
|
|
@@ -81347,6 +81347,15 @@ var init_en = __esm({
|
|
|
81347
81347
|
statusFailed: "Failed",
|
|
81348
81348
|
navigationHint: "\u2191\u2193 Navigate \u2022 Enter Reconnect \u2022 Tab Toggle Service",
|
|
81349
81349
|
pleaseWait: "Please wait..."
|
|
81350
|
+
},
|
|
81351
|
+
sseServer: {
|
|
81352
|
+
started: "\u2713 SSE Server Started",
|
|
81353
|
+
port: "Port",
|
|
81354
|
+
workingDir: "Working Directory",
|
|
81355
|
+
running: "Running",
|
|
81356
|
+
endpoints: "Endpoints",
|
|
81357
|
+
logs: "Logs",
|
|
81358
|
+
stopHint: "Press Ctrl+C to stop server"
|
|
81350
81359
|
}
|
|
81351
81360
|
};
|
|
81352
81361
|
}
|
|
@@ -82351,6 +82360,15 @@ var init_zh = __esm({
|
|
|
82351
82360
|
statusFailed: "\u5931\u8D25",
|
|
82352
82361
|
navigationHint: "\u2191\u2193 \u5BFC\u822A \u2022 Enter \u91CD\u8FDE\u670D\u52A1 \u2022 Tab \u542F\u505C\u670D\u52A1",
|
|
82353
82362
|
pleaseWait: "\u8BF7\u7A0D\u5019..."
|
|
82363
|
+
},
|
|
82364
|
+
sseServer: {
|
|
82365
|
+
started: "\u2713 SSE \u670D\u52A1\u5668\u5DF2\u542F\u52A8",
|
|
82366
|
+
port: "\u7AEF\u53E3",
|
|
82367
|
+
workingDir: "\u5DE5\u4F5C\u76EE\u5F55",
|
|
82368
|
+
running: "\u8FD0\u884C\u4E2D",
|
|
82369
|
+
endpoints: "\u53EF\u7528\u7AEF\u70B9",
|
|
82370
|
+
logs: "\u8FD0\u884C\u65E5\u5FD7",
|
|
82371
|
+
stopHint: "\u6309 Ctrl+C \u505C\u6B62\u670D\u52A1\u5668"
|
|
82354
82372
|
}
|
|
82355
82373
|
};
|
|
82356
82374
|
}
|
|
@@ -83350,6 +83368,15 @@ var init_zh_TW = __esm({
|
|
|
83350
83368
|
statusFailed: "\u5931\u6557",
|
|
83351
83369
|
navigationHint: "\u2191\u2193 \u5C0E\u822A \u2022 Enter \u91CD\u65B0\u9023\u7DDA \u2022 Tab \u555F\u505C\u670D\u52D9",
|
|
83352
83370
|
pleaseWait: "\u8ACB\u7A0D\u5019..."
|
|
83371
|
+
},
|
|
83372
|
+
sseServer: {
|
|
83373
|
+
started: "\u2713 SSE \u4F3A\u670D\u5668\u5DF2\u555F\u52D5",
|
|
83374
|
+
port: "\u9023\u63A5\u57E0",
|
|
83375
|
+
workingDir: "\u5DE5\u4F5C\u76EE\u9304",
|
|
83376
|
+
running: "\u57F7\u884C\u4E2D",
|
|
83377
|
+
endpoints: "\u53EF\u7528\u7AEF\u9EDE",
|
|
83378
|
+
logs: "\u57F7\u884C\u65E5\u8A8C",
|
|
83379
|
+
stopHint: "\u6309 Ctrl+C \u505C\u6B62\u4F3A\u670D\u5668"
|
|
83353
83380
|
}
|
|
83354
83381
|
};
|
|
83355
83382
|
}
|
|
@@ -83433,6 +83460,11 @@ var init_languageConfig = __esm({
|
|
|
83433
83460
|
});
|
|
83434
83461
|
|
|
83435
83462
|
// dist/i18n/I18nContext.js
|
|
83463
|
+
var I18nContext_exports = {};
|
|
83464
|
+
__export(I18nContext_exports, {
|
|
83465
|
+
I18nProvider: () => I18nProvider,
|
|
83466
|
+
useI18n: () => useI18n
|
|
83467
|
+
});
|
|
83436
83468
|
function I18nProvider({ children, defaultLanguage }) {
|
|
83437
83469
|
const [language, setLanguageState] = (0, import_react54.useState)(() => {
|
|
83438
83470
|
return defaultLanguage || getCurrentLanguage();
|
|
@@ -396278,7 +396310,7 @@ var require_dist3 = __commonJS({
|
|
|
396278
396310
|
var require_proxy_from_env = __commonJS({
|
|
396279
396311
|
"node_modules/proxy-from-env/index.js"(exports2) {
|
|
396280
396312
|
"use strict";
|
|
396281
|
-
var
|
|
396313
|
+
var parseUrl2 = __require("url").parse;
|
|
396282
396314
|
var DEFAULT_PORTS = {
|
|
396283
396315
|
ftp: 21,
|
|
396284
396316
|
gopher: 70,
|
|
@@ -396291,7 +396323,7 @@ var require_proxy_from_env = __commonJS({
|
|
|
396291
396323
|
return s.length <= this.length && this.indexOf(s, this.length - s.length) !== -1;
|
|
396292
396324
|
};
|
|
396293
396325
|
function getProxyForUrl(url) {
|
|
396294
|
-
var parsedUrl = typeof url === "string" ?
|
|
396326
|
+
var parsedUrl = typeof url === "string" ? parseUrl2(url) : url || {};
|
|
396295
396327
|
var proto2 = parsedUrl.protocol;
|
|
396296
396328
|
var hostname = parsedUrl.host;
|
|
396297
396329
|
var port = parsedUrl.port;
|
|
@@ -440777,6 +440809,9 @@ var init_LSPManager = __esm({
|
|
|
440777
440809
|
try {
|
|
440778
440810
|
const uri = this.pathToUri(filePath);
|
|
440779
440811
|
const content = await this.getDocumentContent(filePath);
|
|
440812
|
+
if (!content) {
|
|
440813
|
+
return null;
|
|
440814
|
+
}
|
|
440780
440815
|
await client.openDocument(uri, content);
|
|
440781
440816
|
const position = { line, character: column };
|
|
440782
440817
|
const locations = await client.gotoDefinition(uri, position);
|
|
@@ -440799,6 +440834,9 @@ var init_LSPManager = __esm({
|
|
|
440799
440834
|
try {
|
|
440800
440835
|
const uri = this.pathToUri(filePath);
|
|
440801
440836
|
const content = await this.getDocumentContent(filePath);
|
|
440837
|
+
if (!content) {
|
|
440838
|
+
return [];
|
|
440839
|
+
}
|
|
440802
440840
|
await client.openDocument(uri, content);
|
|
440803
440841
|
const position = { line, character: column };
|
|
440804
440842
|
const locations = await client.findReferences(uri, position, false);
|
|
@@ -440821,6 +440859,9 @@ var init_LSPManager = __esm({
|
|
|
440821
440859
|
try {
|
|
440822
440860
|
const uri = this.pathToUri(filePath);
|
|
440823
440861
|
const content = await this.getDocumentContent(filePath);
|
|
440862
|
+
if (!content) {
|
|
440863
|
+
return null;
|
|
440864
|
+
}
|
|
440824
440865
|
await client.openDocument(uri, content);
|
|
440825
440866
|
const symbols2 = await client.documentSymbol(uri);
|
|
440826
440867
|
await client.closeDocument(uri);
|
|
@@ -440842,6 +440883,9 @@ var init_LSPManager = __esm({
|
|
|
440842
440883
|
try {
|
|
440843
440884
|
const uri = this.pathToUri(filePath);
|
|
440844
440885
|
const content = await this.getDocumentContent(filePath);
|
|
440886
|
+
if (!content) {
|
|
440887
|
+
return null;
|
|
440888
|
+
}
|
|
440845
440889
|
await client.openDocument(uri, content);
|
|
440846
440890
|
const position = { line, character: column };
|
|
440847
440891
|
const hover = await client.hover(uri, position);
|
|
@@ -440862,7 +440906,7 @@ var init_LSPManager = __esm({
|
|
|
440862
440906
|
this.documentCache.set(fullPath, content);
|
|
440863
440907
|
return content;
|
|
440864
440908
|
} catch (error) {
|
|
440865
|
-
|
|
440909
|
+
return null;
|
|
440866
440910
|
}
|
|
440867
440911
|
}
|
|
440868
440912
|
pathToUri(filePath) {
|
|
@@ -536100,19 +536144,19 @@ function MessageRenderer({ message, index, isLastMessage, filteredMessages, term
|
|
|
536100
536144
|
};
|
|
536101
536145
|
let toolStatusColor = "cyan";
|
|
536102
536146
|
const isInParallelGroup = message.parallelGroup !== void 0 && message.parallelGroup !== null;
|
|
536103
|
-
const isTimeConsumingTool = message.toolPending || message.
|
|
536147
|
+
const isTimeConsumingTool = message.toolPending || message.messageStatus === "pending";
|
|
536104
536148
|
const shouldShowParallelIndicator = isInParallelGroup && !isTimeConsumingTool;
|
|
536105
536149
|
const isFirstInGroup = shouldShowParallelIndicator && (index === 0 || ((_a21 = filteredMessages[index - 1]) == null ? void 0 : _a21.parallelGroup) !== message.parallelGroup || // Previous message is time-consuming tool, so this is the first non-time-consuming one
|
|
536106
|
-
((_b14 = filteredMessages[index - 1]) == null ? void 0 : _b14.toolPending) || ((_c6 = filteredMessages[index - 1]) == null ? void 0 : _c6.
|
|
536150
|
+
((_b14 = filteredMessages[index - 1]) == null ? void 0 : _b14.toolPending) || ((_c6 = filteredMessages[index - 1]) == null ? void 0 : _c6.messageStatus) === "pending");
|
|
536107
536151
|
const nextMessage = filteredMessages[index + 1];
|
|
536108
536152
|
const nextHasDifferentGroup = nextMessage && nextMessage.parallelGroup !== void 0 && nextMessage.parallelGroup !== null && nextMessage.parallelGroup !== message.parallelGroup;
|
|
536109
536153
|
const isLastInGroup = shouldShowParallelIndicator && (!nextMessage || nextHasDifferentGroup);
|
|
536110
536154
|
if (message.role === "assistant" || message.role === "subagent") {
|
|
536111
|
-
if (message.
|
|
536155
|
+
if (message.messageStatus === "pending") {
|
|
536112
536156
|
toolStatusColor = "yellowBright";
|
|
536113
|
-
} else if (message.
|
|
536157
|
+
} else if (message.messageStatus === "success") {
|
|
536114
536158
|
toolStatusColor = "green";
|
|
536115
|
-
} else if (message.
|
|
536159
|
+
} else if (message.messageStatus === "error") {
|
|
536116
536160
|
toolStatusColor = "red";
|
|
536117
536161
|
} else {
|
|
536118
536162
|
toolStatusColor = message.role === "subagent" ? "magenta" : "blue";
|
|
@@ -536165,8 +536209,8 @@ function MessageRenderer({ message, index, isLastMessage, filteredMessages, term
|
|
|
536165
536209
|
}
|
|
536166
536210
|
} catch {
|
|
536167
536211
|
}
|
|
536168
|
-
const
|
|
536169
|
-
if (
|
|
536212
|
+
const hasToolStatus = message.messageStatus !== void 0;
|
|
536213
|
+
if (hasToolStatus && (message.role === "assistant" || message.role === "subagent")) {
|
|
536170
536214
|
return import_react78.default.createElement(Text, { color: toolStatusColor }, removeAnsiCodes(message.content || " "));
|
|
536171
536215
|
}
|
|
536172
536216
|
return import_react78.default.createElement(
|
|
@@ -536233,7 +536277,7 @@ function MessageRenderer({ message, index, isLastMessage, filteredMessages, term
|
|
|
536233
536277
|
}
|
|
536234
536278
|
return null;
|
|
536235
536279
|
})),
|
|
536236
|
-
|
|
536280
|
+
message.messageStatus === "success" && message.toolResult && // 只在没有 diff 数据时显示预览(有 diff 的工具会用 DiffViewer 显示)
|
|
536237
536281
|
!(message.toolCall && (((_d4 = message.toolCall.arguments) == null ? void 0 : _d4.oldContent) || ((_e2 = message.toolCall.arguments) == null ? void 0 : _e2.batchResults))) && import_react78.default.createElement(ToolResultPreview, { toolName: ((_f = (message.content || "").replace(/^✓\s*/, "").replace(/^⚇✓\s*/, "").replace(/.*⚇✓\s*/, "").replace(/\x1b\[[0-9;]*m/g, "").split("\n")[0]) == null ? void 0 : _f.trim()) || "", result: message.toolResult, maxLines: 5, isSubAgentInternal: message.role === "subagent" || message.subAgentInternal === true }),
|
|
536238
536282
|
message.files && message.files.length > 0 && import_react78.default.createElement(Box_default, { flexDirection: "column" }, message.files.map((file, fileIndex) => import_react78.default.createElement(
|
|
536239
536283
|
Text,
|
|
@@ -538974,32 +539018,14 @@ async function parseAndValidateFileReferences(content) {
|
|
|
538974
539018
|
}
|
|
538975
539019
|
function createMessageWithFileInstructions(content, files, editorContext) {
|
|
538976
539020
|
const parts = [content];
|
|
538977
|
-
if (editorContext) {
|
|
538978
|
-
const editorLines = [];
|
|
538979
|
-
if (editorContext.workspaceFolder) {
|
|
538980
|
-
editorLines.push(`\u2514\u2500 VSCode Workspace: ${editorContext.workspaceFolder}`);
|
|
538981
|
-
}
|
|
538982
|
-
if (editorContext.activeFile) {
|
|
538983
|
-
editorLines.push(`\u2514\u2500 Active File: ${editorContext.activeFile}`);
|
|
538984
|
-
}
|
|
538985
|
-
if (editorContext.cursorPosition) {
|
|
538986
|
-
editorLines.push(`\u2514\u2500 Cursor: Line ${editorContext.cursorPosition.line + 1}, Column ${editorContext.cursorPosition.character + 1}`);
|
|
538987
|
-
}
|
|
538988
|
-
if (editorContext.selectedText) {
|
|
538989
|
-
editorLines.push(`\u2514\u2500 Selected Code:
|
|
538990
|
-
\`\`\`
|
|
538991
|
-
${editorContext.selectedText}
|
|
538992
|
-
\`\`\``);
|
|
538993
|
-
}
|
|
538994
|
-
if (editorLines.length > 0) {
|
|
538995
|
-
parts.push(editorLines.join("\n"));
|
|
538996
|
-
}
|
|
538997
|
-
}
|
|
538998
539021
|
if (files.length > 0) {
|
|
538999
539022
|
const fileInstructions = files.map((f) => `\u2514\u2500 Read \`${f.path}\` (total line ${f.lineCount})`).join("\n");
|
|
539000
539023
|
parts.push(fileInstructions);
|
|
539001
539024
|
}
|
|
539002
|
-
return
|
|
539025
|
+
return {
|
|
539026
|
+
content: parts.join("\n"),
|
|
539027
|
+
editorContext
|
|
539028
|
+
};
|
|
539003
539029
|
}
|
|
539004
539030
|
function cleanIDEContext(content) {
|
|
539005
539031
|
const lines = content.split("\n");
|
|
@@ -547302,31 +547328,6 @@ var init_toolExecutor = __esm({
|
|
|
547302
547328
|
}
|
|
547303
547329
|
});
|
|
547304
547330
|
|
|
547305
|
-
// dist/utils/core/todoPreprocessor.js
|
|
547306
|
-
function formatTodoContext(todos) {
|
|
547307
|
-
if (todos.length === 0) {
|
|
547308
|
-
return "";
|
|
547309
|
-
}
|
|
547310
|
-
const statusSymbol = {
|
|
547311
|
-
pending: "[ ]",
|
|
547312
|
-
completed: "[x]"
|
|
547313
|
-
};
|
|
547314
|
-
const lines = [
|
|
547315
|
-
"## Current TODO List",
|
|
547316
|
-
"",
|
|
547317
|
-
...todos.map((t) => `${statusSymbol[t.status]} ${t.content} (ID: ${t.id})`),
|
|
547318
|
-
"",
|
|
547319
|
-
"**Important**: Update TODO status immediately after completing each task using todo-update tool.",
|
|
547320
|
-
""
|
|
547321
|
-
];
|
|
547322
|
-
return lines.join("\n");
|
|
547323
|
-
}
|
|
547324
|
-
var init_todoPreprocessor = __esm({
|
|
547325
|
-
"dist/utils/core/todoPreprocessor.js"() {
|
|
547326
|
-
"use strict";
|
|
547327
|
-
}
|
|
547328
|
-
});
|
|
547329
|
-
|
|
547330
547331
|
// dist/utils/ui/messageFormatter.js
|
|
547331
547332
|
function formatToolCallMessage(toolCall) {
|
|
547332
547333
|
try {
|
|
@@ -548627,11 +548628,7 @@ var init_autoCompress = __esm({
|
|
|
548627
548628
|
}
|
|
548628
548629
|
});
|
|
548629
548630
|
|
|
548630
|
-
// dist/hooks/conversation/
|
|
548631
|
-
var useConversation_exports = {};
|
|
548632
|
-
__export(useConversation_exports, {
|
|
548633
|
-
handleConversationWithTools: () => handleConversationWithTools
|
|
548634
|
-
});
|
|
548631
|
+
// dist/hooks/conversation/utils/messageCleanup.js
|
|
548635
548632
|
function cleanOrphanedToolCalls2(messages) {
|
|
548636
548633
|
const toolResultIds = /* @__PURE__ */ new Set();
|
|
548637
548634
|
for (const msg of messages) {
|
|
@@ -548681,28 +548678,90 @@ function cleanOrphanedToolCalls2(messages) {
|
|
|
548681
548678
|
console.log(`[cleanOrphanedToolCalls] Removed ${indicesToRemove.length} orphaned messages from conversation`);
|
|
548682
548679
|
}
|
|
548683
548680
|
}
|
|
548684
|
-
|
|
548685
|
-
|
|
548686
|
-
|
|
548687
|
-
|
|
548688
|
-
|
|
548689
|
-
|
|
548690
|
-
|
|
548691
|
-
|
|
548692
|
-
|
|
548693
|
-
|
|
548694
|
-
|
|
548695
|
-
|
|
548696
|
-
|
|
548697
|
-
|
|
548698
|
-
|
|
548699
|
-
|
|
548700
|
-
|
|
548701
|
-
|
|
548702
|
-
|
|
548703
|
-
|
|
548704
|
-
|
|
548681
|
+
var init_messageCleanup = __esm({
|
|
548682
|
+
"dist/hooks/conversation/utils/messageCleanup.js"() {
|
|
548683
|
+
"use strict";
|
|
548684
|
+
}
|
|
548685
|
+
});
|
|
548686
|
+
|
|
548687
|
+
// dist/hooks/conversation/utils/thinkingExtractor.js
|
|
548688
|
+
function extractThinkingContent(receivedThinking, receivedReasoning, receivedReasoningContent) {
|
|
548689
|
+
if (receivedThinking == null ? void 0 : receivedThinking.thinking) {
|
|
548690
|
+
return receivedThinking.thinking;
|
|
548691
|
+
}
|
|
548692
|
+
if ((receivedReasoning == null ? void 0 : receivedReasoning.summary) && receivedReasoning.summary.length > 0) {
|
|
548693
|
+
return receivedReasoning.summary.map((item) => item.text).join("\n");
|
|
548694
|
+
}
|
|
548695
|
+
if (receivedReasoningContent) {
|
|
548696
|
+
return receivedReasoningContent;
|
|
548697
|
+
}
|
|
548698
|
+
return void 0;
|
|
548699
|
+
}
|
|
548700
|
+
var init_thinkingExtractor = __esm({
|
|
548701
|
+
"dist/hooks/conversation/utils/thinkingExtractor.js"() {
|
|
548702
|
+
"use strict";
|
|
548703
|
+
}
|
|
548704
|
+
});
|
|
548705
|
+
|
|
548706
|
+
// dist/hooks/conversation/core/editorContextBuilder.js
|
|
548707
|
+
function buildEditorContextContent(editorContext, userContent) {
|
|
548708
|
+
if (!editorContext) {
|
|
548709
|
+
return userContent;
|
|
548710
|
+
}
|
|
548711
|
+
const editorLines = [];
|
|
548712
|
+
if (editorContext.workspaceFolder) {
|
|
548713
|
+
editorLines.push(`\u2514\u2500 VSCode Workspace: ${editorContext.workspaceFolder}`);
|
|
548714
|
+
}
|
|
548715
|
+
if (editorContext.activeFile) {
|
|
548716
|
+
editorLines.push(`\u2514\u2500 Active File: ${editorContext.activeFile}`);
|
|
548717
|
+
}
|
|
548718
|
+
if (editorContext.cursorPosition) {
|
|
548719
|
+
editorLines.push(`\u2514\u2500 Cursor: Line ${editorContext.cursorPosition.line + 1}, Column ${editorContext.cursorPosition.character + 1}`);
|
|
548720
|
+
}
|
|
548721
|
+
if (editorContext.selectedText) {
|
|
548722
|
+
editorLines.push(`\u2514\u2500 Selected Code:
|
|
548723
|
+
\`\`\`
|
|
548724
|
+
${editorContext.selectedText}
|
|
548725
|
+
\`\`\``);
|
|
548726
|
+
}
|
|
548727
|
+
if (editorLines.length > 0) {
|
|
548728
|
+
return editorLines.join("\n") + "\n\n" + userContent;
|
|
548729
|
+
}
|
|
548730
|
+
return userContent;
|
|
548731
|
+
}
|
|
548732
|
+
var init_editorContextBuilder = __esm({
|
|
548733
|
+
"dist/hooks/conversation/core/editorContextBuilder.js"() {
|
|
548734
|
+
"use strict";
|
|
548735
|
+
}
|
|
548736
|
+
});
|
|
548737
|
+
|
|
548738
|
+
// dist/utils/core/todoPreprocessor.js
|
|
548739
|
+
function formatTodoContext(todos) {
|
|
548740
|
+
if (todos.length === 0) {
|
|
548741
|
+
return "";
|
|
548742
|
+
}
|
|
548743
|
+
const statusSymbol = {
|
|
548744
|
+
pending: "[ ]",
|
|
548745
|
+
completed: "[x]"
|
|
548705
548746
|
};
|
|
548747
|
+
const lines = [
|
|
548748
|
+
"## Current TODO List",
|
|
548749
|
+
"",
|
|
548750
|
+
...todos.map((t) => `${statusSymbol[t.status]} ${t.content} (ID: ${t.id})`),
|
|
548751
|
+
"",
|
|
548752
|
+
"**Important**: Update TODO status immediately after completing each task using todo-update tool.",
|
|
548753
|
+
""
|
|
548754
|
+
];
|
|
548755
|
+
return lines.join("\n");
|
|
548756
|
+
}
|
|
548757
|
+
var init_todoPreprocessor = __esm({
|
|
548758
|
+
"dist/utils/core/todoPreprocessor.js"() {
|
|
548759
|
+
"use strict";
|
|
548760
|
+
}
|
|
548761
|
+
});
|
|
548762
|
+
|
|
548763
|
+
// dist/hooks/conversation/core/sessionInitializer.js
|
|
548764
|
+
async function initializeConversationSession(planMode, vulnerabilityHuntingMode) {
|
|
548706
548765
|
let currentSession = sessionManager.getCurrentSession();
|
|
548707
548766
|
if (!currentSession) {
|
|
548708
548767
|
const isTaskMode = process.env["SNOW_TASK_MODE"] === "true";
|
|
@@ -548710,11 +548769,10 @@ async function handleConversationWithTools(options3) {
|
|
|
548710
548769
|
}
|
|
548711
548770
|
const todoService2 = getTodoService();
|
|
548712
548771
|
const existingTodoList = await todoService2.getTodoList(currentSession.id);
|
|
548713
|
-
const
|
|
548714
|
-
let conversationMessages = [
|
|
548772
|
+
const conversationMessages = [
|
|
548715
548773
|
{
|
|
548716
548774
|
role: "system",
|
|
548717
|
-
content: getSystemPromptForMode(
|
|
548775
|
+
content: getSystemPromptForMode(planMode, vulnerabilityHuntingMode)
|
|
548718
548776
|
}
|
|
548719
548777
|
];
|
|
548720
548778
|
if (existingTodoList && existingTodoList.todos.length > 0) {
|
|
@@ -548729,10 +548787,215 @@ async function handleConversationWithTools(options3) {
|
|
|
548729
548787
|
const filteredMessages = session.messages.filter((msg) => !msg.subAgentInternal);
|
|
548730
548788
|
conversationMessages.push(...filteredMessages);
|
|
548731
548789
|
}
|
|
548790
|
+
return { conversationMessages, currentSession, existingTodoList };
|
|
548791
|
+
}
|
|
548792
|
+
var init_sessionInitializer = __esm({
|
|
548793
|
+
"dist/hooks/conversation/core/sessionInitializer.js"() {
|
|
548794
|
+
"use strict";
|
|
548795
|
+
init_sessionManager();
|
|
548796
|
+
init_mcpToolsManager();
|
|
548797
|
+
init_todoPreprocessor();
|
|
548798
|
+
init_systemPrompt();
|
|
548799
|
+
}
|
|
548800
|
+
});
|
|
548801
|
+
|
|
548802
|
+
// dist/hooks/conversation/core/toolRejectionHandler.js
|
|
548803
|
+
async function handleToolRejection(options3) {
|
|
548804
|
+
const { confirmation, toolsNeedingConfirmation, autoApprovedTools, nonSensitiveTools = [], conversationMessages, accumulatedUsage, saveMessage, setMessages, setIsStreaming, freeEncoder } = options3;
|
|
548805
|
+
setMessages((prev) => prev.filter((msg) => !msg.toolPending));
|
|
548806
|
+
const rejectMessage = typeof confirmation === "object" ? `Tool execution rejected by user: ${confirmation.reason}` : "Error: Tool execution rejected by user";
|
|
548807
|
+
const rejectedToolUIMessages = [];
|
|
548808
|
+
for (const toolCall of toolsNeedingConfirmation) {
|
|
548809
|
+
const rejectionMessage = {
|
|
548810
|
+
role: "tool",
|
|
548811
|
+
tool_call_id: toolCall.id,
|
|
548812
|
+
content: rejectMessage,
|
|
548813
|
+
messageStatus: "error"
|
|
548814
|
+
};
|
|
548815
|
+
conversationMessages.push(rejectionMessage);
|
|
548816
|
+
saveMessage(rejectionMessage).catch((error) => {
|
|
548817
|
+
console.error("Failed to save tool rejection message:", error);
|
|
548818
|
+
});
|
|
548819
|
+
const toolDisplay = formatToolCallMessage(toolCall);
|
|
548820
|
+
const statusIcon = "\u2717";
|
|
548821
|
+
let statusText = "";
|
|
548822
|
+
if (typeof confirmation === "object" && confirmation.reason) {
|
|
548823
|
+
statusText = `
|
|
548824
|
+
\u2514\u2500 Rejection reason: ${confirmation.reason}`;
|
|
548825
|
+
} else {
|
|
548826
|
+
statusText = `
|
|
548827
|
+
\u2514\u2500 ${rejectMessage}`;
|
|
548828
|
+
}
|
|
548829
|
+
rejectedToolUIMessages.push({
|
|
548830
|
+
role: "assistant",
|
|
548831
|
+
content: `${statusIcon} ${toolDisplay.toolName}${statusText}`,
|
|
548832
|
+
streaming: false,
|
|
548833
|
+
messageStatus: "error"
|
|
548834
|
+
});
|
|
548835
|
+
}
|
|
548836
|
+
for (const toolCall of [...autoApprovedTools, ...nonSensitiveTools]) {
|
|
548837
|
+
const rejectionMessage = {
|
|
548838
|
+
role: "tool",
|
|
548839
|
+
tool_call_id: toolCall.id,
|
|
548840
|
+
content: rejectMessage,
|
|
548841
|
+
messageStatus: "error"
|
|
548842
|
+
};
|
|
548843
|
+
conversationMessages.push(rejectionMessage);
|
|
548844
|
+
saveMessage(rejectionMessage).catch((error) => {
|
|
548845
|
+
console.error("Failed to save auto-approved tool rejection message:", error);
|
|
548846
|
+
});
|
|
548847
|
+
}
|
|
548848
|
+
if (rejectedToolUIMessages.length > 0) {
|
|
548849
|
+
setMessages((prev) => [...prev, ...rejectedToolUIMessages]);
|
|
548850
|
+
}
|
|
548851
|
+
if (typeof confirmation === "object" && confirmation.type === "reject_with_reply") {
|
|
548852
|
+
return {
|
|
548853
|
+
shouldContinue: true,
|
|
548854
|
+
shouldEndSession: false,
|
|
548855
|
+
accumulatedUsage
|
|
548856
|
+
};
|
|
548857
|
+
} else {
|
|
548858
|
+
setMessages((prev) => [
|
|
548859
|
+
...prev,
|
|
548860
|
+
{
|
|
548861
|
+
role: "assistant",
|
|
548862
|
+
content: "Tool call rejected, session ended",
|
|
548863
|
+
streaming: false
|
|
548864
|
+
}
|
|
548865
|
+
]);
|
|
548866
|
+
if (setIsStreaming) {
|
|
548867
|
+
setIsStreaming(false);
|
|
548868
|
+
}
|
|
548869
|
+
freeEncoder();
|
|
548870
|
+
return {
|
|
548871
|
+
shouldContinue: false,
|
|
548872
|
+
shouldEndSession: true,
|
|
548873
|
+
accumulatedUsage
|
|
548874
|
+
};
|
|
548875
|
+
}
|
|
548876
|
+
}
|
|
548877
|
+
var init_toolRejectionHandler = __esm({
|
|
548878
|
+
"dist/hooks/conversation/core/toolRejectionHandler.js"() {
|
|
548879
|
+
"use strict";
|
|
548880
|
+
init_messageFormatter();
|
|
548881
|
+
}
|
|
548882
|
+
});
|
|
548883
|
+
|
|
548884
|
+
// dist/hooks/conversation/core/toolCallProcessor.js
|
|
548885
|
+
async function processToolCallsAfterStream(options3) {
|
|
548886
|
+
var _a21;
|
|
548887
|
+
const { receivedToolCalls, streamedContent, receivedReasoning, receivedThinking, receivedReasoningContent, conversationMessages, saveMessage, setMessages } = options3;
|
|
548888
|
+
const sharedThoughtSignature = (_a21 = receivedToolCalls.find((tc) => tc.thoughtSignature)) == null ? void 0 : _a21.thoughtSignature;
|
|
548889
|
+
const assistantMessage = {
|
|
548890
|
+
role: "assistant",
|
|
548891
|
+
content: streamedContent || "",
|
|
548892
|
+
tool_calls: receivedToolCalls.map((tc) => ({
|
|
548893
|
+
id: tc.id,
|
|
548894
|
+
type: "function",
|
|
548895
|
+
function: {
|
|
548896
|
+
name: tc.function.name,
|
|
548897
|
+
arguments: tc.function.arguments
|
|
548898
|
+
},
|
|
548899
|
+
...(tc.thoughtSignature || sharedThoughtSignature) && {
|
|
548900
|
+
thoughtSignature: tc.thoughtSignature || sharedThoughtSignature
|
|
548901
|
+
}
|
|
548902
|
+
})),
|
|
548903
|
+
reasoning: receivedReasoning,
|
|
548904
|
+
thinking: receivedThinking,
|
|
548905
|
+
reasoning_content: receivedReasoningContent
|
|
548906
|
+
};
|
|
548907
|
+
conversationMessages.push(assistantMessage);
|
|
548908
|
+
try {
|
|
548909
|
+
await saveMessage(assistantMessage);
|
|
548910
|
+
} catch (error) {
|
|
548911
|
+
console.error("Failed to save assistant message:", error);
|
|
548912
|
+
}
|
|
548913
|
+
const thinkingContent = extractThinkingContent(receivedThinking, receivedReasoning, receivedReasoningContent);
|
|
548914
|
+
if (streamedContent && streamedContent.trim() || thinkingContent) {
|
|
548915
|
+
setMessages((prev) => [
|
|
548916
|
+
...prev,
|
|
548917
|
+
{
|
|
548918
|
+
role: "assistant",
|
|
548919
|
+
content: (streamedContent == null ? void 0 : streamedContent.trim()) || "",
|
|
548920
|
+
streaming: false,
|
|
548921
|
+
thinking: thinkingContent
|
|
548922
|
+
}
|
|
548923
|
+
]);
|
|
548924
|
+
}
|
|
548925
|
+
const parallelGroupId = receivedToolCalls.length > 1 ? `parallel-${Date.now()}-${Math.random()}` : void 0;
|
|
548926
|
+
for (const toolCall of receivedToolCalls) {
|
|
548927
|
+
const toolDisplay = formatToolCallMessage(toolCall);
|
|
548928
|
+
let toolArgs;
|
|
548929
|
+
try {
|
|
548930
|
+
toolArgs = JSON.parse(toolCall.function.arguments);
|
|
548931
|
+
} catch (e) {
|
|
548932
|
+
toolArgs = {};
|
|
548933
|
+
}
|
|
548934
|
+
if (isToolNeedTwoStepDisplay(toolCall.function.name)) {
|
|
548935
|
+
setMessages((prev) => [
|
|
548936
|
+
...prev,
|
|
548937
|
+
{
|
|
548938
|
+
role: "assistant",
|
|
548939
|
+
content: `\u26A1 ${toolDisplay.toolName}`,
|
|
548940
|
+
streaming: false,
|
|
548941
|
+
toolCall: {
|
|
548942
|
+
name: toolCall.function.name,
|
|
548943
|
+
arguments: toolArgs
|
|
548944
|
+
},
|
|
548945
|
+
toolDisplay,
|
|
548946
|
+
toolCallId: toolCall.id,
|
|
548947
|
+
toolPending: true,
|
|
548948
|
+
messageStatus: "pending",
|
|
548949
|
+
parallelGroup: parallelGroupId
|
|
548950
|
+
}
|
|
548951
|
+
]);
|
|
548952
|
+
}
|
|
548953
|
+
}
|
|
548954
|
+
return { parallelGroupId };
|
|
548955
|
+
}
|
|
548956
|
+
var init_toolCallProcessor = __esm({
|
|
548957
|
+
"dist/hooks/conversation/core/toolCallProcessor.js"() {
|
|
548958
|
+
"use strict";
|
|
548959
|
+
init_messageFormatter();
|
|
548960
|
+
init_toolDisplayConfig();
|
|
548961
|
+
init_thinkingExtractor();
|
|
548962
|
+
}
|
|
548963
|
+
});
|
|
548964
|
+
|
|
548965
|
+
// dist/hooks/conversation/useConversation.js
|
|
548966
|
+
var useConversation_exports = {};
|
|
548967
|
+
__export(useConversation_exports, {
|
|
548968
|
+
handleConversationWithTools: () => handleConversationWithTools
|
|
548969
|
+
});
|
|
548970
|
+
async function handleConversationWithTools(options3) {
|
|
548971
|
+
const {
|
|
548972
|
+
userContent,
|
|
548973
|
+
editorContext,
|
|
548974
|
+
imageContents,
|
|
548975
|
+
controller,
|
|
548976
|
+
// messages, // No longer used - we load from session instead to get complete history with tool calls
|
|
548977
|
+
saveMessage,
|
|
548978
|
+
setMessages,
|
|
548979
|
+
setStreamTokenCount,
|
|
548980
|
+
requestToolConfirmation,
|
|
548981
|
+
requestUserQuestion,
|
|
548982
|
+
isToolAutoApproved,
|
|
548983
|
+
addMultipleToAlwaysApproved,
|
|
548984
|
+
yoloMode,
|
|
548985
|
+
setContextUsage,
|
|
548986
|
+
setIsReasoning,
|
|
548987
|
+
setRetryStatus
|
|
548988
|
+
} = options3;
|
|
548989
|
+
const addToAlwaysApproved = (toolName) => {
|
|
548990
|
+
addMultipleToAlwaysApproved([toolName]);
|
|
548991
|
+
};
|
|
548992
|
+
let { conversationMessages } = await initializeConversationSession(options3.planMode || false, options3.vulnerabilityHuntingMode || false);
|
|
548993
|
+
const mcpTools9 = await collectAllMCPTools();
|
|
548732
548994
|
cleanOrphanedToolCalls2(conversationMessages);
|
|
548995
|
+
const finalUserContent = buildEditorContextContent(editorContext, userContent);
|
|
548733
548996
|
conversationMessages.push({
|
|
548734
548997
|
role: "user",
|
|
548735
|
-
content:
|
|
548998
|
+
content: finalUserContent,
|
|
548736
548999
|
images: imageContents
|
|
548737
549000
|
});
|
|
548738
549001
|
try {
|
|
@@ -548794,26 +549057,14 @@ async function handleConversationWithTools(options3) {
|
|
|
548794
549057
|
let receivedThinking;
|
|
548795
549058
|
let receivedReasoningContent;
|
|
548796
549059
|
let hasStartedReasoning = false;
|
|
548797
|
-
const extractThinkingContent = () => {
|
|
548798
|
-
if (receivedThinking == null ? void 0 : receivedThinking.thinking) {
|
|
548799
|
-
return receivedThinking.thinking;
|
|
548800
|
-
}
|
|
548801
|
-
if ((receivedReasoning == null ? void 0 : receivedReasoning.summary) && receivedReasoning.summary.length > 0) {
|
|
548802
|
-
return receivedReasoning.summary.map((item) => item.text).join("\n");
|
|
548803
|
-
}
|
|
548804
|
-
if (receivedReasoningContent) {
|
|
548805
|
-
return receivedReasoningContent;
|
|
548806
|
-
}
|
|
548807
|
-
return void 0;
|
|
548808
|
-
};
|
|
548809
549060
|
let toolCallAccumulator = "";
|
|
548810
549061
|
let reasoningAccumulator = "";
|
|
548811
549062
|
let chunkCount = 0;
|
|
548812
549063
|
let currentTokenCount = 0;
|
|
548813
549064
|
let lastTokenUpdateTime = 0;
|
|
548814
549065
|
const TOKEN_UPDATE_INTERVAL = 100;
|
|
548815
|
-
const
|
|
548816
|
-
const cacheKey =
|
|
549066
|
+
const currentSession = sessionManager.getCurrentSession();
|
|
549067
|
+
const cacheKey = currentSession == null ? void 0 : currentSession.id;
|
|
548817
549068
|
const onRetry = (error, attempt, nextDelay) => {
|
|
548818
549069
|
if (setRetryStatus) {
|
|
548819
549070
|
setRetryStatus({
|
|
@@ -548830,7 +549081,7 @@ async function handleConversationWithTools(options3) {
|
|
|
548830
549081
|
temperature: 0,
|
|
548831
549082
|
max_tokens: config3.maxTokens || 4096,
|
|
548832
549083
|
tools: mcpTools9.length > 0 ? mcpTools9 : void 0,
|
|
548833
|
-
sessionId:
|
|
549084
|
+
sessionId: currentSession == null ? void 0 : currentSession.id,
|
|
548834
549085
|
// Disable thinking for basicModel (e.g., init command)
|
|
548835
549086
|
disableThinking: options3.useBasicModel,
|
|
548836
549087
|
planMode: options3.planMode,
|
|
@@ -548965,79 +549216,17 @@ async function handleConversationWithTools(options3) {
|
|
|
548965
549216
|
setStreamTokenCount(0);
|
|
548966
549217
|
const shouldProcessToolCalls = receivedToolCalls && receivedToolCalls.length > 0;
|
|
548967
549218
|
if (shouldProcessToolCalls) {
|
|
548968
|
-
const
|
|
548969
|
-
|
|
548970
|
-
|
|
548971
|
-
|
|
548972
|
-
|
|
548973
|
-
|
|
548974
|
-
|
|
548975
|
-
|
|
548976
|
-
|
|
548977
|
-
|
|
548978
|
-
|
|
548979
|
-
// Preserve thoughtSignature for Gemini thinking mode
|
|
548980
|
-
// If this tool call has its own signature, use it; otherwise use shared signature
|
|
548981
|
-
...(tc.thoughtSignature || sharedThoughtSignature) && {
|
|
548982
|
-
thoughtSignature: tc.thoughtSignature || sharedThoughtSignature
|
|
548983
|
-
}
|
|
548984
|
-
})),
|
|
548985
|
-
reasoning: receivedReasoning,
|
|
548986
|
-
// Include reasoning data for caching (Responses API)
|
|
548987
|
-
thinking: receivedThinking,
|
|
548988
|
-
// Include thinking content (Anthropic/OpenAI)
|
|
548989
|
-
reasoning_content: receivedReasoningContent
|
|
548990
|
-
// Include reasoning content (DeepSeek R1)
|
|
548991
|
-
};
|
|
548992
|
-
conversationMessages.push(assistantMessage);
|
|
548993
|
-
try {
|
|
548994
|
-
await saveMessage(assistantMessage);
|
|
548995
|
-
} catch (error) {
|
|
548996
|
-
console.error("Failed to save assistant message:", error);
|
|
548997
|
-
}
|
|
548998
|
-
const thinkingContent = extractThinkingContent();
|
|
548999
|
-
if (streamedContent && streamedContent.trim() || thinkingContent) {
|
|
549000
|
-
setMessages((prev) => [
|
|
549001
|
-
...prev,
|
|
549002
|
-
{
|
|
549003
|
-
role: "assistant",
|
|
549004
|
-
content: (streamedContent == null ? void 0 : streamedContent.trim()) || "",
|
|
549005
|
-
streaming: false,
|
|
549006
|
-
thinking: thinkingContent
|
|
549007
|
-
}
|
|
549008
|
-
]);
|
|
549009
|
-
}
|
|
549010
|
-
const parallelGroupId = receivedToolCalls.length > 1 ? `parallel-${Date.now()}-${Math.random()}` : void 0;
|
|
549011
|
-
for (const toolCall of receivedToolCalls) {
|
|
549012
|
-
const toolDisplay = formatToolCallMessage(toolCall);
|
|
549013
|
-
let toolArgs;
|
|
549014
|
-
try {
|
|
549015
|
-
toolArgs = JSON.parse(toolCall.function.arguments);
|
|
549016
|
-
} catch (e) {
|
|
549017
|
-
toolArgs = {};
|
|
549018
|
-
}
|
|
549019
|
-
if (isToolNeedTwoStepDisplay(toolCall.function.name)) {
|
|
549020
|
-
setMessages((prev) => [
|
|
549021
|
-
...prev,
|
|
549022
|
-
{
|
|
549023
|
-
role: "assistant",
|
|
549024
|
-
content: `\u26A1 ${toolDisplay.toolName}`,
|
|
549025
|
-
streaming: false,
|
|
549026
|
-
toolCall: {
|
|
549027
|
-
name: toolCall.function.name,
|
|
549028
|
-
arguments: toolArgs
|
|
549029
|
-
},
|
|
549030
|
-
toolDisplay,
|
|
549031
|
-
toolCallId: toolCall.id,
|
|
549032
|
-
// Store tool call ID for later update
|
|
549033
|
-
toolPending: true,
|
|
549034
|
-
// Mark as pending execution
|
|
549035
|
-
// Mark parallel group for ALL tools (time-consuming or not)
|
|
549036
|
-
parallelGroup: parallelGroupId
|
|
549037
|
-
}
|
|
549038
|
-
]);
|
|
549039
|
-
}
|
|
549040
|
-
}
|
|
549219
|
+
const { parallelGroupId } = await processToolCallsAfterStream({
|
|
549220
|
+
receivedToolCalls,
|
|
549221
|
+
streamedContent,
|
|
549222
|
+
receivedReasoning,
|
|
549223
|
+
receivedThinking,
|
|
549224
|
+
receivedReasoningContent,
|
|
549225
|
+
conversationMessages,
|
|
549226
|
+
saveMessage,
|
|
549227
|
+
setMessages,
|
|
549228
|
+
extractThinkingContent
|
|
549229
|
+
});
|
|
549041
549230
|
const toolsNeedingConfirmation = [];
|
|
549042
549231
|
const autoApprovedTools = [];
|
|
549043
549232
|
for (const toolCall of receivedToolCalls) {
|
|
@@ -549071,68 +549260,22 @@ async function handleConversationWithTools(options3) {
|
|
|
549071
549260
|
const allTools = sensitiveTools.length > 1 ? sensitiveTools : void 0;
|
|
549072
549261
|
const confirmation = await requestToolConfirmation(firstTool, void 0, allTools);
|
|
549073
549262
|
if (confirmation === "reject" || typeof confirmation === "object" && confirmation.type === "reject_with_reply") {
|
|
549074
|
-
|
|
549075
|
-
|
|
549076
|
-
|
|
549077
|
-
|
|
549078
|
-
|
|
549079
|
-
|
|
549080
|
-
|
|
549081
|
-
|
|
549082
|
-
|
|
549083
|
-
|
|
549084
|
-
|
|
549085
|
-
|
|
549086
|
-
|
|
549087
|
-
const toolDisplay = formatToolCallMessage(toolCall);
|
|
549088
|
-
const statusIcon = "\u2717";
|
|
549089
|
-
let statusText = "";
|
|
549090
|
-
if (typeof confirmation === "object" && confirmation.reason) {
|
|
549091
|
-
statusText = `
|
|
549092
|
-
\u2514\u2500 Rejection reason: ${confirmation.reason}`;
|
|
549093
|
-
} else {
|
|
549094
|
-
statusText = `
|
|
549095
|
-
\u2514\u2500 ${rejectMessage}`;
|
|
549096
|
-
}
|
|
549097
|
-
rejectedToolUIMessages.push({
|
|
549098
|
-
role: "assistant",
|
|
549099
|
-
content: `${statusIcon} ${toolDisplay.toolName}${statusText}`,
|
|
549100
|
-
streaming: false
|
|
549101
|
-
});
|
|
549102
|
-
}
|
|
549103
|
-
for (const toolCall of [
|
|
549104
|
-
...autoApprovedTools,
|
|
549105
|
-
...nonSensitiveTools
|
|
549106
|
-
]) {
|
|
549107
|
-
const rejectionMessage = {
|
|
549108
|
-
role: "tool",
|
|
549109
|
-
tool_call_id: toolCall.id,
|
|
549110
|
-
content: rejectMessage
|
|
549111
|
-
};
|
|
549112
|
-
conversationMessages.push(rejectionMessage);
|
|
549113
|
-
saveMessage(rejectionMessage).catch((error) => {
|
|
549114
|
-
console.error("Failed to save auto-approved tool rejection message:", error);
|
|
549115
|
-
});
|
|
549116
|
-
}
|
|
549117
|
-
if (rejectedToolUIMessages.length > 0) {
|
|
549118
|
-
setMessages((prev) => [...prev, ...rejectedToolUIMessages]);
|
|
549119
|
-
}
|
|
549120
|
-
if (typeof confirmation === "object" && confirmation.type === "reject_with_reply") {
|
|
549263
|
+
const result2 = await handleToolRejection({
|
|
549264
|
+
confirmation,
|
|
549265
|
+
toolsNeedingConfirmation: sensitiveTools,
|
|
549266
|
+
autoApprovedTools,
|
|
549267
|
+
nonSensitiveTools,
|
|
549268
|
+
conversationMessages,
|
|
549269
|
+
accumulatedUsage,
|
|
549270
|
+
saveMessage,
|
|
549271
|
+
setMessages,
|
|
549272
|
+
setIsStreaming: options3.setIsStreaming,
|
|
549273
|
+
freeEncoder
|
|
549274
|
+
});
|
|
549275
|
+
if (result2.shouldContinue) {
|
|
549121
549276
|
continue;
|
|
549122
549277
|
} else {
|
|
549123
|
-
|
|
549124
|
-
...prev,
|
|
549125
|
-
{
|
|
549126
|
-
role: "assistant",
|
|
549127
|
-
content: "Tool call rejected, session ended",
|
|
549128
|
-
streaming: false
|
|
549129
|
-
}
|
|
549130
|
-
]);
|
|
549131
|
-
if (options3.setIsStreaming) {
|
|
549132
|
-
options3.setIsStreaming(false);
|
|
549133
|
-
}
|
|
549134
|
-
freeEncoder();
|
|
549135
|
-
return { usage: accumulatedUsage };
|
|
549278
|
+
return { usage: result2.accumulatedUsage };
|
|
549136
549279
|
}
|
|
549137
549280
|
}
|
|
549138
549281
|
approvedTools.push(...sensitiveTools);
|
|
@@ -549142,65 +549285,21 @@ async function handleConversationWithTools(options3) {
|
|
|
549142
549285
|
const allTools = toolsNeedingConfirmation.length > 1 ? toolsNeedingConfirmation : void 0;
|
|
549143
549286
|
const confirmation = await requestToolConfirmation(firstTool, void 0, allTools);
|
|
549144
549287
|
if (confirmation === "reject" || typeof confirmation === "object" && confirmation.type === "reject_with_reply") {
|
|
549145
|
-
|
|
549146
|
-
|
|
549147
|
-
|
|
549148
|
-
|
|
549149
|
-
|
|
549150
|
-
|
|
549151
|
-
|
|
549152
|
-
|
|
549153
|
-
|
|
549154
|
-
|
|
549155
|
-
|
|
549156
|
-
|
|
549157
|
-
});
|
|
549158
|
-
const toolDisplay = formatToolCallMessage(toolCall);
|
|
549159
|
-
const statusIcon = "\u2717";
|
|
549160
|
-
let statusText = "";
|
|
549161
|
-
if (typeof confirmation === "object" && confirmation.reason) {
|
|
549162
|
-
statusText = `
|
|
549163
|
-
\u2514\u2500 Rejection reason: ${confirmation.reason}`;
|
|
549164
|
-
} else {
|
|
549165
|
-
statusText = `
|
|
549166
|
-
\u2514\u2500 ${rejectMessage}`;
|
|
549167
|
-
}
|
|
549168
|
-
rejectedToolUIMessages.push({
|
|
549169
|
-
role: "assistant",
|
|
549170
|
-
content: `${statusIcon} ${toolDisplay.toolName}${statusText}`,
|
|
549171
|
-
streaming: false
|
|
549172
|
-
});
|
|
549173
|
-
}
|
|
549174
|
-
for (const toolCall of autoApprovedTools) {
|
|
549175
|
-
const rejectionMessage = {
|
|
549176
|
-
role: "tool",
|
|
549177
|
-
tool_call_id: toolCall.id,
|
|
549178
|
-
content: rejectMessage
|
|
549179
|
-
};
|
|
549180
|
-
conversationMessages.push(rejectionMessage);
|
|
549181
|
-
saveMessage(rejectionMessage).catch((error) => {
|
|
549182
|
-
console.error("Failed to save auto-approved tool rejection message:", error);
|
|
549183
|
-
});
|
|
549184
|
-
}
|
|
549185
|
-
if (rejectedToolUIMessages.length > 0) {
|
|
549186
|
-
setMessages((prev) => [...prev, ...rejectedToolUIMessages]);
|
|
549187
|
-
}
|
|
549188
|
-
if (typeof confirmation === "object" && confirmation.type === "reject_with_reply") {
|
|
549288
|
+
const result2 = await handleToolRejection({
|
|
549289
|
+
confirmation,
|
|
549290
|
+
toolsNeedingConfirmation,
|
|
549291
|
+
autoApprovedTools,
|
|
549292
|
+
conversationMessages,
|
|
549293
|
+
accumulatedUsage,
|
|
549294
|
+
saveMessage,
|
|
549295
|
+
setMessages,
|
|
549296
|
+
setIsStreaming: options3.setIsStreaming,
|
|
549297
|
+
freeEncoder
|
|
549298
|
+
});
|
|
549299
|
+
if (result2.shouldContinue) {
|
|
549189
549300
|
continue;
|
|
549190
549301
|
} else {
|
|
549191
|
-
|
|
549192
|
-
...prev,
|
|
549193
|
-
{
|
|
549194
|
-
role: "assistant",
|
|
549195
|
-
content: "Tool call rejected, session ended",
|
|
549196
|
-
streaming: false
|
|
549197
|
-
}
|
|
549198
|
-
]);
|
|
549199
|
-
if (options3.setIsStreaming) {
|
|
549200
|
-
options3.setIsStreaming(false);
|
|
549201
|
-
}
|
|
549202
|
-
freeEncoder();
|
|
549203
|
-
return { usage: accumulatedUsage };
|
|
549302
|
+
return { usage: result2.accumulatedUsage };
|
|
549204
549303
|
}
|
|
549205
549304
|
}
|
|
549206
549305
|
if (confirmation === "approve_always") {
|
|
@@ -549215,7 +549314,8 @@ async function handleConversationWithTools(options3) {
|
|
|
549215
549314
|
const abortedResult = {
|
|
549216
549315
|
role: "tool",
|
|
549217
549316
|
tool_call_id: toolCall.id,
|
|
549218
|
-
content: "Tool execution aborted by user"
|
|
549317
|
+
content: "Tool execution aborted by user",
|
|
549318
|
+
messageStatus: "error"
|
|
549219
549319
|
};
|
|
549220
549320
|
conversationMessages.push(abortedResult);
|
|
549221
549321
|
await saveMessage(abortedResult);
|
|
@@ -549254,6 +549354,7 @@ async function handleConversationWithTools(options3) {
|
|
|
549254
549354
|
},
|
|
549255
549355
|
toolCallId: toolCall.id,
|
|
549256
549356
|
toolPending: true,
|
|
549357
|
+
messageStatus: "pending",
|
|
549257
549358
|
subAgent: {
|
|
549258
549359
|
agentId: subAgentMessage.agentId,
|
|
549259
549360
|
agentName: subAgentMessage.agentName,
|
|
@@ -549308,6 +549409,7 @@ async function handleConversationWithTools(options3) {
|
|
|
549308
549409
|
role: "tool",
|
|
549309
549410
|
tool_call_id: msg.tool_call_id,
|
|
549310
549411
|
content: msg.content,
|
|
549412
|
+
messageStatus: isError2 ? "error" : "success",
|
|
549311
549413
|
subAgentInternal: true
|
|
549312
549414
|
};
|
|
549313
549415
|
saveMessage(sessionMsg).catch((err) => console.error("Failed to save sub-agent tool result:", err));
|
|
@@ -549402,8 +549504,8 @@ async function handleConversationWithTools(options3) {
|
|
|
549402
549504
|
return [...prev, uiMsg];
|
|
549403
549505
|
}
|
|
549404
549506
|
const pendingMsgIndex = prev.findIndex((m) => {
|
|
549405
|
-
var
|
|
549406
|
-
return m.role === "subagent" && ((
|
|
549507
|
+
var _a21, _b14, _c6;
|
|
549508
|
+
return m.role === "subagent" && ((_a21 = m.subAgent) == null ? void 0 : _a21.agentId) === subAgentMessage.agentId && !((_b14 = m.subAgent) == null ? void 0 : _b14.isComplete) && ((_c6 = m.pendingToolIds) == null ? void 0 : _c6.includes(msg.tool_call_id));
|
|
549407
549509
|
});
|
|
549408
549510
|
if (pendingMsgIndex !== -1) {
|
|
549409
549511
|
const updated = [...prev];
|
|
@@ -549420,8 +549522,8 @@ async function handleConversationWithTools(options3) {
|
|
|
549420
549522
|
return prev;
|
|
549421
549523
|
}
|
|
549422
549524
|
const existingIndex = prev.findIndex((m) => {
|
|
549423
|
-
var
|
|
549424
|
-
return m.role === "subagent" && ((
|
|
549525
|
+
var _a21, _b14;
|
|
549526
|
+
return m.role === "subagent" && ((_a21 = m.subAgent) == null ? void 0 : _a21.agentId) === subAgentMessage.agentId && !((_b14 = m.subAgent) == null ? void 0 : _b14.isComplete) && !m.pendingToolIds;
|
|
549425
549527
|
});
|
|
549426
549528
|
let content = "";
|
|
549427
549529
|
if (subAgentMessage.message.type === "content") {
|
|
@@ -549502,7 +549604,8 @@ async function handleConversationWithTools(options3) {
|
|
|
549502
549604
|
const abortedResult = {
|
|
549503
549605
|
role: "tool",
|
|
549504
549606
|
tool_call_id: toolCall.id,
|
|
549505
|
-
content: "Error: Tool execution aborted by user"
|
|
549607
|
+
content: "Error: Tool execution aborted by user",
|
|
549608
|
+
messageStatus: "error"
|
|
549506
549609
|
};
|
|
549507
549610
|
conversationMessages.push(abortedResult);
|
|
549508
549611
|
try {
|
|
@@ -549541,9 +549644,14 @@ async function handleConversationWithTools(options3) {
|
|
|
549541
549644
|
break;
|
|
549542
549645
|
}
|
|
549543
549646
|
for (const result2 of toolResults) {
|
|
549544
|
-
|
|
549647
|
+
const isError2 = result2.content.startsWith("Error:");
|
|
549648
|
+
const resultToSave = {
|
|
549649
|
+
...result2,
|
|
549650
|
+
messageStatus: isError2 ? "error" : "success"
|
|
549651
|
+
};
|
|
549652
|
+
conversationMessages.push(resultToSave);
|
|
549545
549653
|
try {
|
|
549546
|
-
await saveMessage(
|
|
549654
|
+
await saveMessage(resultToSave);
|
|
549547
549655
|
} catch (error) {
|
|
549548
549656
|
console.error("Failed to save tool result before compression:", error);
|
|
549549
549657
|
}
|
|
@@ -549557,8 +549665,8 @@ async function handleConversationWithTools(options3) {
|
|
|
549557
549665
|
streaming: false
|
|
549558
549666
|
};
|
|
549559
549667
|
setMessages((prev) => [...prev, compressingMessage]);
|
|
549560
|
-
const
|
|
549561
|
-
const compressionResult = await performAutoCompression(
|
|
549668
|
+
const session = sessionManager.getCurrentSession();
|
|
549669
|
+
const compressionResult = await performAutoCompression(session == null ? void 0 : session.id);
|
|
549562
549670
|
if (compressionResult && compressionResult.hookFailed) {
|
|
549563
549671
|
setMessages((prev) => [
|
|
549564
549672
|
...prev,
|
|
@@ -549590,9 +549698,9 @@ async function handleConversationWithTools(options3) {
|
|
|
549590
549698
|
options3.setSnapshotFileCount(/* @__PURE__ */ new Map());
|
|
549591
549699
|
}
|
|
549592
549700
|
conversationMessages = [];
|
|
549593
|
-
const
|
|
549594
|
-
if (
|
|
549595
|
-
conversationMessages.push(...
|
|
549701
|
+
const session2 = sessionManager.getCurrentSession();
|
|
549702
|
+
if (session2 && session2.messages.length > 0) {
|
|
549703
|
+
conversationMessages.push(...session2.messages);
|
|
549596
549704
|
}
|
|
549597
549705
|
}
|
|
549598
549706
|
} catch (error) {
|
|
@@ -549621,6 +549729,7 @@ async function handleConversationWithTools(options3) {
|
|
|
549621
549729
|
role: "assistant",
|
|
549622
549730
|
content: `${statusIcon2} ${toolCall.function.name}${statusText2}`,
|
|
549623
549731
|
streaming: false,
|
|
549732
|
+
messageStatus: isError3 ? "error" : "success",
|
|
549624
549733
|
// Pass the full result.content for ToolResultPreview to parse
|
|
549625
549734
|
toolResult: !isError3 ? result2.content : void 0,
|
|
549626
549735
|
subAgentUsage: usage
|
|
@@ -549659,6 +549768,7 @@ async function handleConversationWithTools(options3) {
|
|
|
549659
549768
|
role: "assistant",
|
|
549660
549769
|
content: `${statusIcon} ${toolCall.function.name}${statusText}`,
|
|
549661
549770
|
streaming: false,
|
|
549771
|
+
messageStatus: isError2 ? "error" : "success",
|
|
549662
549772
|
toolCall: editDiffData ? {
|
|
549663
549773
|
name: toolCall.function.name,
|
|
549664
549774
|
arguments: editDiffData
|
|
@@ -549687,8 +549797,8 @@ async function handleConversationWithTools(options3) {
|
|
|
549687
549797
|
streaming: false
|
|
549688
549798
|
};
|
|
549689
549799
|
setMessages((prev) => [...prev, compressingMessage]);
|
|
549690
|
-
const
|
|
549691
|
-
const compressionResult = await performAutoCompression(
|
|
549800
|
+
const session = sessionManager.getCurrentSession();
|
|
549801
|
+
const compressionResult = await performAutoCompression(session == null ? void 0 : session.id);
|
|
549692
549802
|
if (compressionResult && compressionResult.hookFailed) {
|
|
549693
549803
|
setMessages((prev) => [
|
|
549694
549804
|
...prev,
|
|
@@ -549717,9 +549827,9 @@ async function handleConversationWithTools(options3) {
|
|
|
549717
549827
|
accumulatedUsage = compressionResult.usage;
|
|
549718
549828
|
}
|
|
549719
549829
|
conversationMessages = [];
|
|
549720
|
-
const
|
|
549721
|
-
if (
|
|
549722
|
-
conversationMessages.push(...
|
|
549830
|
+
const session2 = sessionManager.getCurrentSession();
|
|
549831
|
+
if (session2 && session2.messages.length > 0) {
|
|
549832
|
+
conversationMessages.push(...session2.messages);
|
|
549723
549833
|
}
|
|
549724
549834
|
}
|
|
549725
549835
|
} catch (error) {
|
|
@@ -549768,7 +549878,7 @@ async function handleConversationWithTools(options3) {
|
|
|
549768
549878
|
content: streamedContent.trim(),
|
|
549769
549879
|
streaming: false,
|
|
549770
549880
|
discontinued: controller.signal.aborted,
|
|
549771
|
-
thinking: extractThinkingContent()
|
|
549881
|
+
thinking: extractThinkingContent(receivedThinking, receivedReasoning, receivedReasoningContent)
|
|
549772
549882
|
};
|
|
549773
549883
|
setMessages((prev) => [...prev, finalAssistantMessage]);
|
|
549774
549884
|
const assistantMessage = {
|
|
@@ -549876,18 +549986,22 @@ var init_useConversation = __esm({
|
|
|
549876
549986
|
init_responses();
|
|
549877
549987
|
init_gemini();
|
|
549878
549988
|
init_anthropic();
|
|
549879
|
-
init_systemPrompt();
|
|
549880
549989
|
init_mcpToolsManager();
|
|
549881
549990
|
init_toolExecutor();
|
|
549882
549991
|
init_apiConfig();
|
|
549883
549992
|
init_sessionManager();
|
|
549884
|
-
init_todoPreprocessor();
|
|
549885
549993
|
init_unifiedHooksExecutor();
|
|
549886
549994
|
init_yoloPermissionChecker();
|
|
549887
549995
|
init_messageFormatter();
|
|
549888
549996
|
init_resourceMonitor();
|
|
549889
549997
|
init_toolDisplayConfig();
|
|
549890
549998
|
await init_autoCompress();
|
|
549999
|
+
init_messageCleanup();
|
|
550000
|
+
init_thinkingExtractor();
|
|
550001
|
+
init_editorContextBuilder();
|
|
550002
|
+
init_sessionInitializer();
|
|
550003
|
+
init_toolRejectionHandler();
|
|
550004
|
+
init_toolCallProcessor();
|
|
549891
550005
|
}
|
|
549892
550006
|
});
|
|
549893
550007
|
|
|
@@ -549934,6 +550048,7 @@ function convertSessionMessagesToUI(sessionMessages) {
|
|
|
549934
550048
|
},
|
|
549935
550049
|
toolCallId: toolCall.id,
|
|
549936
550050
|
toolPending: false,
|
|
550051
|
+
messageStatus: "pending",
|
|
549937
550052
|
subAgentInternal: true
|
|
549938
550053
|
});
|
|
549939
550054
|
processedToolCalls.add(toolCall.id);
|
|
@@ -549968,7 +550083,8 @@ function convertSessionMessagesToUI(sessionMessages) {
|
|
|
549968
550083
|
continue;
|
|
549969
550084
|
}
|
|
549970
550085
|
if (msg.subAgentInternal && msg.role === "tool" && msg.tool_call_id) {
|
|
549971
|
-
const
|
|
550086
|
+
const status = msg.messageStatus ?? (msg.content.startsWith("Error:") ? "error" : "success");
|
|
550087
|
+
const isError2 = status === "error";
|
|
549972
550088
|
let toolName = "tool";
|
|
549973
550089
|
let isTimeConsumingTool = false;
|
|
549974
550090
|
for (let j = i - 1; j >= 0; j--) {
|
|
@@ -550049,6 +550165,7 @@ function convertSessionMessagesToUI(sessionMessages) {
|
|
|
550049
550165
|
name: toolName,
|
|
550050
550166
|
arguments: terminalResultData
|
|
550051
550167
|
} : fileToolData ? fileToolData : void 0,
|
|
550168
|
+
messageStatus: status,
|
|
550052
550169
|
subAgentInternal: true
|
|
550053
550170
|
});
|
|
550054
550171
|
} else {
|
|
@@ -550059,6 +550176,7 @@ function convertSessionMessagesToUI(sessionMessages) {
|
|
|
550059
550176
|
role: "subagent",
|
|
550060
550177
|
content: `\x1B[38;2;255;100;100m\u2687\u2717 ${toolName}\x1B[0m${statusText}`,
|
|
550061
550178
|
streaming: false,
|
|
550179
|
+
messageStatus: "error",
|
|
550062
550180
|
subAgentInternal: true
|
|
550063
550181
|
});
|
|
550064
550182
|
}
|
|
@@ -550098,7 +550216,8 @@ function convertSessionMessagesToUI(sessionMessages) {
|
|
|
550098
550216
|
name: toolCall.function.name,
|
|
550099
550217
|
arguments: toolArgs
|
|
550100
550218
|
},
|
|
550101
|
-
toolDisplay
|
|
550219
|
+
toolDisplay,
|
|
550220
|
+
messageStatus: "pending"
|
|
550102
550221
|
});
|
|
550103
550222
|
}
|
|
550104
550223
|
if (parallelGroupId && !needTwoSteps) {
|
|
@@ -550111,9 +550230,10 @@ function convertSessionMessagesToUI(sessionMessages) {
|
|
|
550111
550230
|
continue;
|
|
550112
550231
|
}
|
|
550113
550232
|
if (msg.role === "tool" && msg.tool_call_id && !msg.subAgentInternal) {
|
|
550114
|
-
const isError2 = msg.content.startsWith("Error:");
|
|
550115
550233
|
const isRejectedWithReply = msg.content.includes("Tool execution rejected by user:");
|
|
550116
|
-
const
|
|
550234
|
+
const status = msg.messageStatus ?? (msg.content.startsWith("Error:") || isRejectedWithReply ? "error" : "success");
|
|
550235
|
+
const isError2 = status === "error";
|
|
550236
|
+
const statusIcon = isError2 ? "\u2717" : "\u2713";
|
|
550117
550237
|
let statusText = "";
|
|
550118
550238
|
if (isError2) {
|
|
550119
550239
|
statusText = `
|
|
@@ -550210,6 +550330,7 @@ function convertSessionMessagesToUI(sessionMessages) {
|
|
|
550210
550330
|
arguments: toolArgs
|
|
550211
550331
|
} : void 0,
|
|
550212
550332
|
terminalResult: terminalResultData,
|
|
550333
|
+
messageStatus: status,
|
|
550213
550334
|
// Add toolDisplay for non-time-consuming tools
|
|
550214
550335
|
toolDisplay: isNonTimeConsuming && !editDiffData ? formatToolCallMessage({
|
|
550215
550336
|
id: msg.tool_call_id || "",
|
|
@@ -550230,7 +550351,8 @@ function convertSessionMessagesToUI(sessionMessages) {
|
|
|
550230
550351
|
content: msg.content,
|
|
550231
550352
|
streaming: false,
|
|
550232
550353
|
images: msg.images,
|
|
550233
|
-
thinking: extractThinkingFromMessage(msg)
|
|
550354
|
+
thinking: extractThinkingFromMessage(msg),
|
|
550355
|
+
editorContext: msg.role === "user" ? msg.editorContext : void 0
|
|
550234
550356
|
});
|
|
550235
550357
|
continue;
|
|
550236
550358
|
}
|
|
@@ -550460,15 +550582,20 @@ ${errorMsg}`,
|
|
|
550460
550582
|
if (msg.role === "user" && optimizedMessage !== originalMessage) {
|
|
550461
550583
|
await saveMessage({
|
|
550462
550584
|
...msg,
|
|
550463
|
-
originalContent: originalMessage
|
|
550585
|
+
originalContent: originalMessage,
|
|
550586
|
+
editorContext: messageForAI.editorContext
|
|
550464
550587
|
});
|
|
550465
550588
|
} else {
|
|
550466
|
-
await saveMessage(
|
|
550589
|
+
await saveMessage({
|
|
550590
|
+
...msg,
|
|
550591
|
+
editorContext: msg.role === "user" ? messageForAI.editorContext : void 0
|
|
550592
|
+
});
|
|
550467
550593
|
}
|
|
550468
550594
|
};
|
|
550469
550595
|
try {
|
|
550470
550596
|
await handleConversationWithTools({
|
|
550471
|
-
userContent: messageForAI,
|
|
550597
|
+
userContent: messageForAI.content,
|
|
550598
|
+
editorContext: messageForAI.editorContext,
|
|
550472
550599
|
imageContents,
|
|
550473
550600
|
controller,
|
|
550474
550601
|
messages,
|
|
@@ -550643,7 +550770,8 @@ ${errorMsg}`,
|
|
|
550643
550770
|
const messageForAI = createMessageWithFileInstructions(cleanContent, regularFiles, vscodeState.vscodeConnected ? vscodeState.editorContext : void 0);
|
|
550644
550771
|
try {
|
|
550645
550772
|
await handleConversationWithTools({
|
|
550646
|
-
userContent: messageForAI,
|
|
550773
|
+
userContent: messageForAI.content,
|
|
550774
|
+
editorContext: messageForAI.editorContext,
|
|
550647
550775
|
imageContents,
|
|
550648
550776
|
controller,
|
|
550649
550777
|
messages,
|
|
@@ -555673,7 +555801,7 @@ function HeadlessModeScreen({ prompt, sessionId, onComplete }) {
|
|
|
555673
555801
|
console.log(`\x1B[36m\u2514\u2500 Assistant Response\x1B[0m`);
|
|
555674
555802
|
const messageForAI = createMessageWithFileInstructions(cleanContent, regularFiles, vscodeState.vscodeConnected ? vscodeState.editorContext : void 0);
|
|
555675
555803
|
await handleConversationWithTools({
|
|
555676
|
-
userContent: messageForAI,
|
|
555804
|
+
userContent: messageForAI.content,
|
|
555677
555805
|
imageContents: [],
|
|
555678
555806
|
controller,
|
|
555679
555807
|
messages: allMessages,
|
|
@@ -556873,6 +557001,918 @@ var init_app = __esm({
|
|
|
556873
557001
|
}
|
|
556874
557002
|
});
|
|
556875
557003
|
|
|
557004
|
+
// dist/api/sse-server.js
|
|
557005
|
+
import { createServer } from "http";
|
|
557006
|
+
import { parse as parseUrl } from "url";
|
|
557007
|
+
var SSEConnection, SSEServer;
|
|
557008
|
+
var init_sse_server = __esm({
|
|
557009
|
+
"dist/api/sse-server.js"() {
|
|
557010
|
+
"use strict";
|
|
557011
|
+
SSEConnection = class {
|
|
557012
|
+
constructor(response, connectionId) {
|
|
557013
|
+
Object.defineProperty(this, "response", {
|
|
557014
|
+
enumerable: true,
|
|
557015
|
+
configurable: true,
|
|
557016
|
+
writable: true,
|
|
557017
|
+
value: void 0
|
|
557018
|
+
});
|
|
557019
|
+
Object.defineProperty(this, "connectionId", {
|
|
557020
|
+
enumerable: true,
|
|
557021
|
+
configurable: true,
|
|
557022
|
+
writable: true,
|
|
557023
|
+
value: void 0
|
|
557024
|
+
});
|
|
557025
|
+
this.response = response;
|
|
557026
|
+
this.connectionId = connectionId;
|
|
557027
|
+
this.response.writeHead(200, {
|
|
557028
|
+
"Content-Type": "text/event-stream",
|
|
557029
|
+
"Cache-Control": "no-cache",
|
|
557030
|
+
Connection: "keep-alive",
|
|
557031
|
+
"Access-Control-Allow-Origin": "*"
|
|
557032
|
+
});
|
|
557033
|
+
this.sendEvent({
|
|
557034
|
+
type: "connected",
|
|
557035
|
+
data: { connectionId: this.connectionId },
|
|
557036
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
557037
|
+
});
|
|
557038
|
+
}
|
|
557039
|
+
/**
|
|
557040
|
+
* 发送 SSE 事件
|
|
557041
|
+
*/
|
|
557042
|
+
sendEvent(event) {
|
|
557043
|
+
const eventData = `data: ${JSON.stringify(event)}
|
|
557044
|
+
|
|
557045
|
+
`;
|
|
557046
|
+
this.response.write(eventData);
|
|
557047
|
+
}
|
|
557048
|
+
/**
|
|
557049
|
+
* 关闭连接
|
|
557050
|
+
*/
|
|
557051
|
+
close() {
|
|
557052
|
+
this.response.end();
|
|
557053
|
+
}
|
|
557054
|
+
getId() {
|
|
557055
|
+
return this.connectionId;
|
|
557056
|
+
}
|
|
557057
|
+
};
|
|
557058
|
+
SSEServer = class {
|
|
557059
|
+
constructor(port = 3e3) {
|
|
557060
|
+
Object.defineProperty(this, "server", {
|
|
557061
|
+
enumerable: true,
|
|
557062
|
+
configurable: true,
|
|
557063
|
+
writable: true,
|
|
557064
|
+
value: null
|
|
557065
|
+
});
|
|
557066
|
+
Object.defineProperty(this, "connections", {
|
|
557067
|
+
enumerable: true,
|
|
557068
|
+
configurable: true,
|
|
557069
|
+
writable: true,
|
|
557070
|
+
value: /* @__PURE__ */ new Map()
|
|
557071
|
+
});
|
|
557072
|
+
Object.defineProperty(this, "sessionConnections", {
|
|
557073
|
+
enumerable: true,
|
|
557074
|
+
configurable: true,
|
|
557075
|
+
writable: true,
|
|
557076
|
+
value: /* @__PURE__ */ new Map()
|
|
557077
|
+
});
|
|
557078
|
+
Object.defineProperty(this, "port", {
|
|
557079
|
+
enumerable: true,
|
|
557080
|
+
configurable: true,
|
|
557081
|
+
writable: true,
|
|
557082
|
+
value: void 0
|
|
557083
|
+
});
|
|
557084
|
+
Object.defineProperty(this, "messageHandler", {
|
|
557085
|
+
enumerable: true,
|
|
557086
|
+
configurable: true,
|
|
557087
|
+
writable: true,
|
|
557088
|
+
value: void 0
|
|
557089
|
+
});
|
|
557090
|
+
Object.defineProperty(this, "logCallback", {
|
|
557091
|
+
enumerable: true,
|
|
557092
|
+
configurable: true,
|
|
557093
|
+
writable: true,
|
|
557094
|
+
value: void 0
|
|
557095
|
+
});
|
|
557096
|
+
this.port = port;
|
|
557097
|
+
}
|
|
557098
|
+
/**
|
|
557099
|
+
* 设置日志回调函数
|
|
557100
|
+
*/
|
|
557101
|
+
setLogCallback(callback) {
|
|
557102
|
+
this.logCallback = callback;
|
|
557103
|
+
}
|
|
557104
|
+
/**
|
|
557105
|
+
* 记录日志
|
|
557106
|
+
*/
|
|
557107
|
+
log(message, level = "info") {
|
|
557108
|
+
if (this.logCallback) {
|
|
557109
|
+
this.logCallback(message, level);
|
|
557110
|
+
} else {
|
|
557111
|
+
console.log(`[${level.toUpperCase()}] ${message}`);
|
|
557112
|
+
}
|
|
557113
|
+
}
|
|
557114
|
+
/**
|
|
557115
|
+
* 设置消息处理器
|
|
557116
|
+
*/
|
|
557117
|
+
setMessageHandler(handler) {
|
|
557118
|
+
this.messageHandler = handler;
|
|
557119
|
+
}
|
|
557120
|
+
/**
|
|
557121
|
+
* 启动 SSE 服务器
|
|
557122
|
+
*/
|
|
557123
|
+
start() {
|
|
557124
|
+
return new Promise((resolve12, reject2) => {
|
|
557125
|
+
this.server = createServer((req, res) => {
|
|
557126
|
+
this.handleRequest(req, res);
|
|
557127
|
+
});
|
|
557128
|
+
this.server.on("error", (error) => {
|
|
557129
|
+
reject2(error);
|
|
557130
|
+
});
|
|
557131
|
+
this.server.listen(this.port, () => {
|
|
557132
|
+
this.log(`SSE \u670D\u52A1\u5668\u5DF2\u542F\u52A8\uFF0C\u76D1\u542C\u7AEF\u53E3 ${this.port}`, "success");
|
|
557133
|
+
resolve12();
|
|
557134
|
+
});
|
|
557135
|
+
});
|
|
557136
|
+
}
|
|
557137
|
+
/**
|
|
557138
|
+
* 停止 SSE 服务器
|
|
557139
|
+
*/
|
|
557140
|
+
stop() {
|
|
557141
|
+
return new Promise((resolve12) => {
|
|
557142
|
+
this.connections.forEach((conn) => {
|
|
557143
|
+
conn.close();
|
|
557144
|
+
});
|
|
557145
|
+
this.connections.clear();
|
|
557146
|
+
this.sessionConnections.clear();
|
|
557147
|
+
if (this.server) {
|
|
557148
|
+
this.server.close(() => {
|
|
557149
|
+
this.log("SSE \u670D\u52A1\u5668\u5DF2\u505C\u6B62", "info");
|
|
557150
|
+
resolve12();
|
|
557151
|
+
});
|
|
557152
|
+
} else {
|
|
557153
|
+
resolve12();
|
|
557154
|
+
}
|
|
557155
|
+
});
|
|
557156
|
+
}
|
|
557157
|
+
/**
|
|
557158
|
+
* 绑定 session 到连接
|
|
557159
|
+
*/
|
|
557160
|
+
bindSessionToConnection(sessionId, connectionId) {
|
|
557161
|
+
this.sessionConnections.set(sessionId, connectionId);
|
|
557162
|
+
this.log(`Session ${sessionId} \u7ED1\u5B9A\u5230\u8FDE\u63A5 ${connectionId}`, "info");
|
|
557163
|
+
}
|
|
557164
|
+
/**
|
|
557165
|
+
* 向特定 session 发送事件
|
|
557166
|
+
*/
|
|
557167
|
+
sendToSession(sessionId, event) {
|
|
557168
|
+
const connectionId = this.sessionConnections.get(sessionId);
|
|
557169
|
+
if (connectionId) {
|
|
557170
|
+
const connection = this.connections.get(connectionId);
|
|
557171
|
+
if (connection) {
|
|
557172
|
+
connection.sendEvent(event);
|
|
557173
|
+
}
|
|
557174
|
+
}
|
|
557175
|
+
}
|
|
557176
|
+
/**
|
|
557177
|
+
* 向特定连接发送事件
|
|
557178
|
+
*/
|
|
557179
|
+
sendToConnection(connectionId, event) {
|
|
557180
|
+
const connection = this.connections.get(connectionId);
|
|
557181
|
+
if (connection) {
|
|
557182
|
+
connection.sendEvent(event);
|
|
557183
|
+
}
|
|
557184
|
+
}
|
|
557185
|
+
/**
|
|
557186
|
+
* 处理 HTTP 请求
|
|
557187
|
+
*/
|
|
557188
|
+
handleRequest(req, res) {
|
|
557189
|
+
const parsedUrl = parseUrl(req.url || "", true);
|
|
557190
|
+
const pathname = parsedUrl.pathname;
|
|
557191
|
+
if (req.method === "OPTIONS") {
|
|
557192
|
+
res.writeHead(200, {
|
|
557193
|
+
"Access-Control-Allow-Origin": "*",
|
|
557194
|
+
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
|
|
557195
|
+
"Access-Control-Allow-Headers": "Content-Type"
|
|
557196
|
+
});
|
|
557197
|
+
res.end();
|
|
557198
|
+
return;
|
|
557199
|
+
}
|
|
557200
|
+
if (pathname === "/events" && req.method === "GET") {
|
|
557201
|
+
this.handleSSEConnection(req, res);
|
|
557202
|
+
return;
|
|
557203
|
+
}
|
|
557204
|
+
if (pathname === "/message" && req.method === "POST") {
|
|
557205
|
+
this.handleMessage(req, res);
|
|
557206
|
+
return;
|
|
557207
|
+
}
|
|
557208
|
+
if (pathname === "/health" && req.method === "GET") {
|
|
557209
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
557210
|
+
res.end(JSON.stringify({
|
|
557211
|
+
status: "ok",
|
|
557212
|
+
connections: this.connections.size
|
|
557213
|
+
}));
|
|
557214
|
+
return;
|
|
557215
|
+
}
|
|
557216
|
+
res.writeHead(404);
|
|
557217
|
+
res.end("Not Found");
|
|
557218
|
+
}
|
|
557219
|
+
/**
|
|
557220
|
+
* 处理 SSE 连接
|
|
557221
|
+
*/
|
|
557222
|
+
handleSSEConnection(req, res) {
|
|
557223
|
+
const connectionId = `conn_${Date.now()}_${Math.random().toString(36).substring(7)}`;
|
|
557224
|
+
const connection = new SSEConnection(res, connectionId);
|
|
557225
|
+
this.connections.set(connectionId, connection);
|
|
557226
|
+
req.on("close", () => {
|
|
557227
|
+
this.connections.delete(connectionId);
|
|
557228
|
+
this.log(`SSE \u8FDE\u63A5\u5DF2\u5173\u95ED: ${connectionId}`, "info");
|
|
557229
|
+
});
|
|
557230
|
+
this.log(`\u65B0\u7684 SSE \u8FDE\u63A5: ${connectionId}`, "success");
|
|
557231
|
+
}
|
|
557232
|
+
/**
|
|
557233
|
+
* 处理客户端消息
|
|
557234
|
+
*/
|
|
557235
|
+
handleMessage(req, res) {
|
|
557236
|
+
let body = "";
|
|
557237
|
+
req.on("data", (chunk2) => {
|
|
557238
|
+
body += chunk2.toString();
|
|
557239
|
+
});
|
|
557240
|
+
req.on("end", async () => {
|
|
557241
|
+
try {
|
|
557242
|
+
const message = JSON.parse(body);
|
|
557243
|
+
if (!message.type || !message.content && message.type === "chat") {
|
|
557244
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
557245
|
+
res.end(JSON.stringify({ error: "Invalid message format" }));
|
|
557246
|
+
return;
|
|
557247
|
+
}
|
|
557248
|
+
let targetConnectionId;
|
|
557249
|
+
if (message.sessionId) {
|
|
557250
|
+
targetConnectionId = this.sessionConnections.get(message.sessionId);
|
|
557251
|
+
if (!targetConnectionId) {
|
|
557252
|
+
const firstConnection = this.connections.values().next().value;
|
|
557253
|
+
if (firstConnection) {
|
|
557254
|
+
targetConnectionId = firstConnection.getId();
|
|
557255
|
+
}
|
|
557256
|
+
}
|
|
557257
|
+
} else {
|
|
557258
|
+
const firstConnection = this.connections.values().next().value;
|
|
557259
|
+
if (firstConnection) {
|
|
557260
|
+
targetConnectionId = firstConnection.getId();
|
|
557261
|
+
}
|
|
557262
|
+
}
|
|
557263
|
+
if (!targetConnectionId) {
|
|
557264
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
557265
|
+
res.end(JSON.stringify({ error: "No active connection" }));
|
|
557266
|
+
return;
|
|
557267
|
+
}
|
|
557268
|
+
const sendEvent = (event) => {
|
|
557269
|
+
this.sendToConnection(targetConnectionId, event);
|
|
557270
|
+
};
|
|
557271
|
+
if (this.messageHandler) {
|
|
557272
|
+
await this.messageHandler(message, sendEvent, targetConnectionId);
|
|
557273
|
+
}
|
|
557274
|
+
res.writeHead(200, {
|
|
557275
|
+
"Content-Type": "application/json",
|
|
557276
|
+
"Access-Control-Allow-Origin": "*"
|
|
557277
|
+
});
|
|
557278
|
+
res.end(JSON.stringify({ success: true }));
|
|
557279
|
+
} catch (error) {
|
|
557280
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
557281
|
+
res.end(JSON.stringify({
|
|
557282
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
557283
|
+
}));
|
|
557284
|
+
}
|
|
557285
|
+
});
|
|
557286
|
+
}
|
|
557287
|
+
/**
|
|
557288
|
+
* 广播事件到所有连接
|
|
557289
|
+
*/
|
|
557290
|
+
broadcast(event) {
|
|
557291
|
+
this.connections.forEach((conn) => {
|
|
557292
|
+
conn.sendEvent(event);
|
|
557293
|
+
});
|
|
557294
|
+
}
|
|
557295
|
+
/**
|
|
557296
|
+
* 获取当前连接数
|
|
557297
|
+
*/
|
|
557298
|
+
getConnectionCount() {
|
|
557299
|
+
return this.connections.size;
|
|
557300
|
+
}
|
|
557301
|
+
};
|
|
557302
|
+
}
|
|
557303
|
+
});
|
|
557304
|
+
|
|
557305
|
+
// dist/utils/sse/sseManager.js
|
|
557306
|
+
var sseManager_exports = {};
|
|
557307
|
+
__export(sseManager_exports, {
|
|
557308
|
+
sseManager: () => sseManager
|
|
557309
|
+
});
|
|
557310
|
+
var SSEManager, sseManager;
|
|
557311
|
+
var init_sseManager = __esm({
|
|
557312
|
+
async "dist/utils/sse/sseManager.js"() {
|
|
557313
|
+
"use strict";
|
|
557314
|
+
init_sse_server();
|
|
557315
|
+
await init_useConversation();
|
|
557316
|
+
init_sessionManager();
|
|
557317
|
+
init_permissionsConfig();
|
|
557318
|
+
init_sensitiveCommandManager();
|
|
557319
|
+
SSEManager = class {
|
|
557320
|
+
constructor() {
|
|
557321
|
+
Object.defineProperty(this, "server", {
|
|
557322
|
+
enumerable: true,
|
|
557323
|
+
configurable: true,
|
|
557324
|
+
writable: true,
|
|
557325
|
+
value: null
|
|
557326
|
+
});
|
|
557327
|
+
Object.defineProperty(this, "isRunning", {
|
|
557328
|
+
enumerable: true,
|
|
557329
|
+
configurable: true,
|
|
557330
|
+
writable: true,
|
|
557331
|
+
value: false
|
|
557332
|
+
});
|
|
557333
|
+
Object.defineProperty(this, "pendingInteractions", {
|
|
557334
|
+
enumerable: true,
|
|
557335
|
+
configurable: true,
|
|
557336
|
+
writable: true,
|
|
557337
|
+
value: /* @__PURE__ */ new Map()
|
|
557338
|
+
});
|
|
557339
|
+
Object.defineProperty(this, "interactionTimeout", {
|
|
557340
|
+
enumerable: true,
|
|
557341
|
+
configurable: true,
|
|
557342
|
+
writable: true,
|
|
557343
|
+
value: 6e4
|
|
557344
|
+
});
|
|
557345
|
+
Object.defineProperty(this, "logCallback", {
|
|
557346
|
+
enumerable: true,
|
|
557347
|
+
configurable: true,
|
|
557348
|
+
writable: true,
|
|
557349
|
+
value: void 0
|
|
557350
|
+
});
|
|
557351
|
+
Object.defineProperty(this, "sessionControllers", {
|
|
557352
|
+
enumerable: true,
|
|
557353
|
+
configurable: true,
|
|
557354
|
+
writable: true,
|
|
557355
|
+
value: /* @__PURE__ */ new Map()
|
|
557356
|
+
});
|
|
557357
|
+
}
|
|
557358
|
+
/**
|
|
557359
|
+
* 设置日志回调函数
|
|
557360
|
+
*/
|
|
557361
|
+
setLogCallback(callback) {
|
|
557362
|
+
this.logCallback = callback;
|
|
557363
|
+
}
|
|
557364
|
+
/**
|
|
557365
|
+
* 记录日志
|
|
557366
|
+
*/
|
|
557367
|
+
log(message, level = "info") {
|
|
557368
|
+
if (this.logCallback) {
|
|
557369
|
+
this.logCallback(message, level);
|
|
557370
|
+
} else {
|
|
557371
|
+
console.log(message);
|
|
557372
|
+
}
|
|
557373
|
+
}
|
|
557374
|
+
/**
|
|
557375
|
+
* 启动 SSE 服务
|
|
557376
|
+
*/
|
|
557377
|
+
async start(port = 3e3) {
|
|
557378
|
+
if (this.isRunning) {
|
|
557379
|
+
this.log("SSE service is already running", "info");
|
|
557380
|
+
return;
|
|
557381
|
+
}
|
|
557382
|
+
this.server = new SSEServer(port);
|
|
557383
|
+
if (this.logCallback) {
|
|
557384
|
+
this.server.setLogCallback(this.logCallback);
|
|
557385
|
+
}
|
|
557386
|
+
this.server.setMessageHandler(async (message, sendEvent, connectionId) => {
|
|
557387
|
+
await this.handleClientMessage(message, sendEvent, connectionId);
|
|
557388
|
+
});
|
|
557389
|
+
await this.server.start();
|
|
557390
|
+
this.isRunning = true;
|
|
557391
|
+
this.log(`SSE service has started on port ${port}`, "success");
|
|
557392
|
+
}
|
|
557393
|
+
/**
|
|
557394
|
+
* 停止 SSE 服务
|
|
557395
|
+
*/
|
|
557396
|
+
async stop() {
|
|
557397
|
+
if (!this.isRunning || !this.server) {
|
|
557398
|
+
return;
|
|
557399
|
+
}
|
|
557400
|
+
await this.server.stop();
|
|
557401
|
+
this.server = null;
|
|
557402
|
+
this.isRunning = false;
|
|
557403
|
+
this.log("SSE service has stopped", "info");
|
|
557404
|
+
}
|
|
557405
|
+
/**
|
|
557406
|
+
* 处理客户端消息
|
|
557407
|
+
*/
|
|
557408
|
+
async handleClientMessage(message, sendEvent, connectionId) {
|
|
557409
|
+
try {
|
|
557410
|
+
if (message.type === "tool_confirmation_response" || message.type === "user_question_response") {
|
|
557411
|
+
this.handleInteractionResponse(message);
|
|
557412
|
+
return;
|
|
557413
|
+
}
|
|
557414
|
+
if (message.type === "abort") {
|
|
557415
|
+
this.handleAbortRequest(message, sendEvent);
|
|
557416
|
+
return;
|
|
557417
|
+
}
|
|
557418
|
+
if (message.type === "chat" || message.type === "image") {
|
|
557419
|
+
await this.handleChatMessage(message, sendEvent, connectionId);
|
|
557420
|
+
}
|
|
557421
|
+
} catch (error) {
|
|
557422
|
+
sendEvent({
|
|
557423
|
+
type: "error",
|
|
557424
|
+
data: {
|
|
557425
|
+
message: error instanceof Error ? error.message : "\u672A\u77E5\u9519\u8BEF",
|
|
557426
|
+
stack: error instanceof Error ? error.stack : void 0
|
|
557427
|
+
},
|
|
557428
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
557429
|
+
});
|
|
557430
|
+
}
|
|
557431
|
+
}
|
|
557432
|
+
/**
|
|
557433
|
+
* 处理交互响应
|
|
557434
|
+
*/
|
|
557435
|
+
handleInteractionResponse(message) {
|
|
557436
|
+
if (!message.requestId) {
|
|
557437
|
+
this.log("Interactive response missing requestId", "error");
|
|
557438
|
+
return;
|
|
557439
|
+
}
|
|
557440
|
+
const pending = this.pendingInteractions.get(message.requestId);
|
|
557441
|
+
if (!pending) {
|
|
557442
|
+
this.log(`No pending interaction requests found: ${message.requestId}`, "error");
|
|
557443
|
+
return;
|
|
557444
|
+
}
|
|
557445
|
+
clearTimeout(pending.timeout);
|
|
557446
|
+
if (pending.type === "tool_confirmation") {
|
|
557447
|
+
pending.resolve(message.response);
|
|
557448
|
+
} else if (pending.type === "user_question") {
|
|
557449
|
+
pending.resolve(message.response);
|
|
557450
|
+
}
|
|
557451
|
+
this.pendingInteractions.delete(message.requestId);
|
|
557452
|
+
}
|
|
557453
|
+
/**
|
|
557454
|
+
* 处理中断请求
|
|
557455
|
+
*/
|
|
557456
|
+
handleAbortRequest(message, sendEvent) {
|
|
557457
|
+
if (!message.sessionId) {
|
|
557458
|
+
this.log("Abort request missing sessionId", "error");
|
|
557459
|
+
return;
|
|
557460
|
+
}
|
|
557461
|
+
const controller = this.sessionControllers.get(message.sessionId);
|
|
557462
|
+
if (controller) {
|
|
557463
|
+
controller.abort();
|
|
557464
|
+
this.log(`Task aborted for session: ${message.sessionId}`, "info");
|
|
557465
|
+
sendEvent({
|
|
557466
|
+
type: "message",
|
|
557467
|
+
data: {
|
|
557468
|
+
role: "assistant",
|
|
557469
|
+
content: "Task has been aborted by user"
|
|
557470
|
+
},
|
|
557471
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
557472
|
+
});
|
|
557473
|
+
this.sessionControllers.delete(message.sessionId);
|
|
557474
|
+
} else {
|
|
557475
|
+
this.log(`No active task found for session: ${message.sessionId}`, "info");
|
|
557476
|
+
}
|
|
557477
|
+
}
|
|
557478
|
+
/**
|
|
557479
|
+
* 处理聊天消息
|
|
557480
|
+
*/
|
|
557481
|
+
async handleChatMessage(message, sendEvent, connectionId) {
|
|
557482
|
+
var _a21;
|
|
557483
|
+
let currentSession;
|
|
557484
|
+
if (message.sessionId) {
|
|
557485
|
+
try {
|
|
557486
|
+
currentSession = await sessionManager.loadSession(message.sessionId);
|
|
557487
|
+
if (currentSession) {
|
|
557488
|
+
sessionManager.setCurrentSession(currentSession);
|
|
557489
|
+
this.log(`Load existing session: ${message.sessionId}`, "success");
|
|
557490
|
+
if (this.server) {
|
|
557491
|
+
this.server.bindSessionToConnection(message.sessionId, connectionId);
|
|
557492
|
+
}
|
|
557493
|
+
} else {
|
|
557494
|
+
currentSession = await sessionManager.createNewSession();
|
|
557495
|
+
this.log(`Session does not exist, create a new session: ${currentSession.id}`, "info");
|
|
557496
|
+
if (this.server) {
|
|
557497
|
+
this.server.bindSessionToConnection(currentSession.id, connectionId);
|
|
557498
|
+
}
|
|
557499
|
+
}
|
|
557500
|
+
} catch (error) {
|
|
557501
|
+
this.log("Load session failed, create new session", "error");
|
|
557502
|
+
currentSession = await sessionManager.createNewSession();
|
|
557503
|
+
if (this.server) {
|
|
557504
|
+
this.server.bindSessionToConnection(currentSession.id, connectionId);
|
|
557505
|
+
}
|
|
557506
|
+
}
|
|
557507
|
+
} else {
|
|
557508
|
+
currentSession = await sessionManager.createNewSession();
|
|
557509
|
+
this.log(`Create new session: ${currentSession.id}`, "success");
|
|
557510
|
+
if (this.server) {
|
|
557511
|
+
this.server.bindSessionToConnection(currentSession.id, connectionId);
|
|
557512
|
+
}
|
|
557513
|
+
}
|
|
557514
|
+
sendEvent({
|
|
557515
|
+
type: "message",
|
|
557516
|
+
data: {
|
|
557517
|
+
role: "system",
|
|
557518
|
+
sessionId: currentSession.id,
|
|
557519
|
+
content: `Session ID: ${currentSession.id}`
|
|
557520
|
+
},
|
|
557521
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
557522
|
+
});
|
|
557523
|
+
sendEvent({
|
|
557524
|
+
type: "message",
|
|
557525
|
+
data: {
|
|
557526
|
+
role: "user",
|
|
557527
|
+
content: message.content,
|
|
557528
|
+
hasImages: Boolean(message.images && message.images.length > 0)
|
|
557529
|
+
},
|
|
557530
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
557531
|
+
});
|
|
557532
|
+
const imageContents = (_a21 = message.images) == null ? void 0 : _a21.map((img) => ({
|
|
557533
|
+
type: "image",
|
|
557534
|
+
data: img.data,
|
|
557535
|
+
// 完整的 data URI
|
|
557536
|
+
mimeType: img.mimeType
|
|
557537
|
+
}));
|
|
557538
|
+
const controller = new AbortController();
|
|
557539
|
+
this.sessionControllers.set(currentSession.id, controller);
|
|
557540
|
+
const saveMessage = async (msg) => {
|
|
557541
|
+
try {
|
|
557542
|
+
await sessionManager.addMessage(msg);
|
|
557543
|
+
} catch (error) {
|
|
557544
|
+
this.log("\u4FDD\u5B58\u6D88\u606F\u5931\u8D25", "error");
|
|
557545
|
+
}
|
|
557546
|
+
};
|
|
557547
|
+
const messagesRef = [];
|
|
557548
|
+
let lastSentMessageId;
|
|
557549
|
+
const setMessages = (updater) => {
|
|
557550
|
+
var _a22;
|
|
557551
|
+
if (typeof updater === "function") {
|
|
557552
|
+
const newMessages = updater(messagesRef);
|
|
557553
|
+
messagesRef.splice(0, messagesRef.length, ...newMessages);
|
|
557554
|
+
} else {
|
|
557555
|
+
messagesRef.splice(0, messagesRef.length, ...updater);
|
|
557556
|
+
}
|
|
557557
|
+
const lastMessage = messagesRef[messagesRef.length - 1];
|
|
557558
|
+
if (lastMessage) {
|
|
557559
|
+
const messageId = `${lastMessage.role}-${(_a22 = lastMessage.content) == null ? void 0 : _a22.substring(0, 50)}-${lastMessage.streaming}`;
|
|
557560
|
+
if (!lastMessage.streaming && messageId === lastSentMessageId) {
|
|
557561
|
+
return;
|
|
557562
|
+
}
|
|
557563
|
+
if (lastMessage.role === "assistant") {
|
|
557564
|
+
sendEvent({
|
|
557565
|
+
type: "message",
|
|
557566
|
+
data: {
|
|
557567
|
+
role: "assistant",
|
|
557568
|
+
content: lastMessage.content,
|
|
557569
|
+
streaming: lastMessage.streaming || false
|
|
557570
|
+
},
|
|
557571
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
557572
|
+
});
|
|
557573
|
+
if (!lastMessage.streaming) {
|
|
557574
|
+
lastSentMessageId = messageId;
|
|
557575
|
+
}
|
|
557576
|
+
} else if (lastMessage.toolCall) {
|
|
557577
|
+
sendEvent({
|
|
557578
|
+
type: "tool_call",
|
|
557579
|
+
data: lastMessage.toolCall,
|
|
557580
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
557581
|
+
});
|
|
557582
|
+
} else if (lastMessage.toolResult) {
|
|
557583
|
+
sendEvent({
|
|
557584
|
+
type: "tool_result",
|
|
557585
|
+
data: {
|
|
557586
|
+
content: lastMessage.toolResult,
|
|
557587
|
+
status: lastMessage.messageStatus
|
|
557588
|
+
},
|
|
557589
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
557590
|
+
});
|
|
557591
|
+
}
|
|
557592
|
+
}
|
|
557593
|
+
};
|
|
557594
|
+
let tokenCount = 0;
|
|
557595
|
+
const setStreamTokenCount = (count) => {
|
|
557596
|
+
if (typeof count === "function") {
|
|
557597
|
+
tokenCount = count(tokenCount);
|
|
557598
|
+
} else {
|
|
557599
|
+
tokenCount = count;
|
|
557600
|
+
}
|
|
557601
|
+
};
|
|
557602
|
+
const setContextUsage = (usage) => {
|
|
557603
|
+
sendEvent({
|
|
557604
|
+
type: "usage",
|
|
557605
|
+
data: usage,
|
|
557606
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
557607
|
+
});
|
|
557608
|
+
};
|
|
557609
|
+
const requestToolConfirmation = async (toolCall, batchToolNames, allTools) => {
|
|
557610
|
+
const requestId = this.generateRequestId();
|
|
557611
|
+
let isSensitive = false;
|
|
557612
|
+
let sensitiveInfo = void 0;
|
|
557613
|
+
if (toolCall.function.name === "terminal-execute") {
|
|
557614
|
+
try {
|
|
557615
|
+
const args2 = JSON.parse(toolCall.function.arguments);
|
|
557616
|
+
if (args2.command && typeof args2.command === "string") {
|
|
557617
|
+
const result2 = isSensitiveCommand(args2.command);
|
|
557618
|
+
isSensitive = result2.isSensitive;
|
|
557619
|
+
if (isSensitive && result2.matchedCommand) {
|
|
557620
|
+
sensitiveInfo = {
|
|
557621
|
+
pattern: result2.matchedCommand.pattern,
|
|
557622
|
+
description: result2.matchedCommand.description
|
|
557623
|
+
};
|
|
557624
|
+
}
|
|
557625
|
+
}
|
|
557626
|
+
} catch {
|
|
557627
|
+
}
|
|
557628
|
+
}
|
|
557629
|
+
const availableOptions = [{ value: "approve", label: "Approve once" }];
|
|
557630
|
+
if (!isSensitive) {
|
|
557631
|
+
availableOptions.push({
|
|
557632
|
+
value: "approve_always",
|
|
557633
|
+
label: "Always approve"
|
|
557634
|
+
});
|
|
557635
|
+
}
|
|
557636
|
+
availableOptions.push({ value: "reject_with_reply", label: "Reject with reply" }, { value: "reject", label: "Reject and end session" });
|
|
557637
|
+
sendEvent({
|
|
557638
|
+
type: "tool_confirmation_request",
|
|
557639
|
+
data: {
|
|
557640
|
+
toolCall,
|
|
557641
|
+
batchToolNames,
|
|
557642
|
+
allTools,
|
|
557643
|
+
isSensitive,
|
|
557644
|
+
sensitiveInfo,
|
|
557645
|
+
availableOptions
|
|
557646
|
+
},
|
|
557647
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
557648
|
+
requestId
|
|
557649
|
+
});
|
|
557650
|
+
return this.waitForInteraction(requestId, "tool_confirmation");
|
|
557651
|
+
};
|
|
557652
|
+
const requestUserQuestion = async (question, options3, toolCall, multiSelect) => {
|
|
557653
|
+
const requestId = this.generateRequestId();
|
|
557654
|
+
sendEvent({
|
|
557655
|
+
type: "user_question_request",
|
|
557656
|
+
data: {
|
|
557657
|
+
question,
|
|
557658
|
+
options: options3,
|
|
557659
|
+
toolCall,
|
|
557660
|
+
multiSelect
|
|
557661
|
+
},
|
|
557662
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
557663
|
+
requestId
|
|
557664
|
+
});
|
|
557665
|
+
return this.waitForInteraction(requestId, "user_question");
|
|
557666
|
+
};
|
|
557667
|
+
const workingDirectory = process.cwd();
|
|
557668
|
+
const permissionsConfig = loadPermissionsConfig(workingDirectory);
|
|
557669
|
+
const approvedToolsSet = new Set(permissionsConfig.alwaysApprovedTools);
|
|
557670
|
+
const isToolAutoApproved = (toolName) => approvedToolsSet.has(toolName);
|
|
557671
|
+
const addMultipleToAlwaysApproved = (toolNames) => {
|
|
557672
|
+
addMultipleToolsToPermissions(workingDirectory, toolNames);
|
|
557673
|
+
toolNames.forEach((name) => approvedToolsSet.add(name));
|
|
557674
|
+
};
|
|
557675
|
+
try {
|
|
557676
|
+
const result2 = await handleConversationWithTools({
|
|
557677
|
+
userContent: message.content || "",
|
|
557678
|
+
imageContents,
|
|
557679
|
+
controller,
|
|
557680
|
+
messages: messagesRef,
|
|
557681
|
+
saveMessage,
|
|
557682
|
+
setMessages,
|
|
557683
|
+
setStreamTokenCount,
|
|
557684
|
+
requestToolConfirmation,
|
|
557685
|
+
requestUserQuestion,
|
|
557686
|
+
isToolAutoApproved,
|
|
557687
|
+
addMultipleToAlwaysApproved,
|
|
557688
|
+
yoloMode: message.yoloMode || false,
|
|
557689
|
+
// 支持客户端传递 YOLO 模式
|
|
557690
|
+
setContextUsage
|
|
557691
|
+
});
|
|
557692
|
+
sendEvent({
|
|
557693
|
+
type: "complete",
|
|
557694
|
+
data: {
|
|
557695
|
+
usage: result2.usage,
|
|
557696
|
+
tokenCount,
|
|
557697
|
+
sessionId: currentSession.id
|
|
557698
|
+
},
|
|
557699
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
557700
|
+
});
|
|
557701
|
+
this.sessionControllers.delete(currentSession.id);
|
|
557702
|
+
} catch (error) {
|
|
557703
|
+
this.sessionControllers.delete(currentSession.id);
|
|
557704
|
+
if (error instanceof Error && (error.message === "Request aborted" || error.message === "User cancelled the interaction")) {
|
|
557705
|
+
sendEvent({
|
|
557706
|
+
type: "message",
|
|
557707
|
+
data: {
|
|
557708
|
+
role: "assistant",
|
|
557709
|
+
content: error.message === "Request aborted" ? "Task has been aborted" : "User cancelled the interaction"
|
|
557710
|
+
},
|
|
557711
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
557712
|
+
});
|
|
557713
|
+
sendEvent({
|
|
557714
|
+
type: "complete",
|
|
557715
|
+
data: {
|
|
557716
|
+
usage: { input_tokens: 0, output_tokens: 0 },
|
|
557717
|
+
tokenCount,
|
|
557718
|
+
sessionId: currentSession.id,
|
|
557719
|
+
cancelled: true
|
|
557720
|
+
},
|
|
557721
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
557722
|
+
});
|
|
557723
|
+
} else {
|
|
557724
|
+
throw error;
|
|
557725
|
+
}
|
|
557726
|
+
}
|
|
557727
|
+
}
|
|
557728
|
+
/**
|
|
557729
|
+
* 等待交互响应
|
|
557730
|
+
*/
|
|
557731
|
+
waitForInteraction(requestId, type) {
|
|
557732
|
+
return new Promise((resolve12, reject2) => {
|
|
557733
|
+
const timeout2 = setTimeout(() => {
|
|
557734
|
+
this.pendingInteractions.delete(requestId);
|
|
557735
|
+
reject2(new Error(`Interactive timeout: ${requestId}`));
|
|
557736
|
+
}, this.interactionTimeout);
|
|
557737
|
+
this.pendingInteractions.set(requestId, {
|
|
557738
|
+
requestId,
|
|
557739
|
+
type,
|
|
557740
|
+
resolve: resolve12,
|
|
557741
|
+
reject: reject2,
|
|
557742
|
+
timeout: timeout2
|
|
557743
|
+
});
|
|
557744
|
+
});
|
|
557745
|
+
}
|
|
557746
|
+
/**
|
|
557747
|
+
* 生成请求ID
|
|
557748
|
+
*/
|
|
557749
|
+
generateRequestId() {
|
|
557750
|
+
return `req_${Date.now()}_${Math.random().toString(36).substring(7)}`;
|
|
557751
|
+
}
|
|
557752
|
+
/**
|
|
557753
|
+
* 广播事件
|
|
557754
|
+
*/
|
|
557755
|
+
broadcast(event) {
|
|
557756
|
+
if (this.server) {
|
|
557757
|
+
this.server.broadcast(event);
|
|
557758
|
+
}
|
|
557759
|
+
}
|
|
557760
|
+
/**
|
|
557761
|
+
* 获取运行状态
|
|
557762
|
+
*/
|
|
557763
|
+
isServerRunning() {
|
|
557764
|
+
return this.isRunning;
|
|
557765
|
+
}
|
|
557766
|
+
/**
|
|
557767
|
+
* 获取连接数
|
|
557768
|
+
*/
|
|
557769
|
+
getConnectionCount() {
|
|
557770
|
+
var _a21;
|
|
557771
|
+
return ((_a21 = this.server) == null ? void 0 : _a21.getConnectionCount()) ?? 0;
|
|
557772
|
+
}
|
|
557773
|
+
};
|
|
557774
|
+
sseManager = new SSEManager();
|
|
557775
|
+
}
|
|
557776
|
+
});
|
|
557777
|
+
|
|
557778
|
+
// dist/ui/components/sse/SSEServerStatus.js
|
|
557779
|
+
var SSEServerStatus_exports = {};
|
|
557780
|
+
__export(SSEServerStatus_exports, {
|
|
557781
|
+
SSEServerStatus: () => SSEServerStatus
|
|
557782
|
+
});
|
|
557783
|
+
var import_react136, SSEServerStatus;
|
|
557784
|
+
var init_SSEServerStatus = __esm({
|
|
557785
|
+
async "dist/ui/components/sse/SSEServerStatus.js"() {
|
|
557786
|
+
"use strict";
|
|
557787
|
+
import_react136 = __toESM(require_react(), 1);
|
|
557788
|
+
await init_build2();
|
|
557789
|
+
init_I18nContext();
|
|
557790
|
+
SSEServerStatus = ({ port, workingDir, onLogUpdate }) => {
|
|
557791
|
+
const { t } = useI18n();
|
|
557792
|
+
const [logs, setLogs] = (0, import_react136.useState)([]);
|
|
557793
|
+
(0, import_react136.useEffect)(() => {
|
|
557794
|
+
if (onLogUpdate) {
|
|
557795
|
+
onLogUpdate((message, level = "info") => {
|
|
557796
|
+
const timestamp = (/* @__PURE__ */ new Date()).toLocaleTimeString("zh-CN", {
|
|
557797
|
+
hour12: false
|
|
557798
|
+
});
|
|
557799
|
+
setLogs((prev) => [...prev, { timestamp, level, message }]);
|
|
557800
|
+
});
|
|
557801
|
+
}
|
|
557802
|
+
}, [onLogUpdate]);
|
|
557803
|
+
const getLevelColor = (level) => {
|
|
557804
|
+
switch (level) {
|
|
557805
|
+
case "success":
|
|
557806
|
+
return "green";
|
|
557807
|
+
case "error":
|
|
557808
|
+
return "red";
|
|
557809
|
+
default:
|
|
557810
|
+
return "gray";
|
|
557811
|
+
}
|
|
557812
|
+
};
|
|
557813
|
+
return import_react136.default.createElement(
|
|
557814
|
+
Box_default,
|
|
557815
|
+
{ flexDirection: "column" },
|
|
557816
|
+
import_react136.default.createElement(
|
|
557817
|
+
Box_default,
|
|
557818
|
+
null,
|
|
557819
|
+
import_react136.default.createElement(Text, { bold: true, color: "green" }, t.sseServer.started)
|
|
557820
|
+
),
|
|
557821
|
+
import_react136.default.createElement(
|
|
557822
|
+
Box_default,
|
|
557823
|
+
null,
|
|
557824
|
+
import_react136.default.createElement(
|
|
557825
|
+
Text,
|
|
557826
|
+
null,
|
|
557827
|
+
t.sseServer.port,
|
|
557828
|
+
": "
|
|
557829
|
+
),
|
|
557830
|
+
import_react136.default.createElement(Text, { color: "cyan" }, port),
|
|
557831
|
+
workingDir && import_react136.default.createElement(
|
|
557832
|
+
import_react136.default.Fragment,
|
|
557833
|
+
null,
|
|
557834
|
+
import_react136.default.createElement(
|
|
557835
|
+
Text,
|
|
557836
|
+
null,
|
|
557837
|
+
" | ",
|
|
557838
|
+
t.sseServer.workingDir,
|
|
557839
|
+
": "
|
|
557840
|
+
),
|
|
557841
|
+
import_react136.default.createElement(Text, { color: "yellow" }, workingDir)
|
|
557842
|
+
),
|
|
557843
|
+
import_react136.default.createElement(Text, null, " | "),
|
|
557844
|
+
import_react136.default.createElement(
|
|
557845
|
+
Text,
|
|
557846
|
+
{ color: "green" },
|
|
557847
|
+
"\u25CF ",
|
|
557848
|
+
t.sseServer.running
|
|
557849
|
+
)
|
|
557850
|
+
),
|
|
557851
|
+
import_react136.default.createElement(
|
|
557852
|
+
Box_default,
|
|
557853
|
+
{ flexDirection: "column" },
|
|
557854
|
+
import_react136.default.createElement(
|
|
557855
|
+
Text,
|
|
557856
|
+
{ dimColor: true },
|
|
557857
|
+
t.sseServer.endpoints,
|
|
557858
|
+
":"
|
|
557859
|
+
),
|
|
557860
|
+
import_react136.default.createElement(
|
|
557861
|
+
Text,
|
|
557862
|
+
{ color: "blue" },
|
|
557863
|
+
" http://localhost:",
|
|
557864
|
+
port,
|
|
557865
|
+
"/events"
|
|
557866
|
+
),
|
|
557867
|
+
import_react136.default.createElement(
|
|
557868
|
+
Text,
|
|
557869
|
+
{ color: "blue" },
|
|
557870
|
+
" POST http://localhost:",
|
|
557871
|
+
port,
|
|
557872
|
+
"/message"
|
|
557873
|
+
),
|
|
557874
|
+
import_react136.default.createElement(
|
|
557875
|
+
Text,
|
|
557876
|
+
{ color: "blue" },
|
|
557877
|
+
" GET http://localhost:",
|
|
557878
|
+
port,
|
|
557879
|
+
"/health"
|
|
557880
|
+
)
|
|
557881
|
+
),
|
|
557882
|
+
import_react136.default.createElement(
|
|
557883
|
+
Box_default,
|
|
557884
|
+
{ flexDirection: "column" },
|
|
557885
|
+
import_react136.default.createElement(
|
|
557886
|
+
Text,
|
|
557887
|
+
{ dimColor: true },
|
|
557888
|
+
t.sseServer.logs,
|
|
557889
|
+
" (",
|
|
557890
|
+
logs.length,
|
|
557891
|
+
"):"
|
|
557892
|
+
),
|
|
557893
|
+
import_react136.default.createElement(Box_default, { flexDirection: "column" }, logs.map((log, index) => import_react136.default.createElement(
|
|
557894
|
+
Box_default,
|
|
557895
|
+
{ key: index },
|
|
557896
|
+
import_react136.default.createElement(
|
|
557897
|
+
Text,
|
|
557898
|
+
{ dimColor: true },
|
|
557899
|
+
"[",
|
|
557900
|
+
log.timestamp,
|
|
557901
|
+
"] "
|
|
557902
|
+
),
|
|
557903
|
+
import_react136.default.createElement(Text, { color: getLevelColor(log.level) }, log.message)
|
|
557904
|
+
)))
|
|
557905
|
+
),
|
|
557906
|
+
import_react136.default.createElement(
|
|
557907
|
+
Box_default,
|
|
557908
|
+
null,
|
|
557909
|
+
import_react136.default.createElement(Text, { dimColor: true }, t.sseServer.stopHint)
|
|
557910
|
+
)
|
|
557911
|
+
);
|
|
557912
|
+
};
|
|
557913
|
+
}
|
|
557914
|
+
});
|
|
557915
|
+
|
|
556876
557916
|
// dist/utils/task/taskExecutor.js
|
|
556877
557917
|
var taskExecutor_exports = {};
|
|
556878
557918
|
__export(taskExecutor_exports, {
|
|
@@ -557019,11 +558059,11 @@ async function executeTask(taskId, prompt) {
|
|
|
557019
558059
|
const controller = new AbortController();
|
|
557020
558060
|
const messages = [];
|
|
557021
558061
|
const messageForAI = createMessageWithFileInstructions2(cleanContent, regularFiles, vscodeState.editorContext);
|
|
557022
|
-
log(`Message for AI prepared. Length: ${messageForAI.length}`);
|
|
558062
|
+
log(`Message for AI prepared. Length: ${messageForAI.content.length}`);
|
|
557023
558063
|
log("Starting conversation with Claude API...");
|
|
557024
558064
|
try {
|
|
557025
558065
|
await handleConversationWithTools2({
|
|
557026
|
-
userContent: messageForAI,
|
|
558066
|
+
userContent: messageForAI.content,
|
|
557027
558067
|
imageContents: [],
|
|
557028
558068
|
controller,
|
|
557029
558069
|
messages,
|
|
@@ -557174,7 +558214,7 @@ var init_taskExecutor = __esm({
|
|
|
557174
558214
|
});
|
|
557175
558215
|
|
|
557176
558216
|
// dist/cli.js
|
|
557177
|
-
var
|
|
558217
|
+
var import_react137 = __toESM(require_react(), 1);
|
|
557178
558218
|
await init_build2();
|
|
557179
558219
|
init_updateNotice();
|
|
557180
558220
|
await init_build3();
|
|
@@ -558060,6 +559100,9 @@ Options
|
|
|
558060
559100
|
--yolo Skip welcome screen and enable YOLO mode (auto-approve tools)
|
|
558061
559101
|
--c-yolo Skip welcome screen, resume last conversation, and enable YOLO mode
|
|
558062
559102
|
--dev Enable developer mode with persistent userId for testing
|
|
559103
|
+
--sse Start SSE server mode for external integration
|
|
559104
|
+
--sse-port SSE server port (default: 3000)
|
|
559105
|
+
--work-dir Working directory for SSE server (default: current directory)
|
|
558063
559106
|
`, {
|
|
558064
559107
|
importMeta: import.meta,
|
|
558065
559108
|
flags: {
|
|
@@ -558098,6 +559141,19 @@ Options
|
|
|
558098
559141
|
dev: {
|
|
558099
559142
|
type: "boolean",
|
|
558100
559143
|
default: false
|
|
559144
|
+
},
|
|
559145
|
+
sse: {
|
|
559146
|
+
type: "boolean",
|
|
559147
|
+
default: false
|
|
559148
|
+
},
|
|
559149
|
+
ssePort: {
|
|
559150
|
+
type: "number",
|
|
559151
|
+
default: 3e3,
|
|
559152
|
+
alias: "sse-port"
|
|
559153
|
+
},
|
|
559154
|
+
workDir: {
|
|
559155
|
+
type: "string",
|
|
559156
|
+
alias: "work-dir"
|
|
558101
559157
|
}
|
|
558102
559158
|
}
|
|
558103
559159
|
});
|
|
@@ -558112,6 +559168,50 @@ if (cli.flags.update) {
|
|
|
558112
559168
|
process.exit(1);
|
|
558113
559169
|
}
|
|
558114
559170
|
}
|
|
559171
|
+
if (cli.flags.sse) {
|
|
559172
|
+
const { sseManager: sseManager2 } = await init_sseManager().then(() => sseManager_exports);
|
|
559173
|
+
const { SSEServerStatus: SSEServerStatus2 } = await init_SSEServerStatus().then(() => SSEServerStatus_exports);
|
|
559174
|
+
const { I18nProvider: I18nProvider2 } = await Promise.resolve().then(() => (init_I18nContext(), I18nContext_exports));
|
|
559175
|
+
const port = cli.flags.ssePort || 3e3;
|
|
559176
|
+
const workDir = cli.flags.workDir;
|
|
559177
|
+
if (workDir) {
|
|
559178
|
+
try {
|
|
559179
|
+
process.chdir(workDir);
|
|
559180
|
+
} catch (error) {
|
|
559181
|
+
console.error(`\u9519\u8BEF: \u65E0\u6CD5\u5207\u6362\u5230\u5DE5\u4F5C\u76EE\u5F55 ${workDir}`);
|
|
559182
|
+
console.error(error instanceof Error ? error.message : error);
|
|
559183
|
+
process.exit(1);
|
|
559184
|
+
}
|
|
559185
|
+
}
|
|
559186
|
+
let logUpdater;
|
|
559187
|
+
const { unmount } = render_default(import_react137.default.createElement(
|
|
559188
|
+
I18nProvider2,
|
|
559189
|
+
null,
|
|
559190
|
+
import_react137.default.createElement(SSEServerStatus2, { port, workingDir: workDir || process.cwd(), onLogUpdate: (callback) => {
|
|
559191
|
+
logUpdater = callback;
|
|
559192
|
+
} })
|
|
559193
|
+
));
|
|
559194
|
+
sseManager2.setLogCallback((message, level) => {
|
|
559195
|
+
if (logUpdater) {
|
|
559196
|
+
logUpdater(message, level);
|
|
559197
|
+
}
|
|
559198
|
+
});
|
|
559199
|
+
await sseManager2.start(port);
|
|
559200
|
+
process.on("SIGINT", async () => {
|
|
559201
|
+
unmount();
|
|
559202
|
+
console.log("\nStopping SSE server...");
|
|
559203
|
+
await sseManager2.stop();
|
|
559204
|
+
process.exit(0);
|
|
559205
|
+
});
|
|
559206
|
+
process.on("SIGTERM", async () => {
|
|
559207
|
+
unmount();
|
|
559208
|
+
console.log("\nStopping SSE server...");
|
|
559209
|
+
await sseManager2.stop();
|
|
559210
|
+
process.exit(0);
|
|
559211
|
+
});
|
|
559212
|
+
await new Promise(() => {
|
|
559213
|
+
});
|
|
559214
|
+
}
|
|
558115
559215
|
if (cli.flags.task) {
|
|
558116
559216
|
const { taskManager: taskManager2 } = await Promise.resolve().then(() => (init_taskManager(), taskManager_exports));
|
|
558117
559217
|
const { executeTaskInBackground: executeTaskInBackground2 } = await Promise.resolve().then(() => (init_taskExecutor(), taskExecutor_exports));
|
|
@@ -558132,9 +559232,9 @@ if (cli.flags.taskExecute) {
|
|
|
558132
559232
|
process.exit(0);
|
|
558133
559233
|
}
|
|
558134
559234
|
var Startup = ({ version: version3, skipWelcome, autoResume, headlessPrompt, headlessSessionId, showTaskList, isDevMode: isDevMode2, enableYolo }) => {
|
|
558135
|
-
const [appReady, setAppReady] =
|
|
558136
|
-
const [AppComponent, setAppComponent] =
|
|
558137
|
-
|
|
559235
|
+
const [appReady, setAppReady] = import_react137.default.useState(false);
|
|
559236
|
+
const [AppComponent, setAppComponent] = import_react137.default.useState(null);
|
|
559237
|
+
import_react137.default.useEffect(() => {
|
|
558138
559238
|
let mounted = true;
|
|
558139
559239
|
const init = async () => {
|
|
558140
559240
|
const deps = await loadDependencies();
|
|
@@ -558180,22 +559280,22 @@ var Startup = ({ version: version3, skipWelcome, autoResume, headlessPrompt, hea
|
|
|
558180
559280
|
};
|
|
558181
559281
|
}, [version3, isDevMode2]);
|
|
558182
559282
|
if (!appReady || !AppComponent) {
|
|
558183
|
-
return
|
|
559283
|
+
return import_react137.default.createElement(
|
|
558184
559284
|
Box_default,
|
|
558185
559285
|
{ flexDirection: "column" },
|
|
558186
|
-
|
|
559286
|
+
import_react137.default.createElement(
|
|
558187
559287
|
Box_default,
|
|
558188
559288
|
null,
|
|
558189
|
-
|
|
559289
|
+
import_react137.default.createElement(
|
|
558190
559290
|
Text,
|
|
558191
559291
|
{ color: "cyan" },
|
|
558192
|
-
|
|
559292
|
+
import_react137.default.createElement(build_default, { type: "dots" })
|
|
558193
559293
|
),
|
|
558194
|
-
|
|
559294
|
+
import_react137.default.createElement(Text, null, " Loading...")
|
|
558195
559295
|
)
|
|
558196
559296
|
);
|
|
558197
559297
|
}
|
|
558198
|
-
return
|
|
559298
|
+
return import_react137.default.createElement(AppComponent, { version: version3, skipWelcome, autoResume, headlessPrompt, headlessSessionId, showTaskList, enableYolo });
|
|
558199
559299
|
};
|
|
558200
559300
|
process.stdout.write("\x1B[?2004l");
|
|
558201
559301
|
process.stdout.write("\x1B[2K\r");
|
|
@@ -558240,7 +559340,7 @@ process.on("SIGTERM", async () => {
|
|
|
558240
559340
|
await cleanupAsync();
|
|
558241
559341
|
process.exit(0);
|
|
558242
559342
|
});
|
|
558243
|
-
render_default(
|
|
559343
|
+
render_default(import_react137.default.createElement(Startup, { version: VERSION2, skipWelcome: Boolean(cli.flags.c || cli.flags.yolo || cli.flags.cYolo), autoResume: Boolean(cli.flags.c || cli.flags.cYolo), headlessPrompt: cli.flags.ask, headlessSessionId: cli.input[0], showTaskList: cli.flags.taskList, isDevMode: cli.flags.dev, enableYolo: Boolean(cli.flags.yolo || cli.flags.cYolo) }), {
|
|
558244
559344
|
exitOnCtrlC: false,
|
|
558245
559345
|
patchConsole: true
|
|
558246
559346
|
});
|