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