export type TextChunk = {type?: 'text' | undefined, text: string}; export type ImageDetail = 'low' | 'auto' | 'high'; export type ImageURL = {url: string, detail?: (ImageDetail | null) | undefined}; export type ImageURLChunk = {type?: 'image_url' | undefined, image_url: ImageURL | string}; export type BuiltInConnectors = 'web_search' | 'web_search_premium' | 'code_interpreter' | 'image_generation' | 'document_library' | 'mistral_mcp'; export type ToolFileChunk = {type?: 'tool_file' | undefined, tool: BuiltInConnectors | string, file_id: string, file_name?: (string | null) | undefined, file_type?: (string | null) | undefined}; export type DocumentURLChunk = {type?: 'document_url' | undefined, document_url: string, document_name?: (string | null) | undefined}; export type ToolReferenceChunk = {type?: 'tool_reference' | undefined, tool: BuiltInConnectors | string, title: string, url?: (string | null) | undefined, favicon?: (string | null) | undefined, description?: (string | null) | undefined}; export type ReferenceChunk = {type?: 'reference' | undefined, reference_ids: Array}; export type ThinkChunk = {type?: 'thinking' | undefined, thinking: Array, signature?: (string | null) | undefined, closed?: boolean | undefined}; export type MessageInputContentChunks = Array; export type MessageInputEntry = {object?: 'entry' | undefined, type?: 'message.input' | undefined, created_at?: string | undefined, completed_at?: (string | null) | undefined, id?: string | undefined, role: 'assistant' | 'user', content: string | MessageInputContentChunks, prefix?: boolean | undefined}; export type MessageOutputContentChunks = Array; export type MessageOutputEntry = {object?: 'entry' | undefined, type?: 'message.output' | undefined, created_at?: string | undefined, completed_at?: (string | null) | undefined, agent_id?: (string | null) | undefined, model?: (string | null) | undefined, id?: string | undefined, role?: 'assistant' | undefined, content: string | MessageOutputContentChunks}; export type FunctionResultEntry = {object?: 'entry' | undefined, type?: 'function.result' | undefined, created_at?: string | undefined, completed_at?: (string | null) | undefined, id?: string | undefined, tool_call_id: string, result: string}; export type FunctionCallEntryArguments = {[key: string]: unknown} | string; export type FunctionCallEntry = {object?: 'entry' | undefined, type?: 'function.call' | undefined, created_at?: string | undefined, completed_at?: (string | null) | undefined, agent_id?: (string | null) | undefined, model?: (string | null) | undefined, id?: string | undefined, tool_call_id: string, name: string, arguments: FunctionCallEntryArguments, confirmation_status?: ('pending' | 'allowed' | 'denied' | null) | undefined}; export type ToolExecutionInfo = {[key: string]: unknown}; export type ToolExecutionEntry = {object?: 'entry' | undefined, type?: 'tool.execution' | undefined, created_at?: string | undefined, completed_at?: (string | null) | undefined, agent_id?: (string | null) | undefined, model?: (string | null) | undefined, id?: string | undefined, name: BuiltInConnectors | string, arguments: string, info?: ToolExecutionInfo | undefined}; export type AgentHandoffEntry = {object?: 'entry' | undefined, type?: 'agent.handoff' | undefined, created_at?: string | undefined, completed_at?: (string | null) | undefined, id?: string | undefined, previous_agent_id: string, previous_agent_name: string, next_agent_id: string, next_agent_name: string}; export type InputEntries = Array; export type ConversationInputs = string | InputEntries; export type CompletionArgsStop = string | Array | null; export type Prediction = {type?: 'content' | undefined, content?: string | undefined}; export type ResponseFormats = 'text' | 'json_object' | 'json_schema'; export type JsonSchema = {name: string, description?: (string | null) | undefined, schema: {[key: string]: unknown}, strict?: boolean | undefined}; export type ResponseFormat = {type?: ResponseFormats | undefined, json_schema?: (JsonSchema | null) | undefined}; export type ToolChoiceEnum = 'auto' | 'none' | 'any' | 'required'; export type ReasoningEffort = 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh'; export type CompletionArgs = {stop?: CompletionArgsStop | undefined, presence_penalty?: (number | null) | undefined, frequency_penalty?: (number | null) | undefined, temperature?: (number | null) | undefined, top_p?: (number | null) | undefined, max_tokens?: (number | null) | undefined, random_seed?: (number | null) | undefined, prediction?: (Prediction | null) | undefined, response_format?: (ResponseFormat | null) | undefined, tool_choice?: ToolChoiceEnum | undefined, reasoning_effort?: (ReasoningEffort | null) | undefined}; export type ToolCallConfirmation = {tool_call_id: string, confirmation: 'allow' | 'deny'}; export type ConversationAppendStreamRequest = {inputs?: ConversationInputs | undefined, stream?: true | undefined, store?: boolean | undefined, handoff_execution?: ('client' | 'server') | undefined, completion_args?: CompletionArgs | undefined, tool_confirmations?: (Array | null) | undefined}; export type CreateApiV1ConversationsConversationIdStreamArgs = {conversation_id: string, body: ConversationAppendStreamRequest}; export type CreateApiV1ConversationsConversationIdStreamOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Append new entries to an existing conversation. * * POST /v1/conversations/{conversation_id}#stream */ export const createApiV1ConversationsConversationIdStream = async (args: CreateApiV1ConversationsConversationIdStreamArgs, options?: CreateApiV1ConversationsConversationIdStreamOptions) => { const {baseUrl = "https://api.mistral.ai", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "text/event-stream") if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/conversations/${encodeURIComponent(String(args.conversation_id))}#stream${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.text() };