openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
108 lines (107 loc) • 4.16 kB
JavaScript
import { o as preparePluginMetadataMachineStateAsync } from "./installed-plugin-index-record-state-euCqi7PU.mjs";
import { l as withPluginMetadataSnapshotScope } from "./current-plugin-metadata-snapshot-H0TP3PFt.mjs";
import { n as isChannelConfigMetadataKey } from "./config-metadata-BVUrt758.mjs";
import { n as getBootstrapChannelPlugin } from "./channel-configured-3z7rRlJy.mjs";
import { o as listPluginDoctorLegacyConfigRules, r as collectDoctorConfigRepairPluginIds } from "./doctor-contract-registry-CFzLZXmq.mjs";
import { a as loadBundledChannelDoctorContractApi } from "./channel-legacy-config-migrate-DVMnZ4Sy.mjs";
import { t as listDoctorConfiguredChannelIds } from "./configured-channel-ids-4FVS0H72.mjs";
import { c as findLegacySystemAgentOwnerIssue } from "./legacy-config-migrations-8hb5BL3G.mjs";
import { t as findLegacyConfigIssues } from "./legacy-REm6ZoIL.mjs";
//#region src/channels/plugins/legacy-config.ts
function collectConfiguredChannelIds(e) {
if (!e || typeof e !== "object") return [];
const t = e.channels;
if (!t || typeof t !== "object" || Array.isArray(t)) return [];
return Object.keys(t).map((e) => e.trim()).filter((e) => e && !isChannelConfigMetadataKey(e));
}
function shouldIncludeLegacyRuleForTouchedPaths(e, t) {
if (!t || t.length === 0) return true;
return t.some((t) => {
const n = Math.min(e.length, t.length);
for (let r = 0; r < n; r += 1) if (e[r] !== t[r]) return false;
return true;
});
}
function collectRelevantChannelIdsForTouchedPaths(e) {
const t = collectConfiguredChannelIds(e.raw);
const n = e.excludedChannelIds?.size ? t.filter((t) => !e.excludedChannelIds?.has(t)) : t;
if (!e.touchedPaths || e.touchedPaths.length === 0) return n;
const r = /* @__PURE__ */ new Set();
for (const t of e.touchedPaths) {
const [e, i] = t;
if (e !== "channels") continue;
if (!i) return n;
const a = i.trim();
if (!a || isChannelConfigMetadataKey(a)) continue;
r.add(a);
}
return n.filter((e) => r.has(e));
}
function collectChannelLegacyConfigRules(e, t, n) {
const r = collectRelevantChannelIdsForTouchedPaths({
raw: e,
touchedPaths: t,
excludedChannelIds: n
});
const i = [];
const a = [];
for (const e of r) {
const t = loadBundledChannelDoctorContractApi(e)?.legacyConfigRules;
if (Array.isArray(t)) {
i.push(...t);
continue;
}
const n = getBootstrapChannelPlugin(e);
if (n?.doctor?.legacyConfigRules?.length) {
i.push(...n.doctor.legacyConfigRules);
continue;
}
if (n) continue;
a.push(e);
}
if (a.length > 0) i.push(...listPluginDoctorLegacyConfigRules({
config: e,
pluginIds: a
}));
const o = /* @__PURE__ */ new Set();
return i.filter((e) => {
if (!shouldIncludeLegacyRuleForTouchedPaths(e.path, t)) return false;
const n = `${e.path.join(".")}::${e.message}`;
if (o.has(n)) return false;
o.add(n);
return true;
});
}
//#endregion
//#region src/commands/doctor/shared/legacy-config-issues.ts
function collectPluginLegacyConfigRules(e, t) {
const n = new Set(listDoctorConfiguredChannelIds(e, { configEntryPolicy: "raw" }));
const r = collectDoctorConfigRepairPluginIds(e, t).filter((e) => !n.has(e));
if (r.length === 0) return [];
return listPluginDoctorLegacyConfigRules({
config: e,
pluginIds: r
});
}
/** Find legacy config issues using core rules plus relevant channel/plugin doctor contracts. */
function findDoctorLegacyConfigIssues(e, t, n) {
return findLegacyConfigIssues(e, t, [...collectChannelLegacyConfigRules(e, n), ...collectPluginLegacyConfigRules(e, n)]);
}
async function addDoctorLegacyIssues(e, t) {
if (!e.exists) return e;
if (!t) (await preparePluginMetadataMachineStateAsync({}))();
const n = e.sourceConfig ?? e.config ?? {};
const collect = () => {
const t = e.parsed ?? n;
const r = findDoctorLegacyConfigIssues(n, t);
const i = findLegacySystemAgentOwnerIssue(e.sourceConfigBeforeMigrations ?? n);
if (i) r.push(i);
return r.length === 0 ? e : {
...e,
legacyIssues: r
};
};
return t ? withPluginMetadataSnapshotScope(t, collect, { config: n }) : collect();
}
//#endregion
export { findDoctorLegacyConfigIssues as n, addDoctorLegacyIssues as t };