@agentunion/fastaun 0.5.13 → 0.5.15

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.
@@ -10,6 +10,10 @@ const V2_GROUP_STALE_BOOTSTRAP_CODE = -33054;
10
10
  const V2_PULL_DEFAULT_PAGE_LIMIT = 50;
11
11
  const V2_PULL_MAX_PAGE_LIMIT = 50;
12
12
  const V2_SENDER_IK_SYNC_FETCH_TIMEOUT_MS = 3_000;
13
+ function pullGateKeyForClient(client, method, params, fallback) {
14
+ const key = client._rpcPipeline?.pullGateKeyForCall?.(method, params);
15
+ return typeof key === 'string' && key ? key : fallback;
16
+ }
13
17
  function strictWindowSeq(value, field, positive = false) {
14
18
  if (!Number.isSafeInteger(value))
15
19
  throw new ValidationError(`${field} must be an integer`);
@@ -1145,7 +1149,10 @@ export class V2E2EECoordinator {
1145
1149
  const ns = client._aid ? `p2p:${client._aid}` : '';
1146
1150
  if (ns)
1147
1151
  client._delivery.syncStarted(ns);
1148
- const result = await client._callRawV2Rpc('message.v2.pull', { window_mode: 'tail', after_seq: afterSeq, limit, _rpc_foreground: true });
1152
+ const pullGateKey = pullGateKeyForClient(client, 'message.v2.pull', {
1153
+ window_mode: 'tail', after_seq: afterSeq, limit,
1154
+ }, `${ns}|tail|after=${afterSeq}|limit=${limit}`);
1155
+ const result = await client._callRawV2Rpc('message.v2.pull', { window_mode: 'tail', after_seq: afterSeq, limit, _rpc_foreground: true }, pullGateKey);
1149
1156
  const page = validateTailPage(result, afterSeq, limit);
1150
1157
  if (ns) {
1151
1158
  client._seqTracker.commitTailWindow(ns, {
@@ -1197,14 +1204,18 @@ export class V2E2EECoordinator {
1197
1204
  client._delivery.syncStarted(ns);
1198
1205
  if (opts?.windowMode === 'tail') {
1199
1206
  if (!opts.gateLocked) {
1200
- const key = `${ns}|tail|after=${afterSeq}|limit=${limit}`;
1207
+ const key = pullGateKeyForClient(client, 'message.v2.pull', {
1208
+ window_mode: 'tail', after_seq: afterSeq, limit,
1209
+ }, `${ns}|tail|after=${afterSeq}|limit=${limit}`);
1201
1210
  return (await client._runPullSerialized(key, () => this.pullV2Impl(afterSeq, limit, { ...opts, gateLocked: true }), false));
1202
1211
  }
1203
1212
  const result = await this.pullV2TailInternal({ window_mode: 'tail', after_seq: afterSeq, limit });
1204
1213
  return (Array.isArray(result.messages) ? result.messages : []);
1205
1214
  }
1206
1215
  if (ns && !opts?.gateLocked) {
1207
- const key = `${ns}|forward|after=${afterSeq}|force=${String(Boolean(opts?.force))}|limit=${limit}`;
1216
+ const key = pullGateKeyForClient(client, 'message.v2.pull', {
1217
+ after_seq: afterSeq, force: opts?.force === true, limit,
1218
+ }, `${ns}|forward|after=${afterSeq}|force=${String(Boolean(opts?.force))}|limit=${limit}`);
1208
1219
  return await client._runPullSerialized(key, async () => this.pullV2Impl(afterSeq, limit, {
1209
1220
  ...(opts ?? {}),
1210
1221
  gateLocked: true,
@@ -1214,7 +1225,9 @@ export class V2E2EECoordinator {
1214
1225
  const decrypted = [];
1215
1226
  let nextAfterSeq = opts?.force ? afterSeq : (afterSeq || (ns ? client._seqTracker.getContiguousSeq(ns) : 0));
1216
1227
  let pullGateKey = ns
1217
- ? `${ns}|forward|after=${afterSeq}|force=${String(Boolean(opts?.force))}|limit=${limit}`
1228
+ ? pullGateKeyForClient(client, 'message.v2.pull', {
1229
+ after_seq: afterSeq, force: opts?.force === true, limit,
1230
+ }, `${ns}|forward|after=${afterSeq}|force=${String(Boolean(opts?.force))}|limit=${limit}`)
1218
1231
  : '';
1219
1232
  const deferredServerCursor = ns ? this.pendingForwardCursor(ns, ns ? client._seqTracker.getContiguousSeq(ns) : 0) : 0;
1220
1233
  const deferredForwardAck = ns ? this.pendingForwardAck(ns, client._seqTracker.getContiguousSeq(ns)) : 0;
@@ -1234,7 +1247,7 @@ export class V2E2EECoordinator {
1234
1247
  limit,
1235
1248
  ...(opts?.force ? { force: true } : {}),
1236
1249
  ...(ackUpToSeq > 0 ? { ack_up_to_seq: ackUpToSeq } : {}),
1237
- });
1250
+ }, pullGateKey);
1238
1251
  if (ackUpToSeq > 0) {
1239
1252
  const actualAckSeq = client._delivery.resolveP2PPullAckSeq(result, ackUpToSeq);
1240
1253
  if (actualAckSeq >= ackUpToSeq) {
@@ -1470,7 +1483,9 @@ export class V2E2EECoordinator {
1470
1483
  if (!shouldContinue)
1471
1484
  break;
1472
1485
  if (pullGateKey && opts?.gateLocked && client._rpcPipeline?.yieldPullGate) {
1473
- const nextKey = `${ns}|forward|after=${nextAfter}|force=${String(Boolean(opts?.force))}|limit=${limit}`;
1486
+ const nextKey = pullGateKeyForClient(client, 'message.v2.pull', {
1487
+ after_seq: nextAfter, force: opts?.force === true, limit,
1488
+ }, `${ns}|forward|after=${nextAfter}|force=${String(Boolean(opts?.force))}|limit=${limit}`);
1474
1489
  await client._rpcPipeline.yieldPullGate(pullGateKey, nextKey, true);
1475
1490
  pullGateKey = nextKey;
1476
1491
  }
@@ -1793,21 +1808,30 @@ export class V2E2EECoordinator {
1793
1808
  const afterSeq = strictWindowSeq(params.after_seq ?? 0, 'after_seq');
1794
1809
  const limit = strictWindowLimit(params.limit ?? V2_PULL_DEFAULT_PAGE_LIMIT);
1795
1810
  const ns = `group:${groupId}`;
1796
- const cursorParams = isJsonObject(params._group_cursor_params)
1797
- ? params._group_cursor_params : params;
1811
+ const explicitCursorParams = isJsonObject(params._group_cursor_params)
1812
+ ? params._group_cursor_params : {};
1813
+ const cursorParams = Object.keys(explicitCursorParams).length > 0 ? explicitCursorParams : params;
1798
1814
  const requestDeviceId = String(cursorParams.device_id ?? '').trim();
1799
1815
  const requestSlotId = String(cursorParams.slot_id ?? '').trim();
1800
1816
  const ownsCursor = (!requestDeviceId || requestDeviceId === String(client._deviceId ?? ''))
1801
1817
  && (!requestSlotId || requestSlotId === String(client._slotId ?? ''));
1802
1818
  if (ownsCursor)
1803
1819
  client._delivery.syncStarted(ns);
1820
+ const pullGateKey = pullGateKeyForClient(client, 'group.v2.pull', {
1821
+ group_id: groupId,
1822
+ window_mode: 'tail',
1823
+ after_seq: afterSeq,
1824
+ limit,
1825
+ _group_cursor_params: explicitCursorParams,
1826
+ }, `${ns}|tail|after=${afterSeq}|limit=${limit}`);
1804
1827
  const result = await client._callRawV2Rpc('group.v2.pull', withExplicitGroupAid({
1805
1828
  group_id: groupId,
1806
1829
  window_mode: 'tail',
1807
1830
  after_seq: afterSeq,
1808
1831
  limit,
1832
+ _group_cursor_params: explicitCursorParams,
1809
1833
  _rpc_foreground: true,
1810
- }, groupAid));
1834
+ }, groupAid), pullGateKey);
1811
1835
  const resultAid = String(result.group_aid ?? result.groupAid ?? '').trim();
1812
1836
  if (resultAid)
1813
1837
  groupAid = resultAid;
@@ -1884,7 +1908,10 @@ export class V2E2EECoordinator {
1884
1908
  client._delivery.syncStarted(ns);
1885
1909
  if (opts?.windowMode === 'tail') {
1886
1910
  if (!opts.gateLocked) {
1887
- const key = `${ns}|tail|after=${afterSeq}|limit=${limit}`;
1911
+ const key = pullGateKeyForClient(client, 'group.v2.pull', {
1912
+ group_id: gid, window_mode: 'tail', after_seq: afterSeq, limit,
1913
+ _group_cursor_params: opts?.cursorParams,
1914
+ }, `${ns}|tail|after=${afterSeq}|limit=${limit}`);
1888
1915
  return (await client._runPullSerialized(key, () => this.pullGroupV2Impl(gid, afterSeq, limit, {
1889
1916
  ...opts,
1890
1917
  gateLocked: true,
@@ -1892,6 +1919,7 @@ export class V2E2EECoordinator {
1892
1919
  }
1893
1920
  const result = await this.pullGroupV2TailInternal({
1894
1921
  ...(opts?.cursorParams ?? {}),
1922
+ _group_cursor_params: opts?.cursorParams,
1895
1923
  group_id: String(opts.wireGroupId ?? gid),
1896
1924
  group_aid: groupAid || undefined,
1897
1925
  window_mode: 'tail',
@@ -1901,7 +1929,10 @@ export class V2E2EECoordinator {
1901
1929
  return (Array.isArray(result.messages) ? result.messages : []);
1902
1930
  }
1903
1931
  if (!opts?.gateLocked) {
1904
- const key = `${ns}|forward|after=${afterSeq}|force=${opts?.force === true}|limit=${limit}`;
1932
+ const key = pullGateKeyForClient(client, 'group.v2.pull', {
1933
+ group_id: gid, after_seq: afterSeq, force: opts?.force === true, limit,
1934
+ _group_cursor_params: opts?.cursorParams,
1935
+ }, `${ns}|forward|after=${afterSeq}|force=${opts?.force === true}|limit=${limit}`);
1905
1936
  return await client._runPullSerialized(key, async () => this.pullGroupV2Impl(gid, afterSeq, limit, {
1906
1937
  ...(opts ?? {}),
1907
1938
  gateLocked: true,
@@ -1912,9 +1943,10 @@ export class V2E2EECoordinator {
1912
1943
  const wireGroupId = String(opts?.wireGroupId ?? groupId ?? '').trim() || gid;
1913
1944
  const cursorParams = opts?.cursorParams ?? {};
1914
1945
  const ownsCursor = opts?.ownsCursor !== false;
1915
- let pullGateKey = ownsCursor
1916
- ? `${ns}|forward|after=${afterSeq}|force=${String(Boolean(opts?.force))}|limit=${limit}`
1917
- : '';
1946
+ let pullGateKey = pullGateKeyForClient(client, 'group.v2.pull', {
1947
+ group_id: gid, after_seq: afterSeq, force: opts?.force === true, limit,
1948
+ _group_cursor_params: cursorParams,
1949
+ }, `${ns}|forward|after=${afterSeq}|force=${String(Boolean(opts?.force))}|limit=${limit}`);
1918
1950
  let nextAfterSeq = (opts?.explicitAfterSeq || opts?.force)
1919
1951
  ? afterSeq
1920
1952
  : (afterSeq || client._seqTracker.getContiguousSeq(ns));
@@ -1940,7 +1972,7 @@ export class V2E2EECoordinator {
1940
1972
  ...cursorParams,
1941
1973
  ...(opts?.force ? { force: true } : {}),
1942
1974
  ...(ackUpToSeq > 0 ? { ack_up_to_seq: ackUpToSeq } : {}),
1943
- }, groupAid));
1975
+ }, groupAid), pullGateKey);
1944
1976
  if (ackUpToSeq > 0) {
1945
1977
  const actualAckSeq = client._delivery.resolveGroupPullAckSeq(result, ackUpToSeq);
1946
1978
  if (actualAckSeq >= ackUpToSeq) {
@@ -2214,7 +2246,10 @@ export class V2E2EECoordinator {
2214
2246
  if (!shouldContinue)
2215
2247
  break;
2216
2248
  if (pullGateKey && opts?.gateLocked && client._rpcPipeline?.yieldPullGate) {
2217
- const nextKey = `${ns}|forward|after=${nextAfter}|force=${String(Boolean(opts?.force))}|limit=${limit}`;
2249
+ const nextKey = pullGateKeyForClient(client, 'group.v2.pull', {
2250
+ group_id: gid, after_seq: nextAfter, force: opts?.force === true, limit,
2251
+ _group_cursor_params: cursorParams,
2252
+ }, `${ns}|forward|after=${nextAfter}|force=${String(Boolean(opts?.force))}|limit=${limit}`);
2218
2253
  await client._rpcPipeline.yieldPullGate(pullGateKey, nextKey, true);
2219
2254
  pullGateKey = nextKey;
2220
2255
  }