diff --git a/src/streamChatResponse.ts b/src/streamChatResponse.ts index ec0a0d475..3ac1e5649 100644 --- a/src/streamChatResponse.ts +++ b/src/streamChatResponse.ts @@ -52,7 +52,7 @@ type TODO = any; export interface StreamCallbacks { onContent?: (content: string) => void; - onToolStart?: (toolName: string) => void; + onToolStart?: (toolName: string, toolArgs?: any) => void; onToolResult?: (result: string, toolName: string) => void; onToolError?: (error: string, toolName?: string) => void; } @@ -128,6 +128,7 @@ export async function streamChatResponse( id: toolCallDelta.id, name: "", arguments: {}, + startNotified: false, }; } currentToolCallId = toolCallDelta.id; @@ -141,15 +142,7 @@ export async function streamChatResponse( if (toolCall) { if (!toolCall.name) { toolCall.name = toolCallDelta.function.name; - if (callbacks?.onToolStart) { - callbacks.onToolStart(toolCall.name); - } else { - process.stdout.write( - `\n${chalk.yellow("[Using tool:")} ${chalk.yellow.bold( - toolCall.name - )}${chalk.yellow("]")}` - ); - } + toolCall.startNotified = false; } } } @@ -167,6 +160,20 @@ export async function streamChatResponse( // Try to parse complete JSON const parsed = JSON.parse(toolArguments); toolCall.arguments = parsed; + + // Notify start if we haven't already and have both name and args + if (toolCall.name && !toolCall.startNotified) { + toolCall.startNotified = true; + if (callbacks?.onToolStart) { + callbacks.onToolStart(toolCall.name, toolCall.arguments); + } else { + process.stdout.write( + `\n${chalk.yellow("[Using tool:")} ${chalk.yellow.bold( + toolCall.name + )}${chalk.yellow("]")}` + ); + } + } } catch (e) { // Not complete JSON yet, continue collecting } diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index 503fe7c3e..813ff1eda 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -4,8 +4,8 @@ import { ChatCompletionMessageParam } from "openai/resources.mjs"; import React, { useEffect, useState } from "react"; import { handleSlashCommands } from "../slashCommands.js"; import { StreamCallbacks, streamChatResponse } from "../streamChatResponse.js"; -import UserInput from "./UserInput.js"; import ToolResultSummary from "./ToolResultSummary.js"; +import UserInput from "./UserInput.js"; interface TUIChatProps { assistant: ContinueClient["assistant"]; @@ -19,6 +19,7 @@ interface DisplayMessage { isStreaming?: boolean; messageType?: "tool-start" | "tool-result" | "tool-error" | "system"; toolName?: string; + toolResult?: string; } const TUIChat: React.FC = ({ @@ -116,12 +117,56 @@ const TUIChat: React.FC = ({ return newMessages; }); }, - onToolStart: (toolName: string) => { + onToolStart: (toolName: string, toolArgs?: any) => { + const formatToolCall = (name: string, args: any) => { + if (!args) return name; + + switch (name) { + case "Read": + return `Read(${args.file_path || args.path || ""})`; + case "Write": + return `Write(${args.file_path || ""})`; + case "Edit": + case "MultiEdit": + return `Edit(${args.file_path || ""})`; + case "Bash": + return `Bash(${args.command || ""})`; + case "Glob": + return `Glob(${args.pattern || ""})`; + case "Grep": + return `Grep(${args.pattern || ""})`; + case "LS": + return `LS(${args.path || ""})`; + case "NotebookRead": + return `NotebookRead(${args.notebook_path || ""})`; + case "NotebookEdit": + return `NotebookEdit(${args.notebook_path || ""})`; + case "WebFetch": + return `WebFetch(${args.url || ""})`; + case "WebSearch": + return `WebSearch(${args.query || ""})`; + case "TodoWrite": + return `TodoWrite(${args.todos?.length || 0} items)`; + case "Task": + return `Task(${args.description || ""})`; + default: + // Handle MCP tools or unknown tools + if (name.startsWith("mcp__")) { + const mcpToolName = name.replace("mcp__", ""); + const firstParam = Object.values(args)[0]; + return `${mcpToolName}(${firstParam || ""})`; + } + // For unknown tools, show first parameter value + const firstValue = Object.values(args)[0]; + return `${name}(${firstValue || ""})`; + } + }; + setMessages((prev) => [ ...prev, { role: "system", - content: `Using ${toolName}...`, + content: formatToolCall(toolName, toolArgs), messageType: "tool-start", toolName, }, @@ -132,11 +177,14 @@ const TUIChat: React.FC = ({ const newMessages = [...prev]; // Find the last tool-start message for this tool and replace it for (let i = newMessages.length - 1; i >= 0; i--) { - if (newMessages[i].messageType === "tool-start" && newMessages[i].toolName === toolName) { + if ( + newMessages[i].messageType === "tool-start" && + newMessages[i].toolName === toolName + ) { newMessages[i] = { ...newMessages[i], - content: result, messageType: "tool-result", + toolResult: result, // Store the actual result separately }; break; } @@ -218,9 +266,7 @@ const TUIChat: React.FC = ({ case "tool-start": return ( - - ○ {message.content} - + ○ {message.content} ); @@ -233,14 +279,12 @@ const TUIChat: React.FC = ({ flexDirection="column" > - - ✓ Completed {message.toolName} - + ● {message.content} -