@@ -117,17 +117,42 @@ function gatewayRouteContext(
117117function getConfiguredDirectRouteContext (
118118 modelInput : string ,
119119 parsed : ReturnType < typeof parseRoutingInput > ,
120- isConfigured : ( provider : string ) => boolean
120+ isConfigured : ( provider : string ) => boolean ,
121+ isGatewayModelAccessible ?: GatewayModelAccessibility
121122) : RouteContext | null {
122- return isConfigured ( parsed . origin ) ? directRouteContext ( modelInput , parsed ) : null ;
123+ if ( ! isConfigured ( parsed . origin ) ) {
124+ return null ;
125+ }
126+
127+ if (
128+ getProviderDefinition ( parsed . origin ) ?. kind === "gateway" &&
129+ isGatewayModelAccessible &&
130+ ! isGatewayModelAccessible ( parsed . origin , parsed . originModelId )
131+ ) {
132+ return null ;
133+ }
134+
135+ return directRouteContext ( modelInput , parsed ) ;
123136}
124137
125138function getConfiguredExplicitGatewayRouteContext (
126139 modelInput : string ,
127140 parsed : ReturnType < typeof parseRoutingInput > ,
128- isConfigured : ( provider : string ) => boolean
141+ isConfigured : ( provider : string ) => boolean ,
142+ isGatewayModelAccessible ?: GatewayModelAccessibility
129143) : RouteContext | null {
130- if ( parsed . explicitGateway == null || ! isConfigured ( parsed . explicitGateway ) ) {
144+ if ( parsed . explicitGateway == null || parsed . explicitGatewayModelId == null ) {
145+ return null ;
146+ }
147+
148+ if ( ! isConfigured ( parsed . explicitGateway ) ) {
149+ return null ;
150+ }
151+
152+ if (
153+ isGatewayModelAccessible &&
154+ ! isGatewayModelAccessible ( parsed . explicitGateway , parsed . explicitGatewayModelId )
155+ ) {
131156 return null ;
132157 }
133158
@@ -174,7 +199,12 @@ function findActiveRouteContext(
174199 // to canonical override/priority routing so the underlying model
175200 // stays reachable via other configured routes.
176201 if ( parsed . explicitGateway != null ) {
177- const explicit = getConfiguredExplicitGatewayRouteContext ( modelInput , parsed , isConfigured ) ;
202+ const explicit = getConfiguredExplicitGatewayRouteContext (
203+ modelInput ,
204+ parsed ,
205+ isConfigured ,
206+ isGatewayModelAccessible
207+ ) ;
178208 if ( explicit ) {
179209 return explicit ;
180210 }
@@ -187,7 +217,12 @@ function findActiveRouteContext(
187217 const canonicalKey = getCanonicalRouteKey ( parsed ) ;
188218 const override = routeOverrides [ canonicalKey ] ;
189219 if ( override === "direct" || override === parsed . origin ) {
190- const direct = getConfiguredDirectRouteContext ( modelInput , parsed , isConfigured ) ;
220+ const direct = getConfiguredDirectRouteContext (
221+ modelInput ,
222+ parsed ,
223+ isConfigured ,
224+ isGatewayModelAccessible
225+ ) ;
191226 if ( direct ) {
192227 return direct ;
193228 }
@@ -211,7 +246,12 @@ function findActiveRouteContext(
211246 // 2. Walk routePriority
212247 for ( const route of routePriority ) {
213248 if ( route === "direct" ) {
214- const direct = getConfiguredDirectRouteContext ( modelInput , parsed , isConfigured ) ;
249+ const direct = getConfiguredDirectRouteContext (
250+ modelInput ,
251+ parsed ,
252+ isConfigured ,
253+ isGatewayModelAccessible
254+ ) ;
215255 if ( direct ) {
216256 return direct ;
217257 }
@@ -310,7 +350,11 @@ export function availableRoutes(
310350
311351 // Add direct route
312352 const originDefinition = getProviderDefinition ( parsed . origin ) ;
313- if ( originDefinition ) {
353+ const directIsAccessible =
354+ originDefinition ?. kind !== "gateway" ||
355+ ! isGatewayModelAccessible ||
356+ isGatewayModelAccessible ( parsed . origin , parsed . originModelId ) ;
357+ if ( originDefinition && directIsAccessible ) {
314358 routes . push ( {
315359 route : "direct" ,
316360 displayName : `Direct (${ originDefinition . displayName } )` ,
0 commit comments