refactor(ai): flatten provider request options - #43513
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
Flatten provider-specific request options in the canonical AI request model. A selected
LanguageModel<Options>now typesproviderOptionsas that provider's direct option record instead of requiring an additional provider namespace.Before / After
Before
Native protocols had to select their own namespace from the canonical request even though the selected model had already established the provider. The legacy Vercel AI SDK shape and the canonical OpenCode shape were therefore coupled.
After
Native protocols decode the flat record directly. The legacy AI SDK adapter adds the provider namespace only when constructing
LanguageModelV3CallOptions. Provider metadata remains namespaced because metadata can contain values from multiple providers and must round-trip with its source identity.How
packages/ai/src/schema/options.tschanges the canonical schema to a flat unknown-value record and deep-merges route, model, and request defaults directly.packages/core/src/aisdk.tsre-namespaces flat request options at the Vercel AI SDK boundary while preserving namespaced content-part metadata.packages/core/src/aisdk-native.tsmaps AI SDK catalog settings into flat native-provider defaults.Scope
This PR deliberately excludes structured native provider
model({ id, settings, credential, defaults })changes, credential selection/lowering,ProviderPackagecredential helpers, model-resolver credential work, stale document deletions, and unrelated documentation changes from #43491.Testing
cd packages/ai && bun typecheckcd packages/core && bun typecheckcd packages/ai && bun run test test/compile.test.ts test/llm.test.ts test/provider/anthropic-messages.test.ts test/provider/gemini.test.ts test/provider/openai-chat.test.ts test/provider/openai-compatible-responses.test.ts test/provider/openai-responses.test.ts test/provider/google-vertex.test.ts test/provider-package.test.ts(258 passed)cd packages/ai && bun run test test/provider/openrouter.test.ts --test-name-pattern 'allows usage accounting|applies OpenRouter payload|filters invalid known OpenRouter'(3 passed)cd packages/core && bun run test test/aisdk.test.ts test/aisdk-native.test.ts(39 passed)cd packages/core && bun run test test/model-resolver.test.ts(39 passed)cd packages/ai && RECORDED_PREFIX=gemini RECORDED_TEST=text bun run test test/provider/golden.recorded.test.ts(1 passed, 38 filtered/skipped)bunx oxlint $(git diff --name-only origin/v2 -- '*.ts')(0 errors; existing warnings only)bun turbo typecheck --concurrency=3(33/33 tasks passed)bun run lintstill exits on the pre-existing octal-escape error inpackages/session-ui/src/v2/components/prompt-input/index.tsx:163; no changed file has a lint error.Flow