UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

79 lines (78 loc) • 2.9 kB
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs"; import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs"; import { r as filterStringEntries } from "./string-normalization-DLmfYZXI.mjs"; import { i as runUtf8CommandWithTimeout } from "./exec-runner-Br73vG-X.mjs"; import { a as resolveWindowsSpawnProgram, r as materializeWindowsSpawnProgram } from "./windows-spawn-BcHMKZuG.mjs"; import "./string-coerce-runtime-BwAZZDf5.mjs"; import "./process-runtime-DcBPEA8Y.mjs"; import { r as CLAUDE_CLI_CLEAR_ENV } from "./cli-constants-CDevEMvo.mjs"; //#region extensions/anthropic/cli-auth-seam.ts const CLAUDE_CLI_AUTH_TIMEOUT_MS = 1e4; const CLAUDE_CLI_AUTH_METHODS = [ "claude.ai", "api_key", "api_key_helper", "oauth_token", "third_party", "none" ]; const CLI_BACKEND_PRESERVE_ENV = "OPENCLAW_LIVE_CLI_BACKEND_PRESERVE_ENV"; function readPreservedCliEnv(e) { const t = e[CLI_BACKEND_PRESERVE_ENV]?.trim(); if (!t) return /* @__PURE__ */ new Set(); if (t.startsWith("[")) try { return new Set(filterStringEntries(JSON.parse(t))); } catch { return /* @__PURE__ */ new Set(); } return new Set(t.split(/[,\s]+/).filter(Boolean)); } /** Ask Claude CLI whether its own login is usable without reading token material. */ async function probeClaudeCliAuthStatus(e) { const t = { ...e?.env ?? process.env }; const n = readPreservedCliEnv(t); for (const e of CLAUDE_CLI_CLEAR_ENV) if (!n.has(e)) delete t[e]; try { const n = resolveWindowsSpawnProgram({ command: e?.command ?? "claude", env: t, packageName: "@anthropic-ai/claude-code" }); const r = materializeWindowsSpawnProgram(n, [ "auth", "status", "--json" ]); e?.signal?.throwIfAborted(); const i = await runUtf8CommandWithTimeout([r.command, ...r.argv], { baseEnv: t, maxOutputBytes: 65536, maxCombinedOutputBytes: 65536, terminateOnOutputLimit: true, timeoutMs: CLAUDE_CLI_AUTH_TIMEOUT_MS, killProcessTree: true }); e?.signal?.throwIfAborted(); if (i.termination === "timeout") return { status: "timeout", timeoutMs: CLAUDE_CLI_AUTH_TIMEOUT_MS }; if (i.termination !== "exit" || i.code === null) return { status: "unreadable" }; const a = JSON.parse(i.stdout); if (!isRecord(a) || typeof a.loggedIn !== "boolean") return { status: "unreadable" }; if (!a.loggedIn) return { status: "missing" }; if (i.code !== 0) return { status: "unreadable" }; const o = CLAUDE_CLI_AUTH_METHODS.find((e) => e === a.authMethod); const s = o === "claude.ai" ? normalizeOptionalString(a.email) : void 0; return { status: "available", ...o ? { authMethod: o } : {}, ...s && s.length <= 320 && !/[\r\n]/u.test(s) ? { email: s } : {} }; } catch (t) { e?.signal?.throwIfAborted(); return { status: isRecord(t) && t.code === "ENOENT" ? "not-installed" : "unreadable" }; } } //#endregion export { probeClaudeCliAuthStatus as t };