@deepagents/context 7.10.1 → 7.10.2

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 CHANGED
@@ -8794,6 +8794,14 @@ function createReadFileTool({
8794
8794
  });
8795
8795
  }
8796
8796
 
8797
+ // packages/context/src/lib/sandbox/types.ts
8798
+ var SandboxNotFoundError = class extends Error {
8799
+ constructor(sandbox, options) {
8800
+ super(`The sandbox "${sandbox}" no longer exists.`, options);
8801
+ this.name = "SandboxNotFoundError";
8802
+ }
8803
+ };
8804
+
8797
8805
  // packages/context/src/lib/sandbox/bash-tool.ts
8798
8806
  var DEFAULT_MAX_FILES = 1e3;
8799
8807
  var DEFAULT_MAX_OUTPUT_LENGTH = 3e4;
@@ -9522,6 +9530,10 @@ var DockerContainer = class {
9522
9530
  this.#execOnly = layout.execOnly;
9523
9531
  this.#autoRemove = autoRemove;
9524
9532
  }
9533
+ /** A removed container is a sandbox that no longer exists, whichever request finds it. */
9534
+ #notFound(error) {
9535
+ return error instanceof ContainerNotFoundError ? new SandboxNotFoundError(this.name, { cause: error }) : error;
9536
+ }
9525
9537
  #config(argv, { workingDirectory, env = {} }) {
9526
9538
  return {
9527
9539
  Cmd: argv,
@@ -9537,16 +9549,23 @@ var DockerContainer = class {
9537
9549
  );
9538
9550
  return { stdout, stderr, exitCode };
9539
9551
  } catch (error) {
9552
+ if (error instanceof ContainerNotFoundError) {
9553
+ throw this.#notFound(error);
9554
+ }
9540
9555
  if (!(error instanceof DockerError)) throw error;
9541
9556
  return { stdout: "", stderr: error.message, exitCode: 1 };
9542
9557
  }
9543
9558
  }
9544
9559
  async spawn(argv, options) {
9545
- return engineProcess2(
9546
- await this.#container.spawn(this.#config(argv, options), {
9547
- stdin: options.stdin
9548
- })
9549
- );
9560
+ try {
9561
+ return engineProcess2(
9562
+ await this.#container.spawn(this.#config(argv, options), {
9563
+ stdin: options.stdin
9564
+ })
9565
+ );
9566
+ } catch (error) {
9567
+ throw this.#notFound(error);
9568
+ }
9550
9569
  }
9551
9570
  #resolve(path6) {
9552
9571
  return posix3.resolve(this.workdir, path6);
@@ -9567,7 +9586,23 @@ var DockerContainer = class {
9567
9586
  target = posix3.resolve(posix3.dirname(target), stat.linkTarget);
9568
9587
  }
9569
9588
  }
9589
+ async #isLinkOrUnstatable(path6, signal) {
9590
+ try {
9591
+ const stat = await this.#container.stat(path6, { signal });
9592
+ return stat !== void 0 && stat.linkTarget !== "";
9593
+ } catch (error) {
9594
+ if (isUnexplainedFailure(error)) return true;
9595
+ throw this.#notFound(error);
9596
+ }
9597
+ }
9570
9598
  async readFile(path6, signal) {
9599
+ try {
9600
+ return await this.#readFile(path6, signal);
9601
+ } catch (error) {
9602
+ throw this.#notFound(error);
9603
+ }
9604
+ }
9605
+ async #readFile(path6, signal) {
9571
9606
  const target = this.#resolve(path6);
9572
9607
  if (this.#isExecOnly(target)) {
9573
9608
  return readFileOverExec(this, target, signal);
@@ -9601,7 +9636,7 @@ var DockerContainer = class {
9601
9636
  }
9602
9637
  async writeFile(path6, content, signal) {
9603
9638
  const target = this.#resolve(path6);
9604
- if (this.#isExecOnly(target)) {
9639
+ if (this.#isExecOnly(target) || await this.#isLinkOrUnstatable(target, signal)) {
9605
9640
  return writeFileOverExec(this, target, content, signal);
9606
9641
  }
9607
9642
  try {
@@ -9610,6 +9645,7 @@ var DockerContainer = class {
9610
9645
  copyUIDGID: true
9611
9646
  });
9612
9647
  } catch (error) {
9648
+ if (error instanceof ContainerNotFoundError) throw this.#notFound(error);
9613
9649
  throw new Error(`Failed to write file "${path6}": ${messageOf(error)}`, {
9614
9650
  cause: error
9615
9651
  });
@@ -14481,6 +14517,7 @@ export {
14481
14517
  PostgresStreamStore,
14482
14518
  PostgresTransaction,
14483
14519
  RuntimeStrategy,
14520
+ SandboxNotFoundError,
14484
14521
  SearchQuerySyntaxError,
14485
14522
  SqlServerContextStore,
14486
14523
  SqliteContextStore,