GeezerVison is showing github.com — chore: sync 11 low-risk upstream provider/reliability fixes from anom… · Draugur-AI/opencode@cd0bd27
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 +1Lines changed: 1 addition & 0 deletions Collapse file Copy file name to clipboardExpand all lines: package.json +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 159 | 159 | | 160 | 160 | | 161 | 161 | | 162 | | - | | 162 | + | | 163 | + | 163 | 164 | } | 164 | 165 | } |
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 { createGroq } from "@ai-sdk/groq" | | 2 | +import { expect, test } from "bun:test" | | 3 | + | | 4 | +test("Groq passes through unknown reasoning effort", 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: "openai/gpt-oss-120b", | | 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 = createGroq({ apiKey: "test", fetch: mockFetch })("openai/gpt-oss-120b") | | 21 | + | | 22 | + await model.doGenerate({ | | 23 | + prompt: [{ role: "user", content: [{ type: "text", text: "Hello" }] }], | | 24 | + providerOptions: { groq: { reasoningEffort: "custom" } }, | | 25 | + }) | | 26 | + | | 27 | + expect(body?.reasoning_effort).toBe("custom") | | 28 | +}) |
Collapse file Copy file name to clipboardExpand all lines: packages/core/test/provider-mistral.test.ts +26Lines changed: 26 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -27,6 +27,32 @@ test("Mistral sends promptCacheKey as prompt_cache_key", async () => { | 27 | 27 | expect(body?.prompt_cache_key).toBe("session-123") | 28 | 28 | }) | 29 | 29 |
| | 30 | +test("Mistral passes through unknown reasoning effort", async () => { | | 31 | + let body: Record<string, 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-large-latest", | | 39 | + object: "chat.completion", | | 40 | + choices: [{ index: 0, message: { role: "assistant", content: "Hello" }, finish_reason: "stop" }], | | 41 | + usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 }, | | 42 | + }) | | 43 | + }, | | 44 | + { preconnect: fetch.preconnect }, | | 45 | + ) | | 46 | + const model = createMistral({ apiKey: "test", fetch: mockFetch })("mistral-large-latest") | | 47 | + | | 48 | + await model.doGenerate({ | | 49 | + prompt: [{ role: "user", content: [{ type: "text", text: "Hello" }] }], | | 50 | + providerOptions: { mistral: { reasoningEffort: "custom" } }, | | 51 | + }) | | 52 | + | | 53 | + expect(body?.reasoning_effort).toBe("custom") | | 54 | +}) | | 55 | + | 30 | 56 | test("Mistral round-trips native reasoning in assistant history", async () => { | 31 | 57 | let body: { messages?: unknown[] } | undefined | 32 | 58 | const mockFetch = Object.assign( | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/test/provider-xai-responses.test.ts +53Lines changed: 53 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -30,3 +30,56 @@ test("xAI Responses sends promptCacheKey as prompt_cache_key", async () => { | 30 | 30 |
| 31 | 31 | expect(body?.prompt_cache_key).toBe("session-123") | 32 | 32 | }) | | 33 | + | | 34 | +test("xAI Responses passes through xhigh reasoning effort", async () => { | | 35 | + let body: Record<string, unknown> | undefined | | 36 | + const mockFetch = Object.assign( | | 37 | + async (_input: Parameters<typeof fetch>[0], init?: RequestInit) => { | | 38 | + body = JSON.parse(String(init?.body)) | | 39 | + return Response.json({ | | 40 | + id: "response-1", | | 41 | + created_at: 0, | | 42 | + model: "grok-4", | | 43 | + object: "response", | | 44 | + output: [], | | 45 | + usage: { input_tokens: 1, output_tokens: 0 }, | | 46 | + status: "completed", | | 47 | + }) | | 48 | + }, | | 49 | + { preconnect: fetch.preconnect }, | | 50 | + ) | | 51 | + const model = createXai({ apiKey: "test", fetch: mockFetch }).responses("grok-4") | | 52 | + | | 53 | + await model.doGenerate({ | | 54 | + prompt: [{ role: "user", content: [{ type: "text", text: "Hello" }] }], | | 55 | + providerOptions: { xai: { reasoningEffort: "xhigh" } }, | | 56 | + }) | | 57 | + | | 58 | + expect(body?.reasoning).toEqual({ effort: "xhigh" }) | | 59 | +}) | | 60 | + | | 61 | +test("xAI Chat passes through xhigh reasoning effort", async () => { | | 62 | + let body: Record<string, unknown> | undefined | | 63 | + const mockFetch = Object.assign( | | 64 | + async (_input: Parameters<typeof fetch>[0], init?: RequestInit) => { | | 65 | + body = JSON.parse(String(init?.body)) | | 66 | + return Response.json({ | | 67 | + id: "chat-1", | | 68 | + created: 0, | | 69 | + model: "grok-4", | | 70 | + object: "chat.completion", | | 71 | + choices: [{ index: 0, message: { role: "assistant", content: "Hello" }, finish_reason: "stop" }], | | 72 | + usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 }, | | 73 | + }) | | 74 | + }, | | 75 | + { preconnect: fetch.preconnect }, | | 76 | + ) | | 77 | + const model = createXai({ apiKey: "test", fetch: mockFetch }).chat("grok-4") | | 78 | + | | 79 | + await model.doGenerate({ | | 80 | + prompt: [{ role: "user", content: [{ type: "text", text: "Hello" }] }], | | 81 | + providerOptions: { xai: { reasoningEffort: "xhigh" } }, | | 82 | + }) | | 83 | + | | 84 | + expect(body?.reasoning_effort).toBe("xhigh") | | 85 | +}) |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/plugin/github-copilot/models.ts +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -88,6 +88,9 @@ function build(key: string, remote: SelectableItem, url: string, prev?: Model): | 88 | 88 | const image = | 89 | 89 | (remote.capabilities.supports.vision ?? false) || | 90 | 90 | (remote.capabilities.limits.vision?.supported_media_types ?? []).some((item) => item.startsWith("image/")) | | 91 | + const pdf = | | 92 | + (remote.capabilities.supports.vision ?? false) && | | 93 | + (remote.capabilities.limits.vision?.supported_media_types?.includes("application/pdf") ?? false) | 91 | 94 |
| 92 | 95 | const isMsgApi = remote.supported_endpoints?.includes("/v1/messages") | 93 | 96 | const endpoint: CopilotEndpoint | undefined = isMsgApi | @@ -127,7 +130,7 @@ function build(key: string, remote: SelectableItem, url: string, prev?: Model): | 127 | 130 | audio: false, | 128 | 131 | image, | 129 | 132 | video: false, | 130 | | - pdf: false, | | 133 | + pdf, | 131 | 134 | }, | 132 | 135 | output: { | 133 | 136 | text: true, | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/provider/transform.ts +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -84,6 +84,8 @@ function sdkKey(npm: string): string | undefined { | 84 | 84 | return "gateway" | 85 | 85 | case "@openrouter/ai-sdk-provider": | 86 | 86 | return "openrouter" | | 87 | + case "merge-gateway-ai-sdk-provider": | | 88 | + return "mergeGateway" | 87 | 89 | case "ai-gateway-provider": | 88 | 90 | // ai-gateway-provider/unified wraps createOpenAICompatible({ name: "Unified" }), | 89 | 91 | // and @ai-sdk/openai-compatible parses compatibleOptions from one of | @@ -551,6 +553,12 @@ export function topP(model: Provider.Model) { | 551 | 553 | if (["minimax-m2", "kimi-k2.5", "kimi-k2p5", "kimi-k2-5"].some((s) => id.includes(s))) { | 552 | 554 | return 0.95 | 553 | 555 | } | | 556 | + if ( | | 557 | + ["deepseek-v4-flash-0731", "deepseek-v4-flash:0731"].some((name) => id.includes(name)) || | | 558 | + (id.includes("deepseek-v4-flash") && (model.providerID === "deepseek" || model.providerID.startsWith("opencode"))) | | 559 | + ) { | | 560 | + return 0.95 | | 561 | + } | 554 | 562 | return undefined | 555 | 563 | } | 556 | 564 |
| @@ -1766,6 +1774,7 @@ function reasoningEffort(model: Provider.Model, effort: string) { | 1766 | 1774 | case "@ai-sdk/togetherai": | 1767 | 1775 | case "venice-ai-sdk-provider": | 1768 | 1776 | case "ai-gateway-provider": | | 1777 | + case "merge-gateway-ai-sdk-provider": | 1769 | 1778 | return { reasoningEffort: effort } | 1770 | 1779 | case "@ai-sdk/cohere": | 1771 | 1780 | case "@ai-sdk/perplexity": | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/session/retry.ts +11-3Lines changed: 11 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -25,8 +25,10 @@ export type Retryable = { | 25 | 25 |
| 26 | 26 | export const RETRY_INITIAL_DELAY = 2000 | 27 | 27 | export const RETRY_BACKOFF_FACTOR = 2 | | 28 | +export const RETRY_JITTER_FACTOR = 0.25 | 28 | 29 | export const RETRY_MAX_DELAY_NO_HEADERS = 30_000 // 30 seconds | 29 | 30 | export const RETRY_MAX_DELAY = 2_147_483_647 // max 32-bit signed integer for setTimeout | | 31 | +export const RETRY_MAX_RETRIES = 5 | 30 | 32 |
| 31 | 33 | const RETRYABLE_MESSAGE_PATTERNS = [ | 32 | 34 | /429|500|502|503|504|524/i, | @@ -41,7 +43,7 @@ function cap(ms: number) { | 41 | 43 | return Math.min(ms, RETRY_MAX_DELAY) | 42 | 44 | } | 43 | 45 |
| 44 | | -export function delay(attempt: number, error?: SessionV1.APIError) { | | 46 | +export function delay(attempt: number, error?: SessionV1.APIError, random = Math.random()) { | 45 | 47 | if (error) { | 46 | 48 | const headers = error.data.responseHeaders | 47 | 49 | if (headers) { | @@ -67,11 +69,16 @@ export function delay(attempt: number, error?: SessionV1.APIError) { | 67 | 69 | } | 68 | 70 | } | 69 | 71 |
| 70 | | - return cap(RETRY_INITIAL_DELAY * Math.pow(RETRY_BACKOFF_FACTOR, attempt - 1)) | | 72 | + return cap(exponential(attempt, random)) | 71 | 73 | } | 72 | 74 | } | 73 | 75 |
| 74 | | - return cap(Math.min(RETRY_INITIAL_DELAY * Math.pow(RETRY_BACKOFF_FACTOR, attempt - 1), RETRY_MAX_DELAY_NO_HEADERS)) | | 76 | + return cap(Math.min(exponential(attempt, random), RETRY_MAX_DELAY_NO_HEADERS)) | | 77 | +} | | 78 | + | | 79 | +function exponential(attempt: number, random: number) { | | 80 | + const base = RETRY_INITIAL_DELAY * Math.pow(RETRY_BACKOFF_FACTOR, attempt - 1) | | 81 | + return Math.ceil(base + base * RETRY_JITTER_FACTOR * random) | 75 | 82 | } | 76 | 83 |
| 77 | 84 | export function retryable(error: Err, provider: string) { | @@ -182,6 +189,7 @@ export function policy(opts: { | 182 | 189 | const error = opts.parse(meta.input) | 183 | 190 | const retry = retryable(error, opts.provider) | 184 | 191 | if (!retry) return Cause.done(meta.attempt) | | 192 | + if (meta.attempt > RETRY_MAX_RETRIES) return Cause.done(meta.attempt) | 185 | 193 | return Effect.gen(function* () { | 186 | 194 | const wait = delay(meta.attempt, SessionV1.APIError.isInstance(error) ? error : undefined) | 187 | 195 | const now = yield* Clock.currentTimeMillis | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/session/system.ts +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -47,7 +47,11 @@ export function provider(model: Provider.Model) { | 47 | 47 | if (model.api.id.includes("gemini-")) return [PROMPT_GEMINI] | 48 | 48 | if (model.api.id.includes("claude")) return [PROMPT_ANTHROPIC] | 49 | 49 | if (model.api.id.toLowerCase().includes("trinity")) return [PROMPT_TRINITY] | 50 | | - if (model.api.id.toLowerCase().includes("kimi")) return [PROMPT_KIMI] | | 50 | + if ( | | 51 | + model.api.id.toLowerCase().includes("kimi") || | | 52 | + ["kimi-for-coding", "moonshotai", "moonshotai-cn"].includes(model.providerID) | | 53 | + ) | | 54 | + return [PROMPT_KIMI] | 51 | 55 | return [PROMPT_DEFAULT] | 52 | 56 | } | 53 | 57 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/test/plugin/github-copilot-models.test.ts +68Lines changed: 68 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -187,6 +187,74 @@ test("converts Copilot AIC token prices to USD per million tokens", async () => | 187 | 187 | expect(models["ignored-non-chat-record"]).toBeUndefined() | 188 | 188 | }) | 189 | 189 |
| | 190 | +test("detects PDF input support when vision and media type are advertised", async () => { | | 191 | + globalThis.fetch = mock(() => | | 192 | + Promise.resolve( | | 193 | + new Response( | | 194 | + JSON.stringify({ | | 195 | + data: [ | | 196 | + { | | 197 | + model_picker_enabled: true, | | 198 | + id: "pdf-model", | | 199 | + name: "PDF Model", | | 200 | + version: "pdf-model-2026-06-01", | | 201 | + capabilities: { | | 202 | + family: "pdf-model", | | 203 | + limits: { | | 204 | + max_context_window_tokens: 128000, | | 205 | + max_output_tokens: 16384, | | 206 | + max_prompt_tokens: 128000, | | 207 | + vision: { | | 208 | + max_prompt_image_size: 10000000, | | 209 | + max_prompt_images: 10, | | 210 | + supported_media_types: ["application/pdf"], | | 211 | + }, | | 212 | + }, | | 213 | + supports: { | | 214 | + streaming: true, | | 215 | + vision: true, | | 216 | + tool_calls: true, | | 217 | + }, | | 218 | + }, | | 219 | + }, | | 220 | + { | | 221 | + model_picker_enabled: true, | | 222 | + id: "vision-only-model", | | 223 | + name: "Vision Only Model", | | 224 | + version: "vision-only-model-2026-06-01", | | 225 | + capabilities: { | | 226 | + family: "vision-only-model", | | 227 | + limits: { | | 228 | + max_context_window_tokens: 128000, | | 229 | + max_output_tokens: 16384, | | 230 | + max_prompt_tokens: 128000, | | 231 | + vision: { | | 232 | + max_prompt_image_size: 10000000, | | 233 | + max_prompt_images: 10, | | 234 | + supported_media_types: ["image/png"], | | 235 | + }, | | 236 | + }, | | 237 | + supports: { | | 238 | + streaming: true, | | 239 | + vision: true, | | 240 | + tool_calls: true, | | 241 | + }, | | 242 | + }, | | 243 | + }, | | 244 | + ], | | 245 | + }), | | 246 | + { status: 200 }, | | 247 | + ), | | 248 | + ), | | 249 | + ) as unknown as typeof fetch | | 250 | + | | 251 | + const models = (await CopilotModels.get("https://api.githubcopilot.com")).models | | 252 | + const model = models["pdf-model"] | | 253 | + | | 254 | + expect(model.capabilities.input.pdf).toBe(true) | | 255 | + expect(models["vision-only-model"].capabilities.input.pdf).toBe(false) | | 256 | +}) | | 257 | + | 190 | 258 | test("uses zero cost when Copilot reports a zero billing batch size", async () => { | 191 | 259 | globalThis.fetch = mock(() => | 192 | 260 | Promise.resolve( | |
|