UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 2.62 kB
import{l as isRecord}from"./record-coerce-BTbqdJ3-.mjs";import"./utils-Dlk0IYAa.mjs";import{i as matchRootFileOpenFailure}from"./boundary-file-read-bB9An35K.mjs";import{c as readPluginCacheFile,n as parsePluginCacheJson}from"./plugin-cache-files-BGuripl0.mjs";import{p as resolveEffectivePluginActivationState,u as normalizePluginsConfig}from"./config-state-C1eV6UWf.mjs";import{t as applyMergePatch}from"./merge-patch-CKGPHlQC.mjs";import{n as loadPluginManifestRegistryForPluginRegistry}from"./plugin-registry-contributions-C4xBwxaW.mjs";import"./plugin-registry-BAbRxjjy.mjs"; //!src/plugins/bundle-config-shared.ts function extractBundleServerMap(e,t){if(!isRecord(e))return{};let n=e;for(const r of t)if(isRecord(e[r])){n=e[r];break}const r={};for(const[e,t]of Object.entries(n))if(isRecord(t))r[e]={...t};return r}function readBundleJsonObject(e){const t=readPluginCacheFile({rootDir:e.rootDir,relativePath:e.relativePath,rejectHardlinks:true,maxBytes:null});if(!t.ok&&t.failurePhase!==`read`){if(e.allowMissing===void 0)return{ok:true,raw:{}};return matchRootFileOpenFailure(t.failure,{path:()=>e.allowMissing?{ok:true,raw:{}}:{ok:false,error:`unable to read ${e.relativePath}: path`,reason:`open`},fallback:t=>({ok:false,error:`unable to read ${e.relativePath}: ${t.reason}`,reason:`open`})})}const n=t.ok?parsePluginCacheJson(t):{ok:false,error:t.failure.error};if(!n.ok)return{ok:false,error:`failed to parse ${e.relativePath}: ${String(n.error)}`};return isRecord(n.value)?{ok:true,raw:structuredClone(n.value)}:{ok:false,error:`${e.relativePath} must contain a JSON object`}}function loadEnabledBundleConfig(e){const t=normalizePluginsConfig(e.cfg?.plugins);if(!t.enabled)return{config:e.createEmptyConfig(),diagnostics:[]};const n=e.manifestRegistry??loadPluginManifestRegistryForPluginRegistry({workspaceDir:e.workspaceDir,config:e.cfg,includeDisabled:true});const r=[];let i=e.createEmptyConfig();for(const a of n.plugins){const n=a.format===`bundle`&&Boolean(a.bundleFormat);const o=a.format!==`bundle`&&e.loadNativePluginConfig!==void 0;if(!n&&!o)continue;if(!resolveEffectivePluginActivationState({id:a.id,origin:a.origin,channelIds:a.channels,config:t,rootConfig:e.cfg,enabledByDefault:a.enabledByDefault}).activated)continue;const s=n&&a.bundleFormat?e.loadBundleConfig({pluginId:a.id,rootDir:a.rootDir,bundleFormat:a.bundleFormat}):e.loadNativePluginConfig?.({record:a});if(!s)continue;i=applyMergePatch(i,s.config);for(const e of s.diagnostics)r.push({pluginId:a.id,message:e})}return{config:i,diagnostics:r}}export{loadEnabledBundleConfig as n,readBundleJsonObject as r,extractBundleServerMap as t};