openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 4.83 kB
JavaScript
import{l as isRecord}from"./record-coerce-BTbqdJ3-.mjs";import{n as describeRootFileOpenFailure,o as openRootFileSync}from"./boundary-file-read-bB9An35K.mjs";import{m as resolvePluginRuntimeExecutionArtifact}from"./bundled-dir-CMJ7m2eP.mjs";import{u as normalizePluginsConfig}from"./config-state-C1eV6UWf.mjs";import{n as isActivatedManifestOwner,r as isBundledManifestOwner,t as hasExplicitManifestOwnerTrust}from"./manifest-owner-policy-DVnu9FAE.mjs";import{t as shouldRejectHardlinkedPluginFiles}from"./hardlink-policy-S8MtjHnf.mjs";import{t as getCachedPluginModuleLoader}from"./plugin-module-loader-cache-Bj5H0vwC.mjs";import{d as resolveConfiguredChannelPluginIds}from"./channel-presence-policy-iYxMh2HT.mjs";import{_ as resolvePluginRuntimeArtifact,a as withPreparedPluginSetupRead}from"./plugin-setup-module-DKdTsN2H.mjs";import{t as createEmptyPluginRegistry}from"./registry-empty-DczuQDzf.mjs";import{n as unwrapDefaultModuleExport}from"./module-export-BuTJede2.mjs";import"./channel-plugin-ids--iuNYdtE.mjs";import{t as resolvePluginRuntimeLoadContext}from"./load-context.resolve-C8UgCzlR.mjs";import{t as shouldIncludeChannelSetupFeatureForConfig}from"./bundled-setup-policy-BOgJnI5C.mjs";import{t as EMPTY_LEGACY_SESSION_SURFACES}from"./legacy-session-surfaces.types-C8E2J1bv.mjs";import fs from"node:fs";
//!src/plugins/legacy-session-surfaces.ts
function formatLoadFailure(e,t){return`Deferred legacy session-key migration for channel owner "${e}": ${t}. Restore or reinstall the plugin setup entry, then rerun openclaw doctor --fix`}function resolveLegacySessionSurface(e){const t=unwrapDefaultModuleExport(e);if(!t||typeof t!==`object`)throw new Error(`setup entry does not export loadLegacySessionSurface`);const n=t;if(n.kind!==`bundled-channel-setup-entry`||typeof n.loadLegacySessionSurface!==`function`)throw new Error(`setup entry does not export loadLegacySessionSurface`);const r=n.loadLegacySessionSurface();if(!isRecord(r))throw new Error(`legacy session surface must be an object`);const i=r.isLegacyGroupSessionKey;const a=r.canonicalizeLegacySessionKey;if(i!==void 0&&typeof i!==`function`||typeof a!==`function`)throw new Error(`legacy session surface must declare canonicalizeLegacySessionKey`);return r}function isEnabledLegacySurfaceOwner(e){if(!shouldIncludeChannelSetupFeatureForConfig({plugin:e.record,config:e.config,normalizedConfig:e.normalizedConfig}))return false;if(isBundledManifestOwner(e.record))return true;if(e.record.origin===`global`||e.record.origin===`config`)return hasExplicitManifestOwnerTrust({plugin:e.record,normalizedConfig:e.normalizedConfig});return isActivatedManifestOwner({plugin:e.record,normalizedConfig:e.normalizedConfig,rootConfig:e.config})}function loadLegacySessionSurface(e){const{source:t,rootDir:n}=resolvePluginRuntimeExecutionArtifact(resolvePluginRuntimeArtifact({pluginId:e.record.id,entryKind:`setup`,source:e.setupSource,rootDir:e.record.rootDir,origin:e.record.origin,preferBuiltPluginArtifacts:false,packageManifest:e.record.packageManifest,registry:e.artifactRegistry}));const r=openRootFileSync({absolutePath:t,rootPath:n,boundaryLabel:`plugin root`,rejectHardlinks:shouldRejectHardlinkedPluginFiles({origin:e.record.origin,rootDir:e.record.rootDir,env:e.env}),skipLexicalRootCheck:true});if(!r.ok)throw new Error(describeRootFileOpenFailure({failure:r,subject:`plugin setup entry path`,boundaryLabel:`plugin root`,filePath:t}));const i=r.path;fs.closeSync(r.fd);return resolveLegacySessionSurface(getCachedPluginModuleLoader({modulePath:i,importerUrl:import.meta.url,loaderFilename:import.meta.url})(i))}function prepareLegacySessionSurfaces(e){return withPreparedPluginSetupRead(()=>{const t=resolvePluginRuntimeLoadContext({config:e.config,env:e.env});const n=(t.manifestRegistry?.plugins??[]).filter(e=>e.packageManifest?.setupFeatures?.legacySessionSurfaces===true);const r=normalizePluginsConfig(t.activationSourceConfig.plugins);let i;const a=n.filter(e=>{if(isEnabledLegacySurfaceOwner({record:e,config:t.activationSourceConfig,normalizedConfig:r}))return true;i??=new Set(resolveConfiguredChannelPluginIds({config:t.config,activationSourceConfig:t.activationSourceConfig,workspaceDir:t.workspaceDir,env:t.env,manifestRecords:n}));return i.has(e.id)});if(a.length===0)return EMPTY_LEGACY_SESSION_SURFACES;const o=a.flatMap(e=>e.setupSource?[]:[formatLoadFailure(e.id,`package metadata declares the surface but has no setupEntry`)]);const s=[];const c=createEmptyPluginRegistry();for(const e of a){if(!e.setupSource)continue;try{s.push(loadLegacySessionSurface({record:e,setupSource:e.setupSource,env:t.env,artifactRegistry:c}))}catch(t){const n=t instanceof Error?t.message:String(t);o.push(formatLoadFailure(e.id,n))}}return Object.freeze({surfaces:Object.freeze(s),failures:Object.freeze(o)})})}export{prepareLegacySessionSurfaces};