@deepagents/experimental 7.10.1 → 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.
@@ -1,22 +1,13 @@
1
1
  import type { TelemetryOptions } from 'ai';
2
2
  import type { CompactOptions, CompactionTrigger } from '@deepagents/compaction';
3
- import type { AgentControls, AgentModel, AgentSandbox, BashToolkitTools, ContextFragment, CreateAgent } from '@deepagents/context';
3
+ import type { AgentControls, AgentModel, AgentSandbox, BashToolkitTools, ContextFragment, CreateAgent, DisposableSandbox, SandboxContext } from '@deepagents/context';
4
4
  import type { AgentPluginDefinition } from './runtime/agent-runtime.ts';
5
5
  import type { ZukhrufToolSet } from './tool.ts';
6
- /**
7
- * Sandboxes are per-chat: the factory receives the conversation identity so
8
- * the backend can be named by `chatId` and re-attached across turns, workers,
9
- * and restarts (the container engine is the registry — no in-memory state).
10
- */
11
- export interface SandboxContext {
12
- chatId: string;
13
- userId: string;
14
- }
15
6
  /**
16
7
  * Needs both file tools: the uploads plugin tells the model to read attached
17
8
  * images with `readFile`.
18
9
  */
19
- export type ZukhrufSandbox = AgentSandbox<BashToolkitTools> & {
10
+ export type ZukhrufSandbox = AgentSandbox<BashToolkitTools, DisposableSandbox> & {
20
11
  /** Absolute directory containing this conversation's files and skills. Omit to disable discovery. */
21
12
  readonly workingDirectory?: string;
22
13
  };
@@ -34,6 +25,12 @@ export interface AgentDeclaration extends AgentControls<ZukhrufToolSet> {
34
25
  name: string;
35
26
  description?: string;
36
27
  model: AgentModel;
28
+ /**
29
+ * Sandboxes are per-chat: the factory receives the conversation identity so
30
+ * the backend can be named by `chatId` and re-attached across turns,
31
+ * workers, and restarts (the container engine is the registry — no
32
+ * in-memory state).
33
+ */
37
34
  sandbox: (context: SandboxContext) => Promise<ZukhrufSandbox>;
38
35
  /** Native agent-loop termination; omitted uses the context agent default. */
39
36
  stopWhen?: CreateAgent['stopWhen'];
@@ -1 +1 @@
1
- {"version":3,"file":"agent.d.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,GAAG;IACF,0FAA0F;IAC1F,QAAQ,EAAE,SAAS,iBAAiB,EAAE,CAAC;CACxC,CAAC;AAEF,MAAM,WAAW,gBAAiB,SAAQ,aAAa,CAAC,cAAc,CAAC;IACrE;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,UAAU,CAAC;IAClB;;;;;OAKG;IACH,OAAO,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;IAC9D,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,WAAW,CAAC,UAAU,CAAC,CAAC;IACnC,YAAY,EAAE,eAAe,EAAE,CAAC;IAChC,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,gEAAgE;IAChE,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,SAAS,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAC/B,2EAA2E;IAC3E,OAAO,CAAC,EAAE,SAAS,qBAAqB,EAAE,CAAC;IAC3C,SAAS,CAAC,EAAE,IAAI,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC;IACnD,uFAAuF;IACvF,UAAU,CAAC,EAAE,eAAe,CAAC;CAC9B;AAED,MAAM,WAAW,uBAAwB,SAAQ,gBAAgB;IAC/D,KAAK,EAAE,cAAc,CAAC;IACtB,SAAS,EAAE,gBAAgB,EAAE,CAAC;IAC9B,OAAO,EAAE,SAAS,qBAAqB,EAAE,CAAC;CAC3C;AAED,wBAAgB,WAAW,CACzB,WAAW,EAAE,gBAAgB,GAC5B,uBAAuB,CAwBzB"}
@@ -4385,6 +4385,7 @@ function isSkill(value) {
4385
4385
  }
4386
4386
 
4387
4387
  // packages/experimental/src/zukhruf/runtime/conversation-sandboxes.ts
4388
+ import { SandboxNotFoundError } from "@deepagents/context";
4388
4389
  var ConversationSandboxes = class {
4389
4390
  // One memoized acquisition for each declaration and conversation.
4390
4391
  #held = /* @__PURE__ */ new Map();
@@ -4395,7 +4396,8 @@ var ConversationSandboxes = class {
4395
4396
  context.userId
4396
4397
  ]);
4397
4398
  const held = this.#held.get(key);
4398
- if (held !== void 0) return held();
4399
+ if (held !== void 0)
4400
+ return this.#existing(key, held, declaration, context);
4399
4401
  const acquiring = declaration.sandbox(context).catch((error) => {
4400
4402
  this.#held.delete(key);
4401
4403
  throw error;
@@ -4403,6 +4405,25 @@ var ConversationSandboxes = class {
4403
4405
  this.#held.set(key, () => acquiring);
4404
4406
  return acquiring;
4405
4407
  }
4408
+ /**
4409
+ * Checked before the turn, not left to its first command: the turn's tools
4410
+ * are bound to this handle, so a sandbox found gone mid-turn fails the
4411
+ * model's tool call instead of acquiring a new sandbox.
4412
+ */
4413
+ async #existing(key, held, declaration, context) {
4414
+ const handle = await held();
4415
+ try {
4416
+ await handle.sandbox.run({ command: "true" });
4417
+ return handle;
4418
+ } catch (error) {
4419
+ if (!(error instanceof SandboxNotFoundError)) throw error;
4420
+ }
4421
+ if (this.#held.get(key) === held) {
4422
+ this.#held.delete(key);
4423
+ await handle.sandbox.dispose();
4424
+ }
4425
+ return this.acquire(declaration, context);
4426
+ }
4406
4427
  async [Symbol.asyncDispose]() {
4407
4428
  await using handles = new AsyncDisposableStack();
4408
4429
  const acquired = await Promise.allSettled(