UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 3.94 kB
import{l as normalizeOptionalString}from"./string-coerce-CpTFcSwY.mjs";import{b as uniqueStrings,m as normalizeTrimmedStringList}from"./string-normalization-D_oBUpO3.mjs";import{r as isPathInside}from"./path-guards-DGttsOJI.mjs";import{t as PUBLIC_SURFACE_SOURCE_EXTENSIONS}from"./package-entrypoints-QGX6Paeq.mjs";import fs from"node:fs";import path from"node:path"; //!src/plugins/bundled-plugin-scan.ts const RUNTIME_SIDECAR_ARTIFACTS=/* @__PURE__ */ new Set([`helper-api.js`,`light-runtime-api.js`,`qa-runner-api.js`,`runtime-api.js`,`runtime-setter-api.js`,`thread-bindings-runtime.js`]);function rewriteBundledPluginEntryToBuiltPath(e){if(!e)return;return e.replace(/^\.\//u,``).replace(/\.[^.]+$/u,`.js`)}function isTopLevelPublicSurfaceSource(e){if(!PUBLIC_SURFACE_SOURCE_EXTENSIONS.includes(path.extname(e)))return false;if(e.startsWith(`.`)||e.startsWith(`test-`)||e.includes(`.test-`))return false;if(e.endsWith(`.d.ts`))return false;if(/^config-api(\.[cm]?[jt]s)$/u.test(e))return false;return!/(\.test|\.spec)(\.[cm]?[jt]s)$/u.test(e)}function deriveBundledPluginIdHint(e){const t=path.basename(e.entryPath,path.extname(e.entryPath));if(!e.hasMultipleExtensions)return e.manifestId;const n=normalizeOptionalString(e.packageName);if(!n)return`${e.manifestId}/${t}`;return`${n.includes(`/`)?n.split(`/`).pop()??n:n}/${t}`}function collectBundledPluginPublicSurfaceArtifacts(e){const t=new Set(normalizeTrimmedStringList([e.sourceEntry,e.setupEntry]).map(e=>path.basename(e)));const n=fs.readdirSync(e.pluginDir,{withFileTypes:true}).filter(e=>e.isFile()).map(e=>e.name).filter(isTopLevelPublicSurfaceSource).filter(e=>!t.has(e)).map(e=>rewriteBundledPluginEntryToBuiltPath(e)).filter(e=>typeof e===`string`&&e.length>0).toSorted((e,t)=>e.localeCompare(t));return n.length>0?n:void 0}function collectBundledPluginRuntimeSidecarArtifacts(e){if(!e)return;const t=e.filter(e=>RUNTIME_SIDECAR_ARTIFACTS.has(e));return t.length>0?t:void 0}function resolveBundledPluginScanDir(e){const t=path.join(e.packageRoot,`extensions`);const n=path.join(e.packageRoot,`dist-runtime`,`extensions`);const r=path.join(e.packageRoot,`dist`,`extensions`);if(e.runningFromBuiltArtifact)return[r,n,t].find(e=>fs.existsSync(e));if(fs.existsSync(t))return t;return fs.existsSync(r)?fs.existsSync(n)?n:r:void 0}function listBundledPluginEntryDirectories(e){const t=e.scanDir?[path.resolve(e.scanDir,e.pluginDirName??``)]:[];const n=path.resolve(e.rootDir,`extensions`,e.pluginDirName??``);const r=[path.resolve(e.rootDir,`dist`,`extensions`,e.pluginDirName??``),path.resolve(e.rootDir,`dist-runtime`,`extensions`,e.pluginDirName??``)];return{roots:uniqueStrings([...t,n,...r]),baseDirs:uniqueStrings([...t.flatMap(e=>[path.resolve(e,`dist`),e]),...r,path.resolve(n,`dist`),n])}}function listBundledPluginEntrySearchPaths(e,t){const n=[];for(const r of[e.built,e.source]){if(typeof r!==`string`||r.length===0)continue;if(!path.isAbsolute(r)){n.push(r);continue}const e=path.normalize(r);for(const r of t){if(!isPathInside(r,e))continue;const t=path.relative(r,e);const i=rewriteBundledPluginEntryToBuiltPath(t);if(i)n.push(i);n.push(t)}}return uniqueStrings(n)}function resolveBundledPluginGeneratedPath(e,t,n,r){if(!t)return null;const{roots:i,baseDirs:a}=listBundledPluginEntryDirectories({rootDir:e,pluginDirName:n,scanDir:r});const o=listBundledPluginEntrySearchPaths(t,i);for(const e of a)for(const t of o){const n=resolveBundledPluginEntryCandidate(e,t);if(!n)continue;if(fs.existsSync(n))return n}return null}function resolveBundledPluginEntryCandidate(e,t){const n=t.replace(/^\.\//u,``);const r=path.isAbsolute(n)?path.normalize(n):path.resolve(e,n);if(!isPathInside(e,r))return null;return r}export{resolveBundledPluginScanDir as a,resolveBundledPluginGeneratedPath as i,collectBundledPluginRuntimeSidecarArtifacts as n,rewriteBundledPluginEntryToBuiltPath as o,deriveBundledPluginIdHint as r,collectBundledPluginPublicSurfaceArtifacts as t};