@agentunion/fastaun-browser 0.5.12 → 0.5.14

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.
@@ -165,20 +165,19 @@ export class MessageDeliveryEngine {
165
165
  isInlineGenerationCurrent(generation) {
166
166
  return generation === this.inlineGeneration;
167
167
  }
168
- isPullOperationCurrent() {
169
- const client = this.runtime.client;
170
- const generation = client._pullOperationGeneration;
171
- if (generation === undefined)
172
- return true;
173
- const pipeline = client._rpcPipeline;
174
- return typeof pipeline?.isPullGenerationCurrent === 'function'
175
- ? pipeline.isPullGenerationCurrent(generation)
168
+ isPullOperationCurrent(namespace = '') {
169
+ const pipeline = this.runtime.client._rpcPipeline;
170
+ return typeof pipeline?.isPullNamespaceCurrent === 'function'
171
+ ? pipeline.isPullNamespaceCurrent(namespace)
176
172
  : true;
177
173
  }
178
- ensurePullOperationCurrent() {
179
- if (!this.isPullOperationCurrent())
174
+ ensurePullOperationCurrent(namespace = '') {
175
+ if (!this.isPullOperationCurrent(namespace))
180
176
  throw new Error('pull invalidated');
181
177
  }
178
+ isPullScopedSource(source) {
179
+ return source === 'pull';
180
+ }
182
181
  captureInlineGeneration() {
183
182
  return this.inlineGeneration;
184
183
  }
@@ -899,7 +898,7 @@ export class MessageDeliveryEngine {
899
898
  }
900
899
  async confirmPlainForwardAck(ns, method, ackSeq, groupId = '') {
901
900
  const client = this.runtime.client;
902
- this.ensurePullOperationCurrent();
901
+ this.ensurePullOperationCurrent(ns);
903
902
  const coordinator = this.forwardCoordinator();
904
903
  const generation = this.captureInlineGeneration();
905
904
  coordinator.recordForwardAck(ns, ackSeq);
@@ -918,7 +917,7 @@ export class MessageDeliveryEngine {
918
917
  _rpc_background: true,
919
918
  };
920
919
  const result = await client._rpcPipeline.rawCall(method, params, { background: true });
921
- this.ensurePullOperationCurrent();
920
+ this.ensurePullOperationCurrent(ns);
922
921
  const actualAckSeq = this.resolveForwardAckSeq(result, ackSeq);
923
922
  if (actualAckSeq < ackSeq) {
924
923
  throw new Error(`${method} server ACK watermark ${actualAckSeq} is below requested ${ackSeq}`);
@@ -936,7 +935,7 @@ export class MessageDeliveryEngine {
936
935
  throw new Error(`${method} response must be an object`);
937
936
  }
938
937
  const client = this.runtime.client;
939
- this.ensurePullOperationCurrent();
938
+ this.ensurePullOperationCurrent(ns);
940
939
  const response = result;
941
940
  const messages = deduplicatePlainForwardPageMessages(response.messages, afterSeq);
942
941
  const coordinator = this.forwardCoordinator();
@@ -967,20 +966,20 @@ export class MessageDeliveryEngine {
967
966
  let committed = false;
968
967
  try {
969
968
  for (const rawMessage of messages) {
970
- this.ensurePullOperationCurrent();
969
+ this.ensurePullOperationCurrent(ns);
971
970
  const seq = positiveSafeSequenceHint(rawMessage.seq);
972
971
  if (method === 'message.pull') {
973
972
  const appEvent = p2pAppEventFromPlainPullMessage(rawMessage);
974
973
  if (await this.publishPulledMessage(appEvent.event, ns, seq, appEvent.payload, false)) {
975
974
  publishedCount += 1;
976
975
  }
977
- this.ensurePullOperationCurrent();
976
+ this.ensurePullOperationCurrent(ns);
978
977
  continue;
979
978
  }
980
979
  const message = normalizeGroupMentionMode(rawMessage);
981
980
  if (this.recallEventFromGroupMessage(message)) {
982
981
  if (await this.publishGroupRecallTombstone(groupId, seq, message, 'pull')) {
983
- this.ensurePullOperationCurrent();
982
+ this.ensurePullOperationCurrent(ns);
984
983
  this.markPublishedSeq(ns, seq);
985
984
  publishedCount += 1;
986
985
  }
@@ -989,11 +988,11 @@ export class MessageDeliveryEngine {
989
988
  this.markPublishedSeq(ns, seq);
990
989
  }
991
990
  else if (await this.publishPulledMessage('group.message_created', ns, seq, message, false)) {
992
- this.ensurePullOperationCurrent();
991
+ this.ensurePullOperationCurrent(ns);
993
992
  publishedCount += 1;
994
993
  }
995
994
  }
996
- this.ensurePullOperationCurrent();
995
+ this.ensurePullOperationCurrent(ns);
997
996
  const contiguousSeq = Number.isSafeInteger(result.contiguous_seq)
998
997
  ? result.contiguous_seq
999
998
  : undefined;
@@ -1006,21 +1005,21 @@ export class MessageDeliveryEngine {
1006
1005
  client._seqTracker.forceContiguousSeq(ns, commitTarget);
1007
1006
  }
1008
1007
  if (client._seqTracker.getContiguousSeq(ns) !== pageContigBefore) {
1009
- this.ensurePullOperationCurrent();
1008
+ this.ensurePullOperationCurrent(ns);
1010
1009
  await this.drainOrderedMessages(ns, undefined, false, false);
1011
- this.ensurePullOperationCurrent();
1010
+ this.ensurePullOperationCurrent(ns);
1012
1011
  await client._commitSeqTrackerState(ns);
1013
1012
  }
1014
1013
  committed = true;
1015
1014
  }
1016
1015
  catch (exc) {
1017
- if (this.isPullOperationCurrent() && !committed && typeof client._seqTracker.restoreNamespaceSnapshot === 'function') {
1016
+ if (this.isPullOperationCurrent(ns) && !committed && typeof client._seqTracker.restoreNamespaceSnapshot === 'function') {
1018
1017
  client._seqTracker.restoreNamespaceSnapshot(ns, pageTrackerSnapshot);
1019
1018
  this.dropSeqTrackerPending(ns);
1020
1019
  }
1021
1020
  throw exc;
1022
1021
  }
1023
- this.ensurePullOperationCurrent();
1022
+ this.ensurePullOperationCurrent(ns);
1024
1023
  const committedAck = client._seqTracker.getContiguousSeq(ns);
1025
1024
  if (deferredServerCursor > 0 && committedAck >= deferredServerCursor) {
1026
1025
  coordinator.clearForwardCursor(ns, committedAck);
@@ -1051,7 +1050,7 @@ export class MessageDeliveryEngine {
1051
1050
  if (clampedAckSeq < pendingAckSeq) {
1052
1051
  throw new Error(`${ackMethod} cannot confirm pending Forward watermark ${pendingAckSeq}`);
1053
1052
  }
1054
- this.ensurePullOperationCurrent();
1053
+ this.ensurePullOperationCurrent(ns);
1055
1054
  await this.confirmPlainForwardAck(ns, ackMethod, pendingAckSeq, groupId);
1056
1055
  }
1057
1056
  const remaining = typeof response.remaining === 'number' && Number.isSafeInteger(response.remaining) && response.remaining >= 0
@@ -1078,12 +1077,19 @@ export class MessageDeliveryEngine {
1078
1077
  }
1079
1078
  async publishOrderedQueueItem(ns, event, seq, payload, pullResponse = false, source = 'push', batch) {
1080
1079
  const client = this.runtime.client;
1080
+ const pullScoped = this.isPullScopedSource(source);
1081
+ if (pullScoped)
1082
+ this.ensurePullOperationCurrent(ns);
1081
1083
  if (event === 'group.changed' && this.isGroupEventNamespace(ns)) {
1082
1084
  await this.publishOrderedGroupChanged(payload, source);
1085
+ if (pullScoped)
1086
+ this.ensurePullOperationCurrent(ns);
1083
1087
  return;
1084
1088
  }
1085
1089
  if (event === 'message.recalled') {
1086
1090
  await this.publishMessageRecallTombstone(seq, payload, source);
1091
+ if (pullScoped)
1092
+ this.ensurePullOperationCurrent(ns);
1087
1093
  return;
1088
1094
  }
1089
1095
  if (pullResponse) {
@@ -1091,6 +1097,8 @@ export class MessageDeliveryEngine {
1091
1097
  return;
1092
1098
  }
1093
1099
  await client._publishAppEvent(event, payload, source, ns, batch);
1100
+ if (pullScoped)
1101
+ this.ensurePullOperationCurrent(ns);
1094
1102
  }
1095
1103
  async publishOrderedGroupChanged(payload, source = 'ordered') {
1096
1104
  const client = this.runtime.client;
@@ -3623,7 +3631,9 @@ export class MessageDeliveryEngine {
3623
3631
  }
3624
3632
  async drainOrderedMessages(ns, beforeSeq, pullResponse = false, persist = true, batch, source = 'pull') {
3625
3633
  const client = this.runtime.client;
3626
- this.ensurePullOperationCurrent();
3634
+ const pullScoped = this.isPullScopedSource(source);
3635
+ if (pullScoped)
3636
+ this.ensurePullOperationCurrent(ns);
3627
3637
  const queue = client._pendingOrderedMsgs.get(ns);
3628
3638
  if (!queue || queue.size === 0)
3629
3639
  return;
@@ -3635,7 +3645,8 @@ export class MessageDeliveryEngine {
3635
3645
  const drainBatches = new Map();
3636
3646
  try {
3637
3647
  for (const seq of ready) {
3638
- this.ensurePullOperationCurrent();
3648
+ if (pullScoped)
3649
+ this.ensurePullOperationCurrent(ns);
3639
3650
  const item = queue.get(seq);
3640
3651
  queue.delete(seq);
3641
3652
  if (!item || client._pushedSeqs.get(ns)?.has(seq))
@@ -3651,7 +3662,8 @@ export class MessageDeliveryEngine {
3651
3662
  }
3652
3663
  }
3653
3664
  await this.publishOrderedQueueItem(ns, item.event, seq, item.payload, pullResponse, itemSource, itemBatch);
3654
- this.ensurePullOperationCurrent();
3665
+ if (pullScoped)
3666
+ this.ensurePullOperationCurrent(ns);
3655
3667
  this.markPublishedSeq(ns, seq);
3656
3668
  delivered = true;
3657
3669
  }
@@ -3664,7 +3676,8 @@ export class MessageDeliveryEngine {
3664
3676
  if (queue.size === 0) {
3665
3677
  client._pendingOrderedMsgs.delete(ns);
3666
3678
  if (delivered && persist) {
3667
- this.ensurePullOperationCurrent();
3679
+ if (pullScoped)
3680
+ this.ensurePullOperationCurrent(ns);
3668
3681
  await this.saveSeqTrackerState();
3669
3682
  }
3670
3683
  }
@@ -3714,17 +3727,21 @@ export class MessageDeliveryEngine {
3714
3727
  const client = this.runtime.client;
3715
3728
  const ownsBatch = !operationBatch && (source === 'push' || source === 'inline_push');
3716
3729
  const batch = operationBatch ?? (ownsBatch ? this.createDeliveryChangeBatch(source) : undefined);
3730
+ const pullScoped = this.isPullScopedSource(source);
3717
3731
  try {
3718
- this.ensurePullOperationCurrent();
3732
+ if (pullScoped)
3733
+ this.ensurePullOperationCurrent(ns);
3719
3734
  const seqNum = Number(seq);
3720
3735
  if (!Number.isFinite(seqNum) || !Number.isInteger(seqNum) || seqNum <= 0 || !ns) {
3721
3736
  if (event === 'message.recalled') {
3722
3737
  const published = await client._withPullResponseProcessing(ns, () => this.publishMessageRecallTombstone(seq, payload, source));
3723
- this.ensurePullOperationCurrent();
3738
+ if (pullScoped)
3739
+ this.ensurePullOperationCurrent(ns);
3724
3740
  return published;
3725
3741
  }
3726
3742
  await client._withPullResponseProcessing(ns, () => client._publishAppEvent(event, payload, source, ns, batch));
3727
- this.ensurePullOperationCurrent();
3743
+ if (pullScoped)
3744
+ this.ensurePullOperationCurrent(ns);
3728
3745
  return true;
3729
3746
  }
3730
3747
  const queue = client._pendingOrderedMsgs.get(ns);
@@ -3735,18 +3752,21 @@ export class MessageDeliveryEngine {
3735
3752
  return false;
3736
3753
  }
3737
3754
  await this.drainOrderedMessages(ns, seqNum, false, persist, batch, source);
3738
- this.ensurePullOperationCurrent();
3755
+ if (pullScoped)
3756
+ this.ensurePullOperationCurrent(ns);
3739
3757
  queue?.delete(seqNum);
3740
3758
  if (queue && queue.size === 0)
3741
3759
  client._pendingOrderedMsgs.delete(ns);
3742
3760
  if (event === 'message.recalled') {
3743
3761
  const published = await client._withPullResponseProcessing(ns, () => this.publishMessageRecallTombstone(seqNum, payload, source));
3744
- this.ensurePullOperationCurrent();
3762
+ if (pullScoped)
3763
+ this.ensurePullOperationCurrent(ns);
3745
3764
  this.markPublishedSeq(ns, seqNum);
3746
3765
  return published;
3747
3766
  }
3748
3767
  await client._withPullResponseProcessing(ns, () => client._publishAppEvent(event, payload, source, ns, batch));
3749
- this.ensurePullOperationCurrent();
3768
+ if (pullScoped)
3769
+ this.ensurePullOperationCurrent(ns);
3750
3770
  this.markPublishedSeq(ns, seqNum);
3751
3771
  return true;
3752
3772
  }