@google/gemini-cli 0.69.0 → 0.70.0

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