UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

46 lines (45 loc) 1.83 kB
import { w as root } from "./fs-safe-B6pvPGnf.js"; import { t as walkRootDirectory } from "./root-walk-CBCU9Iud.js"; import path from "node:path"; //#region src/plugins/control-ui-assets.ts const CONTROL_UI_PLUGIN_MAX_ASSET_BYTES = 4194304; const CONTROL_UI_PLUGIN_MAX_BUILD_BYTES = 8388608; const MAX_CONTROL_UI_ASSETS = 128; async function readPluginControlUiAssets(rootDir, declaration) { const pluginRoot = await root(rootDir, { hardlinks: "reject", symlinks: "reject", maxBytes: CONTROL_UI_PLUGIN_MAX_ASSET_BYTES }); const directory = path.posix.dirname(declaration.entry); const assets = /* @__PURE__ */ new Map(); let bytes = 0; for await (const entry of walkRootDirectory(pluginRoot.rootReal, directory, { symlinkPolicy: "skip", maxDepth: 8, maxEntries: MAX_CONTROL_UI_ASSETS, limitBehavior: "throw" })) { const relativePath = path.posix.relative(directory, entry.relativePath); if (entry.kind !== "file" || !/^(?:[\w-][\w.-]*\/)*[\w-][\w.-]*\.(?:m?js|css)$/u.test(relativePath)) continue; const body = await pluginRoot.readBytes(entry.relativePath); bytes += body.length; if (bytes > 8388608) throw new Error("browser build exceeds its byte limit"); assets.set(relativePath, { body, contentType: relativePath.endsWith(".css") ? "text/css; charset=utf-8" : "text/javascript; charset=utf-8" }); } const entryName = path.posix.basename(declaration.entry); const styles = (declaration.styles ?? []).map((style) => path.posix.relative(directory, style)); if (![entryName, ...styles].every((name) => assets.has(name))) throw new Error("declared browser assets are missing"); return { directory, entryName, styles, assets, bytes }; } //#endregion export { CONTROL_UI_PLUGIN_MAX_BUILD_BYTES as n, readPluginControlUiAssets as r, CONTROL_UI_PLUGIN_MAX_ASSET_BYTES as t };