Open History to see the last commit
1import { ORCHESTRATION_V2_WS_METHODS } from "@t3tools/contracts";
2import { Atom } from "effect/reactivity";
3
4import {
5 createEnvironmentRpcCommand,
6 createEnvironmentRpcQueryAtomFamily,
7 createEnvironmentRpcSubscriptionAtomFamily,
8} from "./runtime.ts";
9import type { EnvironmentRegistry } from "../connection/registry.ts";
10
11export function createOrchestrationEnvironmentAtoms<R, E>(
12 runtime: Atom.AtomRuntime<EnvironmentRegistry | R, E>,
13) {
14 return {
15 v2: {
16 dispatchCommand: createEnvironmentRpcCommand(runtime, {
17 label: "environment-data:orchestration-v2:dispatch-command",
18 tag: ORCHESTRATION_V2_WS_METHODS.dispatchCommand,
19 }),
20 threadProjection: createEnvironmentRpcQueryAtomFamily(runtime, {
21 label: "environment-data:orchestration-v2:thread-projection",
22 tag: ORCHESTRATION_V2_WS_METHODS.getThreadProjection,
23 staleTimeMs: 0,
24 idleTtlMs: 0,
25 }),
26 shell: createEnvironmentRpcSubscriptionAtomFamily(runtime, {
27 label: "environment-data:orchestration-v2:shell",
28 tag: ORCHESTRATION_V2_WS_METHODS.subscribeShell,
29 }),
30 thread: createEnvironmentRpcSubscriptionAtomFamily(runtime, {
31 label: "environment-data:orchestration-v2:thread",
32 tag: ORCHESTRATION_V2_WS_METHODS.subscribeThread,
33 idleTtlMs: 0,
34 }),
35 },
36 turnDiff: createEnvironmentRpcQueryAtomFamily(runtime, {
37 label: "environment-data:orchestration:turn-diff",
38 tag: ORCHESTRATION_V2_WS_METHODS.getTurnDiff,
39 }),
40 workflowScript: createEnvironmentRpcQueryAtomFamily(runtime, {
41 label: "environment-data:orchestration:workflow-script",
42 tag: ORCHESTRATION_V2_WS_METHODS.getWorkflowScript,
43 // Scripts are immutable per run: cache generously.
44 staleTimeMs: 300_000,
45 idleTtlMs: 300_000,
46 }),
47 stopWorkflow: createEnvironmentRpcCommand(runtime, {
48 label: "environment-data:orchestration:stop-workflow",
49 tag: ORCHESTRATION_V2_WS_METHODS.stopWorkflow,
50 }),
51 // Keyed by the item revision, so a live row refetches as its output grows.
52 turnItem: createEnvironmentRpcQueryAtomFamily(runtime, {
53 label: "environment-data:orchestration:turn-item",
54 tag: ORCHESTRATION_V2_WS_METHODS.getTurnItem,
55 staleTimeMs: 60_000,
56 idleTtlMs: 60_000,
57 }),
58 fullThreadDiff: createEnvironmentRpcQueryAtomFamily(runtime, {
59 label: "environment-data:orchestration:full-thread-diff",
60 tag: ORCHESTRATION_V2_WS_METHODS.getFullThreadDiff,
61 }),
62 threadFind: createEnvironmentRpcQueryAtomFamily(runtime, {
63 label: "environment-data:orchestration:thread-find",
64 tag: ORCHESTRATION_V2_WS_METHODS.searchThread,
65 staleTimeMs: 0,
66 idleTtlMs: 0,
67 }),
68 threadFindProgressive: createEnvironmentRpcSubscriptionAtomFamily(runtime, {
69 label: "environment-data:orchestration:thread-find-progressive",
70 tag: ORCHESTRATION_V2_WS_METHODS.searchThreadStream,
71 completeWhen: (result) => result.complete !== false,
72 idleTtlMs: 0,
73 }),
74 threadSearch: createEnvironmentRpcQueryAtomFamily(runtime, {
75 label: "environment-data:orchestration:thread-search",
76 tag: ORCHESTRATION_V2_WS_METHODS.searchThreads,
77 staleTimeMs: 30_000,
78 idleTtlMs: 60_000,
79 }),
80 archivedShellSnapshot: createEnvironmentRpcQueryAtomFamily(runtime, {
81 label: "environment-data:orchestration:archived-shell-snapshot",
82 tag: ORCHESTRATION_V2_WS_METHODS.getArchivedShellSnapshot,
83 }),
84 };
85}