UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 2.51 kB
import{x as root}from"./fs-safe-Bxzu1j4h.mjs";import{a as SESSION_ICON_SVG_MAX_BYTES,s as normalizeSessionIconValue}from"./session-agent-status-CG_6ce8U.mjs";import{t as walkRootDirectory}from"./root-walk-C9rOcTgR.mjs";import path from"node:path";import{createHash}from"node:crypto"; //!src/plugins/control-ui-assets.ts const CONTROL_UI_PLUGIN_MAX_ASSET_BYTES=4194304;const CONTROL_UI_PLUGIN_MAX_BUILD_BYTES=8388608;const CONTROL_UI_PLUGIN_MAX_ASSETS=128;function pluginControlUiGenerationHash(e){const t=createHash(`sha256`);for(const n of e.toSorted((e,t)=>e.name.localeCompare(t.name)))t.update(`${n.name}\0${n.contents.length}\0`).update(n.contents);return t.digest(`hex`)}function pluginControlUiRevision(e,t,n,r){const i=createHash(`sha256`).update(JSON.stringify({declaration:e,uiCapabilities:t,panelIcon:r}));for(const[e,t]of[...n].toSorted(([e],[t])=>e.localeCompare(t)))i.update(`${e}\0${t.body.length}\0`).update(t.body);return i.digest(`hex`)}function isPluginControlUiAssetPath(e){return/^(?:[\w-][\w.-]*\/)*[\w-][\w.-]*\.(?:m?js|css)$/u.test(e)}async function readPluginControlUiAssets(e,t,n={}){const r=await root(e,{hardlinks:n.rejectHardlinks===false?`allow`:`reject`,symlinks:`reject`,maxBytes:CONTROL_UI_PLUGIN_MAX_ASSET_BYTES});const i=path.posix.dirname(t.entry);const a=/* @__PURE__ */ new Map;let o=0;for await(const e of walkRootDirectory(r.rootReal,i,{symlinkPolicy:`skip`,maxDepth:8,maxEntries:128,limitBehavior:`throw`})){const t=path.posix.relative(i,e.relativePath);if(e.kind!==`file`||!isPluginControlUiAssetPath(t))continue;const n=await r.readBytes(e.relativePath);o+=n.length;if(o>8388608)throw new Error(`browser build exceeds its byte limit`);a.set(t,{body:n,contentType:t.endsWith(`.css`)?`text/css; charset=utf-8`:`text/javascript; charset=utf-8`})}const s=path.posix.basename(t.entry);const c=(t.styles??[]).map(e=>path.posix.relative(i,e));if(![s,...c].every(e=>a.has(e)))throw new Error(`declared browser assets are missing`);let l;if(t.panelIcon)try{const e=await r.readBytes(t.panelIcon,{maxBytes:SESSION_ICON_SVG_MAX_BYTES});const n=e.toString(`utf8`).trim();const i=n.startsWith(`<`)?normalizeSessionIconValue(n):null;if(i){l={path:t.panelIcon,body:e,dataUrl:i};o+=e.length}}catch{}return{directory:i,entryName:s,styles:c,assets:a,bytes:o,panelIcon:l}}export{pluginControlUiRevision as a,pluginControlUiGenerationHash as i,CONTROL_UI_PLUGIN_MAX_BUILD_BYTES as n,readPluginControlUiAssets as o,isPluginControlUiAssetPath as r,CONTROL_UI_PLUGIN_MAX_ASSET_BYTES as t};