import type { GraphStreamProjection } from '../types/graph.js'; import type { AssistantRunContext, Principal, ServerAssistant } from '../types/server.js'; /** * The part of a compiled graph the adapter uses. * * Structural, so the server entry point never imports the graph runtime: an application that serves * plain functions does not load it, and one that serves graphs already has it. */ export interface GraphLike { /** Runs an input, yielding one event per superstep. */ stream(input: unknown, options: { threadId?: string; signal?: AbortSignal; metadata?: Record; tenantId?: string; principal?: Principal; control?: DrainSwitch; }): AsyncIterable; /** Answers an interrupt and continues the thread. */ resume(threadId: string, value: unknown, options: { signal?: AbortSignal; metadata?: Record; tenantId?: string; principal?: Principal; control?: DrainSwitch; }): AsyncIterable; /** The thread's checkpoint, at its latest step or at one given. */ state(threadId: string, step?: number): Promise<{ step?: number; state?: unknown; status?: string; metadata?: Record; } | undefined>; /** Runs a thread on from its latest checkpoint, which is how a recovered run resumes at its last step. */ continue?(threadId: string, options: { signal?: AbortSignal; metadata?: Record; tenantId?: string; principal?: Principal; control?: DrainSwitch; }): AsyncIterable; /** Writes values into a thread's state, which is how a rollback is applied. */ updateState?(threadId: string, values: Record, options?: { asNode?: string; }): Promise; /** Runs an input as a stream of typed events. Used when the assistant serves `events`. */ events?(input: unknown, options: GraphEventOptionsLike): GraphEventsLike; /** Like `events()`, answering an interrupt. */ resumeEvents?(threadId: string, value: unknown, options: GraphEventOptionsLike): GraphEventsLike; /** Like `events()`, continuing a thread from its latest checkpoint. */ continueEvents?(threadId: string, options: GraphEventOptionsLike): GraphEventsLike; } /** The options of a graph's `events()` the adapter passes. */ type GraphEventOptionsLike = { threadId?: string; tenantId?: string; principal?: Principal; signal?: AbortSignal; metadata?: Record; control?: DrainSwitch; include?: GraphStreamProjection[]; }; /** A graph's event stream, as the adapter reads it: the events, then the run's result. */ type GraphEventsLike = AsyncIterable & { result: Promise<{ status: string; state: unknown; interrupt?: unknown; interrupts?: unknown[]; }>; }; /** Asks a graph to stop after its current superstep. A graph's `RunControl` has this shape. */ type DrainSwitch = { readonly draining: boolean; readonly reason?: string; }; /** Options for `graphAssistant()`. */ export interface GraphAssistantOptions { /** What the assistant is, reported by the assistants endpoint. */ description?: string; /** Metadata recorded on every checkpoint the server's runs create. */ metadata?: Record; /** * Records these projections of the graph's event stream on each run, such as `messages` and * `tools`, so a client following the run sees model output and tool calls as they happen. The * run's last event still carries its state and any question, as without it. Defaults to none: one * event per superstep. */ events?: GraphStreamProjection[]; } /** * Serves a compiled graph as an assistant. * * Threads map to graph threads, so state, interrupts, history, and checkpoints are the graph's own; * the server adds only the record of which run owns a thread. A graph compiled without a * checkpointer still works for stateless runs, but cannot resume or roll back. * * A workflow from `nexus-ai-pro/graph/functional` is served the same way. When a worker recovers a * run, the assistant continues from the last checkpoint that run wrote, so only the step in flight * runs again. */ export declare function graphAssistant(graph: GraphLike, options?: GraphAssistantOptions): ServerAssistant; /** * Serves a plain function as an assistant, for work that is not a graph. * * The function may return a value or yield events; the last value it yields is the run's output. */ export declare function functionAssistant(run: (input: unknown, context: AssistantRunContext) => AsyncIterable | Promise | unknown, options?: { description?: string; }): ServerAssistant; export {};