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