@@ -607,6 +607,113 @@ export function applyConfigHintsToCachedModels(name: string, prov: OcxProviderCo
607607 return models . map ( model => applyProviderConfigHints ( name , prov , model , contextCap ) ) ;
608608}
609609
610+ /**
611+ * Last-resort context window for combo member synthesis when discovery and
612+ * provider config both omit one. Matches the catalog entry default in
613+ * `normalizeRoutedCatalogEntry` so incomplete live rows still catalog.
614+ */
615+ const COMBO_MEMBER_CONTEXT_FALLBACK = 128_000 ;
616+
617+ /**
618+ * Resolve a combo target to a catalog member for derivation.
619+ * Prefer discovery metadata; when the target is missing from the gather map or
620+ * lacks a positive contextWindow, synthesize from the (registry-enriched)
621+ * provider config so combos remain catalogued when targets are configured but
622+ * discovery metadata is incomplete. Disabled/missing providers stay unresolved.
623+ * When hints still omit contextWindow, apply COMBO_MEMBER_CONTEXT_FALLBACK so a
624+ * live row without ctx (common for LiteLLM / custom xai ids) does not drop the
625+ * whole combo from the public catalog.
626+ */
627+ export function resolveComboCatalogMember (
628+ target : { provider : string ; model : string } ,
629+ memberByKey : ReadonlyMap < string , CatalogModel > ,
630+ providers : ReadonlyMap < string , OcxProviderConfig > ,
631+ contextCap ?: number ,
632+ ) : CatalogModel | undefined {
633+ const existing = memberByKey . get ( targetKey ( target ) ) ;
634+ const prov = providers . get ( target . provider ) ;
635+ // Disabled providers never contribute members — even a complete discovery row
636+ // is unusable for catalog derivation while the provider is off.
637+ if ( prov ?. disabled === true ) return undefined ;
638+
639+ // Complete live/configured rows still honor providerContextCaps so a high
640+ // discovery window cannot outrun an operator-configured cap.
641+ if (
642+ existing
643+ && typeof existing . contextWindow === "number"
644+ && existing . contextWindow > 0
645+ ) {
646+ const capped = applyProviderContextCap ( existing . contextWindow , contextCap ) ;
647+ if ( capped === undefined || capped === existing . contextWindow ) return existing ;
648+ const maxInput = typeof existing . maxInputTokens === "number" && existing . maxInputTokens > 0
649+ ? Math . min ( existing . maxInputTokens , capped )
650+ : capped ;
651+ return {
652+ ...existing ,
653+ contextWindow : capped ,
654+ maxInputTokens : maxInput ,
655+ contextCap,
656+ contextCapped : true as const ,
657+ } ;
658+ }
659+
660+ const base : CatalogModel = existing ?? {
661+ id : target . model ,
662+ provider : target . provider ,
663+ } ;
664+ // Reuse the same hint path configured/static catalog rows use when a provider
665+ // config exists; otherwise keep the base (possibly incomplete) discovery row.
666+ const hinted = prov
667+ ? applyProviderConfigHints ( target . provider , prov , base , contextCap )
668+ : base ;
669+ const hintedContext = typeof hinted . contextWindow === "number" && hinted . contextWindow > 0
670+ ? hinted . contextWindow
671+ : undefined ;
672+ // Prefer a known positive maxInputTokens over inventing 128k when discovery
673+ // advertised an input limit but no context window (common thin /models rows).
674+ const knownMaxInput = typeof hinted . maxInputTokens === "number" && hinted . maxInputTokens > 0
675+ ? hinted . maxInputTokens
676+ : ( typeof base . maxInputTokens === "number" && base . maxInputTokens > 0
677+ ? base . maxInputTokens
678+ : undefined ) ;
679+ // Prefer config/discovery; fall back so incomplete live rows still catalog.
680+ // Pure ghosts (no discovery row) on a known provider still synthesize: live
681+ // discovery is often incomplete for LiteLLM/custom relays, and dropping the
682+ // whole combo solely for a missing /v1/models row is worse than a stub window.
683+ const uncappedContext = hintedContext
684+ ?? knownMaxInput
685+ ?? ( existing || prov ? COMBO_MEMBER_CONTEXT_FALLBACK : undefined ) ;
686+ if ( uncappedContext === undefined ) return undefined ;
687+ // Fallback bypasses applyProviderConfigHints' cap path — clamp here so a
688+ // providerContextCaps value below 128k still wins (same semantics as hints).
689+ const usedFallback = hintedContext === undefined ;
690+ const cappedContext = applyProviderContextCap ( uncappedContext , contextCap ) ;
691+ const contextWindow = cappedContext ?? uncappedContext ;
692+ const fallbackCapped = usedFallback
693+ && contextCap !== undefined
694+ && cappedContext !== undefined
695+ && cappedContext !== uncappedContext ;
696+
697+ const inputModalities = hinted . inputModalities ?? base . inputModalities ?? [ "text" ] ;
698+ // applyProviderConfigHints already folds configuredReasoningEfforts; keep an
699+ // explicit fallback for stubs that only had base fields.
700+ const reasoningEfforts = hinted . reasoningEfforts
701+ ?? ( prov ? configuredReasoningEfforts ( prov , target . model ) : undefined )
702+ ?? base . reasoningEfforts ;
703+ const maxInputTokens = knownMaxInput !== undefined
704+ ? Math . min ( knownMaxInput , contextWindow )
705+ : contextWindow ;
706+
707+ return {
708+ ...hinted ,
709+ inputModalities,
710+ ...( reasoningEfforts !== undefined ? { reasoningEfforts } : { } ) ,
711+ contextWindow,
712+ maxInputTokens,
713+ ...( fallbackCapped ? { contextCap, contextCapped : true as const } : { } ) ,
714+ } ;
715+ }
716+
610717export function isDatedVariantId ( liveId : string , configuredId : string ) : boolean {
611718 if ( ! liveId . startsWith ( `${ configuredId } -` ) ) return false ;
612719 return / ^ \d { 8 } $ / . test ( liveId . slice ( configuredId . length + 1 ) ) ;
@@ -736,17 +843,6 @@ function modelInputModalities(
736843 value === "text" || value === "image" || value === "audio"
737844 ) ) ;
738845 if ( explicit && explicit . length > 0 ) return explicit ;
739- const architecture = plainRecord ( item . architecture ) ;
740- const architectureModality = typeof architecture ?. modality === "string"
741- ? normalizedMetadataString ( architecture . modality , 64 )
742- : undefined ;
743- if ( architectureModality ?. includes ( "->" ) ) {
744- const [ rawInput = "" ] = architectureModality . split ( "->" ) ;
745- const inferred = rawInput
746- . split ( "+" )
747- . filter ( value => value === "text" || value === "image" || value === "audio" ) ;
748- if ( inferred . length > 0 ) return [ ...new Set ( inferred ) ] ;
749- }
750846 if ( capabilityRecord ?. vision === false ) return [ "text" ] ;
751847 if ( capabilityRecord ?. vision === true || capabilities ?. some ( value => value === "vision" || value === "image-input" ) ) {
752848 return [ "text" , "image" ] ;
@@ -1273,21 +1369,26 @@ async function gatherRoutedModelsUncached(
12731369 if ( ! memberByKey . has ( key ) ) memberByKey . set ( key , synthetic ) ;
12741370 }
12751371 }
1372+ // Enriched (registry-hydrated) provider clones — shared by combo member synthesis and
1373+ // custom-model vision-sidecar inheritance so both see the same merged registry view.
1374+ const enrichedByName = new Map ( activeProviders . map ( provider => [ provider . name , provider . provider ] ) ) ;
12761375 for ( const id of listComboIds ( config ) ) {
12771376 const combo = getCombo ( config , id ) ;
12781377 if ( ! combo ) continue ;
12791378 const members = combo . targets
1280- . map ( target => memberByKey . get ( targetKey ( target ) ) )
1379+ . map ( target => resolveComboCatalogMember (
1380+ target ,
1381+ memberByKey ,
1382+ enrichedByName ,
1383+ providerContextCap ( config , target . provider ) ,
1384+ ) )
12811385 . filter ( ( member ) : member is CatalogModel => member !== undefined ) ;
12821386 const derived = deriveComboCatalogModel ( id , combo , members ) ;
12831387 if ( derived ) all . push ( derived ) ;
12841388 else warnUncataloguedComboOnce ( id , combo , members , localOmissions ) ;
12851389 }
12861390 replaceLastComboCatalogOmissions ( localOmissions ) ;
12871391 all . sort ( ( a , b ) => ( a . provider === b . provider ? a . id . localeCompare ( b . id ) : a . provider . localeCompare ( b . provider ) ) ) ;
1288- // Enriched (registry-hydrated) provider clones, keyed by name — the same view used above so
1289- // custom rows get the same noVisionModels / inputModalities treatment as discovered rows.
1290- const enrichedByName = new Map ( activeProviders . map ( provider => [ provider . name , provider . provider ] ) ) ;
12911392 // Provider-derived rows keyed by their Codex-facing slug: a custom override replaces the row
12921393 // with the same slug below, so that row's provider capability metadata is the inheritance source.
12931394 const replacedByRoutedSlug = new Map ( all . map ( model => [ routedSlug ( model . provider , model . id ) , model ] ) ) ;
0 commit comments