Files
t3code/packages/shared/src/orchestrationV2Timeline.ts
T
Julius Marminge 844dad005a feat(orchestration): track provider retries and thread visits
- Project retry progress and recovery for Codex and Claude turns
- Sync thread completion markers through server-side visit timestamps
2026-08-07 13:27:21 +02:00

74 lines
2.3 KiB
TypeScript

import type {
OrchestrationV2Run,
OrchestrationV2RunAttempt,
OrchestrationV2TurnItem,
OrchestrationV2UserMessageInputIntent,
} from "@t3tools/contracts";
type TimelineRun = Pick<OrchestrationV2Run, "id" | "status">;
type TimelineRunAttempt = Pick<OrchestrationV2RunAttempt, "runId" | "rootNodeId" | "status">;
type TimelineTurnItem = Pick<OrchestrationV2TurnItem, "type" | "runId" | "nodeId"> & {
readonly inputIntent?: OrchestrationV2UserMessageInputIntent;
};
export function isOrchestrationV2SupersededInterrupt(input: {
readonly item: TimelineTurnItem;
readonly attempts: ReadonlyArray<TimelineRunAttempt>;
readonly items: ReadonlyArray<TimelineTurnItem>;
}): boolean {
const { item } = input;
if (item.type !== "run_interrupt_result" || item.runId === null || item.nodeId === null) {
return false;
}
const isSuperseded = input.attempts.some(
(attempt) =>
attempt.runId === item.runId &&
attempt.rootNodeId === item.nodeId &&
attempt.status === "superseded",
);
if (!isSuperseded) {
return false;
}
// Paired stop-then-steer results have a matching request on the same run and
// must stay visible. Legacy plain-steer results have no request and stay hidden.
const hasMatchingRequest = input.items.some(
(candidate) => candidate.type === "run_interrupt_request" && candidate.runId === item.runId,
);
return !hasMatchingRequest;
}
export function isOrchestrationV2TurnItemVisible(input: {
readonly item: TimelineTurnItem;
readonly runs: ReadonlyArray<TimelineRun>;
readonly attempts: ReadonlyArray<TimelineRunAttempt>;
readonly items: ReadonlyArray<TimelineTurnItem>;
}): boolean {
const { item } = input;
if (
item.runId !== null &&
input.runs.some((run) => run.id === item.runId && run.status === "rolled_back")
) {
return false;
}
// A queued message is composer state, not conversation history. When its run
// is cancelled the input never reached the provider, so it must not surface
// as a transcript row.
if (
item.type === "user_message" &&
item.inputIntent === "queued_turn" &&
item.runId !== null &&
input.runs.some((run) => run.id === item.runId && run.status === "cancelled")
) {
return false;
}
return !isOrchestrationV2SupersededInterrupt({
item,
attempts: input.attempts,
items: input.items,
});
}