fix: build problems

This commit is contained in:
Nate 2025-08-27 21:07:57 -07:00
parent ec592c7229
commit 8d1dc7ff41
4 changed files with 55 additions and 52 deletions

View file

@ -0,0 +1,50 @@
import { Text } from "ink";
import React from "react";
import { formatToolArgument } from "./formatters.js";
import { getToolDisplayName } from "./index.js";
/**
* Formats a tool call with its arguments for display
* @param toolName The name of the tool
* @param args The tool arguments
* @returns A React node with bolded tool name like "<b>ToolName</b>(arg)" or just "<b>ToolName</b>" if no args
*/
export function ToolCallTitle(props: { toolName: string; args?: any }) {
const { toolName, args } = props;
const displayName = getToolDisplayName(toolName);
if (!args || Object.keys(args).length === 0) {
return <Text bold>{displayName}</Text>;
}
// Get the first argument value if it's a simple one
let formattedValue = "";
const [key, value] = Object.entries(args)[0];
if (
key.toLowerCase().includes("path") ||
typeof value === "number" ||
typeof value === "boolean"
) {
formattedValue = formatToolArgument(value);
} else if (typeof value === "string") {
const valueLines = value.split("\n");
if (valueLines.length === 1) {
formattedValue = formatToolArgument(value);
} else {
// For multi-line strings, show first line with ellipsis
const firstLine = valueLines[0].trim();
formattedValue = firstLine
? `${formatToolArgument(firstLine)}...`
: "...";
}
}
return (
<Text>
<Text bold>{displayName}</Text>({formattedValue})
</Text>
);
}

View file

@ -1,7 +1,4 @@
// @ts-ignore
import { Text } from "ink";
import * as React from "react";
import {
getServiceSync,
MCPServiceState,
@ -15,7 +12,6 @@ import { logger } from "../util/logger.js";
import { editTool } from "./edit.js";
import { exitTool } from "./exit.js";
import { fetchTool } from "./fetch.js";
import { formatToolArgument } from "./formatters.js";
import { listFilesTool } from "./listFiles.js";
import { multiEditTool } from "./multiEdit.js";
import { readFileTool } from "./readFile.js";
@ -206,45 +202,3 @@ export function validateToolCallArgsPresent(toolCall: ToolCall, tool: Tool) {
}
}
}
/**
* Formats a tool call with its arguments for display
* @param toolName The name of the tool
* @param args The tool arguments
* @returns A React node with bolded tool name like "<b>ToolName</b>(arg)" or just "<b>ToolName</b>" if no args
*/
export function formatToolCall(toolName: string, args?: any): React.ReactNode {
const displayName = getToolDisplayName(toolName);
if (!args || Object.keys(args).length === 0) {
return <Text bold>{displayName}</Text>;
}
// Get the first argument value if it's a simple one
let formattedValue = "";
const [key, value] = Object.entries(args)[0];
if (
key.toLowerCase().includes("path") ||
typeof value === "number" ||
typeof value === "boolean"
) {
formattedValue = formatToolArgument(value);
} else if (typeof value === "string") {
const valueLines = value.split("\n");
if (valueLines.length === 1) {
formattedValue = formatToolArgument(value);
} else {
// For multi-line strings, show first line with ellipsis
const firstLine = valueLines[0].trim();
formattedValue = firstLine
? `${formatToolArgument(firstLine)}...`
: "...";
}
}
return (
<Text>
<Text bold>{displayName}</Text>({formattedValue})
</Text>
);
}

View file

@ -1,7 +1,7 @@
import { Box, Text } from "ink";
import React, { memo } from "react";
import { formatToolCall } from "src/tools/index.js";
import { ToolCallTitle } from "src/tools/ToolCallTitle.js";
import type { ChatHistoryItem } from "../../../../../core/index.js";
import { MarkdownRenderer } from "../MarkdownRenderer.js";
@ -93,7 +93,7 @@ export const MemoizedMessage = memo<MemoizedMessageProps>(
</Text>
<Text color="white">
{" "}
{formatToolCall(toolName, toolArgs)}
<ToolCallTitle toolName={toolName} args={toolArgs} />
</Text>
</Box>

View file

@ -1,7 +1,8 @@
import { Box, Text, useInput } from "ink";
import React, { useState } from "react";
import { formatToolCall } from "../../tools/index.js";
import { ToolCallTitle } from "src/tools/ToolCallTitle.js";
import { ToolCallPreview } from "../../tools/types.js";
import { ToolPreview } from "./ToolPreview.js";
@ -101,8 +102,6 @@ export const ToolPermissionSelector: React.FC<ToolPermissionSelectorProps> = ({
}
});
const toolCallDisplay = formatToolCall(toolName, toolArgs);
return (
<Box
flexDirection="column"
@ -111,7 +110,7 @@ export const ToolPermissionSelector: React.FC<ToolPermissionSelectorProps> = ({
borderColor="magenta"
>
<Text color="magenta" bold>
{toolCallDisplay}
<ToolCallTitle toolName={toolName} args={toolArgs} />
</Text>
{/* Show preview of what the tool will do */}