@deepagents/context 7.10.0 → 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/README.md +8 -6
- package/dist/browser.js +77 -43
- package/dist/browser.js.map +2 -2
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +243 -238
- package/dist/index.js.map +4 -4
- package/dist/lib/agent.d.ts.map +1 -1
- package/dist/lib/chat.d.ts.map +1 -1
- package/dist/lib/engine.d.ts +3 -0
- package/dist/lib/engine.d.ts.map +1 -1
- package/dist/lib/sandbox/bash-tool.d.ts.map +1 -1
- package/dist/lib/sandbox/docker-sandbox.d.ts +1 -1
- package/dist/lib/sandbox/docker-sandbox.d.ts.map +1 -1
- package/dist/lib/sandbox/types.d.ts +8 -0
- package/dist/lib/sandbox/types.d.ts.map +1 -1
- package/dist/lib/stream/polling-change-source.d.ts +5 -2
- package/dist/lib/stream/polling-change-source.d.ts.map +1 -1
- package/dist/lib/stream/stream-manager.d.ts +1 -2
- package/dist/lib/stream/stream-manager.d.ts.map +1 -1
- package/dist/lib/stream-buffer.d.ts +6 -8
- package/dist/lib/stream-buffer.d.ts.map +1 -1
- package/dist/lib/tracing/batch-processor.d.ts.map +1 -1
- package/dist/lib/tracing/index.js +81 -81
- package/dist/lib/tracing/index.js.map +2 -2
- package/dist/lib/tracing/openai-traces-integration.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/lib/stream/polling-policy.d.ts +0 -22
- package/dist/lib/stream/polling-policy.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -586,6 +586,8 @@ The package includes durable stream persistence utilities:
|
|
|
586
586
|
- `persistedWriter` (low-level writer wrapper)
|
|
587
587
|
|
|
588
588
|
```typescript
|
|
589
|
+
import { Backoff } from '@zukhruf/async';
|
|
590
|
+
|
|
589
591
|
import {
|
|
590
592
|
PollingChangeSource,
|
|
591
593
|
SqliteStreamStore,
|
|
@@ -595,13 +597,13 @@ import {
|
|
|
595
597
|
const store = new SqliteStreamStore('./streams.db');
|
|
596
598
|
const changeSource = new PollingChangeSource({
|
|
597
599
|
reads: store,
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
maxMs: 500,
|
|
600
|
+
backoff: new Backoff({
|
|
601
|
+
initial: 25,
|
|
601
602
|
multiplier: 2,
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
},
|
|
603
|
+
max: 500,
|
|
604
|
+
jitter: { kind: 'ratio', ratio: 0.15 },
|
|
605
|
+
}),
|
|
606
|
+
statusCheckEvery: 3,
|
|
605
607
|
});
|
|
606
608
|
const manager = new StreamManager({
|
|
607
609
|
store,
|
package/dist/browser.js
CHANGED
|
@@ -2412,60 +2412,94 @@ var StreamStore = class {
|
|
|
2412
2412
|
};
|
|
2413
2413
|
|
|
2414
2414
|
// packages/context/src/lib/stream-buffer.ts
|
|
2415
|
+
var MAX_QUEUED_CHUNKS = 128;
|
|
2415
2416
|
async function persistedWriter(options) {
|
|
2416
|
-
const {
|
|
2417
|
-
writer,
|
|
2418
|
-
store,
|
|
2419
|
-
streamId,
|
|
2420
|
-
strategy = "buffered",
|
|
2421
|
-
flushSize = 20
|
|
2422
|
-
} = options;
|
|
2417
|
+
const { writer, store, streamId } = options;
|
|
2423
2418
|
let seq = 0;
|
|
2424
|
-
let
|
|
2419
|
+
let queue = [];
|
|
2420
|
+
let appending;
|
|
2421
|
+
let appendSettled = Promise.resolve();
|
|
2422
|
+
let failure;
|
|
2425
2423
|
let failedByChunk = false;
|
|
2426
2424
|
let abortedByChunk = false;
|
|
2427
|
-
|
|
2428
|
-
if (
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2425
|
+
function enqueue(part, committed, failed) {
|
|
2426
|
+
if (failure) {
|
|
2427
|
+
failed(failure.error);
|
|
2428
|
+
return;
|
|
2429
|
+
}
|
|
2430
|
+
queue.push({
|
|
2431
|
+
chunk: { streamId, seq: seq++, data: part, createdAt: Date.now() },
|
|
2432
|
+
committed,
|
|
2433
|
+
failed
|
|
2434
|
+
});
|
|
2435
|
+
appending ??= appendQueued();
|
|
2436
|
+
}
|
|
2437
|
+
async function appendQueued() {
|
|
2438
|
+
while (queue.length > 0) {
|
|
2439
|
+
const batch = queue;
|
|
2440
|
+
queue = [];
|
|
2441
|
+
const chunks = batch.map(({ chunk }) => chunk);
|
|
2442
|
+
const append = Promise.try(() => store.appendChunks(chunks));
|
|
2443
|
+
appendSettled = append.then(
|
|
2444
|
+
() => void 0,
|
|
2445
|
+
() => void 0
|
|
2446
|
+
);
|
|
2447
|
+
try {
|
|
2448
|
+
await append;
|
|
2449
|
+
} catch (error) {
|
|
2450
|
+
failure = { error };
|
|
2451
|
+
const rejected = [...batch, ...queue];
|
|
2452
|
+
queue = [];
|
|
2453
|
+
for (const entry of rejected) entry.failed(error);
|
|
2454
|
+
break;
|
|
2455
2455
|
}
|
|
2456
|
+
failedByChunk ||= collectStreamFailures(chunks).length > 0;
|
|
2457
|
+
abortedByChunk ||= chunks.some(({ data }) => data.type === "abort");
|
|
2458
|
+
for (const entry of batch) entry.committed();
|
|
2456
2459
|
}
|
|
2460
|
+
appending = void 0;
|
|
2461
|
+
}
|
|
2462
|
+
async function settle() {
|
|
2463
|
+
while (appending) await appending;
|
|
2464
|
+
}
|
|
2465
|
+
async function flush() {
|
|
2466
|
+
await settle();
|
|
2467
|
+
if (failure) throw failure.error;
|
|
2457
2468
|
}
|
|
2458
2469
|
const wrappedWriter = {
|
|
2459
2470
|
onError: writer.onError,
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2471
|
+
write(part) {
|
|
2472
|
+
const { promise, resolve, reject } = Promise.withResolvers();
|
|
2473
|
+
enqueue(
|
|
2474
|
+
part,
|
|
2475
|
+
() => {
|
|
2476
|
+
writer.write(part);
|
|
2477
|
+
resolve();
|
|
2478
|
+
},
|
|
2479
|
+
reject
|
|
2480
|
+
);
|
|
2481
|
+
return promise;
|
|
2463
2482
|
},
|
|
2464
2483
|
merge(stream) {
|
|
2484
|
+
let cancelled = false;
|
|
2465
2485
|
const transform = new TransformStream({
|
|
2466
|
-
async transform(
|
|
2467
|
-
|
|
2468
|
-
|
|
2486
|
+
async transform(part, controller) {
|
|
2487
|
+
enqueue(
|
|
2488
|
+
part,
|
|
2489
|
+
() => {
|
|
2490
|
+
if (!cancelled) controller.enqueue(part);
|
|
2491
|
+
},
|
|
2492
|
+
(error) => {
|
|
2493
|
+
if (!cancelled) controller.error(error);
|
|
2494
|
+
}
|
|
2495
|
+
);
|
|
2496
|
+
while (queue.length >= MAX_QUEUED_CHUNKS && !failure) {
|
|
2497
|
+
await appendSettled;
|
|
2498
|
+
}
|
|
2499
|
+
},
|
|
2500
|
+
flush: () => flush(),
|
|
2501
|
+
cancel() {
|
|
2502
|
+
cancelled = true;
|
|
2469
2503
|
}
|
|
2470
2504
|
});
|
|
2471
2505
|
writer.merge(stream.pipeThrough(transform));
|
|
@@ -2484,7 +2518,7 @@ async function persistedWriter(options) {
|
|
|
2484
2518
|
);
|
|
2485
2519
|
},
|
|
2486
2520
|
async fail(error) {
|
|
2487
|
-
await
|
|
2521
|
+
await settle();
|
|
2488
2522
|
if (failedByChunk) return;
|
|
2489
2523
|
await store.updateStreamStatus(streamId, "failed", { error });
|
|
2490
2524
|
},
|