UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

113 lines (112 loc) • 4.88 kB
import { r as resolveOsHomeDir } from "./home-dir-zhqynwRJ.mjs"; import { t as formatErrorMessage } from "./errors-BKzCeTYb.mjs"; import { A as tryResolveLegacyCompatibilityAgentId, r as resolveAgentConfig } from "./agent-scope-config-DmXgFGKP.mjs"; import { s as resolveAgentModelPrimaryValue } from "./model-input-DrM4DWHG.mjs"; import { t as splitTrailingAuthProfile } from "./model-ref-profile-C7DWqVP0.mjs"; import "./legacy.default-agent-owner-DpmHgK0A.mjs"; import { _ as resolveConfiguredRouteModelLabel } from "./model-selection-shared-9Kz63Hhm.mjs"; import { n as resolveDefaultModelForAgent } from "./model-selection-config-Bvf5WqHo.mjs"; import "./model-selection-C2A4Wyix.mjs"; import { c as resolveCodexCliHomePath, o as readGeminiCliCredentialsCached, t as hasCodexCliAuthFile } from "./cli-credentials-BaPg7qWx.mjs"; import { n as probeLocalCommand } from "./probes-BWEX26cj.mjs"; import { i as GEMINI_CLI_DEFAULT_MODEL_REF, n as CLAUDE_CLI_DEFAULT_MODEL_REF, o as detectAmbientInferenceBackends, r as CODEX_APP_SERVER_DEFAULT_MODEL_REF } from "./onboard-inference-ambient-Dm4ClvNb.mjs"; import path from "node:path"; import os from "node:os"; //#region src/commands/onboard-inference.ts /** * Onboarding treats inference as the one required step: reuse whatever the * machine already has without activating providers. CLI version and credential * presence are detection evidence; explicit setup verifies the selected login. */ const CODEX_MACOS_APP_NAMES = [ "ChatGPT.app", "Codex.app", "Codex Beta.app" ]; const CODEX_MACOS_APP_PROBE_TIMEOUT_MS = 3e3; async function probeCodexCommand() { const e = await probeLocalCommand("codex"); if (e.found || e.failure === "error" || process.platform !== "darwin") return e; const t = process.env.HOME?.trim() || os.homedir(); const n = new Set(CODEX_MACOS_APP_NAMES.flatMap((e) => [path.join("/Applications", e, "Contents", "Resources", "codex"), path.join(t, "Applications", e, "Contents", "Resources", "codex")])); for (const e of n) { const t = await probeLocalCommand(e, ["--version"], { timeoutMs: CODEX_MACOS_APP_PROBE_TIMEOUT_MS }); if (t.found || t.failure === "error") return t; } return e; } /** * Detect usable inference backends in ladder order. Returns candidates only * for backends that exist on this machine; explicit setup owns selection. * Native CLI discovery stays passive; environment credentials precede unverified CLIs. */ async function detectInferenceBackends(e = {}) { const t = []; const n = e.config ? e.agentId?.trim() || tryResolveLegacyCompatibilityAgentId(e.config) : void 0; const r = e.config && n ? resolveAgentConfig(e.config, n)?.model : void 0; const i = resolveAgentModelPrimaryValue(r) ?? resolveAgentModelPrimaryValue(e.config?.agents?.defaults?.model); if (i) { const r = resolveDefaultModelForAgent({ cfg: e.config ?? {}, ...n ? { agentId: n } : {} }); const a = splitTrailingAuthProfile(i).profile; const o = resolveConfiguredRouteModelLabel({ configuredRef: i, resolved: r, ...a ? { profileId: a } : {} }); t.push({ kind: "existing-model", modelRef: o, label: "Current model", detail: `${o} — already configured`, credentials: true }); } const a = detectAmbientInferenceBackends(); const [o, s, c] = await Promise.all([ probeLocalCommand("claude"), probeCodexCommand(), probeLocalCommand("gemini") ]); if (s.failure === "error" || s.timedOut) throw new Error(`Codex detection failed (${s.command}): ${s.error ?? "version probe failed"}. Check the Codex installation and execution permissions, then retry setup.`); const l = []; if (o.found && !o.timedOut) l.push({ kind: "claude-cli", modelRef: CLAUDE_CLI_DEFAULT_MODEL_REF, label: "Claude Code", detail: "installed; login status unverified" }); let u; try { const e = resolveOsHomeDir(process.env) || process.env.CODEX_HOME?.trim(); u = Boolean(e) && hasCodexCliAuthFile(resolveCodexCliHomePath()); } catch (e) { throw new Error(`Codex sign-in detection failed: ${formatErrorMessage(e)}. Check access to the Codex home, then retry setup.`, { cause: e }); } if (s.found || u) l.push({ kind: "codex-cli", modelRef: CODEX_APP_SERVER_DEFAULT_MODEL_REF, label: "Codex", detail: u ? s.found ? "installed; stored credentials found; login status unverified" : "stored credentials found; runtime installation required" : "installed; login status unverified", credentials: u }); if (c.found && !c.timedOut) { const e = readGeminiCliCredentialsCached({ ttlMs: 6e4 }) !== null ? true : void 0; l.push({ kind: "gemini-cli", modelRef: GEMINI_CLI_DEFAULT_MODEL_REF, label: "Gemini CLI", detail: e ? "installed; credentials found" : "installed; login status unavailable", ...e === void 0 ? {} : { credentials: e } }); } return [ ...t, ...a, ...l ]; } //#endregion export { detectInferenceBackends as t };