openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.91 kB
JavaScript
import{c as resolveUserPath}from"./home-dir-DEN5DisQ.mjs";import{l as isRecord}from"./record-coerce-BTbqdJ3-.mjs";import{a as getPluginCache}from"./plugin-cache-B6QVpzXr.mjs";import{r as resolveOpenClawPackageRootSync}from"./openclaw-root-DP80HYD2.mjs";import{r as isPathInside}from"./path-guards-DGttsOJI.mjs";import"./utils-Dlk0IYAa.mjs";import{a as pluginCacheRealpathSync,l as readPluginCacheJsonFile,r as pluginCacheExistsSync}from"./plugin-cache-files-BGuripl0.mjs";import{a as isSourceCheckoutRoot,i as isPluginInPackageBundledRoots}from"./bundled-dir-CMJ7m2eP.mjs";import fs from"node:fs";import path from"node:path";
//!src/plugins/dev-source-root.ts
const OPENCLAW_DEV_SOURCE_ROOT_ENV=`OPENCLAW_DEV_SOURCE_ROOT`;function readStagedOfficialPluginIds(e){const t=readPluginCacheJsonFile(path.join(e,`dist`,`build-info.json`));if(!t.ok||!isRecord(t.value))return[];const{commit:n,stagedOfficialPlugins:r}=t.value;return typeof n===`string`&&/^[0-9a-f]{40}$/.test(n)&&isRecord(r)&&r.commit===n&&Array.isArray(r.pluginIds)?r.pluginIds:[]}function readPackageName(e){try{const t=JSON.parse(fs.readFileSync(e,`utf-8`));return typeof t.name===`string`?t.name:null}catch{return null}}function resolveOpenClawDevSourceRoot(e=process.env){const t=e[OPENCLAW_DEV_SOURCE_ROOT_ENV]?.trim();if(!t)return null;const n=resolveUserPath(t,e);const r=getPluginCache().sdk.devSourceRoots;if(r.has(n))return r.get(n)??null;const i=pluginCacheRealpathSync(n);const a=i&&readPackageName(path.join(i,`package.json`))===`openclaw`&&pluginCacheExistsSync(path.join(i,`src`))&&pluginCacheExistsSync(path.join(i,`extensions`))?i:null;r.set(n,a);return a}function resolveBundledPluginSourceRoot(e=process.env){const t=resolveOpenClawDevSourceRoot(e);if(t)return t;const n=resolveOpenClawPackageRootSync({moduleUrl:import.meta.url});return n&&(isSourceCheckoutRoot(n)||readStagedOfficialPluginIds(n).length>0)?n:null}function formatSourceBundledPluginNotice(e){return`Kept bundled plugin "${e}" from the OpenClaw source build; the registry artifact has no matching host SDK build identity. Matching version strings do not establish SDK compatibility.`}function isBundledPluginInsideDevSourceRoot(e){const t=resolveBundledPluginSourceRoot(e.env);if(!t)return false;if(!isPluginInPackageBundledRoots({packageRoot:t,rootDir:resolveUserPath(e.rootDir,e.env)}))return false;if(resolveOpenClawDevSourceRoot(e.env))return true;const n=pluginCacheRealpathSync(t);const r=pluginCacheRealpathSync(resolveUserPath(e.rootDir,e.env));if(!isSourceCheckoutRoot(t))return Boolean(n&&r&&readStagedOfficialPluginIds(n).includes(path.basename(r))&&path.dirname(r)===path.join(n,`dist`,`extensions`));return Boolean(n&&r&&[`dist`,`dist-runtime`].some(e=>isPathInside(path.join(n,e,`extensions`),r)))}export{resolveOpenClawDevSourceRoot as i,isBundledPluginInsideDevSourceRoot as n,resolveBundledPluginSourceRoot as r,formatSourceBundledPluginNotice as t};