// 执行记录按工作动作分组;展开状态由调用方控制。 import type { ReactNode } from 'react' import { Collapsible, ToolBlock } from '@ui' import type { Part } from '../contracts' import { formatDuration, humanSize } from '../messageparts' import { timelineEntries, toolGroupLabel, type ToolGroupItem } from '../toolkind' export function ProcessTimeline({ parts, live, idKey, renderPart }: { parts: Part[] live: boolean idKey: string renderPart: (part: Part, liveText: boolean) => ReactNode }) { const rows = timelineEntries(parts, live) return (
{rows.map((row, i) => { if (row.kind === 'thinking') { return row.text &&
思考过程
{row.text}
} if (row.kind === 'text') { return
{renderPart({ type: 'text', text: row.text }, false)}
} if (row.kind === 'check') { const text = row.passed ? '终轮检查通过' : `终轮检查未通过:${row.reason}` return
{text}
} if (row.kind === 'toolblock') { return } if (row.kind === 'tools') { const running = row.items.some(it => it.running) return (
{toolGroupLabel(row.toolKind, row.items.length, running)}
    {row.items.map((it, j) => (
  • {it.headline} {it.status === 'error' && 失败} {it.summary && {it.summary}} {(it.arguments || it.output) && 查看记录 ▸}> {it.arguments &&
    {it.arguments}
    } {it.output &&
    {it.output}
    }
    }
  • ))}
) } return
{renderPart(row.part, false)}
})}
) } function sizeLabel(n: number): string { if (n < 1024) return `${n} 字符` return humanSize(n) } function ToolCallBlock({ item }: { item: ToolGroupItem }) { const composing = item.phase === 'composing' const dur = !item.running ? formatDuration(item.durationMs) : '' const detail = composing ? undefined : (dur ? `${item.headline} · ${dur}` : item.headline) return (
{item.arguments &&
{item.arguments}
} {item.output &&
{item.output}
}
) }