import { CostEstimate, TokenUsage } from "smoltalk"; import { RuntimeContext, ThreadStore } from "./index.js"; import { ThreadStoreJSON } from "./state/threadStore.js"; export type GraphState = { messages?: ThreadStore; data: any; ctx: RuntimeContext; isResume?: boolean; }; export type NodeReturnValue = { data: T; messages: ThreadStore; }; export type RunNodeResult = { messages: ThreadStoreJSON; data: T; tokens?: TokenStats; }; export type TokenStats = { usage: TokenUsage; cost: CostEstimate; }; 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 = { fn: HandlerFn; liveGuardIds: string[]; };