@kevisual/cnb 0.0.13 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/routes.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { createRequire } from "node:module";
1
2
  var __create = Object.create;
2
3
  var __getProtoOf = Object.getPrototypeOf;
3
4
  var __defProp = Object.defineProperty;
@@ -24,6 +25,7 @@ var __export = (target, all) => {
24
25
  set: (newValue) => all[name] = () => newValue
25
26
  });
26
27
  };
28
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
27
29
 
28
30
  // node_modules/.pnpm/dayjs@1.11.19/node_modules/dayjs/dayjs.min.js
29
31
  var require_dayjs_min = __commonJS((exports, module) => {
@@ -65,258 +67,3078 @@ var require_dayjs_min = __commonJS((exports, module) => {
65
67
  if (!i2 && u2.length > 1)
66
68
  return t2(u2[0]);
67
69
  } else {
68
- var a2 = e2.name;
69
- D[a2] = e2, i2 = a2;
70
+ var a2 = e2.name;
71
+ D[a2] = e2, i2 = a2;
72
+ }
73
+ return !r2 && i2 && (g = i2), i2 || !r2 && g;
74
+ }, O = function(t2, e2) {
75
+ if (S(t2))
76
+ return t2.clone();
77
+ var n2 = typeof e2 == "object" ? e2 : {};
78
+ return n2.date = t2, n2.args = arguments, new _(n2);
79
+ }, b = v;
80
+ b.l = w, b.i = S, b.w = function(t2, e2) {
81
+ return O(t2, { locale: e2.$L, utc: e2.$u, x: e2.$x, $offset: e2.$offset });
82
+ };
83
+ var _ = function() {
84
+ function M2(t2) {
85
+ this.$L = w(t2.locale, null, true), this.parse(t2), this.$x = this.$x || t2.x || {}, this[p] = true;
86
+ }
87
+ var m2 = M2.prototype;
88
+ return m2.parse = function(t2) {
89
+ this.$d = function(t3) {
90
+ var { date: e2, utc: n2 } = t3;
91
+ if (e2 === null)
92
+ return new Date(NaN);
93
+ if (b.u(e2))
94
+ return new Date;
95
+ if (e2 instanceof Date)
96
+ return new Date(e2);
97
+ if (typeof e2 == "string" && !/Z$/i.test(e2)) {
98
+ var r2 = e2.match($);
99
+ if (r2) {
100
+ var i2 = r2[2] - 1 || 0, s2 = (r2[7] || "0").substring(0, 3);
101
+ return n2 ? new Date(Date.UTC(r2[1], i2, r2[3] || 1, r2[4] || 0, r2[5] || 0, r2[6] || 0, s2)) : new Date(r2[1], i2, r2[3] || 1, r2[4] || 0, r2[5] || 0, r2[6] || 0, s2);
102
+ }
103
+ }
104
+ return new Date(e2);
105
+ }(t2), this.init();
106
+ }, m2.init = function() {
107
+ var t2 = this.$d;
108
+ this.$y = t2.getFullYear(), this.$M = t2.getMonth(), this.$D = t2.getDate(), this.$W = t2.getDay(), this.$H = t2.getHours(), this.$m = t2.getMinutes(), this.$s = t2.getSeconds(), this.$ms = t2.getMilliseconds();
109
+ }, m2.$utils = function() {
110
+ return b;
111
+ }, m2.isValid = function() {
112
+ return !(this.$d.toString() === l);
113
+ }, m2.isSame = function(t2, e2) {
114
+ var n2 = O(t2);
115
+ return this.startOf(e2) <= n2 && n2 <= this.endOf(e2);
116
+ }, m2.isAfter = function(t2, e2) {
117
+ return O(t2) < this.startOf(e2);
118
+ }, m2.isBefore = function(t2, e2) {
119
+ return this.endOf(e2) < O(t2);
120
+ }, m2.$g = function(t2, e2, n2) {
121
+ return b.u(t2) ? this[e2] : this.set(n2, t2);
122
+ }, m2.unix = function() {
123
+ return Math.floor(this.valueOf() / 1000);
124
+ }, m2.valueOf = function() {
125
+ return this.$d.getTime();
126
+ }, m2.startOf = function(t2, e2) {
127
+ var n2 = this, r2 = !!b.u(e2) || e2, f2 = b.p(t2), l2 = function(t3, e3) {
128
+ var i2 = b.w(n2.$u ? Date.UTC(n2.$y, e3, t3) : new Date(n2.$y, e3, t3), n2);
129
+ return r2 ? i2 : i2.endOf(a);
130
+ }, $2 = function(t3, e3) {
131
+ return b.w(n2.toDate()[t3].apply(n2.toDate("s"), (r2 ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(e3)), n2);
132
+ }, y2 = this.$W, M3 = this.$M, m3 = this.$D, v2 = "set" + (this.$u ? "UTC" : "");
133
+ switch (f2) {
134
+ case h:
135
+ return r2 ? l2(1, 0) : l2(31, 11);
136
+ case c:
137
+ return r2 ? l2(1, M3) : l2(0, M3 + 1);
138
+ case o:
139
+ var g2 = this.$locale().weekStart || 0, D2 = (y2 < g2 ? y2 + 7 : y2) - g2;
140
+ return l2(r2 ? m3 - D2 : m3 + (6 - D2), M3);
141
+ case a:
142
+ case d:
143
+ return $2(v2 + "Hours", 0);
144
+ case u:
145
+ return $2(v2 + "Minutes", 1);
146
+ case s:
147
+ return $2(v2 + "Seconds", 2);
148
+ case i:
149
+ return $2(v2 + "Milliseconds", 3);
150
+ default:
151
+ return this.clone();
152
+ }
153
+ }, m2.endOf = function(t2) {
154
+ return this.startOf(t2, false);
155
+ }, m2.$set = function(t2, e2) {
156
+ var n2, o2 = b.p(t2), f2 = "set" + (this.$u ? "UTC" : ""), l2 = (n2 = {}, n2[a] = f2 + "Date", n2[d] = f2 + "Date", n2[c] = f2 + "Month", n2[h] = f2 + "FullYear", n2[u] = f2 + "Hours", n2[s] = f2 + "Minutes", n2[i] = f2 + "Seconds", n2[r] = f2 + "Milliseconds", n2)[o2], $2 = o2 === a ? this.$D + (e2 - this.$W) : e2;
157
+ if (o2 === c || o2 === h) {
158
+ var y2 = this.clone().set(d, 1);
159
+ y2.$d[l2]($2), y2.init(), this.$d = y2.set(d, Math.min(this.$D, y2.daysInMonth())).$d;
160
+ } else
161
+ l2 && this.$d[l2]($2);
162
+ return this.init(), this;
163
+ }, m2.set = function(t2, e2) {
164
+ return this.clone().$set(t2, e2);
165
+ }, m2.get = function(t2) {
166
+ return this[b.p(t2)]();
167
+ }, m2.add = function(r2, f2) {
168
+ var d2, l2 = this;
169
+ r2 = Number(r2);
170
+ var $2 = b.p(f2), y2 = function(t2) {
171
+ var e2 = O(l2);
172
+ return b.w(e2.date(e2.date() + Math.round(t2 * r2)), l2);
173
+ };
174
+ if ($2 === c)
175
+ return this.set(c, this.$M + r2);
176
+ if ($2 === h)
177
+ return this.set(h, this.$y + r2);
178
+ if ($2 === a)
179
+ return y2(1);
180
+ if ($2 === o)
181
+ return y2(7);
182
+ var M3 = (d2 = {}, d2[s] = e, d2[u] = n, d2[i] = t, d2)[$2] || 1, m3 = this.$d.getTime() + r2 * M3;
183
+ return b.w(m3, this);
184
+ }, m2.subtract = function(t2, e2) {
185
+ return this.add(-1 * t2, e2);
186
+ }, m2.format = function(t2) {
187
+ var e2 = this, n2 = this.$locale();
188
+ if (!this.isValid())
189
+ return n2.invalidDate || l;
190
+ var r2 = t2 || "YYYY-MM-DDTHH:mm:ssZ", i2 = b.z(this), s2 = this.$H, u2 = this.$m, a2 = this.$M, o2 = n2.weekdays, c2 = n2.months, f2 = n2.meridiem, h2 = function(t3, n3, i3, s3) {
191
+ return t3 && (t3[n3] || t3(e2, r2)) || i3[n3].slice(0, s3);
192
+ }, d2 = function(t3) {
193
+ return b.s(s2 % 12 || 12, t3, "0");
194
+ }, $2 = f2 || function(t3, e3, n3) {
195
+ var r3 = t3 < 12 ? "AM" : "PM";
196
+ return n3 ? r3.toLowerCase() : r3;
197
+ };
198
+ return r2.replace(y, function(t3, r3) {
199
+ return r3 || function(t4) {
200
+ switch (t4) {
201
+ case "YY":
202
+ return String(e2.$y).slice(-2);
203
+ case "YYYY":
204
+ return b.s(e2.$y, 4, "0");
205
+ case "M":
206
+ return a2 + 1;
207
+ case "MM":
208
+ return b.s(a2 + 1, 2, "0");
209
+ case "MMM":
210
+ return h2(n2.monthsShort, a2, c2, 3);
211
+ case "MMMM":
212
+ return h2(c2, a2);
213
+ case "D":
214
+ return e2.$D;
215
+ case "DD":
216
+ return b.s(e2.$D, 2, "0");
217
+ case "d":
218
+ return String(e2.$W);
219
+ case "dd":
220
+ return h2(n2.weekdaysMin, e2.$W, o2, 2);
221
+ case "ddd":
222
+ return h2(n2.weekdaysShort, e2.$W, o2, 3);
223
+ case "dddd":
224
+ return o2[e2.$W];
225
+ case "H":
226
+ return String(s2);
227
+ case "HH":
228
+ return b.s(s2, 2, "0");
229
+ case "h":
230
+ return d2(1);
231
+ case "hh":
232
+ return d2(2);
233
+ case "a":
234
+ return $2(s2, u2, true);
235
+ case "A":
236
+ return $2(s2, u2, false);
237
+ case "m":
238
+ return String(u2);
239
+ case "mm":
240
+ return b.s(u2, 2, "0");
241
+ case "s":
242
+ return String(e2.$s);
243
+ case "ss":
244
+ return b.s(e2.$s, 2, "0");
245
+ case "SSS":
246
+ return b.s(e2.$ms, 3, "0");
247
+ case "Z":
248
+ return i2;
249
+ }
250
+ return null;
251
+ }(t3) || i2.replace(":", "");
252
+ });
253
+ }, m2.utcOffset = function() {
254
+ return 15 * -Math.round(this.$d.getTimezoneOffset() / 15);
255
+ }, m2.diff = function(r2, d2, l2) {
256
+ var $2, y2 = this, M3 = b.p(d2), m3 = O(r2), v2 = (m3.utcOffset() - this.utcOffset()) * e, g2 = this - m3, D2 = function() {
257
+ return b.m(y2, m3);
258
+ };
259
+ switch (M3) {
260
+ case h:
261
+ $2 = D2() / 12;
262
+ break;
263
+ case c:
264
+ $2 = D2();
265
+ break;
266
+ case f:
267
+ $2 = D2() / 3;
268
+ break;
269
+ case o:
270
+ $2 = (g2 - v2) / 604800000;
271
+ break;
272
+ case a:
273
+ $2 = (g2 - v2) / 86400000;
274
+ break;
275
+ case u:
276
+ $2 = g2 / n;
277
+ break;
278
+ case s:
279
+ $2 = g2 / e;
280
+ break;
281
+ case i:
282
+ $2 = g2 / t;
283
+ break;
284
+ default:
285
+ $2 = g2;
286
+ }
287
+ return l2 ? $2 : b.a($2);
288
+ }, m2.daysInMonth = function() {
289
+ return this.endOf(c).$D;
290
+ }, m2.$locale = function() {
291
+ return D[this.$L];
292
+ }, m2.locale = function(t2, e2) {
293
+ if (!t2)
294
+ return this.$L;
295
+ var n2 = this.clone(), r2 = w(t2, e2, true);
296
+ return r2 && (n2.$L = r2), n2;
297
+ }, m2.clone = function() {
298
+ return b.w(this.$d, this);
299
+ }, m2.toDate = function() {
300
+ return new Date(this.valueOf());
301
+ }, m2.toJSON = function() {
302
+ return this.isValid() ? this.toISOString() : null;
303
+ }, m2.toISOString = function() {
304
+ return this.$d.toISOString();
305
+ }, m2.toString = function() {
306
+ return this.$d.toUTCString();
307
+ }, M2;
308
+ }(), k = _.prototype;
309
+ return O.prototype = k, [["$ms", r], ["$s", i], ["$m", s], ["$H", u], ["$W", a], ["$M", c], ["$y", h], ["$D", d]].forEach(function(t2) {
310
+ k[t2[1]] = function(e2) {
311
+ return this.$g(e2, t2[0], t2[1]);
312
+ };
313
+ }), O.extend = function(t2, e2) {
314
+ return t2.$i || (t2(e2, _, O), t2.$i = true), O;
315
+ }, O.locale = w, O.isDayjs = S, O.unix = function(t2) {
316
+ return O(1000 * t2);
317
+ }, O.en = D[g], O.Ls = D, O.p = {}, O;
318
+ });
319
+ });
320
+
321
+ // node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/constants.js
322
+ var require_constants = __commonJS((exports, module) => {
323
+ var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
324
+ var hasBlob = typeof Blob !== "undefined";
325
+ if (hasBlob)
326
+ BINARY_TYPES.push("blob");
327
+ module.exports = {
328
+ BINARY_TYPES,
329
+ CLOSE_TIMEOUT: 30000,
330
+ EMPTY_BUFFER: Buffer.alloc(0),
331
+ GUID: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
332
+ hasBlob,
333
+ kForOnEventAttribute: Symbol("kIsForOnEventAttribute"),
334
+ kListener: Symbol("kListener"),
335
+ kStatusCode: Symbol("status-code"),
336
+ kWebSocket: Symbol("websocket"),
337
+ NOOP: () => {}
338
+ };
339
+ });
340
+
341
+ // node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/buffer-util.js
342
+ var require_buffer_util = __commonJS((exports, module) => {
343
+ var { EMPTY_BUFFER } = require_constants();
344
+ var FastBuffer = Buffer[Symbol.species];
345
+ function concat(list, totalLength) {
346
+ if (list.length === 0)
347
+ return EMPTY_BUFFER;
348
+ if (list.length === 1)
349
+ return list[0];
350
+ const target = Buffer.allocUnsafe(totalLength);
351
+ let offset = 0;
352
+ for (let i = 0;i < list.length; i++) {
353
+ const buf = list[i];
354
+ target.set(buf, offset);
355
+ offset += buf.length;
356
+ }
357
+ if (offset < totalLength) {
358
+ return new FastBuffer(target.buffer, target.byteOffset, offset);
359
+ }
360
+ return target;
361
+ }
362
+ function _mask(source, mask, output, offset, length) {
363
+ for (let i = 0;i < length; i++) {
364
+ output[offset + i] = source[i] ^ mask[i & 3];
365
+ }
366
+ }
367
+ function _unmask(buffer, mask) {
368
+ for (let i = 0;i < buffer.length; i++) {
369
+ buffer[i] ^= mask[i & 3];
370
+ }
371
+ }
372
+ function toArrayBuffer(buf) {
373
+ if (buf.length === buf.buffer.byteLength) {
374
+ return buf.buffer;
375
+ }
376
+ return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
377
+ }
378
+ function toBuffer(data) {
379
+ toBuffer.readOnly = true;
380
+ if (Buffer.isBuffer(data))
381
+ return data;
382
+ let buf;
383
+ if (data instanceof ArrayBuffer) {
384
+ buf = new FastBuffer(data);
385
+ } else if (ArrayBuffer.isView(data)) {
386
+ buf = new FastBuffer(data.buffer, data.byteOffset, data.byteLength);
387
+ } else {
388
+ buf = Buffer.from(data);
389
+ toBuffer.readOnly = false;
390
+ }
391
+ return buf;
392
+ }
393
+ module.exports = {
394
+ concat,
395
+ mask: _mask,
396
+ toArrayBuffer,
397
+ toBuffer,
398
+ unmask: _unmask
399
+ };
400
+ });
401
+
402
+ // node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/limiter.js
403
+ var require_limiter = __commonJS((exports, module) => {
404
+ var kDone = Symbol("kDone");
405
+ var kRun = Symbol("kRun");
406
+
407
+ class Limiter {
408
+ constructor(concurrency) {
409
+ this[kDone] = () => {
410
+ this.pending--;
411
+ this[kRun]();
412
+ };
413
+ this.concurrency = concurrency || Infinity;
414
+ this.jobs = [];
415
+ this.pending = 0;
416
+ }
417
+ add(job) {
418
+ this.jobs.push(job);
419
+ this[kRun]();
420
+ }
421
+ [kRun]() {
422
+ if (this.pending === this.concurrency)
423
+ return;
424
+ if (this.jobs.length) {
425
+ const job = this.jobs.shift();
426
+ this.pending++;
427
+ job(this[kDone]);
428
+ }
429
+ }
430
+ }
431
+ module.exports = Limiter;
432
+ });
433
+
434
+ // node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/permessage-deflate.js
435
+ var require_permessage_deflate = __commonJS((exports, module) => {
436
+ var zlib = __require("zlib");
437
+ var bufferUtil2 = require_buffer_util();
438
+ var Limiter = require_limiter();
439
+ var { kStatusCode } = require_constants();
440
+ var FastBuffer = Buffer[Symbol.species];
441
+ var TRAILER = Buffer.from([0, 0, 255, 255]);
442
+ var kPerMessageDeflate = Symbol("permessage-deflate");
443
+ var kTotalLength = Symbol("total-length");
444
+ var kCallback = Symbol("callback");
445
+ var kBuffers = Symbol("buffers");
446
+ var kError = Symbol("error");
447
+ var zlibLimiter;
448
+
449
+ class PerMessageDeflate {
450
+ constructor(options, isServer, maxPayload) {
451
+ this._maxPayload = maxPayload | 0;
452
+ this._options = options || {};
453
+ this._threshold = this._options.threshold !== undefined ? this._options.threshold : 1024;
454
+ this._isServer = !!isServer;
455
+ this._deflate = null;
456
+ this._inflate = null;
457
+ this.params = null;
458
+ if (!zlibLimiter) {
459
+ const concurrency = this._options.concurrencyLimit !== undefined ? this._options.concurrencyLimit : 10;
460
+ zlibLimiter = new Limiter(concurrency);
461
+ }
462
+ }
463
+ static get extensionName() {
464
+ return "permessage-deflate";
465
+ }
466
+ offer() {
467
+ const params = {};
468
+ if (this._options.serverNoContextTakeover) {
469
+ params.server_no_context_takeover = true;
470
+ }
471
+ if (this._options.clientNoContextTakeover) {
472
+ params.client_no_context_takeover = true;
473
+ }
474
+ if (this._options.serverMaxWindowBits) {
475
+ params.server_max_window_bits = this._options.serverMaxWindowBits;
476
+ }
477
+ if (this._options.clientMaxWindowBits) {
478
+ params.client_max_window_bits = this._options.clientMaxWindowBits;
479
+ } else if (this._options.clientMaxWindowBits == null) {
480
+ params.client_max_window_bits = true;
481
+ }
482
+ return params;
483
+ }
484
+ accept(configurations) {
485
+ configurations = this.normalizeParams(configurations);
486
+ this.params = this._isServer ? this.acceptAsServer(configurations) : this.acceptAsClient(configurations);
487
+ return this.params;
488
+ }
489
+ cleanup() {
490
+ if (this._inflate) {
491
+ this._inflate.close();
492
+ this._inflate = null;
493
+ }
494
+ if (this._deflate) {
495
+ const callback = this._deflate[kCallback];
496
+ this._deflate.close();
497
+ this._deflate = null;
498
+ if (callback) {
499
+ callback(new Error("The deflate stream was closed while data was being processed"));
500
+ }
501
+ }
502
+ }
503
+ acceptAsServer(offers) {
504
+ const opts = this._options;
505
+ const accepted = offers.find((params) => {
506
+ 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) {
507
+ return false;
508
+ }
509
+ return true;
510
+ });
511
+ if (!accepted) {
512
+ throw new Error("None of the extension offers can be accepted");
513
+ }
514
+ if (opts.serverNoContextTakeover) {
515
+ accepted.server_no_context_takeover = true;
516
+ }
517
+ if (opts.clientNoContextTakeover) {
518
+ accepted.client_no_context_takeover = true;
519
+ }
520
+ if (typeof opts.serverMaxWindowBits === "number") {
521
+ accepted.server_max_window_bits = opts.serverMaxWindowBits;
522
+ }
523
+ if (typeof opts.clientMaxWindowBits === "number") {
524
+ accepted.client_max_window_bits = opts.clientMaxWindowBits;
525
+ } else if (accepted.client_max_window_bits === true || opts.clientMaxWindowBits === false) {
526
+ delete accepted.client_max_window_bits;
527
+ }
528
+ return accepted;
529
+ }
530
+ acceptAsClient(response) {
531
+ const params = response[0];
532
+ if (this._options.clientNoContextTakeover === false && params.client_no_context_takeover) {
533
+ throw new Error('Unexpected parameter "client_no_context_takeover"');
534
+ }
535
+ if (!params.client_max_window_bits) {
536
+ if (typeof this._options.clientMaxWindowBits === "number") {
537
+ params.client_max_window_bits = this._options.clientMaxWindowBits;
538
+ }
539
+ } else if (this._options.clientMaxWindowBits === false || typeof this._options.clientMaxWindowBits === "number" && params.client_max_window_bits > this._options.clientMaxWindowBits) {
540
+ throw new Error('Unexpected or invalid parameter "client_max_window_bits"');
541
+ }
542
+ return params;
543
+ }
544
+ normalizeParams(configurations) {
545
+ configurations.forEach((params) => {
546
+ Object.keys(params).forEach((key) => {
547
+ let value = params[key];
548
+ if (value.length > 1) {
549
+ throw new Error(`Parameter "${key}" must have only a single value`);
550
+ }
551
+ value = value[0];
552
+ if (key === "client_max_window_bits") {
553
+ if (value !== true) {
554
+ const num = +value;
555
+ if (!Number.isInteger(num) || num < 8 || num > 15) {
556
+ throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
557
+ }
558
+ value = num;
559
+ } else if (!this._isServer) {
560
+ throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
561
+ }
562
+ } else if (key === "server_max_window_bits") {
563
+ const num = +value;
564
+ if (!Number.isInteger(num) || num < 8 || num > 15) {
565
+ throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
566
+ }
567
+ value = num;
568
+ } else if (key === "client_no_context_takeover" || key === "server_no_context_takeover") {
569
+ if (value !== true) {
570
+ throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
571
+ }
572
+ } else {
573
+ throw new Error(`Unknown parameter "${key}"`);
574
+ }
575
+ params[key] = value;
576
+ });
577
+ });
578
+ return configurations;
579
+ }
580
+ decompress(data, fin, callback) {
581
+ zlibLimiter.add((done) => {
582
+ this._decompress(data, fin, (err, result) => {
583
+ done();
584
+ callback(err, result);
585
+ });
586
+ });
587
+ }
588
+ compress(data, fin, callback) {
589
+ zlibLimiter.add((done) => {
590
+ this._compress(data, fin, (err, result) => {
591
+ done();
592
+ callback(err, result);
593
+ });
594
+ });
595
+ }
596
+ _decompress(data, fin, callback) {
597
+ const endpoint = this._isServer ? "client" : "server";
598
+ if (!this._inflate) {
599
+ const key = `${endpoint}_max_window_bits`;
600
+ const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
601
+ this._inflate = zlib.createInflateRaw({
602
+ ...this._options.zlibInflateOptions,
603
+ windowBits
604
+ });
605
+ this._inflate[kPerMessageDeflate] = this;
606
+ this._inflate[kTotalLength] = 0;
607
+ this._inflate[kBuffers] = [];
608
+ this._inflate.on("error", inflateOnError);
609
+ this._inflate.on("data", inflateOnData);
610
+ }
611
+ this._inflate[kCallback] = callback;
612
+ this._inflate.write(data);
613
+ if (fin)
614
+ this._inflate.write(TRAILER);
615
+ this._inflate.flush(() => {
616
+ const err = this._inflate[kError];
617
+ if (err) {
618
+ this._inflate.close();
619
+ this._inflate = null;
620
+ callback(err);
621
+ return;
622
+ }
623
+ const data2 = bufferUtil2.concat(this._inflate[kBuffers], this._inflate[kTotalLength]);
624
+ if (this._inflate._readableState.endEmitted) {
625
+ this._inflate.close();
626
+ this._inflate = null;
627
+ } else {
628
+ this._inflate[kTotalLength] = 0;
629
+ this._inflate[kBuffers] = [];
630
+ if (fin && this.params[`${endpoint}_no_context_takeover`]) {
631
+ this._inflate.reset();
632
+ }
633
+ }
634
+ callback(null, data2);
635
+ });
636
+ }
637
+ _compress(data, fin, callback) {
638
+ const endpoint = this._isServer ? "server" : "client";
639
+ if (!this._deflate) {
640
+ const key = `${endpoint}_max_window_bits`;
641
+ const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
642
+ this._deflate = zlib.createDeflateRaw({
643
+ ...this._options.zlibDeflateOptions,
644
+ windowBits
645
+ });
646
+ this._deflate[kTotalLength] = 0;
647
+ this._deflate[kBuffers] = [];
648
+ this._deflate.on("data", deflateOnData);
649
+ }
650
+ this._deflate[kCallback] = callback;
651
+ this._deflate.write(data);
652
+ this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
653
+ if (!this._deflate) {
654
+ return;
655
+ }
656
+ let data2 = bufferUtil2.concat(this._deflate[kBuffers], this._deflate[kTotalLength]);
657
+ if (fin) {
658
+ data2 = new FastBuffer(data2.buffer, data2.byteOffset, data2.length - 4);
659
+ }
660
+ this._deflate[kCallback] = null;
661
+ this._deflate[kTotalLength] = 0;
662
+ this._deflate[kBuffers] = [];
663
+ if (fin && this.params[`${endpoint}_no_context_takeover`]) {
664
+ this._deflate.reset();
665
+ }
666
+ callback(null, data2);
667
+ });
668
+ }
669
+ }
670
+ module.exports = PerMessageDeflate;
671
+ function deflateOnData(chunk) {
672
+ this[kBuffers].push(chunk);
673
+ this[kTotalLength] += chunk.length;
674
+ }
675
+ function inflateOnData(chunk) {
676
+ this[kTotalLength] += chunk.length;
677
+ if (this[kPerMessageDeflate]._maxPayload < 1 || this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload) {
678
+ this[kBuffers].push(chunk);
679
+ return;
680
+ }
681
+ this[kError] = new RangeError("Max payload size exceeded");
682
+ this[kError].code = "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH";
683
+ this[kError][kStatusCode] = 1009;
684
+ this.removeListener("data", inflateOnData);
685
+ this.reset();
686
+ }
687
+ function inflateOnError(err) {
688
+ this[kPerMessageDeflate]._inflate = null;
689
+ if (this[kError]) {
690
+ this[kCallback](this[kError]);
691
+ return;
692
+ }
693
+ err[kStatusCode] = 1007;
694
+ this[kCallback](err);
695
+ }
696
+ });
697
+
698
+ // node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/validation.js
699
+ var require_validation = __commonJS((exports, module) => {
700
+ var { isUtf8 } = __require("buffer");
701
+ var { hasBlob } = require_constants();
702
+ var tokenChars = [
703
+ 0,
704
+ 0,
705
+ 0,
706
+ 0,
707
+ 0,
708
+ 0,
709
+ 0,
710
+ 0,
711
+ 0,
712
+ 0,
713
+ 0,
714
+ 0,
715
+ 0,
716
+ 0,
717
+ 0,
718
+ 0,
719
+ 0,
720
+ 0,
721
+ 0,
722
+ 0,
723
+ 0,
724
+ 0,
725
+ 0,
726
+ 0,
727
+ 0,
728
+ 0,
729
+ 0,
730
+ 0,
731
+ 0,
732
+ 0,
733
+ 0,
734
+ 0,
735
+ 0,
736
+ 1,
737
+ 0,
738
+ 1,
739
+ 1,
740
+ 1,
741
+ 1,
742
+ 1,
743
+ 0,
744
+ 0,
745
+ 1,
746
+ 1,
747
+ 0,
748
+ 1,
749
+ 1,
750
+ 0,
751
+ 1,
752
+ 1,
753
+ 1,
754
+ 1,
755
+ 1,
756
+ 1,
757
+ 1,
758
+ 1,
759
+ 1,
760
+ 1,
761
+ 0,
762
+ 0,
763
+ 0,
764
+ 0,
765
+ 0,
766
+ 0,
767
+ 0,
768
+ 1,
769
+ 1,
770
+ 1,
771
+ 1,
772
+ 1,
773
+ 1,
774
+ 1,
775
+ 1,
776
+ 1,
777
+ 1,
778
+ 1,
779
+ 1,
780
+ 1,
781
+ 1,
782
+ 1,
783
+ 1,
784
+ 1,
785
+ 1,
786
+ 1,
787
+ 1,
788
+ 1,
789
+ 1,
790
+ 1,
791
+ 1,
792
+ 1,
793
+ 1,
794
+ 0,
795
+ 0,
796
+ 0,
797
+ 1,
798
+ 1,
799
+ 1,
800
+ 1,
801
+ 1,
802
+ 1,
803
+ 1,
804
+ 1,
805
+ 1,
806
+ 1,
807
+ 1,
808
+ 1,
809
+ 1,
810
+ 1,
811
+ 1,
812
+ 1,
813
+ 1,
814
+ 1,
815
+ 1,
816
+ 1,
817
+ 1,
818
+ 1,
819
+ 1,
820
+ 1,
821
+ 1,
822
+ 1,
823
+ 1,
824
+ 1,
825
+ 1,
826
+ 0,
827
+ 1,
828
+ 0,
829
+ 1,
830
+ 0
831
+ ];
832
+ function isValidStatusCode(code) {
833
+ return code >= 1000 && code <= 1014 && code !== 1004 && code !== 1005 && code !== 1006 || code >= 3000 && code <= 4999;
834
+ }
835
+ function _isValidUTF8(buf) {
836
+ const len = buf.length;
837
+ let i = 0;
838
+ while (i < len) {
839
+ if ((buf[i] & 128) === 0) {
840
+ i++;
841
+ } else if ((buf[i] & 224) === 192) {
842
+ if (i + 1 === len || (buf[i + 1] & 192) !== 128 || (buf[i] & 254) === 192) {
843
+ return false;
844
+ }
845
+ i += 2;
846
+ } else if ((buf[i] & 240) === 224) {
847
+ if (i + 2 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || buf[i] === 224 && (buf[i + 1] & 224) === 128 || buf[i] === 237 && (buf[i + 1] & 224) === 160) {
848
+ return false;
849
+ }
850
+ i += 3;
851
+ } else if ((buf[i] & 248) === 240) {
852
+ 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 || buf[i] === 244 && buf[i + 1] > 143 || buf[i] > 244) {
853
+ return false;
854
+ }
855
+ i += 4;
856
+ } else {
857
+ return false;
858
+ }
859
+ }
860
+ return true;
861
+ }
862
+ function isBlob(value) {
863
+ return hasBlob && typeof value === "object" && typeof value.arrayBuffer === "function" && typeof value.type === "string" && typeof value.stream === "function" && (value[Symbol.toStringTag] === "Blob" || value[Symbol.toStringTag] === "File");
864
+ }
865
+ module.exports = {
866
+ isBlob,
867
+ isValidStatusCode,
868
+ isValidUTF8: _isValidUTF8,
869
+ tokenChars
870
+ };
871
+ if (isUtf8) {
872
+ module.exports.isValidUTF8 = function(buf) {
873
+ return buf.length < 24 ? _isValidUTF8(buf) : isUtf8(buf);
874
+ };
875
+ }
876
+ });
877
+
878
+ // node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/receiver.js
879
+ var require_receiver = __commonJS((exports, module) => {
880
+ var { Writable } = __require("stream");
881
+ var PerMessageDeflate = require_permessage_deflate();
882
+ var {
883
+ BINARY_TYPES,
884
+ EMPTY_BUFFER,
885
+ kStatusCode,
886
+ kWebSocket
887
+ } = require_constants();
888
+ var { concat, toArrayBuffer, unmask } = require_buffer_util();
889
+ var { isValidStatusCode, isValidUTF8 } = require_validation();
890
+ var FastBuffer = Buffer[Symbol.species];
891
+ var GET_INFO = 0;
892
+ var GET_PAYLOAD_LENGTH_16 = 1;
893
+ var GET_PAYLOAD_LENGTH_64 = 2;
894
+ var GET_MASK = 3;
895
+ var GET_DATA = 4;
896
+ var INFLATING = 5;
897
+ var DEFER_EVENT = 6;
898
+
899
+ class Receiver extends Writable {
900
+ constructor(options = {}) {
901
+ super();
902
+ this._allowSynchronousEvents = options.allowSynchronousEvents !== undefined ? options.allowSynchronousEvents : true;
903
+ this._binaryType = options.binaryType || BINARY_TYPES[0];
904
+ this._extensions = options.extensions || {};
905
+ this._isServer = !!options.isServer;
906
+ this._maxPayload = options.maxPayload | 0;
907
+ this._skipUTF8Validation = !!options.skipUTF8Validation;
908
+ this[kWebSocket] = undefined;
909
+ this._bufferedBytes = 0;
910
+ this._buffers = [];
911
+ this._compressed = false;
912
+ this._payloadLength = 0;
913
+ this._mask = undefined;
914
+ this._fragmented = 0;
915
+ this._masked = false;
916
+ this._fin = false;
917
+ this._opcode = 0;
918
+ this._totalPayloadLength = 0;
919
+ this._messageLength = 0;
920
+ this._fragments = [];
921
+ this._errored = false;
922
+ this._loop = false;
923
+ this._state = GET_INFO;
924
+ }
925
+ _write(chunk, encoding, cb) {
926
+ if (this._opcode === 8 && this._state == GET_INFO)
927
+ return cb();
928
+ this._bufferedBytes += chunk.length;
929
+ this._buffers.push(chunk);
930
+ this.startLoop(cb);
931
+ }
932
+ consume(n) {
933
+ this._bufferedBytes -= n;
934
+ if (n === this._buffers[0].length)
935
+ return this._buffers.shift();
936
+ if (n < this._buffers[0].length) {
937
+ const buf = this._buffers[0];
938
+ this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n);
939
+ return new FastBuffer(buf.buffer, buf.byteOffset, n);
940
+ }
941
+ const dst = Buffer.allocUnsafe(n);
942
+ do {
943
+ const buf = this._buffers[0];
944
+ const offset = dst.length - n;
945
+ if (n >= buf.length) {
946
+ dst.set(this._buffers.shift(), offset);
947
+ } else {
948
+ dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
949
+ this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n);
950
+ }
951
+ n -= buf.length;
952
+ } while (n > 0);
953
+ return dst;
954
+ }
955
+ startLoop(cb) {
956
+ this._loop = true;
957
+ do {
958
+ switch (this._state) {
959
+ case GET_INFO:
960
+ this.getInfo(cb);
961
+ break;
962
+ case GET_PAYLOAD_LENGTH_16:
963
+ this.getPayloadLength16(cb);
964
+ break;
965
+ case GET_PAYLOAD_LENGTH_64:
966
+ this.getPayloadLength64(cb);
967
+ break;
968
+ case GET_MASK:
969
+ this.getMask();
970
+ break;
971
+ case GET_DATA:
972
+ this.getData(cb);
973
+ break;
974
+ case INFLATING:
975
+ case DEFER_EVENT:
976
+ this._loop = false;
977
+ return;
978
+ }
979
+ } while (this._loop);
980
+ if (!this._errored)
981
+ cb();
982
+ }
983
+ getInfo(cb) {
984
+ if (this._bufferedBytes < 2) {
985
+ this._loop = false;
986
+ return;
987
+ }
988
+ const buf = this.consume(2);
989
+ if ((buf[0] & 48) !== 0) {
990
+ const error49 = this.createError(RangeError, "RSV2 and RSV3 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_2_3");
991
+ cb(error49);
992
+ return;
993
+ }
994
+ const compressed = (buf[0] & 64) === 64;
995
+ if (compressed && !this._extensions[PerMessageDeflate.extensionName]) {
996
+ const error49 = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
997
+ cb(error49);
998
+ return;
999
+ }
1000
+ this._fin = (buf[0] & 128) === 128;
1001
+ this._opcode = buf[0] & 15;
1002
+ this._payloadLength = buf[1] & 127;
1003
+ if (this._opcode === 0) {
1004
+ if (compressed) {
1005
+ const error49 = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
1006
+ cb(error49);
1007
+ return;
1008
+ }
1009
+ if (!this._fragmented) {
1010
+ const error49 = this.createError(RangeError, "invalid opcode 0", true, 1002, "WS_ERR_INVALID_OPCODE");
1011
+ cb(error49);
1012
+ return;
1013
+ }
1014
+ this._opcode = this._fragmented;
1015
+ } else if (this._opcode === 1 || this._opcode === 2) {
1016
+ if (this._fragmented) {
1017
+ const error49 = this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, "WS_ERR_INVALID_OPCODE");
1018
+ cb(error49);
1019
+ return;
1020
+ }
1021
+ this._compressed = compressed;
1022
+ } else if (this._opcode > 7 && this._opcode < 11) {
1023
+ if (!this._fin) {
1024
+ const error49 = this.createError(RangeError, "FIN must be set", true, 1002, "WS_ERR_EXPECTED_FIN");
1025
+ cb(error49);
1026
+ return;
1027
+ }
1028
+ if (compressed) {
1029
+ const error49 = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
1030
+ cb(error49);
1031
+ return;
1032
+ }
1033
+ if (this._payloadLength > 125 || this._opcode === 8 && this._payloadLength === 1) {
1034
+ const error49 = this.createError(RangeError, `invalid payload length ${this._payloadLength}`, true, 1002, "WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");
1035
+ cb(error49);
1036
+ return;
1037
+ }
1038
+ } else {
1039
+ const error49 = this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, "WS_ERR_INVALID_OPCODE");
1040
+ cb(error49);
1041
+ return;
1042
+ }
1043
+ if (!this._fin && !this._fragmented)
1044
+ this._fragmented = this._opcode;
1045
+ this._masked = (buf[1] & 128) === 128;
1046
+ if (this._isServer) {
1047
+ if (!this._masked) {
1048
+ const error49 = this.createError(RangeError, "MASK must be set", true, 1002, "WS_ERR_EXPECTED_MASK");
1049
+ cb(error49);
1050
+ return;
1051
+ }
1052
+ } else if (this._masked) {
1053
+ const error49 = this.createError(RangeError, "MASK must be clear", true, 1002, "WS_ERR_UNEXPECTED_MASK");
1054
+ cb(error49);
1055
+ return;
1056
+ }
1057
+ if (this._payloadLength === 126)
1058
+ this._state = GET_PAYLOAD_LENGTH_16;
1059
+ else if (this._payloadLength === 127)
1060
+ this._state = GET_PAYLOAD_LENGTH_64;
1061
+ else
1062
+ this.haveLength(cb);
1063
+ }
1064
+ getPayloadLength16(cb) {
1065
+ if (this._bufferedBytes < 2) {
1066
+ this._loop = false;
1067
+ return;
1068
+ }
1069
+ this._payloadLength = this.consume(2).readUInt16BE(0);
1070
+ this.haveLength(cb);
1071
+ }
1072
+ getPayloadLength64(cb) {
1073
+ if (this._bufferedBytes < 8) {
1074
+ this._loop = false;
1075
+ return;
1076
+ }
1077
+ const buf = this.consume(8);
1078
+ const num = buf.readUInt32BE(0);
1079
+ if (num > Math.pow(2, 53 - 32) - 1) {
1080
+ const error49 = this.createError(RangeError, "Unsupported WebSocket frame: payload length > 2^53 - 1", false, 1009, "WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");
1081
+ cb(error49);
1082
+ return;
1083
+ }
1084
+ this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
1085
+ this.haveLength(cb);
1086
+ }
1087
+ haveLength(cb) {
1088
+ if (this._payloadLength && this._opcode < 8) {
1089
+ this._totalPayloadLength += this._payloadLength;
1090
+ if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
1091
+ const error49 = this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");
1092
+ cb(error49);
1093
+ return;
1094
+ }
1095
+ }
1096
+ if (this._masked)
1097
+ this._state = GET_MASK;
1098
+ else
1099
+ this._state = GET_DATA;
1100
+ }
1101
+ getMask() {
1102
+ if (this._bufferedBytes < 4) {
1103
+ this._loop = false;
1104
+ return;
1105
+ }
1106
+ this._mask = this.consume(4);
1107
+ this._state = GET_DATA;
1108
+ }
1109
+ getData(cb) {
1110
+ let data = EMPTY_BUFFER;
1111
+ if (this._payloadLength) {
1112
+ if (this._bufferedBytes < this._payloadLength) {
1113
+ this._loop = false;
1114
+ return;
1115
+ }
1116
+ data = this.consume(this._payloadLength);
1117
+ if (this._masked && (this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0) {
1118
+ unmask(data, this._mask);
1119
+ }
1120
+ }
1121
+ if (this._opcode > 7) {
1122
+ this.controlMessage(data, cb);
1123
+ return;
1124
+ }
1125
+ if (this._compressed) {
1126
+ this._state = INFLATING;
1127
+ this.decompress(data, cb);
1128
+ return;
1129
+ }
1130
+ if (data.length) {
1131
+ this._messageLength = this._totalPayloadLength;
1132
+ this._fragments.push(data);
1133
+ }
1134
+ this.dataMessage(cb);
1135
+ }
1136
+ decompress(data, cb) {
1137
+ const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
1138
+ perMessageDeflate.decompress(data, this._fin, (err, buf) => {
1139
+ if (err)
1140
+ return cb(err);
1141
+ if (buf.length) {
1142
+ this._messageLength += buf.length;
1143
+ if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
1144
+ const error49 = this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");
1145
+ cb(error49);
1146
+ return;
1147
+ }
1148
+ this._fragments.push(buf);
1149
+ }
1150
+ this.dataMessage(cb);
1151
+ if (this._state === GET_INFO)
1152
+ this.startLoop(cb);
1153
+ });
1154
+ }
1155
+ dataMessage(cb) {
1156
+ if (!this._fin) {
1157
+ this._state = GET_INFO;
1158
+ return;
1159
+ }
1160
+ const messageLength = this._messageLength;
1161
+ const fragments = this._fragments;
1162
+ this._totalPayloadLength = 0;
1163
+ this._messageLength = 0;
1164
+ this._fragmented = 0;
1165
+ this._fragments = [];
1166
+ if (this._opcode === 2) {
1167
+ let data;
1168
+ if (this._binaryType === "nodebuffer") {
1169
+ data = concat(fragments, messageLength);
1170
+ } else if (this._binaryType === "arraybuffer") {
1171
+ data = toArrayBuffer(concat(fragments, messageLength));
1172
+ } else if (this._binaryType === "blob") {
1173
+ data = new Blob(fragments);
1174
+ } else {
1175
+ data = fragments;
1176
+ }
1177
+ if (this._allowSynchronousEvents) {
1178
+ this.emit("message", data, true);
1179
+ this._state = GET_INFO;
1180
+ } else {
1181
+ this._state = DEFER_EVENT;
1182
+ setImmediate(() => {
1183
+ this.emit("message", data, true);
1184
+ this._state = GET_INFO;
1185
+ this.startLoop(cb);
1186
+ });
1187
+ }
1188
+ } else {
1189
+ const buf = concat(fragments, messageLength);
1190
+ if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
1191
+ const error49 = this.createError(Error, "invalid UTF-8 sequence", true, 1007, "WS_ERR_INVALID_UTF8");
1192
+ cb(error49);
1193
+ return;
1194
+ }
1195
+ if (this._state === INFLATING || this._allowSynchronousEvents) {
1196
+ this.emit("message", buf, false);
1197
+ this._state = GET_INFO;
1198
+ } else {
1199
+ this._state = DEFER_EVENT;
1200
+ setImmediate(() => {
1201
+ this.emit("message", buf, false);
1202
+ this._state = GET_INFO;
1203
+ this.startLoop(cb);
1204
+ });
1205
+ }
1206
+ }
1207
+ }
1208
+ controlMessage(data, cb) {
1209
+ if (this._opcode === 8) {
1210
+ if (data.length === 0) {
1211
+ this._loop = false;
1212
+ this.emit("conclude", 1005, EMPTY_BUFFER);
1213
+ this.end();
1214
+ } else {
1215
+ const code = data.readUInt16BE(0);
1216
+ if (!isValidStatusCode(code)) {
1217
+ const error49 = this.createError(RangeError, `invalid status code ${code}`, true, 1002, "WS_ERR_INVALID_CLOSE_CODE");
1218
+ cb(error49);
1219
+ return;
1220
+ }
1221
+ const buf = new FastBuffer(data.buffer, data.byteOffset + 2, data.length - 2);
1222
+ if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
1223
+ const error49 = this.createError(Error, "invalid UTF-8 sequence", true, 1007, "WS_ERR_INVALID_UTF8");
1224
+ cb(error49);
1225
+ return;
1226
+ }
1227
+ this._loop = false;
1228
+ this.emit("conclude", code, buf);
1229
+ this.end();
1230
+ }
1231
+ this._state = GET_INFO;
1232
+ return;
1233
+ }
1234
+ if (this._allowSynchronousEvents) {
1235
+ this.emit(this._opcode === 9 ? "ping" : "pong", data);
1236
+ this._state = GET_INFO;
1237
+ } else {
1238
+ this._state = DEFER_EVENT;
1239
+ setImmediate(() => {
1240
+ this.emit(this._opcode === 9 ? "ping" : "pong", data);
1241
+ this._state = GET_INFO;
1242
+ this.startLoop(cb);
1243
+ });
1244
+ }
1245
+ }
1246
+ createError(ErrorCtor, message, prefix, statusCode, errorCode) {
1247
+ this._loop = false;
1248
+ this._errored = true;
1249
+ const err = new ErrorCtor(prefix ? `Invalid WebSocket frame: ${message}` : message);
1250
+ Error.captureStackTrace(err, this.createError);
1251
+ err.code = errorCode;
1252
+ err[kStatusCode] = statusCode;
1253
+ return err;
1254
+ }
1255
+ }
1256
+ module.exports = Receiver;
1257
+ });
1258
+
1259
+ // node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/sender.js
1260
+ var require_sender = __commonJS((exports, module) => {
1261
+ var { Duplex } = __require("stream");
1262
+ var { randomFillSync } = __require("crypto");
1263
+ var PerMessageDeflate = require_permessage_deflate();
1264
+ var { EMPTY_BUFFER, kWebSocket, NOOP } = require_constants();
1265
+ var { isBlob, isValidStatusCode } = require_validation();
1266
+ var { mask: applyMask, toBuffer } = require_buffer_util();
1267
+ var kByteLength = Symbol("kByteLength");
1268
+ var maskBuffer = Buffer.alloc(4);
1269
+ var RANDOM_POOL_SIZE = 8 * 1024;
1270
+ var randomPool;
1271
+ var randomPoolPointer = RANDOM_POOL_SIZE;
1272
+ var DEFAULT = 0;
1273
+ var DEFLATING = 1;
1274
+ var GET_BLOB_DATA = 2;
1275
+
1276
+ class Sender {
1277
+ constructor(socket, extensions, generateMask) {
1278
+ this._extensions = extensions || {};
1279
+ if (generateMask) {
1280
+ this._generateMask = generateMask;
1281
+ this._maskBuffer = Buffer.alloc(4);
1282
+ }
1283
+ this._socket = socket;
1284
+ this._firstFragment = true;
1285
+ this._compress = false;
1286
+ this._bufferedBytes = 0;
1287
+ this._queue = [];
1288
+ this._state = DEFAULT;
1289
+ this.onerror = NOOP;
1290
+ this[kWebSocket] = undefined;
1291
+ }
1292
+ static frame(data, options) {
1293
+ let mask;
1294
+ let merge3 = false;
1295
+ let offset = 2;
1296
+ let skipMasking = false;
1297
+ if (options.mask) {
1298
+ mask = options.maskBuffer || maskBuffer;
1299
+ if (options.generateMask) {
1300
+ options.generateMask(mask);
1301
+ } else {
1302
+ if (randomPoolPointer === RANDOM_POOL_SIZE) {
1303
+ if (randomPool === undefined) {
1304
+ randomPool = Buffer.alloc(RANDOM_POOL_SIZE);
1305
+ }
1306
+ randomFillSync(randomPool, 0, RANDOM_POOL_SIZE);
1307
+ randomPoolPointer = 0;
1308
+ }
1309
+ mask[0] = randomPool[randomPoolPointer++];
1310
+ mask[1] = randomPool[randomPoolPointer++];
1311
+ mask[2] = randomPool[randomPoolPointer++];
1312
+ mask[3] = randomPool[randomPoolPointer++];
1313
+ }
1314
+ skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) === 0;
1315
+ offset = 6;
1316
+ }
1317
+ let dataLength;
1318
+ if (typeof data === "string") {
1319
+ if ((!options.mask || skipMasking) && options[kByteLength] !== undefined) {
1320
+ dataLength = options[kByteLength];
1321
+ } else {
1322
+ data = Buffer.from(data);
1323
+ dataLength = data.length;
1324
+ }
1325
+ } else {
1326
+ dataLength = data.length;
1327
+ merge3 = options.mask && options.readOnly && !skipMasking;
1328
+ }
1329
+ let payloadLength = dataLength;
1330
+ if (dataLength >= 65536) {
1331
+ offset += 8;
1332
+ payloadLength = 127;
1333
+ } else if (dataLength > 125) {
1334
+ offset += 2;
1335
+ payloadLength = 126;
1336
+ }
1337
+ const target = Buffer.allocUnsafe(merge3 ? dataLength + offset : offset);
1338
+ target[0] = options.fin ? options.opcode | 128 : options.opcode;
1339
+ if (options.rsv1)
1340
+ target[0] |= 64;
1341
+ target[1] = payloadLength;
1342
+ if (payloadLength === 126) {
1343
+ target.writeUInt16BE(dataLength, 2);
1344
+ } else if (payloadLength === 127) {
1345
+ target[2] = target[3] = 0;
1346
+ target.writeUIntBE(dataLength, 4, 6);
1347
+ }
1348
+ if (!options.mask)
1349
+ return [target, data];
1350
+ target[1] |= 128;
1351
+ target[offset - 4] = mask[0];
1352
+ target[offset - 3] = mask[1];
1353
+ target[offset - 2] = mask[2];
1354
+ target[offset - 1] = mask[3];
1355
+ if (skipMasking)
1356
+ return [target, data];
1357
+ if (merge3) {
1358
+ applyMask(data, mask, target, offset, dataLength);
1359
+ return [target];
1360
+ }
1361
+ applyMask(data, mask, data, 0, dataLength);
1362
+ return [target, data];
1363
+ }
1364
+ close(code, data, mask, cb) {
1365
+ let buf;
1366
+ if (code === undefined) {
1367
+ buf = EMPTY_BUFFER;
1368
+ } else if (typeof code !== "number" || !isValidStatusCode(code)) {
1369
+ throw new TypeError("First argument must be a valid error code number");
1370
+ } else if (data === undefined || !data.length) {
1371
+ buf = Buffer.allocUnsafe(2);
1372
+ buf.writeUInt16BE(code, 0);
1373
+ } else {
1374
+ const length = Buffer.byteLength(data);
1375
+ if (length > 123) {
1376
+ throw new RangeError("The message must not be greater than 123 bytes");
1377
+ }
1378
+ buf = Buffer.allocUnsafe(2 + length);
1379
+ buf.writeUInt16BE(code, 0);
1380
+ if (typeof data === "string") {
1381
+ buf.write(data, 2);
1382
+ } else {
1383
+ buf.set(data, 2);
1384
+ }
1385
+ }
1386
+ const options = {
1387
+ [kByteLength]: buf.length,
1388
+ fin: true,
1389
+ generateMask: this._generateMask,
1390
+ mask,
1391
+ maskBuffer: this._maskBuffer,
1392
+ opcode: 8,
1393
+ readOnly: false,
1394
+ rsv1: false
1395
+ };
1396
+ if (this._state !== DEFAULT) {
1397
+ this.enqueue([this.dispatch, buf, false, options, cb]);
1398
+ } else {
1399
+ this.sendFrame(Sender.frame(buf, options), cb);
1400
+ }
1401
+ }
1402
+ ping(data, mask, cb) {
1403
+ let byteLength;
1404
+ let readOnly;
1405
+ if (typeof data === "string") {
1406
+ byteLength = Buffer.byteLength(data);
1407
+ readOnly = false;
1408
+ } else if (isBlob(data)) {
1409
+ byteLength = data.size;
1410
+ readOnly = false;
1411
+ } else {
1412
+ data = toBuffer(data);
1413
+ byteLength = data.length;
1414
+ readOnly = toBuffer.readOnly;
1415
+ }
1416
+ if (byteLength > 125) {
1417
+ throw new RangeError("The data size must not be greater than 125 bytes");
1418
+ }
1419
+ const options = {
1420
+ [kByteLength]: byteLength,
1421
+ fin: true,
1422
+ generateMask: this._generateMask,
1423
+ mask,
1424
+ maskBuffer: this._maskBuffer,
1425
+ opcode: 9,
1426
+ readOnly,
1427
+ rsv1: false
1428
+ };
1429
+ if (isBlob(data)) {
1430
+ if (this._state !== DEFAULT) {
1431
+ this.enqueue([this.getBlobData, data, false, options, cb]);
1432
+ } else {
1433
+ this.getBlobData(data, false, options, cb);
1434
+ }
1435
+ } else if (this._state !== DEFAULT) {
1436
+ this.enqueue([this.dispatch, data, false, options, cb]);
1437
+ } else {
1438
+ this.sendFrame(Sender.frame(data, options), cb);
1439
+ }
1440
+ }
1441
+ pong(data, mask, cb) {
1442
+ let byteLength;
1443
+ let readOnly;
1444
+ if (typeof data === "string") {
1445
+ byteLength = Buffer.byteLength(data);
1446
+ readOnly = false;
1447
+ } else if (isBlob(data)) {
1448
+ byteLength = data.size;
1449
+ readOnly = false;
1450
+ } else {
1451
+ data = toBuffer(data);
1452
+ byteLength = data.length;
1453
+ readOnly = toBuffer.readOnly;
1454
+ }
1455
+ if (byteLength > 125) {
1456
+ throw new RangeError("The data size must not be greater than 125 bytes");
1457
+ }
1458
+ const options = {
1459
+ [kByteLength]: byteLength,
1460
+ fin: true,
1461
+ generateMask: this._generateMask,
1462
+ mask,
1463
+ maskBuffer: this._maskBuffer,
1464
+ opcode: 10,
1465
+ readOnly,
1466
+ rsv1: false
1467
+ };
1468
+ if (isBlob(data)) {
1469
+ if (this._state !== DEFAULT) {
1470
+ this.enqueue([this.getBlobData, data, false, options, cb]);
1471
+ } else {
1472
+ this.getBlobData(data, false, options, cb);
1473
+ }
1474
+ } else if (this._state !== DEFAULT) {
1475
+ this.enqueue([this.dispatch, data, false, options, cb]);
1476
+ } else {
1477
+ this.sendFrame(Sender.frame(data, options), cb);
1478
+ }
1479
+ }
1480
+ send(data, options, cb) {
1481
+ const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
1482
+ let opcode = options.binary ? 2 : 1;
1483
+ let rsv1 = options.compress;
1484
+ let byteLength;
1485
+ let readOnly;
1486
+ if (typeof data === "string") {
1487
+ byteLength = Buffer.byteLength(data);
1488
+ readOnly = false;
1489
+ } else if (isBlob(data)) {
1490
+ byteLength = data.size;
1491
+ readOnly = false;
1492
+ } else {
1493
+ data = toBuffer(data);
1494
+ byteLength = data.length;
1495
+ readOnly = toBuffer.readOnly;
1496
+ }
1497
+ if (this._firstFragment) {
1498
+ this._firstFragment = false;
1499
+ if (rsv1 && perMessageDeflate && perMessageDeflate.params[perMessageDeflate._isServer ? "server_no_context_takeover" : "client_no_context_takeover"]) {
1500
+ rsv1 = byteLength >= perMessageDeflate._threshold;
1501
+ }
1502
+ this._compress = rsv1;
1503
+ } else {
1504
+ rsv1 = false;
1505
+ opcode = 0;
1506
+ }
1507
+ if (options.fin)
1508
+ this._firstFragment = true;
1509
+ const opts = {
1510
+ [kByteLength]: byteLength,
1511
+ fin: options.fin,
1512
+ generateMask: this._generateMask,
1513
+ mask: options.mask,
1514
+ maskBuffer: this._maskBuffer,
1515
+ opcode,
1516
+ readOnly,
1517
+ rsv1
1518
+ };
1519
+ if (isBlob(data)) {
1520
+ if (this._state !== DEFAULT) {
1521
+ this.enqueue([this.getBlobData, data, this._compress, opts, cb]);
1522
+ } else {
1523
+ this.getBlobData(data, this._compress, opts, cb);
1524
+ }
1525
+ } else if (this._state !== DEFAULT) {
1526
+ this.enqueue([this.dispatch, data, this._compress, opts, cb]);
1527
+ } else {
1528
+ this.dispatch(data, this._compress, opts, cb);
1529
+ }
1530
+ }
1531
+ getBlobData(blob, compress, options, cb) {
1532
+ this._bufferedBytes += options[kByteLength];
1533
+ this._state = GET_BLOB_DATA;
1534
+ blob.arrayBuffer().then((arrayBuffer) => {
1535
+ if (this._socket.destroyed) {
1536
+ const err = new Error("The socket was closed while the blob was being read");
1537
+ process.nextTick(callCallbacks, this, err, cb);
1538
+ return;
1539
+ }
1540
+ this._bufferedBytes -= options[kByteLength];
1541
+ const data = toBuffer(arrayBuffer);
1542
+ if (!compress) {
1543
+ this._state = DEFAULT;
1544
+ this.sendFrame(Sender.frame(data, options), cb);
1545
+ this.dequeue();
1546
+ } else {
1547
+ this.dispatch(data, compress, options, cb);
1548
+ }
1549
+ }).catch((err) => {
1550
+ process.nextTick(onError, this, err, cb);
1551
+ });
1552
+ }
1553
+ dispatch(data, compress, options, cb) {
1554
+ if (!compress) {
1555
+ this.sendFrame(Sender.frame(data, options), cb);
1556
+ return;
1557
+ }
1558
+ const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
1559
+ this._bufferedBytes += options[kByteLength];
1560
+ this._state = DEFLATING;
1561
+ perMessageDeflate.compress(data, options.fin, (_, buf) => {
1562
+ if (this._socket.destroyed) {
1563
+ const err = new Error("The socket was closed while data was being compressed");
1564
+ callCallbacks(this, err, cb);
1565
+ return;
1566
+ }
1567
+ this._bufferedBytes -= options[kByteLength];
1568
+ this._state = DEFAULT;
1569
+ options.readOnly = false;
1570
+ this.sendFrame(Sender.frame(buf, options), cb);
1571
+ this.dequeue();
1572
+ });
1573
+ }
1574
+ dequeue() {
1575
+ while (this._state === DEFAULT && this._queue.length) {
1576
+ const params = this._queue.shift();
1577
+ this._bufferedBytes -= params[3][kByteLength];
1578
+ Reflect.apply(params[0], this, params.slice(1));
1579
+ }
1580
+ }
1581
+ enqueue(params) {
1582
+ this._bufferedBytes += params[3][kByteLength];
1583
+ this._queue.push(params);
1584
+ }
1585
+ sendFrame(list, cb) {
1586
+ if (list.length === 2) {
1587
+ this._socket.cork();
1588
+ this._socket.write(list[0]);
1589
+ this._socket.write(list[1], cb);
1590
+ this._socket.uncork();
1591
+ } else {
1592
+ this._socket.write(list[0], cb);
1593
+ }
1594
+ }
1595
+ }
1596
+ module.exports = Sender;
1597
+ function callCallbacks(sender2, err, cb) {
1598
+ if (typeof cb === "function")
1599
+ cb(err);
1600
+ for (let i = 0;i < sender2._queue.length; i++) {
1601
+ const params = sender2._queue[i];
1602
+ const callback = params[params.length - 1];
1603
+ if (typeof callback === "function")
1604
+ callback(err);
1605
+ }
1606
+ }
1607
+ function onError(sender2, err, cb) {
1608
+ callCallbacks(sender2, err, cb);
1609
+ sender2.onerror(err);
1610
+ }
1611
+ });
1612
+
1613
+ // node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/event-target.js
1614
+ var require_event_target = __commonJS((exports, module) => {
1615
+ var { kForOnEventAttribute, kListener } = require_constants();
1616
+ var kCode = Symbol("kCode");
1617
+ var kData = Symbol("kData");
1618
+ var kError = Symbol("kError");
1619
+ var kMessage = Symbol("kMessage");
1620
+ var kReason = Symbol("kReason");
1621
+ var kTarget = Symbol("kTarget");
1622
+ var kType = Symbol("kType");
1623
+ var kWasClean = Symbol("kWasClean");
1624
+
1625
+ class Event {
1626
+ constructor(type) {
1627
+ this[kTarget] = null;
1628
+ this[kType] = type;
1629
+ }
1630
+ get target() {
1631
+ return this[kTarget];
1632
+ }
1633
+ get type() {
1634
+ return this[kType];
1635
+ }
1636
+ }
1637
+ Object.defineProperty(Event.prototype, "target", { enumerable: true });
1638
+ Object.defineProperty(Event.prototype, "type", { enumerable: true });
1639
+
1640
+ class CloseEvent extends Event {
1641
+ constructor(type, options = {}) {
1642
+ super(type);
1643
+ this[kCode] = options.code === undefined ? 0 : options.code;
1644
+ this[kReason] = options.reason === undefined ? "" : options.reason;
1645
+ this[kWasClean] = options.wasClean === undefined ? false : options.wasClean;
1646
+ }
1647
+ get code() {
1648
+ return this[kCode];
1649
+ }
1650
+ get reason() {
1651
+ return this[kReason];
1652
+ }
1653
+ get wasClean() {
1654
+ return this[kWasClean];
1655
+ }
1656
+ }
1657
+ Object.defineProperty(CloseEvent.prototype, "code", { enumerable: true });
1658
+ Object.defineProperty(CloseEvent.prototype, "reason", { enumerable: true });
1659
+ Object.defineProperty(CloseEvent.prototype, "wasClean", { enumerable: true });
1660
+
1661
+ class ErrorEvent extends Event {
1662
+ constructor(type, options = {}) {
1663
+ super(type);
1664
+ this[kError] = options.error === undefined ? null : options.error;
1665
+ this[kMessage] = options.message === undefined ? "" : options.message;
1666
+ }
1667
+ get error() {
1668
+ return this[kError];
1669
+ }
1670
+ get message() {
1671
+ return this[kMessage];
1672
+ }
1673
+ }
1674
+ Object.defineProperty(ErrorEvent.prototype, "error", { enumerable: true });
1675
+ Object.defineProperty(ErrorEvent.prototype, "message", { enumerable: true });
1676
+
1677
+ class MessageEvent extends Event {
1678
+ constructor(type, options = {}) {
1679
+ super(type);
1680
+ this[kData] = options.data === undefined ? null : options.data;
1681
+ }
1682
+ get data() {
1683
+ return this[kData];
1684
+ }
1685
+ }
1686
+ Object.defineProperty(MessageEvent.prototype, "data", { enumerable: true });
1687
+ var EventTarget = {
1688
+ addEventListener(type, handler, options = {}) {
1689
+ for (const listener of this.listeners(type)) {
1690
+ if (!options[kForOnEventAttribute] && listener[kListener] === handler && !listener[kForOnEventAttribute]) {
1691
+ return;
1692
+ }
1693
+ }
1694
+ let wrapper;
1695
+ if (type === "message") {
1696
+ wrapper = function onMessage(data, isBinary) {
1697
+ const event = new MessageEvent("message", {
1698
+ data: isBinary ? data : data.toString()
1699
+ });
1700
+ event[kTarget] = this;
1701
+ callListener(handler, this, event);
1702
+ };
1703
+ } else if (type === "close") {
1704
+ wrapper = function onClose(code, message) {
1705
+ const event = new CloseEvent("close", {
1706
+ code,
1707
+ reason: message.toString(),
1708
+ wasClean: this._closeFrameReceived && this._closeFrameSent
1709
+ });
1710
+ event[kTarget] = this;
1711
+ callListener(handler, this, event);
1712
+ };
1713
+ } else if (type === "error") {
1714
+ wrapper = function onError(error49) {
1715
+ const event = new ErrorEvent("error", {
1716
+ error: error49,
1717
+ message: error49.message
1718
+ });
1719
+ event[kTarget] = this;
1720
+ callListener(handler, this, event);
1721
+ };
1722
+ } else if (type === "open") {
1723
+ wrapper = function onOpen() {
1724
+ const event = new Event("open");
1725
+ event[kTarget] = this;
1726
+ callListener(handler, this, event);
1727
+ };
1728
+ } else {
1729
+ return;
1730
+ }
1731
+ wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute];
1732
+ wrapper[kListener] = handler;
1733
+ if (options.once) {
1734
+ this.once(type, wrapper);
1735
+ } else {
1736
+ this.on(type, wrapper);
1737
+ }
1738
+ },
1739
+ removeEventListener(type, handler) {
1740
+ for (const listener of this.listeners(type)) {
1741
+ if (listener[kListener] === handler && !listener[kForOnEventAttribute]) {
1742
+ this.removeListener(type, listener);
1743
+ break;
1744
+ }
1745
+ }
1746
+ }
1747
+ };
1748
+ module.exports = {
1749
+ CloseEvent,
1750
+ ErrorEvent,
1751
+ Event,
1752
+ EventTarget,
1753
+ MessageEvent
1754
+ };
1755
+ function callListener(listener, thisArg, event) {
1756
+ if (typeof listener === "object" && listener.handleEvent) {
1757
+ listener.handleEvent.call(listener, event);
1758
+ } else {
1759
+ listener.call(thisArg, event);
1760
+ }
1761
+ }
1762
+ });
1763
+
1764
+ // node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/extension.js
1765
+ var require_extension = __commonJS((exports, module) => {
1766
+ var { tokenChars } = require_validation();
1767
+ function push(dest, name, elem) {
1768
+ if (dest[name] === undefined)
1769
+ dest[name] = [elem];
1770
+ else
1771
+ dest[name].push(elem);
1772
+ }
1773
+ function parse6(header) {
1774
+ const offers = Object.create(null);
1775
+ let params = Object.create(null);
1776
+ let mustUnescape = false;
1777
+ let isEscaping = false;
1778
+ let inQuotes = false;
1779
+ let extensionName;
1780
+ let paramName;
1781
+ let start = -1;
1782
+ let code = -1;
1783
+ let end = -1;
1784
+ let i = 0;
1785
+ for (;i < header.length; i++) {
1786
+ code = header.charCodeAt(i);
1787
+ if (extensionName === undefined) {
1788
+ if (end === -1 && tokenChars[code] === 1) {
1789
+ if (start === -1)
1790
+ start = i;
1791
+ } else if (i !== 0 && (code === 32 || code === 9)) {
1792
+ if (end === -1 && start !== -1)
1793
+ end = i;
1794
+ } else if (code === 59 || code === 44) {
1795
+ if (start === -1) {
1796
+ throw new SyntaxError(`Unexpected character at index ${i}`);
1797
+ }
1798
+ if (end === -1)
1799
+ end = i;
1800
+ const name = header.slice(start, end);
1801
+ if (code === 44) {
1802
+ push(offers, name, params);
1803
+ params = Object.create(null);
1804
+ } else {
1805
+ extensionName = name;
1806
+ }
1807
+ start = end = -1;
1808
+ } else {
1809
+ throw new SyntaxError(`Unexpected character at index ${i}`);
1810
+ }
1811
+ } else if (paramName === undefined) {
1812
+ if (end === -1 && tokenChars[code] === 1) {
1813
+ if (start === -1)
1814
+ start = i;
1815
+ } else if (code === 32 || code === 9) {
1816
+ if (end === -1 && start !== -1)
1817
+ end = i;
1818
+ } else if (code === 59 || code === 44) {
1819
+ if (start === -1) {
1820
+ throw new SyntaxError(`Unexpected character at index ${i}`);
1821
+ }
1822
+ if (end === -1)
1823
+ end = i;
1824
+ push(params, header.slice(start, end), true);
1825
+ if (code === 44) {
1826
+ push(offers, extensionName, params);
1827
+ params = Object.create(null);
1828
+ extensionName = undefined;
1829
+ }
1830
+ start = end = -1;
1831
+ } else if (code === 61 && start !== -1 && end === -1) {
1832
+ paramName = header.slice(start, i);
1833
+ start = end = -1;
1834
+ } else {
1835
+ throw new SyntaxError(`Unexpected character at index ${i}`);
1836
+ }
1837
+ } else {
1838
+ if (isEscaping) {
1839
+ if (tokenChars[code] !== 1) {
1840
+ throw new SyntaxError(`Unexpected character at index ${i}`);
1841
+ }
1842
+ if (start === -1)
1843
+ start = i;
1844
+ else if (!mustUnescape)
1845
+ mustUnescape = true;
1846
+ isEscaping = false;
1847
+ } else if (inQuotes) {
1848
+ if (tokenChars[code] === 1) {
1849
+ if (start === -1)
1850
+ start = i;
1851
+ } else if (code === 34 && start !== -1) {
1852
+ inQuotes = false;
1853
+ end = i;
1854
+ } else if (code === 92) {
1855
+ isEscaping = true;
1856
+ } else {
1857
+ throw new SyntaxError(`Unexpected character at index ${i}`);
1858
+ }
1859
+ } else if (code === 34 && header.charCodeAt(i - 1) === 61) {
1860
+ inQuotes = true;
1861
+ } else if (end === -1 && tokenChars[code] === 1) {
1862
+ if (start === -1)
1863
+ start = i;
1864
+ } else if (start !== -1 && (code === 32 || code === 9)) {
1865
+ if (end === -1)
1866
+ end = i;
1867
+ } else if (code === 59 || code === 44) {
1868
+ if (start === -1) {
1869
+ throw new SyntaxError(`Unexpected character at index ${i}`);
1870
+ }
1871
+ if (end === -1)
1872
+ end = i;
1873
+ let value = header.slice(start, end);
1874
+ if (mustUnescape) {
1875
+ value = value.replace(/\\/g, "");
1876
+ mustUnescape = false;
1877
+ }
1878
+ push(params, paramName, value);
1879
+ if (code === 44) {
1880
+ push(offers, extensionName, params);
1881
+ params = Object.create(null);
1882
+ extensionName = undefined;
1883
+ }
1884
+ paramName = undefined;
1885
+ start = end = -1;
1886
+ } else {
1887
+ throw new SyntaxError(`Unexpected character at index ${i}`);
1888
+ }
1889
+ }
1890
+ }
1891
+ if (start === -1 || inQuotes || code === 32 || code === 9) {
1892
+ throw new SyntaxError("Unexpected end of input");
1893
+ }
1894
+ if (end === -1)
1895
+ end = i;
1896
+ const token = header.slice(start, end);
1897
+ if (extensionName === undefined) {
1898
+ push(offers, token, params);
1899
+ } else {
1900
+ if (paramName === undefined) {
1901
+ push(params, token, true);
1902
+ } else if (mustUnescape) {
1903
+ push(params, paramName, token.replace(/\\/g, ""));
1904
+ } else {
1905
+ push(params, paramName, token);
1906
+ }
1907
+ push(offers, extensionName, params);
1908
+ }
1909
+ return offers;
1910
+ }
1911
+ function format(extensions) {
1912
+ return Object.keys(extensions).map((extension2) => {
1913
+ let configurations = extensions[extension2];
1914
+ if (!Array.isArray(configurations))
1915
+ configurations = [configurations];
1916
+ return configurations.map((params) => {
1917
+ return [extension2].concat(Object.keys(params).map((k) => {
1918
+ let values = params[k];
1919
+ if (!Array.isArray(values))
1920
+ values = [values];
1921
+ return values.map((v) => v === true ? k : `${k}=${v}`).join("; ");
1922
+ })).join("; ");
1923
+ }).join(", ");
1924
+ }).join(", ");
1925
+ }
1926
+ module.exports = { format, parse: parse6 };
1927
+ });
1928
+
1929
+ // node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/websocket.js
1930
+ var require_websocket = __commonJS((exports, module) => {
1931
+ var EventEmitter4 = __require("events");
1932
+ var https = __require("https");
1933
+ var http = __require("http");
1934
+ var net = __require("net");
1935
+ var tls = __require("tls");
1936
+ var { randomBytes, createHash } = __require("crypto");
1937
+ var { Duplex, Readable } = __require("stream");
1938
+ var { URL: URL2 } = __require("url");
1939
+ var PerMessageDeflate = require_permessage_deflate();
1940
+ var Receiver = require_receiver();
1941
+ var Sender = require_sender();
1942
+ var { isBlob } = require_validation();
1943
+ var {
1944
+ BINARY_TYPES,
1945
+ CLOSE_TIMEOUT,
1946
+ EMPTY_BUFFER,
1947
+ GUID,
1948
+ kForOnEventAttribute,
1949
+ kListener,
1950
+ kStatusCode,
1951
+ kWebSocket,
1952
+ NOOP
1953
+ } = require_constants();
1954
+ var {
1955
+ EventTarget: { addEventListener, removeEventListener }
1956
+ } = require_event_target();
1957
+ var { format, parse: parse6 } = require_extension();
1958
+ var { toBuffer } = require_buffer_util();
1959
+ var kAborted = Symbol("kAborted");
1960
+ var protocolVersions = [8, 13];
1961
+ var readyStates = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"];
1962
+ var subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
1963
+
1964
+ class WebSocket extends EventEmitter4 {
1965
+ constructor(address, protocols, options) {
1966
+ super();
1967
+ this._binaryType = BINARY_TYPES[0];
1968
+ this._closeCode = 1006;
1969
+ this._closeFrameReceived = false;
1970
+ this._closeFrameSent = false;
1971
+ this._closeMessage = EMPTY_BUFFER;
1972
+ this._closeTimer = null;
1973
+ this._errorEmitted = false;
1974
+ this._extensions = {};
1975
+ this._paused = false;
1976
+ this._protocol = "";
1977
+ this._readyState = WebSocket.CONNECTING;
1978
+ this._receiver = null;
1979
+ this._sender = null;
1980
+ this._socket = null;
1981
+ if (address !== null) {
1982
+ this._bufferedAmount = 0;
1983
+ this._isServer = false;
1984
+ this._redirects = 0;
1985
+ if (protocols === undefined) {
1986
+ protocols = [];
1987
+ } else if (!Array.isArray(protocols)) {
1988
+ if (typeof protocols === "object" && protocols !== null) {
1989
+ options = protocols;
1990
+ protocols = [];
1991
+ } else {
1992
+ protocols = [protocols];
1993
+ }
1994
+ }
1995
+ initAsClient(this, address, protocols, options);
1996
+ } else {
1997
+ this._autoPong = options.autoPong;
1998
+ this._closeTimeout = options.closeTimeout;
1999
+ this._isServer = true;
2000
+ }
2001
+ }
2002
+ get binaryType() {
2003
+ return this._binaryType;
2004
+ }
2005
+ set binaryType(type) {
2006
+ if (!BINARY_TYPES.includes(type))
2007
+ return;
2008
+ this._binaryType = type;
2009
+ if (this._receiver)
2010
+ this._receiver._binaryType = type;
2011
+ }
2012
+ get bufferedAmount() {
2013
+ if (!this._socket)
2014
+ return this._bufferedAmount;
2015
+ return this._socket._writableState.length + this._sender._bufferedBytes;
2016
+ }
2017
+ get extensions() {
2018
+ return Object.keys(this._extensions).join();
2019
+ }
2020
+ get isPaused() {
2021
+ return this._paused;
2022
+ }
2023
+ get onclose() {
2024
+ return null;
2025
+ }
2026
+ get onerror() {
2027
+ return null;
2028
+ }
2029
+ get onopen() {
2030
+ return null;
2031
+ }
2032
+ get onmessage() {
2033
+ return null;
2034
+ }
2035
+ get protocol() {
2036
+ return this._protocol;
2037
+ }
2038
+ get readyState() {
2039
+ return this._readyState;
2040
+ }
2041
+ get url() {
2042
+ return this._url;
2043
+ }
2044
+ setSocket(socket, head, options) {
2045
+ const receiver2 = new Receiver({
2046
+ allowSynchronousEvents: options.allowSynchronousEvents,
2047
+ binaryType: this.binaryType,
2048
+ extensions: this._extensions,
2049
+ isServer: this._isServer,
2050
+ maxPayload: options.maxPayload,
2051
+ skipUTF8Validation: options.skipUTF8Validation
2052
+ });
2053
+ const sender2 = new Sender(socket, this._extensions, options.generateMask);
2054
+ this._receiver = receiver2;
2055
+ this._sender = sender2;
2056
+ this._socket = socket;
2057
+ receiver2[kWebSocket] = this;
2058
+ sender2[kWebSocket] = this;
2059
+ socket[kWebSocket] = this;
2060
+ receiver2.on("conclude", receiverOnConclude);
2061
+ receiver2.on("drain", receiverOnDrain);
2062
+ receiver2.on("error", receiverOnError);
2063
+ receiver2.on("message", receiverOnMessage);
2064
+ receiver2.on("ping", receiverOnPing);
2065
+ receiver2.on("pong", receiverOnPong);
2066
+ sender2.onerror = senderOnError;
2067
+ if (socket.setTimeout)
2068
+ socket.setTimeout(0);
2069
+ if (socket.setNoDelay)
2070
+ socket.setNoDelay();
2071
+ if (head.length > 0)
2072
+ socket.unshift(head);
2073
+ socket.on("close", socketOnClose);
2074
+ socket.on("data", socketOnData);
2075
+ socket.on("end", socketOnEnd);
2076
+ socket.on("error", socketOnError);
2077
+ this._readyState = WebSocket.OPEN;
2078
+ this.emit("open");
2079
+ }
2080
+ emitClose() {
2081
+ if (!this._socket) {
2082
+ this._readyState = WebSocket.CLOSED;
2083
+ this.emit("close", this._closeCode, this._closeMessage);
2084
+ return;
2085
+ }
2086
+ if (this._extensions[PerMessageDeflate.extensionName]) {
2087
+ this._extensions[PerMessageDeflate.extensionName].cleanup();
2088
+ }
2089
+ this._receiver.removeAllListeners();
2090
+ this._readyState = WebSocket.CLOSED;
2091
+ this.emit("close", this._closeCode, this._closeMessage);
2092
+ }
2093
+ close(code, data) {
2094
+ if (this.readyState === WebSocket.CLOSED)
2095
+ return;
2096
+ if (this.readyState === WebSocket.CONNECTING) {
2097
+ const msg = "WebSocket was closed before the connection was established";
2098
+ abortHandshake(this, this._req, msg);
2099
+ return;
2100
+ }
2101
+ if (this.readyState === WebSocket.CLOSING) {
2102
+ if (this._closeFrameSent && (this._closeFrameReceived || this._receiver._writableState.errorEmitted)) {
2103
+ this._socket.end();
2104
+ }
2105
+ return;
2106
+ }
2107
+ this._readyState = WebSocket.CLOSING;
2108
+ this._sender.close(code, data, !this._isServer, (err) => {
2109
+ if (err)
2110
+ return;
2111
+ this._closeFrameSent = true;
2112
+ if (this._closeFrameReceived || this._receiver._writableState.errorEmitted) {
2113
+ this._socket.end();
2114
+ }
2115
+ });
2116
+ setCloseTimer(this);
2117
+ }
2118
+ pause() {
2119
+ if (this.readyState === WebSocket.CONNECTING || this.readyState === WebSocket.CLOSED) {
2120
+ return;
2121
+ }
2122
+ this._paused = true;
2123
+ this._socket.pause();
2124
+ }
2125
+ ping(data, mask, cb) {
2126
+ if (this.readyState === WebSocket.CONNECTING) {
2127
+ throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
2128
+ }
2129
+ if (typeof data === "function") {
2130
+ cb = data;
2131
+ data = mask = undefined;
2132
+ } else if (typeof mask === "function") {
2133
+ cb = mask;
2134
+ mask = undefined;
2135
+ }
2136
+ if (typeof data === "number")
2137
+ data = data.toString();
2138
+ if (this.readyState !== WebSocket.OPEN) {
2139
+ sendAfterClose(this, data, cb);
2140
+ return;
2141
+ }
2142
+ if (mask === undefined)
2143
+ mask = !this._isServer;
2144
+ this._sender.ping(data || EMPTY_BUFFER, mask, cb);
2145
+ }
2146
+ pong(data, mask, cb) {
2147
+ if (this.readyState === WebSocket.CONNECTING) {
2148
+ throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
2149
+ }
2150
+ if (typeof data === "function") {
2151
+ cb = data;
2152
+ data = mask = undefined;
2153
+ } else if (typeof mask === "function") {
2154
+ cb = mask;
2155
+ mask = undefined;
2156
+ }
2157
+ if (typeof data === "number")
2158
+ data = data.toString();
2159
+ if (this.readyState !== WebSocket.OPEN) {
2160
+ sendAfterClose(this, data, cb);
2161
+ return;
2162
+ }
2163
+ if (mask === undefined)
2164
+ mask = !this._isServer;
2165
+ this._sender.pong(data || EMPTY_BUFFER, mask, cb);
2166
+ }
2167
+ resume() {
2168
+ if (this.readyState === WebSocket.CONNECTING || this.readyState === WebSocket.CLOSED) {
2169
+ return;
2170
+ }
2171
+ this._paused = false;
2172
+ if (!this._receiver._writableState.needDrain)
2173
+ this._socket.resume();
2174
+ }
2175
+ send(data, options, cb) {
2176
+ if (this.readyState === WebSocket.CONNECTING) {
2177
+ throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
2178
+ }
2179
+ if (typeof options === "function") {
2180
+ cb = options;
2181
+ options = {};
2182
+ }
2183
+ if (typeof data === "number")
2184
+ data = data.toString();
2185
+ if (this.readyState !== WebSocket.OPEN) {
2186
+ sendAfterClose(this, data, cb);
2187
+ return;
2188
+ }
2189
+ const opts = {
2190
+ binary: typeof data !== "string",
2191
+ mask: !this._isServer,
2192
+ compress: true,
2193
+ fin: true,
2194
+ ...options
2195
+ };
2196
+ if (!this._extensions[PerMessageDeflate.extensionName]) {
2197
+ opts.compress = false;
2198
+ }
2199
+ this._sender.send(data || EMPTY_BUFFER, opts, cb);
2200
+ }
2201
+ terminate() {
2202
+ if (this.readyState === WebSocket.CLOSED)
2203
+ return;
2204
+ if (this.readyState === WebSocket.CONNECTING) {
2205
+ const msg = "WebSocket was closed before the connection was established";
2206
+ abortHandshake(this, this._req, msg);
2207
+ return;
2208
+ }
2209
+ if (this._socket) {
2210
+ this._readyState = WebSocket.CLOSING;
2211
+ this._socket.destroy();
2212
+ }
2213
+ }
2214
+ }
2215
+ Object.defineProperty(WebSocket, "CONNECTING", {
2216
+ enumerable: true,
2217
+ value: readyStates.indexOf("CONNECTING")
2218
+ });
2219
+ Object.defineProperty(WebSocket.prototype, "CONNECTING", {
2220
+ enumerable: true,
2221
+ value: readyStates.indexOf("CONNECTING")
2222
+ });
2223
+ Object.defineProperty(WebSocket, "OPEN", {
2224
+ enumerable: true,
2225
+ value: readyStates.indexOf("OPEN")
2226
+ });
2227
+ Object.defineProperty(WebSocket.prototype, "OPEN", {
2228
+ enumerable: true,
2229
+ value: readyStates.indexOf("OPEN")
2230
+ });
2231
+ Object.defineProperty(WebSocket, "CLOSING", {
2232
+ enumerable: true,
2233
+ value: readyStates.indexOf("CLOSING")
2234
+ });
2235
+ Object.defineProperty(WebSocket.prototype, "CLOSING", {
2236
+ enumerable: true,
2237
+ value: readyStates.indexOf("CLOSING")
2238
+ });
2239
+ Object.defineProperty(WebSocket, "CLOSED", {
2240
+ enumerable: true,
2241
+ value: readyStates.indexOf("CLOSED")
2242
+ });
2243
+ Object.defineProperty(WebSocket.prototype, "CLOSED", {
2244
+ enumerable: true,
2245
+ value: readyStates.indexOf("CLOSED")
2246
+ });
2247
+ [
2248
+ "binaryType",
2249
+ "bufferedAmount",
2250
+ "extensions",
2251
+ "isPaused",
2252
+ "protocol",
2253
+ "readyState",
2254
+ "url"
2255
+ ].forEach((property) => {
2256
+ Object.defineProperty(WebSocket.prototype, property, { enumerable: true });
2257
+ });
2258
+ ["open", "error", "close", "message"].forEach((method) => {
2259
+ Object.defineProperty(WebSocket.prototype, `on${method}`, {
2260
+ enumerable: true,
2261
+ get() {
2262
+ for (const listener of this.listeners(method)) {
2263
+ if (listener[kForOnEventAttribute])
2264
+ return listener[kListener];
2265
+ }
2266
+ return null;
2267
+ },
2268
+ set(handler) {
2269
+ for (const listener of this.listeners(method)) {
2270
+ if (listener[kForOnEventAttribute]) {
2271
+ this.removeListener(method, listener);
2272
+ break;
2273
+ }
2274
+ }
2275
+ if (typeof handler !== "function")
2276
+ return;
2277
+ this.addEventListener(method, handler, {
2278
+ [kForOnEventAttribute]: true
2279
+ });
2280
+ }
2281
+ });
2282
+ });
2283
+ WebSocket.prototype.addEventListener = addEventListener;
2284
+ WebSocket.prototype.removeEventListener = removeEventListener;
2285
+ module.exports = WebSocket;
2286
+ function initAsClient(websocket2, address, protocols, options) {
2287
+ const opts = {
2288
+ allowSynchronousEvents: true,
2289
+ autoPong: true,
2290
+ closeTimeout: CLOSE_TIMEOUT,
2291
+ protocolVersion: protocolVersions[1],
2292
+ maxPayload: 100 * 1024 * 1024,
2293
+ skipUTF8Validation: false,
2294
+ perMessageDeflate: true,
2295
+ followRedirects: false,
2296
+ maxRedirects: 10,
2297
+ ...options,
2298
+ socketPath: undefined,
2299
+ hostname: undefined,
2300
+ protocol: undefined,
2301
+ timeout: undefined,
2302
+ method: "GET",
2303
+ host: undefined,
2304
+ path: undefined,
2305
+ port: undefined
2306
+ };
2307
+ websocket2._autoPong = opts.autoPong;
2308
+ websocket2._closeTimeout = opts.closeTimeout;
2309
+ if (!protocolVersions.includes(opts.protocolVersion)) {
2310
+ throw new RangeError(`Unsupported protocol version: ${opts.protocolVersion} ` + `(supported versions: ${protocolVersions.join(", ")})`);
2311
+ }
2312
+ let parsedUrl;
2313
+ if (address instanceof URL2) {
2314
+ parsedUrl = address;
2315
+ } else {
2316
+ try {
2317
+ parsedUrl = new URL2(address);
2318
+ } catch (e) {
2319
+ throw new SyntaxError(`Invalid URL: ${address}`);
2320
+ }
2321
+ }
2322
+ if (parsedUrl.protocol === "http:") {
2323
+ parsedUrl.protocol = "ws:";
2324
+ } else if (parsedUrl.protocol === "https:") {
2325
+ parsedUrl.protocol = "wss:";
2326
+ }
2327
+ websocket2._url = parsedUrl.href;
2328
+ const isSecure = parsedUrl.protocol === "wss:";
2329
+ const isIpcUrl = parsedUrl.protocol === "ws+unix:";
2330
+ let invalidUrlMessage;
2331
+ if (parsedUrl.protocol !== "ws:" && !isSecure && !isIpcUrl) {
2332
+ invalidUrlMessage = `The URL's protocol must be one of "ws:", "wss:", ` + '"http:", "https:", or "ws+unix:"';
2333
+ } else if (isIpcUrl && !parsedUrl.pathname) {
2334
+ invalidUrlMessage = "The URL's pathname is empty";
2335
+ } else if (parsedUrl.hash) {
2336
+ invalidUrlMessage = "The URL contains a fragment identifier";
2337
+ }
2338
+ if (invalidUrlMessage) {
2339
+ const err = new SyntaxError(invalidUrlMessage);
2340
+ if (websocket2._redirects === 0) {
2341
+ throw err;
2342
+ } else {
2343
+ emitErrorAndClose(websocket2, err);
2344
+ return;
2345
+ }
2346
+ }
2347
+ const defaultPort = isSecure ? 443 : 80;
2348
+ const key = randomBytes(16).toString("base64");
2349
+ const request = isSecure ? https.request : http.request;
2350
+ const protocolSet = new Set;
2351
+ let perMessageDeflate;
2352
+ opts.createConnection = opts.createConnection || (isSecure ? tlsConnect : netConnect);
2353
+ opts.defaultPort = opts.defaultPort || defaultPort;
2354
+ opts.port = parsedUrl.port || defaultPort;
2355
+ opts.host = parsedUrl.hostname.startsWith("[") ? parsedUrl.hostname.slice(1, -1) : parsedUrl.hostname;
2356
+ opts.headers = {
2357
+ ...opts.headers,
2358
+ "Sec-WebSocket-Version": opts.protocolVersion,
2359
+ "Sec-WebSocket-Key": key,
2360
+ Connection: "Upgrade",
2361
+ Upgrade: "websocket"
2362
+ };
2363
+ opts.path = parsedUrl.pathname + parsedUrl.search;
2364
+ opts.timeout = opts.handshakeTimeout;
2365
+ if (opts.perMessageDeflate) {
2366
+ perMessageDeflate = new PerMessageDeflate(opts.perMessageDeflate !== true ? opts.perMessageDeflate : {}, false, opts.maxPayload);
2367
+ opts.headers["Sec-WebSocket-Extensions"] = format({
2368
+ [PerMessageDeflate.extensionName]: perMessageDeflate.offer()
2369
+ });
2370
+ }
2371
+ if (protocols.length) {
2372
+ for (const protocol of protocols) {
2373
+ if (typeof protocol !== "string" || !subprotocolRegex.test(protocol) || protocolSet.has(protocol)) {
2374
+ throw new SyntaxError("An invalid or duplicated subprotocol was specified");
2375
+ }
2376
+ protocolSet.add(protocol);
2377
+ }
2378
+ opts.headers["Sec-WebSocket-Protocol"] = protocols.join(",");
2379
+ }
2380
+ if (opts.origin) {
2381
+ if (opts.protocolVersion < 13) {
2382
+ opts.headers["Sec-WebSocket-Origin"] = opts.origin;
2383
+ } else {
2384
+ opts.headers.Origin = opts.origin;
2385
+ }
2386
+ }
2387
+ if (parsedUrl.username || parsedUrl.password) {
2388
+ opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
2389
+ }
2390
+ if (isIpcUrl) {
2391
+ const parts = opts.path.split(":");
2392
+ opts.socketPath = parts[0];
2393
+ opts.path = parts[1];
2394
+ }
2395
+ let req;
2396
+ if (opts.followRedirects) {
2397
+ if (websocket2._redirects === 0) {
2398
+ websocket2._originalIpc = isIpcUrl;
2399
+ websocket2._originalSecure = isSecure;
2400
+ websocket2._originalHostOrSocketPath = isIpcUrl ? opts.socketPath : parsedUrl.host;
2401
+ const headers = options && options.headers;
2402
+ options = { ...options, headers: {} };
2403
+ if (headers) {
2404
+ for (const [key2, value] of Object.entries(headers)) {
2405
+ options.headers[key2.toLowerCase()] = value;
2406
+ }
2407
+ }
2408
+ } else if (websocket2.listenerCount("redirect") === 0) {
2409
+ const isSameHost = isIpcUrl ? websocket2._originalIpc ? opts.socketPath === websocket2._originalHostOrSocketPath : false : websocket2._originalIpc ? false : parsedUrl.host === websocket2._originalHostOrSocketPath;
2410
+ if (!isSameHost || websocket2._originalSecure && !isSecure) {
2411
+ delete opts.headers.authorization;
2412
+ delete opts.headers.cookie;
2413
+ if (!isSameHost)
2414
+ delete opts.headers.host;
2415
+ opts.auth = undefined;
2416
+ }
2417
+ }
2418
+ if (opts.auth && !options.headers.authorization) {
2419
+ options.headers.authorization = "Basic " + Buffer.from(opts.auth).toString("base64");
2420
+ }
2421
+ req = websocket2._req = request(opts);
2422
+ if (websocket2._redirects) {
2423
+ websocket2.emit("redirect", websocket2.url, req);
2424
+ }
2425
+ } else {
2426
+ req = websocket2._req = request(opts);
2427
+ }
2428
+ if (opts.timeout) {
2429
+ req.on("timeout", () => {
2430
+ abortHandshake(websocket2, req, "Opening handshake has timed out");
2431
+ });
2432
+ }
2433
+ req.on("error", (err) => {
2434
+ if (req === null || req[kAborted])
2435
+ return;
2436
+ req = websocket2._req = null;
2437
+ emitErrorAndClose(websocket2, err);
2438
+ });
2439
+ req.on("response", (res) => {
2440
+ const location2 = res.headers.location;
2441
+ const statusCode = res.statusCode;
2442
+ if (location2 && opts.followRedirects && statusCode >= 300 && statusCode < 400) {
2443
+ if (++websocket2._redirects > opts.maxRedirects) {
2444
+ abortHandshake(websocket2, req, "Maximum redirects exceeded");
2445
+ return;
2446
+ }
2447
+ req.abort();
2448
+ let addr;
2449
+ try {
2450
+ addr = new URL2(location2, address);
2451
+ } catch (e) {
2452
+ const err = new SyntaxError(`Invalid URL: ${location2}`);
2453
+ emitErrorAndClose(websocket2, err);
2454
+ return;
2455
+ }
2456
+ initAsClient(websocket2, addr, protocols, options);
2457
+ } else if (!websocket2.emit("unexpected-response", req, res)) {
2458
+ abortHandshake(websocket2, req, `Unexpected server response: ${res.statusCode}`);
2459
+ }
2460
+ });
2461
+ req.on("upgrade", (res, socket, head) => {
2462
+ websocket2.emit("upgrade", res);
2463
+ if (websocket2.readyState !== WebSocket.CONNECTING)
2464
+ return;
2465
+ req = websocket2._req = null;
2466
+ const upgrade = res.headers.upgrade;
2467
+ if (upgrade === undefined || upgrade.toLowerCase() !== "websocket") {
2468
+ abortHandshake(websocket2, socket, "Invalid Upgrade header");
2469
+ return;
2470
+ }
2471
+ const digest = createHash("sha1").update(key + GUID).digest("base64");
2472
+ if (res.headers["sec-websocket-accept"] !== digest) {
2473
+ abortHandshake(websocket2, socket, "Invalid Sec-WebSocket-Accept header");
2474
+ return;
2475
+ }
2476
+ const serverProt = res.headers["sec-websocket-protocol"];
2477
+ let protError;
2478
+ if (serverProt !== undefined) {
2479
+ if (!protocolSet.size) {
2480
+ protError = "Server sent a subprotocol but none was requested";
2481
+ } else if (!protocolSet.has(serverProt)) {
2482
+ protError = "Server sent an invalid subprotocol";
2483
+ }
2484
+ } else if (protocolSet.size) {
2485
+ protError = "Server sent no subprotocol";
2486
+ }
2487
+ if (protError) {
2488
+ abortHandshake(websocket2, socket, protError);
2489
+ return;
2490
+ }
2491
+ if (serverProt)
2492
+ websocket2._protocol = serverProt;
2493
+ const secWebSocketExtensions = res.headers["sec-websocket-extensions"];
2494
+ if (secWebSocketExtensions !== undefined) {
2495
+ if (!perMessageDeflate) {
2496
+ const message = "Server sent a Sec-WebSocket-Extensions header but no extension " + "was requested";
2497
+ abortHandshake(websocket2, socket, message);
2498
+ return;
2499
+ }
2500
+ let extensions;
2501
+ try {
2502
+ extensions = parse6(secWebSocketExtensions);
2503
+ } catch (err) {
2504
+ const message = "Invalid Sec-WebSocket-Extensions header";
2505
+ abortHandshake(websocket2, socket, message);
2506
+ return;
2507
+ }
2508
+ const extensionNames = Object.keys(extensions);
2509
+ if (extensionNames.length !== 1 || extensionNames[0] !== PerMessageDeflate.extensionName) {
2510
+ const message = "Server indicated an extension that was not requested";
2511
+ abortHandshake(websocket2, socket, message);
2512
+ return;
2513
+ }
2514
+ try {
2515
+ perMessageDeflate.accept(extensions[PerMessageDeflate.extensionName]);
2516
+ } catch (err) {
2517
+ const message = "Invalid Sec-WebSocket-Extensions header";
2518
+ abortHandshake(websocket2, socket, message);
2519
+ return;
2520
+ }
2521
+ websocket2._extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
2522
+ }
2523
+ websocket2.setSocket(socket, head, {
2524
+ allowSynchronousEvents: opts.allowSynchronousEvents,
2525
+ generateMask: opts.generateMask,
2526
+ maxPayload: opts.maxPayload,
2527
+ skipUTF8Validation: opts.skipUTF8Validation
2528
+ });
2529
+ });
2530
+ if (opts.finishRequest) {
2531
+ opts.finishRequest(req, websocket2);
2532
+ } else {
2533
+ req.end();
2534
+ }
2535
+ }
2536
+ function emitErrorAndClose(websocket2, err) {
2537
+ websocket2._readyState = WebSocket.CLOSING;
2538
+ websocket2._errorEmitted = true;
2539
+ websocket2.emit("error", err);
2540
+ websocket2.emitClose();
2541
+ }
2542
+ function netConnect(options) {
2543
+ options.path = options.socketPath;
2544
+ return net.connect(options);
2545
+ }
2546
+ function tlsConnect(options) {
2547
+ options.path = undefined;
2548
+ if (!options.servername && options.servername !== "") {
2549
+ options.servername = net.isIP(options.host) ? "" : options.host;
2550
+ }
2551
+ return tls.connect(options);
2552
+ }
2553
+ function abortHandshake(websocket2, stream2, message) {
2554
+ websocket2._readyState = WebSocket.CLOSING;
2555
+ const err = new Error(message);
2556
+ Error.captureStackTrace(err, abortHandshake);
2557
+ if (stream2.setHeader) {
2558
+ stream2[kAborted] = true;
2559
+ stream2.abort();
2560
+ if (stream2.socket && !stream2.socket.destroyed) {
2561
+ stream2.socket.destroy();
2562
+ }
2563
+ process.nextTick(emitErrorAndClose, websocket2, err);
2564
+ } else {
2565
+ stream2.destroy(err);
2566
+ stream2.once("error", websocket2.emit.bind(websocket2, "error"));
2567
+ stream2.once("close", websocket2.emitClose.bind(websocket2));
2568
+ }
2569
+ }
2570
+ function sendAfterClose(websocket2, data, cb) {
2571
+ if (data) {
2572
+ const length = isBlob(data) ? data.size : toBuffer(data).length;
2573
+ if (websocket2._socket)
2574
+ websocket2._sender._bufferedBytes += length;
2575
+ else
2576
+ websocket2._bufferedAmount += length;
2577
+ }
2578
+ if (cb) {
2579
+ const err = new Error(`WebSocket is not open: readyState ${websocket2.readyState} ` + `(${readyStates[websocket2.readyState]})`);
2580
+ process.nextTick(cb, err);
2581
+ }
2582
+ }
2583
+ function receiverOnConclude(code, reason) {
2584
+ const websocket2 = this[kWebSocket];
2585
+ websocket2._closeFrameReceived = true;
2586
+ websocket2._closeMessage = reason;
2587
+ websocket2._closeCode = code;
2588
+ if (websocket2._socket[kWebSocket] === undefined)
2589
+ return;
2590
+ websocket2._socket.removeListener("data", socketOnData);
2591
+ process.nextTick(resume, websocket2._socket);
2592
+ if (code === 1005)
2593
+ websocket2.close();
2594
+ else
2595
+ websocket2.close(code, reason);
2596
+ }
2597
+ function receiverOnDrain() {
2598
+ const websocket2 = this[kWebSocket];
2599
+ if (!websocket2.isPaused)
2600
+ websocket2._socket.resume();
2601
+ }
2602
+ function receiverOnError(err) {
2603
+ const websocket2 = this[kWebSocket];
2604
+ if (websocket2._socket[kWebSocket] !== undefined) {
2605
+ websocket2._socket.removeListener("data", socketOnData);
2606
+ process.nextTick(resume, websocket2._socket);
2607
+ websocket2.close(err[kStatusCode]);
2608
+ }
2609
+ if (!websocket2._errorEmitted) {
2610
+ websocket2._errorEmitted = true;
2611
+ websocket2.emit("error", err);
2612
+ }
2613
+ }
2614
+ function receiverOnFinish() {
2615
+ this[kWebSocket].emitClose();
2616
+ }
2617
+ function receiverOnMessage(data, isBinary) {
2618
+ this[kWebSocket].emit("message", data, isBinary);
2619
+ }
2620
+ function receiverOnPing(data) {
2621
+ const websocket2 = this[kWebSocket];
2622
+ if (websocket2._autoPong)
2623
+ websocket2.pong(data, !this._isServer, NOOP);
2624
+ websocket2.emit("ping", data);
2625
+ }
2626
+ function receiverOnPong(data) {
2627
+ this[kWebSocket].emit("pong", data);
2628
+ }
2629
+ function resume(stream2) {
2630
+ stream2.resume();
2631
+ }
2632
+ function senderOnError(err) {
2633
+ const websocket2 = this[kWebSocket];
2634
+ if (websocket2.readyState === WebSocket.CLOSED)
2635
+ return;
2636
+ if (websocket2.readyState === WebSocket.OPEN) {
2637
+ websocket2._readyState = WebSocket.CLOSING;
2638
+ setCloseTimer(websocket2);
2639
+ }
2640
+ this._socket.end();
2641
+ if (!websocket2._errorEmitted) {
2642
+ websocket2._errorEmitted = true;
2643
+ websocket2.emit("error", err);
2644
+ }
2645
+ }
2646
+ function setCloseTimer(websocket2) {
2647
+ websocket2._closeTimer = setTimeout(websocket2._socket.destroy.bind(websocket2._socket), websocket2._closeTimeout);
2648
+ }
2649
+ function socketOnClose() {
2650
+ const websocket2 = this[kWebSocket];
2651
+ this.removeListener("close", socketOnClose);
2652
+ this.removeListener("data", socketOnData);
2653
+ this.removeListener("end", socketOnEnd);
2654
+ websocket2._readyState = WebSocket.CLOSING;
2655
+ if (!this._readableState.endEmitted && !websocket2._closeFrameReceived && !websocket2._receiver._writableState.errorEmitted && this._readableState.length !== 0) {
2656
+ const chunk = this.read(this._readableState.length);
2657
+ websocket2._receiver.write(chunk);
2658
+ }
2659
+ websocket2._receiver.end();
2660
+ this[kWebSocket] = undefined;
2661
+ clearTimeout(websocket2._closeTimer);
2662
+ if (websocket2._receiver._writableState.finished || websocket2._receiver._writableState.errorEmitted) {
2663
+ websocket2.emitClose();
2664
+ } else {
2665
+ websocket2._receiver.on("error", receiverOnFinish);
2666
+ websocket2._receiver.on("finish", receiverOnFinish);
2667
+ }
2668
+ }
2669
+ function socketOnData(chunk) {
2670
+ if (!this[kWebSocket]._receiver.write(chunk)) {
2671
+ this.pause();
2672
+ }
2673
+ }
2674
+ function socketOnEnd() {
2675
+ const websocket2 = this[kWebSocket];
2676
+ websocket2._readyState = WebSocket.CLOSING;
2677
+ websocket2._receiver.end();
2678
+ this.end();
2679
+ }
2680
+ function socketOnError() {
2681
+ const websocket2 = this[kWebSocket];
2682
+ this.removeListener("error", socketOnError);
2683
+ this.on("error", NOOP);
2684
+ if (websocket2) {
2685
+ websocket2._readyState = WebSocket.CLOSING;
2686
+ this.destroy();
2687
+ }
2688
+ }
2689
+ });
2690
+
2691
+ // node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/stream.js
2692
+ var require_stream = __commonJS((exports, module) => {
2693
+ var WebSocket = require_websocket();
2694
+ var { Duplex } = __require("stream");
2695
+ function emitClose(stream2) {
2696
+ stream2.emit("close");
2697
+ }
2698
+ function duplexOnEnd() {
2699
+ if (!this.destroyed && this._writableState.finished) {
2700
+ this.destroy();
2701
+ }
2702
+ }
2703
+ function duplexOnError(err) {
2704
+ this.removeListener("error", duplexOnError);
2705
+ this.destroy();
2706
+ if (this.listenerCount("error") === 0) {
2707
+ this.emit("error", err);
2708
+ }
2709
+ }
2710
+ function createWebSocketStream(ws, options) {
2711
+ let terminateOnDestroy = true;
2712
+ const duplex = new Duplex({
2713
+ ...options,
2714
+ autoDestroy: false,
2715
+ emitClose: false,
2716
+ objectMode: false,
2717
+ writableObjectMode: false
2718
+ });
2719
+ ws.on("message", function message(msg, isBinary) {
2720
+ const data = !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
2721
+ if (!duplex.push(data))
2722
+ ws.pause();
2723
+ });
2724
+ ws.once("error", function error49(err) {
2725
+ if (duplex.destroyed)
2726
+ return;
2727
+ terminateOnDestroy = false;
2728
+ duplex.destroy(err);
2729
+ });
2730
+ ws.once("close", function close() {
2731
+ if (duplex.destroyed)
2732
+ return;
2733
+ duplex.push(null);
2734
+ });
2735
+ duplex._destroy = function(err, callback) {
2736
+ if (ws.readyState === ws.CLOSED) {
2737
+ callback(err);
2738
+ process.nextTick(emitClose, duplex);
2739
+ return;
2740
+ }
2741
+ let called = false;
2742
+ ws.once("error", function error49(err2) {
2743
+ called = true;
2744
+ callback(err2);
2745
+ });
2746
+ ws.once("close", function close() {
2747
+ if (!called)
2748
+ callback(err);
2749
+ process.nextTick(emitClose, duplex);
2750
+ });
2751
+ if (terminateOnDestroy)
2752
+ ws.terminate();
2753
+ };
2754
+ duplex._final = function(callback) {
2755
+ if (ws.readyState === ws.CONNECTING) {
2756
+ ws.once("open", function open() {
2757
+ duplex._final(callback);
2758
+ });
2759
+ return;
2760
+ }
2761
+ if (ws._socket === null)
2762
+ return;
2763
+ if (ws._socket._writableState.finished) {
2764
+ callback();
2765
+ if (duplex._readableState.endEmitted)
2766
+ duplex.destroy();
2767
+ } else {
2768
+ ws._socket.once("finish", function finish() {
2769
+ callback();
2770
+ });
2771
+ ws.close();
2772
+ }
2773
+ };
2774
+ duplex._read = function() {
2775
+ if (ws.isPaused)
2776
+ ws.resume();
2777
+ };
2778
+ duplex._write = function(chunk, encoding, callback) {
2779
+ if (ws.readyState === ws.CONNECTING) {
2780
+ ws.once("open", function open() {
2781
+ duplex._write(chunk, encoding, callback);
2782
+ });
2783
+ return;
2784
+ }
2785
+ ws.send(chunk, callback);
2786
+ };
2787
+ duplex.on("end", duplexOnEnd);
2788
+ duplex.on("error", duplexOnError);
2789
+ return duplex;
2790
+ }
2791
+ module.exports = createWebSocketStream;
2792
+ });
2793
+
2794
+ // node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/subprotocol.js
2795
+ var require_subprotocol = __commonJS((exports, module) => {
2796
+ var { tokenChars } = require_validation();
2797
+ function parse6(header) {
2798
+ const protocols = new Set;
2799
+ let start = -1;
2800
+ let end = -1;
2801
+ let i = 0;
2802
+ for (i;i < header.length; i++) {
2803
+ const code = header.charCodeAt(i);
2804
+ if (end === -1 && tokenChars[code] === 1) {
2805
+ if (start === -1)
2806
+ start = i;
2807
+ } else if (i !== 0 && (code === 32 || code === 9)) {
2808
+ if (end === -1 && start !== -1)
2809
+ end = i;
2810
+ } else if (code === 44) {
2811
+ if (start === -1) {
2812
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2813
+ }
2814
+ if (end === -1)
2815
+ end = i;
2816
+ const protocol2 = header.slice(start, end);
2817
+ if (protocols.has(protocol2)) {
2818
+ throw new SyntaxError(`The "${protocol2}" subprotocol is duplicated`);
2819
+ }
2820
+ protocols.add(protocol2);
2821
+ start = end = -1;
2822
+ } else {
2823
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2824
+ }
2825
+ }
2826
+ if (start === -1 || end !== -1) {
2827
+ throw new SyntaxError("Unexpected end of input");
2828
+ }
2829
+ const protocol = header.slice(start, i);
2830
+ if (protocols.has(protocol)) {
2831
+ throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
2832
+ }
2833
+ protocols.add(protocol);
2834
+ return protocols;
2835
+ }
2836
+ module.exports = { parse: parse6 };
2837
+ });
2838
+
2839
+ // node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/websocket-server.js
2840
+ var require_websocket_server = __commonJS((exports, module) => {
2841
+ var EventEmitter4 = __require("events");
2842
+ var http = __require("http");
2843
+ var { Duplex } = __require("stream");
2844
+ var { createHash } = __require("crypto");
2845
+ var extension2 = require_extension();
2846
+ var PerMessageDeflate = require_permessage_deflate();
2847
+ var subprotocol2 = require_subprotocol();
2848
+ var WebSocket = require_websocket();
2849
+ var { CLOSE_TIMEOUT, GUID, kWebSocket } = require_constants();
2850
+ var keyRegex = /^[+/0-9A-Za-z]{22}==$/;
2851
+ var RUNNING = 0;
2852
+ var CLOSING = 1;
2853
+ var CLOSED = 2;
2854
+
2855
+ class WebSocketServer extends EventEmitter4 {
2856
+ constructor(options, callback) {
2857
+ super();
2858
+ options = {
2859
+ allowSynchronousEvents: true,
2860
+ autoPong: true,
2861
+ maxPayload: 100 * 1024 * 1024,
2862
+ skipUTF8Validation: false,
2863
+ perMessageDeflate: false,
2864
+ handleProtocols: null,
2865
+ clientTracking: true,
2866
+ closeTimeout: CLOSE_TIMEOUT,
2867
+ verifyClient: null,
2868
+ noServer: false,
2869
+ backlog: null,
2870
+ server: null,
2871
+ host: null,
2872
+ path: null,
2873
+ port: null,
2874
+ WebSocket,
2875
+ ...options
2876
+ };
2877
+ if (options.port == null && !options.server && !options.noServer || options.port != null && (options.server || options.noServer) || options.server && options.noServer) {
2878
+ throw new TypeError('One and only one of the "port", "server", or "noServer" options ' + "must be specified");
2879
+ }
2880
+ if (options.port != null) {
2881
+ this._server = http.createServer((req, res) => {
2882
+ const body = http.STATUS_CODES[426];
2883
+ res.writeHead(426, {
2884
+ "Content-Length": body.length,
2885
+ "Content-Type": "text/plain"
2886
+ });
2887
+ res.end(body);
2888
+ });
2889
+ this._server.listen(options.port, options.host, options.backlog, callback);
2890
+ } else if (options.server) {
2891
+ this._server = options.server;
2892
+ }
2893
+ if (this._server) {
2894
+ const emitConnection = this.emit.bind(this, "connection");
2895
+ this._removeListeners = addListeners(this._server, {
2896
+ listening: this.emit.bind(this, "listening"),
2897
+ error: this.emit.bind(this, "error"),
2898
+ upgrade: (req, socket, head) => {
2899
+ this.handleUpgrade(req, socket, head, emitConnection);
2900
+ }
2901
+ });
2902
+ }
2903
+ if (options.perMessageDeflate === true)
2904
+ options.perMessageDeflate = {};
2905
+ if (options.clientTracking) {
2906
+ this.clients = new Set;
2907
+ this._shouldEmitClose = false;
2908
+ }
2909
+ this.options = options;
2910
+ this._state = RUNNING;
2911
+ }
2912
+ address() {
2913
+ if (this.options.noServer) {
2914
+ throw new Error('The server is operating in "noServer" mode');
2915
+ }
2916
+ if (!this._server)
2917
+ return null;
2918
+ return this._server.address();
2919
+ }
2920
+ close(cb) {
2921
+ if (this._state === CLOSED) {
2922
+ if (cb) {
2923
+ this.once("close", () => {
2924
+ cb(new Error("The server is not running"));
2925
+ });
2926
+ }
2927
+ process.nextTick(emitClose, this);
2928
+ return;
2929
+ }
2930
+ if (cb)
2931
+ this.once("close", cb);
2932
+ if (this._state === CLOSING)
2933
+ return;
2934
+ this._state = CLOSING;
2935
+ if (this.options.noServer || this.options.server) {
2936
+ if (this._server) {
2937
+ this._removeListeners();
2938
+ this._removeListeners = this._server = null;
2939
+ }
2940
+ if (this.clients) {
2941
+ if (!this.clients.size) {
2942
+ process.nextTick(emitClose, this);
2943
+ } else {
2944
+ this._shouldEmitClose = true;
2945
+ }
2946
+ } else {
2947
+ process.nextTick(emitClose, this);
2948
+ }
2949
+ } else {
2950
+ const server = this._server;
2951
+ this._removeListeners();
2952
+ this._removeListeners = this._server = null;
2953
+ server.close(() => {
2954
+ emitClose(this);
2955
+ });
70
2956
  }
71
- return !r2 && i2 && (g = i2), i2 || !r2 && g;
72
- }, O = function(t2, e2) {
73
- if (S(t2))
74
- return t2.clone();
75
- var n2 = typeof e2 == "object" ? e2 : {};
76
- return n2.date = t2, n2.args = arguments, new _(n2);
77
- }, b = v;
78
- b.l = w, b.i = S, b.w = function(t2, e2) {
79
- return O(t2, { locale: e2.$L, utc: e2.$u, x: e2.$x, $offset: e2.$offset });
80
- };
81
- var _ = function() {
82
- function M2(t2) {
83
- this.$L = w(t2.locale, null, true), this.parse(t2), this.$x = this.$x || t2.x || {}, this[p] = true;
2957
+ }
2958
+ shouldHandle(req) {
2959
+ if (this.options.path) {
2960
+ const index2 = req.url.indexOf("?");
2961
+ const pathname = index2 !== -1 ? req.url.slice(0, index2) : req.url;
2962
+ if (pathname !== this.options.path)
2963
+ return false;
84
2964
  }
85
- var m2 = M2.prototype;
86
- return m2.parse = function(t2) {
87
- this.$d = function(t3) {
88
- var { date: e2, utc: n2 } = t3;
89
- if (e2 === null)
90
- return new Date(NaN);
91
- if (b.u(e2))
92
- return new Date;
93
- if (e2 instanceof Date)
94
- return new Date(e2);
95
- if (typeof e2 == "string" && !/Z$/i.test(e2)) {
96
- var r2 = e2.match($);
97
- if (r2) {
98
- var i2 = r2[2] - 1 || 0, s2 = (r2[7] || "0").substring(0, 3);
99
- return n2 ? new Date(Date.UTC(r2[1], i2, r2[3] || 1, r2[4] || 0, r2[5] || 0, r2[6] || 0, s2)) : new Date(r2[1], i2, r2[3] || 1, r2[4] || 0, r2[5] || 0, r2[6] || 0, s2);
100
- }
2965
+ return true;
2966
+ }
2967
+ handleUpgrade(req, socket, head, cb) {
2968
+ socket.on("error", socketOnError);
2969
+ const key = req.headers["sec-websocket-key"];
2970
+ const upgrade = req.headers.upgrade;
2971
+ const version3 = +req.headers["sec-websocket-version"];
2972
+ if (req.method !== "GET") {
2973
+ const message = "Invalid HTTP method";
2974
+ abortHandshakeOrEmitwsClientError(this, req, socket, 405, message);
2975
+ return;
2976
+ }
2977
+ if (upgrade === undefined || upgrade.toLowerCase() !== "websocket") {
2978
+ const message = "Invalid Upgrade header";
2979
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
2980
+ return;
2981
+ }
2982
+ if (key === undefined || !keyRegex.test(key)) {
2983
+ const message = "Missing or invalid Sec-WebSocket-Key header";
2984
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
2985
+ return;
2986
+ }
2987
+ if (version3 !== 13 && version3 !== 8) {
2988
+ const message = "Missing or invalid Sec-WebSocket-Version header";
2989
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message, {
2990
+ "Sec-WebSocket-Version": "13, 8"
2991
+ });
2992
+ return;
2993
+ }
2994
+ if (!this.shouldHandle(req)) {
2995
+ abortHandshake(socket, 400);
2996
+ return;
2997
+ }
2998
+ const secWebSocketProtocol = req.headers["sec-websocket-protocol"];
2999
+ let protocols = new Set;
3000
+ if (secWebSocketProtocol !== undefined) {
3001
+ try {
3002
+ protocols = subprotocol2.parse(secWebSocketProtocol);
3003
+ } catch (err) {
3004
+ const message = "Invalid Sec-WebSocket-Protocol header";
3005
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3006
+ return;
3007
+ }
3008
+ }
3009
+ const secWebSocketExtensions = req.headers["sec-websocket-extensions"];
3010
+ const extensions = {};
3011
+ if (this.options.perMessageDeflate && secWebSocketExtensions !== undefined) {
3012
+ const perMessageDeflate = new PerMessageDeflate(this.options.perMessageDeflate, true, this.options.maxPayload);
3013
+ try {
3014
+ const offers = extension2.parse(secWebSocketExtensions);
3015
+ if (offers[PerMessageDeflate.extensionName]) {
3016
+ perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]);
3017
+ extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
101
3018
  }
102
- return new Date(e2);
103
- }(t2), this.init();
104
- }, m2.init = function() {
105
- var t2 = this.$d;
106
- this.$y = t2.getFullYear(), this.$M = t2.getMonth(), this.$D = t2.getDate(), this.$W = t2.getDay(), this.$H = t2.getHours(), this.$m = t2.getMinutes(), this.$s = t2.getSeconds(), this.$ms = t2.getMilliseconds();
107
- }, m2.$utils = function() {
108
- return b;
109
- }, m2.isValid = function() {
110
- return !(this.$d.toString() === l);
111
- }, m2.isSame = function(t2, e2) {
112
- var n2 = O(t2);
113
- return this.startOf(e2) <= n2 && n2 <= this.endOf(e2);
114
- }, m2.isAfter = function(t2, e2) {
115
- return O(t2) < this.startOf(e2);
116
- }, m2.isBefore = function(t2, e2) {
117
- return this.endOf(e2) < O(t2);
118
- }, m2.$g = function(t2, e2, n2) {
119
- return b.u(t2) ? this[e2] : this.set(n2, t2);
120
- }, m2.unix = function() {
121
- return Math.floor(this.valueOf() / 1000);
122
- }, m2.valueOf = function() {
123
- return this.$d.getTime();
124
- }, m2.startOf = function(t2, e2) {
125
- var n2 = this, r2 = !!b.u(e2) || e2, f2 = b.p(t2), l2 = function(t3, e3) {
126
- var i2 = b.w(n2.$u ? Date.UTC(n2.$y, e3, t3) : new Date(n2.$y, e3, t3), n2);
127
- return r2 ? i2 : i2.endOf(a);
128
- }, $2 = function(t3, e3) {
129
- return b.w(n2.toDate()[t3].apply(n2.toDate("s"), (r2 ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(e3)), n2);
130
- }, y2 = this.$W, M3 = this.$M, m3 = this.$D, v2 = "set" + (this.$u ? "UTC" : "");
131
- switch (f2) {
132
- case h:
133
- return r2 ? l2(1, 0) : l2(31, 11);
134
- case c:
135
- return r2 ? l2(1, M3) : l2(0, M3 + 1);
136
- case o:
137
- var g2 = this.$locale().weekStart || 0, D2 = (y2 < g2 ? y2 + 7 : y2) - g2;
138
- return l2(r2 ? m3 - D2 : m3 + (6 - D2), M3);
139
- case a:
140
- case d:
141
- return $2(v2 + "Hours", 0);
142
- case u:
143
- return $2(v2 + "Minutes", 1);
144
- case s:
145
- return $2(v2 + "Seconds", 2);
146
- case i:
147
- return $2(v2 + "Milliseconds", 3);
148
- default:
149
- return this.clone();
3019
+ } catch (err) {
3020
+ const message = "Invalid or unacceptable Sec-WebSocket-Extensions header";
3021
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3022
+ return;
150
3023
  }
151
- }, m2.endOf = function(t2) {
152
- return this.startOf(t2, false);
153
- }, m2.$set = function(t2, e2) {
154
- var n2, o2 = b.p(t2), f2 = "set" + (this.$u ? "UTC" : ""), l2 = (n2 = {}, n2[a] = f2 + "Date", n2[d] = f2 + "Date", n2[c] = f2 + "Month", n2[h] = f2 + "FullYear", n2[u] = f2 + "Hours", n2[s] = f2 + "Minutes", n2[i] = f2 + "Seconds", n2[r] = f2 + "Milliseconds", n2)[o2], $2 = o2 === a ? this.$D + (e2 - this.$W) : e2;
155
- if (o2 === c || o2 === h) {
156
- var y2 = this.clone().set(d, 1);
157
- y2.$d[l2]($2), y2.init(), this.$d = y2.set(d, Math.min(this.$D, y2.daysInMonth())).$d;
158
- } else
159
- l2 && this.$d[l2]($2);
160
- return this.init(), this;
161
- }, m2.set = function(t2, e2) {
162
- return this.clone().$set(t2, e2);
163
- }, m2.get = function(t2) {
164
- return this[b.p(t2)]();
165
- }, m2.add = function(r2, f2) {
166
- var d2, l2 = this;
167
- r2 = Number(r2);
168
- var $2 = b.p(f2), y2 = function(t2) {
169
- var e2 = O(l2);
170
- return b.w(e2.date(e2.date() + Math.round(t2 * r2)), l2);
171
- };
172
- if ($2 === c)
173
- return this.set(c, this.$M + r2);
174
- if ($2 === h)
175
- return this.set(h, this.$y + r2);
176
- if ($2 === a)
177
- return y2(1);
178
- if ($2 === o)
179
- return y2(7);
180
- var M3 = (d2 = {}, d2[s] = e, d2[u] = n, d2[i] = t, d2)[$2] || 1, m3 = this.$d.getTime() + r2 * M3;
181
- return b.w(m3, this);
182
- }, m2.subtract = function(t2, e2) {
183
- return this.add(-1 * t2, e2);
184
- }, m2.format = function(t2) {
185
- var e2 = this, n2 = this.$locale();
186
- if (!this.isValid())
187
- return n2.invalidDate || l;
188
- var r2 = t2 || "YYYY-MM-DDTHH:mm:ssZ", i2 = b.z(this), s2 = this.$H, u2 = this.$m, a2 = this.$M, o2 = n2.weekdays, c2 = n2.months, f2 = n2.meridiem, h2 = function(t3, n3, i3, s3) {
189
- return t3 && (t3[n3] || t3(e2, r2)) || i3[n3].slice(0, s3);
190
- }, d2 = function(t3) {
191
- return b.s(s2 % 12 || 12, t3, "0");
192
- }, $2 = f2 || function(t3, e3, n3) {
193
- var r3 = t3 < 12 ? "AM" : "PM";
194
- return n3 ? r3.toLowerCase() : r3;
3024
+ }
3025
+ if (this.options.verifyClient) {
3026
+ const info = {
3027
+ origin: req.headers[`${version3 === 8 ? "sec-websocket-origin" : "origin"}`],
3028
+ secure: !!(req.socket.authorized || req.socket.encrypted),
3029
+ req
195
3030
  };
196
- return r2.replace(y, function(t3, r3) {
197
- return r3 || function(t4) {
198
- switch (t4) {
199
- case "YY":
200
- return String(e2.$y).slice(-2);
201
- case "YYYY":
202
- return b.s(e2.$y, 4, "0");
203
- case "M":
204
- return a2 + 1;
205
- case "MM":
206
- return b.s(a2 + 1, 2, "0");
207
- case "MMM":
208
- return h2(n2.monthsShort, a2, c2, 3);
209
- case "MMMM":
210
- return h2(c2, a2);
211
- case "D":
212
- return e2.$D;
213
- case "DD":
214
- return b.s(e2.$D, 2, "0");
215
- case "d":
216
- return String(e2.$W);
217
- case "dd":
218
- return h2(n2.weekdaysMin, e2.$W, o2, 2);
219
- case "ddd":
220
- return h2(n2.weekdaysShort, e2.$W, o2, 3);
221
- case "dddd":
222
- return o2[e2.$W];
223
- case "H":
224
- return String(s2);
225
- case "HH":
226
- return b.s(s2, 2, "0");
227
- case "h":
228
- return d2(1);
229
- case "hh":
230
- return d2(2);
231
- case "a":
232
- return $2(s2, u2, true);
233
- case "A":
234
- return $2(s2, u2, false);
235
- case "m":
236
- return String(u2);
237
- case "mm":
238
- return b.s(u2, 2, "0");
239
- case "s":
240
- return String(e2.$s);
241
- case "ss":
242
- return b.s(e2.$s, 2, "0");
243
- case "SSS":
244
- return b.s(e2.$ms, 3, "0");
245
- case "Z":
246
- return i2;
3031
+ if (this.options.verifyClient.length === 2) {
3032
+ this.options.verifyClient(info, (verified, code, message, headers) => {
3033
+ if (!verified) {
3034
+ return abortHandshake(socket, code || 401, message, headers);
247
3035
  }
248
- return null;
249
- }(t3) || i2.replace(":", "");
250
- });
251
- }, m2.utcOffset = function() {
252
- return 15 * -Math.round(this.$d.getTimezoneOffset() / 15);
253
- }, m2.diff = function(r2, d2, l2) {
254
- var $2, y2 = this, M3 = b.p(d2), m3 = O(r2), v2 = (m3.utcOffset() - this.utcOffset()) * e, g2 = this - m3, D2 = function() {
255
- return b.m(y2, m3);
256
- };
257
- switch (M3) {
258
- case h:
259
- $2 = D2() / 12;
260
- break;
261
- case c:
262
- $2 = D2();
263
- break;
264
- case f:
265
- $2 = D2() / 3;
266
- break;
267
- case o:
268
- $2 = (g2 - v2) / 604800000;
269
- break;
270
- case a:
271
- $2 = (g2 - v2) / 86400000;
272
- break;
273
- case u:
274
- $2 = g2 / n;
275
- break;
276
- case s:
277
- $2 = g2 / e;
278
- break;
279
- case i:
280
- $2 = g2 / t;
281
- break;
282
- default:
283
- $2 = g2;
3036
+ this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
3037
+ });
3038
+ return;
284
3039
  }
285
- return l2 ? $2 : b.a($2);
286
- }, m2.daysInMonth = function() {
287
- return this.endOf(c).$D;
288
- }, m2.$locale = function() {
289
- return D[this.$L];
290
- }, m2.locale = function(t2, e2) {
291
- if (!t2)
292
- return this.$L;
293
- var n2 = this.clone(), r2 = w(t2, e2, true);
294
- return r2 && (n2.$L = r2), n2;
295
- }, m2.clone = function() {
296
- return b.w(this.$d, this);
297
- }, m2.toDate = function() {
298
- return new Date(this.valueOf());
299
- }, m2.toJSON = function() {
300
- return this.isValid() ? this.toISOString() : null;
301
- }, m2.toISOString = function() {
302
- return this.$d.toISOString();
303
- }, m2.toString = function() {
304
- return this.$d.toUTCString();
305
- }, M2;
306
- }(), k = _.prototype;
307
- return O.prototype = k, [["$ms", r], ["$s", i], ["$m", s], ["$H", u], ["$W", a], ["$M", c], ["$y", h], ["$D", d]].forEach(function(t2) {
308
- k[t2[1]] = function(e2) {
309
- return this.$g(e2, t2[0], t2[1]);
310
- };
311
- }), O.extend = function(t2, e2) {
312
- return t2.$i || (t2(e2, _, O), t2.$i = true), O;
313
- }, O.locale = w, O.isDayjs = S, O.unix = function(t2) {
314
- return O(1000 * t2);
315
- }, O.en = D[g], O.Ls = D, O.p = {}, O;
316
- });
3040
+ if (!this.options.verifyClient(info))
3041
+ return abortHandshake(socket, 401);
3042
+ }
3043
+ this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
3044
+ }
3045
+ completeUpgrade(extensions, key, protocols, req, socket, head, cb) {
3046
+ if (!socket.readable || !socket.writable)
3047
+ return socket.destroy();
3048
+ if (socket[kWebSocket]) {
3049
+ throw new Error("server.handleUpgrade() was called more than once with the same " + "socket, possibly due to a misconfiguration");
3050
+ }
3051
+ if (this._state > RUNNING)
3052
+ return abortHandshake(socket, 503);
3053
+ const digest = createHash("sha1").update(key + GUID).digest("base64");
3054
+ const headers = [
3055
+ "HTTP/1.1 101 Switching Protocols",
3056
+ "Upgrade: websocket",
3057
+ "Connection: Upgrade",
3058
+ `Sec-WebSocket-Accept: ${digest}`
3059
+ ];
3060
+ const ws = new this.options.WebSocket(null, undefined, this.options);
3061
+ if (protocols.size) {
3062
+ const protocol = this.options.handleProtocols ? this.options.handleProtocols(protocols, req) : protocols.values().next().value;
3063
+ if (protocol) {
3064
+ headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
3065
+ ws._protocol = protocol;
3066
+ }
3067
+ }
3068
+ if (extensions[PerMessageDeflate.extensionName]) {
3069
+ const params = extensions[PerMessageDeflate.extensionName].params;
3070
+ const value = extension2.format({
3071
+ [PerMessageDeflate.extensionName]: [params]
3072
+ });
3073
+ headers.push(`Sec-WebSocket-Extensions: ${value}`);
3074
+ ws._extensions = extensions;
3075
+ }
3076
+ this.emit("headers", headers, req);
3077
+ socket.write(headers.concat(`\r
3078
+ `).join(`\r
3079
+ `));
3080
+ socket.removeListener("error", socketOnError);
3081
+ ws.setSocket(socket, head, {
3082
+ allowSynchronousEvents: this.options.allowSynchronousEvents,
3083
+ maxPayload: this.options.maxPayload,
3084
+ skipUTF8Validation: this.options.skipUTF8Validation
3085
+ });
3086
+ if (this.clients) {
3087
+ this.clients.add(ws);
3088
+ ws.on("close", () => {
3089
+ this.clients.delete(ws);
3090
+ if (this._shouldEmitClose && !this.clients.size) {
3091
+ process.nextTick(emitClose, this);
3092
+ }
3093
+ });
3094
+ }
3095
+ cb(ws, req);
3096
+ }
3097
+ }
3098
+ module.exports = WebSocketServer;
3099
+ function addListeners(server, map3) {
3100
+ for (const event of Object.keys(map3))
3101
+ server.on(event, map3[event]);
3102
+ return function removeListeners() {
3103
+ for (const event of Object.keys(map3)) {
3104
+ server.removeListener(event, map3[event]);
3105
+ }
3106
+ };
3107
+ }
3108
+ function emitClose(server) {
3109
+ server._state = CLOSED;
3110
+ server.emit("close");
3111
+ }
3112
+ function socketOnError() {
3113
+ this.destroy();
3114
+ }
3115
+ function abortHandshake(socket, code, message, headers) {
3116
+ message = message || http.STATUS_CODES[code];
3117
+ headers = {
3118
+ Connection: "close",
3119
+ "Content-Type": "text/html",
3120
+ "Content-Length": Buffer.byteLength(message),
3121
+ ...headers
3122
+ };
3123
+ socket.once("finish", socket.destroy);
3124
+ socket.end(`HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r
3125
+ ` + Object.keys(headers).map((h) => `${h}: ${headers[h]}`).join(`\r
3126
+ `) + `\r
3127
+ \r
3128
+ ` + message);
3129
+ }
3130
+ function abortHandshakeOrEmitwsClientError(server, req, socket, code, message, headers) {
3131
+ if (server.listenerCount("wsClientError")) {
3132
+ const err = new Error(message);
3133
+ Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError);
3134
+ server.emit("wsClientError", err, socket, req);
3135
+ } else {
3136
+ abortHandshake(socket, code, message, headers);
3137
+ }
3138
+ }
317
3139
  });
318
3140
 
319
- // node_modules/.pnpm/@kevisual+router@0.0.64_typescript@5.9.3/node_modules/@kevisual/router/dist/router.js
3141
+ // node_modules/.pnpm/@kevisual+router@0.0.70/node_modules/@kevisual/router/dist/router.js
320
3142
  import require$$1, { webcrypto } from "node:crypto";
321
3143
  import require$$2 from "node:http";
322
3144
  import require$$1$1 from "node:https";
@@ -599,6 +3421,44 @@ function requireEventemitter3() {
599
3421
  }
600
3422
  var eventemitter3Exports = requireEventemitter3();
601
3423
  var EventEmitter = /* @__PURE__ */ getDefaultExportFromCjs(eventemitter3Exports);
3424
+ function isPlainObject$1(value) {
3425
+ if (!value || typeof value !== "object") {
3426
+ return false;
3427
+ }
3428
+ const proto = Object.getPrototypeOf(value);
3429
+ const hasObjectPrototype = proto === null || proto === Object.prototype || Object.getPrototypeOf(proto) === null;
3430
+ if (!hasObjectPrototype) {
3431
+ return false;
3432
+ }
3433
+ return Object.prototype.toString.call(value) === "[object Object]";
3434
+ }
3435
+ function isUnsafeProperty(key) {
3436
+ return key === "__proto__";
3437
+ }
3438
+ function merge$1(target, source) {
3439
+ const sourceKeys = Object.keys(source);
3440
+ for (let i = 0;i < sourceKeys.length; i++) {
3441
+ const key = sourceKeys[i];
3442
+ if (isUnsafeProperty(key)) {
3443
+ continue;
3444
+ }
3445
+ const sourceValue = source[key];
3446
+ const targetValue = target[key];
3447
+ if (isMergeableValue(sourceValue) && isMergeableValue(targetValue)) {
3448
+ target[key] = merge$1(targetValue, sourceValue);
3449
+ } else if (Array.isArray(sourceValue)) {
3450
+ target[key] = merge$1([], sourceValue);
3451
+ } else if (isPlainObject$1(sourceValue)) {
3452
+ target[key] = merge$1({}, sourceValue);
3453
+ } else if (targetValue === undefined || sourceValue !== undefined) {
3454
+ target[key] = sourceValue;
3455
+ }
3456
+ }
3457
+ return target;
3458
+ }
3459
+ function isMergeableValue(value) {
3460
+ return isPlainObject$1(value) || Array.isArray(value);
3461
+ }
602
3462
 
603
3463
  class MockProcess {
604
3464
  emitter;
@@ -637,7 +3497,7 @@ class MockProcess {
637
3497
  this.process = undefined;
638
3498
  }
639
3499
  }
640
- var listenProcess = async ({ app, mockProcess, params, timeout = 10 * 60 * 60 * 1000 }) => {
3500
+ var listenProcess = async ({ app, mockProcess, params = {}, timeout = 10 * 60 * 60 * 1000 }) => {
641
3501
  const process2 = mockProcess || new MockProcess;
642
3502
  let isEnd = false;
643
3503
  const timer = setTimeout(() => {
@@ -650,23 +3510,25 @@ var listenProcess = async ({ app, mockProcess, params, timeout = 10 * 60 * 60 *
650
3510
  }, timeout);
651
3511
  const getParams = async () => {
652
3512
  return new Promise((resolve) => {
653
- process2.on((msg) => {
3513
+ process2.on((params2) => {
654
3514
  if (isEnd)
655
3515
  return;
656
3516
  isEnd = true;
657
3517
  clearTimeout(timer);
658
- resolve(msg);
3518
+ resolve(params2 || {});
659
3519
  });
660
3520
  });
661
3521
  };
662
3522
  try {
663
- const { payload = {}, ...rest } = await getParams();
664
- const msg = { ...params, ...rest, payload: { ...params?.payload, ...payload } };
3523
+ const _params = await getParams();
3524
+ const mergeParams = merge$1(params, _params);
3525
+ const msg = mergeParams?.message || {};
3526
+ const ctx = mergeParams?.context || {};
665
3527
  if (!msg.path && !msg.id) {
666
3528
  const route = app.routes.find((r) => r.path !== "router");
667
3529
  msg.id = route?.id;
668
3530
  }
669
- const result = await app.run(msg);
3531
+ const result = await app.run(msg, ctx);
670
3532
  const response = {
671
3533
  success: true,
672
3534
  data: result,
@@ -676,6 +3538,7 @@ var listenProcess = async ({ app, mockProcess, params, timeout = 10 * 60 * 60 *
676
3538
  process2.exit?.(0);
677
3539
  });
678
3540
  } catch (error) {
3541
+ console.error("Error in listenProcess:", error);
679
3542
  process2.send?.({
680
3543
  success: false,
681
3544
  error: error.message
@@ -11655,7 +14518,7 @@ var allProcessors = {
11655
14518
  optional: optionalProcessor,
11656
14519
  lazy: lazyProcessor
11657
14520
  };
11658
- function toJSONSchema(input, params) {
14521
+ function toJSONSchema$1(input, params) {
11659
14522
  if ("_idmap" in input) {
11660
14523
  const registry2 = input;
11661
14524
  const ctx2 = initializeContext({ ...params, processors: allProcessors });
@@ -12022,7 +14885,7 @@ var index = /* @__PURE__ */ Object.freeze({
12022
14885
  safeParse: safeParse$1,
12023
14886
  safeParseAsync: safeParseAsync$1,
12024
14887
  toDotPath,
12025
- toJSONSchema,
14888
+ toJSONSchema: toJSONSchema$1,
12026
14889
  treeifyError,
12027
14890
  util: util$1,
12028
14891
  version
@@ -13852,7 +16715,7 @@ function convertSchema(schema, ctx) {
13852
16715
  }
13853
16716
  return baseSchema;
13854
16717
  }
13855
- function fromJSONSchema(schema, params) {
16718
+ function fromJSONSchema$1(schema, params) {
13856
16719
  if (typeof schema === "boolean") {
13857
16720
  return schema ? z$1.any() : z$1.never();
13858
16721
  }
@@ -14016,7 +16879,7 @@ var z = /* @__PURE__ */ Object.freeze({
14016
16879
  float32,
14017
16880
  float64,
14018
16881
  formatError,
14019
- fromJSONSchema,
16882
+ fromJSONSchema: fromJSONSchema$1,
14020
16883
  function: _function,
14021
16884
  getErrorMap,
14022
16885
  globalRegistry,
@@ -14109,7 +16972,7 @@ var z = /* @__PURE__ */ Object.freeze({
14109
16972
  superRefine,
14110
16973
  symbol,
14111
16974
  templateLiteral,
14112
- toJSONSchema,
16975
+ toJSONSchema: toJSONSchema$1,
14113
16976
  toLowerCase: _toLowerCase,
14114
16977
  toUpperCase: _toUpperCase,
14115
16978
  transform,
@@ -14243,8 +17106,8 @@ class Route {
14243
17106
  }
14244
17107
  return this;
14245
17108
  }
14246
- addTo(router) {
14247
- router.add(this);
17109
+ addTo(router, opts) {
17110
+ router.add(this, opts);
14248
17111
  }
14249
17112
  setData(data) {
14250
17113
  this.data = data;
@@ -14254,6 +17117,37 @@ class Route {
14254
17117
  throw new CustomError(...args);
14255
17118
  }
14256
17119
  }
17120
+ var toJSONSchema = (route) => {
17121
+ const pickValues = pick$1(route, pickValue);
17122
+ if (pickValues?.metadata?.args) {
17123
+ const args = pickValues.metadata.args;
17124
+ const keys = Object.keys(args);
17125
+ const newArgs = {};
17126
+ for (let key of keys) {
17127
+ const item = args[key];
17128
+ if (item && typeof item === "object" && typeof item.toJSONSchema === "function") {
17129
+ newArgs[key] = item.toJSONSchema();
17130
+ } else {
17131
+ newArgs[key] = args[key];
17132
+ }
17133
+ }
17134
+ pickValues.metadata.args = newArgs;
17135
+ }
17136
+ return pickValues;
17137
+ };
17138
+ var fromJSONSchema = (route) => {
17139
+ const args = route?.metadata?.args;
17140
+ if (!args)
17141
+ return route;
17142
+ const keys = Object.keys(args);
17143
+ const newArgs = {};
17144
+ for (let key of keys) {
17145
+ const item = args[key];
17146
+ newArgs[key] = fromJSONSchema$1(item);
17147
+ }
17148
+ route.metadata.args = newArgs;
17149
+ return route;
17150
+ };
14257
17151
 
14258
17152
  class QueryRouter {
14259
17153
  appId = "";
@@ -14263,9 +17157,13 @@ class QueryRouter {
14263
17157
  constructor() {
14264
17158
  this.routes = [];
14265
17159
  }
14266
- add(route) {
17160
+ add(route, opts) {
17161
+ const overwrite = opts?.overwrite ?? true;
14267
17162
  const has = this.routes.findIndex((r) => r.path === route.path && r.key === route.key);
14268
17163
  if (has !== -1) {
17164
+ if (!overwrite) {
17165
+ return;
17166
+ }
14269
17167
  this.routes.splice(has, 1);
14270
17168
  }
14271
17169
  this.routes.push(route);
@@ -14499,7 +17397,22 @@ class QueryRouter {
14499
17397
  }
14500
17398
  getList(filter) {
14501
17399
  return this.routes.filter(filter || (() => true)).map((r) => {
14502
- return pick$1(r, pickValue);
17400
+ const pickValues = pick$1(r, pickValue);
17401
+ if (pickValues?.metadata?.args) {
17402
+ const args = pickValues.metadata.args;
17403
+ const keys = Object.keys(args);
17404
+ const newArgs = {};
17405
+ for (let key of keys) {
17406
+ const item = args[key];
17407
+ if (item && typeof item === "object" && typeof item.toJSONSchema === "function") {
17408
+ newArgs[key] = item.toJSONSchema();
17409
+ } else {
17410
+ newArgs[key] = args[key];
17411
+ }
17412
+ }
17413
+ pickValues.metadata.args = newArgs;
17414
+ }
17415
+ return pickValues;
14503
17416
  });
14504
17417
  }
14505
17418
  getHandle(router, wrapperFn, ctx) {
@@ -14572,6 +17485,8 @@ class QueryRouter {
14572
17485
  }
14573
17486
  return listenProcess({ app: this, params, ...opts });
14574
17487
  }
17488
+ toJSONSchema = toJSONSchema;
17489
+ fromJSONSchema = fromJSONSchema;
14575
17490
  }
14576
17491
 
14577
17492
  class QueryRouterServer extends QueryRouter {
@@ -14589,8 +17504,8 @@ class QueryRouterServer extends QueryRouter {
14589
17504
  setHandle(wrapperFn, ctx) {
14590
17505
  this.handle = this.getHandle(this, wrapperFn, ctx);
14591
17506
  }
14592
- addRoute(route) {
14593
- this.add(route);
17507
+ addRoute(route, opts) {
17508
+ this.add(route, opts);
14594
17509
  }
14595
17510
  Route = Route;
14596
17511
  route(...args) {
@@ -18529,8 +21444,8 @@ class InitEnv {
18529
21444
  }
18530
21445
  InitEnv.init();
18531
21446
 
18532
- // node_modules/.pnpm/@kevisual+use-config@1.0.28_dotenv@17.2.3/node_modules/@kevisual/use-config/dist/app.js
18533
- import { createRequire } from "node:module";
21447
+ // node_modules/.pnpm/@kevisual+use-config@1.0.30_dotenv@17.2.3/node_modules/@kevisual/use-config/dist/app.js
21448
+ import { createRequire as createRequire2 } from "node:module";
18534
21449
  import fs from "node:fs";
18535
21450
  import path from "node:path";
18536
21451
  var __create2 = Object.create;
@@ -18550,7 +21465,7 @@ var __toESM2 = (mod, isNodeMode, target) => {
18550
21465
  return to;
18551
21466
  };
18552
21467
  var __commonJS2 = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
18553
- var __require = /* @__PURE__ */ createRequire(import.meta.url);
21468
+ var __require2 = /* @__PURE__ */ createRequire2(import.meta.url);
18554
21469
  var require_package = __commonJS2((exports, module) => {
18555
21470
  module.exports = {
18556
21471
  name: "dotenv",
@@ -18616,10 +21531,10 @@ var require_package = __commonJS2((exports, module) => {
18616
21531
  };
18617
21532
  });
18618
21533
  var require_main = __commonJS2((exports, module) => {
18619
- var fs2 = __require("fs");
18620
- var path2 = __require("path");
18621
- var os = __require("os");
18622
- var crypto2 = __require("crypto");
21534
+ var fs2 = __require2("fs");
21535
+ var path2 = __require2("path");
21536
+ var os = __require2("os");
21537
+ var crypto2 = __require2("crypto");
18623
21538
  var packageJson = require_package();
18624
21539
  var version2 = packageJson.version;
18625
21540
  var TIPS = [
@@ -19032,7 +21947,7 @@ var useKey = (key, opts) => {
19032
21947
  v = process.env[key];
19033
21948
  }
19034
21949
  if (!v) {
19035
- return opts?.defaultValue || null;
21950
+ return opts?.defaultValue || "";
19036
21951
  }
19037
21952
  if (opts?.isNumber && typeof v === "string") {
19038
21953
  return Number(v);
@@ -19596,6 +22511,7 @@ InitEnv2.init();
19596
22511
  // src/cnb-core.ts
19597
22512
  class CNBCore {
19598
22513
  baseURL = "https://api.cnb.cool";
22514
+ hackURL = "https://cnb.cool";
19599
22515
  token;
19600
22516
  cookie;
19601
22517
  constructor(options) {
@@ -19609,6 +22525,10 @@ class CNBCore {
19609
22525
  this.cookie = options.cnb.cookie;
19610
22526
  }
19611
22527
  }
22528
+ if (options?.cors?.baseUrl) {
22529
+ this.baseURL = options.cors.baseUrl + "/" + this.baseURL;
22530
+ this.hackURL = options.cors.baseUrl + "/" + this.hackURL;
22531
+ }
19612
22532
  }
19613
22533
  async request({ url: url2, method = "GET", data, params, headers, body, useCookie, useOrigin }) {
19614
22534
  const defaultHeaders = {
@@ -19797,7 +22717,7 @@ class Repo extends CNBCore {
19797
22717
  return this.post({ url: url2, data: postData });
19798
22718
  }
19799
22719
  deleteRepo(name) {
19800
- const url2 = `https://cnb.cool/${name}`;
22720
+ const url2 = `${this.hackURL}/${name}`;
19801
22721
  return this.delete({ url: url2, useCookie: true });
19802
22722
  }
19803
22723
  async createCommit(repo, data) {
@@ -19811,7 +22731,7 @@ class Repo extends CNBCore {
19811
22731
  if (!data.parent_commit_sha && preCommitSha) {
19812
22732
  data.parent_commit_sha = preCommitSha;
19813
22733
  }
19814
- const url2 = `https://cnb.cool/${repo}/-/git/commits`;
22734
+ const url2 = `${this.hackURL}/${repo}/-/git/commits`;
19815
22735
  const postData = {
19816
22736
  ...data,
19817
22737
  base_branch: data.base_branch || "refs/heads/main",
@@ -19871,7 +22791,7 @@ class User extends CNBCore {
19871
22791
  super({ token: options.token, cookie: options.cookie });
19872
22792
  }
19873
22793
  getCurrentUser() {
19874
- const url2 = `https://cnb.cool/user`;
22794
+ const url2 = `${this.hackURL}/user`;
19875
22795
  return this.get({
19876
22796
  url: url2,
19877
22797
  useCookie: true
@@ -19883,7 +22803,7 @@ class User extends CNBCore {
19883
22803
  }
19884
22804
  createAccessToken(data) {
19885
22805
  const scope = data?.scope || "mission-manage:rw,mission-delete:rw,group-delete:rw,group-manage:rw,group-resource:rw,account-engage:rw,account-email:r,account-profile:rw,registry-delete:rw,registry-manage:rw,registry-package-delete:rw,registry-package:rw,repo-security:r,repo-delete:rw,repo-manage:rw,repo-basic-info:r,repo-cnb-detail:rw,repo-cnb-history:r,repo-cnb-trigger:rw,repo-commit-status:rw,repo-contents:rw,repo-notes:rw,repo-issue:rw,repo-pr:rw,repo-code:rw";
19886
- const url2 = "https://cnb.cool/user/personal_access_tokens";
22806
+ const url2 = `${this.hackURL}/user/personal_access_tokens`;
19887
22807
  return this.post({
19888
22808
  url: url2,
19889
22809
  useCookie: true,
@@ -19894,7 +22814,7 @@ class User extends CNBCore {
19894
22814
  });
19895
22815
  }
19896
22816
  getAccessTokens(params) {
19897
- const url2 = "https://cnb.cool/user/personal_access_tokens";
22817
+ const url2 = `${this.hackURL}/user/personal_access_tokens`;
19898
22818
  return this.get({
19899
22819
  url: url2,
19900
22820
  useCookie: true,
@@ -19906,7 +22826,7 @@ class User extends CNBCore {
19906
22826
  });
19907
22827
  }
19908
22828
  deleteAccessToken(tokenId) {
19909
- const url2 = `https://cnb.cool/user/personal_access_tokens/${tokenId}`;
22829
+ const url2 = `${this.hackURL}/user/personal_access_tokens/${tokenId}`;
19910
22830
  return this.delete({
19911
22831
  url: url2,
19912
22832
  useCookie: true
@@ -33655,7 +36575,7 @@ config3(en_default());
33655
36575
  // node_modules/.pnpm/zod@4.3.6/node_modules/zod/index.js
33656
36576
  var zod_default = exports_external;
33657
36577
 
33658
- // node_modules/.pnpm/@opencode-ai+plugin@1.1.44/node_modules/@opencode-ai/plugin/dist/tool.js
36578
+ // node_modules/.pnpm/@opencode-ai+plugin@1.1.51/node_modules/@opencode-ai/plugin/dist/tool.js
33659
36579
  function tool2(input) {
33660
36580
  return input;
33661
36581
  }
@@ -33911,9 +36831,15 @@ function nanoid4(size = 21) {
33911
36831
  // agent/routes/workspace/keep.ts
33912
36832
  var import_dayjs = __toESM(require_dayjs_min(), 1);
33913
36833
 
33914
- // src/workspace/keep-live.ts
33915
- import WebSocket from "ws";
36834
+ // node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/wrapper.mjs
36835
+ var import_stream = __toESM(require_stream(), 1);
36836
+ var import_receiver = __toESM(require_receiver(), 1);
36837
+ var import_sender = __toESM(require_sender(), 1);
36838
+ var import_websocket = __toESM(require_websocket(), 1);
36839
+ var import_websocket_server = __toESM(require_websocket_server(), 1);
36840
+ var wrapper_default = import_websocket.default;
33916
36841
 
36842
+ // src/workspace/keep-live.ts
33917
36843
  class WSKeepAlive {
33918
36844
  ws = null;
33919
36845
  config;
@@ -33975,7 +36901,7 @@ class WSKeepAlive {
33975
36901
  connect() {
33976
36902
  const { wsUrl, cookie, debug } = this.config;
33977
36903
  this.log(`Connecting to ${wsUrl}...`);
33978
- this.ws = new WebSocket(wsUrl, {
36904
+ this.ws = new wrapper_default(wsUrl, {
33979
36905
  headers: {
33980
36906
  Origin: this.url.origin,
33981
36907
  Cookie: cookie,
@@ -34018,7 +36944,7 @@ class WSKeepAlive {
34018
36944
  startPing() {
34019
36945
  this.stopPing();
34020
36946
  this.pingTimer = setInterval(() => {
34021
- if (this.ws && this.ws.readyState === WebSocket.OPEN) {
36947
+ if (this.ws && this.ws.readyState === wrapper_default.OPEN) {
34022
36948
  this.ws.ping();
34023
36949
  this.log("Sent ping");
34024
36950
  }
@@ -36775,7 +39701,7 @@ var init_events = __esm(() => {
36775
39701
  Object.assign(EventEmitter4, { once: once2, getEventListeners, getMaxListeners: getMaxListeners2, setMaxListeners: setMaxListeners2, EventEmitter: EventEmitter4, usingDomains: false, captureRejectionSymbol, errorMonitor: kErrorMonitor, addAbortListener, init: EventEmitter4, listenerCount: listenerCount2 });
36776
39702
  events_default = EventEmitter4;
36777
39703
  });
36778
- var require_stream = __commonJS3((exports, module) => {
39704
+ var require_stream2 = __commonJS3((exports, module) => {
36779
39705
  var __commonJS22 = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
36780
39706
  var require_primordials = __commonJS22((exports2, module2) => {
36781
39707
 
@@ -40612,7 +43538,7 @@ var require_stream = __commonJS3((exports, module) => {
40612
43538
  });
40613
43539
  var require_promises = __commonJS22((exports2, module2) => {
40614
43540
  var { ArrayPrototypePop, Promise: Promise2 } = require_primordials(), { isIterable, isNodeStream, isWebStream } = require_utils(), { pipelineImpl: pl2 } = require_pipeline(), { finished } = require_end_of_stream();
40615
- require_stream2();
43541
+ require_stream22();
40616
43542
  function pipeline(...streams) {
40617
43543
  return new Promise2((resolve, reject) => {
40618
43544
  let signal, end, lastArg = streams[streams.length - 1];
@@ -40630,7 +43556,7 @@ var require_stream = __commonJS3((exports, module) => {
40630
43556
  }
40631
43557
  module2.exports = { finished, pipeline };
40632
43558
  });
40633
- var require_stream2 = __commonJS22((exports2, module2) => {
43559
+ var require_stream22 = __commonJS22((exports2, module2) => {
40634
43560
  var { Buffer: Buffer3 } = (init_buffer(), __toCommonJS(exports_buffer)), { ObjectDefineProperty, ObjectKeys, ReflectApply } = require_primordials(), { promisify: { custom: customPromisify } } = require_util(), { streamReturningOperators, promiseReturningOperators } = require_operators(), { codes: { ERR_ILLEGAL_CONSTRUCTOR } } = require_errors(), compose = require_compose(), { setDefaultHighWaterMark, getDefaultHighWaterMark } = require_state(), { pipeline } = require_pipeline(), { destroyer } = require_destroy(), eos = require_end_of_stream(), promises = require_promises(), utils = require_utils(), Stream = module2.exports = require_legacy().Stream;
40635
43561
  Stream.isDestroyed = utils.isDestroyed;
40636
43562
  Stream.isDisturbed = utils.isDisturbed;
@@ -40684,9 +43610,9 @@ var require_stream = __commonJS3((exports, module) => {
40684
43610
  };
40685
43611
  });
40686
43612
  var require_ours = __commonJS22((exports2, module2) => {
40687
- var Stream = require_stream();
43613
+ var Stream = require_stream2();
40688
43614
  {
40689
- let CustomStream = require_stream2(), promises = require_promises(), originalDestroy = CustomStream.Readable.destroy;
43615
+ let CustomStream = require_stream22(), promises = require_promises(), originalDestroy = CustomStream.Readable.destroy;
40690
43616
  module2.exports = CustomStream.Readable, module2.exports._uint8ArrayToBuffer = CustomStream._uint8ArrayToBuffer, module2.exports._isUint8Array = CustomStream._isUint8Array, module2.exports.isDisturbed = CustomStream.isDisturbed, module2.exports.isErrored = CustomStream.isErrored, module2.exports.isReadable = CustomStream.isReadable, module2.exports.Readable = CustomStream.Readable, module2.exports.Writable = CustomStream.Writable, module2.exports.Duplex = CustomStream.Duplex, module2.exports.Transform = CustomStream.Transform, module2.exports.PassThrough = CustomStream.PassThrough, module2.exports.addAbortSignal = CustomStream.addAbortSignal, module2.exports.finished = CustomStream.finished, module2.exports.destroy = CustomStream.destroy, module2.exports.destroy = originalDestroy, module2.exports.pipeline = CustomStream.pipeline, module2.exports.compose = CustomStream.compose, Object.defineProperty(CustomStream, "promises", { configurable: true, enumerable: true, get() {
40691
43617
  return promises;
40692
43618
  } }), module2.exports.Stream = CustomStream.Stream;
@@ -40869,7 +43795,7 @@ var require_buffer;
40869
43795
  var require_node;
40870
43796
  var require_base2;
40871
43797
  var require_der;
40872
- var require_constants;
43798
+ var require_constants2;
40873
43799
  var require_der2;
40874
43800
  var require_pem;
40875
43801
  var require_decoders;
@@ -48949,13 +51875,13 @@ var init_crypto = __esm(() => {
48949
51875
  base.Node = require_node();
48950
51876
  });
48951
51877
  require_der = __commonJS22((exports) => {
48952
- var constants23 = require_constants();
51878
+ var constants23 = require_constants2();
48953
51879
  exports.tagClass = { 0: "universal", 1: "application", 2: "context", 3: "private" };
48954
51880
  exports.tagClassByName = constants23._reverse(exports.tagClass);
48955
51881
  exports.tag = { 0: "end", 1: "bool", 2: "int", 3: "bitstr", 4: "octstr", 5: "null_", 6: "objid", 7: "objDesc", 8: "external", 9: "real", 10: "enum", 11: "embed", 12: "utf8str", 13: "relativeOid", 16: "seq", 17: "set", 18: "numstr", 19: "printstr", 20: "t61str", 21: "videostr", 22: "ia5str", 23: "utctime", 24: "gentime", 25: "graphstr", 26: "iso646str", 27: "genstr", 28: "unistr", 29: "charstr", 30: "bmpstr" };
48956
51882
  exports.tagByName = constants23._reverse(exports.tag);
48957
51883
  });
48958
- require_constants = __commonJS22((exports) => {
51884
+ require_constants2 = __commonJS22((exports) => {
48959
51885
  var constants23 = exports;
48960
51886
  constants23._reverse = function(map3) {
48961
51887
  var res = {};
@@ -49418,7 +52344,7 @@ var init_crypto = __esm(() => {
49418
52344
  asn1.bignum = require_bn3();
49419
52345
  asn1.define = require_api().define;
49420
52346
  asn1.base = require_base2();
49421
- asn1.constants = require_constants();
52347
+ asn1.constants = require_constants2();
49422
52348
  asn1.decoders = require_decoders();
49423
52349
  asn1.encoders = require_encoders();
49424
52350
  });
@@ -49494,7 +52420,7 @@ var init_crypto = __esm(() => {
49494
52420
  module.exports = { "2.16.840.1.101.3.4.1.1": "aes-128-ecb", "2.16.840.1.101.3.4.1.2": "aes-128-cbc", "2.16.840.1.101.3.4.1.3": "aes-128-ofb", "2.16.840.1.101.3.4.1.4": "aes-128-cfb", "2.16.840.1.101.3.4.1.21": "aes-192-ecb", "2.16.840.1.101.3.4.1.22": "aes-192-cbc", "2.16.840.1.101.3.4.1.23": "aes-192-ofb", "2.16.840.1.101.3.4.1.24": "aes-192-cfb", "2.16.840.1.101.3.4.1.41": "aes-256-ecb", "2.16.840.1.101.3.4.1.42": "aes-256-cbc", "2.16.840.1.101.3.4.1.43": "aes-256-ofb", "2.16.840.1.101.3.4.1.44": "aes-256-cfb" };
49495
52421
  });
49496
52422
  require_hash_base = __commonJS22((exports, module) => {
49497
- var Buffer22 = require_safe_buffer().Buffer, Transform = require_stream().Transform, inherits2 = require_inherits();
52423
+ var Buffer22 = require_safe_buffer().Buffer, Transform = require_stream2().Transform, inherits2 = require_inherits();
49498
52424
  function HashBase(blockSize) {
49499
52425
  Transform.call(this), this._block = Buffer22.allocUnsafe(blockSize), this._blockSize = blockSize, this._blockOffset = 0, this._length = [0, 0, 0, 0], this._finalized = false;
49500
52426
  }