openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
66 lines (65 loc) • 2.65 kB
JavaScript
import { w as root } from "./fs-safe-BbWvmdVn.mjs";
import { t as walkRootDirectory } from "./root-walk-Bu7TVTb7.mjs";
import path from "node:path";
import { createHash } from "node:crypto";
//#region 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;
/** Identity of the complete immutable browser generation produced by the CLI. */
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");
}
/** Shared by the live catalog and the packaged UI inventory; keep this byte contract stable. */
function pluginControlUiRevision(e, t, n) {
const r = createHash("sha256").update(JSON.stringify({
declaration: e,
uiCapabilities: t
}));
for (const [e, t] of [...n].toSorted(([e], [t]) => e.localeCompare(t))) r.update(`${e}\0${t.body.length}\0`).update(t.body);
return r.digest("hex");
}
/** Files admitted from a plugin's dedicated browser build directory. */
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");
return {
directory: i,
entryName: s,
styles: c,
assets: a,
bytes: o
};
}
//#endregion
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 };