import { MessageJSON } from "smoltalk"; import { type Run } from "./asyncContext.js"; import type { AgencyCallbacks } from "./hooks.js"; import type { RuntimeContext } from "./state/context.js"; import type { AgencyFunction } from "./agencyFunction.js"; import { State, StateStack } from "./state/stateStack.js"; import { ThreadStore } from "./state/threadStore.js"; import { type InvocationOptions } from "./invocationOptions.js"; import { GraphState, RunNodeCoreResult, RunNodeResult } from "./types.js"; import { type ServedInvocationOutcome } from "./invocationUsage.js"; export declare function setupNode(args: { state: GraphState; }): { stack: State; step: number; self: Record; threads: ThreadStore; run: Run; }; export declare function setupFunction(run: Run): { stateStack: StateStack; stack: State; step: number; self: Record; threads: ThreadStore; }; /** * Invoke an exported Agency function from *outside* any Agency execution * frame — the `agency serve` path, where an HTTP/MCP request maps a * function name + named args to a single stateless call. * * Generated function bodies assume an ambient `agencyStore` frame: they * read `getRuntimeContext().ctx`, the base `StateStack`/`ThreadStore` via * `setupFunction()`, and globals via `__globals()`. In normal execution a * function only ever runs inside a node body (or an LLM tool-call that is * itself inside a node), so that frame is already installed. `runNode` * installs it for nodes; this is the equivalent entry point for a bare * function call. Without it the first line of every generated function * throws "getRuntimeContext() called outside an Agency execution frame". * * Mirrors `runNode`'s bootstrap (cross-module init, this module's globals * init, top-level callback registration) against a fresh execution * context so the function sees fully-initialized statics/globals and any * module-level `callback(...)` blocks, then runs the call inside a * node-grade ALS frame with a real `ThreadStore` (so functions that use * `llm()` / message threads work), and tears it down like `runNode` does * (persist memory, flush statelog). * * Two deliberate divergences from `runNode`, both consequences of the * stateless-RPC model: * - No `agentStart`/`agentEnd` span and no run-level token roll-up. The * generated function body still reports its own failures to statelog * and converts exceptions to a `Failure` result, so per-call errors * are traced and surface to the caller; what is absent is only the * run-level envelope. A practical consequence: `llm()` spend inside a * served function is not attributed to `getCost` / cost dashboards. * - No checkpoint/restore loop — a function call is one shot, so there * is no `RestoreSignal` handling here (a `catch` would risk swallowing * that and other control-flow signals). */ type RunExportedFunctionArgs = { ctx: RuntimeContext; fn: AgencyFunction; namedArgs: Record; initializeGlobals?: (run: Run) => void | Promise; invocation?: InvocationOptions; }; /** Public entry point — unchanged contract: returns the raw function value or * throws the identical original error. An attached debugger answers the * function's debug stops before it returns (`settleFunctionStops`). */ export declare function runExportedFunction(args: RunExportedFunctionArgs): Promise; /** Serve-only entry point: the same execution, but the outcome (value/error + * usage snapshot) is handed to the serve adapter instead of unwrapped. */ export declare function runExportedFunctionForServe(args: RunExportedFunctionArgs): Promise>; type RunNodeArgs = { ctx: RuntimeContext; nodeName: string; data: Record; messages?: MessageJSON[]; callbacks?: AgencyCallbacks; initializeGlobals?: (run: Run) => void | Promise; abortSignal?: AbortSignal; pauseSignal?: AbortSignal; invocation?: InvocationOptions; input?: unknown; }; /** Public entry point — returns the RunNodeResult with its usage snapshot * attached, or throws the identical original error. An attached debugger * answers the leg's debug stops here, after the leg has finished, so the * caller never sees one (`settleStops`). */ export declare function runNode(args: RunNodeArgs): Promise>; /** Serve-only entry point: hands the outcome (RunNodeResult/error + usage * snapshot) to the serve adapter instead of unwrapping it. */ export declare function runNodeForServe(args: RunNodeArgs): Promise>>; export {};