import * as Crypto from "effect/Crypto";import { Atom } from "effect/unstable/reactivity"; import { createAtomCommandScheduler, createEnvironmentCommand } from "./runtime.ts";import { type ArchiveThreadInput, type CancelQueuedRunInput, type CreateThreadInput, type DeleteThreadInput, type EditQueuedRunInput, type InterruptThreadTurnInput, type MarkThreadUnreadInput, type ForkThreadFromRunInput, type MergeThreadBackInput, type PromoteQueuedRunInput, type ReorderQueuedRunInput, type RespondToThreadApprovalInput, type RespondToThreadUserInputInput, type RevertThreadCheckpointInput, type SetThreadInteractionModeInput, type SetThreadRuntimeModeInput, type SettleThreadInput, type SnoozeThreadInput, type StartThreadTurnInput, type StopThreadSessionInput, type UnarchiveThreadInput, type UnsettleThreadInput, type UnsnoozeThreadInput, type UpdateThreadMetadataInput, type VisitThreadInput, archiveThread, cancelQueuedRun, createThread, deleteThread, editQueuedRun, interruptThreadTurn, forkThreadFromRun, markThreadUnread, mergeThreadBack, promoteQueuedRun, reorderQueuedRun, respondToThreadApproval, respondToThreadUserInput, revertThreadCheckpoint, setThreadInteractionMode, setThreadRuntimeMode, settleThread, snoozeThread, startThreadTurn, stopThreadSession, unarchiveThread, unsettleThread, unsnoozeThread, updateThreadMetadata, visitThread,} from "../operations/commands.ts";import type { EnvironmentRegistry } from "../connection/registry.ts"; export type { ArchiveThreadInput, CancelQueuedRunInput, CreateThreadInput, DeleteThreadInput, EditQueuedRunInput, InterruptThreadTurnInput, MarkThreadUnreadInput, ForkThreadFromRunInput, MergeThreadBackInput, PromoteQueuedRunInput, ReorderQueuedRunInput, RespondToThreadApprovalInput, RespondToThreadUserInputInput, RevertThreadCheckpointInput, SetThreadInteractionModeInput, SetThreadRuntimeModeInput, SettleThreadInput, SnoozeThreadInput, StartThreadTurnInput, StopThreadSessionInput, ThreadCommandInput, UnarchiveThreadInput, UnsettleThreadInput, UnsnoozeThreadInput, UpdateThreadMetadataInput, VisitThreadInput,} from "../operations/commands.ts"; export function createThreadEnvironmentAtoms<R, E>( runtime: Atom.AtomRuntime<EnvironmentRegistry | Crypto.Crypto | R, E>,) { const scheduler = createAtomCommandScheduler(); const concurrency = { mode: "serial" as const, key: ({ environmentId, input }: { environmentId: string; input: { threadId: string } }) => JSON.stringify([environmentId, input.threadId]), }; return { create: createEnvironmentCommand(runtime, { label: "environment-data:commands:thread:create", execute: (input: CreateThreadInput) => createThread(input), scheduler, concurrency, }), delete: createEnvironmentCommand(runtime, { label: "environment-data:commands:thread:delete", execute: (input: DeleteThreadInput) => deleteThread(input), scheduler, concurrency, }), archive: createEnvironmentCommand(runtime, { label: "environment-data:commands:thread:archive", execute: (input: ArchiveThreadInput) => archiveThread(input), scheduler, concurrency, }), unarchive: createEnvironmentCommand(runtime, { label: "environment-data:commands:thread:unarchive", execute: (input: UnarchiveThreadInput) => unarchiveThread(input), scheduler, concurrency, }), settle: createEnvironmentCommand(runtime, { label: "environment-data:commands:thread:settle", execute: (input: SettleThreadInput) => settleThread(input), scheduler, concurrency, }), unsettle: createEnvironmentCommand(runtime, { label: "environment-data:commands:thread:unsettle", execute: (input: UnsettleThreadInput) => unsettleThread(input), scheduler, concurrency, }), snooze: createEnvironmentCommand(runtime, { label: "environment-data:commands:thread:snooze", execute: (input: SnoozeThreadInput) => snoozeThread(input), scheduler, concurrency, }), unsnooze: createEnvironmentCommand(runtime, { label: "environment-data:commands:thread:unsnooze", execute: (input: UnsnoozeThreadInput) => unsnoozeThread(input), scheduler, concurrency, }), visit: createEnvironmentCommand(runtime, { label: "environment-data:commands:thread:visit", execute: (input: VisitThreadInput) => visitThread(input), scheduler, concurrency, }), markUnread: createEnvironmentCommand(runtime, { label: "environment-data:commands:thread:mark-unread", execute: (input: MarkThreadUnreadInput) => markThreadUnread(input), scheduler, concurrency, }), updateMetadata: createEnvironmentCommand(runtime, { label: "environment-data:commands:thread:update-metadata", execute: (input: UpdateThreadMetadataInput) => updateThreadMetadata(input), scheduler, concurrency, }), setRuntimeMode: createEnvironmentCommand(runtime, { label: "environment-data:commands:thread:set-runtime-mode", execute: (input: SetThreadRuntimeModeInput) => setThreadRuntimeMode(input), scheduler, concurrency, }), setInteractionMode: createEnvironmentCommand(runtime, { label: "environment-data:commands:thread:set-interaction-mode", execute: (input: SetThreadInteractionModeInput) => setThreadInteractionMode(input), scheduler, concurrency, }), startTurn: createEnvironmentCommand(runtime, { label: "environment-data:commands:thread:start-turn", execute: (input: StartThreadTurnInput) => startThreadTurn(input), scheduler, concurrency, }), interruptTurn: createEnvironmentCommand(runtime, { label: "environment-data:commands:thread:interrupt-turn", execute: (input: InterruptThreadTurnInput) => interruptThreadTurn(input), scheduler, concurrency, }), respondToApproval: createEnvironmentCommand(runtime, { label: "environment-data:commands:thread:respond-to-approval", execute: (input: RespondToThreadApprovalInput) => respondToThreadApproval(input), scheduler, concurrency, }), respondToUserInput: createEnvironmentCommand(runtime, { label: "environment-data:commands:thread:respond-to-user-input", execute: (input: RespondToThreadUserInputInput) => respondToThreadUserInput(input), scheduler, concurrency, }), revertCheckpoint: createEnvironmentCommand(runtime, { label: "environment-data:commands:thread:revert-checkpoint", execute: (input: RevertThreadCheckpointInput) => revertThreadCheckpoint(input), scheduler, concurrency, }), stopSession: createEnvironmentCommand(runtime, { label: "environment-data:commands:thread:stop-session", execute: (input: StopThreadSessionInput) => stopThreadSession(input), scheduler, concurrency, }), forkFromRun: createEnvironmentCommand(runtime, { label: "environment-data:commands:thread:fork-from-run", execute: (input: ForkThreadFromRunInput) => forkThreadFromRun(input), scheduler, concurrency: { mode: "serial", key: ({ environmentId, input }) => JSON.stringify([environmentId, input.sourceThreadId]), }, }), mergeBack: createEnvironmentCommand(runtime, { label: "environment-data:commands:thread:merge-back", execute: (input: MergeThreadBackInput) => mergeThreadBack(input), scheduler, concurrency: { mode: "serial", key: ({ environmentId, input }) => JSON.stringify([environmentId, input.sourceThreadId, input.targetThreadId]), }, }), reorderQueuedRun: createEnvironmentCommand(runtime, { label: "environment-data:commands:thread:reorder-queued-run", execute: (input: ReorderQueuedRunInput) => reorderQueuedRun(input), scheduler, concurrency, }), promoteQueuedRun: createEnvironmentCommand(runtime, { label: "environment-data:commands:thread:promote-queued-run", execute: (input: PromoteQueuedRunInput) => promoteQueuedRun(input), scheduler, concurrency, }), cancelQueuedRun: createEnvironmentCommand(runtime, { label: "environment-data:commands:thread:cancel-queued-run", execute: (input: CancelQueuedRunInput) => cancelQueuedRun(input), scheduler, concurrency, }), editQueuedRun: createEnvironmentCommand(runtime, { label: "environment-data:commands:thread:edit-queued-run", execute: (input: EditQueuedRunInput) => editQueuedRun(input), scheduler, concurrency, }), };}
import * as Crypto from "effect/Crypto";
import { Atom } from "effect/unstable/reactivity";
import { createAtomCommandScheduler, createEnvironmentCommand } from "./runtime.ts";
import {
type ArchiveThreadInput,
type CancelQueuedRunInput,
type CreateThreadInput,
type DeleteThreadInput,
type EditQueuedRunInput,
type InterruptThreadTurnInput,
type MarkThreadUnreadInput,
type ForkThreadFromRunInput,
type MergeThreadBackInput,
type PromoteQueuedRunInput,
type ReorderQueuedRunInput,
type RespondToThreadApprovalInput,
type RespondToThreadUserInputInput,
type RevertThreadCheckpointInput,
type SetThreadInteractionModeInput,
type SetThreadRuntimeModeInput,
type SettleThreadInput,
type SnoozeThreadInput,
type StartThreadTurnInput,
type StopThreadSessionInput,
type UnarchiveThreadInput,
type UnsettleThreadInput,
type UnsnoozeThreadInput,
type UpdateThreadMetadataInput,
type VisitThreadInput,
archiveThread,
cancelQueuedRun,
createThread,
deleteThread,
editQueuedRun,
interruptThreadTurn,
forkThreadFromRun,
markThreadUnread,
mergeThreadBack,
promoteQueuedRun,
reorderQueuedRun,
respondToThreadApproval,
respondToThreadUserInput,
revertThreadCheckpoint,
setThreadInteractionMode,
setThreadRuntimeMode,
settleThread,
snoozeThread,
startThreadTurn,
stopThreadSession,
unarchiveThread,
unsettleThread,
unsnoozeThread,
updateThreadMetadata,
visitThread,
} from "../operations/commands.ts";
import type { EnvironmentRegistry } from "../connection/registry.ts";
export type {
ArchiveThreadInput,
CancelQueuedRunInput,
CreateThreadInput,
DeleteThreadInput,
EditQueuedRunInput,
InterruptThreadTurnInput,
MarkThreadUnreadInput,
ForkThreadFromRunInput,
MergeThreadBackInput,
PromoteQueuedRunInput,
ReorderQueuedRunInput,
RespondToThreadApprovalInput,
RespondToThreadUserInputInput,
RevertThreadCheckpointInput,
SetThreadInteractionModeInput,
SetThreadRuntimeModeInput,
SettleThreadInput,
SnoozeThreadInput,
StartThreadTurnInput,
StopThreadSessionInput,
ThreadCommandInput,
UnarchiveThreadInput,
UnsettleThreadInput,
UnsnoozeThreadInput,
UpdateThreadMetadataInput,
VisitThreadInput,
} from "../operations/commands.ts";
export function createThreadEnvironmentAtoms<R, E>(
runtime: Atom.AtomRuntime<EnvironmentRegistry | Crypto.Crypto | R, E>,
) {
const scheduler = createAtomCommandScheduler();
const concurrency = {
mode: "serial" as const,
key: ({ environmentId, input }: { environmentId: string; input: { threadId: string } }) =>
JSON.stringify([environmentId, input.threadId]),
};
return {
create: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:create",
execute: (input: CreateThreadInput) => createThread(input),
scheduler,
concurrency,
}),
delete: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:delete",
execute: (input: DeleteThreadInput) => deleteThread(input),
scheduler,
concurrency,
}),
archive: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:archive",
execute: (input: ArchiveThreadInput) => archiveThread(input),
scheduler,
concurrency,
}),
unarchive: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:unarchive",
execute: (input: UnarchiveThreadInput) => unarchiveThread(input),
scheduler,
concurrency,
}),
settle: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:settle",
execute: (input: SettleThreadInput) => settleThread(input),
scheduler,
concurrency,
}),
unsettle: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:unsettle",
execute: (input: UnsettleThreadInput) => unsettleThread(input),
scheduler,
concurrency,
}),
snooze: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:snooze",
execute: (input: SnoozeThreadInput) => snoozeThread(input),
scheduler,
concurrency,
}),
unsnooze: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:unsnooze",
execute: (input: UnsnoozeThreadInput) => unsnoozeThread(input),
scheduler,
concurrency,
}),
visit: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:visit",
execute: (input: VisitThreadInput) => visitThread(input),
scheduler,
concurrency,
}),
markUnread: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:mark-unread",
execute: (input: MarkThreadUnreadInput) => markThreadUnread(input),
scheduler,
concurrency,
}),
updateMetadata: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:update-metadata",
execute: (input: UpdateThreadMetadataInput) => updateThreadMetadata(input),
scheduler,
concurrency,
}),
setRuntimeMode: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:set-runtime-mode",
execute: (input: SetThreadRuntimeModeInput) => setThreadRuntimeMode(input),
scheduler,
concurrency,
}),
setInteractionMode: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:set-interaction-mode",
execute: (input: SetThreadInteractionModeInput) => setThreadInteractionMode(input),
scheduler,
concurrency,
}),
startTurn: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:start-turn",
execute: (input: StartThreadTurnInput) => startThreadTurn(input),
scheduler,
concurrency,
}),
interruptTurn: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:interrupt-turn",
execute: (input: InterruptThreadTurnInput) => interruptThreadTurn(input),
scheduler,
concurrency,
}),
respondToApproval: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:respond-to-approval",
execute: (input: RespondToThreadApprovalInput) => respondToThreadApproval(input),
scheduler,
concurrency,
}),
respondToUserInput: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:respond-to-user-input",
execute: (input: RespondToThreadUserInputInput) => respondToThreadUserInput(input),
scheduler,
concurrency,
}),
revertCheckpoint: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:revert-checkpoint",
execute: (input: RevertThreadCheckpointInput) => revertThreadCheckpoint(input),
scheduler,
concurrency,
}),
stopSession: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:stop-session",
execute: (input: StopThreadSessionInput) => stopThreadSession(input),
scheduler,
concurrency,
}),
forkFromRun: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:fork-from-run",
execute: (input: ForkThreadFromRunInput) => forkThreadFromRun(input),
scheduler,
concurrency: {
mode: "serial",
key: ({ environmentId, input }) => JSON.stringify([environmentId, input.sourceThreadId]),
},
}),
mergeBack: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:merge-back",
execute: (input: MergeThreadBackInput) => mergeThreadBack(input),
scheduler,
concurrency: {
mode: "serial",
key: ({ environmentId, input }) =>
JSON.stringify([environmentId, input.sourceThreadId, input.targetThreadId]),
},
}),
reorderQueuedRun: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:reorder-queued-run",
execute: (input: ReorderQueuedRunInput) => reorderQueuedRun(input),
scheduler,
concurrency,
}),
promoteQueuedRun: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:promote-queued-run",
execute: (input: PromoteQueuedRunInput) => promoteQueuedRun(input),
scheduler,
concurrency,
}),
cancelQueuedRun: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:cancel-queued-run",
execute: (input: CancelQueuedRunInput) => cancelQueuedRun(input),
scheduler,
concurrency,
}),
editQueuedRun: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:edit-queued-run",
execute: (input: EditQueuedRunInput) => editQueuedRun(input),
scheduler,
concurrency,
}),
};
}