claude-threads 1.16.3 → 1.17.1

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
@@ -30303,2853 +30303,17 @@ var require_react_reconciler = __commonJS((exports, module) => {
30303
30303
  }
30304
30304
  });
30305
30305
 
30306
- // node_modules/ink/node_modules/ws/lib/constants.js
30307
- var require_constants6 = __commonJS((exports, module) => {
30308
- var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
30309
- var hasBlob = typeof Blob !== "undefined";
30310
- if (hasBlob)
30311
- BINARY_TYPES.push("blob");
30312
- module.exports = {
30313
- BINARY_TYPES,
30314
- EMPTY_BUFFER: Buffer.alloc(0),
30315
- GUID: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
30316
- hasBlob,
30317
- kForOnEventAttribute: Symbol("kIsForOnEventAttribute"),
30318
- kListener: Symbol("kListener"),
30319
- kStatusCode: Symbol("status-code"),
30320
- kWebSocket: Symbol("websocket"),
30321
- NOOP: () => {}
30322
- };
30323
- });
30324
-
30325
- // node_modules/ink/node_modules/ws/lib/buffer-util.js
30326
- var require_buffer_util2 = __commonJS((exports, module) => {
30327
- var { EMPTY_BUFFER } = require_constants6();
30328
- var FastBuffer = Buffer[Symbol.species];
30329
- function concat(list, totalLength) {
30330
- if (list.length === 0)
30331
- return EMPTY_BUFFER;
30332
- if (list.length === 1)
30333
- return list[0];
30334
- const target = Buffer.allocUnsafe(totalLength);
30335
- let offset = 0;
30336
- for (let i2 = 0;i2 < list.length; i2++) {
30337
- const buf = list[i2];
30338
- target.set(buf, offset);
30339
- offset += buf.length;
30340
- }
30341
- if (offset < totalLength) {
30342
- return new FastBuffer(target.buffer, target.byteOffset, offset);
30343
- }
30344
- return target;
30345
- }
30346
- function _mask(source, mask, output, offset, length) {
30347
- for (let i2 = 0;i2 < length; i2++) {
30348
- output[offset + i2] = source[i2] ^ mask[i2 & 3];
30349
- }
30350
- }
30351
- function _unmask(buffer, mask) {
30352
- for (let i2 = 0;i2 < buffer.length; i2++) {
30353
- buffer[i2] ^= mask[i2 & 3];
30354
- }
30355
- }
30356
- function toArrayBuffer(buf) {
30357
- if (buf.length === buf.buffer.byteLength) {
30358
- return buf.buffer;
30359
- }
30360
- return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
30361
- }
30362
- function toBuffer(data) {
30363
- toBuffer.readOnly = true;
30364
- if (Buffer.isBuffer(data))
30365
- return data;
30366
- let buf;
30367
- if (data instanceof ArrayBuffer) {
30368
- buf = new FastBuffer(data);
30369
- } else if (ArrayBuffer.isView(data)) {
30370
- buf = new FastBuffer(data.buffer, data.byteOffset, data.byteLength);
30371
- } else {
30372
- buf = Buffer.from(data);
30373
- toBuffer.readOnly = false;
30374
- }
30375
- return buf;
30376
- }
30377
- module.exports = {
30378
- concat,
30379
- mask: _mask,
30380
- toArrayBuffer,
30381
- toBuffer,
30382
- unmask: _unmask
30383
- };
30384
- if (!process.env.WS_NO_BUFFER_UTIL) {
30385
- try {
30386
- const bufferUtil = (()=>{throw new Error("Cannot require module "+"bufferutil");})();
30387
- module.exports.mask = function(source, mask, output, offset, length) {
30388
- if (length < 48)
30389
- _mask(source, mask, output, offset, length);
30390
- else
30391
- bufferUtil.mask(source, mask, output, offset, length);
30392
- };
30393
- module.exports.unmask = function(buffer, mask) {
30394
- if (buffer.length < 32)
30395
- _unmask(buffer, mask);
30396
- else
30397
- bufferUtil.unmask(buffer, mask);
30398
- };
30399
- } catch (e) {}
30400
- }
30401
- });
30402
-
30403
- // node_modules/ink/node_modules/ws/lib/limiter.js
30404
- var require_limiter2 = __commonJS((exports, module) => {
30405
- var kDone = Symbol("kDone");
30406
- var kRun = Symbol("kRun");
30407
-
30408
- class Limiter {
30409
- constructor(concurrency) {
30410
- this[kDone] = () => {
30411
- this.pending--;
30412
- this[kRun]();
30413
- };
30414
- this.concurrency = concurrency || Infinity;
30415
- this.jobs = [];
30416
- this.pending = 0;
30417
- }
30418
- add(job) {
30419
- this.jobs.push(job);
30420
- this[kRun]();
30421
- }
30422
- [kRun]() {
30423
- if (this.pending === this.concurrency)
30424
- return;
30425
- if (this.jobs.length) {
30426
- const job = this.jobs.shift();
30427
- this.pending++;
30428
- job(this[kDone]);
30429
- }
30430
- }
30431
- }
30432
- module.exports = Limiter;
30433
- });
30434
-
30435
- // node_modules/ink/node_modules/ws/lib/permessage-deflate.js
30436
- var require_permessage_deflate2 = __commonJS((exports, module) => {
30437
- var zlib = __require("zlib");
30438
- var bufferUtil = require_buffer_util2();
30439
- var Limiter = require_limiter2();
30440
- var { kStatusCode } = require_constants6();
30441
- var FastBuffer = Buffer[Symbol.species];
30442
- var TRAILER = Buffer.from([0, 0, 255, 255]);
30443
- var kPerMessageDeflate = Symbol("permessage-deflate");
30444
- var kTotalLength = Symbol("total-length");
30445
- var kCallback = Symbol("callback");
30446
- var kBuffers = Symbol("buffers");
30447
- var kError = Symbol("error");
30448
- var zlibLimiter;
30449
-
30450
- class PerMessageDeflate {
30451
- constructor(options, isServer, maxPayload) {
30452
- this._maxPayload = maxPayload | 0;
30453
- this._options = options || {};
30454
- this._threshold = this._options.threshold !== undefined ? this._options.threshold : 1024;
30455
- this._isServer = !!isServer;
30456
- this._deflate = null;
30457
- this._inflate = null;
30458
- this.params = null;
30459
- if (!zlibLimiter) {
30460
- const concurrency = this._options.concurrencyLimit !== undefined ? this._options.concurrencyLimit : 10;
30461
- zlibLimiter = new Limiter(concurrency);
30462
- }
30463
- }
30464
- static get extensionName() {
30465
- return "permessage-deflate";
30466
- }
30467
- offer() {
30468
- const params = {};
30469
- if (this._options.serverNoContextTakeover) {
30470
- params.server_no_context_takeover = true;
30471
- }
30472
- if (this._options.clientNoContextTakeover) {
30473
- params.client_no_context_takeover = true;
30474
- }
30475
- if (this._options.serverMaxWindowBits) {
30476
- params.server_max_window_bits = this._options.serverMaxWindowBits;
30477
- }
30478
- if (this._options.clientMaxWindowBits) {
30479
- params.client_max_window_bits = this._options.clientMaxWindowBits;
30480
- } else if (this._options.clientMaxWindowBits == null) {
30481
- params.client_max_window_bits = true;
30482
- }
30483
- return params;
30484
- }
30485
- accept(configurations) {
30486
- configurations = this.normalizeParams(configurations);
30487
- this.params = this._isServer ? this.acceptAsServer(configurations) : this.acceptAsClient(configurations);
30488
- return this.params;
30489
- }
30490
- cleanup() {
30491
- if (this._inflate) {
30492
- this._inflate.close();
30493
- this._inflate = null;
30494
- }
30495
- if (this._deflate) {
30496
- const callback = this._deflate[kCallback];
30497
- this._deflate.close();
30498
- this._deflate = null;
30499
- if (callback) {
30500
- callback(new Error("The deflate stream was closed while data was being processed"));
30501
- }
30502
- }
30503
- }
30504
- acceptAsServer(offers) {
30505
- const opts = this._options;
30506
- const accepted = offers.find((params) => {
30507
- if (opts.serverNoContextTakeover === false && params.server_no_context_takeover || params.server_max_window_bits && (opts.serverMaxWindowBits === false || typeof opts.serverMaxWindowBits === "number" && opts.serverMaxWindowBits > params.server_max_window_bits) || typeof opts.clientMaxWindowBits === "number" && !params.client_max_window_bits) {
30508
- return false;
30509
- }
30510
- return true;
30511
- });
30512
- if (!accepted) {
30513
- throw new Error("None of the extension offers can be accepted");
30514
- }
30515
- if (opts.serverNoContextTakeover) {
30516
- accepted.server_no_context_takeover = true;
30517
- }
30518
- if (opts.clientNoContextTakeover) {
30519
- accepted.client_no_context_takeover = true;
30520
- }
30521
- if (typeof opts.serverMaxWindowBits === "number") {
30522
- accepted.server_max_window_bits = opts.serverMaxWindowBits;
30523
- }
30524
- if (typeof opts.clientMaxWindowBits === "number") {
30525
- accepted.client_max_window_bits = opts.clientMaxWindowBits;
30526
- } else if (accepted.client_max_window_bits === true || opts.clientMaxWindowBits === false) {
30527
- delete accepted.client_max_window_bits;
30528
- }
30529
- return accepted;
30530
- }
30531
- acceptAsClient(response) {
30532
- const params = response[0];
30533
- if (this._options.clientNoContextTakeover === false && params.client_no_context_takeover) {
30534
- throw new Error('Unexpected parameter "client_no_context_takeover"');
30535
- }
30536
- if (!params.client_max_window_bits) {
30537
- if (typeof this._options.clientMaxWindowBits === "number") {
30538
- params.client_max_window_bits = this._options.clientMaxWindowBits;
30539
- }
30540
- } else if (this._options.clientMaxWindowBits === false || typeof this._options.clientMaxWindowBits === "number" && params.client_max_window_bits > this._options.clientMaxWindowBits) {
30541
- throw new Error('Unexpected or invalid parameter "client_max_window_bits"');
30542
- }
30543
- return params;
30544
- }
30545
- normalizeParams(configurations) {
30546
- configurations.forEach((params) => {
30547
- Object.keys(params).forEach((key) => {
30548
- let value = params[key];
30549
- if (value.length > 1) {
30550
- throw new Error(`Parameter "${key}" must have only a single value`);
30551
- }
30552
- value = value[0];
30553
- if (key === "client_max_window_bits") {
30554
- if (value !== true) {
30555
- const num = +value;
30556
- if (!Number.isInteger(num) || num < 8 || num > 15) {
30557
- throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
30558
- }
30559
- value = num;
30560
- } else if (!this._isServer) {
30561
- throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
30562
- }
30563
- } else if (key === "server_max_window_bits") {
30564
- const num = +value;
30565
- if (!Number.isInteger(num) || num < 8 || num > 15) {
30566
- throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
30567
- }
30568
- value = num;
30569
- } else if (key === "client_no_context_takeover" || key === "server_no_context_takeover") {
30570
- if (value !== true) {
30571
- throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
30572
- }
30573
- } else {
30574
- throw new Error(`Unknown parameter "${key}"`);
30575
- }
30576
- params[key] = value;
30577
- });
30578
- });
30579
- return configurations;
30580
- }
30581
- decompress(data, fin, callback) {
30582
- zlibLimiter.add((done) => {
30583
- this._decompress(data, fin, (err, result) => {
30584
- done();
30585
- callback(err, result);
30586
- });
30587
- });
30588
- }
30589
- compress(data, fin, callback) {
30590
- zlibLimiter.add((done) => {
30591
- this._compress(data, fin, (err, result) => {
30592
- done();
30593
- callback(err, result);
30594
- });
30595
- });
30596
- }
30597
- _decompress(data, fin, callback) {
30598
- const endpoint = this._isServer ? "client" : "server";
30599
- if (!this._inflate) {
30600
- const key = `${endpoint}_max_window_bits`;
30601
- const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
30602
- this._inflate = zlib.createInflateRaw({
30603
- ...this._options.zlibInflateOptions,
30604
- windowBits
30605
- });
30606
- this._inflate[kPerMessageDeflate] = this;
30607
- this._inflate[kTotalLength] = 0;
30608
- this._inflate[kBuffers] = [];
30609
- this._inflate.on("error", inflateOnError);
30610
- this._inflate.on("data", inflateOnData);
30611
- }
30612
- this._inflate[kCallback] = callback;
30613
- this._inflate.write(data);
30614
- if (fin)
30615
- this._inflate.write(TRAILER);
30616
- this._inflate.flush(() => {
30617
- const err = this._inflate[kError];
30618
- if (err) {
30619
- this._inflate.close();
30620
- this._inflate = null;
30621
- callback(err);
30622
- return;
30623
- }
30624
- const data2 = bufferUtil.concat(this._inflate[kBuffers], this._inflate[kTotalLength]);
30625
- if (this._inflate._readableState.endEmitted) {
30626
- this._inflate.close();
30627
- this._inflate = null;
30628
- } else {
30629
- this._inflate[kTotalLength] = 0;
30630
- this._inflate[kBuffers] = [];
30631
- if (fin && this.params[`${endpoint}_no_context_takeover`]) {
30632
- this._inflate.reset();
30633
- }
30634
- }
30635
- callback(null, data2);
30636
- });
30637
- }
30638
- _compress(data, fin, callback) {
30639
- const endpoint = this._isServer ? "server" : "client";
30640
- if (!this._deflate) {
30641
- const key = `${endpoint}_max_window_bits`;
30642
- const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
30643
- this._deflate = zlib.createDeflateRaw({
30644
- ...this._options.zlibDeflateOptions,
30645
- windowBits
30646
- });
30647
- this._deflate[kTotalLength] = 0;
30648
- this._deflate[kBuffers] = [];
30649
- this._deflate.on("data", deflateOnData);
30650
- }
30651
- this._deflate[kCallback] = callback;
30652
- this._deflate.write(data);
30653
- this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
30654
- if (!this._deflate) {
30655
- return;
30656
- }
30657
- let data2 = bufferUtil.concat(this._deflate[kBuffers], this._deflate[kTotalLength]);
30658
- if (fin) {
30659
- data2 = new FastBuffer(data2.buffer, data2.byteOffset, data2.length - 4);
30660
- }
30661
- this._deflate[kCallback] = null;
30662
- this._deflate[kTotalLength] = 0;
30663
- this._deflate[kBuffers] = [];
30664
- if (fin && this.params[`${endpoint}_no_context_takeover`]) {
30665
- this._deflate.reset();
30666
- }
30667
- callback(null, data2);
30668
- });
30669
- }
30670
- }
30671
- module.exports = PerMessageDeflate;
30672
- function deflateOnData(chunk) {
30673
- this[kBuffers].push(chunk);
30674
- this[kTotalLength] += chunk.length;
30675
- }
30676
- function inflateOnData(chunk) {
30677
- this[kTotalLength] += chunk.length;
30678
- if (this[kPerMessageDeflate]._maxPayload < 1 || this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload) {
30679
- this[kBuffers].push(chunk);
30680
- return;
30681
- }
30682
- this[kError] = new RangeError("Max payload size exceeded");
30683
- this[kError].code = "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH";
30684
- this[kError][kStatusCode] = 1009;
30685
- this.removeListener("data", inflateOnData);
30686
- this.reset();
30687
- }
30688
- function inflateOnError(err) {
30689
- this[kPerMessageDeflate]._inflate = null;
30690
- if (this[kError]) {
30691
- this[kCallback](this[kError]);
30692
- return;
30693
- }
30694
- err[kStatusCode] = 1007;
30695
- this[kCallback](err);
30696
- }
30697
- });
30698
-
30699
- // node_modules/ink/node_modules/ws/lib/validation.js
30700
- var require_validation2 = __commonJS((exports, module) => {
30701
- var { isUtf8 } = __require("buffer");
30702
- var { hasBlob } = require_constants6();
30703
- var tokenChars = [
30704
- 0,
30705
- 0,
30706
- 0,
30707
- 0,
30708
- 0,
30709
- 0,
30710
- 0,
30711
- 0,
30712
- 0,
30713
- 0,
30714
- 0,
30715
- 0,
30716
- 0,
30717
- 0,
30718
- 0,
30719
- 0,
30720
- 0,
30721
- 0,
30722
- 0,
30723
- 0,
30724
- 0,
30725
- 0,
30726
- 0,
30727
- 0,
30728
- 0,
30729
- 0,
30730
- 0,
30731
- 0,
30732
- 0,
30733
- 0,
30734
- 0,
30735
- 0,
30736
- 0,
30737
- 1,
30738
- 0,
30739
- 1,
30740
- 1,
30741
- 1,
30742
- 1,
30743
- 1,
30744
- 0,
30745
- 0,
30746
- 1,
30747
- 1,
30748
- 0,
30749
- 1,
30750
- 1,
30751
- 0,
30752
- 1,
30753
- 1,
30754
- 1,
30755
- 1,
30756
- 1,
30757
- 1,
30758
- 1,
30759
- 1,
30760
- 1,
30761
- 1,
30762
- 0,
30763
- 0,
30764
- 0,
30765
- 0,
30766
- 0,
30767
- 0,
30768
- 0,
30769
- 1,
30770
- 1,
30771
- 1,
30772
- 1,
30773
- 1,
30774
- 1,
30775
- 1,
30776
- 1,
30777
- 1,
30778
- 1,
30779
- 1,
30780
- 1,
30781
- 1,
30782
- 1,
30783
- 1,
30784
- 1,
30785
- 1,
30786
- 1,
30787
- 1,
30788
- 1,
30789
- 1,
30790
- 1,
30791
- 1,
30792
- 1,
30793
- 1,
30794
- 1,
30795
- 0,
30796
- 0,
30797
- 0,
30798
- 1,
30799
- 1,
30800
- 1,
30801
- 1,
30802
- 1,
30803
- 1,
30804
- 1,
30805
- 1,
30806
- 1,
30807
- 1,
30808
- 1,
30809
- 1,
30810
- 1,
30811
- 1,
30812
- 1,
30813
- 1,
30814
- 1,
30815
- 1,
30816
- 1,
30817
- 1,
30818
- 1,
30819
- 1,
30820
- 1,
30821
- 1,
30822
- 1,
30823
- 1,
30824
- 1,
30825
- 1,
30826
- 1,
30827
- 0,
30828
- 1,
30829
- 0,
30830
- 1,
30831
- 0
30832
- ];
30833
- function isValidStatusCode(code) {
30834
- return code >= 1000 && code <= 1014 && code !== 1004 && code !== 1005 && code !== 1006 || code >= 3000 && code <= 4999;
30835
- }
30836
- function _isValidUTF8(buf) {
30837
- const len = buf.length;
30838
- let i2 = 0;
30839
- while (i2 < len) {
30840
- if ((buf[i2] & 128) === 0) {
30841
- i2++;
30842
- } else if ((buf[i2] & 224) === 192) {
30843
- if (i2 + 1 === len || (buf[i2 + 1] & 192) !== 128 || (buf[i2] & 254) === 192) {
30844
- return false;
30845
- }
30846
- i2 += 2;
30847
- } else if ((buf[i2] & 240) === 224) {
30848
- if (i2 + 2 >= len || (buf[i2 + 1] & 192) !== 128 || (buf[i2 + 2] & 192) !== 128 || buf[i2] === 224 && (buf[i2 + 1] & 224) === 128 || buf[i2] === 237 && (buf[i2 + 1] & 224) === 160) {
30849
- return false;
30850
- }
30851
- i2 += 3;
30852
- } else if ((buf[i2] & 248) === 240) {
30853
- if (i2 + 3 >= len || (buf[i2 + 1] & 192) !== 128 || (buf[i2 + 2] & 192) !== 128 || (buf[i2 + 3] & 192) !== 128 || buf[i2] === 240 && (buf[i2 + 1] & 240) === 128 || buf[i2] === 244 && buf[i2 + 1] > 143 || buf[i2] > 244) {
30854
- return false;
30855
- }
30856
- i2 += 4;
30857
- } else {
30858
- return false;
30859
- }
30860
- }
30861
- return true;
30862
- }
30863
- function isBlob(value) {
30864
- return hasBlob && typeof value === "object" && typeof value.arrayBuffer === "function" && typeof value.type === "string" && typeof value.stream === "function" && (value[Symbol.toStringTag] === "Blob" || value[Symbol.toStringTag] === "File");
30865
- }
30866
- module.exports = {
30867
- isBlob,
30868
- isValidStatusCode,
30869
- isValidUTF8: _isValidUTF8,
30870
- tokenChars
30871
- };
30872
- if (isUtf8) {
30873
- module.exports.isValidUTF8 = function(buf) {
30874
- return buf.length < 24 ? _isValidUTF8(buf) : isUtf8(buf);
30875
- };
30876
- } else if (!process.env.WS_NO_UTF_8_VALIDATE) {
30877
- try {
30878
- const isValidUTF8 = (()=>{throw new Error("Cannot require module "+"utf-8-validate");})();
30879
- module.exports.isValidUTF8 = function(buf) {
30880
- return buf.length < 32 ? _isValidUTF8(buf) : isValidUTF8(buf);
30881
- };
30882
- } catch (e) {}
30883
- }
30884
- });
30885
-
30886
- // node_modules/ink/node_modules/ws/lib/receiver.js
30887
- var require_receiver2 = __commonJS((exports, module) => {
30888
- var { Writable } = __require("stream");
30889
- var PerMessageDeflate = require_permessage_deflate2();
30890
- var {
30891
- BINARY_TYPES,
30892
- EMPTY_BUFFER,
30893
- kStatusCode,
30894
- kWebSocket
30895
- } = require_constants6();
30896
- var { concat, toArrayBuffer, unmask } = require_buffer_util2();
30897
- var { isValidStatusCode, isValidUTF8 } = require_validation2();
30898
- var FastBuffer = Buffer[Symbol.species];
30899
- var GET_INFO = 0;
30900
- var GET_PAYLOAD_LENGTH_16 = 1;
30901
- var GET_PAYLOAD_LENGTH_64 = 2;
30902
- var GET_MASK = 3;
30903
- var GET_DATA = 4;
30904
- var INFLATING = 5;
30905
- var DEFER_EVENT = 6;
30906
-
30907
- class Receiver extends Writable {
30908
- constructor(options = {}) {
30909
- super();
30910
- this._allowSynchronousEvents = options.allowSynchronousEvents !== undefined ? options.allowSynchronousEvents : true;
30911
- this._binaryType = options.binaryType || BINARY_TYPES[0];
30912
- this._extensions = options.extensions || {};
30913
- this._isServer = !!options.isServer;
30914
- this._maxPayload = options.maxPayload | 0;
30915
- this._skipUTF8Validation = !!options.skipUTF8Validation;
30916
- this[kWebSocket] = undefined;
30917
- this._bufferedBytes = 0;
30918
- this._buffers = [];
30919
- this._compressed = false;
30920
- this._payloadLength = 0;
30921
- this._mask = undefined;
30922
- this._fragmented = 0;
30923
- this._masked = false;
30924
- this._fin = false;
30925
- this._opcode = 0;
30926
- this._totalPayloadLength = 0;
30927
- this._messageLength = 0;
30928
- this._fragments = [];
30929
- this._errored = false;
30930
- this._loop = false;
30931
- this._state = GET_INFO;
30932
- }
30933
- _write(chunk, encoding, cb) {
30934
- if (this._opcode === 8 && this._state == GET_INFO)
30935
- return cb();
30936
- this._bufferedBytes += chunk.length;
30937
- this._buffers.push(chunk);
30938
- this.startLoop(cb);
30939
- }
30940
- consume(n) {
30941
- this._bufferedBytes -= n;
30942
- if (n === this._buffers[0].length)
30943
- return this._buffers.shift();
30944
- if (n < this._buffers[0].length) {
30945
- const buf = this._buffers[0];
30946
- this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n);
30947
- return new FastBuffer(buf.buffer, buf.byteOffset, n);
30948
- }
30949
- const dst = Buffer.allocUnsafe(n);
30950
- do {
30951
- const buf = this._buffers[0];
30952
- const offset = dst.length - n;
30953
- if (n >= buf.length) {
30954
- dst.set(this._buffers.shift(), offset);
30955
- } else {
30956
- dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
30957
- this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n);
30958
- }
30959
- n -= buf.length;
30960
- } while (n > 0);
30961
- return dst;
30962
- }
30963
- startLoop(cb) {
30964
- this._loop = true;
30965
- do {
30966
- switch (this._state) {
30967
- case GET_INFO:
30968
- this.getInfo(cb);
30969
- break;
30970
- case GET_PAYLOAD_LENGTH_16:
30971
- this.getPayloadLength16(cb);
30972
- break;
30973
- case GET_PAYLOAD_LENGTH_64:
30974
- this.getPayloadLength64(cb);
30975
- break;
30976
- case GET_MASK:
30977
- this.getMask();
30978
- break;
30979
- case GET_DATA:
30980
- this.getData(cb);
30981
- break;
30982
- case INFLATING:
30983
- case DEFER_EVENT:
30984
- this._loop = false;
30985
- return;
30986
- }
30987
- } while (this._loop);
30988
- if (!this._errored)
30989
- cb();
30990
- }
30991
- getInfo(cb) {
30992
- if (this._bufferedBytes < 2) {
30993
- this._loop = false;
30994
- return;
30995
- }
30996
- const buf = this.consume(2);
30997
- if ((buf[0] & 48) !== 0) {
30998
- const error = this.createError(RangeError, "RSV2 and RSV3 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_2_3");
30999
- cb(error);
31000
- return;
31001
- }
31002
- const compressed = (buf[0] & 64) === 64;
31003
- if (compressed && !this._extensions[PerMessageDeflate.extensionName]) {
31004
- const error = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
31005
- cb(error);
31006
- return;
31007
- }
31008
- this._fin = (buf[0] & 128) === 128;
31009
- this._opcode = buf[0] & 15;
31010
- this._payloadLength = buf[1] & 127;
31011
- if (this._opcode === 0) {
31012
- if (compressed) {
31013
- const error = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
31014
- cb(error);
31015
- return;
31016
- }
31017
- if (!this._fragmented) {
31018
- const error = this.createError(RangeError, "invalid opcode 0", true, 1002, "WS_ERR_INVALID_OPCODE");
31019
- cb(error);
31020
- return;
31021
- }
31022
- this._opcode = this._fragmented;
31023
- } else if (this._opcode === 1 || this._opcode === 2) {
31024
- if (this._fragmented) {
31025
- const error = this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, "WS_ERR_INVALID_OPCODE");
31026
- cb(error);
31027
- return;
31028
- }
31029
- this._compressed = compressed;
31030
- } else if (this._opcode > 7 && this._opcode < 11) {
31031
- if (!this._fin) {
31032
- const error = this.createError(RangeError, "FIN must be set", true, 1002, "WS_ERR_EXPECTED_FIN");
31033
- cb(error);
31034
- return;
31035
- }
31036
- if (compressed) {
31037
- const error = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
31038
- cb(error);
31039
- return;
31040
- }
31041
- if (this._payloadLength > 125 || this._opcode === 8 && this._payloadLength === 1) {
31042
- const error = this.createError(RangeError, `invalid payload length ${this._payloadLength}`, true, 1002, "WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");
31043
- cb(error);
31044
- return;
31045
- }
31046
- } else {
31047
- const error = this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, "WS_ERR_INVALID_OPCODE");
31048
- cb(error);
31049
- return;
31050
- }
31051
- if (!this._fin && !this._fragmented)
31052
- this._fragmented = this._opcode;
31053
- this._masked = (buf[1] & 128) === 128;
31054
- if (this._isServer) {
31055
- if (!this._masked) {
31056
- const error = this.createError(RangeError, "MASK must be set", true, 1002, "WS_ERR_EXPECTED_MASK");
31057
- cb(error);
31058
- return;
31059
- }
31060
- } else if (this._masked) {
31061
- const error = this.createError(RangeError, "MASK must be clear", true, 1002, "WS_ERR_UNEXPECTED_MASK");
31062
- cb(error);
31063
- return;
31064
- }
31065
- if (this._payloadLength === 126)
31066
- this._state = GET_PAYLOAD_LENGTH_16;
31067
- else if (this._payloadLength === 127)
31068
- this._state = GET_PAYLOAD_LENGTH_64;
31069
- else
31070
- this.haveLength(cb);
31071
- }
31072
- getPayloadLength16(cb) {
31073
- if (this._bufferedBytes < 2) {
31074
- this._loop = false;
31075
- return;
31076
- }
31077
- this._payloadLength = this.consume(2).readUInt16BE(0);
31078
- this.haveLength(cb);
31079
- }
31080
- getPayloadLength64(cb) {
31081
- if (this._bufferedBytes < 8) {
31082
- this._loop = false;
31083
- return;
31084
- }
31085
- const buf = this.consume(8);
31086
- const num = buf.readUInt32BE(0);
31087
- if (num > Math.pow(2, 53 - 32) - 1) {
31088
- const error = this.createError(RangeError, "Unsupported WebSocket frame: payload length > 2^53 - 1", false, 1009, "WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");
31089
- cb(error);
31090
- return;
31091
- }
31092
- this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
31093
- this.haveLength(cb);
31094
- }
31095
- haveLength(cb) {
31096
- if (this._payloadLength && this._opcode < 8) {
31097
- this._totalPayloadLength += this._payloadLength;
31098
- if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
31099
- const error = this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");
31100
- cb(error);
31101
- return;
31102
- }
31103
- }
31104
- if (this._masked)
31105
- this._state = GET_MASK;
31106
- else
31107
- this._state = GET_DATA;
31108
- }
31109
- getMask() {
31110
- if (this._bufferedBytes < 4) {
31111
- this._loop = false;
31112
- return;
31113
- }
31114
- this._mask = this.consume(4);
31115
- this._state = GET_DATA;
31116
- }
31117
- getData(cb) {
31118
- let data = EMPTY_BUFFER;
31119
- if (this._payloadLength) {
31120
- if (this._bufferedBytes < this._payloadLength) {
31121
- this._loop = false;
31122
- return;
31123
- }
31124
- data = this.consume(this._payloadLength);
31125
- if (this._masked && (this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0) {
31126
- unmask(data, this._mask);
31127
- }
31128
- }
31129
- if (this._opcode > 7) {
31130
- this.controlMessage(data, cb);
31131
- return;
31132
- }
31133
- if (this._compressed) {
31134
- this._state = INFLATING;
31135
- this.decompress(data, cb);
31136
- return;
31137
- }
31138
- if (data.length) {
31139
- this._messageLength = this._totalPayloadLength;
31140
- this._fragments.push(data);
31141
- }
31142
- this.dataMessage(cb);
31143
- }
31144
- decompress(data, cb) {
31145
- const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
31146
- perMessageDeflate.decompress(data, this._fin, (err, buf) => {
31147
- if (err)
31148
- return cb(err);
31149
- if (buf.length) {
31150
- this._messageLength += buf.length;
31151
- if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
31152
- const error = this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");
31153
- cb(error);
31154
- return;
31155
- }
31156
- this._fragments.push(buf);
31157
- }
31158
- this.dataMessage(cb);
31159
- if (this._state === GET_INFO)
31160
- this.startLoop(cb);
31161
- });
31162
- }
31163
- dataMessage(cb) {
31164
- if (!this._fin) {
31165
- this._state = GET_INFO;
31166
- return;
31167
- }
31168
- const messageLength = this._messageLength;
31169
- const fragments = this._fragments;
31170
- this._totalPayloadLength = 0;
31171
- this._messageLength = 0;
31172
- this._fragmented = 0;
31173
- this._fragments = [];
31174
- if (this._opcode === 2) {
31175
- let data;
31176
- if (this._binaryType === "nodebuffer") {
31177
- data = concat(fragments, messageLength);
31178
- } else if (this._binaryType === "arraybuffer") {
31179
- data = toArrayBuffer(concat(fragments, messageLength));
31180
- } else if (this._binaryType === "blob") {
31181
- data = new Blob(fragments);
31182
- } else {
31183
- data = fragments;
31184
- }
31185
- if (this._allowSynchronousEvents) {
31186
- this.emit("message", data, true);
31187
- this._state = GET_INFO;
31188
- } else {
31189
- this._state = DEFER_EVENT;
31190
- setImmediate(() => {
31191
- this.emit("message", data, true);
31192
- this._state = GET_INFO;
31193
- this.startLoop(cb);
31194
- });
31195
- }
31196
- } else {
31197
- const buf = concat(fragments, messageLength);
31198
- if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
31199
- const error = this.createError(Error, "invalid UTF-8 sequence", true, 1007, "WS_ERR_INVALID_UTF8");
31200
- cb(error);
31201
- return;
31202
- }
31203
- if (this._state === INFLATING || this._allowSynchronousEvents) {
31204
- this.emit("message", buf, false);
31205
- this._state = GET_INFO;
31206
- } else {
31207
- this._state = DEFER_EVENT;
31208
- setImmediate(() => {
31209
- this.emit("message", buf, false);
31210
- this._state = GET_INFO;
31211
- this.startLoop(cb);
31212
- });
31213
- }
31214
- }
31215
- }
31216
- controlMessage(data, cb) {
31217
- if (this._opcode === 8) {
31218
- if (data.length === 0) {
31219
- this._loop = false;
31220
- this.emit("conclude", 1005, EMPTY_BUFFER);
31221
- this.end();
31222
- } else {
31223
- const code = data.readUInt16BE(0);
31224
- if (!isValidStatusCode(code)) {
31225
- const error = this.createError(RangeError, `invalid status code ${code}`, true, 1002, "WS_ERR_INVALID_CLOSE_CODE");
31226
- cb(error);
31227
- return;
31228
- }
31229
- const buf = new FastBuffer(data.buffer, data.byteOffset + 2, data.length - 2);
31230
- if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
31231
- const error = this.createError(Error, "invalid UTF-8 sequence", true, 1007, "WS_ERR_INVALID_UTF8");
31232
- cb(error);
31233
- return;
31234
- }
31235
- this._loop = false;
31236
- this.emit("conclude", code, buf);
31237
- this.end();
31238
- }
31239
- this._state = GET_INFO;
31240
- return;
31241
- }
31242
- if (this._allowSynchronousEvents) {
31243
- this.emit(this._opcode === 9 ? "ping" : "pong", data);
31244
- this._state = GET_INFO;
31245
- } else {
31246
- this._state = DEFER_EVENT;
31247
- setImmediate(() => {
31248
- this.emit(this._opcode === 9 ? "ping" : "pong", data);
31249
- this._state = GET_INFO;
31250
- this.startLoop(cb);
31251
- });
31252
- }
31253
- }
31254
- createError(ErrorCtor, message, prefix, statusCode, errorCode) {
31255
- this._loop = false;
31256
- this._errored = true;
31257
- const err = new ErrorCtor(prefix ? `Invalid WebSocket frame: ${message}` : message);
31258
- Error.captureStackTrace(err, this.createError);
31259
- err.code = errorCode;
31260
- err[kStatusCode] = statusCode;
31261
- return err;
31262
- }
31263
- }
31264
- module.exports = Receiver;
31265
- });
31266
-
31267
- // node_modules/ink/node_modules/ws/lib/sender.js
31268
- var require_sender2 = __commonJS((exports, module) => {
31269
- var { Duplex } = __require("stream");
31270
- var { randomFillSync } = __require("crypto");
31271
- var PerMessageDeflate = require_permessage_deflate2();
31272
- var { EMPTY_BUFFER, kWebSocket, NOOP } = require_constants6();
31273
- var { isBlob, isValidStatusCode } = require_validation2();
31274
- var { mask: applyMask, toBuffer } = require_buffer_util2();
31275
- var kByteLength = Symbol("kByteLength");
31276
- var maskBuffer = Buffer.alloc(4);
31277
- var RANDOM_POOL_SIZE = 8 * 1024;
31278
- var randomPool;
31279
- var randomPoolPointer = RANDOM_POOL_SIZE;
31280
- var DEFAULT = 0;
31281
- var DEFLATING = 1;
31282
- var GET_BLOB_DATA = 2;
31283
-
31284
- class Sender {
31285
- constructor(socket, extensions, generateMask) {
31286
- this._extensions = extensions || {};
31287
- if (generateMask) {
31288
- this._generateMask = generateMask;
31289
- this._maskBuffer = Buffer.alloc(4);
31290
- }
31291
- this._socket = socket;
31292
- this._firstFragment = true;
31293
- this._compress = false;
31294
- this._bufferedBytes = 0;
31295
- this._queue = [];
31296
- this._state = DEFAULT;
31297
- this.onerror = NOOP;
31298
- this[kWebSocket] = undefined;
31299
- }
31300
- static frame(data, options) {
31301
- let mask;
31302
- let merge2 = false;
31303
- let offset = 2;
31304
- let skipMasking = false;
31305
- if (options.mask) {
31306
- mask = options.maskBuffer || maskBuffer;
31307
- if (options.generateMask) {
31308
- options.generateMask(mask);
31309
- } else {
31310
- if (randomPoolPointer === RANDOM_POOL_SIZE) {
31311
- if (randomPool === undefined) {
31312
- randomPool = Buffer.alloc(RANDOM_POOL_SIZE);
31313
- }
31314
- randomFillSync(randomPool, 0, RANDOM_POOL_SIZE);
31315
- randomPoolPointer = 0;
31316
- }
31317
- mask[0] = randomPool[randomPoolPointer++];
31318
- mask[1] = randomPool[randomPoolPointer++];
31319
- mask[2] = randomPool[randomPoolPointer++];
31320
- mask[3] = randomPool[randomPoolPointer++];
31321
- }
31322
- skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) === 0;
31323
- offset = 6;
31324
- }
31325
- let dataLength;
31326
- if (typeof data === "string") {
31327
- if ((!options.mask || skipMasking) && options[kByteLength] !== undefined) {
31328
- dataLength = options[kByteLength];
31329
- } else {
31330
- data = Buffer.from(data);
31331
- dataLength = data.length;
31332
- }
31333
- } else {
31334
- dataLength = data.length;
31335
- merge2 = options.mask && options.readOnly && !skipMasking;
31336
- }
31337
- let payloadLength = dataLength;
31338
- if (dataLength >= 65536) {
31339
- offset += 8;
31340
- payloadLength = 127;
31341
- } else if (dataLength > 125) {
31342
- offset += 2;
31343
- payloadLength = 126;
31344
- }
31345
- const target = Buffer.allocUnsafe(merge2 ? dataLength + offset : offset);
31346
- target[0] = options.fin ? options.opcode | 128 : options.opcode;
31347
- if (options.rsv1)
31348
- target[0] |= 64;
31349
- target[1] = payloadLength;
31350
- if (payloadLength === 126) {
31351
- target.writeUInt16BE(dataLength, 2);
31352
- } else if (payloadLength === 127) {
31353
- target[2] = target[3] = 0;
31354
- target.writeUIntBE(dataLength, 4, 6);
31355
- }
31356
- if (!options.mask)
31357
- return [target, data];
31358
- target[1] |= 128;
31359
- target[offset - 4] = mask[0];
31360
- target[offset - 3] = mask[1];
31361
- target[offset - 2] = mask[2];
31362
- target[offset - 1] = mask[3];
31363
- if (skipMasking)
31364
- return [target, data];
31365
- if (merge2) {
31366
- applyMask(data, mask, target, offset, dataLength);
31367
- return [target];
31368
- }
31369
- applyMask(data, mask, data, 0, dataLength);
31370
- return [target, data];
31371
- }
31372
- close(code, data, mask, cb) {
31373
- let buf;
31374
- if (code === undefined) {
31375
- buf = EMPTY_BUFFER;
31376
- } else if (typeof code !== "number" || !isValidStatusCode(code)) {
31377
- throw new TypeError("First argument must be a valid error code number");
31378
- } else if (data === undefined || !data.length) {
31379
- buf = Buffer.allocUnsafe(2);
31380
- buf.writeUInt16BE(code, 0);
31381
- } else {
31382
- const length = Buffer.byteLength(data);
31383
- if (length > 123) {
31384
- throw new RangeError("The message must not be greater than 123 bytes");
31385
- }
31386
- buf = Buffer.allocUnsafe(2 + length);
31387
- buf.writeUInt16BE(code, 0);
31388
- if (typeof data === "string") {
31389
- buf.write(data, 2);
31390
- } else {
31391
- buf.set(data, 2);
31392
- }
31393
- }
31394
- const options = {
31395
- [kByteLength]: buf.length,
31396
- fin: true,
31397
- generateMask: this._generateMask,
31398
- mask,
31399
- maskBuffer: this._maskBuffer,
31400
- opcode: 8,
31401
- readOnly: false,
31402
- rsv1: false
31403
- };
31404
- if (this._state !== DEFAULT) {
31405
- this.enqueue([this.dispatch, buf, false, options, cb]);
31406
- } else {
31407
- this.sendFrame(Sender.frame(buf, options), cb);
31408
- }
31409
- }
31410
- ping(data, mask, cb) {
31411
- let byteLength;
31412
- let readOnly;
31413
- if (typeof data === "string") {
31414
- byteLength = Buffer.byteLength(data);
31415
- readOnly = false;
31416
- } else if (isBlob(data)) {
31417
- byteLength = data.size;
31418
- readOnly = false;
31419
- } else {
31420
- data = toBuffer(data);
31421
- byteLength = data.length;
31422
- readOnly = toBuffer.readOnly;
31423
- }
31424
- if (byteLength > 125) {
31425
- throw new RangeError("The data size must not be greater than 125 bytes");
31426
- }
31427
- const options = {
31428
- [kByteLength]: byteLength,
31429
- fin: true,
31430
- generateMask: this._generateMask,
31431
- mask,
31432
- maskBuffer: this._maskBuffer,
31433
- opcode: 9,
31434
- readOnly,
31435
- rsv1: false
31436
- };
31437
- if (isBlob(data)) {
31438
- if (this._state !== DEFAULT) {
31439
- this.enqueue([this.getBlobData, data, false, options, cb]);
31440
- } else {
31441
- this.getBlobData(data, false, options, cb);
31442
- }
31443
- } else if (this._state !== DEFAULT) {
31444
- this.enqueue([this.dispatch, data, false, options, cb]);
31445
- } else {
31446
- this.sendFrame(Sender.frame(data, options), cb);
31447
- }
31448
- }
31449
- pong(data, mask, cb) {
31450
- let byteLength;
31451
- let readOnly;
31452
- if (typeof data === "string") {
31453
- byteLength = Buffer.byteLength(data);
31454
- readOnly = false;
31455
- } else if (isBlob(data)) {
31456
- byteLength = data.size;
31457
- readOnly = false;
31458
- } else {
31459
- data = toBuffer(data);
31460
- byteLength = data.length;
31461
- readOnly = toBuffer.readOnly;
31462
- }
31463
- if (byteLength > 125) {
31464
- throw new RangeError("The data size must not be greater than 125 bytes");
31465
- }
31466
- const options = {
31467
- [kByteLength]: byteLength,
31468
- fin: true,
31469
- generateMask: this._generateMask,
31470
- mask,
31471
- maskBuffer: this._maskBuffer,
31472
- opcode: 10,
31473
- readOnly,
31474
- rsv1: false
31475
- };
31476
- if (isBlob(data)) {
31477
- if (this._state !== DEFAULT) {
31478
- this.enqueue([this.getBlobData, data, false, options, cb]);
31479
- } else {
31480
- this.getBlobData(data, false, options, cb);
31481
- }
31482
- } else if (this._state !== DEFAULT) {
31483
- this.enqueue([this.dispatch, data, false, options, cb]);
31484
- } else {
31485
- this.sendFrame(Sender.frame(data, options), cb);
31486
- }
31487
- }
31488
- send(data, options, cb) {
31489
- const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
31490
- let opcode = options.binary ? 2 : 1;
31491
- let rsv1 = options.compress;
31492
- let byteLength;
31493
- let readOnly;
31494
- if (typeof data === "string") {
31495
- byteLength = Buffer.byteLength(data);
31496
- readOnly = false;
31497
- } else if (isBlob(data)) {
31498
- byteLength = data.size;
31499
- readOnly = false;
31500
- } else {
31501
- data = toBuffer(data);
31502
- byteLength = data.length;
31503
- readOnly = toBuffer.readOnly;
31504
- }
31505
- if (this._firstFragment) {
31506
- this._firstFragment = false;
31507
- if (rsv1 && perMessageDeflate && perMessageDeflate.params[perMessageDeflate._isServer ? "server_no_context_takeover" : "client_no_context_takeover"]) {
31508
- rsv1 = byteLength >= perMessageDeflate._threshold;
31509
- }
31510
- this._compress = rsv1;
31511
- } else {
31512
- rsv1 = false;
31513
- opcode = 0;
31514
- }
31515
- if (options.fin)
31516
- this._firstFragment = true;
31517
- const opts = {
31518
- [kByteLength]: byteLength,
31519
- fin: options.fin,
31520
- generateMask: this._generateMask,
31521
- mask: options.mask,
31522
- maskBuffer: this._maskBuffer,
31523
- opcode,
31524
- readOnly,
31525
- rsv1
31526
- };
31527
- if (isBlob(data)) {
31528
- if (this._state !== DEFAULT) {
31529
- this.enqueue([this.getBlobData, data, this._compress, opts, cb]);
31530
- } else {
31531
- this.getBlobData(data, this._compress, opts, cb);
31532
- }
31533
- } else if (this._state !== DEFAULT) {
31534
- this.enqueue([this.dispatch, data, this._compress, opts, cb]);
31535
- } else {
31536
- this.dispatch(data, this._compress, opts, cb);
31537
- }
31538
- }
31539
- getBlobData(blob, compress, options, cb) {
31540
- this._bufferedBytes += options[kByteLength];
31541
- this._state = GET_BLOB_DATA;
31542
- blob.arrayBuffer().then((arrayBuffer) => {
31543
- if (this._socket.destroyed) {
31544
- const err = new Error("The socket was closed while the blob was being read");
31545
- process.nextTick(callCallbacks, this, err, cb);
31546
- return;
31547
- }
31548
- this._bufferedBytes -= options[kByteLength];
31549
- const data = toBuffer(arrayBuffer);
31550
- if (!compress) {
31551
- this._state = DEFAULT;
31552
- this.sendFrame(Sender.frame(data, options), cb);
31553
- this.dequeue();
31554
- } else {
31555
- this.dispatch(data, compress, options, cb);
31556
- }
31557
- }).catch((err) => {
31558
- process.nextTick(onError, this, err, cb);
31559
- });
31560
- }
31561
- dispatch(data, compress, options, cb) {
31562
- if (!compress) {
31563
- this.sendFrame(Sender.frame(data, options), cb);
31564
- return;
31565
- }
31566
- const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
31567
- this._bufferedBytes += options[kByteLength];
31568
- this._state = DEFLATING;
31569
- perMessageDeflate.compress(data, options.fin, (_, buf) => {
31570
- if (this._socket.destroyed) {
31571
- const err = new Error("The socket was closed while data was being compressed");
31572
- callCallbacks(this, err, cb);
31573
- return;
31574
- }
31575
- this._bufferedBytes -= options[kByteLength];
31576
- this._state = DEFAULT;
31577
- options.readOnly = false;
31578
- this.sendFrame(Sender.frame(buf, options), cb);
31579
- this.dequeue();
31580
- });
31581
- }
31582
- dequeue() {
31583
- while (this._state === DEFAULT && this._queue.length) {
31584
- const params = this._queue.shift();
31585
- this._bufferedBytes -= params[3][kByteLength];
31586
- Reflect.apply(params[0], this, params.slice(1));
31587
- }
31588
- }
31589
- enqueue(params) {
31590
- this._bufferedBytes += params[3][kByteLength];
31591
- this._queue.push(params);
31592
- }
31593
- sendFrame(list, cb) {
31594
- if (list.length === 2) {
31595
- this._socket.cork();
31596
- this._socket.write(list[0]);
31597
- this._socket.write(list[1], cb);
31598
- this._socket.uncork();
31599
- } else {
31600
- this._socket.write(list[0], cb);
31601
- }
31602
- }
31603
- }
31604
- module.exports = Sender;
31605
- function callCallbacks(sender, err, cb) {
31606
- if (typeof cb === "function")
31607
- cb(err);
31608
- for (let i2 = 0;i2 < sender._queue.length; i2++) {
31609
- const params = sender._queue[i2];
31610
- const callback = params[params.length - 1];
31611
- if (typeof callback === "function")
31612
- callback(err);
31613
- }
31614
- }
31615
- function onError(sender, err, cb) {
31616
- callCallbacks(sender, err, cb);
31617
- sender.onerror(err);
31618
- }
31619
- });
31620
-
31621
- // node_modules/ink/node_modules/ws/lib/event-target.js
31622
- var require_event_target2 = __commonJS((exports, module) => {
31623
- var { kForOnEventAttribute, kListener } = require_constants6();
31624
- var kCode = Symbol("kCode");
31625
- var kData = Symbol("kData");
31626
- var kError = Symbol("kError");
31627
- var kMessage = Symbol("kMessage");
31628
- var kReason = Symbol("kReason");
31629
- var kTarget = Symbol("kTarget");
31630
- var kType = Symbol("kType");
31631
- var kWasClean = Symbol("kWasClean");
31632
-
31633
- class Event {
31634
- constructor(type2) {
31635
- this[kTarget] = null;
31636
- this[kType] = type2;
31637
- }
31638
- get target() {
31639
- return this[kTarget];
31640
- }
31641
- get type() {
31642
- return this[kType];
31643
- }
31644
- }
31645
- Object.defineProperty(Event.prototype, "target", { enumerable: true });
31646
- Object.defineProperty(Event.prototype, "type", { enumerable: true });
31647
-
31648
- class CloseEvent extends Event {
31649
- constructor(type2, options = {}) {
31650
- super(type2);
31651
- this[kCode] = options.code === undefined ? 0 : options.code;
31652
- this[kReason] = options.reason === undefined ? "" : options.reason;
31653
- this[kWasClean] = options.wasClean === undefined ? false : options.wasClean;
31654
- }
31655
- get code() {
31656
- return this[kCode];
31657
- }
31658
- get reason() {
31659
- return this[kReason];
31660
- }
31661
- get wasClean() {
31662
- return this[kWasClean];
31663
- }
31664
- }
31665
- Object.defineProperty(CloseEvent.prototype, "code", { enumerable: true });
31666
- Object.defineProperty(CloseEvent.prototype, "reason", { enumerable: true });
31667
- Object.defineProperty(CloseEvent.prototype, "wasClean", { enumerable: true });
31668
-
31669
- class ErrorEvent extends Event {
31670
- constructor(type2, options = {}) {
31671
- super(type2);
31672
- this[kError] = options.error === undefined ? null : options.error;
31673
- this[kMessage] = options.message === undefined ? "" : options.message;
31674
- }
31675
- get error() {
31676
- return this[kError];
31677
- }
31678
- get message() {
31679
- return this[kMessage];
31680
- }
31681
- }
31682
- Object.defineProperty(ErrorEvent.prototype, "error", { enumerable: true });
31683
- Object.defineProperty(ErrorEvent.prototype, "message", { enumerable: true });
31684
-
31685
- class MessageEvent extends Event {
31686
- constructor(type2, options = {}) {
31687
- super(type2);
31688
- this[kData] = options.data === undefined ? null : options.data;
31689
- }
31690
- get data() {
31691
- return this[kData];
31692
- }
31693
- }
31694
- Object.defineProperty(MessageEvent.prototype, "data", { enumerable: true });
31695
- var EventTarget = {
31696
- addEventListener(type2, handler2, options = {}) {
31697
- for (const listener of this.listeners(type2)) {
31698
- if (!options[kForOnEventAttribute] && listener[kListener] === handler2 && !listener[kForOnEventAttribute]) {
31699
- return;
31700
- }
31701
- }
31702
- let wrapper;
31703
- if (type2 === "message") {
31704
- wrapper = function onMessage(data, isBinary2) {
31705
- const event = new MessageEvent("message", {
31706
- data: isBinary2 ? data : data.toString()
31707
- });
31708
- event[kTarget] = this;
31709
- callListener(handler2, this, event);
31710
- };
31711
- } else if (type2 === "close") {
31712
- wrapper = function onClose(code, message) {
31713
- const event = new CloseEvent("close", {
31714
- code,
31715
- reason: message.toString(),
31716
- wasClean: this._closeFrameReceived && this._closeFrameSent
31717
- });
31718
- event[kTarget] = this;
31719
- callListener(handler2, this, event);
31720
- };
31721
- } else if (type2 === "error") {
31722
- wrapper = function onError(error) {
31723
- const event = new ErrorEvent("error", {
31724
- error,
31725
- message: error.message
31726
- });
31727
- event[kTarget] = this;
31728
- callListener(handler2, this, event);
31729
- };
31730
- } else if (type2 === "open") {
31731
- wrapper = function onOpen() {
31732
- const event = new Event("open");
31733
- event[kTarget] = this;
31734
- callListener(handler2, this, event);
31735
- };
31736
- } else {
31737
- return;
31738
- }
31739
- wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute];
31740
- wrapper[kListener] = handler2;
31741
- if (options.once) {
31742
- this.once(type2, wrapper);
31743
- } else {
31744
- this.on(type2, wrapper);
31745
- }
31746
- },
31747
- removeEventListener(type2, handler2) {
31748
- for (const listener of this.listeners(type2)) {
31749
- if (listener[kListener] === handler2 && !listener[kForOnEventAttribute]) {
31750
- this.removeListener(type2, listener);
31751
- break;
31752
- }
31753
- }
31754
- }
31755
- };
31756
- module.exports = {
31757
- CloseEvent,
31758
- ErrorEvent,
31759
- Event,
31760
- EventTarget,
31761
- MessageEvent
31762
- };
31763
- function callListener(listener, thisArg, event) {
31764
- if (typeof listener === "object" && listener.handleEvent) {
31765
- listener.handleEvent.call(listener, event);
31766
- } else {
31767
- listener.call(thisArg, event);
31768
- }
31769
- }
31770
- });
31771
-
31772
- // node_modules/ink/node_modules/ws/lib/extension.js
31773
- var require_extension2 = __commonJS((exports, module) => {
31774
- var { tokenChars } = require_validation2();
31775
- function push(dest, name, elem) {
31776
- if (dest[name] === undefined)
31777
- dest[name] = [elem];
31778
- else
31779
- dest[name].push(elem);
31780
- }
31781
- function parse(header) {
31782
- const offers = Object.create(null);
31783
- let params = Object.create(null);
31784
- let mustUnescape = false;
31785
- let isEscaping = false;
31786
- let inQuotes = false;
31787
- let extensionName;
31788
- let paramName;
31789
- let start = -1;
31790
- let code = -1;
31791
- let end = -1;
31792
- let i2 = 0;
31793
- for (;i2 < header.length; i2++) {
31794
- code = header.charCodeAt(i2);
31795
- if (extensionName === undefined) {
31796
- if (end === -1 && tokenChars[code] === 1) {
31797
- if (start === -1)
31798
- start = i2;
31799
- } else if (i2 !== 0 && (code === 32 || code === 9)) {
31800
- if (end === -1 && start !== -1)
31801
- end = i2;
31802
- } else if (code === 59 || code === 44) {
31803
- if (start === -1) {
31804
- throw new SyntaxError(`Unexpected character at index ${i2}`);
31805
- }
31806
- if (end === -1)
31807
- end = i2;
31808
- const name = header.slice(start, end);
31809
- if (code === 44) {
31810
- push(offers, name, params);
31811
- params = Object.create(null);
31812
- } else {
31813
- extensionName = name;
31814
- }
31815
- start = end = -1;
31816
- } else {
31817
- throw new SyntaxError(`Unexpected character at index ${i2}`);
31818
- }
31819
- } else if (paramName === undefined) {
31820
- if (end === -1 && tokenChars[code] === 1) {
31821
- if (start === -1)
31822
- start = i2;
31823
- } else if (code === 32 || code === 9) {
31824
- if (end === -1 && start !== -1)
31825
- end = i2;
31826
- } else if (code === 59 || code === 44) {
31827
- if (start === -1) {
31828
- throw new SyntaxError(`Unexpected character at index ${i2}`);
31829
- }
31830
- if (end === -1)
31831
- end = i2;
31832
- push(params, header.slice(start, end), true);
31833
- if (code === 44) {
31834
- push(offers, extensionName, params);
31835
- params = Object.create(null);
31836
- extensionName = undefined;
31837
- }
31838
- start = end = -1;
31839
- } else if (code === 61 && start !== -1 && end === -1) {
31840
- paramName = header.slice(start, i2);
31841
- start = end = -1;
31842
- } else {
31843
- throw new SyntaxError(`Unexpected character at index ${i2}`);
31844
- }
31845
- } else {
31846
- if (isEscaping) {
31847
- if (tokenChars[code] !== 1) {
31848
- throw new SyntaxError(`Unexpected character at index ${i2}`);
31849
- }
31850
- if (start === -1)
31851
- start = i2;
31852
- else if (!mustUnescape)
31853
- mustUnescape = true;
31854
- isEscaping = false;
31855
- } else if (inQuotes) {
31856
- if (tokenChars[code] === 1) {
31857
- if (start === -1)
31858
- start = i2;
31859
- } else if (code === 34 && start !== -1) {
31860
- inQuotes = false;
31861
- end = i2;
31862
- } else if (code === 92) {
31863
- isEscaping = true;
31864
- } else {
31865
- throw new SyntaxError(`Unexpected character at index ${i2}`);
31866
- }
31867
- } else if (code === 34 && header.charCodeAt(i2 - 1) === 61) {
31868
- inQuotes = true;
31869
- } else if (end === -1 && tokenChars[code] === 1) {
31870
- if (start === -1)
31871
- start = i2;
31872
- } else if (start !== -1 && (code === 32 || code === 9)) {
31873
- if (end === -1)
31874
- end = i2;
31875
- } else if (code === 59 || code === 44) {
31876
- if (start === -1) {
31877
- throw new SyntaxError(`Unexpected character at index ${i2}`);
31878
- }
31879
- if (end === -1)
31880
- end = i2;
31881
- let value = header.slice(start, end);
31882
- if (mustUnescape) {
31883
- value = value.replace(/\\/g, "");
31884
- mustUnescape = false;
31885
- }
31886
- push(params, paramName, value);
31887
- if (code === 44) {
31888
- push(offers, extensionName, params);
31889
- params = Object.create(null);
31890
- extensionName = undefined;
31891
- }
31892
- paramName = undefined;
31893
- start = end = -1;
31894
- } else {
31895
- throw new SyntaxError(`Unexpected character at index ${i2}`);
31896
- }
31897
- }
31898
- }
31899
- if (start === -1 || inQuotes || code === 32 || code === 9) {
31900
- throw new SyntaxError("Unexpected end of input");
31901
- }
31902
- if (end === -1)
31903
- end = i2;
31904
- const token = header.slice(start, end);
31905
- if (extensionName === undefined) {
31906
- push(offers, token, params);
31907
- } else {
31908
- if (paramName === undefined) {
31909
- push(params, token, true);
31910
- } else if (mustUnescape) {
31911
- push(params, paramName, token.replace(/\\/g, ""));
31912
- } else {
31913
- push(params, paramName, token);
31914
- }
31915
- push(offers, extensionName, params);
31916
- }
31917
- return offers;
31918
- }
31919
- function format2(extensions) {
31920
- return Object.keys(extensions).map((extension) => {
31921
- let configurations = extensions[extension];
31922
- if (!Array.isArray(configurations))
31923
- configurations = [configurations];
31924
- return configurations.map((params) => {
31925
- return [extension].concat(Object.keys(params).map((k) => {
31926
- let values = params[k];
31927
- if (!Array.isArray(values))
31928
- values = [values];
31929
- return values.map((v) => v === true ? k : `${k}=${v}`).join("; ");
31930
- })).join("; ");
31931
- }).join(", ");
31932
- }).join(", ");
31933
- }
31934
- module.exports = { format: format2, parse };
31935
- });
31936
-
31937
- // node_modules/ink/node_modules/ws/lib/websocket.js
31938
- var require_websocket2 = __commonJS((exports, module) => {
31939
- var EventEmitter5 = __require("events");
31940
- var https = __require("https");
31941
- var http = __require("http");
31942
- var net = __require("net");
31943
- var tls = __require("tls");
31944
- var { randomBytes, createHash } = __require("crypto");
31945
- var { Duplex, Readable } = __require("stream");
31946
- var { URL: URL2 } = __require("url");
31947
- var PerMessageDeflate = require_permessage_deflate2();
31948
- var Receiver = require_receiver2();
31949
- var Sender = require_sender2();
31950
- var { isBlob } = require_validation2();
31951
- var {
31952
- BINARY_TYPES,
31953
- EMPTY_BUFFER,
31954
- GUID,
31955
- kForOnEventAttribute,
31956
- kListener,
31957
- kStatusCode,
31958
- kWebSocket,
31959
- NOOP
31960
- } = require_constants6();
31961
- var {
31962
- EventTarget: { addEventListener, removeEventListener }
31963
- } = require_event_target2();
31964
- var { format: format2, parse } = require_extension2();
31965
- var { toBuffer } = require_buffer_util2();
31966
- var closeTimeout = 30 * 1000;
31967
- var kAborted = Symbol("kAborted");
31968
- var protocolVersions = [8, 13];
31969
- var readyStates = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"];
31970
- var subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
31971
-
31972
- class WebSocket extends EventEmitter5 {
31973
- constructor(address, protocols, options) {
31974
- super();
31975
- this._binaryType = BINARY_TYPES[0];
31976
- this._closeCode = 1006;
31977
- this._closeFrameReceived = false;
31978
- this._closeFrameSent = false;
31979
- this._closeMessage = EMPTY_BUFFER;
31980
- this._closeTimer = null;
31981
- this._errorEmitted = false;
31982
- this._extensions = {};
31983
- this._paused = false;
31984
- this._protocol = "";
31985
- this._readyState = WebSocket.CONNECTING;
31986
- this._receiver = null;
31987
- this._sender = null;
31988
- this._socket = null;
31989
- if (address !== null) {
31990
- this._bufferedAmount = 0;
31991
- this._isServer = false;
31992
- this._redirects = 0;
31993
- if (protocols === undefined) {
31994
- protocols = [];
31995
- } else if (!Array.isArray(protocols)) {
31996
- if (typeof protocols === "object" && protocols !== null) {
31997
- options = protocols;
31998
- protocols = [];
31999
- } else {
32000
- protocols = [protocols];
32001
- }
32002
- }
32003
- initAsClient(this, address, protocols, options);
32004
- } else {
32005
- this._autoPong = options.autoPong;
32006
- this._isServer = true;
32007
- }
32008
- }
32009
- get binaryType() {
32010
- return this._binaryType;
32011
- }
32012
- set binaryType(type2) {
32013
- if (!BINARY_TYPES.includes(type2))
32014
- return;
32015
- this._binaryType = type2;
32016
- if (this._receiver)
32017
- this._receiver._binaryType = type2;
32018
- }
32019
- get bufferedAmount() {
32020
- if (!this._socket)
32021
- return this._bufferedAmount;
32022
- return this._socket._writableState.length + this._sender._bufferedBytes;
32023
- }
32024
- get extensions() {
32025
- return Object.keys(this._extensions).join();
32026
- }
32027
- get isPaused() {
32028
- return this._paused;
32029
- }
32030
- get onclose() {
32031
- return null;
32032
- }
32033
- get onerror() {
32034
- return null;
32035
- }
32036
- get onopen() {
32037
- return null;
32038
- }
32039
- get onmessage() {
32040
- return null;
32041
- }
32042
- get protocol() {
32043
- return this._protocol;
32044
- }
32045
- get readyState() {
32046
- return this._readyState;
32047
- }
32048
- get url() {
32049
- return this._url;
32050
- }
32051
- setSocket(socket, head, options) {
32052
- const receiver = new Receiver({
32053
- allowSynchronousEvents: options.allowSynchronousEvents,
32054
- binaryType: this.binaryType,
32055
- extensions: this._extensions,
32056
- isServer: this._isServer,
32057
- maxPayload: options.maxPayload,
32058
- skipUTF8Validation: options.skipUTF8Validation
32059
- });
32060
- const sender = new Sender(socket, this._extensions, options.generateMask);
32061
- this._receiver = receiver;
32062
- this._sender = sender;
32063
- this._socket = socket;
32064
- receiver[kWebSocket] = this;
32065
- sender[kWebSocket] = this;
32066
- socket[kWebSocket] = this;
32067
- receiver.on("conclude", receiverOnConclude);
32068
- receiver.on("drain", receiverOnDrain);
32069
- receiver.on("error", receiverOnError);
32070
- receiver.on("message", receiverOnMessage);
32071
- receiver.on("ping", receiverOnPing);
32072
- receiver.on("pong", receiverOnPong);
32073
- sender.onerror = senderOnError;
32074
- if (socket.setTimeout)
32075
- socket.setTimeout(0);
32076
- if (socket.setNoDelay)
32077
- socket.setNoDelay();
32078
- if (head.length > 0)
32079
- socket.unshift(head);
32080
- socket.on("close", socketOnClose);
32081
- socket.on("data", socketOnData);
32082
- socket.on("end", socketOnEnd);
32083
- socket.on("error", socketOnError);
32084
- this._readyState = WebSocket.OPEN;
32085
- this.emit("open");
32086
- }
32087
- emitClose() {
32088
- if (!this._socket) {
32089
- this._readyState = WebSocket.CLOSED;
32090
- this.emit("close", this._closeCode, this._closeMessage);
32091
- return;
32092
- }
32093
- if (this._extensions[PerMessageDeflate.extensionName]) {
32094
- this._extensions[PerMessageDeflate.extensionName].cleanup();
32095
- }
32096
- this._receiver.removeAllListeners();
32097
- this._readyState = WebSocket.CLOSED;
32098
- this.emit("close", this._closeCode, this._closeMessage);
32099
- }
32100
- close(code, data) {
32101
- if (this.readyState === WebSocket.CLOSED)
32102
- return;
32103
- if (this.readyState === WebSocket.CONNECTING) {
32104
- const msg = "WebSocket was closed before the connection was established";
32105
- abortHandshake(this, this._req, msg);
32106
- return;
32107
- }
32108
- if (this.readyState === WebSocket.CLOSING) {
32109
- if (this._closeFrameSent && (this._closeFrameReceived || this._receiver._writableState.errorEmitted)) {
32110
- this._socket.end();
32111
- }
32112
- return;
32113
- }
32114
- this._readyState = WebSocket.CLOSING;
32115
- this._sender.close(code, data, !this._isServer, (err) => {
32116
- if (err)
32117
- return;
32118
- this._closeFrameSent = true;
32119
- if (this._closeFrameReceived || this._receiver._writableState.errorEmitted) {
32120
- this._socket.end();
32121
- }
32122
- });
32123
- setCloseTimer(this);
32124
- }
32125
- pause() {
32126
- if (this.readyState === WebSocket.CONNECTING || this.readyState === WebSocket.CLOSED) {
32127
- return;
32128
- }
32129
- this._paused = true;
32130
- this._socket.pause();
32131
- }
32132
- ping(data, mask, cb) {
32133
- if (this.readyState === WebSocket.CONNECTING) {
32134
- throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
32135
- }
32136
- if (typeof data === "function") {
32137
- cb = data;
32138
- data = mask = undefined;
32139
- } else if (typeof mask === "function") {
32140
- cb = mask;
32141
- mask = undefined;
32142
- }
32143
- if (typeof data === "number")
32144
- data = data.toString();
32145
- if (this.readyState !== WebSocket.OPEN) {
32146
- sendAfterClose(this, data, cb);
32147
- return;
32148
- }
32149
- if (mask === undefined)
32150
- mask = !this._isServer;
32151
- this._sender.ping(data || EMPTY_BUFFER, mask, cb);
32152
- }
32153
- pong(data, mask, cb) {
32154
- if (this.readyState === WebSocket.CONNECTING) {
32155
- throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
32156
- }
32157
- if (typeof data === "function") {
32158
- cb = data;
32159
- data = mask = undefined;
32160
- } else if (typeof mask === "function") {
32161
- cb = mask;
32162
- mask = undefined;
32163
- }
32164
- if (typeof data === "number")
32165
- data = data.toString();
32166
- if (this.readyState !== WebSocket.OPEN) {
32167
- sendAfterClose(this, data, cb);
32168
- return;
32169
- }
32170
- if (mask === undefined)
32171
- mask = !this._isServer;
32172
- this._sender.pong(data || EMPTY_BUFFER, mask, cb);
32173
- }
32174
- resume() {
32175
- if (this.readyState === WebSocket.CONNECTING || this.readyState === WebSocket.CLOSED) {
32176
- return;
32177
- }
32178
- this._paused = false;
32179
- if (!this._receiver._writableState.needDrain)
32180
- this._socket.resume();
32181
- }
32182
- send(data, options, cb) {
32183
- if (this.readyState === WebSocket.CONNECTING) {
32184
- throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
32185
- }
32186
- if (typeof options === "function") {
32187
- cb = options;
32188
- options = {};
32189
- }
32190
- if (typeof data === "number")
32191
- data = data.toString();
32192
- if (this.readyState !== WebSocket.OPEN) {
32193
- sendAfterClose(this, data, cb);
32194
- return;
32195
- }
32196
- const opts = {
32197
- binary: typeof data !== "string",
32198
- mask: !this._isServer,
32199
- compress: true,
32200
- fin: true,
32201
- ...options
32202
- };
32203
- if (!this._extensions[PerMessageDeflate.extensionName]) {
32204
- opts.compress = false;
32205
- }
32206
- this._sender.send(data || EMPTY_BUFFER, opts, cb);
32207
- }
32208
- terminate() {
32209
- if (this.readyState === WebSocket.CLOSED)
32210
- return;
32211
- if (this.readyState === WebSocket.CONNECTING) {
32212
- const msg = "WebSocket was closed before the connection was established";
32213
- abortHandshake(this, this._req, msg);
32214
- return;
32215
- }
32216
- if (this._socket) {
32217
- this._readyState = WebSocket.CLOSING;
32218
- this._socket.destroy();
32219
- }
32220
- }
32221
- }
32222
- Object.defineProperty(WebSocket, "CONNECTING", {
32223
- enumerable: true,
32224
- value: readyStates.indexOf("CONNECTING")
32225
- });
32226
- Object.defineProperty(WebSocket.prototype, "CONNECTING", {
32227
- enumerable: true,
32228
- value: readyStates.indexOf("CONNECTING")
32229
- });
32230
- Object.defineProperty(WebSocket, "OPEN", {
32231
- enumerable: true,
32232
- value: readyStates.indexOf("OPEN")
32233
- });
32234
- Object.defineProperty(WebSocket.prototype, "OPEN", {
32235
- enumerable: true,
32236
- value: readyStates.indexOf("OPEN")
32237
- });
32238
- Object.defineProperty(WebSocket, "CLOSING", {
32239
- enumerable: true,
32240
- value: readyStates.indexOf("CLOSING")
32241
- });
32242
- Object.defineProperty(WebSocket.prototype, "CLOSING", {
32243
- enumerable: true,
32244
- value: readyStates.indexOf("CLOSING")
32245
- });
32246
- Object.defineProperty(WebSocket, "CLOSED", {
32247
- enumerable: true,
32248
- value: readyStates.indexOf("CLOSED")
32249
- });
32250
- Object.defineProperty(WebSocket.prototype, "CLOSED", {
32251
- enumerable: true,
32252
- value: readyStates.indexOf("CLOSED")
32253
- });
32254
- [
32255
- "binaryType",
32256
- "bufferedAmount",
32257
- "extensions",
32258
- "isPaused",
32259
- "protocol",
32260
- "readyState",
32261
- "url"
32262
- ].forEach((property) => {
32263
- Object.defineProperty(WebSocket.prototype, property, { enumerable: true });
32264
- });
32265
- ["open", "error", "close", "message"].forEach((method) => {
32266
- Object.defineProperty(WebSocket.prototype, `on${method}`, {
32267
- enumerable: true,
32268
- get() {
32269
- for (const listener of this.listeners(method)) {
32270
- if (listener[kForOnEventAttribute])
32271
- return listener[kListener];
32272
- }
32273
- return null;
32274
- },
32275
- set(handler2) {
32276
- for (const listener of this.listeners(method)) {
32277
- if (listener[kForOnEventAttribute]) {
32278
- this.removeListener(method, listener);
32279
- break;
32280
- }
32281
- }
32282
- if (typeof handler2 !== "function")
32283
- return;
32284
- this.addEventListener(method, handler2, {
32285
- [kForOnEventAttribute]: true
32286
- });
32287
- }
32288
- });
32289
- });
32290
- WebSocket.prototype.addEventListener = addEventListener;
32291
- WebSocket.prototype.removeEventListener = removeEventListener;
32292
- module.exports = WebSocket;
32293
- function initAsClient(websocket, address, protocols, options) {
32294
- const opts = {
32295
- allowSynchronousEvents: true,
32296
- autoPong: true,
32297
- protocolVersion: protocolVersions[1],
32298
- maxPayload: 100 * 1024 * 1024,
32299
- skipUTF8Validation: false,
32300
- perMessageDeflate: true,
32301
- followRedirects: false,
32302
- maxRedirects: 10,
32303
- ...options,
32304
- socketPath: undefined,
32305
- hostname: undefined,
32306
- protocol: undefined,
32307
- timeout: undefined,
32308
- method: "GET",
32309
- host: undefined,
32310
- path: undefined,
32311
- port: undefined
32312
- };
32313
- websocket._autoPong = opts.autoPong;
32314
- if (!protocolVersions.includes(opts.protocolVersion)) {
32315
- throw new RangeError(`Unsupported protocol version: ${opts.protocolVersion} ` + `(supported versions: ${protocolVersions.join(", ")})`);
32316
- }
32317
- let parsedUrl;
32318
- if (address instanceof URL2) {
32319
- parsedUrl = address;
32320
- } else {
32321
- try {
32322
- parsedUrl = new URL2(address);
32323
- } catch (e) {
32324
- throw new SyntaxError(`Invalid URL: ${address}`);
32325
- }
32326
- }
32327
- if (parsedUrl.protocol === "http:") {
32328
- parsedUrl.protocol = "ws:";
32329
- } else if (parsedUrl.protocol === "https:") {
32330
- parsedUrl.protocol = "wss:";
32331
- }
32332
- websocket._url = parsedUrl.href;
32333
- const isSecure = parsedUrl.protocol === "wss:";
32334
- const isIpcUrl = parsedUrl.protocol === "ws+unix:";
32335
- let invalidUrlMessage;
32336
- if (parsedUrl.protocol !== "ws:" && !isSecure && !isIpcUrl) {
32337
- invalidUrlMessage = `The URL's protocol must be one of "ws:", "wss:", ` + '"http:", "https:", or "ws+unix:"';
32338
- } else if (isIpcUrl && !parsedUrl.pathname) {
32339
- invalidUrlMessage = "The URL's pathname is empty";
32340
- } else if (parsedUrl.hash) {
32341
- invalidUrlMessage = "The URL contains a fragment identifier";
32342
- }
32343
- if (invalidUrlMessage) {
32344
- const err = new SyntaxError(invalidUrlMessage);
32345
- if (websocket._redirects === 0) {
32346
- throw err;
32347
- } else {
32348
- emitErrorAndClose(websocket, err);
32349
- return;
32350
- }
32351
- }
32352
- const defaultPort = isSecure ? 443 : 80;
32353
- const key = randomBytes(16).toString("base64");
32354
- const request = isSecure ? https.request : http.request;
32355
- const protocolSet = new Set;
32356
- let perMessageDeflate;
32357
- opts.createConnection = opts.createConnection || (isSecure ? tlsConnect : netConnect);
32358
- opts.defaultPort = opts.defaultPort || defaultPort;
32359
- opts.port = parsedUrl.port || defaultPort;
32360
- opts.host = parsedUrl.hostname.startsWith("[") ? parsedUrl.hostname.slice(1, -1) : parsedUrl.hostname;
32361
- opts.headers = {
32362
- ...opts.headers,
32363
- "Sec-WebSocket-Version": opts.protocolVersion,
32364
- "Sec-WebSocket-Key": key,
32365
- Connection: "Upgrade",
32366
- Upgrade: "websocket"
32367
- };
32368
- opts.path = parsedUrl.pathname + parsedUrl.search;
32369
- opts.timeout = opts.handshakeTimeout;
32370
- if (opts.perMessageDeflate) {
32371
- perMessageDeflate = new PerMessageDeflate(opts.perMessageDeflate !== true ? opts.perMessageDeflate : {}, false, opts.maxPayload);
32372
- opts.headers["Sec-WebSocket-Extensions"] = format2({
32373
- [PerMessageDeflate.extensionName]: perMessageDeflate.offer()
32374
- });
32375
- }
32376
- if (protocols.length) {
32377
- for (const protocol of protocols) {
32378
- if (typeof protocol !== "string" || !subprotocolRegex.test(protocol) || protocolSet.has(protocol)) {
32379
- throw new SyntaxError("An invalid or duplicated subprotocol was specified");
32380
- }
32381
- protocolSet.add(protocol);
32382
- }
32383
- opts.headers["Sec-WebSocket-Protocol"] = protocols.join(",");
32384
- }
32385
- if (opts.origin) {
32386
- if (opts.protocolVersion < 13) {
32387
- opts.headers["Sec-WebSocket-Origin"] = opts.origin;
32388
- } else {
32389
- opts.headers.Origin = opts.origin;
32390
- }
32391
- }
32392
- if (parsedUrl.username || parsedUrl.password) {
32393
- opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
32394
- }
32395
- if (isIpcUrl) {
32396
- const parts = opts.path.split(":");
32397
- opts.socketPath = parts[0];
32398
- opts.path = parts[1];
32399
- }
32400
- let req;
32401
- if (opts.followRedirects) {
32402
- if (websocket._redirects === 0) {
32403
- websocket._originalIpc = isIpcUrl;
32404
- websocket._originalSecure = isSecure;
32405
- websocket._originalHostOrSocketPath = isIpcUrl ? opts.socketPath : parsedUrl.host;
32406
- const headers = options && options.headers;
32407
- options = { ...options, headers: {} };
32408
- if (headers) {
32409
- for (const [key2, value] of Object.entries(headers)) {
32410
- options.headers[key2.toLowerCase()] = value;
32411
- }
32412
- }
32413
- } else if (websocket.listenerCount("redirect") === 0) {
32414
- const isSameHost = isIpcUrl ? websocket._originalIpc ? opts.socketPath === websocket._originalHostOrSocketPath : false : websocket._originalIpc ? false : parsedUrl.host === websocket._originalHostOrSocketPath;
32415
- if (!isSameHost || websocket._originalSecure && !isSecure) {
32416
- delete opts.headers.authorization;
32417
- delete opts.headers.cookie;
32418
- if (!isSameHost)
32419
- delete opts.headers.host;
32420
- opts.auth = undefined;
32421
- }
32422
- }
32423
- if (opts.auth && !options.headers.authorization) {
32424
- options.headers.authorization = "Basic " + Buffer.from(opts.auth).toString("base64");
32425
- }
32426
- req = websocket._req = request(opts);
32427
- if (websocket._redirects) {
32428
- websocket.emit("redirect", websocket.url, req);
32429
- }
32430
- } else {
32431
- req = websocket._req = request(opts);
32432
- }
32433
- if (opts.timeout) {
32434
- req.on("timeout", () => {
32435
- abortHandshake(websocket, req, "Opening handshake has timed out");
32436
- });
32437
- }
32438
- req.on("error", (err) => {
32439
- if (req === null || req[kAborted])
32440
- return;
32441
- req = websocket._req = null;
32442
- emitErrorAndClose(websocket, err);
32443
- });
32444
- req.on("response", (res) => {
32445
- const location = res.headers.location;
32446
- const statusCode = res.statusCode;
32447
- if (location && opts.followRedirects && statusCode >= 300 && statusCode < 400) {
32448
- if (++websocket._redirects > opts.maxRedirects) {
32449
- abortHandshake(websocket, req, "Maximum redirects exceeded");
32450
- return;
32451
- }
32452
- req.abort();
32453
- let addr;
32454
- try {
32455
- addr = new URL2(location, address);
32456
- } catch (e) {
32457
- const err = new SyntaxError(`Invalid URL: ${location}`);
32458
- emitErrorAndClose(websocket, err);
32459
- return;
32460
- }
32461
- initAsClient(websocket, addr, protocols, options);
32462
- } else if (!websocket.emit("unexpected-response", req, res)) {
32463
- abortHandshake(websocket, req, `Unexpected server response: ${res.statusCode}`);
32464
- }
32465
- });
32466
- req.on("upgrade", (res, socket, head) => {
32467
- websocket.emit("upgrade", res);
32468
- if (websocket.readyState !== WebSocket.CONNECTING)
32469
- return;
32470
- req = websocket._req = null;
32471
- const upgrade = res.headers.upgrade;
32472
- if (upgrade === undefined || upgrade.toLowerCase() !== "websocket") {
32473
- abortHandshake(websocket, socket, "Invalid Upgrade header");
32474
- return;
32475
- }
32476
- const digest = createHash("sha1").update(key + GUID).digest("base64");
32477
- if (res.headers["sec-websocket-accept"] !== digest) {
32478
- abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
32479
- return;
32480
- }
32481
- const serverProt = res.headers["sec-websocket-protocol"];
32482
- let protError;
32483
- if (serverProt !== undefined) {
32484
- if (!protocolSet.size) {
32485
- protError = "Server sent a subprotocol but none was requested";
32486
- } else if (!protocolSet.has(serverProt)) {
32487
- protError = "Server sent an invalid subprotocol";
32488
- }
32489
- } else if (protocolSet.size) {
32490
- protError = "Server sent no subprotocol";
32491
- }
32492
- if (protError) {
32493
- abortHandshake(websocket, socket, protError);
32494
- return;
32495
- }
32496
- if (serverProt)
32497
- websocket._protocol = serverProt;
32498
- const secWebSocketExtensions = res.headers["sec-websocket-extensions"];
32499
- if (secWebSocketExtensions !== undefined) {
32500
- if (!perMessageDeflate) {
32501
- const message = "Server sent a Sec-WebSocket-Extensions header but no extension " + "was requested";
32502
- abortHandshake(websocket, socket, message);
32503
- return;
32504
- }
32505
- let extensions;
32506
- try {
32507
- extensions = parse(secWebSocketExtensions);
32508
- } catch (err) {
32509
- const message = "Invalid Sec-WebSocket-Extensions header";
32510
- abortHandshake(websocket, socket, message);
32511
- return;
32512
- }
32513
- const extensionNames = Object.keys(extensions);
32514
- if (extensionNames.length !== 1 || extensionNames[0] !== PerMessageDeflate.extensionName) {
32515
- const message = "Server indicated an extension that was not requested";
32516
- abortHandshake(websocket, socket, message);
32517
- return;
32518
- }
32519
- try {
32520
- perMessageDeflate.accept(extensions[PerMessageDeflate.extensionName]);
32521
- } catch (err) {
32522
- const message = "Invalid Sec-WebSocket-Extensions header";
32523
- abortHandshake(websocket, socket, message);
32524
- return;
32525
- }
32526
- websocket._extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
32527
- }
32528
- websocket.setSocket(socket, head, {
32529
- allowSynchronousEvents: opts.allowSynchronousEvents,
32530
- generateMask: opts.generateMask,
32531
- maxPayload: opts.maxPayload,
32532
- skipUTF8Validation: opts.skipUTF8Validation
32533
- });
32534
- });
32535
- if (opts.finishRequest) {
32536
- opts.finishRequest(req, websocket);
32537
- } else {
32538
- req.end();
32539
- }
32540
- }
32541
- function emitErrorAndClose(websocket, err) {
32542
- websocket._readyState = WebSocket.CLOSING;
32543
- websocket._errorEmitted = true;
32544
- websocket.emit("error", err);
32545
- websocket.emitClose();
32546
- }
32547
- function netConnect(options) {
32548
- options.path = options.socketPath;
32549
- return net.connect(options);
32550
- }
32551
- function tlsConnect(options) {
32552
- options.path = undefined;
32553
- if (!options.servername && options.servername !== "") {
32554
- options.servername = net.isIP(options.host) ? "" : options.host;
32555
- }
32556
- return tls.connect(options);
32557
- }
32558
- function abortHandshake(websocket, stream, message) {
32559
- websocket._readyState = WebSocket.CLOSING;
32560
- const err = new Error(message);
32561
- Error.captureStackTrace(err, abortHandshake);
32562
- if (stream.setHeader) {
32563
- stream[kAborted] = true;
32564
- stream.abort();
32565
- if (stream.socket && !stream.socket.destroyed) {
32566
- stream.socket.destroy();
32567
- }
32568
- process.nextTick(emitErrorAndClose, websocket, err);
32569
- } else {
32570
- stream.destroy(err);
32571
- stream.once("error", websocket.emit.bind(websocket, "error"));
32572
- stream.once("close", websocket.emitClose.bind(websocket));
32573
- }
32574
- }
32575
- function sendAfterClose(websocket, data, cb) {
32576
- if (data) {
32577
- const length = isBlob(data) ? data.size : toBuffer(data).length;
32578
- if (websocket._socket)
32579
- websocket._sender._bufferedBytes += length;
32580
- else
32581
- websocket._bufferedAmount += length;
32582
- }
32583
- if (cb) {
32584
- const err = new Error(`WebSocket is not open: readyState ${websocket.readyState} ` + `(${readyStates[websocket.readyState]})`);
32585
- process.nextTick(cb, err);
32586
- }
32587
- }
32588
- function receiverOnConclude(code, reason) {
32589
- const websocket = this[kWebSocket];
32590
- websocket._closeFrameReceived = true;
32591
- websocket._closeMessage = reason;
32592
- websocket._closeCode = code;
32593
- if (websocket._socket[kWebSocket] === undefined)
32594
- return;
32595
- websocket._socket.removeListener("data", socketOnData);
32596
- process.nextTick(resume, websocket._socket);
32597
- if (code === 1005)
32598
- websocket.close();
32599
- else
32600
- websocket.close(code, reason);
32601
- }
32602
- function receiverOnDrain() {
32603
- const websocket = this[kWebSocket];
32604
- if (!websocket.isPaused)
32605
- websocket._socket.resume();
32606
- }
32607
- function receiverOnError(err) {
32608
- const websocket = this[kWebSocket];
32609
- if (websocket._socket[kWebSocket] !== undefined) {
32610
- websocket._socket.removeListener("data", socketOnData);
32611
- process.nextTick(resume, websocket._socket);
32612
- websocket.close(err[kStatusCode]);
32613
- }
32614
- if (!websocket._errorEmitted) {
32615
- websocket._errorEmitted = true;
32616
- websocket.emit("error", err);
32617
- }
32618
- }
32619
- function receiverOnFinish() {
32620
- this[kWebSocket].emitClose();
32621
- }
32622
- function receiverOnMessage(data, isBinary2) {
32623
- this[kWebSocket].emit("message", data, isBinary2);
32624
- }
32625
- function receiverOnPing(data) {
32626
- const websocket = this[kWebSocket];
32627
- if (websocket._autoPong)
32628
- websocket.pong(data, !this._isServer, NOOP);
32629
- websocket.emit("ping", data);
32630
- }
32631
- function receiverOnPong(data) {
32632
- this[kWebSocket].emit("pong", data);
32633
- }
32634
- function resume(stream) {
32635
- stream.resume();
32636
- }
32637
- function senderOnError(err) {
32638
- const websocket = this[kWebSocket];
32639
- if (websocket.readyState === WebSocket.CLOSED)
32640
- return;
32641
- if (websocket.readyState === WebSocket.OPEN) {
32642
- websocket._readyState = WebSocket.CLOSING;
32643
- setCloseTimer(websocket);
32644
- }
32645
- this._socket.end();
32646
- if (!websocket._errorEmitted) {
32647
- websocket._errorEmitted = true;
32648
- websocket.emit("error", err);
32649
- }
32650
- }
32651
- function setCloseTimer(websocket) {
32652
- websocket._closeTimer = setTimeout(websocket._socket.destroy.bind(websocket._socket), closeTimeout);
32653
- }
32654
- function socketOnClose() {
32655
- const websocket = this[kWebSocket];
32656
- this.removeListener("close", socketOnClose);
32657
- this.removeListener("data", socketOnData);
32658
- this.removeListener("end", socketOnEnd);
32659
- websocket._readyState = WebSocket.CLOSING;
32660
- let chunk;
32661
- if (!this._readableState.endEmitted && !websocket._closeFrameReceived && !websocket._receiver._writableState.errorEmitted && (chunk = websocket._socket.read()) !== null) {
32662
- websocket._receiver.write(chunk);
32663
- }
32664
- websocket._receiver.end();
32665
- this[kWebSocket] = undefined;
32666
- clearTimeout(websocket._closeTimer);
32667
- if (websocket._receiver._writableState.finished || websocket._receiver._writableState.errorEmitted) {
32668
- websocket.emitClose();
32669
- } else {
32670
- websocket._receiver.on("error", receiverOnFinish);
32671
- websocket._receiver.on("finish", receiverOnFinish);
32672
- }
32673
- }
32674
- function socketOnData(chunk) {
32675
- if (!this[kWebSocket]._receiver.write(chunk)) {
32676
- this.pause();
32677
- }
32678
- }
32679
- function socketOnEnd() {
32680
- const websocket = this[kWebSocket];
32681
- websocket._readyState = WebSocket.CLOSING;
32682
- websocket._receiver.end();
32683
- this.end();
32684
- }
32685
- function socketOnError() {
32686
- const websocket = this[kWebSocket];
32687
- this.removeListener("error", socketOnError);
32688
- this.on("error", NOOP);
32689
- if (websocket) {
32690
- websocket._readyState = WebSocket.CLOSING;
32691
- this.destroy();
32692
- }
32693
- }
32694
- });
32695
-
32696
- // node_modules/ink/node_modules/ws/lib/stream.js
32697
- var require_stream2 = __commonJS((exports, module) => {
32698
- var WebSocket = require_websocket2();
32699
- var { Duplex } = __require("stream");
32700
- function emitClose(stream) {
32701
- stream.emit("close");
32702
- }
32703
- function duplexOnEnd() {
32704
- if (!this.destroyed && this._writableState.finished) {
32705
- this.destroy();
32706
- }
32707
- }
32708
- function duplexOnError(err) {
32709
- this.removeListener("error", duplexOnError);
32710
- this.destroy();
32711
- if (this.listenerCount("error") === 0) {
32712
- this.emit("error", err);
32713
- }
32714
- }
32715
- function createWebSocketStream(ws, options) {
32716
- let terminateOnDestroy = true;
32717
- const duplex = new Duplex({
32718
- ...options,
32719
- autoDestroy: false,
32720
- emitClose: false,
32721
- objectMode: false,
32722
- writableObjectMode: false
32723
- });
32724
- ws.on("message", function message(msg, isBinary2) {
32725
- const data = !isBinary2 && duplex._readableState.objectMode ? msg.toString() : msg;
32726
- if (!duplex.push(data))
32727
- ws.pause();
32728
- });
32729
- ws.once("error", function error(err) {
32730
- if (duplex.destroyed)
32731
- return;
32732
- terminateOnDestroy = false;
32733
- duplex.destroy(err);
32734
- });
32735
- ws.once("close", function close() {
32736
- if (duplex.destroyed)
32737
- return;
32738
- duplex.push(null);
32739
- });
32740
- duplex._destroy = function(err, callback) {
32741
- if (ws.readyState === ws.CLOSED) {
32742
- callback(err);
32743
- process.nextTick(emitClose, duplex);
32744
- return;
32745
- }
32746
- let called = false;
32747
- ws.once("error", function error(err2) {
32748
- called = true;
32749
- callback(err2);
32750
- });
32751
- ws.once("close", function close() {
32752
- if (!called)
32753
- callback(err);
32754
- process.nextTick(emitClose, duplex);
32755
- });
32756
- if (terminateOnDestroy)
32757
- ws.terminate();
32758
- };
32759
- duplex._final = function(callback) {
32760
- if (ws.readyState === ws.CONNECTING) {
32761
- ws.once("open", function open() {
32762
- duplex._final(callback);
32763
- });
32764
- return;
32765
- }
32766
- if (ws._socket === null)
32767
- return;
32768
- if (ws._socket._writableState.finished) {
32769
- callback();
32770
- if (duplex._readableState.endEmitted)
32771
- duplex.destroy();
32772
- } else {
32773
- ws._socket.once("finish", function finish() {
32774
- callback();
32775
- });
32776
- ws.close();
32777
- }
32778
- };
32779
- duplex._read = function() {
32780
- if (ws.isPaused)
32781
- ws.resume();
32782
- };
32783
- duplex._write = function(chunk, encoding, callback) {
32784
- if (ws.readyState === ws.CONNECTING) {
32785
- ws.once("open", function open() {
32786
- duplex._write(chunk, encoding, callback);
32787
- });
32788
- return;
32789
- }
32790
- ws.send(chunk, callback);
32791
- };
32792
- duplex.on("end", duplexOnEnd);
32793
- duplex.on("error", duplexOnError);
32794
- return duplex;
32795
- }
32796
- module.exports = createWebSocketStream;
32797
- });
32798
-
32799
- // node_modules/ink/node_modules/ws/lib/subprotocol.js
32800
- var require_subprotocol2 = __commonJS((exports, module) => {
32801
- var { tokenChars } = require_validation2();
32802
- function parse(header) {
32803
- const protocols = new Set;
32804
- let start = -1;
32805
- let end = -1;
32806
- let i2 = 0;
32807
- for (i2;i2 < header.length; i2++) {
32808
- const code = header.charCodeAt(i2);
32809
- if (end === -1 && tokenChars[code] === 1) {
32810
- if (start === -1)
32811
- start = i2;
32812
- } else if (i2 !== 0 && (code === 32 || code === 9)) {
32813
- if (end === -1 && start !== -1)
32814
- end = i2;
32815
- } else if (code === 44) {
32816
- if (start === -1) {
32817
- throw new SyntaxError(`Unexpected character at index ${i2}`);
32818
- }
32819
- if (end === -1)
32820
- end = i2;
32821
- const protocol2 = header.slice(start, end);
32822
- if (protocols.has(protocol2)) {
32823
- throw new SyntaxError(`The "${protocol2}" subprotocol is duplicated`);
32824
- }
32825
- protocols.add(protocol2);
32826
- start = end = -1;
32827
- } else {
32828
- throw new SyntaxError(`Unexpected character at index ${i2}`);
32829
- }
32830
- }
32831
- if (start === -1 || end !== -1) {
32832
- throw new SyntaxError("Unexpected end of input");
32833
- }
32834
- const protocol = header.slice(start, i2);
32835
- if (protocols.has(protocol)) {
32836
- throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
32837
- }
32838
- protocols.add(protocol);
32839
- return protocols;
32840
- }
32841
- module.exports = { parse };
32842
- });
32843
-
32844
- // node_modules/ink/node_modules/ws/lib/websocket-server.js
32845
- var require_websocket_server2 = __commonJS((exports, module) => {
32846
- var EventEmitter5 = __require("events");
32847
- var http = __require("http");
32848
- var { Duplex } = __require("stream");
32849
- var { createHash } = __require("crypto");
32850
- var extension = require_extension2();
32851
- var PerMessageDeflate = require_permessage_deflate2();
32852
- var subprotocol = require_subprotocol2();
32853
- var WebSocket = require_websocket2();
32854
- var { GUID, kWebSocket } = require_constants6();
32855
- var keyRegex = /^[+/0-9A-Za-z]{22}==$/;
32856
- var RUNNING = 0;
32857
- var CLOSING = 1;
32858
- var CLOSED = 2;
32859
-
32860
- class WebSocketServer extends EventEmitter5 {
32861
- constructor(options, callback) {
32862
- super();
32863
- options = {
32864
- allowSynchronousEvents: true,
32865
- autoPong: true,
32866
- maxPayload: 100 * 1024 * 1024,
32867
- skipUTF8Validation: false,
32868
- perMessageDeflate: false,
32869
- handleProtocols: null,
32870
- clientTracking: true,
32871
- verifyClient: null,
32872
- noServer: false,
32873
- backlog: null,
32874
- server: null,
32875
- host: null,
32876
- path: null,
32877
- port: null,
32878
- WebSocket,
32879
- ...options
32880
- };
32881
- if (options.port == null && !options.server && !options.noServer || options.port != null && (options.server || options.noServer) || options.server && options.noServer) {
32882
- throw new TypeError('One and only one of the "port", "server", or "noServer" options ' + "must be specified");
32883
- }
32884
- if (options.port != null) {
32885
- this._server = http.createServer((req, res) => {
32886
- const body = http.STATUS_CODES[426];
32887
- res.writeHead(426, {
32888
- "Content-Length": body.length,
32889
- "Content-Type": "text/plain"
32890
- });
32891
- res.end(body);
32892
- });
32893
- this._server.listen(options.port, options.host, options.backlog, callback);
32894
- } else if (options.server) {
32895
- this._server = options.server;
32896
- }
32897
- if (this._server) {
32898
- const emitConnection = this.emit.bind(this, "connection");
32899
- this._removeListeners = addListeners(this._server, {
32900
- listening: this.emit.bind(this, "listening"),
32901
- error: this.emit.bind(this, "error"),
32902
- upgrade: (req, socket, head) => {
32903
- this.handleUpgrade(req, socket, head, emitConnection);
32904
- }
32905
- });
32906
- }
32907
- if (options.perMessageDeflate === true)
32908
- options.perMessageDeflate = {};
32909
- if (options.clientTracking) {
32910
- this.clients = new Set;
32911
- this._shouldEmitClose = false;
32912
- }
32913
- this.options = options;
32914
- this._state = RUNNING;
32915
- }
32916
- address() {
32917
- if (this.options.noServer) {
32918
- throw new Error('The server is operating in "noServer" mode');
32919
- }
32920
- if (!this._server)
32921
- return null;
32922
- return this._server.address();
32923
- }
32924
- close(cb) {
32925
- if (this._state === CLOSED) {
32926
- if (cb) {
32927
- this.once("close", () => {
32928
- cb(new Error("The server is not running"));
32929
- });
32930
- }
32931
- process.nextTick(emitClose, this);
32932
- return;
32933
- }
32934
- if (cb)
32935
- this.once("close", cb);
32936
- if (this._state === CLOSING)
32937
- return;
32938
- this._state = CLOSING;
32939
- if (this.options.noServer || this.options.server) {
32940
- if (this._server) {
32941
- this._removeListeners();
32942
- this._removeListeners = this._server = null;
32943
- }
32944
- if (this.clients) {
32945
- if (!this.clients.size) {
32946
- process.nextTick(emitClose, this);
32947
- } else {
32948
- this._shouldEmitClose = true;
32949
- }
32950
- } else {
32951
- process.nextTick(emitClose, this);
32952
- }
32953
- } else {
32954
- const server = this._server;
32955
- this._removeListeners();
32956
- this._removeListeners = this._server = null;
32957
- server.close(() => {
32958
- emitClose(this);
32959
- });
32960
- }
32961
- }
32962
- shouldHandle(req) {
32963
- if (this.options.path) {
32964
- const index = req.url.indexOf("?");
32965
- const pathname = index !== -1 ? req.url.slice(0, index) : req.url;
32966
- if (pathname !== this.options.path)
32967
- return false;
32968
- }
32969
- return true;
32970
- }
32971
- handleUpgrade(req, socket, head, cb) {
32972
- socket.on("error", socketOnError);
32973
- const key = req.headers["sec-websocket-key"];
32974
- const upgrade = req.headers.upgrade;
32975
- const version = +req.headers["sec-websocket-version"];
32976
- if (req.method !== "GET") {
32977
- const message = "Invalid HTTP method";
32978
- abortHandshakeOrEmitwsClientError(this, req, socket, 405, message);
32979
- return;
32980
- }
32981
- if (upgrade === undefined || upgrade.toLowerCase() !== "websocket") {
32982
- const message = "Invalid Upgrade header";
32983
- abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
32984
- return;
32985
- }
32986
- if (key === undefined || !keyRegex.test(key)) {
32987
- const message = "Missing or invalid Sec-WebSocket-Key header";
32988
- abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
32989
- return;
32990
- }
32991
- if (version !== 13 && version !== 8) {
32992
- const message = "Missing or invalid Sec-WebSocket-Version header";
32993
- abortHandshakeOrEmitwsClientError(this, req, socket, 400, message, {
32994
- "Sec-WebSocket-Version": "13, 8"
32995
- });
32996
- return;
32997
- }
32998
- if (!this.shouldHandle(req)) {
32999
- abortHandshake(socket, 400);
33000
- return;
33001
- }
33002
- const secWebSocketProtocol = req.headers["sec-websocket-protocol"];
33003
- let protocols = new Set;
33004
- if (secWebSocketProtocol !== undefined) {
33005
- try {
33006
- protocols = subprotocol.parse(secWebSocketProtocol);
33007
- } catch (err) {
33008
- const message = "Invalid Sec-WebSocket-Protocol header";
33009
- abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
33010
- return;
33011
- }
33012
- }
33013
- const secWebSocketExtensions = req.headers["sec-websocket-extensions"];
33014
- const extensions = {};
33015
- if (this.options.perMessageDeflate && secWebSocketExtensions !== undefined) {
33016
- const perMessageDeflate = new PerMessageDeflate(this.options.perMessageDeflate, true, this.options.maxPayload);
33017
- try {
33018
- const offers = extension.parse(secWebSocketExtensions);
33019
- if (offers[PerMessageDeflate.extensionName]) {
33020
- perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]);
33021
- extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
33022
- }
33023
- } catch (err) {
33024
- const message = "Invalid or unacceptable Sec-WebSocket-Extensions header";
33025
- abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
33026
- return;
33027
- }
33028
- }
33029
- if (this.options.verifyClient) {
33030
- const info = {
33031
- origin: req.headers[`${version === 8 ? "sec-websocket-origin" : "origin"}`],
33032
- secure: !!(req.socket.authorized || req.socket.encrypted),
33033
- req
33034
- };
33035
- if (this.options.verifyClient.length === 2) {
33036
- this.options.verifyClient(info, (verified, code, message, headers) => {
33037
- if (!verified) {
33038
- return abortHandshake(socket, code || 401, message, headers);
33039
- }
33040
- this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
33041
- });
33042
- return;
33043
- }
33044
- if (!this.options.verifyClient(info))
33045
- return abortHandshake(socket, 401);
33046
- }
33047
- this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
33048
- }
33049
- completeUpgrade(extensions, key, protocols, req, socket, head, cb) {
33050
- if (!socket.readable || !socket.writable)
33051
- return socket.destroy();
33052
- if (socket[kWebSocket]) {
33053
- throw new Error("server.handleUpgrade() was called more than once with the same " + "socket, possibly due to a misconfiguration");
33054
- }
33055
- if (this._state > RUNNING)
33056
- return abortHandshake(socket, 503);
33057
- const digest = createHash("sha1").update(key + GUID).digest("base64");
33058
- const headers = [
33059
- "HTTP/1.1 101 Switching Protocols",
33060
- "Upgrade: websocket",
33061
- "Connection: Upgrade",
33062
- `Sec-WebSocket-Accept: ${digest}`
33063
- ];
33064
- const ws = new this.options.WebSocket(null, undefined, this.options);
33065
- if (protocols.size) {
33066
- const protocol = this.options.handleProtocols ? this.options.handleProtocols(protocols, req) : protocols.values().next().value;
33067
- if (protocol) {
33068
- headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
33069
- ws._protocol = protocol;
33070
- }
33071
- }
33072
- if (extensions[PerMessageDeflate.extensionName]) {
33073
- const params = extensions[PerMessageDeflate.extensionName].params;
33074
- const value = extension.format({
33075
- [PerMessageDeflate.extensionName]: [params]
33076
- });
33077
- headers.push(`Sec-WebSocket-Extensions: ${value}`);
33078
- ws._extensions = extensions;
33079
- }
33080
- this.emit("headers", headers, req);
33081
- socket.write(headers.concat(`\r
33082
- `).join(`\r
33083
- `));
33084
- socket.removeListener("error", socketOnError);
33085
- ws.setSocket(socket, head, {
33086
- allowSynchronousEvents: this.options.allowSynchronousEvents,
33087
- maxPayload: this.options.maxPayload,
33088
- skipUTF8Validation: this.options.skipUTF8Validation
33089
- });
33090
- if (this.clients) {
33091
- this.clients.add(ws);
33092
- ws.on("close", () => {
33093
- this.clients.delete(ws);
33094
- if (this._shouldEmitClose && !this.clients.size) {
33095
- process.nextTick(emitClose, this);
33096
- }
33097
- });
33098
- }
33099
- cb(ws, req);
33100
- }
33101
- }
33102
- module.exports = WebSocketServer;
33103
- function addListeners(server, map2) {
33104
- for (const event of Object.keys(map2))
33105
- server.on(event, map2[event]);
33106
- return function removeListeners() {
33107
- for (const event of Object.keys(map2)) {
33108
- server.removeListener(event, map2[event]);
33109
- }
33110
- };
33111
- }
33112
- function emitClose(server) {
33113
- server._state = CLOSED;
33114
- server.emit("close");
33115
- }
33116
- function socketOnError() {
33117
- this.destroy();
33118
- }
33119
- function abortHandshake(socket, code, message, headers) {
33120
- message = message || http.STATUS_CODES[code];
33121
- headers = {
33122
- Connection: "close",
33123
- "Content-Type": "text/html",
33124
- "Content-Length": Buffer.byteLength(message),
33125
- ...headers
33126
- };
33127
- socket.once("finish", socket.destroy);
33128
- socket.end(`HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r
33129
- ` + Object.keys(headers).map((h) => `${h}: ${headers[h]}`).join(`\r
33130
- `) + `\r
33131
- \r
33132
- ` + message);
33133
- }
33134
- function abortHandshakeOrEmitwsClientError(server, req, socket, code, message, headers) {
33135
- if (server.listenerCount("wsClientError")) {
33136
- const err = new Error(message);
33137
- Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError);
33138
- server.emit("wsClientError", err, socket, req);
33139
- } else {
33140
- abortHandshake(socket, code, message, headers);
33141
- }
33142
- }
33143
- });
33144
-
33145
- // node_modules/ink/node_modules/ws/wrapper.mjs
33146
- var import_stream, import_receiver, import_sender, import_websocket5, import_websocket_server, wrapper_default;
30306
+ // node_modules/ws/wrapper.mjs
30307
+ var import_stream, import_extension, import_permessage_deflate, import_receiver, import_sender, import_subprotocol, import_websocket5, import_websocket_server, wrapper_default;
33147
30308
  var init_wrapper = __esm(() => {
33148
- import_stream = __toESM(require_stream2(), 1);
33149
- import_receiver = __toESM(require_receiver2(), 1);
33150
- import_sender = __toESM(require_sender2(), 1);
33151
- import_websocket5 = __toESM(require_websocket2(), 1);
33152
- import_websocket_server = __toESM(require_websocket_server2(), 1);
30309
+ import_stream = __toESM(require_stream(), 1);
30310
+ import_extension = __toESM(require_extension(), 1);
30311
+ import_permessage_deflate = __toESM(require_permessage_deflate(), 1);
30312
+ import_receiver = __toESM(require_receiver(), 1);
30313
+ import_sender = __toESM(require_sender(), 1);
30314
+ import_subprotocol = __toESM(require_subprotocol(), 1);
30315
+ import_websocket5 = __toESM(require_websocket(), 1);
30316
+ import_websocket_server = __toESM(require_websocket_server(), 1);
33153
30317
  wrapper_default = import_websocket5.default;
33154
30318
  });
33155
30319
 
@@ -54157,6 +51321,13 @@ async function runOnboarding(reconfigure = false) {
54157
51321
  { title: "Require", value: "require", description: "Always require branch name before starting" }
54158
51322
  ],
54159
51323
  initial: existingConfig?.worktreeMode === "off" ? 1 : existingConfig?.worktreeMode === "require" ? 2 : 0
51324
+ },
51325
+ {
51326
+ type: "confirm",
51327
+ name: "respondOnlyWhenMentioned",
51328
+ message: "Respond only when @mentioned?",
51329
+ initial: existingConfig?.respondOnlyWhenMentioned || false,
51330
+ hint: "New threads start in quiet mode; users can still toggle per-thread with !mentions"
54160
51331
  }
54161
51332
  ], { onCancel });
54162
51333
  const config = {
@@ -54164,6 +51335,9 @@ async function runOnboarding(reconfigure = false) {
54164
51335
  ...globalSettings,
54165
51336
  platforms: []
54166
51337
  };
51338
+ if (!config.respondOnlyWhenMentioned) {
51339
+ delete config.respondOnlyWhenMentioned;
51340
+ }
54167
51341
  console.log("");
54168
51342
  console.log(bold(" Platform Setup"));
54169
51343
  console.log("");
@@ -54274,7 +51448,7 @@ async function runReconfigureFlow(existingConfig) {
54274
51448
  {
54275
51449
  title: "Global settings",
54276
51450
  value: "global",
54277
- description: `workingDir, chrome, worktreeMode`
51451
+ description: `workingDir, chrome, worktreeMode, mentions`
54278
51452
  }
54279
51453
  ];
54280
51454
  for (let i2 = 0;i2 < config.platforms.length; i2++) {
@@ -54321,9 +51495,19 @@ async function runReconfigureFlow(existingConfig) {
54321
51495
  { title: "Require", value: "require", description: "Always require branch name before starting" }
54322
51496
  ],
54323
51497
  initial: config.worktreeMode === "off" ? 1 : config.worktreeMode === "require" ? 2 : 0
51498
+ },
51499
+ {
51500
+ type: "confirm",
51501
+ name: "respondOnlyWhenMentioned",
51502
+ message: "Respond only when @mentioned?",
51503
+ initial: config.respondOnlyWhenMentioned || false,
51504
+ hint: "New threads start in quiet mode; users can still toggle per-thread with !mentions"
54324
51505
  }
54325
51506
  ], { onCancel });
54326
51507
  config = { ...config, ...globalSettings };
51508
+ if (!config.respondOnlyWhenMentioned) {
51509
+ delete config.respondOnlyWhenMentioned;
51510
+ }
54327
51511
  console.log(green(" ✓ Global settings updated"));
54328
51512
  } else if (action === "add-new") {
54329
51513
  console.log("");
@@ -54452,6 +51636,7 @@ async function showConfigSummary(config) {
54452
51636
  console.log(dim(` Working Directory: ${config.workingDir}`));
54453
51637
  console.log(dim(` Chrome Integration: ${config.chrome ? "Enabled" : "Disabled"}`));
54454
51638
  console.log(dim(` Worktree Mode: ${config.worktreeMode}`));
51639
+ console.log(dim(` Respond Only When Mentioned: ${config.respondOnlyWhenMentioned ? "Enabled" : "Disabled"}`));
54455
51640
  console.log("");
54456
51641
  console.log(dim(` Platforms (${config.platforms.length}):`));
54457
51642
  for (const platform of config.platforms) {
@@ -59463,6 +56648,14 @@ var COMMAND_REGISTRY = [
59463
56648
  worksInFirstMessage: true,
59464
56649
  isStackable: true
59465
56650
  },
56651
+ {
56652
+ command: "mentions",
56653
+ description: "Toggle quiet mode: only respond when @mentioned by name",
56654
+ args: "on / off",
56655
+ category: "settings",
56656
+ audience: "user",
56657
+ claudeNotes: "User decisions, not yours"
56658
+ },
59466
56659
  {
59467
56660
  command: "update",
59468
56661
  description: "Show auto-update status",
@@ -59572,6 +56765,7 @@ var COMMAND_PATTERNS = [
59572
56765
  ["invite", /^!invite\s+@?([\w.-]+)\s*$/i],
59573
56766
  ["kick", /^!kick\s+@?([\w.-]+)\s*$/i],
59574
56767
  ["permissions", /^!permissions?\s+(default|auto|bypass|interactive|skip)\s*$/i],
56768
+ ["mentions", /^!mentions(?:\s+(on|off))?\s*$/i],
59575
56769
  ["update", /^!update(?:\s+(now|defer))?\s*$/i],
59576
56770
  ["context", /^!context\s*$/i],
59577
56771
  ["cost", /^!cost\s*$/i],
@@ -59956,6 +57150,15 @@ var handlePermissions = async (ctx, args) => {
59956
57150
  await ctx.sessionManager.setSessionPermissionMode(ctx.threadId, ctx.username, mode);
59957
57151
  return { handled: true };
59958
57152
  };
57153
+ var handleMentions = async (ctx, args) => {
57154
+ if (ctx.commandContext === "first-message") {
57155
+ return { handled: false };
57156
+ }
57157
+ if (ctx.isAllowed) {
57158
+ await ctx.sessionManager.setRespondOnlyWhenMentioned(ctx.threadId, ctx.username, args);
57159
+ }
57160
+ return { handled: true };
57161
+ };
59959
57162
  var handleWorktree = async (ctx, args) => {
59960
57163
  const parts = args?.split(/\s+/) || [];
59961
57164
  const subcommandOrBranch = parts[0]?.toLowerCase();
@@ -60089,6 +57292,7 @@ handlers.set("kick", handleKick);
60089
57292
  handlers.set("github-email", handleGitHubEmail);
60090
57293
  handlers.set("cd", handleCd);
60091
57294
  handlers.set("permissions", handlePermissions);
57295
+ handlers.set("mentions", handleMentions);
60092
57296
  handlers.set("worktree", handleWorktree);
60093
57297
  handlers.set("bug", handleBug);
60094
57298
  handlers.set("plugin", handlePlugin);
@@ -71262,6 +68466,31 @@ async function kickUser(session, kickedUser, kickedBy, ctx) {
71262
68466
  sessionLog5(session).warn(`\uD83D\uDEAB @${kickedUser} was not in session`);
71263
68467
  }
71264
68468
  }
68469
+ async function setRespondOnlyWhenMentioned(session, username, arg, ctx) {
68470
+ if (!await requireSessionOwner(session, username, "change session settings")) {
68471
+ return;
68472
+ }
68473
+ const normalized = arg?.toLowerCase();
68474
+ let enabled;
68475
+ if (normalized === "on") {
68476
+ enabled = true;
68477
+ } else if (normalized === "off") {
68478
+ enabled = false;
68479
+ } else {
68480
+ enabled = !session.respondOnlyWhenMentioned;
68481
+ }
68482
+ session.respondOnlyWhenMentioned = enabled;
68483
+ ctx.ops.persistSession(session);
68484
+ const botName = session.platform.getBotName();
68485
+ if (enabled) {
68486
+ await post(session, "success", `Quiet mode on — I'll only respond when you @mention me (\`@${botName}\`). Use \`!mentions off\` to turn this off.`);
68487
+ } else {
68488
+ await post(session, "success", `Quiet mode off — I'll respond to every message in this thread again.`);
68489
+ }
68490
+ sessionLog5(session).info(`\uD83D\uDD15 respondOnlyWhenMentioned=${enabled} by @${username}`);
68491
+ session.threadLogger?.logCommand("mentions", enabled ? "on" : "off", username);
68492
+ await updateSessionHeader(session, ctx);
68493
+ }
71265
68494
  async function setGitHubEmail(session, username, arg, ctx) {
71266
68495
  const formatter = session.platform.getFormatter();
71267
68496
  const trimmed = arg?.trim();
@@ -71436,6 +68665,9 @@ async function updateSessionHeader(session, ctx) {
71436
68665
  if (otherParticipants) {
71437
68666
  items.push(["\uD83D\uDC65", "Participants", otherParticipants]);
71438
68667
  }
68668
+ if (session.respondOnlyWhenMentioned) {
68669
+ items.push(["\uD83D\uDD15", "Replies", `only when ${formatter.formatBold("@mentioned")} (${formatter.formatCode("!mentions off")} to disable)`]);
68670
+ }
71439
68671
  if (session.claudeAccountId) {
71440
68672
  const account = ctx.ops.getClaudeAccount(session.claudeAccountId);
71441
68673
  const label = account?.displayName ?? session.claudeAccountId;
@@ -72090,6 +69322,7 @@ async function startSession(options, username, displayName, replyToPostId, platf
72090
69322
  planApproved: false,
72091
69323
  sessionAllowedUsers: new Set([username]),
72092
69324
  forceInteractivePermissions,
69325
+ respondOnlyWhenMentioned: ctx.config.respondOnlyWhenMentioned ?? false,
72093
69326
  permissionModeOverride: sessionPermissionModeOverride,
72094
69327
  sessionStartPostId: startPost ? startPost.id : null,
72095
69328
  sessionHeaderMode,
@@ -72245,6 +69478,7 @@ Please start a new session.`), { action: "Post resume failure notification" });
72245
69478
  planApproved: state.planApproved ?? false,
72246
69479
  sessionAllowedUsers: new Set(state.sessionAllowedUsers),
72247
69480
  forceInteractivePermissions: state.forceInteractivePermissions ?? false,
69481
+ respondOnlyWhenMentioned: state.respondOnlyWhenMentioned ?? false,
72248
69482
  sessionStartPostId: state.sessionStartPostId ?? null,
72249
69483
  sessionHeaderMode: resumeSessionHeaderMode(state.sessionHeaderMode, ctx.ops.getPlatformOverhead(platformId).sessionHeader),
72250
69484
  timers: createSessionTimers(),
@@ -72982,6 +70216,7 @@ class SessionManager extends EventEmitter4 {
72982
70216
  permissionMode;
72983
70217
  chromeEnabled;
72984
70218
  worktreeMode;
70219
+ respondOnlyWhenMentioned;
72985
70220
  threadLogsEnabled;
72986
70221
  threadLogsRetentionDays;
72987
70222
  limits;
@@ -73000,12 +70235,13 @@ class SessionManager extends EventEmitter4 {
73000
70235
  platformOverhead = new Map;
73001
70236
  autoUpdateManager = null;
73002
70237
  accountPool;
73003
- constructor(workingDir, permissionModeOrSkipFlag = "default", chromeEnabled = false, worktreeMode = "prompt", sessionsPath, threadLogsEnabled = true, threadLogsRetentionDays = 30, limits, claudeAccounts) {
70238
+ constructor(workingDir, permissionModeOrSkipFlag = "default", chromeEnabled = false, worktreeMode = "prompt", sessionsPath, threadLogsEnabled = true, threadLogsRetentionDays = 30, limits, claudeAccounts, respondOnlyWhenMentioned = false) {
73004
70239
  super();
73005
70240
  this.workingDir = workingDir;
73006
70241
  this.permissionMode = typeof permissionModeOrSkipFlag === "boolean" ? permissionModeOrSkipFlag ? "bypass" : "default" : permissionModeOrSkipFlag;
73007
70242
  this.chromeEnabled = chromeEnabled;
73008
70243
  this.worktreeMode = worktreeMode;
70244
+ this.respondOnlyWhenMentioned = respondOnlyWhenMentioned;
73009
70245
  this.threadLogsEnabled = threadLogsEnabled;
73010
70246
  this.threadLogsRetentionDays = threadLogsRetentionDays;
73011
70247
  this.limits = resolveLimits(limits);
@@ -73093,6 +70329,7 @@ class SessionManager extends EventEmitter4 {
73093
70329
  workingDir: this.workingDir,
73094
70330
  permissionMode: this.permissionMode,
73095
70331
  chromeEnabled: this.chromeEnabled,
70332
+ respondOnlyWhenMentioned: this.respondOnlyWhenMentioned,
73096
70333
  debug: this.debug,
73097
70334
  maxSessions: this.limits.maxSessions,
73098
70335
  threadLogsEnabled: this.threadLogsEnabled,
@@ -73286,6 +70523,7 @@ class SessionManager extends EventEmitter4 {
73286
70523
  planApproved: session.planApproved,
73287
70524
  sessionAllowedUsers: [...session.sessionAllowedUsers],
73288
70525
  forceInteractivePermissions: session.forceInteractivePermissions,
70526
+ respondOnlyWhenMentioned: session.respondOnlyWhenMentioned,
73289
70527
  sessionStartPostId: session.sessionStartPostId,
73290
70528
  tasksPostId: taskListSnapshot?.postId ?? null,
73291
70529
  lastTasksContent: taskListSnapshot?.content ?? null,
@@ -73583,6 +70821,12 @@ class SessionManager extends EventEmitter4 {
73583
70821
  return;
73584
70822
  await setGitHubEmail(session, username, arg, this.getContext());
73585
70823
  }
70824
+ async setRespondOnlyWhenMentioned(threadId, username, arg) {
70825
+ const session = this.findSessionByThreadId(threadId);
70826
+ if (!session)
70827
+ return;
70828
+ await setRespondOnlyWhenMentioned(session, username, arg, this.getContext());
70829
+ }
73586
70830
  async setSessionPermissionMode(threadId, username, mode) {
73587
70831
  const session = this.findSessionByThreadId(threadId);
73588
70832
  if (!session)
@@ -83543,6 +80787,9 @@ async function handleMessage(client, session, post2, user, options) {
83543
80787
  return;
83544
80788
  }
83545
80789
  }
80790
+ if (activeSession.respondOnlyWhenMentioned && !client.isBotMentioned(message)) {
80791
+ return;
80792
+ }
83546
80793
  if (!session.isUserAllowedInSession(threadRoot, username)) {
83547
80794
  if (content)
83548
80795
  await session.requestMessageApproval(threadRoot, username, content);
@@ -83582,6 +80829,9 @@ async function handleMessage(client, session, post2, user, options) {
83582
80829
  return;
83583
80830
  }
83584
80831
  }
80832
+ if (persistedSession?.respondOnlyWhenMentioned && !client.isBotMentioned(message)) {
80833
+ return;
80834
+ }
83585
80835
  const files2 = post2.metadata?.files;
83586
80836
  if (content || files2?.length) {
83587
80837
  await session.resumePausedSession(threadRoot, content, files2, username);
@@ -84878,7 +82128,7 @@ async function startWithoutDaemon() {
84878
82128
  keepAlive.setEnabled(keepAliveEnabled);
84879
82129
  const threadLogsEnabled = config.threadLogs?.enabled ?? true;
84880
82130
  const threadLogsRetentionDays = config.threadLogs?.retentionDays ?? 30;
84881
- const session = new SessionManager(workingDir, initialPermissionMode, config.chrome, config.worktreeMode, undefined, threadLogsEnabled, threadLogsRetentionDays, config.limits, config.claudeAccounts);
82131
+ const session = new SessionManager(workingDir, initialPermissionMode, config.chrome, config.worktreeMode, undefined, threadLogsEnabled, threadLogsRetentionDays, config.limits, config.claudeAccounts, config.respondOnlyWhenMentioned);
84882
82132
  if (config.stickyMessage) {
84883
82133
  session.setStickyMessageCustomization(config.stickyMessage.description, config.stickyMessage.footer);
84884
82134
  }