diff --git a/examples/chat-ui/src/hooks/useStreamResponse.ts b/examples/chat-ui/src/hooks/useStreamResponse.ts index 080aba3..c185b28 100644 --- a/examples/chat-ui/src/hooks/useStreamResponse.ts +++ b/examples/chat-ui/src/hooks/useStreamResponse.ts @@ -273,6 +273,28 @@ export const useStreamResponse = ({ processedEvents.add(eventKey) debugLog(`[useStreamResponse] Tool call event:`, event) + + // End reasoning phase immediately when we see a tool call for linear flow + if (reasoningStartTime && !reasoningEndTime) { + reasoningEndTime = Date.now() + debugLog(`[useStreamResponse] Reasoning ended due to tool call at:`, reasoningEndTime, 'Duration:', reasoningEndTime - reasoningStartTime, 'ms') + + // Update reasoning end time and stop streaming immediately + setConversations((prev) => { + const updated = [...prev] + const conv = updated.find((c) => c.id === conversationId) + if (conv && assistantMessageIndex >= 0) { + const assistantMessage = conv.messages[assistantMessageIndex] + if (assistantMessage && hasContent(assistantMessage) && assistantMessage.role === 'assistant') { + assistantMessage.reasoningEndTime = reasoningEndTime + assistantMessage.isReasoningStreaming = false + debugLog(`[useStreamResponse] Stopped reasoning streaming due to tool call`) + } + } + return updated + }) + } + if (event.toolName) { setConversations((prev) => { const updated = [...prev] diff --git a/examples/example-server/vengabus/src/index.ts b/examples/example-server/vengabus/src/index.ts index af12712..0dcffde 100644 --- a/examples/example-server/vengabus/src/index.ts +++ b/examples/example-server/vengabus/src/index.ts @@ -35,9 +35,15 @@ mcpServer.registerTool("get_vengabus_times", description: "This checks to see when the next Vengabus is, or whether there is one for the user's current location. Please display all the information to the user in a tabulated form.", inputSchema: { } }, - async () => ({ - content: [{ type: "text", text: `Next Vengabus: imminent. Current user's route: New York to San Francisco. Route name: "Intercity Disco".` }] - }) + async () => { + await scheduler.wait(100) + return ({ + content: [{ + type: 'text', + text: `Next Vengabus: imminent. Current user's route: New York to San Francisco. Route name: "Intercity Disco".` + }] + }) + } ); app.post('/mcp', async (c) => {