import { BaseTextAdapter, StructuredOutputOptions, StructuredOutputResult } from '@tanstack/ai/adapters'; import { Modality, AdapterYieldChunk, TextOptions } from '@tanstack/ai'; import { MISTRAL_CHAT_MODELS, MistralChatModelProviderOptionsByName, MistralModelInputModalitiesByName, MistralModelReasoningByName, MistralTextAdapterModel } from '../model-meta.js'; import { ExternalTextProviderOptions } from '../text/text-provider-options.js'; import { MistralMessageMetadataByModality } from '../message-types.js'; import { MistralClientConfig } from '../utils/client.js'; /** * Configuration for Mistral text adapter. */ export type MistralTextConfig = MistralClientConfig; /** * Alias for TextProviderOptions for external use. */ export type MistralTextProviderOptions = ExternalTextProviderOptions; type ResolveProviderOptions = TModel extends keyof MistralChatModelProviderOptionsByName ? MistralChatModelProviderOptionsByName[TModel] : MistralTextProviderOptions; /** The reasoning levels of a model, for `chat({ reasoning })`. `never`: none. */ type ResolveReasoning = TModel extends keyof MistralModelReasoningByName ? MistralModelReasoningByName[TModel] : never; type ResolveInputModalities = TModel extends keyof MistralModelInputModalitiesByName ? MistralModelInputModalitiesByName[TModel] : readonly ['text']; /** * Mistral Text (Chat) Adapter. * * Tree-shakeable adapter for Mistral chat/text completion functionality. */ export declare class MistralTextAdapter = ResolveProviderOptions, TInputModalities extends ReadonlyArray = ResolveInputModalities> extends BaseTextAdapter, unknown, never, ResolveReasoning> { readonly name: "mistral"; readonly api: "mistral-conversations"; readonly provider: string; readonly inputModalities: readonly ("text" | "image" | "audio" | "document" | "video")[] | undefined; private readonly client; private readonly rawConfig; constructor(config: MistralTextConfig, model: TModel); chatStream(options: TextOptions): AsyncIterable; /** * Generate structured output using Mistral's JSON Schema response format. */ structuredOutput(options: StructuredOutputOptions): Promise>; /** * Processes streaming chunks from the Mistral API and yields AG-UI stream events. */ private processMistralStreamChunks; /** * Makes a raw fetch request to the Mistral chat completions endpoint and * parses the SSE stream manually, bypassing the SDK's Zod validation which * rejects streaming tool call chunks that omit `name` in argument deltas. */ private fetchRawMistralStream; /** * Converts the SDK's camelCase `ChatCompletionStreamRequest` into the * snake_case wire body, including converting messages. */ private toWireBody; /** * Splits a Mistral delta content payload into text and reasoning deltas. * Mistral reasoning models (magistral-*) stream reasoning content as * `{ type: 'thinking', thinking: [{ type: 'text', text }, ...] }` content * parts. A single delta may contain text only, thinking only, or — rarely — * both (when a step transitions); both fields are returned so the caller * can sequence REASONING and TEXT lifecycle events in order. */ private extractDeltaParts; /** * Maps common TextOptions to Mistral Chat Completions request parameters. */ private mapTextOptionsToMistral; /** * Converts a TanStack AI ModelMessage to a Mistral ChatCompletionMessageParam. */ private convertMessageToMistral; /** Readable thinking and text, in the stored block order. */ private assistantContent; /** * Converts a ContentPart to a Mistral content part. Returns undefined for * unsupported part types. */ private convertContentPartToMistral; /** * Normalizes message content to an array of ContentPart. */ private normalizeContent; /** * Extracts text content from a content value that may be string, null, or ContentPart array. */ private extractTextContent; } /** * Creates a Mistral text adapter with explicit API key. * * @param model - The model name (e.g., 'mistral-large-latest') * @param apiKey - Your Mistral API key * @param config - Optional additional configuration * @returns Configured Mistral text adapter instance * * @example * ```typescript * const adapter = createMistralText('mistral-large-latest', 'api_key'); * ``` */ export declare function createMistralText(model: TModel, apiKey: string, config?: Omit): MistralTextAdapter; /** * Creates a Mistral text adapter using the `MISTRAL_API_KEY` environment variable. * * @param model - The model name (e.g., 'mistral-large-latest') * @param config - Optional configuration (excluding apiKey) * @returns Configured Mistral text adapter instance * @throws Error if MISTRAL_API_KEY is not found in environment * * @example * ```typescript * const adapter = mistralText('mistral-large-latest'); * ``` */ export declare function mistralText(model: TModel, config?: Omit): MistralTextAdapter; export {};