1+ import { useEffect , useMemo } from "react"
12import {
23 type ProviderSettings ,
34 type OrganizationAllowList ,
@@ -20,6 +21,32 @@ type ZooGatewayProps = {
2021 simplifySettings ?: boolean
2122}
2223
24+ function isSonnet45ModelId ( id : string ) {
25+ return / s o n n e t - 4 [ . - ] 5 | s o n n e t - 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 ) => / c l a u d e / i. test ( id ) && / s o n n e t / i. test ( id ) && / s o n n e t - 4 / i. test ( id ) )
43+ if ( sonnet4 . length > 0 ) {
44+ return sonnet4 [ 0 ]
45+ }
46+
47+ return modelIds [ 0 ]
48+ }
49+
2350export 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