openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
129 lines (128 loc) • 5.06 kB
JavaScript
import { n as sanitizeForLog } from "./ansi-CZa2t0Hf.mjs";
import { r as collectConfiguredModelRefs } from "./configured-model-refs-DtaDJ1Vw.mjs";
import { t as applyProviderConfigDefaultsForConfig } from "./provider-policy-Bet0NXK_.mjs";
import { n as loadPersistedAuthProfileStore } from "./persisted-Dv3zNYHi.mjs";
import { s as ensureAuthProfileStoreWithoutExternalProfiles } from "./store-runtime-dW0pXLJI.mjs";
import { t as repairOAuthProfileIdMismatch } from "./repair-O0s3O0SG.mjs";
import { n as listAuthProfileRepairCandidates } from "./doctor-auth-legacy-paths-C0oSsdur.mjs";
import { i as removeAuthProfileConfig, r as configReferencesAuthProfile } from "./provider-auth-helpers-ByDXB7Po.mjs";
//#region src/commands/doctor-auth-legacy-oauth.ts
function sanitizePromptLabel(e) {
return (e ? sanitizeForLog(e).trim() : void 0) || void 0;
}
/**
* Applies provider-declared OAuth profile id repairs to config after prompting.
*
* Providers own the legacy id mapping; doctor only loads setup-time provider metadata and asks
* before writing config so stale provider-specific ids do not silently shadow current profiles.
*/
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 { resolvePluginProvidersCore: o } = await import("./providers.runtime.js");
const s = o({
config: e,
env: process.env,
mode: "setup"
});
for (const e of s) for (const o of e.deprecatedProfileIds ?? []) {
const s = a.flatMap(({ agentDir: e, profiles: t }) => {
const n = t[o];
return n ? [{
agentDir: e,
provider: n.provider
}] : [];
});
if (s.length === 0 && !configReferencesAuthProfile(n, o)) continue;
const { note: c } = await import("./terminal-core/note.js");
c(`- Remove retired auth profile ${o}. The provider's native login remains unchanged.`, "Auth profiles");
const l = sanitizePromptLabel(e.label) ?? e.id;
if (!await t.confirm({
message: `Remove retired ${l} auth profile now?`,
initialValue: true
})) {
i.push({
checkId: "core/doctor/auth-migration/retired-profile",
target: o,
severity: "warning",
category: "recommended",
message: `Retired auth profile ${o} 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?.[o]?.provider;
const d = /* @__PURE__ */ new Set([e.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: e.id,
config: n,
env: process.env
});
n = removeAuthProfileConfig(n, o);
for (const e of s) r.push({
agentDir: e.agentDir,
profileIds: [o]
});
}
if (!Object.values(n.auth?.profiles ?? {}).some((e) => e?.mode === "oauth")) return {
config: n,
retiredProfileCleanupPlans: r,
findings: i
};
const c = ensureAuthProfileStoreWithoutExternalProfiles();
if (Object.keys(c.profiles).length === 0) return {
config: n,
retiredProfileCleanupPlans: r,
findings: i
};
for (const e of s) for (const r of e.oauthProfileIdRepairs ?? []) {
const a = repairOAuthProfileIdMismatch({
cfg: n,
store: c,
provider: e.id,
legacyProfileId: r.legacyProfileId
});
if (!a.migrated || a.changes.length === 0) continue;
const { note: o } = await import("./terminal-core/note.js");
o(a.changes.map((e) => `- ${e}`).join("\n"), "Auth profiles");
const s = sanitizePromptLabel(r.promptLabel) ?? sanitizePromptLabel(e.label) ?? e.id;
if (!await t.confirm({
message: `Update ${s} OAuth profile id in config now?`,
initialValue: true
})) {
i.push({
checkId: "core/doctor/auth-migration/oauth-profile-id",
target: r.legacyProfileId,
severity: "warning",
category: "fix-now",
message: `OAuth profile references for ${s} 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
};
}
//#endregion
export { maybeRepairLegacyOAuthProfileIds };