mirror of
https://gitee.com/zhangsken/opencode.git
synced 2026-12-05 18:44:31 +08:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 00397cd135 |
@@ -304,7 +304,7 @@
|
||||
"@ai-sdk/google": "3.0.73",
|
||||
"@ai-sdk/google-vertex": "4.0.181",
|
||||
"@ai-sdk/groq": "3.0.31",
|
||||
"@ai-sdk/mistral": "3.0.51",
|
||||
"@ai-sdk/mistral": "3.0.59",
|
||||
"@ai-sdk/openai": "3.0.84",
|
||||
"@ai-sdk/openai-compatible": "2.0.41",
|
||||
"@ai-sdk/perplexity": "3.0.26",
|
||||
@@ -579,7 +579,7 @@
|
||||
"@ai-sdk/google": "3.0.73",
|
||||
"@ai-sdk/google-vertex": "4.0.181",
|
||||
"@ai-sdk/groq": "3.0.31",
|
||||
"@ai-sdk/mistral": "3.0.51",
|
||||
"@ai-sdk/mistral": "3.0.59",
|
||||
"@ai-sdk/openai": "3.0.84",
|
||||
"@ai-sdk/openai-compatible": "2.0.41",
|
||||
"@ai-sdk/perplexity": "3.0.26",
|
||||
@@ -1058,6 +1058,7 @@
|
||||
"tree-sitter-bash",
|
||||
],
|
||||
"patchedDependencies": {
|
||||
"@ai-sdk/mistral@3.0.59": "patches/@ai-sdk%2Fmistral@3.0.59.patch",
|
||||
"@pierre/trees@1.0.0-beta.4": "patches/@pierre%2Ftrees@1.0.0-beta.4.patch",
|
||||
"@tanstack/virtual-core@3.17.3": "patches/@tanstack%2Fvirtual-core@3.17.3.patch",
|
||||
"@ai-sdk/xai@3.0.102": "patches/@ai-sdk%2Fxai@3.0.102.patch",
|
||||
@@ -1065,9 +1066,9 @@
|
||||
"gcp-metadata@8.1.2": "patches/gcp-metadata@8.1.2.patch",
|
||||
"@standard-community/standard-openapi@0.2.9": "patches/@standard-community%2Fstandard-openapi@0.2.9.patch",
|
||||
"effect@4.0.0-beta.83": "patches/effect@4.0.0-beta.83.patch",
|
||||
"@ai-sdk/mistral@3.0.51": "patches/@ai-sdk%2Fmistral@3.0.51.patch",
|
||||
"@silvia-odwyer/photon-node@0.3.4": "patches/@silvia-odwyer%2Fphoton-node@0.3.4.patch",
|
||||
"@npmcli/agent@4.0.2": "patches/@npmcli%2Fagent@4.0.2.patch",
|
||||
"@silvia-odwyer/photon-node@0.3.4": "patches/@silvia-odwyer%2Fphoton-node@0.3.4.patch",
|
||||
"@ai-sdk/mistral@3.0.51": "patches/@ai-sdk%2Fmistral@3.0.51.patch",
|
||||
"solid-js@1.9.10": "patches/solid-js@1.9.10.patch",
|
||||
"@ai-sdk/groq@3.0.31": "patches/@ai-sdk%2Fgroq@3.0.31.patch",
|
||||
"@ai-sdk/google@3.0.73": "patches/@ai-sdk%2Fgoogle@3.0.73.patch",
|
||||
@@ -1195,7 +1196,7 @@
|
||||
|
||||
"@ai-sdk/groq": ["@ai-sdk/groq@3.0.31", "", { "dependencies": { "@ai-sdk/provider": "3.0.8", "@ai-sdk/provider-utils": "4.0.21" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-XbbugpnFmXGu2TlXiq8KUJskP6/VVbuFcnFIGDzDIB/Chg6XHsNnqrTF80Zxkh0Pd3+NvbM+2Uqrtsndk6bDAg=="],
|
||||
|
||||
"@ai-sdk/mistral": ["@ai-sdk/mistral@3.0.51", "", { "dependencies": { "@ai-sdk/provider": "3.0.14", "@ai-sdk/provider-utils": "4.0.40" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-83eXY6p0lUFhSuMvNDmTKDuMciK5XDAWDlNh5c0L80tKjmtCFRItA1MZHp4IKe1r7eK8Rb5nN7qtxqMLUFRIRw=="],
|
||||
"@ai-sdk/mistral": ["@ai-sdk/mistral@3.0.59", "", { "dependencies": { "@ai-sdk/provider": "3.0.15", "@ai-sdk/provider-utils": "4.0.46" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-siNvAgWfjyEHGPPT+Lo2WDAz9JuVL0ev49TGirg+oB7cDeBtfb1Z+n+5Obsz+xxQWZbKk6emX2LkRrO4DsOtNA=="],
|
||||
|
||||
"@ai-sdk/openai": ["@ai-sdk/openai@3.0.48", "", { "dependencies": { "@ai-sdk/provider": "3.0.8", "@ai-sdk/provider-utils": "4.0.21" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-ALmj/53EXpcRqMbGpPJPP4UOSWw0q4VGpnDo7YctvsynjkrKDmoneDG/1a7VQnSPYHnJp6tTRMf5ZdxZ5whulg=="],
|
||||
|
||||
@@ -5683,9 +5684,9 @@
|
||||
|
||||
"@ai-sdk/groq/@ai-sdk/provider-utils": ["@ai-sdk/provider-utils@4.0.21", "", { "dependencies": { "@ai-sdk/provider": "3.0.8", "@standard-schema/spec": "^1.1.0", "eventsource-parser": "^3.0.6" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-MtFUYI1/8mgDvRmaBDjbLJPFFrMG777AvSgyIFQtZHIMzm88R/12vYBBpnk7pfiWLFE1DSZzY4WDYzGbKAcmiw=="],
|
||||
|
||||
"@ai-sdk/mistral/@ai-sdk/provider": ["@ai-sdk/provider@3.0.14", "", { "dependencies": { "json-schema": "^0.4.0" } }, "sha512-5X1k57JBJ4H7H1QjX7CnJYAB1I19r/trVZTMcSms7/kLNZ8RaU4Nt2agcwZzv82Hfx6Q7/TOLU7agAKeFfc8cA=="],
|
||||
"@ai-sdk/mistral/@ai-sdk/provider": ["@ai-sdk/provider@3.0.15", "", { "dependencies": { "json-schema": "^0.4.0" } }, "sha512-XeZW1CcDF2GMbH4wejW6xBRI2QCOgnkVYUnxoeDadB1mf85riL2bMUeDoh+6gJ/r4mjNfzUPW8OjLjvwTP0u1Q=="],
|
||||
|
||||
"@ai-sdk/mistral/@ai-sdk/provider-utils": ["@ai-sdk/provider-utils@4.0.40", "", { "dependencies": { "@ai-sdk/provider": "3.0.14", "@standard-schema/spec": "^1.1.0", "eventsource-parser": "^3.0.8" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-OL5IrpUm9Y8Dwy+w/vvFwPotS6m52O9W0op2oXgXdCROMJIBalBI0oro6OIBYkPxvm5Xg02GSkoQN25RlR0bnw=="],
|
||||
"@ai-sdk/mistral/@ai-sdk/provider-utils": ["@ai-sdk/provider-utils@4.0.46", "", { "dependencies": { "@ai-sdk/provider": "3.0.15", "@standard-schema/spec": "^1.1.0", "eventsource-parser": "^3.0.8", "undici": "^6.28.0" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-tEtld97plCFiYevsJuOkGkeuhQndeMWFBVrJS4AjnbD5AqrNSXRCe0p+BZ3Cju/sxDeeZ9ym3q9YUV8fASA7aQ=="],
|
||||
|
||||
"@ai-sdk/openai/@ai-sdk/provider-utils": ["@ai-sdk/provider-utils@4.0.21", "", { "dependencies": { "@ai-sdk/provider": "3.0.8", "@standard-schema/spec": "^1.1.0", "eventsource-parser": "^3.0.6" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-MtFUYI1/8mgDvRmaBDjbLJPFFrMG777AvSgyIFQtZHIMzm88R/12vYBBpnk7pfiWLFE1DSZzY4WDYzGbKAcmiw=="],
|
||||
|
||||
@@ -6165,6 +6166,8 @@
|
||||
|
||||
"ai-gateway-provider/@ai-sdk/groq": ["@ai-sdk/groq@3.0.59", "", { "dependencies": { "@ai-sdk/provider": "3.0.15", "@ai-sdk/provider-utils": "4.0.45" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-X4h60TGq4pIOXPsthatUr+bfTaYCaKGX597hG9JgcueEl4+nboCdw99ixjFKGkvYlBJwLCCfI957EmGA2QlF0w=="],
|
||||
|
||||
"ai-gateway-provider/@ai-sdk/mistral": ["@ai-sdk/mistral@3.0.51", "", { "dependencies": { "@ai-sdk/provider": "3.0.14", "@ai-sdk/provider-utils": "4.0.40" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-83eXY6p0lUFhSuMvNDmTKDuMciK5XDAWDlNh5c0L80tKjmtCFRItA1MZHp4IKe1r7eK8Rb5nN7qtxqMLUFRIRw=="],
|
||||
|
||||
"ai-gateway-provider/@ai-sdk/openai": ["@ai-sdk/openai@3.0.84", "", { "dependencies": { "@ai-sdk/provider": "3.0.14", "@ai-sdk/provider-utils": "4.0.38" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-cmgbeJL0bbY0yTJH4/AdmP5E7MjWRL9G8UdhIi0JlV/So03o82ORJofW8OzwCZPTORVQblFbpZXYGDcUd9NdUQ=="],
|
||||
|
||||
"ai-gateway-provider/@ai-sdk/perplexity": ["@ai-sdk/perplexity@3.0.53", "", { "dependencies": { "@ai-sdk/provider": "3.0.15", "@ai-sdk/provider-utils": "4.0.45" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-bL3SWrPltTuxVNg/bZ5APbJLVe0+BIU+BYAbT8Yo0eSAZ5eMTImN2murQHZa08Wi8lUMm8MNolaYBQkb0JDbFw=="],
|
||||
@@ -6603,6 +6606,8 @@
|
||||
|
||||
"@ai-sdk/mistral/@ai-sdk/provider-utils/@standard-schema/spec": ["@standard-schema/spec@1.1.0", "", {}, "sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w=="],
|
||||
|
||||
"@ai-sdk/mistral/@ai-sdk/provider-utils/undici": ["undici@6.28.0", "", {}, "sha512-LIY910g9TI13YS95lrMFrs8Rm/u/irgHeTWoKCoteeJ04CUJ92eEfj0rVn+7VKMPBpUPiUoBKfhNyLI23EE/KA=="],
|
||||
|
||||
"@ai-sdk/openai-compatible/@ai-sdk/provider-utils/@standard-schema/spec": ["@standard-schema/spec@1.1.0", "", {}, "sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w=="],
|
||||
|
||||
"@ai-sdk/openai/@ai-sdk/provider-utils/@standard-schema/spec": ["@standard-schema/spec@1.1.0", "", {}, "sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w=="],
|
||||
@@ -7001,6 +7006,10 @@
|
||||
|
||||
"ai-gateway-provider/@ai-sdk/groq/@ai-sdk/provider-utils": ["@ai-sdk/provider-utils@4.0.45", "", { "dependencies": { "@ai-sdk/provider": "3.0.15", "@standard-schema/spec": "^1.1.0", "eventsource-parser": "^3.0.8", "undici": "^5.29.0" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-7u5B/E2uZmU65SlJhhQGFHZwRCN0xOz4HHtFc4sEGV9PHbX3fGiEiZBpc/SABay1dGeJgK3VD60rvLGoWdWPXA=="],
|
||||
|
||||
"ai-gateway-provider/@ai-sdk/mistral/@ai-sdk/provider": ["@ai-sdk/provider@3.0.14", "", { "dependencies": { "json-schema": "^0.4.0" } }, "sha512-5X1k57JBJ4H7H1QjX7CnJYAB1I19r/trVZTMcSms7/kLNZ8RaU4Nt2agcwZzv82Hfx6Q7/TOLU7agAKeFfc8cA=="],
|
||||
|
||||
"ai-gateway-provider/@ai-sdk/mistral/@ai-sdk/provider-utils": ["@ai-sdk/provider-utils@4.0.40", "", { "dependencies": { "@ai-sdk/provider": "3.0.14", "@standard-schema/spec": "^1.1.0", "eventsource-parser": "^3.0.8" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-OL5IrpUm9Y8Dwy+w/vvFwPotS6m52O9W0op2oXgXdCROMJIBalBI0oro6OIBYkPxvm5Xg02GSkoQN25RlR0bnw=="],
|
||||
|
||||
"ai-gateway-provider/@ai-sdk/openai/@ai-sdk/provider": ["@ai-sdk/provider@3.0.14", "", { "dependencies": { "json-schema": "^0.4.0" } }, "sha512-5X1k57JBJ4H7H1QjX7CnJYAB1I19r/trVZTMcSms7/kLNZ8RaU4Nt2agcwZzv82Hfx6Q7/TOLU7agAKeFfc8cA=="],
|
||||
|
||||
"ai-gateway-provider/@ai-sdk/openai/@ai-sdk/provider-utils": ["@ai-sdk/provider-utils@4.0.38", "", { "dependencies": { "@ai-sdk/provider": "3.0.14", "@standard-schema/spec": "^1.1.0", "eventsource-parser": "^3.0.8" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-/HHGmtKllqjg1OLc023v9w9kK3laW7Z6TzfZukYQWCsGBbzB9p60zTvvpXFVcs44NZBVXL3viOa1HRKUbeee8g=="],
|
||||
@@ -7447,6 +7456,8 @@
|
||||
|
||||
"ai-gateway-provider/@ai-sdk/groq/@ai-sdk/provider-utils/undici": ["undici@5.29.0", "", { "dependencies": { "@fastify/busboy": "^2.0.0" } }, "sha512-raqeBD6NQK4SkWhQzeYKd1KmIG6dllBOTt55Rmkt4HtI9mwdWtJljnrXjAFUBLTSN67HWrOIZ3EPF4kjUw80Bg=="],
|
||||
|
||||
"ai-gateway-provider/@ai-sdk/mistral/@ai-sdk/provider-utils/@standard-schema/spec": ["@standard-schema/spec@1.1.0", "", {}, "sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w=="],
|
||||
|
||||
"ai-gateway-provider/@ai-sdk/openai/@ai-sdk/provider-utils/@standard-schema/spec": ["@standard-schema/spec@1.1.0", "", {}, "sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w=="],
|
||||
|
||||
"ai-gateway-provider/@ai-sdk/perplexity/@ai-sdk/provider-utils/@standard-schema/spec": ["@standard-schema/spec@1.1.0", "", {}, "sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w=="],
|
||||
|
||||
@@ -151,6 +151,7 @@
|
||||
"@standard-community/standard-openapi@0.2.9": "patches/@standard-community%2Fstandard-openapi@0.2.9.patch",
|
||||
"solid-js@1.9.10": "patches/solid-js@1.9.10.patch",
|
||||
"@ai-sdk/xai@3.0.102": "patches/@ai-sdk%2Fxai@3.0.102.patch",
|
||||
"@ai-sdk/mistral@3.0.59": "patches/@ai-sdk%2Fmistral@3.0.59.patch",
|
||||
"@ai-sdk/mistral@3.0.51": "patches/@ai-sdk%2Fmistral@3.0.51.patch",
|
||||
"gcp-metadata@8.1.2": "patches/gcp-metadata@8.1.2.patch",
|
||||
"pacote@21.5.0": "patches/pacote@21.5.0.patch",
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
"@ai-sdk/google": "3.0.73",
|
||||
"@ai-sdk/google-vertex": "4.0.181",
|
||||
"@ai-sdk/groq": "3.0.31",
|
||||
"@ai-sdk/mistral": "3.0.51",
|
||||
"@ai-sdk/mistral": "3.0.59",
|
||||
"@ai-sdk/openai": "3.0.84",
|
||||
"@ai-sdk/openai-compatible": "2.0.41",
|
||||
"@ai-sdk/perplexity": "3.0.26",
|
||||
|
||||
@@ -1,6 +1,114 @@
|
||||
import { createMistral } from "@ai-sdk/mistral"
|
||||
import { expect, test } from "bun:test"
|
||||
|
||||
test.each([false, true])(
|
||||
"Mistral accumulates fragmented tool calls with native reasoning (parallel: %s)",
|
||||
async (parallel) => {
|
||||
const thinking = {
|
||||
type: "thinking" as const,
|
||||
thinking: [{ type: "text", text: "Check the weather." }],
|
||||
closed: true,
|
||||
signature: "sig-123",
|
||||
}
|
||||
const calls = ["Paris", ...(parallel ? ["London"] : [])].map((city, index) => ({
|
||||
index,
|
||||
id: `call0000${index}`,
|
||||
city,
|
||||
}))
|
||||
const chunks = [
|
||||
{ content: [thinking] },
|
||||
{
|
||||
tool_calls: calls.map((call) => ({
|
||||
index: call.index,
|
||||
id: call.id,
|
||||
type: "function",
|
||||
function: { name: "weather", arguments: '{"city":"' },
|
||||
})),
|
||||
},
|
||||
...calls.toReversed().map((call) => ({
|
||||
content: "",
|
||||
tool_calls: [{ index: call.index, function: { name: "", arguments: call.city } }],
|
||||
})),
|
||||
{ tool_calls: calls.map((call) => ({ index: call.index, function: { arguments: '"}' } })) },
|
||||
].map((delta) => ({
|
||||
id: "response-1",
|
||||
created: 0,
|
||||
model: "zai-glm-5-2",
|
||||
choices: [{ index: 0, delta }],
|
||||
}))
|
||||
const body: { messages?: unknown[] }[] = []
|
||||
const mockFetch = Object.assign(
|
||||
async (_input: Parameters<typeof fetch>[0], init?: RequestInit) => {
|
||||
if (typeof init?.body !== "string") throw new Error("Expected JSON request body")
|
||||
body.push(JSON.parse(init.body))
|
||||
return new Response(
|
||||
[...chunks, { choices: [{ index: 0, delta: {}, finish_reason: "tool_calls" }] }]
|
||||
.map((chunk) => `data: ${JSON.stringify(chunk)}\n\n`)
|
||||
.join(""),
|
||||
{ headers: { "Content-Type": "text/event-stream" } },
|
||||
)
|
||||
},
|
||||
{ preconnect: fetch.preconnect },
|
||||
)
|
||||
const model = createMistral({ apiKey: "test", fetch: mockFetch })("zai-glm-5-2")
|
||||
const result = await model.doStream({
|
||||
prompt: [{ role: "user", content: [{ type: "text", text: "Check the weather" }] }],
|
||||
})
|
||||
const events = []
|
||||
for await (const event of result.stream) events.push(event)
|
||||
|
||||
expect(events.filter((event) => event.type === "error")).toEqual([])
|
||||
const tools = events.filter((event) => event.type === "tool-call")
|
||||
expect(tools).toEqual(
|
||||
calls.map((call) => ({
|
||||
type: "tool-call",
|
||||
toolCallId: call.id,
|
||||
toolName: "weather",
|
||||
input: JSON.stringify({ city: call.city }),
|
||||
})),
|
||||
)
|
||||
expect(events.filter((event) => event.type === "tool-input-start")).toHaveLength(calls.length)
|
||||
expect(events.filter((event) => event.type === "tool-input-end")).toHaveLength(calls.length)
|
||||
const reasoning = events.find((event) => event.type === "reasoning-end")
|
||||
expect(reasoning?.providerMetadata).toEqual({ mistral: { thinking } })
|
||||
|
||||
const next = await model.doStream({
|
||||
prompt: [
|
||||
{ role: "user", content: [{ type: "text", text: "Check the weather" }] },
|
||||
{
|
||||
role: "assistant",
|
||||
content: [
|
||||
{ type: "reasoning", text: "Check the weather.", providerOptions: reasoning?.providerMetadata },
|
||||
...tools.map((tool) => ({ ...tool, input: JSON.parse(tool.input) })),
|
||||
],
|
||||
},
|
||||
{
|
||||
role: "tool",
|
||||
content: tools.map((tool) => ({
|
||||
type: "tool-result",
|
||||
toolCallId: tool.toolCallId,
|
||||
toolName: tool.toolName,
|
||||
output: { type: "text", value: "Sunny" },
|
||||
})),
|
||||
},
|
||||
],
|
||||
})
|
||||
await next.stream.cancel()
|
||||
expect(body[1]?.messages?.slice(1)).toEqual([
|
||||
{
|
||||
role: "assistant",
|
||||
content: [thinking],
|
||||
tool_calls: calls.map((call) => ({
|
||||
id: call.id,
|
||||
type: "function",
|
||||
function: { name: "weather", arguments: JSON.stringify({ city: call.city }) },
|
||||
})),
|
||||
},
|
||||
...calls.map((call) => ({ role: "tool", name: "weather", tool_call_id: call.id, content: "Sunny" })),
|
||||
])
|
||||
},
|
||||
)
|
||||
|
||||
test("Mistral sends promptCacheKey as prompt_cache_key", async () => {
|
||||
let body: Record<string, unknown> | undefined
|
||||
const mockFetch = Object.assign(
|
||||
@@ -154,7 +262,13 @@ test("Mistral round-trips native reasoning in assistant history", async () => {
|
||||
{ role: "user", content: [{ type: "text", text: "Hello again" }] },
|
||||
],
|
||||
})
|
||||
expect(body?.messages?.[1]).toEqual({ role: "assistant", content: "thinkingHi" })
|
||||
expect(body?.messages?.[1]).toEqual({
|
||||
role: "assistant",
|
||||
content: [
|
||||
{ type: "thinking", thinking: [{ type: "text", text: "thinking" }], closed: true },
|
||||
{ type: "text", text: "Hi" },
|
||||
],
|
||||
})
|
||||
})
|
||||
|
||||
test("Mistral preserves native reasoning metadata while streaming", async () => {
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
"@ai-sdk/google": "3.0.73",
|
||||
"@ai-sdk/google-vertex": "4.0.181",
|
||||
"@ai-sdk/groq": "3.0.31",
|
||||
"@ai-sdk/mistral": "3.0.51",
|
||||
"@ai-sdk/mistral": "3.0.59",
|
||||
"@ai-sdk/openai": "3.0.84",
|
||||
"@ai-sdk/openai-compatible": "2.0.41",
|
||||
"@ai-sdk/perplexity": "3.0.26",
|
||||
|
||||
@@ -0,0 +1,629 @@
|
||||
diff --git a/dist/index.d.mts b/dist/index.d.mts
|
||||
index 1bde0b9f8cbe6771a52c1041095c9dddfe8e5b6c..1a37b06424a8176515836d473429ffa7d212267c 100644
|
||||
--- a/dist/index.d.mts
|
||||
+++ b/dist/index.d.mts
|
||||
@@ -10,10 +10,8 @@ declare const mistralLanguageModelOptions: z.ZodObject<{
|
||||
structuredOutputs: z.ZodOptional<z.ZodBoolean>;
|
||||
strictJsonSchema: z.ZodOptional<z.ZodBoolean>;
|
||||
parallelToolCalls: z.ZodOptional<z.ZodBoolean>;
|
||||
- reasoningEffort: z.ZodOptional<z.ZodEnum<{
|
||||
- none: "none";
|
||||
- high: "high";
|
||||
- }>>;
|
||||
+ reasoningEffort: z.ZodOptional<z.ZodString>;
|
||||
+ promptCacheKey: z.ZodOptional<z.ZodString>;
|
||||
}, z.core.$strip>;
|
||||
type MistralLanguageModelOptions = z.infer<typeof mistralLanguageModelOptions>;
|
||||
|
||||
diff --git a/dist/index.d.ts b/dist/index.d.ts
|
||||
index 1bde0b9f8cbe6771a52c1041095c9dddfe8e5b6c..1a37b06424a8176515836d473429ffa7d212267c 100644
|
||||
--- a/dist/index.d.ts
|
||||
+++ b/dist/index.d.ts
|
||||
@@ -10,10 +10,8 @@ declare const mistralLanguageModelOptions: z.ZodObject<{
|
||||
structuredOutputs: z.ZodOptional<z.ZodBoolean>;
|
||||
strictJsonSchema: z.ZodOptional<z.ZodBoolean>;
|
||||
parallelToolCalls: z.ZodOptional<z.ZodBoolean>;
|
||||
- reasoningEffort: z.ZodOptional<z.ZodEnum<{
|
||||
- none: "none";
|
||||
- high: "high";
|
||||
- }>>;
|
||||
+ reasoningEffort: z.ZodOptional<z.ZodString>;
|
||||
+ promptCacheKey: z.ZodOptional<z.ZodString>;
|
||||
}, z.core.$strip>;
|
||||
type MistralLanguageModelOptions = z.infer<typeof mistralLanguageModelOptions>;
|
||||
|
||||
diff --git a/dist/index.js b/dist/index.js
|
||||
index c1ce828c1f1e4f1890bf9119bfa082de177db5bf..96d158333040ba41804382f382302c0982eebf9c 100644
|
||||
--- a/dist/index.js
|
||||
+++ b/dist/index.js
|
||||
@@ -152,6 +152,11 @@ function convertToMistralChatMessages(prompt) {
|
||||
}
|
||||
case "reasoning": {
|
||||
hasReasoning = true;
|
||||
+ const native = part.providerOptions?.mistral?.thinking;
|
||||
+ if (native?.type === "thinking") {
|
||||
+ contentParts.push(native);
|
||||
+ break;
|
||||
+ }
|
||||
contentParts.push({
|
||||
type: "thinking",
|
||||
thinking: [{ type: "text", text: part.text }],
|
||||
@@ -277,7 +282,8 @@ var mistralLanguageModelOptions = import_v4.z.object({
|
||||
* - `'high'`: Enable reasoning
|
||||
* - `'none'`: Disable reasoning
|
||||
*/
|
||||
- reasoningEffort: import_v4.z.enum(["high", "none"]).optional()
|
||||
+ reasoningEffort: import_v4.z.string().optional(),
|
||||
+ promptCacheKey: import_v4.z.string().optional()
|
||||
});
|
||||
|
||||
// src/mistral-error.ts
|
||||
@@ -416,6 +422,7 @@ var MistralChatLanguageModel = class {
|
||||
stop: stopSequences,
|
||||
random_seed: seed,
|
||||
reasoning_effort: options.reasoningEffort,
|
||||
+ prompt_cache_key: options.promptCacheKey,
|
||||
// response format:
|
||||
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? structuredOutputs && (responseFormat == null ? void 0 : responseFormat.schema) != null ? {
|
||||
type: "json_schema",
|
||||
@@ -474,9 +481,11 @@ var MistralChatLanguageModel = class {
|
||||
for (const part of choice.message.content) {
|
||||
if (part.type === "thinking") {
|
||||
const reasoningText = extractReasoningContent(part.thinking);
|
||||
- if (reasoningText.length > 0) {
|
||||
- content.push({ type: "reasoning", text: reasoningText });
|
||||
- }
|
||||
+ content.push({
|
||||
+ type: "reasoning",
|
||||
+ text: reasoningText,
|
||||
+ providerMetadata: { mistral: { thinking: part } }
|
||||
+ });
|
||||
} else if (part.type === "text") {
|
||||
if (part.text.length > 0) {
|
||||
content.push({ type: "text", text: part.text });
|
||||
@@ -537,6 +546,7 @@ var MistralChatLanguageModel = class {
|
||||
let isFirstChunk = true;
|
||||
let activeText = false;
|
||||
let activeReasoningId = null;
|
||||
+ let activeThinking = null;
|
||||
const toolCalls = /* @__PURE__ */ new Set();
|
||||
const toolCallsById = /* @__PURE__ */ new Map();
|
||||
const toolCallsByIndex = /* @__PURE__ */ new Map();
|
||||
@@ -575,18 +585,19 @@ var MistralChatLanguageModel = class {
|
||||
for (const part of delta.content) {
|
||||
if (part.type === "thinking") {
|
||||
const reasoningDelta = extractReasoningContent(part.thinking);
|
||||
- if (reasoningDelta.length > 0) {
|
||||
- if (activeReasoningId == null) {
|
||||
- if (activeText) {
|
||||
- controller.enqueue({ type: "text-end", id: "0" });
|
||||
- activeText = false;
|
||||
- }
|
||||
- activeReasoningId = generateId2();
|
||||
- controller.enqueue({
|
||||
- type: "reasoning-start",
|
||||
- id: activeReasoningId
|
||||
- });
|
||||
+ activeThinking = mergeThinking(activeThinking, part);
|
||||
+ if (activeReasoningId == null) {
|
||||
+ if (activeText) {
|
||||
+ controller.enqueue({ type: "text-end", id: "0" });
|
||||
+ activeText = false;
|
||||
}
|
||||
+ activeReasoningId = generateId2();
|
||||
+ controller.enqueue({
|
||||
+ type: "reasoning-start",
|
||||
+ id: activeReasoningId
|
||||
+ });
|
||||
+ }
|
||||
+ if (reasoningDelta.length > 0) {
|
||||
controller.enqueue({
|
||||
type: "reasoning-delta",
|
||||
id: activeReasoningId,
|
||||
@@ -601,9 +612,11 @@ var MistralChatLanguageModel = class {
|
||||
if (activeReasoningId != null) {
|
||||
controller.enqueue({
|
||||
type: "reasoning-end",
|
||||
- id: activeReasoningId
|
||||
+ id: activeReasoningId,
|
||||
+ providerMetadata: { mistral: { thinking: activeThinking } }
|
||||
});
|
||||
activeReasoningId = null;
|
||||
+ activeThinking = null;
|
||||
}
|
||||
controller.enqueue({ type: "text-start", id: "0" });
|
||||
activeText = true;
|
||||
@@ -677,7 +690,8 @@ var MistralChatLanguageModel = class {
|
||||
if (activeReasoningId != null) {
|
||||
controller.enqueue({
|
||||
type: "reasoning-end",
|
||||
- id: activeReasoningId
|
||||
+ id: activeReasoningId,
|
||||
+ providerMetadata: { mistral: { thinking: activeThinking } }
|
||||
});
|
||||
}
|
||||
if (activeText) {
|
||||
@@ -711,6 +725,13 @@ var MistralChatLanguageModel = class {
|
||||
function extractReasoningContent(thinking) {
|
||||
return thinking.filter((chunk) => chunk.type === "text").map((chunk) => chunk.text).join("");
|
||||
}
|
||||
+function mergeThinking(current, next) {
|
||||
+ if (current === null) return { ...next, thinking: [...next.thinking] };
|
||||
+ current.thinking.push(...next.thinking);
|
||||
+ if (next.closed !== void 0) current.closed = next.closed;
|
||||
+ if (next.signature !== void 0) current.signature = next.signature;
|
||||
+ return current;
|
||||
+}
|
||||
function extractTextContent(content) {
|
||||
if (typeof content === "string") {
|
||||
return content;
|
||||
@@ -737,6 +758,30 @@ function extractTextContent(content) {
|
||||
}
|
||||
return textContent.length ? textContent.join("") : void 0;
|
||||
}
|
||||
+var mistralThinkingContentSchema = import_v43.z.discriminatedUnion("type", [
|
||||
+ import_v43.z.object({
|
||||
+ type: import_v43.z.literal("text"),
|
||||
+ text: import_v43.z.string()
|
||||
+ }),
|
||||
+ import_v43.z.object({
|
||||
+ type: import_v43.z.literal("tool_reference"),
|
||||
+ tool: import_v43.z.string(),
|
||||
+ title: import_v43.z.string(),
|
||||
+ url: import_v43.z.string().nullish(),
|
||||
+ favicon: import_v43.z.string().nullish(),
|
||||
+ description: import_v43.z.string().nullish()
|
||||
+ }),
|
||||
+ import_v43.z.object({
|
||||
+ type: import_v43.z.literal("reference"),
|
||||
+ reference_ids: import_v43.z.array(import_v43.z.union([import_v43.z.string(), import_v43.z.number().int()]))
|
||||
+ })
|
||||
+]);
|
||||
+var mistralThinkChunkSchema = import_v43.z.object({
|
||||
+ type: import_v43.z.literal("thinking"),
|
||||
+ thinking: import_v43.z.array(mistralThinkingContentSchema),
|
||||
+ closed: import_v43.z.boolean().optional(),
|
||||
+ signature: import_v43.z.string().nullish()
|
||||
+});
|
||||
var mistralContentSchema = import_v43.z.union([
|
||||
import_v43.z.string(),
|
||||
import_v43.z.array(
|
||||
@@ -759,15 +804,7 @@ var mistralContentSchema = import_v43.z.union([
|
||||
type: import_v43.z.literal("reference"),
|
||||
reference_ids: import_v43.z.array(import_v43.z.union([import_v43.z.string(), import_v43.z.number()]))
|
||||
}),
|
||||
- import_v43.z.object({
|
||||
- type: import_v43.z.literal("thinking"),
|
||||
- thinking: import_v43.z.array(
|
||||
- import_v43.z.object({
|
||||
- type: import_v43.z.literal("text"),
|
||||
- text: import_v43.z.string()
|
||||
- })
|
||||
- )
|
||||
- })
|
||||
+ mistralThinkChunkSchema
|
||||
])
|
||||
)
|
||||
]).nullish();
|
||||
diff --git a/dist/index.mjs b/dist/index.mjs
|
||||
index c7a1f1e5a229a999c9d6c522d0cf765d5a5ebe0b..674b9de49e1545d45b6015049365587c2f42364d 100644
|
||||
--- a/dist/index.mjs
|
||||
+++ b/dist/index.mjs
|
||||
@@ -142,6 +142,11 @@ function convertToMistralChatMessages(prompt) {
|
||||
}
|
||||
case "reasoning": {
|
||||
hasReasoning = true;
|
||||
+ const native = part.providerOptions?.mistral?.thinking;
|
||||
+ if (native?.type === "thinking") {
|
||||
+ contentParts.push(native);
|
||||
+ break;
|
||||
+ }
|
||||
contentParts.push({
|
||||
type: "thinking",
|
||||
thinking: [{ type: "text", text: part.text }],
|
||||
@@ -267,7 +272,8 @@ var mistralLanguageModelOptions = z.object({
|
||||
* - `'high'`: Enable reasoning
|
||||
* - `'none'`: Disable reasoning
|
||||
*/
|
||||
- reasoningEffort: z.enum(["high", "none"]).optional()
|
||||
+ reasoningEffort: z.string().optional(),
|
||||
+ promptCacheKey: z.string().optional()
|
||||
});
|
||||
|
||||
// src/mistral-error.ts
|
||||
@@ -408,6 +414,7 @@ var MistralChatLanguageModel = class {
|
||||
stop: stopSequences,
|
||||
random_seed: seed,
|
||||
reasoning_effort: options.reasoningEffort,
|
||||
+ prompt_cache_key: options.promptCacheKey,
|
||||
// response format:
|
||||
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? structuredOutputs && (responseFormat == null ? void 0 : responseFormat.schema) != null ? {
|
||||
type: "json_schema",
|
||||
@@ -466,9 +473,11 @@ var MistralChatLanguageModel = class {
|
||||
for (const part of choice.message.content) {
|
||||
if (part.type === "thinking") {
|
||||
const reasoningText = extractReasoningContent(part.thinking);
|
||||
- if (reasoningText.length > 0) {
|
||||
- content.push({ type: "reasoning", text: reasoningText });
|
||||
- }
|
||||
+ content.push({
|
||||
+ type: "reasoning",
|
||||
+ text: reasoningText,
|
||||
+ providerMetadata: { mistral: { thinking: part } }
|
||||
+ });
|
||||
} else if (part.type === "text") {
|
||||
if (part.text.length > 0) {
|
||||
content.push({ type: "text", text: part.text });
|
||||
@@ -529,6 +538,7 @@ var MistralChatLanguageModel = class {
|
||||
let isFirstChunk = true;
|
||||
let activeText = false;
|
||||
let activeReasoningId = null;
|
||||
+ let activeThinking = null;
|
||||
const toolCalls = /* @__PURE__ */ new Set();
|
||||
const toolCallsById = /* @__PURE__ */ new Map();
|
||||
const toolCallsByIndex = /* @__PURE__ */ new Map();
|
||||
@@ -567,18 +577,19 @@ var MistralChatLanguageModel = class {
|
||||
for (const part of delta.content) {
|
||||
if (part.type === "thinking") {
|
||||
const reasoningDelta = extractReasoningContent(part.thinking);
|
||||
- if (reasoningDelta.length > 0) {
|
||||
- if (activeReasoningId == null) {
|
||||
- if (activeText) {
|
||||
- controller.enqueue({ type: "text-end", id: "0" });
|
||||
- activeText = false;
|
||||
- }
|
||||
- activeReasoningId = generateId2();
|
||||
- controller.enqueue({
|
||||
- type: "reasoning-start",
|
||||
- id: activeReasoningId
|
||||
- });
|
||||
+ activeThinking = mergeThinking(activeThinking, part);
|
||||
+ if (activeReasoningId == null) {
|
||||
+ if (activeText) {
|
||||
+ controller.enqueue({ type: "text-end", id: "0" });
|
||||
+ activeText = false;
|
||||
}
|
||||
+ activeReasoningId = generateId2();
|
||||
+ controller.enqueue({
|
||||
+ type: "reasoning-start",
|
||||
+ id: activeReasoningId
|
||||
+ });
|
||||
+ }
|
||||
+ if (reasoningDelta.length > 0) {
|
||||
controller.enqueue({
|
||||
type: "reasoning-delta",
|
||||
id: activeReasoningId,
|
||||
@@ -593,9 +604,11 @@ var MistralChatLanguageModel = class {
|
||||
if (activeReasoningId != null) {
|
||||
controller.enqueue({
|
||||
type: "reasoning-end",
|
||||
- id: activeReasoningId
|
||||
+ id: activeReasoningId,
|
||||
+ providerMetadata: { mistral: { thinking: activeThinking } }
|
||||
});
|
||||
activeReasoningId = null;
|
||||
+ activeThinking = null;
|
||||
}
|
||||
controller.enqueue({ type: "text-start", id: "0" });
|
||||
activeText = true;
|
||||
@@ -669,7 +682,8 @@ var MistralChatLanguageModel = class {
|
||||
if (activeReasoningId != null) {
|
||||
controller.enqueue({
|
||||
type: "reasoning-end",
|
||||
- id: activeReasoningId
|
||||
+ id: activeReasoningId,
|
||||
+ providerMetadata: { mistral: { thinking: activeThinking } }
|
||||
});
|
||||
}
|
||||
if (activeText) {
|
||||
@@ -703,6 +717,13 @@ var MistralChatLanguageModel = class {
|
||||
function extractReasoningContent(thinking) {
|
||||
return thinking.filter((chunk) => chunk.type === "text").map((chunk) => chunk.text).join("");
|
||||
}
|
||||
+function mergeThinking(current, next) {
|
||||
+ if (current === null) return { ...next, thinking: [...next.thinking] };
|
||||
+ current.thinking.push(...next.thinking);
|
||||
+ if (next.closed !== void 0) current.closed = next.closed;
|
||||
+ if (next.signature !== void 0) current.signature = next.signature;
|
||||
+ return current;
|
||||
+}
|
||||
function extractTextContent(content) {
|
||||
if (typeof content === "string") {
|
||||
return content;
|
||||
@@ -729,6 +750,30 @@ function extractTextContent(content) {
|
||||
}
|
||||
return textContent.length ? textContent.join("") : void 0;
|
||||
}
|
||||
+var mistralThinkingContentSchema = z3.discriminatedUnion("type", [
|
||||
+ z3.object({
|
||||
+ type: z3.literal("text"),
|
||||
+ text: z3.string()
|
||||
+ }),
|
||||
+ z3.object({
|
||||
+ type: z3.literal("tool_reference"),
|
||||
+ tool: z3.string(),
|
||||
+ title: z3.string(),
|
||||
+ url: z3.string().nullish(),
|
||||
+ favicon: z3.string().nullish(),
|
||||
+ description: z3.string().nullish()
|
||||
+ }),
|
||||
+ z3.object({
|
||||
+ type: z3.literal("reference"),
|
||||
+ reference_ids: z3.array(z3.union([z3.string(), z3.number().int()]))
|
||||
+ })
|
||||
+]);
|
||||
+var mistralThinkChunkSchema = z3.object({
|
||||
+ type: z3.literal("thinking"),
|
||||
+ thinking: z3.array(mistralThinkingContentSchema),
|
||||
+ closed: z3.boolean().optional(),
|
||||
+ signature: z3.string().nullish()
|
||||
+});
|
||||
var mistralContentSchema = z3.union([
|
||||
z3.string(),
|
||||
z3.array(
|
||||
@@ -751,15 +796,7 @@ var mistralContentSchema = z3.union([
|
||||
type: z3.literal("reference"),
|
||||
reference_ids: z3.array(z3.union([z3.string(), z3.number()]))
|
||||
}),
|
||||
- z3.object({
|
||||
- type: z3.literal("thinking"),
|
||||
- thinking: z3.array(
|
||||
- z3.object({
|
||||
- type: z3.literal("text"),
|
||||
- text: z3.string()
|
||||
- })
|
||||
- )
|
||||
- })
|
||||
+ mistralThinkChunkSchema
|
||||
])
|
||||
)
|
||||
]).nullish();
|
||||
diff --git a/src/convert-to-mistral-chat-messages.ts b/src/convert-to-mistral-chat-messages.ts
|
||||
index f965c322d85d899df94d1c11820f6b99add7ec80..d6af945adacc5bb14bc5505c1d8e9f44bae510d8 100644
|
||||
--- a/src/convert-to-mistral-chat-messages.ts
|
||||
+++ b/src/convert-to-mistral-chat-messages.ts
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
import type {
|
||||
MistralAssistantMessageContent,
|
||||
MistralPrompt,
|
||||
+ MistralThinkChunk,
|
||||
} from './mistral-chat-prompt';
|
||||
import { convertToBase64 } from '@ai-sdk/provider-utils';
|
||||
|
||||
@@ -107,6 +108,12 @@ export function convertToMistralChatMessages(
|
||||
}
|
||||
case 'reasoning': {
|
||||
hasReasoning = true;
|
||||
+ const native = part.providerOptions?.mistral
|
||||
+ ?.thinking as MistralThinkChunk | undefined;
|
||||
+ if (native?.type === 'thinking') {
|
||||
+ contentParts.push(native);
|
||||
+ break;
|
||||
+ }
|
||||
contentParts.push({
|
||||
type: 'thinking',
|
||||
thinking: [{ type: 'text', text: part.text }],
|
||||
diff --git a/src/mistral-chat-language-model.ts b/src/mistral-chat-language-model.ts
|
||||
index 42b780264c5be03e1713dd95c4bb78af60e96fd2..e21d257815b1d47eff6f21a6ecd16f5ea75e2095 100644
|
||||
--- a/src/mistral-chat-language-model.ts
|
||||
+++ b/src/mistral-chat-language-model.ts
|
||||
@@ -123,6 +123,7 @@ export class MistralChatLanguageModel implements LanguageModelV3 {
|
||||
stop: stopSequences,
|
||||
random_seed: seed,
|
||||
reasoning_effort: options.reasoningEffort,
|
||||
+ prompt_cache_key: options.promptCacheKey,
|
||||
|
||||
// response format:
|
||||
response_format:
|
||||
@@ -202,9 +203,11 @@ export class MistralChatLanguageModel implements LanguageModelV3 {
|
||||
for (const part of choice.message.content) {
|
||||
if (part.type === 'thinking') {
|
||||
const reasoningText = extractReasoningContent(part.thinking);
|
||||
- if (reasoningText.length > 0) {
|
||||
- content.push({ type: 'reasoning', text: reasoningText });
|
||||
- }
|
||||
+ content.push({
|
||||
+ type: 'reasoning',
|
||||
+ text: reasoningText,
|
||||
+ providerMetadata: { mistral: { thinking: part } },
|
||||
+ });
|
||||
} else if (part.type === 'text') {
|
||||
if (part.text.length > 0) {
|
||||
content.push({ type: 'text', text: part.text });
|
||||
@@ -279,6 +282,7 @@ export class MistralChatLanguageModel implements LanguageModelV3 {
|
||||
let isFirstChunk = true;
|
||||
let activeText = false;
|
||||
let activeReasoningId: string | null = null;
|
||||
+ let activeThinking: z.infer<typeof mistralThinkChunkSchema> | null = null;
|
||||
const toolCalls = new Set<{
|
||||
id: string;
|
||||
name: string;
|
||||
@@ -341,20 +345,21 @@ export class MistralChatLanguageModel implements LanguageModelV3 {
|
||||
for (const part of delta.content) {
|
||||
if (part.type === 'thinking') {
|
||||
const reasoningDelta = extractReasoningContent(part.thinking);
|
||||
- if (reasoningDelta.length > 0) {
|
||||
- if (activeReasoningId == null) {
|
||||
- // end any active text before starting reasoning
|
||||
- if (activeText) {
|
||||
- controller.enqueue({ type: 'text-end', id: '0' });
|
||||
- activeText = false;
|
||||
- }
|
||||
-
|
||||
- activeReasoningId = generateId();
|
||||
- controller.enqueue({
|
||||
- type: 'reasoning-start',
|
||||
- id: activeReasoningId,
|
||||
- });
|
||||
+ activeThinking = mergeThinking(activeThinking, part);
|
||||
+ if (activeReasoningId == null) {
|
||||
+ // end any active text before starting reasoning
|
||||
+ if (activeText) {
|
||||
+ controller.enqueue({ type: 'text-end', id: '0' });
|
||||
+ activeText = false;
|
||||
}
|
||||
+
|
||||
+ activeReasoningId = generateId();
|
||||
+ controller.enqueue({
|
||||
+ type: 'reasoning-start',
|
||||
+ id: activeReasoningId,
|
||||
+ });
|
||||
+ }
|
||||
+ if (reasoningDelta.length > 0) {
|
||||
controller.enqueue({
|
||||
type: 'reasoning-delta',
|
||||
id: activeReasoningId,
|
||||
@@ -372,8 +377,12 @@ export class MistralChatLanguageModel implements LanguageModelV3 {
|
||||
controller.enqueue({
|
||||
type: 'reasoning-end',
|
||||
id: activeReasoningId,
|
||||
+ providerMetadata: {
|
||||
+ mistral: { thinking: activeThinking },
|
||||
+ },
|
||||
});
|
||||
activeReasoningId = null;
|
||||
+ activeThinking = null;
|
||||
}
|
||||
controller.enqueue({ type: 'text-start', id: '0' });
|
||||
activeText = true;
|
||||
@@ -463,6 +472,9 @@ export class MistralChatLanguageModel implements LanguageModelV3 {
|
||||
controller.enqueue({
|
||||
type: 'reasoning-end',
|
||||
id: activeReasoningId,
|
||||
+ providerMetadata: {
|
||||
+ mistral: { thinking: activeThinking },
|
||||
+ },
|
||||
});
|
||||
}
|
||||
if (activeText) {
|
||||
@@ -497,7 +509,7 @@ export class MistralChatLanguageModel implements LanguageModelV3 {
|
||||
}
|
||||
|
||||
function extractReasoningContent(
|
||||
- thinking: Array<{ type: string; text: string }>,
|
||||
+ thinking: Array<z.infer<typeof mistralThinkingContentSchema>>,
|
||||
) {
|
||||
return thinking
|
||||
.filter(chunk => chunk.type === 'text')
|
||||
@@ -505,6 +517,17 @@ function extractReasoningContent(
|
||||
.join('');
|
||||
}
|
||||
|
||||
+function mergeThinking(
|
||||
+ current: z.infer<typeof mistralThinkChunkSchema> | null,
|
||||
+ next: z.infer<typeof mistralThinkChunkSchema>,
|
||||
+) {
|
||||
+ if (current === null) return { ...next, thinking: [...next.thinking] };
|
||||
+ current.thinking.push(...next.thinking);
|
||||
+ if (next.closed !== undefined) current.closed = next.closed;
|
||||
+ if (next.signature !== undefined) current.signature = next.signature;
|
||||
+ return current;
|
||||
+}
|
||||
+
|
||||
function extractTextContent(content: z.infer<typeof mistralContentSchema>) {
|
||||
if (typeof content === 'string') {
|
||||
return content;
|
||||
@@ -538,6 +561,32 @@ function extractTextContent(content: z.infer<typeof mistralContentSchema>) {
|
||||
return textContent.length ? textContent.join('') : undefined;
|
||||
}
|
||||
|
||||
+const mistralThinkingContentSchema = z.discriminatedUnion('type', [
|
||||
+ z.object({
|
||||
+ type: z.literal('text'),
|
||||
+ text: z.string(),
|
||||
+ }),
|
||||
+ z.object({
|
||||
+ type: z.literal('tool_reference'),
|
||||
+ tool: z.string(),
|
||||
+ title: z.string(),
|
||||
+ url: z.string().nullish(),
|
||||
+ favicon: z.string().nullish(),
|
||||
+ description: z.string().nullish(),
|
||||
+ }),
|
||||
+ z.object({
|
||||
+ type: z.literal('reference'),
|
||||
+ reference_ids: z.array(z.union([z.string(), z.number().int()])),
|
||||
+ }),
|
||||
+]);
|
||||
+
|
||||
+const mistralThinkChunkSchema = z.object({
|
||||
+ type: z.literal('thinking'),
|
||||
+ thinking: z.array(mistralThinkingContentSchema),
|
||||
+ closed: z.boolean().optional(),
|
||||
+ signature: z.string().nullish(),
|
||||
+});
|
||||
+
|
||||
const mistralContentSchema = z
|
||||
.union([
|
||||
z.string(),
|
||||
@@ -561,15 +610,7 @@ const mistralContentSchema = z
|
||||
type: z.literal('reference'),
|
||||
reference_ids: z.array(z.union([z.string(), z.number()])),
|
||||
}),
|
||||
- z.object({
|
||||
- type: z.literal('thinking'),
|
||||
- thinking: z.array(
|
||||
- z.object({
|
||||
- type: z.literal('text'),
|
||||
- text: z.string(),
|
||||
- }),
|
||||
- ),
|
||||
- }),
|
||||
+ mistralThinkChunkSchema,
|
||||
]),
|
||||
),
|
||||
])
|
||||
diff --git a/src/mistral-chat-options.ts b/src/mistral-chat-options.ts
|
||||
index 54b29c08517d348995b6ca093b11160e453d5c8b..ef23b4fccea1b0580f2130b3ce37a930f5840aa8 100644
|
||||
--- a/src/mistral-chat-options.ts
|
||||
+++ b/src/mistral-chat-options.ts
|
||||
@@ -63,7 +63,12 @@ export const mistralLanguageModelOptions = z.object({
|
||||
* - `'high'`: Enable reasoning
|
||||
* - `'none'`: Disable reasoning
|
||||
*/
|
||||
- reasoningEffort: z.enum(['high', 'none']).optional(),
|
||||
+ reasoningEffort: z.string().optional(),
|
||||
+
|
||||
+ /**
|
||||
+ * A stable identifier used to route requests with shared prompt prefixes.
|
||||
+ */
|
||||
+ promptCacheKey: z.string().optional(),
|
||||
});
|
||||
|
||||
export type MistralLanguageModelOptions = z.infer<
|
||||
diff --git a/src/mistral-chat-prompt.ts b/src/mistral-chat-prompt.ts
|
||||
index 0555168b9c1bef3a952ab66ad03dd347f50dc30b..172b11dde3dd326c2f3befd99237474ed8c79285 100644
|
||||
--- a/src/mistral-chat-prompt.ts
|
||||
+++ b/src/mistral-chat-prompt.ts
|
||||
@@ -33,12 +33,27 @@ export interface MistralAssistantMessage {
|
||||
}
|
||||
|
||||
export type MistralAssistantMessageContent =
|
||||
+ | { type: 'text'; text: string }
|
||||
+ | MistralThinkChunk;
|
||||
+
|
||||
+export type MistralThinkChunk = {
|
||||
+ type: 'thinking';
|
||||
+ thinking: Array<MistralThinkingContent>;
|
||||
+ closed?: boolean;
|
||||
+ signature?: string | null;
|
||||
+};
|
||||
+
|
||||
+export type MistralThinkingContent =
|
||||
| { type: 'text'; text: string }
|
||||
| {
|
||||
- type: 'thinking';
|
||||
- thinking: Array<{ type: 'text'; text: string }>;
|
||||
- closed: true;
|
||||
- };
|
||||
+ type: 'tool_reference';
|
||||
+ tool: string;
|
||||
+ title: string;
|
||||
+ url?: string | null;
|
||||
+ favicon?: string | null;
|
||||
+ description?: string | null;
|
||||
+ }
|
||||
+ | { type: 'reference'; reference_ids: Array<string | number> };
|
||||
|
||||
export interface MistralToolMessage {
|
||||
role: 'tool';
|
||||
Reference in New Issue
Block a user