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

runInterruptResult.ts

43 lines1.4 KB

1import {
2 type OrchestrationV2ExecutionNode,
3 type OrchestrationV2ProviderThread,
4 type OrchestrationV2Run,
5 type OrchestrationV2TurnItem,
6 RUN_STOPPED_BY_PROVIDER_REASON,
7} from "@t3tools/contracts";
8import type * as DateTime from "effect/DateTime";
9import type * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
10​
11export function makeInterruptResultTurnItem(input: {
12 readonly idAllocator: IdAllocator.IdAllocatorV2["Service"];
13 readonly run: OrchestrationV2Run;
14 readonly rootNode: OrchestrationV2ExecutionNode;
15 readonly providerThread: OrchestrationV2ProviderThread;
16 readonly reason: string | undefined;
17 readonly completedAt: DateTime.Utc;
18}): OrchestrationV2TurnItem {
19 return {
20 id: input.idAllocator.derive.runSignalTurnItem({
21 runId: input.run.id,
22 signal: "interrupt-result",
23 }),
24 threadId: input.run.threadId,
25 runId: input.run.id,
26 nodeId: input.rootNode.id,
27 providerThreadId: input.providerThread.id,
28 providerTurnId: input.rootNode.providerTurnId,
29 nativeItemRef: null,
30 parentItemId: input.idAllocator.derive.runSignalTurnItem({
31 runId: input.run.id,
32 signal: "interrupt-request",
33 }),
34 ordinal: input.run.ordinal * 100 + 98,
35 status: "interrupted",
36 title: "Interrupted",
37 startedAt: input.completedAt,
38 completedAt: input.completedAt,
39 updatedAt: input.completedAt,
40 type: "run_interrupt_result",
41 message: input.reason ?? RUN_STOPPED_BY_PROVIDER_REASON,
42 };