UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

174 lines (173 loc) • 6.8 kB
import { r as truncateUtf16Safe } from "./utf16-slice-CuDyEXgS.mjs"; import { r as terminalText } from "./safe-text-C80HAQ2e.mjs"; import { t as formatCliCommand } from "./command-format-CqdwUgPk.mjs"; import { t as resolveBrewExecutable } from "./brew-B7tDLl2z.mjs"; import { t as isContainerEnvironment } from "./container-environment-BQP66a3c.mjs"; import { t as detectBinary } from "./detect-binary-B596fFLF.mjs"; import { r as t } from "./i18n-AiHKCZaZ.mjs"; import "./onboard-helpers-I6fwzX78.mjs"; import { n as buildWorkspaceSkillStatus } from "./status-C6DUmZEt.mjs"; import { i as resolveInstallerKindReadiness, n as installSkill, t as MIN_AUTO_GO_VERSION } from "./install-ChEop2sy.mjs"; //#region src/commands/onboard-skills.ts const SKIPPED_INSTALL_NAME_LIMIT = 8; function summarizeInstallFailure(e) { const n = terminalText`${e}`.replace(/^Install failed(?:\s*\([^)]*\))?\s*:?\s*/i, "").trim(); if (!n) return; return n.length > 140 ? `${truncateUtf16Safe(n, 139)}…` : n; } function formatSkillHint(e) { const n = e.description?.trim(); const r = e.install[0]?.label?.trim(); const i = terminalText`${n && r ? `${n} — ${r}` : n || r || ""}`; if (!i) return "install"; return i.length > 90 ? `${truncateUtf16Safe(i, 89)}…` : i; } const SKIP_REASON_LABELS = { brew: "Homebrew", go: `Go toolchain (${MIN_AUTO_GO_VERSION}+)`, uv: "uv" }; /** Runs the interactive skills setup step and returns the updated config. */ async function setupSkills(e, n, r, i, a = {}) { const o = buildWorkspaceSkillStatus(n, { config: e }); const s = o.skills.filter((e) => e.eligible); const c = o.skills.filter((e) => !e.disabled && !e.blockedByAllowlist && e.missing.os.length > 0); const l = o.skills.filter((e) => !e.eligible && !e.disabled && !e.blockedByAllowlist && e.missing.os.length === 0); const u = o.skills.filter((e) => e.blockedByAllowlist); await i.note([ `Eligible: ${s.length}`, `Missing requirements: ${l.length}`, `Unsupported on this OS: ${c.length}`, `Blocked by allowlist: ${u.length}` ].join("\n"), t("wizard.skills.statusTitle")); const d = l.filter((e) => e.install.length > 0 && e.missing.bins.length > 0 && e.bundled && e.source === "openclaw-bundled"); const f = /* @__PURE__ */ new Map(); const resolveKindReadinessOnce = async (e) => { const n = f.get(e); if (n) return n; const r = await resolveInstallerKindReadiness(e); f.set(e, r); return r; }; const p = process.platform === "linux" && isContainerEnvironment(); let m = d; if (p && d.length > 0 && !await detectBinary("brew") && resolveBrewExecutable() === void 0) { m = d.filter((e) => e.install.some((e) => e.kind !== "brew")); if (m.length < d.length) await i.note([t("wizard.skills.containerBrewHidden"), t("wizard.skills.containerBrewManual")].join("\n"), t("wizard.skills.containerInstallsTitle")); } const h = m; let g = e; if (h.length === 0 && l.length === 0) { await i.note([ "No missing skill dependencies to install.", `To inspect available skills, run: ${formatCliCommand("openclaw skills list --verbose")}`, `To check skill status, run: ${formatCliCommand("openclaw skills check")}` ].join("\n"), t("wizard.skills.allReadyTitle") ?? "All skills ready"); return g; } if (h.length > 0) { const e = (await i.multiselect({ message: t("wizard.skills.installDeps"), options: [{ value: "__skip__", label: t("common.skipForNow"), hint: t("wizard.skills.skipDepsHint") }, ...h.map((e) => ({ value: e.name, label: terminalText`${e.emoji ?? "🧩"} ${e.name}`, hint: formatSkillHint(e) }))] })).filter((e) => e !== "__skip__").map((e) => h.find((n) => n.name === e)).filter((e) => e !== void 0); const o = []; const s = []; for (const n of e) { const e = n.install[0]; if (!e) continue; const r = await resolveKindReadinessOnce(e.kind); if (r.ready) o.push(n); else s.push({ skill: n, reason: r.reason }); } if (o.some((e) => e.install.some((e) => e.kind === "node"))) { const e = a.nodeManager ?? g.skills?.install?.nodeManager ?? "npm"; g = { ...g, skills: { ...g.skills, install: { ...g.skills?.install, nodeManager: e } } }; } for (const e of o) { const o = e.install[0]?.id; if (!o) continue; await a.beforePersistentEffect?.(); const c = i.progress(t("wizard.skills.installing", { name: terminalText`${e.name}` })); const l = await installSkill({ workspaceDir: n, skillName: e.name, installId: o, config: g }); const u = l.warnings ?? []; if (l.ok) c.stop(u.length > 0 ? t("wizard.skills.installedWithWarnings", { name: terminalText`${e.name}` }) : t("wizard.skills.installed", { name: terminalText`${e.name}` })); else if (l.skipReason) { c.stop(t("wizard.skills.installSkipped", { name: terminalText`${e.name}` })); const n = summarizeInstallFailure(l.message); s.push({ skill: e, reason: l.skipReason, ...n ? { detail: n } : {} }); } else { const n = l.code == null ? "" : ` (exit ${l.code})`; const r = summarizeInstallFailure(l.message); c.stop(t("wizard.skills.installFailed", { name: terminalText`${e.name}`, code: n, detail: r ? ` - ${r}` : "" })); } for (const e of u) r.log(e); if (l.ok || l.skipReason) continue; if (l.stderr) r.log(l.stderr.trim()); else if (l.stdout) r.log(l.stdout.trim()); r.log(`Tip: run \`${formatCliCommand("openclaw doctor")}\` to review skills + requirements.`); r.log(t("wizard.skills.docsLine")); } if ((process.platform === "darwin" || process.platform === "linux") && s.some((e) => e.reason === "brew")) await i.note([ "Many skill dependencies are shipped via Homebrew.", "Without brew, you'll need to build from source or download releases manually.", "", "Install Homebrew:", "/bin/bash -c \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\"" ].join("\n"), t("wizard.skills.homebrewRecommendedTitle")); if (s.length > 0) { const e = s; const n = [t("wizard.skills.manualPrereqsIntro")]; for (const r of [ "brew", "go", "uv" ]) { const i = e.filter((e) => e.reason === r).map((e) => e.skill.name); if (i.length > 0) { const e = i.slice(0, SKIPPED_INSTALL_NAME_LIMIT); const a = i.length > e.length ? ` (+${i.length - e.length} more)` : ""; n.push(terminalText`${SKIP_REASON_LABELS[r]}: ${e.join(", ")}${a}`); } } for (const r of e.filter((e) => e.detail).slice(0, SKIPPED_INSTALL_NAME_LIMIT)) n.push(terminalText`${r.skill.name}: ${r.detail}`); n.push(t("wizard.skills.manualPrereqsDoctorHint")); await i.note(n.join("\n"), t("wizard.skills.manualPrereqsTitle")); } } return g; } //#endregion export { setupSkills as t };