@agentunion/fastaun 0.5.14 → 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.
package/dist/client.js CHANGED
@@ -575,6 +575,7 @@ export class AUNClient {
575
575
  aunPath: this._configModel.aunPath,
576
576
  });
577
577
  this._logger.bindDeviceId(this._deviceId);
578
+ this._logger.bindAid(initAid ?? '');
578
579
  this._clientLog = this._logger.for('aun_core.client');
579
580
  if (debugFlag) {
580
581
  this._clientLog.info(`AUNClient initialized (debug=true, aunPath=${this._configModel.aunPath})`);
@@ -624,13 +625,13 @@ export class AUNClient {
624
625
  });
625
626
  this._transport = new RPCTransport({
626
627
  eventDispatcher: this._dispatcher,
627
- timeout: 10_000,
628
- onDisconnect: (err, closeCode) => this._handleTransportDisconnect(err, closeCode),
628
+ timeout: 35_000,
629
629
  verifySsl: this._configModel.verifySsl,
630
630
  logger: this._logger.for('aun_core.transport'),
631
631
  dnsNet,
632
632
  });
633
- this._transport.setMetaObserver((meta) => this._observeRpcMeta(meta));
633
+ this._transport.setProtocolMetaObserver((meta) => this._observeRpcMeta(meta));
634
+ this._transport.setProtocolDisconnectCallback((err, closeCode) => this._handleTransportDisconnect(err, closeCode));
634
635
  this._runtime = new ClientRuntime(this);
635
636
  this._identityRuntime = new IdentityRuntimeManager(this._runtime);
636
637
  this._peerDirectory = new PeerDirectory(this._runtime);
@@ -654,11 +655,11 @@ export class AUNClient {
654
655
  }
655
656
  }
656
657
  // 内部订阅:推送消息自动解密后 re-publish 给用户
657
- this._dispatcher.subscribe('_raw.message.received', (data) => this._onRawMessageReceived(data));
658
+ this._dispatcher.subscribeProtocol('_raw.message.received', (data) => this._onRawMessageReceived(data));
658
659
  // P2P 消息撤回推送:在线 push 与 pull tombstone 去重后再发布给应用层
659
- this._dispatcher.subscribe('_raw.message.recalled', (data) => this._safeAsync(this._onRawMessageRecalled(data)));
660
+ this._dispatcher.subscribeProtocol('_raw.message.recalled', (data) => this._safeAsync(this._onRawMessageRecalled(data)));
660
661
  // V2 P2P 推送通知:收到通知后自动走 message.v2.pull 拉取并解密
661
- this._dispatcher.subscribe('_raw.peer.v2.message_received', (data) => {
662
+ this._dispatcher.subscribeProtocol('_raw.peer.v2.message_received', (data) => {
662
663
  const ns = this._aid ? `p2p:${this._aid}` : '';
663
664
  const hasInline = isJsonObject(data)
664
665
  && isJsonObject(data.inline_message);
@@ -668,7 +669,7 @@ export class AUNClient {
668
669
  : this._onV2PushNotification(data, 'v2'));
669
670
  });
670
671
  // V2 群组消息推送通知:收到通知后自动走 group.v2.pull 拉取并解密
671
- this._dispatcher.subscribe('_raw.group.v2.message_created', (data) => {
672
+ this._dispatcher.subscribeProtocol('_raw.group.v2.message_created', (data) => {
672
673
  const groupId = isJsonObject(data)
673
674
  ? String(data.group_id ?? '').trim()
674
675
  : '';
@@ -681,26 +682,26 @@ export class AUNClient {
681
682
  : this._onRawGroupV2MessageCreated(data, 'v2'));
682
683
  });
683
684
  // 群组消息推送:自动解密后 re-publish
684
- this._dispatcher.subscribe('_raw.group.message_created', (data) => this._onRawGroupMessageCreated(data));
685
+ this._dispatcher.subscribeProtocol('_raw.group.message_created', (data) => this._onRawGroupMessageCreated(data));
685
686
  // 群组消息撤回推送:在线 push 通道,与 pull 双 tombstone 兜底互补(SDK 去重只回调一次)
686
- this._dispatcher.subscribe('_raw.group.message_recalled', (data) => this._safeAsync(this._onRawGroupMessageRecalled(data)));
687
+ this._dispatcher.subscribeProtocol('_raw.group.message_recalled', (data) => this._safeAsync(this._onRawGroupMessageRecalled(data)));
687
688
  // 群组变更事件:透传并触发 V2 state/SPK 维护
688
- this._dispatcher.subscribe('_raw.group.changed', (data) => this._onRawGroupChanged(data));
689
+ this._dispatcher.subscribeProtocol('_raw.group.changed', (data) => this._onRawGroupChanged(data));
689
690
  // 定向邀请底层事件:按群 + 目标 AID 聚合后向应用层只提示一次。
690
- this._dispatcher.subscribe('_raw.group.invite_created', (data) => this._onRawGroupInviteCreated(data));
691
- this._dispatcher.subscribe('_raw.group.invite_finalized', (data) => this._onRawGroupInviteFinalized(data));
691
+ this._dispatcher.subscribeProtocol('_raw.group.invite_created', (data) => this._onRawGroupInviteCreated(data));
692
+ this._dispatcher.subscribeProtocol('_raw.group.invite_finalized', (data) => this._onRawGroupInviteFinalized(data));
692
693
  // V2 state proposal 服务平面事件:owner/admin 负责确认或重新提案
693
- this._dispatcher.subscribe('_raw.group.v2.state_proposed', (data) => this._safeAsync(this._onV2StateProposed(data)));
694
- this._dispatcher.subscribe('_raw.group.v2.state_retry_needed', (data) => this._safeAsync(this._onV2StateRetryNeeded(data)));
695
- this._dispatcher.subscribe('_raw.group.v2.state_confirmed', (data) => this._safeAsync(this._onV2StateConfirmed(data)));
694
+ this._dispatcher.subscribeProtocol('_raw.group.v2.state_proposed', (data) => this._safeAsync(this._onV2StateProposed(data)));
695
+ this._dispatcher.subscribeProtocol('_raw.group.v2.state_retry_needed', (data) => this._safeAsync(this._onV2StateRetryNeeded(data)));
696
+ this._dispatcher.subscribeProtocol('_raw.group.v2.state_confirmed', (data) => this._safeAsync(this._onV2StateConfirmed(data)));
696
697
  // 群组状态提交事件:验证 state_hash 链并更新本地存储
697
- this._dispatcher.subscribe('_raw.group.state_committed', (data) => this._onGroupStateCommitted(data));
698
+ this._dispatcher.subscribeProtocol('_raw.group.state_committed', (data) => this._onGroupStateCommitted(data));
698
699
  // 其他事件直接透传
699
700
  for (const evt of ['message.ack', 'storage.object_changed', 'stream/created', 'stream/closed']) {
700
- this._dispatcher.subscribe(`_raw.${evt}`, (data) => this._dispatcher.enqueue(evt, data));
701
+ this._dispatcher.subscribeProtocol(`_raw.${evt}`, (data) => this._dispatcher.enqueue(evt, data));
701
702
  }
702
703
  // 服务端主动断开通知:记录日志并标记不重连
703
- this._dispatcher.subscribe('_raw.gateway.disconnect', (data) => this._onGatewayDisconnect(data));
704
+ this._dispatcher.subscribeProtocol('_raw.gateway.disconnect', (data) => this._onGatewayDisconnect(data));
704
705
  }
705
706
  // ── 属性 ──────────────────────────────────────────────────
706
707
  /** 当前 AID */
@@ -867,6 +868,7 @@ export class AUNClient {
867
868
  const debugFlag = nextConfig.debug;
868
869
  this._logger = new AUNLogger({ debug: debugFlag, aunPath: nextConfig.aunPath });
869
870
  this._logger.bindDeviceId(this._deviceId);
871
+ this._logger.bindAid(aid.aid);
870
872
  this._clientLog = this._logger.for('aun_core.client');
871
873
  const dnsNet = new DnsResilientNet({
872
874
  verifySsl: nextConfig.verifySsl,
@@ -908,13 +910,13 @@ export class AUNClient {
908
910
  });
909
911
  this._transport = new RPCTransport({
910
912
  eventDispatcher: this._dispatcher,
911
- timeout: 10_000,
912
- onDisconnect: (err, closeCode) => this._handleTransportDisconnect(err, closeCode),
913
+ timeout: 35_000,
913
914
  verifySsl: nextConfig.verifySsl,
914
915
  logger: this._logger.for('aun_core.transport'),
915
916
  dnsNet,
916
917
  });
917
- this._transport.setMetaObserver((meta) => this._observeRpcMeta(meta));
918
+ this._transport.setProtocolMetaObserver((meta) => this._observeRpcMeta(meta));
919
+ this._transport.setProtocolDisconnectCallback((err, closeCode) => this._handleTransportDisconnect(err, closeCode));
918
920
  }
919
921
  loadIdentity(aid) {
920
922
  this._identityRuntime.loadIdentity(aid);
@@ -1740,7 +1742,7 @@ export class AUNClient {
1740
1742
  this._clientLog.debug(`on exit: elapsed=${Date.now() - tStart}ms event=${event}`);
1741
1743
  return result;
1742
1744
  }
1743
- async _callRawV2Rpc(method, params) {
1745
+ async _callRawV2Rpc(method, params, pullGateKey = '') {
1744
1746
  const p = { ...(params ?? {}) };
1745
1747
  const forceForeground = Boolean(p._rpc_foreground);
1746
1748
  const rpcBackground = !forceForeground
@@ -1769,7 +1771,10 @@ export class AUNClient {
1769
1771
  if (method.startsWith('group.') && p.slot_id === undefined) {
1770
1772
  p.slot_id = this._slotId;
1771
1773
  }
1772
- return await this._rpcPipeline.rawCall(method, p, { background: rpcBackground });
1774
+ return await this._rpcPipeline.rawCall(method, p, {
1775
+ background: rpcBackground,
1776
+ ...(pullGateKey ? { pullGateKey } : {}),
1777
+ });
1773
1778
  }
1774
1779
  /** P2-13: 取消订阅事件(对齐 Python/JS off 方法) */
1775
1780
  off(event, handler) {