openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
68 lines (67 loc) • 2.5 kB
JavaScript
import { t as formatErrorMessage } from "./errors-BKzCeTYb.mjs";
import { n as cloneConfigWithResolutionFacts } from "./resolution-facts-xaIKuREs.mjs";
import { n as createHistoricalWebhookPinMigration } from "./legacy-webhook-pins-GMe5akAq.mjs";
//#region src/plugins/doctor-compatibility-migration.ts
/** Selection and order belong to callers; every hook transforms a private candidate. */
function applyPluginDoctorCompatibilitySequence(e, t) {
let n = e;
const r = [];
const i = [];
for (const { pluginId: e, normalizeCompatibilityConfig: a, transform: o } of t) {
if (!a) continue;
const t = cloneConfigWithResolutionFacts(n);
try {
const e = a({ cfg: t });
const s = {
...e,
config: e?.changes.length ? e.config : n,
changes: e?.changes ?? []
};
const c = o ? o(s) : s;
if (c?.changes.length) {
n = c.config;
r.push(...c.changes);
}
i.push(...c?.warnings ?? []);
} catch (t) {
i.push(`Plugin "${e}" config repair failed: ${formatErrorMessage(t)}. Its config was preserved; run \`openclaw doctor --fix\` after repairing the plugin.`);
}
}
return {
config: n,
changes: r,
...i.length ? { warnings: i } : {}
};
}
/** Apply resolved declarations without coupling the compatibility owner to registry loading. */
function applyResolvedPluginDoctorCompatibilityMigrations(e, t, n) {
const r = n.historicalWebhookListeners ? createHistoricalWebhookPinMigration(n.env, n.historicalWebhookCompletion, n.historicalWebhookListeners === "preserve-configured") : void 0;
const i = r ? r({
config: e,
changes: []
}, void 0, n) : {
config: e,
changes: []
};
const a = applyPluginDoctorCompatibilitySequence(i.config, t.map((e) => {
if (!n.isDeferred(e.pluginId)) n.onInspectedPlugin?.(e.pluginId, e.rules.length > 0 || Boolean(e.normalizeCompatibilityConfig) || e.providerRenames.length > 0);
return {
pluginId: e.pluginId,
normalizeCompatibilityConfig: e.normalizeCompatibilityConfig,
transform: r ? (t) => {
if (e.historicalWebhookNormalizer) t.historicalWebhookAccountIds = e.historicalWebhookNormalizer({ cfg: cloneConfigWithResolutionFacts(t.config) }).historicalWebhookAccountIds;
return r(t, e.historicalWebhookListener, {
...n,
pluginId: e.pluginId,
origin: e.origin
});
} : void 0
};
}));
return {
...a,
changes: [...i.changes, ...a.changes]
};
}
//#endregion
export { applyResolvedPluginDoctorCompatibilityMigrations as n, applyPluginDoctorCompatibilitySequence as t };