fix(core): normalize provider endpoint templates - #41816
Merged
Merged
Conversation
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.
What
Resolve Bedrock Mantle catalog endpoints from the provider's configured region without teaching the generic model resolver about Bedrock.
This is the adapter-based alternative to #41786 and closes #40075.
Before / After
Before: models.dev supplies Mantle endpoints such as
https://bedrock-mantle.${AWS_REGION}.api.aws/openai/v1. Withsettings.region: "us-west-2"and noAWS_REGION,ModelResolverrejected the intermediate catalog settings before the native Mantle adapter or provider could interpret them.The regression test failed before the fix with:
After:
AISDKNativetranslates the known Mantle placeholder from the effective configured or credential region, preserving model-specific/v1and/openai/v1paths. Generic environment expansion and unresolved-variable validation then run on the effective mapped settings before provider loading. Explicit provider configuration therefore wins over the process environment while providers still construct routes from concrete URLs.How
packages/core/src/aisdk-native.tsresolves only the MantleAWS_REGIONplaceholder while translating the AI SDK catalog package into the native AI package.packages/core/src/model-resolver.tsmaps provider-specific settings first, then performs one-pass generic environment expansion and validation before loading or constructing the provider.packages/aiis unchanged; the native Mantle provider continues receiving a concretebaseURLand region.Scope
${ENV}behavior remains unchanged for other providers.UnresolvedProviderVariablesError.Testing
cd packages/core && bun run test test/model-resolver.test.tsfailed with unresolvedAWS_REGION.cd packages/core && bun run test test/model-resolver.test.ts test/aisdk-native.test.ts(47 pass)cd packages/core && bun typecheckbun turbo typecheck --concurrency=3(33 successful)Flow
flowchart LR A[Catalog model and config] --> B[AI SDK native adapter] B -->|Mantle template plus region| C[Effective provider settings] C --> D[Generic environment expansion] D --> E{Variables unresolved?} E -->|Yes| F[UnresolvedProviderVariablesError] E -->|No| G[Provider constructs route] G --> H[Final endpoint invariant] H --> I[LanguageModel]