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