@deepagents/experimental 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
@@ -4749,6 +4749,7 @@ function isSkill(value) {
4749
4749
  }
4750
4750
 
4751
4751
  // packages/experimental/src/zukhruf/runtime/conversation-sandboxes.ts
4752
+ import { SandboxNotFoundError } from "@deepagents/context";
4752
4753
  var ConversationSandboxes = class {
4753
4754
  // One memoized acquisition for each declaration and conversation.
4754
4755
  #held = /* @__PURE__ */ new Map();
@@ -4759,7 +4760,8 @@ var ConversationSandboxes = class {
4759
4760
  context.userId
4760
4761
  ]);
4761
4762
  const held = this.#held.get(key);
4762
- if (held !== void 0) return held();
4763
+ if (held !== void 0)
4764
+ return this.#existing(key, held, declaration, context);
4763
4765
  const acquiring = declaration.sandbox(context).catch((error) => {
4764
4766
  this.#held.delete(key);
4765
4767
  throw error;
@@ -4767,6 +4769,25 @@ var ConversationSandboxes = class {
4767
4769
  this.#held.set(key, () => acquiring);
4768
4770
  return acquiring;
4769
4771
  }
4772
+ /**
4773
+ * Checked before the turn, not left to its first command: the turn's tools
4774
+ * are bound to this handle, so a sandbox found gone mid-turn fails the
4775
+ * model's tool call instead of acquiring a new sandbox.
4776
+ */
4777
+ async #existing(key, held, declaration, context) {
4778
+ const handle = await held();
4779
+ try {
4780
+ await handle.sandbox.run({ command: "true" });
4781
+ return handle;
4782
+ } catch (error) {
4783
+ if (!(error instanceof SandboxNotFoundError)) throw error;
4784
+ }
4785
+ if (this.#held.get(key) === held) {
4786
+ this.#held.delete(key);
4787
+ await handle.sandbox.dispose();
4788
+ }
4789
+ return this.acquire(declaration, context);
4790
+ }
4770
4791
  async [Symbol.asyncDispose]() {
4771
4792
  await using handles = new AsyncDisposableStack();
4772
4793
  const acquired = await Promise.allSettled(