/** * agentfootprint/stream — agent events → Server-Sent Events helpers. * * Pattern: Adapter (event stream → SSE wire format). * Role: Outer ring. Subscribes to a `Runner`'s `EventDispatcher` * and yields SSE-formatted strings. Drop into any HTTP * framework that accepts an async iterable response body * (Fetch Response, Express res.write, Hono streaming, etc.). * Emits: N/A — observes only. */ import type { AgentfootprintEvent } from './events/registry.js'; import type { RunnerBase } from './core/RunnerBase.js'; /** * Hand the runner this iterable's caller before calling `runner.run()`. * Yields SSE-formatted strings until the run finishes (success, error, * or pause). Each event becomes: * * event: * data: * * * @example * // Express * app.post('/agent', async (req, res) => { * res.setHeader('content-type', 'text/event-stream'); * for await (const chunk of toSSE(agent)) { * res.write(chunk); * } * res.end(); * // (in parallel: await agent.run(req.body)) * }); */ export interface ToSSEOptions { /** * Filter predicate — return false to skip an event. Default: all events. * Common: `event => event.type.startsWith('agentfootprint.stream.')` * for a token-only feed. */ readonly filter?: (event: AgentfootprintEvent) => boolean; /** * Output shape: * - 'full' (default) — each event is JSON-serialized verbatim. * - 'text' — only `agentfootprint.stream.token.content` is yielded, * in plain text form (no event/data prefix). Useful for piping * directly into a chat UI. */ readonly format?: 'full' | 'text'; /** * Custom event name extractor. By default `event.type` is used. * Useful for SSE consumers that want their own naming. */ readonly eventName?: (event: AgentfootprintEvent) => string; /** * Heartbeat interval in ms. SSE connections through proxies/load * balancers often die after ~30s of silence; emit `: ping` comments * at this interval. Default 0 (disabled). */ readonly heartbeatMs?: number; } /** * Subscribe to a runner's `EventDispatcher` and yield SSE-formatted * strings until the run completes. */ export declare function toSSE(runner: RunnerBase, options?: ToSSEOptions): AsyncIterable; /** * Class form for consumers who prefer `new SSEFormatter(runner).stream()`. * Identical behavior to `toSSE(runner)` — pick by preference. */ export declare class SSEFormatter { private readonly runner; private readonly options; constructor(runner: RunnerBase, options?: ToSSEOptions); /** Async iterable of SSE chunks. Consume with `for await`. */ stream(): AsyncIterable; } /** * Format any JSON-able payload as a single SSE event chunk. * * Useful for app-level events outside the runner's typed registry * (auth/error frames, app-state echoes). Most consumers won't need this. */ export declare function encodeSSE(eventName: string, payload: unknown): string; //# sourceMappingURL=stream.d.ts.map