/** * CustomStreamingAdapter — CustomAdapter with streaming support. * * Extends {@link CustomAdapter} so that handlers can yield incremental text * by returning an `AsyncIterable` or `AsyncIterable`. * Plain `Promise` handlers work unchanged (single-chunk fallback). * * Usage: * * const adapter = new CustomStreamingAdapter(); * * // Streaming handler — yields tokens incrementally * adapter.registerHandler('writer', async function*(payload) { * yield 'Once '; * yield 'upon '; * yield 'a time…'; * }); * * // Non-streaming handler — works exactly as before * adapter.registerHandler('analyze', async (payload) => ({ result: 'done' })); * * // Consume the stream * for await (const chunk of adapter.executeAgentStream('writer', payload, ctx)) { * process.stdout.write(chunk.text); * } * * @module CustomStreamingAdapter * @version 1.0.0 */ import type { AgentPayload, AgentContext, AdapterCapabilities } from '../types/agent-adapter'; import type { IStreamingAdapter, StreamingChunk } from '../types/streaming-adapter'; import { CustomAdapter, AgentHandler } from './custom-adapter'; /** * Extended handler type that may also return an async iterable of string tokens * or full `StreamingChunk` objects. */ export type StreamingAgentHandler = AgentHandler | ((payload: AgentPayload, context: AgentContext) => AsyncIterable) | ((payload: AgentPayload, context: AgentContext) => AsyncIterable); export declare class CustomStreamingAdapter extends CustomAdapter implements IStreamingAdapter { private streamingHandlers; get capabilities(): AdapterCapabilities; /** * Register a handler. Streaming handlers (functions returning `AsyncIterable`) * are detected automatically and exposed through `executeAgentStream()`. */ registerHandler(agentId: string, handler: StreamingAgentHandler, metadata?: { description?: string; capabilities?: string[]; }): void; /** * Mark an already-registered handler as streaming. * Useful when the handler function is not an async generator but returns * an `AsyncIterable` (e.g. a closure around a separate generator). */ markStreaming(agentId: string): void; supportsStreaming(agentId: string): boolean; /** * Execute a handler with streaming support. * * - If the handler is registered as streaming (yields tokens), pipes the * async iterable to `StreamingChunk` values. * - Otherwise falls back to `executeAgent()` and wraps the result as a * single chunk (same behaviour as the non-streaming `CustomAdapter`). */ executeAgentStream(agentId: string, payload: AgentPayload, context: AgentContext): AsyncIterable; /** Pipe an `AsyncIterable` to `StreamingChunk` values. */ private _pipeIterable; } //# sourceMappingURL=custom-streaming-adapter.d.ts.map