Files
Agent-Workbench/src/client/TaskFollowUp.tsx
T

43 lines
3.5 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 { useEffect, useState } from 'react';
import { api } from './api';
import type { DeliveryStatus, Session } from './types';
export function TaskFollowUp({ session, openArtifact }: { session: Session; openArtifact: (id: string) => void }) {
const task = session.execution?.task, run = session.execution?.run;
const [value, setValue] = useState<DeliveryStatus | null>(null), [error, setError] = useState(''), [refresh, setRefresh] = useState(0), [loading, setLoading] = useState(false);
const identity = session.id + '/' + task?.id + '/' + run?.id;
const [loadedIdentity, setLoadedIdentity] = useState('');
const active = ['running', 'awaiting_approval', 'stopping'].includes(session.status);
useEffect(() => {
let alive = true;
setError('');
if (!task || !run || active) { setLoading(false); return; }
const timer = setTimeout(() => {
setLoading(true); setError('');
api<DeliveryStatus>(`/sessions/${session.id}/delivery-status?taskId=${task.id}&runId=${run.id}`)
.then(result => { if (alive) { setValue(result); setLoadedIdentity(identity); } })
.catch(reason => { if (alive) { setError(reason instanceof Error ? reason.message : String(reason)); setValue(null); } })
.finally(() => { if (alive) setLoading(false); });
}, 160);
return () => { alive = false; clearTimeout(timer); };
}, [identity, session.revision, session.status, refresh]);
const current = loadedIdentity === identity ? value : null, diagnostic = current?.diagnostics.at(-1), context = diagnostic?.context;
return <section className="task-record-section task-follow-up" aria-label="当前缺口与下一步">
<div className="record-heading"><h3>当前缺口与下一步</h3><button className="text-button" disabled={active || loading} onClick={() => setRefresh(n => n + 1)}>{loading ? '正在核对' : '刷新当前结果'}</button></div>
{active ? <p className="record-footnote">等待所属运行、检查或审批结束,再核对当前结果。</p> : error ? <p role="alert" className="plan-problem">{error} 请刷新当前结果;原记录保留。</p> : current ? <>
<p><strong>{current.followUp.statusLabel}</strong></p>
<p className="follow-up-next">下一步:{current.followUp.nextStep}</p>
{!!current.followUp.gaps.length && <details><summary>待处理事项 · {current.followUp.gaps.length}</summary><ul>{current.followUp.gaps.map((gap, i) => <li key={gap.kind + gap.id + i}><strong>{gap.label}</strong><p>{gap.nextStep}</p></li>)}</ul></details>}
{diagnostic && context && <div className="diagnostic-origin" aria-label="诊断原执行">
<strong>最近只读诊断 · {diagnostic.status === 'completed' ? '答复已完成' : diagnostic.status === 'failed' ? '诊断失败' : '尚未完成'}</strong>
<p>{diagnostic.question}</p>
{diagnostic.failure && <p>本次诊断错误:{diagnostic.failure.message}</p>}
{context.evidenceVerified ? <><p>原执行:{context.originalRunId?.slice(0, 8) ?? '未记录'}</p><p>原错误:{context.failure?.value.message ?? '未记录具体错误;原因保持未知。'}</p>
{context.check && <p>原检查:{context.check.id.slice(0, 8)} · {context.check.status}</p>}</> : <p>{context.error ?? context.note}</p>}
{context.artifactId && <button className="text-button" onClick={() => openArtifact(context.artifactId!)}>查看诊断原绑定</button>}
</div>}
<p className="record-footnote">{current.followUp.note}</p>
</> : <p className="record-footnote">正在核对当前目标、要求和原结果。</p>}
</section>;
}