@pingagent/sdk 0.1.5 → 0.1.6

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/dist/index.js CHANGED
@@ -16,7 +16,7 @@ import {
16
16
  loadIdentity,
17
17
  saveIdentity,
18
18
  updateStoredToken
19
- } from "./chunk-V4IHFEJC.js";
19
+ } from "./chunk-OHS3SA5V.js";
20
20
  export {
21
21
  A2AAdapter,
22
22
  ContactManager,
@@ -5,7 +5,7 @@ import {
5
5
  ensureTokenValid,
6
6
  loadIdentity,
7
7
  updateStoredToken
8
- } from "./chunk-V4IHFEJC.js";
8
+ } from "./chunk-OHS3SA5V.js";
9
9
 
10
10
  // src/web-server.ts
11
11
  import * as fs from "fs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pingagent/sdk",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -50,8 +50,8 @@ const LIST_CONVERSATIONS_INTERVAL_MS = 60_000;
50
50
 
51
51
  const DEFAULT_HEARTBEAT = {
52
52
  enable: true,
53
- idleThresholdMs: 25_000,
54
- pingIntervalMs: 30_000,
53
+ idleThresholdMs: 10_000,
54
+ pingIntervalMs: 15_000,
55
55
  pongTimeoutMs: 10_000,
56
56
  maxMissedPongs: 2,
57
57
  tickMs: 5_000,
@@ -189,8 +189,6 @@ export class WsSubscription {
189
189
 
190
190
  ws.on('message', (data: Buffer | string) => {
191
191
  try {
192
- const msg = JSON.parse(data.toString());
193
-
194
192
  // Any server frame counts as activity; keep connection stable and avoid unnecessary pings.
195
193
  const state = this.heartbeatStates.get(conversationId);
196
194
  if (state) {
@@ -202,6 +200,8 @@ export class WsSubscription {
202
200
  }
203
201
  }
204
202
 
203
+ const msg = JSON.parse(data.toString());
204
+
205
205
  if (msg.type === 'ws_message' && msg.envelope) {
206
206
  const env = msg.envelope;
207
207
  if (env.sender_did !== this.opts.myDid) {
@@ -271,6 +271,14 @@ export class WsSubscription {
271
271
  continue;
272
272
  }
273
273
 
274
+ // Application-level keepalive for CDN/NAT idle timeouts (more reliable than ping/pong alone).
275
+ // Receiver can ignore this message.
276
+ try {
277
+ ws.send(JSON.stringify({ type: 'hb' }));
278
+ } catch {
279
+ // ignore; ping/pong + reconnect will handle dead sockets
280
+ }
281
+
274
282
  ws.ping();
275
283
  state.lastPingAt = now;
276
284
  const jitterFactor = 1 + (Math.random() - 0.5) * 2 * jitter;
@@ -280,7 +288,7 @@ export class WsSubscription {
280
288
  state.missedPongs += 1;
281
289
  state.pongTimeout = null;
282
290
 
283
- if (state.missedPongs > maxMissedPongs) {
291
+ if (state.missedPongs >= maxMissedPongs) {
284
292
  try {
285
293
  // Trigger close handler -> scheduleReconnect
286
294
  ws.close(1001, 'pong timeout');