diff --git a/src/streamChatResponse.ts b/src/streamChatResponse.ts index 68d4288f7..ec0a0d475 100644 --- a/src/streamChatResponse.ts +++ b/src/streamChatResponse.ts @@ -53,8 +53,8 @@ type TODO = any; export interface StreamCallbacks { onContent?: (content: string) => void; onToolStart?: (toolName: string) => void; - onToolResult?: (result: string) => void; - onToolError?: (error: string) => void; + onToolResult?: (result: string, toolName: string) => void; + onToolError?: (error: string, toolName?: string) => void; } // Define a function to handle streaming responses with tool calling @@ -220,7 +220,7 @@ export async function streamChatResponse( }); if (callbacks?.onToolResult) { - callbacks.onToolResult(toolResult); + callbacks.onToolResult(toolResult, toolCall.name); } else { console.info(chalk.green(toolResult) + "\n"); } @@ -234,7 +234,7 @@ export async function streamChatResponse( content: errorMessage, }); if (callbacks?.onToolError) { - callbacks.onToolError(errorMessage); + callbacks.onToolError(errorMessage, toolCall.name); } else { console.info( `${chalk.red("[Tool error:")} ${chalk.red(errorMessage)}${chalk.red( diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index 7ba3dd546..5e44dcbc3 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -5,6 +5,7 @@ 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"; interface TUIChatProps { assistant: ContinueClient["assistant"]; @@ -126,23 +127,25 @@ const TUIChat: React.FC = ({ }, ]); }, - onToolResult: (result: string) => { + onToolResult: (result: string, toolName: string) => { setMessages((prev) => [ ...prev, { role: "system", content: result, messageType: "tool-result", + toolName, }, ]); }, - onToolError: (error: string) => { + onToolError: (error: string, toolName?: string) => { setMessages((prev) => [ ...prev, { role: "system", content: error, messageType: "tool-error", + toolName, }, ]); }, @@ -231,7 +234,10 @@ const TUIChat: React.FC = ({ Tool completed - {message.content} + ); diff --git a/src/ui/ToolResultSummary.tsx b/src/ui/ToolResultSummary.tsx new file mode 100644 index 000000000..416fb2f03 --- /dev/null +++ b/src/ui/ToolResultSummary.tsx @@ -0,0 +1,93 @@ +import { Text, Box } from "ink"; +import React from "react"; + +interface ToolResultSummaryProps { + toolName?: string; + content: string; +} + +const ToolResultSummary: React.FC = ({ + toolName, + content, +}) => { + const getSummary = () => { + if (!content) return "No output"; + + const lines = content.split('\n').length; + const chars = content.length; + + // Use exact tool name matching + switch (toolName) { + case "Read": + // Try to extract file path from content if it contains line numbers + if (content.includes("→")) { + const pathMatch = content.match(/^(.+?):/); + const filePath = pathMatch ? pathMatch[1] : "file"; + return `Read ${filePath} (${lines} lines)`; + } + return `Read tool output (${lines} lines)`; + + case "Bash": + return `Command output (${lines} lines)`; + + case "Glob": + const fileCount = lines; + return `Found ${fileCount} ${fileCount === 1 ? 'file' : 'files'}`; + + case "Grep": + return `Found ${lines} ${lines === 1 ? 'match' : 'matches'}`; + + case "LS": + return `Listed ${lines} ${lines === 1 ? 'item' : 'items'}`; + + case "Write": + return "File written successfully"; + + case "Edit": + case "MultiEdit": + return "File edited successfully"; + + case "NotebookRead": + return `Read notebook (${lines} lines)`; + + case "NotebookEdit": + return "Notebook edited successfully"; + + case "WebFetch": + return `Fetched web content (${lines} lines)`; + + case "WebSearch": + return `Search results (${lines} lines)`; + + case "TodoWrite": + return "Todo list updated"; + + case "Task": + return `Task completed (${lines} lines)`; + + default: + // Handle MCP tools or unknown tools + if (toolName?.startsWith("mcp__")) { + const mcpToolName = toolName.replace("mcp__", ""); + return `${mcpToolName} tool output (${lines} lines)`; + } + + // Fallback for unknown tools + if (chars > 1000) { + return `${toolName || 'Tool'} output: ${lines} lines, ${chars} characters`; + } else if (lines > 10) { + return `${toolName || 'Tool'} output: ${lines} lines`; + } else { + return content.slice(0, 100) + (content.length > 100 ? "..." : ""); + } + } + }; + + return ( + + {getSummary()} + + ); +}; + +export default ToolResultSummary; \ No newline at end of file