| 1 | import { Tool, ToolCallState } from "core"; |
| 2 | import Mustache from "mustache"; |
| 3 | import { getStatusIntro } from "./utils"; |
| 4 | |
| 5 | interface ToolCallStatusMessageProps { |
| 6 | tool: Tool | undefined; |
| 7 | toolCallState: ToolCallState; |
| 8 | } |
| 9 | |
| 10 | export function ToolCallStatusMessage({ |
| 11 | tool, |
| 12 | toolCallState, |
| 13 | }: ToolCallStatusMessageProps) { |
| 14 | if (!tool) return "Agent tool use"; |
| 15 | |
| 16 | const toolName = tool.displayTitle ?? tool.function.name; |
| 17 | const defaultToolDescription = `${toolName} tool`; |
| 18 | |
| 19 | const futureMessage: string = tool.wouldLikeTo |
| 20 | ? Mustache.render(tool.wouldLikeTo, toolCallState.parsedArgs) |
| 21 | : `use the ${defaultToolDescription}`; |
| 22 | // TODO go back and replace arg string values and tool names with <code> tags |
| 23 | // to make them more readable |
| 24 | |
| 25 | let intro = getStatusIntro(toolCallState.status, tool.isInstant); |
| 26 | let message = ""; |
| 27 | |
| 28 | // Handle the special case for "done" status or instant tools that are calling |
| 29 | if ( |
| 30 | toolCallState.status === "done" || |
| 31 | (tool.isInstant && toolCallState.status === "calling") |
| 32 | ) { |
| 33 | message = tool.hasAlready |
| 34 | ? Mustache.render(tool.hasAlready, toolCallState.parsedArgs) |
| 35 | : `used the ${defaultToolDescription}`; |
| 36 | } else { |
| 37 | switch (toolCallState.status) { |
| 38 | case "generating": |
| 39 | case "generated": |
| 40 | case "canceled": |
| 41 | case "errored": |
| 42 | message = futureMessage; |
| 43 | break; |
| 44 | case "calling": |
| 45 | message = tool.isCurrently |
| 46 | ? Mustache.render(tool.isCurrently, toolCallState.parsedArgs) |
| 47 | : `calling the ${defaultToolDescription}`; |
| 48 | break; |
| 49 | default: |
| 50 | message = defaultToolDescription; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | return ( |
| 55 | <div |
| 56 | className="text-description line-clamp-4 min-w-0 break-all" |
| 57 | data-testid="tool-call-title" |
| 58 | > |
| 59 | {`Continue ${intro} ${message}`} |
| 60 | </div> |
| 61 | ); |
| 62 | } |