openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
640 lines (639 loc) • 23 kB
JavaScript
import { c as resolveUserPath } from "./home-dir-EKmgmdPG.mjs";
import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs";
import { b as uniqueStrings } from "./string-normalization-DLmfYZXI.mjs";
import { r as truncateUtf16Safe } from "./utf16-slice-CuDyEXgS.mjs";
import { i as stripAnsi } from "./ansi-CZa2t0Hf.mjs";
import { n as sanitizeTerminalText } from "./safe-text-C80HAQ2e.mjs";
import { r as isPathInside } from "./path-guards-TIjxtj6H.mjs";
import "./utils-C8YECn2Q.mjs";
import { A as withTimeout } from "./fs-safe-BbWvmdVn.mjs";
import { t as VERSION } from "./version-GlxUMdxI.mjs";
import { t as clearPluginMetadataLifecycleCaches } from "./plugin-metadata-lifecycle-C9EqhiS5.mjs";
import { a as resolveDefaultPluginExtensionsDir } from "./install-paths-Bwm0P5EG.mjs";
import { A as resolvePluginInstallSources, C as NpmChannelResolutionError, D as resolveClawHubInstallSpecsForUpdateChannel, E as isUnavailablePluginSource, M as parseClawHubPluginSpec, T as installWithSourceFallback, k as resolveNpmInstallSpecsForUpdateChannel, w as installWithChannelFallback } from "./official-external-plugin-catalog-DtkWz1Xo.mjs";
import { s as parseRegistryNpmSpec, t as buildNpmResolutionFields } from "./npm-registry-spec-HKkAvl6N.mjs";
import { o as clearLoadInstalledPluginIndexInstallRecordsCache } from "./installed-plugin-index-record-reader-B-7uGQZ9.mjs";
import { c as normalizeUpdateChannel, u as resolveRegistryUpdateChannel } from "./update-channels-CDc4OFaS.mjs";
import { r as isUnavailableClawHubTarget } from "./clawhub-error-codes-5kIjtf6h.mjs";
import { n as isUnavailableNpmTarget } from "./install-types-BBbGKapR.mjs";
import { t as ManagedPluginLifecycleError } from "./management-lifecycle-error-COJYzrtT.mjs";
import { t as enableExplicitlySelectedPluginInConfig } from "./enable-BY2SJL8Z.mjs";
import { r as assertConfigWriteAllowedInCurrentMode } from "./config-write-guard-CxNxfJ_I.mjs";
import { s as withPluginLifecycleLeaseAsync } from "./plugin-lifecycle-lease-CXjHGDEI.mjs";
import { c as recordPluginInstall } from "./installed-plugin-index-records-MNCNSlg8.mjs";
import { n as WizardCancelledError, r as WizardNavigationError } from "./prompts-CCXo2K24.mjs";
import { r as t } from "./i18n-AiHKCZaZ.mjs";
import { a as resolveBundledPluginSources, n as findBundledPluginSourceInMap } from "./bundled-sources-CIS6N5EC.mjs";
import { a as installPluginFromNpmPackArchive, r as installPluginFromNpmSpec } from "./install-Xai3w73h.mjs";
import { n as resolveBundledInstallPlanForCatalogEntry } from "./install-source-plan-CS6sfMiy.mjs";
import { r as prepareManagedPluginArtifactConsentHandler, t as capturePluginCapabilityConsentHandlerErrors } from "./capability-consent-ByRkpzSz.mjs";
import { t as buildClawHubPluginInstallRecordFields } from "./clawhub-install-records-DSHcVKgw.mjs";
import { t as invalidatePluginRuntimeDiscoveryAfterConfigMutation } from "./registry-refresh-Bfs6LAit.mjs";
import { t as createPluginCapabilityConsentPrompter } from "./plugin-capability-consent-jChdL17s.mjs";
import fs from "node:fs";
import path from "node:path";
//#region src/plugins/install-overrides.ts
/** Env var containing JSON plugin install override specs. */
const PLUGIN_INSTALL_OVERRIDES_ENV = "OPENCLAW_PLUGIN_INSTALL_OVERRIDES";
/** Env var gate that must be enabled before install overrides are honored. */
const ALLOW_PLUGIN_INSTALL_OVERRIDES_ENV = "OPENCLAW_ALLOW_PLUGIN_INSTALL_OVERRIDES";
function overrideAllowed(e) {
return e[ALLOW_PLUGIN_INSTALL_OVERRIDES_ENV]?.trim() === "1";
}
function parseOverrideSpec(e) {
const n = e.trim();
if (!n) return null;
if (n.startsWith("npm:")) {
const e = n.slice(4).trim();
return e && parseRegistryNpmSpec(e) ? {
kind: "npm",
spec: e
} : null;
}
if (n.startsWith("npm-pack:")) {
const e = n.slice(9).trim();
if (!e) return null;
return {
kind: "npm-pack",
archivePath: resolveUserPath(e)
};
}
return null;
}
/** Resolves a gated plugin install override from environment configuration. */
function resolvePluginInstallOverride(e) {
const n = process.env;
if (!overrideAllowed(n)) return null;
const r = n[PLUGIN_INSTALL_OVERRIDES_ENV]?.trim();
if (!r) return null;
let i;
try {
i = JSON.parse(r);
} catch {
return null;
}
if (!isRecord(i)) return null;
const a = i[e.pluginId];
return typeof a === "string" ? parseOverrideSpec(a) : null;
}
//#endregion
//#region src/commands/onboarding-plugin-install.ts
const ONBOARDING_PLUGIN_INSTALL_TIMEOUT_MS = 3e5;
const ONBOARDING_PLUGIN_INSTALL_WATCHDOG_TIMEOUT_MS = 305e3;
function incompletePluginInstall(e, n, r, i) {
return {
cfg: e,
installed: false,
pluginId: n,
status: r,
...i === void 0 ? {} : { error: i }
};
}
function resolveRealDirectory(e) {
try {
const n = fs.realpathSync(e);
return fs.statSync(n).isDirectory() ? n : null;
} catch {
return null;
}
}
function resolveGitDirectoryMarker(e) {
const n = path.join(e, ".git");
try {
const r = fs.statSync(n);
if (r.isDirectory()) return resolveRealDirectory(n);
if (!r.isFile()) return null;
const i = fs.readFileSync(n, "utf8").trim();
const a = /^gitdir:\s*(.+)$/i.exec(i)?.[1]?.trim();
if (!a) return null;
return resolveRealDirectory(path.isAbsolute(a) ? a : path.resolve(e, a));
} catch {
return null;
}
}
function hasTrustedGitWorkspace(e) {
const n = resolveRealDirectory(e);
if (!n) return false;
for (let e = n;; e = path.dirname(e)) {
if (resolveGitDirectoryMarker(e)) return true;
if (path.dirname(e) === e) return false;
}
}
function resolveLocalPluginRoots(e) {
const n = [process.cwd()];
if (e && e !== process.cwd()) n.push(e);
return n;
}
function addPluginLoadPath(e, n) {
const r = e.plugins?.load?.paths ?? [];
const i = uniqueStrings([...r, n]);
return {
...e,
plugins: {
...e.plugins,
load: {
...e.plugins?.load,
paths: i
}
}
};
}
function pathsReferToSameDirectory(e, n) {
if (!e || !n) return false;
const r = resolveRealDirectory(e);
const i = resolveRealDirectory(n);
return Boolean(r && i && r === i);
}
function formatPortableLocalPath(e, n) {
const r = [n, process.cwd()].filter((e) => Boolean(e));
for (const n of r) {
const r = resolveRealDirectory(n);
if (!r) continue;
if (isPathInside(r, e)) {
const n = path.relative(r, e).split(path.sep).join("/");
return n ? `./${n}` : ".";
}
}
}
function resolveLocalPath(e) {
if (!e.allowLocal) return null;
const n = e.entry.install.localPath?.trim();
if (!n) return null;
const r = resolveLocalPluginRoots(e.workspaceDir).map(resolveRealDirectory).filter((e) => e !== null);
for (const e of r) {
const i = resolveRealDirectory(path.resolve(e, n));
if (i && r.some((e) => isPathInside(e, i))) return i;
}
return null;
}
function resolveBundledLocalPath(e) {
const n = resolveBundledPluginSources({ workspaceDir: e.workspaceDir });
const r = e.entry.install.npmSpec?.trim();
if (r) return resolveBundledInstallPlanForCatalogEntry({
pluginId: e.entry.pluginId,
npmSpec: r,
findBundledSource: (e) => findBundledPluginSourceInMap({
bundled: n,
lookup: e
})
})?.bundledSource.localPath ?? null;
return findBundledPluginSourceInMap({
bundled: n,
lookup: {
kind: "pluginId",
value: e.entry.pluginId
}
})?.localPath ?? null;
}
async function reportPluginInstallTimeout(e, n) {
const r = sanitizeTerminalText(n);
await e.prompter.note([t("wizard.plugins.installTimedOut", {
spec: r,
duration: t("common.minutes", { count: ONBOARDING_PLUGIN_INSTALL_TIMEOUT_MS / 6e4 })
}), t("wizard.plugins.returningToSelection")].join("\n"), t("wizard.plugins.installTitle"));
e.runtime.error?.(`Plugin install timed out after ${ONBOARDING_PLUGIN_INSTALL_TIMEOUT_MS}ms: ${r}`);
return incompletePluginInstall(e.cfg, e.entry.pluginId, "timed_out");
}
function summarizeInstallError(e) {
const n = sanitizeTerminalText(e).replace(/^Install failed(?:\s*\([^)]*\))?\s*:?\s*/i, "").trim();
if (!n) return "Unknown install failure";
return n.length > 180 ? `${truncateUtf16Safe(n, 179)}…` : n;
}
const ONBOARDING_PLUGIN_INSTALL_ERROR_MAX_CHARS = 12e3;
function formatInstallErrorDetail(e) {
const n = e.replace(/\r\n?/g, "\n").split("\n").map((e) => sanitizeTerminalText(e)).join("\n").trim();
if (n.length <= ONBOARDING_PLUGIN_INSTALL_ERROR_MAX_CHARS) return n;
return `${truncateUtf16Safe(n, 11969).trimEnd()}
… (installer output truncated)`;
}
async function notePluginInstallFailure(e, n, r) {
await e.note([t("wizard.plugins.installFailed", {
spec: sanitizeTerminalText(n),
error: summarizeInstallError(r)
}), t("wizard.plugins.returningToSelection")].join("\n"), t("wizard.plugins.installTitle"));
}
function isTimeoutError(e) {
return e instanceof Error && e.message === "timeout";
}
async function finishOnboardingPluginInstall(e, n) {
const r = enableExplicitlySelectedPluginInConfig(e.cfg, n.pluginId);
if (!r.enabled) {
const i = sanitizeTerminalText(e.entry.label);
const a = r.reason ?? "plugin disabled";
await e.prompter.note(t("wizard.plugins.enableFailed", {
plugin: i,
reason: a
}), t("wizard.plugins.installTitle"));
e.runtime.error?.(`Plugin install failed: ${sanitizeTerminalText(n.pluginId)} is disabled (${a}).`);
return incompletePluginInstall(r.config, n.pluginId, "failed");
}
const i = n.install ? recordPluginInstall(r.config, n.install) : await n.prepareConfig?.(r.config) ?? r.config;
clearLoadInstalledPluginIndexInstallRecordsCache();
clearPluginMetadataLifecycleCaches();
await invalidatePluginRuntimeDiscoveryAfterConfigMutation({ logger: { warn: (n) => e.runtime.log(n) } });
return {
cfg: i,
installed: true,
pluginId: n.pluginId,
status: "installed"
};
}
function logInstallWarning(e, n, r = false) {
const i = (r ? n.split("\n") : [n]).map((e) => sanitizeTerminalText(e)).join("\n").trim();
if (!i) return;
e.log?.(`${i}\n`);
}
function startPluginInstallProgress(e, n) {
const r = e.progress(t("wizard.plugins.installingPlugin", { plugin: n }));
r.update(t("wizard.plugins.preparingInstall"));
return {
progress: r,
updateProgress: (e) => {
const n = sanitizeTerminalText(e).trim();
if (n) r.update(n);
}
};
}
async function runInstallWatchdog(e) {
const n = new AbortController();
const r = e(n.signal);
try {
return await withTimeout(r, ONBOARDING_PLUGIN_INSTALL_WATCHDOG_TIMEOUT_MS);
} catch (e) {
if (isTimeoutError(e)) {
n.abort();
await r.catch(() => void 0);
}
throw e;
}
}
async function installPluginWithProgress(e) {
const { source: n } = e;
const r = capturePluginCapabilityConsentHandlerErrors(e.onCapabilityConsent);
const i = await prepareManagedPluginArtifactConsentHandler({
config: e.cfg,
source: n.kind === "clawhub" ? "clawhub" : "npm",
spec: n.kind === "npm-pack" ? `npm-pack:${n.archivePath}` : n.spec,
expectedIntegrity: e.entry.install.expectedIntegrity,
onCapabilityConsent: r.onCapabilityConsent,
recordOfficialCapabilities: e.recordOfficialCapabilities,
beforePersistentEffect: e.beforePersistentEffect
});
const a = sanitizeTerminalText(e.entry.label);
const { progress: o, updateProgress: s } = startPluginInstallProgress(e.prompter, a);
let c = false;
const renderTrustWarning = (n) => {
logInstallWarning(e.runtime, n, true);
c = true;
};
const installOptions = () => ({
config: e.cfg,
timeoutMs: ONBOARDING_PLUGIN_INSTALL_TIMEOUT_MS,
expectedPluginId: e.entry.pluginId,
expectedIntegrity: e.entry.install.expectedIntegrity,
extensionsDir: resolveDefaultPluginExtensionsDir(),
onBeforePluginArtifactCommit: i.onBeforePluginArtifactCommit,
beforePersistentApply: e.beforePersistentApply,
logger: {
info: s,
warn: (r) => {
s(r);
if (n.kind === "clawhub") {
const e = stripAnsi(r);
if (e.startsWith("Warning\n")) return;
if (e.startsWith("Blocked\n") || e.startsWith("Review\n")) {
renderTrustWarning(r);
return;
}
}
logInstallWarning(e.runtime, r);
}
}
});
try {
let s;
if (n.kind === "clawhub") {
const { installPluginFromClawHub: e } = await import("./clawhub-CgljpKJh.mjs");
s = await e({
...installOptions(),
spec: n.spec,
mode: "install"
});
const r = !s.ok && "warning" in s ? s.warning : void 0;
if (r && !c) {
o.stop("Review ClawHub warning");
renderTrustWarning(r);
}
} else s = await runInstallWatchdog((r) => {
const i = {
...installOptions(),
signal: r
};
return n.kind === "npm-pack" ? installPluginFromNpmPackArchive({
...i,
archivePath: n.archivePath
}) : installPluginFromNpmSpec({
...i,
spec: n.spec,
mode: "update",
...e.trustedSourceLinkedOfficialInstall ?? e.entry.trustedSourceLinkedOfficialInstall ? { trustedSourceLinkedOfficialInstall: true } : {}
});
});
o.stop(t(s.ok ? "wizard.plugins.installedPlugin" : "wizard.plugins.installFailedShort", { plugin: a }));
r.rethrowCallbackError();
return {
status: "completed",
result: s,
capabilityConsent: i
};
} catch (e) {
const s = n.kind !== "clawhub" && isTimeoutError(e);
o.stop(t(s ? "wizard.plugins.installTimedOutShort" : "wizard.plugins.installFailedShort", { plugin: a }));
r.rethrowCallbackError();
if (s) return { status: "timed_out" };
if (n.kind === "npm-pack" && !(e instanceof ManagedPluginLifecycleError) || n.kind === "clawhub" && (e instanceof WizardCancelledError || e instanceof WizardNavigationError)) throw e;
return {
status: "completed",
capabilityConsent: i,
result: {
ok: false,
error: e instanceof Error ? e.message : String(e)
}
};
}
}
async function installPluginFromOverride(e) {
const { entry: n, prompter: r, runtime: i } = e;
i.log?.(`Using plugin install override for ${sanitizeTerminalText(n.pluginId)} from ${PLUGIN_INSTALL_OVERRIDES_ENV} (${ALLOW_PLUGIN_INSTALL_OVERRIDES_ENV}=1).`);
const a = await installPluginWithProgress({
...e,
source: e.override,
trustedSourceLinkedOfficialInstall: false
});
const o = e.override.kind === "npm" ? e.override.spec : `npm-pack:${e.override.archivePath}`;
if (a.status === "timed_out") return await reportPluginInstallTimeout(e, o);
const { result: s } = a;
if (!s.ok) {
const a = formatInstallErrorDetail(s.error);
await notePluginInstallFailure(r, o, s.error);
i.error?.(`Plugin install failed: ${summarizeInstallError(s.error)}`);
return incompletePluginInstall(e.cfg, n.pluginId, "failed", a);
}
const c = e.override.kind === "npm-pack" ? s.npmTarballName : void 0;
const l = {
pluginId: s.pluginId,
source: "npm",
spec: e.override.kind === "npm-pack" ? s.npmResolution?.resolvedSpec ?? s.manifestName ?? s.pluginId : e.override.spec,
...e.override.kind === "npm-pack" ? { sourcePath: e.override.archivePath } : {},
installPath: s.targetDir,
...s.version ? { version: s.version } : {},
...buildNpmResolutionFields(s.npmResolution),
...e.override.kind === "npm-pack" ? {
artifactKind: "npm-pack",
artifactFormat: "tgz",
...s.npmResolution?.integrity ? { npmIntegrity: s.npmResolution.integrity } : {},
...s.npmResolution?.shasum ? { npmShasum: s.npmResolution.shasum } : {},
...c ? { npmTarballName: c } : {}
} : {}
};
return await finishOnboardingPluginInstall(e, {
pluginId: s.pluginId,
install: a.capabilityConsent.applyAcceptedSurface(s.pluginId, l)
});
}
/** Ensures an onboarding plugin is installed, enabled, and recorded in config. */
async function ensureOnboardingPluginInstalled(e) {
const { entry: n, prompter: r, runtime: i, workspaceDir: a } = e;
const o = e.cfg;
const s = e.onCapabilityConsent ?? createPluginCapabilityConsentPrompter(r);
const c = resolvePluginInstallOverride({ pluginId: n.pluginId });
if (c) {
assertConfigWriteAllowedInCurrentMode();
return await withPluginLifecycleLeaseAsync({}, async () => installPluginFromOverride({
...e,
override: c,
onCapabilityConsent: s
}));
}
const l = resolveLocalPluginRoots(a).some(hasTrustedGitWorkspace);
const u = resolveBundledLocalPath({
entry: n,
workspaceDir: a
});
const d = u ?? resolveLocalPath({
entry: n,
workspaceDir: a,
allowLocal: l
});
const f = n.install.clawhubSpec?.trim();
const p = f && parseClawHubPluginSpec(f) ? f : null;
const m = n.install.npmSpec?.trim();
const h = m && parseRegistryNpmSpec(m) ? m : null;
const g = resolveRegistryUpdateChannel({
configChannel: normalizeUpdateChannel(o.update?.channel),
currentVersion: VERSION
});
const _ = p ? resolveClawHubInstallSpecsForUpdateChannel({
spec: p,
updateChannel: g,
officialPackageName: n.trustedSourceLinkedOfficialInstall ? parseClawHubPluginSpec(p)?.name : void 0,
coreVersion: VERSION,
versionBoundToCore: n.versionBoundToOpenClaw
}) : null;
let v;
const y = _?.installSpec ?? p;
const b = (() => {
const e = Boolean(p) || Boolean(h);
const remoteDefault = () => resolvePluginInstallSources(n.install)[0]?.source ?? "skip";
if (!e) return d ? "local" : "skip";
if (!d) return remoteDefault();
if (u) return "local";
switch (o.update?.channel) {
case "dev": return "local";
case "stable":
case "extended-stable":
case "beta": return remoteDefault();
default: return n.install.defaultChoice === "local" ? "local" : remoteDefault();
}
})();
const x = e.promptInstall === false ? b : await (async () => {
const i = n.label;
const a = e.autoConfirmSingleSource;
const o = u ? null : y;
const s = u ? null : h;
const c = sanitizeTerminalText(i);
const l = o ? sanitizeTerminalText(o) : null;
const f = s ? sanitizeTerminalText(s) : null;
const p = d ? sanitizeTerminalText(d) : null;
const m = [];
if (f) m.push({
value: "npm",
label: t("wizard.plugins.downloadFromNpm", { spec: f })
});
if (l) m.push({
value: "clawhub",
label: t("wizard.plugins.downloadFromClawHub", { spec: l })
});
if (d) m.push({
value: "local",
label: t("wizard.plugins.useLocalPluginPath"),
...p ? { hint: p } : {}
});
if (a && m.length === 1) return m[0].value;
m.push({
value: "skip",
label: t("common.skipForNow")
});
const g = [
b,
"clawhub",
"npm",
"local",
"skip"
].find((e) => m.some((n) => n.value === e));
return await r.select({
message: t("wizard.plugins.installPluginPrompt", { plugin: c }),
options: m,
initialValue: g
});
})();
if (x === "skip") return incompletePluginInstall(o, n.pluginId, "skipped");
assertConfigWriteAllowedInCurrentMode();
return await withPluginLifecycleLeaseAsync({}, async () => {
const installLocal = async (n) => {
const r = e.cfg;
const i = e.entry;
const a = e.prompter;
const o = e.runtime;
const c = e.workspaceDir;
const l = e.beforePersistentEffect;
const d = capturePluginCapabilityConsentHandlerErrors(s);
try {
return await finishOnboardingPluginInstall({
cfg: r,
entry: i,
prompter: a,
runtime: o
}, {
pluginId: i.pluginId,
prepareConfig: async (e) => {
if (pathsReferToSameDirectory(n, u)) return e;
const a = await prepareManagedPluginArtifactConsentHandler({
config: r,
source: "path",
spec: h ?? n,
onCapabilityConsent: d.onCapabilityConsent,
beforePersistentEffect: l
});
await a.onBeforePluginArtifactCommit({
pluginId: i.pluginId,
stagedArtifactDir: n,
mode: "install"
});
const o = formatPortableLocalPath(n, c);
return recordPluginInstall(addPluginLoadPath(e, n), a.applyAcceptedSurface(i.pluginId, {
pluginId: i.pluginId,
source: "path",
installPath: n,
...o ? { sourcePath: o } : {},
...h ? { spec: h } : {}
}));
}
});
} catch (e) {
d.rethrowCallbackError();
const o = e instanceof Error ? e.message : String(e);
await notePluginInstallFailure(a, n, o);
return incompletePluginInstall(r, i.pluginId, "failed", formatInstallErrorDetail(o));
}
};
if (x === "local" && d) return await installLocal(d);
const a = resolvePluginInstallSources(n.install, e.promptInstall === false ? void 0 : x === "npm" || x === "clawhub" ? x : void 0);
if (a.length === 0) return incompletePluginInstall(o, n.pluginId, "failed", "No declared remote install source.");
if (h && a.some((e) => e.source === "npm")) try {
v = await resolveNpmInstallSpecsForUpdateChannel({
spec: h,
updateChannel: g,
officialPackageName: n.trustedSourceLinkedOfficialInstall ? parseRegistryNpmSpec(h)?.name : void 0,
coreVersion: VERSION,
versionBoundToCore: n.versionBoundToOpenClaw
});
} catch (e) {
if (!(e instanceof NpmChannelResolutionError)) throw e;
await notePluginInstallFailure(r, h, e.message);
return incompletePluginInstall(o, n.pluginId, "failed", formatInstallErrorDetail(e.message));
}
const onFallback = async (e) => {
await r.note(e, t("wizard.plugins.installTitle"));
};
const { attempt: c, source: l } = await installWithSourceFallback({
sources: a,
install: async (r) => {
const i = r.source === "npm" ? v : _;
const a = {
...n,
install: {
...n.install,
expectedIntegrity: r.expectedIntegrity
}
};
return await installWithChannelFallback({
installSpec: i?.installSpec ?? r.spec,
...r.expectedIntegrity ? {} : { fallbackSpec: i?.fallbackSpec },
install: (n) => installPluginWithProgress({
...e,
entry: a,
source: {
kind: r.source,
spec: n
},
onCapabilityConsent: s
}),
isRetryable: (e) => e.status === "completed" && !e.result.ok && (r.source === "npm" ? isUnavailableNpmTarget(e.result) : isUnavailableClawHubTarget(e.result)),
onFallback
});
},
result: (e) => e.status === "completed" ? e.result : { ok: false },
onFallback
});
if (c.status === "timed_out") return await reportPluginInstallTimeout(e, l.spec);
const { result: f, capabilityConsent: p } = c;
if (f.ok) {
const e = (l.source === "npm" ? v : _)?.recordSpec ?? l.spec;
const a = "clawhub" in f ? {
...buildClawHubPluginInstallRecordFields(f.clawhub),
spec: e,
installPath: f.targetDir
} : {
source: "npm",
spec: e,
installPath: f.targetDir,
version: f.version,
...buildNpmResolutionFields(f.npmResolution)
};
return await finishOnboardingPluginInstall({
cfg: o,
entry: n,
prompter: r,
runtime: i
}, {
pluginId: f.pluginId,
install: p.applyAcceptedSurface(f.pluginId, {
pluginId: f.pluginId,
...a
})
});
}
await notePluginInstallFailure(r, l.spec, f.error);
if (d && isUnavailablePluginSource(l.source, f)) {
if (await r.confirm({
message: t("wizard.plugins.useLocalPluginPathInstead", { path: sanitizeTerminalText(d) }),
initialValue: true
})) return await installLocal(d);
}
i.error?.(`Plugin install failed: ${summarizeInstallError(f.error)}`);
return incompletePluginInstall(o, n.pluginId, "failed", formatInstallErrorDetail(f.error));
});
}
//#endregion
export { ensureOnboardingPluginInstalled as t };