openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
4 lines • 4.12 kB
JavaScript
import{n as sanitizeForLog}from"./ansi-54CEWBZf.mjs";import{r as collectConfiguredModelRefs}from"./configured-model-refs-BvslYBsZ.mjs";import{t as applyProviderConfigDefaultsForConfig}from"./provider-policy-DP_7V9xH.mjs";import{n as loadPersistedAuthProfileStore}from"./persisted-CpbPYi0y.mjs";import{s as ensureAuthProfileStoreWithoutExternalProfiles}from"./store-runtime-GNz-2GjY.mjs";import{t as repairOAuthProfileIdMismatch}from"./repair-C0j0sRhV.mjs";import{n as listAuthProfileRepairCandidates}from"./doctor-auth-legacy-paths-B65BBpsr.mjs";import{i as removeAuthProfileConfig,r as configReferencesAuthProfile}from"./provider-auth-helpers-5o5rkp5c.mjs";
//!src/commands/doctor-auth-legacy-oauth.ts
function sanitizePromptLabel(e){return(e?sanitizeForLog(e).trim():void 0)||void 0}async function maybeRepairLegacyOAuthProfileIds(e,t){let n=e;const r=[];const i=[];const a=listAuthProfileRepairCandidates(e,process.env).map(({agentDir:e})=>({agentDir:e,profiles:loadPersistedAuthProfileStore(e)?.profiles??{}}));if(Object.keys(e.auth?.profiles??{}).length===0&&!Object.values(e.auth?.order??{}).some(e=>e.length>0)&&!Object.values(e.models?.providers??{}).some(e=>typeof e.apiKey===`string`)&&a.every(({profiles:e})=>Object.keys(e).length===0))return{config:n,retiredProfileCleanupPlans:r,findings:i};const{withPluginProviders:o}=await import(`./providers.runtime-MIvUZNGN.mjs`);return await o({config:e,env:process.env,mode:`setup`},async e=>{for(const o of e)for(const e of o.deprecatedProfileIds??[]){const s=a.flatMap(({agentDir:t,profiles:n})=>{const r=n[e];return r?[{agentDir:t,provider:r.provider}]:[]});if(s.length===0&&!configReferencesAuthProfile(n,e))continue;const{note:c}=await import(`./terminal-core/note.js`);c(`- Remove retired auth profile ${e}. The provider's native login remains unchanged.`,`Auth profiles`);const l=sanitizePromptLabel(o.label)??o.id;if(!await t.confirm({message:`Remove retired ${l} auth profile now?`,initialValue:true})){i.push({checkId:`core/doctor/auth-migration/retired-profile`,target:e,severity:`warning`,category:`recommended`,message:`Retired auth profile ${e} remains configured. Its provider's native login is unchanged.`,fixHint:`Run openclaw doctor --fix and accept the retired-profile cleanup to remove stale profile references. Keep your provider's native login.`,docsUrl:`https://docs.openclaw.ai/cli/doctor/running#auth-migration-recovery`});continue}const u=n.auth?.profiles?.[e]?.provider;const d=/* @__PURE__ */ new Set([o.id,...s.map(e=>e.provider)]);if(u)d.add(u);if(collectConfiguredModelRefs(n).some(({value:e})=>{const t=e.indexOf(`/`);return t>0&&d.has(e.slice(0,t))}))n=applyProviderConfigDefaultsForConfig({provider:o.id,config:n,env:process.env});n=removeAuthProfileConfig(n,e);for(const t of s)r.push({agentDir:t.agentDir,profileIds:[e]})}if(!Object.values(n.auth?.profiles??{}).some(e=>e?.mode===`oauth`))return{config:n,retiredProfileCleanupPlans:r,findings:i};const o=ensureAuthProfileStoreWithoutExternalProfiles();if(Object.keys(o.profiles).length===0)return{config:n,retiredProfileCleanupPlans:r,findings:i};for(const r of e)for(const e of r.oauthProfileIdRepairs??[]){const a=repairOAuthProfileIdMismatch({cfg:n,store:o,provider:r.id,legacyProfileId:e.legacyProfileId});if(!a.migrated||a.changes.length===0)continue;const{note:s}=await import(`./terminal-core/note.js`);s(a.changes.map(e=>`- ${e}`).join(`
`),`Auth profiles`);const c=sanitizePromptLabel(e.promptLabel)??sanitizePromptLabel(r.label)??r.id;if(!await t.confirm({message:`Update ${c} OAuth profile id in config now?`,initialValue:true})){i.push({checkId:`core/doctor/auth-migration/oauth-profile-id`,target:e.legacyProfileId,severity:`warning`,category:`fix-now`,message:`OAuth profile references for ${c} still use a legacy profile ID.`,fixHint:`Run openclaw doctor --fix and accept the OAuth profile ID repair, then check openclaw models status for the intended account.`,docsUrl:`https://docs.openclaw.ai/cli/doctor/running#auth-migration-recovery`});continue}n=a.config}return{config:n,retiredProfileCleanupPlans:r,findings:i}})}export{maybeRepairLegacyOAuthProfileIds};