UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 2.68 kB
import{a as coerceSecretRef}from"./types.secrets-UWdyCdE6.mjs";import{n as findNormalizedProviderValue}from"./provider-id-A-8WTtLA.mjs";import{t as normalizeOptionalSecretInput}from"./normalize-secret-input-CEFJUjQX.mjs";import{a as resolveAuthProfileOrder,f as listProfilesForProvider}from"./order-B8e_5ABM.mjs";import{i as ensureAuthProfileStoreAsync}from"./store-runtime-GNz-2GjY.mjs";import"./provider-auth-Czspvb3-.mjs";import{i as resolveRequiredConfiguredSecretRefInputString,r as resolveConfiguredSecretInputWithFallback}from"./secret-input-runtime-BSybHjM3.mjs";import{t as PUBLIC_GITHUB_COPILOT_DOMAIN}from"./domain-Bn9uiqna.mjs";import{n as PROVIDER_ID}from"./models-hnw5ORFF.mjs";import{i as parseGithubCopilotApiKey,n as formatGithubCopilotApiKey}from"./oauth-BWqU5YzB.mjs"; //!extensions/github-copilot/auth.ts async function resolveFirstGithubToken(e){const t=await ensureAuthProfileStoreAsync(e.agentDir,{allowKeychainPrompt:false});const n=listProfilesForProvider(t,PROVIDER_ID);const r=n.length>0;const i=e.profileId?.trim();const a=normalizeOptionalSecretInput(e.env.COPILOT_GITHUB_TOKEN)??``;const o=e.config?.models?.providers?.[PROVIDER_ID];const s=o?.auth===void 0||o.auth===`api-key`||o.auth===`token`;const c=s&&Boolean(coerceSecretRef(o?.apiKey,e.config?.secrets?.defaults))||o?.auth===`api-key`&&Boolean(normalizeOptionalSecretInput(o.apiKey));if(!i&&(e.authProfileMode||c||a||!r)){if(a&&!c)return{githubToken:a};if(!e.config)return{githubToken:``};const t=await resolveConfiguredSecretInputWithFallback({config:e.config,env:e.env,value:s?o?.apiKey:normalizeOptionalSecretInput(o?.apiKey),path:`models.providers.${PROVIDER_ID}.apiKey`,readFallback:()=>``});if(t.secretRefConfigured&&!t.value)throw new Error(t.unresolvedRefReason??`models.providers.${`github-copilot`}.apiKey SecretRef is unresolved.`);return{githubToken:t.value?.trim()||a}}const l=findNormalizedProviderValue(t.order,`github-copilot`)??findNormalizedProviderValue(e.config?.auth?.order,`github-copilot`);const u=i?n.find(e=>e===i):l===void 0?n[0]:resolveAuthProfileOrder({cfg:e.config,store:t,provider:PROVIDER_ID})[0];const d=u?t.profiles[u]:void 0;if(d?.type===`oauth`){const e=formatGithubCopilotApiKey(d);if(!normalizeOptionalSecretInput(d.refresh))return{githubToken:``};const t=parseGithubCopilotApiKey(e);return{...t,githubDomain:t.githubDomain??`github.com`,profileId:u}}if(d?.type!==`token`)return{githubToken:``};return{githubToken:(await resolveRequiredConfiguredSecretRefInputString({config:e.config??{},env:e.env,value:d.tokenRef,path:`providers.github-copilot.authProfiles.${u??`default`}.tokenRef`})??d.token??``).trim(),profileId:u}}export{resolveFirstGithubToken as t};