mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-17 13:55:50 +00:00
72 lines
1.9 KiB
TypeScript
72 lines
1.9 KiB
TypeScript
import React from 'react';
|
|
import { MessageResponse } from '../../components/MessageResponse.js';
|
|
import { TOOL_SUMMARY_MAX_LENGTH } from '../../constants/toolLimits.js';
|
|
import { Box, Text } from '../../ink.js';
|
|
import type { ToolProgressData } from '../../Tool.js';
|
|
import type { ProgressMessage } from '../../types/message.js';
|
|
import { formatFileSize, truncate } from '../../utils/format.js';
|
|
import type { Output } from './WebFetchTool.js';
|
|
export function renderToolUseMessage({
|
|
url,
|
|
prompt
|
|
}: Partial<{
|
|
url: string;
|
|
prompt: string;
|
|
}>, {
|
|
verbose
|
|
}: {
|
|
theme?: string;
|
|
verbose: boolean;
|
|
}): React.ReactNode {
|
|
if (!url) {
|
|
return null;
|
|
}
|
|
if (verbose) {
|
|
return `url: "${url}"${verbose && prompt ? `, prompt: "${prompt}"` : ''}`;
|
|
}
|
|
return url;
|
|
}
|
|
export function renderToolUseProgressMessage(): React.ReactNode {
|
|
return <MessageResponse height={1}>
|
|
<Text dimColor>Fetching…</Text>
|
|
</MessageResponse>;
|
|
}
|
|
export function renderToolResultMessage({
|
|
bytes,
|
|
code,
|
|
codeText,
|
|
result
|
|
}: Output, _progressMessagesForMessage: ProgressMessage<ToolProgressData>[], {
|
|
verbose
|
|
}: {
|
|
verbose: boolean;
|
|
}): React.ReactNode {
|
|
const formattedSize = formatFileSize(bytes);
|
|
if (verbose) {
|
|
return <Box flexDirection="column">
|
|
<MessageResponse height={1}>
|
|
<Text>
|
|
Received <Text bold>{formattedSize}</Text> ({code} {codeText})
|
|
</Text>
|
|
</MessageResponse>
|
|
<Box flexDirection="column">
|
|
<Text>{result}</Text>
|
|
</Box>
|
|
</Box>;
|
|
}
|
|
return <MessageResponse height={1}>
|
|
<Text>
|
|
Received <Text bold>{formattedSize}</Text> ({code} {codeText})
|
|
</Text>
|
|
</MessageResponse>;
|
|
}
|
|
export function getToolUseSummary(input: Partial<{
|
|
url: string;
|
|
prompt: string;
|
|
}> | undefined): string | null {
|
|
if (!input?.url) {
|
|
return null;
|
|
}
|
|
return truncate(input.url, TOOL_SUMMARY_MAX_LENGTH);
|
|
}
|