Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion apps/playground/src/components/model-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -868,16 +868,37 @@ export function ModelSelector({
const selectedModelId = selectedModelIdRaw.includes(":")
? selectedModelIdRaw.split(":")[0]
: selectedModelIdRaw;
Comment on lines 868 to 870

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use trailing-suffix parsing instead of first-colon split

Line 868 currently uses split(":")[0], which strips at the first colon. This can mis-parse model IDs containing additional colons and break selectedModel resolution. Use lastIndexOf(":") (same pattern as downstream parsing) to only remove the trailing region suffix.

Suggested fix
-	const selectedModelId = selectedModelIdRaw.includes(":")
-		? selectedModelIdRaw.split(":")[0]
-		: selectedModelIdRaw;
+	const colonIndex = selectedModelIdRaw.lastIndexOf(":");
+	const selectedModelId =
+		colonIndex === -1
+			? selectedModelIdRaw
+			: selectedModelIdRaw.slice(0, colonIndex);

Also applies to: 871-884

🤖 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/model-selector.tsx` around lines 868 - 870,
selectedModelId currently uses selectedModelIdRaw.split(":")[0], which removes
everything after the first colon and can mis-parse IDs that contain additional
colons; change the logic to locate the last colon (use lastIndexOf(":")) and
strip only the trailing region suffix so you preserve any internal colons in the
ID when computing selectedModelId, and apply the same trailing-suffix parsing
fix to the other similar spots that handle selectedModelIdRaw/selectedModel
resolution in the same block (the code around selectedModelId,
selectedModelIdRaw and selectedModel resolution).

const selectedModel = models.find((m) => m.id === selectedModelId);
// First try root model id, then fall back to finding a model whose mapping
// modelName matches the raw value (needed for regional models where the URL
// encodes the provider-specific modelName rather than the root model id).
const selectedModel =
models.find((m) => m.id === selectedModelId) ??
(selectedProviderId
? models.find((m) =>
m.mappings.some(
(mp) =>
mp.providerId === selectedProviderId &&
mp.modelName === selectedModelIdRaw,
),
)
: undefined);
const selectedProviderDef = providers.find(
(p) => p.id === selectedProviderId,
);
// When the URL uses model.id (no region), prefer the mapping without a region
// to avoid picking up a regional variant that happens to be first in the array.
const hasRegionInValue = selectedModelIdRaw.includes(":");
const selectedMapping =
selectedModel?.mappings.find(
(p) =>
p.providerId === selectedProviderId &&
p.modelName === selectedModelIdRaw,
) ??
(!hasRegionInValue
? selectedModel?.mappings.find(
(p) => p.providerId === selectedProviderId && !p.region,
)
: undefined) ??
selectedModel?.mappings.find((p) => p.providerId === selectedProviderId);
const selectedEntryKey =
selectedModel && selectedProviderId && selectedMapping
Expand Down
Loading