claude-simple 0.2.27 → 0.2.28

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/client.js CHANGED
@@ -4,6 +4,7 @@ import { startAutoUpdate } from './src/auto-update.js';
4
4
  import { WebSocket } from 'ws';
5
5
  import os from 'os';
6
6
  import crypto from 'crypto';
7
+ import zlib from 'zlib';
7
8
  import { promises as fs, watch as watchFs } from 'fs';
8
9
  import path from 'path';
9
10
 
@@ -408,8 +409,26 @@ function connect() {
408
409
  }
409
410
 
410
411
  const body = await res.text();
411
- // Body is always decoded text here — length must match UTF-8 bytes.
412
- headers['content-length'] = String(Buffer.byteLength(body));
412
+ const raw = Buffer.from(body, 'utf8');
413
+ // Large JSON (session history) is gzip+base64 on the control channel so
414
+ // Hub→phone does not wait on an uncompressed multi-MB WS frame.
415
+ if (raw.length >= 4096) {
416
+ try {
417
+ const zipped = zlib.gzipSync(raw, { level: 4 });
418
+ if (zipped.length < raw.length * 0.95) {
419
+ sendControl({
420
+ type: 'http-res',
421
+ reqId: msg.reqId,
422
+ status: res.status,
423
+ headers,
424
+ body: zipped.toString('base64'),
425
+ encoding: 'gzip',
426
+ });
427
+ return;
428
+ }
429
+ } catch { /* fall through to plain text */ }
430
+ }
431
+ headers['content-length'] = String(raw.length);
413
432
  sendControl({
414
433
  type: 'http-res',
415
434
  reqId: msg.reqId,