Elffuss BraidHub

kikocis/continue public

fix: update serve stream callbacks
Changeset1bedc7304a6417f4f5b3f74325b95f1cb80fa223a52d480a22989295a68e641f
AuthorNate <sestinj@gmail.com> · 2025-08-28 19:12 -07:00
CommitterNate <sestinj@gmail.com> · 2025-08-28 19:12 -07:00
Parents10459a948591

Browse the files at this changeset

1 file changed

modified extensions/cli/src/commands/serve.helpers.ts +37 −35
@@ -1,9 +1,4 @@
1-import type {
2- ChatHistoryItem,
3- Session,
4- ToolCallState,
5- ToolStatus,
6-} from "core/index.js";
1+import type { Session, ToolCallState, ToolStatus } from "core/index.js";
72
83 import { streamChatResponse } from "../stream/streamChatResponse.js";
94 import { StreamCallbacks } from "../stream/streamChatResponse.types.js";
@@ -27,42 +22,41 @@
2722 // Set up periodic interruption checks
2823 const interruptionChecker = setInterval(checkInterruption, 100);
2924
30- let currentStreamingItem: ChatHistoryItem | null = null;
31-
3225 // Create callbacks to capture tool events
3326 const callbacks: StreamCallbacks = {
34- onContent: (_: string) => {},
35- onContentComplete: (content: string) => {
36- currentStreamingItem = {
37- message: { role: "assistant", content },
38- contextItems: [],
39- };
40- state.session.history.push(currentStreamingItem);
27+ onContent: (_: string) => {
28+ // onContent is empty - doesn't update history during streaming
29+ // This is just for real-time display purposes
30+ },
31+ onContentComplete: (_: string) => {
32+ // Note: streamChatResponse already adds messages to history via handleToolCalls
33+ // so we don't need to add them here - this callback is just for notification
34+ // that content streaming is complete
4135 },
4236 onToolStart: (toolName: string, toolArgs?: any) => {
43- // If there was streaming content, finalize it first
44- if (currentStreamingItem && currentStreamingItem.message.content) {
45- currentStreamingItem = null;
46- }
47-
4837 // Always create a new assistant message for each tool call
4938 const toolCallId = `tool_${Date.now()}_${Math.random().toString(36).substring(2, 15)}`;
39+ const toolCall = {
40+ id: toolCallId,
41+ type: "function" as const,
42+ function: {
43+ name: toolName,
44+ arguments: JSON.stringify(toolArgs || {}),
45+ },
46+ };
5047 const toolCallState: ToolCallState = {
5148 toolCallId: toolCallId,
52- toolCall: {
53- id: toolCallId,
54- type: "function",
55- function: {
56- name: toolName,
57- arguments: JSON.stringify(toolArgs || {}),
58- },
59- },
49+ toolCall: toolCall,
6050 status: "calling",
6151 parsedArgs: toolArgs,
6252 };
6353
6454 state.session.history.push({
65- message: { role: "assistant", content: "" },
55+ message: {
56+ role: "assistant",
57+ content: "",
58+ toolCalls: [toolCall],
59+ },
6660 contextItems: [],
6761 toolCallStates: [toolCallState],
6862 });
@@ -85,7 +79,7 @@
8579 description: "Tool execution result",
8680 },
8781 ];
88- return;
82+ break;
8983 }
9084 }
9185 }
@@ -110,7 +104,7 @@
110104 description: "Tool execution error",
111105 },
112106 ];
113- return;
107+ break;
114108 }
115109 }
116110 }
@@ -125,6 +119,7 @@
125119 toolName: string,
126120 toolArgs: any,
127121 requestId: string,
122+ toolCallPreview?: any[],
128123 ) => {
129124 // Set pending permission state
130125 state.pendingPermission = {
@@ -132,6 +127,7 @@
132127 toolArgs,
133128 requestId,
134129 timestamp: Date.now(),
130+ toolCallPreview,
135131 };
136132
137133 // Add a system message indicating permission is needed
@@ -145,6 +141,15 @@
145141
146142 // Don't wait here - the streamChatResponse will handle waiting
147143 },
144+ onSystemMessage: (message: string) => {
145+ state.session.history.push({
146+ message: {
147+ role: "system",
148+ content: message,
149+ },
150+ contextItems: [],
151+ });
152+ },
148153 };
149154
150155 try {
@@ -158,10 +163,6 @@
158163 return response || "";
159164 } finally {
160165 clearInterval(interruptionChecker);
161- // Ensure any streaming message is finalized
162- if (currentStreamingItem !== null) {
163- currentStreamingItem = null;
164- }
165166 }
166167 }
167168
@@ -170,6 +171,7 @@
170171 toolArgs: any;
171172 requestId: string;
172173 timestamp: number;
174+ toolCallPreview?: any[];
173175 }
174176
175177 export interface ServerState {