openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
102 lines (101 loc) • 4.93 kB
JavaScript
import { i as createPluginCache, w as withPluginCache } from "./plugin-cache-B_eRuqTM.mjs";
import { t as _usingCtx } from "./usingCtx-rhpPzaNq.mjs";
import { g as resolveOfficialExternalPluginLegacyIds, i as getOfficialExternalPluginCatalogEntryForPackage, r as getOfficialExternalPluginCatalogEntry } from "./official-external-plugin-catalog-DtkWz1Xo.mjs";
import { i as resolvePluginManifestInstallOwner } from "./manifest-registry-build-BbYTyBDW.mjs";
import { i as loadInstalledPluginIndexInstallRecordsSync } from "./installed-plugin-index-record-reader-B-7uGQZ9.mjs";
import { g as resolveOfficialExternalPluginId } from "./official-external-plugin-catalog-source-4o5oPhVN.mjs";
import { t as ConfigMutationConflictError } from "./mutation-conflict-Bs0nsNWn.mjs";
import { r as resolveConfigWidePluginMetadataSnapshot } from "./io.plugin-metadata-CBwzHw3m.mjs";
import { c as setDeferredPluginMigrationConfigFacts, n as getDeferredPluginMigrationConfigFacts } from "./deferred-plugin-migration-config-B3TJC-SY.mjs";
import "./installed-plugin-index-records-MNCNSlg8.mjs";
import { o as migratePluginConfigId } from "./update-config-BFVDqf5S.mjs";
import { isDeepStrictEqual } from "node:util";
//#region src/commands/doctor/shared/installed-plugin-id-recovery.ts
async function resolveInstalledPluginIdOwners(e, t) {
try {
var n = _usingCtx();
const r = n.a(createPluginCache());
return withPluginCache(r, () => {
const n = loadInstalledPluginIndexInstallRecordsSync({ env: t });
const r = resolveConfigWidePluginMetadataSnapshot({
config: e,
env: t,
allowCurrent: false,
installRecords: n
});
const i = /* @__PURE__ */ new Map();
for (const e of r.plugins) for (const t of new Set(e.legacyPluginIds ?? [])) {
const n = i.get(t) ?? [];
n.push(e);
i.set(t, n);
}
const a = /* @__PURE__ */ new Map();
const o = /* @__PURE__ */ new Map();
for (const [e, t] of i) {
const i = t[0];
if (i) o.set(e, i.id);
if (t.length !== 1 || !i || r.byPluginId.has(e) || Object.hasOwn(n, e) || r.diagnostics.some((t) => t.level === "error" || t.pluginId === e || t.pluginId === i.id)) continue;
const s = n[i.id];
const c = r.index.plugins.find((e) => e.pluginId === i.id && e.manifestPath === i.manifestPath);
const l = i.packageName ? getOfficialExternalPluginCatalogEntryForPackage(i.packageName) : void 0;
if (!s || !c || i.trustedOfficialInstall !== true || resolvePluginManifestInstallOwner(i) !== i.id || !l || resolveOfficialExternalPluginId(l) !== i.id || !resolveOfficialExternalPluginLegacyIds(l).includes(e)) continue;
a.set(e, {
pluginId: i.id,
rootDir: c.rootDir,
manifestHash: c.manifestHash,
packageHash: c.packageJson?.hash,
record: structuredClone(s)
});
}
for (const e of Object.keys(n)) {
const t = getOfficialExternalPluginCatalogEntry(e);
if (t && resolveOfficialExternalPluginId(t) === e) {
for (const n of resolveOfficialExternalPluginLegacyIds(t)) if (!o.has(n)) o.set(n, e);
}
}
return {
eligibleOwners: a,
candidateOwners: o
};
});
} catch (e) {
n.e = e;
} finally {
await n.d();
}
}
/** Recover after install publication even when a previous config write lost its transient receipt. */
async function recoverInstalledPluginConfigIds(e, t, n) {
const { eligibleOwners: r, candidateOwners: i } = await resolveInstalledPluginIdOwners(e, t);
const a = new Map(n?.previousRecovery);
for (const [e, t] of a) {
const i = r.get(e);
if (i && n?.repairedPluginIds.includes(t.pluginId) && i.pluginId === t.pluginId && i.rootDir === t.rootDir && isDeepStrictEqual(i.record, n.records[i.pluginId])) a.set(e, i);
}
const o = [];
let s = e;
for (const [e, t] of r) {
const n = migratePluginConfigId(s, e, t.pluginId);
if (n !== s) {
a.set(e, t);
o.push(`Moved installed plugin config "${e}" to "${t.pluginId}".`);
setDeferredPluginMigrationConfigFacts(n, getDeferredPluginMigrationConfigFacts(s));
s = n;
}
}
return {
config: s,
changes: o,
notices: [...i].flatMap(([t, n]) => !r.has(t) && migratePluginConfigId(e, t, n) !== e ? [`Kept plugin config "${t}": the installed replacement owner is not unambiguous. Resolve plugin discovery or install-record conflicts, then rerun Doctor.`] : []),
recovery: a,
preservePluginIds: [...i.keys()]
};
}
/** Called under the existing plugin lifecycle lease before the config writer publishes. */
async function assertInstalledPluginIdRecoveryCurrent(e, t, n) {
if (!t?.size) return;
const r = await resolveInstalledPluginIdOwners(e, n);
for (const [e, n] of t) if (!isDeepStrictEqual(r.eligibleOwners.get(e), n)) throw new ConfigMutationConflictError(`Plugin ownership changed after Doctor prepared "${e}" config recovery; rerun Doctor.`, { retryable: false });
}
//#endregion
export { recoverInstalledPluginConfigIds as n, assertInstalledPluginIdRecoveryCurrent as t };