import type { JSX } from "react"; import { translate } from "../../../../i18n/index"; import { AgentCodeBlock } from "./code/AgentCodeBlock"; import { AgentUnifiedPatchViewer } from "./file-diff/AgentUnifiedPatchViewer"; import { stringValue, ToolMarkdownBlock, ToolSection, type AgentToolRendererProps } from "./agentToolContentShared"; import { getFileChangeRenderData, getToolCallFailureText } from "./render-data/agentToolRenderData"; export function AgentWriteContent({ call, onLinkClick }: AgentToolRendererProps): JSX.Element | null { "use memo"; const files = getFileChangeRenderData(call); const [file] = files; const path = file?.path ?? stringValue(call.input?.path) ?? stringValue(call.input?.file_path) ?? stringValue(call.input?.filePath) ?? null; const contentFiles = files.filter((candidate) => candidate.content !== null); const contentPaths = new Set(contentFiles.map((candidate) => candidate.path)); const patchFiles = files.filter( (candidate) => candidate.unifiedDiff !== null && !contentPaths.has(candidate.path) ); const fallbackContent = files.length === 0 ? call.summary.trim() || null : null; const failureText = getToolCallFailureText(call); const showFileHeaders = files.length > 1; const hasRenderableContent = Boolean(failureText) || Boolean(path && files.length === 0) || patchFiles.length > 0 || contentFiles.length > 0 || Boolean(fallbackContent); if (!hasRenderableContent) { return null; } return (