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(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(`/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

当前缺口与下一步

{active ?

等待所属运行、检查或审批结束,再核对当前结果。

: error ?

{error} 请刷新当前结果;原记录保留。

: current ? <>

{current.followUp.statusLabel}

下一步:{current.followUp.nextStep}

{!!current.followUp.gaps.length &&
待处理事项 · {current.followUp.gaps.length}
    {current.followUp.gaps.map((gap, i) =>
  • {gap.label}

    {gap.nextStep}

  • )}
} {diagnostic && context &&
最近只读诊断 · {diagnostic.status === 'completed' ? '答复已完成' : diagnostic.status === 'failed' ? '诊断失败' : '尚未完成'}

{diagnostic.question}

{diagnostic.failure &&

本次诊断错误:{diagnostic.failure.message}

} {context.evidenceVerified ? <>

原执行:{context.originalRunId?.slice(0, 8) ?? '未记录'}

原错误:{context.failure?.value.message ?? '未记录具体错误;原因保持未知。'}

{context.check &&

原检查:{context.check.id.slice(0, 8)} · {context.check.status}

} :

{context.error ?? context.note}

} {context.artifactId && }
}

{current.followUp.note}

:

正在核对当前目标、要求和原结果。

}
; }