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