@computesdk/sandbox0 1.0.18 → 1.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +50 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -6,6 +6,9 @@ var __export = (target, all) => {
|
|
|
6
6
|
};
|
|
7
7
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
8
|
|
|
9
|
+
// src/index.ts
|
|
10
|
+
import { randomUUID } from "crypto";
|
|
11
|
+
|
|
9
12
|
// ../../node_modules/.pnpm/sandbox0@0.9.5_bufferutil@4.1.0_utf-8-validate@6.0.6/node_modules/sandbox0/dist/apispec/src/apis/index.js
|
|
10
13
|
var apis_exports = {};
|
|
11
14
|
__export(apis_exports, {
|
|
@@ -22788,11 +22791,14 @@ var _provider = defineProvider({
|
|
|
22788
22791
|
const timeout = options?.timeout ?? observations.get(sandbox)?.commandTimeout;
|
|
22789
22792
|
const ttlSec = commandTimeoutSeconds(timeout);
|
|
22790
22793
|
const deadline = timeout !== void 0 && timeout > 0 ? startedAt + timeout : void 0;
|
|
22794
|
+
const base = `/tmp/.sandbox0-exec-${randomUUID().replace(/-/g, "").slice(0, 12)}`;
|
|
22795
|
+
const wrapped = options?.background ? command : `( ${command}
|
|
22796
|
+
) > ${base}.out 2> ${base}.err; C=$?; wc -c < ${base}.out > ${base}.outlen 2>/dev/null; wc -c < ${base}.err > ${base}.errlen 2>/dev/null; printf '%s' "$C" > ${base}.code`;
|
|
22791
22797
|
let started;
|
|
22792
22798
|
for (let attempt = 0; ; attempt += 1) {
|
|
22793
22799
|
try {
|
|
22794
|
-
started = await sandbox.cmd(
|
|
22795
|
-
command: ["sh", "-lc",
|
|
22800
|
+
started = await sandbox.cmd(wrapped, {
|
|
22801
|
+
command: ["sh", "-lc", wrapped],
|
|
22796
22802
|
wait: false,
|
|
22797
22803
|
cwd: options?.cwd,
|
|
22798
22804
|
envVars: options?.env,
|
|
@@ -22822,10 +22828,51 @@ var _provider = defineProvider({
|
|
|
22822
22828
|
deadline,
|
|
22823
22829
|
timeout
|
|
22824
22830
|
);
|
|
22831
|
+
const readViaCommand = async (script) => {
|
|
22832
|
+
const s = await sandbox.cmd(script, {
|
|
22833
|
+
command: ["sh", "-lc", script],
|
|
22834
|
+
wait: false,
|
|
22835
|
+
ttlSec: 60
|
|
22836
|
+
});
|
|
22837
|
+
try {
|
|
22838
|
+
const done = await observeCommandCompletion(
|
|
22839
|
+
sandbox,
|
|
22840
|
+
s.contextId,
|
|
22841
|
+
Date.now() + 6e4,
|
|
22842
|
+
6e4
|
|
22843
|
+
);
|
|
22844
|
+
return done.context?.stdout ?? done.output.stdout;
|
|
22845
|
+
} finally {
|
|
22846
|
+
deleteContextBestEffort(sandbox, s.contextId);
|
|
22847
|
+
}
|
|
22848
|
+
};
|
|
22849
|
+
const readVerified = async (path, lenPath) => {
|
|
22850
|
+
const expected = Number.parseInt(
|
|
22851
|
+
(await readViaCommand(`cat ${lenPath} 2>/dev/null`)).trim(),
|
|
22852
|
+
10
|
|
22853
|
+
);
|
|
22854
|
+
const first = await readViaCommand(`cat ${path}`);
|
|
22855
|
+
if (Number.isNaN(expected) || Buffer.byteLength(first) === expected) return first;
|
|
22856
|
+
const second = await readViaCommand(`cat ${path}`);
|
|
22857
|
+
return Buffer.byteLength(second) >= Buffer.byteLength(first) ? second : first;
|
|
22858
|
+
};
|
|
22859
|
+
let stdout;
|
|
22860
|
+
let stderr;
|
|
22861
|
+
let codeText;
|
|
22862
|
+
try {
|
|
22863
|
+
stdout = await readVerified(`${base}.out`, `${base}.outlen`);
|
|
22864
|
+
stderr = await readVerified(`${base}.err`, `${base}.errlen`);
|
|
22865
|
+
codeText = await readViaCommand(`cat ${base}.code 2>/dev/null`).catch(() => "");
|
|
22866
|
+
} finally {
|
|
22867
|
+
await readViaCommand(
|
|
22868
|
+
`rm -f ${base}.out ${base}.err ${base}.outlen ${base}.errlen ${base}.code`
|
|
22869
|
+
).catch(() => void 0);
|
|
22870
|
+
}
|
|
22871
|
+
const fileExit = Number.parseInt(codeText.trim(), 10);
|
|
22825
22872
|
return {
|
|
22826
|
-
stdout
|
|
22827
|
-
stderr
|
|
22828
|
-
exitCode: completed.context?.exitCode ?? completed.terminal?.exitCode ?? 1,
|
|
22873
|
+
stdout,
|
|
22874
|
+
stderr,
|
|
22875
|
+
exitCode: Number.isInteger(fileExit) ? fileExit : completed.context?.exitCode ?? completed.terminal?.exitCode ?? 1,
|
|
22829
22876
|
durationMs: Date.now() - startedAt
|
|
22830
22877
|
};
|
|
22831
22878
|
} catch (error) {
|