UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 5.89 kB
import{c as normalizeOptionalLowercaseString}from"./string-coerce-CpTFcSwY.mjs";import{a as asOptionalRecord}from"./record-coerce-BTbqdJ3-.mjs";import{u as isUnresolvedSecretInputError}from"./types.secrets-UWdyCdE6.mjs";import{l as findUninspectedPluginDiagnostic}from"./discovery-Bo4UPPd9.mjs";import{t as PluginSetupPreparationRequiredError}from"./plugin-setup-module-DKdTsN2H.mjs";import{t as applyPluginDoctorCompatibilitySequence}from"./doctor-compatibility-migration-Cq22yA_e.mjs";import{s as loadManifestMetadataSnapshot}from"./manifest-contract-eligibility-BFn2JM5T.mjs";import{i as getBundledChannelSetupPlugin,n as getBundledChannelPlugin}from"./bundled-CcedQErj.mjs";import{n as getLoadedChannelPlugin}from"./registry-CpNh6QcT.mjs";import{t as listDoctorConfiguredChannelIds}from"./configured-channel-ids-fKSHMbv6.mjs";import{n as listReadOnlyChannelPluginsForConfigAsync}from"./read-only-B-Uv2t8Q.mjs"; //!src/commands/doctor/shared/channel-doctor.ts function isChannelDoctorBlockedByConfig(e,t){if(t.plugins?.enabled===false)return true;const n=normalizeOptionalLowercaseString(e)??e;if(t.plugins?.entries?.[n]?.enabled===false)return true;return asOptionalRecord(t.channels?.[n])?.enabled===false}function safelyResolveChannelPlugin(e,t){try{return t(e)}catch(e){if(e instanceof PluginSetupPreparationRequiredError)throw e;return}}async function listReadOnlyChannelDoctorsById(e){const t=await listReadOnlyChannelPluginsForConfigAsync(e.cfg,{...e.env?{env:e.env}:{},includePersistedAuthState:false,includeSetupFallbackPlugins:true});return new Map(t.map(({id:e,doctor:t})=>[e,t]))}function mergeDoctorAdapters(e){const t={};for(const n of e){if(!n)continue;for(const[e,r]of Object.entries(n))if(r!==void 0&&!(e in t))Object.assign(t,{[e]:r})}return Object.keys(t).length>0?t:void 0}async function listChannelDoctorEntries(e,t=listDoctorConfiguredChannelIds(e.cfg,{configEntryPolicy:`enabled`,skipWhenPluginsDisabled:true,excludeExplicitlyDisabled:true,sort:`codepoint`})){if(!t.some(t=>!isChannelDoctorBlockedByConfig(t,e.cfg)))return[];return collectChannelDoctorEntries(e,t,await listReadOnlyChannelDoctorsById(e))}function collectChannelDoctorEntries(e,t,n){const r=new Set(t.filter(t=>!isChannelDoctorBlockedByConfig(t,e.cfg)));if(r.size===0)return[];const i=[];for(const e of r){const t=mergeDoctorAdapters([n.get(e),safelyResolveChannelPlugin(e,getLoadedChannelPlugin)?.doctor,safelyResolveChannelPlugin(e,getBundledChannelSetupPlugin)?.doctor,safelyResolveChannelPlugin(e,getBundledChannelPlugin)?.doctor]);if(!t)continue;i.push({id:e,doctor:t})}return i}function preserveUnavailableChannelConfig(e){if(!e.cfg.plugins?.load?.paths?.length)return;const t=findUninspectedPluginDiagnostic(loadManifestMetadataSnapshot({config:e.cfg,env:e.env}).diagnostics);return t?{config:e.cfg,changes:[],warnings:[t.message]}:void 0}async function collectChannelDoctorMutations(e,t,n){const r=preserveUnavailableChannelConfig(e);if(r)return[r];const i=[];let a=e.cfg;for(const{doctor:r}of await listChannelDoctorEntries(e,n)){const e=await t(r,a);if(e?.changes.length){i.push(e);a=e.config}else if(e?.warnings?.length)i.push({config:a,changes:[],warnings:e.warnings})}return i}async function createChannelDoctorEmptyAllowlistPolicyHooks(e){const t=await listReadOnlyChannelDoctorsById(e);const n=/* @__PURE__ */ new Map;const entriesForChannel=r=>{const i=n.get(r);if(i)return i;const a=collectChannelDoctorEntries(e,[r],t);n.set(r,a);return a};return{extraWarningsForAccount:e=>entriesForChannel(e.channelName).flatMap(t=>t.doctor.collectEmptyAllowlistExtraWarnings?.(e)??[]),shouldSkipDefaultEmptyGroupAllowlistWarning:e=>entriesForChannel(e.channelName).some(t=>t.doctor.shouldSkipDefaultEmptyGroupAllowlistWarning?.(e)===true)}}async function runChannelDoctorConfigSequences(e){const t=preserveUnavailableChannelConfig(e);if(t)return{changeNotes:[],warningNotes:t.warnings??[]};const n=[];const r=[];const i=[];for(const t of await listChannelDoctorEntries(e)){const a=await t.doctor.runConfigSequence?.(e);if(!a)continue;n.push(...a.changeNotes);r.push(...a.infoNotes??[]);i.push(...a.warningNotes)}return{changeNotes:n,warningNotes:i,...r.length>0?{infoNotes:r}:{}}}async function collectChannelDoctorCompatibilityMutations(e,t={}){const n=preserveUnavailableChannelConfig({cfg:e,env:t.env});if(n)return[n];const r=applyPluginDoctorCompatibilitySequence(e,(await listChannelDoctorEntries({cfg:e,env:t.env})).map(({id:e,doctor:t})=>({pluginId:e,normalizeCompatibilityConfig:t.normalizeCompatibilityConfig?.bind(t)})));return r.changes.length||r.warnings?.length?[r]:[]}async function collectChannelDoctorStaleConfigMutations(e,t={}){return collectChannelDoctorMutations({cfg:e,env:t.env},(e,t)=>e.cleanStaleConfig?.({cfg:t}),t.channelIds)}async function collectChannelDoctorPreviewWarnings(e){const t=[];for(const n of await listChannelDoctorEntries(e)){let r;try{r=await n.doctor.collectPreviewWarnings?.(e)}catch(e){if(!isUnresolvedSecretInputError(e))throw e;t.push(`- channels.${n.id}: configured SecretRef at ${e.path} is unavailable in doctor preview; skipping secret-backed channel preview checks.`);continue}if(r?.length)t.push(...r)}return t}async function collectChannelDoctorMutableAllowlistWarnings(e){const t=[];for(const n of await listChannelDoctorEntries(e)){const r=await n.doctor.collectMutableAllowlistWarnings?.(e);if(r?.length)t.push(...r)}return t}async function collectChannelDoctorRepairMutations(e){return collectChannelDoctorMutations(e,(t,n)=>t.repairConfig?.({cfg:n,doctorFixCommand:e.doctorFixCommand,...e.env?{env:e.env}:{}}))}export{collectChannelDoctorStaleConfigMutations as a,collectChannelDoctorRepairMutations as i,collectChannelDoctorMutableAllowlistWarnings as n,createChannelDoctorEmptyAllowlistPolicyHooks as o,collectChannelDoctorPreviewWarnings as r,runChannelDoctorConfigSequences as s,collectChannelDoctorCompatibilityMutations as t};