snow-ai 0.5.3 → 0.5.4
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/bundle/cli.mjs +73 -36
- package/package.json +1 -1
package/bundle/cli.mjs
CHANGED
|
@@ -425873,9 +425873,9 @@ var init_codebaseSearch = __esm({
|
|
|
425873
425873
|
return dotProduct / (Math.sqrt(normA) * Math.sqrt(normB));
|
|
425874
425874
|
}
|
|
425875
425875
|
/**
|
|
425876
|
-
|
|
425877
|
-
|
|
425878
|
-
async search(query, topN = 10) {
|
|
425876
|
+
* Search codebase using semantic similarity with retry logic
|
|
425877
|
+
*/
|
|
425878
|
+
async search(query, topN = 10, abortSignal) {
|
|
425879
425879
|
const config3 = loadCodebaseConfig();
|
|
425880
425880
|
const enableAgentReview = config3.enableAgentReview;
|
|
425881
425881
|
const { available, reason } = await this.isCodebaseIndexAvailable();
|
|
@@ -425943,7 +425943,7 @@ var init_codebaseSearch = __esm({
|
|
|
425943
425943
|
role: msg.role,
|
|
425944
425944
|
content: msg.content
|
|
425945
425945
|
})).slice(-10)) || [];
|
|
425946
|
-
const reviewResult = await codebaseReviewAgent.reviewResults(query, formattedResults, conversationContext.length > 0 ? conversationContext : void 0);
|
|
425946
|
+
const reviewResult = await codebaseReviewAgent.reviewResults(query, formattedResults, conversationContext.length > 0 ? conversationContext : void 0, abortSignal);
|
|
425947
425947
|
finalResults = reviewResult.filteredResults;
|
|
425948
425948
|
reviewFailed = reviewResult.reviewFailed || false;
|
|
425949
425949
|
removedCount = reviewResult.removedCount;
|
|
@@ -433746,7 +433746,7 @@ AI Tip: Provide searchContent (string) and replaceContent (string).`);
|
|
|
433746
433746
|
const { codebaseSearchService: codebaseSearchService2 } = await Promise.resolve().then(() => (init_codebaseSearch(), codebaseSearch_exports));
|
|
433747
433747
|
switch (actualToolName) {
|
|
433748
433748
|
case "search":
|
|
433749
|
-
result2 = await codebaseSearchService2.search(args2.query, args2.topN);
|
|
433749
|
+
result2 = await codebaseSearchService2.search(args2.query, args2.topN, abortSignal);
|
|
433750
433750
|
break;
|
|
433751
433751
|
default:
|
|
433752
433752
|
throw new Error(`Unknown codebase tool: ${actualToolName}`);
|
|
@@ -433839,9 +433839,13 @@ ${combinedOutput}`);
|
|
|
433839
433839
|
async function executeOnExternalMCPService(serviceName, server, toolName, args2) {
|
|
433840
433840
|
const client = await getPersistentClient(serviceName, server);
|
|
433841
433841
|
logger.debug(`Using persistent MCP client for ${serviceName} tool ${toolName}`);
|
|
433842
|
+
const timeout2 = server.timeout ?? 3e5;
|
|
433842
433843
|
const result2 = await client.callTool({
|
|
433843
433844
|
name: toolName,
|
|
433844
433845
|
arguments: args2
|
|
433846
|
+
}, void 0, {
|
|
433847
|
+
timeout: timeout2,
|
|
433848
|
+
resetTimeoutOnProgress: true
|
|
433845
433849
|
});
|
|
433846
433850
|
logger.debug(`result from ${serviceName} tool ${toolName}:`, result2);
|
|
433847
433851
|
return result2.content;
|
|
@@ -523811,40 +523815,80 @@ function findPreserveStartIndex(messages) {
|
|
|
523811
523815
|
return messages.length;
|
|
523812
523816
|
}
|
|
523813
523817
|
function cleanOrphanedToolCalls(messages) {
|
|
523814
|
-
const toolResultIds = /* @__PURE__ */ new Set();
|
|
523815
|
-
for (const msg of messages) {
|
|
523816
|
-
if (msg.role === "tool" && msg.tool_call_id) {
|
|
523817
|
-
toolResultIds.add(msg.tool_call_id);
|
|
523818
|
-
}
|
|
523819
|
-
}
|
|
523820
|
-
const declaredToolCallIds = /* @__PURE__ */ new Set();
|
|
523821
|
-
for (const msg of messages) {
|
|
523822
|
-
if (msg.role === "assistant" && msg.tool_calls) {
|
|
523823
|
-
for (const tc of msg.tool_calls) {
|
|
523824
|
-
declaredToolCallIds.add(tc.id);
|
|
523825
|
-
}
|
|
523826
|
-
}
|
|
523827
|
-
}
|
|
523828
523818
|
const indicesToRemove = [];
|
|
523829
|
-
for (let i =
|
|
523819
|
+
for (let i = 0; i < messages.length; i++) {
|
|
523830
523820
|
const msg = messages[i];
|
|
523831
523821
|
if (!msg)
|
|
523832
523822
|
continue;
|
|
523833
|
-
if (msg.role === "assistant" && msg.tool_calls) {
|
|
523834
|
-
const
|
|
523835
|
-
if (!
|
|
523836
|
-
|
|
523837
|
-
console.warn("[contextCompressor:cleanOrphanedToolCalls] Removing assistant message with orphaned tool_calls", {
|
|
523823
|
+
if (msg.role === "assistant" && msg.tool_calls && msg.tool_calls.length > 0) {
|
|
523824
|
+
const nextMsg = messages[i + 1];
|
|
523825
|
+
if (!nextMsg || nextMsg.role !== "tool") {
|
|
523826
|
+
console.warn("[contextCompressor:cleanOrphanedToolCalls] Removing assistant message - next message is not tool result", {
|
|
523838
523827
|
messageIndex: i,
|
|
523839
523828
|
toolCallIds: msg.tool_calls.map((tc) => tc.id),
|
|
523840
|
-
|
|
523829
|
+
nextMessageRole: (nextMsg == null ? void 0 : nextMsg.role) || "none"
|
|
523830
|
+
});
|
|
523831
|
+
indicesToRemove.push(i);
|
|
523832
|
+
continue;
|
|
523833
|
+
}
|
|
523834
|
+
const expectedToolCallIds = new Set(msg.tool_calls.map((tc) => tc.id));
|
|
523835
|
+
const foundToolCallIds = /* @__PURE__ */ new Set();
|
|
523836
|
+
for (let j = i + 1; j < messages.length; j++) {
|
|
523837
|
+
const followingMsg = messages[j];
|
|
523838
|
+
if (!followingMsg)
|
|
523839
|
+
continue;
|
|
523840
|
+
if (followingMsg.role === "tool") {
|
|
523841
|
+
if (followingMsg.tool_call_id) {
|
|
523842
|
+
foundToolCallIds.add(followingMsg.tool_call_id);
|
|
523843
|
+
}
|
|
523844
|
+
} else {
|
|
523845
|
+
break;
|
|
523846
|
+
}
|
|
523847
|
+
}
|
|
523848
|
+
const missingIds = Array.from(expectedToolCallIds).filter((id) => !foundToolCallIds.has(id));
|
|
523849
|
+
if (missingIds.length > 0) {
|
|
523850
|
+
console.warn("[contextCompressor:cleanOrphanedToolCalls] Removing assistant message - missing immediate tool results", {
|
|
523851
|
+
messageIndex: i,
|
|
523852
|
+
toolCallIds: msg.tool_calls.map((tc) => tc.id),
|
|
523853
|
+
missingIds
|
|
523841
523854
|
});
|
|
523842
523855
|
indicesToRemove.push(i);
|
|
523843
523856
|
}
|
|
523844
523857
|
}
|
|
523845
523858
|
if (msg.role === "tool" && msg.tool_call_id) {
|
|
523846
|
-
|
|
523847
|
-
|
|
523859
|
+
let foundCorrespondingAssistant = false;
|
|
523860
|
+
for (let j = i - 1; j >= 0; j--) {
|
|
523861
|
+
const prevMsg = messages[j];
|
|
523862
|
+
if (!prevMsg)
|
|
523863
|
+
continue;
|
|
523864
|
+
if (prevMsg.role === "assistant" && prevMsg.tool_calls) {
|
|
523865
|
+
const hasToolCall = prevMsg.tool_calls.some((tc) => tc.id === msg.tool_call_id);
|
|
523866
|
+
if (hasToolCall) {
|
|
523867
|
+
foundCorrespondingAssistant = true;
|
|
523868
|
+
let isImmediatelyAfter = true;
|
|
523869
|
+
for (let k = j + 1; k < i; k++) {
|
|
523870
|
+
const betweenMsg = messages[k];
|
|
523871
|
+
if (betweenMsg && betweenMsg.role !== "tool") {
|
|
523872
|
+
isImmediatelyAfter = false;
|
|
523873
|
+
break;
|
|
523874
|
+
}
|
|
523875
|
+
}
|
|
523876
|
+
if (!isImmediatelyAfter) {
|
|
523877
|
+
console.warn("[contextCompressor:cleanOrphanedToolCalls] Removing tool result - not immediately after assistant", {
|
|
523878
|
+
messageIndex: i,
|
|
523879
|
+
toolCallId: msg.tool_call_id,
|
|
523880
|
+
assistantIndex: j
|
|
523881
|
+
});
|
|
523882
|
+
indicesToRemove.push(i);
|
|
523883
|
+
}
|
|
523884
|
+
break;
|
|
523885
|
+
}
|
|
523886
|
+
} else if (prevMsg.role !== "tool") {
|
|
523887
|
+
break;
|
|
523888
|
+
}
|
|
523889
|
+
}
|
|
523890
|
+
if (!foundCorrespondingAssistant) {
|
|
523891
|
+
console.warn("[contextCompressor:cleanOrphanedToolCalls] Removing orphaned tool result - no corresponding assistant", {
|
|
523848
523892
|
messageIndex: i,
|
|
523849
523893
|
toolCallId: msg.tool_call_id
|
|
523850
523894
|
});
|
|
@@ -523852,6 +523896,7 @@ function cleanOrphanedToolCalls(messages) {
|
|
|
523852
523896
|
}
|
|
523853
523897
|
}
|
|
523854
523898
|
}
|
|
523899
|
+
indicesToRemove.sort((a, b) => b - a);
|
|
523855
523900
|
for (const idx2 of indicesToRemove) {
|
|
523856
523901
|
messages.splice(idx2, 1);
|
|
523857
523902
|
}
|
|
@@ -525604,14 +525649,6 @@ async function handleConversationWithTools(options3) {
|
|
|
525604
525649
|
);
|
|
525605
525650
|
if (controller.signal.aborted) {
|
|
525606
525651
|
if (receivedToolCalls && receivedToolCalls.length > 0) {
|
|
525607
|
-
const assistantMsgWithTools = conversationMessages.find((msg) => msg.role === "assistant" && msg.tool_calls && msg.tool_calls.some((tc) => receivedToolCalls.some((rtc) => rtc.id === tc.id)));
|
|
525608
|
-
if (assistantMsgWithTools) {
|
|
525609
|
-
try {
|
|
525610
|
-
await saveMessage(assistantMsgWithTools);
|
|
525611
|
-
} catch (error) {
|
|
525612
|
-
console.error("Failed to save assistant message before abort:", error);
|
|
525613
|
-
}
|
|
525614
|
-
}
|
|
525615
525652
|
for (const toolCall of receivedToolCalls) {
|
|
525616
525653
|
const abortedResult = {
|
|
525617
525654
|
role: "tool",
|