import { type RecursionClientOptions } from './client-options.js'; import type { ManagedAgentsContentBlock, ManagedAgentsEvent, ManagedAgentsUsage } from './generated/index.js'; /** * One decoded frame from a session event stream. * * Field names are the wire's own, matching every other managed-agents type in * this package: those are imported verbatim from the Go service's spec rather * than derived from a camelCase DTO, and a stream frame that disagreed with * `ManagedAgentsEvent` would be the odd one out. */ export interface ManagedAgentSessionStreamEvent { /** * Fields the service has added since this decoder was written. * * This type is hand-maintained rather than generated, so an index signature * is what keeps the decoder a passthrough: a new field on the Go * `managedStreamEvent` struct reaches the caller as `unknown` instead of * being silently dropped while someone notices. The declared fields below * stay precisely typed. */ [key: string]: unknown; /** Frame type, e.g. `session.status_running`, `message`, `session.error`. */ type: string; /** Event id. Pass the last one seen as `afterEventId` to resume without gaps. */ id?: string; session_id?: string; session_thread_id?: string; processed_at?: string; content?: ManagedAgentsContentBlock[]; /** Provider-specific; shape varies by model and is deliberately not narrowed. */ stop_reason?: unknown; usage?: ManagedAgentsUsage; error?: Record; anchor_event_id?: string; raw_event?: ManagedAgentsEvent; } export interface ManagedAgentSessionStreamParams { /** Session id (UUID). Any id in the tree resolves to its root session. */ sessionId: string; /** * Resume cursor: only events after this id are delivered. * * Sent as the `after_event_id` query parameter rather than the `Last-Event-ID` * header. The public gateway's cross-origin allowlist admits the query but not * that non-safelisted header, and using one cursor everywhere keeps a browser * caller and a server caller on the same code path. */ afterEventId?: string; /** Restrict delivery to these frame types. Omit for everything. */ types?: readonly string[]; /** Abort the request and end the iteration. */ signal?: AbortSignal; } /** * Stream a managed agent session's events as they are produced. * * Iteration ends when the server closes the stream, which it does once the * session reaches a terminal status. Aborting `signal` ends it early. * * @example * for await (const event of streamManagedAgentSessionEvents( * { apiKey: process.env.LABELBOX_API_KEY! }, * { sessionId }, * )) { * if (event.type === 'session.error') break; * console.log(event.type, event.content); * } */ export declare function streamManagedAgentSessionEvents(options: RecursionClientOptions, params: ManagedAgentSessionStreamParams): AsyncGenerator; /** A stream that failed before any frame was delivered. */ export declare class ManagedAgentSessionStreamError extends Error { readonly status: number; /** Stable machine-readable code from the service, when the body carried one. */ readonly code: string | undefined; constructor(status: number, body: { code?: string; message?: string; }); } export declare function decodeEventStream(body: ReadableStream, signal?: AbortSignal, maxRecordBytes?: number): AsyncGenerator;