The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { isActiveSubagentStatus } from "@t3tools/client-runtime/state/subagentRuntime"; |
| 2 | import type { OrchestrationV2Subagent } from "@t3tools/contracts"; |
| 3 | import { formatDuration } from "@t3tools/shared/orchestrationTimingCopy"; |
| 4 | import * as DateTime from "effect/DateTime"; |
| 5 | |
| 6 | import { m, type MessageResolver } from "../../i18n/messages"; |
| 7 | |
| 8 | export function subagentCardElapsed( |
| 9 | agents: ReadonlyArray<Pick<OrchestrationV2Subagent, "status" | "startedAt" | "completedAt">>, |
| 10 | nowMs: number, |
| 11 | resolve: MessageResolver = m, |
| 12 | ): string | null { |
| 13 | const starts = agents.flatMap((agent) => |
| 14 | agent.startedAt ? [DateTime.toEpochMillis(agent.startedAt)] : [], |
| 15 | ); |
| 16 | if (starts.length === 0) return null; |
| 17 | const live = agents.some((agent) => isActiveSubagentStatus(agent.status)); |
| 18 | if (!live && agents.some((agent) => agent.completedAt === null)) return null; |
| 19 | const ends = agents.flatMap((agent) => |
| 20 | agent.completedAt ? [DateTime.toEpochMillis(agent.completedAt)] : [], |
| 21 | ); |
| 22 | const duration = (live ? nowMs : Math.max(...ends)) - Math.min(...starts); |
| 23 | return duration > 0 ? formatDuration(duration, resolve) : null; |
| 24 | } |