@tangle-network/sandbox 0.60.83 → 0.60.85
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.
|
@@ -431,7 +431,7 @@ interface SessionGatewayStats {
|
|
|
431
431
|
*/
|
|
432
432
|
declare function calculateConnectionQuality(metrics: ConnectionMetrics, isConnected: boolean): ConnectionQuality;
|
|
433
433
|
//#endregion
|
|
434
|
-
//#region ../../../packages/sdk/dist/client-
|
|
434
|
+
//#region ../../../packages/sdk/dist/client-C_E_mxfN.d.ts
|
|
435
435
|
//#region src/session-gateway/core-types.d.ts
|
|
436
436
|
interface SubscriptionDenial {
|
|
437
437
|
channel: string;
|
|
@@ -498,13 +498,12 @@ interface SessionGatewayClientConfig$2 extends Omit<SessionGatewayClientConfig,
|
|
|
498
498
|
} //#endregion
|
|
499
499
|
//#region src/session-gateway/core.d.ts
|
|
500
500
|
declare class SessionGatewayClientCore {
|
|
501
|
+
#private;
|
|
501
502
|
private readonly initialMetrics;
|
|
502
503
|
private ws;
|
|
503
|
-
private readonly config;
|
|
504
504
|
private readonly handlers;
|
|
505
505
|
private readonly replayStateStore;
|
|
506
506
|
private readonly tokenRefresher;
|
|
507
|
-
private currentToken;
|
|
508
507
|
private state;
|
|
509
508
|
private connectedAt;
|
|
510
509
|
private hasConnectedBefore;
|
|
@@ -33,7 +33,7 @@ function calculateConnectionQuality(metrics, isConnected) {
|
|
|
33
33
|
return "good";
|
|
34
34
|
}
|
|
35
35
|
//#endregion
|
|
36
|
-
//#region ../../../packages/sdk/dist/client-
|
|
36
|
+
//#region ../../../packages/sdk/dist/client-CGwxRfro.js
|
|
37
37
|
function invokeClientCallback(name, callback, onError) {
|
|
38
38
|
try {
|
|
39
39
|
callback();
|
|
@@ -84,6 +84,8 @@ var ConnectionWaiters = class {
|
|
|
84
84
|
this.waiters.clear();
|
|
85
85
|
}
|
|
86
86
|
};
|
|
87
|
+
/** Browser-safe session gateway contracts for both SDK clients. */
|
|
88
|
+
const INITIAL_METRICS$1 = createConnectionMetrics();
|
|
87
89
|
const DEFAULT_CONFIG = {
|
|
88
90
|
transport: "websocket",
|
|
89
91
|
channels: [],
|
|
@@ -231,18 +233,16 @@ var TokenRefresher = class {
|
|
|
231
233
|
}
|
|
232
234
|
}
|
|
233
235
|
};
|
|
234
|
-
/** Browser-safe session gateway contracts for both SDK clients. */
|
|
235
|
-
const INITIAL_METRICS$1 = createConnectionMetrics();
|
|
236
236
|
const CONNECTION_ESTABLISHMENT_TIMEOUT_CODE = 4008;
|
|
237
237
|
const CONNECTION_ERROR_CODE = 4009;
|
|
238
238
|
const CONNECTION_ERROR_REASON = "WebSocket connection error";
|
|
239
239
|
var SessionGatewayClientCore = class {
|
|
240
240
|
ws = null;
|
|
241
|
-
config;
|
|
241
|
+
#config;
|
|
242
242
|
handlers;
|
|
243
243
|
replayStateStore;
|
|
244
244
|
tokenRefresher;
|
|
245
|
-
currentToken;
|
|
245
|
+
#currentToken;
|
|
246
246
|
state = "disconnected";
|
|
247
247
|
connectedAt = null;
|
|
248
248
|
hasConnectedBefore = false;
|
|
@@ -278,7 +278,7 @@ var SessionGatewayClientCore = class {
|
|
|
278
278
|
this.connectionMetrics = { ...initialMetrics };
|
|
279
279
|
if (!config.token.trim()) throw new Error("Session gateway token must not be empty");
|
|
280
280
|
const replayStorage = resolveReplayStorage(config.replayStorage);
|
|
281
|
-
this
|
|
281
|
+
this.#config = {
|
|
282
282
|
url: config.url,
|
|
283
283
|
sessionId: config.sessionId,
|
|
284
284
|
token: config.token,
|
|
@@ -299,11 +299,11 @@ var SessionGatewayClientCore = class {
|
|
|
299
299
|
connectionEstablishmentTimeoutMs: config.connectionEstablishmentTimeoutMs ?? DEFAULT_CONFIG.connectionEstablishmentTimeoutMs
|
|
300
300
|
};
|
|
301
301
|
this.handlers = config.handlers ?? {};
|
|
302
|
-
this.connectionWaiters = new ConnectionWaiters(this
|
|
303
|
-
this.replayStateStore = new ReplayStateStore(this
|
|
302
|
+
this.connectionWaiters = new ConnectionWaiters(this.#config.connectionEstablishmentTimeoutMs);
|
|
303
|
+
this.replayStateStore = new ReplayStateStore(this.#config.enableReplayPersistence, replayStorage, this.#config.replayStorageKeyPrefix, this.#config.url, this.#config.sessionId);
|
|
304
304
|
this.tokenRefresher = new TokenRefresher(config.onTokenRefresh, (token) => this.updateToken(token), this.handlers.onError);
|
|
305
|
-
this
|
|
306
|
-
if (this
|
|
305
|
+
this.#currentToken = config.token;
|
|
306
|
+
if (this.#config.enableReplayPersistence) this.loadReplayState();
|
|
307
307
|
}
|
|
308
308
|
/**
|
|
309
309
|
* Connect to the session gateway.
|
|
@@ -316,8 +316,8 @@ var SessionGatewayClientCore = class {
|
|
|
316
316
|
this.connectWebSocket();
|
|
317
317
|
}
|
|
318
318
|
connectWebSocket() {
|
|
319
|
-
const url = new URL(this
|
|
320
|
-
url.searchParams.set("token", this
|
|
319
|
+
const url = new URL(this.#config.url);
|
|
320
|
+
url.searchParams.set("token", this.#currentToken);
|
|
321
321
|
this.connectionEstablishedForSocket = false;
|
|
322
322
|
const socket = new WebSocket(url.toString());
|
|
323
323
|
this.ws = socket;
|
|
@@ -466,14 +466,14 @@ var SessionGatewayClientCore = class {
|
|
|
466
466
|
*/
|
|
467
467
|
updateToken(token) {
|
|
468
468
|
if (!token.trim()) throw new Error("Session gateway token must not be empty");
|
|
469
|
-
this
|
|
469
|
+
this.#currentToken = token;
|
|
470
470
|
if (this.state === "connected" && this.ws) this.ws.close(1e3, "Token refreshed");
|
|
471
471
|
}
|
|
472
472
|
/**
|
|
473
473
|
* Get the current auth token.
|
|
474
474
|
*/
|
|
475
475
|
getToken() {
|
|
476
|
-
return this
|
|
476
|
+
return this.#currentToken;
|
|
477
477
|
}
|
|
478
478
|
setState(state) {
|
|
479
479
|
if (this.state !== state) {
|
|
@@ -510,7 +510,7 @@ var SessionGatewayClientCore = class {
|
|
|
510
510
|
this.ws = null;
|
|
511
511
|
this.connectionEstablishedForSocket = false;
|
|
512
512
|
this.cleanup();
|
|
513
|
-
if (this
|
|
513
|
+
if (this.#config.autoReconnect && this.reconnectAttempts < this.#config.maxReconnectAttempts) {
|
|
514
514
|
this.setState("reconnecting");
|
|
515
515
|
if (this.state === "reconnecting") this.scheduleReconnect();
|
|
516
516
|
} else {
|
|
@@ -555,14 +555,14 @@ var SessionGatewayClientCore = class {
|
|
|
555
555
|
}
|
|
556
556
|
if ("id" in message && message.id) {
|
|
557
557
|
const eventId = message.id;
|
|
558
|
-
if (this
|
|
558
|
+
if (this.#config.enableDeduplication) {
|
|
559
559
|
if (this.processedEventIds.has(eventId)) {
|
|
560
560
|
this.duplicatesSkipped++;
|
|
561
561
|
return;
|
|
562
562
|
}
|
|
563
563
|
this.processedEventIds.add(eventId);
|
|
564
|
-
if (this.processedEventIds.size > this
|
|
565
|
-
const entriesToRemove = Math.floor(this
|
|
564
|
+
if (this.processedEventIds.size > this.#config.maxDeduplicationSize) {
|
|
565
|
+
const entriesToRemove = Math.floor(this.#config.maxDeduplicationSize * .1);
|
|
566
566
|
let removed = 0;
|
|
567
567
|
for (const oldId of this.processedEventIds) {
|
|
568
568
|
if (removed >= entriesToRemove) break;
|
|
@@ -585,7 +585,7 @@ var SessionGatewayClientCore = class {
|
|
|
585
585
|
if (this.lastPingSentAt) {
|
|
586
586
|
const latency = now - this.lastPingSentAt;
|
|
587
587
|
this.pingLatencyHistory.push(latency);
|
|
588
|
-
if (this.pingLatencyHistory.length > this
|
|
588
|
+
if (this.pingLatencyHistory.length > this.#config.latencyHistorySize) this.pingLatencyHistory.shift();
|
|
589
589
|
this.updateConnectionMetrics(latency, now);
|
|
590
590
|
}
|
|
591
591
|
}
|
|
@@ -719,7 +719,7 @@ var SessionGatewayClientCore = class {
|
|
|
719
719
|
return this.connectionWaiters.wait();
|
|
720
720
|
}
|
|
721
721
|
restoreSubscriptions() {
|
|
722
|
-
const channels = this
|
|
722
|
+
const channels = this.#config.channels;
|
|
723
723
|
const replayOptions = {};
|
|
724
724
|
if (this.lastEventId) replayOptions.lastEventId = this.lastEventId;
|
|
725
725
|
if (this.currentExecutionId) replayOptions.executionId = this.currentExecutionId;
|
|
@@ -743,7 +743,7 @@ var SessionGatewayClientCore = class {
|
|
|
743
743
|
this.stopPingInterval();
|
|
744
744
|
this.pingInterval = setInterval(() => {
|
|
745
745
|
this.sendPing();
|
|
746
|
-
}, this
|
|
746
|
+
}, this.#config.pingIntervalMs);
|
|
747
747
|
}
|
|
748
748
|
stopPingInterval() {
|
|
749
749
|
if (this.pingInterval) {
|
|
@@ -754,14 +754,14 @@ var SessionGatewayClientCore = class {
|
|
|
754
754
|
sendPing() {
|
|
755
755
|
if (this.ws?.readyState !== WebSocket.OPEN) return;
|
|
756
756
|
const timeSinceLastPong = this.lastPongAt ? Date.now() - this.lastPongAt : 0;
|
|
757
|
-
if (this.lastPongAt && timeSinceLastPong > this
|
|
757
|
+
if (this.lastPongAt && timeSinceLastPong > this.#config.pongTimeoutMs) {
|
|
758
758
|
this.missedPongCount++;
|
|
759
759
|
this.connectionMetrics = {
|
|
760
760
|
...this.connectionMetrics,
|
|
761
761
|
missedPongCount: this.missedPongCount
|
|
762
762
|
};
|
|
763
763
|
this.updateConnectionQuality();
|
|
764
|
-
if (this.missedPongCount >= this
|
|
764
|
+
if (this.missedPongCount >= this.#config.maxMissedPongs) {
|
|
765
765
|
this.ws?.close(4e3, "Pong timeout - connection unresponsive");
|
|
766
766
|
return;
|
|
767
767
|
}
|
|
@@ -776,8 +776,8 @@ var SessionGatewayClientCore = class {
|
|
|
776
776
|
missedPongCount: this.missedPongCount
|
|
777
777
|
};
|
|
778
778
|
this.updateConnectionQuality();
|
|
779
|
-
if (this.missedPongCount >= this
|
|
780
|
-
}, this
|
|
779
|
+
if (this.missedPongCount >= this.#config.maxMissedPongs) this.ws?.close(4e3, "Pong timeout - connection unresponsive");
|
|
780
|
+
}, this.#config.pongTimeoutMs);
|
|
781
781
|
}
|
|
782
782
|
clearPongTimeout() {
|
|
783
783
|
if (this.pongTimeout) {
|
|
@@ -788,7 +788,7 @@ var SessionGatewayClientCore = class {
|
|
|
788
788
|
scheduleReconnect() {
|
|
789
789
|
if (this.reconnectTimer) return;
|
|
790
790
|
this.reconnectAttempts++;
|
|
791
|
-
const delay = Math.min(this
|
|
791
|
+
const delay = Math.min(this.#config.initialReconnectDelayMs * 2 ** (this.reconnectAttempts - 1), this.#config.maxReconnectDelayMs);
|
|
792
792
|
const jitter = delay * .3 * (Math.random() * 2 - 1);
|
|
793
793
|
this.reconnectTimer = setTimeout(() => {
|
|
794
794
|
this.reconnectTimer = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangle-network/sandbox",
|
|
3
|
-
"version": "0.60.
|
|
3
|
+
"version": "0.60.85",
|
|
4
4
|
"description": "Client SDK for the Tangle Sandbox platform - build AI agent applications with dev containers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -154,17 +154,17 @@
|
|
|
154
154
|
"vitest": "^4.1.11",
|
|
155
155
|
"ws": "^8.20.0",
|
|
156
156
|
"yjs": "13.6.30",
|
|
157
|
-
"@products/sandbox-test-utils": "0.0.0",
|
|
158
|
-
"@tangle-network/agent-profile-materialize": "0.26.0",
|
|
159
157
|
"@repo/shared": "0.0.0",
|
|
158
|
+
"@tangle-network/agent-profile-materialize": "0.26.0",
|
|
160
159
|
"@tangle-network/cli-agent-registry": "0.10.2",
|
|
161
|
-
"@tangle-network/sdk": "4.0.16",
|
|
162
160
|
"@tangle-network/runtime-contracts": "0.19.0",
|
|
161
|
+
"@tangle-network/sdk": "4.0.16",
|
|
162
|
+
"@products/sandbox-test-utils": "0.0.0",
|
|
163
163
|
"@tangle-network/sse-core": "0.0.0"
|
|
164
164
|
},
|
|
165
165
|
"tangleRelease": {
|
|
166
|
-
"sourceSha": "
|
|
167
|
-
"mergedAt": "2026-10-
|
|
166
|
+
"sourceSha": "31981a378701b0d6db095e6459a18f887497a2aa",
|
|
167
|
+
"mergedAt": "2026-10-18T03:03:45-06:00"
|
|
168
168
|
},
|
|
169
169
|
"scripts": {
|
|
170
170
|
"build": "node scripts/build-dist.mjs",
|