@code-yeongyu/senpi-ai 2026.8.13 → 2026.8.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/api/anthropic-messages.d.ts.map +1 -1
- package/dist/api/anthropic-messages.js +40 -14
- package/dist/api/anthropic-messages.js.map +1 -1
- package/dist/api/bedrock-converse-stream.d.ts.map +1 -1
- package/dist/api/bedrock-converse-stream.js +16 -4
- package/dist/api/bedrock-converse-stream.js.map +1 -1
- package/dist/api/cloudflare-gateway-binding.d.ts +69 -0
- package/dist/api/cloudflare-gateway-binding.d.ts.map +1 -0
- package/dist/api/cloudflare-gateway-binding.js +159 -0
- package/dist/api/cloudflare-gateway-binding.js.map +1 -0
- package/dist/api/constrained-sampling.d.ts +3 -0
- package/dist/api/constrained-sampling.d.ts.map +1 -1
- package/dist/api/constrained-sampling.js +125 -5
- package/dist/api/constrained-sampling.js.map +1 -1
- package/dist/api/google-generative-ai.js +7 -3
- package/dist/api/google-generative-ai.js.map +1 -1
- package/dist/api/google-shared.d.ts +1 -1
- package/dist/api/google-shared.d.ts.map +1 -1
- package/dist/api/google-shared.js +13 -9
- package/dist/api/google-shared.js.map +1 -1
- package/dist/api/google-vertex.js +7 -3
- package/dist/api/google-vertex.js.map +1 -1
- package/dist/api/mistral-conversations.d.ts +1 -1
- package/dist/api/mistral-conversations.d.ts.map +1 -1
- package/dist/api/mistral-conversations.js +208 -42
- package/dist/api/mistral-conversations.js.map +1 -1
- package/dist/api/openai-codex-responses.d.ts.map +1 -1
- package/dist/api/openai-codex-responses.js +13 -4
- package/dist/api/openai-codex-responses.js.map +1 -1
- package/dist/api/openai-completions.d.ts.map +1 -1
- package/dist/api/openai-completions.js +10 -7
- package/dist/api/openai-completions.js.map +1 -1
- package/dist/api/openai-responses-shared.d.ts +1 -0
- package/dist/api/openai-responses-shared.d.ts.map +1 -1
- package/dist/api/openai-responses-shared.js +31 -7
- package/dist/api/openai-responses-shared.js.map +1 -1
- package/dist/api/openai-responses.d.ts.map +1 -1
- package/dist/api/openai-responses.js +8 -1
- package/dist/api/openai-responses.js.map +1 -1
- package/dist/auth/oauth/cursor.d.ts +16 -0
- package/dist/auth/oauth/cursor.d.ts.map +1 -0
- package/dist/auth/oauth/cursor.js +234 -0
- package/dist/auth/oauth/cursor.js.map +1 -0
- package/dist/auth/oauth/github-copilot.d.ts.map +1 -1
- package/dist/auth/oauth/github-copilot.js +6 -3
- package/dist/auth/oauth/github-copilot.js.map +1 -1
- package/dist/auth/oauth/load.d.ts +2 -0
- package/dist/auth/oauth/load.d.ts.map +1 -1
- package/dist/auth/oauth/load.js +5 -0
- package/dist/auth/oauth/load.js.map +1 -1
- package/dist/auth/resolve.js +44 -9
- package/dist/auth/resolve.js.map +1 -1
- package/dist/auth/types.d.ts +2 -0
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/auth/types.js.map +1 -1
- package/dist/bun-oauth.d.ts.map +1 -1
- package/dist/bun-oauth.js +2 -0
- package/dist/bun-oauth.js.map +1 -1
- package/dist/image-models.generated.d.ts +15 -0
- package/dist/image-models.generated.d.ts.map +1 -1
- package/dist/image-models.generated.js +15 -0
- package/dist/image-models.generated.js.map +1 -1
- package/dist/providers/all.d.ts.map +1 -1
- package/dist/providers/all.js +2 -0
- package/dist/providers/all.js.map +1 -1
- package/dist/providers/cursor.d.ts +15 -0
- package/dist/providers/cursor.d.ts.map +1 -0
- package/dist/providers/cursor.js +32 -0
- package/dist/providers/cursor.js.map +1 -0
- package/dist/providers/data/.manifest.json +1 -1
- package/dist/providers/data/alibaba-token-plan.json +1 -1
- package/dist/providers/data/baseten.json +1 -1
- package/dist/providers/data/cloudflare-ai-gateway.json +1 -1
- package/dist/providers/data/cloudflare-workers-ai.json +1 -1
- package/dist/providers/data/deepseek.json +1 -1
- package/dist/providers/data/fireworks.json +1 -1
- package/dist/providers/data/github-copilot.json +1 -1
- package/dist/providers/data/google-vertex.json +1 -1
- package/dist/providers/data/google.json +1 -1
- package/dist/providers/data/huggingface.json +1 -1
- package/dist/providers/data/kimi-coding.json +1 -1
- package/dist/providers/data/nvidia.json +1 -1
- package/dist/providers/data/openai-codex.json +1 -1
- package/dist/providers/data/openai.json +1 -1
- package/dist/providers/data/opencode-go.json +1 -1
- package/dist/providers/data/opencode.json +1 -1
- package/dist/providers/data/openrouter.json +1 -1
- package/dist/providers/data/qwen-token-plan-cn.json +1 -1
- package/dist/providers/data/qwen-token-plan.json +1 -1
- package/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/dist/providers/data/zai-coding-cn.json +1 -1
- package/dist/providers/data/zai.json +1 -1
- package/dist/types.d.ts +14 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/overflow.d.ts.map +1 -1
- package/dist/utils/overflow.js +2 -0
- package/dist/utils/overflow.js.map +1 -1
- package/dist/utils/pi-user-agent.d.ts +2 -0
- package/dist/utils/pi-user-agent.d.ts.map +1 -0
- package/dist/utils/pi-user-agent.js +12 -0
- package/dist/utils/pi-user-agent.js.map +1 -0
- package/dist/utils/prompt-cache-ttl.d.ts.map +1 -1
- package/dist/utils/prompt-cache-ttl.js +3 -2
- package/dist/utils/prompt-cache-ttl.js.map +1 -1
- package/dist/utils/retry.d.ts.map +1 -1
- package/dist/utils/retry.js +1 -0
- package/dist/utils/retry.js.map +1 -1
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +34 -0
- package/dist/utils/validation.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { HTTPClient, Mistral } from "@mistralai/mistralai";
|
|
2
1
|
import { calculateCost, clampThinkingLevel } from "../models.js";
|
|
3
2
|
import { AssistantMessageEventStream } from "../utils/event-stream.js";
|
|
4
3
|
import { shortHash } from "../utils/hash.js";
|
|
4
|
+
import { headersToRecord } from "../utils/headers.js";
|
|
5
5
|
import { parseStreamingJson } from "../utils/json-parse.js";
|
|
6
6
|
import { sanitizeSurrogates } from "../utils/sanitize-unicode.js";
|
|
7
|
-
import { resolveJsonSchemaStrictSampling } from "./constrained-sampling.js";
|
|
7
|
+
import { getJsonSchemaToolParameters, resolveJsonSchemaStrictSampling } from "./constrained-sampling.js";
|
|
8
8
|
import { applyExtraBody, buildBaseOptions, MISTRAL_RESERVED_BODY_KEYS } from "./simple-options.js";
|
|
9
9
|
import { transformMessages } from "./transform-messages.js";
|
|
10
10
|
const MISTRAL_TOOL_CALL_ID_LENGTH = 9;
|
|
11
11
|
const MAX_MISTRAL_ERROR_BODY_CHARS = 4000;
|
|
12
12
|
/**
|
|
13
|
-
* Stream responses from Mistral
|
|
13
|
+
* Stream responses from the native Mistral Chat Completions endpoint.
|
|
14
14
|
*/
|
|
15
15
|
export const stream = (model, context, options) => {
|
|
16
16
|
const stream = new AssistantMessageEventStream();
|
|
@@ -21,12 +21,6 @@ export const stream = (model, context, options) => {
|
|
|
21
21
|
if (!apiKey) {
|
|
22
22
|
throw new Error(`No API key for provider: ${model.provider}`);
|
|
23
23
|
}
|
|
24
|
-
// Intentionally per-request: avoids shared SDK mutable state across concurrent consumers.
|
|
25
|
-
const mistral = new Mistral({
|
|
26
|
-
apiKey,
|
|
27
|
-
serverURL: model.baseUrl,
|
|
28
|
-
...(options?.fetch ? { httpClient: new HTTPClient({ fetcher: options.fetch }) } : {}),
|
|
29
|
-
});
|
|
30
24
|
const normalizeMistralToolCallId = createMistralToolCallIdNormalizer();
|
|
31
25
|
const preserveThinking = options?.promptMode === "reasoning" || options?.reasoningEffort !== undefined;
|
|
32
26
|
const transformedMessages = transformMessages(context.messages, model, (id) => normalizeMistralToolCallId(id), {
|
|
@@ -37,7 +31,7 @@ export const stream = (model, context, options) => {
|
|
|
37
31
|
if (nextPayload !== undefined) {
|
|
38
32
|
payload = nextPayload;
|
|
39
33
|
}
|
|
40
|
-
const mistralStream = await
|
|
34
|
+
const mistralStream = await requestMistralStream(model, payload, apiKey, options);
|
|
41
35
|
stream.push({ type: "start", partial: output });
|
|
42
36
|
await consumeChatStream(model, output, stream, mistralStream);
|
|
43
37
|
if (options?.signal?.aborted) {
|
|
@@ -134,9 +128,9 @@ function deriveMistralToolCallId(id, attempt) {
|
|
|
134
128
|
}
|
|
135
129
|
function formatMistralError(error) {
|
|
136
130
|
if (error instanceof Error) {
|
|
137
|
-
const
|
|
138
|
-
const statusCode = typeof
|
|
139
|
-
const bodyText = typeof
|
|
131
|
+
const httpError = error;
|
|
132
|
+
const statusCode = typeof httpError.statusCode === "number" ? httpError.statusCode : undefined;
|
|
133
|
+
const bodyText = typeof httpError.body === "string" ? httpError.body.trim() : undefined;
|
|
140
134
|
if (statusCode !== undefined && bodyText) {
|
|
141
135
|
return `Mistral API error (${statusCode}): ${truncateErrorText(bodyText, MAX_MISTRAL_ERROR_BODY_CHARS)}`;
|
|
142
136
|
}
|
|
@@ -160,26 +154,197 @@ function safeJsonStringify(value) {
|
|
|
160
154
|
return String(value);
|
|
161
155
|
}
|
|
162
156
|
}
|
|
163
|
-
function
|
|
164
|
-
const
|
|
165
|
-
|
|
157
|
+
async function requestMistralStream(model, payload, apiKey, options) {
|
|
158
|
+
const baseUrl = new URL(model.baseUrl);
|
|
159
|
+
baseUrl.pathname = `${baseUrl.pathname.replace(/\/+$/u, "")}/`;
|
|
160
|
+
const url = new URL("v1/chat/completions", baseUrl);
|
|
161
|
+
const headers = buildMistralHeaders(model, apiKey, options);
|
|
162
|
+
const timeoutSignal = AbortSignal.timeout(options?.timeoutMs ?? 60_000);
|
|
163
|
+
const signal = options?.signal ? AbortSignal.any([options.signal, timeoutSignal]) : timeoutSignal;
|
|
164
|
+
const response = await (options?.fetch ?? globalThis.fetch)(url, {
|
|
165
|
+
method: "POST",
|
|
166
|
+
headers,
|
|
167
|
+
body: JSON.stringify(toMistralWirePayload(payload)),
|
|
168
|
+
signal,
|
|
169
|
+
});
|
|
170
|
+
await options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model);
|
|
171
|
+
if (!response.ok) {
|
|
172
|
+
const body = await response.text();
|
|
173
|
+
throw new MistralHttpError(response.status, body, response.statusText);
|
|
174
|
+
}
|
|
175
|
+
if (!response.body) {
|
|
176
|
+
throw new Error("Mistral response has no body");
|
|
177
|
+
}
|
|
178
|
+
return readMistralEvents(response.body, signal);
|
|
179
|
+
}
|
|
180
|
+
class MistralHttpError extends Error {
|
|
181
|
+
constructor(statusCode, body, statusText) {
|
|
182
|
+
super(statusText || `Request failed with status ${statusCode}`);
|
|
183
|
+
this.name = "MistralHttpError";
|
|
184
|
+
this.statusCode = statusCode;
|
|
185
|
+
this.body = body;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function buildMistralHeaders(model, apiKey, options) {
|
|
189
|
+
const headers = new Headers({
|
|
190
|
+
accept: "text/event-stream",
|
|
191
|
+
authorization: `Bearer ${apiKey}`,
|
|
192
|
+
"content-type": "application/json",
|
|
193
|
+
});
|
|
194
|
+
applyMistralHeaderOverrides(headers, model.headers);
|
|
195
|
+
applyMistralHeaderOverrides(headers, options?.headers);
|
|
196
|
+
const hasExplicitAffinity = hasMistralHeaderOverride(model.headers, "x-affinity") || hasMistralHeaderOverride(options?.headers, "x-affinity");
|
|
197
|
+
if (shouldUsePromptCaching(options) && !hasExplicitAffinity) {
|
|
198
|
+
headers.set("x-affinity", options.sessionId);
|
|
199
|
+
}
|
|
200
|
+
return headers;
|
|
201
|
+
}
|
|
202
|
+
function applyMistralHeaderOverrides(headers, overrides) {
|
|
203
|
+
if (!overrides)
|
|
204
|
+
return;
|
|
205
|
+
for (const [name, value] of Object.entries(overrides)) {
|
|
206
|
+
if (value === null)
|
|
207
|
+
headers.delete(name);
|
|
208
|
+
else
|
|
209
|
+
headers.set(name, value);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function hasMistralHeaderOverride(overrides, target) {
|
|
213
|
+
return !!overrides && Object.keys(overrides).some((name) => name.toLowerCase() === target);
|
|
214
|
+
}
|
|
215
|
+
function toMistralWirePayload(payload) {
|
|
216
|
+
const wirePayload = { ...payload };
|
|
217
|
+
for (const [source, target] of [
|
|
218
|
+
["topP", "top_p"],
|
|
219
|
+
["maxTokens", "max_tokens"],
|
|
220
|
+
["randomSeed", "random_seed"],
|
|
221
|
+
["responseFormat", "response_format"],
|
|
222
|
+
["toolChoice", "tool_choice"],
|
|
223
|
+
["presencePenalty", "presence_penalty"],
|
|
224
|
+
["frequencyPenalty", "frequency_penalty"],
|
|
225
|
+
["parallelToolCalls", "parallel_tool_calls"],
|
|
226
|
+
["reasoningEffort", "reasoning_effort"],
|
|
227
|
+
["promptMode", "prompt_mode"],
|
|
228
|
+
["promptCacheKey", "prompt_cache_key"],
|
|
229
|
+
["safePrompt", "safe_prompt"],
|
|
230
|
+
]) {
|
|
231
|
+
remapMistralProperty(wirePayload, source, target);
|
|
232
|
+
}
|
|
233
|
+
wirePayload.messages = payload.messages.map((message) => toMistralWireMessage(message));
|
|
234
|
+
const responseFormat = wirePayload.response_format;
|
|
235
|
+
if (isMistralRecord(responseFormat)) {
|
|
236
|
+
const wireResponseFormat = { ...responseFormat };
|
|
237
|
+
remapMistralProperty(wireResponseFormat, "jsonSchema", "json_schema");
|
|
238
|
+
const jsonSchema = wireResponseFormat.json_schema;
|
|
239
|
+
if (isMistralRecord(jsonSchema)) {
|
|
240
|
+
const wireJsonSchema = { ...jsonSchema };
|
|
241
|
+
remapMistralProperty(wireJsonSchema, "schemaDefinition", "schema");
|
|
242
|
+
wireResponseFormat.json_schema = wireJsonSchema;
|
|
243
|
+
}
|
|
244
|
+
wirePayload.response_format = wireResponseFormat;
|
|
245
|
+
}
|
|
246
|
+
return wirePayload;
|
|
247
|
+
}
|
|
248
|
+
function toMistralWireMessage(message) {
|
|
249
|
+
const wireMessage = { ...message };
|
|
250
|
+
remapMistralProperty(wireMessage, "toolCalls", "tool_calls");
|
|
251
|
+
remapMistralProperty(wireMessage, "toolCallId", "tool_call_id");
|
|
252
|
+
if (Array.isArray(message.content)) {
|
|
253
|
+
wireMessage.content = message.content.map((chunk) => toMistralWireContentChunk(chunk));
|
|
254
|
+
}
|
|
255
|
+
return wireMessage;
|
|
256
|
+
}
|
|
257
|
+
function toMistralWireContentChunk(chunk) {
|
|
258
|
+
const wireChunk = { ...chunk };
|
|
259
|
+
for (const [source, target] of [
|
|
260
|
+
["imageUrl", "image_url"],
|
|
261
|
+
["documentUrl", "document_url"],
|
|
262
|
+
["documentName", "document_name"],
|
|
263
|
+
["fileId", "file_id"],
|
|
264
|
+
["referenceIds", "reference_ids"],
|
|
265
|
+
["inputAudio", "input_audio"],
|
|
266
|
+
]) {
|
|
267
|
+
remapMistralProperty(wireChunk, source, target);
|
|
268
|
+
}
|
|
269
|
+
return wireChunk;
|
|
270
|
+
}
|
|
271
|
+
function remapMistralProperty(record, source, target) {
|
|
272
|
+
if (!(source in record))
|
|
273
|
+
return;
|
|
274
|
+
record[target] = record[source];
|
|
275
|
+
delete record[source];
|
|
276
|
+
}
|
|
277
|
+
function isMistralRecord(value) {
|
|
278
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
279
|
+
}
|
|
280
|
+
const MISTRAL_STREAM_DONE = Symbol("mistral-stream-done");
|
|
281
|
+
async function* readMistralEvents(body, signal) {
|
|
282
|
+
const reader = body.getReader();
|
|
283
|
+
const decoder = new TextDecoder();
|
|
284
|
+
let buffer = "";
|
|
285
|
+
const onAbort = () => {
|
|
286
|
+
void reader.cancel().catch(() => { });
|
|
166
287
|
};
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
288
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
289
|
+
try {
|
|
290
|
+
while (true) {
|
|
291
|
+
if (signal.aborted)
|
|
292
|
+
throw signal.reason;
|
|
293
|
+
const { done, value } = await reader.read();
|
|
294
|
+
if (signal.aborted)
|
|
295
|
+
throw signal.reason;
|
|
296
|
+
buffer += done ? decoder.decode() : decoder.decode(value, { stream: true });
|
|
297
|
+
let boundary = findMistralEventBoundary(buffer);
|
|
298
|
+
while (boundary) {
|
|
299
|
+
const event = parseMistralEvent(buffer.slice(0, boundary.index));
|
|
300
|
+
buffer = buffer.slice(boundary.index + boundary.length);
|
|
301
|
+
if (event === MISTRAL_STREAM_DONE)
|
|
302
|
+
return;
|
|
303
|
+
if (event)
|
|
304
|
+
yield event;
|
|
305
|
+
boundary = findMistralEventBoundary(buffer);
|
|
306
|
+
}
|
|
307
|
+
if (done)
|
|
308
|
+
break;
|
|
309
|
+
}
|
|
310
|
+
if (buffer.trim()) {
|
|
311
|
+
const event = parseMistralEvent(buffer);
|
|
312
|
+
if (event !== MISTRAL_STREAM_DONE && event)
|
|
313
|
+
yield event;
|
|
314
|
+
}
|
|
178
315
|
}
|
|
179
|
-
|
|
180
|
-
|
|
316
|
+
finally {
|
|
317
|
+
signal.removeEventListener("abort", onAbort);
|
|
318
|
+
try {
|
|
319
|
+
await reader.cancel();
|
|
320
|
+
}
|
|
321
|
+
catch { }
|
|
322
|
+
try {
|
|
323
|
+
reader.releaseLock();
|
|
324
|
+
}
|
|
325
|
+
catch { }
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
function findMistralEventBoundary(buffer) {
|
|
329
|
+
const match = /\r\n\r\n|\r\n\r|\r\n\n|\r\r\n|\n\r\n|\r\r|\n\r|\n\n/u.exec(buffer);
|
|
330
|
+
return match?.index === undefined ? undefined : { index: match.index, length: match[0].length };
|
|
331
|
+
}
|
|
332
|
+
function parseMistralEvent(raw) {
|
|
333
|
+
const data = raw
|
|
334
|
+
.split(/\r\n|\r|\n/u)
|
|
335
|
+
.filter((line) => line.startsWith("data:"))
|
|
336
|
+
.map((line) => line.slice(5).trimStart())
|
|
337
|
+
.join("\n")
|
|
338
|
+
.trim();
|
|
339
|
+
if (!data)
|
|
340
|
+
return undefined;
|
|
341
|
+
if (data === "[DONE]")
|
|
342
|
+
return MISTRAL_STREAM_DONE;
|
|
343
|
+
const parsed = JSON.parse(data);
|
|
344
|
+
if (!isMistralRecord(parsed) || !Array.isArray(parsed.choices)) {
|
|
345
|
+
throw new Error("Invalid Mistral streaming event");
|
|
181
346
|
}
|
|
182
|
-
return
|
|
347
|
+
return { data: parsed };
|
|
183
348
|
}
|
|
184
349
|
function buildChatPayload(model, context, messages, options) {
|
|
185
350
|
const payload = {
|
|
@@ -257,23 +422,23 @@ async function consumeChatStream(model, output, stream, mistralStream) {
|
|
|
257
422
|
// mirroring how OpenAI-style streaming exposes a stable response identifier per stream.
|
|
258
423
|
output.responseId ||= chunk.id;
|
|
259
424
|
if (chunk.usage) {
|
|
260
|
-
const promptTokens = chunk.usage.
|
|
425
|
+
const promptTokens = chunk.usage.prompt_tokens || 0;
|
|
261
426
|
const cachedPromptTokens = getMistralCachedPromptTokens(chunk.usage, promptTokens);
|
|
262
427
|
output.usage.input = Math.max(0, promptTokens - cachedPromptTokens);
|
|
263
|
-
output.usage.output = chunk.usage.
|
|
428
|
+
output.usage.output = chunk.usage.completion_tokens || 0;
|
|
264
429
|
output.usage.cacheRead = cachedPromptTokens;
|
|
265
430
|
output.usage.cacheWrite = 0;
|
|
266
431
|
output.usage.totalTokens =
|
|
267
|
-
chunk.usage.
|
|
432
|
+
chunk.usage.total_tokens ||
|
|
268
433
|
output.usage.input + output.usage.output + output.usage.cacheRead + output.usage.cacheWrite;
|
|
269
434
|
calculateCost(model, output.usage);
|
|
270
435
|
}
|
|
271
436
|
const choice = chunk.choices[0];
|
|
272
437
|
if (!choice)
|
|
273
438
|
continue;
|
|
274
|
-
if (choice.
|
|
275
|
-
output.rawStopReason = choice.
|
|
276
|
-
const stopReasonResult = mapChatStopReason(choice.
|
|
439
|
+
if (choice.finish_reason) {
|
|
440
|
+
output.rawStopReason = choice.finish_reason;
|
|
441
|
+
const stopReasonResult = mapChatStopReason(choice.finish_reason);
|
|
277
442
|
output.stopReason = stopReasonResult.stopReason;
|
|
278
443
|
if (stopReasonResult.errorMessage) {
|
|
279
444
|
output.errorMessage = stopReasonResult.errorMessage;
|
|
@@ -301,8 +466,8 @@ async function consumeChatStream(model, output, stream, mistralStream) {
|
|
|
301
466
|
continue;
|
|
302
467
|
}
|
|
303
468
|
if (item.type === "thinking") {
|
|
304
|
-
const deltaText = item.thinking
|
|
305
|
-
.map((part) =>
|
|
469
|
+
const deltaText = (item.thinking ?? [])
|
|
470
|
+
.map((part) => part.text ?? "")
|
|
306
471
|
.filter((text) => text.length > 0)
|
|
307
472
|
.join("");
|
|
308
473
|
const thinkingDelta = sanitizeSurrogates(deltaText);
|
|
@@ -324,7 +489,7 @@ async function consumeChatStream(model, output, stream, mistralStream) {
|
|
|
324
489
|
continue;
|
|
325
490
|
}
|
|
326
491
|
if (item.type === "text") {
|
|
327
|
-
const textDelta = sanitizeSurrogates(item.text);
|
|
492
|
+
const textDelta = sanitizeSurrogates(item.text ?? "");
|
|
328
493
|
if (currentBlock?.type !== "text") {
|
|
329
494
|
finishCurrentBlock(currentBlock);
|
|
330
495
|
currentBlock = { type: "text", text: "" };
|
|
@@ -341,7 +506,7 @@ async function consumeChatStream(model, output, stream, mistralStream) {
|
|
|
341
506
|
}
|
|
342
507
|
}
|
|
343
508
|
}
|
|
344
|
-
const toolCalls = delta.
|
|
509
|
+
const toolCalls = delta.tool_calls || [];
|
|
345
510
|
for (const toolCall of toolCalls) {
|
|
346
511
|
if (currentBlock) {
|
|
347
512
|
finishCurrentBlock(currentBlock);
|
|
@@ -410,7 +575,7 @@ function toFunctionTools(tools) {
|
|
|
410
575
|
function: {
|
|
411
576
|
name: tool.name,
|
|
412
577
|
description: tool.description,
|
|
413
|
-
parameters: stripSymbolKeys(tool
|
|
578
|
+
parameters: stripSymbolKeys(getJsonSchemaToolParameters(tool, strict)),
|
|
414
579
|
strict: strict ?? false,
|
|
415
580
|
},
|
|
416
581
|
};
|
|
@@ -480,9 +645,10 @@ function toChatMessages(messages, supportsImages) {
|
|
|
480
645
|
id: block.id,
|
|
481
646
|
type: "function",
|
|
482
647
|
function: { name: block.name, arguments: JSON.stringify(block.arguments || {}) },
|
|
648
|
+
index: 0,
|
|
483
649
|
});
|
|
484
650
|
}
|
|
485
|
-
const assistantMessage = { role: "assistant" };
|
|
651
|
+
const assistantMessage = { role: "assistant", prefix: false };
|
|
486
652
|
if (contentParts.length > 0)
|
|
487
653
|
assistantMessage.content = contentParts;
|
|
488
654
|
if (toolCalls.length > 0)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mistral-conversations.js","sourceRoot":"","sources":["../../src/api/mistral-conversations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAQ3D,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAejE,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,+BAA+B,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AACnG,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,MAAM,2BAA2B,GAAG,CAAC,CAAC;AACtC,MAAM,4BAA4B,GAAG,IAAI,CAAC;AAgB1C;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAA4D,CAC9E,KAAqC,EACrC,OAAgB,EAChB,OAAwB,EACM,EAAE;IAChC,MAAM,MAAM,GAAG,IAAI,2BAA2B,EAAE,CAAC;IAEjD,CAAC,KAAK,IAAI,EAAE;QACX,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK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E,EAAE,CAAC;IACnF,CAAC;AACF,CAAC","sourcesContent":["import { HTTPClient, Mistral } from \"@mistralai/mistralai\";\nimport type {\n\tChatCompletionStreamRequest,\n\tChatCompletionStreamRequestMessage,\n\tCompletionEvent,\n\tContentChunk,\n\tFunctionTool,\n} from \"@mistralai/mistralai/models/components\";\nimport { calculateCost, clampThinkingLevel } from \"../models.ts\";\nimport type {\n\tAssistantMessage,\n\tContext,\n\tMessage,\n\tModel,\n\tSimpleStreamOptions,\n\tStopReason,\n\tStreamFunction,\n\tStreamOptions,\n\tTextContent,\n\tThinkingContent,\n\tTool,\n\tToolCall,\n} from \"../types.ts\";\nimport { AssistantMessageEventStream } from \"../utils/event-stream.ts\";\nimport { shortHash } from \"../utils/hash.ts\";\nimport { parseStreamingJson } from \"../utils/json-parse.ts\";\nimport { sanitizeSurrogates } from \"../utils/sanitize-unicode.ts\";\nimport { resolveJsonSchemaStrictSampling } from \"./constrained-sampling.ts\";\nimport { applyExtraBody, buildBaseOptions, MISTRAL_RESERVED_BODY_KEYS } from \"./simple-options.ts\";\nimport { transformMessages } from \"./transform-messages.ts\";\n\nconst MISTRAL_TOOL_CALL_ID_LENGTH = 9;\nconst MAX_MISTRAL_ERROR_BODY_CHARS = 4000;\n\n/**\n * Provider-specific options for the Mistral API.\n */\ntype MistralReasoningEffort = \"none\" | \"high\";\ntype MistralChatCompletionStreamRequest = ChatCompletionStreamRequest & {\n\tpromptCacheKey?: string;\n};\n\nexport interface MistralOptions extends StreamOptions {\n\ttoolChoice?: \"auto\" | \"none\" | \"any\" | \"required\" | { type: \"function\"; function: { name: string } };\n\tpromptMode?: \"reasoning\";\n\treasoningEffort?: MistralReasoningEffort;\n}\n\n/**\n * Stream responses from Mistral using `chat.stream`.\n */\nexport const stream: StreamFunction<\"mistral-conversations\", MistralOptions> = (\n\tmodel: Model<\"mistral-conversations\">,\n\tcontext: Context,\n\toptions?: MistralOptions,\n): AssistantMessageEventStream => {\n\tconst stream = new AssistantMessageEventStream();\n\n\t(async () => {\n\t\tconst output = createOutput(model);\n\n\t\ttry {\n\t\t\tconst apiKey = options?.apiKey;\n\t\t\tif (!apiKey) {\n\t\t\t\tthrow new Error(`No API key for provider: ${model.provider}`);\n\t\t\t}\n\n\t\t\t// Intentionally per-request: avoids shared SDK mutable state across concurrent consumers.\n\t\t\tconst mistral = new Mistral({\n\t\t\t\tapiKey,\n\t\t\t\tserverURL: model.baseUrl,\n\t\t\t\t...(options?.fetch ? { httpClient: new HTTPClient({ fetcher: options.fetch }) } : {}),\n\t\t\t});\n\n\t\t\tconst normalizeMistralToolCallId = createMistralToolCallIdNormalizer();\n\t\t\tconst preserveThinking = options?.promptMode === \"reasoning\" || options?.reasoningEffort !== undefined;\n\t\t\tconst transformedMessages = transformMessages(\n\t\t\t\tcontext.messages,\n\t\t\t\tmodel,\n\t\t\t\t(id) => normalizeMistralToolCallId(id),\n\t\t\t\t{\n\t\t\t\t\tpreserveThinking,\n\t\t\t\t},\n\t\t\t);\n\n\t\t\tlet payload = buildChatPayload(model, context, transformedMessages, options);\n\t\t\tconst nextPayload = await options?.onPayload?.(payload, model);\n\t\t\tif (nextPayload !== undefined) {\n\t\t\t\tpayload = nextPayload as MistralChatCompletionStreamRequest;\n\t\t\t}\n\t\t\tconst mistralStream = await mistral.chat.stream(payload, buildRequestOptions(model, options));\n\t\t\tstream.push({ type: \"start\", partial: output });\n\t\t\tawait consumeChatStream(model, output, stream, mistralStream);\n\n\t\t\tif (options?.signal?.aborted) {\n\t\t\t\tthrow new Error(\"Request was aborted\");\n\t\t\t}\n\n\t\t\tif (output.stopReason === \"pending\") {\n\t\t\t\tthrow new Error(\"Mistral stream ended without a finish reason\");\n\t\t\t}\n\t\t\tif (output.stopReason === \"aborted\" || output.stopReason === \"error\") {\n\t\t\t\tthrow new Error(output.errorMessage || \"An unknown error occurred\");\n\t\t\t}\n\n\t\t\tstream.push({ type: \"done\", reason: output.stopReason, message: output });\n\t\t\tstream.end();\n\t\t} catch (error) {\n\t\t\tfor (const block of output.content) {\n\t\t\t\t// partialArgs is only a streaming scratch buffer; never persist it.\n\t\t\t\tdelete (block as { partialArgs?: string }).partialArgs;\n\t\t\t}\n\t\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\t\toutput.errorMessage = formatMistralError(error);\n\t\t\tstream.push({ type: \"error\", reason: output.stopReason, error: output });\n\t\t\tstream.end();\n\t\t}\n\t})();\n\n\treturn stream;\n};\n\n/**\n * Maps provider-agnostic `SimpleStreamOptions` to Mistral options.\n */\nexport const streamSimple: StreamFunction<\"mistral-conversations\", SimpleStreamOptions> = (\n\tmodel: Model<\"mistral-conversations\">,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream => {\n\tconst apiKey = options?.apiKey;\n\tif (!apiKey) {\n\t\tthrow new Error(`No API key for provider: ${model.provider}`);\n\t}\n\n\tconst base = buildBaseOptions(model, context, options, apiKey);\n\tconst clampedReasoning = options?.reasoning ? clampThinkingLevel(model, options.reasoning) : undefined;\n\tconst reasoning = clampedReasoning === \"off\" ? undefined : clampedReasoning;\n\tconst shouldUseReasoning = model.reasoning && reasoning !== undefined;\n\n\treturn stream(model, context, {\n\t\t...base,\n\t\tpromptMode: shouldUseReasoning && usesPromptModeReasoning(model) ? \"reasoning\" : undefined,\n\t\treasoningEffort:\n\t\t\tshouldUseReasoning && usesReasoningEffort(model) ? mapReasoningEffort(model, reasoning) : undefined,\n\t} satisfies MistralOptions);\n};\n\nfunction createOutput(model: Model<\"mistral-conversations\">): AssistantMessage {\n\treturn {\n\t\trole: \"assistant\",\n\t\tcontent: [],\n\t\tapi: model.api,\n\t\tprovider: model.provider,\n\t\tmodel: model.id,\n\t\tusage: {\n\t\t\tinput: 0,\n\t\t\toutput: 0,\n\t\t\tcacheRead: 0,\n\t\t\tcacheWrite: 0,\n\t\t\ttotalTokens: 0,\n\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t},\n\t\tstopReason: \"pending\",\n\t\ttimestamp: Date.now(),\n\t};\n}\n\nfunction createMistralToolCallIdNormalizer(): (id: string) => string {\n\tconst idMap = new Map<string, string>();\n\tconst reverseMap = new Map<string, string>();\n\n\treturn (id: string): string => {\n\t\tconst existing = idMap.get(id);\n\t\tif (existing) return existing;\n\n\t\tlet attempt = 0;\n\t\twhile (true) {\n\t\t\tconst candidate = deriveMistralToolCallId(id, attempt);\n\t\t\tconst owner = reverseMap.get(candidate);\n\t\t\tif (!owner || owner === id) {\n\t\t\t\tidMap.set(id, candidate);\n\t\t\t\treverseMap.set(candidate, id);\n\t\t\t\treturn candidate;\n\t\t\t}\n\t\t\tattempt++;\n\t\t}\n\t};\n}\n\nfunction deriveMistralToolCallId(id: string, attempt: number): string {\n\tconst normalized = id.replace(/[^a-zA-Z0-9]/g, \"\");\n\tif (attempt === 0 && normalized.length === MISTRAL_TOOL_CALL_ID_LENGTH) return normalized;\n\tconst seedBase = normalized || id;\n\tconst seed = attempt === 0 ? seedBase : `${seedBase}:${attempt}`;\n\treturn shortHash(seed)\n\t\t.replace(/[^a-zA-Z0-9]/g, \"\")\n\t\t.slice(0, MISTRAL_TOOL_CALL_ID_LENGTH);\n}\n\nfunction formatMistralError(error: unknown): string {\n\tif (error instanceof Error) {\n\t\tconst sdkError = error as Error & { statusCode?: unknown; body?: unknown };\n\t\tconst statusCode = typeof sdkError.statusCode === \"number\" ? sdkError.statusCode : undefined;\n\t\tconst bodyText = typeof sdkError.body === \"string\" ? sdkError.body.trim() : undefined;\n\t\tif (statusCode !== undefined && bodyText) {\n\t\t\treturn `Mistral API error (${statusCode}): ${truncateErrorText(bodyText, MAX_MISTRAL_ERROR_BODY_CHARS)}`;\n\t\t}\n\t\tif (statusCode !== undefined) return `Mistral API error (${statusCode}): ${error.message}`;\n\t\treturn error.message;\n\t}\n\treturn safeJsonStringify(error);\n}\n\nfunction truncateErrorText(text: string, maxChars: number): string {\n\tif (text.length <= maxChars) return text;\n\treturn `${text.slice(0, maxChars)}... [truncated ${text.length - maxChars} chars]`;\n}\n\nfunction safeJsonStringify(value: unknown): string {\n\ttry {\n\t\tconst serialized = JSON.stringify(value);\n\t\treturn serialized === undefined ? String(value) : serialized;\n\t} catch {\n\t\treturn String(value);\n\t}\n}\n\nfunction buildRequestOptions(model: Model<\"mistral-conversations\">, options?: MistralOptions) {\n\tconst requestOptions: {\n\t\tsignal?: AbortSignal;\n\t\tretries: { strategy: \"none\" };\n\t\theaders?: Record<string, string>;\n\t} = {\n\t\tretries: { strategy: \"none\" },\n\t};\n\tif (options?.signal) requestOptions.signal = options.signal;\n\n\tconst headers: Record<string, string> = {};\n\tif (model.headers) Object.assign(headers, model.headers);\n\tif (options?.headers) Object.assign(headers, options.headers);\n\n\t// Mistral infrastructure uses `x-affinity` for KV-cache reuse (prefix caching).\n\t// Respect explicit caller-provided header values.\n\tif (shouldUsePromptCaching(options) && !headers[\"x-affinity\"]) {\n\t\theaders[\"x-affinity\"] = options.sessionId;\n\t}\n\n\tif (Object.keys(headers).length > 0) {\n\t\trequestOptions.headers = headers;\n\t}\n\n\treturn requestOptions;\n}\n\nfunction buildChatPayload(\n\tmodel: Model<\"mistral-conversations\">,\n\tcontext: Context,\n\tmessages: Message[],\n\toptions?: MistralOptions,\n): MistralChatCompletionStreamRequest {\n\tconst payload: MistralChatCompletionStreamRequest = {\n\t\tmodel: model.id,\n\t\tstream: true,\n\t\tmessages: toChatMessages(messages, model.input.includes(\"image\")),\n\t};\n\n\tif (context.tools?.length) payload.tools = toFunctionTools(context.tools);\n\tif (options?.temperature !== undefined) payload.temperature = options.temperature;\n\tif (options?.maxTokens !== undefined) payload.maxTokens = options.maxTokens;\n\tif (options?.toolChoice) payload.toolChoice = mapToolChoice(options.toolChoice);\n\tif (options?.promptMode) payload.promptMode = options.promptMode;\n\tif (options?.reasoningEffort) payload.reasoningEffort = options.reasoningEffort;\n\tif (shouldUsePromptCaching(options)) payload.promptCacheKey = options.sessionId;\n\n\tif (context.systemPrompt) {\n\t\tpayload.messages.unshift({\n\t\t\trole: \"system\",\n\t\t\tcontent: sanitizeSurrogates(context.systemPrompt),\n\t\t});\n\t}\n\n\tapplyExtraBody(payload, options?.extraBody, MISTRAL_RESERVED_BODY_KEYS);\n\n\treturn payload;\n}\n\nfunction shouldUsePromptCaching(options?: MistralOptions): options is MistralOptions & { sessionId: string } {\n\treturn options?.cacheRetention !== \"none\" && !!options?.sessionId;\n}\n\nfunction getMistralCachedPromptTokens(usage: unknown, promptTokens: number): number {\n\tconst rawUsage = usage as {\n\t\tpromptTokensDetails?: { cachedTokens?: unknown } | null;\n\t\tprompt_tokens_details?: { cached_tokens?: unknown } | null;\n\t\tpromptTokenDetails?: { cachedTokens?: unknown } | null;\n\t\tprompt_token_details?: { cached_tokens?: unknown } | null;\n\t\tnumCachedTokens?: unknown;\n\t\tnum_cached_tokens?: unknown;\n\t};\n\tconst rawCachedTokens =\n\t\trawUsage.promptTokensDetails?.cachedTokens ??\n\t\trawUsage.prompt_tokens_details?.cached_tokens ??\n\t\trawUsage.promptTokenDetails?.cachedTokens ??\n\t\trawUsage.prompt_token_details?.cached_tokens ??\n\t\trawUsage.numCachedTokens ??\n\t\trawUsage.num_cached_tokens ??\n\t\t0;\n\tconst cachedTokens = typeof rawCachedTokens === \"number\" && Number.isFinite(rawCachedTokens) ? rawCachedTokens : 0;\n\treturn Math.min(promptTokens, Math.max(0, cachedTokens));\n}\n\nasync function consumeChatStream(\n\tmodel: Model<\"mistral-conversations\">,\n\toutput: AssistantMessage,\n\tstream: AssistantMessageEventStream,\n\tmistralStream: AsyncIterable<CompletionEvent>,\n): Promise<void> {\n\tlet currentBlock: TextContent | ThinkingContent | null = null;\n\tconst blocks = output.content;\n\tconst blockIndex = () => blocks.length - 1;\n\tconst toolBlocksByKey = new Map<string, number>();\n\n\tconst finishCurrentBlock = (block?: typeof currentBlock) => {\n\t\tif (!block) return;\n\t\tif (block.type === \"text\") {\n\t\t\tstream.push({\n\t\t\t\ttype: \"text_end\",\n\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\tcontent: block.text,\n\t\t\t\tpartial: output,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tif (block.type === \"thinking\") {\n\t\t\tstream.push({\n\t\t\t\ttype: \"thinking_end\",\n\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\tcontent: block.thinking,\n\t\t\t\tpartial: output,\n\t\t\t});\n\t\t}\n\t};\n\n\tfor await (const event of mistralStream) {\n\t\tconst chunk = event.data;\n\t\t// Mistral's streamed CompletionChunk carries an id field. Keep the first non-empty one,\n\t\t// mirroring how OpenAI-style streaming exposes a stable response identifier per stream.\n\t\toutput.responseId ||= chunk.id;\n\n\t\tif (chunk.usage) {\n\t\t\tconst promptTokens = chunk.usage.promptTokens || 0;\n\t\t\tconst cachedPromptTokens = getMistralCachedPromptTokens(chunk.usage, promptTokens);\n\n\t\t\toutput.usage.input = Math.max(0, promptTokens - cachedPromptTokens);\n\t\t\toutput.usage.output = chunk.usage.completionTokens || 0;\n\t\t\toutput.usage.cacheRead = cachedPromptTokens;\n\t\t\toutput.usage.cacheWrite = 0;\n\t\t\toutput.usage.totalTokens =\n\t\t\t\tchunk.usage.totalTokens ||\n\t\t\t\toutput.usage.input + output.usage.output + output.usage.cacheRead + output.usage.cacheWrite;\n\t\t\tcalculateCost(model, output.usage);\n\t\t}\n\n\t\tconst choice = chunk.choices[0];\n\t\tif (!choice) continue;\n\n\t\tif (choice.finishReason) {\n\t\t\toutput.rawStopReason = choice.finishReason;\n\t\t\tconst stopReasonResult = mapChatStopReason(choice.finishReason);\n\t\t\toutput.stopReason = stopReasonResult.stopReason;\n\t\t\tif (stopReasonResult.errorMessage) {\n\t\t\t\toutput.errorMessage = stopReasonResult.errorMessage;\n\t\t\t}\n\t\t}\n\n\t\tconst delta = choice.delta;\n\t\tif (delta.content !== null && delta.content !== undefined) {\n\t\t\tconst contentItems = typeof delta.content === \"string\" ? [delta.content] : delta.content;\n\t\t\tfor (const item of contentItems) {\n\t\t\t\tif (typeof item === \"string\") {\n\t\t\t\t\tconst textDelta = sanitizeSurrogates(item);\n\t\t\t\t\tif (currentBlock?.type !== \"text\") {\n\t\t\t\t\t\tfinishCurrentBlock(currentBlock);\n\t\t\t\t\t\tcurrentBlock = { type: \"text\", text: \"\" };\n\t\t\t\t\t\toutput.content.push(currentBlock);\n\t\t\t\t\t\tstream.push({ type: \"text_start\", contentIndex: blockIndex(), partial: output });\n\t\t\t\t\t}\n\t\t\t\t\tcurrentBlock.text += textDelta;\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"text_delta\",\n\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\tdelta: textDelta,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (item.type === \"thinking\") {\n\t\t\t\t\tconst deltaText = item.thinking\n\t\t\t\t\t\t.map((part) => (\"text\" in part ? part.text : \"\"))\n\t\t\t\t\t\t.filter((text) => text.length > 0)\n\t\t\t\t\t\t.join(\"\");\n\t\t\t\t\tconst thinkingDelta = sanitizeSurrogates(deltaText);\n\t\t\t\t\tif (!thinkingDelta) continue;\n\t\t\t\t\tif (currentBlock?.type !== \"thinking\") {\n\t\t\t\t\t\tfinishCurrentBlock(currentBlock);\n\t\t\t\t\t\tcurrentBlock = { type: \"thinking\", thinking: \"\" };\n\t\t\t\t\t\toutput.content.push(currentBlock);\n\t\t\t\t\t\tstream.push({ type: \"thinking_start\", contentIndex: blockIndex(), partial: output });\n\t\t\t\t\t}\n\t\t\t\t\tcurrentBlock.thinking += thinkingDelta;\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"thinking_delta\",\n\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\tdelta: thinkingDelta,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (item.type === \"text\") {\n\t\t\t\t\tconst textDelta = sanitizeSurrogates(item.text);\n\t\t\t\t\tif (currentBlock?.type !== \"text\") {\n\t\t\t\t\t\tfinishCurrentBlock(currentBlock);\n\t\t\t\t\t\tcurrentBlock = { type: \"text\", text: \"\" };\n\t\t\t\t\t\toutput.content.push(currentBlock);\n\t\t\t\t\t\tstream.push({ type: \"text_start\", contentIndex: blockIndex(), partial: output });\n\t\t\t\t\t}\n\t\t\t\t\tcurrentBlock.text += textDelta;\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"text_delta\",\n\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\tdelta: textDelta,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst toolCalls = delta.toolCalls || [];\n\t\tfor (const toolCall of toolCalls) {\n\t\t\tif (currentBlock) {\n\t\t\t\tfinishCurrentBlock(currentBlock);\n\t\t\t\tcurrentBlock = null;\n\t\t\t}\n\t\t\tconst callId =\n\t\t\t\ttoolCall.id && toolCall.id !== \"null\"\n\t\t\t\t\t? toolCall.id\n\t\t\t\t\t: deriveMistralToolCallId(`toolcall:${toolCall.index ?? 0}`, 0);\n\t\t\tconst key = `${callId}:${toolCall.index || 0}`;\n\t\t\tconst existingIndex = toolBlocksByKey.get(key);\n\t\t\tlet block: (ToolCall & { partialArgs?: string }) | undefined;\n\n\t\t\tif (existingIndex !== undefined) {\n\t\t\t\tconst existing = output.content[existingIndex];\n\t\t\t\tif (existing?.type === \"toolCall\") {\n\t\t\t\t\tblock = existing as ToolCall & { partialArgs?: string };\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!block) {\n\t\t\t\tblock = {\n\t\t\t\t\ttype: \"toolCall\",\n\t\t\t\t\tid: callId,\n\t\t\t\t\tname: toolCall.function.name,\n\t\t\t\t\targuments: {},\n\t\t\t\t\tpartialArgs: \"\",\n\t\t\t\t};\n\t\t\t\toutput.content.push(block);\n\t\t\t\ttoolBlocksByKey.set(key, output.content.length - 1);\n\t\t\t\tstream.push({ type: \"toolcall_start\", contentIndex: output.content.length - 1, partial: output });\n\t\t\t}\n\n\t\t\tconst argsDelta =\n\t\t\t\ttypeof toolCall.function.arguments === \"string\"\n\t\t\t\t\t? toolCall.function.arguments\n\t\t\t\t\t: JSON.stringify(toolCall.function.arguments || {});\n\t\t\tblock.partialArgs = (block.partialArgs || \"\") + argsDelta;\n\t\t\tblock.arguments = parseStreamingJson<Record<string, unknown>>(block.partialArgs);\n\t\t\tstream.push({\n\t\t\t\ttype: \"toolcall_delta\",\n\t\t\t\tcontentIndex: toolBlocksByKey.get(key)!,\n\t\t\t\tdelta: argsDelta,\n\t\t\t\tpartial: output,\n\t\t\t});\n\t\t}\n\t}\n\n\tfinishCurrentBlock(currentBlock);\n\tfor (const index of toolBlocksByKey.values()) {\n\t\tconst block = output.content[index];\n\t\tif (block.type !== \"toolCall\") continue;\n\t\tconst toolBlock = block as ToolCall & { partialArgs?: string };\n\t\ttoolBlock.arguments = parseStreamingJson<Record<string, unknown>>(toolBlock.partialArgs);\n\t\t// Finalize in-place and strip the scratch buffer so replay only\n\t\t// carries parsed arguments.\n\t\tdelete toolBlock.partialArgs;\n\t\tstream.push({\n\t\t\ttype: \"toolcall_end\",\n\t\t\tcontentIndex: index,\n\t\t\ttoolCall: toolBlock,\n\t\t\tpartial: output,\n\t\t});\n\t}\n}\n\nfunction toFunctionTools(tools: Tool[]): Array<FunctionTool & { type: \"function\" }> {\n\treturn tools.map((tool) => {\n\t\tconst strict = resolveJsonSchemaStrictSampling(tool, true);\n\t\treturn {\n\t\t\ttype: \"function\",\n\t\t\tfunction: {\n\t\t\t\tname: tool.name,\n\t\t\t\tdescription: tool.description,\n\t\t\t\tparameters: stripSymbolKeys(tool.parameters) as Record<string, unknown>,\n\t\t\t\tstrict: strict ?? false,\n\t\t\t},\n\t\t};\n\t});\n}\n\nfunction stripSymbolKeys(value: unknown): unknown {\n\tif (Array.isArray(value)) {\n\t\treturn value.map((item) => stripSymbolKeys(item));\n\t}\n\n\tif (value && typeof value === \"object\") {\n\t\tconst result: Record<string, unknown> = {};\n\t\tfor (const [key, entry] of Object.entries(value)) {\n\t\t\tresult[key] = stripSymbolKeys(entry);\n\t\t}\n\t\treturn result;\n\t}\n\n\treturn value;\n}\n\nfunction toChatMessages(messages: Message[], supportsImages: boolean): ChatCompletionStreamRequestMessage[] {\n\tconst result: ChatCompletionStreamRequestMessage[] = [];\n\n\tfor (const msg of messages) {\n\t\tif (msg.role === \"user\") {\n\t\t\tif (typeof msg.content === \"string\") {\n\t\t\t\tresult.push({ role: \"user\", content: sanitizeSurrogates(msg.content) });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst hadImages = msg.content.some((item) => item.type === \"image\");\n\t\t\tconst content: ContentChunk[] = msg.content\n\t\t\t\t.filter((item) => item.type === \"text\" || supportsImages)\n\t\t\t\t.map((item) => {\n\t\t\t\t\tif (item.type === \"text\") return { type: \"text\", text: sanitizeSurrogates(item.text) };\n\t\t\t\t\treturn { type: \"image_url\", imageUrl: `data:${item.mimeType};base64,${item.data}` };\n\t\t\t\t});\n\t\t\tif (content.length > 0) {\n\t\t\t\tresult.push({ role: \"user\", content });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (hadImages && !supportsImages) {\n\t\t\t\tresult.push({ role: \"user\", content: \"(image omitted: model does not support images)\" });\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (msg.role === \"assistant\") {\n\t\t\tconst contentParts: ContentChunk[] = [];\n\t\t\tconst toolCalls: Array<{ id: string; type: \"function\"; function: { name: string; arguments: string } }> = [];\n\n\t\t\tfor (const block of msg.content) {\n\t\t\t\tif (block.type === \"text\") {\n\t\t\t\t\tif (block.text.trim().length > 0) {\n\t\t\t\t\t\tcontentParts.push({ type: \"text\", text: sanitizeSurrogates(block.text) });\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (block.type === \"thinking\") {\n\t\t\t\t\tif (block.thinking.trim().length > 0) {\n\t\t\t\t\t\tcontentParts.push({\n\t\t\t\t\t\t\ttype: \"thinking\",\n\t\t\t\t\t\t\tthinking: [{ type: \"text\", text: sanitizeSurrogates(block.thinking) }],\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (block.type !== \"toolCall\") {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\ttoolCalls.push({\n\t\t\t\t\tid: block.id,\n\t\t\t\t\ttype: \"function\",\n\t\t\t\t\tfunction: { name: block.name, arguments: JSON.stringify(block.arguments || {}) },\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst assistantMessage: ChatCompletionStreamRequestMessage = { role: \"assistant\" };\n\t\t\tif (contentParts.length > 0) assistantMessage.content = contentParts;\n\t\t\tif (toolCalls.length > 0) assistantMessage.toolCalls = toolCalls;\n\t\t\tif (contentParts.length > 0 || toolCalls.length > 0) result.push(assistantMessage);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst toolContent: ContentChunk[] = [];\n\t\tconst textResult = msg.content\n\t\t\t.filter((part) => part.type === \"text\")\n\t\t\t.map((part) => (part.type === \"text\" ? sanitizeSurrogates(part.text) : \"\"))\n\t\t\t.join(\"\\n\");\n\t\tconst hasImages = msg.content.some((part) => part.type === \"image\");\n\t\tconst toolText = buildToolResultText(textResult, hasImages, supportsImages, msg.isError);\n\t\ttoolContent.push({ type: \"text\", text: toolText });\n\t\tfor (const part of msg.content) {\n\t\t\tif (!supportsImages) continue;\n\t\t\tif (part.type !== \"image\") continue;\n\t\t\ttoolContent.push({\n\t\t\t\ttype: \"image_url\",\n\t\t\t\timageUrl: `data:${part.mimeType};base64,${part.data}`,\n\t\t\t});\n\t\t}\n\t\tresult.push({\n\t\t\trole: \"tool\",\n\t\t\ttoolCallId: msg.toolCallId,\n\t\t\tname: msg.toolName,\n\t\t\tcontent: toolContent,\n\t\t});\n\t}\n\n\treturn result;\n}\n\nfunction buildToolResultText(text: string, hasImages: boolean, supportsImages: boolean, isError: boolean): string {\n\tconst trimmed = text.trim();\n\tconst errorPrefix = isError ? \"[tool error] \" : \"\";\n\n\tif (trimmed.length > 0) {\n\t\tconst imageSuffix = hasImages && !supportsImages ? \"\\n[tool image omitted: model does not support images]\" : \"\";\n\t\treturn `${errorPrefix}${trimmed}${imageSuffix}`;\n\t}\n\n\tif (hasImages) {\n\t\tif (supportsImages) {\n\t\t\treturn isError ? \"[tool error] (see attached image)\" : \"(see attached image)\";\n\t\t}\n\t\treturn isError\n\t\t\t? \"[tool error] (image omitted: model does not support images)\"\n\t\t\t: \"(image omitted: model does not support images)\";\n\t}\n\n\treturn isError ? \"[tool error] (no tool output)\" : \"(no tool output)\";\n}\n\nfunction usesReasoningEffort(model: Model<\"mistral-conversations\">): boolean {\n\treturn model.id === \"mistral-small-2603\" || model.id === \"mistral-small-latest\" || model.id === \"mistral-medium-3.5\";\n}\n\nfunction usesPromptModeReasoning(model: Model<\"mistral-conversations\">): boolean {\n\treturn model.reasoning && !usesReasoningEffort(model);\n}\n\nfunction mapReasoningEffort(\n\tmodel: Model<\"mistral-conversations\">,\n\tlevel: Exclude<SimpleStreamOptions[\"reasoning\"], undefined>,\n): MistralReasoningEffort {\n\treturn (model.thinkingLevelMap?.[level] ?? \"high\") as MistralReasoningEffort;\n}\n\nfunction mapToolChoice(\n\tchoice: MistralOptions[\"toolChoice\"],\n): \"auto\" | \"none\" | \"any\" | \"required\" | { type: \"function\"; function: { name: string } } | undefined {\n\tif (!choice) return undefined;\n\tif (choice === \"auto\" || choice === \"none\" || choice === \"any\" || choice === \"required\") {\n\t\treturn choice;\n\t}\n\treturn {\n\t\ttype: \"function\",\n\t\tfunction: { name: choice.function.name },\n\t};\n}\n\nfunction mapChatStopReason(reason: string | null): { stopReason: StopReason; errorMessage?: string } {\n\tif (reason === null) return { stopReason: \"stop\" };\n\tswitch (reason) {\n\t\tcase \"stop\":\n\t\t\treturn { stopReason: \"stop\" };\n\t\tcase \"length\":\n\t\tcase \"model_length\":\n\t\t\treturn { stopReason: \"length\" };\n\t\tcase \"tool_calls\":\n\t\t\treturn { stopReason: \"toolUse\" };\n\t\tcase \"error\":\n\t\t\treturn { stopReason: \"error\", errorMessage: \"Provider stopped with: error\" };\n\t\tdefault:\n\t\t\treturn { stopReason: \"error\", errorMessage: `Provider stopped with: ${reason}` };\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"mistral-conversations.js","sourceRoot":"","sources":["../../src/api/mistral-conversations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAejE,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,2BAA2B,EAAE,+BAA+B,EAAE,MAAM,2BAA2B,CAAC;AACzG,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AACnG,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,MAAM,2BAA2B,GAAG,CAAC,CAAC;AACtC,MAAM,4BAA4B,GAAG,IAAI,CAAC;AA4F1C;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAA4D,CAC9E,KAAqC,EACrC,OAAgB,EAChB,OAAwB,EACM,EAAE;IAChC,MAAM,MAAM,GAAG,IAAI,2BAA2B,EAAE,CAAC;IAEjD,CAAC,KAAK,IAAI,EAAE;QACX,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,C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AE,UAAU,EAAE,QAAQ,EAAE,CAAC;QACjC,KAAK,YAAY;YAChB,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;QAClC,KAAK,OAAO;YACX,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAAE,8BAA8B,EAAE,CAAC;QAC9E;YACC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAAE,0BAA0B,MAAM,EAAE,EAAE,CAAC;IACnF,CAAC;AACF,CAAC","sourcesContent":["import { calculateCost, clampThinkingLevel } from \"../models.ts\";\nimport type {\n\tAssistantMessage,\n\tContext,\n\tMessage,\n\tModel,\n\tSimpleStreamOptions,\n\tStopReason,\n\tStreamFunction,\n\tStreamOptions,\n\tTextContent,\n\tThinkingContent,\n\tTool,\n\tToolCall,\n} from \"../types.ts\";\nimport { AssistantMessageEventStream } from \"../utils/event-stream.ts\";\nimport { shortHash } from \"../utils/hash.ts\";\nimport { headersToRecord } from \"../utils/headers.ts\";\nimport { parseStreamingJson } from \"../utils/json-parse.ts\";\nimport { sanitizeSurrogates } from \"../utils/sanitize-unicode.ts\";\nimport { getJsonSchemaToolParameters, resolveJsonSchemaStrictSampling } from \"./constrained-sampling.ts\";\nimport { applyExtraBody, buildBaseOptions, MISTRAL_RESERVED_BODY_KEYS } from \"./simple-options.ts\";\nimport { transformMessages } from \"./transform-messages.ts\";\n\nconst MISTRAL_TOOL_CALL_ID_LENGTH = 9;\nconst MAX_MISTRAL_ERROR_BODY_CHARS = 4000;\n\n/**\n * Provider-specific options for the Mistral API.\n */\ntype MistralReasoningEffort = \"none\" | \"high\";\n\nexport interface MistralOptions extends StreamOptions {\n\ttoolChoice?: \"auto\" | \"none\" | \"any\" | \"required\" | { type: \"function\"; function: { name: string } };\n\tpromptMode?: \"reasoning\";\n\treasoningEffort?: MistralReasoningEffort;\n}\n\ntype MistralContentChunk =\n\t| { type: \"text\"; text: string }\n\t| { type: \"image_url\"; imageUrl: string }\n\t| { type: \"thinking\"; thinking: Array<{ type: \"text\"; text: string }> };\n\ntype MistralRequestToolCall = {\n\tid: string;\n\ttype: \"function\";\n\tfunction: { name: string; arguments: string };\n\tindex: number;\n};\n\ntype MistralChatMessage = {\n\trole: \"system\" | \"user\" | \"assistant\" | \"tool\";\n\tcontent?: string | MistralContentChunk[];\n\ttoolCalls?: MistralRequestToolCall[];\n\ttoolCallId?: string;\n\tname?: string;\n\tprefix?: boolean;\n};\n\ntype MistralFunctionTool = {\n\ttype: \"function\";\n\tfunction: {\n\t\tname: string;\n\t\tdescription: string;\n\t\tparameters: Record<string, unknown>;\n\t\tstrict: boolean;\n\t};\n};\n\ntype MistralChatPayload = {\n\t[key: string]: unknown;\n\tmodel: string;\n\tstream: boolean;\n\tmessages: MistralChatMessage[];\n\ttools?: MistralFunctionTool[];\n\ttemperature?: number;\n\tmaxTokens?: number;\n\ttoolChoice?: Exclude<MistralOptions[\"toolChoice\"], undefined>;\n\tpromptMode?: \"reasoning\";\n\treasoningEffort?: MistralReasoningEffort;\n\tpromptCacheKey?: string;\n};\n\ntype MistralStreamContentChunk = {\n\ttype: string;\n\ttext?: string;\n\tthinking?: Array<{ text?: string }>;\n};\n\ntype MistralStreamToolCall = {\n\tid?: string;\n\tindex?: number;\n\tfunction: {\n\t\tname: string;\n\t\targuments: string | Record<string, unknown>;\n\t};\n};\n\ntype MistralCompletionEvent = {\n\tdata: {\n\t\tid?: string;\n\t\tusage?: {\n\t\t\t[key: string]: unknown;\n\t\t\tprompt_tokens?: number;\n\t\t\tcompletion_tokens?: number;\n\t\t\ttotal_tokens?: number;\n\t\t};\n\t\tchoices: Array<{\n\t\t\tfinish_reason?: string | null;\n\t\t\tdelta: {\n\t\t\t\tcontent?: string | MistralStreamContentChunk[] | null;\n\t\t\t\ttool_calls?: MistralStreamToolCall[] | null;\n\t\t\t};\n\t\t}>;\n\t};\n};\n\n/**\n * Stream responses from the native Mistral Chat Completions endpoint.\n */\nexport const stream: StreamFunction<\"mistral-conversations\", MistralOptions> = (\n\tmodel: Model<\"mistral-conversations\">,\n\tcontext: Context,\n\toptions?: MistralOptions,\n): AssistantMessageEventStream => {\n\tconst stream = new AssistantMessageEventStream();\n\n\t(async () => {\n\t\tconst output = createOutput(model);\n\n\t\ttry {\n\t\t\tconst apiKey = options?.apiKey;\n\t\t\tif (!apiKey) {\n\t\t\t\tthrow new Error(`No API key for provider: ${model.provider}`);\n\t\t\t}\n\n\t\t\tconst normalizeMistralToolCallId = createMistralToolCallIdNormalizer();\n\t\t\tconst preserveThinking = options?.promptMode === \"reasoning\" || options?.reasoningEffort !== undefined;\n\t\t\tconst transformedMessages = transformMessages(\n\t\t\t\tcontext.messages,\n\t\t\t\tmodel,\n\t\t\t\t(id) => normalizeMistralToolCallId(id),\n\t\t\t\t{\n\t\t\t\t\tpreserveThinking,\n\t\t\t\t},\n\t\t\t);\n\n\t\t\tlet payload = buildChatPayload(model, context, transformedMessages, options);\n\t\t\tconst nextPayload = await options?.onPayload?.(payload, model);\n\t\t\tif (nextPayload !== undefined) {\n\t\t\t\tpayload = nextPayload as MistralChatPayload;\n\t\t\t}\n\t\t\tconst mistralStream = await requestMistralStream(model, payload, apiKey, options);\n\t\t\tstream.push({ type: \"start\", partial: output });\n\t\t\tawait consumeChatStream(model, output, stream, mistralStream);\n\n\t\t\tif (options?.signal?.aborted) {\n\t\t\t\tthrow new Error(\"Request was aborted\");\n\t\t\t}\n\n\t\t\tif (output.stopReason === \"pending\") {\n\t\t\t\tthrow new Error(\"Mistral stream ended without a finish reason\");\n\t\t\t}\n\t\t\tif (output.stopReason === \"aborted\" || output.stopReason === \"error\") {\n\t\t\t\tthrow new Error(output.errorMessage || \"An unknown error occurred\");\n\t\t\t}\n\n\t\t\tstream.push({ type: \"done\", reason: output.stopReason, message: output });\n\t\t\tstream.end();\n\t\t} catch (error) {\n\t\t\tfor (const block of output.content) {\n\t\t\t\t// partialArgs is only a streaming scratch buffer; never persist it.\n\t\t\t\tdelete (block as { partialArgs?: string }).partialArgs;\n\t\t\t}\n\t\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\t\toutput.errorMessage = formatMistralError(error);\n\t\t\tstream.push({ type: \"error\", reason: output.stopReason, error: output });\n\t\t\tstream.end();\n\t\t}\n\t})();\n\n\treturn stream;\n};\n\n/**\n * Maps provider-agnostic `SimpleStreamOptions` to Mistral options.\n */\nexport const streamSimple: StreamFunction<\"mistral-conversations\", SimpleStreamOptions> = (\n\tmodel: Model<\"mistral-conversations\">,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream => {\n\tconst apiKey = options?.apiKey;\n\tif (!apiKey) {\n\t\tthrow new Error(`No API key for provider: ${model.provider}`);\n\t}\n\n\tconst base = buildBaseOptions(model, context, options, apiKey);\n\tconst clampedReasoning = options?.reasoning ? clampThinkingLevel(model, options.reasoning) : undefined;\n\tconst reasoning = clampedReasoning === \"off\" ? undefined : clampedReasoning;\n\tconst shouldUseReasoning = model.reasoning && reasoning !== undefined;\n\n\treturn stream(model, context, {\n\t\t...base,\n\t\tpromptMode: shouldUseReasoning && usesPromptModeReasoning(model) ? \"reasoning\" : undefined,\n\t\treasoningEffort:\n\t\t\tshouldUseReasoning && usesReasoningEffort(model) ? mapReasoningEffort(model, reasoning) : undefined,\n\t} satisfies MistralOptions);\n};\n\nfunction createOutput(model: Model<\"mistral-conversations\">): AssistantMessage {\n\treturn {\n\t\trole: \"assistant\",\n\t\tcontent: [],\n\t\tapi: model.api,\n\t\tprovider: model.provider,\n\t\tmodel: model.id,\n\t\tusage: {\n\t\t\tinput: 0,\n\t\t\toutput: 0,\n\t\t\tcacheRead: 0,\n\t\t\tcacheWrite: 0,\n\t\t\ttotalTokens: 0,\n\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t},\n\t\tstopReason: \"pending\",\n\t\ttimestamp: Date.now(),\n\t};\n}\n\nfunction createMistralToolCallIdNormalizer(): (id: string) => string {\n\tconst idMap = new Map<string, string>();\n\tconst reverseMap = new Map<string, string>();\n\n\treturn (id: string): string => {\n\t\tconst existing = idMap.get(id);\n\t\tif (existing) return existing;\n\n\t\tlet attempt = 0;\n\t\twhile (true) {\n\t\t\tconst candidate = deriveMistralToolCallId(id, attempt);\n\t\t\tconst owner = reverseMap.get(candidate);\n\t\t\tif (!owner || owner === id) {\n\t\t\t\tidMap.set(id, candidate);\n\t\t\t\treverseMap.set(candidate, id);\n\t\t\t\treturn candidate;\n\t\t\t}\n\t\t\tattempt++;\n\t\t}\n\t};\n}\n\nfunction deriveMistralToolCallId(id: string, attempt: number): string {\n\tconst normalized = id.replace(/[^a-zA-Z0-9]/g, \"\");\n\tif (attempt === 0 && normalized.length === MISTRAL_TOOL_CALL_ID_LENGTH) return normalized;\n\tconst seedBase = normalized || id;\n\tconst seed = attempt === 0 ? seedBase : `${seedBase}:${attempt}`;\n\treturn shortHash(seed)\n\t\t.replace(/[^a-zA-Z0-9]/g, \"\")\n\t\t.slice(0, MISTRAL_TOOL_CALL_ID_LENGTH);\n}\n\nfunction formatMistralError(error: unknown): string {\n\tif (error instanceof Error) {\n\t\tconst httpError = error as Error & { statusCode?: unknown; body?: unknown };\n\t\tconst statusCode = typeof httpError.statusCode === \"number\" ? httpError.statusCode : undefined;\n\t\tconst bodyText = typeof httpError.body === \"string\" ? httpError.body.trim() : undefined;\n\t\tif (statusCode !== undefined && bodyText) {\n\t\t\treturn `Mistral API error (${statusCode}): ${truncateErrorText(bodyText, MAX_MISTRAL_ERROR_BODY_CHARS)}`;\n\t\t}\n\t\tif (statusCode !== undefined) return `Mistral API error (${statusCode}): ${error.message}`;\n\t\treturn error.message;\n\t}\n\treturn safeJsonStringify(error);\n}\n\nfunction truncateErrorText(text: string, maxChars: number): string {\n\tif (text.length <= maxChars) return text;\n\treturn `${text.slice(0, maxChars)}... [truncated ${text.length - maxChars} chars]`;\n}\n\nfunction safeJsonStringify(value: unknown): string {\n\ttry {\n\t\tconst serialized = JSON.stringify(value);\n\t\treturn serialized === undefined ? String(value) : serialized;\n\t} catch {\n\t\treturn String(value);\n\t}\n}\n\nasync function requestMistralStream(\n\tmodel: Model<\"mistral-conversations\">,\n\tpayload: MistralChatPayload,\n\tapiKey: string,\n\toptions?: MistralOptions,\n): Promise<AsyncIterable<MistralCompletionEvent>> {\n\tconst baseUrl = new URL(model.baseUrl);\n\tbaseUrl.pathname = `${baseUrl.pathname.replace(/\\/+$/u, \"\")}/`;\n\tconst url = new URL(\"v1/chat/completions\", baseUrl);\n\tconst headers = buildMistralHeaders(model, apiKey, options);\n\tconst timeoutSignal = AbortSignal.timeout(options?.timeoutMs ?? 60_000);\n\tconst signal = options?.signal ? AbortSignal.any([options.signal, timeoutSignal]) : timeoutSignal;\n\tconst response = await (options?.fetch ?? globalThis.fetch)(url, {\n\t\tmethod: \"POST\",\n\t\theaders,\n\t\tbody: JSON.stringify(toMistralWirePayload(payload)),\n\t\tsignal,\n\t});\n\n\tawait options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model);\n\n\tif (!response.ok) {\n\t\tconst body = await response.text();\n\t\tthrow new MistralHttpError(response.status, body, response.statusText);\n\t}\n\tif (!response.body) {\n\t\tthrow new Error(\"Mistral response has no body\");\n\t}\n\n\treturn readMistralEvents(response.body, signal);\n}\n\nclass MistralHttpError extends Error {\n\tstatusCode: number;\n\tbody: string;\n\n\tconstructor(statusCode: number, body: string, statusText: string) {\n\t\tsuper(statusText || `Request failed with status ${statusCode}`);\n\t\tthis.name = \"MistralHttpError\";\n\t\tthis.statusCode = statusCode;\n\t\tthis.body = body;\n\t}\n}\n\nfunction buildMistralHeaders(model: Model<\"mistral-conversations\">, apiKey: string, options?: MistralOptions): Headers {\n\tconst headers = new Headers({\n\t\taccept: \"text/event-stream\",\n\t\tauthorization: `Bearer ${apiKey}`,\n\t\t\"content-type\": \"application/json\",\n\t});\n\tapplyMistralHeaderOverrides(headers, model.headers);\n\tapplyMistralHeaderOverrides(headers, options?.headers);\n\n\tconst hasExplicitAffinity =\n\t\thasMistralHeaderOverride(model.headers, \"x-affinity\") || hasMistralHeaderOverride(options?.headers, \"x-affinity\");\n\tif (shouldUsePromptCaching(options) && !hasExplicitAffinity) {\n\t\theaders.set(\"x-affinity\", options.sessionId);\n\t}\n\n\treturn headers;\n}\n\nfunction applyMistralHeaderOverrides(headers: Headers, overrides?: Record<string, string | null>): void {\n\tif (!overrides) return;\n\tfor (const [name, value] of Object.entries(overrides)) {\n\t\tif (value === null) headers.delete(name);\n\t\telse headers.set(name, value);\n\t}\n}\n\nfunction hasMistralHeaderOverride(overrides: Record<string, string | null> | undefined, target: string): boolean {\n\treturn !!overrides && Object.keys(overrides).some((name) => name.toLowerCase() === target);\n}\n\nfunction toMistralWirePayload(payload: MistralChatPayload): Record<string, unknown> {\n\tconst wirePayload: Record<string, unknown> = { ...payload };\n\tfor (const [source, target] of [\n\t\t[\"topP\", \"top_p\"],\n\t\t[\"maxTokens\", \"max_tokens\"],\n\t\t[\"randomSeed\", \"random_seed\"],\n\t\t[\"responseFormat\", \"response_format\"],\n\t\t[\"toolChoice\", \"tool_choice\"],\n\t\t[\"presencePenalty\", \"presence_penalty\"],\n\t\t[\"frequencyPenalty\", \"frequency_penalty\"],\n\t\t[\"parallelToolCalls\", \"parallel_tool_calls\"],\n\t\t[\"reasoningEffort\", \"reasoning_effort\"],\n\t\t[\"promptMode\", \"prompt_mode\"],\n\t\t[\"promptCacheKey\", \"prompt_cache_key\"],\n\t\t[\"safePrompt\", \"safe_prompt\"],\n\t] as const) {\n\t\tremapMistralProperty(wirePayload, source, target);\n\t}\n\twirePayload.messages = payload.messages.map((message) => toMistralWireMessage(message));\n\n\tconst responseFormat = wirePayload.response_format;\n\tif (isMistralRecord(responseFormat)) {\n\t\tconst wireResponseFormat = { ...responseFormat };\n\t\tremapMistralProperty(wireResponseFormat, \"jsonSchema\", \"json_schema\");\n\t\tconst jsonSchema = wireResponseFormat.json_schema;\n\t\tif (isMistralRecord(jsonSchema)) {\n\t\t\tconst wireJsonSchema = { ...jsonSchema };\n\t\t\tremapMistralProperty(wireJsonSchema, \"schemaDefinition\", \"schema\");\n\t\t\twireResponseFormat.json_schema = wireJsonSchema;\n\t\t}\n\t\twirePayload.response_format = wireResponseFormat;\n\t}\n\n\treturn wirePayload;\n}\n\nfunction toMistralWireMessage(message: MistralChatMessage): Record<string, unknown> {\n\tconst wireMessage: Record<string, unknown> = { ...message };\n\tremapMistralProperty(wireMessage, \"toolCalls\", \"tool_calls\");\n\tremapMistralProperty(wireMessage, \"toolCallId\", \"tool_call_id\");\n\tif (Array.isArray(message.content)) {\n\t\twireMessage.content = message.content.map((chunk) => toMistralWireContentChunk(chunk));\n\t}\n\treturn wireMessage;\n}\n\nfunction toMistralWireContentChunk(chunk: MistralContentChunk): Record<string, unknown> {\n\tconst wireChunk: Record<string, unknown> = { ...chunk };\n\tfor (const [source, target] of [\n\t\t[\"imageUrl\", \"image_url\"],\n\t\t[\"documentUrl\", \"document_url\"],\n\t\t[\"documentName\", \"document_name\"],\n\t\t[\"fileId\", \"file_id\"],\n\t\t[\"referenceIds\", \"reference_ids\"],\n\t\t[\"inputAudio\", \"input_audio\"],\n\t] as const) {\n\t\tremapMistralProperty(wireChunk, source, target);\n\t}\n\treturn wireChunk;\n}\n\nfunction remapMistralProperty(record: Record<string, unknown>, source: string, target: string): void {\n\tif (!(source in record)) return;\n\trecord[target] = record[source];\n\tdelete record[source];\n}\n\nfunction isMistralRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nconst MISTRAL_STREAM_DONE = Symbol(\"mistral-stream-done\");\n\nasync function* readMistralEvents(\n\tbody: ReadableStream<Uint8Array>,\n\tsignal: AbortSignal,\n): AsyncGenerator<MistralCompletionEvent> {\n\tconst reader = body.getReader();\n\tconst decoder = new TextDecoder();\n\tlet buffer = \"\";\n\tconst onAbort = () => {\n\t\tvoid reader.cancel().catch(() => {});\n\t};\n\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\n\ttry {\n\t\twhile (true) {\n\t\t\tif (signal.aborted) throw signal.reason;\n\t\t\tconst { done, value } = await reader.read();\n\t\t\tif (signal.aborted) throw signal.reason;\n\t\t\tbuffer += done ? decoder.decode() : decoder.decode(value, { stream: true });\n\n\t\t\tlet boundary = findMistralEventBoundary(buffer);\n\t\t\twhile (boundary) {\n\t\t\t\tconst event = parseMistralEvent(buffer.slice(0, boundary.index));\n\t\t\t\tbuffer = buffer.slice(boundary.index + boundary.length);\n\t\t\t\tif (event === MISTRAL_STREAM_DONE) return;\n\t\t\t\tif (event) yield event;\n\t\t\t\tboundary = findMistralEventBoundary(buffer);\n\t\t\t}\n\n\t\t\tif (done) break;\n\t\t}\n\n\t\tif (buffer.trim()) {\n\t\t\tconst event = parseMistralEvent(buffer);\n\t\t\tif (event !== MISTRAL_STREAM_DONE && event) yield event;\n\t\t}\n\t} finally {\n\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t\ttry {\n\t\t\tawait reader.cancel();\n\t\t} catch {}\n\t\ttry {\n\t\t\treader.releaseLock();\n\t\t} catch {}\n\t}\n}\n\nfunction findMistralEventBoundary(buffer: string): { index: number; length: number } | undefined {\n\tconst match = /\\r\\n\\r\\n|\\r\\n\\r|\\r\\n\\n|\\r\\r\\n|\\n\\r\\n|\\r\\r|\\n\\r|\\n\\n/u.exec(buffer);\n\treturn match?.index === undefined ? undefined : { index: match.index, length: match[0].length };\n}\n\nfunction parseMistralEvent(raw: string): MistralCompletionEvent | typeof MISTRAL_STREAM_DONE | undefined {\n\tconst data = raw\n\t\t.split(/\\r\\n|\\r|\\n/u)\n\t\t.filter((line) => line.startsWith(\"data:\"))\n\t\t.map((line) => line.slice(5).trimStart())\n\t\t.join(\"\\n\")\n\t\t.trim();\n\tif (!data) return undefined;\n\tif (data === \"[DONE]\") return MISTRAL_STREAM_DONE;\n\n\tconst parsed: unknown = JSON.parse(data);\n\tif (!isMistralRecord(parsed) || !Array.isArray(parsed.choices)) {\n\t\tthrow new Error(\"Invalid Mistral streaming event\");\n\t}\n\treturn { data: parsed as MistralCompletionEvent[\"data\"] };\n}\n\nfunction buildChatPayload(\n\tmodel: Model<\"mistral-conversations\">,\n\tcontext: Context,\n\tmessages: Message[],\n\toptions?: MistralOptions,\n): MistralChatPayload {\n\tconst payload: MistralChatPayload = {\n\t\tmodel: model.id,\n\t\tstream: true,\n\t\tmessages: toChatMessages(messages, model.input.includes(\"image\")),\n\t};\n\n\tif (context.tools?.length) payload.tools = toFunctionTools(context.tools);\n\tif (options?.temperature !== undefined) payload.temperature = options.temperature;\n\tif (options?.maxTokens !== undefined) payload.maxTokens = options.maxTokens;\n\tif (options?.toolChoice) payload.toolChoice = mapToolChoice(options.toolChoice);\n\tif (options?.promptMode) payload.promptMode = options.promptMode;\n\tif (options?.reasoningEffort) payload.reasoningEffort = options.reasoningEffort;\n\tif (shouldUsePromptCaching(options)) payload.promptCacheKey = options.sessionId;\n\n\tif (context.systemPrompt) {\n\t\tpayload.messages.unshift({\n\t\t\trole: \"system\",\n\t\t\tcontent: sanitizeSurrogates(context.systemPrompt),\n\t\t});\n\t}\n\n\tapplyExtraBody(payload, options?.extraBody, MISTRAL_RESERVED_BODY_KEYS);\n\n\treturn payload;\n}\n\nfunction shouldUsePromptCaching(options?: MistralOptions): options is MistralOptions & { sessionId: string } {\n\treturn options?.cacheRetention !== \"none\" && !!options?.sessionId;\n}\n\nfunction getMistralCachedPromptTokens(usage: unknown, promptTokens: number): number {\n\tconst rawUsage = usage as {\n\t\tpromptTokensDetails?: { cachedTokens?: unknown } | null;\n\t\tprompt_tokens_details?: { cached_tokens?: unknown } | null;\n\t\tpromptTokenDetails?: { cachedTokens?: unknown } | null;\n\t\tprompt_token_details?: { cached_tokens?: unknown } | null;\n\t\tnumCachedTokens?: unknown;\n\t\tnum_cached_tokens?: unknown;\n\t};\n\tconst rawCachedTokens =\n\t\trawUsage.promptTokensDetails?.cachedTokens ??\n\t\trawUsage.prompt_tokens_details?.cached_tokens ??\n\t\trawUsage.promptTokenDetails?.cachedTokens ??\n\t\trawUsage.prompt_token_details?.cached_tokens ??\n\t\trawUsage.numCachedTokens ??\n\t\trawUsage.num_cached_tokens ??\n\t\t0;\n\tconst cachedTokens = typeof rawCachedTokens === \"number\" && Number.isFinite(rawCachedTokens) ? rawCachedTokens : 0;\n\treturn Math.min(promptTokens, Math.max(0, cachedTokens));\n}\n\nasync function consumeChatStream(\n\tmodel: Model<\"mistral-conversations\">,\n\toutput: AssistantMessage,\n\tstream: AssistantMessageEventStream,\n\tmistralStream: AsyncIterable<MistralCompletionEvent>,\n): Promise<void> {\n\tlet currentBlock: TextContent | ThinkingContent | null = null;\n\tconst blocks = output.content;\n\tconst blockIndex = () => blocks.length - 1;\n\tconst toolBlocksByKey = new Map<string, number>();\n\n\tconst finishCurrentBlock = (block?: typeof currentBlock) => {\n\t\tif (!block) return;\n\t\tif (block.type === \"text\") {\n\t\t\tstream.push({\n\t\t\t\ttype: \"text_end\",\n\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\tcontent: block.text,\n\t\t\t\tpartial: output,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tif (block.type === \"thinking\") {\n\t\t\tstream.push({\n\t\t\t\ttype: \"thinking_end\",\n\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\tcontent: block.thinking,\n\t\t\t\tpartial: output,\n\t\t\t});\n\t\t}\n\t};\n\n\tfor await (const event of mistralStream) {\n\t\tconst chunk = event.data;\n\t\t// Mistral's streamed CompletionChunk carries an id field. Keep the first non-empty one,\n\t\t// mirroring how OpenAI-style streaming exposes a stable response identifier per stream.\n\t\toutput.responseId ||= chunk.id;\n\n\t\tif (chunk.usage) {\n\t\t\tconst promptTokens = chunk.usage.prompt_tokens || 0;\n\t\t\tconst cachedPromptTokens = getMistralCachedPromptTokens(chunk.usage, promptTokens);\n\n\t\t\toutput.usage.input = Math.max(0, promptTokens - cachedPromptTokens);\n\t\t\toutput.usage.output = chunk.usage.completion_tokens || 0;\n\t\t\toutput.usage.cacheRead = cachedPromptTokens;\n\t\t\toutput.usage.cacheWrite = 0;\n\t\t\toutput.usage.totalTokens =\n\t\t\t\tchunk.usage.total_tokens ||\n\t\t\t\toutput.usage.input + output.usage.output + output.usage.cacheRead + output.usage.cacheWrite;\n\t\t\tcalculateCost(model, output.usage);\n\t\t}\n\n\t\tconst choice = chunk.choices[0];\n\t\tif (!choice) continue;\n\n\t\tif (choice.finish_reason) {\n\t\t\toutput.rawStopReason = choice.finish_reason;\n\t\t\tconst stopReasonResult = mapChatStopReason(choice.finish_reason);\n\t\t\toutput.stopReason = stopReasonResult.stopReason;\n\t\t\tif (stopReasonResult.errorMessage) {\n\t\t\t\toutput.errorMessage = stopReasonResult.errorMessage;\n\t\t\t}\n\t\t}\n\n\t\tconst delta = choice.delta;\n\t\tif (delta.content !== null && delta.content !== undefined) {\n\t\t\tconst contentItems = typeof delta.content === \"string\" ? [delta.content] : delta.content;\n\t\t\tfor (const item of contentItems) {\n\t\t\t\tif (typeof item === \"string\") {\n\t\t\t\t\tconst textDelta = sanitizeSurrogates(item);\n\t\t\t\t\tif (currentBlock?.type !== \"text\") {\n\t\t\t\t\t\tfinishCurrentBlock(currentBlock);\n\t\t\t\t\t\tcurrentBlock = { type: \"text\", text: \"\" };\n\t\t\t\t\t\toutput.content.push(currentBlock);\n\t\t\t\t\t\tstream.push({ type: \"text_start\", contentIndex: blockIndex(), partial: output });\n\t\t\t\t\t}\n\t\t\t\t\tcurrentBlock.text += textDelta;\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"text_delta\",\n\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\tdelta: textDelta,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (item.type === \"thinking\") {\n\t\t\t\t\tconst deltaText = (item.thinking ?? [])\n\t\t\t\t\t\t.map((part) => part.text ?? \"\")\n\t\t\t\t\t\t.filter((text) => text.length > 0)\n\t\t\t\t\t\t.join(\"\");\n\t\t\t\t\tconst thinkingDelta = sanitizeSurrogates(deltaText);\n\t\t\t\t\tif (!thinkingDelta) continue;\n\t\t\t\t\tif (currentBlock?.type !== \"thinking\") {\n\t\t\t\t\t\tfinishCurrentBlock(currentBlock);\n\t\t\t\t\t\tcurrentBlock = { type: \"thinking\", thinking: \"\" };\n\t\t\t\t\t\toutput.content.push(currentBlock);\n\t\t\t\t\t\tstream.push({ type: \"thinking_start\", contentIndex: blockIndex(), partial: output });\n\t\t\t\t\t}\n\t\t\t\t\tcurrentBlock.thinking += thinkingDelta;\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"thinking_delta\",\n\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\tdelta: thinkingDelta,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (item.type === \"text\") {\n\t\t\t\t\tconst textDelta = sanitizeSurrogates(item.text ?? \"\");\n\t\t\t\t\tif (currentBlock?.type !== \"text\") {\n\t\t\t\t\t\tfinishCurrentBlock(currentBlock);\n\t\t\t\t\t\tcurrentBlock = { type: \"text\", text: \"\" };\n\t\t\t\t\t\toutput.content.push(currentBlock);\n\t\t\t\t\t\tstream.push({ type: \"text_start\", contentIndex: blockIndex(), partial: output });\n\t\t\t\t\t}\n\t\t\t\t\tcurrentBlock.text += textDelta;\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"text_delta\",\n\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\tdelta: textDelta,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst toolCalls = delta.tool_calls || [];\n\t\tfor (const toolCall of toolCalls) {\n\t\t\tif (currentBlock) {\n\t\t\t\tfinishCurrentBlock(currentBlock);\n\t\t\t\tcurrentBlock = null;\n\t\t\t}\n\t\t\tconst callId =\n\t\t\t\ttoolCall.id && toolCall.id !== \"null\"\n\t\t\t\t\t? toolCall.id\n\t\t\t\t\t: deriveMistralToolCallId(`toolcall:${toolCall.index ?? 0}`, 0);\n\t\t\tconst key = `${callId}:${toolCall.index || 0}`;\n\t\t\tconst existingIndex = toolBlocksByKey.get(key);\n\t\t\tlet block: (ToolCall & { partialArgs?: string }) | undefined;\n\n\t\t\tif (existingIndex !== undefined) {\n\t\t\t\tconst existing = output.content[existingIndex];\n\t\t\t\tif (existing?.type === \"toolCall\") {\n\t\t\t\t\tblock = existing as ToolCall & { partialArgs?: string };\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!block) {\n\t\t\t\tblock = {\n\t\t\t\t\ttype: \"toolCall\",\n\t\t\t\t\tid: callId,\n\t\t\t\t\tname: toolCall.function.name,\n\t\t\t\t\targuments: {},\n\t\t\t\t\tpartialArgs: \"\",\n\t\t\t\t};\n\t\t\t\toutput.content.push(block);\n\t\t\t\ttoolBlocksByKey.set(key, output.content.length - 1);\n\t\t\t\tstream.push({ type: \"toolcall_start\", contentIndex: output.content.length - 1, partial: output });\n\t\t\t}\n\n\t\t\tconst argsDelta =\n\t\t\t\ttypeof toolCall.function.arguments === \"string\"\n\t\t\t\t\t? toolCall.function.arguments\n\t\t\t\t\t: JSON.stringify(toolCall.function.arguments || {});\n\t\t\tblock.partialArgs = (block.partialArgs || \"\") + argsDelta;\n\t\t\tblock.arguments = parseStreamingJson<Record<string, unknown>>(block.partialArgs);\n\t\t\tstream.push({\n\t\t\t\ttype: \"toolcall_delta\",\n\t\t\t\tcontentIndex: toolBlocksByKey.get(key)!,\n\t\t\t\tdelta: argsDelta,\n\t\t\t\tpartial: output,\n\t\t\t});\n\t\t}\n\t}\n\n\tfinishCurrentBlock(currentBlock);\n\tfor (const index of toolBlocksByKey.values()) {\n\t\tconst block = output.content[index];\n\t\tif (block.type !== \"toolCall\") continue;\n\t\tconst toolBlock = block as ToolCall & { partialArgs?: string };\n\t\ttoolBlock.arguments = parseStreamingJson<Record<string, unknown>>(toolBlock.partialArgs);\n\t\t// Finalize in-place and strip the scratch buffer so replay only\n\t\t// carries parsed arguments.\n\t\tdelete toolBlock.partialArgs;\n\t\tstream.push({\n\t\t\ttype: \"toolcall_end\",\n\t\t\tcontentIndex: index,\n\t\t\ttoolCall: toolBlock,\n\t\t\tpartial: output,\n\t\t});\n\t}\n}\n\nfunction toFunctionTools(tools: Tool[]): MistralFunctionTool[] {\n\treturn tools.map((tool) => {\n\t\tconst strict = resolveJsonSchemaStrictSampling(tool, true);\n\t\treturn {\n\t\t\ttype: \"function\",\n\t\t\tfunction: {\n\t\t\t\tname: tool.name,\n\t\t\t\tdescription: tool.description,\n\t\t\t\tparameters: stripSymbolKeys(getJsonSchemaToolParameters(tool, strict)) as Record<string, unknown>,\n\t\t\t\tstrict: strict ?? false,\n\t\t\t},\n\t\t};\n\t});\n}\n\nfunction stripSymbolKeys(value: unknown): unknown {\n\tif (Array.isArray(value)) {\n\t\treturn value.map((item) => stripSymbolKeys(item));\n\t}\n\n\tif (value && typeof value === \"object\") {\n\t\tconst result: Record<string, unknown> = {};\n\t\tfor (const [key, entry] of Object.entries(value)) {\n\t\t\tresult[key] = stripSymbolKeys(entry);\n\t\t}\n\t\treturn result;\n\t}\n\n\treturn value;\n}\n\nfunction toChatMessages(messages: Message[], supportsImages: boolean): MistralChatMessage[] {\n\tconst result: MistralChatMessage[] = [];\n\n\tfor (const msg of messages) {\n\t\tif (msg.role === \"user\") {\n\t\t\tif (typeof msg.content === \"string\") {\n\t\t\t\tresult.push({ role: \"user\", content: sanitizeSurrogates(msg.content) });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst hadImages = msg.content.some((item) => item.type === \"image\");\n\t\t\tconst content: MistralContentChunk[] = msg.content\n\t\t\t\t.filter((item) => item.type === \"text\" || supportsImages)\n\t\t\t\t.map((item) => {\n\t\t\t\t\tif (item.type === \"text\") return { type: \"text\", text: sanitizeSurrogates(item.text) };\n\t\t\t\t\treturn { type: \"image_url\", imageUrl: `data:${item.mimeType};base64,${item.data}` };\n\t\t\t\t});\n\t\t\tif (content.length > 0) {\n\t\t\t\tresult.push({ role: \"user\", content });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (hadImages && !supportsImages) {\n\t\t\t\tresult.push({ role: \"user\", content: \"(image omitted: model does not support images)\" });\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (msg.role === \"assistant\") {\n\t\t\tconst contentParts: MistralContentChunk[] = [];\n\t\t\tconst toolCalls: MistralRequestToolCall[] = [];\n\n\t\t\tfor (const block of msg.content) {\n\t\t\t\tif (block.type === \"text\") {\n\t\t\t\t\tif (block.text.trim().length > 0) {\n\t\t\t\t\t\tcontentParts.push({ type: \"text\", text: sanitizeSurrogates(block.text) });\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (block.type === \"thinking\") {\n\t\t\t\t\tif (block.thinking.trim().length > 0) {\n\t\t\t\t\t\tcontentParts.push({\n\t\t\t\t\t\t\ttype: \"thinking\",\n\t\t\t\t\t\t\tthinking: [{ type: \"text\", text: sanitizeSurrogates(block.thinking) }],\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (block.type !== \"toolCall\") {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\ttoolCalls.push({\n\t\t\t\t\tid: block.id,\n\t\t\t\t\ttype: \"function\",\n\t\t\t\t\tfunction: { name: block.name, arguments: JSON.stringify(block.arguments || {}) },\n\t\t\t\t\tindex: 0,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst assistantMessage: MistralChatMessage = { role: \"assistant\", prefix: false };\n\t\t\tif (contentParts.length > 0) assistantMessage.content = contentParts;\n\t\t\tif (toolCalls.length > 0) assistantMessage.toolCalls = toolCalls;\n\t\t\tif (contentParts.length > 0 || toolCalls.length > 0) result.push(assistantMessage);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst toolContent: MistralContentChunk[] = [];\n\t\tconst textResult = msg.content\n\t\t\t.filter((part) => part.type === \"text\")\n\t\t\t.map((part) => (part.type === \"text\" ? sanitizeSurrogates(part.text) : \"\"))\n\t\t\t.join(\"\\n\");\n\t\tconst hasImages = msg.content.some((part) => part.type === \"image\");\n\t\tconst toolText = buildToolResultText(textResult, hasImages, supportsImages, msg.isError);\n\t\ttoolContent.push({ type: \"text\", text: toolText });\n\t\tfor (const part of msg.content) {\n\t\t\tif (!supportsImages) continue;\n\t\t\tif (part.type !== \"image\") continue;\n\t\t\ttoolContent.push({\n\t\t\t\ttype: \"image_url\",\n\t\t\t\timageUrl: `data:${part.mimeType};base64,${part.data}`,\n\t\t\t});\n\t\t}\n\t\tresult.push({\n\t\t\trole: \"tool\",\n\t\t\ttoolCallId: msg.toolCallId,\n\t\t\tname: msg.toolName,\n\t\t\tcontent: toolContent,\n\t\t});\n\t}\n\n\treturn result;\n}\n\nfunction buildToolResultText(text: string, hasImages: boolean, supportsImages: boolean, isError: boolean): string {\n\tconst trimmed = text.trim();\n\tconst errorPrefix = isError ? \"[tool error] \" : \"\";\n\n\tif (trimmed.length > 0) {\n\t\tconst imageSuffix = hasImages && !supportsImages ? \"\\n[tool image omitted: model does not support images]\" : \"\";\n\t\treturn `${errorPrefix}${trimmed}${imageSuffix}`;\n\t}\n\n\tif (hasImages) {\n\t\tif (supportsImages) {\n\t\t\treturn isError ? \"[tool error] (see attached image)\" : \"(see attached image)\";\n\t\t}\n\t\treturn isError\n\t\t\t? \"[tool error] (image omitted: model does not support images)\"\n\t\t\t: \"(image omitted: model does not support images)\";\n\t}\n\n\treturn isError ? \"[tool error] (no tool output)\" : \"(no tool output)\";\n}\n\nfunction usesReasoningEffort(model: Model<\"mistral-conversations\">): boolean {\n\treturn model.id === \"mistral-small-2603\" || model.id === \"mistral-small-latest\" || model.id === \"mistral-medium-3.5\";\n}\n\nfunction usesPromptModeReasoning(model: Model<\"mistral-conversations\">): boolean {\n\treturn model.reasoning && !usesReasoningEffort(model);\n}\n\nfunction mapReasoningEffort(\n\tmodel: Model<\"mistral-conversations\">,\n\tlevel: Exclude<SimpleStreamOptions[\"reasoning\"], undefined>,\n): MistralReasoningEffort {\n\treturn (model.thinkingLevelMap?.[level] ?? \"high\") as MistralReasoningEffort;\n}\n\nfunction mapToolChoice(\n\tchoice: MistralOptions[\"toolChoice\"],\n): \"auto\" | \"none\" | \"any\" | \"required\" | { type: \"function\"; function: { name: string } } | undefined {\n\tif (!choice) return undefined;\n\tif (choice === \"auto\" || choice === \"none\" || choice === \"any\" || choice === \"required\") {\n\t\treturn choice;\n\t}\n\treturn {\n\t\ttype: \"function\",\n\t\tfunction: { name: choice.function.name },\n\t};\n}\n\nfunction mapChatStopReason(reason: string | null): { stopReason: StopReason; errorMessage?: string } {\n\tif (reason === null) return { stopReason: \"stop\" };\n\tswitch (reason) {\n\t\tcase \"stop\":\n\t\t\treturn { stopReason: \"stop\" };\n\t\tcase \"length\":\n\t\tcase \"model_length\":\n\t\t\treturn { stopReason: \"length\" };\n\t\tcase \"tool_calls\":\n\t\t\treturn { stopReason: \"toolUse\" };\n\t\tcase \"error\":\n\t\t\treturn { stopReason: \"error\", errorMessage: \"Provider stopped with: error\" };\n\t\tdefault:\n\t\t\treturn { stopReason: \"error\", errorMessage: `Provider stopped with: ${reason}` };\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai-codex-responses.d.ts","sourceRoot":"","sources":["../../src/api/openai-codex-responses.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEX,6BAA6B,EAG7B,MAAM,yCAAyC,CAAC;AAmBjD,OAAO,KAAK,EAOX,mBAAmB,EACnB,cAAc,EACd,aAAa,EAEb,MAAM,aAAa,CAAC;AAgBrB,OAAO,EAKN,KAAK,8BAA8B,EAGnC,MAAM,4CAA4C,CAAC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