@computesdk/sandbox0 1.0.19 → 1.0.21
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.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- 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.d.mts
CHANGED
|
@@ -23,6 +23,8 @@ interface Sandbox0Config {
|
|
|
23
23
|
/** Default command timeout in milliseconds. */
|
|
24
24
|
commandTimeout?: number;
|
|
25
25
|
}
|
|
26
|
-
declare const sandbox0: (config?: Sandbox0Config) => _computesdk_provider.Provider<Sandbox, any, any, computesdk.Volume
|
|
26
|
+
declare const sandbox0: (config?: Sandbox0Config) => _computesdk_provider.Provider<Sandbox, any, any, computesdk.Volume> & {
|
|
27
|
+
readonly sizes: computesdk.InstanceSizeManager;
|
|
28
|
+
};
|
|
27
29
|
|
|
28
30
|
export { type Sandbox0Config, sandbox0 };
|
package/dist/index.d.ts
CHANGED
|
@@ -23,6 +23,8 @@ interface Sandbox0Config {
|
|
|
23
23
|
/** Default command timeout in milliseconds. */
|
|
24
24
|
commandTimeout?: number;
|
|
25
25
|
}
|
|
26
|
-
declare const sandbox0: (config?: Sandbox0Config) => _computesdk_provider.Provider<Sandbox, any, any, computesdk.Volume
|
|
26
|
+
declare const sandbox0: (config?: Sandbox0Config) => _computesdk_provider.Provider<Sandbox, any, any, computesdk.Volume> & {
|
|
27
|
+
readonly sizes: computesdk.InstanceSizeManager;
|
|
28
|
+
};
|
|
27
29
|
|
|
28
30
|
export { type Sandbox0Config, sandbox0 };
|
package/dist/index.js
CHANGED
|
@@ -25,6 +25,7 @@ __export(index_exports, {
|
|
|
25
25
|
sandbox0: () => sandbox0
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
var import_node_crypto2 = require("crypto");
|
|
28
29
|
|
|
29
30
|
// ../../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
|
|
30
31
|
var apis_exports = {};
|
|
@@ -22808,11 +22809,14 @@ var _provider = (0, import_provider.defineProvider)({
|
|
|
22808
22809
|
const timeout = options?.timeout ?? observations.get(sandbox)?.commandTimeout;
|
|
22809
22810
|
const ttlSec = commandTimeoutSeconds(timeout);
|
|
22810
22811
|
const deadline = timeout !== void 0 && timeout > 0 ? startedAt + timeout : void 0;
|
|
22812
|
+
const base = `/tmp/.sandbox0-exec-${(0, import_node_crypto2.randomUUID)().replace(/-/g, "").slice(0, 12)}`;
|
|
22813
|
+
const wrapped = options?.background ? command : `( ${command}
|
|
22814
|
+
) > ${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`;
|
|
22811
22815
|
let started;
|
|
22812
22816
|
for (let attempt = 0; ; attempt += 1) {
|
|
22813
22817
|
try {
|
|
22814
|
-
started = await sandbox.cmd(
|
|
22815
|
-
command: ["sh", "-lc",
|
|
22818
|
+
started = await sandbox.cmd(wrapped, {
|
|
22819
|
+
command: ["sh", "-lc", wrapped],
|
|
22816
22820
|
wait: false,
|
|
22817
22821
|
cwd: options?.cwd,
|
|
22818
22822
|
envVars: options?.env,
|
|
@@ -22842,10 +22846,51 @@ var _provider = (0, import_provider.defineProvider)({
|
|
|
22842
22846
|
deadline,
|
|
22843
22847
|
timeout
|
|
22844
22848
|
);
|
|
22849
|
+
const readViaCommand = async (script) => {
|
|
22850
|
+
const s = await sandbox.cmd(script, {
|
|
22851
|
+
command: ["sh", "-lc", script],
|
|
22852
|
+
wait: false,
|
|
22853
|
+
ttlSec: 60
|
|
22854
|
+
});
|
|
22855
|
+
try {
|
|
22856
|
+
const done = await observeCommandCompletion(
|
|
22857
|
+
sandbox,
|
|
22858
|
+
s.contextId,
|
|
22859
|
+
Date.now() + 6e4,
|
|
22860
|
+
6e4
|
|
22861
|
+
);
|
|
22862
|
+
return done.context?.stdout ?? done.output.stdout;
|
|
22863
|
+
} finally {
|
|
22864
|
+
deleteContextBestEffort(sandbox, s.contextId);
|
|
22865
|
+
}
|
|
22866
|
+
};
|
|
22867
|
+
const readVerified = async (path, lenPath) => {
|
|
22868
|
+
const expected = Number.parseInt(
|
|
22869
|
+
(await readViaCommand(`cat ${lenPath} 2>/dev/null`)).trim(),
|
|
22870
|
+
10
|
|
22871
|
+
);
|
|
22872
|
+
const first = await readViaCommand(`cat ${path}`);
|
|
22873
|
+
if (Number.isNaN(expected) || Buffer.byteLength(first) === expected) return first;
|
|
22874
|
+
const second = await readViaCommand(`cat ${path}`);
|
|
22875
|
+
return Buffer.byteLength(second) >= Buffer.byteLength(first) ? second : first;
|
|
22876
|
+
};
|
|
22877
|
+
let stdout;
|
|
22878
|
+
let stderr;
|
|
22879
|
+
let codeText;
|
|
22880
|
+
try {
|
|
22881
|
+
stdout = await readVerified(`${base}.out`, `${base}.outlen`);
|
|
22882
|
+
stderr = await readVerified(`${base}.err`, `${base}.errlen`);
|
|
22883
|
+
codeText = await readViaCommand(`cat ${base}.code 2>/dev/null`).catch(() => "");
|
|
22884
|
+
} finally {
|
|
22885
|
+
await readViaCommand(
|
|
22886
|
+
`rm -f ${base}.out ${base}.err ${base}.outlen ${base}.errlen ${base}.code`
|
|
22887
|
+
).catch(() => void 0);
|
|
22888
|
+
}
|
|
22889
|
+
const fileExit = Number.parseInt(codeText.trim(), 10);
|
|
22845
22890
|
return {
|
|
22846
|
-
stdout
|
|
22847
|
-
stderr
|
|
22848
|
-
exitCode: completed.context?.exitCode ?? completed.terminal?.exitCode ?? 1,
|
|
22891
|
+
stdout,
|
|
22892
|
+
stderr,
|
|
22893
|
+
exitCode: Number.isInteger(fileExit) ? fileExit : completed.context?.exitCode ?? completed.terminal?.exitCode ?? 1,
|
|
22849
22894
|
durationMs: Date.now() - startedAt
|
|
22850
22895
|
};
|
|
22851
22896
|
} catch (error) {
|