openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
128 lines (127 loc) • 5.53 kB
JavaScript
import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs";
import { t as discoverConfiguredPluginLoadPaths } from "./discovery-DvJYrQFY.mjs";
import { t as createSubsystemLogger } from "./subsystem-BHJiy01V.mjs";
import { Fn as object, Lt as boolean } from "./schemas-Cy6abvsu.mjs";
import { n as findUninspectedPluginDiagnostic } from "./discovery-availability-DtlJ7XvT.mjs";
import { n as isChannelConfigMetadataKey } from "./config-metadata-BVUrt758.mjs";
import { o as visitChannelEntries } from "./legacy-config-record-shared-D3vIaBh9.mjs";
import { t as loadBundledPluginPublicArtifactModuleFromCandidatesSync } from "./public-surface-loader-DENdCm5a.mjs";
import { t as HISTORICAL_WEBHOOK_CHANNELS } from "./legacy-webhook-pins-GMe5akAq.mjs";
import { t as applyPluginDoctorCompatibilitySequence } from "./doctor-compatibility-migration-Be-t21B8.mjs";
import { n as getBootstrapChannelPlugin } from "./channel-configured-3z7rRlJy.mjs";
import { i as isPluginDoctorMigrationDeferred, n as applyPluginDoctorCompatibilityMigrations, r as collectDoctorConfigRepairPluginIds } from "./doctor-contract-registry-CFzLZXmq.mjs";
import { t as listDoctorConfiguredChannelIds } from "./configured-channel-ids-4FVS0H72.mjs";
//#region src/channels/plugins/doctor-contract-api.ts
/**
* Loads a bundled channel's public doctor contract.
*/
function loadBundledChannelDoctorContractApi(e) {
return loadBundledPluginPublicArtifactModuleFromCandidatesSync({
dirName: e.trim(),
artifactCandidates: ["doctor-contract-api.js"]
}) ?? void 0;
}
//#endregion
//#region src/commands/doctor/shared/channel-legacy-config-migrate.ts
const log = createSubsystemLogger("plugins/doctor-contracts");
const LegacyHeartbeatVisibilitySchema = object({
showOk: boolean().optional(),
showAlerts: boolean().optional(),
useIndicator: boolean().optional()
}).strict().optional();
/** Feishu owns visibility/intervalMs; only its shared heartbeat keys belong to retirement. */
function selectLegacyHeartbeatVisibility(e, t) {
if (!t) return;
const n = e === "feishu" ? ["heartbeatVisibility", "heartbeat"] : ["heartbeatVisibility"];
for (const r of n) {
const n = t[r];
if (n === void 0) continue;
if (e === "feishu" && (!isRecord(n) || ![
"showOk",
"showAlerts",
"useIndicator"
].some((e) => Object.hasOwn(n, e)))) continue;
return {
key: r,
value: n
};
}
}
function migrateHeartbeatVisibility(e, t) {
const n = isRecord(e.channels) ? e.channels : null;
if (!n) return;
const migrateEntry = (e, n, r = false) => {
const i = isRecord(e.heartbeat) ? e.heartbeat : null;
const a = i ? Object.keys(i) : [];
if (!i || r && a.length === 0 || a.some((e) => e !== "showOk" && e !== "showAlerts" && e !== "useIndicator")) return;
if (r && e.heartbeatVisibility !== void 0 && selectLegacyHeartbeatVisibility("feishu", e)?.key !== "heartbeatVisibility") return;
if (e.heartbeatVisibility === void 0) {
e.heartbeatVisibility = e.heartbeat;
t.push(`Moved ${n}.heartbeat → ${n}.heartbeatVisibility.`);
} else t.push(`Removed ${n}.heartbeat (${n}.heartbeatVisibility already set).`);
delete e.heartbeat;
};
const r = isRecord(n.defaults) ? n.defaults : null;
if (r) migrateEntry(r, "channels.defaults");
for (const t of Object.keys(n)) {
if (!t.trim() || isChannelConfigMetadataKey(t)) continue;
visitChannelEntries(e, t, (e, n) => migrateEntry(e, n, t === "feishu"));
}
}
function resolveBundledChannelCompatibilityNormalizer(e) {
if (isPluginDoctorMigrationDeferred(e)) return;
const t = loadBundledChannelDoctorContractApi(e)?.normalizeCompatibilityConfig;
if (typeof t === "function") return t;
return getBootstrapChannelPlugin(e)?.doctor?.normalizeCompatibilityConfig;
}
/** Apply bundled and plugin channel compatibility migrations to a legacy config object. */
function applyChannelDoctorCompatibilityMigrations(e, t) {
const n = e;
const r = n.plugins?.load?.paths ?? [];
if (r.length > 0) {
const t = findUninspectedPluginDiagnostic(discoverConfiguredPluginLoadPaths({ loadPaths: r }).diagnostics);
if (t) {
log.warn(t.message);
return {
next: e,
changes: []
};
}
}
const i = [];
migrateHeartbeatVisibility(e, i);
const a = [];
const o = applyPluginDoctorCompatibilitySequence(n, listDoctorConfiguredChannelIds(e, {
configEntryPolicy: "raw",
sort: "codepoint"
}).map((e) => {
const t = resolveBundledChannelCompatibilityNormalizer(e);
if (!t) a.push(e);
return {
pluginId: e,
normalizeCompatibilityConfig: t
};
}));
const s = t?.pluginContracts === false ? [] : t?.pluginCompatibility?.pluginIds ?? [.../* @__PURE__ */ new Set([...a, ...collectDoctorConfigRepairPluginIds(e)])].toSorted();
const c = s.length || t?.historicalWebhookListeners ? applyPluginDoctorCompatibilityMigrations(o.config, {
config: n,
pluginIds: t?.historicalWebhookListeners ? [.../* @__PURE__ */ new Set([...s, ...HISTORICAL_WEBHOOK_CHANNELS])] : s,
historicalWebhookListeners: t?.historicalWebhookListeners,
manifestRegistry: t?.pluginCompatibility?.manifestRegistry
}) : {
config: o.config,
changes: []
};
const l = [.../* @__PURE__ */ new Set([...o.warnings ?? [], ...c.warnings ?? []])];
return {
next: c.config,
changes: [
...i,
...o.changes,
...c.changes
],
...l.length ? { warnings: l } : {}
};
}
//#endregion
export { loadBundledChannelDoctorContractApi as a, selectLegacyHeartbeatVisibility as i, applyChannelDoctorCompatibilityMigrations as n, migrateHeartbeatVisibility as r, LegacyHeartbeatVisibilitySchema as t };