openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
65 lines (64 loc) • 2.4 kB
JavaScript
import { l as normalizeOptionalString } from "./string-coerce-CIXf7egm.js";
import { n as CHAT_CHANNEL_ORDER } from "./ids-BVZRYG0I.js";
import { c as listBundledChannelSetupPlugins } from "./bundled-0Ib5Dos0.js";
import { C as requireActivePluginRegistry, a as getActivePluginChannelRegistry } from "./runtime-BL4wZfTq.js";
import "./registry-COqNvmCg.js";
//#region src/channels/plugins/setup-registry.ts
/**
* Channel setup plugin registry.
*
* Resolves loaded or bundled setup plugins for onboarding flows.
*/
function dedupeSetupPlugins(plugins) {
const seen = /* @__PURE__ */ new Set();
const resolved = [];
for (const plugin of plugins) {
const id = normalizeOptionalString(plugin.id) ?? "";
if (!id || seen.has(id)) continue;
seen.add(id);
resolved.push(plugin);
}
return resolved;
}
function sortChannelSetupPlugins(plugins) {
return dedupeSetupPlugins(plugins).toSorted((a, b) => {
const indexA = CHAT_CHANNEL_ORDER.indexOf(a.id);
const indexB = CHAT_CHANNEL_ORDER.indexOf(b.id);
const orderA = a.meta.order ?? (indexA === -1 ? 999 : indexA);
const orderB = b.meta.order ?? (indexB === -1 ? 999 : indexB);
if (orderA !== orderB) return orderA - orderB;
return a.id.localeCompare(b.id);
});
}
function resolveChannelSetupPlugins() {
const registryPlugins = (requireActivePluginRegistry().channelSetups ?? []).map((entry) => entry.plugin);
const sorted = sortChannelSetupPlugins(registryPlugins.length > 0 ? registryPlugins : listBundledChannelSetupPlugins());
const byId = /* @__PURE__ */ new Map();
for (const plugin of sorted) byId.set(plugin.id, plugin);
return {
sorted,
byId
};
}
/**
* Lists setup-capable channel plugins, falling back to bundled setup metadata.
*/
function listChannelSetupPlugins() {
return resolveChannelSetupPlugins().sorted.slice();
}
/**
* Lists setup plugins from the active channel registry only.
*/
function listActiveChannelSetupPlugins() {
return sortChannelSetupPlugins((getActivePluginChannelRegistry()?.channelSetups ?? []).map((entry) => entry.plugin));
}
/**
* Returns one setup-capable channel plugin by id.
*/
function getChannelSetupPlugin(id) {
const resolvedId = normalizeOptionalString(id) ?? "";
if (!resolvedId) return;
return resolveChannelSetupPlugins().byId.get(resolvedId);
}
//#endregion
export { listActiveChannelSetupPlugins as n, listChannelSetupPlugins as r, getChannelSetupPlugin as t };