@clawchatsai/connector 0.0.14 → 0.0.15

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.
Files changed (2) hide show
  1. package/dist/index.js +39 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -24,6 +24,8 @@ export const PLUGIN_VERSION = '0.0.13';
24
24
  const MAX_DC_MESSAGE_SIZE = 256 * 1024;
25
25
  /** Active DataChannel connections: connectionId → send function */
26
26
  const connectedClients = new Map();
27
+ /** Reassembly buffers for chunked gateway-msg from browser (large payloads like image attachments). */
28
+ const gatewayMsgChunkBuffers = new Map();
27
29
  let app = null;
28
30
  let signaling = null;
29
31
  let webrtcPeer = null;
@@ -286,6 +288,43 @@ function setupDataChannelHandler(dc, connectionId, ctx) {
286
288
  app.gatewayClient.sendToGateway(msg['payload']);
287
289
  }
288
290
  break;
291
+ case 'gateway-msg-chunk': {
292
+ // Reassemble chunked gateway messages from the browser.
293
+ // Large payloads (e.g. image attachments as base64) exceed the
294
+ // DataChannel's safe single-message limit (~64 KiB) and are split
295
+ // by the browser's transport.js into indexed chunks.
296
+ const chunkId = msg['id'];
297
+ const index = msg['index'];
298
+ const total = msg['total'];
299
+ const chunkData = msg['data'];
300
+ if (!chunkId || typeof index !== 'number' || typeof total !== 'number' || !chunkData) {
301
+ dc.send(JSON.stringify({ type: 'error', message: 'malformed gateway-msg-chunk' }));
302
+ break;
303
+ }
304
+ if (!gatewayMsgChunkBuffers.has(chunkId)) {
305
+ gatewayMsgChunkBuffers.set(chunkId, {
306
+ chunks: new Array(total),
307
+ received: 0,
308
+ total,
309
+ createdAt: Date.now(),
310
+ });
311
+ // Expire stale buffers after 30s to prevent memory leaks
312
+ setTimeout(() => gatewayMsgChunkBuffers.delete(chunkId), 30_000);
313
+ }
314
+ const buf = gatewayMsgChunkBuffers.get(chunkId);
315
+ if (!buf.chunks[index]) {
316
+ buf.chunks[index] = chunkData;
317
+ buf.received++;
318
+ }
319
+ if (buf.received === buf.total) {
320
+ gatewayMsgChunkBuffers.delete(chunkId);
321
+ const fullPayload = buf.chunks.join('');
322
+ if (app?.gatewayClient) {
323
+ app.gatewayClient.sendToGateway(fullPayload);
324
+ }
325
+ }
326
+ break;
327
+ }
289
328
  default:
290
329
  dc.send(JSON.stringify({ type: 'error', message: 'unknown message type' }));
291
330
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clawchatsai/connector",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "type": "module",
5
5
  "description": "ClawChats OpenClaw plugin — P2P tunnel + local API bridge",
6
6
  "main": "dist/index.js",