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