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

turnItemPresentation.ts

42 lines1.4 KB

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