@agentunion/fastaun 0.5.33 → 0.5.34
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 +30 -2
- package/README.md +28 -26
- package/_packed_docs/CHANGELOG.md +30 -2
- package/_packed_docs/INDEX.md +17 -3
- package/_packed_docs/KITE_DOCS_GUIDE.md +10 -4
- package/_packed_docs/protocol/03-Gateway-/350/277/236/346/216/245/346/250/241/345/274/217.md +58 -8
- package/_packed_docs/sdk/0.5.33-SDK/345/272/224/347/224/250/351/233/206/346/210/220/346/214/207/345/215/227.md +464 -316
- package/_packed_docs/sdk/0.5.33-SDK/345/274/200/345/217/221/344/270/216/347/247/273/346/244/215/346/214/207/345/215/227.md +499 -304
- package/_packed_docs/sdk/0.5.34-SDK/345/272/224/347/224/250/351/233/206/346/210/220/346/214/207/345/215/227.md +133 -0
- package/_packed_docs/sdk/0.5.34-SDK/345/274/200/345/217/221/344/270/216/347/247/273/346/244/215/346/214/207/345/215/227.md +107 -0
- package/_packed_docs/sdk/01-/345/277/253/351/200/237/345/274/200/345/247/213.md +16 -13
- package/_packed_docs/sdk/03-/346/240/270/345/277/203/346/246/202/345/277/265.md +13 -1
- package/_packed_docs/sdk/04-/350/277/236/346/216/245/344/270/216/350/256/244/350/257/201.md +17 -7
- package/_packed_docs/sdk/06-API/346/211/213/345/206/214.md +55 -14
- package/_packed_docs/sdk/09-collab-rpc-manual.md +48 -30
- package/_packed_docs/sdk/09-custody-api-manual.md +3 -3
- package/_packed_docs/sdk/09-group-rpc-manual.md +53 -6
- package/_packed_docs/sdk/09-message-rpc-manual.md +22 -0
- package/_packed_docs/sdk/09-meta-rpc-manual.md +2 -1
- package/_packed_docs/sdk/09-payload-reference.md +9 -8
- package/_packed_docs/sdk/09-proxy-rpc-manual.md +20 -14
- package/_packed_docs/sdk/09-storage-rpc-manual.md +1698 -1659
- package/_packed_docs/sdk/09-stream-rpc-manual.md +33 -20
- package/_packed_docs/sdk/AUN_DOCS_GUIDE.md +11 -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/272/224/347/224/250/351/233/206/346/210/220/346/214/207/345/215/227.md +53 -28
- 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 +62 -28
- package/_packed_docs/sdk/INDEX.md +21 -9
- package/_packed_docs/sdk/README.md +11 -6
- package/dist/auth.js +8 -2
- package/dist/auth.js.map +1 -1
- package/dist/client/control-messages.js +2 -2
- package/dist/client/control-messages.js.map +1 -1
- package/dist/client/delivery.d.ts +5 -0
- package/dist/client/delivery.js +146 -32
- package/dist/client/delivery.js.map +1 -1
- package/dist/client/lifecycle.js +3 -0
- package/dist/client/lifecycle.js.map +1 -1
- package/dist/client/rpc-budget.d.ts +21 -0
- package/dist/client/rpc-budget.js +82 -0
- package/dist/client/rpc-budget.js.map +1 -0
- package/dist/client/rpc-pipeline.d.ts +3 -0
- package/dist/client/rpc-pipeline.js +166 -60
- package/dist/client/rpc-pipeline.js.map +1 -1
- package/dist/client/sync-channels.d.ts +89 -0
- package/dist/client/sync-channels.js +489 -0
- package/dist/client/sync-channels.js.map +1 -0
- package/dist/client/v2-e2ee.d.ts +4 -1
- package/dist/client/v2-e2ee.js +401 -298
- package/dist/client/v2-e2ee.js.map +1 -1
- package/dist/client.d.ts +2 -0
- package/dist/client.js +63 -1
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/pubsub/binding.js +14 -1
- package/dist/pubsub/binding.js.map +1 -1
- package/dist/pubsub/channel.d.ts +4 -0
- package/dist/pubsub/channel.js +26 -0
- package/dist/pubsub/channel.js.map +1 -1
- package/dist/pubsub/client.d.ts +9 -0
- package/dist/pubsub/client.js +154 -31
- package/dist/pubsub/client.js.map +1 -1
- package/dist/pubsub/credentials.d.ts +3 -0
- package/dist/pubsub/credentials.js +57 -20
- package/dist/pubsub/credentials.js.map +1 -1
- package/dist/pubsub/index.d.ts +3 -0
- package/dist/pubsub/index.js +69 -53
- package/dist/pubsub/index.js.map +1 -1
- package/dist/pubsub/service.d.ts +3 -0
- package/dist/pubsub/service.js +167 -12
- package/dist/pubsub/service.js.map +1 -1
- package/dist/pubsub/types.d.ts +2 -0
- package/dist/storage/lowlevel.d.ts +3 -1
- package/dist/storage/lowlevel.js +13 -0
- package/dist/storage/lowlevel.js.map +1 -1
- package/dist/storage/types.d.ts +10 -0
- package/dist/storage/types.js.map +1 -1
- package/dist/storage/vfs.d.ts +3 -1
- package/dist/storage/vfs.js +2 -2
- package/dist/storage/vfs.js.map +1 -1
- package/dist/tools/cross-sdk-agent.d.ts +55 -5
- package/dist/tools/cross-sdk-agent.js +88 -21
- package/dist/tools/cross-sdk-agent.js.map +1 -1
- package/dist/transport.d.ts +12 -0
- package/dist/transport.js +91 -6
- package/dist/transport.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -263,6 +263,7 @@ export declare class AUNClient {
|
|
|
263
263
|
private _peerDirectory;
|
|
264
264
|
private _lifecycle;
|
|
265
265
|
private _rpcPipeline;
|
|
266
|
+
private _syncChannelCoordinator;
|
|
266
267
|
private _delivery;
|
|
267
268
|
private _v2E2EE;
|
|
268
269
|
private _groupState;
|
|
@@ -362,6 +363,7 @@ export declare class AUNClient {
|
|
|
362
363
|
lookupPeer(aid: string, certFingerprint?: string | null): Promise<AID>;
|
|
363
364
|
peers(): AID[];
|
|
364
365
|
/** transport 的 meta observer:吸收 gateway 注入的 _meta 字段。失败不影响业务。 */
|
|
366
|
+
private _historyChannels;
|
|
365
367
|
private _observeRpcMeta;
|
|
366
368
|
isGroupIndexStale(groupAid: string): boolean;
|
|
367
369
|
markGroupIndexFresh(groupAid: string, options: {
|
package/dist/client.js
CHANGED
|
@@ -26,6 +26,7 @@ import { AUNLogger } from './logger.js';
|
|
|
26
26
|
import { normalizeGroupId } from './group-id.js';
|
|
27
27
|
import { validateAIDFormat, validateGroupIDFormat } from './validators.js';
|
|
28
28
|
import { RPCTransport } from './transport.js';
|
|
29
|
+
import { SyncChannels } from './client/sync-channels.js';
|
|
29
30
|
import { AuthFlow } from './auth.js';
|
|
30
31
|
import { AgentMdManager, buildDefaultAgentMd, updateOwnershipAgentMd } from './agent-md.js';
|
|
31
32
|
import { AgentMdChangeCoordinator } from './agent-md-changes.js';
|
|
@@ -1050,6 +1051,7 @@ export class AUNClient {
|
|
|
1050
1051
|
_peerDirectory;
|
|
1051
1052
|
_lifecycle;
|
|
1052
1053
|
_rpcPipeline;
|
|
1054
|
+
_syncChannelCoordinator = null;
|
|
1053
1055
|
_delivery;
|
|
1054
1056
|
_v2E2EE;
|
|
1055
1057
|
_groupState;
|
|
@@ -1161,6 +1163,7 @@ export class AUNClient {
|
|
|
1161
1163
|
this._installRiskHooks();
|
|
1162
1164
|
this._transport.setClassMessageHandler((event, payload) => this._controlMessages().onPush(payload, event.includes('group.')));
|
|
1163
1165
|
this._transport.setProtocolMetaObserver((meta) => this._observeRpcMeta(meta));
|
|
1166
|
+
this._transport.setSyncControlObserver((meta, method, params) => this._historyChannels().observe(meta, method, params));
|
|
1164
1167
|
this._transport.setServiceEventVerifier((event, payload) => this._verifyIncomingServiceEvent(event, payload), () => this._identity?.aid ?? '', () => this._serviceEventIdentityVersion);
|
|
1165
1168
|
this._transport.setProtocolDisconnectCallback((err, closeCode) => this._handleTransportDisconnect(err, closeCode));
|
|
1166
1169
|
this._transport._onForegroundDrained = () => this._delivery.onForegroundPullsDrained();
|
|
@@ -1351,6 +1354,11 @@ export class AUNClient {
|
|
|
1351
1354
|
const client = new AUNClient(AID._create({ aid: aid.aid, aunPath: aid.aunPath, certPem: aid.certPem, privateKeyPem: aid.privateKeyPem,
|
|
1352
1355
|
certValid: aid.isCertValid(), privateKeyValid: aid.isPrivateKeyValid(), deviceId: this._deviceId, slotId,
|
|
1353
1356
|
verifySsl: aid.verifySsl, rootCaPath: aid.rootCaPath, debug: aid.debug, aidStore: aid._aidStore }));
|
|
1357
|
+
const identity = this._auth.loadIdentityOrNone(), token = String(identity?.access_token ?? ''), expiresAt = identity?.access_token_expires_at;
|
|
1358
|
+
if (identity?.aid === aid.aid && token.startsWith('eyJ') && token.split('.').length === 3
|
|
1359
|
+
&& typeof expiresAt === 'number' && expiresAt > Date.now() / 1000 + 30) {
|
|
1360
|
+
Object.assign(client._identity, { access_token: token, access_token_expires_at: expiresAt });
|
|
1361
|
+
}
|
|
1354
1362
|
client._ownershipOperation = true;
|
|
1355
1363
|
client._ownershipType = this.getType();
|
|
1356
1364
|
return client;
|
|
@@ -1693,6 +1701,7 @@ export class AUNClient {
|
|
|
1693
1701
|
this._installRiskHooks();
|
|
1694
1702
|
this._transport.setClassMessageHandler((event, payload) => this._controlMessages().onPush(payload, event.includes('group.')));
|
|
1695
1703
|
this._transport.setProtocolMetaObserver((meta) => this._observeRpcMeta(meta));
|
|
1704
|
+
this._transport.setSyncControlObserver((meta, method, params) => this._historyChannels().observe(meta, method, params));
|
|
1696
1705
|
this._transport.setServiceEventVerifier((event, payload) => this._verifyIncomingServiceEvent(event, payload), () => this._identity?.aid ?? '', () => this._serviceEventIdentityVersion);
|
|
1697
1706
|
this._transport.setProtocolDisconnectCallback((err, closeCode) => this._handleTransportDisconnect(err, closeCode));
|
|
1698
1707
|
this._transport._onForegroundDrained = () => this._delivery.onForegroundPullsDrained();
|
|
@@ -1748,6 +1757,56 @@ export class AUNClient {
|
|
|
1748
1757
|
return this._peerDirectory.peers();
|
|
1749
1758
|
}
|
|
1750
1759
|
/** transport 的 meta observer:吸收 gateway 注入的 _meta 字段。失败不影响业务。 */
|
|
1760
|
+
_historyChannels() {
|
|
1761
|
+
return this._syncChannelCoordinator ??= new SyncChannels({
|
|
1762
|
+
main: () => this._transport,
|
|
1763
|
+
current: () => this._state === 'ready' && !this._closing && this._transport.isConnected(),
|
|
1764
|
+
wake: () => this._delivery?.requestBackgroundPullRecovery(),
|
|
1765
|
+
owner: () => String(this._aid ?? ''),
|
|
1766
|
+
namespace: (method, params) => this._rpcPipeline.pullGateKeyForCall(method, params).split('|')[0],
|
|
1767
|
+
pendingNamespaces: () => [...this._delivery.pendingHistoryNamespaces(), ...this._rpcPipeline.pendingHistoryNamespaces()],
|
|
1768
|
+
fail: (method, params, error) => this._dispatcher.enqueue('sync.error', { namespace: params.sender_aid ? this._delivery.peerNamespace(String(params.sender_aid)) : `group:${String(params.group_id ?? params.group_aid ?? '')}`, method, code: 'OVERSIZED_MESSAGE', error: error instanceof Error ? error.message : String(error) }),
|
|
1769
|
+
create: async (parent, timeout = 35000, signal) => {
|
|
1770
|
+
const deadline = Date.now() + timeout;
|
|
1771
|
+
const dispatcher = new EventDispatcher(this._logger.for('aun_core.events'));
|
|
1772
|
+
const transport = new RPCTransport({ eventDispatcher: dispatcher, rpcBudget: this._transport.rpcBudget, syncAuxiliary: true,
|
|
1773
|
+
timeout, verifySsl: this._configModel.verifySsl, logger: this._logger.for('aun_core.transport') });
|
|
1774
|
+
transport.setSyncControlObserver((meta, method, params) => this._historyChannels().observe(meta, method, params));
|
|
1775
|
+
transport.setRequestAdmission(this._transport._requestAdmission);
|
|
1776
|
+
transport.setRequestCheck(this._transport._requestCheck);
|
|
1777
|
+
transport.setProtocolDisconnectCallback(() => this._historyChannels().auxiliaryDisconnected(transport));
|
|
1778
|
+
const abort = () => { void transport.close(); };
|
|
1779
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
1780
|
+
try {
|
|
1781
|
+
if (signal?.aborted)
|
|
1782
|
+
throw new TimeoutError('history sync cancelled', { retryable: true });
|
|
1783
|
+
const challenge = await transport.connect(this._gatewayUrl);
|
|
1784
|
+
if (Date.now() >= deadline || signal?.aborted)
|
|
1785
|
+
throw new TimeoutError('history sync deadline exceeded', { retryable: true });
|
|
1786
|
+
transport.setTimeout(Math.max(1, deadline - Date.now()));
|
|
1787
|
+
const token = AuthFlow._getCachedAccessToken(this._identity ?? {})
|
|
1788
|
+
|| AuthFlow._getCachedAccessToken(this._sessionParams ?? {});
|
|
1789
|
+
if (!token)
|
|
1790
|
+
throw new ConnectionError('auxiliary sync connection has no valid access token');
|
|
1791
|
+
const hello = await this._auth.initializeWithToken(transport, challenge, token, { deviceId: this._deviceId,
|
|
1792
|
+
slotId: this._slotId, connectionKind: 'short', shortTtlMs: 0, extraInfo: { _sync_parent: parent } });
|
|
1793
|
+
if (!isJsonObject(hello.connection) || !hello.connection.id)
|
|
1794
|
+
throw new ConnectionError('auxiliary sync connection has no identity');
|
|
1795
|
+
if (!isJsonObject(hello.negotiated_capabilities) || hello.negotiated_capabilities.elastic_connections_v1 !== true || hello.negotiated_capabilities.sync_channels_v1 !== true)
|
|
1796
|
+
throw new ConnectionError('auxiliary sync capabilities were not negotiated');
|
|
1797
|
+
return { id: String(hello.connection.id), transport, dispose: () => dispatcher.close() };
|
|
1798
|
+
}
|
|
1799
|
+
catch (error) {
|
|
1800
|
+
await transport.close();
|
|
1801
|
+
await dispatcher.close();
|
|
1802
|
+
throw error;
|
|
1803
|
+
}
|
|
1804
|
+
finally {
|
|
1805
|
+
signal?.removeEventListener('abort', abort);
|
|
1806
|
+
}
|
|
1807
|
+
},
|
|
1808
|
+
});
|
|
1809
|
+
}
|
|
1751
1810
|
_observeRpcMeta(meta) {
|
|
1752
1811
|
this._agentMdManager.observeRpcMeta(meta, this._aid);
|
|
1753
1812
|
this._groupIndexMetaCache.observeRpcMeta(meta, { localAid: this._aid ?? '' });
|
|
@@ -2081,7 +2140,7 @@ export class AUNClient {
|
|
|
2081
2140
|
return await existing;
|
|
2082
2141
|
this._entityOwnershipChecks.set(`${identity}:${aid}`, task);
|
|
2083
2142
|
}
|
|
2084
|
-
const consensus = await this.checkOwnershipConsensus(aid);
|
|
2143
|
+
const consensus = await this.checkOwnershipConsensus(aid, true);
|
|
2085
2144
|
if (consensus.status === 'consensus' && consensus.owner_aid === this._aid)
|
|
2086
2145
|
return true;
|
|
2087
2146
|
await this._completeEntityOwnership(aid, type, undefined, () => {
|
|
@@ -4560,6 +4619,7 @@ export class AUNClient {
|
|
|
4560
4619
|
// ── 内部:连接 ────────────────────────────────────────────
|
|
4561
4620
|
/** 执行一次连接流程 */
|
|
4562
4621
|
async _connectOnce(params, allowReauth, reconnectOwner, connectionOwner) {
|
|
4622
|
+
this._syncChannelCoordinator?.reset();
|
|
4563
4623
|
await this._restoreRiskState();
|
|
4564
4624
|
this._assertRiskReconnect();
|
|
4565
4625
|
this._riskNegotiated = false;
|
|
@@ -4671,6 +4731,7 @@ export class AUNClient {
|
|
|
4671
4731
|
this._migrationPending = false;
|
|
4672
4732
|
this._lastDisconnectInfo = null;
|
|
4673
4733
|
this._state = 'ready';
|
|
4734
|
+
this._historyChannels().bind(this._gatewayConnectionId, this._negotiatedCapabilities.elastic_connections_v1 === true && this._negotiatedCapabilities.sync_channels_v1 === true && params.connection_kind !== 'short');
|
|
4674
4735
|
this._connectedAt = Date.now();
|
|
4675
4736
|
if (Array.isArray(params.gateways)) {
|
|
4676
4737
|
this._gatewayCandidates = [...new Set(params.gateways
|
|
@@ -5663,6 +5724,7 @@ export class AUNClient {
|
|
|
5663
5724
|
}
|
|
5664
5725
|
/** 停止所有后台任务 */
|
|
5665
5726
|
_stopBackgroundTasks() {
|
|
5727
|
+
this._syncChannelCoordinator?.reset();
|
|
5666
5728
|
this._stopCredentialRenewal();
|
|
5667
5729
|
this._auth.invalidateStrictPkiCache();
|
|
5668
5730
|
this._certCache.clear();
|