@deepagents/context 7.1.4 → 7.2.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/browser.js CHANGED
@@ -2366,6 +2366,28 @@ var ContextStore = class {
2366
2366
  }
2367
2367
  };
2368
2368
 
2369
+ // packages/context/src/lib/stream/stream-store.ts
2370
+ function collectStreamFailures(chunks) {
2371
+ const failures = /* @__PURE__ */ new Map();
2372
+ for (const chunk of chunks) {
2373
+ if (failures.has(chunk.streamId)) continue;
2374
+ if (chunk.data.type === "error") {
2375
+ failures.set(chunk.streamId, chunk.data.errorText);
2376
+ } else if (chunk.data.type === "finish" && chunk.data.finishReason === "interrupted") {
2377
+ failures.set(
2378
+ chunk.streamId,
2379
+ "Model stream interrupted before completion."
2380
+ );
2381
+ }
2382
+ }
2383
+ return [...failures].map(([streamId, error]) => ({ streamId, error }));
2384
+ }
2385
+ var StreamStore = class {
2386
+ async listRunningStreamIds() {
2387
+ return this.listStreamIds({ status: "running" });
2388
+ }
2389
+ };
2390
+
2369
2391
  // packages/context/src/lib/stream-buffer.ts
2370
2392
  async function persistedWriter(options) {
2371
2393
  const {
@@ -2377,7 +2399,7 @@ async function persistedWriter(options) {
2377
2399
  } = options;
2378
2400
  let seq = 0;
2379
2401
  let buffer = [];
2380
- let failedByErrorChunk = false;
2402
+ let failedByChunk = false;
2381
2403
  let abortedByChunk = false;
2382
2404
  async function flush() {
2383
2405
  if (buffer.length === 0) return;
@@ -2393,15 +2415,9 @@ async function persistedWriter(options) {
2393
2415
  createdAt: Date.now()
2394
2416
  };
2395
2417
  }
2396
- function isStreamErrorPart(part) {
2397
- return part.type === "error";
2398
- }
2399
2418
  async function appendBatch(batch) {
2400
- const hasErrorPart = !failedByErrorChunk && batch.map((chunk) => chunk.data).some(isStreamErrorPart);
2401
2419
  await store.appendChunks(batch);
2402
- if (hasErrorPart) {
2403
- failedByErrorChunk = true;
2404
- }
2420
+ failedByChunk ||= collectStreamFailures(batch).length > 0;
2405
2421
  }
2406
2422
  async function persistChunk(chunk) {
2407
2423
  if (chunk.data.type === "abort") {
@@ -2438,7 +2454,7 @@ async function persistedWriter(options) {
2438
2454
  flush,
2439
2455
  async complete() {
2440
2456
  await flush();
2441
- if (failedByErrorChunk) return;
2457
+ if (failedByChunk) return;
2442
2458
  await store.updateStreamStatus(
2443
2459
  streamId,
2444
2460
  abortedByChunk ? "cancelled" : "completed"
@@ -2446,7 +2462,7 @@ async function persistedWriter(options) {
2446
2462
  },
2447
2463
  async fail(error) {
2448
2464
  await flush();
2449
- if (failedByErrorChunk) return;
2465
+ if (failedByChunk) return;
2450
2466
  await store.updateStreamStatus(streamId, "failed", { error });
2451
2467
  },
2452
2468
  async cleanup() {
@@ -2455,22 +2471,6 @@ async function persistedWriter(options) {
2455
2471
  };
2456
2472
  }
2457
2473
 
2458
- // packages/context/src/lib/stream/stream-store.ts
2459
- function collectStreamFailures(chunks) {
2460
- const failures = /* @__PURE__ */ new Map();
2461
- for (const chunk of chunks) {
2462
- if (chunk.data.type === "error" && !failures.has(chunk.streamId)) {
2463
- failures.set(chunk.streamId, chunk.data.errorText);
2464
- }
2465
- }
2466
- return [...failures].map(([streamId, error]) => ({ streamId, error }));
2467
- }
2468
- var StreamStore = class {
2469
- async listRunningStreamIds() {
2470
- return this.listStreamIds({ status: "running" });
2471
- }
2472
- };
2473
-
2474
2474
  // packages/context/src/lib/visualize.ts
2475
2475
  function visualizeGraph(data) {
2476
2476
  if (data.nodes.length === 0) {