Elffuss BraidHub

kikocis/continue public

main · 1.4 KiBRawPermalink
1import { Text } from "ink";
2import React from "react";
3
4import { formatToolArgument } from "./formatters.js";
5
6import { getToolDisplayName } from "./index.js";
7
8/**
9 * Formats a tool call with its arguments for display
10 * @param toolName The name of the tool
11 * @param args The tool arguments
12 * @returns A React node with bolded tool name like "<b>ToolName</b>(arg)" or just "<b>ToolName</b>" if no args
13 */
14export function ToolCallTitle(props: { toolName: string; args?: any }) {
15 const { toolName, args } = props;
16
17 const displayName = getToolDisplayName(toolName);
18
19 if (!args || Object.keys(args).length === 0) {
20 return <Text bold>{displayName}</Text>;
21 }
22
23 // Get the first argument value if it's a simple one
24 let formattedValue = "";
25 const [key, value] = Object.entries(args)[0];
26 if (
27 key.toLowerCase().includes("path") ||
28 typeof value === "number" ||
29 typeof value === "boolean"
30 ) {
31 formattedValue = formatToolArgument(value);
32 } else if (typeof value === "string") {
33 const valueLines = value.split("\n");
34 if (valueLines.length === 1) {
35 formattedValue = formatToolArgument(value);
36 } else {
37 // For multi-line strings, show first line with ellipsis
38 const firstLine = valueLines[0].trim();
39 formattedValue = firstLine
40 ? `${formatToolArgument(firstLine)}...`
41 : "...";
42 }
43 }
44
45 return (
46 <Text>
47 <Text bold>{displayName}</Text>({formattedValue})
48 </Text>
49 );
50}