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