refactor(webview): use canonical provider identifiers - #1023
Conversation
|
Warning Review limit reached
Next review available in: 18 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughWebview model selection and configuration validation now use shared ChangesWebview provider identifier migration
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related issues
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
87080d6 to
607df7f
Compare
607df7f to
5b1c51a
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
webview-ui/src/components/ui/hooks/useSelectedModel.ts (1)
421-422: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winFinish converting internal provider comparisons to
providerIdentifiers.The switch labels are canonical now, but this hook still uses literal equality checks at Lines 63–65, 80–82, 108, and 430. That leaves readiness and fallback dispatch on a separate contract from
getSelectedModel; useproviderIdentifiers.*for internal comparisons while retaining serialized/router-map literals where required.Proposed fix
- provider === "anthropic" && + provider === providerIdentifiers.anthropic &&🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@webview-ui/src/components/ui/hooks/useSelectedModel.ts` around lines 421 - 422, Replace the remaining literal provider equality checks in useSelectedModel at the readiness, fallback-dispatch, and related branches (including the checks around lines 63–65, 80–82, 108, and 430) with the corresponding providerIdentifiers.* constants. Keep serialized values and router-map keys as literals where their external contract requires them, and preserve the existing switch behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@webview-ui/src/components/ui/hooks/useSelectedModel.ts`:
- Around line 421-422: Replace the remaining literal provider equality checks in
useSelectedModel at the readiness, fallback-dispatch, and related branches
(including the checks around lines 63–65, 80–82, 108, and 430) with the
corresponding providerIdentifiers.* constants. Keep serialized values and
router-map keys as literals where their external contract requires them, and
preserve the existing switch behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 4c9baa5b-47db-4ebc-add6-8c5cce143a56
📒 Files selected for processing (3)
webview-ui/src/components/ui/hooks/useSelectedModel.tswebview-ui/src/utils/__tests__/validate.spec.tswebview-ui/src/utils/validate.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@webview-ui/src/components/ui/hooks/useSelectedModel.ts`:
- Around line 421-423: Update the Anthropic-only condition within the grouped
branch of useSelectedModel to compare provider against
providerIdentifiers.anthropic rather than the hardcoded "anthropic" string,
preserving the 1M-context tier override when the registry identifier changes.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 996ce2b7-1d39-454f-b5da-46ffffa37b85
📒 Files selected for processing (2)
webview-ui/src/components/ui/hooks/__tests__/useSelectedModel.spec.tswebview-ui/src/components/ui/hooks/useSelectedModel.ts
edelauna
left a comment
There was a problem hiding this comment.
Looks good - had a comment on preventing returning undefined, and if we should up date some other locations?
| case providerIdentifiers.baseten: | ||
| if (!apiConfiguration.basetenApiKey) { | ||
| return i18next.t("settings:validation.apiKey") | ||
| } |
There was a problem hiding this comment.
The switch was fully migrated here, but two if-condition comparisons lower in the same file were missed:
- Line 210:
if (provider === "vscode-lm")→ should useproviderIdentifiers.vscodeLm - Line 321:
if (apiConfiguration.apiProvider !== "zoo-gateway")→ should useproviderIdentifiers.zooGateway
Those lines aren't in the diff, but they're in functions that live in the same file and have the same staleness risk if the identifier values ever change.
| // case "fake-ai": | ||
| default: { | ||
| provider satisfies "anthropic" | "gemini-cli" | "fake-ai" | ||
| case providerIdentifiers.anthropic: |
There was a problem hiding this comment.
The three explicit cases correctly replace the old default:, but the exhaustiveness guard is now gone. With noImplicitReturns absent from tsconfig, a new provider added to ProviderName without a case here would silently return undefined at runtime. Worth adding after the last case:
| case providerIdentifiers.anthropic: | |
| case providerIdentifiers.anthropic: | |
| case providerIdentifiers.geminiCli: | |
| case providerIdentifiers.fakeAi: { |
(And after the closing } of this block, before the final switch }):
default: {
provider satisfies never
throw new Error(`Unsupported provider: ${provider}`)
}
| const { result } = renderHook(() => useSelectedModel(apiConfiguration), { wrapper }) | ||
|
|
||
| expect(result.current.id).toBe("claude-opus-4-6") | ||
| expect(result.current.info?.contextWindow).toBe(1_000_000) |
There was a problem hiding this comment.
The Sonnet 4.6 test just above also asserts inputPrice and outputPrice from the same tier-override path. Could this test do the same?
| expect(result.current.info?.contextWindow).toBe(1_000_000) | |
| expect(result.current.info?.contextWindow).toBe(1_000_000) | |
| expect(result.current.info?.inputPrice).toBe(10.0) | |
| expect(result.current.info?.outputPrice).toBe(37.5) |
Summary
providerIdentifierssembleandopenai-compatibleunchangedTDD
Verification
npx vitest run src/utils/__tests__/validate.spec.ts src/components/ui/hooks/__tests__/useSelectedModel.spec.ts— 76 passednpx vitest run src/components/settings src/components/ui/hooks src/utils— 53 files, 654 passednpm run check-types— passedCloses #959.
Summary by CodeRabbit