Files
Agent-Workbench/docs/turn-progress-b-evidence/source/src/client/TurnProgress.tsx
T

26 lines
3.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { Run } from './types';
const labels: Record<string, string> = { baseline: '本次运行基线', waiting: '等待所属操作', evidence_growth: '新增外显证据', new_failure_evidence: '新增失败证据',
user_boundary: '用户边界变化', repeated_failure_candidate: '重复失败候选', repeated_read_candidate: '重复读取候选', no_observed_change: '未见新外显事实', unknown_bounded: '观察容量已满,保留未知' };
const failureLabels: Record<string, string> = { invalid_input: '参数无效', permission: '权限或审批拒绝', requires_verification: '结果待核对', network: '网络连接', service: '上游服务',
authentication: '身份验证', rate_limit: '请求限流', quota: '服务额度', tool_or_environment: '工具或环境', unknown: '尚未分类' };
export function TurnProgress({ run, openArtifact }: { run: Run; openArtifact: (id: string) => void }) {
if (!run.progressShadow && !run.progressShadowError) return null;
const shadow = run.progressShadow;
return <details className="turn-progress" aria-label="单轮观察">
<summary>单轮观察 · 仅记录{shadow ? ` · 已保留 ${shadow.turns.filter(row => row.phase === 'settled').length} 轮` : ''}</summary>
<p className="record-footnote">依据实际工具、文件范围、失败和证据变化分类;观察不改变停止、权限或预算。</p>
{run.progressShadowError && <p className="plan-problem">部分观察未能记录,原工具结果保留。</p>}
{shadow?.truncated && <p className="record-footnote">观察已达保留上限;较早收据仍在原工件中,未保留范围不推定为重复。</p>}
<ol>{shadow?.turns.map((turn, index) => <li key={`${turn.stepId}/${turn.phase}/${index}`}>
<strong>{turn.stepIndex === null ? '基线' : `第 ${turn.stepIndex} 轮`} · {labels[turn.classification] ?? turn.classification}</strong>
<p>新增读取 {turn.delta.read_characters} 字符 · 重复读取 {turn.delta.repeated_reads} 次{turn.delta.changed_files ? ` · 改动文件 ${turn.delta.changed_files}` : ''}{turn.delta.check_results ? ` · 检查结果 ${turn.delta.check_results}` : ''}{turn.delta.requirement_evidence ? ` · 要求证据 ${turn.delta.requirement_evidence}` : ''}</p>
{!!(turn.delta.new_failures || turn.delta.repeated_failures) && <p>新失败 {turn.delta.new_failures} · 重复失败 {turn.delta.repeated_failures}</p>}
{turn.reasons.some(reason => /^(new|repeated)_failure:/.test(reason)) && <p>失败类别:{[...new Set(turn.reasons.filter(reason => /^(new|repeated)_failure:/.test(reason)).map(reason => {
const kind = reason.split(':')[1]; return failureLabels[kind] ?? kind;
}))].join('、')}</p>}
{!!turn.waiting.length && <p>等待 {turn.waiting.map(row => ({ approval: '审批', check_job: '检查作业', review: '审查' }[row.kind] ?? row.kind)).join('、')}</p>}
{run.progressShadowArtifactIds?.[index] && <button className="text-button" onClick={() => openArtifact(run.progressShadowArtifactIds![index])}>查看原观察收据</button>}
</li>)}</ol>
</details>;
}