@agentunion/fastaun-browser 0.4.12 → 0.4.13
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 +27 -0
- package/_packed_docs/CHANGELOG.md +27 -0
- package/_packed_docs/sdk/09-group-rpc-manual.md +10 -12
- package/_packed_docs/sdk/09-message-rpc-manual.md +6 -7
- package/dist/auth.d.ts +2 -0
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +98 -9
- package/dist/auth.js.map +1 -1
- package/dist/bundle.js +298 -40
- package/dist/client/delivery.d.ts +3 -0
- package/dist/client/delivery.d.ts.map +1 -1
- package/dist/client/delivery.js +117 -7
- package/dist/client/delivery.js.map +1 -1
- package/dist/client/rpc-pipeline.d.ts.map +1 -1
- package/dist/client/rpc-pipeline.js +8 -3
- package/dist/client/rpc-pipeline.js.map +1 -1
- package/dist/client/v2-e2ee.d.ts.map +1 -1
- package/dist/client/v2-e2ee.js +67 -8
- package/dist/client/v2-e2ee.js.map +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +31 -3
- package/dist/client.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/bundle.js
CHANGED
|
@@ -454,7 +454,7 @@ var init_indexeddb_store = __esm({
|
|
|
454
454
|
});
|
|
455
455
|
|
|
456
456
|
// src/version.ts
|
|
457
|
-
var VERSION = "0.4.
|
|
457
|
+
var VERSION = "0.4.13";
|
|
458
458
|
|
|
459
459
|
// src/types.ts
|
|
460
460
|
var ConnectionState = /* @__PURE__ */ ((ConnectionState2) => {
|
|
@@ -1838,6 +1838,31 @@ var _noopLog4 = { error: () => {
|
|
|
1838
1838
|
}, debug: () => {
|
|
1839
1839
|
} };
|
|
1840
1840
|
var AUN_SDK_LANG = "javascript";
|
|
1841
|
+
var SENSITIVE_RPC_LOG_KEYS = /* @__PURE__ */ new Set([
|
|
1842
|
+
"access_token",
|
|
1843
|
+
"refresh_token",
|
|
1844
|
+
"kite_token",
|
|
1845
|
+
"token"
|
|
1846
|
+
]);
|
|
1847
|
+
function redactRpcLogPayload(value, key = "", depth = 0) {
|
|
1848
|
+
const keyLower = key.toLowerCase();
|
|
1849
|
+
if (SENSITIVE_RPC_LOG_KEYS.has(keyLower) || keyLower.endsWith("_token")) {
|
|
1850
|
+
const text = String(value ?? "");
|
|
1851
|
+
return text ? `<redacted len=${text.length}>` : "";
|
|
1852
|
+
}
|
|
1853
|
+
if (depth >= 6) return "<max-depth>";
|
|
1854
|
+
if (Array.isArray(value)) {
|
|
1855
|
+
return value.map((item) => redactRpcLogPayload(item, "", depth + 1));
|
|
1856
|
+
}
|
|
1857
|
+
if (value && typeof value === "object") {
|
|
1858
|
+
const out = {};
|
|
1859
|
+
for (const [childKey, childValue] of Object.entries(value)) {
|
|
1860
|
+
out[childKey] = redactRpcLogPayload(childValue, childKey, depth + 1);
|
|
1861
|
+
}
|
|
1862
|
+
return out;
|
|
1863
|
+
}
|
|
1864
|
+
return value;
|
|
1865
|
+
}
|
|
1841
1866
|
function splitPemBundle(bundle) {
|
|
1842
1867
|
const marker = "-----END CERTIFICATE-----";
|
|
1843
1868
|
const certs = [];
|
|
@@ -2401,6 +2426,9 @@ var _AuthFlow = class _AuthFlow {
|
|
|
2401
2426
|
}
|
|
2402
2427
|
} catch (e) {
|
|
2403
2428
|
if (!(e instanceof AuthError)) throw e;
|
|
2429
|
+
if (this._refreshFailureRequiresRelogin(e)) {
|
|
2430
|
+
await this._clearCachedTokens(identity, e.message);
|
|
2431
|
+
}
|
|
2404
2432
|
}
|
|
2405
2433
|
}
|
|
2406
2434
|
const login = await this.authenticate(gatewayUrl, identity.aid);
|
|
@@ -2430,14 +2458,20 @@ var _AuthFlow = class _AuthFlow {
|
|
|
2430
2458
|
this._log.debug(`refreshCachedTokens enter: aid=${identity.aid} gateway=${gatewayUrl}`);
|
|
2431
2459
|
try {
|
|
2432
2460
|
const refreshToken = String(identity.refresh_token ?? "");
|
|
2433
|
-
if (!refreshToken)
|
|
2434
|
-
|
|
2461
|
+
if (!refreshToken) {
|
|
2462
|
+
await this._clearCachedTokens(identity, "missing refresh_token");
|
|
2463
|
+
throw new AuthError("missing refresh_token");
|
|
2464
|
+
}
|
|
2465
|
+
const refreshed = await this._refreshAccessToken(gatewayUrl, refreshToken, identity);
|
|
2435
2466
|
this._rememberTokens(identity, refreshed);
|
|
2436
2467
|
await this._validateNewCert(identity, gatewayUrl);
|
|
2437
2468
|
await this._persistIdentity(identity);
|
|
2438
2469
|
this._log.debug(`refreshCachedTokens exit: elapsed=${Date.now() - tStart}ms aid=${identity.aid}`);
|
|
2439
2470
|
return identity;
|
|
2440
2471
|
} catch (err) {
|
|
2472
|
+
if (this._refreshFailureRequiresRelogin(err)) {
|
|
2473
|
+
await this._clearCachedTokens(identity, err instanceof Error ? err.message : String(err));
|
|
2474
|
+
}
|
|
2441
2475
|
this._log.debug(`refreshCachedTokens exit (error): elapsed=${Date.now() - tStart}ms err=${err instanceof Error ? err.message : String(err)}`);
|
|
2442
2476
|
throw err;
|
|
2443
2477
|
}
|
|
@@ -2518,12 +2552,12 @@ var _AuthFlow = class _AuthFlow {
|
|
|
2518
2552
|
method,
|
|
2519
2553
|
params
|
|
2520
2554
|
});
|
|
2521
|
-
this._log.debug(`short RPC request full: ${requestPayload}`);
|
|
2555
|
+
this._log.debug(`short RPC request full: ${JSON.stringify(redactRpcLogPayload(JSON.parse(requestPayload)))}`);
|
|
2522
2556
|
ws.send(requestPayload);
|
|
2523
2557
|
return;
|
|
2524
2558
|
}
|
|
2525
2559
|
globalThis.clearTimeout(timeout);
|
|
2526
|
-
this._log.debug(`short RPC response full: method=${method} ${JSON.stringify(msg)}`);
|
|
2560
|
+
this._log.debug(`short RPC response full: method=${method} ${JSON.stringify(redactRpcLogPayload(msg))}`);
|
|
2527
2561
|
try {
|
|
2528
2562
|
ws.close();
|
|
2529
2563
|
} catch {
|
|
@@ -2538,7 +2572,7 @@ var _AuthFlow = class _AuthFlow {
|
|
|
2538
2572
|
return;
|
|
2539
2573
|
}
|
|
2540
2574
|
if (result.success === false) {
|
|
2541
|
-
reject(new AuthError(String(result.error ?? `${method} failed`)));
|
|
2575
|
+
reject(new AuthError(String(result.error ?? `${method} failed`), { data: result }));
|
|
2542
2576
|
return;
|
|
2543
2577
|
}
|
|
2544
2578
|
resolve(result);
|
|
@@ -2674,12 +2708,28 @@ var _AuthFlow = class _AuthFlow {
|
|
|
2674
2708
|
return phase2;
|
|
2675
2709
|
}
|
|
2676
2710
|
/** 刷新 access token */
|
|
2677
|
-
async _refreshAccessToken(gatewayUrl, refreshToken) {
|
|
2678
|
-
const
|
|
2679
|
-
refresh_token: refreshToken
|
|
2680
|
-
|
|
2711
|
+
async _refreshAccessToken(gatewayUrl, refreshToken, identity) {
|
|
2712
|
+
const params = {
|
|
2713
|
+
refresh_token: refreshToken,
|
|
2714
|
+
sdk_lang: AUN_SDK_LANG,
|
|
2715
|
+
sdk_version: VERSION
|
|
2716
|
+
};
|
|
2717
|
+
if (identity) {
|
|
2718
|
+
const aid = String(identity.aid ?? "").trim();
|
|
2719
|
+
const deviceId = String(identity.device_id ?? "").trim();
|
|
2720
|
+
const slotId = String(identity.slot_id ?? "").trim();
|
|
2721
|
+
const accessToken = String(identity.access_token ?? "").trim();
|
|
2722
|
+
if (aid) params.aid = aid;
|
|
2723
|
+
if (deviceId) params.device_id = deviceId;
|
|
2724
|
+
if (slotId) params.slot_id = slotId;
|
|
2725
|
+
if (accessToken) params.access_token = accessToken;
|
|
2726
|
+
if (typeof identity.access_token_expires_at === "number") {
|
|
2727
|
+
params.access_token_expires_at = identity.access_token_expires_at;
|
|
2728
|
+
}
|
|
2729
|
+
}
|
|
2730
|
+
const result = await this._shortRpc(gatewayUrl, "auth.refresh_token", params);
|
|
2681
2731
|
if (!result.success) {
|
|
2682
|
-
throw new AuthError(String(result.error ?? "refresh failed"));
|
|
2732
|
+
throw new AuthError(String(result.error ?? "refresh failed"), { data: result });
|
|
2683
2733
|
}
|
|
2684
2734
|
return result;
|
|
2685
2735
|
}
|
|
@@ -3012,6 +3062,35 @@ var _AuthFlow = class _AuthFlow {
|
|
|
3012
3062
|
const activeCert = authResult.active_cert;
|
|
3013
3063
|
if (typeof activeCert === "string" && activeCert) identity._pending_active_cert = activeCert;
|
|
3014
3064
|
}
|
|
3065
|
+
_refreshFailureRequiresRelogin(err) {
|
|
3066
|
+
if (!(err instanceof AuthError)) return false;
|
|
3067
|
+
const data = err.data;
|
|
3068
|
+
if (isJsonObject(data)) {
|
|
3069
|
+
if (data.relogin_required === true) return true;
|
|
3070
|
+
const error = String(data.error ?? "").trim().toLowerCase();
|
|
3071
|
+
return ["missing refresh_token", "invalid_or_expired_refresh_token", "refresh not supported"].includes(error);
|
|
3072
|
+
}
|
|
3073
|
+
const message = err.message.trim().toLowerCase();
|
|
3074
|
+
return ["missing refresh_token", "invalid_or_expired_refresh_token", "refresh not supported"].includes(message);
|
|
3075
|
+
}
|
|
3076
|
+
async _clearCachedTokens(identity, reason = "") {
|
|
3077
|
+
const aid = String(identity.aid ?? "");
|
|
3078
|
+
const hadToken = Boolean(
|
|
3079
|
+
identity.access_token || identity.refresh_token || identity.kite_token || identity.token || identity.access_token_expires_at
|
|
3080
|
+
);
|
|
3081
|
+
if (!hadToken) return;
|
|
3082
|
+
identity.access_token = "";
|
|
3083
|
+
identity.refresh_token = "";
|
|
3084
|
+
identity.kite_token = "";
|
|
3085
|
+
identity.token = "";
|
|
3086
|
+
identity.access_token_expires_at = 0;
|
|
3087
|
+
try {
|
|
3088
|
+
await this._persistIdentity(identity);
|
|
3089
|
+
this._log.warn(`cleared cached tokens after refresh failure: aid=${aid} reason=${reason}`);
|
|
3090
|
+
} catch (persistErr) {
|
|
3091
|
+
this._log.warn(`failed to persist token cleanup: aid=${aid} err=${persistErr instanceof Error ? persistErr.message : String(persistErr)}`);
|
|
3092
|
+
}
|
|
3093
|
+
}
|
|
3015
3094
|
/** 验证服务端返回的 new_cert,通过后正式接受 */
|
|
3016
3095
|
async _validateNewCert(identity, gatewayUrl = "") {
|
|
3017
3096
|
const newCertPem = identity._pending_new_cert;
|
|
@@ -3712,10 +3791,6 @@ var PENDING_ORDERED_LIMIT = 5e4;
|
|
|
3712
3791
|
var GROUP_RECALL_SEEN_LIMIT = 1e4;
|
|
3713
3792
|
var APP_MESSAGE_ENVELOPE_KEYS = [
|
|
3714
3793
|
"module_id",
|
|
3715
|
-
"message_id",
|
|
3716
|
-
"id",
|
|
3717
|
-
"seq",
|
|
3718
|
-
"msg_seq",
|
|
3719
3794
|
"message_type",
|
|
3720
3795
|
"type",
|
|
3721
3796
|
"kind",
|
|
@@ -3728,15 +3803,18 @@ var APP_MESSAGE_ENVELOPE_KEYS = [
|
|
|
3728
3803
|
"group_id",
|
|
3729
3804
|
"timestamp",
|
|
3730
3805
|
"created_at",
|
|
3731
|
-
"t_server",
|
|
3732
3806
|
"encrypted",
|
|
3733
|
-
"
|
|
3734
|
-
"
|
|
3735
|
-
"
|
|
3736
|
-
"
|
|
3737
|
-
"device_id",
|
|
3738
|
-
"slot_id"
|
|
3807
|
+
"context",
|
|
3808
|
+
"protected_headers",
|
|
3809
|
+
"headers",
|
|
3810
|
+
"payload_type"
|
|
3739
3811
|
];
|
|
3812
|
+
var APP_SEND_ENVELOPE_METHODS = /* @__PURE__ */ new Set([
|
|
3813
|
+
"message.send",
|
|
3814
|
+
"group.send",
|
|
3815
|
+
"message.thought.put",
|
|
3816
|
+
"group.thought.put"
|
|
3817
|
+
]);
|
|
3740
3818
|
var APP_GROUP_EVENT_ENVELOPE_KEYS = [
|
|
3741
3819
|
"module_id",
|
|
3742
3820
|
"event_id",
|
|
@@ -3847,13 +3925,51 @@ var MessageDeliveryEngine = class {
|
|
|
3847
3925
|
}
|
|
3848
3926
|
return payload;
|
|
3849
3927
|
}
|
|
3928
|
+
envelopeMetadata(value) {
|
|
3929
|
+
let source = value;
|
|
3930
|
+
if (source && typeof source === "object") {
|
|
3931
|
+
const maybeHeaders = source;
|
|
3932
|
+
if (typeof maybeHeaders.toObject === "function") source = maybeHeaders.toObject();
|
|
3933
|
+
}
|
|
3934
|
+
if (!isJsonObject(source)) return void 0;
|
|
3935
|
+
const out = {};
|
|
3936
|
+
for (const [key, item] of Object.entries(source)) {
|
|
3937
|
+
if (key === "_auth") continue;
|
|
3938
|
+
out[key] = item;
|
|
3939
|
+
}
|
|
3940
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
3941
|
+
}
|
|
3850
3942
|
appMessageEnvelope(payload) {
|
|
3851
3943
|
if (!isJsonObject(payload)) return {};
|
|
3852
3944
|
const message = payload;
|
|
3945
|
+
const body = isJsonObject(message.payload) ? message.payload : {};
|
|
3853
3946
|
const envelope = {};
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3947
|
+
const firstValue = (...values) => {
|
|
3948
|
+
for (const value of values) {
|
|
3949
|
+
if (value === void 0 || value === null) continue;
|
|
3950
|
+
if (typeof value === "string" && !value.trim()) continue;
|
|
3951
|
+
return value;
|
|
3952
|
+
}
|
|
3953
|
+
return void 0;
|
|
3954
|
+
};
|
|
3955
|
+
const setIfPresent = (key, value) => {
|
|
3956
|
+
if (value === void 0 || value === null) return;
|
|
3957
|
+
if (typeof value === "string" && !value.trim()) return;
|
|
3958
|
+
envelope[key] = value;
|
|
3959
|
+
};
|
|
3960
|
+
setIfPresent("from", firstValue(message.from, message.from_aid, message.sender_aid));
|
|
3961
|
+
setIfPresent("to", firstValue(message.to, message.to_aid));
|
|
3962
|
+
setIfPresent("group_id", message.group_id);
|
|
3963
|
+
setIfPresent("type", firstValue(body.type, message.type, message.message_type, message.payload_type));
|
|
3964
|
+
setIfPresent("kind", firstValue(body.kind, message.kind));
|
|
3965
|
+
setIfPresent("version", firstValue(body.version, message.version));
|
|
3966
|
+
setIfPresent("timestamp", firstValue(message.timestamp, message.created_at, message.t_server));
|
|
3967
|
+
if ("encrypted" in message) envelope.encrypted = Boolean(message.encrypted);
|
|
3968
|
+
const context = this.envelopeMetadata(message.context);
|
|
3969
|
+
if (context) envelope.context = context;
|
|
3970
|
+
const protectedHeaders = this.envelopeMetadata(message.protected_headers) ?? this.envelopeMetadata(message.headers);
|
|
3971
|
+
if (protectedHeaders) envelope.protected_headers = protectedHeaders;
|
|
3972
|
+
setIfPresent("payload_type", firstValue(message.payload_type, protectedHeaders?.payload_type));
|
|
3857
3973
|
return envelope;
|
|
3858
3974
|
}
|
|
3859
3975
|
isGroupScopedEvent(event) {
|
|
@@ -3874,6 +3990,53 @@ var MessageDeliveryEngine = class {
|
|
|
3874
3990
|
result.envelope = this.appMessageEnvelope(result);
|
|
3875
3991
|
return result;
|
|
3876
3992
|
}
|
|
3993
|
+
sendResultEnvelope(method, params, result, encrypted) {
|
|
3994
|
+
if (!APP_SEND_ENVELOPE_METHODS.has(method)) return {};
|
|
3995
|
+
const body = isJsonObject(params.payload) ? params.payload : {};
|
|
3996
|
+
const resultObj = isJsonObject(result) ? result : {};
|
|
3997
|
+
const envelope = {};
|
|
3998
|
+
const firstValue = (...values) => {
|
|
3999
|
+
for (const value of values) {
|
|
4000
|
+
if (value === void 0 || value === null) continue;
|
|
4001
|
+
if (typeof value === "string" && !value.trim()) continue;
|
|
4002
|
+
return value;
|
|
4003
|
+
}
|
|
4004
|
+
return void 0;
|
|
4005
|
+
};
|
|
4006
|
+
const setIfPresent = (key, value) => {
|
|
4007
|
+
if (value === void 0 || value === null) return;
|
|
4008
|
+
if (typeof value === "string" && !value.trim()) return;
|
|
4009
|
+
envelope[key] = value;
|
|
4010
|
+
};
|
|
4011
|
+
setIfPresent("from", this.runtime.client._aid);
|
|
4012
|
+
if (method.startsWith("message.")) {
|
|
4013
|
+
setIfPresent("to", params.to);
|
|
4014
|
+
} else {
|
|
4015
|
+
setIfPresent("group_id", params.group_id);
|
|
4016
|
+
}
|
|
4017
|
+
setIfPresent("type", firstValue(body.type, params.type, params.message_type, params.payload_type));
|
|
4018
|
+
setIfPresent("kind", firstValue(body.kind, params.kind));
|
|
4019
|
+
setIfPresent("version", firstValue(body.version, params.version));
|
|
4020
|
+
setIfPresent("timestamp", firstValue(params.timestamp, resultObj.timestamp, resultObj.created_at, resultObj.t_server, Date.now()));
|
|
4021
|
+
envelope.encrypted = Boolean(encrypted);
|
|
4022
|
+
const context = this.envelopeMetadata(params.context);
|
|
4023
|
+
if (context) envelope.context = context;
|
|
4024
|
+
const protectedHeaders = this.envelopeMetadata(params.protected_headers) ?? this.envelopeMetadata(params.headers);
|
|
4025
|
+
if (protectedHeaders) envelope.protected_headers = protectedHeaders;
|
|
4026
|
+
setIfPresent("payload_type", firstValue(params.payload_type, protectedHeaders?.payload_type, body.type));
|
|
4027
|
+
return envelope;
|
|
4028
|
+
}
|
|
4029
|
+
attachSendResultEnvelope(method, params, result, encrypted) {
|
|
4030
|
+
if (!APP_SEND_ENVELOPE_METHODS.has(method) || !isJsonObject(result)) return result;
|
|
4031
|
+
const out = { ...result };
|
|
4032
|
+
out.envelope = this.sendResultEnvelope(method, params, out, encrypted);
|
|
4033
|
+
if ("payload" in params) {
|
|
4034
|
+
out.payload = params.payload;
|
|
4035
|
+
} else if ("content" in params) {
|
|
4036
|
+
out.payload = params.content;
|
|
4037
|
+
}
|
|
4038
|
+
return out;
|
|
4039
|
+
}
|
|
3877
4040
|
attachAppGroupEventEnvelope(payload) {
|
|
3878
4041
|
if (!isJsonObject(payload)) return payload;
|
|
3879
4042
|
const result = { ...payload };
|
|
@@ -5455,6 +5618,8 @@ var RpcPipeline = class {
|
|
|
5455
5618
|
async callImpl(method, params) {
|
|
5456
5619
|
const client = this.runtime.client;
|
|
5457
5620
|
const p = this.preflight(method, params).params;
|
|
5621
|
+
const skipSendResultEnvelope = Boolean(p._skip_send_result_envelope);
|
|
5622
|
+
delete p._skip_send_result_envelope;
|
|
5458
5623
|
if (method === "message.send") {
|
|
5459
5624
|
const encrypt = p.encrypt !== void 0 ? p.encrypt : true;
|
|
5460
5625
|
delete p.encrypt;
|
|
@@ -5518,12 +5683,12 @@ var RpcPipeline = class {
|
|
|
5518
5683
|
const pullGateKey = this.pullGateKeyForCall(method, p);
|
|
5519
5684
|
if (pullGateKey) {
|
|
5520
5685
|
return await this.runPullSerialized(pullGateKey, async () => {
|
|
5521
|
-
return await this.callImplInner(method, p);
|
|
5686
|
+
return await this.callImplInner(method, p, skipSendResultEnvelope);
|
|
5522
5687
|
});
|
|
5523
5688
|
}
|
|
5524
|
-
return await this.callImplInner(method, p);
|
|
5689
|
+
return await this.callImplInner(method, p, skipSendResultEnvelope);
|
|
5525
5690
|
}
|
|
5526
|
-
async callImplInner(method, p) {
|
|
5691
|
+
async callImplInner(method, p, skipSendResultEnvelope = false) {
|
|
5527
5692
|
const client = this.runtime.client;
|
|
5528
5693
|
if (method === "message.pull") {
|
|
5529
5694
|
await client._ensureV2SessionReady("message.pull");
|
|
@@ -5571,6 +5736,14 @@ var RpcPipeline = class {
|
|
|
5571
5736
|
const callTimeout = NON_IDEMPOTENT_METHODS.has(method) ? NON_IDEMPOTENT_TIMEOUT : void 0;
|
|
5572
5737
|
let result = callTimeout ? await client._transport.call(method, p, callTimeout) : await client._transport.call(method, p);
|
|
5573
5738
|
result = await this.postprocessResult(method, p, result);
|
|
5739
|
+
if (!skipSendResultEnvelope) {
|
|
5740
|
+
result = client._delivery.attachSendResultEnvelope(
|
|
5741
|
+
method,
|
|
5742
|
+
p,
|
|
5743
|
+
result,
|
|
5744
|
+
Boolean(p.encrypted)
|
|
5745
|
+
);
|
|
5746
|
+
}
|
|
5574
5747
|
return result;
|
|
5575
5748
|
}
|
|
5576
5749
|
preflight(method, params) {
|
|
@@ -10633,17 +10806,34 @@ var V2E2EECoordinator = class {
|
|
|
10633
10806
|
return client.call("message.send", {
|
|
10634
10807
|
to: toAid,
|
|
10635
10808
|
payload: envelope,
|
|
10636
|
-
encrypt: false
|
|
10809
|
+
encrypt: false,
|
|
10810
|
+
_skip_send_result_envelope: true
|
|
10637
10811
|
});
|
|
10638
10812
|
};
|
|
10639
10813
|
try {
|
|
10640
|
-
|
|
10814
|
+
const result = await attempt(true);
|
|
10815
|
+
return client._delivery.attachSendResultEnvelope("message.send", {
|
|
10816
|
+
to: toAid,
|
|
10817
|
+
payload,
|
|
10818
|
+
message_id: opts?.messageId,
|
|
10819
|
+
timestamp: opts?.timestamp,
|
|
10820
|
+
protected_headers: opts?.protectedHeaders,
|
|
10821
|
+
context: opts?.context
|
|
10822
|
+
}, result, true);
|
|
10641
10823
|
} catch (exc) {
|
|
10642
10824
|
const excCode = exc?.code;
|
|
10643
10825
|
if (V2_RETRYABLE_CODES.has(excCode)) {
|
|
10644
10826
|
client._clientLog.debug(`V2 P2P speculative send rejected (code=${excCode}), refreshing bootstrap`);
|
|
10645
10827
|
this.deleteBootstrapCacheEntry(toAid);
|
|
10646
|
-
|
|
10828
|
+
const result = await attempt(false);
|
|
10829
|
+
return client._delivery.attachSendResultEnvelope("message.send", {
|
|
10830
|
+
to: toAid,
|
|
10831
|
+
payload,
|
|
10832
|
+
message_id: opts?.messageId,
|
|
10833
|
+
timestamp: opts?.timestamp,
|
|
10834
|
+
protected_headers: opts?.protectedHeaders,
|
|
10835
|
+
context: opts?.context
|
|
10836
|
+
}, result, true);
|
|
10647
10837
|
}
|
|
10648
10838
|
throw exc;
|
|
10649
10839
|
}
|
|
@@ -10810,7 +11000,14 @@ var V2E2EECoordinator = class {
|
|
|
10810
11000
|
client._saveSeqTrackerState();
|
|
10811
11001
|
}
|
|
10812
11002
|
}
|
|
10813
|
-
return
|
|
11003
|
+
return client._delivery.attachSendResultEnvelope("group.send", {
|
|
11004
|
+
group_id: gid,
|
|
11005
|
+
payload,
|
|
11006
|
+
message_id: opts?.messageId,
|
|
11007
|
+
timestamp: opts?.timestamp,
|
|
11008
|
+
protected_headers: opts?.protectedHeaders,
|
|
11009
|
+
context: opts?.context
|
|
11010
|
+
}, result, true);
|
|
10814
11011
|
} catch (exc) {
|
|
10815
11012
|
const excCode = exc?.code;
|
|
10816
11013
|
if (V2_RETRYABLE_CODES.has(excCode)) {
|
|
@@ -10826,7 +11023,14 @@ var V2E2EECoordinator = class {
|
|
|
10826
11023
|
client._saveSeqTrackerState();
|
|
10827
11024
|
}
|
|
10828
11025
|
}
|
|
10829
|
-
return
|
|
11026
|
+
return client._delivery.attachSendResultEnvelope("group.send", {
|
|
11027
|
+
group_id: gid,
|
|
11028
|
+
payload,
|
|
11029
|
+
message_id: opts?.messageId,
|
|
11030
|
+
timestamp: opts?.timestamp,
|
|
11031
|
+
protected_headers: opts?.protectedHeaders,
|
|
11032
|
+
context: opts?.context
|
|
11033
|
+
}, result, true);
|
|
10830
11034
|
}
|
|
10831
11035
|
throw exc;
|
|
10832
11036
|
}
|
|
@@ -11007,13 +11211,27 @@ var V2E2EECoordinator = class {
|
|
|
11007
11211
|
return result;
|
|
11008
11212
|
};
|
|
11009
11213
|
try {
|
|
11010
|
-
|
|
11214
|
+
const result = await attempt(true);
|
|
11215
|
+
return client._delivery.attachSendResultEnvelope("message.thought.put", {
|
|
11216
|
+
...params,
|
|
11217
|
+
to: toAid,
|
|
11218
|
+
payload,
|
|
11219
|
+
thought_id: thoughtId,
|
|
11220
|
+
timestamp
|
|
11221
|
+
}, result, true);
|
|
11011
11222
|
} catch (exc) {
|
|
11012
11223
|
const excCode = Number(exc?.code);
|
|
11013
11224
|
if (V2_RETRYABLE_CODES.has(excCode)) {
|
|
11014
11225
|
client._clientLog.debug(`V2 P2P thought put speculative rejected (code=${String(excCode)}), refreshing bootstrap`);
|
|
11015
11226
|
this.deleteBootstrapCacheEntry(toAid);
|
|
11016
|
-
|
|
11227
|
+
const result = await attempt(false);
|
|
11228
|
+
return client._delivery.attachSendResultEnvelope("message.thought.put", {
|
|
11229
|
+
...params,
|
|
11230
|
+
to: toAid,
|
|
11231
|
+
payload,
|
|
11232
|
+
thought_id: thoughtId,
|
|
11233
|
+
timestamp
|
|
11234
|
+
}, result, true);
|
|
11017
11235
|
}
|
|
11018
11236
|
throw exc;
|
|
11019
11237
|
}
|
|
@@ -11063,13 +11281,27 @@ var V2E2EECoordinator = class {
|
|
|
11063
11281
|
return result;
|
|
11064
11282
|
};
|
|
11065
11283
|
try {
|
|
11066
|
-
|
|
11284
|
+
const result = await attempt(true);
|
|
11285
|
+
return client._delivery.attachSendResultEnvelope("group.thought.put", {
|
|
11286
|
+
...params,
|
|
11287
|
+
group_id: groupId,
|
|
11288
|
+
payload,
|
|
11289
|
+
thought_id: thoughtId,
|
|
11290
|
+
timestamp
|
|
11291
|
+
}, result, true);
|
|
11067
11292
|
} catch (exc) {
|
|
11068
11293
|
const excCode = Number(exc?.code);
|
|
11069
11294
|
if (V2_RETRYABLE_CODES.has(excCode)) {
|
|
11070
11295
|
client._clientLog.debug(`V2 group thought put speculative rejected (code=${String(excCode)}), refreshing bootstrap`);
|
|
11071
11296
|
this.deleteBootstrapCacheEntry(`group:${groupId}`);
|
|
11072
|
-
|
|
11297
|
+
const result = await attempt(false);
|
|
11298
|
+
return client._delivery.attachSendResultEnvelope("group.thought.put", {
|
|
11299
|
+
...params,
|
|
11300
|
+
group_id: groupId,
|
|
11301
|
+
payload,
|
|
11302
|
+
thought_id: thoughtId,
|
|
11303
|
+
timestamp
|
|
11304
|
+
}, result, true);
|
|
11073
11305
|
}
|
|
11074
11306
|
throw exc;
|
|
11075
11307
|
}
|
|
@@ -15246,6 +15478,20 @@ function _v2ConcatBytes(...parts) {
|
|
|
15246
15478
|
function formatCaughtError2(error) {
|
|
15247
15479
|
return error instanceof Error ? error : String(error);
|
|
15248
15480
|
}
|
|
15481
|
+
var RELOGIN_REFRESH_ERRORS = /* @__PURE__ */ new Set([
|
|
15482
|
+
"missing refresh_token",
|
|
15483
|
+
"invalid_or_expired_refresh_token",
|
|
15484
|
+
"refresh not supported"
|
|
15485
|
+
]);
|
|
15486
|
+
function authErrorRequiresRelogin(error) {
|
|
15487
|
+
const data = error.data;
|
|
15488
|
+
if (isJsonObject(data)) {
|
|
15489
|
+
if (data.relogin_required === true) return true;
|
|
15490
|
+
const code = String(data.error ?? "").trim().toLowerCase();
|
|
15491
|
+
if (RELOGIN_REFRESH_ERRORS.has(code)) return true;
|
|
15492
|
+
}
|
|
15493
|
+
return RELOGIN_REFRESH_ERRORS.has(error.message.trim().toLowerCase());
|
|
15494
|
+
}
|
|
15249
15495
|
function v2E2eeMeta2(envelope) {
|
|
15250
15496
|
const suite = String(envelope.suite ?? "");
|
|
15251
15497
|
const modeSuite = String(envelope.suite ?? "unknown");
|
|
@@ -16660,16 +16906,28 @@ var _AUNClient = class _AUNClient {
|
|
|
16660
16906
|
this._tokenRefreshFailures = 0;
|
|
16661
16907
|
} catch (exc) {
|
|
16662
16908
|
if (exc instanceof AuthError) {
|
|
16909
|
+
if (authErrorRequiresRelogin(exc)) {
|
|
16910
|
+
this._clientLog.warn(`token refresh requires relogin, stopping refresh loop and triggering reconnect: ${exc.message}`);
|
|
16911
|
+
await this._dispatcher.publish("token.refresh_exhausted", {
|
|
16912
|
+
aid: this._identity?.aid ?? null,
|
|
16913
|
+
consecutive_failures: 1,
|
|
16914
|
+
last_error: String(exc),
|
|
16915
|
+
relogin_required: true
|
|
16916
|
+
});
|
|
16917
|
+
this._tokenRefreshFailures = 0;
|
|
16918
|
+
await this._handleTransportDisconnect(new Error("token refresh relogin required, triggering reconnect"));
|
|
16919
|
+
return;
|
|
16920
|
+
}
|
|
16663
16921
|
this._tokenRefreshFailures++;
|
|
16664
16922
|
if (this._tokenRefreshFailures >= 3) {
|
|
16665
|
-
this._clientLog.warn(`token
|
|
16666
|
-
this._dispatcher.publish("token.refresh_exhausted", {
|
|
16923
|
+
this._clientLog.warn(`token refresh failed ${this._tokenRefreshFailures} consecutive times, stopping refresh loop and triggering reconnect`);
|
|
16924
|
+
await this._dispatcher.publish("token.refresh_exhausted", {
|
|
16667
16925
|
aid: this._identity?.aid ?? null,
|
|
16668
16926
|
consecutive_failures: this._tokenRefreshFailures,
|
|
16669
16927
|
last_error: String(exc)
|
|
16670
16928
|
});
|
|
16671
16929
|
this._tokenRefreshFailures = 0;
|
|
16672
|
-
this._handleTransportDisconnect(new Error("token refresh exhausted, triggering reconnect"));
|
|
16930
|
+
await this._handleTransportDisconnect(new Error("token refresh exhausted, triggering reconnect"));
|
|
16673
16931
|
return;
|
|
16674
16932
|
}
|
|
16675
16933
|
this._clientLog.warn(`token refresh failed (${this._tokenRefreshFailures}/3), next retry: ${String(exc)}`);
|
|
@@ -13,10 +13,13 @@ export declare class MessageDeliveryEngine {
|
|
|
13
13
|
isInstanceScopedMessageEvent(event: string): boolean;
|
|
14
14
|
attachCurrentInstanceContext(payload: EventPayload): EventPayload;
|
|
15
15
|
normalizePublishedMessagePayload(event: string, payload: EventPayload): EventPayload;
|
|
16
|
+
private envelopeMetadata;
|
|
16
17
|
appMessageEnvelope(payload: EventPayload): JsonObject;
|
|
17
18
|
isGroupScopedEvent(event: string): boolean;
|
|
18
19
|
appGroupEventEnvelope(payload: EventPayload): JsonObject;
|
|
19
20
|
attachAppMessageEnvelope(payload: EventPayload): EventPayload;
|
|
21
|
+
sendResultEnvelope(method: string, params: RpcParams, result: unknown, encrypted: boolean): JsonObject;
|
|
22
|
+
attachSendResultEnvelope(method: string, params: RpcParams, result: unknown, encrypted: boolean): unknown;
|
|
20
23
|
attachAppGroupEventEnvelope(payload: EventPayload): EventPayload;
|
|
21
24
|
stripInternalSenderDeviceFields(payload: EventPayload): EventPayload;
|
|
22
25
|
recallEventFromMessage(message: EventPayload): JsonObject | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delivery.d.ts","sourceRoot":"","sources":["../../src/client/delivery.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,OAAO,EAAgB,KAAK,UAAU,EAAkB,KAAK,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAC1G,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{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