openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.17 kB
JavaScript
import{t as normalizeAnyChannelId}from"./registry-normalize-BP0gv89S.mjs";import{n as getLoadedChannelPlugin}from"./registry-CpNh6QcT.mjs";import"./plugins-DxOycUNJ.mjs";import{t as createClackPrompter}from"./clack-prompter-CkhFfk2k.mjs";import{t as resolveChannelSetupOwner}from"./owner-DONBZpm3.mjs";import{a as resolveTrustedChannelCatalogInput,t as getTrustedChannelPluginCatalogEntry}from"./trusted-catalog-BvCsWGaP.mjs";import{n as loadChannelSetupPluginRegistrySnapshotForChannel,t as ensureChannelSetupPluginInstalled}from"./plugin-install-BUge6pit.mjs";
//!src/commands/channel-setup/channel-plugin-resolution.ts
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}}export{resolveInstallableChannelPlugin as t};