openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
65 lines (64 loc) • 2.84 kB
JavaScript
import { n as unwrapDefaultModuleExport } from "./module-export-DTZ89pa-.mjs";
import { i as mergeChannelPluginSection, t as isChannelConfigured } from "./channel-configured-3z7rRlJy.mjs";
//#region src/plugins/loader-channel-setup.ts
function mergeLoadedChannelSecrets(e, t) {
if (!e || typeof e !== "object") return;
const n = e;
const r = mergeChannelPluginSection(n.secrets, t);
return {
...n,
...r !== void 0 ? { secrets: r } : {}
};
}
function resolveBundledRuntimeChannelRegistration(e) {
const t = unwrapDefaultModuleExport(e);
if (!t || typeof t !== "object") return {};
const n = t;
if (n.kind !== "bundled-channel-entry" || typeof n.id !== "string" || typeof n.loadChannelPlugin !== "function") return {};
return {
id: n.id,
loadChannelPlugin: n.loadChannelPlugin,
...typeof n.loadChannelSecrets === "function" ? { loadChannelSecrets: n.loadChannelSecrets } : {},
...typeof n.setChannelRuntime === "function" ? { setChannelRuntime: n.setChannelRuntime } : {}
};
}
function loadBundledRuntimeChannelPlugin(e) {
if (typeof e.registration.loadChannelPlugin !== "function") return {};
try {
const t = mergeLoadedChannelSecrets(e.registration.loadChannelPlugin(), e.registration.loadChannelSecrets?.());
return t ? { plugin: t } : {};
} catch (e) {
return { loadError: e };
}
}
function resolveSetupChannelRegistration(e) {
const t = unwrapDefaultModuleExport(e);
if (!t || typeof t !== "object") return {};
const n = t;
if (n.kind === "bundled-channel-setup-entry" && typeof n.loadSetupPlugin === "function") try {
const e = mergeLoadedChannelSecrets(n.loadSetupPlugin(), typeof n.loadSetupSecrets === "function" ? n.loadSetupSecrets() : void 0);
if (e) return {
plugin: e,
usesBundledSetupContract: true,
...typeof n.setChannelRuntime === "function" ? { setChannelRuntime: n.setChannelRuntime } : {},
...typeof n.registerSetupRuntime === "function" ? { registerSetupRuntime: n.registerSetupRuntime } : {}
};
} catch (e) {
return { loadError: e };
}
if (!n.plugin || typeof n.plugin !== "object") return {};
return {
plugin: n.plugin,
...typeof n.setChannelRuntime === "function" ? { setChannelRuntime: n.setChannelRuntime } : {}
};
}
function shouldLoadChannelPluginInSetupRuntime(e) {
if (e.channelPluginLoadIntent !== "setup" || !e.setupSource || e.manifestChannels.length === 0) return false;
return !e.manifestChannels.some((t) => isChannelConfigured(e.cfg, t, e.env));
}
function channelPluginIdBelongsToManifest(e) {
if (!e.channelId) return true;
return e.channelId === e.pluginId || e.manifestChannels.includes(e.channelId);
}
//#endregion
export { shouldLoadChannelPluginInSetupRuntime as a, resolveSetupChannelRegistration as i, loadBundledRuntimeChannelPlugin as n, resolveBundledRuntimeChannelRegistration as r, channelPluginIdBelongsToManifest as t };