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 CancelQueuedRunInput,
8 type CreateThreadInput,
9 type DeleteThreadInput,
10 type EditQueuedRunInput,
11 type InterruptThreadTurnInput,
12 type MarkThreadUnreadInput,
13 type ForkThreadFromRunInput,
14 type MergeThreadBackInput,
15 type PromoteQueuedRunInput,
16 type ReorderQueuedRunInput,
17 type RespondToThreadApprovalInput,
18 type RespondToThreadUserInputInput,
19 type RevertThreadCheckpointInput,
20 type SetThreadInteractionModeInput,
21 type SetThreadRuntimeModeInput,
22 type PinThreadInput,
23 type SettleThreadInput,
24 type SnoozeThreadInput,
25 type StartThreadTurnInput,
26 type StopThreadSessionInput,
27 type UnarchiveThreadInput,
28 type UnpinThreadInput,
29 type UnsettleThreadInput,
30 type UnsnoozeThreadInput,
31 type UpdateThreadMetadataInput,
32 type VisitThreadInput,
33 archiveThread,
34 cancelQueuedRun,
35 createThread,
36 deleteThread,
37 editQueuedRun,
38 interruptThreadTurn,
39 forkThreadFromRun,
40 markThreadUnread,
41 mergeThreadBack,
42 promoteQueuedRun,
43 reorderQueuedRun,
44 respondToThreadApproval,
45 respondToThreadUserInput,
46 revertThreadCheckpoint,
47 setThreadInteractionMode,
48 setThreadRuntimeMode,
49 pinThread,
50 settleThread,
51 snoozeThread,
52 startThreadTurn,
53 stopThreadSession,
54 unarchiveThread,
55 unpinThread,
56 unsettleThread,
57 unsnoozeThread,
58 updateThreadMetadata,
59 visitThread,
60} from "../operations/commands.ts";
61import type { EnvironmentRegistry } from "../connection/registry.ts";
62
63export type {
64 ArchiveThreadInput,
65 CancelQueuedRunInput,
66 CreateThreadInput,
67 DeleteThreadInput,
68 EditQueuedRunInput,
69 InterruptThreadTurnInput,
70 MarkThreadUnreadInput,
71 ForkThreadFromRunInput,
72 MergeThreadBackInput,
73 PromoteQueuedRunInput,
74 ReorderQueuedRunInput,
75 RespondToThreadApprovalInput,
76 RespondToThreadUserInputInput,
77 RevertThreadCheckpointInput,
78 SetThreadInteractionModeInput,
79 SetThreadRuntimeModeInput,
80 PinThreadInput,
81 SettleThreadInput,
82 SnoozeThreadInput,
83 StartThreadTurnInput,
84 StopThreadSessionInput,
85 ThreadCommandInput,
86 UnarchiveThreadInput,
87 UnpinThreadInput,
88 UnsettleThreadInput,
89 UnsnoozeThreadInput,
90 UpdateThreadMetadataInput,
91 VisitThreadInput,
92} from "../operations/commands.ts";
93
94export function createThreadEnvironmentAtoms<R, E>(
95 runtime: Atom.AtomRuntime<EnvironmentRegistry | Crypto.Crypto | R, E>,
96) {
97 const scheduler = createAtomCommandScheduler();
98 const concurrency = {
99 mode: "serial" as const,
100 key: ({ environmentId, input }: { environmentId: string; input: { threadId: string } }) =>
101 JSON.stringify([environmentId, input.threadId]),
102 };
103 return {
104 create: createEnvironmentCommand(runtime, {
105 label: "environment-data:commands:thread:create",
106 execute: (input: CreateThreadInput) => createThread(input),
107 scheduler,
108 concurrency,
109 }),
110 delete: createEnvironmentCommand(runtime, {
111 label: "environment-data:commands:thread:delete",
112 execute: (input: DeleteThreadInput) => deleteThread(input),
113 scheduler,
114 concurrency,
115 }),
116 archive: createEnvironmentCommand(runtime, {
117 label: "environment-data:commands:thread:archive",
118 execute: (input: ArchiveThreadInput) => archiveThread(input),
119 scheduler,
120 concurrency,
121 }),
122 unarchive: createEnvironmentCommand(runtime, {
123 label: "environment-data:commands:thread:unarchive",
124 execute: (input: UnarchiveThreadInput) => unarchiveThread(input),
125 scheduler,
126 concurrency,
127 }),
128 settle: createEnvironmentCommand(runtime, {
129 label: "environment-data:commands:thread:settle",
130 execute: (input: SettleThreadInput) => settleThread(input),
131 scheduler,
132 concurrency,
133 }),
134 unsettle: createEnvironmentCommand(runtime, {
135 label: "environment-data:commands:thread:unsettle",
136 execute: (input: UnsettleThreadInput) => unsettleThread(input),
137 scheduler,
138 concurrency,
139 }),
140 snooze: createEnvironmentCommand(runtime, {
141 label: "environment-data:commands:thread:snooze",
142 execute: (input: SnoozeThreadInput) => snoozeThread(input),
143 scheduler,
144 concurrency,
145 }),
146 unsnooze: createEnvironmentCommand(runtime, {
147 label: "environment-data:commands:thread:unsnooze",
148 execute: (input: UnsnoozeThreadInput) => unsnoozeThread(input),
149 scheduler,
150 concurrency,
151 }),
152 pin: createEnvironmentCommand(runtime, {
153 label: "environment-data:commands:thread:pin",
154 execute: (input: PinThreadInput) => pinThread(input),
155 scheduler,
156 concurrency,
157 }),
158 unpin: createEnvironmentCommand(runtime, {
159 label: "environment-data:commands:thread:unpin",
160 execute: (input: UnpinThreadInput) => unpinThread(input),
161 scheduler,
162 concurrency,
163 }),
164 visit: createEnvironmentCommand(runtime, {
165 label: "environment-data:commands:thread:visit",
166 execute: (input: VisitThreadInput) => visitThread(input),
167 scheduler,
168 concurrency,
169 }),
170 markUnread: createEnvironmentCommand(runtime, {
171 label: "environment-data:commands:thread:mark-unread",
172 execute: (input: MarkThreadUnreadInput) => markThreadUnread(input),
173 scheduler,
174 concurrency,
175 }),
176 updateMetadata: createEnvironmentCommand(runtime, {
177 label: "environment-data:commands:thread:update-metadata",
178 execute: (input: UpdateThreadMetadataInput) => updateThreadMetadata(input),
179 scheduler,
180 concurrency,
181 }),
182 setRuntimeMode: createEnvironmentCommand(runtime, {
183 label: "environment-data:commands:thread:set-runtime-mode",
184 execute: (input: SetThreadRuntimeModeInput) => setThreadRuntimeMode(input),
185 scheduler,
186 concurrency,
187 }),
188 setInteractionMode: createEnvironmentCommand(runtime, {
189 label: "environment-data:commands:thread:set-interaction-mode",
190 execute: (input: SetThreadInteractionModeInput) => setThreadInteractionMode(input),
191 scheduler,
192 concurrency,
193 }),
194 startTurn: createEnvironmentCommand(runtime, {
195 label: "environment-data:commands:thread:start-turn",
196 execute: (input: StartThreadTurnInput) => startThreadTurn(input),
197 scheduler,
198 concurrency,
199 }),
200 interruptTurn: createEnvironmentCommand(runtime, {
201 label: "environment-data:commands:thread:interrupt-turn",
202 execute: (input: InterruptThreadTurnInput) => interruptThreadTurn(input),
203 scheduler,
204 concurrency,
205 }),
206 respondToApproval: createEnvironmentCommand(runtime, {
207 label: "environment-data:commands:thread:respond-to-approval",
208 execute: (input: RespondToThreadApprovalInput) => respondToThreadApproval(input),
209 scheduler,
210 concurrency,
211 }),
212 respondToUserInput: createEnvironmentCommand(runtime, {
213 label: "environment-data:commands:thread:respond-to-user-input",
214 execute: (input: RespondToThreadUserInputInput) => respondToThreadUserInput(input),
215 scheduler,
216 concurrency,
217 }),
218 revertCheckpoint: createEnvironmentCommand(runtime, {
219 label: "environment-data:commands:thread:revert-checkpoint",
220 execute: (input: RevertThreadCheckpointInput) => revertThreadCheckpoint(input),
221 scheduler,
222 concurrency,
223 }),
224 stopSession: createEnvironmentCommand(runtime, {
225 label: "environment-data:commands:thread:stop-session",
226 execute: (input: StopThreadSessionInput) => stopThreadSession(input),
227 scheduler,
228 concurrency,
229 }),
230 forkFromRun: createEnvironmentCommand(runtime, {
231 label: "environment-data:commands:thread:fork-from-run",
232 execute: (input: ForkThreadFromRunInput) => forkThreadFromRun(input),
233 scheduler,
234 concurrency: {
235 mode: "serial",
236 key: ({ environmentId, input }) => JSON.stringify([environmentId, input.sourceThreadId]),
237 },
238 }),
239 mergeBack: createEnvironmentCommand(runtime, {
240 label: "environment-data:commands:thread:merge-back",
241 execute: (input: MergeThreadBackInput) => mergeThreadBack(input),
242 scheduler,
243 concurrency: {
244 mode: "serial",
245 key: ({ environmentId, input }) =>
246 JSON.stringify([environmentId, input.sourceThreadId, input.targetThreadId]),
247 },
248 }),
249 reorderQueuedRun: createEnvironmentCommand(runtime, {
250 label: "environment-data:commands:thread:reorder-queued-run",
251 execute: (input: ReorderQueuedRunInput) => reorderQueuedRun(input),
252 scheduler,
253 concurrency,
254 }),
255 promoteQueuedRun: createEnvironmentCommand(runtime, {
256 label: "environment-data:commands:thread:promote-queued-run",
257 execute: (input: PromoteQueuedRunInput) => promoteQueuedRun(input),
258 scheduler,
259 concurrency,
260 }),
261 cancelQueuedRun: createEnvironmentCommand(runtime, {
262 label: "environment-data:commands:thread:cancel-queued-run",
263 execute: (input: CancelQueuedRunInput) => cancelQueuedRun(input),
264 scheduler,
265 concurrency,
266 }),
267 editQueuedRun: createEnvironmentCommand(runtime, {
268 label: "environment-data:commands:thread:edit-queued-run",
269 execute: (input: EditQueuedRunInput) => editQueuedRun(input),
270 scheduler,
271 concurrency,
272 }),
273 };
274}