@@ -21,7 +21,10 @@ import { isModelAvailable } from "@/common/routing";
2121import type { ProviderModelEntry , ProvidersConfigMap } from "@/common/orpc/types" ;
2222import { DEFAULT_MODEL_KEY , HIDDEN_MODELS_KEY } from "@/common/constants/storage" ;
2323
24- import { isGatewayModelAccessibleFromAuthoritativeCatalog } from "@/common/utils/providers/gatewayModelCatalog" ;
24+ import {
25+ isGatewayModelAccessibleFromAuthoritativeCatalog ,
26+ isProviderModelAccessibleFromAuthoritativeCatalog ,
27+ } from "@/common/utils/providers/gatewayModelCatalog" ;
2528import { getProviderModelEntryId } from "@/common/utils/providers/modelEntries" ;
2629
2730const BUILT_IN_MODELS : string [ ] = Object . values ( KNOWN_MODELS ) . map ( ( m ) => m . id ) ;
@@ -162,10 +165,30 @@ export function useModelsFromSettings() {
162165 [ config ]
163166 ) ;
164167
168+ const isAuthoritativeProviderModelAccessible = useCallback (
169+ ( modelString : string ) => {
170+ const colonIndex = modelString . indexOf ( ":" ) ;
171+ if ( colonIndex <= 0 || colonIndex >= modelString . length - 1 ) {
172+ return true ;
173+ }
174+
175+ const provider = modelString . slice ( 0 , colonIndex ) ;
176+ const providerModelId = modelString . slice ( colonIndex + 1 ) ;
177+ return isProviderModelAccessibleFromAuthoritativeCatalog (
178+ provider ,
179+ providerModelId ,
180+ config ?. [ provider ] ?. models
181+ ) ;
182+ } ,
183+ [ config ]
184+ ) ;
185+
165186 const customModels = useMemo ( ( ) => {
166- const next = filterHiddenModels ( getCustomModels ( config ) , hiddenModels ) ;
187+ const next = filterHiddenModels ( getCustomModels ( config ) , hiddenModels ) . filter (
188+ isAuthoritativeProviderModelAccessible
189+ ) ;
167190 return effectivePolicy ? next . filter ( ( m ) => isModelAllowedByPolicy ( effectivePolicy , m ) ) : next ;
168- } , [ config , hiddenModels , effectivePolicy ] ) ;
191+ } , [ config , hiddenModels , effectivePolicy , isAuthoritativeProviderModelAccessible ] ) ;
169192
170193 const openaiApiKeySet = config === null ? null : config . openai ?. apiKeySet === true ;
171194 const codexOauthSet = config === null ? null : config . openai ?. codexOauthSet === true ;
@@ -186,6 +209,10 @@ export function useModelsFromSettings() {
186209 return false ;
187210 }
188211
212+ if ( ! isAuthoritativeProviderModelAccessible ( modelId ) ) {
213+ return true ;
214+ }
215+
189216 if (
190217 isModelAvailable (
191218 modelId ,
@@ -221,6 +248,7 @@ export function useModelsFromSettings() {
221248 effectivePolicy ,
222249 isConfigured ,
223250 isGatewayModelAccessible ,
251+ isAuthoritativeProviderModelAccessible ,
224252 routePriority ,
225253 routeOverrides ,
226254 openaiApiKeySet ,
@@ -240,14 +268,16 @@ export function useModelsFromSettings() {
240268 const providerFiltered =
241269 config == null
242270 ? suggested
243- : suggested . filter ( ( modelId ) =>
244- isModelAvailable (
245- modelId ,
246- routePriority ,
247- routeOverrides ,
248- isConfigured ,
249- isGatewayModelAccessible
250- )
271+ : suggested . filter (
272+ ( modelId ) =>
273+ isAuthoritativeProviderModelAccessible ( modelId ) &&
274+ isModelAvailable (
275+ modelId ,
276+ routePriority ,
277+ routeOverrides ,
278+ isConfigured ,
279+ isGatewayModelAccessible
280+ )
251281 ) ;
252282
253283 if ( config == null ) {
@@ -286,6 +316,7 @@ export function useModelsFromSettings() {
286316 effectivePolicy ,
287317 isConfigured ,
288318 isGatewayModelAccessible ,
319+ isAuthoritativeProviderModelAccessible ,
289320 routePriority ,
290321 routeOverrides ,
291322 openaiApiKeySet ,
0 commit comments