@deepagents/context 7.10.2 → 7.11.0
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 +74 -9
- package/dist/index.js.map +3 -3
- package/dist/lib/sandbox/bash-tool.d.ts +2 -2
- package/dist/lib/sandbox/bash-tool.d.ts.map +1 -1
- package/dist/lib/sandbox/container-session.d.ts.map +1 -1
- package/dist/lib/sandbox/docker-sandbox.d.ts.map +1 -1
- package/dist/lib/sandbox/read-file-tool/index.d.ts +2 -2
- package/dist/lib/sandbox/read-file-tool/index.d.ts.map +1 -1
- package/dist/lib/sandbox/session.d.ts +5 -1
- package/dist/lib/sandbox/session.d.ts.map +1 -1
- package/dist/lib/sandbox/types.d.ts +84 -17
- package/dist/lib/sandbox/types.d.ts.map +1 -1
- package/dist/lib/sandbox/virtual-sandbox.d.ts +19 -1
- package/dist/lib/sandbox/virtual-sandbox.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -7594,6 +7594,7 @@ async function deleteFileOverExec(container, path6, signal) {
|
|
|
7594
7594
|
}
|
|
7595
7595
|
return true;
|
|
7596
7596
|
}
|
|
7597
|
+
var CONTROL_DIRECTORIES = ["/dev/shm", "/tmp"];
|
|
7597
7598
|
async function collectOutput(process2) {
|
|
7598
7599
|
const [stdout, stderr, exitCode] = await Promise.all([
|
|
7599
7600
|
text2(process2.stdout),
|
|
@@ -7602,11 +7603,14 @@ async function collectOutput(process2) {
|
|
|
7602
7603
|
]);
|
|
7603
7604
|
return { stdout, stderr, exitCode };
|
|
7604
7605
|
}
|
|
7605
|
-
function managedCommand(command,
|
|
7606
|
+
function managedCommand(command, controlFile, commandTimeout) {
|
|
7606
7607
|
return [
|
|
7607
7608
|
"set -m",
|
|
7608
|
-
|
|
7609
|
-
|
|
7609
|
+
"control=",
|
|
7610
|
+
`for dir in ${CONTROL_DIRECTORIES.join(" ")}; do`,
|
|
7611
|
+
` if { : > "$dir/"${shellQuote(controlFile)}; } 2>/dev/null; then control="$dir/"${shellQuote(controlFile)}; break; fi`,
|
|
7612
|
+
"done",
|
|
7613
|
+
`[ -n "$control" ] || { echo ${shellQuote(`Cannot start the command: neither ${CONTROL_DIRECTORIES.join(" nor ")} is writable for the file that lets the sandbox stop it`)} >&2; exit 1; }`,
|
|
7610
7614
|
"timer=",
|
|
7611
7615
|
`trap 'if [ -n "$timer" ]; then kill -TERM "$timer" 2>/dev/null || :; wait "$timer" 2>/dev/null || :; fi; rm -f "$control" "$control.timeout"' EXIT`,
|
|
7612
7616
|
`bash -lc ${shellQuote(command)} &`,
|
|
@@ -7630,13 +7634,16 @@ function managedCommand(command, controlPath, commandTimeout) {
|
|
|
7630
7634
|
'exit "$status"'
|
|
7631
7635
|
].join("\n");
|
|
7632
7636
|
}
|
|
7633
|
-
async function terminate(container,
|
|
7637
|
+
async function terminate(container, controlFile, exitCode) {
|
|
7634
7638
|
const exited = exitCode.then(
|
|
7635
7639
|
() => true,
|
|
7636
7640
|
() => true
|
|
7637
7641
|
);
|
|
7638
7642
|
const killGroup = [
|
|
7639
|
-
`
|
|
7643
|
+
`for dir in ${CONTROL_DIRECTORIES.join(" ")}; do`,
|
|
7644
|
+
` { IFS= read -r pid < "$dir/"${shellQuote(controlFile)}; } 2>/dev/null && break`,
|
|
7645
|
+
" pid=",
|
|
7646
|
+
"done",
|
|
7640
7647
|
'[ -n "$pid" ] || exit 0',
|
|
7641
7648
|
"printf found",
|
|
7642
7649
|
'kill -KILL -- "-$pid" 2>/dev/null || exit 0',
|
|
@@ -7679,18 +7686,18 @@ function containerSession(container, errors) {
|
|
|
7679
7686
|
async function spawn5(options) {
|
|
7680
7687
|
const { command, abortSignal, stdin } = options;
|
|
7681
7688
|
abortSignal?.throwIfAborted();
|
|
7682
|
-
const
|
|
7689
|
+
const controlFile = `deepagents-exec-${randomUUID()}.pid`;
|
|
7683
7690
|
const process2 = await container.spawn(
|
|
7684
7691
|
[
|
|
7685
7692
|
"bash",
|
|
7686
7693
|
"-c",
|
|
7687
|
-
managedCommand(command,
|
|
7694
|
+
managedCommand(command, controlFile, container.commandTimeout)
|
|
7688
7695
|
],
|
|
7689
7696
|
{ ...scope(options), stdin }
|
|
7690
7697
|
);
|
|
7691
7698
|
const control = controlProcess({
|
|
7692
7699
|
exitCode: process2.exitCode,
|
|
7693
|
-
kill: () => terminate(container,
|
|
7700
|
+
kill: () => terminate(container, controlFile, process2.exitCode),
|
|
7694
7701
|
abortSignal
|
|
7695
7702
|
});
|
|
7696
7703
|
return {
|
|
@@ -9666,7 +9673,15 @@ var DockerContainer = class {
|
|
|
9666
9673
|
try {
|
|
9667
9674
|
await this.#container.stop();
|
|
9668
9675
|
if (this.#autoRemove) {
|
|
9669
|
-
await this.#container.wait({
|
|
9676
|
+
const { Error: failure } = await this.#container.wait({
|
|
9677
|
+
condition: "removed"
|
|
9678
|
+
});
|
|
9679
|
+
if (failure?.Message) {
|
|
9680
|
+
throw new DockerSandboxError(
|
|
9681
|
+
`Failed to remove container "${this.name}": ${failure.Message}`,
|
|
9682
|
+
this.name
|
|
9683
|
+
);
|
|
9684
|
+
}
|
|
9670
9685
|
}
|
|
9671
9686
|
} catch (error) {
|
|
9672
9687
|
if (error instanceof ContainerNotFoundError) return;
|
|
@@ -11027,6 +11042,7 @@ function buildSubcommandRepair(name, subcommands) {
|
|
|
11027
11042
|
// packages/context/src/lib/sandbox/virtual-sandbox.ts
|
|
11028
11043
|
import { createJustBashSandboxSessionFromNativeSandbox } from "@ai-sdk/sandbox-just-bash";
|
|
11029
11044
|
import {
|
|
11045
|
+
InMemoryFs,
|
|
11030
11046
|
Sandbox
|
|
11031
11047
|
} from "just-bash";
|
|
11032
11048
|
async function createVirtualSandbox({
|
|
@@ -11054,6 +11070,54 @@ async function createVirtualSandbox({
|
|
|
11054
11070
|
}
|
|
11055
11071
|
return sandbox;
|
|
11056
11072
|
}
|
|
11073
|
+
var VirtualSandboxEnvironment = class {
|
|
11074
|
+
#options;
|
|
11075
|
+
#filesystems = /* @__PURE__ */ new Map();
|
|
11076
|
+
constructor(options = {}) {
|
|
11077
|
+
this.#options = options;
|
|
11078
|
+
}
|
|
11079
|
+
async open(chat2) {
|
|
11080
|
+
let fs = this.#filesystems.get(chat2.chatId);
|
|
11081
|
+
if (fs === void 0) {
|
|
11082
|
+
fs = new InMemoryFs();
|
|
11083
|
+
this.#filesystems.set(chat2.chatId, fs);
|
|
11084
|
+
}
|
|
11085
|
+
const sandbox = await createVirtualSandbox({ ...this.#options, fs });
|
|
11086
|
+
let closing;
|
|
11087
|
+
const close = () => closing ??= sandbox.dispose();
|
|
11088
|
+
const live = (operation) => async (...args) => {
|
|
11089
|
+
if (closing !== void 0) {
|
|
11090
|
+
throw new Error(
|
|
11091
|
+
`The sandbox handle of chat "${chat2.chatId}" is closed.`
|
|
11092
|
+
);
|
|
11093
|
+
}
|
|
11094
|
+
if (this.#filesystems.get(chat2.chatId) !== fs) {
|
|
11095
|
+
throw new SandboxNotFoundError(chat2.chatId);
|
|
11096
|
+
}
|
|
11097
|
+
return operation.apply(sandbox, args);
|
|
11098
|
+
};
|
|
11099
|
+
return Object.assign(sandbox, {
|
|
11100
|
+
run: live(sandbox.run),
|
|
11101
|
+
spawn: live(sandbox.spawn),
|
|
11102
|
+
readFile: live(sandbox.readFile),
|
|
11103
|
+
readBinaryFile: live(sandbox.readBinaryFile),
|
|
11104
|
+
readTextFile: live(sandbox.readTextFile),
|
|
11105
|
+
writeFile: live(sandbox.writeFile),
|
|
11106
|
+
writeBinaryFile: live(sandbox.writeBinaryFile),
|
|
11107
|
+
writeTextFile: live(sandbox.writeTextFile),
|
|
11108
|
+
stat: live(sandbox.stat),
|
|
11109
|
+
listDirectory: live(sandbox.listDirectory),
|
|
11110
|
+
deleteFile: live(sandbox.deleteFile),
|
|
11111
|
+
resume: live(async () => {
|
|
11112
|
+
}),
|
|
11113
|
+
close,
|
|
11114
|
+
[Symbol.asyncDispose]: close
|
|
11115
|
+
});
|
|
11116
|
+
}
|
|
11117
|
+
async delete(chat2) {
|
|
11118
|
+
this.#filesystems.delete(chat2.chatId);
|
|
11119
|
+
}
|
|
11120
|
+
};
|
|
11057
11121
|
|
|
11058
11122
|
// packages/context/src/lib/skills/fragments.ts
|
|
11059
11123
|
import dedent4 from "dedent";
|
|
@@ -14528,6 +14592,7 @@ export {
|
|
|
14528
14592
|
TomlRenderer,
|
|
14529
14593
|
ToonRenderer,
|
|
14530
14594
|
UrlBinaryInstaller,
|
|
14595
|
+
VirtualSandboxEnvironment,
|
|
14531
14596
|
VolumeCreateError,
|
|
14532
14597
|
VolumeInspectError,
|
|
14533
14598
|
VolumePathError,
|