> Discover all available pages from the documentation index: https://mastra.zisheng.pro/ja/llms.txt # withMastra() AI SDK モデルを Mastra の Processor や Memory でラップします。 ## 使用例 ```typescript import { openai } from '@ai-sdk/openai' import { generateText } from 'ai' import { withMastra } from '@mastra/ai-sdk' import type { Processor } from '@mastra/core/processors' const loggingProcessor: Processor<'logger'> = { id: 'logger', async processInput({ messages }) { console.log('Input:', messages.length, 'messages') return messages }, } const model = withMastra(openai('gpt-5.4'), { inputProcessors: [loggingProcessor], }) const { text } = await generateText({ model, prompt: 'What is 2 + 2?', }) ``` ## パラメーター **model** (`LanguageModelV2 | LanguageModelV3`): 任意の AI SDK v5 または v6 言語モデル(例: openai('gpt-5.4')、anthropic('claude-opus-4-6'))。 **options** (`WithMastraOptions`): Processor と Memory の設定オブジェクト。 **options.inputProcessors** (`InputProcessor[]`): LLM の呼び出し前に実行する入力 Processor。 **options.outputProcessors** (`OutputProcessor[]`): LLM のレスポンスに対して実行する出力 Processor。 **options.memory** (`WithMastraMemoryOptions`): Memory の設定。メッセージ履歴の自動永続化を有効にします。 **options.memory.storage** (`MemoryStorage`): メッセージを永続化するための Memory ストレージドメイン。複合ストアから await storage.getStore('memory') を使用して取得します。 **options.memory.threadId** (`string`): 会話を永続化するためのスレッド ID。 **options.memory.resourceId** (`string`): リソース ID(ユーザーまたはセッションの識別子)。 **options.memory.lastMessages** (`number | false`): 取得する直近のメッセージ数。無効にする場合は false。 **options.memory.semanticRecall** (`WithMastraSemanticRecallOptions`): セマンティックリコールの設定(RAG ベースの Memory 取得)。 **options.memory.workingMemory** (`MemoryConfig['workingMemory']`): Working Memory の設定(永続化されるユーザーデータ)。 **options.memory.readOnly** (`boolean`): 読み取り専用モード。新しいメッセージの保存を防ぎます。 ## 戻り値 `generateText`、`streamText`、`generateObject`、`streamObject` と互換性のある、ラップされたモデル。 ## ストリーミングの動作 `processOutputResult` を実装する出力 Processor は、ストリームの完了後に実行されます。メッセージ履歴とセマンティックリコールを永続化するには、ストリームを最後まで消費してください。