@@ -273,12 +273,17 @@ export function buildOpenAISource(fields: {
273273 apiKey ?: string ;
274274 model : string ;
275275 reasoningEffort ?: ReasoningEffort ;
276+ maxTokens ?: number ;
277+ temperature ?: number ;
278+ topP ?: number ;
276279 quirks ?: Record < string , unknown > ;
277280} ) : InferenceSource {
278- const overrides =
279- fields . reasoningEffort !== undefined
280- ? { providerOptions : { reasoning_effort : fields . reasoningEffort } }
281- : { } ;
281+ const providerOptions : Record < string , unknown > = { } ;
282+ if ( fields . reasoningEffort !== undefined )
283+ providerOptions [ "reasoning_effort" ] = fields . reasoningEffort ;
284+ if ( fields . temperature !== undefined )
285+ providerOptions [ "temperature" ] = fields . temperature ;
286+ if ( fields . topP !== undefined ) providerOptions [ "top_p" ] = fields . topP ;
282287 registerSourceSecret ( fields . id , fields . apiKey ) ;
283288 return {
284289 id : fields . id ,
@@ -288,7 +293,10 @@ export function buildOpenAISource(fields: {
288293 : normalizeOpenAICompatibleBaseURL ( fields . baseURL ) ,
289294 credentialId : fields . id ,
290295 model : fields . model ,
291- defaults : { maxTokens : SOURCE_MAX_TOKENS , ...overrides } ,
296+ defaults : {
297+ maxTokens : fields . maxTokens ?? SOURCE_MAX_TOKENS ,
298+ ...( Object . keys ( providerOptions ) . length > 0 ? { providerOptions } : { } ) ,
299+ } ,
292300 ...( fields . quirks !== undefined ? { quirks : fields . quirks } : { } ) ,
293301 } ;
294302}
@@ -1382,12 +1390,55 @@ export function mergeOAuthCatalog(
13821390export async function refreshLiveProviderCatalog (
13831391 settings : Settings | null ,
13841392 resolved : ResolvedProvider ,
1393+ liveSelection ?: ( ) => Pick < ResolvedProvider , "providerName" | "model" > ,
13851394) : Promise < ProviderCatalogEntry [ ] > {
13861395 const [ codexProfiles , xaiProfiles ] = await Promise . all ( [
13871396 listCodexProfiles ( ) ,
13881397 listXaiProfiles ( ) ,
13891398 ] ) ;
1390- return mergeOAuthCatalog ( settings , resolved , codexProfiles , xaiProfiles ) ;
1399+ const catalog = mergeOAuthCatalog (
1400+ settings ,
1401+ resolved ,
1402+ codexProfiles ,
1403+ xaiProfiles ,
1404+ ) ;
1405+ // Discovery can finish after a model switch; never restore its old bare-model slot.
1406+ const active = liveSelection ?.( ) ?? resolved ;
1407+ refreshProviderContextWindows (
1408+ settings ?? undefined ,
1409+ catalog ,
1410+ active . providerName ,
1411+ active . model ,
1412+ ) ;
1413+ return catalog ;
1414+ }
1415+
1416+ export function refreshProviderContextWindows (
1417+ settings : Settings | undefined ,
1418+ catalog : readonly ProviderCatalogEntry [ ] ,
1419+ activeProvider : string ,
1420+ activeModel : string ,
1421+ ) : void {
1422+ // Catalog models can expand during discovery. OAuth projections deliberately
1423+ // omit settings-only window overrides, just as startup resolution does.
1424+ const providers = Object . fromEntries (
1425+ catalog . map ( ( entry ) => {
1426+ const window =
1427+ entry . codexProfile === undefined && entry . xaiProfile === undefined
1428+ ? settings ?. providers [ entry . name ] ?. contextWindow
1429+ : undefined ;
1430+ return [
1431+ entry . name ,
1432+ {
1433+ models : entry . models ,
1434+ ...( window !== undefined ? { contextWindow : window } : { } ) ,
1435+ } ,
1436+ ] ;
1437+ } ) ,
1438+ ) ;
1439+ setProviderContextWindowOverrides (
1440+ buildProviderContextWindowOverrides ( providers , activeProvider , activeModel ) ,
1441+ ) ;
13911442}
13921443
13931444export function catalogEntryAsProviderSettings (
@@ -1413,6 +1464,11 @@ export function catalogEntryAsProviderSettings(
14131464 ? { defaultModel : entry . defaultModel }
14141465 : { } ) ,
14151466 ...( entry . free !== undefined ? { free : entry . free } : { } ) ,
1467+ ...( entry . maxTokens !== undefined ? { maxTokens : entry . maxTokens } : { } ) ,
1468+ ...( entry . temperature !== undefined
1469+ ? { temperature : entry . temperature }
1470+ : { } ) ,
1471+ ...( entry . topP !== undefined ? { topP : entry . topP } : { } ) ,
14161472 ...( entry . bifrostVirtualKey === true ? { bifrostVirtualKey : true } : { } ) ,
14171473 ...( entry . anthropic === true ? { anthropic : true } : { } ) ,
14181474 ...( go ? { opencodeGo : true } : { } ) ,
@@ -1497,6 +1553,11 @@ export function buildProviderCatalog(
14971553 ? { defaultModel : p . defaultModel }
14981554 : { } ) ,
14991555 ...( p . free !== undefined ? { free : p . free } : { } ) ,
1556+ ...( p . maxTokens !== undefined ? { maxTokens : p . maxTokens } : { } ) ,
1557+ ...( p . temperature !== undefined
1558+ ? { temperature : p . temperature }
1559+ : { } ) ,
1560+ ...( p . topP !== undefined ? { topP : p . topP } : { } ) ,
15001561 ...( p . bifrostVirtualKey === true ? { bifrostVirtualKey : true } : { } ) ,
15011562 ...( p . anthropic === true ? { anthropic : true } : { } ) ,
15021563 ...( go ? { opencodeGo : true } : { } ) ,
0 commit comments