import type { LanguageModelV2, LanguageModelV2Middleware } from './_types/@ai-sdk_provider/dist/index.d.ts'; import type { LanguageModelV3 } from './_types/@internal_ai-v6/dist/index.d.ts'; import type { MemoryConfig, SemanticRecall as SemanticRecallConfig } from '@mastra/core/memory'; import type { InputProcessor, OutputProcessor } from '@mastra/core/processors'; import type { MemoryStorage } from '@mastra/core/storage'; import type { MastraEmbeddingModel, MastraVector } from '@mastra/core/vector'; /** * Memory context for processors that need thread/resource info */ export interface ProcessorMemoryContext { /** Thread ID for conversation persistence */ threadId?: string; /** Resource ID (user/session identifier) */ resourceId?: string; /** Memory configuration options */ config?: MemoryConfig; } /** * Options for creating processor middleware */ export interface ProcessorMiddlewareOptions { /** Input processors to run before the LLM call */ inputProcessors?: InputProcessor[]; /** Output processors to run on the LLM response */ outputProcessors?: OutputProcessor[]; /** Memory context for processors that need thread/resource info */ memory?: ProcessorMemoryContext; } /** * Semantic recall configuration with required vector and embedder. * Inherits JSDoc from SemanticRecall type in memory/types.ts. */ export type WithMastraSemanticRecallOptions = SemanticRecallConfig & { /** Vector store for semantic search (required) */ vector: MastraVector; /** Embedder for generating query embeddings (required) */ embedder: MastraEmbeddingModel; }; /** * Memory configuration for withMastra */ export interface WithMastraMemoryOptions { /** Storage adapter for message persistence (required) */ storage: MemoryStorage; /** Thread ID for conversation persistence (required) */ threadId: string; /** Resource ID (user/session identifier) */ resourceId?: string; /** Number of recent messages to retrieve, or false to disable */ lastMessages?: number | false; /** Semantic recall configuration (RAG-based memory retrieval) */ semanticRecall?: WithMastraSemanticRecallOptions; /** Working memory configuration (persistent user data) */ workingMemory?: MemoryConfig['workingMemory']; /** Read-only mode - prevents saving new messages */ readOnly?: boolean; } /** * Options for withMastra wrapper */ export interface WithMastraOptions { /** Memory configuration - enables automatic message history persistence */ memory?: WithMastraMemoryOptions; /** Input processors to run before the LLM call */ inputProcessors?: InputProcessor[]; /** Output processors to run on the LLM response */ outputProcessors?: OutputProcessor[]; } /** * Wraps a language model with Mastra capabilities including memory and processors. * * @example * ```typescript * // With message history (auto-creates MessageHistory processor) * import { openai } from '@ai-sdk/openai'; * import { withMastra } from '@mastra/ai-sdk'; * import { LibSQLStore } from '@mastra/libsql'; * * const storage = new LibSQLStore({ url: 'file:memory.db' }); * await storage.init(); * * const model = withMastra(openai('gpt-4o'), { * memory: { * storage, * threadId: 'thread-123', * resourceId: 'user-456', * lastMessages: 10, * }, * }); * * const { text } = await generateText({ model, prompt: 'Hello' }); * ``` * * @example * ```typescript * // With semantic recall (RAG-based memory) * const model = withMastra(openai('gpt-4o'), { * memory: { * storage, * threadId: 'thread-123', * semanticRecall: { * vector: pinecone, * embedder: openai.embedding('text-embedding-3-small'), * topK: 5, * messageRange: 2, // Include 2 messages before/after each match * }, * }, * }); * ``` * * @example * ```typescript * // With working memory (persistent user data) * const model = withMastra(openai('gpt-4o'), { * memory: { * storage, * threadId: 'thread-123', * workingMemory: { * enabled: true, * template: '# User Profile\n- **Name**:\n- **Preferences**:', * }, * }, * }); * ``` * * @example * ```typescript * // With custom processors * const model = withMastra(openai('gpt-4o'), { * inputProcessors: [myInputProcessor], * outputProcessors: [myOutputProcessor], * }); * ``` */ export declare function withMastra(model: LanguageModelV2, options?: WithMastraOptions): LanguageModelV2; export declare function withMastra(model: LanguageModelV3, options?: WithMastraOptions): LanguageModelV3; /** * Creates AI SDK middleware that runs Mastra processors on input/output. * For a simpler API, use `withMastra` instead. * * @example * ```typescript * import { wrapLanguageModel, generateText } from '@internal/ai-sdk-v5'; * import { openai } from '@ai-sdk/openai'; * import { createProcessorMiddleware } from '@mastra/ai-sdk'; * * const model = wrapLanguageModel({ * model: openai('gpt-4o'), * middleware: createProcessorMiddleware({ * inputProcessors: [myProcessor], * outputProcessors: [myProcessor], * }), * }); * * const { text } = await generateText({ model, prompt: 'Hello' }); * ``` */ export declare function createProcessorMiddleware(options: ProcessorMiddlewareOptions): LanguageModelV2Middleware; //# sourceMappingURL=middleware.d.ts.map