GeezerVison is showing github.com — fix(provider): serialize Mistral prompt cache keys (#38448) · argszero/opencode@fada1a5
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: bun.lock +13-4Lines changed: 13 additions & 4 deletions Collapse file Copy file name to clipboardExpand all lines: package.json +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 149 | 149 | | 150 | 150 | | 151 | 151 | | | 152 | + | 152 | 153 | | 153 | 154 | | 154 | 155 | | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/package.json +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 72 | 72 | "@ai-sdk/google": "3.0.73", | 73 | 73 | "@ai-sdk/google-vertex": "4.0.128", | 74 | 74 | "@ai-sdk/groq": "3.0.31", | 75 | | - "@ai-sdk/mistral": "3.0.27", | | 75 | + "@ai-sdk/mistral": "3.0.34", | 76 | 76 | "@ai-sdk/openai": "3.0.84", | 77 | 77 | "@ai-sdk/openai-compatible": "2.0.41", | 78 | 78 | "@ai-sdk/perplexity": "3.0.26", | |
Collapse file Copy file name to clipboard +28Lines changed: 28 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { createMistral } from "@ai-sdk/mistral" | | 2 | +import { expect, test } from "bun:test" | | 3 | + | | 4 | +test("Mistral sends promptCacheKey as prompt_cache_key", async () => { | | 5 | + let body: Record<string, unknown> | undefined | | 6 | + const mockFetch = Object.assign( | | 7 | + async (_input: Parameters<typeof fetch>[0], init?: RequestInit) => { | | 8 | + body = JSON.parse(String(init?.body)) | | 9 | + return Response.json({ | | 10 | + id: "response-1", | | 11 | + created: 0, | | 12 | + model: "mistral-large-latest", | | 13 | + object: "chat.completion", | | 14 | + choices: [{ index: 0, message: { role: "assistant", content: "Hello" }, finish_reason: "stop" }], | | 15 | + usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 }, | | 16 | + }) | | 17 | + }, | | 18 | + { preconnect: fetch.preconnect }, | | 19 | + ) | | 20 | + const model = createMistral({ apiKey: "test", fetch: mockFetch })("mistral-large-latest") | | 21 | + | | 22 | + await model.doGenerate({ | | 23 | + prompt: [{ role: "user", content: [{ type: "text", text: "Hello" }] }], | | 24 | + providerOptions: { mistral: { promptCacheKey: "session-123" } }, | | 25 | + }) | | 26 | + | | 27 | + expect(body?.prompt_cache_key).toBe("session-123") | | 28 | +}) |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/package.json +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 66 | 66 | "@ai-sdk/google": "3.0.73", | 67 | 67 | "@ai-sdk/google-vertex": "4.0.128", | 68 | 68 | "@ai-sdk/groq": "3.0.31", | 69 | | - "@ai-sdk/mistral": "3.0.27", | | 69 | + "@ai-sdk/mistral": "3.0.34", | 70 | 70 | "@ai-sdk/openai": "3.0.84", | 71 | 71 | "@ai-sdk/openai-compatible": "2.0.41", | 72 | 72 | "@ai-sdk/perplexity": "3.0.26", | |
Collapse file Copy file name to clipboard +84Lines changed: 84 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +diff --git a/dist/index.d.ts b/dist/index.d.ts | | 2 | +index 1ca9113bed2728a616db773a8e08d8d6957447d7..15408ec429dc210b5fa43589d81b69c93bf27b2d 100644 | | 3 | +--- a/dist/index.d.ts | | 4 | ++++ b/dist/index.d.ts | | 5 | +@@ -14,6 +14,7 @@ declare const mistralLanguageModelOptions: z.ZodObject<{ | | 6 | + none: "none"; | | 7 | + high: "high"; | | 8 | + }>>; | | 9 | ++ promptCacheKey: z.ZodOptional<z.ZodString>; | | 10 | + }, z.core.$strip>; | | 11 | + type MistralLanguageModelOptions = z.infer<typeof mistralLanguageModelOptions>; | | 12 | + | | 13 | +diff --git a/dist/index.js b/dist/index.js | | 14 | +index 45735e524aaff54ea058c99c729c5ffd3c507058..6aca5f6f13da0054ede31c1f1a692e4eaed37d34 100644 | | 15 | +--- a/dist/index.js | | 16 | ++++ b/dist/index.js | | 17 | +@@ -268,7 +268,8 @@ var mistralLanguageModelOptions = import_v4.z.object({ | | 18 | + * - `'high'`: Enable reasoning | | 19 | + * - `'none'`: Disable reasoning | | 20 | + */ | | 21 | +- reasoningEffort: import_v4.z.enum(["high", "none"]).optional() | | 22 | ++ reasoningEffort: import_v4.z.enum(["high", "none"]).optional(), | | 23 | ++ promptCacheKey: import_v4.z.string().optional() | | 24 | + }); | | 25 | + | | 26 | + // src/mistral-error.ts | | 27 | +@@ -413,6 +414,7 @@ var MistralChatLanguageModel = class { | | 28 | + top_p: topP, | | 29 | + random_seed: seed, | | 30 | + reasoning_effort: options.reasoningEffort, | | 31 | ++ prompt_cache_key: options.promptCacheKey, | | 32 | + // response format: | | 33 | + response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? structuredOutputs && (responseFormat == null ? void 0 : responseFormat.schema) != null ? { | | 34 | + type: "json_schema", | | 35 | +diff --git a/dist/index.mjs b/dist/index.mjs | | 36 | +index 4c22df1cd78a1ba81309c8a86ceecefef4ba4aea..30cd3b1f503860109b7fa2107cd1eb17b70c96be 100644 | | 37 | +--- a/dist/index.mjs | | 38 | ++++ b/dist/index.mjs | | 39 | +@@ -256,7 +256,8 @@ var mistralLanguageModelOptions = z.object({ | | 40 | + * - `'high'`: Enable reasoning | | 41 | + * - `'none'`: Disable reasoning | | 42 | + */ | | 43 | +- reasoningEffort: z.enum(["high", "none"]).optional() | | 44 | ++ reasoningEffort: z.enum(["high", "none"]).optional(), | | 45 | ++ promptCacheKey: z.string().optional() | | 46 | + }); | | 47 | + | | 48 | + // src/mistral-error.ts | | 49 | +@@ -403,6 +404,7 @@ var MistralChatLanguageModel = class { | | 50 | + top_p: topP, | | 51 | + random_seed: seed, | | 52 | + reasoning_effort: options.reasoningEffort, | | 53 | ++ prompt_cache_key: options.promptCacheKey, | | 54 | + // response format: | | 55 | + response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? structuredOutputs && (responseFormat == null ? void 0 : responseFormat.schema) != null ? { | | 56 | + type: "json_schema", | | 57 | +diff --git a/src/mistral-chat-language-model.ts b/src/mistral-chat-language-model.ts | | 58 | +index 480c472d534bedbe8897979673453bd1c29a70b7..e46496da94f7d4af9822897202ca6baae67dae3a 100644 | | 59 | +--- a/src/mistral-chat-language-model.ts | | 60 | ++++ b/src/mistral-chat-language-model.ts | | 61 | +@@ -129,6 +129,7 @@ export class MistralChatLanguageModel implements LanguageModelV3 { | | 62 | + top_p: topP, | | 63 | + random_seed: seed, | | 64 | + reasoning_effort: options.reasoningEffort, | | 65 | ++ prompt_cache_key: options.promptCacheKey, | | 66 | + | | 67 | + // response format: | | 68 | + response_format: | | 69 | +diff --git a/src/mistral-chat-options.ts b/src/mistral-chat-options.ts | | 70 | +index 80fff45fba2c378fa06962f071946bcd2b882a0b..b4fdfa51f3bf11a4220e010c8aca92482cb0c3db 100644 | | 71 | +--- a/src/mistral-chat-options.ts | | 72 | ++++ b/src/mistral-chat-options.ts | | 73 | +@@ -62,6 +62,11 @@ export const mistralLanguageModelOptions = z.object({ | | 74 | + * - `'none'`: Disable reasoning | | 75 | + */ | | 76 | + reasoningEffort: z.enum(['high', 'none']).optional(), | | 77 | ++ | | 78 | ++ /** | | 79 | ++ * A stable identifier used to route requests with shared prompt prefixes. | | 80 | ++ */ | | 81 | ++ promptCacheKey: z.string().optional(), | | 82 | + }); | | 83 | + | | 84 | + export type MistralLanguageModelOptions = z.infer< |
|