@agentunion/fastaun-browser 0.5.14 → 0.5.16

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 (50) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/_packed_docs/CHANGELOG.md +44 -0
  3. package/_packed_docs/agent.md/SCHEMA.md +15 -8
  4. package/_packed_docs/aun/345/210/206/345/270/203/345/274/217/346/265/213/350/257/225/350/277/220/350/241/214/346/214/207/345/215/227.md +85 -4
  5. package/_packed_docs/aun/346/265/213/350/257/225/350/277/220/350/241/214/346/214/207/345/215/227.md +1 -1
  6. package/dist/agent-md-schema.d.ts.map +1 -1
  7. package/dist/agent-md-schema.js +6 -0
  8. package/dist/agent-md-schema.js.map +1 -1
  9. package/dist/agent-md.d.ts +1 -0
  10. package/dist/agent-md.d.ts.map +1 -1
  11. package/dist/agent-md.js +2 -0
  12. package/dist/agent-md.js.map +1 -1
  13. package/dist/bundle.js +421 -264
  14. package/dist/client/delivery.d.ts.map +1 -1
  15. package/dist/client/delivery.js +2 -4
  16. package/dist/client/delivery.js.map +1 -1
  17. package/dist/client/lifecycle.d.ts.map +1 -1
  18. package/dist/client/lifecycle.js +5 -1
  19. package/dist/client/lifecycle.js.map +1 -1
  20. package/dist/client/rpc-pipeline.d.ts +1 -0
  21. package/dist/client/rpc-pipeline.d.ts.map +1 -1
  22. package/dist/client/rpc-pipeline.js +10 -8
  23. package/dist/client/rpc-pipeline.js.map +1 -1
  24. package/dist/client/v2-e2ee.d.ts.map +1 -1
  25. package/dist/client/v2-e2ee.js +24 -13
  26. package/dist/client/v2-e2ee.js.map +1 -1
  27. package/dist/client.d.ts.map +1 -1
  28. package/dist/client.js +46 -28
  29. package/dist/client.js.map +1 -1
  30. package/dist/events.d.ts +25 -12
  31. package/dist/events.d.ts.map +1 -1
  32. package/dist/events.js +164 -79
  33. package/dist/events.js.map +1 -1
  34. package/dist/group-index.js +1 -1
  35. package/dist/group-index.js.map +1 -1
  36. package/dist/logger.d.ts +9 -1
  37. package/dist/logger.d.ts.map +1 -1
  38. package/dist/logger.js +29 -7
  39. package/dist/logger.js.map +1 -1
  40. package/dist/result.d.ts +1 -2
  41. package/dist/result.d.ts.map +1 -1
  42. package/dist/result.js +2 -2
  43. package/dist/result.js.map +1 -1
  44. package/dist/transport.d.ts +5 -1
  45. package/dist/transport.d.ts.map +1 -1
  46. package/dist/transport.js +57 -32
  47. package/dist/transport.js.map +1 -1
  48. package/dist/version.d.ts +1 -1
  49. package/dist/version.js +1 -1
  50. package/package.json +1 -1
package/dist/logger.js CHANGED
@@ -14,6 +14,24 @@
14
14
  * 占位符仅支持 %s(按 args 顺序替换,多余的 args 拼到末尾)
15
15
  * - error error level supports Error as last param: logger.error('msg', err)
16
16
  */
17
+ import { normalizeGroupAid } from './group-id.js';
18
+ export function trafficLogContext(direction, data) {
19
+ const params = data && typeof data === 'object' && !Array.isArray(data) ? data : {};
20
+ const target = params.target && typeof params.target === 'object' ? params.target : {};
21
+ const notify = params._notify && typeof params._notify === 'object' ? params._notify : {};
22
+ const text = (value) => typeof value === 'string' ? value.trim() : '';
23
+ const group = text(params.group_aid) || text(params.group_id) || text(target.group_aid) || text(target.group_id);
24
+ const groupAid = normalizeGroupAid(group);
25
+ const peerAid = group
26
+ ? (groupAid.includes('.') && !groupAid.includes('/') ? groupAid : '')
27
+ : direction === 'outbound'
28
+ ? text(target.aid) || text(params.to) || text(params.to_aid) || text(params.peer_aid)
29
+ : text(notify.from_aid) || text(params.from_aid) || text(params.sender_aid) || text(params.from);
30
+ return { direction, peerAid };
31
+ }
32
+ export function withLogContext(logger, context) {
33
+ return logger.withContext?.(context) ?? logger;
34
+ }
17
35
  const LEVEL_ORDER = { DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3 };
18
36
  function formatMessage(template, args) {
19
37
  if (args.length === 0)
@@ -51,13 +69,15 @@ export class AUNLogger {
51
69
  this._aunPath = String(opts.aunPath || '-');
52
70
  this._minLevel = this._debug ? LEVEL_ORDER.DEBUG : LEVEL_ORDER.INFO;
53
71
  }
54
- for(module) {
72
+ for(module, context) {
73
+ const snapshot = context ? { ...context, aid: context.aid ?? this._aid ?? '' } : undefined;
55
74
  return {
56
- error: (msg, ...args) => this._emit('ERROR', module, msg, args),
57
- warn: (msg, ...args) => this._emit('WARN', module, msg, args),
58
- info: (msg, ...args) => this._emit('INFO', module, msg, args),
59
- debug: (msg, ...args) => this._emit('DEBUG', module, msg, args),
75
+ error: (msg, ...args) => this._emit('ERROR', module, msg, args, snapshot),
76
+ warn: (msg, ...args) => this._emit('WARN', module, msg, args, snapshot),
77
+ info: (msg, ...args) => this._emit('INFO', module, msg, args, snapshot),
78
+ debug: (msg, ...args) => this._emit('DEBUG', module, msg, args, snapshot),
60
79
  isDebugEnabled: () => this.isDebugEnabled(),
80
+ withContext: (next) => this.for(module, { ...next, aid: next.aid ?? snapshot?.aid }),
61
81
  };
62
82
  }
63
83
  isDebugEnabled() {
@@ -72,14 +92,16 @@ export class AUNLogger {
72
92
  close() {
73
93
  // 浏览器环境无文件清理,no-op
74
94
  }
75
- _emit(level, module, msg, args) {
95
+ _emit(level, module, msg, args, context) {
76
96
  if (LEVEL_ORDER[level] < this._minLevel)
77
97
  return;
78
98
  if (level === 'DEBUG' && !this._debug)
79
99
  return;
80
100
  const { date, time, ms } = this._now();
81
101
  const head = `[${date} ${time}.${ms}][${level}][${module}][aun_path=${this._aunPath || '-'}][device_id=${this._deviceId || '-'}]`;
82
- const aidPart = this._aid ? ` [${this._aid}]` : '';
102
+ const aidPart = context
103
+ ? ` [${context.aid || '-'} ${context.direction === 'outbound' ? '->' : '<-'} ${context.peerAid || '-'}]`
104
+ : this._aid ? ` [${this._aid}]` : '';
83
105
  const formatted = formatMessage(msg, args);
84
106
  const line = `${head}${aidPart} ${formatted}`;
85
107
  // 取最后一个 Error 实例附加到控制台输出,便于浏览器展开 stack
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.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,QAAQ,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,EAAE,CAAC;QAClF,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,CAAC;QACvC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;IAC5B,CAAC;CACF"}
package/dist/result.d.ts CHANGED
@@ -2,7 +2,6 @@
2
2
  export interface ErrorInfo {
3
3
  code: string;
4
4
  message: string;
5
- cause?: unknown;
6
5
  }
7
6
  /** 统一结果类型:成功时 ok=true + data,失败时 ok=false + error */
8
7
  export type Result<T> = {
@@ -15,5 +14,5 @@ export type Result<T> = {
15
14
  /** 构造成功结果 */
16
15
  export declare function resultOk<T>(data: T): Result<T>;
17
16
  /** 构造失败结果 */
18
- export declare function resultErr(code: string, message: string, cause?: unknown): Result<never>;
17
+ export declare function resultErr(code: string, message: string, _cause?: unknown): Result<never>;
19
18
  //# sourceMappingURL=result.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AAEA,WAAW;AACX,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,qDAAqD;AACrD,MAAM,MAAM,MAAM,CAAC,CAAC,IAChB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GACrB;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,SAAS,CAAA;CAAE,CAAC;AAEpC,aAAa;AACb,wBAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAE9C;AAED,aAAa;AACb,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAEvF"}
1
+ {"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AAEA,WAAW;AACX,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,qDAAqD;AACrD,MAAM,MAAM,MAAM,CAAC,CAAC,IAChB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GACrB;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,SAAS,CAAA;CAAE,CAAC;AAEpC,aAAa;AACb,wBAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAE9C;AAED,aAAa;AACb,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAExF"}
package/dist/result.js CHANGED
@@ -4,7 +4,7 @@ export function resultOk(data) {
4
4
  return { ok: true, data };
5
5
  }
6
6
  /** 构造失败结果 */
7
- export function resultErr(code, message, cause) {
8
- return { ok: false, error: { code, message, ...(cause !== undefined ? { cause } : {}) } };
7
+ export function resultErr(code, message, _cause) {
8
+ return { ok: false, error: { code, message } };
9
9
  }
10
10
  //# sourceMappingURL=result.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"result.js","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AAAA,qDAAqD;AAcrD,aAAa;AACb,MAAM,UAAU,QAAQ,CAAI,IAAO;IACjC,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AAC5B,CAAC;AAED,aAAa;AACb,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,OAAe,EAAE,KAAe;IACtE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;AAC5F,CAAC"}
1
+ {"version":3,"file":"result.js","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AAAA,qDAAqD;AAarD,aAAa;AACb,MAAM,UAAU,QAAQ,CAAI,IAAO;IACjC,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AAC5B,CAAC;AAED,aAAa;AACb,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,OAAe,EAAE,MAAgB;IACvE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC;AACjD,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { EventDispatcher } from './events.js';
2
- import type { ModuleLogger } from './logger.js';
2
+ import { type ModuleLogger } from './logger.js';
3
3
  import { type JsonObject, type RpcMessage, type RpcParams, type RpcResult } from './types.js';
4
4
  export declare function createTransportWebSocket(url: string): WebSocket;
5
5
  /**
@@ -17,6 +17,7 @@ export declare class RPCTransport {
17
17
  private _timeout;
18
18
  private _connectTimeout;
19
19
  private _onDisconnect;
20
+ private _onDisconnectIsProtocol;
20
21
  private _ws;
21
22
  private _closed;
22
23
  private _lastCloseCode;
@@ -32,6 +33,7 @@ export declare class RPCTransport {
32
33
  private _drainingRpcQueue;
33
34
  private _sendChain;
34
35
  private _metaObserver;
36
+ private _metaObserverIsProtocol;
35
37
  private _traceMode;
36
38
  private _traceObserver;
37
39
  private _actorTail;
@@ -41,6 +43,7 @@ export declare class RPCTransport {
41
43
  timeout?: number;
42
44
  onDisconnect?: ((error: Error | null, closeCode?: number) => Promise<void>) | null;
43
45
  });
46
+ setProtocolDisconnectCallback(callback: ((error: Error | null, closeCode?: number) => Promise<void>) | null): void;
44
47
  /** 设置默认超时(秒) */
45
48
  setTimeout(timeout: number): void;
46
49
  /** 设置 WebSocket 建连及 challenge 超时(秒)。 */
@@ -54,6 +57,7 @@ export declare class RPCTransport {
54
57
  * 不影响 RPC result 返回。
55
58
  */
56
59
  setMetaObserver(observer: ((meta: JsonObject) => void | Promise<void>) | null): void;
60
+ setProtocolMetaObserver(observer: ((meta: JsonObject) => void | Promise<void>) | null): void;
57
61
  private _notifyMetaObserver;
58
62
  /** 设置 trace 模式:off / log / diag */
59
63
  setTraceMode(mode: string): void;
@@ -1 +1 @@
1
- {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAQhD,OAAO,EAAgB,KAAK,UAAU,EAAkB,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAqU5H,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAU/D;AA8ND;;;;;;;GAOG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,IAAI,CAA0B;IACtC,SAAS,CAAC,GAAG,EAAE,YAAY,GAAG,IAAI;IAElC,OAAO,CAAC,WAAW,CAAkB;IACrC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,aAAa,CAAsE;IAC3F,OAAO,CAAC,GAAG,CAA0B;IACrC,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,cAAc,CAAuB;IAC7C,OAAO,CAAC,gBAAgB,CAAM;IAC9B,OAAO,CAAC,qBAAqB,CAAK;IAClC,OAAO,CAAC,oBAAoB,CAAoC;IAChE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,WAAW;IACX,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAIR,UAAU;IAIxB,iCAAiC;YACnB,cAAc;IA6D5B;;;OAGG;IACH,IAAI,CACF,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,SAAS,GAAG,IAAI,EACzB,OAAO,CAAC,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,MAAM,EACd,UAAU,UAAQ,GACjB,OAAO,CAAC,SAAS,CAAC;IAOrB,OAAO,CAAC,SAAS;IAuHjB,kDAAkD;IAClD,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;YAIlD,WAAW;IAyBzB,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,aAAa;IAerB,OAAO,CAAC,kBAAkB;IAkC1B,OAAO,CAAC,SAAS;YAiBH,iBAAiB;YAYjB,0BAA0B;IA4BxC,kCAAkC;IAClC,OAAO,CAAC,UAAU;IAclB,sCAAsC;IACtC,OAAO,CAAC,cAAc;IAgDtB,+DAA+D;IAC/D,OAAO,CAAC,oBAAoB;IA+B5B,OAAO,CAAC,cAAc;IAStB,OAAO,CAAC,YAAY;IA8CpB,OAAO,CAAC,kBAAkB;IAQ1B,OAAO,CAAC,aAAa;IAoErB,OAAO,CAAC,cAAc;CAiBvB"}
package/dist/transport.js CHANGED
@@ -1,4 +1,5 @@
1
1
  // ── RPC Transport(浏览器原生 WebSocket)──────────────────
2
+ import { trafficLogContext, withLogContext } from './logger.js';
2
3
  import { ConnectionError, SerializationError, TimeoutError, ValidationError, mapRemoteError, } from './errors.js';
3
4
  import { isJsonObject } from './types.js';
4
5
  const MAX_WS_PAYLOAD_SIZE = 1_000_000;
@@ -544,6 +545,7 @@ export class RPCTransport {
544
545
  _timeout;
545
546
  _connectTimeout;
546
547
  _onDisconnect;
548
+ _onDisconnectIsProtocol = false;
547
549
  _ws = null;
548
550
  _closed = true;
549
551
  _lastCloseCode = null;
@@ -561,6 +563,7 @@ export class RPCTransport {
561
563
  // Gateway 在 RPC envelope 注入 _meta 字段(与 result 同级),由 client 层 observer 接收。
562
564
  // 注入失败 / 字段缺失时 observer 不会被调用,不影响业务路径。
563
565
  _metaObserver = null;
566
+ _metaObserverIsProtocol = false;
564
567
  // Trace 模式:off / log / diag
565
568
  _traceMode = 'off';
566
569
  // Trace observer:observer(traceInfo) 在每次 RPC/事件携带 _trace 时调用
@@ -571,10 +574,14 @@ export class RPCTransport {
571
574
  _actorBusy = false;
572
575
  constructor(opts) {
573
576
  this._dispatcher = opts.eventDispatcher;
574
- this._timeout = opts.timeout ?? 10;
577
+ this._timeout = opts.timeout ?? 35;
575
578
  this._connectTimeout = opts.timeout ?? 10;
576
579
  this._onDisconnect = opts.onDisconnect ?? null;
577
580
  }
581
+ setProtocolDisconnectCallback(callback) {
582
+ this._onDisconnect = callback;
583
+ this._onDisconnectIsProtocol = true;
584
+ }
578
585
  /** 设置默认超时(秒) */
579
586
  setTimeout(timeout) {
580
587
  this._timeout = timeout;
@@ -595,6 +602,11 @@ export class RPCTransport {
595
602
  */
596
603
  setMetaObserver(observer) {
597
604
  this._metaObserver = observer;
605
+ this._metaObserverIsProtocol = false;
606
+ }
607
+ setProtocolMetaObserver(observer) {
608
+ this._metaObserver = observer;
609
+ this._metaObserverIsProtocol = true;
598
610
  }
599
611
  _notifyMetaObserver(message) {
600
612
  const observer = this._metaObserver;
@@ -603,14 +615,18 @@ export class RPCTransport {
603
615
  const meta = message._meta;
604
616
  if (!isJsonObject(meta))
605
617
  return;
606
- this._dispatcher.enqueueTask(async () => {
618
+ const task = async () => {
607
619
  try {
608
620
  await observer(meta);
609
621
  }
610
622
  catch (exc) {
611
623
  this._log.debug(`meta_observer raised: ${String(exc)}`);
612
624
  }
613
- });
625
+ };
626
+ if (this._metaObserverIsProtocol)
627
+ this._dispatcher.enqueueProtocolTask(task);
628
+ else
629
+ this._dispatcher.enqueueTask(task);
614
630
  }
615
631
  /** 设置 trace 模式:off / log / diag */
616
632
  setTraceMode(mode) {
@@ -902,6 +918,9 @@ export class RPCTransport {
902
918
  const localParams = sendParams;
903
919
  const backgroundRpc = background || localParams._rpc_background === true;
904
920
  delete localParams._rpc_background;
921
+ const requestContext = trafficLogContext('outbound', sendParams);
922
+ const requestLog = withLogContext(this._log, requestContext);
923
+ const responseLog = withLogContext(requestLog, { direction: 'inbound', peerAid: requestContext.peerAid });
905
924
  if (effectiveTraceMode !== 'off') {
906
925
  // 浏览器环境使用 crypto.randomUUID 或 Math.random 生成 trace_id
907
926
  traceId = typeof crypto !== 'undefined' && crypto.randomUUID
@@ -912,7 +931,7 @@ export class RPCTransport {
912
931
  tracePayload.spans = [{ node: 'sdk', ts: tStart, action: 'send' }];
913
932
  }
914
933
  localParams._trace = tracePayload;
915
- this._log.info(`[trace=${traceId}] rpc_send method=${method} rpc_id=${rpcId}`);
934
+ requestLog.info(`[trace=${traceId}] rpc_send method=${method} rpc_id=${rpcId}`);
916
935
  }
917
936
  const payload = JSON.stringify({
918
937
  jsonrpc: '2.0',
@@ -928,7 +947,7 @@ export class RPCTransport {
928
947
  const promise = new Promise((resolve, reject) => {
929
948
  const timer = globalThis.setTimeout(() => {
930
949
  this._removeRpc(rpcId, pending);
931
- this._log.warn(`RPC timeout: method=${method}, id=${rpcId}, elapsed=${Date.now() - tStart}ms, timeout=${effectiveTimeout}ms`);
950
+ requestLog.warn(`RPC timeout: method=${method}, id=${rpcId}, elapsed=${Date.now() - tStart}ms, timeout=${effectiveTimeout}ms`);
932
951
  reject(new TimeoutError(`rpc timeout: ${method}`, { retryable: true }));
933
952
  this._drainRpcQueue();
934
953
  }, effectiveTimeout);
@@ -937,31 +956,31 @@ export class RPCTransport {
937
956
  clearTimeout(timer);
938
957
  const elapsed = Date.now() - tStart;
939
958
  if (response.error !== undefined) {
940
- this._log.debug(`RPC error response: method=${method}, id=${rpcId}, elapsed=${elapsed}ms, error=${JSON.stringify(response.error)}`);
959
+ responseLog.debug(`RPC error response: method=${method}, id=${rpcId}, elapsed=${elapsed}ms, error=${JSON.stringify(response.error)}`);
941
960
  if (traceId) {
942
- this._log.info(`[trace=${traceId}] rpc_recv method=${method} rpc_id=${rpcId} duration_ms=${elapsed} status=error`);
961
+ responseLog.info(`[trace=${traceId}] rpc_recv method=${method} rpc_id=${rpcId} duration_ms=${elapsed} status=error`);
943
962
  }
944
963
  const respTrace = response._trace;
945
964
  if (respTrace && typeof respTrace === 'object' && !Array.isArray(respTrace)) {
946
- this._handleResponseTrace(method, 'error', elapsed, respTrace);
965
+ this._handleResponseTrace(method, 'error', elapsed, respTrace, responseLog);
947
966
  }
948
967
  reject(mapRemoteError(response.error));
949
968
  }
950
969
  else if (response.result !== undefined) {
951
- this._log.debug(`RPC response ok: method=${method}, id=${rpcId}, elapsed=${elapsed}ms ${summarizeDict(response.result, DIAG_RESULT_FIELDS)}`);
970
+ responseLog.debug(`RPC response ok: method=${method}, id=${rpcId}, elapsed=${elapsed}ms ${summarizeDict(response.result, DIAG_RESULT_FIELDS)}`);
952
971
  if (traceId) {
953
- this._log.info(`[trace=${traceId}] rpc_recv method=${method} rpc_id=${rpcId} duration_ms=${elapsed} status=ok`);
972
+ responseLog.info(`[trace=${traceId}] rpc_recv method=${method} rpc_id=${rpcId} duration_ms=${elapsed} status=ok`);
954
973
  }
955
974
  this._notifyMetaObserver(response);
956
975
  // 处理 success 路径的 _trace
957
976
  const respTrace = response._trace;
958
977
  if (respTrace && typeof respTrace === 'object' && !Array.isArray(respTrace)) {
959
- this._handleResponseTrace(method, 'ok', elapsed, respTrace);
978
+ this._handleResponseTrace(method, 'ok', elapsed, respTrace, responseLog);
960
979
  }
961
980
  resolve(response.result);
962
981
  }
963
982
  else {
964
- this._log.warn(`RPC response missing result or error: method=${method}, id=${rpcId}, elapsed=${elapsed}ms`);
983
+ responseLog.warn(`RPC response missing result or error: method=${method}, id=${rpcId}, elapsed=${elapsed}ms`);
965
984
  reject(new SerializationError(`rpc response missing result and error: ${method}`));
966
985
  }
967
986
  },
@@ -979,12 +998,12 @@ export class RPCTransport {
979
998
  // 入队并触发 drain
980
999
  if (backgroundRpc) {
981
1000
  this._backgroundRpcQueue.push({
982
- rpcId, method, payload, pending, tStart, timeoutMs: effectiveTimeout, background: true,
1001
+ rpcId, method, payload, pending, tStart, timeoutMs: effectiveTimeout, background: true, logger: requestLog,
983
1002
  });
984
1003
  }
985
1004
  else {
986
1005
  this._rpcQueue.push({
987
- rpcId, method, payload, pending, tStart, timeoutMs: effectiveTimeout, background: false,
1006
+ rpcId, method, payload, pending, tStart, timeoutMs: effectiveTimeout, background: false, logger: requestLog,
988
1007
  });
989
1008
  }
990
1009
  this._drainRpcQueue();
@@ -1015,8 +1034,9 @@ export class RPCTransport {
1015
1034
  if (payloadSize > MAX_WS_PAYLOAD_SIZE) {
1016
1035
  throw new ValidationError('payload is too large');
1017
1036
  }
1037
+ const notifyLog = withLogContext(this._log, trafficLogContext('outbound', params ?? {}));
1018
1038
  await this._sendText(payload, `notification ${normalizedMethod}`);
1019
- this._log.debug(`notification sent: method=${normalizedMethod}, size=${payloadSize}`);
1039
+ notifyLog.debug(`notification sent: method=${normalizedMethod}, size=${payloadSize}`);
1020
1040
  }
1021
1041
  _enqueueSend(task) {
1022
1042
  const run = this._sendChain.then(() => Promise.resolve(task()), () => Promise.resolve(task()));
@@ -1182,7 +1202,7 @@ export class RPCTransport {
1182
1202
  const elapsed = Date.now() - entry.tStart;
1183
1203
  if (elapsed >= entry.timeoutMs) {
1184
1204
  clearTimeout(entry.pending.timer);
1185
- this._log.warn(`RPC queue timeout: method=${entry.method}, id=${entry.rpcId}, elapsed=${elapsed}ms, timeout=${entry.timeoutMs}ms`);
1205
+ entry.logger.warn(`RPC queue timeout: method=${entry.method}, id=${entry.rpcId}, elapsed=${elapsed}ms, timeout=${entry.timeoutMs}ms`);
1186
1206
  entry.pending.reject(new TimeoutError(`rpc timeout before send: ${entry.method}`, { retryable: true }));
1187
1207
  continue;
1188
1208
  }
@@ -1191,12 +1211,12 @@ export class RPCTransport {
1191
1211
  this._pendingBackground.add(entry.rpcId);
1192
1212
  }
1193
1213
  this._sendText(entry.payload, `rpc ${entry.method}`, () => this._pending.get(entry.rpcId) === entry.pending).then(() => {
1194
- this._log.debug(`RPC request sent: method=${entry.method}, id=${entry.rpcId}, background=${entry.background}`);
1214
+ entry.logger.debug(`RPC request sent: method=${entry.method}, id=${entry.rpcId}, background=${entry.background}`);
1195
1215
  }).catch((err) => {
1196
1216
  if (this._pending.get(entry.rpcId) !== entry.pending)
1197
1217
  return;
1198
1218
  this._removeRpc(entry.rpcId, entry.pending);
1199
- this._log.error(`RPC send failed: method=${entry.method}, id=${entry.rpcId}, error=${String(err)}`, err instanceof Error ? err : undefined);
1219
+ entry.logger.error(`RPC send failed: method=${entry.method}, id=${entry.rpcId}, error=${String(err)}`, err instanceof Error ? err : undefined);
1200
1220
  entry.pending.reject(err instanceof ConnectionError
1201
1221
  ? err
1202
1222
  : new ConnectionError(`failed to send rpc ${entry.method}: ${err instanceof Error ? err.message : String(err)}`));
@@ -1209,7 +1229,7 @@ export class RPCTransport {
1209
1229
  }
1210
1230
  }
1211
1231
  /** 处理 RPC 响应中的 _trace 字段:追加 sdk.recv span,格式化输出,通知 observer */
1212
- _handleResponseTrace(method, status, elapsedMs, respTrace) {
1232
+ _handleResponseTrace(method, status, elapsedMs, respTrace, logger = this._log) {
1213
1233
  try {
1214
1234
  const sdkRecvSpan = {
1215
1235
  node: 'sdk',
@@ -1220,7 +1240,7 @@ export class RPCTransport {
1220
1240
  const existingSpans = Array.isArray(respTrace.spans) ? respTrace.spans : [];
1221
1241
  const spans = [...existingSpans, sdkRecvSpan];
1222
1242
  const enriched = { ...respTrace, spans };
1223
- this._log.info(traceDisplay(method, status, elapsedMs, respTrace, spans));
1243
+ logger.info(traceDisplay(method, status, elapsedMs, respTrace, spans));
1224
1244
  if (this._traceObserver !== null) {
1225
1245
  const observer = this._traceObserver;
1226
1246
  this._dispatcher.enqueueTask(async () => {
@@ -1234,7 +1254,7 @@ export class RPCTransport {
1234
1254
  }
1235
1255
  }
1236
1256
  catch (err) {
1237
- this._log.debug(`trace handling raised: ${err instanceof Error ? err.message : String(err)}`);
1257
+ logger.debug(`trace handling raised: ${err instanceof Error ? err.message : String(err)}`);
1238
1258
  }
1239
1259
  }
1240
1260
  // ── 内部消息处理 ──────────────────────────────────
@@ -1278,16 +1298,20 @@ export class RPCTransport {
1278
1298
  const error = new ConnectionError(`websocket closed: code=${event.code} reason=${event.reason}`);
1279
1299
  if (this._onDisconnect) {
1280
1300
  const onDisconnect = this._onDisconnect;
1281
- this._dispatcher.enqueueTask(async () => {
1301
+ const task = async () => {
1282
1302
  try {
1283
1303
  await onDisconnect(error, event.code);
1284
1304
  }
1285
1305
  catch (exc) {
1286
1306
  this._log.warn('[aun_core.transport] disconnect callback exception:', exc);
1287
1307
  }
1288
- });
1308
+ };
1309
+ if (this._onDisconnectIsProtocol)
1310
+ this._dispatcher.enqueueProtocolTask(task);
1311
+ else
1312
+ this._dispatcher.enqueueTask(task);
1289
1313
  }
1290
- this._dispatcher.enqueue('connection.error', { error });
1314
+ this._dispatcher.enqueueProtocol('connection.error', { error });
1291
1315
  }
1292
1316
  }
1293
1317
  _notConnectedError() {
@@ -1310,7 +1334,7 @@ export class RPCTransport {
1310
1334
  }
1311
1335
  else {
1312
1336
  // H23: 未知 id 多数是超时后到达的慢响应;打 warn 便于排查,避免被完全吞掉
1313
- this._log.warn('[aun_core.transport] recv unknown rpc response (maybe arrived after timeout): id=' + rpcId);
1337
+ withLogContext(this._log, { direction: 'inbound', peerAid: '' }).warn('[aun_core.transport] recv unknown rpc response (maybe arrived after timeout): id=' + rpcId);
1314
1338
  }
1315
1339
  return;
1316
1340
  }
@@ -1318,15 +1342,16 @@ export class RPCTransport {
1318
1342
  // challenge 消息
1319
1343
  if (method === 'challenge') {
1320
1344
  this._challenge = message;
1321
- this._log.debug('challenge received');
1322
- this._dispatcher.enqueue('connection.challenge', message.params ?? {});
1345
+ withLogContext(this._log, trafficLogContext('inbound', message.params ?? message)).debug('challenge received');
1346
+ this._dispatcher.enqueueProtocol('connection.challenge', message.params ?? {});
1323
1347
  return;
1324
1348
  }
1325
1349
  // 事件推送
1326
1350
  if (method.startsWith('event/')) {
1327
1351
  const protocolEvent = method.slice(6);
1328
1352
  const sdkEvent = EVENT_NAME_MAP[protocolEvent] ?? protocolEvent;
1329
- this._log.debug(`event recv: event=${sdkEvent} ${summarizeDict(message.params, DIAG_RESULT_FIELDS)}`);
1353
+ const eventLog = withLogContext(this._log, trafficLogContext('inbound', message.params ?? message));
1354
+ eventLog.debug(`event recv: event=${sdkEvent} ${summarizeDict(message.params, DIAG_RESULT_FIELDS)}`);
1330
1355
  this._notifyMetaObserver(message);
1331
1356
  // 提取事件中的 _trace 并回调 observer,然后从 params 中剥离
1332
1357
  const params = (message.params ?? {});
@@ -1345,7 +1370,7 @@ export class RPCTransport {
1345
1370
  });
1346
1371
  }
1347
1372
  const traceObj = eventTrace;
1348
- this._log.info(`[trace=${String(traceObj.trace_id ?? '')}] event_recv event=${sdkEvent}`);
1373
+ eventLog.info(`[trace=${String(traceObj.trace_id ?? '')}] event_recv event=${sdkEvent}`);
1349
1374
  }
1350
1375
  }
1351
1376
  // 发布为 _raw.{event},由 AUNClient 处理后再发布用户可见的事件
@@ -1353,13 +1378,13 @@ export class RPCTransport {
1353
1378
  this._dispatcher.enqueue(sdkEvent, params);
1354
1379
  return;
1355
1380
  }
1356
- this._dispatcher.enqueue(`_raw.${sdkEvent}`, params);
1381
+ this._dispatcher.enqueueProtocol(`_raw.${sdkEvent}`, params);
1357
1382
  return;
1358
1383
  }
1359
1384
  // 其他通知
1360
1385
  this._notifyMetaObserver(message);
1361
- this._log.debug(`notification recv: method=${method || '<no-method>'}`);
1362
- this._dispatcher.enqueue('notification', message);
1386
+ withLogContext(this._log, trafficLogContext('inbound', message.params ?? {})).debug(`notification recv: method=${method || '<no-method>'}`);
1387
+ this._dispatcher.enqueueProtocol('notification', message);
1363
1388
  }
1364
1389
  _decodeMessage(raw) {
1365
1390
  if (isJsonObject(raw)) {