openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
268 lines (267 loc) • 11.7 kB
JavaScript
import { c as resolveUserPath } from "./home-dir-EKmgmdPG.mjs";
import "./utils-C8YECn2Q.mjs";
import { t as formatCliCommand } from "./command-format-CqdwUgPk.mjs";
import { a as resolveCompatibilityHostVersion } from "./version-GlxUMdxI.mjs";
import { f as resolveEffectiveEnableState, u as normalizePluginsConfig } from "./config-state-B1JlHgba.mjs";
import { t as formatSourceBundledPluginNotice } from "./dev-source-root-HNpp2lb0.mjs";
import { a as resolveDefaultPluginExtensionsDir, c as resolvePluginInstallDir, d as resolvePluginNpmPackageDir, s as resolveDefaultPluginNpmDir } from "./install-paths-Bwm0P5EG.mjs";
import { A as resolvePluginInstallSources, M as parseClawHubPluginSpec, l as listOfficialExternalPluginCatalogEntries, p as resolveOfficialExternalPluginInstall } from "./official-external-plugin-catalog-DtkWz1Xo.mjs";
import { l as resolveOpenClawReleaseCohortVersion, s as parseRegistryNpmSpec } from "./npm-registry-spec-HKkAvl6N.mjs";
import { g as resolveOfficialExternalPluginId } from "./official-external-plugin-catalog-source-4o5oPhVN.mjs";
import { s as resolveTrustedSourceLinkedOfficialNpmInstall } from "./official-external-install-records-DHqBi8wk.mjs";
import { h as shouldDeferConfiguredPluginInstallRepair } from "./update-phase-YdZvaQsy.mjs";
import { n as expectedIntegrityForUpdate, r as isPackageVersionDowngrade } from "./package-update-utils-9Q0D2cR2.mjs";
import { n as isPayloadMissing } from "./payload-verification-BFPGDf3M.mjs";
import { S as resolveNpmUpdateTarget, r as resolveOfficialPluginCohortNpmSpecs, t as detectPluginVersionDrift } from "./plugin-version-drift-CpF8p-dx.mjs";
import { a as collectConfiguredChannelIds, i as collectBlockedPluginIds, o as collectConfiguredPluginIds, r as resolveConfiguredPluginInstallContext, t as collectDownloadableInstallCandidates } from "./missing-configured-plugin-install.candidates-Bdz7t8z-.mjs";
import path from "node:path";
//#region src/commands/doctor/shared/missing-configured-plugin-install.records.ts
function forceNpmInstallRecordRepair(e) {
if (e.source !== "npm") return e;
const t = { ...e };
delete t.resolvedSpec;
delete t.resolvedVersion;
return t;
}
function installPathsEqual(e, t) {
return path.resolve(e) === path.resolve(t);
}
function resolveLegacyNpmPackageInstallPath(e) {
return path.join(e.npmRoot, "node_modules", ...e.packageName.split("/"));
}
function collectInstalledRecordPackageNames(e) {
const t = e.source === "npm" ? [
e.resolvedName,
e.spec ? parseRegistryNpmSpec(e.spec)?.name : void 0,
e.resolvedSpec ? parseRegistryNpmSpec(e.resolvedSpec)?.name : void 0
] : e.source === "clawhub" ? [e.clawhubPackage, e.spec ? parseClawHubPluginSpec(e.spec)?.name : void 0] : [];
return new Set(t.filter((e) => Boolean(e)));
}
function isTrustedOfficialInstallRecordForCandidate(e) {
const { record: t, candidate: n } = e;
if (!t || t.source !== "npm" && t.source !== "clawhub") return false;
if (t.source === "clawhub" && t.clawhubChannel !== "official") return false;
const r = new Set([n.npmSpec ? parseRegistryNpmSpec(n.npmSpec)?.name : void 0, n.clawhubSpec ? parseClawHubPluginSpec(n.clawhubSpec)?.name : void 0].filter((e) => Boolean(e)));
return r.size > 0 && [...collectInstalledRecordPackageNames(t)].some((e) => r.has(e));
}
function resolveSafeBrokenOfficialInstallRemovalPath(e) {
const t = e.record?.installPath?.trim();
if (!t) return null;
const n = resolveUserPath(t, e.env);
try {
const t = resolveDefaultPluginExtensionsDir(e.env);
if (installPathsEqual(n, resolvePluginInstallDir(e.pluginId, t))) return n;
} catch {}
const r = e.candidate.npmSpec ? parseRegistryNpmSpec(e.candidate.npmSpec) : null;
if (!r?.name) return null;
const i = resolveDefaultPluginNpmDir(e.env);
return [resolvePluginNpmPackageDir({
packageName: r.name,
npmDir: i
}), resolveLegacyNpmPackageInstallPath({
packageName: r.name,
npmRoot: i
})].some((e) => installPathsEqual(n, e)) ? n : null;
}
function recordMatchesBundledPackage(e, t) {
const n = t.packageName?.trim();
return Boolean(n && collectInstalledRecordPackageNames(e).has(n));
}
/** Share record-removal planning between read-only no-op admission and leased repair. */
function planBundledInstallRecordRepair(e) {
const { records: t, bundledPluginsById: n, operatorManagedPluginIds: r } = e;
let i = t;
const a = [];
const o = [];
const s = [];
for (const [e, c] of Object.entries(t)) {
const l = n.get(e);
if (r.has(e) || !l || !recordMatchesBundledPackage(c, l)) continue;
if (l.preserveExternalInstallRecord) {
const t = formatSourceBundledPluginNotice(e);
o.push(t);
s.push({
pluginId: e,
status: "unchanged",
code: "source-bundled-plugin",
message: t
});
continue;
}
if (i === t) i = { ...t };
delete i[e];
a.push(`Removed stale managed install record for bundled plugin "${e}".`);
}
return {
nextRecords: i,
changes: a,
notices: o,
sourceOutcomes: s
};
}
//#endregion
//#region src/commands/doctor/shared/missing-configured-plugin-install.targets.ts
function resolveConfiguredPluginRepairVersions(e) {
const { env: t } = e;
const { records: n, updateChannel: r, operatorManagedPluginIds: i, bundledPluginsById: a, officialReplacementPluginIds: o } = e.context;
const s = resolveCompatibilityHostVersion(t);
const c = resolveOfficialPluginCohortNpmSpecs({
gatewayVersion: s,
installRecords: n,
config: e.cfg
});
return {
coreVersion: s,
cohortSpecs: c,
newerRecordedPluginIds: new Set(r === "stable" || r === "beta" ? Object.keys(c).filter((e) => {
const t = n[e]?.resolvedVersion ?? n[e]?.version;
return t && isPackageVersionDowngrade(resolveOpenClawReleaseCohortVersion(t), resolveOpenClawReleaseCohortVersion(s));
}) : []),
driftedPluginIds: new Set(e.repairVersionDrift && !shouldDeferConfiguredPluginInstallRepair(t) ? detectPluginVersionDrift({
gatewayVersion: s,
installRecords: n,
config: e.cfg
}).drifts.flatMap(({ pluginId: r }) => {
const s = n[r];
if (!s || !c[r] || i.has(r) || a.has(r) || o.has(r)) return [];
if (resolveTrustedSourceLinkedOfficialNpmInstall({
pluginId: r,
record: s
})?.replacementPluginId) {
e.onWarning(`Plugin "${r}" needs a package-id migration. Run ${formatCliCommand(`openclaw plugins update ${c[r]}`, t)}.`, r);
return [];
}
return [r];
}) : [])
};
}
function resolveRecordedInstallCandidate(e) {
const t = e.record;
if (!t && e.candidate.trustedSourceLinkedOfficialInstall) {
const t = parseRegistryNpmSpec(e.candidate.npmSpec ?? "")?.name;
if (t?.startsWith("@openclaw/") && listOfficialExternalPluginCatalogEntries().some((n) => n.source === "official" && n.name === t && resolveOfficialExternalPluginId(n) === e.candidate.pluginId && parseRegistryNpmSpec(resolveOfficialExternalPluginInstall(n)?.npmSpec ?? "")?.name === t)) return {
...e.candidate,
versionBoundToOpenClaw: true
};
}
const n = t?.source === "npm" || t?.source === "clawhub" ? t.source : void 0;
const r = n === "npm" ? parseRegistryNpmSpec : parseClawHubPluginSpec;
const i = n === "npm" ? e.candidate.npmSpec : e.candidate.clawhubSpec;
const a = e.repairReason === "stale-version-bound-runtime";
const o = n ? resolvePluginInstallSources(e.candidate, n)[0] : void 0;
const s = a ? o?.spec : t?.spec ?? o?.spec;
return t && n ? {
...e.candidate,
defaultChoice: n,
...n === "npm" ? {
npmSpec: s,
clawhubSpec: void 0
} : {
clawhubSpec: s,
npmSpec: void 0
},
expectedIntegrity: a ? o?.expectedIntegrity : expectedIntegrityForUpdate(t.spec, t.integrity),
trustedSourceLinkedOfficialInstall: e.candidate.trustedSourceLinkedOfficialInstall && (!t.spec || r(t.spec)?.name === r(i ?? "")?.name)
} : e.candidate;
}
/** Keep stale-runtime pin replacement behind the same repair admission as doctor. */
function resolveConfiguredPluginCandidateRepair(e) {
const { candidate: t, context: n } = e;
if (n.bundledPluginsById.has(t.pluginId)) return;
const r = n.officialReplacementPluginIds.has(t.pluginId);
const i = e.records[t.pluginId];
if (r && (!t.trustedSourceLinkedOfficialInstall || !isTrustedOfficialInstallRecordForCandidate({
record: i,
candidate: t
}))) return;
const a = Object.hasOwn(e.records, t.pluginId);
const o = a && !isPayloadMissing(e.env, i?.installPath);
if (!r && (o || n.knownIds.has(t.pluginId) && !a)) return;
return {
shouldReplaceBrokenOfficialInstall: r,
...n.installedPluginIdsWithStaleVersionBoundRuntimePackages.has(t.pluginId) && !n.installedPluginIdsWithRepairablePackageDiagnostics.has(t.pluginId) && !n.configuredPluginIdsWithStaleDescriptors.has(t.pluginId) && o ? { repairReason: "stale-version-bound-runtime" } : {}
};
}
/** Metadata-only inventory for the same npm targets used by post-core sync and repair. */
async function collectConfiguredNpmPluginTargets(e) {
const t = collectConfiguredPluginIds(e.config, e.env);
const n = collectConfiguredChannelIds(e.config, e.env);
if (t.size === 0 && n.size === 0) return [];
const r = collectBlockedPluginIds(e.config);
const i = await resolveConfiguredPluginInstallContext({
cfg: e.config,
env: e.env,
configuredPluginIds: t,
configuredChannelIds: n,
blockedPluginIds: r,
baselineRecords: e.installRecords,
coreVersion: e.targetVersion
});
const a = new Map(collectDownloadableInstallCandidates({
cfg: e.config,
env: e.env,
configuredPluginIds: t,
configuredChannelIds: n,
configuredChannelOwnerPluginIds: i.configuredChannelOwnerPluginIds,
blockedPluginIds: r,
missingPluginIds: /* @__PURE__ */ new Set()
}).map((e) => [e.pluginId, e]));
const o = normalizePluginsConfig(e.config.plugins);
const s = [];
const c = /* @__PURE__ */ new Set([
...t,
...a.keys(),
...[...i.configuredChannelOwnerPluginIds.values()].flatMap((e) => Array.from(e))
]);
for (const t of c) {
const n = i.records[t];
if (i.operatorManagedPluginIds.has(t) || i.bundledPluginsById.has(t) || n && (n.source !== "npm" || n.artifactKind || n.sourcePath) || !resolveEffectiveEnableState({
id: t,
origin: "global",
config: o,
rootConfig: e.config
}).enabled) continue;
const r = a.get(t);
const c = r && resolveConfiguredPluginCandidateRepair({
candidate: r,
records: i.records,
env: e.env,
context: i
});
if (r && c) {
const i = resolveRecordedInstallCandidate({
candidate: r,
record: n,
repairReason: c.repairReason
});
const a = resolvePluginInstallSources(i, n?.source === "npm" ? "npm" : void 0)[0];
if (a?.source === "npm" && parseRegistryNpmSpec(a.spec)) s.push({
pluginId: t,
spec: a.spec,
updateChannel: e.channel,
coreVersion: e.targetVersion,
officialPackageName: i.trustedSourceLinkedOfficialInstall ? parseRegistryNpmSpec(a.spec)?.name : void 0,
versionBoundToCore: i.versionBoundToOpenClaw
});
} else if (n?.source === "npm") {
const { target: i } = resolveNpmUpdateTarget({
record: n,
trustedOfficialInstall: resolveTrustedSourceLinkedOfficialNpmInstall({
pluginId: t,
record: n
}),
syncOfficialPluginInstalls: true,
updateChannel: e.channel,
coreVersion: e.targetVersion,
versionBoundToCore: r?.versionBoundToOpenClaw
});
if (i && parseRegistryNpmSpec(i.spec)) s.push({
pluginId: t,
...i
});
}
}
return s.toSorted((e, t) => e.pluginId.localeCompare(t.pluginId));
}
//#endregion
export { forceNpmInstallRecordRepair as a, resolveLegacyNpmPackageInstallPath as c, resolveRecordedInstallCandidate as i, resolveSafeBrokenOfficialInstallRemovalPath as l, resolveConfiguredPluginCandidateRepair as n, installPathsEqual as o, resolveConfiguredPluginRepairVersions as r, planBundledInstallRecordRepair as s, collectConfiguredNpmPluginTargets as t };