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

orchestrationV2Timeline.ts

42 lines1.3 KB

1import type {
2 OrchestrationV2Run,
3 OrchestrationV2RunAttempt,
4 OrchestrationV2TurnItem,
5} from "@t3tools/contracts";
6​
7type TimelineRun = Pick<OrchestrationV2Run, "id" | "status">;
8type TimelineRunAttempt = Pick<OrchestrationV2RunAttempt, "runId" | "rootNodeId" | "status">;
9type TimelineTurnItem = Pick<OrchestrationV2TurnItem, "type" | "runId" | "nodeId">;
10​
11export function isOrchestrationV2SupersededInterrupt(input: {
12 readonly item: TimelineTurnItem;
13 readonly attempts: ReadonlyArray<TimelineRunAttempt>;
14}): boolean {
15 const { item } = input;
16 if (item.type !== "run_interrupt_result" || item.runId === null || item.nodeId === null) {
17 return false;
18 }
19​
20 return input.attempts.some(
21 (attempt) =>
22 attempt.runId === item.runId &&
23 attempt.rootNodeId === item.nodeId &&
24 attempt.status === "superseded",
25 );
27​
28export function isOrchestrationV2TurnItemVisible(input: {
29 readonly item: TimelineTurnItem;
30 readonly runs: ReadonlyArray<TimelineRun>;
31 readonly attempts: ReadonlyArray<TimelineRunAttempt>;
32}): boolean {
33 const { item } = input;
34 if (
35 item.runId !== null &&
36 input.runs.some((run) => run.id === item.runId && run.status === "rolled_back")
37 ) {
38 return false;
39 }
40​
41 return !isOrchestrationV2SupersededInterrupt({ item, attempts: input.attempts });