continue-custom/extensions/cli/src/ui/components/ToolPreview.tsx
Nate be45ab63ca Add 'extensions/cli/' from commit 'e27a5c87d520e28844c9eac10bc6d301feee4b5e'
git-subtree-dir: extensions/cli
git-subtree-mainline: 1674c2aff1
git-subtree-split: e27a5c87d5
2025-08-20 17:19:56 -07:00

63 lines
1.7 KiB
TypeScript

import { Box, Text } from "ink";
import React from "react";
import { getToolDisplayName } from "../../tools/index.js";
import { ToolCallPreview } from "../../tools/types.js";
import { ColoredDiff } from "../ColoredDiff.js";
import { ChecklistDisplay } from "./ChecklistDisplay.js";
interface ToolPreviewProps {
toolCallPreview?: ToolCallPreview[];
toolName: string;
toolArgs: any;
}
/**
* Generates a preview of what a tool will do based on its arguments
*/
export const ToolPreview: React.FC<ToolPreviewProps> = ({
toolCallPreview,
toolName,
toolArgs,
}) => {
if (toolCallPreview) {
return (
<Box display={"flex"} flexDirection="column" marginTop={1}>
{toolCallPreview.map((preview, index) => {
if (preview.type === "text") {
return (
<Box key={index} paddingLeft={preview.paddingLeft ?? 0}>
{index === 0 && <Text color="gray">⎿ </Text>}
<Text color={preview.color ?? "gray"}>{preview.content}</Text>
</Box>
);
} else if (preview.type === "checklist") {
return (
<Box key={index}>
<ChecklistDisplay
content={`Task list status:\n${preview.content}`}
/>
</Box>
);
} else {
return <ColoredDiff key={index} diffContent={preview.content} />;
}
})}
</Box>
);
}
let message = `Will call ${getToolDisplayName(toolName)}`;
const argCount = Object.keys(toolArgs || {}).length;
if (argCount > 0) {
message += ` with ${argCount} argument${argCount === 1 ? "" : "s"}`;
}
return (
<Box>
<Text color="gray">⎿ </Text>
<Text color="gray">{message}</Text>
</Box>
);
};