GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(provider): preserve Mistral reasoning history (#38453) · argszero/opencode@20589d6

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • bun.lock
  • package.json
  • packages
    • core
      • package.json
      • test
        • provider-mistral.test.ts
    • opencode
      • package.json
      • test/session
        • llm.test.ts
  • patches
    • @ai-sdk%[email protected]
    • @ai-sdk%[email protected]
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎bun.lock‎

Copy file name to clipboardExpand all lines: bun.lock
+7-7Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎package.json‎

Copy file name to clipboardExpand all lines: package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
"@standard-community/[email protected]": "patches/@standard-community%[email protected]",
150150
"[email protected]": "patches/[email protected]",
151151
"@ai-sdk/[email protected]": "patches/@ai-sdk%[email protected]",
152-
"@ai-sdk/[email protected].34": "patches/@ai-sdk%[email protected].34.patch",
152+
"@ai-sdk/[email protected].51": "patches/@ai-sdk%[email protected].51.patch",
153153
"[email protected]": "patches/[email protected]",
154154
"[email protected]": "patches/[email protected]",
155155
"@ai-sdk/[email protected]": "patches/@ai-sdk%[email protected]",
Collapse file

‎packages/core/package.json‎

Copy file name to clipboardExpand all lines: packages/core/package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"@ai-sdk/google": "3.0.73",
7373
"@ai-sdk/google-vertex": "4.0.128",
7474
"@ai-sdk/groq": "3.0.31",
75-
"@ai-sdk/mistral": "3.0.34",
75+
"@ai-sdk/mistral": "3.0.51",
7676
"@ai-sdk/openai": "3.0.84",
7777
"@ai-sdk/openai-compatible": "2.0.41",
7878
"@ai-sdk/perplexity": "3.0.26",
Collapse file

‎packages/core/test/provider-mistral.test.ts‎

Copy file name to clipboardExpand all lines: packages/core/test/provider-mistral.test.ts
+254Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,257 @@ test("Mistral sends promptCacheKey as prompt_cache_key", async () => {
2626

2727
expect(body?.prompt_cache_key).toBe("session-123")
2828
})
29+
30+
test("Mistral round-trips native reasoning in assistant history", async () => {
31+
let body: { messages?: unknown[] } | undefined
32+
const mockFetch = Object.assign(
33+
async (_input: Parameters<typeof fetch>[0], init?: RequestInit) => {
34+
body = JSON.parse(String(init?.body))
35+
return Response.json({
36+
id: "response-1",
37+
created: 0,
38+
model: "mistral-small-latest",
39+
object: "chat.completion",
40+
choices: [
41+
{
42+
index: 0,
43+
message: {
44+
role: "assistant",
45+
content: [
46+
{
47+
type: "thinking",
48+
thinking: [
49+
{ type: "text", text: "The user is greeting me." },
50+
{
51+
type: "tool_reference",
52+
tool: "web_search",
53+
title: "Example result",
54+
url: "https://example.com/tool",
55+
favicon: "https://example.com/favicon.ico",
56+
description: "Example description",
57+
},
58+
{ type: "reference", reference_ids: [1, "source-2"] },
59+
],
60+
closed: true,
61+
signature: "sig-123",
62+
},
63+
{ type: "text", text: "Hi" },
64+
],
65+
},
66+
finish_reason: "stop",
67+
},
68+
],
69+
usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 },
70+
})
71+
},
72+
{ preconnect: fetch.preconnect },
73+
)
74+
const model = createMistral({ apiKey: "test", fetch: mockFetch })("mistral-small-latest")
75+
76+
const first = await model.doGenerate({
77+
prompt: [{ role: "user", content: [{ type: "text", text: "Hello" }] }],
78+
})
79+
const reasoning = first.content.find((part) => part.type === "reasoning")
80+
const text = first.content.find((part) => part.type === "text")
81+
if (!reasoning || !text) throw new Error("expected reasoning and text")
82+
83+
await model.doGenerate({
84+
prompt: [
85+
{ role: "user", content: [{ type: "text", text: "Hello" }] },
86+
{
87+
role: "assistant",
88+
content: [{ ...reasoning, providerOptions: reasoning.providerMetadata }, text],
89+
},
90+
{ role: "user", content: [{ type: "text", text: "Hello again" }] },
91+
],
92+
})
93+
94+
expect(body?.messages?.[1]).toEqual({
95+
role: "assistant",
96+
content: [
97+
{
98+
type: "thinking",
99+
thinking: [
100+
{ type: "text", text: "The user is greeting me." },
101+
{
102+
type: "tool_reference",
103+
tool: "web_search",
104+
title: "Example result",
105+
url: "https://example.com/tool",
106+
favicon: "https://example.com/favicon.ico",
107+
description: "Example description",
108+
},
109+
{ type: "reference", reference_ids: [1, "source-2"] },
110+
],
111+
closed: true,
112+
signature: "sig-123",
113+
},
114+
{ type: "text", text: "Hi" },
115+
],
116+
})
117+
118+
await model.doGenerate({
119+
prompt: [
120+
{ role: "user", content: [{ type: "text", text: "Hello" }] },
121+
{
122+
role: "assistant",
123+
content: [
124+
{ type: "reasoning", text: "thinking" },
125+
{ type: "text", text: "Hi" },
126+
],
127+
},
128+
{ role: "user", content: [{ type: "text", text: "Hello again" }] },
129+
],
130+
})
131+
expect(body?.messages?.[1]).toEqual({ role: "assistant", content: "thinkingHi" })
132+
})
133+
134+
test("Mistral preserves native reasoning metadata while streaming", async () => {
135+
const chunks = [
136+
{
137+
id: "response-1",
138+
created: 0,
139+
model: "mistral-small-latest",
140+
choices: [
141+
{
142+
index: 0,
143+
delta: {
144+
role: "assistant",
145+
content: [
146+
{
147+
type: "thinking",
148+
thinking: [
149+
{ type: "text", text: "thinking" },
150+
{
151+
type: "tool_reference",
152+
tool: "web_search",
153+
title: "Example result",
154+
url: "https://example.com/tool",
155+
favicon: "https://example.com/favicon.ico",
156+
description: "Example description",
157+
},
158+
],
159+
},
160+
],
161+
},
162+
},
163+
],
164+
},
165+
{
166+
id: "response-1",
167+
created: 0,
168+
model: "mistral-small-latest",
169+
choices: [
170+
{
171+
index: 0,
172+
delta: {
173+
content: [
174+
{
175+
type: "thinking",
176+
thinking: [{ type: "reference", reference_ids: [1, "source-2"] }],
177+
closed: true,
178+
signature: "sig-123",
179+
},
180+
],
181+
},
182+
},
183+
],
184+
},
185+
{
186+
id: "response-1",
187+
created: 0,
188+
model: "mistral-small-latest",
189+
choices: [{ index: 0, delta: { content: [{ type: "text", text: "answer" }] } }],
190+
},
191+
{
192+
id: "response-1",
193+
created: 0,
194+
model: "mistral-small-latest",
195+
choices: [{ index: 0, delta: {}, finish_reason: "stop" }],
196+
usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 },
197+
},
198+
]
199+
const mockFetch = Object.assign(
200+
async () =>
201+
new Response(chunks.map((chunk) => `data: ${JSON.stringify(chunk)}\n\n`).join(""), {
202+
headers: { "Content-Type": "text/event-stream" },
203+
}),
204+
{ preconnect: fetch.preconnect },
205+
)
206+
const model = createMistral({ apiKey: "test", fetch: mockFetch })("mistral-small-latest")
207+
const result = await model.doStream({
208+
prompt: [{ role: "user", content: [{ type: "text", text: "Hello" }] }],
209+
})
210+
const events = []
211+
for await (const event of result.stream) events.push(event)
212+
213+
expect(events.find((event) => event.type === "reasoning-end")?.providerMetadata).toEqual({
214+
mistral: {
215+
thinking: {
216+
type: "thinking",
217+
thinking: [
218+
{ type: "text", text: "thinking" },
219+
{
220+
type: "tool_reference",
221+
tool: "web_search",
222+
title: "Example result",
223+
url: "https://example.com/tool",
224+
favicon: "https://example.com/favicon.ico",
225+
description: "Example description",
226+
},
227+
{ type: "reference", reference_ids: [1, "source-2"] },
228+
],
229+
closed: true,
230+
signature: "sig-123",
231+
},
232+
},
233+
})
234+
expect(
235+
events
236+
.filter((event) => event.type === "reasoning-start" || event.type === "reasoning-delta")
237+
.every((event) => event.providerMetadata === undefined),
238+
).toBe(true)
239+
})
240+
241+
test("Mistral preserves metadata-only thinking chunks", async () => {
242+
const thinking = {
243+
type: "thinking" as const,
244+
thinking: [
245+
{
246+
type: "tool_reference",
247+
tool: "web_search",
248+
title: "Example result",
249+
url: "https://example.com/tool",
250+
favicon: "https://example.com/favicon.ico",
251+
description: "Example description",
252+
},
253+
{ type: "reference", reference_ids: [1, "source-2"] },
254+
],
255+
closed: true,
256+
signature: "sig-123",
257+
}
258+
const mockFetch = Object.assign(
259+
async () =>
260+
Response.json({
261+
id: "response-1",
262+
created: 0,
263+
model: "mistral-small-latest",
264+
object: "chat.completion",
265+
choices: [{ index: 0, message: { role: "assistant", content: [thinking] }, finish_reason: "stop" }],
266+
usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 },
267+
}),
268+
{ preconnect: fetch.preconnect },
269+
)
270+
const model = createMistral({ apiKey: "test", fetch: mockFetch })("mistral-small-latest")
271+
const result = await model.doGenerate({
272+
prompt: [{ role: "user", content: [{ type: "text", text: "Hello" }] }],
273+
})
274+
275+
expect(result.content).toEqual([
276+
{
277+
type: "reasoning",
278+
text: "",
279+
providerMetadata: { mistral: { thinking } },
280+
},
281+
])
282+
})
Collapse file

‎packages/opencode/package.json‎

Copy file name to clipboardExpand all lines: packages/opencode/package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"@ai-sdk/google": "3.0.73",
6767
"@ai-sdk/google-vertex": "4.0.128",
6868
"@ai-sdk/groq": "3.0.31",
69-
"@ai-sdk/mistral": "3.0.34",
69+
"@ai-sdk/mistral": "3.0.51",
7070
"@ai-sdk/openai": "3.0.84",
7171
"@ai-sdk/openai-compatible": "2.0.41",
7272
"@ai-sdk/perplexity": "3.0.26",

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.