UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

65 lines (64 loc) 2.91 kB
import { m as readNonBlankString } from "./string-coerce-CIXf7egm.js"; import { c as resolveUserPath } from "./home-dir-BPhrG-aM.js"; import "./utils-P__uGsPB.js"; import { o as listAgentIds, u as resolveAgentDir } from "./agent-scope-config-DcbEhP0R.js"; import { w as resolveStateDir } from "./paths-D2sRr1a_.js"; import "./agent-scope-DbtJyKUL.js"; import { c as resolveSharedMainAuthAgentDir } from "./path-resolve-oRkRBkQd.js"; import { r as resolveLegacyInheritedAuthAgentDir } from "./legacy-inherited-auth-dir-CMGSmv-F.js"; import fs from "node:fs"; import path from "node:path"; //#region src/commands/doctor-auth-legacy-paths.ts function resolveLegacyAuthAgentDir(agentDir) { return agentDir ? resolveUserPath(agentDir) : resolveSharedMainAuthAgentDir(); } function listExistingAgentDirsFromState(env) { const root = path.join(resolveStateDir(env), "agents"); let entries; try { entries = fs.readdirSync(root, { withFileTypes: true }); } catch { return []; } return entries.filter((entry) => entry.isDirectory() || entry.isSymbolicLink()).map((entry) => path.join(root, entry.name, "agent")).filter((agentDir) => { try { return fs.statSync(agentDir).isDirectory(); } catch { return false; } }); } /** * One canonical enumeration of legacy auth-store repair candidates. Sidecar * inline-recovery and flat-store SQLite migration must see the same dirs, or * decryptable sidecar secrets get imported as credential-less profiles. */ function listAuthProfileRepairCandidates(cfg, env) { const candidates = /* @__PURE__ */ new Map(); const addCandidate = (agentDir) => { const resolvedAgentDir = agentDir ? resolveUserPath(agentDir, env) : void 0; const authPath = resolveLegacyAuthProfilesPath(resolvedAgentDir ?? resolveSharedMainAuthAgentDir(env)); if (!candidates.get(authPath) || agentDir === void 0) candidates.set(authPath, { agentDir: resolvedAgentDir, authPath }); }; addCandidate(void 0); addCandidate(resolveLegacyInheritedAuthAgentDir(cfg, env)); const envAgentDir = readNonBlankString(env.OPENCLAW_AGENT_DIR) ?? readNonBlankString(env.PI_CODING_AGENT_DIR); if (envAgentDir) addCandidate(envAgentDir); for (const agentId of listAgentIds(cfg)) addCandidate(resolveAgentDir(cfg, agentId, env)); for (const agentDir of listExistingAgentDirsFromState(env)) addCandidate(agentDir); return [...candidates.values()]; } function resolveLegacyAuthProfilesPath(agentDir) { return path.join(resolveLegacyAuthAgentDir(agentDir), "auth-profiles.json"); } function resolveLegacyAuthStatePath(agentDir) { return path.join(resolveLegacyAuthAgentDir(agentDir), "auth-state.json"); } function resolveLegacyFlatAuthPath(agentDir) { return path.join(resolveLegacyAuthAgentDir(agentDir), "auth.json"); } //#endregion export { resolveLegacyFlatAuthPath as i, resolveLegacyAuthProfilesPath as n, resolveLegacyAuthStatePath as r, listAuthProfileRepairCandidates as t };