Open History to see the last commit
1import * as Crypto from "effect/Crypto";
2import { Atom } from "effect/unstable/reactivity";
3
4import { createAtomCommandScheduler, createEnvironmentCommand } from "./runtime.ts";
5import {
6 type ArchiveThreadInput,
7 type CreateThreadInput,
8 type DeleteThreadInput,
9 type InterruptThreadTurnInput,
10 type RespondToThreadApprovalInput,
11 type RespondToThreadUserInputInput,
12 type RevertThreadCheckpointInput,
13 type SetThreadInteractionModeInput,
14 type SetThreadRuntimeModeInput,
15 type SettleThreadInput,
16 type StartThreadTurnInput,
17 type StopThreadSessionInput,
18 type UnarchiveThreadInput,
19 type UnsettleThreadInput,
20 type UpdateThreadMetadataInput,
21 archiveThread,
22 createThread,
23 deleteThread,
24 interruptThreadTurn,
25 respondToThreadApproval,
26 respondToThreadUserInput,
27 revertThreadCheckpoint,
28 setThreadInteractionMode,
29 setThreadRuntimeMode,
30 settleThread,
31 startThreadTurn,
32 stopThreadSession,
33 unarchiveThread,
34 unsettleThread,
35 updateThreadMetadata,
36} from "../operations/commands.ts";
37import type { EnvironmentRegistry } from "../connection/registry.ts";
38
39export type {
40 ArchiveThreadInput,
41 CreateThreadInput,
42 DeleteThreadInput,
43 InterruptThreadTurnInput,
44 RespondToThreadApprovalInput,
45 RespondToThreadUserInputInput,
46 RevertThreadCheckpointInput,
47 SetThreadInteractionModeInput,
48 SetThreadRuntimeModeInput,
49 SettleThreadInput,
50 StartThreadTurnInput,
51 StopThreadSessionInput,
52 UnarchiveThreadInput,
53 UnsettleThreadInput,
54 UpdateThreadMetadataInput,
55} from "../operations/commands.ts";
56
57export function createThreadEnvironmentAtoms<R, E>(
58 runtime: Atom.AtomRuntime<EnvironmentRegistry | Crypto.Crypto | R, E>,
59) {
60 const scheduler = createAtomCommandScheduler();
61 const concurrency = {
62 mode: "serial" as const,
63 key: ({ environmentId, input }: { environmentId: string; input: { threadId: string } }) =>
64 JSON.stringify([environmentId, input.threadId]),
65 };
66 return {
67 create: createEnvironmentCommand(runtime, {
68 label: "environment-data:commands:thread:create",
69 execute: (input: CreateThreadInput) => createThread(input),
70 scheduler,
71 concurrency,
72 }),
73 delete: createEnvironmentCommand(runtime, {
74 label: "environment-data:commands:thread:delete",
75 execute: (input: DeleteThreadInput) => deleteThread(input),
76 scheduler,
77 concurrency,
78 }),
79 archive: createEnvironmentCommand(runtime, {
80 label: "environment-data:commands:thread:archive",
81 execute: (input: ArchiveThreadInput) => archiveThread(input),
82 scheduler,
83 concurrency,
84 }),
85 unarchive: createEnvironmentCommand(runtime, {
86 label: "environment-data:commands:thread:unarchive",
87 execute: (input: UnarchiveThreadInput) => unarchiveThread(input),
88 scheduler,
89 concurrency,
90 }),
91 settle: createEnvironmentCommand(runtime, {
92 label: "environment-data:commands:thread:settle",
93 execute: (input: SettleThreadInput) => settleThread(input),
94 scheduler,
95 concurrency,
96 }),
97 unsettle: createEnvironmentCommand(runtime, {
98 label: "environment-data:commands:thread:unsettle",
99 execute: (input: UnsettleThreadInput) => unsettleThread(input),
100 scheduler,
101 concurrency,
102 }),
103 updateMetadata: createEnvironmentCommand(runtime, {
104 label: "environment-data:commands:thread:update-metadata",
105 execute: (input: UpdateThreadMetadataInput) => updateThreadMetadata(input),
106 scheduler,
107 concurrency,
108 }),
109 setRuntimeMode: createEnvironmentCommand(runtime, {
110 label: "environment-data:commands:thread:set-runtime-mode",
111 execute: (input: SetThreadRuntimeModeInput) => setThreadRuntimeMode(input),
112 scheduler,
113 concurrency,
114 }),
115 setInteractionMode: createEnvironmentCommand(runtime, {
116 label: "environment-data:commands:thread:set-interaction-mode",
117 execute: (input: SetThreadInteractionModeInput) => setThreadInteractionMode(input),
118 scheduler,
119 concurrency,
120 }),
121 startTurn: createEnvironmentCommand(runtime, {
122 label: "environment-data:commands:thread:start-turn",
123 execute: (input: StartThreadTurnInput) => startThreadTurn(input),
124 scheduler,
125 concurrency,
126 }),
127 interruptTurn: createEnvironmentCommand(runtime, {
128 label: "environment-data:commands:thread:interrupt-turn",
129 execute: (input: InterruptThreadTurnInput) => interruptThreadTurn(input),
130 scheduler,
131 concurrency,
132 }),
133 respondToApproval: createEnvironmentCommand(runtime, {
134 label: "environment-data:commands:thread:respond-to-approval",
135 execute: (input: RespondToThreadApprovalInput) => respondToThreadApproval(input),
136 scheduler,
137 concurrency,
138 }),
139 respondToUserInput: createEnvironmentCommand(runtime, {
140 label: "environment-data:commands:thread:respond-to-user-input",
141 execute: (input: RespondToThreadUserInputInput) => respondToThreadUserInput(input),
142 scheduler,
143 concurrency,
144 }),
145 revertCheckpoint: createEnvironmentCommand(runtime, {
146 label: "environment-data:commands:thread:revert-checkpoint",
147 execute: (input: RevertThreadCheckpointInput) => revertThreadCheckpoint(input),
148 scheduler,
149 concurrency,
150 }),
151 stopSession: createEnvironmentCommand(runtime, {
152 label: "environment-data:commands:thread:stop-session",
153 execute: (input: StopThreadSessionInput) => stopThreadSession(input),
154 scheduler,
155 concurrency,
156 }),
157 };
158}