Skip to content

fix(chat): resolve missing web search due to region mapping mismatch - #2224

Merged
smakosh merged 2 commits into
theopenco:mainfrom
amelitoalcuitas:fix/web-search-missing
May 9, 2026
Merged

smakosh merged 2 commits into
theopenco:mainfrom
amelitoalcuitas:fix/web-search-missing

Conversation

@amelitoalcuitas

@amelitoalcuitas amelitoalcuitas commented May 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Refactor
    • Improved consistency in how model capabilities are detected across the chat interface and comparison panels through centralized helper functions and unified lookup logic.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 9, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

This 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.

Changes

Model Capability Detection Refactoring

Layer / File(s) Summary
Helper Utilities
apps/playground/src/components/playground/chat-page-client.tsx
parseModelSelectorValue parses selectedModel string into { providerId, modelId, providerModelName }. getSelectedMapping resolves the correct ApiModelProviderMapping with exact-match (providerId+modelName) and providerId-only fallback logic.
Main Chat Page Capability Detection
apps/playground/src/components/playground/chat-page-client.tsx
supportsImages, supportsReasoning, supportsWebSearch, and supportsImageGen useMemo blocks refactored to use helper functions, deriving capabilities from resolved mapping instead of prior ad-hoc parsing and availableModels-based lookups.
Extra Chat Panel Capability Detection
apps/playground/src/components/playground/chat-page-client.tsx
ExtraChatPanel capability detection for supportsImages, supportsReasoning, and supportsWebSearch refactored to use parseModelSelectorValue + getSelectedMapping, replacing prior direct parsing and mapping-selection logic.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • theopenco/llmgateway#2216: Modifies capability-detection logic in the same file for supportsReasoning and supportsWebSearch, making concurrent changes to overlapping code sections.

Suggested reviewers

  • smakosh
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(chat): resolve missing web search due to region mapping mismatch' accurately describes the main change: centralizing model parsing and capability detection to fix a web search availability issue caused by inconsistent provider mapping lookups.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
apps/playground/src/components/playground/chat-page-client.tsx (1)

73-88: ⚡ Quick win

Refactor 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), as split("/") 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

📥 Commits

Reviewing files that changed from the base of the PR and between 9639ba6 and b536331.

📒 Files selected for processing (1)
  • apps/playground/src/components/playground/chat-page-client.tsx

@smakosh smakosh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@smakosh
smakosh enabled auto-merge May 9, 2026 13:01
@smakosh
smakosh added this pull request to the merge queue May 9, 2026
Merged via the queue into theopenco:main with commit 94e86c5 May 9, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants