@@ -620,6 +620,104 @@ export function applyConfigHintsToCachedModels(name: string, prov: OcxProviderCo
620620 return models . map ( model => applyProviderConfigHints ( name , prov , model , contextCap ) ) ;
621621}
622622
623+
624+ /**
625+ * Last-resort context window for combo member synthesis when discovery and
626+ * provider config both omit one. Matches the catalog entry default in
627+ * `normalizeRoutedCatalogEntry` so incomplete live rows still catalog.
628+ */
629+ const COMBO_MEMBER_CONTEXT_FALLBACK = 128_000 ;
630+
631+ /**
632+ * Resolve a combo target to a catalog member for derivation.
633+ * Prefer discovery metadata; when the target is missing from the gather map or
634+ * lacks a positive contextWindow, synthesize from the (registry-enriched)
635+ * provider config so combos remain catalogued when targets are configured but
636+ * discovery metadata is incomplete. Disabled providers stay unresolved.
637+ * When hints still omit contextWindow, prefer known maxInputTokens, else
638+ * COMBO_MEMBER_CONTEXT_FALLBACK so a live row without ctx does not drop the
639+ * whole combo from the public catalog.
640+ */
641+ export function resolveComboCatalogMember (
642+ target : { provider : string ; model : string } ,
643+ memberByKey : ReadonlyMap < string , CatalogModel > ,
644+ providers : ReadonlyMap < string , OcxProviderConfig > ,
645+ contextCap ?: number ,
646+ ) : CatalogModel | undefined {
647+ const existing = memberByKey . get ( targetKey ( target ) ) ;
648+ const prov = providers . get ( target . provider ) ;
649+ // Disabled providers never contribute members — even a complete discovery row
650+ // is unusable for catalog derivation while the provider is off.
651+ if ( prov ?. disabled === true ) return undefined ;
652+
653+ // Complete live/configured rows still honor providerContextCaps so a high
654+ // discovery window cannot outrun an operator-configured cap.
655+ if (
656+ existing
657+ && typeof existing . contextWindow === "number"
658+ && existing . contextWindow > 0
659+ ) {
660+ const capped = applyProviderContextCap ( existing . contextWindow , contextCap ) ;
661+ if ( capped === undefined || capped === existing . contextWindow ) return existing ;
662+ const maxInput = typeof existing . maxInputTokens === "number" && existing . maxInputTokens > 0
663+ ? Math . min ( existing . maxInputTokens , capped )
664+ : capped ;
665+ return {
666+ ...existing ,
667+ contextWindow : capped ,
668+ maxInputTokens : maxInput ,
669+ contextCap,
670+ contextCapped : true as const ,
671+ } ;
672+ }
673+
674+ const base : CatalogModel = existing ?? {
675+ id : target . model ,
676+ provider : target . provider ,
677+ } ;
678+ const hinted = prov
679+ ? applyProviderConfigHints ( target . provider , prov , base , contextCap )
680+ : base ;
681+ const hintedContext = typeof hinted . contextWindow === "number" && hinted . contextWindow > 0
682+ ? hinted . contextWindow
683+ : undefined ;
684+ // Prefer a known positive maxInputTokens over inventing 128k when discovery
685+ // advertised an input limit but no context window (common thin /models rows).
686+ const knownMaxInput = typeof hinted . maxInputTokens === "number" && hinted . maxInputTokens > 0
687+ ? hinted . maxInputTokens
688+ : ( typeof base . maxInputTokens === "number" && base . maxInputTokens > 0
689+ ? base . maxInputTokens
690+ : undefined ) ;
691+ const uncappedContext = hintedContext
692+ ?? knownMaxInput
693+ ?? ( existing || prov ? COMBO_MEMBER_CONTEXT_FALLBACK : undefined ) ;
694+ if ( uncappedContext === undefined ) return undefined ;
695+ const usedFallback = hintedContext === undefined ;
696+ const cappedContext = applyProviderContextCap ( uncappedContext , contextCap ) ;
697+ const contextWindow = cappedContext ?? uncappedContext ;
698+ const fallbackCapped = usedFallback
699+ && contextCap !== undefined
700+ && cappedContext !== undefined
701+ && cappedContext !== uncappedContext ;
702+
703+ const inputModalities = hinted . inputModalities ?? base . inputModalities ?? [ "text" ] ;
704+ const reasoningEfforts = hinted . reasoningEfforts
705+ ?? ( prov ? configuredReasoningEfforts ( prov , target . model ) : undefined )
706+ ?? base . reasoningEfforts ;
707+ const maxInputTokens = knownMaxInput !== undefined
708+ ? Math . min ( knownMaxInput , contextWindow )
709+ : contextWindow ;
710+
711+ return {
712+ ...hinted ,
713+ inputModalities,
714+ ...( reasoningEfforts !== undefined ? { reasoningEfforts } : { } ) ,
715+ contextWindow,
716+ maxInputTokens,
717+ ...( fallbackCapped ? { contextCap, contextCapped : true as const } : { } ) ,
718+ } ;
719+ }
720+
623721export function isDatedVariantId ( liveId : string , configuredId : string ) : boolean {
624722 if ( ! liveId . startsWith ( `${ configuredId } -` ) ) return false ;
625723 return / ^ \d { 8 } $ / . test ( liveId . slice ( configuredId . length + 1 ) ) ;
@@ -1319,21 +1417,26 @@ async function gatherRoutedModelsUncached(
13191417 if ( ! memberByKey . has ( key ) ) memberByKey . set ( key , synthetic ) ;
13201418 }
13211419 }
1420+ // Enriched (registry-hydrated) provider clones — shared by combo member synthesis and
1421+ // custom-model vision-sidecar inheritance so both see the same merged registry view.
1422+ const enrichedByName = new Map ( activeProviders . map ( provider => [ provider . name , provider . provider ] ) ) ;
13221423 for ( const id of listComboIds ( config ) ) {
13231424 const combo = getCombo ( config , id ) ;
13241425 if ( ! combo ) continue ;
13251426 const members = combo . targets
1326- . map ( target => memberByKey . get ( targetKey ( target ) ) )
1427+ . map ( target => resolveComboCatalogMember (
1428+ target ,
1429+ memberByKey ,
1430+ enrichedByName ,
1431+ providerContextCap ( config , target . provider ) ,
1432+ ) )
13271433 . filter ( ( member ) : member is CatalogModel => member !== undefined ) ;
13281434 const derived = deriveComboCatalogModel ( id , combo , members ) ;
13291435 if ( derived ) all . push ( derived ) ;
13301436 else warnUncataloguedComboOnce ( id , combo , members , localOmissions ) ;
13311437 }
13321438 replaceLastComboCatalogOmissions ( localOmissions ) ;
13331439 all . sort ( ( a , b ) => ( a . provider === b . provider ? a . id . localeCompare ( b . id ) : a . provider . localeCompare ( b . provider ) ) ) ;
1334- // Enriched (registry-hydrated) provider clones, keyed by name — the same view used above so
1335- // custom rows get the same noVisionModels / inputModalities treatment as discovered rows.
1336- const enrichedByName = new Map ( activeProviders . map ( provider => [ provider . name , provider . provider ] ) ) ;
13371440 // Provider-derived rows keyed by their Codex-facing slug: a custom override replaces the row
13381441 // with the same slug below, so that row's provider capability metadata is the inheritance source.
13391442 const replacedByRoutedSlug = new Map ( all . map ( model => [ routedSlug ( model . provider , model . id ) , model ] ) ) ;
0 commit comments