@axiom-lattice/core 2.1.0 → 2.1.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 +19 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -2524,7 +2524,11 @@ var ThreadStatus = /* @__PURE__ */ ((ThreadStatus2) => {
|
|
|
2524
2524
|
})(ThreadStatus || {});
|
|
2525
2525
|
|
|
2526
2526
|
// src/chunk_buffer_lattice/InMemoryChunkBuffer.ts
|
|
2527
|
-
import {
|
|
2527
|
+
import {
|
|
2528
|
+
ReplaySubject,
|
|
2529
|
+
observeOn,
|
|
2530
|
+
asyncScheduler
|
|
2531
|
+
} from "rxjs";
|
|
2528
2532
|
var InMemoryChunkBuffer = class extends ChunkBuffer {
|
|
2529
2533
|
constructor(config) {
|
|
2530
2534
|
super();
|
|
@@ -2582,13 +2586,12 @@ var InMemoryChunkBuffer = class extends ChunkBuffer {
|
|
|
2582
2586
|
*/
|
|
2583
2587
|
getOrCreateBuffer(threadId) {
|
|
2584
2588
|
let buffer = this.getBufferIfValid(threadId);
|
|
2585
|
-
4;
|
|
2586
2589
|
if (!buffer) {
|
|
2587
2590
|
const now = Date.now();
|
|
2588
2591
|
buffer = {
|
|
2589
2592
|
threadId,
|
|
2590
2593
|
chunks$: new ReplaySubject(
|
|
2591
|
-
this.config.maxChunks ??
|
|
2594
|
+
this.config.maxChunks ?? 1e5
|
|
2592
2595
|
),
|
|
2593
2596
|
status: "active" /* ACTIVE */,
|
|
2594
2597
|
createdAt: now,
|
|
@@ -2600,7 +2603,7 @@ var InMemoryChunkBuffer = class extends ChunkBuffer {
|
|
|
2600
2603
|
if (buffer.status !== "active" /* ACTIVE */) {
|
|
2601
2604
|
buffer.status = "active" /* ACTIVE */;
|
|
2602
2605
|
buffer.chunks$ = new ReplaySubject(
|
|
2603
|
-
this.config.maxChunks ??
|
|
2606
|
+
this.config.maxChunks ?? 1e5
|
|
2604
2607
|
);
|
|
2605
2608
|
buffer.updatedAt = Date.now();
|
|
2606
2609
|
buffer.expiresAt = Date.now() + this.config.ttl;
|
|
@@ -2704,7 +2707,8 @@ var InMemoryChunkBuffer = class extends ChunkBuffer {
|
|
|
2704
2707
|
let resolveNext = null;
|
|
2705
2708
|
let errorNext = null;
|
|
2706
2709
|
let isCompleted = false;
|
|
2707
|
-
|
|
2710
|
+
let pendingError = null;
|
|
2711
|
+
const subscription = buffer.chunks$.pipe(observeOn(asyncScheduler)).subscribe({
|
|
2708
2712
|
next: (chunk) => {
|
|
2709
2713
|
queue.push(chunk);
|
|
2710
2714
|
if (resolveNext) {
|
|
@@ -2714,10 +2718,15 @@ var InMemoryChunkBuffer = class extends ChunkBuffer {
|
|
|
2714
2718
|
}
|
|
2715
2719
|
},
|
|
2716
2720
|
error: (err) => {
|
|
2721
|
+
pendingError = err;
|
|
2717
2722
|
if (errorNext) {
|
|
2718
2723
|
const reject = errorNext;
|
|
2719
2724
|
errorNext = null;
|
|
2720
2725
|
reject(err);
|
|
2726
|
+
} else if (resolveNext) {
|
|
2727
|
+
const resolve = resolveNext;
|
|
2728
|
+
resolveNext = null;
|
|
2729
|
+
resolve();
|
|
2721
2730
|
}
|
|
2722
2731
|
},
|
|
2723
2732
|
complete: () => {
|
|
@@ -2729,8 +2738,12 @@ var InMemoryChunkBuffer = class extends ChunkBuffer {
|
|
|
2729
2738
|
}
|
|
2730
2739
|
}
|
|
2731
2740
|
});
|
|
2741
|
+
let startYieldChunk = false;
|
|
2732
2742
|
try {
|
|
2733
2743
|
while (true) {
|
|
2744
|
+
if (pendingError) {
|
|
2745
|
+
throw pendingError;
|
|
2746
|
+
}
|
|
2734
2747
|
if (queue.length === 0) {
|
|
2735
2748
|
if (isCompleted) break;
|
|
2736
2749
|
await new Promise((resolve, reject) => {
|
|
@@ -2738,16 +2751,18 @@ var InMemoryChunkBuffer = class extends ChunkBuffer {
|
|
|
2738
2751
|
errorNext = reject;
|
|
2739
2752
|
});
|
|
2740
2753
|
}
|
|
2754
|
+
if (pendingError) {
|
|
2755
|
+
throw pendingError;
|
|
2756
|
+
}
|
|
2741
2757
|
while (queue.length > 0) {
|
|
2742
2758
|
const chunk = queue.shift();
|
|
2743
2759
|
if (!chunk) continue;
|
|
2744
2760
|
if (chunk.data?.id === messageId) {
|
|
2761
|
+
startYieldChunk = true;
|
|
2745
2762
|
accumulatedContent += chunk.data?.content || "";
|
|
2746
2763
|
}
|
|
2747
|
-
if (
|
|
2748
|
-
|
|
2749
|
-
yield chunk;
|
|
2750
|
-
}
|
|
2764
|
+
if (startYieldChunk) {
|
|
2765
|
+
yield chunk;
|
|
2751
2766
|
}
|
|
2752
2767
|
}
|
|
2753
2768
|
}
|