openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
46 lines (45 loc) • 1.53 kB
JavaScript
import path from "node:path";
import { randomUUID } from "node:crypto";
//#region src/agents/sandbox/input-staging.ts
const INPUT_STAGER = Symbol.for("openclaw.sandboxInputStager");
/** Prepared host ownership, separate from the guest's file-mutation permissions. */
function bindSandboxInputStager(e, t) {
Object.defineProperty(e, INPUT_STAGER, {
value: t,
configurable: true
});
}
function getSandboxInputStager(e) {
return e[INPUT_STAGER];
}
/** Local backend owners prepare this capability; guest paths never select its root. */
function createSandboxInputStager(e) {
return async (t) => {
const assertCurrent = () => {
t.signal?.throwIfAborted();
e.assertCurrent();
t.assertCurrent();
};
assertCurrent();
const [{ root: n }, { stagedInputDirectory: r, STAGED_INPUT_GITIGNORE: i }] = await Promise.all([import("./fs-safe-CZVDXVig.mjs"), import("./staged-inputs-CtBnAYMV.mjs")]);
const a = r(randomUUID());
const o = `${a}/${t.prefix}.log`;
const s = e.bridge.resolvePath({
filePath: o,
cwd: e.root
});
if (s.hostPath !== path.join(e.root, o)) throw new Error("Sandbox input staging is shadowed by another mount");
const c = await n(e.root);
for (const [e, n] of [[`${a}/.gitignore`, i], [o, t.content]]) {
assertCurrent();
await c.create(e, n, {
mode: 384,
assertBeforeMutation: assertCurrent
});
}
assertCurrent();
return s.containerPath;
};
}
//#endregion
export { createSandboxInputStager as n, getSandboxInputStager as r, bindSandboxInputStager as t };