@@ -5,8 +5,8 @@ import type {
55} from "openclaw/plugin-sdk/plugin-entry" ;
66import { createProviderApiKeyAuthMethod } from "openclaw/plugin-sdk/provider-auth-api-key" ;
77import {
8- buildLiveModelProviderConfig ,
98 getCachedLiveProviderModelRows ,
9+ LiveModelCatalogHttpError ,
1010 type LiveModelCatalogFetchGuard ,
1111} from "openclaw/plugin-sdk/provider-catalog-live-runtime" ;
1212import { buildManifestModelProviderConfig } from "openclaw/plugin-sdk/provider-catalog-shared" ;
@@ -234,7 +234,7 @@ function buildOpenAIDiscoverablePlatformModels(baseUrl: string): ModelDefinition
234234 contextWindow,
235235 api : "openai-responses" ,
236236 baseUrl,
237- input : id === OPENAI_GPT_54_PRO_MODEL_ID ? [ "text" ] : [ "text" , "image" ] ,
237+ input : [ "text" , "image" ] ,
238238 maxTokens : OPENAI_GPT_54_MAX_TOKENS ,
239239 } ) ) ;
240240}
@@ -245,56 +245,61 @@ async function buildOpenAILiveProviderConfig(
245245 const baseUrl =
246246 normalizeOptionalString ( params . baseUrl ) ?? resolveOpenAIDefaultBaseUrl ( params . env ) ;
247247 const models = buildOpenAIManifestModelsForBaseUrl ( baseUrl ) ;
248+ const fallback : ModelProviderConfig = {
249+ baseUrl,
250+ api : "openai-responses" ,
251+ ...( params . apiKey ? { apiKey : params . apiKey } : { } ) ,
252+ models,
253+ } ;
248254 if ( ! shouldFetchOpenAILiveModels ( baseUrl ) ) {
249- return {
250- baseUrl,
251- api : "openai-responses" ,
255+ return fallback ;
256+ }
257+ try {
258+ const rows = await getCachedLiveProviderModelRows ( {
259+ providerId : PROVIDER_ID ,
260+ endpoint : OPENAI_MODELS_ENDPOINT ,
252261 apiKey : params . apiKey ,
253- models,
262+ discoveryApiKey : params . discoveryApiKey ,
263+ fetchGuard : params . fetchGuard ,
264+ signal : params . signal ,
265+ ttlMs : OPENAI_MODELS_CACHE_TTL_MS ,
266+ auditContext : "openai-model-discovery" ,
267+ } ) ;
268+ const discoveredIds = new Set (
269+ rows . flatMap ( ( row ) => {
270+ if ( ! row || typeof row !== "object" || Array . isArray ( row ) ) {
271+ return [ ] ;
272+ }
273+ const candidate = row as { id ?: unknown ; object ?: unknown } ;
274+ if ( candidate . object !== undefined && candidate . object !== "model" ) {
275+ return [ ] ;
276+ }
277+ const modelId = typeof candidate . id === "string" ? candidate . id . trim ( ) : "" ;
278+ return modelId ? [ modelId ] : [ ] ;
279+ } ) ,
280+ ) ;
281+ const selectedIds = new Set < string > ( ) ;
282+ // A successful account catalog is authoritative even when it has no
283+ // visible supported models; static rows cannot grant model access.
284+ return {
285+ ...fallback ,
286+ models : [ ...models , ...buildOpenAIDiscoverablePlatformModels ( baseUrl ) ] . filter ( ( model ) => {
287+ if ( ! discoveredIds . has ( model . id ) || selectedIds . has ( model . id ) ) {
288+ return false ;
289+ }
290+ selectedIds . add ( model . id ) ;
291+ return true ;
292+ } ) ,
254293 } ;
294+ } catch ( error ) {
295+ if (
296+ error instanceof LiveModelCatalogHttpError &&
297+ ( error . status === 401 || error . status === 403 )
298+ ) {
299+ return { ...fallback , models : [ ] } ;
300+ }
301+ return fallback ;
255302 }
256- return await buildLiveModelProviderConfig ( {
257- providerId : PROVIDER_ID ,
258- endpoint : OPENAI_MODELS_ENDPOINT ,
259- providerConfig : {
260- baseUrl,
261- api : "openai-responses" ,
262- } ,
263- models,
264- projectRows : ( rows , fallback ) => {
265- const discoveredIds = new Set (
266- rows . flatMap ( ( row ) => {
267- if ( ! row || typeof row !== "object" || Array . isArray ( row ) ) {
268- return [ ] ;
269- }
270- const candidate = row as { id ?: unknown ; object ?: unknown } ;
271- if ( candidate . object !== undefined && candidate . object !== "model" ) {
272- return [ ] ;
273- }
274- const modelId = typeof candidate . id === "string" ? candidate . id . trim ( ) : "" ;
275- return modelId ? [ modelId ] : [ ] ;
276- } ) ,
277- ) ;
278- const selectedIds = new Set < string > ( ) ;
279- // Discovery alone confirms account access; leave the manifest as the
280- // advisory fallback when OpenAI cannot return an authenticated catalog.
281- return [ ...fallback . models , ...buildOpenAIDiscoverablePlatformModels ( baseUrl ) ] . filter (
282- ( model ) => {
283- if ( ! discoveredIds . has ( model . id ) || selectedIds . has ( model . id ) ) {
284- return false ;
285- }
286- selectedIds . add ( model . id ) ;
287- return true ;
288- } ,
289- ) ;
290- } ,
291- apiKey : params . apiKey ,
292- discoveryApiKey : params . discoveryApiKey ,
293- fetchGuard : params . fetchGuard ,
294- signal : params . signal ,
295- ttlMs : OPENAI_MODELS_CACHE_TTL_MS ,
296- auditContext : "openai-model-discovery" ,
297- } ) ;
298303}
299304
300305function readCodexModelString ( row : unknown , key : string ) : string | undefined {
@@ -578,18 +583,21 @@ async function buildOpenAICodexLiveProviderConfig(params: {
578583 const models = rows
579584 . map ( buildOpenAICodexModelFromLiveRow )
580585 . filter ( ( model ) : model is ModelDefinitionConfig => Boolean ( model ) ) ;
581- if ( models . length > 0 ) {
582- // Successful Codex OAuth discovery is account-scoped and authoritative
583- // for the picker/list catalog. Do not merge static OpenAI fallback rows
584- // into a successful live catalog.
585- return {
586- baseUrl : OPENAI_CODEX_RESPONSES_BASE_URL ,
587- api : "openai-chatgpt-responses" ,
588- auth : "oauth" ,
589- models,
590- } ;
586+ // A successful account-scoped response is authoritative even when all
587+ // rows are hidden; static hints must not invent subscription access.
588+ return {
589+ baseUrl : OPENAI_CODEX_RESPONSES_BASE_URL ,
590+ api : "openai-chatgpt-responses" ,
591+ auth : "oauth" ,
592+ models,
593+ } ;
594+ } catch ( error ) {
595+ if (
596+ error instanceof LiveModelCatalogHttpError &&
597+ ( error . status === 401 || error . status === 403 )
598+ ) {
599+ return { ...buildOpenAICodexStaticProviderConfig ( ) , models : [ ] } ;
591600 }
592- } catch {
593601 // Codex/ChatGPT discovery is advisory. Static OpenAI rows stay available
594602 // when OAuth refresh or the remote model list is unavailable.
595603 }
0 commit comments