Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

turnItemPresentation.ts

40 lines1.3 KB

1import {
2 ORCHESTRATION_V2_WORKSPACE_PREPARATION_FAILURE_CODE,
3 type OrchestrationV2Run,
4 type OrchestrationV2TurnItem,
5} from "@t3tools/contracts";
6​
7const WORKSPACE_PREPARATION_INPUT = "Preparing workspace";
8​
9export function turnItemIsWorkspacePreparation(item: OrchestrationV2TurnItem): boolean {
10 return (
11 (item.type === "command_execution" && item.input === WORKSPACE_PREPARATION_INPUT) ||
12 (item.type === "error" &&
13 item.status === "cancelled" &&
14 item.failure.code === ORCHESTRATION_V2_WORKSPACE_PREPARATION_FAILURE_CODE)
15 );
17​
18export function workspacePreparationRetryRunIds(
19 runs: ReadonlyArray<Pick<OrchestrationV2Run, "id" | "status" | "workspacePreparation">>,
20 items: ReadonlyArray<OrchestrationV2TurnItem>,
21): ReadonlySet<OrchestrationV2Run["id"]> {
22 const failedRuns = new Set(
23 runs.flatMap((run) =>
24 run.status === "failed" && run.workspacePreparation !== undefined ? [run.id] : [],
25 ),
26 );
27 const retryable = new Set<OrchestrationV2Run["id"]>();
28 if (failedRuns.size === 0) return retryable;
29 for (const item of items) {
30 if (
31 item.type === "error" &&
32 item.status === "failed" &&
33 item.failure.code === ORCHESTRATION_V2_WORKSPACE_PREPARATION_FAILURE_CODE &&
34 item.runId !== null &&
35 failedRuns.has(item.runId)
36 )
37 retryable.add(item.runId);
38 }
39 return retryable;