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 { type OrchestrationV2TurnItem } from "@t3tools/contracts"; |
| 2 | import * as DateTime from "effect/DateTime"; |
| 3 | |
| 4 | export function subagentGroupTiming( |
| 5 | agents: ReadonlyArray<{ |
| 6 | status: OrchestrationV2TurnItem["status"]; |
| 7 | startedAt: DateTime.Utc | null; |
| 8 | completedAt: DateTime.Utc | null; |
| 9 | }>, |
| 10 | ) { |
| 11 | let startMs: number | null = null; |
| 12 | let endMs: number | null = null; |
| 13 | let endUnknown = false; |
| 14 | for (const agent of agents) { |
| 15 | if (agent.startedAt) { |
| 16 | const ms = DateTime.toEpochMillis(agent.startedAt); |
| 17 | startMs = startMs === null ? ms : Math.min(startMs, ms); |
| 18 | } |
| 19 | if (agent.completedAt) { |
| 20 | const ms = DateTime.toEpochMillis(agent.completedAt); |
| 21 | endMs = endMs === null ? ms : Math.max(endMs, ms); |
| 22 | } else { |
| 23 | endUnknown = true; |
| 24 | } |
| 25 | } |
| 26 | const live = agents.some( |
| 27 | ({ status }) => status === "pending" || status === "running" || status === "waiting", |
| 28 | ); |
| 29 | return { |
| 30 | status: live ? ("running" as const) : ("completed" as const), |
| 31 | startedAt: startMs === null ? null : new Date(startMs).toISOString(), |
| 32 | completedAt: live || endUnknown || endMs === null ? null : new Date(endMs).toISOString(), |
| 33 | }; |
| 34 | } |