Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(llm): tools calls not displayed while in progress
Elian Doran1892bec7729b
diff --git a/apps/client/src/services/llm_chat.ts b/apps/client/src/services/llm_chat.tsindex e4263aa896..fa0a0279d3 100644--- a/apps/client/src/services/llm_chat.ts+++ b/apps/client/src/services/llm_chat.ts@@ -77,9 +77,13 @@ export async function streamChatCompletion(break;case "tool_use":callbacks.onToolUse?.(data.toolName, data.toolInput);+ // Yield to force Preact to commit the pending tool call+ // state before we process the result.+ await new Promise((r) => setTimeout(r, 1));break;case "tool_result":callbacks.onToolResult?.(data.toolName, data.result, data.isError);+ await new Promise((r) => setTimeout(r, 1));break;case "citation":if (data.citation) {diff --git a/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts b/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.tsindex faa7448bb6..3b79475ae5 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts+++ b/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts@@ -279,12 +279,14 @@ export function useLlmChat(setStreamingBlocks([...contentBlocks]);},onToolResult: (toolName, result, isError) => {- // Find the most recent tool_call block for this tool without a result+ // Replace the matching block with a new object so Preact sees the change.for (let i = contentBlocks.length - 1; i >= 0; i--) {const block = contentBlocks[i];if (block.type === "tool_call" && block.toolCall.toolName === toolName && !block.toolCall.result) {- block.toolCall.result = result;- block.toolCall.isError = isError;+ contentBlocks[i] = {+ type: "tool_call",+ toolCall: { ...block.toolCall, result, isError }+ };break;}}