@kenkaiiii/gg-boss 4.3.138 → 4.3.140

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.
@@ -0,0 +1,3738 @@
1
+ import {
2
+ __commonJS,
3
+ __require,
4
+ __toESM,
5
+ init_esm_shims
6
+ } from "./chunk-B2WQ5E5J.js";
7
+
8
+ // ../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/constants.js
9
+ var require_constants = __commonJS({
10
+ "../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/constants.js"(exports, module) {
11
+ "use strict";
12
+ init_esm_shims();
13
+ var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
14
+ var hasBlob = typeof Blob !== "undefined";
15
+ if (hasBlob) BINARY_TYPES.push("blob");
16
+ module.exports = {
17
+ BINARY_TYPES,
18
+ CLOSE_TIMEOUT: 3e4,
19
+ EMPTY_BUFFER: Buffer.alloc(0),
20
+ GUID: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
21
+ hasBlob,
22
+ kForOnEventAttribute: /* @__PURE__ */ Symbol("kIsForOnEventAttribute"),
23
+ kListener: /* @__PURE__ */ Symbol("kListener"),
24
+ kStatusCode: /* @__PURE__ */ Symbol("status-code"),
25
+ kWebSocket: /* @__PURE__ */ Symbol("websocket"),
26
+ NOOP: () => {
27
+ }
28
+ };
29
+ }
30
+ });
31
+
32
+ // ../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/buffer-util.js
33
+ var require_buffer_util = __commonJS({
34
+ "../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/buffer-util.js"(exports, module) {
35
+ "use strict";
36
+ init_esm_shims();
37
+ var { EMPTY_BUFFER } = require_constants();
38
+ var FastBuffer = Buffer[Symbol.species];
39
+ function concat(list, totalLength) {
40
+ if (list.length === 0) return EMPTY_BUFFER;
41
+ if (list.length === 1) return list[0];
42
+ const target = Buffer.allocUnsafe(totalLength);
43
+ let offset = 0;
44
+ for (let i = 0; i < list.length; i++) {
45
+ const buf = list[i];
46
+ target.set(buf, offset);
47
+ offset += buf.length;
48
+ }
49
+ if (offset < totalLength) {
50
+ return new FastBuffer(target.buffer, target.byteOffset, offset);
51
+ }
52
+ return target;
53
+ }
54
+ function _mask(source, mask, output, offset, length) {
55
+ for (let i = 0; i < length; i++) {
56
+ output[offset + i] = source[i] ^ mask[i & 3];
57
+ }
58
+ }
59
+ function _unmask(buffer, mask) {
60
+ for (let i = 0; i < buffer.length; i++) {
61
+ buffer[i] ^= mask[i & 3];
62
+ }
63
+ }
64
+ function toArrayBuffer(buf) {
65
+ if (buf.length === buf.buffer.byteLength) {
66
+ return buf.buffer;
67
+ }
68
+ return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
69
+ }
70
+ function toBuffer(data) {
71
+ toBuffer.readOnly = true;
72
+ if (Buffer.isBuffer(data)) return data;
73
+ let buf;
74
+ if (data instanceof ArrayBuffer) {
75
+ buf = new FastBuffer(data);
76
+ } else if (ArrayBuffer.isView(data)) {
77
+ buf = new FastBuffer(data.buffer, data.byteOffset, data.byteLength);
78
+ } else {
79
+ buf = Buffer.from(data);
80
+ toBuffer.readOnly = false;
81
+ }
82
+ return buf;
83
+ }
84
+ module.exports = {
85
+ concat,
86
+ mask: _mask,
87
+ toArrayBuffer,
88
+ toBuffer,
89
+ unmask: _unmask
90
+ };
91
+ if (!process.env.WS_NO_BUFFER_UTIL) {
92
+ try {
93
+ const bufferUtil = __require("bufferutil");
94
+ module.exports.mask = function(source, mask, output, offset, length) {
95
+ if (length < 48) _mask(source, mask, output, offset, length);
96
+ else bufferUtil.mask(source, mask, output, offset, length);
97
+ };
98
+ module.exports.unmask = function(buffer, mask) {
99
+ if (buffer.length < 32) _unmask(buffer, mask);
100
+ else bufferUtil.unmask(buffer, mask);
101
+ };
102
+ } catch (e) {
103
+ }
104
+ }
105
+ }
106
+ });
107
+
108
+ // ../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/limiter.js
109
+ var require_limiter = __commonJS({
110
+ "../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/limiter.js"(exports, module) {
111
+ "use strict";
112
+ init_esm_shims();
113
+ var kDone = /* @__PURE__ */ Symbol("kDone");
114
+ var kRun = /* @__PURE__ */ Symbol("kRun");
115
+ var Limiter = class {
116
+ /**
117
+ * Creates a new `Limiter`.
118
+ *
119
+ * @param {Number} [concurrency=Infinity] The maximum number of jobs allowed
120
+ * to run concurrently
121
+ */
122
+ constructor(concurrency) {
123
+ this[kDone] = () => {
124
+ this.pending--;
125
+ this[kRun]();
126
+ };
127
+ this.concurrency = concurrency || Infinity;
128
+ this.jobs = [];
129
+ this.pending = 0;
130
+ }
131
+ /**
132
+ * Adds a job to the queue.
133
+ *
134
+ * @param {Function} job The job to run
135
+ * @public
136
+ */
137
+ add(job) {
138
+ this.jobs.push(job);
139
+ this[kRun]();
140
+ }
141
+ /**
142
+ * Removes a job from the queue and runs it if possible.
143
+ *
144
+ * @private
145
+ */
146
+ [kRun]() {
147
+ if (this.pending === this.concurrency) return;
148
+ if (this.jobs.length) {
149
+ const job = this.jobs.shift();
150
+ this.pending++;
151
+ job(this[kDone]);
152
+ }
153
+ }
154
+ };
155
+ module.exports = Limiter;
156
+ }
157
+ });
158
+
159
+ // ../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/permessage-deflate.js
160
+ var require_permessage_deflate = __commonJS({
161
+ "../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/permessage-deflate.js"(exports, module) {
162
+ "use strict";
163
+ init_esm_shims();
164
+ var zlib = __require("zlib");
165
+ var bufferUtil = require_buffer_util();
166
+ var Limiter = require_limiter();
167
+ var { kStatusCode } = require_constants();
168
+ var FastBuffer = Buffer[Symbol.species];
169
+ var TRAILER = Buffer.from([0, 0, 255, 255]);
170
+ var kPerMessageDeflate = /* @__PURE__ */ Symbol("permessage-deflate");
171
+ var kTotalLength = /* @__PURE__ */ Symbol("total-length");
172
+ var kCallback = /* @__PURE__ */ Symbol("callback");
173
+ var kBuffers = /* @__PURE__ */ Symbol("buffers");
174
+ var kError = /* @__PURE__ */ Symbol("error");
175
+ var zlibLimiter;
176
+ var PerMessageDeflate2 = class {
177
+ /**
178
+ * Creates a PerMessageDeflate instance.
179
+ *
180
+ * @param {Object} [options] Configuration options
181
+ * @param {(Boolean|Number)} [options.clientMaxWindowBits] Advertise support
182
+ * for, or request, a custom client window size
183
+ * @param {Boolean} [options.clientNoContextTakeover=false] Advertise/
184
+ * acknowledge disabling of client context takeover
185
+ * @param {Number} [options.concurrencyLimit=10] The number of concurrent
186
+ * calls to zlib
187
+ * @param {Boolean} [options.isServer=false] Create the instance in either
188
+ * server or client mode
189
+ * @param {Number} [options.maxPayload=0] The maximum allowed message length
190
+ * @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
191
+ * use of a custom server window size
192
+ * @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
193
+ * disabling of server context takeover
194
+ * @param {Number} [options.threshold=1024] Size (in bytes) below which
195
+ * messages should not be compressed if context takeover is disabled
196
+ * @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on
197
+ * deflate
198
+ * @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
199
+ * inflate
200
+ */
201
+ constructor(options) {
202
+ this._options = options || {};
203
+ this._threshold = this._options.threshold !== void 0 ? this._options.threshold : 1024;
204
+ this._maxPayload = this._options.maxPayload | 0;
205
+ this._isServer = !!this._options.isServer;
206
+ this._deflate = null;
207
+ this._inflate = null;
208
+ this.params = null;
209
+ if (!zlibLimiter) {
210
+ const concurrency = this._options.concurrencyLimit !== void 0 ? this._options.concurrencyLimit : 10;
211
+ zlibLimiter = new Limiter(concurrency);
212
+ }
213
+ }
214
+ /**
215
+ * @type {String}
216
+ */
217
+ static get extensionName() {
218
+ return "permessage-deflate";
219
+ }
220
+ /**
221
+ * Create an extension negotiation offer.
222
+ *
223
+ * @return {Object} Extension parameters
224
+ * @public
225
+ */
226
+ offer() {
227
+ const params = {};
228
+ if (this._options.serverNoContextTakeover) {
229
+ params.server_no_context_takeover = true;
230
+ }
231
+ if (this._options.clientNoContextTakeover) {
232
+ params.client_no_context_takeover = true;
233
+ }
234
+ if (this._options.serverMaxWindowBits) {
235
+ params.server_max_window_bits = this._options.serverMaxWindowBits;
236
+ }
237
+ if (this._options.clientMaxWindowBits) {
238
+ params.client_max_window_bits = this._options.clientMaxWindowBits;
239
+ } else if (this._options.clientMaxWindowBits == null) {
240
+ params.client_max_window_bits = true;
241
+ }
242
+ return params;
243
+ }
244
+ /**
245
+ * Accept an extension negotiation offer/response.
246
+ *
247
+ * @param {Array} configurations The extension negotiation offers/reponse
248
+ * @return {Object} Accepted configuration
249
+ * @public
250
+ */
251
+ accept(configurations) {
252
+ configurations = this.normalizeParams(configurations);
253
+ this.params = this._isServer ? this.acceptAsServer(configurations) : this.acceptAsClient(configurations);
254
+ return this.params;
255
+ }
256
+ /**
257
+ * Releases all resources used by the extension.
258
+ *
259
+ * @public
260
+ */
261
+ cleanup() {
262
+ if (this._inflate) {
263
+ this._inflate.close();
264
+ this._inflate = null;
265
+ }
266
+ if (this._deflate) {
267
+ const callback = this._deflate[kCallback];
268
+ this._deflate.close();
269
+ this._deflate = null;
270
+ if (callback) {
271
+ callback(
272
+ new Error(
273
+ "The deflate stream was closed while data was being processed"
274
+ )
275
+ );
276
+ }
277
+ }
278
+ }
279
+ /**
280
+ * Accept an extension negotiation offer.
281
+ *
282
+ * @param {Array} offers The extension negotiation offers
283
+ * @return {Object} Accepted configuration
284
+ * @private
285
+ */
286
+ acceptAsServer(offers) {
287
+ const opts = this._options;
288
+ const accepted = offers.find((params) => {
289
+ 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) {
290
+ return false;
291
+ }
292
+ return true;
293
+ });
294
+ if (!accepted) {
295
+ throw new Error("None of the extension offers can be accepted");
296
+ }
297
+ if (opts.serverNoContextTakeover) {
298
+ accepted.server_no_context_takeover = true;
299
+ }
300
+ if (opts.clientNoContextTakeover) {
301
+ accepted.client_no_context_takeover = true;
302
+ }
303
+ if (typeof opts.serverMaxWindowBits === "number") {
304
+ accepted.server_max_window_bits = opts.serverMaxWindowBits;
305
+ }
306
+ if (typeof opts.clientMaxWindowBits === "number") {
307
+ accepted.client_max_window_bits = opts.clientMaxWindowBits;
308
+ } else if (accepted.client_max_window_bits === true || opts.clientMaxWindowBits === false) {
309
+ delete accepted.client_max_window_bits;
310
+ }
311
+ return accepted;
312
+ }
313
+ /**
314
+ * Accept the extension negotiation response.
315
+ *
316
+ * @param {Array} response The extension negotiation response
317
+ * @return {Object} Accepted configuration
318
+ * @private
319
+ */
320
+ acceptAsClient(response) {
321
+ const params = response[0];
322
+ if (this._options.clientNoContextTakeover === false && params.client_no_context_takeover) {
323
+ throw new Error('Unexpected parameter "client_no_context_takeover"');
324
+ }
325
+ if (!params.client_max_window_bits) {
326
+ if (typeof this._options.clientMaxWindowBits === "number") {
327
+ params.client_max_window_bits = this._options.clientMaxWindowBits;
328
+ }
329
+ } else if (this._options.clientMaxWindowBits === false || typeof this._options.clientMaxWindowBits === "number" && params.client_max_window_bits > this._options.clientMaxWindowBits) {
330
+ throw new Error(
331
+ 'Unexpected or invalid parameter "client_max_window_bits"'
332
+ );
333
+ }
334
+ return params;
335
+ }
336
+ /**
337
+ * Normalize parameters.
338
+ *
339
+ * @param {Array} configurations The extension negotiation offers/reponse
340
+ * @return {Array} The offers/response with normalized parameters
341
+ * @private
342
+ */
343
+ normalizeParams(configurations) {
344
+ configurations.forEach((params) => {
345
+ Object.keys(params).forEach((key) => {
346
+ let value = params[key];
347
+ if (value.length > 1) {
348
+ throw new Error(`Parameter "${key}" must have only a single value`);
349
+ }
350
+ value = value[0];
351
+ if (key === "client_max_window_bits") {
352
+ if (value !== true) {
353
+ const num = +value;
354
+ if (!Number.isInteger(num) || num < 8 || num > 15) {
355
+ throw new TypeError(
356
+ `Invalid value for parameter "${key}": ${value}`
357
+ );
358
+ }
359
+ value = num;
360
+ } else if (!this._isServer) {
361
+ throw new TypeError(
362
+ `Invalid value for parameter "${key}": ${value}`
363
+ );
364
+ }
365
+ } else if (key === "server_max_window_bits") {
366
+ const num = +value;
367
+ if (!Number.isInteger(num) || num < 8 || num > 15) {
368
+ throw new TypeError(
369
+ `Invalid value for parameter "${key}": ${value}`
370
+ );
371
+ }
372
+ value = num;
373
+ } else if (key === "client_no_context_takeover" || key === "server_no_context_takeover") {
374
+ if (value !== true) {
375
+ throw new TypeError(
376
+ `Invalid value for parameter "${key}": ${value}`
377
+ );
378
+ }
379
+ } else {
380
+ throw new Error(`Unknown parameter "${key}"`);
381
+ }
382
+ params[key] = value;
383
+ });
384
+ });
385
+ return configurations;
386
+ }
387
+ /**
388
+ * Decompress data. Concurrency limited.
389
+ *
390
+ * @param {Buffer} data Compressed data
391
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
392
+ * @param {Function} callback Callback
393
+ * @public
394
+ */
395
+ decompress(data, fin, callback) {
396
+ zlibLimiter.add((done) => {
397
+ this._decompress(data, fin, (err, result) => {
398
+ done();
399
+ callback(err, result);
400
+ });
401
+ });
402
+ }
403
+ /**
404
+ * Compress data. Concurrency limited.
405
+ *
406
+ * @param {(Buffer|String)} data Data to compress
407
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
408
+ * @param {Function} callback Callback
409
+ * @public
410
+ */
411
+ compress(data, fin, callback) {
412
+ zlibLimiter.add((done) => {
413
+ this._compress(data, fin, (err, result) => {
414
+ done();
415
+ callback(err, result);
416
+ });
417
+ });
418
+ }
419
+ /**
420
+ * Decompress data.
421
+ *
422
+ * @param {Buffer} data Compressed data
423
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
424
+ * @param {Function} callback Callback
425
+ * @private
426
+ */
427
+ _decompress(data, fin, callback) {
428
+ const endpoint = this._isServer ? "client" : "server";
429
+ if (!this._inflate) {
430
+ const key = `${endpoint}_max_window_bits`;
431
+ const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
432
+ this._inflate = zlib.createInflateRaw({
433
+ ...this._options.zlibInflateOptions,
434
+ windowBits
435
+ });
436
+ this._inflate[kPerMessageDeflate] = this;
437
+ this._inflate[kTotalLength] = 0;
438
+ this._inflate[kBuffers] = [];
439
+ this._inflate.on("error", inflateOnError);
440
+ this._inflate.on("data", inflateOnData);
441
+ }
442
+ this._inflate[kCallback] = callback;
443
+ this._inflate.write(data);
444
+ if (fin) this._inflate.write(TRAILER);
445
+ this._inflate.flush(() => {
446
+ const err = this._inflate[kError];
447
+ if (err) {
448
+ this._inflate.close();
449
+ this._inflate = null;
450
+ callback(err);
451
+ return;
452
+ }
453
+ const data2 = bufferUtil.concat(
454
+ this._inflate[kBuffers],
455
+ this._inflate[kTotalLength]
456
+ );
457
+ if (this._inflate._readableState.endEmitted) {
458
+ this._inflate.close();
459
+ this._inflate = null;
460
+ } else {
461
+ this._inflate[kTotalLength] = 0;
462
+ this._inflate[kBuffers] = [];
463
+ if (fin && this.params[`${endpoint}_no_context_takeover`]) {
464
+ this._inflate.reset();
465
+ }
466
+ }
467
+ callback(null, data2);
468
+ });
469
+ }
470
+ /**
471
+ * Compress data.
472
+ *
473
+ * @param {(Buffer|String)} data Data to compress
474
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
475
+ * @param {Function} callback Callback
476
+ * @private
477
+ */
478
+ _compress(data, fin, callback) {
479
+ const endpoint = this._isServer ? "server" : "client";
480
+ if (!this._deflate) {
481
+ const key = `${endpoint}_max_window_bits`;
482
+ const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
483
+ this._deflate = zlib.createDeflateRaw({
484
+ ...this._options.zlibDeflateOptions,
485
+ windowBits
486
+ });
487
+ this._deflate[kTotalLength] = 0;
488
+ this._deflate[kBuffers] = [];
489
+ this._deflate.on("data", deflateOnData);
490
+ }
491
+ this._deflate[kCallback] = callback;
492
+ this._deflate.write(data);
493
+ this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
494
+ if (!this._deflate) {
495
+ return;
496
+ }
497
+ let data2 = bufferUtil.concat(
498
+ this._deflate[kBuffers],
499
+ this._deflate[kTotalLength]
500
+ );
501
+ if (fin) {
502
+ data2 = new FastBuffer(data2.buffer, data2.byteOffset, data2.length - 4);
503
+ }
504
+ this._deflate[kCallback] = null;
505
+ this._deflate[kTotalLength] = 0;
506
+ this._deflate[kBuffers] = [];
507
+ if (fin && this.params[`${endpoint}_no_context_takeover`]) {
508
+ this._deflate.reset();
509
+ }
510
+ callback(null, data2);
511
+ });
512
+ }
513
+ };
514
+ module.exports = PerMessageDeflate2;
515
+ function deflateOnData(chunk) {
516
+ this[kBuffers].push(chunk);
517
+ this[kTotalLength] += chunk.length;
518
+ }
519
+ function inflateOnData(chunk) {
520
+ this[kTotalLength] += chunk.length;
521
+ if (this[kPerMessageDeflate]._maxPayload < 1 || this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload) {
522
+ this[kBuffers].push(chunk);
523
+ return;
524
+ }
525
+ this[kError] = new RangeError("Max payload size exceeded");
526
+ this[kError].code = "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH";
527
+ this[kError][kStatusCode] = 1009;
528
+ this.removeListener("data", inflateOnData);
529
+ this.reset();
530
+ }
531
+ function inflateOnError(err) {
532
+ this[kPerMessageDeflate]._inflate = null;
533
+ if (this[kError]) {
534
+ this[kCallback](this[kError]);
535
+ return;
536
+ }
537
+ err[kStatusCode] = 1007;
538
+ this[kCallback](err);
539
+ }
540
+ }
541
+ });
542
+
543
+ // ../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/validation.js
544
+ var require_validation = __commonJS({
545
+ "../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/validation.js"(exports, module) {
546
+ "use strict";
547
+ init_esm_shims();
548
+ var { isUtf8 } = __require("buffer");
549
+ var { hasBlob } = require_constants();
550
+ var tokenChars = [
551
+ 0,
552
+ 0,
553
+ 0,
554
+ 0,
555
+ 0,
556
+ 0,
557
+ 0,
558
+ 0,
559
+ 0,
560
+ 0,
561
+ 0,
562
+ 0,
563
+ 0,
564
+ 0,
565
+ 0,
566
+ 0,
567
+ // 0 - 15
568
+ 0,
569
+ 0,
570
+ 0,
571
+ 0,
572
+ 0,
573
+ 0,
574
+ 0,
575
+ 0,
576
+ 0,
577
+ 0,
578
+ 0,
579
+ 0,
580
+ 0,
581
+ 0,
582
+ 0,
583
+ 0,
584
+ // 16 - 31
585
+ 0,
586
+ 1,
587
+ 0,
588
+ 1,
589
+ 1,
590
+ 1,
591
+ 1,
592
+ 1,
593
+ 0,
594
+ 0,
595
+ 1,
596
+ 1,
597
+ 0,
598
+ 1,
599
+ 1,
600
+ 0,
601
+ // 32 - 47
602
+ 1,
603
+ 1,
604
+ 1,
605
+ 1,
606
+ 1,
607
+ 1,
608
+ 1,
609
+ 1,
610
+ 1,
611
+ 1,
612
+ 0,
613
+ 0,
614
+ 0,
615
+ 0,
616
+ 0,
617
+ 0,
618
+ // 48 - 63
619
+ 0,
620
+ 1,
621
+ 1,
622
+ 1,
623
+ 1,
624
+ 1,
625
+ 1,
626
+ 1,
627
+ 1,
628
+ 1,
629
+ 1,
630
+ 1,
631
+ 1,
632
+ 1,
633
+ 1,
634
+ 1,
635
+ // 64 - 79
636
+ 1,
637
+ 1,
638
+ 1,
639
+ 1,
640
+ 1,
641
+ 1,
642
+ 1,
643
+ 1,
644
+ 1,
645
+ 1,
646
+ 1,
647
+ 0,
648
+ 0,
649
+ 0,
650
+ 1,
651
+ 1,
652
+ // 80 - 95
653
+ 1,
654
+ 1,
655
+ 1,
656
+ 1,
657
+ 1,
658
+ 1,
659
+ 1,
660
+ 1,
661
+ 1,
662
+ 1,
663
+ 1,
664
+ 1,
665
+ 1,
666
+ 1,
667
+ 1,
668
+ 1,
669
+ // 96 - 111
670
+ 1,
671
+ 1,
672
+ 1,
673
+ 1,
674
+ 1,
675
+ 1,
676
+ 1,
677
+ 1,
678
+ 1,
679
+ 1,
680
+ 1,
681
+ 0,
682
+ 1,
683
+ 0,
684
+ 1,
685
+ 0
686
+ // 112 - 127
687
+ ];
688
+ function isValidStatusCode(code) {
689
+ return code >= 1e3 && code <= 1014 && code !== 1004 && code !== 1005 && code !== 1006 || code >= 3e3 && code <= 4999;
690
+ }
691
+ function _isValidUTF8(buf) {
692
+ const len = buf.length;
693
+ let i = 0;
694
+ while (i < len) {
695
+ if ((buf[i] & 128) === 0) {
696
+ i++;
697
+ } else if ((buf[i] & 224) === 192) {
698
+ if (i + 1 === len || (buf[i + 1] & 192) !== 128 || (buf[i] & 254) === 192) {
699
+ return false;
700
+ }
701
+ i += 2;
702
+ } else if ((buf[i] & 240) === 224) {
703
+ if (i + 2 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || buf[i] === 224 && (buf[i + 1] & 224) === 128 || // Overlong
704
+ buf[i] === 237 && (buf[i + 1] & 224) === 160) {
705
+ return false;
706
+ }
707
+ i += 3;
708
+ } else if ((buf[i] & 248) === 240) {
709
+ if (i + 3 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || (buf[i + 3] & 192) !== 128 || buf[i] === 240 && (buf[i + 1] & 240) === 128 || // Overlong
710
+ buf[i] === 244 && buf[i + 1] > 143 || buf[i] > 244) {
711
+ return false;
712
+ }
713
+ i += 4;
714
+ } else {
715
+ return false;
716
+ }
717
+ }
718
+ return true;
719
+ }
720
+ function isBlob(value) {
721
+ 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");
722
+ }
723
+ module.exports = {
724
+ isBlob,
725
+ isValidStatusCode,
726
+ isValidUTF8: _isValidUTF8,
727
+ tokenChars
728
+ };
729
+ if (isUtf8) {
730
+ module.exports.isValidUTF8 = function(buf) {
731
+ return buf.length < 24 ? _isValidUTF8(buf) : isUtf8(buf);
732
+ };
733
+ } else if (!process.env.WS_NO_UTF_8_VALIDATE) {
734
+ try {
735
+ const isValidUTF8 = __require("utf-8-validate");
736
+ module.exports.isValidUTF8 = function(buf) {
737
+ return buf.length < 32 ? _isValidUTF8(buf) : isValidUTF8(buf);
738
+ };
739
+ } catch (e) {
740
+ }
741
+ }
742
+ }
743
+ });
744
+
745
+ // ../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/receiver.js
746
+ var require_receiver = __commonJS({
747
+ "../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/receiver.js"(exports, module) {
748
+ "use strict";
749
+ init_esm_shims();
750
+ var { Writable } = __require("stream");
751
+ var PerMessageDeflate2 = require_permessage_deflate();
752
+ var {
753
+ BINARY_TYPES,
754
+ EMPTY_BUFFER,
755
+ kStatusCode,
756
+ kWebSocket
757
+ } = require_constants();
758
+ var { concat, toArrayBuffer, unmask } = require_buffer_util();
759
+ var { isValidStatusCode, isValidUTF8 } = require_validation();
760
+ var FastBuffer = Buffer[Symbol.species];
761
+ var GET_INFO = 0;
762
+ var GET_PAYLOAD_LENGTH_16 = 1;
763
+ var GET_PAYLOAD_LENGTH_64 = 2;
764
+ var GET_MASK = 3;
765
+ var GET_DATA = 4;
766
+ var INFLATING = 5;
767
+ var DEFER_EVENT = 6;
768
+ var Receiver2 = class extends Writable {
769
+ /**
770
+ * Creates a Receiver instance.
771
+ *
772
+ * @param {Object} [options] Options object
773
+ * @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether
774
+ * any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
775
+ * multiple times in the same tick
776
+ * @param {String} [options.binaryType=nodebuffer] The type for binary data
777
+ * @param {Object} [options.extensions] An object containing the negotiated
778
+ * extensions
779
+ * @param {Boolean} [options.isServer=false] Specifies whether to operate in
780
+ * client or server mode
781
+ * @param {Number} [options.maxPayload=0] The maximum allowed message length
782
+ * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
783
+ * not to skip UTF-8 validation for text and close messages
784
+ */
785
+ constructor(options = {}) {
786
+ super();
787
+ this._allowSynchronousEvents = options.allowSynchronousEvents !== void 0 ? options.allowSynchronousEvents : true;
788
+ this._binaryType = options.binaryType || BINARY_TYPES[0];
789
+ this._extensions = options.extensions || {};
790
+ this._isServer = !!options.isServer;
791
+ this._maxPayload = options.maxPayload | 0;
792
+ this._skipUTF8Validation = !!options.skipUTF8Validation;
793
+ this[kWebSocket] = void 0;
794
+ this._bufferedBytes = 0;
795
+ this._buffers = [];
796
+ this._compressed = false;
797
+ this._payloadLength = 0;
798
+ this._mask = void 0;
799
+ this._fragmented = 0;
800
+ this._masked = false;
801
+ this._fin = false;
802
+ this._opcode = 0;
803
+ this._totalPayloadLength = 0;
804
+ this._messageLength = 0;
805
+ this._fragments = [];
806
+ this._errored = false;
807
+ this._loop = false;
808
+ this._state = GET_INFO;
809
+ }
810
+ /**
811
+ * Implements `Writable.prototype._write()`.
812
+ *
813
+ * @param {Buffer} chunk The chunk of data to write
814
+ * @param {String} encoding The character encoding of `chunk`
815
+ * @param {Function} cb Callback
816
+ * @private
817
+ */
818
+ _write(chunk, encoding, cb) {
819
+ if (this._opcode === 8 && this._state == GET_INFO) return cb();
820
+ this._bufferedBytes += chunk.length;
821
+ this._buffers.push(chunk);
822
+ this.startLoop(cb);
823
+ }
824
+ /**
825
+ * Consumes `n` bytes from the buffered data.
826
+ *
827
+ * @param {Number} n The number of bytes to consume
828
+ * @return {Buffer} The consumed bytes
829
+ * @private
830
+ */
831
+ consume(n) {
832
+ this._bufferedBytes -= n;
833
+ if (n === this._buffers[0].length) return this._buffers.shift();
834
+ if (n < this._buffers[0].length) {
835
+ const buf = this._buffers[0];
836
+ this._buffers[0] = new FastBuffer(
837
+ buf.buffer,
838
+ buf.byteOffset + n,
839
+ buf.length - n
840
+ );
841
+ return new FastBuffer(buf.buffer, buf.byteOffset, n);
842
+ }
843
+ const dst = Buffer.allocUnsafe(n);
844
+ do {
845
+ const buf = this._buffers[0];
846
+ const offset = dst.length - n;
847
+ if (n >= buf.length) {
848
+ dst.set(this._buffers.shift(), offset);
849
+ } else {
850
+ dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
851
+ this._buffers[0] = new FastBuffer(
852
+ buf.buffer,
853
+ buf.byteOffset + n,
854
+ buf.length - n
855
+ );
856
+ }
857
+ n -= buf.length;
858
+ } while (n > 0);
859
+ return dst;
860
+ }
861
+ /**
862
+ * Starts the parsing loop.
863
+ *
864
+ * @param {Function} cb Callback
865
+ * @private
866
+ */
867
+ startLoop(cb) {
868
+ this._loop = true;
869
+ do {
870
+ switch (this._state) {
871
+ case GET_INFO:
872
+ this.getInfo(cb);
873
+ break;
874
+ case GET_PAYLOAD_LENGTH_16:
875
+ this.getPayloadLength16(cb);
876
+ break;
877
+ case GET_PAYLOAD_LENGTH_64:
878
+ this.getPayloadLength64(cb);
879
+ break;
880
+ case GET_MASK:
881
+ this.getMask();
882
+ break;
883
+ case GET_DATA:
884
+ this.getData(cb);
885
+ break;
886
+ case INFLATING:
887
+ case DEFER_EVENT:
888
+ this._loop = false;
889
+ return;
890
+ }
891
+ } while (this._loop);
892
+ if (!this._errored) cb();
893
+ }
894
+ /**
895
+ * Reads the first two bytes of a frame.
896
+ *
897
+ * @param {Function} cb Callback
898
+ * @private
899
+ */
900
+ getInfo(cb) {
901
+ if (this._bufferedBytes < 2) {
902
+ this._loop = false;
903
+ return;
904
+ }
905
+ const buf = this.consume(2);
906
+ if ((buf[0] & 48) !== 0) {
907
+ const error = this.createError(
908
+ RangeError,
909
+ "RSV2 and RSV3 must be clear",
910
+ true,
911
+ 1002,
912
+ "WS_ERR_UNEXPECTED_RSV_2_3"
913
+ );
914
+ cb(error);
915
+ return;
916
+ }
917
+ const compressed = (buf[0] & 64) === 64;
918
+ if (compressed && !this._extensions[PerMessageDeflate2.extensionName]) {
919
+ const error = this.createError(
920
+ RangeError,
921
+ "RSV1 must be clear",
922
+ true,
923
+ 1002,
924
+ "WS_ERR_UNEXPECTED_RSV_1"
925
+ );
926
+ cb(error);
927
+ return;
928
+ }
929
+ this._fin = (buf[0] & 128) === 128;
930
+ this._opcode = buf[0] & 15;
931
+ this._payloadLength = buf[1] & 127;
932
+ if (this._opcode === 0) {
933
+ if (compressed) {
934
+ const error = this.createError(
935
+ RangeError,
936
+ "RSV1 must be clear",
937
+ true,
938
+ 1002,
939
+ "WS_ERR_UNEXPECTED_RSV_1"
940
+ );
941
+ cb(error);
942
+ return;
943
+ }
944
+ if (!this._fragmented) {
945
+ const error = this.createError(
946
+ RangeError,
947
+ "invalid opcode 0",
948
+ true,
949
+ 1002,
950
+ "WS_ERR_INVALID_OPCODE"
951
+ );
952
+ cb(error);
953
+ return;
954
+ }
955
+ this._opcode = this._fragmented;
956
+ } else if (this._opcode === 1 || this._opcode === 2) {
957
+ if (this._fragmented) {
958
+ const error = this.createError(
959
+ RangeError,
960
+ `invalid opcode ${this._opcode}`,
961
+ true,
962
+ 1002,
963
+ "WS_ERR_INVALID_OPCODE"
964
+ );
965
+ cb(error);
966
+ return;
967
+ }
968
+ this._compressed = compressed;
969
+ } else if (this._opcode > 7 && this._opcode < 11) {
970
+ if (!this._fin) {
971
+ const error = this.createError(
972
+ RangeError,
973
+ "FIN must be set",
974
+ true,
975
+ 1002,
976
+ "WS_ERR_EXPECTED_FIN"
977
+ );
978
+ cb(error);
979
+ return;
980
+ }
981
+ if (compressed) {
982
+ const error = this.createError(
983
+ RangeError,
984
+ "RSV1 must be clear",
985
+ true,
986
+ 1002,
987
+ "WS_ERR_UNEXPECTED_RSV_1"
988
+ );
989
+ cb(error);
990
+ return;
991
+ }
992
+ if (this._payloadLength > 125 || this._opcode === 8 && this._payloadLength === 1) {
993
+ const error = this.createError(
994
+ RangeError,
995
+ `invalid payload length ${this._payloadLength}`,
996
+ true,
997
+ 1002,
998
+ "WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH"
999
+ );
1000
+ cb(error);
1001
+ return;
1002
+ }
1003
+ } else {
1004
+ const error = this.createError(
1005
+ RangeError,
1006
+ `invalid opcode ${this._opcode}`,
1007
+ true,
1008
+ 1002,
1009
+ "WS_ERR_INVALID_OPCODE"
1010
+ );
1011
+ cb(error);
1012
+ return;
1013
+ }
1014
+ if (!this._fin && !this._fragmented) this._fragmented = this._opcode;
1015
+ this._masked = (buf[1] & 128) === 128;
1016
+ if (this._isServer) {
1017
+ if (!this._masked) {
1018
+ const error = this.createError(
1019
+ RangeError,
1020
+ "MASK must be set",
1021
+ true,
1022
+ 1002,
1023
+ "WS_ERR_EXPECTED_MASK"
1024
+ );
1025
+ cb(error);
1026
+ return;
1027
+ }
1028
+ } else if (this._masked) {
1029
+ const error = this.createError(
1030
+ RangeError,
1031
+ "MASK must be clear",
1032
+ true,
1033
+ 1002,
1034
+ "WS_ERR_UNEXPECTED_MASK"
1035
+ );
1036
+ cb(error);
1037
+ return;
1038
+ }
1039
+ if (this._payloadLength === 126) this._state = GET_PAYLOAD_LENGTH_16;
1040
+ else if (this._payloadLength === 127) this._state = GET_PAYLOAD_LENGTH_64;
1041
+ else this.haveLength(cb);
1042
+ }
1043
+ /**
1044
+ * Gets extended payload length (7+16).
1045
+ *
1046
+ * @param {Function} cb Callback
1047
+ * @private
1048
+ */
1049
+ getPayloadLength16(cb) {
1050
+ if (this._bufferedBytes < 2) {
1051
+ this._loop = false;
1052
+ return;
1053
+ }
1054
+ this._payloadLength = this.consume(2).readUInt16BE(0);
1055
+ this.haveLength(cb);
1056
+ }
1057
+ /**
1058
+ * Gets extended payload length (7+64).
1059
+ *
1060
+ * @param {Function} cb Callback
1061
+ * @private
1062
+ */
1063
+ getPayloadLength64(cb) {
1064
+ if (this._bufferedBytes < 8) {
1065
+ this._loop = false;
1066
+ return;
1067
+ }
1068
+ const buf = this.consume(8);
1069
+ const num = buf.readUInt32BE(0);
1070
+ if (num > Math.pow(2, 53 - 32) - 1) {
1071
+ const error = this.createError(
1072
+ RangeError,
1073
+ "Unsupported WebSocket frame: payload length > 2^53 - 1",
1074
+ false,
1075
+ 1009,
1076
+ "WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH"
1077
+ );
1078
+ cb(error);
1079
+ return;
1080
+ }
1081
+ this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
1082
+ this.haveLength(cb);
1083
+ }
1084
+ /**
1085
+ * Payload length has been read.
1086
+ *
1087
+ * @param {Function} cb Callback
1088
+ * @private
1089
+ */
1090
+ haveLength(cb) {
1091
+ if (this._payloadLength && this._opcode < 8) {
1092
+ this._totalPayloadLength += this._payloadLength;
1093
+ if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
1094
+ const error = this.createError(
1095
+ RangeError,
1096
+ "Max payload size exceeded",
1097
+ false,
1098
+ 1009,
1099
+ "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"
1100
+ );
1101
+ cb(error);
1102
+ return;
1103
+ }
1104
+ }
1105
+ if (this._masked) this._state = GET_MASK;
1106
+ else this._state = GET_DATA;
1107
+ }
1108
+ /**
1109
+ * Reads mask bytes.
1110
+ *
1111
+ * @private
1112
+ */
1113
+ getMask() {
1114
+ if (this._bufferedBytes < 4) {
1115
+ this._loop = false;
1116
+ return;
1117
+ }
1118
+ this._mask = this.consume(4);
1119
+ this._state = GET_DATA;
1120
+ }
1121
+ /**
1122
+ * Reads data bytes.
1123
+ *
1124
+ * @param {Function} cb Callback
1125
+ * @private
1126
+ */
1127
+ getData(cb) {
1128
+ let data = EMPTY_BUFFER;
1129
+ if (this._payloadLength) {
1130
+ if (this._bufferedBytes < this._payloadLength) {
1131
+ this._loop = false;
1132
+ return;
1133
+ }
1134
+ data = this.consume(this._payloadLength);
1135
+ if (this._masked && (this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0) {
1136
+ unmask(data, this._mask);
1137
+ }
1138
+ }
1139
+ if (this._opcode > 7) {
1140
+ this.controlMessage(data, cb);
1141
+ return;
1142
+ }
1143
+ if (this._compressed) {
1144
+ this._state = INFLATING;
1145
+ this.decompress(data, cb);
1146
+ return;
1147
+ }
1148
+ if (data.length) {
1149
+ this._messageLength = this._totalPayloadLength;
1150
+ this._fragments.push(data);
1151
+ }
1152
+ this.dataMessage(cb);
1153
+ }
1154
+ /**
1155
+ * Decompresses data.
1156
+ *
1157
+ * @param {Buffer} data Compressed data
1158
+ * @param {Function} cb Callback
1159
+ * @private
1160
+ */
1161
+ decompress(data, cb) {
1162
+ const perMessageDeflate = this._extensions[PerMessageDeflate2.extensionName];
1163
+ perMessageDeflate.decompress(data, this._fin, (err, buf) => {
1164
+ if (err) return cb(err);
1165
+ if (buf.length) {
1166
+ this._messageLength += buf.length;
1167
+ if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
1168
+ const error = this.createError(
1169
+ RangeError,
1170
+ "Max payload size exceeded",
1171
+ false,
1172
+ 1009,
1173
+ "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"
1174
+ );
1175
+ cb(error);
1176
+ return;
1177
+ }
1178
+ this._fragments.push(buf);
1179
+ }
1180
+ this.dataMessage(cb);
1181
+ if (this._state === GET_INFO) this.startLoop(cb);
1182
+ });
1183
+ }
1184
+ /**
1185
+ * Handles a data message.
1186
+ *
1187
+ * @param {Function} cb Callback
1188
+ * @private
1189
+ */
1190
+ dataMessage(cb) {
1191
+ if (!this._fin) {
1192
+ this._state = GET_INFO;
1193
+ return;
1194
+ }
1195
+ const messageLength = this._messageLength;
1196
+ const fragments = this._fragments;
1197
+ this._totalPayloadLength = 0;
1198
+ this._messageLength = 0;
1199
+ this._fragmented = 0;
1200
+ this._fragments = [];
1201
+ if (this._opcode === 2) {
1202
+ let data;
1203
+ if (this._binaryType === "nodebuffer") {
1204
+ data = concat(fragments, messageLength);
1205
+ } else if (this._binaryType === "arraybuffer") {
1206
+ data = toArrayBuffer(concat(fragments, messageLength));
1207
+ } else if (this._binaryType === "blob") {
1208
+ data = new Blob(fragments);
1209
+ } else {
1210
+ data = fragments;
1211
+ }
1212
+ if (this._allowSynchronousEvents) {
1213
+ this.emit("message", data, true);
1214
+ this._state = GET_INFO;
1215
+ } else {
1216
+ this._state = DEFER_EVENT;
1217
+ setImmediate(() => {
1218
+ this.emit("message", data, true);
1219
+ this._state = GET_INFO;
1220
+ this.startLoop(cb);
1221
+ });
1222
+ }
1223
+ } else {
1224
+ const buf = concat(fragments, messageLength);
1225
+ if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
1226
+ const error = this.createError(
1227
+ Error,
1228
+ "invalid UTF-8 sequence",
1229
+ true,
1230
+ 1007,
1231
+ "WS_ERR_INVALID_UTF8"
1232
+ );
1233
+ cb(error);
1234
+ return;
1235
+ }
1236
+ if (this._state === INFLATING || this._allowSynchronousEvents) {
1237
+ this.emit("message", buf, false);
1238
+ this._state = GET_INFO;
1239
+ } else {
1240
+ this._state = DEFER_EVENT;
1241
+ setImmediate(() => {
1242
+ this.emit("message", buf, false);
1243
+ this._state = GET_INFO;
1244
+ this.startLoop(cb);
1245
+ });
1246
+ }
1247
+ }
1248
+ }
1249
+ /**
1250
+ * Handles a control message.
1251
+ *
1252
+ * @param {Buffer} data Data to handle
1253
+ * @return {(Error|RangeError|undefined)} A possible error
1254
+ * @private
1255
+ */
1256
+ controlMessage(data, cb) {
1257
+ if (this._opcode === 8) {
1258
+ if (data.length === 0) {
1259
+ this._loop = false;
1260
+ this.emit("conclude", 1005, EMPTY_BUFFER);
1261
+ this.end();
1262
+ } else {
1263
+ const code = data.readUInt16BE(0);
1264
+ if (!isValidStatusCode(code)) {
1265
+ const error = this.createError(
1266
+ RangeError,
1267
+ `invalid status code ${code}`,
1268
+ true,
1269
+ 1002,
1270
+ "WS_ERR_INVALID_CLOSE_CODE"
1271
+ );
1272
+ cb(error);
1273
+ return;
1274
+ }
1275
+ const buf = new FastBuffer(
1276
+ data.buffer,
1277
+ data.byteOffset + 2,
1278
+ data.length - 2
1279
+ );
1280
+ if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
1281
+ const error = this.createError(
1282
+ Error,
1283
+ "invalid UTF-8 sequence",
1284
+ true,
1285
+ 1007,
1286
+ "WS_ERR_INVALID_UTF8"
1287
+ );
1288
+ cb(error);
1289
+ return;
1290
+ }
1291
+ this._loop = false;
1292
+ this.emit("conclude", code, buf);
1293
+ this.end();
1294
+ }
1295
+ this._state = GET_INFO;
1296
+ return;
1297
+ }
1298
+ if (this._allowSynchronousEvents) {
1299
+ this.emit(this._opcode === 9 ? "ping" : "pong", data);
1300
+ this._state = GET_INFO;
1301
+ } else {
1302
+ this._state = DEFER_EVENT;
1303
+ setImmediate(() => {
1304
+ this.emit(this._opcode === 9 ? "ping" : "pong", data);
1305
+ this._state = GET_INFO;
1306
+ this.startLoop(cb);
1307
+ });
1308
+ }
1309
+ }
1310
+ /**
1311
+ * Builds an error object.
1312
+ *
1313
+ * @param {function(new:Error|RangeError)} ErrorCtor The error constructor
1314
+ * @param {String} message The error message
1315
+ * @param {Boolean} prefix Specifies whether or not to add a default prefix to
1316
+ * `message`
1317
+ * @param {Number} statusCode The status code
1318
+ * @param {String} errorCode The exposed error code
1319
+ * @return {(Error|RangeError)} The error
1320
+ * @private
1321
+ */
1322
+ createError(ErrorCtor, message, prefix, statusCode, errorCode) {
1323
+ this._loop = false;
1324
+ this._errored = true;
1325
+ const err = new ErrorCtor(
1326
+ prefix ? `Invalid WebSocket frame: ${message}` : message
1327
+ );
1328
+ Error.captureStackTrace(err, this.createError);
1329
+ err.code = errorCode;
1330
+ err[kStatusCode] = statusCode;
1331
+ return err;
1332
+ }
1333
+ };
1334
+ module.exports = Receiver2;
1335
+ }
1336
+ });
1337
+
1338
+ // ../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/sender.js
1339
+ var require_sender = __commonJS({
1340
+ "../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/sender.js"(exports, module) {
1341
+ "use strict";
1342
+ init_esm_shims();
1343
+ var { Duplex } = __require("stream");
1344
+ var { randomFillSync } = __require("crypto");
1345
+ var PerMessageDeflate2 = require_permessage_deflate();
1346
+ var { EMPTY_BUFFER, kWebSocket, NOOP } = require_constants();
1347
+ var { isBlob, isValidStatusCode } = require_validation();
1348
+ var { mask: applyMask, toBuffer } = require_buffer_util();
1349
+ var kByteLength = /* @__PURE__ */ Symbol("kByteLength");
1350
+ var maskBuffer = Buffer.alloc(4);
1351
+ var RANDOM_POOL_SIZE = 8 * 1024;
1352
+ var randomPool;
1353
+ var randomPoolPointer = RANDOM_POOL_SIZE;
1354
+ var DEFAULT = 0;
1355
+ var DEFLATING = 1;
1356
+ var GET_BLOB_DATA = 2;
1357
+ var Sender2 = class _Sender {
1358
+ /**
1359
+ * Creates a Sender instance.
1360
+ *
1361
+ * @param {Duplex} socket The connection socket
1362
+ * @param {Object} [extensions] An object containing the negotiated extensions
1363
+ * @param {Function} [generateMask] The function used to generate the masking
1364
+ * key
1365
+ */
1366
+ constructor(socket, extensions, generateMask) {
1367
+ this._extensions = extensions || {};
1368
+ if (generateMask) {
1369
+ this._generateMask = generateMask;
1370
+ this._maskBuffer = Buffer.alloc(4);
1371
+ }
1372
+ this._socket = socket;
1373
+ this._firstFragment = true;
1374
+ this._compress = false;
1375
+ this._bufferedBytes = 0;
1376
+ this._queue = [];
1377
+ this._state = DEFAULT;
1378
+ this.onerror = NOOP;
1379
+ this[kWebSocket] = void 0;
1380
+ }
1381
+ /**
1382
+ * Frames a piece of data according to the HyBi WebSocket protocol.
1383
+ *
1384
+ * @param {(Buffer|String)} data The data to frame
1385
+ * @param {Object} options Options object
1386
+ * @param {Boolean} [options.fin=false] Specifies whether or not to set the
1387
+ * FIN bit
1388
+ * @param {Function} [options.generateMask] The function used to generate the
1389
+ * masking key
1390
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1391
+ * `data`
1392
+ * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
1393
+ * key
1394
+ * @param {Number} options.opcode The opcode
1395
+ * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
1396
+ * modified
1397
+ * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
1398
+ * RSV1 bit
1399
+ * @return {(Buffer|String)[]} The framed data
1400
+ * @public
1401
+ */
1402
+ static frame(data, options) {
1403
+ let mask;
1404
+ let merge = false;
1405
+ let offset = 2;
1406
+ let skipMasking = false;
1407
+ if (options.mask) {
1408
+ mask = options.maskBuffer || maskBuffer;
1409
+ if (options.generateMask) {
1410
+ options.generateMask(mask);
1411
+ } else {
1412
+ if (randomPoolPointer === RANDOM_POOL_SIZE) {
1413
+ if (randomPool === void 0) {
1414
+ randomPool = Buffer.alloc(RANDOM_POOL_SIZE);
1415
+ }
1416
+ randomFillSync(randomPool, 0, RANDOM_POOL_SIZE);
1417
+ randomPoolPointer = 0;
1418
+ }
1419
+ mask[0] = randomPool[randomPoolPointer++];
1420
+ mask[1] = randomPool[randomPoolPointer++];
1421
+ mask[2] = randomPool[randomPoolPointer++];
1422
+ mask[3] = randomPool[randomPoolPointer++];
1423
+ }
1424
+ skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) === 0;
1425
+ offset = 6;
1426
+ }
1427
+ let dataLength;
1428
+ if (typeof data === "string") {
1429
+ if ((!options.mask || skipMasking) && options[kByteLength] !== void 0) {
1430
+ dataLength = options[kByteLength];
1431
+ } else {
1432
+ data = Buffer.from(data);
1433
+ dataLength = data.length;
1434
+ }
1435
+ } else {
1436
+ dataLength = data.length;
1437
+ merge = options.mask && options.readOnly && !skipMasking;
1438
+ }
1439
+ let payloadLength = dataLength;
1440
+ if (dataLength >= 65536) {
1441
+ offset += 8;
1442
+ payloadLength = 127;
1443
+ } else if (dataLength > 125) {
1444
+ offset += 2;
1445
+ payloadLength = 126;
1446
+ }
1447
+ const target = Buffer.allocUnsafe(merge ? dataLength + offset : offset);
1448
+ target[0] = options.fin ? options.opcode | 128 : options.opcode;
1449
+ if (options.rsv1) target[0] |= 64;
1450
+ target[1] = payloadLength;
1451
+ if (payloadLength === 126) {
1452
+ target.writeUInt16BE(dataLength, 2);
1453
+ } else if (payloadLength === 127) {
1454
+ target[2] = target[3] = 0;
1455
+ target.writeUIntBE(dataLength, 4, 6);
1456
+ }
1457
+ if (!options.mask) return [target, data];
1458
+ target[1] |= 128;
1459
+ target[offset - 4] = mask[0];
1460
+ target[offset - 3] = mask[1];
1461
+ target[offset - 2] = mask[2];
1462
+ target[offset - 1] = mask[3];
1463
+ if (skipMasking) return [target, data];
1464
+ if (merge) {
1465
+ applyMask(data, mask, target, offset, dataLength);
1466
+ return [target];
1467
+ }
1468
+ applyMask(data, mask, data, 0, dataLength);
1469
+ return [target, data];
1470
+ }
1471
+ /**
1472
+ * Sends a close message to the other peer.
1473
+ *
1474
+ * @param {Number} [code] The status code component of the body
1475
+ * @param {(String|Buffer)} [data] The message component of the body
1476
+ * @param {Boolean} [mask=false] Specifies whether or not to mask the message
1477
+ * @param {Function} [cb] Callback
1478
+ * @public
1479
+ */
1480
+ close(code, data, mask, cb) {
1481
+ let buf;
1482
+ if (code === void 0) {
1483
+ buf = EMPTY_BUFFER;
1484
+ } else if (typeof code !== "number" || !isValidStatusCode(code)) {
1485
+ throw new TypeError("First argument must be a valid error code number");
1486
+ } else if (data === void 0 || !data.length) {
1487
+ buf = Buffer.allocUnsafe(2);
1488
+ buf.writeUInt16BE(code, 0);
1489
+ } else {
1490
+ const length = Buffer.byteLength(data);
1491
+ if (length > 123) {
1492
+ throw new RangeError("The message must not be greater than 123 bytes");
1493
+ }
1494
+ buf = Buffer.allocUnsafe(2 + length);
1495
+ buf.writeUInt16BE(code, 0);
1496
+ if (typeof data === "string") {
1497
+ buf.write(data, 2);
1498
+ } else {
1499
+ buf.set(data, 2);
1500
+ }
1501
+ }
1502
+ const options = {
1503
+ [kByteLength]: buf.length,
1504
+ fin: true,
1505
+ generateMask: this._generateMask,
1506
+ mask,
1507
+ maskBuffer: this._maskBuffer,
1508
+ opcode: 8,
1509
+ readOnly: false,
1510
+ rsv1: false
1511
+ };
1512
+ if (this._state !== DEFAULT) {
1513
+ this.enqueue([this.dispatch, buf, false, options, cb]);
1514
+ } else {
1515
+ this.sendFrame(_Sender.frame(buf, options), cb);
1516
+ }
1517
+ }
1518
+ /**
1519
+ * Sends a ping message to the other peer.
1520
+ *
1521
+ * @param {*} data The message to send
1522
+ * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
1523
+ * @param {Function} [cb] Callback
1524
+ * @public
1525
+ */
1526
+ ping(data, mask, cb) {
1527
+ let byteLength;
1528
+ let readOnly;
1529
+ if (typeof data === "string") {
1530
+ byteLength = Buffer.byteLength(data);
1531
+ readOnly = false;
1532
+ } else if (isBlob(data)) {
1533
+ byteLength = data.size;
1534
+ readOnly = false;
1535
+ } else {
1536
+ data = toBuffer(data);
1537
+ byteLength = data.length;
1538
+ readOnly = toBuffer.readOnly;
1539
+ }
1540
+ if (byteLength > 125) {
1541
+ throw new RangeError("The data size must not be greater than 125 bytes");
1542
+ }
1543
+ const options = {
1544
+ [kByteLength]: byteLength,
1545
+ fin: true,
1546
+ generateMask: this._generateMask,
1547
+ mask,
1548
+ maskBuffer: this._maskBuffer,
1549
+ opcode: 9,
1550
+ readOnly,
1551
+ rsv1: false
1552
+ };
1553
+ if (isBlob(data)) {
1554
+ if (this._state !== DEFAULT) {
1555
+ this.enqueue([this.getBlobData, data, false, options, cb]);
1556
+ } else {
1557
+ this.getBlobData(data, false, options, cb);
1558
+ }
1559
+ } else if (this._state !== DEFAULT) {
1560
+ this.enqueue([this.dispatch, data, false, options, cb]);
1561
+ } else {
1562
+ this.sendFrame(_Sender.frame(data, options), cb);
1563
+ }
1564
+ }
1565
+ /**
1566
+ * Sends a pong message to the other peer.
1567
+ *
1568
+ * @param {*} data The message to send
1569
+ * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
1570
+ * @param {Function} [cb] Callback
1571
+ * @public
1572
+ */
1573
+ pong(data, mask, cb) {
1574
+ let byteLength;
1575
+ let readOnly;
1576
+ if (typeof data === "string") {
1577
+ byteLength = Buffer.byteLength(data);
1578
+ readOnly = false;
1579
+ } else if (isBlob(data)) {
1580
+ byteLength = data.size;
1581
+ readOnly = false;
1582
+ } else {
1583
+ data = toBuffer(data);
1584
+ byteLength = data.length;
1585
+ readOnly = toBuffer.readOnly;
1586
+ }
1587
+ if (byteLength > 125) {
1588
+ throw new RangeError("The data size must not be greater than 125 bytes");
1589
+ }
1590
+ const options = {
1591
+ [kByteLength]: byteLength,
1592
+ fin: true,
1593
+ generateMask: this._generateMask,
1594
+ mask,
1595
+ maskBuffer: this._maskBuffer,
1596
+ opcode: 10,
1597
+ readOnly,
1598
+ rsv1: false
1599
+ };
1600
+ if (isBlob(data)) {
1601
+ if (this._state !== DEFAULT) {
1602
+ this.enqueue([this.getBlobData, data, false, options, cb]);
1603
+ } else {
1604
+ this.getBlobData(data, false, options, cb);
1605
+ }
1606
+ } else if (this._state !== DEFAULT) {
1607
+ this.enqueue([this.dispatch, data, false, options, cb]);
1608
+ } else {
1609
+ this.sendFrame(_Sender.frame(data, options), cb);
1610
+ }
1611
+ }
1612
+ /**
1613
+ * Sends a data message to the other peer.
1614
+ *
1615
+ * @param {*} data The message to send
1616
+ * @param {Object} options Options object
1617
+ * @param {Boolean} [options.binary=false] Specifies whether `data` is binary
1618
+ * or text
1619
+ * @param {Boolean} [options.compress=false] Specifies whether or not to
1620
+ * compress `data`
1621
+ * @param {Boolean} [options.fin=false] Specifies whether the fragment is the
1622
+ * last one
1623
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1624
+ * `data`
1625
+ * @param {Function} [cb] Callback
1626
+ * @public
1627
+ */
1628
+ send(data, options, cb) {
1629
+ const perMessageDeflate = this._extensions[PerMessageDeflate2.extensionName];
1630
+ let opcode = options.binary ? 2 : 1;
1631
+ let rsv1 = options.compress;
1632
+ let byteLength;
1633
+ let readOnly;
1634
+ if (typeof data === "string") {
1635
+ byteLength = Buffer.byteLength(data);
1636
+ readOnly = false;
1637
+ } else if (isBlob(data)) {
1638
+ byteLength = data.size;
1639
+ readOnly = false;
1640
+ } else {
1641
+ data = toBuffer(data);
1642
+ byteLength = data.length;
1643
+ readOnly = toBuffer.readOnly;
1644
+ }
1645
+ if (this._firstFragment) {
1646
+ this._firstFragment = false;
1647
+ if (rsv1 && perMessageDeflate && perMessageDeflate.params[perMessageDeflate._isServer ? "server_no_context_takeover" : "client_no_context_takeover"]) {
1648
+ rsv1 = byteLength >= perMessageDeflate._threshold;
1649
+ }
1650
+ this._compress = rsv1;
1651
+ } else {
1652
+ rsv1 = false;
1653
+ opcode = 0;
1654
+ }
1655
+ if (options.fin) this._firstFragment = true;
1656
+ const opts = {
1657
+ [kByteLength]: byteLength,
1658
+ fin: options.fin,
1659
+ generateMask: this._generateMask,
1660
+ mask: options.mask,
1661
+ maskBuffer: this._maskBuffer,
1662
+ opcode,
1663
+ readOnly,
1664
+ rsv1
1665
+ };
1666
+ if (isBlob(data)) {
1667
+ if (this._state !== DEFAULT) {
1668
+ this.enqueue([this.getBlobData, data, this._compress, opts, cb]);
1669
+ } else {
1670
+ this.getBlobData(data, this._compress, opts, cb);
1671
+ }
1672
+ } else if (this._state !== DEFAULT) {
1673
+ this.enqueue([this.dispatch, data, this._compress, opts, cb]);
1674
+ } else {
1675
+ this.dispatch(data, this._compress, opts, cb);
1676
+ }
1677
+ }
1678
+ /**
1679
+ * Gets the contents of a blob as binary data.
1680
+ *
1681
+ * @param {Blob} blob The blob
1682
+ * @param {Boolean} [compress=false] Specifies whether or not to compress
1683
+ * the data
1684
+ * @param {Object} options Options object
1685
+ * @param {Boolean} [options.fin=false] Specifies whether or not to set the
1686
+ * FIN bit
1687
+ * @param {Function} [options.generateMask] The function used to generate the
1688
+ * masking key
1689
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1690
+ * `data`
1691
+ * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
1692
+ * key
1693
+ * @param {Number} options.opcode The opcode
1694
+ * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
1695
+ * modified
1696
+ * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
1697
+ * RSV1 bit
1698
+ * @param {Function} [cb] Callback
1699
+ * @private
1700
+ */
1701
+ getBlobData(blob, compress, options, cb) {
1702
+ this._bufferedBytes += options[kByteLength];
1703
+ this._state = GET_BLOB_DATA;
1704
+ blob.arrayBuffer().then((arrayBuffer) => {
1705
+ if (this._socket.destroyed) {
1706
+ const err = new Error(
1707
+ "The socket was closed while the blob was being read"
1708
+ );
1709
+ process.nextTick(callCallbacks, this, err, cb);
1710
+ return;
1711
+ }
1712
+ this._bufferedBytes -= options[kByteLength];
1713
+ const data = toBuffer(arrayBuffer);
1714
+ if (!compress) {
1715
+ this._state = DEFAULT;
1716
+ this.sendFrame(_Sender.frame(data, options), cb);
1717
+ this.dequeue();
1718
+ } else {
1719
+ this.dispatch(data, compress, options, cb);
1720
+ }
1721
+ }).catch((err) => {
1722
+ process.nextTick(onError, this, err, cb);
1723
+ });
1724
+ }
1725
+ /**
1726
+ * Dispatches a message.
1727
+ *
1728
+ * @param {(Buffer|String)} data The message to send
1729
+ * @param {Boolean} [compress=false] Specifies whether or not to compress
1730
+ * `data`
1731
+ * @param {Object} options Options object
1732
+ * @param {Boolean} [options.fin=false] Specifies whether or not to set the
1733
+ * FIN bit
1734
+ * @param {Function} [options.generateMask] The function used to generate the
1735
+ * masking key
1736
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1737
+ * `data`
1738
+ * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
1739
+ * key
1740
+ * @param {Number} options.opcode The opcode
1741
+ * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
1742
+ * modified
1743
+ * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
1744
+ * RSV1 bit
1745
+ * @param {Function} [cb] Callback
1746
+ * @private
1747
+ */
1748
+ dispatch(data, compress, options, cb) {
1749
+ if (!compress) {
1750
+ this.sendFrame(_Sender.frame(data, options), cb);
1751
+ return;
1752
+ }
1753
+ const perMessageDeflate = this._extensions[PerMessageDeflate2.extensionName];
1754
+ this._bufferedBytes += options[kByteLength];
1755
+ this._state = DEFLATING;
1756
+ perMessageDeflate.compress(data, options.fin, (_, buf) => {
1757
+ if (this._socket.destroyed) {
1758
+ const err = new Error(
1759
+ "The socket was closed while data was being compressed"
1760
+ );
1761
+ callCallbacks(this, err, cb);
1762
+ return;
1763
+ }
1764
+ this._bufferedBytes -= options[kByteLength];
1765
+ this._state = DEFAULT;
1766
+ options.readOnly = false;
1767
+ this.sendFrame(_Sender.frame(buf, options), cb);
1768
+ this.dequeue();
1769
+ });
1770
+ }
1771
+ /**
1772
+ * Executes queued send operations.
1773
+ *
1774
+ * @private
1775
+ */
1776
+ dequeue() {
1777
+ while (this._state === DEFAULT && this._queue.length) {
1778
+ const params = this._queue.shift();
1779
+ this._bufferedBytes -= params[3][kByteLength];
1780
+ Reflect.apply(params[0], this, params.slice(1));
1781
+ }
1782
+ }
1783
+ /**
1784
+ * Enqueues a send operation.
1785
+ *
1786
+ * @param {Array} params Send operation parameters.
1787
+ * @private
1788
+ */
1789
+ enqueue(params) {
1790
+ this._bufferedBytes += params[3][kByteLength];
1791
+ this._queue.push(params);
1792
+ }
1793
+ /**
1794
+ * Sends a frame.
1795
+ *
1796
+ * @param {(Buffer | String)[]} list The frame to send
1797
+ * @param {Function} [cb] Callback
1798
+ * @private
1799
+ */
1800
+ sendFrame(list, cb) {
1801
+ if (list.length === 2) {
1802
+ this._socket.cork();
1803
+ this._socket.write(list[0]);
1804
+ this._socket.write(list[1], cb);
1805
+ this._socket.uncork();
1806
+ } else {
1807
+ this._socket.write(list[0], cb);
1808
+ }
1809
+ }
1810
+ };
1811
+ module.exports = Sender2;
1812
+ function callCallbacks(sender, err, cb) {
1813
+ if (typeof cb === "function") cb(err);
1814
+ for (let i = 0; i < sender._queue.length; i++) {
1815
+ const params = sender._queue[i];
1816
+ const callback = params[params.length - 1];
1817
+ if (typeof callback === "function") callback(err);
1818
+ }
1819
+ }
1820
+ function onError(sender, err, cb) {
1821
+ callCallbacks(sender, err, cb);
1822
+ sender.onerror(err);
1823
+ }
1824
+ }
1825
+ });
1826
+
1827
+ // ../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/event-target.js
1828
+ var require_event_target = __commonJS({
1829
+ "../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/event-target.js"(exports, module) {
1830
+ "use strict";
1831
+ init_esm_shims();
1832
+ var { kForOnEventAttribute, kListener } = require_constants();
1833
+ var kCode = /* @__PURE__ */ Symbol("kCode");
1834
+ var kData = /* @__PURE__ */ Symbol("kData");
1835
+ var kError = /* @__PURE__ */ Symbol("kError");
1836
+ var kMessage = /* @__PURE__ */ Symbol("kMessage");
1837
+ var kReason = /* @__PURE__ */ Symbol("kReason");
1838
+ var kTarget = /* @__PURE__ */ Symbol("kTarget");
1839
+ var kType = /* @__PURE__ */ Symbol("kType");
1840
+ var kWasClean = /* @__PURE__ */ Symbol("kWasClean");
1841
+ var Event = class {
1842
+ /**
1843
+ * Create a new `Event`.
1844
+ *
1845
+ * @param {String} type The name of the event
1846
+ * @throws {TypeError} If the `type` argument is not specified
1847
+ */
1848
+ constructor(type) {
1849
+ this[kTarget] = null;
1850
+ this[kType] = type;
1851
+ }
1852
+ /**
1853
+ * @type {*}
1854
+ */
1855
+ get target() {
1856
+ return this[kTarget];
1857
+ }
1858
+ /**
1859
+ * @type {String}
1860
+ */
1861
+ get type() {
1862
+ return this[kType];
1863
+ }
1864
+ };
1865
+ Object.defineProperty(Event.prototype, "target", { enumerable: true });
1866
+ Object.defineProperty(Event.prototype, "type", { enumerable: true });
1867
+ var CloseEvent = class extends Event {
1868
+ /**
1869
+ * Create a new `CloseEvent`.
1870
+ *
1871
+ * @param {String} type The name of the event
1872
+ * @param {Object} [options] A dictionary object that allows for setting
1873
+ * attributes via object members of the same name
1874
+ * @param {Number} [options.code=0] The status code explaining why the
1875
+ * connection was closed
1876
+ * @param {String} [options.reason=''] A human-readable string explaining why
1877
+ * the connection was closed
1878
+ * @param {Boolean} [options.wasClean=false] Indicates whether or not the
1879
+ * connection was cleanly closed
1880
+ */
1881
+ constructor(type, options = {}) {
1882
+ super(type);
1883
+ this[kCode] = options.code === void 0 ? 0 : options.code;
1884
+ this[kReason] = options.reason === void 0 ? "" : options.reason;
1885
+ this[kWasClean] = options.wasClean === void 0 ? false : options.wasClean;
1886
+ }
1887
+ /**
1888
+ * @type {Number}
1889
+ */
1890
+ get code() {
1891
+ return this[kCode];
1892
+ }
1893
+ /**
1894
+ * @type {String}
1895
+ */
1896
+ get reason() {
1897
+ return this[kReason];
1898
+ }
1899
+ /**
1900
+ * @type {Boolean}
1901
+ */
1902
+ get wasClean() {
1903
+ return this[kWasClean];
1904
+ }
1905
+ };
1906
+ Object.defineProperty(CloseEvent.prototype, "code", { enumerable: true });
1907
+ Object.defineProperty(CloseEvent.prototype, "reason", { enumerable: true });
1908
+ Object.defineProperty(CloseEvent.prototype, "wasClean", { enumerable: true });
1909
+ var ErrorEvent = class extends Event {
1910
+ /**
1911
+ * Create a new `ErrorEvent`.
1912
+ *
1913
+ * @param {String} type The name of the event
1914
+ * @param {Object} [options] A dictionary object that allows for setting
1915
+ * attributes via object members of the same name
1916
+ * @param {*} [options.error=null] The error that generated this event
1917
+ * @param {String} [options.message=''] The error message
1918
+ */
1919
+ constructor(type, options = {}) {
1920
+ super(type);
1921
+ this[kError] = options.error === void 0 ? null : options.error;
1922
+ this[kMessage] = options.message === void 0 ? "" : options.message;
1923
+ }
1924
+ /**
1925
+ * @type {*}
1926
+ */
1927
+ get error() {
1928
+ return this[kError];
1929
+ }
1930
+ /**
1931
+ * @type {String}
1932
+ */
1933
+ get message() {
1934
+ return this[kMessage];
1935
+ }
1936
+ };
1937
+ Object.defineProperty(ErrorEvent.prototype, "error", { enumerable: true });
1938
+ Object.defineProperty(ErrorEvent.prototype, "message", { enumerable: true });
1939
+ var MessageEvent = class extends Event {
1940
+ /**
1941
+ * Create a new `MessageEvent`.
1942
+ *
1943
+ * @param {String} type The name of the event
1944
+ * @param {Object} [options] A dictionary object that allows for setting
1945
+ * attributes via object members of the same name
1946
+ * @param {*} [options.data=null] The message content
1947
+ */
1948
+ constructor(type, options = {}) {
1949
+ super(type);
1950
+ this[kData] = options.data === void 0 ? null : options.data;
1951
+ }
1952
+ /**
1953
+ * @type {*}
1954
+ */
1955
+ get data() {
1956
+ return this[kData];
1957
+ }
1958
+ };
1959
+ Object.defineProperty(MessageEvent.prototype, "data", { enumerable: true });
1960
+ var EventTarget = {
1961
+ /**
1962
+ * Register an event listener.
1963
+ *
1964
+ * @param {String} type A string representing the event type to listen for
1965
+ * @param {(Function|Object)} handler The listener to add
1966
+ * @param {Object} [options] An options object specifies characteristics about
1967
+ * the event listener
1968
+ * @param {Boolean} [options.once=false] A `Boolean` indicating that the
1969
+ * listener should be invoked at most once after being added. If `true`,
1970
+ * the listener would be automatically removed when invoked.
1971
+ * @public
1972
+ */
1973
+ addEventListener(type, handler, options = {}) {
1974
+ for (const listener of this.listeners(type)) {
1975
+ if (!options[kForOnEventAttribute] && listener[kListener] === handler && !listener[kForOnEventAttribute]) {
1976
+ return;
1977
+ }
1978
+ }
1979
+ let wrapper;
1980
+ if (type === "message") {
1981
+ wrapper = function onMessage(data, isBinary) {
1982
+ const event = new MessageEvent("message", {
1983
+ data: isBinary ? data : data.toString()
1984
+ });
1985
+ event[kTarget] = this;
1986
+ callListener(handler, this, event);
1987
+ };
1988
+ } else if (type === "close") {
1989
+ wrapper = function onClose(code, message) {
1990
+ const event = new CloseEvent("close", {
1991
+ code,
1992
+ reason: message.toString(),
1993
+ wasClean: this._closeFrameReceived && this._closeFrameSent
1994
+ });
1995
+ event[kTarget] = this;
1996
+ callListener(handler, this, event);
1997
+ };
1998
+ } else if (type === "error") {
1999
+ wrapper = function onError(error) {
2000
+ const event = new ErrorEvent("error", {
2001
+ error,
2002
+ message: error.message
2003
+ });
2004
+ event[kTarget] = this;
2005
+ callListener(handler, this, event);
2006
+ };
2007
+ } else if (type === "open") {
2008
+ wrapper = function onOpen() {
2009
+ const event = new Event("open");
2010
+ event[kTarget] = this;
2011
+ callListener(handler, this, event);
2012
+ };
2013
+ } else {
2014
+ return;
2015
+ }
2016
+ wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute];
2017
+ wrapper[kListener] = handler;
2018
+ if (options.once) {
2019
+ this.once(type, wrapper);
2020
+ } else {
2021
+ this.on(type, wrapper);
2022
+ }
2023
+ },
2024
+ /**
2025
+ * Remove an event listener.
2026
+ *
2027
+ * @param {String} type A string representing the event type to remove
2028
+ * @param {(Function|Object)} handler The listener to remove
2029
+ * @public
2030
+ */
2031
+ removeEventListener(type, handler) {
2032
+ for (const listener of this.listeners(type)) {
2033
+ if (listener[kListener] === handler && !listener[kForOnEventAttribute]) {
2034
+ this.removeListener(type, listener);
2035
+ break;
2036
+ }
2037
+ }
2038
+ }
2039
+ };
2040
+ module.exports = {
2041
+ CloseEvent,
2042
+ ErrorEvent,
2043
+ Event,
2044
+ EventTarget,
2045
+ MessageEvent
2046
+ };
2047
+ function callListener(listener, thisArg, event) {
2048
+ if (typeof listener === "object" && listener.handleEvent) {
2049
+ listener.handleEvent.call(listener, event);
2050
+ } else {
2051
+ listener.call(thisArg, event);
2052
+ }
2053
+ }
2054
+ }
2055
+ });
2056
+
2057
+ // ../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/extension.js
2058
+ var require_extension = __commonJS({
2059
+ "../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/extension.js"(exports, module) {
2060
+ "use strict";
2061
+ init_esm_shims();
2062
+ var { tokenChars } = require_validation();
2063
+ function push(dest, name, elem) {
2064
+ if (dest[name] === void 0) dest[name] = [elem];
2065
+ else dest[name].push(elem);
2066
+ }
2067
+ function parse(header) {
2068
+ const offers = /* @__PURE__ */ Object.create(null);
2069
+ let params = /* @__PURE__ */ Object.create(null);
2070
+ let mustUnescape = false;
2071
+ let isEscaping = false;
2072
+ let inQuotes = false;
2073
+ let extensionName;
2074
+ let paramName;
2075
+ let start = -1;
2076
+ let code = -1;
2077
+ let end = -1;
2078
+ let i = 0;
2079
+ for (; i < header.length; i++) {
2080
+ code = header.charCodeAt(i);
2081
+ if (extensionName === void 0) {
2082
+ if (end === -1 && tokenChars[code] === 1) {
2083
+ if (start === -1) start = i;
2084
+ } else if (i !== 0 && (code === 32 || code === 9)) {
2085
+ if (end === -1 && start !== -1) end = i;
2086
+ } else if (code === 59 || code === 44) {
2087
+ if (start === -1) {
2088
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2089
+ }
2090
+ if (end === -1) end = i;
2091
+ const name = header.slice(start, end);
2092
+ if (code === 44) {
2093
+ push(offers, name, params);
2094
+ params = /* @__PURE__ */ Object.create(null);
2095
+ } else {
2096
+ extensionName = name;
2097
+ }
2098
+ start = end = -1;
2099
+ } else {
2100
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2101
+ }
2102
+ } else if (paramName === void 0) {
2103
+ if (end === -1 && tokenChars[code] === 1) {
2104
+ if (start === -1) start = i;
2105
+ } else if (code === 32 || code === 9) {
2106
+ if (end === -1 && start !== -1) end = i;
2107
+ } else if (code === 59 || code === 44) {
2108
+ if (start === -1) {
2109
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2110
+ }
2111
+ if (end === -1) end = i;
2112
+ push(params, header.slice(start, end), true);
2113
+ if (code === 44) {
2114
+ push(offers, extensionName, params);
2115
+ params = /* @__PURE__ */ Object.create(null);
2116
+ extensionName = void 0;
2117
+ }
2118
+ start = end = -1;
2119
+ } else if (code === 61 && start !== -1 && end === -1) {
2120
+ paramName = header.slice(start, i);
2121
+ start = end = -1;
2122
+ } else {
2123
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2124
+ }
2125
+ } else {
2126
+ if (isEscaping) {
2127
+ if (tokenChars[code] !== 1) {
2128
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2129
+ }
2130
+ if (start === -1) start = i;
2131
+ else if (!mustUnescape) mustUnescape = true;
2132
+ isEscaping = false;
2133
+ } else if (inQuotes) {
2134
+ if (tokenChars[code] === 1) {
2135
+ if (start === -1) start = i;
2136
+ } else if (code === 34 && start !== -1) {
2137
+ inQuotes = false;
2138
+ end = i;
2139
+ } else if (code === 92) {
2140
+ isEscaping = true;
2141
+ } else {
2142
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2143
+ }
2144
+ } else if (code === 34 && header.charCodeAt(i - 1) === 61) {
2145
+ inQuotes = true;
2146
+ } else if (end === -1 && tokenChars[code] === 1) {
2147
+ if (start === -1) start = i;
2148
+ } else if (start !== -1 && (code === 32 || code === 9)) {
2149
+ if (end === -1) end = i;
2150
+ } else if (code === 59 || code === 44) {
2151
+ if (start === -1) {
2152
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2153
+ }
2154
+ if (end === -1) end = i;
2155
+ let value = header.slice(start, end);
2156
+ if (mustUnescape) {
2157
+ value = value.replace(/\\/g, "");
2158
+ mustUnescape = false;
2159
+ }
2160
+ push(params, paramName, value);
2161
+ if (code === 44) {
2162
+ push(offers, extensionName, params);
2163
+ params = /* @__PURE__ */ Object.create(null);
2164
+ extensionName = void 0;
2165
+ }
2166
+ paramName = void 0;
2167
+ start = end = -1;
2168
+ } else {
2169
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2170
+ }
2171
+ }
2172
+ }
2173
+ if (start === -1 || inQuotes || code === 32 || code === 9) {
2174
+ throw new SyntaxError("Unexpected end of input");
2175
+ }
2176
+ if (end === -1) end = i;
2177
+ const token = header.slice(start, end);
2178
+ if (extensionName === void 0) {
2179
+ push(offers, token, params);
2180
+ } else {
2181
+ if (paramName === void 0) {
2182
+ push(params, token, true);
2183
+ } else if (mustUnescape) {
2184
+ push(params, paramName, token.replace(/\\/g, ""));
2185
+ } else {
2186
+ push(params, paramName, token);
2187
+ }
2188
+ push(offers, extensionName, params);
2189
+ }
2190
+ return offers;
2191
+ }
2192
+ function format(extensions) {
2193
+ return Object.keys(extensions).map((extension2) => {
2194
+ let configurations = extensions[extension2];
2195
+ if (!Array.isArray(configurations)) configurations = [configurations];
2196
+ return configurations.map((params) => {
2197
+ return [extension2].concat(
2198
+ Object.keys(params).map((k) => {
2199
+ let values = params[k];
2200
+ if (!Array.isArray(values)) values = [values];
2201
+ return values.map((v) => v === true ? k : `${k}=${v}`).join("; ");
2202
+ })
2203
+ ).join("; ");
2204
+ }).join(", ");
2205
+ }).join(", ");
2206
+ }
2207
+ module.exports = { format, parse };
2208
+ }
2209
+ });
2210
+
2211
+ // ../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/websocket.js
2212
+ var require_websocket = __commonJS({
2213
+ "../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/websocket.js"(exports, module) {
2214
+ "use strict";
2215
+ init_esm_shims();
2216
+ var EventEmitter = __require("events");
2217
+ var https = __require("https");
2218
+ var http = __require("http");
2219
+ var net = __require("net");
2220
+ var tls = __require("tls");
2221
+ var { randomBytes, createHash } = __require("crypto");
2222
+ var { Duplex, Readable } = __require("stream");
2223
+ var { URL } = __require("url");
2224
+ var PerMessageDeflate2 = require_permessage_deflate();
2225
+ var Receiver2 = require_receiver();
2226
+ var Sender2 = require_sender();
2227
+ var { isBlob } = require_validation();
2228
+ var {
2229
+ BINARY_TYPES,
2230
+ CLOSE_TIMEOUT,
2231
+ EMPTY_BUFFER,
2232
+ GUID,
2233
+ kForOnEventAttribute,
2234
+ kListener,
2235
+ kStatusCode,
2236
+ kWebSocket,
2237
+ NOOP
2238
+ } = require_constants();
2239
+ var {
2240
+ EventTarget: { addEventListener, removeEventListener }
2241
+ } = require_event_target();
2242
+ var { format, parse } = require_extension();
2243
+ var { toBuffer } = require_buffer_util();
2244
+ var kAborted = /* @__PURE__ */ Symbol("kAborted");
2245
+ var protocolVersions = [8, 13];
2246
+ var readyStates = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"];
2247
+ var subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
2248
+ var WebSocket2 = class _WebSocket extends EventEmitter {
2249
+ /**
2250
+ * Create a new `WebSocket`.
2251
+ *
2252
+ * @param {(String|URL)} address The URL to which to connect
2253
+ * @param {(String|String[])} [protocols] The subprotocols
2254
+ * @param {Object} [options] Connection options
2255
+ */
2256
+ constructor(address, protocols, options) {
2257
+ super();
2258
+ this._binaryType = BINARY_TYPES[0];
2259
+ this._closeCode = 1006;
2260
+ this._closeFrameReceived = false;
2261
+ this._closeFrameSent = false;
2262
+ this._closeMessage = EMPTY_BUFFER;
2263
+ this._closeTimer = null;
2264
+ this._errorEmitted = false;
2265
+ this._extensions = {};
2266
+ this._paused = false;
2267
+ this._protocol = "";
2268
+ this._readyState = _WebSocket.CONNECTING;
2269
+ this._receiver = null;
2270
+ this._sender = null;
2271
+ this._socket = null;
2272
+ if (address !== null) {
2273
+ this._bufferedAmount = 0;
2274
+ this._isServer = false;
2275
+ this._redirects = 0;
2276
+ if (protocols === void 0) {
2277
+ protocols = [];
2278
+ } else if (!Array.isArray(protocols)) {
2279
+ if (typeof protocols === "object" && protocols !== null) {
2280
+ options = protocols;
2281
+ protocols = [];
2282
+ } else {
2283
+ protocols = [protocols];
2284
+ }
2285
+ }
2286
+ initAsClient(this, address, protocols, options);
2287
+ } else {
2288
+ this._autoPong = options.autoPong;
2289
+ this._closeTimeout = options.closeTimeout;
2290
+ this._isServer = true;
2291
+ }
2292
+ }
2293
+ /**
2294
+ * For historical reasons, the custom "nodebuffer" type is used by the default
2295
+ * instead of "blob".
2296
+ *
2297
+ * @type {String}
2298
+ */
2299
+ get binaryType() {
2300
+ return this._binaryType;
2301
+ }
2302
+ set binaryType(type) {
2303
+ if (!BINARY_TYPES.includes(type)) return;
2304
+ this._binaryType = type;
2305
+ if (this._receiver) this._receiver._binaryType = type;
2306
+ }
2307
+ /**
2308
+ * @type {Number}
2309
+ */
2310
+ get bufferedAmount() {
2311
+ if (!this._socket) return this._bufferedAmount;
2312
+ return this._socket._writableState.length + this._sender._bufferedBytes;
2313
+ }
2314
+ /**
2315
+ * @type {String}
2316
+ */
2317
+ get extensions() {
2318
+ return Object.keys(this._extensions).join();
2319
+ }
2320
+ /**
2321
+ * @type {Boolean}
2322
+ */
2323
+ get isPaused() {
2324
+ return this._paused;
2325
+ }
2326
+ /**
2327
+ * @type {Function}
2328
+ */
2329
+ /* istanbul ignore next */
2330
+ get onclose() {
2331
+ return null;
2332
+ }
2333
+ /**
2334
+ * @type {Function}
2335
+ */
2336
+ /* istanbul ignore next */
2337
+ get onerror() {
2338
+ return null;
2339
+ }
2340
+ /**
2341
+ * @type {Function}
2342
+ */
2343
+ /* istanbul ignore next */
2344
+ get onopen() {
2345
+ return null;
2346
+ }
2347
+ /**
2348
+ * @type {Function}
2349
+ */
2350
+ /* istanbul ignore next */
2351
+ get onmessage() {
2352
+ return null;
2353
+ }
2354
+ /**
2355
+ * @type {String}
2356
+ */
2357
+ get protocol() {
2358
+ return this._protocol;
2359
+ }
2360
+ /**
2361
+ * @type {Number}
2362
+ */
2363
+ get readyState() {
2364
+ return this._readyState;
2365
+ }
2366
+ /**
2367
+ * @type {String}
2368
+ */
2369
+ get url() {
2370
+ return this._url;
2371
+ }
2372
+ /**
2373
+ * Set up the socket and the internal resources.
2374
+ *
2375
+ * @param {Duplex} socket The network socket between the server and client
2376
+ * @param {Buffer} head The first packet of the upgraded stream
2377
+ * @param {Object} options Options object
2378
+ * @param {Boolean} [options.allowSynchronousEvents=false] Specifies whether
2379
+ * any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
2380
+ * multiple times in the same tick
2381
+ * @param {Function} [options.generateMask] The function used to generate the
2382
+ * masking key
2383
+ * @param {Number} [options.maxPayload=0] The maximum allowed message size
2384
+ * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
2385
+ * not to skip UTF-8 validation for text and close messages
2386
+ * @private
2387
+ */
2388
+ setSocket(socket, head, options) {
2389
+ const receiver = new Receiver2({
2390
+ allowSynchronousEvents: options.allowSynchronousEvents,
2391
+ binaryType: this.binaryType,
2392
+ extensions: this._extensions,
2393
+ isServer: this._isServer,
2394
+ maxPayload: options.maxPayload,
2395
+ skipUTF8Validation: options.skipUTF8Validation
2396
+ });
2397
+ const sender = new Sender2(socket, this._extensions, options.generateMask);
2398
+ this._receiver = receiver;
2399
+ this._sender = sender;
2400
+ this._socket = socket;
2401
+ receiver[kWebSocket] = this;
2402
+ sender[kWebSocket] = this;
2403
+ socket[kWebSocket] = this;
2404
+ receiver.on("conclude", receiverOnConclude);
2405
+ receiver.on("drain", receiverOnDrain);
2406
+ receiver.on("error", receiverOnError);
2407
+ receiver.on("message", receiverOnMessage);
2408
+ receiver.on("ping", receiverOnPing);
2409
+ receiver.on("pong", receiverOnPong);
2410
+ sender.onerror = senderOnError;
2411
+ if (socket.setTimeout) socket.setTimeout(0);
2412
+ if (socket.setNoDelay) socket.setNoDelay();
2413
+ if (head.length > 0) socket.unshift(head);
2414
+ socket.on("close", socketOnClose);
2415
+ socket.on("data", socketOnData);
2416
+ socket.on("end", socketOnEnd);
2417
+ socket.on("error", socketOnError);
2418
+ this._readyState = _WebSocket.OPEN;
2419
+ this.emit("open");
2420
+ }
2421
+ /**
2422
+ * Emit the `'close'` event.
2423
+ *
2424
+ * @private
2425
+ */
2426
+ emitClose() {
2427
+ if (!this._socket) {
2428
+ this._readyState = _WebSocket.CLOSED;
2429
+ this.emit("close", this._closeCode, this._closeMessage);
2430
+ return;
2431
+ }
2432
+ if (this._extensions[PerMessageDeflate2.extensionName]) {
2433
+ this._extensions[PerMessageDeflate2.extensionName].cleanup();
2434
+ }
2435
+ this._receiver.removeAllListeners();
2436
+ this._readyState = _WebSocket.CLOSED;
2437
+ this.emit("close", this._closeCode, this._closeMessage);
2438
+ }
2439
+ /**
2440
+ * Start a closing handshake.
2441
+ *
2442
+ * +----------+ +-----------+ +----------+
2443
+ * - - -|ws.close()|-->|close frame|-->|ws.close()|- - -
2444
+ * | +----------+ +-----------+ +----------+ |
2445
+ * +----------+ +-----------+ |
2446
+ * CLOSING |ws.close()|<--|close frame|<--+-----+ CLOSING
2447
+ * +----------+ +-----------+ |
2448
+ * | | | +---+ |
2449
+ * +------------------------+-->|fin| - - - -
2450
+ * | +---+ | +---+
2451
+ * - - - - -|fin|<---------------------+
2452
+ * +---+
2453
+ *
2454
+ * @param {Number} [code] Status code explaining why the connection is closing
2455
+ * @param {(String|Buffer)} [data] The reason why the connection is
2456
+ * closing
2457
+ * @public
2458
+ */
2459
+ close(code, data) {
2460
+ if (this.readyState === _WebSocket.CLOSED) return;
2461
+ if (this.readyState === _WebSocket.CONNECTING) {
2462
+ const msg = "WebSocket was closed before the connection was established";
2463
+ abortHandshake(this, this._req, msg);
2464
+ return;
2465
+ }
2466
+ if (this.readyState === _WebSocket.CLOSING) {
2467
+ if (this._closeFrameSent && (this._closeFrameReceived || this._receiver._writableState.errorEmitted)) {
2468
+ this._socket.end();
2469
+ }
2470
+ return;
2471
+ }
2472
+ this._readyState = _WebSocket.CLOSING;
2473
+ this._sender.close(code, data, !this._isServer, (err) => {
2474
+ if (err) return;
2475
+ this._closeFrameSent = true;
2476
+ if (this._closeFrameReceived || this._receiver._writableState.errorEmitted) {
2477
+ this._socket.end();
2478
+ }
2479
+ });
2480
+ setCloseTimer(this);
2481
+ }
2482
+ /**
2483
+ * Pause the socket.
2484
+ *
2485
+ * @public
2486
+ */
2487
+ pause() {
2488
+ if (this.readyState === _WebSocket.CONNECTING || this.readyState === _WebSocket.CLOSED) {
2489
+ return;
2490
+ }
2491
+ this._paused = true;
2492
+ this._socket.pause();
2493
+ }
2494
+ /**
2495
+ * Send a ping.
2496
+ *
2497
+ * @param {*} [data] The data to send
2498
+ * @param {Boolean} [mask] Indicates whether or not to mask `data`
2499
+ * @param {Function} [cb] Callback which is executed when the ping is sent
2500
+ * @public
2501
+ */
2502
+ ping(data, mask, cb) {
2503
+ if (this.readyState === _WebSocket.CONNECTING) {
2504
+ throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
2505
+ }
2506
+ if (typeof data === "function") {
2507
+ cb = data;
2508
+ data = mask = void 0;
2509
+ } else if (typeof mask === "function") {
2510
+ cb = mask;
2511
+ mask = void 0;
2512
+ }
2513
+ if (typeof data === "number") data = data.toString();
2514
+ if (this.readyState !== _WebSocket.OPEN) {
2515
+ sendAfterClose(this, data, cb);
2516
+ return;
2517
+ }
2518
+ if (mask === void 0) mask = !this._isServer;
2519
+ this._sender.ping(data || EMPTY_BUFFER, mask, cb);
2520
+ }
2521
+ /**
2522
+ * Send a pong.
2523
+ *
2524
+ * @param {*} [data] The data to send
2525
+ * @param {Boolean} [mask] Indicates whether or not to mask `data`
2526
+ * @param {Function} [cb] Callback which is executed when the pong is sent
2527
+ * @public
2528
+ */
2529
+ pong(data, mask, cb) {
2530
+ if (this.readyState === _WebSocket.CONNECTING) {
2531
+ throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
2532
+ }
2533
+ if (typeof data === "function") {
2534
+ cb = data;
2535
+ data = mask = void 0;
2536
+ } else if (typeof mask === "function") {
2537
+ cb = mask;
2538
+ mask = void 0;
2539
+ }
2540
+ if (typeof data === "number") data = data.toString();
2541
+ if (this.readyState !== _WebSocket.OPEN) {
2542
+ sendAfterClose(this, data, cb);
2543
+ return;
2544
+ }
2545
+ if (mask === void 0) mask = !this._isServer;
2546
+ this._sender.pong(data || EMPTY_BUFFER, mask, cb);
2547
+ }
2548
+ /**
2549
+ * Resume the socket.
2550
+ *
2551
+ * @public
2552
+ */
2553
+ resume() {
2554
+ if (this.readyState === _WebSocket.CONNECTING || this.readyState === _WebSocket.CLOSED) {
2555
+ return;
2556
+ }
2557
+ this._paused = false;
2558
+ if (!this._receiver._writableState.needDrain) this._socket.resume();
2559
+ }
2560
+ /**
2561
+ * Send a data message.
2562
+ *
2563
+ * @param {*} data The message to send
2564
+ * @param {Object} [options] Options object
2565
+ * @param {Boolean} [options.binary] Specifies whether `data` is binary or
2566
+ * text
2567
+ * @param {Boolean} [options.compress] Specifies whether or not to compress
2568
+ * `data`
2569
+ * @param {Boolean} [options.fin=true] Specifies whether the fragment is the
2570
+ * last one
2571
+ * @param {Boolean} [options.mask] Specifies whether or not to mask `data`
2572
+ * @param {Function} [cb] Callback which is executed when data is written out
2573
+ * @public
2574
+ */
2575
+ send(data, options, cb) {
2576
+ if (this.readyState === _WebSocket.CONNECTING) {
2577
+ throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
2578
+ }
2579
+ if (typeof options === "function") {
2580
+ cb = options;
2581
+ options = {};
2582
+ }
2583
+ if (typeof data === "number") data = data.toString();
2584
+ if (this.readyState !== _WebSocket.OPEN) {
2585
+ sendAfterClose(this, data, cb);
2586
+ return;
2587
+ }
2588
+ const opts = {
2589
+ binary: typeof data !== "string",
2590
+ mask: !this._isServer,
2591
+ compress: true,
2592
+ fin: true,
2593
+ ...options
2594
+ };
2595
+ if (!this._extensions[PerMessageDeflate2.extensionName]) {
2596
+ opts.compress = false;
2597
+ }
2598
+ this._sender.send(data || EMPTY_BUFFER, opts, cb);
2599
+ }
2600
+ /**
2601
+ * Forcibly close the connection.
2602
+ *
2603
+ * @public
2604
+ */
2605
+ terminate() {
2606
+ if (this.readyState === _WebSocket.CLOSED) return;
2607
+ if (this.readyState === _WebSocket.CONNECTING) {
2608
+ const msg = "WebSocket was closed before the connection was established";
2609
+ abortHandshake(this, this._req, msg);
2610
+ return;
2611
+ }
2612
+ if (this._socket) {
2613
+ this._readyState = _WebSocket.CLOSING;
2614
+ this._socket.destroy();
2615
+ }
2616
+ }
2617
+ };
2618
+ Object.defineProperty(WebSocket2, "CONNECTING", {
2619
+ enumerable: true,
2620
+ value: readyStates.indexOf("CONNECTING")
2621
+ });
2622
+ Object.defineProperty(WebSocket2.prototype, "CONNECTING", {
2623
+ enumerable: true,
2624
+ value: readyStates.indexOf("CONNECTING")
2625
+ });
2626
+ Object.defineProperty(WebSocket2, "OPEN", {
2627
+ enumerable: true,
2628
+ value: readyStates.indexOf("OPEN")
2629
+ });
2630
+ Object.defineProperty(WebSocket2.prototype, "OPEN", {
2631
+ enumerable: true,
2632
+ value: readyStates.indexOf("OPEN")
2633
+ });
2634
+ Object.defineProperty(WebSocket2, "CLOSING", {
2635
+ enumerable: true,
2636
+ value: readyStates.indexOf("CLOSING")
2637
+ });
2638
+ Object.defineProperty(WebSocket2.prototype, "CLOSING", {
2639
+ enumerable: true,
2640
+ value: readyStates.indexOf("CLOSING")
2641
+ });
2642
+ Object.defineProperty(WebSocket2, "CLOSED", {
2643
+ enumerable: true,
2644
+ value: readyStates.indexOf("CLOSED")
2645
+ });
2646
+ Object.defineProperty(WebSocket2.prototype, "CLOSED", {
2647
+ enumerable: true,
2648
+ value: readyStates.indexOf("CLOSED")
2649
+ });
2650
+ [
2651
+ "binaryType",
2652
+ "bufferedAmount",
2653
+ "extensions",
2654
+ "isPaused",
2655
+ "protocol",
2656
+ "readyState",
2657
+ "url"
2658
+ ].forEach((property) => {
2659
+ Object.defineProperty(WebSocket2.prototype, property, { enumerable: true });
2660
+ });
2661
+ ["open", "error", "close", "message"].forEach((method) => {
2662
+ Object.defineProperty(WebSocket2.prototype, `on${method}`, {
2663
+ enumerable: true,
2664
+ get() {
2665
+ for (const listener of this.listeners(method)) {
2666
+ if (listener[kForOnEventAttribute]) return listener[kListener];
2667
+ }
2668
+ return null;
2669
+ },
2670
+ set(handler) {
2671
+ for (const listener of this.listeners(method)) {
2672
+ if (listener[kForOnEventAttribute]) {
2673
+ this.removeListener(method, listener);
2674
+ break;
2675
+ }
2676
+ }
2677
+ if (typeof handler !== "function") return;
2678
+ this.addEventListener(method, handler, {
2679
+ [kForOnEventAttribute]: true
2680
+ });
2681
+ }
2682
+ });
2683
+ });
2684
+ WebSocket2.prototype.addEventListener = addEventListener;
2685
+ WebSocket2.prototype.removeEventListener = removeEventListener;
2686
+ module.exports = WebSocket2;
2687
+ function initAsClient(websocket, address, protocols, options) {
2688
+ const opts = {
2689
+ allowSynchronousEvents: true,
2690
+ autoPong: true,
2691
+ closeTimeout: CLOSE_TIMEOUT,
2692
+ protocolVersion: protocolVersions[1],
2693
+ maxPayload: 100 * 1024 * 1024,
2694
+ skipUTF8Validation: false,
2695
+ perMessageDeflate: true,
2696
+ followRedirects: false,
2697
+ maxRedirects: 10,
2698
+ ...options,
2699
+ socketPath: void 0,
2700
+ hostname: void 0,
2701
+ protocol: void 0,
2702
+ timeout: void 0,
2703
+ method: "GET",
2704
+ host: void 0,
2705
+ path: void 0,
2706
+ port: void 0
2707
+ };
2708
+ websocket._autoPong = opts.autoPong;
2709
+ websocket._closeTimeout = opts.closeTimeout;
2710
+ if (!protocolVersions.includes(opts.protocolVersion)) {
2711
+ throw new RangeError(
2712
+ `Unsupported protocol version: ${opts.protocolVersion} (supported versions: ${protocolVersions.join(", ")})`
2713
+ );
2714
+ }
2715
+ let parsedUrl;
2716
+ if (address instanceof URL) {
2717
+ parsedUrl = address;
2718
+ } else {
2719
+ try {
2720
+ parsedUrl = new URL(address);
2721
+ } catch {
2722
+ throw new SyntaxError(`Invalid URL: ${address}`);
2723
+ }
2724
+ }
2725
+ if (parsedUrl.protocol === "http:") {
2726
+ parsedUrl.protocol = "ws:";
2727
+ } else if (parsedUrl.protocol === "https:") {
2728
+ parsedUrl.protocol = "wss:";
2729
+ }
2730
+ websocket._url = parsedUrl.href;
2731
+ const isSecure = parsedUrl.protocol === "wss:";
2732
+ const isIpcUrl = parsedUrl.protocol === "ws+unix:";
2733
+ let invalidUrlMessage;
2734
+ if (parsedUrl.protocol !== "ws:" && !isSecure && !isIpcUrl) {
2735
+ invalidUrlMessage = `The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`;
2736
+ } else if (isIpcUrl && !parsedUrl.pathname) {
2737
+ invalidUrlMessage = "The URL's pathname is empty";
2738
+ } else if (parsedUrl.hash) {
2739
+ invalidUrlMessage = "The URL contains a fragment identifier";
2740
+ }
2741
+ if (invalidUrlMessage) {
2742
+ const err = new SyntaxError(invalidUrlMessage);
2743
+ if (websocket._redirects === 0) {
2744
+ throw err;
2745
+ } else {
2746
+ emitErrorAndClose(websocket, err);
2747
+ return;
2748
+ }
2749
+ }
2750
+ const defaultPort = isSecure ? 443 : 80;
2751
+ const key = randomBytes(16).toString("base64");
2752
+ const request = isSecure ? https.request : http.request;
2753
+ const protocolSet = /* @__PURE__ */ new Set();
2754
+ let perMessageDeflate;
2755
+ opts.createConnection = opts.createConnection || (isSecure ? tlsConnect : netConnect);
2756
+ opts.defaultPort = opts.defaultPort || defaultPort;
2757
+ opts.port = parsedUrl.port || defaultPort;
2758
+ opts.host = parsedUrl.hostname.startsWith("[") ? parsedUrl.hostname.slice(1, -1) : parsedUrl.hostname;
2759
+ opts.headers = {
2760
+ ...opts.headers,
2761
+ "Sec-WebSocket-Version": opts.protocolVersion,
2762
+ "Sec-WebSocket-Key": key,
2763
+ Connection: "Upgrade",
2764
+ Upgrade: "websocket"
2765
+ };
2766
+ opts.path = parsedUrl.pathname + parsedUrl.search;
2767
+ opts.timeout = opts.handshakeTimeout;
2768
+ if (opts.perMessageDeflate) {
2769
+ perMessageDeflate = new PerMessageDeflate2({
2770
+ ...opts.perMessageDeflate,
2771
+ isServer: false,
2772
+ maxPayload: opts.maxPayload
2773
+ });
2774
+ opts.headers["Sec-WebSocket-Extensions"] = format({
2775
+ [PerMessageDeflate2.extensionName]: perMessageDeflate.offer()
2776
+ });
2777
+ }
2778
+ if (protocols.length) {
2779
+ for (const protocol of protocols) {
2780
+ if (typeof protocol !== "string" || !subprotocolRegex.test(protocol) || protocolSet.has(protocol)) {
2781
+ throw new SyntaxError(
2782
+ "An invalid or duplicated subprotocol was specified"
2783
+ );
2784
+ }
2785
+ protocolSet.add(protocol);
2786
+ }
2787
+ opts.headers["Sec-WebSocket-Protocol"] = protocols.join(",");
2788
+ }
2789
+ if (opts.origin) {
2790
+ if (opts.protocolVersion < 13) {
2791
+ opts.headers["Sec-WebSocket-Origin"] = opts.origin;
2792
+ } else {
2793
+ opts.headers.Origin = opts.origin;
2794
+ }
2795
+ }
2796
+ if (parsedUrl.username || parsedUrl.password) {
2797
+ opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
2798
+ }
2799
+ if (isIpcUrl) {
2800
+ const parts = opts.path.split(":");
2801
+ opts.socketPath = parts[0];
2802
+ opts.path = parts[1];
2803
+ }
2804
+ let req;
2805
+ if (opts.followRedirects) {
2806
+ if (websocket._redirects === 0) {
2807
+ websocket._originalIpc = isIpcUrl;
2808
+ websocket._originalSecure = isSecure;
2809
+ websocket._originalHostOrSocketPath = isIpcUrl ? opts.socketPath : parsedUrl.host;
2810
+ const headers = options && options.headers;
2811
+ options = { ...options, headers: {} };
2812
+ if (headers) {
2813
+ for (const [key2, value] of Object.entries(headers)) {
2814
+ options.headers[key2.toLowerCase()] = value;
2815
+ }
2816
+ }
2817
+ } else if (websocket.listenerCount("redirect") === 0) {
2818
+ const isSameHost = isIpcUrl ? websocket._originalIpc ? opts.socketPath === websocket._originalHostOrSocketPath : false : websocket._originalIpc ? false : parsedUrl.host === websocket._originalHostOrSocketPath;
2819
+ if (!isSameHost || websocket._originalSecure && !isSecure) {
2820
+ delete opts.headers.authorization;
2821
+ delete opts.headers.cookie;
2822
+ if (!isSameHost) delete opts.headers.host;
2823
+ opts.auth = void 0;
2824
+ }
2825
+ }
2826
+ if (opts.auth && !options.headers.authorization) {
2827
+ options.headers.authorization = "Basic " + Buffer.from(opts.auth).toString("base64");
2828
+ }
2829
+ req = websocket._req = request(opts);
2830
+ if (websocket._redirects) {
2831
+ websocket.emit("redirect", websocket.url, req);
2832
+ }
2833
+ } else {
2834
+ req = websocket._req = request(opts);
2835
+ }
2836
+ if (opts.timeout) {
2837
+ req.on("timeout", () => {
2838
+ abortHandshake(websocket, req, "Opening handshake has timed out");
2839
+ });
2840
+ }
2841
+ req.on("error", (err) => {
2842
+ if (req === null || req[kAborted]) return;
2843
+ req = websocket._req = null;
2844
+ emitErrorAndClose(websocket, err);
2845
+ });
2846
+ req.on("response", (res) => {
2847
+ const location = res.headers.location;
2848
+ const statusCode = res.statusCode;
2849
+ if (location && opts.followRedirects && statusCode >= 300 && statusCode < 400) {
2850
+ if (++websocket._redirects > opts.maxRedirects) {
2851
+ abortHandshake(websocket, req, "Maximum redirects exceeded");
2852
+ return;
2853
+ }
2854
+ req.abort();
2855
+ let addr;
2856
+ try {
2857
+ addr = new URL(location, address);
2858
+ } catch (e) {
2859
+ const err = new SyntaxError(`Invalid URL: ${location}`);
2860
+ emitErrorAndClose(websocket, err);
2861
+ return;
2862
+ }
2863
+ initAsClient(websocket, addr, protocols, options);
2864
+ } else if (!websocket.emit("unexpected-response", req, res)) {
2865
+ abortHandshake(
2866
+ websocket,
2867
+ req,
2868
+ `Unexpected server response: ${res.statusCode}`
2869
+ );
2870
+ }
2871
+ });
2872
+ req.on("upgrade", (res, socket, head) => {
2873
+ websocket.emit("upgrade", res);
2874
+ if (websocket.readyState !== WebSocket2.CONNECTING) return;
2875
+ req = websocket._req = null;
2876
+ const upgrade = res.headers.upgrade;
2877
+ if (upgrade === void 0 || upgrade.toLowerCase() !== "websocket") {
2878
+ abortHandshake(websocket, socket, "Invalid Upgrade header");
2879
+ return;
2880
+ }
2881
+ const digest = createHash("sha1").update(key + GUID).digest("base64");
2882
+ if (res.headers["sec-websocket-accept"] !== digest) {
2883
+ abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
2884
+ return;
2885
+ }
2886
+ const serverProt = res.headers["sec-websocket-protocol"];
2887
+ let protError;
2888
+ if (serverProt !== void 0) {
2889
+ if (!protocolSet.size) {
2890
+ protError = "Server sent a subprotocol but none was requested";
2891
+ } else if (!protocolSet.has(serverProt)) {
2892
+ protError = "Server sent an invalid subprotocol";
2893
+ }
2894
+ } else if (protocolSet.size) {
2895
+ protError = "Server sent no subprotocol";
2896
+ }
2897
+ if (protError) {
2898
+ abortHandshake(websocket, socket, protError);
2899
+ return;
2900
+ }
2901
+ if (serverProt) websocket._protocol = serverProt;
2902
+ const secWebSocketExtensions = res.headers["sec-websocket-extensions"];
2903
+ if (secWebSocketExtensions !== void 0) {
2904
+ if (!perMessageDeflate) {
2905
+ const message = "Server sent a Sec-WebSocket-Extensions header but no extension was requested";
2906
+ abortHandshake(websocket, socket, message);
2907
+ return;
2908
+ }
2909
+ let extensions;
2910
+ try {
2911
+ extensions = parse(secWebSocketExtensions);
2912
+ } catch (err) {
2913
+ const message = "Invalid Sec-WebSocket-Extensions header";
2914
+ abortHandshake(websocket, socket, message);
2915
+ return;
2916
+ }
2917
+ const extensionNames = Object.keys(extensions);
2918
+ if (extensionNames.length !== 1 || extensionNames[0] !== PerMessageDeflate2.extensionName) {
2919
+ const message = "Server indicated an extension that was not requested";
2920
+ abortHandshake(websocket, socket, message);
2921
+ return;
2922
+ }
2923
+ try {
2924
+ perMessageDeflate.accept(extensions[PerMessageDeflate2.extensionName]);
2925
+ } catch (err) {
2926
+ const message = "Invalid Sec-WebSocket-Extensions header";
2927
+ abortHandshake(websocket, socket, message);
2928
+ return;
2929
+ }
2930
+ websocket._extensions[PerMessageDeflate2.extensionName] = perMessageDeflate;
2931
+ }
2932
+ websocket.setSocket(socket, head, {
2933
+ allowSynchronousEvents: opts.allowSynchronousEvents,
2934
+ generateMask: opts.generateMask,
2935
+ maxPayload: opts.maxPayload,
2936
+ skipUTF8Validation: opts.skipUTF8Validation
2937
+ });
2938
+ });
2939
+ if (opts.finishRequest) {
2940
+ opts.finishRequest(req, websocket);
2941
+ } else {
2942
+ req.end();
2943
+ }
2944
+ }
2945
+ function emitErrorAndClose(websocket, err) {
2946
+ websocket._readyState = WebSocket2.CLOSING;
2947
+ websocket._errorEmitted = true;
2948
+ websocket.emit("error", err);
2949
+ websocket.emitClose();
2950
+ }
2951
+ function netConnect(options) {
2952
+ options.path = options.socketPath;
2953
+ return net.connect(options);
2954
+ }
2955
+ function tlsConnect(options) {
2956
+ options.path = void 0;
2957
+ if (!options.servername && options.servername !== "") {
2958
+ options.servername = net.isIP(options.host) ? "" : options.host;
2959
+ }
2960
+ return tls.connect(options);
2961
+ }
2962
+ function abortHandshake(websocket, stream, message) {
2963
+ websocket._readyState = WebSocket2.CLOSING;
2964
+ const err = new Error(message);
2965
+ Error.captureStackTrace(err, abortHandshake);
2966
+ if (stream.setHeader) {
2967
+ stream[kAborted] = true;
2968
+ stream.abort();
2969
+ if (stream.socket && !stream.socket.destroyed) {
2970
+ stream.socket.destroy();
2971
+ }
2972
+ process.nextTick(emitErrorAndClose, websocket, err);
2973
+ } else {
2974
+ stream.destroy(err);
2975
+ stream.once("error", websocket.emit.bind(websocket, "error"));
2976
+ stream.once("close", websocket.emitClose.bind(websocket));
2977
+ }
2978
+ }
2979
+ function sendAfterClose(websocket, data, cb) {
2980
+ if (data) {
2981
+ const length = isBlob(data) ? data.size : toBuffer(data).length;
2982
+ if (websocket._socket) websocket._sender._bufferedBytes += length;
2983
+ else websocket._bufferedAmount += length;
2984
+ }
2985
+ if (cb) {
2986
+ const err = new Error(
2987
+ `WebSocket is not open: readyState ${websocket.readyState} (${readyStates[websocket.readyState]})`
2988
+ );
2989
+ process.nextTick(cb, err);
2990
+ }
2991
+ }
2992
+ function receiverOnConclude(code, reason) {
2993
+ const websocket = this[kWebSocket];
2994
+ websocket._closeFrameReceived = true;
2995
+ websocket._closeMessage = reason;
2996
+ websocket._closeCode = code;
2997
+ if (websocket._socket[kWebSocket] === void 0) return;
2998
+ websocket._socket.removeListener("data", socketOnData);
2999
+ process.nextTick(resume, websocket._socket);
3000
+ if (code === 1005) websocket.close();
3001
+ else websocket.close(code, reason);
3002
+ }
3003
+ function receiverOnDrain() {
3004
+ const websocket = this[kWebSocket];
3005
+ if (!websocket.isPaused) websocket._socket.resume();
3006
+ }
3007
+ function receiverOnError(err) {
3008
+ const websocket = this[kWebSocket];
3009
+ if (websocket._socket[kWebSocket] !== void 0) {
3010
+ websocket._socket.removeListener("data", socketOnData);
3011
+ process.nextTick(resume, websocket._socket);
3012
+ websocket.close(err[kStatusCode]);
3013
+ }
3014
+ if (!websocket._errorEmitted) {
3015
+ websocket._errorEmitted = true;
3016
+ websocket.emit("error", err);
3017
+ }
3018
+ }
3019
+ function receiverOnFinish() {
3020
+ this[kWebSocket].emitClose();
3021
+ }
3022
+ function receiverOnMessage(data, isBinary) {
3023
+ this[kWebSocket].emit("message", data, isBinary);
3024
+ }
3025
+ function receiverOnPing(data) {
3026
+ const websocket = this[kWebSocket];
3027
+ if (websocket._autoPong) websocket.pong(data, !this._isServer, NOOP);
3028
+ websocket.emit("ping", data);
3029
+ }
3030
+ function receiverOnPong(data) {
3031
+ this[kWebSocket].emit("pong", data);
3032
+ }
3033
+ function resume(stream) {
3034
+ stream.resume();
3035
+ }
3036
+ function senderOnError(err) {
3037
+ const websocket = this[kWebSocket];
3038
+ if (websocket.readyState === WebSocket2.CLOSED) return;
3039
+ if (websocket.readyState === WebSocket2.OPEN) {
3040
+ websocket._readyState = WebSocket2.CLOSING;
3041
+ setCloseTimer(websocket);
3042
+ }
3043
+ this._socket.end();
3044
+ if (!websocket._errorEmitted) {
3045
+ websocket._errorEmitted = true;
3046
+ websocket.emit("error", err);
3047
+ }
3048
+ }
3049
+ function setCloseTimer(websocket) {
3050
+ websocket._closeTimer = setTimeout(
3051
+ websocket._socket.destroy.bind(websocket._socket),
3052
+ websocket._closeTimeout
3053
+ );
3054
+ }
3055
+ function socketOnClose() {
3056
+ const websocket = this[kWebSocket];
3057
+ this.removeListener("close", socketOnClose);
3058
+ this.removeListener("data", socketOnData);
3059
+ this.removeListener("end", socketOnEnd);
3060
+ websocket._readyState = WebSocket2.CLOSING;
3061
+ if (!this._readableState.endEmitted && !websocket._closeFrameReceived && !websocket._receiver._writableState.errorEmitted && this._readableState.length !== 0) {
3062
+ const chunk = this.read(this._readableState.length);
3063
+ websocket._receiver.write(chunk);
3064
+ }
3065
+ websocket._receiver.end();
3066
+ this[kWebSocket] = void 0;
3067
+ clearTimeout(websocket._closeTimer);
3068
+ if (websocket._receiver._writableState.finished || websocket._receiver._writableState.errorEmitted) {
3069
+ websocket.emitClose();
3070
+ } else {
3071
+ websocket._receiver.on("error", receiverOnFinish);
3072
+ websocket._receiver.on("finish", receiverOnFinish);
3073
+ }
3074
+ }
3075
+ function socketOnData(chunk) {
3076
+ if (!this[kWebSocket]._receiver.write(chunk)) {
3077
+ this.pause();
3078
+ }
3079
+ }
3080
+ function socketOnEnd() {
3081
+ const websocket = this[kWebSocket];
3082
+ websocket._readyState = WebSocket2.CLOSING;
3083
+ websocket._receiver.end();
3084
+ this.end();
3085
+ }
3086
+ function socketOnError() {
3087
+ const websocket = this[kWebSocket];
3088
+ this.removeListener("error", socketOnError);
3089
+ this.on("error", NOOP);
3090
+ if (websocket) {
3091
+ websocket._readyState = WebSocket2.CLOSING;
3092
+ this.destroy();
3093
+ }
3094
+ }
3095
+ }
3096
+ });
3097
+
3098
+ // ../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/stream.js
3099
+ var require_stream = __commonJS({
3100
+ "../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/stream.js"(exports, module) {
3101
+ "use strict";
3102
+ init_esm_shims();
3103
+ var WebSocket2 = require_websocket();
3104
+ var { Duplex } = __require("stream");
3105
+ function emitClose(stream) {
3106
+ stream.emit("close");
3107
+ }
3108
+ function duplexOnEnd() {
3109
+ if (!this.destroyed && this._writableState.finished) {
3110
+ this.destroy();
3111
+ }
3112
+ }
3113
+ function duplexOnError(err) {
3114
+ this.removeListener("error", duplexOnError);
3115
+ this.destroy();
3116
+ if (this.listenerCount("error") === 0) {
3117
+ this.emit("error", err);
3118
+ }
3119
+ }
3120
+ function createWebSocketStream2(ws, options) {
3121
+ let terminateOnDestroy = true;
3122
+ const duplex = new Duplex({
3123
+ ...options,
3124
+ autoDestroy: false,
3125
+ emitClose: false,
3126
+ objectMode: false,
3127
+ writableObjectMode: false
3128
+ });
3129
+ ws.on("message", function message(msg, isBinary) {
3130
+ const data = !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
3131
+ if (!duplex.push(data)) ws.pause();
3132
+ });
3133
+ ws.once("error", function error(err) {
3134
+ if (duplex.destroyed) return;
3135
+ terminateOnDestroy = false;
3136
+ duplex.destroy(err);
3137
+ });
3138
+ ws.once("close", function close() {
3139
+ if (duplex.destroyed) return;
3140
+ duplex.push(null);
3141
+ });
3142
+ duplex._destroy = function(err, callback) {
3143
+ if (ws.readyState === ws.CLOSED) {
3144
+ callback(err);
3145
+ process.nextTick(emitClose, duplex);
3146
+ return;
3147
+ }
3148
+ let called = false;
3149
+ ws.once("error", function error(err2) {
3150
+ called = true;
3151
+ callback(err2);
3152
+ });
3153
+ ws.once("close", function close() {
3154
+ if (!called) callback(err);
3155
+ process.nextTick(emitClose, duplex);
3156
+ });
3157
+ if (terminateOnDestroy) ws.terminate();
3158
+ };
3159
+ duplex._final = function(callback) {
3160
+ if (ws.readyState === ws.CONNECTING) {
3161
+ ws.once("open", function open() {
3162
+ duplex._final(callback);
3163
+ });
3164
+ return;
3165
+ }
3166
+ if (ws._socket === null) return;
3167
+ if (ws._socket._writableState.finished) {
3168
+ callback();
3169
+ if (duplex._readableState.endEmitted) duplex.destroy();
3170
+ } else {
3171
+ ws._socket.once("finish", function finish() {
3172
+ callback();
3173
+ });
3174
+ ws.close();
3175
+ }
3176
+ };
3177
+ duplex._read = function() {
3178
+ if (ws.isPaused) ws.resume();
3179
+ };
3180
+ duplex._write = function(chunk, encoding, callback) {
3181
+ if (ws.readyState === ws.CONNECTING) {
3182
+ ws.once("open", function open() {
3183
+ duplex._write(chunk, encoding, callback);
3184
+ });
3185
+ return;
3186
+ }
3187
+ ws.send(chunk, callback);
3188
+ };
3189
+ duplex.on("end", duplexOnEnd);
3190
+ duplex.on("error", duplexOnError);
3191
+ return duplex;
3192
+ }
3193
+ module.exports = createWebSocketStream2;
3194
+ }
3195
+ });
3196
+
3197
+ // ../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/subprotocol.js
3198
+ var require_subprotocol = __commonJS({
3199
+ "../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/subprotocol.js"(exports, module) {
3200
+ "use strict";
3201
+ init_esm_shims();
3202
+ var { tokenChars } = require_validation();
3203
+ function parse(header) {
3204
+ const protocols = /* @__PURE__ */ new Set();
3205
+ let start = -1;
3206
+ let end = -1;
3207
+ let i = 0;
3208
+ for (i; i < header.length; i++) {
3209
+ const code = header.charCodeAt(i);
3210
+ if (end === -1 && tokenChars[code] === 1) {
3211
+ if (start === -1) start = i;
3212
+ } else if (i !== 0 && (code === 32 || code === 9)) {
3213
+ if (end === -1 && start !== -1) end = i;
3214
+ } else if (code === 44) {
3215
+ if (start === -1) {
3216
+ throw new SyntaxError(`Unexpected character at index ${i}`);
3217
+ }
3218
+ if (end === -1) end = i;
3219
+ const protocol2 = header.slice(start, end);
3220
+ if (protocols.has(protocol2)) {
3221
+ throw new SyntaxError(`The "${protocol2}" subprotocol is duplicated`);
3222
+ }
3223
+ protocols.add(protocol2);
3224
+ start = end = -1;
3225
+ } else {
3226
+ throw new SyntaxError(`Unexpected character at index ${i}`);
3227
+ }
3228
+ }
3229
+ if (start === -1 || end !== -1) {
3230
+ throw new SyntaxError("Unexpected end of input");
3231
+ }
3232
+ const protocol = header.slice(start, i);
3233
+ if (protocols.has(protocol)) {
3234
+ throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
3235
+ }
3236
+ protocols.add(protocol);
3237
+ return protocols;
3238
+ }
3239
+ module.exports = { parse };
3240
+ }
3241
+ });
3242
+
3243
+ // ../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/websocket-server.js
3244
+ var require_websocket_server = __commonJS({
3245
+ "../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/websocket-server.js"(exports, module) {
3246
+ "use strict";
3247
+ init_esm_shims();
3248
+ var EventEmitter = __require("events");
3249
+ var http = __require("http");
3250
+ var { Duplex } = __require("stream");
3251
+ var { createHash } = __require("crypto");
3252
+ var extension2 = require_extension();
3253
+ var PerMessageDeflate2 = require_permessage_deflate();
3254
+ var subprotocol2 = require_subprotocol();
3255
+ var WebSocket2 = require_websocket();
3256
+ var { CLOSE_TIMEOUT, GUID, kWebSocket } = require_constants();
3257
+ var keyRegex = /^[+/0-9A-Za-z]{22}==$/;
3258
+ var RUNNING = 0;
3259
+ var CLOSING = 1;
3260
+ var CLOSED = 2;
3261
+ var WebSocketServer2 = class extends EventEmitter {
3262
+ /**
3263
+ * Create a `WebSocketServer` instance.
3264
+ *
3265
+ * @param {Object} options Configuration options
3266
+ * @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether
3267
+ * any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
3268
+ * multiple times in the same tick
3269
+ * @param {Boolean} [options.autoPong=true] Specifies whether or not to
3270
+ * automatically send a pong in response to a ping
3271
+ * @param {Number} [options.backlog=511] The maximum length of the queue of
3272
+ * pending connections
3273
+ * @param {Boolean} [options.clientTracking=true] Specifies whether or not to
3274
+ * track clients
3275
+ * @param {Number} [options.closeTimeout=30000] Duration in milliseconds to
3276
+ * wait for the closing handshake to finish after `websocket.close()` is
3277
+ * called
3278
+ * @param {Function} [options.handleProtocols] A hook to handle protocols
3279
+ * @param {String} [options.host] The hostname where to bind the server
3280
+ * @param {Number} [options.maxPayload=104857600] The maximum allowed message
3281
+ * size
3282
+ * @param {Boolean} [options.noServer=false] Enable no server mode
3283
+ * @param {String} [options.path] Accept only connections matching this path
3284
+ * @param {(Boolean|Object)} [options.perMessageDeflate=false] Enable/disable
3285
+ * permessage-deflate
3286
+ * @param {Number} [options.port] The port where to bind the server
3287
+ * @param {(http.Server|https.Server)} [options.server] A pre-created HTTP/S
3288
+ * server to use
3289
+ * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
3290
+ * not to skip UTF-8 validation for text and close messages
3291
+ * @param {Function} [options.verifyClient] A hook to reject connections
3292
+ * @param {Function} [options.WebSocket=WebSocket] Specifies the `WebSocket`
3293
+ * class to use. It must be the `WebSocket` class or class that extends it
3294
+ * @param {Function} [callback] A listener for the `listening` event
3295
+ */
3296
+ constructor(options, callback) {
3297
+ super();
3298
+ options = {
3299
+ allowSynchronousEvents: true,
3300
+ autoPong: true,
3301
+ maxPayload: 100 * 1024 * 1024,
3302
+ skipUTF8Validation: false,
3303
+ perMessageDeflate: false,
3304
+ handleProtocols: null,
3305
+ clientTracking: true,
3306
+ closeTimeout: CLOSE_TIMEOUT,
3307
+ verifyClient: null,
3308
+ noServer: false,
3309
+ backlog: null,
3310
+ // use default (511 as implemented in net.js)
3311
+ server: null,
3312
+ host: null,
3313
+ path: null,
3314
+ port: null,
3315
+ WebSocket: WebSocket2,
3316
+ ...options
3317
+ };
3318
+ if (options.port == null && !options.server && !options.noServer || options.port != null && (options.server || options.noServer) || options.server && options.noServer) {
3319
+ throw new TypeError(
3320
+ 'One and only one of the "port", "server", or "noServer" options must be specified'
3321
+ );
3322
+ }
3323
+ if (options.port != null) {
3324
+ this._server = http.createServer((req, res) => {
3325
+ const body = http.STATUS_CODES[426];
3326
+ res.writeHead(426, {
3327
+ "Content-Length": body.length,
3328
+ "Content-Type": "text/plain"
3329
+ });
3330
+ res.end(body);
3331
+ });
3332
+ this._server.listen(
3333
+ options.port,
3334
+ options.host,
3335
+ options.backlog,
3336
+ callback
3337
+ );
3338
+ } else if (options.server) {
3339
+ this._server = options.server;
3340
+ }
3341
+ if (this._server) {
3342
+ const emitConnection = this.emit.bind(this, "connection");
3343
+ this._removeListeners = addListeners(this._server, {
3344
+ listening: this.emit.bind(this, "listening"),
3345
+ error: this.emit.bind(this, "error"),
3346
+ upgrade: (req, socket, head) => {
3347
+ this.handleUpgrade(req, socket, head, emitConnection);
3348
+ }
3349
+ });
3350
+ }
3351
+ if (options.perMessageDeflate === true) options.perMessageDeflate = {};
3352
+ if (options.clientTracking) {
3353
+ this.clients = /* @__PURE__ */ new Set();
3354
+ this._shouldEmitClose = false;
3355
+ }
3356
+ this.options = options;
3357
+ this._state = RUNNING;
3358
+ }
3359
+ /**
3360
+ * Returns the bound address, the address family name, and port of the server
3361
+ * as reported by the operating system if listening on an IP socket.
3362
+ * If the server is listening on a pipe or UNIX domain socket, the name is
3363
+ * returned as a string.
3364
+ *
3365
+ * @return {(Object|String|null)} The address of the server
3366
+ * @public
3367
+ */
3368
+ address() {
3369
+ if (this.options.noServer) {
3370
+ throw new Error('The server is operating in "noServer" mode');
3371
+ }
3372
+ if (!this._server) return null;
3373
+ return this._server.address();
3374
+ }
3375
+ /**
3376
+ * Stop the server from accepting new connections and emit the `'close'` event
3377
+ * when all existing connections are closed.
3378
+ *
3379
+ * @param {Function} [cb] A one-time listener for the `'close'` event
3380
+ * @public
3381
+ */
3382
+ close(cb) {
3383
+ if (this._state === CLOSED) {
3384
+ if (cb) {
3385
+ this.once("close", () => {
3386
+ cb(new Error("The server is not running"));
3387
+ });
3388
+ }
3389
+ process.nextTick(emitClose, this);
3390
+ return;
3391
+ }
3392
+ if (cb) this.once("close", cb);
3393
+ if (this._state === CLOSING) return;
3394
+ this._state = CLOSING;
3395
+ if (this.options.noServer || this.options.server) {
3396
+ if (this._server) {
3397
+ this._removeListeners();
3398
+ this._removeListeners = this._server = null;
3399
+ }
3400
+ if (this.clients) {
3401
+ if (!this.clients.size) {
3402
+ process.nextTick(emitClose, this);
3403
+ } else {
3404
+ this._shouldEmitClose = true;
3405
+ }
3406
+ } else {
3407
+ process.nextTick(emitClose, this);
3408
+ }
3409
+ } else {
3410
+ const server = this._server;
3411
+ this._removeListeners();
3412
+ this._removeListeners = this._server = null;
3413
+ server.close(() => {
3414
+ emitClose(this);
3415
+ });
3416
+ }
3417
+ }
3418
+ /**
3419
+ * See if a given request should be handled by this server instance.
3420
+ *
3421
+ * @param {http.IncomingMessage} req Request object to inspect
3422
+ * @return {Boolean} `true` if the request is valid, else `false`
3423
+ * @public
3424
+ */
3425
+ shouldHandle(req) {
3426
+ if (this.options.path) {
3427
+ const index = req.url.indexOf("?");
3428
+ const pathname = index !== -1 ? req.url.slice(0, index) : req.url;
3429
+ if (pathname !== this.options.path) return false;
3430
+ }
3431
+ return true;
3432
+ }
3433
+ /**
3434
+ * Handle a HTTP Upgrade request.
3435
+ *
3436
+ * @param {http.IncomingMessage} req The request object
3437
+ * @param {Duplex} socket The network socket between the server and client
3438
+ * @param {Buffer} head The first packet of the upgraded stream
3439
+ * @param {Function} cb Callback
3440
+ * @public
3441
+ */
3442
+ handleUpgrade(req, socket, head, cb) {
3443
+ socket.on("error", socketOnError);
3444
+ const key = req.headers["sec-websocket-key"];
3445
+ const upgrade = req.headers.upgrade;
3446
+ const version = +req.headers["sec-websocket-version"];
3447
+ if (req.method !== "GET") {
3448
+ const message = "Invalid HTTP method";
3449
+ abortHandshakeOrEmitwsClientError(this, req, socket, 405, message);
3450
+ return;
3451
+ }
3452
+ if (upgrade === void 0 || upgrade.toLowerCase() !== "websocket") {
3453
+ const message = "Invalid Upgrade header";
3454
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3455
+ return;
3456
+ }
3457
+ if (key === void 0 || !keyRegex.test(key)) {
3458
+ const message = "Missing or invalid Sec-WebSocket-Key header";
3459
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3460
+ return;
3461
+ }
3462
+ if (version !== 13 && version !== 8) {
3463
+ const message = "Missing or invalid Sec-WebSocket-Version header";
3464
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message, {
3465
+ "Sec-WebSocket-Version": "13, 8"
3466
+ });
3467
+ return;
3468
+ }
3469
+ if (!this.shouldHandle(req)) {
3470
+ abortHandshake(socket, 400);
3471
+ return;
3472
+ }
3473
+ const secWebSocketProtocol = req.headers["sec-websocket-protocol"];
3474
+ let protocols = /* @__PURE__ */ new Set();
3475
+ if (secWebSocketProtocol !== void 0) {
3476
+ try {
3477
+ protocols = subprotocol2.parse(secWebSocketProtocol);
3478
+ } catch (err) {
3479
+ const message = "Invalid Sec-WebSocket-Protocol header";
3480
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3481
+ return;
3482
+ }
3483
+ }
3484
+ const secWebSocketExtensions = req.headers["sec-websocket-extensions"];
3485
+ const extensions = {};
3486
+ if (this.options.perMessageDeflate && secWebSocketExtensions !== void 0) {
3487
+ const perMessageDeflate = new PerMessageDeflate2({
3488
+ ...this.options.perMessageDeflate,
3489
+ isServer: true,
3490
+ maxPayload: this.options.maxPayload
3491
+ });
3492
+ try {
3493
+ const offers = extension2.parse(secWebSocketExtensions);
3494
+ if (offers[PerMessageDeflate2.extensionName]) {
3495
+ perMessageDeflate.accept(offers[PerMessageDeflate2.extensionName]);
3496
+ extensions[PerMessageDeflate2.extensionName] = perMessageDeflate;
3497
+ }
3498
+ } catch (err) {
3499
+ const message = "Invalid or unacceptable Sec-WebSocket-Extensions header";
3500
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3501
+ return;
3502
+ }
3503
+ }
3504
+ if (this.options.verifyClient) {
3505
+ const info = {
3506
+ origin: req.headers[`${version === 8 ? "sec-websocket-origin" : "origin"}`],
3507
+ secure: !!(req.socket.authorized || req.socket.encrypted),
3508
+ req
3509
+ };
3510
+ if (this.options.verifyClient.length === 2) {
3511
+ this.options.verifyClient(info, (verified, code, message, headers) => {
3512
+ if (!verified) {
3513
+ return abortHandshake(socket, code || 401, message, headers);
3514
+ }
3515
+ this.completeUpgrade(
3516
+ extensions,
3517
+ key,
3518
+ protocols,
3519
+ req,
3520
+ socket,
3521
+ head,
3522
+ cb
3523
+ );
3524
+ });
3525
+ return;
3526
+ }
3527
+ if (!this.options.verifyClient(info)) return abortHandshake(socket, 401);
3528
+ }
3529
+ this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
3530
+ }
3531
+ /**
3532
+ * Upgrade the connection to WebSocket.
3533
+ *
3534
+ * @param {Object} extensions The accepted extensions
3535
+ * @param {String} key The value of the `Sec-WebSocket-Key` header
3536
+ * @param {Set} protocols The subprotocols
3537
+ * @param {http.IncomingMessage} req The request object
3538
+ * @param {Duplex} socket The network socket between the server and client
3539
+ * @param {Buffer} head The first packet of the upgraded stream
3540
+ * @param {Function} cb Callback
3541
+ * @throws {Error} If called more than once with the same socket
3542
+ * @private
3543
+ */
3544
+ completeUpgrade(extensions, key, protocols, req, socket, head, cb) {
3545
+ if (!socket.readable || !socket.writable) return socket.destroy();
3546
+ if (socket[kWebSocket]) {
3547
+ throw new Error(
3548
+ "server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration"
3549
+ );
3550
+ }
3551
+ if (this._state > RUNNING) return abortHandshake(socket, 503);
3552
+ const digest = createHash("sha1").update(key + GUID).digest("base64");
3553
+ const headers = [
3554
+ "HTTP/1.1 101 Switching Protocols",
3555
+ "Upgrade: websocket",
3556
+ "Connection: Upgrade",
3557
+ `Sec-WebSocket-Accept: ${digest}`
3558
+ ];
3559
+ const ws = new this.options.WebSocket(null, void 0, this.options);
3560
+ if (protocols.size) {
3561
+ const protocol = this.options.handleProtocols ? this.options.handleProtocols(protocols, req) : protocols.values().next().value;
3562
+ if (protocol) {
3563
+ headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
3564
+ ws._protocol = protocol;
3565
+ }
3566
+ }
3567
+ if (extensions[PerMessageDeflate2.extensionName]) {
3568
+ const params = extensions[PerMessageDeflate2.extensionName].params;
3569
+ const value = extension2.format({
3570
+ [PerMessageDeflate2.extensionName]: [params]
3571
+ });
3572
+ headers.push(`Sec-WebSocket-Extensions: ${value}`);
3573
+ ws._extensions = extensions;
3574
+ }
3575
+ this.emit("headers", headers, req);
3576
+ socket.write(headers.concat("\r\n").join("\r\n"));
3577
+ socket.removeListener("error", socketOnError);
3578
+ ws.setSocket(socket, head, {
3579
+ allowSynchronousEvents: this.options.allowSynchronousEvents,
3580
+ maxPayload: this.options.maxPayload,
3581
+ skipUTF8Validation: this.options.skipUTF8Validation
3582
+ });
3583
+ if (this.clients) {
3584
+ this.clients.add(ws);
3585
+ ws.on("close", () => {
3586
+ this.clients.delete(ws);
3587
+ if (this._shouldEmitClose && !this.clients.size) {
3588
+ process.nextTick(emitClose, this);
3589
+ }
3590
+ });
3591
+ }
3592
+ cb(ws, req);
3593
+ }
3594
+ };
3595
+ module.exports = WebSocketServer2;
3596
+ function addListeners(server, map) {
3597
+ for (const event of Object.keys(map)) server.on(event, map[event]);
3598
+ return function removeListeners() {
3599
+ for (const event of Object.keys(map)) {
3600
+ server.removeListener(event, map[event]);
3601
+ }
3602
+ };
3603
+ }
3604
+ function emitClose(server) {
3605
+ server._state = CLOSED;
3606
+ server.emit("close");
3607
+ }
3608
+ function socketOnError() {
3609
+ this.destroy();
3610
+ }
3611
+ function abortHandshake(socket, code, message, headers) {
3612
+ message = message || http.STATUS_CODES[code];
3613
+ headers = {
3614
+ Connection: "close",
3615
+ "Content-Type": "text/html",
3616
+ "Content-Length": Buffer.byteLength(message),
3617
+ ...headers
3618
+ };
3619
+ socket.once("finish", socket.destroy);
3620
+ socket.end(
3621
+ `HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r
3622
+ ` + Object.keys(headers).map((h) => `${h}: ${headers[h]}`).join("\r\n") + "\r\n\r\n" + message
3623
+ );
3624
+ }
3625
+ function abortHandshakeOrEmitwsClientError(server, req, socket, code, message, headers) {
3626
+ if (server.listenerCount("wsClientError")) {
3627
+ const err = new Error(message);
3628
+ Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError);
3629
+ server.emit("wsClientError", err, socket, req);
3630
+ } else {
3631
+ abortHandshake(socket, code, message, headers);
3632
+ }
3633
+ }
3634
+ }
3635
+ });
3636
+
3637
+ // ../../node_modules/.pnpm/ink@7.0.2_@types+react@19.2.14_react@19.2.5/node_modules/ink/build/devtools.js
3638
+ init_esm_shims();
3639
+
3640
+ // ../../node_modules/.pnpm/ink@7.0.2_@types+react@19.2.14_react@19.2.5/node_modules/ink/build/devtools-window-polyfill.js
3641
+ init_esm_shims();
3642
+
3643
+ // ../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/wrapper.mjs
3644
+ init_esm_shims();
3645
+ var import_stream = __toESM(require_stream(), 1);
3646
+ var import_extension = __toESM(require_extension(), 1);
3647
+ var import_permessage_deflate = __toESM(require_permessage_deflate(), 1);
3648
+ var import_receiver = __toESM(require_receiver(), 1);
3649
+ var import_sender = __toESM(require_sender(), 1);
3650
+ var import_subprotocol = __toESM(require_subprotocol(), 1);
3651
+ var import_websocket = __toESM(require_websocket(), 1);
3652
+ var import_websocket_server = __toESM(require_websocket_server(), 1);
3653
+ var wrapper_default = import_websocket.default;
3654
+
3655
+ // ../../node_modules/.pnpm/ink@7.0.2_@types+react@19.2.14_react@19.2.5/node_modules/ink/build/devtools-window-polyfill.js
3656
+ var customGlobal = globalThis;
3657
+ customGlobal.WebSocket ||= wrapper_default;
3658
+ customGlobal.window ||= globalThis;
3659
+ customGlobal.self ||= globalThis;
3660
+ customGlobal.window.__REACT_DEVTOOLS_COMPONENT_FILTERS__ = [
3661
+ {
3662
+ // ComponentFilterElementType
3663
+ type: 1,
3664
+ // ElementTypeHostComponent
3665
+ value: 7,
3666
+ isEnabled: true
3667
+ },
3668
+ {
3669
+ // ComponentFilterDisplayName
3670
+ type: 2,
3671
+ value: "InternalApp",
3672
+ isEnabled: true,
3673
+ isValid: true
3674
+ },
3675
+ {
3676
+ // ComponentFilterDisplayName
3677
+ type: 2,
3678
+ value: "InternalAppContext",
3679
+ isEnabled: true,
3680
+ isValid: true
3681
+ },
3682
+ {
3683
+ // ComponentFilterDisplayName
3684
+ type: 2,
3685
+ value: "InternalStdoutContext",
3686
+ isEnabled: true,
3687
+ isValid: true
3688
+ },
3689
+ {
3690
+ // ComponentFilterDisplayName
3691
+ type: 2,
3692
+ value: "InternalStderrContext",
3693
+ isEnabled: true,
3694
+ isValid: true
3695
+ },
3696
+ {
3697
+ // ComponentFilterDisplayName
3698
+ type: 2,
3699
+ value: "InternalStdinContext",
3700
+ isEnabled: true,
3701
+ isValid: true
3702
+ },
3703
+ {
3704
+ // ComponentFilterDisplayName
3705
+ type: 2,
3706
+ value: "InternalFocusContext",
3707
+ isEnabled: true,
3708
+ isValid: true
3709
+ }
3710
+ ];
3711
+
3712
+ // ../../node_modules/.pnpm/ink@7.0.2_@types+react@19.2.14_react@19.2.5/node_modules/ink/build/devtools.js
3713
+ import devtools from "react-devtools-core";
3714
+ var isDevToolsReachable = async () => new Promise((resolve) => {
3715
+ const socket = new wrapper_default("ws://localhost:8097");
3716
+ const timeout = setTimeout(() => {
3717
+ socket.terminate();
3718
+ resolve(false);
3719
+ }, 2e3);
3720
+ timeout.unref();
3721
+ socket.on("open", () => {
3722
+ clearTimeout(timeout);
3723
+ socket.terminate();
3724
+ resolve(true);
3725
+ });
3726
+ socket.on("error", () => {
3727
+ clearTimeout(timeout);
3728
+ socket.terminate();
3729
+ resolve(false);
3730
+ });
3731
+ });
3732
+ if (await isDevToolsReachable()) {
3733
+ devtools.initialize();
3734
+ devtools.connectToDevTools();
3735
+ } else {
3736
+ console.warn("DEV is set to true, but the React DevTools server is not running. Start it with:\n\n$ npx react-devtools\n");
3737
+ }
3738
+ //# sourceMappingURL=devtools-VBUDNGEI.js.map