@agentunion/fastaun 0.5.24 → 0.5.25
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 +29 -0
- package/_packed_docs/CHANGELOG.md +29 -0
- package/_packed_docs/TS/346/263/250/345/206/214/350/207/252/345/212/250/347/273/221/345/256/232Owner/347/232/204E2E/351/252/214/350/257/201/344/273/243/347/240/201.md +196 -0
- package/_packed_docs/protocol/Ownership/345/215/217/350/256/256/345/256/232/344/271/2112.1.md +2 -2
- package/_packed_docs/sdk/0.5.24-SDK/345/272/224/347/224/250/351/233/206/346/210/220/346/214/207/345/215/227.md +401 -0
- package/_packed_docs/sdk/0.5.24-SDK/345/274/200/345/217/221/344/270/216/347/247/273/346/244/215/346/214/207/345/215/227.md +354 -0
- package/_packed_docs/sdk/AUN_DOCS_GUIDE.md +4 -0
- package/_packed_docs/sdk/INDEX.md +9 -0
- package/dist/agent-md.d.ts +1 -0
- package/dist/agent-md.js +38 -10
- package/dist/agent-md.js.map +1 -1
- package/dist/auth.d.ts +1 -0
- package/dist/auth.js +44 -10
- package/dist/auth.js.map +1 -1
- package/dist/client/delivery.d.ts +3 -0
- package/dist/client/delivery.js +197 -47
- package/dist/client/delivery.js.map +1 -1
- package/dist/client/rpc-pipeline.js +10 -0
- package/dist/client/rpc-pipeline.js.map +1 -1
- package/dist/client/v2-e2ee.js +17 -5
- package/dist/client/v2-e2ee.js.map +1 -1
- package/dist/client.d.ts +1 -0
- package/dist/client.js +43 -25
- package/dist/client.js.map +1 -1
- package/dist/group-fs.js +5 -0
- package/dist/group-fs.js.map +1 -1
- package/dist/ownership-v21.d.ts +2 -0
- package/dist/ownership-v21.js +61 -30
- package/dist/ownership-v21.js.map +1 -1
- package/dist/tools/cross-sdk-agent.d.ts +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
package/dist/client.js
CHANGED
|
@@ -352,7 +352,9 @@ function createAgentMdManagerForRuntime(opts) {
|
|
|
352
352
|
entitySignerResolver: opts.fetchEntitySigner,
|
|
353
353
|
gatewayResolver: async (aid) => {
|
|
354
354
|
const gatewayUrl = await opts.gateway.resolve(aid);
|
|
355
|
-
opts.
|
|
355
|
+
const localAid = opts.ownerAid();
|
|
356
|
+
if (localAid && aid.slice(aid.indexOf('.') + 1).trim().toLowerCase() === localAid.slice(localAid.indexOf('.') + 1).trim().toLowerCase())
|
|
357
|
+
opts.gateway.set(gatewayUrl);
|
|
356
358
|
return gatewayUrl;
|
|
357
359
|
},
|
|
358
360
|
accessTokenResolver: async (aid, gatewayUrl) => {
|
|
@@ -446,7 +448,7 @@ function createAgentMdManagerForRuntime(opts) {
|
|
|
446
448
|
}
|
|
447
449
|
if (!opts.gateway.get()) {
|
|
448
450
|
try {
|
|
449
|
-
opts.gateway.set(await opts.gateway.resolve(target));
|
|
451
|
+
opts.gateway.set(await opts.gateway.resolve(opts.ownerAid() ?? target));
|
|
450
452
|
}
|
|
451
453
|
catch { /* best effort before cert fetch */ }
|
|
452
454
|
}
|
|
@@ -763,6 +765,7 @@ export class AUNClient {
|
|
|
763
765
|
/** Gateway URL */
|
|
764
766
|
_gatewayUrl = null;
|
|
765
767
|
_gatewayCandidates = [];
|
|
768
|
+
_peerGatewayCache = new Map();
|
|
766
769
|
/** 是否正在关闭 */
|
|
767
770
|
_closing = false;
|
|
768
771
|
_disconnecting = false;
|
|
@@ -1360,6 +1363,7 @@ export class AUNClient {
|
|
|
1360
1363
|
this._certCache.clear();
|
|
1361
1364
|
this._gatewayUrl = null;
|
|
1362
1365
|
this._gatewayCandidates = [];
|
|
1366
|
+
this._peerGatewayCache.clear();
|
|
1363
1367
|
this._deviceId = aid.deviceId || getDeviceId(nextConfig.aunPath);
|
|
1364
1368
|
this._slotId = aid.slotId || 'default';
|
|
1365
1369
|
const debugFlag = nextConfig.debug;
|
|
@@ -1522,6 +1526,7 @@ export class AUNClient {
|
|
|
1522
1526
|
}
|
|
1523
1527
|
/** 关闭连接 */
|
|
1524
1528
|
async close() {
|
|
1529
|
+
this._peerGatewayCache.clear();
|
|
1525
1530
|
return this._lifecycle.close();
|
|
1526
1531
|
}
|
|
1527
1532
|
/**
|
|
@@ -2667,9 +2672,11 @@ export class AUNClient {
|
|
|
2667
2672
|
on(event, handler) {
|
|
2668
2673
|
const tStart = Date.now();
|
|
2669
2674
|
this._clientLog.debug(`on enter: event=${event}`);
|
|
2675
|
+
const messageEvent = event === 'message.received' || event === 'message.recalled' || event === 'message.batch';
|
|
2676
|
+
const hadMessageConsumer = messageEvent && [...this._dispatcher._snapshotApplicationHandlers(['message.received', 'message.recalled', 'message.batch']).values()].some((handlers) => handlers.length > 0);
|
|
2670
2677
|
const result = this._dispatcher.subscribe(event, handler);
|
|
2671
|
-
if (
|
|
2672
|
-
if (this._p2pPeerPullEnabled)
|
|
2678
|
+
if (messageEvent) {
|
|
2679
|
+
if (this._p2pPeerPullEnabled && !hadMessageConsumer)
|
|
2673
2680
|
this._delivery.refreshPendingPeers();
|
|
2674
2681
|
this._delivery.requestBackgroundPullRecovery();
|
|
2675
2682
|
}
|
|
@@ -4701,20 +4708,15 @@ export class AUNClient {
|
|
|
4701
4708
|
return gateways[0];
|
|
4702
4709
|
}
|
|
4703
4710
|
async _resolveOwnershipCertificateGateway(aid) {
|
|
4704
|
-
const issuer = aid.slice(aid.indexOf('.') + 1);
|
|
4705
|
-
if (issuer === this._aid?.slice(this._aid.indexOf('.') + 1))
|
|
4711
|
+
const issuer = aid.slice(aid.indexOf('.') + 1).trim().toLowerCase();
|
|
4712
|
+
if (issuer === this._aid?.slice(this._aid.indexOf('.') + 1).trim().toLowerCase())
|
|
4706
4713
|
return this._resolveGatewayForAid(aid);
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
}
|
|
4713
|
-
catch (error) {
|
|
4714
|
-
lastError = error;
|
|
4715
|
-
}
|
|
4714
|
+
try {
|
|
4715
|
+
return await this._resolveGatewayForAid(aid);
|
|
4716
|
+
}
|
|
4717
|
+
catch (error) {
|
|
4718
|
+
throw ownershipFailure('unavailable', error instanceof Error ? error.message : 'signer Gateway discovery failed', true);
|
|
4716
4719
|
}
|
|
4717
|
-
throw ownershipFailure('unavailable', lastError instanceof Error ? lastError.message : 'signer Gateway discovery failed', true);
|
|
4718
4720
|
}
|
|
4719
4721
|
/** 发现并缓存全部 Gateway 候选,供首连和自动重连故障转移使用。 */
|
|
4720
4722
|
async _resolveGatewayCandidatesForAid(aid) {
|
|
@@ -4722,17 +4724,26 @@ export class AUNClient {
|
|
|
4722
4724
|
if (!resolvedAid) {
|
|
4723
4725
|
throw new StateError('gateway discovery requires a loaded AID');
|
|
4724
4726
|
}
|
|
4727
|
+
const dotIdx = resolvedAid.indexOf('.');
|
|
4728
|
+
const issuerDomain = (dotIdx >= 0 ? resolvedAid.slice(dotIdx + 1) : resolvedAid).trim().toLowerCase();
|
|
4729
|
+
const currentAid = this._aid;
|
|
4730
|
+
const sameIssuer = currentAid !== null && issuerDomain === currentAid.slice(currentAid.indexOf('.') + 1).trim().toLowerCase();
|
|
4725
4731
|
const discovery = this._discovery;
|
|
4726
4732
|
const tokenStore = this._tokenStore;
|
|
4727
4733
|
const discoveryIsCurrent = () => (this._discovery === discovery
|
|
4728
4734
|
&& this._tokenStore === tokenStore
|
|
4729
4735
|
&& !this._closing);
|
|
4730
|
-
if (this._gatewayCandidates.length > 0)
|
|
4736
|
+
if (sameIssuer && this._gatewayCandidates.length > 0)
|
|
4731
4737
|
return [...this._gatewayCandidates];
|
|
4732
|
-
if (this._gatewayUrl) {
|
|
4738
|
+
if (sameIssuer && this._gatewayUrl) {
|
|
4733
4739
|
this._gatewayCandidates = [this._gatewayUrl];
|
|
4734
4740
|
return [...this._gatewayCandidates];
|
|
4735
4741
|
}
|
|
4742
|
+
if (!sameIssuer) {
|
|
4743
|
+
const cached = this._peerGatewayCache.get(issuerDomain);
|
|
4744
|
+
if (cached)
|
|
4745
|
+
return [...cached];
|
|
4746
|
+
}
|
|
4736
4747
|
try {
|
|
4737
4748
|
const loadMetadata = tokenStore.loadMetadata;
|
|
4738
4749
|
const metadata = typeof loadMetadata === 'function'
|
|
@@ -4744,16 +4755,19 @@ export class AUNClient {
|
|
|
4744
4755
|
const cachedGateway = cachedList[0]
|
|
4745
4756
|
?? (isJsonObject(metadata) ? String(metadata.gateway_url ?? '').trim() : '');
|
|
4746
4757
|
if (cachedGateway) {
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
|
|
4758
|
+
const gatewayUrls = [...new Set([cachedGateway, ...cachedList])];
|
|
4759
|
+
if (sameIssuer) {
|
|
4760
|
+
this._gatewayCandidates = gatewayUrls;
|
|
4761
|
+
this._gatewayUrl = gatewayUrls[0];
|
|
4762
|
+
}
|
|
4763
|
+
else
|
|
4764
|
+
this._peerGatewayCache.set(issuerDomain, gatewayUrls);
|
|
4765
|
+
return [...gatewayUrls];
|
|
4750
4766
|
}
|
|
4751
4767
|
}
|
|
4752
4768
|
catch {
|
|
4753
4769
|
// 缓存读取失败不影响发现流程。
|
|
4754
4770
|
}
|
|
4755
|
-
const dotIdx = resolvedAid.indexOf('.');
|
|
4756
|
-
const issuerDomain = dotIdx >= 0 ? resolvedAid.slice(dotIdx + 1) : resolvedAid;
|
|
4757
4771
|
const portSuffix = this._configModel.discoveryPort ? `:${this._configModel.discoveryPort}` : '';
|
|
4758
4772
|
const aidUrl = `https://${resolvedAid}${portSuffix}/.well-known/aun-gateway`;
|
|
4759
4773
|
const gatewayDomainUrl = `https://gateway.${issuerDomain}${portSuffix}/.well-known/aun-gateway`;
|
|
@@ -4773,9 +4787,13 @@ export class AUNClient {
|
|
|
4773
4787
|
const gatewayUrls = [...new Set(discovered.map((item) => String(item ?? '').trim()).filter(Boolean))];
|
|
4774
4788
|
if (gatewayUrls.length === 0)
|
|
4775
4789
|
throw new ValidationError('gateway discovery returned no candidates');
|
|
4776
|
-
this._gatewayCandidates = gatewayUrls;
|
|
4777
4790
|
const gateway = gatewayUrls[0];
|
|
4778
|
-
|
|
4791
|
+
if (sameIssuer) {
|
|
4792
|
+
this._gatewayCandidates = gatewayUrls;
|
|
4793
|
+
this._gatewayUrl = gateway;
|
|
4794
|
+
}
|
|
4795
|
+
else
|
|
4796
|
+
this._peerGatewayCache.set(issuerDomain, gatewayUrls);
|
|
4779
4797
|
try {
|
|
4780
4798
|
const saveMetadata = tokenStore.saveMetadata;
|
|
4781
4799
|
if (typeof saveMetadata === 'function') {
|