Open History to see the last commit
1import { WS_METHODS } from "@t3tools/contracts";
2import { Atom } from "effect/unstable/reactivity";
3
4import { createEnvironmentRpcCommand, createEnvironmentRpcQueryAtomFamily } from "./runtime.ts";
5import type { EnvironmentRegistry } from "../connection/registry.ts";
6
7/**
8 * Workflow-run inspection atoms (Claude Agent SDK workflow artifacts).
9 *
10 * `readScript` and `readJournal` are cached queries — the script never
11 * changes for a given path within a run, and journal reads are refreshed by
12 * re-query. `readAgentTranscript` is an imperative command because the
13 * caller drives cursor-paged polling while a transcript pane is open.
14 */
15export function createWorkflowEnvironmentAtoms<R, E>(
16 runtime: Atom.AtomRuntime<EnvironmentRegistry | R, E>,
17) {
18 return {
19 readScript: createEnvironmentRpcQueryAtomFamily(runtime, {
20 label: "environment-data:workflow:read-script",
21 tag: WS_METHODS.workflowReadScript,
22 staleTimeMs: 30_000,
23 }),
24 readJournal: createEnvironmentRpcQueryAtomFamily(runtime, {
25 label: "environment-data:workflow:read-journal",
26 tag: WS_METHODS.workflowReadJournal,
27 staleTimeMs: 5_000,
28 // The journal grows while a run is live and the query only mounts
29 // while the Logs tab is open — poll so new results appear without a
30 // manual refresh.
31 refreshIntervalMs: 4_000,
32 }),
33 readAgentTranscript: createEnvironmentRpcCommand(runtime, {
34 label: "environment-data:workflow:read-agent-transcript",
35 tag: WS_METHODS.workflowReadAgentTranscript,
36 }),
37 };
38}