Skip to content

Commit cf0c895

Browse files
James Mtendamemacursoragent
andcommitted
fix(zoo-gateway): pick default model from fetched list, prefer Sonnet 4.5
Resolves Sonnet 4.5 from the gateway model catalog instead of a static Vercel slug so test (Bedrock) and live accounts both get a valid default. Reassigns stale profile model IDs when they are not in the catalog. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 98f3172 commit cf0c895

1 file changed

Lines changed: 44 additions & 5 deletions

File tree

webview-ui/src/components/settings/providers/ZooGateway.tsx

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useEffect, useMemo } from "react"
12
import {
23
type ProviderSettings,
34
type OrganizationAllowList,
@@ -20,6 +21,32 @@ type ZooGatewayProps = {
2021
simplifySettings?: boolean
2122
}
2223

24+
function isSonnet45ModelId(id: string) {
25+
return /sonnet-4[.-]5|sonnet-4\.5/i.test(id)
26+
}
27+
28+
function pickZooGatewayDefaultModelId(modelIds: string[]) {
29+
if (modelIds.length === 0) {
30+
return zooGatewayDefaultModelId
31+
}
32+
33+
const sonnet45 = modelIds.filter(isSonnet45ModelId)
34+
if (sonnet45.length > 0) {
35+
return (
36+
sonnet45.find((id) => id === "anthropic/claude-sonnet-4.5") ??
37+
sonnet45.find((id) => id.includes("claude-sonnet-4.5")) ??
38+
sonnet45[0]
39+
)
40+
}
41+
42+
const sonnet4 = modelIds.filter((id) => /claude/i.test(id) && /sonnet/i.test(id) && /sonnet-4/i.test(id))
43+
if (sonnet4.length > 0) {
44+
return sonnet4[0]
45+
}
46+
47+
return modelIds[0]
48+
}
49+
2350
export const ZooGateway = ({
2451
apiConfiguration,
2552
setApiConfigurationField,
@@ -33,13 +60,25 @@ export const ZooGateway = ({
3360
useExtensionState()
3461

3562
const authUrl = getZooCodeAuthUrl(uriScheme, zooCodeBaseUrl, deviceName)
36-
// Resolve the dashboard link off the same base URL the auth/gateway flow uses,
37-
// so non-prod environments (staging/dev) point at the matching dashboard.
3863
const resolvedDashboardBase = zooCodeBaseUrl?.replace(/\/$/, "") || "https://www.zoocode.dev"
3964

65+
const zooModels = useMemo(() => routerModels?.["zoo-gateway"] ?? {}, [routerModels])
66+
const modelIds = useMemo(() => Object.keys(zooModels), [zooModels])
67+
const resolvedDefaultModelId = useMemo(() => pickZooGatewayDefaultModelId(modelIds), [modelIds])
68+
69+
useEffect(() => {
70+
if (modelIds.length === 0) {
71+
return
72+
}
73+
74+
const current = apiConfiguration.zooGatewayModelId
75+
if (!current || !modelIds.includes(current)) {
76+
setApiConfigurationField("zooGatewayModelId", resolvedDefaultModelId)
77+
}
78+
}, [apiConfiguration.zooGatewayModelId, modelIds, resolvedDefaultModelId, setApiConfigurationField])
79+
4080
return (
4181
<>
42-
{/* Zoo Code Authentication Section */}
4382
<div className="flex flex-col gap-1 rounded-md border border-vscode-panel-border p-2">
4483
<div className="flex items-center justify-between">
4584
<label className="block text-sm font-medium">{t("settings:providers.zooGateway.account")}</label>
@@ -72,8 +111,8 @@ export const ZooGateway = ({
72111
<ModelPicker
73112
apiConfiguration={apiConfiguration}
74113
setApiConfigurationField={setApiConfigurationField}
75-
defaultModelId={zooGatewayDefaultModelId}
76-
models={routerModels?.["zoo-gateway"] ?? {}}
114+
defaultModelId={resolvedDefaultModelId}
115+
models={zooModels}
77116
modelIdKey="zooGatewayModelId"
78117
serviceName="Zoo Gateway"
79118
serviceUrl={`${resolvedDashboardBase}/dashboard/models`}

0 commit comments

Comments
 (0)