UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 3.37 kB
import{c as resolveCliRuntimeCanonicalProvider,o as resolveCliBackendConfig}from"./cli-backends-BDgFsc0L.mjs";import{o as resolveAuthProfileOrderWithMetadata}from"./order-B8e_5ABM.mjs";import{t as resolveBundledCliBackendAuthPolicy}from"./cli-backend-auth-policy-Dr9dmiV1.mjs"; //!src/agents/cli-execution-auth.ts const GOOGLE_GEMINI_CLI_PROVIDER_ID=`google-gemini-cli`;const GOOGLE_PROVIDER_ID=`google`;const CLAUDE_CLI_PROVIDER_ID=`claude-cli`;var CliExecutionAuthProfileError=class extends Error{constructor(...e){super(...e);this.name=`CliExecutionAuthProfileError`}};function cliBackendAcceptsAuthProfileForwarding(e){const t=resolveCliBackendConfig(e.provider,e.config,{agentId:e.agentId});return t?.id===GOOGLE_GEMINI_CLI_PROVIDER_ID||t?.id===CLAUDE_CLI_PROVIDER_ID}function selectCliExecutionAuthProfile(e){const{store:t}=e;const n=e.selected?.authProfileId?.trim();const r=n&&e.selected?.authProfileIdSource!==`auto`;const i=e.sessionBinding?.authProfileId?.trim();const a=resolveBundledCliBackendAuthPolicy(e.cliExecutionProvider)?.nativeAuthProfileIds;if(!r&&e.sessionBinding&&!i)return;const o=r?n:i&&(t.profiles[i]||a?.includes(i))?i:void 0;const s=o??n;if(s&&a?.includes(s))return{kind:`native`,profileId:s};const c=resolveCliRuntimeCanonicalProvider({runtime:e.cliExecutionProvider,config:e.config,includeSetupRegistry:true,metadataSnapshot:e.metadataSnapshot});const acceptsCredential=(t,n)=>t.provider===e.cliExecutionProvider||t.provider===c&&(e.cliExecutionProvider===CLAUDE_CLI_PROVIDER_ID?n||t.type!==`api_key`:e.cliExecutionProvider===GOOGLE_GEMINI_CLI_PROVIDER_ID&&t.type===`api_key`);if(o){const n=t.profiles[o];if(!n)throw new CliExecutionAuthProfileError(`No credentials found for profile "${o}".`);if(acceptsCredential(n,true))return{kind:`stored`,profileId:o,provider:n.provider};throw new CliExecutionAuthProfileError(`CLI backend "${e.cliExecutionProvider}" cannot use auth profile "${o}" owned by "${n.provider}".`)}const l=[e.cliExecutionProvider];if(c&&(e.cliExecutionProvider===CLAUDE_CLI_PROVIDER_ID||e.cliExecutionProvider===GOOGLE_GEMINI_CLI_PROVIDER_ID&&e.authProfileProvider===GOOGLE_PROVIDER_ID))l.push(c);for(const r of l){const i=resolveAuthProfileOrderWithMetadata({cfg:e.config,store:t,provider:r,preferredProfile:n,readinessMode:e.readinessMode,authAliasLookupParams:{metadataSnapshot:e.metadataSnapshot}});for(const e of i.profileIds){const n=t.profiles[e];if(n&&acceptsCredential(n,false)&&!a?.includes(e))return{kind:`stored`,profileId:e,provider:n.provider}}if(i.hasExplicitOrder)return}}async function resolveCliExecutionAuthSelection(e){const t=e.loadAuthProfileStoreForRuntimeAsync??(await import(`./store-runtime-KjP2H80g.mjs`)).loadAuthProfileStoreForRuntimeAsync;const n=e.selected?.authProfileId?.trim();const r=await t(e.agentDir,{readOnly:true,allowKeychainPrompt:false,externalCliProviderIds:[e.cliExecutionProvider],profileId:n&&e.selected?.authProfileIdSource!==`auto`?n:e.sessionBinding?.authProfileId?.trim()??n});return selectCliExecutionAuthProfile({...e,store:r})}async function resolveCliExecutionAuthProfileId(e){const t=await resolveCliExecutionAuthSelection(e);return t?.kind===`stored`?t.profileId:void 0}export{selectCliExecutionAuthProfile as a,resolveCliExecutionAuthSelection as i,cliBackendAcceptsAuthProfileForwarding as n,resolveCliExecutionAuthProfileId as r,CliExecutionAuthProfileError as t};