@deepagents/context 2.1.0 → 2.3.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.
Files changed (42) hide show
  1. package/README.md +18 -14
  2. package/dist/browser.js +37 -2
  3. package/dist/browser.js.map +3 -3
  4. package/dist/index.js +845 -112
  5. package/dist/index.js.map +4 -4
  6. package/dist/lib/guardrail.d.ts +2 -6
  7. package/dist/lib/guardrail.d.ts.map +1 -1
  8. package/dist/lib/sandbox/abort.d.ts.map +1 -1
  9. package/dist/lib/sandbox/agent-os-sandbox.d.ts +5 -1
  10. package/dist/lib/sandbox/agent-os-sandbox.d.ts.map +1 -1
  11. package/dist/lib/sandbox/daytona-sandbox.d.ts +63 -0
  12. package/dist/lib/sandbox/daytona-sandbox.d.ts.map +1 -0
  13. package/dist/lib/sandbox/docker-sandbox-errors.d.ts +9 -4
  14. package/dist/lib/sandbox/docker-sandbox-errors.d.ts.map +1 -1
  15. package/dist/lib/sandbox/docker-sandbox.d.ts +24 -1
  16. package/dist/lib/sandbox/docker-sandbox.d.ts.map +1 -1
  17. package/dist/lib/sandbox/file-events.d.ts +10 -1
  18. package/dist/lib/sandbox/file-events.d.ts.map +1 -1
  19. package/dist/lib/sandbox/index.d.ts +1 -1
  20. package/dist/lib/sandbox/index.d.ts.map +1 -1
  21. package/dist/lib/sandbox/installers/bin.d.ts +40 -0
  22. package/dist/lib/sandbox/installers/bin.d.ts.map +1 -0
  23. package/dist/lib/sandbox/installers/index.d.ts +1 -0
  24. package/dist/lib/sandbox/installers/index.d.ts.map +1 -1
  25. package/dist/lib/save/save-pipeline.d.ts.map +1 -1
  26. package/dist/lib/skills/fragments.d.ts +2 -2
  27. package/dist/lib/store/sqlite.store.d.ts +1 -0
  28. package/dist/lib/store/sqlite.store.d.ts.map +1 -1
  29. package/dist/lib/store/store.d.ts +8 -0
  30. package/dist/lib/store/store.d.ts.map +1 -1
  31. package/dist/lib/stream/postgres.stream-store.d.ts.map +1 -1
  32. package/dist/lib/stream/sqlite.stream-store.d.ts.map +1 -1
  33. package/dist/lib/stream/stream-manager.d.ts +1 -1
  34. package/dist/lib/stream/stream-manager.d.ts.map +1 -1
  35. package/dist/lib/stream/stream-store.d.ts +8 -1
  36. package/dist/lib/stream/stream-store.d.ts.map +1 -1
  37. package/dist/lib/stream/types.d.ts +7 -0
  38. package/dist/lib/stream/types.d.ts.map +1 -0
  39. package/dist/lib/stream-buffer.d.ts.map +1 -1
  40. package/package.json +7 -3
  41. package/dist/lib/sandbox/container-tool.d.ts +0 -190
  42. package/dist/lib/sandbox/container-tool.d.ts.map +0 -1
package/README.md CHANGED
@@ -27,14 +27,13 @@ like store implementations, sandbox tooling, and filesystem-based skill loading.
27
27
 
28
28
  The server-side package also ships the sandbox primitives used by
29
29
  `@deepagents/text2sql` and other tool-driven agents. Use `createBashTool()`
30
- with `createVirtualSandbox()`, `createContainerTool()`, `createDockerSandbox()`,
31
- or `createAgentOsSandbox()` depending on whether commands should run in memory,
30
+ with `createVirtualSandbox()`, `createDockerSandbox()`, or
31
+ `createAgentOsSandbox()` depending on whether commands should run in memory,
32
32
  Docker, or Agent OS.
33
33
 
34
34
  See the docs for the full API surface:
35
35
 
36
36
  - [Sandbox](https://januarylabs.github.io/deepagents/docs/context/sandbox)
37
- - [Container Tool](https://januarylabs.github.io/deepagents/docs/context/container-tool)
38
37
  - [Subcommand Builders](https://januarylabs.github.io/deepagents/docs/context/subcommand)
39
38
 
40
39
  ## Basic Usage
@@ -408,31 +407,36 @@ The package includes durable stream persistence utilities:
408
407
  - `persistedWriter` (low-level writer wrapper)
409
408
 
410
409
  ```typescript
411
- import { SqliteStreamStore, StreamManager } from '@deepagents/context';
410
+ import {
411
+ PollingChangeSource,
412
+ SqliteStreamStore,
413
+ StreamManager,
414
+ } from '@deepagents/context';
412
415
 
413
416
  const store = new SqliteStreamStore('./streams.db');
414
- const manager = new StreamManager({
415
- store,
416
- watchPolling: {
417
+ const changeSource = new PollingChangeSource({
418
+ reads: store,
419
+ config: {
417
420
  minMs: 25,
418
421
  maxMs: 500,
419
422
  multiplier: 2,
420
423
  jitterRatio: 0.15,
421
424
  statusCheckEvery: 3,
422
- chunkPageSize: 128,
423
- },
424
- cancelPolling: {
425
- minMs: 50,
426
- maxMs: 500,
427
- multiplier: 2,
428
- jitterRatio: 0.15,
429
425
  },
430
426
  });
427
+ const manager = new StreamManager({
428
+ store,
429
+ changeSource,
430
+ chunkPageSize: 128,
431
+ });
431
432
 
432
433
  // Discover active streams without writing raw SQL.
433
434
  const runningStreamIds = await store.listStreamIds({ status: 'running' });
434
435
  const runningViaConvenienceMethod = await store.listRunningStreamIds();
435
436
 
437
+ // Streams auto-fail if a persisted chunk has type: 'error'
438
+ // (the stream's `error` field is populated from `errorText`).
439
+
436
440
  // Shutdown cleanup (idempotent)
437
441
  store.close();
438
442
  ```
package/dist/browser.js CHANGED
@@ -2222,6 +2222,18 @@ function soul() {
2222
2222
 
2223
2223
  // packages/context/src/lib/store/store.ts
2224
2224
  var ContextStore = class {
2225
+ /**
2226
+ * Add multiple messages to the graph.
2227
+ *
2228
+ * Stores can override this for atomic/batched persistence. The default keeps
2229
+ * the single-message contract for implementations that do not need a custom
2230
+ * batch path.
2231
+ */
2232
+ async addMessages(messages) {
2233
+ for (const message2 of messages) {
2234
+ await this.addMessage(message2);
2235
+ }
2236
+ }
2225
2237
  };
2226
2238
 
2227
2239
  // packages/context/src/lib/stream-buffer.ts
@@ -2235,11 +2247,12 @@ async function persistedWriter(options) {
2235
2247
  } = options;
2236
2248
  let seq = 0;
2237
2249
  let buffer = [];
2250
+ let failedByErrorChunk = false;
2238
2251
  async function flush() {
2239
2252
  if (buffer.length === 0) return;
2240
2253
  const batch = buffer;
2241
2254
  buffer = [];
2242
- await store.appendChunks(batch);
2255
+ await appendBatch(batch);
2243
2256
  }
2244
2257
  function makeChunk(part) {
2245
2258
  return {
@@ -2249,9 +2262,19 @@ async function persistedWriter(options) {
2249
2262
  createdAt: Date.now()
2250
2263
  };
2251
2264
  }
2265
+ function isStreamErrorPart(part) {
2266
+ return part.type === "error";
2267
+ }
2268
+ async function appendBatch(batch) {
2269
+ const hasErrorPart = !failedByErrorChunk && batch.map((chunk) => chunk.data).some(isStreamErrorPart);
2270
+ await store.appendChunks(batch);
2271
+ if (hasErrorPart) {
2272
+ failedByErrorChunk = true;
2273
+ }
2274
+ }
2252
2275
  async function persistChunk(chunk) {
2253
2276
  if (strategy === "immediate") {
2254
- await store.appendChunks([chunk]);
2277
+ await appendBatch([chunk]);
2255
2278
  } else {
2256
2279
  buffer.push(chunk);
2257
2280
  if (buffer.length >= flushSize) {
@@ -2281,10 +2304,12 @@ async function persistedWriter(options) {
2281
2304
  flush,
2282
2305
  async complete() {
2283
2306
  await flush();
2307
+ if (failedByErrorChunk) return;
2284
2308
  await store.updateStreamStatus(streamId, "completed");
2285
2309
  },
2286
2310
  async fail(error) {
2287
2311
  await flush();
2312
+ if (failedByErrorChunk) return;
2288
2313
  await store.updateStreamStatus(streamId, "failed", { error });
2289
2314
  },
2290
2315
  async cleanup() {
@@ -2294,6 +2319,15 @@ async function persistedWriter(options) {
2294
2319
  }
2295
2320
 
2296
2321
  // packages/context/src/lib/stream/stream-store.ts
2322
+ function collectStreamFailures(chunks) {
2323
+ const failures = /* @__PURE__ */ new Map();
2324
+ for (const chunk of chunks) {
2325
+ if (chunk.data.type === "error" && !failures.has(chunk.streamId)) {
2326
+ failures.set(chunk.streamId, chunk.data.errorText);
2327
+ }
2328
+ }
2329
+ return [...failures].map(([streamId, error]) => ({ streamId, error }));
2330
+ }
2297
2331
  var StreamStore = class {
2298
2332
  async listRunningStreamIds() {
2299
2333
  return this.listStreamIds({ status: "running" });
@@ -2373,6 +2407,7 @@ export {
2373
2407
  assistant,
2374
2408
  assistantText,
2375
2409
  clarification,
2410
+ collectStreamFailures,
2376
2411
  correction,
2377
2412
  defaultTokenizer,
2378
2413
  estimate,