import { RuntimeContext, ThreadStore } from "./index.js"; import { ThreadStoreJSON } from "./state/threadStore.js"; import type { RunUsage } from "./invocationUsage.js"; import type { Run } from "./asyncContext.js"; export type GraphState = { messages?: ThreadStore; data: any; ctx: RuntimeContext; isResume?: boolean; /** The run the graph was started under. Each node body takes it from * here, because the graph engine calls a node with its state only. */ run: Run; }; /** A run's result before its entry point attaches `usage` and `traceId`. */ export type RunNodeCoreResult = Omit, "usage" | "traceId">; export type NodeReturnValue = { data: T; messages: ThreadStore; }; export type RunNodeResult = { messages: ThreadStoreJSON; data: T; /** What the run has spent since it began, per kind and model. A resumed * run's figure includes what it spent before it paused, so a host that * records a paused result replaces that record when the run reports again. */ usage: RunUsage; /** The run's id, the same on every result of one run across pauses. */ traceId: string; }; export type Rejected = { type: "reject"; value?: any; }; export type Approved = { type: "approve"; value?: any; }; export type Propagated = { type: "propagate"; }; export type Passed = { type: "pass"; }; export type HandlerFn = (interrupt: { effect: string; message: string; data: any; origin: string; expectsValue?: boolean; }) => Promise; /** One registered handler on `ctx.handlers`. A handler belongs to the * scope where it was registered: `liveGuardIds` records which guards * were live on the registering branch's stack at that moment, and that * set decides both which guard trips the handler may adjudicate (only * guards NOT in the set — you cannot adjudicate a guard you are inside) * and which guards are suspended while the handler runs (also the * guards not in the set: a handler's own work spends its registration * site's budget, never a budget it is deciding about). Identity-based * on guardId — ids are serialized and survive resume and fork, which * array indices and registration counts do not (see the resumable- * guards plan, decision 14). */ export type HandlerEntry = { /** Called with the run it runs under, then the interrupt. A handler * registered from TypeScript takes only the interrupt, and * `RuntimeContext.pushHandler` wraps it into this shape. */ fn: RunHandlerFn; liveGuardIds: string[]; }; /** A handler function as the handler chain calls it: the run, then the * interrupt. */ export type RunHandlerFn = (run: Run, interrupt: Parameters[0]) => ReturnType;