@@ -10,7 +10,6 @@ import { resolveAgentWorkspaceDir } from "../agents/agent-scope.js";
1010import {
1111 type AuthProfileStore ,
1212 ensureAuthProfileStore ,
13- resolveAuthProfileOrder ,
1413 saveAuthProfileStore ,
1514} from "../agents/auth-profiles.js" ;
1615import {
@@ -43,6 +42,7 @@ import { loadSessionEntry, readSessionMessages } from "./session-utils.js";
4342const LIVE = isTruthyEnvValue ( process . env . LIVE ) || isTruthyEnvValue ( process . env . OPENCLAW_LIVE_TEST ) ;
4443const GATEWAY_LIVE = isTruthyEnvValue ( process . env . OPENCLAW_LIVE_GATEWAY ) ;
4544const ZAI_FALLBACK = isTruthyEnvValue ( process . env . OPENCLAW_LIVE_GATEWAY_ZAI_FALLBACK ) ;
45+ const REQUIRE_PROFILE_KEYS = isTruthyEnvValue ( process . env . OPENCLAW_LIVE_REQUIRE_PROFILE_KEYS ) ;
4646const PROVIDERS = parseFilter ( process . env . OPENCLAW_LIVE_GATEWAY_PROVIDERS ) ;
4747const THINKING_LEVEL = "high" ;
4848const THINKING_TAG_RE = / < \s * \/ ? \s * (?: t h i n k (?: i n g ) ? | t h o u g h t | a n t t h i n k i n g ) \s * > / i;
@@ -1383,9 +1383,6 @@ describeLive("gateway live (dev agent, profile keys)", () => {
13831383 await ensureOpenClawModelsJson ( cfg ) ;
13841384
13851385 const agentDir = resolveOpenClawAgentDir ( ) ;
1386- const authStore = ensureAuthProfileStore ( agentDir , {
1387- allowKeychainPrompt : false ,
1388- } ) ;
13891386 const authStorage = discoverAuthStorage ( agentDir ) ;
13901387 const modelRegistry = discoverModels ( authStorage , agentDir ) ;
13911388 const all = modelRegistry . getAll ( ) ;
@@ -1399,32 +1396,37 @@ describeLive("gateway live (dev agent, profile keys)", () => {
13991396 ? all . filter ( ( m ) => filter . has ( `${ m . provider } /${ m . id } ` ) )
14001397 : all . filter ( ( m ) => isModernModelRef ( { provider : m . provider , id : m . id } ) ) ;
14011398
1402- const providerProfileCache = new Map < string , boolean > ( ) ;
14031399 const candidates : Array < Model < Api > > = [ ] ;
1400+ const skipped : Array < { model : string ; error : string } > = [ ] ;
14041401 for ( const model of wanted ) {
14051402 if ( shouldSuppressBuiltInModel ( { provider : model . provider , id : model . id } ) ) {
14061403 continue ;
14071404 }
14081405 if ( PROVIDERS && ! PROVIDERS . has ( model . provider ) ) {
14091406 continue ;
14101407 }
1411- let hasProfile = providerProfileCache . get ( model . provider ) ;
1412- if ( hasProfile === undefined ) {
1413- const order = resolveAuthProfileOrder ( {
1414- cfg,
1415- store : authStore ,
1416- provider : model . provider ,
1417- } ) ;
1418- hasProfile = order . some ( ( profileId ) => Boolean ( authStore . profiles [ profileId ] ) ) ;
1419- providerProfileCache . set ( model . provider , hasProfile ) ;
1420- }
1421- if ( ! hasProfile ) {
1422- continue ;
1408+ const modelRef = `${ model . provider } /${ model . id } ` ;
1409+ try {
1410+ const apiKeyInfo = await getApiKeyForModel ( { model, cfg } ) ;
1411+ if ( REQUIRE_PROFILE_KEYS && ! apiKeyInfo . source . startsWith ( "profile:" ) ) {
1412+ skipped . push ( {
1413+ model : modelRef ,
1414+ error : `non-profile credential source: ${ apiKeyInfo . source } ` ,
1415+ } ) ;
1416+ continue ;
1417+ }
1418+ candidates . push ( model ) ;
1419+ } catch ( error ) {
1420+ skipped . push ( { model : modelRef , error : String ( error ) } ) ;
14231421 }
1424- candidates . push ( model ) ;
14251422 }
14261423
14271424 if ( candidates . length === 0 ) {
1425+ if ( skipped . length > 0 ) {
1426+ logProgress (
1427+ `[all-models] auth lookup skipped candidates:\n${ formatFailurePreview ( skipped , 8 ) } ` ,
1428+ ) ;
1429+ }
14281430 logProgress ( "[all-models] no API keys found; skipping" ) ;
14291431 return ;
14301432 }
0 commit comments