/** * @license * Copyright 2025 Qwen Team * SPDX-License-Identifier: Apache-2.0 * * Edit tool call component - specialized for file editing operations */ import { useMemo } from 'react'; import type { BaseToolCallProps } from '../shared/types.js'; import { groupContent, mapToolStatusToContainerStatus, } from '../shared/utils.js'; import { FileLink } from '../../../layout/FileLink.js'; import type { ToolCallContainerProps } from '../shared/LayoutComponents.js'; export const ToolCallContainer: React.FC = ({ label, status = 'success', children, toolCallId: _toolCallId, labelSuffix, className: _className, }) => (
{label} {labelSuffix}
{children && (
{children}
)}
); /** * Calculate diff summary (added/removed lines) */ const getDiffSummary = ( oldText: string | null | undefined, newText: string | undefined, ): string => { const oldLines = oldText ? oldText.split('\n').length : 0; const newLines = newText ? newText.split('\n').length : 0; const diff = newLines - oldLines; if (diff > 0) { return `+${diff} lines`; } else if (diff < 0) { return `${diff} lines`; } else { return 'Modified'; } }; /** * Specialized component for Edit tool calls * Optimized for displaying file editing operations with diffs */ export const EditToolCall: React.FC = ({ toolCall }) => { const { content, locations, toolCallId } = toolCall; // Group content by type; memoize to avoid new array identities on every render const { errors, diffs } = useMemo(() => groupContent(content), [content]); // Failed case: show explicit failed message and render inline diffs if (toolCall.status === 'failed') { const firstDiff = diffs[0]; const path = firstDiff?.path || locations?.[0]?.path || ''; const containerStatus = mapToolStatusToContainerStatus(toolCall.status); return (
Edit {path && ( )}
{/* Failed state text (replace summary) */}
edit failed
); } // Error case: show error if (errors.length > 0) { const path = diffs[0]?.path || locations?.[0]?.path || ''; return ( ) : undefined } > {errors.join('\n')} ); } // Success case with diff: show minimal inline preview; clicking the title opens VS Code diff if (diffs.length > 0) { const firstDiff = diffs[0]; const path = firstDiff.path || (locations && locations[0]?.path) || ''; const summary = getDiffSummary(firstDiff.oldText, firstDiff.newText); const containerStatus = mapToolStatusToContainerStatus(toolCall.status); return (
{/* Align the inline Edit label styling with shared toolcall label: larger + bold */} Edit {path && ( )}
{summary}
); } // Success case without diff: show file in compact format if (locations && locations.length > 0) { const containerStatus = mapToolStatusToContainerStatus(toolCall.status); return ( } >
); } // No output, don't show anything return null; };