fix(provider): serialize Mistral prompt cache keys (#38448)

This commit is contained in:
Aiden Cline 2026-07-22 22:53:51 -05:00 committed by GitHub
commit fada1a538f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 128 additions and 6 deletions

View file

@ -0,0 +1,28 @@
import { createMistral } from "@ai-sdk/mistral"
import { expect, test } from "bun:test"
test("Mistral sends promptCacheKey as prompt_cache_key", async () => {
let body: Record<string, unknown> | undefined
const mockFetch = Object.assign(
async (_input: Parameters<typeof fetch>[0], init?: RequestInit) => {
body = JSON.parse(String(init?.body))
return Response.json({
id: "response-1",
created: 0,
model: "mistral-large-latest",
object: "chat.completion",
choices: [{ index: 0, message: { role: "assistant", content: "Hello" }, finish_reason: "stop" }],
usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 },
})
},
{ preconnect: fetch.preconnect },
)
const model = createMistral({ apiKey: "test", fetch: mockFetch })("mistral-large-latest")
await model.doGenerate({
prompt: [{ role: "user", content: [{ type: "text", text: "Hello" }] }],
providerOptions: { mistral: { promptCacheKey: "session-123" } },
})
expect(body?.prompt_cache_key).toBe("session-123")
})