Repository navigation
fix(chat): resolve missing web search due to region mapping mismatch - #2224
Conversation
WalkthroughThis PR introduces two helper functions to centralize model capability detection parsing and mapping resolution. Both the main chat page and ExtraChatPanel refactor to use these helpers consistently, replacing prior ad-hoc string parsing and different lookup strategies with a unified flow. ChangesModel Capability Detection Refactoring
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/playground/src/components/playground/chat-page-client.tsx (1)
73-88: ⚡ Quick winRefactor to avoid type assertion and improve edge case handling.
The type assertion
as [string, string]on line 79 bypasses TypeScript's type safety. Additionally, the current implementation doesn't correctly handle model identifiers with multiple slashes (e.g.,provider/model/region), assplit("/")would return more than two elements and the destructuring would discard trailing segments.♻️ Suggested refactor using indexOf/slice
function parseModelSelectorValue(value: string): { providerId: string; modelId: string; providerModelName: string; } { - const [providerId, rawModelId] = value.includes("/") - ? (value.split("/") as [string, string]) - : ["", value]; + const slashIndex = value.indexOf("/"); + const providerId = slashIndex === -1 ? "" : value.slice(0, slashIndex); + const rawModelId = slashIndex === -1 ? value : value.slice(slashIndex + 1); const colonIndex = rawModelId.lastIndexOf(":"); return { providerId, modelId: colonIndex === -1 ? rawModelId : rawModelId.slice(0, colonIndex), providerModelName: rawModelId, }; }This approach eliminates the type assertion and correctly handles identifiers with multiple slashes by treating everything after the first
/as the model portion.🤖 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 `@apps/playground/src/components/playground/chat-page-client.tsx` around lines 73 - 88, The parseModelSelectorValue function uses a type assertion on split and mishandles values with multiple slashes; change the split logic to find the first "/" with indexOf and slice so everything after the first slash becomes rawModelId (and providerId is empty string when no slash) instead of using (value.split("/") as [string,string]); keep the existing colon handling (colonIndex/ providerModelName) and return the same keys (providerId, modelId, providerModelName) but compute providerId and rawModelId via indexOf + slice to avoid the unsafe type assertion and correctly handle values like "provider/model/region".
🤖 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 `@apps/playground/src/components/playground/chat-page-client.tsx`:
- Around line 73-88: The parseModelSelectorValue function uses a type assertion
on split and mishandles values with multiple slashes; change the split logic to
find the first "/" with indexOf and slice so everything after the first slash
becomes rawModelId (and providerId is empty string when no slash) instead of
using (value.split("/") as [string,string]); keep the existing colon handling
(colonIndex/ providerModelName) and return the same keys (providerId, modelId,
providerModelName) but compute providerId and rawModelId via indexOf + slice to
avoid the unsafe type assertion and correctly handle values like
"provider/model/region".
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: d349ea89-9930-4771-af4e-7204cc2c3276
📒 Files selected for processing (1)
apps/playground/src/components/playground/chat-page-client.tsx
Summary by CodeRabbit