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