Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

threadCommands.ts

258 lines8.7 KB

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