UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

126 lines (125 loc) • 4.01 kB
import { t as hasNonEmptyString } from "./string-coerce-CCIiB4H7.mjs"; import { c as resolveUserPath } from "./home-dir-EKmgmdPG.mjs"; import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs"; import { r as resolveStateDir } from "./state-dir-DiG0gXzD.mjs"; import "./utils-C8YECn2Q.mjs"; import "./paths-DAcAg5aV.mjs"; import { i as listAgentIds } from "./agent-roster-t1ooUdXp.mjs"; import { a as resolveAgentDir } from "./agent-scope-config-DmXgFGKP.mjs"; import { t as readExistingStateRootMode } from "./private-dir-mode-D4XRpa8Z.mjs"; import "./agent-scope-BwB8YH6y.mjs"; import "./shared-DyBTHA2R.mjs"; import { u as AUTH_PROFILE_SECRET_FIELDS } from "./target-registry-query-le6rMGHo.mjs"; import { t as createConfigIO } from "./io.factory-DEa_bi2j.mjs"; import { H as resolveNativeSharedAuthStorePath, b as resolveAuthProfileDatabasePath } from "./sqlite-B2CoJ4Om.mjs"; import "./config-CMA-J084.mjs"; import { r as writePrivateTextFileAtomicSync } from "./private-file-store-D564pKJx.mjs"; import fs from "node:fs"; import path from "node:path"; import { replaceFileAtomicSync } from "@openclaw/fs-safe/atomic"; //#region src/secrets/auth-profiles-scan.ts /** Scans auth-profile stores for plaintext credentials, SecretRefs, and OAuth tokens. */ /** Iterates credential-bearing auth profiles with normalized field metadata for audit/apply. */ function* iterateAuthProfileCredentials(e) { for (const [t, n] of Object.entries(e)) { if (!isRecord(n) || !hasNonEmptyString(n.provider)) continue; const e = n.provider; if (n.type === "api_key" || n.type === "token") { const r = AUTH_PROFILE_SECRET_FIELDS[n.type]; yield { kind: n.type, profileId: t, provider: e, profile: n, valueField: r.valueField, refField: r.refField, value: n[r.valueField], refValue: n[r.refField] }; continue; } if (n.type === "oauth") yield { kind: "oauth", profileId: t, provider: e, profile: n, hasAccess: hasNonEmptyString(n.access), hasRefresh: hasNonEmptyString(n.refresh) }; } } //#endregion //#region src/secrets/auth-store-paths.ts function listAuthProfileStoreTargets(e, t, n = process.env) { const r = /* @__PURE__ */ new Map(); const i = { ...n, OPENCLAW_STATE_DIR: t, OPENCLAW_AGENT_DIR: void 0 }; const addTarget = (e) => { const t = path.resolve(e.path); if (r.get(t)?.kind === "shared") return; r.set(t, e); }; addTarget({ kind: "shared", path: resolveNativeSharedAuthStorePath(i), env: i, stateDir: t }); const a = path.join(resolveUserPath(t, i), "agents"); if (fs.existsSync(a)) for (const e of fs.readdirSync(a, { withFileTypes: true })) { if (!e.isDirectory()) continue; const t = path.join(a, e.name, "agent"); addTarget({ kind: "agent", agentDir: t, path: resolveAuthProfileDatabasePath(t) }); } for (const t of listAgentIds(e)) { const n = resolveUserPath(resolveAgentDir(e, t, i), i); addTarget({ kind: "agent", agentDir: n, path: resolveAuthProfileDatabasePath(n) }); } return [...r.values()]; } //#endregion //#region src/secrets/config-io.ts /** Config IO adapter used by secrets apply/configure flows. */ const silentConfigIoLogger = { error: () => {}, warn: () => {} }; /** * Creates config I/O for secrets commands with config-loader logging suppressed. */ function createSecretsConfigIO(e) { return createConfigIO({ env: e.env, logger: silentConfigIoLogger }); } /** * Atomically writes secret-adjacent text, using the private store for default 0600 files. */ function writeTextFileAtomic(e, t, n = 384, r = process.env) { const i = resolveStateDir(r); if (n !== 384) { replaceFileAtomicSync({ filePath: e, content: t, mode: n, dirMode: readExistingStateRootMode(path.dirname(e), i), tempPrefix: ".openclaw-secrets" }); return; } writePrivateTextFileAtomicSync(e, t, i); } //#endregion export { iterateAuthProfileCredentials as i, writeTextFileAtomic as n, listAuthProfileStoreTargets as r, createSecretsConfigIO as t };