UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 7.43 kB
import{c as normalizeOptionalLowercaseString}from"./string-coerce-CpTFcSwY.mjs";import{n as sanitizeForLog}from"./ansi-54CEWBZf.mjs";import{t as isPluginEnabledByDefaultForPlatform}from"./default-enablement-HKNNloGt.mjs";import{u as normalizePluginsConfig}from"./config-state-C1eV6UWf.mjs";import{a as resolveManifestOwnerBasePolicyBlock,n as isActivatedManifestOwner,t as hasExplicitManifestOwnerTrust}from"./manifest-owner-policy-DVnu9FAE.mjs";import{t as listExplicitlyDisabledChannelIdsForConfig}from"./config-presence-BcbNJcgC.mjs";import{o as isSafeChannelEnvVarTriggerName}from"./package-state-probes-D9nK4Yua.mjs";import{n as loadPluginManifestRegistryForPluginRegistry}from"./plugin-registry-contributions-C4xBwxaW.mjs";import{l as listExplicitConfiguredChannelIdsForConfig,n as hasExplicitChannelConfig,p as resolveConfiguredChannelPresencePolicy}from"./channel-presence-policy-iYxMh2HT.mjs";import"./plugin-registry-BAbRxjjy.mjs";import{t as normalizeLowercaseStringSet}from"./normalized-string-set-BuDEgK2s.mjs";import"./channel-plugin-ids--iuNYdtE.mjs"; //!src/commands/doctor/shared/channel-plugin-blockers.ts const CHANNEL_PLUGIN_BLOCKERS_CHECK_ID=`core/doctor/channel-plugin-blockers`;function scanConfiguredChannelPluginBlockers(e,t=process.env,n=e,r={}){const i=listExplicitConfiguredChannelIdsForConfig(e).map(e=>normalizeOptionalLowercaseString(e)).filter(e=>Boolean(e));const a=normalizePluginsConfig(n.plugins);const o=normalizePluginsConfig(e.plugins);const s=r.manifestRecords??loadPluginManifestRegistryForPluginRegistry({config:e,env:t,includeDisabled:true}).plugins;const c=r.ambientEnvTriggers===`suppress`?/* @__PURE__ */ new Map:listPackageEnvConfiguredChannelTriggers(s,t);const l=resolveConfiguredChannelPresencePolicy({config:e,activationSourceConfig:n,env:t,includePersistedAuthState:false,ambientEnvTriggers:r.ambientEnvTriggers,manifestRecords:s}).filter(e=>!c.has(e.channelId)||e.sources.some(e=>e!==`env`&&e!==`manifest-env`)).map(e=>e.channelId);const u=/* @__PURE__ */ new Set([...i,...i.length===0?l:[]]);for(const t of listExplicitlyDisabledChannelIdsForConfig(e)){const e=normalizeOptionalLowercaseString(t)??t;u.delete(e);c.delete(e)}if(u.size===0&&c.size===0)return[];const d=[];const f=/* @__PURE__ */ new Set;const p=/* @__PURE__ */ new Set;const addHits=(e,t,n=false)=>{for(const r of t){if(!r.reason)continue;if(r.reason===`plugins disabled`){if(p.has(e))continue;p.add(e)}const t=`${e}\0${r.pluginId}\0${r.reason}`;if(f.has(t))continue;f.add(t);const i={channelId:e,pluginId:r.pluginId,reason:r.reason};if(n)i.channelAvailable=true;d.push(i)}};const resolveChannelOwnerStates=t=>s.filter(e=>e.channels.some(e=>normalizeOptionalLowercaseString(e)===t)).map(r=>{const resolveBase=(e,n)=>{const i=r.origin===`bundled`&&hasExplicitChannelConfig({config:e,channelId:t});const a=r.origin===`workspace`&&n.slots.contextEngine===r.id;return{bundledChannelConfigured:i,workspaceSlot:a,block:resolveManifestOwnerBasePolicyBlock({plugin:r,normalizedConfig:n,allowRestrictiveAllowlistBypass:i||a})}};const i=resolveBase(n,a);const s=i.block;const c=r.origin===`bundled`||hasExplicitManifestOwnerTrust({plugin:r,normalizedConfig:a})||i.workspaceSlot;const l=r.origin===`bundled`&&(i.bundledChannelConfigured||isActivatedManifestOwner({plugin:r,normalizedConfig:a,rootConfig:n}));const u=r.origin===`bundled`&&!isPluginEnabledByDefaultForPlatform(r)&&a.entries[r.id]?.enabled!==true;const d=resolveBase(e,o);const f=d.block===null&&c&&(d.bundledChannelConfigured||isActivatedManifestOwner({plugin:r,normalizedConfig:o,rootConfig:e}));return{pluginId:r.id,available:f,reason:f?void 0:r.origin===`bundled`&&s===`not-in-allowlist`&&u?`not enabled and not in allowlist`:mapManifestOwnerBlockerReason(s)??(!c&&s===null?`missing explicit enablement`:r.origin===`bundled`&&s===null&&!l?`not enabled`:void 0)}});for(const e of u){const t=resolveChannelOwnerStates(e);if(t.some(e=>e.available))continue;addHits(e,t)}for(const[e,t]of c){const n=resolveChannelOwnerStates(e);const r=n.some(e=>e.available);for(const i of t.values()){const t=n.filter(e=>i.has(e.pluginId));if(t.some(e=>e.available))continue;addHits(e,t,r)}}return d}function listPackageEnvConfiguredChannelTriggers(e,t){const n=/* @__PURE__ */ new Map;for(const r of e){const e=normalizeLowercaseStringSet(r.channels.values());const i=normalizeOptionalLowercaseString(r.packageChannel?.id);if(!i||!e.has(i))continue;const a=r.packageChannel?.configuredState?.env;const o=a?.allOf??[];const s=a?.anyOf??[];if(o.length===0&&s.length===0)continue;let c=n.get(i);if(!c){c=/* @__PURE__ */ new Map;n.set(i,c)}const hasEnvValue=e=>{if(!isSafeChannelEnvVarTriggerName(e))return false;const n=t[e]??t[e.toUpperCase()];return typeof n===`string`&&n.trim().length>0};if(!o.every(hasEnvValue)||s.length>0&&!s.some(hasEnvValue))continue;for(const e of[...o,...s].filter(hasEnvValue)){const t=e.trim().toUpperCase();let n=c.get(t);if(!n){n=/* @__PURE__ */ new Set;c.set(t,n)}n.add(r.id)}}return n}function mapManifestOwnerBlockerReason(e){return e===null?void 0:{"plugins-disabled":`plugins disabled`,"plugin-disabled":`disabled in config`,"blocked-by-denylist":`blocked by denylist`,"not-in-allowlist":`not in allowlist`}[e]}function formatReason(e){if(e.reason===`disabled in config`)return`plugin "${sanitizeForLog(e.pluginId)}" is disabled by plugins.entries.${sanitizeForLog(e.pluginId)}.enabled=false.`;if(e.reason===`blocked by denylist`)return`plugin "${sanitizeForLog(e.pluginId)}" is blocked by plugins.deny. Remove "${sanitizeForLog(e.pluginId)}" from plugins.deny.`;if(e.reason===`plugins disabled`)return`plugins.enabled=false blocks channel plugins globally.`;if(e.reason===`missing explicit enablement`)return`external plugin "${sanitizeForLog(e.pluginId)}" is installed without explicit trust. Add plugins.entries.${sanitizeForLog(e.pluginId)}.enabled=true.`;if(e.reason===`not enabled`)return`plugin "${sanitizeForLog(e.pluginId)}" is installed but not enabled. Add plugins.entries.${sanitizeForLog(e.pluginId)}.enabled=true.`;if(e.reason===`not enabled and not in allowlist`)return`plugin "${sanitizeForLog(e.pluginId)}" is not enabled and is omitted from plugins.allow. Add plugins.entries.${sanitizeForLog(e.pluginId)}.enabled=true and include "${sanitizeForLog(e.pluginId)}" in plugins.allow.`;return`plugin "${sanitizeForLog(e.pluginId)}" is installed but omitted from plugins.allow. Include "${sanitizeForLog(e.pluginId)}" in plugins.allow.`}function formatChannelPluginBlocker(e){return`channels.${sanitizeForLog(e.channelId)}: channel is configured, but ${formatReason(e)} Fix plugin enablement before relying on setup guidance for this channel.`}function collectConfiguredChannelPluginBlockerWarnings(e){return e.map(e=>`- ${formatChannelPluginBlocker(e)}`)}function channelPluginBlockerHitToHealthFinding(e){return{checkId:CHANNEL_PLUGIN_BLOCKERS_CHECK_ID,severity:`warning`,message:formatChannelPluginBlocker(e),path:`channels.${e.channelId}`,target:e.pluginId,requirement:e.reason,fixHint:`Fix plugin enablement before relying on setup guidance for this channel.`}}function isWarningBlockedByChannelPlugin(e,t){return t.some(t=>{if(t.channelAvailable)return false;const n=`channels.${sanitizeForLog(t.channelId)}`;return e.includes(`${n}:`)||e.includes(`${n}.`)})}export{channelPluginBlockerHitToHealthFinding,collectConfiguredChannelPluginBlockerWarnings,isWarningBlockedByChannelPlugin,scanConfiguredChannelPluginBlockers};