| 1 | import "./SubagentDetails.css"; |
| 2 | |
| 3 | import { useT, type Translator } from "../lib/i18n"; |
| 4 | import { parseSubagentOutcomeText, type SubagentOutcome } from "../lib/subagentOutcome"; |
| 5 | |
| 6 | type SubagentOutcomeCardProps = { |
| 7 | text?: string; |
| 8 | outcome?: SubagentOutcome; |
| 9 | }; |
| 10 | |
| 11 | function outcomeLabel(t: Translator, status: string): string { |
| 12 | switch (status) { |
| 13 | case "completed": return t("subagent.phase.completed"); |
| 14 | case "partial": return t("subagent.phase.partial"); |
| 15 | case "failed": return t("subagent.phase.failed"); |
| 16 | case "cancelled": return t("subagent.phase.cancelled"); |
| 17 | default: return status; |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | export function SubagentOutcomeCard({ |
| 22 | text, |
| 23 | outcome, |
| 24 | }: SubagentOutcomeCardProps) { |
| 25 | const t = useT(); |
| 26 | const [ref, status, errorCode, retryable] = outcome ?? parseSubagentOutcomeText(text) ?? []; |
| 27 | if (!ref && !status) return null; |
| 28 | return ( |
| 29 | <div className="tool__subagent-outcome"> |
| 30 | <div className="tool__subagent-outcome-status"> |
| 31 | {t("caps.subagent")} {outcomeLabel(t, status ?? "unknown")} |
| 32 | {retryable ? ` · ${t("subagent.outcome.retryable")}` : ""} |
| 33 | </div> |
| 34 | {ref && <code>{ref}</code>} |
| 35 | {errorCode && <div className="tool__note">{errorCode}</div>} |
| 36 | </div> |
| 37 | ); |
| 38 | } |
| 39 |