import type { PubSub } from '../../events/pubsub.js'; import type { IMastraLogger } from '../../logger/index.js'; import { MastraModelOutput } from '../../stream/base/output.js'; import type { ChunkType } from '../../stream/types.js'; import type { AgentStepFinishEventData, AgentFinishEventData, AgentSuspendedEventData } from './types.js'; /** * Options for creating a durable agent stream */ export interface DurableAgentStreamOptions { /** Pubsub instance to subscribe to */ pubsub: PubSub; /** Run identifier */ runId: string; /** Message ID for this execution */ messageId: string; /** Model information for the output */ model: { modelId: string | undefined; provider: string | undefined; version: 'v2' | 'v3'; }; /** Thread ID for memory */ threadId?: string; /** Resource ID for memory */ resourceId?: string; /** * Start replay from this index (0-based). * If undefined, uses full replay (subscribeWithReplay). * If specified, uses efficient indexed replay (subscribeFromOffset). */ offset?: number; /** Callback when chunk is received */ onChunk?: (chunk: ChunkType) => void | Promise; /** Callback when step finishes */ onStepFinish?: (result: AgentStepFinishEventData) => void | Promise; /** Callback when execution finishes */ onFinish?: (result: AgentFinishEventData) => void | Promise; /** Callback on error */ onError?: (error: Error) => void | Promise; /** Callback when workflow suspends */ onSuspended?: (data: AgentSuspendedEventData) => void | Promise; /** Optional logger for structured logging */ logger?: IMastraLogger; } /** * Result from creating a durable agent stream */ export interface DurableAgentStreamResult { /** The MastraModelOutput that streams from pubsub events */ output: MastraModelOutput; /** Cleanup function to unsubscribe from pubsub */ cleanup: () => void; /** Promise that resolves when subscription is established */ ready: Promise; } /** * Create a MastraModelOutput that streams from pubsub events. * * This adapter subscribes to the agent stream pubsub channel and converts * pubsub events into a ReadableStream that MastraModelOutput can consume. * Callbacks are invoked as events arrive. */ export declare function createDurableAgentStream(options: DurableAgentStreamOptions): DurableAgentStreamResult; /** * Helper to emit a chunk event to pubsub */ export declare function emitChunkEvent(pubsub: PubSub, runId: string, chunk: ChunkType): Promise; /** * Helper to emit a step start event to pubsub */ export declare function emitStepStartEvent(pubsub: PubSub, runId: string, data: { stepId?: string; request?: unknown; warnings?: unknown[]; }): Promise; /** * Helper to emit a step finish event to pubsub */ export declare function emitStepFinishEvent(pubsub: PubSub, runId: string, data: AgentStepFinishEventData): Promise; /** * Helper to emit a finish event to pubsub */ export declare function emitFinishEvent(pubsub: PubSub, runId: string, data: AgentFinishEventData): Promise; /** * Helper to emit an error event to pubsub */ export declare function emitErrorEvent(pubsub: PubSub, runId: string, error: Error): Promise; /** * Helper to emit a suspended event to pubsub */ export declare function emitSuspendedEvent(pubsub: PubSub, runId: string, data: AgentSuspendedEventData): Promise; //# sourceMappingURL=stream-adapter.d.ts.map