import type { ReactNode } from "react"; import type { ZCodeModelTrajectoryContentPart, ZCodeModelTrajectoryRecord, ZCodeModelTrajectoryUsage, } from "@zcode/services"; import { Badge } from "@/components/ui/badge.js"; import { cn } from "@/components/lib/utils.js"; import type { useZCodeIntl } from "@/i18n/IntlProvider.js"; type IntlShape = ReturnType["intl"]; export function ContentPartView({ part, intl, sectionLabel, showToolHeader = true, }: { part: ZCodeModelTrajectoryContentPart; intl: IntlShape; sectionLabel?: string; showToolHeader?: boolean; }) { if (part.kind === "text") { if (!part.text) { return null; } const content = (

{part.text}

); return sectionLabel ? {content} : content; } if (part.kind === "reasoning") { if (!part.text) { return null; } return (

{part.text}

); } if (part.kind === "tool-call") { return ( ); } if (part.kind === "tool-result") { return ( ); } if (part.kind === "image") { return ( [image{part.mediaType ? ` · ${part.mediaType}` : ""}] ); } return ; } function ToolPayload({ label, id, payloadLabel, value, intl, showHeader, }: { label: string; id?: string; payloadLabel: string; value: unknown; intl: IntlShape; showHeader: boolean; }) { const payload = (
{payloadLabel}
); return showHeader ? ( : null}> {payload} ) : ( payload ); } function ToolIdBadge({ id, intl }: { id: string; intl: IntlShape }) { return ( {intl.formatMessage({ id: "modelTrajectory.toolId" })}: {id} ); } function DetailSection({ label, meta, children, }: { label: string; meta?: ReactNode; children: ReactNode; }) { return (
{label} {meta ? {meta} : null}
{children}
); } function CodeBlock({ value }: { value: string }) { return (
      {value || "—"}
    
); } export function UsageBadges({ usage, intl, }: { usage?: ZCodeModelTrajectoryUsage; intl: IntlShape; }) { if (!usage) { return null; } const parts: string[] = []; if (typeof usage.inputTokens === "number") { parts.push( intl.formatMessage( { id: "modelTrajectory.usage.input" }, { count: usage.inputTokens.toLocaleString() }, ), ); } if (typeof usage.outputTokens === "number") { parts.push( intl.formatMessage( { id: "modelTrajectory.usage.output" }, { count: usage.outputTokens.toLocaleString() }, ), ); } if (parts.length === 0) { return null; } return ( {parts.join(" ")} ); } export function EmptyState({ text, detail, tone, }: { text: string; detail?: string; tone?: "error"; }) { return (

{text}

{detail ? (

{detail}

) : null}
); } export function summarizeRecords(records: ZCodeModelTrajectoryRecord[]): { totalTokens: number; models: string[]; } { let totalTokens = 0; const models = new Set(); for (const record of records) { const total = record.response?.usage?.totalTokens; if (typeof total === "number") { totalTokens += total; } const model = record.model.modelId ?? record.response?.modelId; if (model) { models.add(model); } } return { totalTokens, models: [...models] }; } function formatValue(value: unknown): string { if (value === undefined || value === null) { return ""; } if (typeof value === "string") { return value; } try { return JSON.stringify(value, null, 2); } catch { return String(value); } }