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

orchestration.ts

81 lines3.2 KB

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 // Keyed by the item revision, so a live row refetches as its output grows.
48 turnItem: createEnvironmentRpcQueryAtomFamily(runtime, {
49 label: "environment-data:orchestration:turn-item",
50 tag: ORCHESTRATION_V2_WS_METHODS.getTurnItem,
51 staleTimeMs: 60_000,
52 idleTtlMs: 60_000,
53 }),
54 fullThreadDiff: createEnvironmentRpcQueryAtomFamily(runtime, {
55 label: "environment-data:orchestration:full-thread-diff",
56 tag: ORCHESTRATION_V2_WS_METHODS.getFullThreadDiff,
57 }),
58 threadFind: createEnvironmentRpcQueryAtomFamily(runtime, {
59 label: "environment-data:orchestration:thread-find",
60 tag: ORCHESTRATION_V2_WS_METHODS.searchThread,
61 staleTimeMs: 0,
62 idleTtlMs: 0,
63 }),
64 threadFindProgressive: createEnvironmentRpcSubscriptionAtomFamily(runtime, {
65 label: "environment-data:orchestration:thread-find-progressive",
66 tag: ORCHESTRATION_V2_WS_METHODS.searchThreadStream,
67 completeWhen: (result) => result.complete !== false,
68 idleTtlMs: 0,
69 }),
70 threadSearch: createEnvironmentRpcQueryAtomFamily(runtime, {
71 label: "environment-data:orchestration:thread-search",
72 tag: ORCHESTRATION_V2_WS_METHODS.searchThreads,
73 staleTimeMs: 30_000,
74 idleTtlMs: 60_000,
75 }),
76 archivedShellSnapshot: createEnvironmentRpcQueryAtomFamily(runtime, {
77 label: "environment-data:orchestration:archived-shell-snapshot",
78 tag: ORCHESTRATION_V2_WS_METHODS.getArchivedShellSnapshot,
79 }),
80 };