@agentunion/fastaun 0.5.9 → 0.5.10

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.
Files changed (38) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/_packed_docs/CHANGELOG.md +32 -0
  3. package/_packed_docs/sdk/04-/350/277/236/346/216/245/344/270/216/350/256/244/350/257/201.md +6 -5
  4. package/_packed_docs/sdk/06-API/346/211/213/345/206/214.md +43 -8
  5. package/_packed_docs/sdk/09-group-rpc-manual.md +18 -3
  6. package/_packed_docs/sdk/09-message-rpc-manual.md +34 -10
  7. package/dist/agent-md.js +5 -1
  8. package/dist/agent-md.js.map +1 -1
  9. package/dist/auth.d.ts +2 -1
  10. package/dist/auth.js +30 -44
  11. package/dist/auth.js.map +1 -1
  12. package/dist/client/delivery.d.ts +21 -5
  13. package/dist/client/delivery.js +236 -52
  14. package/dist/client/delivery.js.map +1 -1
  15. package/dist/client/group-state.js +6 -6
  16. package/dist/client/group-state.js.map +1 -1
  17. package/dist/client/lifecycle.js +5 -14
  18. package/dist/client/lifecycle.js.map +1 -1
  19. package/dist/client/rpc-pipeline.d.ts +4 -0
  20. package/dist/client/rpc-pipeline.js +33 -1
  21. package/dist/client/rpc-pipeline.js.map +1 -1
  22. package/dist/client/v2-e2ee.d.ts +1 -0
  23. package/dist/client/v2-e2ee.js +43 -17
  24. package/dist/client/v2-e2ee.js.map +1 -1
  25. package/dist/client.js +21 -27
  26. package/dist/client.js.map +1 -1
  27. package/dist/events.d.ts +23 -8
  28. package/dist/events.js +120 -26
  29. package/dist/events.js.map +1 -1
  30. package/dist/register-flow.js +15 -111
  31. package/dist/register-flow.js.map +1 -1
  32. package/dist/transport.d.ts +32 -3
  33. package/dist/transport.js +758 -33
  34. package/dist/transport.js.map +1 -1
  35. package/dist/version.d.ts +1 -1
  36. package/dist/version.js +1 -1
  37. package/dist/version.js.map +1 -1
  38. package/package.json +1 -1
package/dist/client.js CHANGED
@@ -688,7 +688,7 @@ export class AUNClient {
688
688
  this._dispatcher.subscribe('_raw.group.state_committed', (data) => this._onGroupStateCommitted(data));
689
689
  // 其他事件直接透传
690
690
  for (const evt of ['message.ack', 'storage.object_changed', 'stream/created', 'stream/closed']) {
691
- this._dispatcher.subscribe(`_raw.${evt}`, (data) => this._dispatcher.publish(evt, data));
691
+ this._dispatcher.subscribe(`_raw.${evt}`, (data) => this._dispatcher.enqueue(evt, data));
692
692
  }
693
693
  // 服务端主动断开通知:记录日志并标记不重连
694
694
  this._dispatcher.subscribe('_raw.gateway.disconnect', (data) => this._onGatewayDisconnect(data));
@@ -1943,11 +1943,11 @@ export class AUNClient {
1943
1943
  }
1944
1944
  return true;
1945
1945
  }
1946
- async _drainOrderedMessages(ns, beforeSeq, pullResponse = false, persist = true) {
1947
- return this._delivery.drainOrderedMessages(ns, beforeSeq, pullResponse, persist);
1946
+ async _drainOrderedMessages(ns, beforeSeq, pullResponse = false, persist = true, source = 'push') {
1947
+ return this._delivery.drainOrderedMessages(ns, beforeSeq, pullResponse, persist, source);
1948
1948
  }
1949
- async _publishOrderedMessage(event, ns, seq, payload) {
1950
- return this._delivery.publishOrderedMessage(event, ns, seq, payload);
1949
+ async _publishOrderedMessage(event, ns, seq, payload, source = 'push') {
1950
+ return this._delivery.publishOrderedMessage(event, ns, seq, payload, source);
1951
1951
  }
1952
1952
  async _publishPulledMessage(event, ns, seq, payload, persist = true) {
1953
1953
  return this._delivery.publishPulledMessage(event, ns, seq, payload, persist);
@@ -1992,7 +1992,7 @@ export class AUNClient {
1992
1992
  }
1993
1993
  else {
1994
1994
  // data 非对象也透传给用户(兼容旧版)
1995
- await this._dispatcher.publish('group.changed', data);
1995
+ this._dispatcher.enqueue('group.changed', data);
1996
1996
  }
1997
1997
  this._clientLog.debug(`_onRawGroupChanged exit: elapsed=${Date.now() - tStart}ms`);
1998
1998
  }
@@ -2056,7 +2056,7 @@ export class AUNClient {
2056
2056
  certPem = await this._fetchPeerCert(sigAid, expectedFP || undefined);
2057
2057
  }
2058
2058
  catch {
2059
- this._dispatcher.publish('signature_pending', { aid: sigAid, method }).catch(() => { });
2059
+ this._dispatcher.enqueue('signature_pending', { aid: sigAid, method });
2060
2060
  return false;
2061
2061
  }
2062
2062
  }
@@ -2076,19 +2076,19 @@ export class AUNClient {
2076
2076
  if (!ok) {
2077
2077
  this._clientLog.warn(`group event signature verification failed aid=${sigAid} method=${method}`);
2078
2078
  // P1-16: 签名失败统一发布事件
2079
- this._dispatcher.publish('signature.verification_failed', {
2079
+ this._dispatcher.enqueue('signature.verification_failed', {
2080
2080
  aid: sigAid, method, error: 'ECDSA verification failed',
2081
- }).catch(() => { });
2081
+ });
2082
2082
  }
2083
2083
  return ok;
2084
2084
  }
2085
2085
  catch (exc) {
2086
2086
  this._clientLog.warn(`group event signature verification error: ${formatCaughtError(exc)}`);
2087
2087
  // P1-16: 签名失败统一发布事件
2088
- this._dispatcher.publish('signature.verification_failed', {
2088
+ this._dispatcher.enqueue('signature.verification_failed', {
2089
2089
  aid: String(cs.aid ?? ''), method: String(cs._method ?? ''),
2090
2090
  error: formatCaughtError(exc),
2091
- }).catch(() => { });
2091
+ });
2092
2092
  return false;
2093
2093
  }
2094
2094
  }
@@ -2485,7 +2485,7 @@ export class AUNClient {
2485
2485
  }
2486
2486
  }
2487
2487
  else {
2488
- await this._dispatcher.publish('state_change', statePayload);
2488
+ this._dispatcher.enqueue('state_change', statePayload);
2489
2489
  }
2490
2490
  this._assertReconnectOwner(reconnectOwner);
2491
2491
  this._lifecycle.assertConnectionAttemptOwner(connectionOwner);
@@ -2827,7 +2827,7 @@ export class AUNClient {
2827
2827
  this._attachV2EnvelopeMetadata(event, e2eeMeta);
2828
2828
  this._logMessageDebug('decrypt-fail', 'v2.decrypt', undecryptableEvent, event);
2829
2829
  if (emitUndecryptable)
2830
- await this._dispatcher.publish(undecryptableEvent, event);
2830
+ this._dispatcher.enqueue(undecryptableEvent, event);
2831
2831
  return null;
2832
2832
  }
2833
2833
  this._clientLog.debug(`V2 decrypt key lookup ok: seq=${String(msg.seq ?? '')}, group=${groupIdForKeys || '<p2p>'}, ik_len=${ikPriv.byteLength}, spk_len=${spkPriv?.byteLength ?? 0}`);
@@ -2866,7 +2866,7 @@ export class AUNClient {
2866
2866
  this._attachV2EnvelopeMetadata(event, e2eeMeta);
2867
2867
  this._logMessageDebug('decrypt-fail', 'v2.decrypt', undecryptableEvent, event);
2868
2868
  if (emitUndecryptable)
2869
- await this._dispatcher.publish(undecryptableEvent, event);
2869
+ this._dispatcher.enqueue(undecryptableEvent, event);
2870
2870
  return null;
2871
2871
  }
2872
2872
  let plaintext;
@@ -2895,7 +2895,7 @@ export class AUNClient {
2895
2895
  this._attachV2EnvelopeMetadata(event, e2eeMeta);
2896
2896
  this._logMessageDebug('decrypt-fail', 'v2.decrypt', undecryptableEvent, event);
2897
2897
  if (emitUndecryptable)
2898
- await this._dispatcher.publish(undecryptableEvent, event);
2898
+ this._dispatcher.enqueue(undecryptableEvent, event);
2899
2899
  return null;
2900
2900
  }
2901
2901
  if (plaintext === null) {
@@ -3437,7 +3437,7 @@ export class AUNClient {
3437
3437
  if (this._sessionParams !== null && identity.access_token) {
3438
3438
  this._sessionParams.access_token = identity.access_token;
3439
3439
  }
3440
- await this._dispatcher.publish('token.refreshed', {
3440
+ this._dispatcher.enqueue('token.refreshed', {
3441
3441
  aid: identity.aid,
3442
3442
  expires_at: identity.access_token_expires_at,
3443
3443
  });
@@ -3447,7 +3447,7 @@ export class AUNClient {
3447
3447
  if (exc instanceof AuthError) {
3448
3448
  if (authErrorRequiresRelogin(exc)) {
3449
3449
  this._clientLog.warn(`token refresh requires relogin, stopping refresh loop and triggering reconnect: ${exc.message}`);
3450
- await this._dispatcher.publish('token.refresh_exhausted', {
3450
+ this._dispatcher.enqueue('token.refresh_exhausted', {
3451
3451
  aid: this._identity?.aid ?? null,
3452
3452
  consecutive_failures: 1,
3453
3453
  last_error: String(exc),
@@ -3460,7 +3460,7 @@ export class AUNClient {
3460
3460
  this._tokenRefreshFailures++;
3461
3461
  if (this._tokenRefreshFailures >= 3) {
3462
3462
  this._clientLog.warn(`token refresh failed ${this._tokenRefreshFailures} consecutive times, stopping refresh loop and triggering reconnect`);
3463
- await this._dispatcher.publish('token.refresh_exhausted', {
3463
+ this._dispatcher.enqueue('token.refresh_exhausted', {
3464
3464
  aid: this._identity?.aid ?? null,
3465
3465
  consecutive_failures: this._tokenRefreshFailures,
3466
3466
  last_error: String(exc),
@@ -3472,7 +3472,7 @@ export class AUNClient {
3472
3472
  this._clientLog.debug(`token refresh failed (${this._tokenRefreshFailures}/3), will retry: ${exc}`);
3473
3473
  }
3474
3474
  else {
3475
- await this._dispatcher.publish('connection.error', { error: formatCaughtError(exc) });
3475
+ this._dispatcher.enqueue('connection.error', { error: formatCaughtError(exc) });
3476
3476
  }
3477
3477
  }
3478
3478
  scheduleNext();
@@ -3543,7 +3543,7 @@ export class AUNClient {
3543
3543
  this._lastDisconnectInfo = { code, reason, detail };
3544
3544
  // 透传给应用层订阅者
3545
3545
  try {
3546
- await this._dispatcher.publish('gateway.disconnect', {
3546
+ this._dispatcher.enqueue('gateway.disconnect', {
3547
3547
  code,
3548
3548
  reason,
3549
3549
  detail,
@@ -3669,13 +3669,7 @@ export class AUNClient {
3669
3669
  async _publishReconnectEvent(owner, event, payload) {
3670
3670
  if (!this._ownsReconnect(owner))
3671
3671
  return false;
3672
- this._reconnectEventDispatchDepth += 1;
3673
- try {
3674
- await this._dispatcher.publish(event, payload);
3675
- }
3676
- finally {
3677
- this._reconnectEventDispatchDepth -= 1;
3678
- }
3672
+ this._dispatcher.enqueue(event, payload);
3679
3673
  return this._ownsReconnect(owner);
3680
3674
  }
3681
3675
  async _cancelReconnectAndWait() {