Changesets · Branches · Tags · Compare
| Changeset | a84763de5f60e51e6b25bdb57398d720866f55f5820e75ed9556d7ce880bc2bb |
|---|---|
| Author | Nate <sestinj@gmail.com> · 2025-08-28 19:26 -07:00 |
| Committer | Nate <sestinj@gmail.com> · 2025-08-28 19:26 -07:00 |
| Parents | a9ed471f6c5a |
1 file changed
modified extensions/cli/src/commands/serve.helpers.ts +41 −8
| @@ -1,4 +1,4 @@ | ||
| 1 | -import type { Session, ToolStatus } from "core/index.js"; | |
| 1 | +import type { Session, ToolCallState, ToolStatus } from "core/index.js"; | |
| 2 | 2 | |
| 3 | 3 | import { streamChatResponse } from "../stream/streamChatResponse.js"; |
| 4 | 4 | import { StreamCallbacks } from "../stream/streamChatResponse.types.js"; |
| @@ -38,15 +38,48 @@ | ||
| 38 | 38 | // This callback is just for notification/UI updates |
| 39 | 39 | // The tool call state is already created and added by handleToolCalls |
| 40 | 40 | }, |
| 41 | - onToolResult: (_: string, __: string, ___: ToolStatus) => { | |
| 42 | - // Note: handleToolCalls already updates the tool call states in history | |
| 43 | - // This callback is just for notification/UI updates | |
| 41 | + onToolResult: (result: string, toolName: string, status: ToolStatus) => { | |
| 42 | + // Update only the tool call state status | |
| 43 | + // The actual result is already added as a separate message by handleToolCalls | |
| 44 | + for (let i = state.session.history.length - 1; i >= 0; i--) { | |
| 45 | + const item = state.session.history[i]; | |
| 46 | + if (item.toolCallStates) { | |
| 47 | + const toolState = item.toolCallStates.find( | |
| 48 | + (ts: ToolCallState) => | |
| 49 | + ts.toolCall.function.name === toolName && | |
| 50 | + (ts.status === "calling" || ts.status === "generated"), | |
| 51 | + ); | |
| 52 | + if (toolState) { | |
| 53 | + // Only update the status, not the output | |
| 54 | + toolState.status = status; | |
| 55 | + break; | |
| 56 | + } | |
| 57 | + } | |
| 58 | + } | |
| 44 | 59 | }, |
| 45 | 60 | onToolError: (error: string, toolName?: string) => { |
| 46 | - // Note: handleToolCalls and preprocessStreamedToolCalls already handle errors | |
| 47 | - // This callback is just for notification/UI updates | |
| 48 | - // If we need to display a generic error message (no tool name), add it | |
| 49 | - if (!toolName) { | |
| 61 | + // Update the tool call state to errored status | |
| 62 | + if (toolName) { | |
| 63 | + // Find and update the corresponding tool call state | |
| 64 | + for (let i = state.session.history.length - 1; i >= 0; i--) { | |
| 65 | + const item = state.session.history[i]; | |
| 66 | + if (item.toolCallStates) { | |
| 67 | + const toolState = item.toolCallStates.find( | |
| 68 | + (ts: ToolCallState) => | |
| 69 | + ts.toolCall.function.name === toolName && | |
| 70 | + (ts.status === "calling" || ts.status === "generated"), | |
| 71 | + ); | |
| 72 | + if (toolState) { | |
| 73 | + // Only update the status, not the output | |
| 74 | + // The error message is already added as a separate tool result message | |
| 75 | + // by handleToolCalls/preprocessStreamedToolCalls | |
| 76 | + toolState.status = "errored"; | |
| 77 | + break; | |
| 78 | + } | |
| 79 | + } | |
| 80 | + } | |
| 81 | + } else { | |
| 82 | + // Generic error message when no tool name is provided | |
| 50 | 83 | state.session.history.push({ |
| 51 | 84 | message: { role: "system", content: error }, |
| 52 | 85 | contextItems: [], |