UNPKG

@mastra/core

Version:
61 lines 3.68 kB
import type { CoreMessage as CoreMessageV4, UIMessage as UIMessageV4 } from '../../../_types/@internal_ai-sdk-v4/dist/index.d.ts'; import type { AdapterContext } from '../adapters/index.js'; import type { MastraDBMessage, MessageSource } from '../state/types.js'; import type { AIV5Type, AIV6Type } from '../types.js'; /** * Sanitizes AIV4 UI messages by filtering out incomplete tool calls. * Removes messages with empty parts arrays after sanitization. */ export declare function sanitizeAIV4UIMessages(messages: UIMessageV4[]): UIMessageV4[]; /** * Sanitizes AIV5 UI messages by filtering out streaming states, data-* parts, empty text parts, and optionally incomplete tool calls. * Handles legacy data by filtering empty text parts that may exist in pre-existing DB records. */ export declare function sanitizeV5UIMessages(messages: AIV5Type.UIMessage[], mode?: ToolCallConversionMode): AIV5Type.UIMessage[]; /** * Adds step-start parts between tool parts and non-tool parts for proper AIV5 message conversion. * This ensures AIV5.convertToModelMessages produces the correct message order. */ export declare function addStartStepPartsForAIV5(messages: AIV5Type.UIMessage[]): AIV5Type.UIMessage[]; /** * Converts AIV4 UI messages to AIV4 Core messages. * * Provider file IDs (e.g. OpenAI Files API "file-...") stored in * `experimental_attachments` would make AI SDK v4's internal `attachmentsToParts` * throw `Invalid URL: file-...` inside `convertToCoreMessages`. Strip them before * conversion and re-append them as file parts on the resulting user core message * so the IDs survive untouched. */ export declare function aiV4UIMessagesToAIV4CoreMessages(messages: UIMessageV4[]): CoreMessageV4[]; /** * How suspended (result-less) tool calls are handled when converting to model messages. * * - `response`: messages coming FROM the LLM. Suspended calls are kept so they stay in * message history, and no pairing is enforced — nothing here is sent to a provider. * - `prompt`: messages going TO the LLM. Suspended calls are dropped. * - `prompt-with-suspended`: messages going TO the LLM with suspended calls kept visible to * the agent. Each is paired with a pending result so the prompt stays valid. * * The last two both submit to a provider, so both enforce tool-call/tool-result pairing. * That requirement belongs to the provider protocol, not to the caller's preference. */ export type ToolCallConversionMode = 'response' | 'prompt' | 'prompt-with-suspended'; /** * Converts AIV5 UI messages to AIV5 Model messages. * Handles sanitization, step-start insertion, provider options restoration, and Anthropic compatibility. * * @param messages - AIV5 UI messages to convert * @param dbMessages - MastraDB messages used to look up tool call args for Anthropic compatibility * @param mode - How to handle suspended tool calls */ export declare function aiV5UIMessagesToAIV5ModelMessages(messages: AIV5Type.UIMessage[], dbMessages: MastraDBMessage[], mode?: ToolCallConversionMode): AIV5Type.ModelMessage[]; /** * Converts AIV4 Core messages to AIV5 Model messages. */ export declare function aiV4CoreMessagesToAIV5ModelMessages(messages: CoreMessageV4[], source: MessageSource, adapterContext: AdapterContext, dbMessages: MastraDBMessage[]): AIV5Type.ModelMessage[]; /** * Converts various message formats to AIV4 CoreMessage format for system messages. * Supports string, MastraDBMessage, or AI SDK message types. */ export declare function systemMessageToAIV4Core(message: CoreMessageV4 | AIV5Type.ModelMessage | AIV6Type.ModelMessage | MastraDBMessage | string): CoreMessageV4; //# sourceMappingURL=output-converter.d.ts.map