openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
83 lines (82 loc) • 2.73 kB
JavaScript
import { t as normalizeAnyChannelId } from "./registry-normalize-guW5_4yo.mjs";
import { n as getLoadedChannelPlugin } from "./registry-ByqVE5S3.mjs";
import "./plugins-BoMiRtiY.mjs";
import { t as createClackPrompter } from "./clack-prompter-oqVcatgQ.mjs";
import { t as resolveChannelSetupOwner } from "./owner-DJdrBk7A.mjs";
import { a as resolveTrustedChannelCatalogInput, t as getTrustedChannelPluginCatalogEntry } from "./trusted-catalog-BsRi13Hw.mjs";
import { n as loadChannelSetupPluginRegistrySnapshotForChannel, t as ensureChannelSetupPluginInstalled } from "./plugin-install-CXJAWztN.mjs";
//#region src/commands/channel-setup/channel-plugin-resolution.ts
/** Resolve an existing channel plugin, scoped setup plugin, or installable catalog entry. */
async function resolveInstallableChannelPlugin(e) {
const t = e.supports ?? (() => true);
let n = e.cfg;
const r = e.channelId ?? normalizeAnyChannelId(e.rawChannel);
const i = e.preferRegisteredPlugin && r ? getLoadedChannelPlugin(r) : void 0;
if (e.preferRegisteredPlugin && r && i) return {
cfg: n,
channelId: r,
plugin: i,
configChanged: false,
pluginInstalled: false
};
const { workspaceDir: a } = resolveChannelSetupOwner(n, e.agentId);
let o = (e.rawChannel ? resolveTrustedChannelCatalogInput(e.rawChannel, {
cfg: n,
workspaceDir: a
}) : void 0) ?? (e.channelId ? getTrustedChannelPluginCatalogEntry(e.channelId, {
cfg: n,
workspaceDir: a
}) : void 0);
const s = r ?? (o ? normalizeAnyChannelId(o.id) ?? o.id : void 0);
if (!s) return {
cfg: n,
catalogEntry: o,
configChanged: false,
pluginInstalled: false
};
let c = getLoadedChannelPlugin(s);
let l = false;
if (!c && o) {
const loadPlugin = async (r) => {
const i = await loadChannelSetupPluginRegistrySnapshotForChannel({
cfg: n,
runtime: e.runtime,
channel: s,
...r ? { pluginId: r } : {},
workspaceDir: a
});
const o = i.channels.find((e) => e.plugin.id === s)?.plugin;
if (o) return o;
const c = i.channelSetups.find((e) => e.plugin.id === s)?.plugin;
return c && t(c) ? c : void 0;
};
c = await loadPlugin(o.pluginId);
if (!c && e.allowInstall !== false) {
const t = await ensureChannelSetupPluginInstalled({
cfg: n,
entry: o,
prompter: e.prompter ?? createClackPrompter(),
runtime: e.runtime,
workspaceDir: a
});
n = t.cfg;
const r = t.pluginId ?? o.pluginId;
l = t.installed;
if (l) c = await loadPlugin(r);
if (r && o.pluginId !== r) o = {
...o,
pluginId: r
};
}
}
return {
cfg: n,
channelId: s,
plugin: c,
catalogEntry: o,
configChanged: n !== e.cfg,
pluginInstalled: l
};
}
//#endregion
export { resolveInstallableChannelPlugin as t };