/** `resolve` — apply or discard a pending preview/approval action. */ import type { ReactNode } from "react"; import { Badge, Badges, Kv, KvGrid, Note, ResultText } from "../parts"; import type { ToolRenderer, ToolRenderProps } from "../types"; import { detailsRecord, isRecord, normalizeWs, str, truncate } from "../util"; function Summary({ args, result }: ToolRenderProps): ReactNode { const action = str(args.action); const reason = str(args.reason); const tone = result?.isError ? "err" : action === "apply" ? "ok" : "warn"; return ( <> {action ?? "?"} {reason && {truncate(normalizeWs(reason), 100)}} ); } function Body({ args, result }: ToolRenderProps): ReactNode { const action = str(args.action); const reason = str(args.reason); const tone = result?.isError ? "err" : action === "apply" ? "ok" : "warn"; const details = detailsRecord(result); const sourceToolName = details ? str(details.sourceToolName) : null; const label = details ? str(details.label) : null; const extra = isRecord(args.extra) ? args.extra : details && isRecord(details.extra) ? details.extra : null; const extraRows: ReactNode[] = []; if (extra) { for (const k in extra) { const v = extra[k]; let text: string; if (typeof v === "string") text = v; else { try { text = JSON.stringify(v) ?? String(v); } catch { text = String(v); } } extraRows.push( {truncate(normalizeWs(text), 200)} , ); } } return ( <> {action === "apply" ? "proposed → resolved" : action === "discard" ? "proposed → rejected" : (action ?? "?")} , sourceToolName && {sourceToolName}, label && {truncate(normalizeWs(label), 120)}, ]} /> {reason && {reason}} {extraRows.length > 0 && {extraRows}} ); } export const resolveRenderer: ToolRenderer = { Summary, Body };