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 CancelQueuedThreadTurnInput,
9 type DeleteThreadInput,
10 type InterruptThreadTurnInput,
11 type RespondToThreadApprovalInput,
12 type RespondToThreadUserInputInput,
13 type RevertThreadCheckpointInput,
14 type SetThreadInteractionModeInput,
15 type SetThreadRuntimeModeInput,
16 type PinThreadInput,
17 type ReorderPinnedThreadInput,
18 type SettleThreadInput,
19 type SnoozeThreadInput,
20 type StartThreadTurnInput,
21 type StopThreadSessionInput,
22 type UnarchiveThreadInput,
23 type UnpinThreadInput,
24 type UnsettleThreadInput,
25 type UnsnoozeThreadInput,
26 type UpdateThreadMetadataInput,
27 archiveThread,
28 createThread,
29 cancelQueuedThreadTurn,
30 deleteThread,
31 interruptThreadTurn,
32 respondToThreadApproval,
33 respondToThreadUserInput,
34 revertThreadCheckpoint,
35 setThreadInteractionMode,
36 setThreadRuntimeMode,
37 pinThread,
38 reorderPinnedThread,
39 settleThread,
40 snoozeThread,
41 startThreadTurn,
42 stopThreadSession,
43 unarchiveThread,
44 unpinThread,
45 unsettleThread,
46 unsnoozeThread,
47 updateThreadMetadata,
48} from "../operations/commands.ts";
49import type { EnvironmentRegistry } from "../connection/registry.ts";
50
51export type {
52 ArchiveThreadInput,
53 CreateThreadInput,
54 CancelQueuedThreadTurnInput,
55 DeleteThreadInput,
56 InterruptThreadTurnInput,
57 RespondToThreadApprovalInput,
58 RespondToThreadUserInputInput,
59 RevertThreadCheckpointInput,
60 SetThreadInteractionModeInput,
61 SetThreadRuntimeModeInput,
62 PinThreadInput,
63 ReorderPinnedThreadInput,
64 SettleThreadInput,
65 SnoozeThreadInput,
66 StartThreadTurnInput,
67 StopThreadSessionInput,
68 UnarchiveThreadInput,
69 UnpinThreadInput,
70 UnsettleThreadInput,
71 UnsnoozeThreadInput,
72 UpdateThreadMetadataInput,
73} from "../operations/commands.ts";
74
75export function createThreadEnvironmentAtoms<R, E>(
76 runtime: Atom.AtomRuntime<EnvironmentRegistry | Crypto.Crypto | R, E>,
77) {
78 const scheduler = createAtomCommandScheduler();
79 const concurrency = {
80 mode: "serial" as const,
81 key: ({ environmentId, input }: { environmentId: string; input: { threadId: string } }) =>
82 JSON.stringify([environmentId, input.threadId]),
83 };
84 return {
85 create: createEnvironmentCommand(runtime, {
86 label: "environment-data:commands:thread:create",
87 execute: (input: CreateThreadInput) => createThread(input),
88 scheduler,
89 concurrency,
90 }),
91 delete: createEnvironmentCommand(runtime, {
92 label: "environment-data:commands:thread:delete",
93 execute: (input: DeleteThreadInput) => deleteThread(input),
94 scheduler,
95 concurrency,
96 }),
97 archive: createEnvironmentCommand(runtime, {
98 label: "environment-data:commands:thread:archive",
99 execute: (input: ArchiveThreadInput) => archiveThread(input),
100 scheduler,
101 concurrency,
102 }),
103 unarchive: createEnvironmentCommand(runtime, {
104 label: "environment-data:commands:thread:unarchive",
105 execute: (input: UnarchiveThreadInput) => unarchiveThread(input),
106 scheduler,
107 concurrency,
108 }),
109 settle: createEnvironmentCommand(runtime, {
110 label: "environment-data:commands:thread:settle",
111 execute: (input: SettleThreadInput) => settleThread(input),
112 scheduler,
113 concurrency,
114 }),
115 unsettle: createEnvironmentCommand(runtime, {
116 label: "environment-data:commands:thread:unsettle",
117 execute: (input: UnsettleThreadInput) => unsettleThread(input),
118 scheduler,
119 concurrency,
120 }),
121 snooze: createEnvironmentCommand(runtime, {
122 label: "environment-data:commands:thread:snooze",
123 execute: (input: SnoozeThreadInput) => snoozeThread(input),
124 scheduler,
125 concurrency,
126 }),
127 unsnooze: createEnvironmentCommand(runtime, {
128 label: "environment-data:commands:thread:unsnooze",
129 execute: (input: UnsnoozeThreadInput) => unsnoozeThread(input),
130 scheduler,
131 concurrency,
132 }),
133 pin: createEnvironmentCommand(runtime, {
134 label: "environment-data:commands:thread:pin",
135 execute: (input: PinThreadInput) => pinThread(input),
136 scheduler,
137 concurrency,
138 }),
139 unpin: createEnvironmentCommand(runtime, {
140 label: "environment-data:commands:thread:unpin",
141 execute: (input: UnpinThreadInput) => unpinThread(input),
142 scheduler,
143 concurrency,
144 }),
145 reorderPin: createEnvironmentCommand(runtime, {
146 label: "environment-data:commands:thread:reorder-pin",
147 execute: (input: ReorderPinnedThreadInput) => reorderPinnedThread(input),
148 scheduler,
149 concurrency,
150 }),
151 updateMetadata: createEnvironmentCommand(runtime, {
152 label: "environment-data:commands:thread:update-metadata",
153 execute: (input: UpdateThreadMetadataInput) => updateThreadMetadata(input),
154 scheduler,
155 concurrency,
156 }),
157 setRuntimeMode: createEnvironmentCommand(runtime, {
158 label: "environment-data:commands:thread:set-runtime-mode",
159 execute: (input: SetThreadRuntimeModeInput) => setThreadRuntimeMode(input),
160 scheduler,
161 concurrency,
162 }),
163 setInteractionMode: createEnvironmentCommand(runtime, {
164 label: "environment-data:commands:thread:set-interaction-mode",
165 execute: (input: SetThreadInteractionModeInput) => setThreadInteractionMode(input),
166 scheduler,
167 concurrency,
168 }),
169 startTurn: createEnvironmentCommand(runtime, {
170 label: "environment-data:commands:thread:start-turn",
171 execute: (input: StartThreadTurnInput) => startThreadTurn(input),
172 scheduler,
173 concurrency,
174 }),
175 cancelQueuedTurn: createEnvironmentCommand(runtime, {
176 label: "environment-data:commands:thread:cancel-queued-turn",
177 execute: (input: CancelQueuedThreadTurnInput) => cancelQueuedThreadTurn(input),
178 scheduler,
179 concurrency,
180 }),
181 interruptTurn: createEnvironmentCommand(runtime, {
182 label: "environment-data:commands:thread:interrupt-turn",
183 execute: (input: InterruptThreadTurnInput) => interruptThreadTurn(input),
184 scheduler,
185 concurrency,
186 }),
187 respondToApproval: createEnvironmentCommand(runtime, {
188 label: "environment-data:commands:thread:respond-to-approval",
189 execute: (input: RespondToThreadApprovalInput) => respondToThreadApproval(input),
190 scheduler,
191 concurrency,
192 }),
193 respondToUserInput: createEnvironmentCommand(runtime, {
194 label: "environment-data:commands:thread:respond-to-user-input",
195 execute: (input: RespondToThreadUserInputInput) => respondToThreadUserInput(input),
196 scheduler,
197 concurrency,
198 }),
199 revertCheckpoint: createEnvironmentCommand(runtime, {
200 label: "environment-data:commands:thread:revert-checkpoint",
201 execute: (input: RevertThreadCheckpointInput) => revertThreadCheckpoint(input),
202 scheduler,
203 concurrency,
204 }),
205 stopSession: createEnvironmentCommand(runtime, {
206 label: "environment-data:commands:thread:stop-session",
207 execute: (input: StopThreadSessionInput) => stopThreadSession(input),
208 scheduler,
209 concurrency,
210 }),
211 };
212}