@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 CHANGED
@@ -2617,13 +2617,12 @@ var InMemoryChunkBuffer = class extends ChunkBuffer {
2617
2617
  */
2618
2618
  getOrCreateBuffer(threadId) {
2619
2619
  let buffer = this.getBufferIfValid(threadId);
2620
- 4;
2621
2620
  if (!buffer) {
2622
2621
  const now = Date.now();
2623
2622
  buffer = {
2624
2623
  threadId,
2625
2624
  chunks$: new import_rxjs.ReplaySubject(
2626
- this.config.maxChunks ?? 1e4
2625
+ this.config.maxChunks ?? 1e5
2627
2626
  ),
2628
2627
  status: "active" /* ACTIVE */,
2629
2628
  createdAt: now,
@@ -2635,7 +2634,7 @@ var InMemoryChunkBuffer = class extends ChunkBuffer {
2635
2634
  if (buffer.status !== "active" /* ACTIVE */) {
2636
2635
  buffer.status = "active" /* ACTIVE */;
2637
2636
  buffer.chunks$ = new import_rxjs.ReplaySubject(
2638
- this.config.maxChunks ?? 1e4
2637
+ this.config.maxChunks ?? 1e5
2639
2638
  );
2640
2639
  buffer.updatedAt = Date.now();
2641
2640
  buffer.expiresAt = Date.now() + this.config.ttl;
@@ -2739,7 +2738,8 @@ var InMemoryChunkBuffer = class extends ChunkBuffer {
2739
2738
  let resolveNext = null;
2740
2739
  let errorNext = null;
2741
2740
  let isCompleted = false;
2742
- const subscription = buffer.chunks$.subscribe({
2741
+ let pendingError = null;
2742
+ const subscription = buffer.chunks$.pipe((0, import_rxjs.observeOn)(import_rxjs.asyncScheduler)).subscribe({
2743
2743
  next: (chunk) => {
2744
2744
  queue.push(chunk);
2745
2745
  if (resolveNext) {
@@ -2749,10 +2749,15 @@ var InMemoryChunkBuffer = class extends ChunkBuffer {
2749
2749
  }
2750
2750
  },
2751
2751
  error: (err) => {
2752
+ pendingError = err;
2752
2753
  if (errorNext) {
2753
2754
  const reject = errorNext;
2754
2755
  errorNext = null;
2755
2756
  reject(err);
2757
+ } else if (resolveNext) {
2758
+ const resolve = resolveNext;
2759
+ resolveNext = null;
2760
+ resolve();
2756
2761
  }
2757
2762
  },
2758
2763
  complete: () => {
@@ -2764,8 +2769,12 @@ var InMemoryChunkBuffer = class extends ChunkBuffer {
2764
2769
  }
2765
2770
  }
2766
2771
  });
2772
+ let startYieldChunk = false;
2767
2773
  try {
2768
2774
  while (true) {
2775
+ if (pendingError) {
2776
+ throw pendingError;
2777
+ }
2769
2778
  if (queue.length === 0) {
2770
2779
  if (isCompleted) break;
2771
2780
  await new Promise((resolve, reject) => {
@@ -2773,16 +2782,18 @@ var InMemoryChunkBuffer = class extends ChunkBuffer {
2773
2782
  errorNext = reject;
2774
2783
  });
2775
2784
  }
2785
+ if (pendingError) {
2786
+ throw pendingError;
2787
+ }
2776
2788
  while (queue.length > 0) {
2777
2789
  const chunk = queue.shift();
2778
2790
  if (!chunk) continue;
2779
2791
  if (chunk.data?.id === messageId) {
2792
+ startYieldChunk = true;
2780
2793
  accumulatedContent += chunk.data?.content || "";
2781
2794
  }
2782
- if (accumulatedContent.length > knownContent.length) {
2783
- if (accumulatedContent.startsWith(knownContent)) {
2784
- yield chunk;
2785
- }
2795
+ if (startYieldChunk) {
2796
+ yield chunk;
2786
2797
  }
2787
2798
  }
2788
2799
  }