Converts hardcoded UI copy to i18n keys across the app, adds global translation for non-component modules, and splits the English catalog into feature modules with duplicate-key detection.
34 lines
1.4 KiB
TypeScript
34 lines
1.4 KiB
TypeScript
import type { ToolRenderer } from "../types"
|
|
import { ensureMarkdownContent, extractDiffPayload, getRelativePath, getToolName, isToolStateCompleted, readToolStatePayload } from "../utils"
|
|
import { tGlobal } from "../../../lib/i18n"
|
|
|
|
export const editRenderer: ToolRenderer = {
|
|
tools: ["edit"],
|
|
getAction: () => tGlobal("toolCall.renderer.action.preparingEdit"),
|
|
getTitle({ toolState }) {
|
|
const state = toolState()
|
|
if (!state) return undefined
|
|
const { input } = readToolStatePayload(state)
|
|
const filePath = typeof input.filePath === "string" ? input.filePath : ""
|
|
if (!filePath) return getToolName("edit")
|
|
return `${getToolName("edit")} ${getRelativePath(filePath)}`
|
|
},
|
|
renderBody({ toolState, toolName, renderDiff, renderMarkdown }) {
|
|
const state = toolState()
|
|
if (!state || state.status === "pending") return null
|
|
|
|
const diffPayload = extractDiffPayload(toolName(), state)
|
|
if (diffPayload) {
|
|
return renderDiff(diffPayload)
|
|
}
|
|
|
|
const { metadata } = readToolStatePayload(state)
|
|
const diffText = typeof metadata.diff === "string" ? metadata.diff : null
|
|
const fallback = isToolStateCompleted(state) && typeof state.output === "string" ? state.output : null
|
|
const content = ensureMarkdownContent(diffText || fallback, "diff", true)
|
|
if (!content) return null
|
|
|
|
return renderMarkdown({ content, size: "large", disableHighlight: state.status === "running" })
|
|
},
|
|
}
|