GeezerVison is showing github.com — fix: ensure vercel variants pass amazon models under bedrock key (#13… · un33k/opencode@933a491
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: packages/opencode/src/provider/transform.ts +11-3Lines changed: 11 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -802,15 +802,22 @@ export namespace ProviderTransform { | 802 | 802 | return {} | 803 | 803 | } | 804 | 804 |
| | 805 | + // Maps model ID prefix to provider slug used in providerOptions. | | 806 | + // Example: "amazon/nova-2-lite" → "bedrock" | | 807 | + const SLUG_OVERRIDES: Record<string, string> = { | | 808 | + amazon: "bedrock", | | 809 | + } | | 810 | + | 805 | 811 | export function providerOptions(model: Provider.Model, options: { [x: string]: any }) { | 806 | 812 | if (model.api.npm === "@ai-sdk/gateway") { | 807 | 813 | // Gateway providerOptions are split across two namespaces: | 808 | | - // - `gateway`: gateway-native routing/caching controls | | 814 | + // - `gateway`: gateway-native routing/caching controls (order, only, byok, etc.) | 809 | 815 | // - `<upstream slug>`: provider-specific model options (anthropic/openai/...) | 810 | 816 | // We keep `gateway` as-is and route every other top-level option under the | 811 | | - // model-derived upstream slug so variants/options can stay flat internally. | | 817 | + // model-derived upstream slug. | 812 | 818 | const i = model.api.id.indexOf("/") | 813 | | - const slug = i > 0 ? model.api.id.slice(0, i) : undefined | | 819 | + const rawSlug = i > 0 ? model.api.id.slice(0, i) : undefined | | 820 | + const slug = rawSlug ? (SLUG_OVERRIDES[rawSlug] ?? rawSlug) : undefined | 814 | 821 | const gateway = options.gateway | 815 | 822 | const rest = Object.fromEntries(Object.entries(options).filter(([k]) => k !== "gateway")) | 816 | 823 | const has = Object.keys(rest).length > 0 | @@ -820,6 +827,7 @@ export namespace ProviderTransform { | 820 | 827 |
| 821 | 828 | if (has) { | 822 | 829 | if (slug) { | | 830 | + // Route model-specific options under the provider slug | 823 | 831 | result[slug] = rest | 824 | 832 | } else if (gateway && typeof gateway === "object" && !Array.isArray(gateway)) { | 825 | 833 | result.gateway = { ...gateway, ...rest } | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/test/provider/transform.test.ts +30Lines changed: 30 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -341,6 +341,36 @@ describe("ProviderTransform.providerOptions", () => { | 341 | 341 | gateway: { reasoningEffort: "high" }, | 342 | 342 | }) | 343 | 343 | }) | | 344 | + | | 345 | + test("maps amazon slug to bedrock for provider options", () => { | | 346 | + const model = createModel({ | | 347 | + providerID: "vercel", | | 348 | + api: { | | 349 | + id: "amazon/nova-2-lite", | | 350 | + url: "https://ai-gateway.vercel.sh/v3/ai", | | 351 | + npm: "@ai-sdk/gateway", | | 352 | + }, | | 353 | + }) | | 354 | + | | 355 | + expect(ProviderTransform.providerOptions(model, { reasoningConfig: { type: "enabled" } })).toEqual({ | | 356 | + bedrock: { reasoningConfig: { type: "enabled" } }, | | 357 | + }) | | 358 | + }) | | 359 | + | | 360 | + test("uses groq slug for groq models", () => { | | 361 | + const model = createModel({ | | 362 | + providerID: "vercel", | | 363 | + api: { | | 364 | + id: "groq/llama-3.3-70b-versatile", | | 365 | + url: "https://ai-gateway.vercel.sh/v3/ai", | | 366 | + npm: "@ai-sdk/gateway", | | 367 | + }, | | 368 | + }) | | 369 | + | | 370 | + expect(ProviderTransform.providerOptions(model, { reasoningFormat: "parsed" })).toEqual({ | | 371 | + groq: { reasoningFormat: "parsed" }, | | 372 | + }) | | 373 | + }) | 344 | 374 | }) | 345 | 375 |
| 346 | 376 | describe("ProviderTransform.schema - gemini array items", () => { | |
|