@agentunion/fastaun 0.5.30 → 0.5.32

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 (105) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/_packed_docs/CHANGELOG.md +60 -0
  3. package/_packed_docs/sdk/0.5.31-SDK/345/272/224/347/224/250/351/233/206/346/210/220/346/214/207/345/215/227.md +162 -0
  4. package/_packed_docs/sdk/0.5.31-SDK/345/274/200/345/217/221/344/270/216/347/247/273/346/244/215/346/214/207/345/215/227.md +167 -0
  5. package/_packed_docs/sdk/0.5.32-SDK/345/272/224/347/224/250/351/233/206/346/210/220/346/214/207/345/215/227.md +350 -0
  6. package/_packed_docs/sdk/0.5.32-SDK/345/274/200/345/217/221/344/270/216/347/247/273/346/244/215/346/214/207/345/215/227.md +319 -0
  7. package/_packed_docs/sdk/AUN_DOCS_GUIDE.md +12 -5
  8. package/_packed_docs/sdk/AUN/344/272/213/344/273/266/345/217/221/345/270/203/350/256/242/351/230/205/345/272/224/347/224/250/351/233/206/346/210/220/346/214/207/345/215/227.md +459 -0
  9. package/_packed_docs/sdk/AUN/344/272/213/344/273/266/345/217/221/345/270/203/350/256/242/351/230/205/345/274/200/345/217/221/347/247/273/346/244/215/346/214/207/345/215/227.md +554 -0
  10. package/_packed_docs/sdk/INDEX.md +27 -5
  11. package/_packed_docs/sdk//345/255/220AID/344/277/256/346/224/271agent.md/351/200/232/347/237/245Owner/345/234/272/346/231/257/346/214/207/345/215/227.md +234 -0
  12. package/dist/agent-md-schema.js +7 -6
  13. package/dist/agent-md-schema.js.map +1 -1
  14. package/dist/agent-md.d.ts +2 -0
  15. package/dist/agent-md.js +20 -6
  16. package/dist/agent-md.js.map +1 -1
  17. package/dist/aid-store.d.ts +1 -0
  18. package/dist/aid-store.js +1 -0
  19. package/dist/aid-store.js.map +1 -1
  20. package/dist/aid.js +1 -1
  21. package/dist/aid.js.map +1 -1
  22. package/dist/auth.js +1 -1
  23. package/dist/auth.js.map +1 -1
  24. package/dist/client/control-messages.d.ts +22 -7
  25. package/dist/client/control-messages.js +220 -185
  26. package/dist/client/control-messages.js.map +1 -1
  27. package/dist/client/delivery.d.ts +3 -0
  28. package/dist/client/delivery.js +67 -3
  29. package/dist/client/delivery.js.map +1 -1
  30. package/dist/client/group-state.d.ts +3 -0
  31. package/dist/client/group-state.js +48 -14
  32. package/dist/client/group-state.js.map +1 -1
  33. package/dist/client/lifecycle.js +12 -3
  34. package/dist/client/lifecycle.js.map +1 -1
  35. package/dist/client/rpc-pipeline.d.ts +9 -3
  36. package/dist/client/rpc-pipeline.js +61 -26
  37. package/dist/client/rpc-pipeline.js.map +1 -1
  38. package/dist/client/v2-e2ee.d.ts +13 -1
  39. package/dist/client/v2-e2ee.js +32 -19
  40. package/dist/client/v2-e2ee.js.map +1 -1
  41. package/dist/client.d.ts +18 -1
  42. package/dist/client.js +396 -140
  43. package/dist/client.js.map +1 -1
  44. package/dist/discovery.d.ts +1 -0
  45. package/dist/discovery.js +3 -1
  46. package/dist/discovery.js.map +1 -1
  47. package/dist/group-fs.js +1 -1
  48. package/dist/group-fs.js.map +1 -1
  49. package/dist/index.d.ts +2 -0
  50. package/dist/index.js +1 -0
  51. package/dist/index.js.map +1 -1
  52. package/dist/ownership-v21.d.ts +2 -2
  53. package/dist/ownership-v21.js +18 -21
  54. package/dist/ownership-v21.js.map +1 -1
  55. package/dist/ownership-workflow.js +6 -4
  56. package/dist/ownership-workflow.js.map +1 -1
  57. package/dist/pubsub/binding.d.ts +54 -0
  58. package/dist/pubsub/binding.js +343 -0
  59. package/dist/pubsub/binding.js.map +1 -0
  60. package/dist/pubsub/channel.d.ts +45 -0
  61. package/dist/pubsub/channel.js +137 -0
  62. package/dist/pubsub/channel.js.map +1 -0
  63. package/dist/pubsub/client.d.ts +93 -0
  64. package/dist/pubsub/client.js +318 -0
  65. package/dist/pubsub/client.js.map +1 -0
  66. package/dist/pubsub/credentials.d.ts +51 -0
  67. package/dist/pubsub/credentials.js +360 -0
  68. package/dist/pubsub/credentials.js.map +1 -0
  69. package/dist/pubsub/errors.d.ts +5 -0
  70. package/dist/pubsub/errors.js +6 -0
  71. package/dist/pubsub/errors.js.map +1 -0
  72. package/dist/pubsub/index.d.ts +48 -0
  73. package/dist/pubsub/index.js +152 -0
  74. package/dist/pubsub/index.js.map +1 -0
  75. package/dist/pubsub/scheduler.d.ts +58 -0
  76. package/dist/pubsub/scheduler.js +249 -0
  77. package/dist/pubsub/scheduler.js.map +1 -0
  78. package/dist/pubsub/service.d.ts +100 -0
  79. package/dist/pubsub/service.js +650 -0
  80. package/dist/pubsub/service.js.map +1 -0
  81. package/dist/pubsub/types.d.ts +119 -0
  82. package/dist/pubsub/types.js +2 -0
  83. package/dist/pubsub/types.js.map +1 -0
  84. package/dist/register-flow.js +1 -1
  85. package/dist/register-flow.js.map +1 -1
  86. package/dist/storage/lowlevel.js +49 -8
  87. package/dist/storage/lowlevel.js.map +1 -1
  88. package/dist/storage/read-cache.d.ts +7 -3
  89. package/dist/storage/read-cache.js +137 -18
  90. package/dist/storage/read-cache.js.map +1 -1
  91. package/dist/storage/vfs.d.ts +1 -0
  92. package/dist/storage/vfs.js +12 -4
  93. package/dist/storage/vfs.js.map +1 -1
  94. package/dist/tools/cross-sdk-agent.d.ts +1 -1
  95. package/dist/tools/cross-sdk-agent.js +4 -2
  96. package/dist/tools/cross-sdk-agent.js.map +1 -1
  97. package/dist/tools/pubsub-actor.d.ts +27 -0
  98. package/dist/tools/pubsub-actor.js +260 -0
  99. package/dist/tools/pubsub-actor.js.map +1 -0
  100. package/dist/transport.d.ts +26 -2
  101. package/dist/transport.js +182 -17
  102. package/dist/transport.js.map +1 -1
  103. package/dist/version.d.ts +1 -1
  104. package/dist/version.js +1 -1
  105. package/package.json +1 -1
@@ -1,6 +1,7 @@
1
1
  import type { ProtectedHeadersInput } from '../protected-headers.js';
2
2
  import { type JsonObject, type RpcParams, type RpcResult } from '../types.js';
3
3
  import type { ClientRuntime } from './runtime.js';
4
+ import type { RpcBackground } from '../transport.js';
4
5
  type BootstrapEntry = Record<string, any> & {
5
6
  cachedAt?: number;
6
7
  };
@@ -50,7 +51,10 @@ export declare class V2E2EECoordinator {
50
51
  getV2SenderPubDer(fromAid: string, senderDeviceId: string, certFingerprint?: string): Promise<Uint8Array | null>;
51
52
  pendingSenderIKMessageKey(msg: Record<string, unknown>, groupId: string, fromAid?: string): string;
52
53
  pendingSenderIKFetchKey(fromAid: string, senderDeviceId: string, groupId: string): string;
53
- fetchSenderIKOnce(fromAid: string, senderDeviceId: string, groupId: string, certFingerprint?: string): Promise<Uint8Array | null>;
54
+ fetchSenderIKOnce(fromAid: string, senderDeviceId: string, groupId: string, certFingerprint?: string, rpcOptions?: {
55
+ background?: RpcBackground;
56
+ deadline?: number;
57
+ }): Promise<Uint8Array | null>;
54
58
  scheduleSenderIKPending(args: {
55
59
  msg: Record<string, unknown>;
56
60
  fromAid: string;
@@ -71,6 +75,8 @@ export declare class V2E2EECoordinator {
71
75
  protectedHeaders?: ProtectedHeadersInput;
72
76
  context?: Record<string, unknown>;
73
77
  needRender?: boolean;
78
+ background?: RpcBackground;
79
+ deadline?: number;
74
80
  }): Promise<Record<string, unknown>>;
75
81
  sendV2(to: string, payload: Record<string, unknown>, opts?: {
76
82
  messageId?: string;
@@ -81,6 +87,8 @@ export declare class V2E2EECoordinator {
81
87
  protectedHeaders?: ProtectedHeadersInput;
82
88
  context?: Record<string, unknown>;
83
89
  needRender?: boolean;
90
+ background?: RpcBackground;
91
+ deadline?: number;
84
92
  }): Promise<unknown>;
85
93
  private historyDecryptFailure;
86
94
  private ensureDeliveryCurrent;
@@ -118,6 +126,8 @@ export declare class V2E2EECoordinator {
118
126
  protectedHeaders?: ProtectedHeadersInput;
119
127
  context?: Record<string, unknown>;
120
128
  needRender?: boolean;
129
+ background?: RpcBackground;
130
+ deadline?: number;
121
131
  }): Promise<unknown>;
122
132
  buildV2GroupEnvelope(opts: {
123
133
  groupId: string;
@@ -128,6 +138,8 @@ export declare class V2E2EECoordinator {
128
138
  protectedHeaders?: ProtectedHeadersInput;
129
139
  context?: Record<string, unknown>;
130
140
  needRender?: boolean;
141
+ background?: RpcBackground;
142
+ deadline?: number;
131
143
  }): Promise<Record<string, unknown>>;
132
144
  pullGroupV2TailInternal(params: Record<string, unknown>, deferPublish?: boolean, namespaceLocked?: boolean): Promise<Record<string, unknown>>;
133
145
  historyGroupV2Internal(params: Record<string, unknown>): Promise<Record<string, unknown>>;
@@ -485,9 +485,6 @@ export class V2E2EECoordinator {
485
485
  catch (exc) {
486
486
  client._clientLog.warn(`V2 session init failed (non-fatal): ${formatE2EEError(exc)}`);
487
487
  }
488
- if (opts.backgroundSync && client._v2Session && typeof client._v2AutoConfirmPendingProposals === 'function') {
489
- client._safeAsync(client._v2AutoConfirmPendingProposals());
490
- }
491
488
  }
492
489
  async initV2Session() {
493
490
  const client = this.client;
@@ -561,7 +558,7 @@ export class V2E2EECoordinator {
561
558
  inflight.add(gid);
562
559
  client._safeAsync((async () => {
563
560
  try {
564
- await client._v2Session.ensureGroupRegistered?.(gid, client._v2CallFn());
561
+ await client._v2Session.ensureGroupRegistered?.(gid, (method, params) => client.call(method, { ...params, _rpc_background: true }));
565
562
  client._clientLog.debug(`group SPK registered: group=${gid} reason=${opts.reason}`);
566
563
  }
567
564
  catch (exc) {
@@ -583,7 +580,7 @@ export class V2E2EECoordinator {
583
580
  inflight.add(gid);
584
581
  client._safeAsync((async () => {
585
582
  try {
586
- await client._v2Session.rotateGroupSPK?.(gid, client._v2CallFn());
583
+ await client._v2Session.rotateGroupSPK?.(gid, (method, params) => client.call(method, { ...params, _rpc_background: true }));
587
584
  client._clientLog.debug(`group SPK rotated: group=${gid} reason=${opts.reason}`);
588
585
  }
589
586
  catch (exc) {
@@ -642,15 +639,15 @@ export class V2E2EECoordinator {
642
639
  pendingSenderIKFetchKey(fromAid, senderDeviceId, groupId) {
643
640
  return `${fromAid}#${senderDeviceId}#${groupId || ''}`;
644
641
  }
645
- async fetchSenderIKOnce(fromAid, senderDeviceId, groupId, certFingerprint = '') {
642
+ async fetchSenderIKOnce(fromAid, senderDeviceId, groupId, certFingerprint = '', rpcOptions) {
646
643
  const client = this.client;
647
644
  const peerAid = String(fromAid ?? '').trim();
648
645
  const deviceId = String(senderDeviceId ?? '').trim();
649
646
  const gid = String(groupId ?? '').trim();
650
647
  const fingerprint = String(certFingerprint ?? '').trim().toLowerCase();
651
- if (!peerAid)
648
+ if (!peerAid || rpcOptions?.deadline !== undefined && rpcOptions.deadline <= Date.now())
652
649
  return null;
653
- const fetchKey = [peerAid, deviceId, gid, fingerprint].join('#');
650
+ const fetchKey = [peerAid, deviceId, gid, fingerprint, ...(rpcOptions ? [rpcOptions.background, rpcOptions.deadline] : [])].join('#');
654
651
  const existing = this.senderIKSyncFetches.get(fetchKey);
655
652
  if (existing)
656
653
  return await existing;
@@ -658,12 +655,15 @@ export class V2E2EECoordinator {
658
655
  const started = Date.now();
659
656
  let timer;
660
657
  const timedOut = Symbol('sender-ik-timeout');
658
+ const expired = () => rpcOptions?.deadline !== undefined && rpcOptions.deadline <= Date.now();
661
659
  const fetch = async () => {
660
+ if (expired())
661
+ return null;
662
662
  try {
663
663
  const bootstrap = await client.call('message.v2.bootstrap', {
664
664
  peer_aid: peerAid,
665
665
  e2ee_wrap_capabilities: v2WrapCapabilities(),
666
- });
666
+ }, ...(rpcOptions ? [rpcOptions] : []));
667
667
  const peers = (Array.isArray(bootstrap?.peer_devices) ? bootstrap.peer_devices : []);
668
668
  for (const dev of peers)
669
669
  client._cacheV2PeerIKFromDevice(dev, peerAid);
@@ -671,14 +671,18 @@ export class V2E2EECoordinator {
671
671
  catch (exc) {
672
672
  client._clientLog.warn(`V2 sender IK 同步 bootstrap 失败: peer=${peerAid} device=${deviceId || '-'} err=${formatE2EEError(exc)}`);
673
673
  }
674
+ if (expired())
675
+ return null;
674
676
  let senderPubDer = await this.getV2SenderPubDer(peerAid, deviceId, fingerprint);
677
+ if (expired())
678
+ return null;
675
679
  if (senderPubDer || !gid)
676
680
  return senderPubDer;
677
681
  try {
678
682
  const bootstrap = await client.call('group.v2.bootstrap', {
679
683
  group_id: gid,
680
684
  e2ee_wrap_capabilities: v2WrapCapabilities(),
681
- });
685
+ }, ...(rpcOptions ? [rpcOptions] : []));
682
686
  const devices = (Array.isArray(bootstrap?.devices) ? bootstrap.devices : []);
683
687
  const audit = (Array.isArray(bootstrap?.audit_recipients) ? bootstrap.audit_recipients : []);
684
688
  for (const dev of devices)
@@ -689,6 +693,8 @@ export class V2E2EECoordinator {
689
693
  catch (exc) {
690
694
  client._clientLog.warn(`V2 sender IK 同步 group bootstrap 失败: group=${gid} peer=${peerAid} err=${formatE2EEError(exc)}`);
691
695
  }
696
+ if (expired())
697
+ return null;
692
698
  senderPubDer = await this.getV2SenderPubDer(peerAid, deviceId, fingerprint);
693
699
  return senderPubDer;
694
700
  };
@@ -696,7 +702,7 @@ export class V2E2EECoordinator {
696
702
  const result = await Promise.race([
697
703
  fetch(),
698
704
  new Promise((resolve) => {
699
- timer = setTimeout(() => resolve(timedOut), V2_SENDER_IK_SYNC_FETCH_TIMEOUT_MS);
705
+ timer = setTimeout(() => resolve(timedOut), Math.max(0, Math.min(V2_SENDER_IK_SYNC_FETCH_TIMEOUT_MS, (rpcOptions?.deadline ?? Infinity) - Date.now())));
700
706
  }),
701
707
  ]);
702
708
  if (result === timedOut) {
@@ -924,10 +930,11 @@ export class V2E2EECoordinator {
924
930
  }
925
931
  else {
926
932
  this.targetSetCache.delete(to);
927
- const bs = await client.call('message.v2.bootstrap', {
933
+ const bootstrapParams = {
928
934
  peer_aid: to,
929
935
  e2ee_wrap_capabilities: v2WrapCapabilities(),
930
- });
936
+ };
937
+ const bs = await (opts.background === undefined && opts.deadline === undefined ? client.call('message.v2.bootstrap', bootstrapParams) : client.call('message.v2.bootstrap', bootstrapParams, { background: opts.background, deadline: opts.deadline }));
931
938
  if (typeof client._primeBootstrapPeerCerts === 'function') {
932
939
  await client._primeBootstrapPeerCerts(bs, to);
933
940
  }
@@ -995,10 +1002,11 @@ export class V2E2EECoordinator {
995
1002
  }
996
1003
  else {
997
1004
  this.targetSetCache.delete(client._aid);
998
- const selfBs = await client.call('message.v2.bootstrap', {
1005
+ const selfParams = {
999
1006
  peer_aid: client._aid,
1000
1007
  e2ee_wrap_capabilities: v2WrapCapabilities(),
1001
- });
1008
+ };
1009
+ const selfBs = await (opts.background === undefined && opts.deadline === undefined ? client.call('message.v2.bootstrap', selfParams) : client.call('message.v2.bootstrap', selfParams, { background: opts.background, deadline: opts.deadline }));
1002
1010
  if (typeof client._primeBootstrapPeerCerts === 'function') {
1003
1011
  await client._primeBootstrapPeerCerts(selfBs, client._aid);
1004
1012
  }
@@ -1114,9 +1122,11 @@ export class V2E2EECoordinator {
1114
1122
  protectedHeaders: opts?.protectedHeaders,
1115
1123
  context: opts?.context,
1116
1124
  needRender: opts?.needRender,
1125
+ background: opts?.background,
1126
+ deadline: opts?.deadline,
1117
1127
  useCache,
1118
1128
  });
1119
- const result = await client.call('message.send', {
1129
+ const request = {
1120
1130
  to: toAid,
1121
1131
  payload: envelope,
1122
1132
  message_id: messageId,
@@ -1127,7 +1137,8 @@ export class V2E2EECoordinator {
1127
1137
  encrypt: false,
1128
1138
  need_render: opts?.needRender ?? true,
1129
1139
  _skip_send_result_envelope: true,
1130
- });
1140
+ };
1141
+ const result = await (opts?.background === undefined && opts?.deadline === undefined ? client.call('message.send', request) : client.call('message.send', request, { background: opts?.background, deadline: opts?.deadline }));
1131
1142
  client._clientLog.debug(`message.v2.send ok: to=${toAid}, use_cache=${useCache}, seq=${String((isJsonObject(result) ? result.seq : '') ?? '')}`);
1132
1143
  return result;
1133
1144
  };
@@ -2503,6 +2514,8 @@ export class V2E2EECoordinator {
2503
2514
  protectedHeaders: opts?.protectedHeaders,
2504
2515
  context: opts?.context,
2505
2516
  needRender: opts?.needRender,
2517
+ background: opts?.background,
2518
+ deadline: opts?.deadline,
2506
2519
  useCache,
2507
2520
  });
2508
2521
  const result = await client.call('group.v2.send', withExplicitGroupAid({
@@ -2511,7 +2524,7 @@ export class V2E2EECoordinator {
2511
2524
  ...(opts?.ttl !== undefined ? { ttl: opts.ttl } : {}),
2512
2525
  ...(opts?.messageClass !== undefined ? { message_class: opts.messageClass } : {}),
2513
2526
  ...(opts?.protectedHeaders ? { protected_headers: opts.protectedHeaders } : {}),
2514
- }, groupAid));
2527
+ }, groupAid), ...(opts?.background !== undefined || opts?.deadline !== undefined ? [{ background: opts?.background, deadline: opts?.deadline }] : []));
2515
2528
  client._clientLog.debug(`group.v2.send ok: group=${gid}, use_cache=${useCache}, seq=${String((isJsonObject(result) ? result.seq : '') ?? '')}`);
2516
2529
  return result;
2517
2530
  };
@@ -2575,7 +2588,7 @@ export class V2E2EECoordinator {
2575
2588
  const bs = await client.call('group.v2.bootstrap', {
2576
2589
  group_id: groupId,
2577
2590
  e2ee_wrap_capabilities: v2WrapCapabilities(),
2578
- });
2591
+ }, ...(opts.background !== undefined || opts.deadline !== undefined ? [{ background: opts.background, deadline: opts.deadline }] : []));
2579
2592
  allDevices = (Array.isArray(bs.devices) ? bs.devices : []);
2580
2593
  auditRecipientsRaw = (Array.isArray(bs.audit_recipients) ? bs.audit_recipients : []);
2581
2594
  epoch = Number(bs.epoch ?? 0) || 0;