@agentunion/fastaun 0.5.17 → 0.5.18
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/CHANGELOG.md +41 -0
- package/_packed_docs/CHANGELOG.md +41 -0
- package/_packed_docs/INDEX.md +28 -3
- package/_packed_docs/KITE_DOCS_GUIDE.md +11 -5
- package/_packed_docs/agent.md/SCHEMA.md +37 -18
- 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 +23 -17
- package/_packed_docs/aun/346/265/213/350/257/225/350/277/220/350/241/214/346/214/207/345/215/227.md +4 -2
- package/_packed_docs/protocol/01-/350/272/253/344/273/275/344/270/216/345/207/255/350/257/201/345/215/217/350/256/256-auth.md +95 -6
- package/_packed_docs/protocol/07-/351/224/231/350/257/257/347/240/201/344/270/216/347/212/266/346/200/201/346/234/272.md +19 -4
- package/_packed_docs/protocol/11-Storage-/345/255/220/345/215/217/350/256/256.md +25 -2
- package/_packed_docs/sdk/06-API/346/211/213/345/206/214.md +42 -4
- package/_packed_docs/sdk/09-storage-rpc-manual.md +25 -4
- package/_packed_docs/sdk/INDEX.md +3 -2
- package/dist/agent-md-schema.js +2 -0
- package/dist/agent-md-schema.js.map +1 -1
- package/dist/agent-md.d.ts +1 -1
- package/dist/agent-md.js +3 -1
- package/dist/agent-md.js.map +1 -1
- package/dist/aid-store.d.ts +58 -0
- package/dist/aid-store.js +234 -3
- package/dist/aid-store.js.map +1 -1
- package/dist/aid.d.ts +17 -1
- package/dist/aid.js +48 -2
- package/dist/aid.js.map +1 -1
- package/dist/client/delivery.d.ts +2 -0
- package/dist/client/delivery.js +124 -19
- package/dist/client/delivery.js.map +1 -1
- package/dist/client/rpc-pipeline.js +7 -9
- package/dist/client/rpc-pipeline.js.map +1 -1
- package/dist/client/v2-e2ee.d.ts +7 -1
- package/dist/client/v2-e2ee.js +815 -515
- package/dist/client/v2-e2ee.js.map +1 -1
- package/dist/client.d.ts +3 -0
- package/dist/client.js +67 -7
- package/dist/client.js.map +1 -1
- package/dist/facades.d.ts +2 -0
- package/dist/facades.js +6 -0
- package/dist/facades.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/ownership-proof.d.ts +40 -0
- package/dist/ownership-proof.js +140 -0
- package/dist/ownership-proof.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +8 -8
package/dist/client.d.ts
CHANGED
|
@@ -140,6 +140,9 @@ export declare class AUNClient {
|
|
|
140
140
|
private _pushProcessQueues;
|
|
141
141
|
/** P2P pull 进行中到达的纯通知 push 上界;pull gate 释放后需要补拉一次。 */
|
|
142
142
|
private _pendingP2pPullUpper;
|
|
143
|
+
/** P2P pending pull 的延迟重试定时器及次数,覆盖服务端异步落库窗口。 */
|
|
144
|
+
private _pendingP2pPullTimers;
|
|
145
|
+
private _pendingP2pPullRetries;
|
|
143
146
|
/** 缺 sender IK 时暂存原始 V2 消息,后台补齐 IK 后重试解密。 */
|
|
144
147
|
private _v2SenderIKPending;
|
|
145
148
|
/** sender IK 后台补齐任务去重。 */
|
package/dist/client.js
CHANGED
|
@@ -120,6 +120,8 @@ const DEFAULT_SESSION_OPTIONS = {
|
|
|
120
120
|
const RECONNECT_MIN_BASE_DELAY_MS = 1_000;
|
|
121
121
|
const RECONNECT_MAX_BASE_DELAY_MS = 64_000;
|
|
122
122
|
const TOKEN_REFRESH_CHECK_INTERVAL_MS = 30_000;
|
|
123
|
+
const PENDING_P2P_PULL_DELAY_MS = 100;
|
|
124
|
+
const PENDING_P2P_PULL_MAX_RETRIES = 20;
|
|
123
125
|
const MAX_NOTIFY_PAYLOAD_SIZE = 64 * 1024;
|
|
124
126
|
// P1-23: 非幂等方法使用更长超时(35s),避免 SDK 10s 超时 < gateway 30s 处理时间
|
|
125
127
|
const NON_IDEMPOTENT_TIMEOUT_MS = 35_000;
|
|
@@ -494,6 +496,9 @@ export class AUNClient {
|
|
|
494
496
|
_pushProcessQueues = new Map();
|
|
495
497
|
/** P2P pull 进行中到达的纯通知 push 上界;pull gate 释放后需要补拉一次。 */
|
|
496
498
|
_pendingP2pPullUpper = new Map();
|
|
499
|
+
/** P2P pending pull 的延迟重试定时器及次数,覆盖服务端异步落库窗口。 */
|
|
500
|
+
_pendingP2pPullTimers = new Map();
|
|
501
|
+
_pendingP2pPullRetries = new Map();
|
|
497
502
|
/** 缺 sender IK 时暂存原始 V2 消息,后台补齐 IK 后重试解密。 */
|
|
498
503
|
_v2SenderIKPending = new Map();
|
|
499
504
|
/** sender IK 后台补齐任务去重。 */
|
|
@@ -1876,6 +1881,7 @@ export class AUNClient {
|
|
|
1876
1881
|
const previous = this._pendingP2pPullUpper.get(ns) ?? 0;
|
|
1877
1882
|
if (seq > previous) {
|
|
1878
1883
|
this._pendingP2pPullUpper.set(ns, seq);
|
|
1884
|
+
this._pendingP2pPullRetries.delete(ns);
|
|
1879
1885
|
}
|
|
1880
1886
|
this._clientLog.debug(`P2P pending pull upper recorded: ns=${ns}, seq=${seq}, previous=${previous}, contiguous=${this._seqTracker.getContiguousSeq(ns)}`);
|
|
1881
1887
|
}
|
|
@@ -1890,6 +1896,7 @@ export class AUNClient {
|
|
|
1890
1896
|
const contig = this._seqTracker.getContiguousSeq(ns);
|
|
1891
1897
|
if (upperSeq <= contig) {
|
|
1892
1898
|
this._pendingP2pPullUpper.delete(ns);
|
|
1899
|
+
this._pendingP2pPullRetries.delete(ns);
|
|
1893
1900
|
this._clientLog.debug(`P2P pending pull upper already covered: ns=${ns}, upper_seq=${upperSeq}, contiguous=${contig}, reason=${reason}`);
|
|
1894
1901
|
return false;
|
|
1895
1902
|
}
|
|
@@ -1897,11 +1904,49 @@ export class AUNClient {
|
|
|
1897
1904
|
this._clientLog.debug(`P2P pending pull postponed: ns=${ns}, upper_seq=${upperSeq}, contiguous=${contig}, state=${this._state}, closing=${this._closing}, reason=${reason}`);
|
|
1898
1905
|
return false;
|
|
1899
1906
|
}
|
|
1900
|
-
if (this.
|
|
1907
|
+
if (this._sessionOptions.background_sync === false)
|
|
1901
1908
|
return false;
|
|
1902
|
-
this.
|
|
1903
|
-
|
|
1904
|
-
|
|
1909
|
+
if (this._rpcPipeline?.hasPullActivity?.(ns, false) || this._pendingP2pPullTimers.has(ns))
|
|
1910
|
+
return false;
|
|
1911
|
+
const retries = (this._pendingP2pPullRetries.get(ns) ?? 0) + 1;
|
|
1912
|
+
if (retries > PENDING_P2P_PULL_MAX_RETRIES) {
|
|
1913
|
+
this._pendingP2pPullUpper.delete(ns);
|
|
1914
|
+
this._pendingP2pPullRetries.delete(ns);
|
|
1915
|
+
this._clientLog.warn(`P2P pending pull retries exhausted: ns=${ns}, upper_seq=${upperSeq}, contiguous=${contig}, reason=${reason}`);
|
|
1916
|
+
return false;
|
|
1917
|
+
}
|
|
1918
|
+
this._pendingP2pPullRetries.set(ns, retries);
|
|
1919
|
+
this._clientLog.info(`P2P pending push follow-up pull scheduled: ns=${ns}, upper_seq=${upperSeq}, contiguous=${contig}, retry=${retries}, reason=${reason}`);
|
|
1920
|
+
const timer = setTimeout(() => {
|
|
1921
|
+
this._pendingP2pPullTimers.delete(ns);
|
|
1922
|
+
const currentUpper = this._pendingP2pPullUpper.get(ns) ?? 0;
|
|
1923
|
+
if (currentUpper <= 0 || currentUpper <= this._seqTracker.getContiguousSeq(ns)) {
|
|
1924
|
+
this._pendingP2pPullUpper.delete(ns);
|
|
1925
|
+
this._pendingP2pPullRetries.delete(ns);
|
|
1926
|
+
return;
|
|
1927
|
+
}
|
|
1928
|
+
// 暂时移除上界,避免 synthetic push 被 hasPullActivity 当成自身的 pending pull 拦截。
|
|
1929
|
+
this._pendingP2pPullUpper.delete(ns);
|
|
1930
|
+
const retry = this._onV2PushNotification({ seq: currentUpper }, 'v2')
|
|
1931
|
+
.then(() => {
|
|
1932
|
+
if (this._seqTracker.getContiguousSeq(ns) < currentUpper) {
|
|
1933
|
+
const pending = this._pendingP2pPullUpper.get(ns) ?? 0;
|
|
1934
|
+
if (currentUpper > pending)
|
|
1935
|
+
this._pendingP2pPullUpper.set(ns, currentUpper);
|
|
1936
|
+
}
|
|
1937
|
+
})
|
|
1938
|
+
.catch((error) => {
|
|
1939
|
+
const pending = this._pendingP2pPullUpper.get(ns) ?? 0;
|
|
1940
|
+
if (currentUpper > pending)
|
|
1941
|
+
this._pendingP2pPullUpper.set(ns, currentUpper);
|
|
1942
|
+
throw error;
|
|
1943
|
+
})
|
|
1944
|
+
.finally(() => {
|
|
1945
|
+
this._schedulePendingP2pPullIfNeeded(ns, 'pending-pull-retry-complete');
|
|
1946
|
+
});
|
|
1947
|
+
this._safeAsync(retry);
|
|
1948
|
+
}, PENDING_P2P_PULL_DELAY_MS);
|
|
1949
|
+
this._pendingP2pPullTimers.set(ns, timer);
|
|
1905
1950
|
return true;
|
|
1906
1951
|
}
|
|
1907
1952
|
_markPublishedSeq(ns, seq) {
|
|
@@ -2213,6 +2258,10 @@ export class AUNClient {
|
|
|
2213
2258
|
}
|
|
2214
2259
|
const paramsHash = String(cs.params_hash ?? '');
|
|
2215
2260
|
const timestamp = String(cs.timestamp ?? '');
|
|
2261
|
+
const signedAt = Number(timestamp) * 1000;
|
|
2262
|
+
if (!/^\d+$/.test(timestamp) || !Number.isSafeInteger(Number(timestamp)) || signedAt < new Date(certObj.validFrom).getTime() || signedAt > new Date(certObj.validTo).getTime()) {
|
|
2263
|
+
return false;
|
|
2264
|
+
}
|
|
2216
2265
|
const signData = Buffer.from(`${method}|${sigAid}|${timestamp}|${paramsHash}`, 'utf-8');
|
|
2217
2266
|
const sigB64 = String(cs.signature ?? '');
|
|
2218
2267
|
const pubKey = certObj.publicKey;
|
|
@@ -2441,6 +2490,10 @@ export class AUNClient {
|
|
|
2441
2490
|
this._pushedSeqs.clear();
|
|
2442
2491
|
this._pendingOrderedMsgs.clear();
|
|
2443
2492
|
this._pendingP2pPullUpper.clear();
|
|
2493
|
+
for (const timer of this._pendingP2pPullTimers.values())
|
|
2494
|
+
clearTimeout(timer);
|
|
2495
|
+
this._pendingP2pPullTimers.clear();
|
|
2496
|
+
this._pendingP2pPullRetries.clear();
|
|
2444
2497
|
this._v2SenderIKPending.clear();
|
|
2445
2498
|
this._v2SenderIKFetching.clear();
|
|
2446
2499
|
this._groupSynced.clear();
|
|
@@ -2457,6 +2510,10 @@ export class AUNClient {
|
|
|
2457
2510
|
this._pushedSeqs.clear();
|
|
2458
2511
|
this._pendingOrderedMsgs.clear();
|
|
2459
2512
|
this._pendingP2pPullUpper.clear();
|
|
2513
|
+
for (const timer of this._pendingP2pPullTimers.values())
|
|
2514
|
+
clearTimeout(timer);
|
|
2515
|
+
this._pendingP2pPullTimers.clear();
|
|
2516
|
+
this._pendingP2pPullRetries.clear();
|
|
2460
2517
|
this._v2SenderIKPending.clear();
|
|
2461
2518
|
this._v2SenderIKFetching.clear();
|
|
2462
2519
|
this._groupSynced.clear();
|
|
@@ -3279,7 +3336,10 @@ export class AUNClient {
|
|
|
3279
3336
|
if (senderDeviceId)
|
|
3280
3337
|
result.sender_device_id = senderDeviceId;
|
|
3281
3338
|
const explicitDirection = String(msg.direction ?? '').trim();
|
|
3282
|
-
|
|
3339
|
+
if (explicitDirection)
|
|
3340
|
+
result.direction = explicitDirection;
|
|
3341
|
+
else if (fromAid && fromAid !== this._aid)
|
|
3342
|
+
result.direction = 'inbound';
|
|
3283
3343
|
if (msg.device_id !== undefined)
|
|
3284
3344
|
result.device_id = msg.device_id;
|
|
3285
3345
|
attachGatewayProximity(result, msg);
|
|
@@ -3478,8 +3538,8 @@ export class AUNClient {
|
|
|
3478
3538
|
return this._delivery.onRawGroupV2MessageCreated(data, expectedVersion, inlineGeneration);
|
|
3479
3539
|
}
|
|
3480
3540
|
/** Push 通知带 payload 时的就地解密(复用 _decryptV2Message) */
|
|
3481
|
-
async _decryptV2PushMessage(data) {
|
|
3482
|
-
return await this._v2E2EE.decryptV2PushMessage(data);
|
|
3541
|
+
async _decryptV2PushMessage(data, deferStatus) {
|
|
3542
|
+
return await this._v2E2EE.decryptV2PushMessage(data, deferStatus);
|
|
3483
3543
|
}
|
|
3484
3544
|
/** 按当前 AID 发现 Gateway;用于 authenticate()/connect() 的新入口。 */
|
|
3485
3545
|
async _resolveGatewayForAid(aid) {
|