import { B as Beam } from './beam-D2GMLSrC.js'; import { ReadableStream } from 'stream/web'; import '@mastra/memory'; import 'events'; import 'playwright'; import 'zod'; import 'pino'; import 'ai'; import '@mastra/core/workflows'; import '@mastra/core/agent'; import '@mastra/core/tools'; import 'steel-sdk'; /** * AI SDK Adapter * * This module provides adapters for the Vercel AI SDK streaming protocols. * It enables integration between our event-based agent system and * the AI SDK's streaming components. */ /** * Configuration options for AI SDK adapter */ interface AISDKAdapterOptions { /** * The protocol to use for streaming (text or data) * @default 'data' */ streamProtocol?: "text" | "data"; /** * Whether to include token usage metadata * @default true */ includeMetadata?: boolean; /** * Whether to include step information * @default true */ includeSteps?: boolean; } /** * Adapter class to convert Beam events to AI SDK stream format */ declare class AISDKAdapter { private beam; private encoder; private options; private readable; private controller; private currentStep; private textBuffer; private textStepId; private textStepStarted; private boundHandlers; constructor(beam: Beam, options?: AISDKAdapterOptions); /** * Creates a stream of AI SDK formatted data from Beam events */ createStream(): ReadableStream; /** * Creates a Response object from the stream */ toResponse(): Response; /** * Attaches event handlers to the Beam instance */ private attachEventHandlers; /** * Detaches all event handlers from the Beam instance */ private detachEventHandlers; /** * Helper to encode and send a stream part */ private writeStreamPart; /** * Safely extracts a value from a potentially undefined nested object */ private safeGet; /** * Flushes any buffered text content to the stream as a single step */ private flushTextBuffer; /** * Handle text output from the agent */ private handleText; /** * Handle tool calls from the agent */ private handleToolCall; /** * Handle tool results */ private handleToolResult; /** * Handle step information */ private handleStep; /** * Handle planning information */ private handlePlan; /** * Handle errors */ private handleError; /** * Handle workflow completion */ private handleDone; } /** * Constants for AI SDK adapter */ /** * Stream part types as defined by AI SDK * * See https://sdk.vercel.ai/docs/ai-sdk-ui/stream-protocol for documentation */ declare const STREAM_PART_TYPES: { /** Text content */ readonly TEXT: "0"; /** Data parts */ readonly DATA: "2"; /** Error parts */ readonly ERROR: "3"; /** Finish message */ readonly FINISH: "d"; /** Start of a step */ readonly STEP_START: "f"; /** Finish of a step */ readonly STEP_FINISH: "e"; /** Reasoning content */ readonly REASONING: "g"; /** Source information */ readonly SOURCE: "h"; /** Tool call */ readonly TOOL_CALL: "9"; /** Tool result */ readonly TOOL_RESULT: "a"; /** Start of streaming tool call */ readonly TOOL_CALL_START: "b"; /** Delta update for streaming tool call */ readonly TOOL_CALL_DELTA: "c"; /** Message annotations */ readonly ANNOTATIONS: "8"; /** Redacted reasoning */ readonly REDACTED_REASONING: "i"; /** Reasoning signature */ readonly REASONING_SIGNATURE: "j"; /** File part */ readonly FILE: "k"; }; /** * Type of finish reason for messages */ type FinishReason = "stop" | "length" | "content-filter" | "tool-calls" | "error" | "other" | "unknown"; /** * Stream helpers for AI SDK Adapter * * These functions provide compatibility with AI SDK's stream creation and handling patterns. */ /** * Basic annotation object structure */ interface Annotation { id: string; [key: string]: unknown; } /** * Interface for a DataStreamWriter */ interface DataStreamWriter { /** * Write text to the stream */ writeText(text: string): void; /** * Write data to the stream */ writeData(data: unknown[] | unknown): void; /** * Write a tool call to the stream */ writeToolCall(toolCallId: string, toolName: string, args: Record): void; /** * Write a tool result to the stream */ writeToolResult(toolCallId: string, result: unknown): void; /** * Write an error to the stream */ writeError(error: string): void; /** * Write reasoning to the stream */ writeReasoning(reasoning: string): void; /** * Write message annotations to the stream */ writeMessageAnnotation(annotation: unknown): void; /** * Write annotations to the stream */ writeAnnotations(annotations: Annotation[]): void; /** * Write a step start to the stream */ writeStepStart(messageId: string): void; /** * Write a step finish to the stream */ writeStepFinish(options: { finishReason: FinishReason; usage?: { promptTokens: number; completionTokens: number; }; isContinued?: boolean; }): void; /** * Write a finish message to the stream */ writeFinish(options: { finishReason: FinishReason; usage?: { promptTokens: number; completionTokens: number; }; }): void; /** * Close the stream */ close(): void; } /** * Creates a data stream response with a writable stream for custom data */ declare function createDataStreamResponse(options: { beam: Beam; adapterOptions?: AISDKAdapterOptions; }, callback?: (writer: DataStreamWriter) => void | Promise): Response; /** * Pipes a data stream to a response and allows writing custom data */ declare function pipeDataStreamToResponse(options: { beam: Beam; adapterOptions?: AISDKAdapterOptions; }, callback: (writer: DataStreamWriter) => void | Promise): Response; /** * Creates a text stream response from a beam instance */ declare function createTextStreamResponse(beam: Beam): Response; export { AISDKAdapter, type AISDKAdapterOptions, type DataStreamWriter, type FinishReason, STREAM_PART_TYPES, createDataStreamResponse, createTextStreamResponse, pipeDataStreamToResponse };