feat(provider): discriminate provider behaviour by npm where unique#28536
Draft
andrewesweet wants to merge 3 commits into
Draft
feat(provider): discriminate provider behaviour by npm where unique#28536andrewesweet wants to merge 3 commits into
andrewesweet wants to merge 3 commits into
Conversation
Switch the custom-loader iteration to walk merged provider entries and resolve loaders by exact ID match or unique-npm fallback. A user-defined provider entry with `npm: "@ai-sdk/google-vertex"` (and any other unique-npm provider) now inherits the canonical loader's setup, enabling multi-region Vertex AI in one session. Migrate behavioural literal-ID checks in provider.ts, transform.ts, and agent.ts to `model.api.npm === NPM.X` wherever the canonical loader's npm value is unique. ID-keyed checks stay in place for the `@ai-sdk/openai-compatible` family (7 loaders share that npm) and the azure pair (`azure` plus `azure-cognitive-services`). Add `packages/opencode/src/provider/npm.ts` with named constants so the migrated equality checks live in one place and typos become compile errors. Fix `google-vertex-anthropic` loader to honour `provider.options.project` and `provider.options.location` from config, aligning it with the `google-vertex` loader (drive-by, two-line change). Refs anomalyco#28524 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Based on my search, I found one potentially related PR: Related PR:
The searches returned PR #28536 (the current PR) multiple times, and one other related PR (#28489) that deals with provider aliasing. The other results are unrelated feature additions. No direct duplicate PRs found for this specific feature of discriminating provider behavior by unique npm values. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
- Drop top-of-file comment block on `src/provider/npm.ts`. - Tighten the comments inside `resolveLoader` in `src/provider/provider.ts` so they stop reading like AI section headers. - Restore `[].includes()` form for the Anthropic/Vertex-Anthropic check at `src/provider/transform.ts:211`, using `[NPM.ANTHROPIC, NPM.GOOGLE_VERTEX_ANTHROPIC] as string[]` so the `as const` tuple widens enough for `.includes` to accept `model.api.npm`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
A future reader of the file can't know what "before" refers to. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #28524
Type of change
What does this PR do?
Declaring a second Vertex AI provider entry under a custom ID (say
google-vertex-eufor theeumulti-region) silently skips the Vertex loader today. The resulting SDK has no ADC credentials and requests fail withModel not found. The custom-loader iteration inpackages/opencode/src/provider/provider.tswalksObject.entries(custom(dep)), keyed by exact provider ID, so anything that isn't a canonical loader name is dropped.This PR walks the merged provider database instead. Each entry resolves to a loader by exact-ID match (canonical behaviour, untouched) or by unique-
npmmatch. When thenpmis shared (the@ai-sdk/openai-compatiblefamily of seven loaders, plus the@ai-sdk/azurepair), the resolver returnsundefinedand the entry falls through to the generic SDK path. That keeps the change narrow. Explicit aliasing inside those shared-npm groups is a separate problem; #28489 attacks one slice of it with anauth_providerconfig field.I also moved the literal
model.providerID === "X"discriminations inprovider.ts,transform.ts, andagent.tstomodel.api.npm === NPM.Xwherever the canonical loader uniquely owns its npm. Sites inside the openai-compatible family stay ID-keyed; npm can't discriminate among them. A newpackages/opencode/src/provider/npm.tsholds the npm constants so a typo at a call site is a compile error.Drive-by: the
google-vertex-anthropicloader was readingprojectandlocationfrom env vars only and silently ignoringprovider.options. Fixed to mirrorgoogle-vertex(config first, env fallback). Regression test included.How did you verify your code works?
Seven new tests in
packages/opencode/test/provider/provider.test.tscover the alias path, canonical-entry regression, ambiguous-npm fallthrough for the azure pair and the openai-compatible family, thegoogle-vertex-anthropicconfig gap, and the migrated Bedrock cross-region small-model picker.Manual, with the config below in
opencode.jsonand Google ADC set up (gcloud auth application-default login):Both succeed. Debug logs show each request hitting its configured regional endpoint with an
Authorization: Bearer …header from ADC.Example
{ "provider": { "google-vertex": { "options": { "project": "P", "location": "europe-west4" }, "models": { "gemini-2.5-pro": {} } }, "google-vertex-eu": { "npm": "@ai-sdk/google-vertex", "options": { "project": "P", "location": "eu" }, "models": { "gemini-3.5-flash": {} } } } }Screenshots / recordings
N/A — backend/provider logic change.
Checklist