export declare const START: "__start__"; export declare const END: "__end__"; export type StartNode = typeof START; export type EndNode = typeof END; export type NodeName = string | StartNode | EndNode; export type Annotated = T; export interface Channel { reducer: (current: T, update: T) => T; default: () => T; /** If true, resets to default() at the start of every superstep */ ephemeral?: boolean; } export declare function lastValue(defaultVal: () => T): Channel; export declare function appendList(defaultVal?: () => T[]): Channel; export declare function mergeObject>(defaultVal: () => T): Channel; /** Resets to default at the start of every superstep — good for per-step scratch data */ export declare function ephemeralValue(defaultVal: () => T): Channel; export type ChannelSchema = { [K in keyof S]: Channel; }; export declare class Send { readonly node: string; readonly args: Record; constructor(node: string, args: Record); } export interface CommandOptions { /** State update to apply */ update?: Partial; /** Go to a specific node (or END) */ goto?: NodeName | NodeName[]; /** Dynamic fan-out sends */ send?: Send[]; /** Emit a resume value for human-in-the-loop */ resume?: unknown; /** Target graph for the update — use Command.PARENT to push to parent */ graph?: typeof Command.PARENT; } export declare class Command { static readonly PARENT: "__parent__"; readonly update?: Partial; readonly goto?: NodeName | NodeName[]; readonly send?: Send[]; readonly resume?: unknown; readonly graph?: typeof Command.PARENT | undefined; constructor(opts: CommandOptions); } export type NodeReturn = Partial | Command | void; export type NodeFn = (state: S, config?: ONIConfig) => Promise> | NodeReturn; export interface NodeDefinition { name: string; fn: NodeFn; retry?: RetryPolicy; /** If set, this node IS a compiled subgraph */ subgraph?: ONISkeleton; cache?: boolean | CachePolicy; /** Hard timeout in ms — node is aborted if it exceeds this */ timeout?: number; circuitBreaker?: { threshold: number; resetAfter: number; fallback?: (state: S, error: Error) => NodeReturn; }; } export interface RetryPolicy { maxAttempts: number; /** Initial delay in ms */ initialDelay?: number; /** Multiplier for exponential backoff (default 2) */ backoffMultiplier?: number; /** Max delay cap in ms (default 30_000) */ maxDelay?: number; /** Predicate: only retry if this returns true */ retryOn?: (error: Error) => boolean; /** Whether to add random jitter to backoff delay (default true) */ jitter?: boolean; } export interface CachePolicy { /** Cache key function — defaults to JSON.stringify(state) */ key?: (state: unknown) => string; /** TTL in ms — cache entries expire after this. Default: Infinity (per-invocation) */ ttl?: number; } export interface StaticEdge { type: "static"; from: NodeName; to: NodeName; } export interface ConditionalEdge { type: "conditional"; from: NodeName; condition: (state: S, config?: ONIConfig) => NodeName | NodeName[] | Send[]; pathMap?: Record; } export type Edge = StaticEdge | ConditionalEdge; export interface DynamicInterrupt { node: string; timing: "before" | "after"; condition: (state: S) => boolean; } export interface InterruptConfig { interruptBefore?: string[]; interruptAfter?: string[]; } export interface ONIConfig { threadId?: string; recursionLimit?: number; metadata?: Record; tags?: string[]; agentId?: string; parentRunId?: string; /** Abort signal — propagated to LLM calls and async operations inside nodes */ signal?: AbortSignal; /** Dynamic runtime interrupt conditions */ dynamicInterrupts?: DynamicInterrupt[]; } export interface ONICheckpoint { threadId: string; step: number; state: S; nextNodes: string[]; timestamp: number; agentId?: string; /** Pending Send queue at time of checkpoint */ pendingSends?: Array<{ node: string; args: Record; }>; /** Arbitrary metadata from config — useful for filtering and debugging */ metadata?: Record; /** Per-node channel writes from the last superstep */ pendingWrites?: Array<{ nodeId: string; writes: Record; }>; } export interface CheckpointListOptions { limit?: number; before?: number; filter?: Record; } export interface ONICheckpointer { get(threadId: string): Promise | null>; put(checkpoint: ONICheckpoint): Promise; list(threadId: string, opts?: CheckpointListOptions): Promise[]>; delete(threadId: string): Promise; } export type StreamMode = "values" | "updates" | "debug" | "messages" | "custom"; export interface ONIStreamEvent { event: "node_start" | "node_end" | "state_update" | "error" | "interrupt" | "send"; node?: string; data: Partial | S | Error | ONIInterruptEvent | Send; step: number; timestamp: number; agentId?: string; /** Set when using multiple stream modes — indicates which mode produced this event */ mode?: StreamMode; } export interface ONIInterruptEvent { node: string; timing: "before" | "after"; state: unknown; } export interface CustomStreamEvent { event: "custom"; node: string; name: string; data: unknown; step: number; timestamp: number; agentId?: string; mode?: StreamMode; } export interface MessageStreamEvent { event: "messages" | "messages/complete" | "messages/metadata"; node: string; data: { chunk: string; content: string; role: "assistant"; id: string; }; step: number; timestamp: number; agentId?: string; mode?: StreamMode; } export interface ONISkeleton { invoke(input: Partial, config?: ONIConfig): Promise; stream(input: Partial, config?: ONIConfig & { streamMode?: StreamMode | StreamMode[]; }): AsyncGenerator | CustomStreamEvent | MessageStreamEvent>; batch(inputs: Partial[], config?: ONIConfig): Promise; getState(config: { threadId: string; }): Promise; updateState(config: { threadId: string; }, update: Partial): Promise; /** Time-travel: get state as it was at a specific superstep */ getStateAt(config: { threadId: string; step: number; }): Promise; /** Get full checkpoint history for a thread */ getHistory(config: { threadId: string; }): Promise[]>; /** Fork: replay execution from a historical checkpoint */ forkFrom(config: { threadId: string; step: number; newThreadId: string; }): Promise; } //# sourceMappingURL=types.d.ts.map