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