@kevisual/cnb 0.0.29 → 0.0.31

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/opencode.js CHANGED
@@ -1,333 +1,228 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, {
5
+ get: all[name],
6
+ enumerable: true,
7
+ configurable: true,
8
+ set: (newValue) => all[name] = () => newValue
9
+ });
10
+ };
11
+
12
+ // node_modules/.pnpm/@kevisual+router@0.0.84/node_modules/@kevisual/router/dist/router.js
1
13
  import { createRequire } from "node:module";
14
+ import { webcrypto as crypto2 } from "node:crypto";
15
+ import url2 from "node:url";
2
16
  var __create = Object.create;
3
17
  var __getProtoOf = Object.getPrototypeOf;
4
- var __defProp = Object.defineProperty;
18
+ var __defProp2 = Object.defineProperty;
5
19
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
20
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
21
  var __toESM = (mod, isNodeMode, target) => {
8
22
  target = mod != null ? __create(__getProtoOf(mod)) : {};
9
- const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
23
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target;
10
24
  for (let key of __getOwnPropNames(mod))
11
25
  if (!__hasOwnProp.call(to, key))
12
- __defProp(to, key, {
26
+ __defProp2(to, key, {
13
27
  get: () => mod[key],
14
28
  enumerable: true
15
29
  });
16
30
  return to;
17
31
  };
18
32
  var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
19
- var __export = (target, all) => {
33
+ var __export2 = (target, all) => {
20
34
  for (var name in all)
21
- __defProp(target, name, {
35
+ __defProp2(target, name, {
22
36
  get: all[name],
23
37
  enumerable: true,
24
38
  configurable: true,
25
39
  set: (newValue) => all[name] = () => newValue
26
40
  });
27
41
  };
28
- var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
29
42
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
30
-
31
- // node_modules/.pnpm/dayjs@1.11.19/node_modules/dayjs/dayjs.min.js
32
- var require_dayjs_min = __commonJS((exports, module) => {
33
- (function(t, e) {
34
- typeof exports == "object" && typeof module != "undefined" ? module.exports = e() : typeof define == "function" && define.amd ? define(e) : (t = typeof globalThis != "undefined" ? globalThis : t || self).dayjs = e();
35
- })(exports, function() {
36
- var t = 1000, e = 60000, n = 3600000, r = "millisecond", i = "second", s = "minute", u = "hour", a = "day", o = "week", c = "month", f = "quarter", h = "year", d = "date", l = "Invalid Date", $ = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/, y = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g, M = { name: "en", weekdays: "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"), months: "January_February_March_April_May_June_July_August_September_October_November_December".split("_"), ordinal: function(t2) {
37
- var e2 = ["th", "st", "nd", "rd"], n2 = t2 % 100;
38
- return "[" + t2 + (e2[(n2 - 20) % 10] || e2[n2] || e2[0]) + "]";
39
- } }, m = function(t2, e2, n2) {
40
- var r2 = String(t2);
41
- return !r2 || r2.length >= e2 ? t2 : "" + Array(e2 + 1 - r2.length).join(n2) + t2;
42
- }, v = { s: m, z: function(t2) {
43
- var e2 = -t2.utcOffset(), n2 = Math.abs(e2), r2 = Math.floor(n2 / 60), i2 = n2 % 60;
44
- return (e2 <= 0 ? "+" : "-") + m(r2, 2, "0") + ":" + m(i2, 2, "0");
45
- }, m: function t2(e2, n2) {
46
- if (e2.date() < n2.date())
47
- return -t2(n2, e2);
48
- var r2 = 12 * (n2.year() - e2.year()) + (n2.month() - e2.month()), i2 = e2.clone().add(r2, c), s2 = n2 - i2 < 0, u2 = e2.clone().add(r2 + (s2 ? -1 : 1), c);
49
- return +(-(r2 + (n2 - i2) / (s2 ? i2 - u2 : u2 - i2)) || 0);
50
- }, a: function(t2) {
51
- return t2 < 0 ? Math.ceil(t2) || 0 : Math.floor(t2);
52
- }, p: function(t2) {
53
- return { M: c, y: h, w: o, d: a, D: d, h: u, m: s, s: i, ms: r, Q: f }[t2] || String(t2 || "").toLowerCase().replace(/s$/, "");
54
- }, u: function(t2) {
55
- return t2 === undefined;
56
- } }, g = "en", D = {};
57
- D[g] = M;
58
- var p = "$isDayjsObject", S = function(t2) {
59
- return t2 instanceof _ || !(!t2 || !t2[p]);
60
- }, w = function t2(e2, n2, r2) {
61
- var i2;
62
- if (!e2)
63
- return g;
64
- if (typeof e2 == "string") {
65
- var s2 = e2.toLowerCase();
66
- D[s2] && (i2 = s2), n2 && (D[s2] = n2, i2 = s2);
67
- var u2 = e2.split("-");
68
- if (!i2 && u2.length > 1)
69
- return t2(u2[0]);
70
- } else {
71
- var a2 = e2.name;
72
- D[a2] = e2, i2 = a2;
73
- }
74
- return !r2 && i2 && (g = i2), i2 || !r2 && g;
75
- }, O = function(t2, e2) {
76
- if (S(t2))
77
- return t2.clone();
78
- var n2 = typeof e2 == "object" ? e2 : {};
79
- return n2.date = t2, n2.args = arguments, new _(n2);
80
- }, b = v;
81
- b.l = w, b.i = S, b.w = function(t2, e2) {
82
- return O(t2, { locale: e2.$L, utc: e2.$u, x: e2.$x, $offset: e2.$offset });
83
- };
84
- var _ = function() {
85
- function M2(t2) {
86
- this.$L = w(t2.locale, null, true), this.parse(t2), this.$x = this.$x || t2.x || {}, this[p] = true;
87
- }
88
- var m2 = M2.prototype;
89
- return m2.parse = function(t2) {
90
- this.$d = function(t3) {
91
- var { date: e2, utc: n2 } = t3;
92
- if (e2 === null)
93
- return new Date(NaN);
94
- if (b.u(e2))
95
- return new Date;
96
- if (e2 instanceof Date)
97
- return new Date(e2);
98
- if (typeof e2 == "string" && !/Z$/i.test(e2)) {
99
- var r2 = e2.match($);
100
- if (r2) {
101
- var i2 = r2[2] - 1 || 0, s2 = (r2[7] || "0").substring(0, 3);
102
- 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);
103
- }
104
- }
105
- return new Date(e2);
106
- }(t2), this.init();
107
- }, m2.init = function() {
108
- var t2 = this.$d;
109
- 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();
110
- }, m2.$utils = function() {
111
- return b;
112
- }, m2.isValid = function() {
113
- return !(this.$d.toString() === l);
114
- }, m2.isSame = function(t2, e2) {
115
- var n2 = O(t2);
116
- return this.startOf(e2) <= n2 && n2 <= this.endOf(e2);
117
- }, m2.isAfter = function(t2, e2) {
118
- return O(t2) < this.startOf(e2);
119
- }, m2.isBefore = function(t2, e2) {
120
- return this.endOf(e2) < O(t2);
121
- }, m2.$g = function(t2, e2, n2) {
122
- return b.u(t2) ? this[e2] : this.set(n2, t2);
123
- }, m2.unix = function() {
124
- return Math.floor(this.valueOf() / 1000);
125
- }, m2.valueOf = function() {
126
- return this.$d.getTime();
127
- }, m2.startOf = function(t2, e2) {
128
- var n2 = this, r2 = !!b.u(e2) || e2, f2 = b.p(t2), l2 = function(t3, e3) {
129
- var i2 = b.w(n2.$u ? Date.UTC(n2.$y, e3, t3) : new Date(n2.$y, e3, t3), n2);
130
- return r2 ? i2 : i2.endOf(a);
131
- }, $2 = function(t3, e3) {
132
- return b.w(n2.toDate()[t3].apply(n2.toDate("s"), (r2 ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(e3)), n2);
133
- }, y2 = this.$W, M3 = this.$M, m3 = this.$D, v2 = "set" + (this.$u ? "UTC" : "");
134
- switch (f2) {
135
- case h:
136
- return r2 ? l2(1, 0) : l2(31, 11);
137
- case c:
138
- return r2 ? l2(1, M3) : l2(0, M3 + 1);
139
- case o:
140
- var g2 = this.$locale().weekStart || 0, D2 = (y2 < g2 ? y2 + 7 : y2) - g2;
141
- return l2(r2 ? m3 - D2 : m3 + (6 - D2), M3);
142
- case a:
143
- case d:
144
- return $2(v2 + "Hours", 0);
145
- case u:
146
- return $2(v2 + "Minutes", 1);
147
- case s:
148
- return $2(v2 + "Seconds", 2);
149
- case i:
150
- return $2(v2 + "Milliseconds", 3);
151
- default:
152
- return this.clone();
153
- }
154
- }, m2.endOf = function(t2) {
155
- return this.startOf(t2, false);
156
- }, m2.$set = function(t2, e2) {
157
- 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;
158
- if (o2 === c || o2 === h) {
159
- var y2 = this.clone().set(d, 1);
160
- y2.$d[l2]($2), y2.init(), this.$d = y2.set(d, Math.min(this.$D, y2.daysInMonth())).$d;
161
- } else
162
- l2 && this.$d[l2]($2);
163
- return this.init(), this;
164
- }, m2.set = function(t2, e2) {
165
- return this.clone().$set(t2, e2);
166
- }, m2.get = function(t2) {
167
- return this[b.p(t2)]();
168
- }, m2.add = function(r2, f2) {
169
- var d2, l2 = this;
170
- r2 = Number(r2);
171
- var $2 = b.p(f2), y2 = function(t2) {
172
- var e2 = O(l2);
173
- return b.w(e2.date(e2.date() + Math.round(t2 * r2)), l2);
174
- };
175
- if ($2 === c)
176
- return this.set(c, this.$M + r2);
177
- if ($2 === h)
178
- return this.set(h, this.$y + r2);
179
- if ($2 === a)
180
- return y2(1);
181
- if ($2 === o)
182
- return y2(7);
183
- var M3 = (d2 = {}, d2[s] = e, d2[u] = n, d2[i] = t, d2)[$2] || 1, m3 = this.$d.getTime() + r2 * M3;
184
- return b.w(m3, this);
185
- }, m2.subtract = function(t2, e2) {
186
- return this.add(-1 * t2, e2);
187
- }, m2.format = function(t2) {
188
- var e2 = this, n2 = this.$locale();
189
- if (!this.isValid())
190
- return n2.invalidDate || l;
191
- 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) {
192
- return t3 && (t3[n3] || t3(e2, r2)) || i3[n3].slice(0, s3);
193
- }, d2 = function(t3) {
194
- return b.s(s2 % 12 || 12, t3, "0");
195
- }, $2 = f2 || function(t3, e3, n3) {
196
- var r3 = t3 < 12 ? "AM" : "PM";
197
- return n3 ? r3.toLowerCase() : r3;
198
- };
199
- return r2.replace(y, function(t3, r3) {
200
- return r3 || function(t4) {
201
- switch (t4) {
202
- case "YY":
203
- return String(e2.$y).slice(-2);
204
- case "YYYY":
205
- return b.s(e2.$y, 4, "0");
206
- case "M":
207
- return a2 + 1;
208
- case "MM":
209
- return b.s(a2 + 1, 2, "0");
210
- case "MMM":
211
- return h2(n2.monthsShort, a2, c2, 3);
212
- case "MMMM":
213
- return h2(c2, a2);
214
- case "D":
215
- return e2.$D;
216
- case "DD":
217
- return b.s(e2.$D, 2, "0");
218
- case "d":
219
- return String(e2.$W);
220
- case "dd":
221
- return h2(n2.weekdaysMin, e2.$W, o2, 2);
222
- case "ddd":
223
- return h2(n2.weekdaysShort, e2.$W, o2, 3);
224
- case "dddd":
225
- return o2[e2.$W];
226
- case "H":
227
- return String(s2);
228
- case "HH":
229
- return b.s(s2, 2, "0");
230
- case "h":
231
- return d2(1);
232
- case "hh":
233
- return d2(2);
234
- case "a":
235
- return $2(s2, u2, true);
236
- case "A":
237
- return $2(s2, u2, false);
238
- case "m":
239
- return String(u2);
240
- case "mm":
241
- return b.s(u2, 2, "0");
242
- case "s":
243
- return String(e2.$s);
244
- case "ss":
245
- return b.s(e2.$s, 2, "0");
246
- case "SSS":
247
- return b.s(e2.$ms, 3, "0");
248
- case "Z":
249
- return i2;
250
- }
251
- return null;
252
- }(t3) || i2.replace(":", "");
253
- });
254
- }, m2.utcOffset = function() {
255
- return 15 * -Math.round(this.$d.getTimezoneOffset() / 15);
256
- }, m2.diff = function(r2, d2, l2) {
257
- var $2, y2 = this, M3 = b.p(d2), m3 = O(r2), v2 = (m3.utcOffset() - this.utcOffset()) * e, g2 = this - m3, D2 = function() {
258
- return b.m(y2, m3);
259
- };
260
- switch (M3) {
261
- case h:
262
- $2 = D2() / 12;
263
- break;
264
- case c:
265
- $2 = D2();
266
- break;
267
- case f:
268
- $2 = D2() / 3;
269
- break;
270
- case o:
271
- $2 = (g2 - v2) / 604800000;
272
- break;
273
- case a:
274
- $2 = (g2 - v2) / 86400000;
43
+ var require_eventemitter3 = __commonJS((exports, module) => {
44
+ var has = Object.prototype.hasOwnProperty;
45
+ var prefix = "~";
46
+ function Events() {}
47
+ if (Object.create) {
48
+ Events.prototype = Object.create(null);
49
+ if (!new Events().__proto__)
50
+ prefix = false;
51
+ }
52
+ function EE(fn, context, once) {
53
+ this.fn = fn;
54
+ this.context = context;
55
+ this.once = once || false;
56
+ }
57
+ function addListener(emitter, event, fn, context, once) {
58
+ if (typeof fn !== "function") {
59
+ throw new TypeError("The listener must be a function");
60
+ }
61
+ var listener = new EE(fn, context || emitter, once), evt = prefix ? prefix + event : event;
62
+ if (!emitter._events[evt])
63
+ emitter._events[evt] = listener, emitter._eventsCount++;
64
+ else if (!emitter._events[evt].fn)
65
+ emitter._events[evt].push(listener);
66
+ else
67
+ emitter._events[evt] = [emitter._events[evt], listener];
68
+ return emitter;
69
+ }
70
+ function clearEvent(emitter, evt) {
71
+ if (--emitter._eventsCount === 0)
72
+ emitter._events = new Events;
73
+ else
74
+ delete emitter._events[evt];
75
+ }
76
+ function EventEmitter() {
77
+ this._events = new Events;
78
+ this._eventsCount = 0;
79
+ }
80
+ EventEmitter.prototype.eventNames = function eventNames() {
81
+ var names = [], events, name;
82
+ if (this._eventsCount === 0)
83
+ return names;
84
+ for (name in events = this._events) {
85
+ if (has.call(events, name))
86
+ names.push(prefix ? name.slice(1) : name);
87
+ }
88
+ if (Object.getOwnPropertySymbols) {
89
+ return names.concat(Object.getOwnPropertySymbols(events));
90
+ }
91
+ return names;
92
+ };
93
+ EventEmitter.prototype.listeners = function listeners(event) {
94
+ var evt = prefix ? prefix + event : event, handlers = this._events[evt];
95
+ if (!handlers)
96
+ return [];
97
+ if (handlers.fn)
98
+ return [handlers.fn];
99
+ for (var i = 0, l = handlers.length, ee = new Array(l);i < l; i++) {
100
+ ee[i] = handlers[i].fn;
101
+ }
102
+ return ee;
103
+ };
104
+ EventEmitter.prototype.listenerCount = function listenerCount(event) {
105
+ var evt = prefix ? prefix + event : event, listeners = this._events[evt];
106
+ if (!listeners)
107
+ return 0;
108
+ if (listeners.fn)
109
+ return 1;
110
+ return listeners.length;
111
+ };
112
+ EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
113
+ var evt = prefix ? prefix + event : event;
114
+ if (!this._events[evt])
115
+ return false;
116
+ var listeners = this._events[evt], len = arguments.length, args, i;
117
+ if (listeners.fn) {
118
+ if (listeners.once)
119
+ this.removeListener(event, listeners.fn, undefined, true);
120
+ switch (len) {
121
+ case 1:
122
+ return listeners.fn.call(listeners.context), true;
123
+ case 2:
124
+ return listeners.fn.call(listeners.context, a1), true;
125
+ case 3:
126
+ return listeners.fn.call(listeners.context, a1, a2), true;
127
+ case 4:
128
+ return listeners.fn.call(listeners.context, a1, a2, a3), true;
129
+ case 5:
130
+ return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
131
+ case 6:
132
+ return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
133
+ }
134
+ for (i = 1, args = new Array(len - 1);i < len; i++) {
135
+ args[i - 1] = arguments[i];
136
+ }
137
+ listeners.fn.apply(listeners.context, args);
138
+ } else {
139
+ var length = listeners.length, j;
140
+ for (i = 0;i < length; i++) {
141
+ if (listeners[i].once)
142
+ this.removeListener(event, listeners[i].fn, undefined, true);
143
+ switch (len) {
144
+ case 1:
145
+ listeners[i].fn.call(listeners[i].context);
275
146
  break;
276
- case u:
277
- $2 = g2 / n;
147
+ case 2:
148
+ listeners[i].fn.call(listeners[i].context, a1);
278
149
  break;
279
- case s:
280
- $2 = g2 / e;
150
+ case 3:
151
+ listeners[i].fn.call(listeners[i].context, a1, a2);
281
152
  break;
282
- case i:
283
- $2 = g2 / t;
153
+ case 4:
154
+ listeners[i].fn.call(listeners[i].context, a1, a2, a3);
284
155
  break;
285
156
  default:
286
- $2 = g2;
287
- }
288
- return l2 ? $2 : b.a($2);
289
- }, m2.daysInMonth = function() {
290
- return this.endOf(c).$D;
291
- }, m2.$locale = function() {
292
- return D[this.$L];
293
- }, m2.locale = function(t2, e2) {
294
- if (!t2)
295
- return this.$L;
296
- var n2 = this.clone(), r2 = w(t2, e2, true);
297
- return r2 && (n2.$L = r2), n2;
298
- }, m2.clone = function() {
299
- return b.w(this.$d, this);
300
- }, m2.toDate = function() {
301
- return new Date(this.valueOf());
302
- }, m2.toJSON = function() {
303
- return this.isValid() ? this.toISOString() : null;
304
- }, m2.toISOString = function() {
305
- return this.$d.toISOString();
306
- }, m2.toString = function() {
307
- return this.$d.toUTCString();
308
- }, M2;
309
- }(), k = _.prototype;
310
- return O.prototype = k, [["$ms", r], ["$s", i], ["$m", s], ["$H", u], ["$W", a], ["$M", c], ["$y", h], ["$D", d]].forEach(function(t2) {
311
- k[t2[1]] = function(e2) {
312
- return this.$g(e2, t2[0], t2[1]);
313
- };
314
- }), O.extend = function(t2, e2) {
315
- return t2.$i || (t2(e2, _, O), t2.$i = true), O;
316
- }, O.locale = w, O.isDayjs = S, O.unix = function(t2) {
317
- return O(1000 * t2);
318
- }, O.en = D[g], O.Ls = D, O.p = {}, O;
319
- });
157
+ if (!args)
158
+ for (j = 1, args = new Array(len - 1);j < len; j++) {
159
+ args[j - 1] = arguments[j];
160
+ }
161
+ listeners[i].fn.apply(listeners[i].context, args);
162
+ }
163
+ }
164
+ }
165
+ return true;
166
+ };
167
+ EventEmitter.prototype.on = function on(event, fn, context) {
168
+ return addListener(this, event, fn, context, false);
169
+ };
170
+ EventEmitter.prototype.once = function once(event, fn, context) {
171
+ return addListener(this, event, fn, context, true);
172
+ };
173
+ EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
174
+ var evt = prefix ? prefix + event : event;
175
+ if (!this._events[evt])
176
+ return this;
177
+ if (!fn) {
178
+ clearEvent(this, evt);
179
+ return this;
180
+ }
181
+ var listeners = this._events[evt];
182
+ if (listeners.fn) {
183
+ if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) {
184
+ clearEvent(this, evt);
185
+ }
186
+ } else {
187
+ for (var i = 0, events = [], length = listeners.length;i < length; i++) {
188
+ if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) {
189
+ events.push(listeners[i]);
190
+ }
191
+ }
192
+ if (events.length)
193
+ this._events[evt] = events.length === 1 ? events[0] : events;
194
+ else
195
+ clearEvent(this, evt);
196
+ }
197
+ return this;
198
+ };
199
+ EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
200
+ var evt;
201
+ if (event) {
202
+ evt = prefix ? prefix + event : event;
203
+ if (this._events[evt])
204
+ clearEvent(this, evt);
205
+ } else {
206
+ this._events = new Events;
207
+ this._eventsCount = 0;
208
+ }
209
+ return this;
210
+ };
211
+ EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
212
+ EventEmitter.prototype.addListener = EventEmitter.prototype.on;
213
+ EventEmitter.prefixed = prefix;
214
+ EventEmitter.EventEmitter = EventEmitter;
215
+ if (typeof module !== "undefined") {
216
+ module.exports = EventEmitter;
217
+ }
320
218
  });
321
-
322
- // node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/constants.js
323
- var require_constants2 = __commonJS((exports, module) => {
219
+ var require_constants = __commonJS((exports, module) => {
324
220
  var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
325
221
  var hasBlob = typeof Blob !== "undefined";
326
222
  if (hasBlob)
327
223
  BINARY_TYPES.push("blob");
328
224
  module.exports = {
329
225
  BINARY_TYPES,
330
- CLOSE_TIMEOUT: 30000,
331
226
  EMPTY_BUFFER: Buffer.alloc(0),
332
227
  GUID: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
333
228
  hasBlob,
@@ -338,10 +233,8 @@ var require_constants2 = __commonJS((exports, module) => {
338
233
  NOOP: () => {}
339
234
  };
340
235
  });
341
-
342
- // node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/buffer-util.js
343
- var require_buffer_util2 = __commonJS((exports, module) => {
344
- var { EMPTY_BUFFER } = require_constants2();
236
+ var require_buffer_util = __commonJS((exports, module) => {
237
+ var { EMPTY_BUFFER } = require_constants();
345
238
  var FastBuffer = Buffer[Symbol.species];
346
239
  function concat(list, totalLength) {
347
240
  if (list.length === 0)
@@ -399,9 +292,7 @@ var require_buffer_util2 = __commonJS((exports, module) => {
399
292
  unmask: _unmask
400
293
  };
401
294
  });
402
-
403
- // node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/limiter.js
404
- var require_limiter2 = __commonJS((exports, module) => {
295
+ var require_limiter = __commonJS((exports, module) => {
405
296
  var kDone = Symbol("kDone");
406
297
  var kRun = Symbol("kRun");
407
298
 
@@ -431,13 +322,11 @@ var require_limiter2 = __commonJS((exports, module) => {
431
322
  }
432
323
  module.exports = Limiter;
433
324
  });
434
-
435
- // node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/permessage-deflate.js
436
- var require_permessage_deflate2 = __commonJS((exports, module) => {
325
+ var require_permessage_deflate = __commonJS((exports, module) => {
437
326
  var zlib = __require("zlib");
438
- var bufferUtil = require_buffer_util2();
439
- var Limiter = require_limiter2();
440
- var { kStatusCode } = require_constants2();
327
+ var bufferUtil = require_buffer_util();
328
+ var Limiter = require_limiter();
329
+ var { kStatusCode } = require_constants();
441
330
  var FastBuffer = Buffer[Symbol.species];
442
331
  var TRAILER = Buffer.from([0, 0, 255, 255]);
443
332
  var kPerMessageDeflate = Symbol("permessage-deflate");
@@ -687,19 +576,13 @@ var require_permessage_deflate2 = __commonJS((exports, module) => {
687
576
  }
688
577
  function inflateOnError(err) {
689
578
  this[kPerMessageDeflate]._inflate = null;
690
- if (this[kError]) {
691
- this[kCallback](this[kError]);
692
- return;
693
- }
694
579
  err[kStatusCode] = 1007;
695
580
  this[kCallback](err);
696
581
  }
697
582
  });
698
-
699
- // node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/validation.js
700
- var require_validation2 = __commonJS((exports, module) => {
583
+ var require_validation = __commonJS((exports, module) => {
701
584
  var { isUtf8 } = __require("buffer");
702
- var { hasBlob } = require_constants2();
585
+ var { hasBlob } = require_constants();
703
586
  var tokenChars = [
704
587
  0,
705
588
  0,
@@ -875,19 +758,17 @@ var require_validation2 = __commonJS((exports, module) => {
875
758
  };
876
759
  }
877
760
  });
878
-
879
- // node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/receiver.js
880
- var require_receiver2 = __commonJS((exports, module) => {
761
+ var require_receiver = __commonJS((exports, module) => {
881
762
  var { Writable } = __require("stream");
882
- var PerMessageDeflate = require_permessage_deflate2();
763
+ var PerMessageDeflate = require_permessage_deflate();
883
764
  var {
884
765
  BINARY_TYPES,
885
766
  EMPTY_BUFFER,
886
767
  kStatusCode,
887
768
  kWebSocket
888
- } = require_constants2();
889
- var { concat, toArrayBuffer, unmask } = require_buffer_util2();
890
- var { isValidStatusCode, isValidUTF8 } = require_validation2();
769
+ } = require_constants();
770
+ var { concat, toArrayBuffer, unmask } = require_buffer_util();
771
+ var { isValidStatusCode, isValidUTF8 } = require_validation();
891
772
  var FastBuffer = Buffer[Symbol.species];
892
773
  var GET_INFO = 0;
893
774
  var GET_PAYLOAD_LENGTH_16 = 1;
@@ -988,14 +869,14 @@ var require_receiver2 = __commonJS((exports, module) => {
988
869
  }
989
870
  const buf = this.consume(2);
990
871
  if ((buf[0] & 48) !== 0) {
991
- const error49 = this.createError(RangeError, "RSV2 and RSV3 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_2_3");
992
- cb(error49);
872
+ const error48 = this.createError(RangeError, "RSV2 and RSV3 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_2_3");
873
+ cb(error48);
993
874
  return;
994
875
  }
995
876
  const compressed = (buf[0] & 64) === 64;
996
877
  if (compressed && !this._extensions[PerMessageDeflate.extensionName]) {
997
- const error49 = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
998
- cb(error49);
878
+ const error48 = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
879
+ cb(error48);
999
880
  return;
1000
881
  }
1001
882
  this._fin = (buf[0] & 128) === 128;
@@ -1003,42 +884,42 @@ var require_receiver2 = __commonJS((exports, module) => {
1003
884
  this._payloadLength = buf[1] & 127;
1004
885
  if (this._opcode === 0) {
1005
886
  if (compressed) {
1006
- const error49 = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
1007
- cb(error49);
887
+ const error48 = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
888
+ cb(error48);
1008
889
  return;
1009
890
  }
1010
891
  if (!this._fragmented) {
1011
- const error49 = this.createError(RangeError, "invalid opcode 0", true, 1002, "WS_ERR_INVALID_OPCODE");
1012
- cb(error49);
892
+ const error48 = this.createError(RangeError, "invalid opcode 0", true, 1002, "WS_ERR_INVALID_OPCODE");
893
+ cb(error48);
1013
894
  return;
1014
895
  }
1015
896
  this._opcode = this._fragmented;
1016
897
  } else if (this._opcode === 1 || this._opcode === 2) {
1017
898
  if (this._fragmented) {
1018
- const error49 = this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, "WS_ERR_INVALID_OPCODE");
1019
- cb(error49);
899
+ const error48 = this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, "WS_ERR_INVALID_OPCODE");
900
+ cb(error48);
1020
901
  return;
1021
902
  }
1022
903
  this._compressed = compressed;
1023
904
  } else if (this._opcode > 7 && this._opcode < 11) {
1024
905
  if (!this._fin) {
1025
- const error49 = this.createError(RangeError, "FIN must be set", true, 1002, "WS_ERR_EXPECTED_FIN");
1026
- cb(error49);
906
+ const error48 = this.createError(RangeError, "FIN must be set", true, 1002, "WS_ERR_EXPECTED_FIN");
907
+ cb(error48);
1027
908
  return;
1028
909
  }
1029
910
  if (compressed) {
1030
- const error49 = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
1031
- cb(error49);
911
+ const error48 = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
912
+ cb(error48);
1032
913
  return;
1033
914
  }
1034
915
  if (this._payloadLength > 125 || this._opcode === 8 && this._payloadLength === 1) {
1035
- const error49 = this.createError(RangeError, `invalid payload length ${this._payloadLength}`, true, 1002, "WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");
1036
- cb(error49);
916
+ const error48 = this.createError(RangeError, `invalid payload length ${this._payloadLength}`, true, 1002, "WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");
917
+ cb(error48);
1037
918
  return;
1038
919
  }
1039
920
  } else {
1040
- const error49 = this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, "WS_ERR_INVALID_OPCODE");
1041
- cb(error49);
921
+ const error48 = this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, "WS_ERR_INVALID_OPCODE");
922
+ cb(error48);
1042
923
  return;
1043
924
  }
1044
925
  if (!this._fin && !this._fragmented)
@@ -1046,13 +927,13 @@ var require_receiver2 = __commonJS((exports, module) => {
1046
927
  this._masked = (buf[1] & 128) === 128;
1047
928
  if (this._isServer) {
1048
929
  if (!this._masked) {
1049
- const error49 = this.createError(RangeError, "MASK must be set", true, 1002, "WS_ERR_EXPECTED_MASK");
1050
- cb(error49);
930
+ const error48 = this.createError(RangeError, "MASK must be set", true, 1002, "WS_ERR_EXPECTED_MASK");
931
+ cb(error48);
1051
932
  return;
1052
933
  }
1053
934
  } else if (this._masked) {
1054
- const error49 = this.createError(RangeError, "MASK must be clear", true, 1002, "WS_ERR_UNEXPECTED_MASK");
1055
- cb(error49);
935
+ const error48 = this.createError(RangeError, "MASK must be clear", true, 1002, "WS_ERR_UNEXPECTED_MASK");
936
+ cb(error48);
1056
937
  return;
1057
938
  }
1058
939
  if (this._payloadLength === 126)
@@ -1078,8 +959,8 @@ var require_receiver2 = __commonJS((exports, module) => {
1078
959
  const buf = this.consume(8);
1079
960
  const num = buf.readUInt32BE(0);
1080
961
  if (num > Math.pow(2, 53 - 32) - 1) {
1081
- const error49 = this.createError(RangeError, "Unsupported WebSocket frame: payload length > 2^53 - 1", false, 1009, "WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");
1082
- cb(error49);
962
+ const error48 = this.createError(RangeError, "Unsupported WebSocket frame: payload length > 2^53 - 1", false, 1009, "WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");
963
+ cb(error48);
1083
964
  return;
1084
965
  }
1085
966
  this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
@@ -1089,8 +970,8 @@ var require_receiver2 = __commonJS((exports, module) => {
1089
970
  if (this._payloadLength && this._opcode < 8) {
1090
971
  this._totalPayloadLength += this._payloadLength;
1091
972
  if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
1092
- const error49 = this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");
1093
- cb(error49);
973
+ const error48 = this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");
974
+ cb(error48);
1094
975
  return;
1095
976
  }
1096
977
  }
@@ -1142,3039 +1023,8 @@ var require_receiver2 = __commonJS((exports, module) => {
1142
1023
  if (buf.length) {
1143
1024
  this._messageLength += buf.length;
1144
1025
  if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
1145
- const error49 = this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");
1146
- cb(error49);
1147
- return;
1148
- }
1149
- this._fragments.push(buf);
1150
- }
1151
- this.dataMessage(cb);
1152
- if (this._state === GET_INFO)
1153
- this.startLoop(cb);
1154
- });
1155
- }
1156
- dataMessage(cb) {
1157
- if (!this._fin) {
1158
- this._state = GET_INFO;
1159
- return;
1160
- }
1161
- const messageLength = this._messageLength;
1162
- const fragments = this._fragments;
1163
- this._totalPayloadLength = 0;
1164
- this._messageLength = 0;
1165
- this._fragmented = 0;
1166
- this._fragments = [];
1167
- if (this._opcode === 2) {
1168
- let data;
1169
- if (this._binaryType === "nodebuffer") {
1170
- data = concat(fragments, messageLength);
1171
- } else if (this._binaryType === "arraybuffer") {
1172
- data = toArrayBuffer(concat(fragments, messageLength));
1173
- } else if (this._binaryType === "blob") {
1174
- data = new Blob(fragments);
1175
- } else {
1176
- data = fragments;
1177
- }
1178
- if (this._allowSynchronousEvents) {
1179
- this.emit("message", data, true);
1180
- this._state = GET_INFO;
1181
- } else {
1182
- this._state = DEFER_EVENT;
1183
- setImmediate(() => {
1184
- this.emit("message", data, true);
1185
- this._state = GET_INFO;
1186
- this.startLoop(cb);
1187
- });
1188
- }
1189
- } else {
1190
- const buf = concat(fragments, messageLength);
1191
- if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
1192
- const error49 = this.createError(Error, "invalid UTF-8 sequence", true, 1007, "WS_ERR_INVALID_UTF8");
1193
- cb(error49);
1194
- return;
1195
- }
1196
- if (this._state === INFLATING || this._allowSynchronousEvents) {
1197
- this.emit("message", buf, false);
1198
- this._state = GET_INFO;
1199
- } else {
1200
- this._state = DEFER_EVENT;
1201
- setImmediate(() => {
1202
- this.emit("message", buf, false);
1203
- this._state = GET_INFO;
1204
- this.startLoop(cb);
1205
- });
1206
- }
1207
- }
1208
- }
1209
- controlMessage(data, cb) {
1210
- if (this._opcode === 8) {
1211
- if (data.length === 0) {
1212
- this._loop = false;
1213
- this.emit("conclude", 1005, EMPTY_BUFFER);
1214
- this.end();
1215
- } else {
1216
- const code = data.readUInt16BE(0);
1217
- if (!isValidStatusCode(code)) {
1218
- const error49 = this.createError(RangeError, `invalid status code ${code}`, true, 1002, "WS_ERR_INVALID_CLOSE_CODE");
1219
- cb(error49);
1220
- return;
1221
- }
1222
- const buf = new FastBuffer(data.buffer, data.byteOffset + 2, data.length - 2);
1223
- if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
1224
- const error49 = this.createError(Error, "invalid UTF-8 sequence", true, 1007, "WS_ERR_INVALID_UTF8");
1225
- cb(error49);
1226
- return;
1227
- }
1228
- this._loop = false;
1229
- this.emit("conclude", code, buf);
1230
- this.end();
1231
- }
1232
- this._state = GET_INFO;
1233
- return;
1234
- }
1235
- if (this._allowSynchronousEvents) {
1236
- this.emit(this._opcode === 9 ? "ping" : "pong", data);
1237
- this._state = GET_INFO;
1238
- } else {
1239
- this._state = DEFER_EVENT;
1240
- setImmediate(() => {
1241
- this.emit(this._opcode === 9 ? "ping" : "pong", data);
1242
- this._state = GET_INFO;
1243
- this.startLoop(cb);
1244
- });
1245
- }
1246
- }
1247
- createError(ErrorCtor, message, prefix, statusCode, errorCode) {
1248
- this._loop = false;
1249
- this._errored = true;
1250
- const err = new ErrorCtor(prefix ? `Invalid WebSocket frame: ${message}` : message);
1251
- Error.captureStackTrace(err, this.createError);
1252
- err.code = errorCode;
1253
- err[kStatusCode] = statusCode;
1254
- return err;
1255
- }
1256
- }
1257
- module.exports = Receiver;
1258
- });
1259
-
1260
- // node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/sender.js
1261
- var require_sender2 = __commonJS((exports, module) => {
1262
- var { Duplex } = __require("stream");
1263
- var { randomFillSync } = __require("crypto");
1264
- var PerMessageDeflate = require_permessage_deflate2();
1265
- var { EMPTY_BUFFER, kWebSocket, NOOP } = require_constants2();
1266
- var { isBlob, isValidStatusCode } = require_validation2();
1267
- var { mask: applyMask, toBuffer } = require_buffer_util2();
1268
- var kByteLength = Symbol("kByteLength");
1269
- var maskBuffer = Buffer.alloc(4);
1270
- var RANDOM_POOL_SIZE = 8 * 1024;
1271
- var randomPool;
1272
- var randomPoolPointer = RANDOM_POOL_SIZE;
1273
- var DEFAULT = 0;
1274
- var DEFLATING = 1;
1275
- var GET_BLOB_DATA = 2;
1276
-
1277
- class Sender {
1278
- constructor(socket, extensions, generateMask) {
1279
- this._extensions = extensions || {};
1280
- if (generateMask) {
1281
- this._generateMask = generateMask;
1282
- this._maskBuffer = Buffer.alloc(4);
1283
- }
1284
- this._socket = socket;
1285
- this._firstFragment = true;
1286
- this._compress = false;
1287
- this._bufferedBytes = 0;
1288
- this._queue = [];
1289
- this._state = DEFAULT;
1290
- this.onerror = NOOP;
1291
- this[kWebSocket] = undefined;
1292
- }
1293
- static frame(data, options) {
1294
- let mask;
1295
- let merge4 = false;
1296
- let offset = 2;
1297
- let skipMasking = false;
1298
- if (options.mask) {
1299
- mask = options.maskBuffer || maskBuffer;
1300
- if (options.generateMask) {
1301
- options.generateMask(mask);
1302
- } else {
1303
- if (randomPoolPointer === RANDOM_POOL_SIZE) {
1304
- if (randomPool === undefined) {
1305
- randomPool = Buffer.alloc(RANDOM_POOL_SIZE);
1306
- }
1307
- randomFillSync(randomPool, 0, RANDOM_POOL_SIZE);
1308
- randomPoolPointer = 0;
1309
- }
1310
- mask[0] = randomPool[randomPoolPointer++];
1311
- mask[1] = randomPool[randomPoolPointer++];
1312
- mask[2] = randomPool[randomPoolPointer++];
1313
- mask[3] = randomPool[randomPoolPointer++];
1314
- }
1315
- skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) === 0;
1316
- offset = 6;
1317
- }
1318
- let dataLength;
1319
- if (typeof data === "string") {
1320
- if ((!options.mask || skipMasking) && options[kByteLength] !== undefined) {
1321
- dataLength = options[kByteLength];
1322
- } else {
1323
- data = Buffer.from(data);
1324
- dataLength = data.length;
1325
- }
1326
- } else {
1327
- dataLength = data.length;
1328
- merge4 = options.mask && options.readOnly && !skipMasking;
1329
- }
1330
- let payloadLength = dataLength;
1331
- if (dataLength >= 65536) {
1332
- offset += 8;
1333
- payloadLength = 127;
1334
- } else if (dataLength > 125) {
1335
- offset += 2;
1336
- payloadLength = 126;
1337
- }
1338
- const target = Buffer.allocUnsafe(merge4 ? dataLength + offset : offset);
1339
- target[0] = options.fin ? options.opcode | 128 : options.opcode;
1340
- if (options.rsv1)
1341
- target[0] |= 64;
1342
- target[1] = payloadLength;
1343
- if (payloadLength === 126) {
1344
- target.writeUInt16BE(dataLength, 2);
1345
- } else if (payloadLength === 127) {
1346
- target[2] = target[3] = 0;
1347
- target.writeUIntBE(dataLength, 4, 6);
1348
- }
1349
- if (!options.mask)
1350
- return [target, data];
1351
- target[1] |= 128;
1352
- target[offset - 4] = mask[0];
1353
- target[offset - 3] = mask[1];
1354
- target[offset - 2] = mask[2];
1355
- target[offset - 1] = mask[3];
1356
- if (skipMasking)
1357
- return [target, data];
1358
- if (merge4) {
1359
- applyMask(data, mask, target, offset, dataLength);
1360
- return [target];
1361
- }
1362
- applyMask(data, mask, data, 0, dataLength);
1363
- return [target, data];
1364
- }
1365
- close(code, data, mask, cb) {
1366
- let buf;
1367
- if (code === undefined) {
1368
- buf = EMPTY_BUFFER;
1369
- } else if (typeof code !== "number" || !isValidStatusCode(code)) {
1370
- throw new TypeError("First argument must be a valid error code number");
1371
- } else if (data === undefined || !data.length) {
1372
- buf = Buffer.allocUnsafe(2);
1373
- buf.writeUInt16BE(code, 0);
1374
- } else {
1375
- const length = Buffer.byteLength(data);
1376
- if (length > 123) {
1377
- throw new RangeError("The message must not be greater than 123 bytes");
1378
- }
1379
- buf = Buffer.allocUnsafe(2 + length);
1380
- buf.writeUInt16BE(code, 0);
1381
- if (typeof data === "string") {
1382
- buf.write(data, 2);
1383
- } else {
1384
- buf.set(data, 2);
1385
- }
1386
- }
1387
- const options = {
1388
- [kByteLength]: buf.length,
1389
- fin: true,
1390
- generateMask: this._generateMask,
1391
- mask,
1392
- maskBuffer: this._maskBuffer,
1393
- opcode: 8,
1394
- readOnly: false,
1395
- rsv1: false
1396
- };
1397
- if (this._state !== DEFAULT) {
1398
- this.enqueue([this.dispatch, buf, false, options, cb]);
1399
- } else {
1400
- this.sendFrame(Sender.frame(buf, options), cb);
1401
- }
1402
- }
1403
- ping(data, mask, cb) {
1404
- let byteLength;
1405
- let readOnly;
1406
- if (typeof data === "string") {
1407
- byteLength = Buffer.byteLength(data);
1408
- readOnly = false;
1409
- } else if (isBlob(data)) {
1410
- byteLength = data.size;
1411
- readOnly = false;
1412
- } else {
1413
- data = toBuffer(data);
1414
- byteLength = data.length;
1415
- readOnly = toBuffer.readOnly;
1416
- }
1417
- if (byteLength > 125) {
1418
- throw new RangeError("The data size must not be greater than 125 bytes");
1419
- }
1420
- const options = {
1421
- [kByteLength]: byteLength,
1422
- fin: true,
1423
- generateMask: this._generateMask,
1424
- mask,
1425
- maskBuffer: this._maskBuffer,
1426
- opcode: 9,
1427
- readOnly,
1428
- rsv1: false
1429
- };
1430
- if (isBlob(data)) {
1431
- if (this._state !== DEFAULT) {
1432
- this.enqueue([this.getBlobData, data, false, options, cb]);
1433
- } else {
1434
- this.getBlobData(data, false, options, cb);
1435
- }
1436
- } else if (this._state !== DEFAULT) {
1437
- this.enqueue([this.dispatch, data, false, options, cb]);
1438
- } else {
1439
- this.sendFrame(Sender.frame(data, options), cb);
1440
- }
1441
- }
1442
- pong(data, mask, cb) {
1443
- let byteLength;
1444
- let readOnly;
1445
- if (typeof data === "string") {
1446
- byteLength = Buffer.byteLength(data);
1447
- readOnly = false;
1448
- } else if (isBlob(data)) {
1449
- byteLength = data.size;
1450
- readOnly = false;
1451
- } else {
1452
- data = toBuffer(data);
1453
- byteLength = data.length;
1454
- readOnly = toBuffer.readOnly;
1455
- }
1456
- if (byteLength > 125) {
1457
- throw new RangeError("The data size must not be greater than 125 bytes");
1458
- }
1459
- const options = {
1460
- [kByteLength]: byteLength,
1461
- fin: true,
1462
- generateMask: this._generateMask,
1463
- mask,
1464
- maskBuffer: this._maskBuffer,
1465
- opcode: 10,
1466
- readOnly,
1467
- rsv1: false
1468
- };
1469
- if (isBlob(data)) {
1470
- if (this._state !== DEFAULT) {
1471
- this.enqueue([this.getBlobData, data, false, options, cb]);
1472
- } else {
1473
- this.getBlobData(data, false, options, cb);
1474
- }
1475
- } else if (this._state !== DEFAULT) {
1476
- this.enqueue([this.dispatch, data, false, options, cb]);
1477
- } else {
1478
- this.sendFrame(Sender.frame(data, options), cb);
1479
- }
1480
- }
1481
- send(data, options, cb) {
1482
- const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
1483
- let opcode = options.binary ? 2 : 1;
1484
- let rsv1 = options.compress;
1485
- let byteLength;
1486
- let readOnly;
1487
- if (typeof data === "string") {
1488
- byteLength = Buffer.byteLength(data);
1489
- readOnly = false;
1490
- } else if (isBlob(data)) {
1491
- byteLength = data.size;
1492
- readOnly = false;
1493
- } else {
1494
- data = toBuffer(data);
1495
- byteLength = data.length;
1496
- readOnly = toBuffer.readOnly;
1497
- }
1498
- if (this._firstFragment) {
1499
- this._firstFragment = false;
1500
- if (rsv1 && perMessageDeflate && perMessageDeflate.params[perMessageDeflate._isServer ? "server_no_context_takeover" : "client_no_context_takeover"]) {
1501
- rsv1 = byteLength >= perMessageDeflate._threshold;
1502
- }
1503
- this._compress = rsv1;
1504
- } else {
1505
- rsv1 = false;
1506
- opcode = 0;
1507
- }
1508
- if (options.fin)
1509
- this._firstFragment = true;
1510
- const opts = {
1511
- [kByteLength]: byteLength,
1512
- fin: options.fin,
1513
- generateMask: this._generateMask,
1514
- mask: options.mask,
1515
- maskBuffer: this._maskBuffer,
1516
- opcode,
1517
- readOnly,
1518
- rsv1
1519
- };
1520
- if (isBlob(data)) {
1521
- if (this._state !== DEFAULT) {
1522
- this.enqueue([this.getBlobData, data, this._compress, opts, cb]);
1523
- } else {
1524
- this.getBlobData(data, this._compress, opts, cb);
1525
- }
1526
- } else if (this._state !== DEFAULT) {
1527
- this.enqueue([this.dispatch, data, this._compress, opts, cb]);
1528
- } else {
1529
- this.dispatch(data, this._compress, opts, cb);
1530
- }
1531
- }
1532
- getBlobData(blob, compress, options, cb) {
1533
- this._bufferedBytes += options[kByteLength];
1534
- this._state = GET_BLOB_DATA;
1535
- blob.arrayBuffer().then((arrayBuffer) => {
1536
- if (this._socket.destroyed) {
1537
- const err = new Error("The socket was closed while the blob was being read");
1538
- process.nextTick(callCallbacks, this, err, cb);
1539
- return;
1540
- }
1541
- this._bufferedBytes -= options[kByteLength];
1542
- const data = toBuffer(arrayBuffer);
1543
- if (!compress) {
1544
- this._state = DEFAULT;
1545
- this.sendFrame(Sender.frame(data, options), cb);
1546
- this.dequeue();
1547
- } else {
1548
- this.dispatch(data, compress, options, cb);
1549
- }
1550
- }).catch((err) => {
1551
- process.nextTick(onError, this, err, cb);
1552
- });
1553
- }
1554
- dispatch(data, compress, options, cb) {
1555
- if (!compress) {
1556
- this.sendFrame(Sender.frame(data, options), cb);
1557
- return;
1558
- }
1559
- const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
1560
- this._bufferedBytes += options[kByteLength];
1561
- this._state = DEFLATING;
1562
- perMessageDeflate.compress(data, options.fin, (_, buf) => {
1563
- if (this._socket.destroyed) {
1564
- const err = new Error("The socket was closed while data was being compressed");
1565
- callCallbacks(this, err, cb);
1566
- return;
1567
- }
1568
- this._bufferedBytes -= options[kByteLength];
1569
- this._state = DEFAULT;
1570
- options.readOnly = false;
1571
- this.sendFrame(Sender.frame(buf, options), cb);
1572
- this.dequeue();
1573
- });
1574
- }
1575
- dequeue() {
1576
- while (this._state === DEFAULT && this._queue.length) {
1577
- const params = this._queue.shift();
1578
- this._bufferedBytes -= params[3][kByteLength];
1579
- Reflect.apply(params[0], this, params.slice(1));
1580
- }
1581
- }
1582
- enqueue(params) {
1583
- this._bufferedBytes += params[3][kByteLength];
1584
- this._queue.push(params);
1585
- }
1586
- sendFrame(list, cb) {
1587
- if (list.length === 2) {
1588
- this._socket.cork();
1589
- this._socket.write(list[0]);
1590
- this._socket.write(list[1], cb);
1591
- this._socket.uncork();
1592
- } else {
1593
- this._socket.write(list[0], cb);
1594
- }
1595
- }
1596
- }
1597
- module.exports = Sender;
1598
- function callCallbacks(sender, err, cb) {
1599
- if (typeof cb === "function")
1600
- cb(err);
1601
- for (let i = 0;i < sender._queue.length; i++) {
1602
- const params = sender._queue[i];
1603
- const callback = params[params.length - 1];
1604
- if (typeof callback === "function")
1605
- callback(err);
1606
- }
1607
- }
1608
- function onError(sender, err, cb) {
1609
- callCallbacks(sender, err, cb);
1610
- sender.onerror(err);
1611
- }
1612
- });
1613
-
1614
- // node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/event-target.js
1615
- var require_event_target2 = __commonJS((exports, module) => {
1616
- var { kForOnEventAttribute, kListener } = require_constants2();
1617
- var kCode = Symbol("kCode");
1618
- var kData = Symbol("kData");
1619
- var kError = Symbol("kError");
1620
- var kMessage = Symbol("kMessage");
1621
- var kReason = Symbol("kReason");
1622
- var kTarget = Symbol("kTarget");
1623
- var kType = Symbol("kType");
1624
- var kWasClean = Symbol("kWasClean");
1625
-
1626
- class Event {
1627
- constructor(type) {
1628
- this[kTarget] = null;
1629
- this[kType] = type;
1630
- }
1631
- get target() {
1632
- return this[kTarget];
1633
- }
1634
- get type() {
1635
- return this[kType];
1636
- }
1637
- }
1638
- Object.defineProperty(Event.prototype, "target", { enumerable: true });
1639
- Object.defineProperty(Event.prototype, "type", { enumerable: true });
1640
-
1641
- class CloseEvent extends Event {
1642
- constructor(type, options = {}) {
1643
- super(type);
1644
- this[kCode] = options.code === undefined ? 0 : options.code;
1645
- this[kReason] = options.reason === undefined ? "" : options.reason;
1646
- this[kWasClean] = options.wasClean === undefined ? false : options.wasClean;
1647
- }
1648
- get code() {
1649
- return this[kCode];
1650
- }
1651
- get reason() {
1652
- return this[kReason];
1653
- }
1654
- get wasClean() {
1655
- return this[kWasClean];
1656
- }
1657
- }
1658
- Object.defineProperty(CloseEvent.prototype, "code", { enumerable: true });
1659
- Object.defineProperty(CloseEvent.prototype, "reason", { enumerable: true });
1660
- Object.defineProperty(CloseEvent.prototype, "wasClean", { enumerable: true });
1661
-
1662
- class ErrorEvent extends Event {
1663
- constructor(type, options = {}) {
1664
- super(type);
1665
- this[kError] = options.error === undefined ? null : options.error;
1666
- this[kMessage] = options.message === undefined ? "" : options.message;
1667
- }
1668
- get error() {
1669
- return this[kError];
1670
- }
1671
- get message() {
1672
- return this[kMessage];
1673
- }
1674
- }
1675
- Object.defineProperty(ErrorEvent.prototype, "error", { enumerable: true });
1676
- Object.defineProperty(ErrorEvent.prototype, "message", { enumerable: true });
1677
-
1678
- class MessageEvent extends Event {
1679
- constructor(type, options = {}) {
1680
- super(type);
1681
- this[kData] = options.data === undefined ? null : options.data;
1682
- }
1683
- get data() {
1684
- return this[kData];
1685
- }
1686
- }
1687
- Object.defineProperty(MessageEvent.prototype, "data", { enumerable: true });
1688
- var EventTarget = {
1689
- addEventListener(type, handler, options = {}) {
1690
- for (const listener of this.listeners(type)) {
1691
- if (!options[kForOnEventAttribute] && listener[kListener] === handler && !listener[kForOnEventAttribute]) {
1692
- return;
1693
- }
1694
- }
1695
- let wrapper;
1696
- if (type === "message") {
1697
- wrapper = function onMessage(data, isBinary) {
1698
- const event = new MessageEvent("message", {
1699
- data: isBinary ? data : data.toString()
1700
- });
1701
- event[kTarget] = this;
1702
- callListener(handler, this, event);
1703
- };
1704
- } else if (type === "close") {
1705
- wrapper = function onClose(code, message) {
1706
- const event = new CloseEvent("close", {
1707
- code,
1708
- reason: message.toString(),
1709
- wasClean: this._closeFrameReceived && this._closeFrameSent
1710
- });
1711
- event[kTarget] = this;
1712
- callListener(handler, this, event);
1713
- };
1714
- } else if (type === "error") {
1715
- wrapper = function onError(error49) {
1716
- const event = new ErrorEvent("error", {
1717
- error: error49,
1718
- message: error49.message
1719
- });
1720
- event[kTarget] = this;
1721
- callListener(handler, this, event);
1722
- };
1723
- } else if (type === "open") {
1724
- wrapper = function onOpen() {
1725
- const event = new Event("open");
1726
- event[kTarget] = this;
1727
- callListener(handler, this, event);
1728
- };
1729
- } else {
1730
- return;
1731
- }
1732
- wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute];
1733
- wrapper[kListener] = handler;
1734
- if (options.once) {
1735
- this.once(type, wrapper);
1736
- } else {
1737
- this.on(type, wrapper);
1738
- }
1739
- },
1740
- removeEventListener(type, handler) {
1741
- for (const listener of this.listeners(type)) {
1742
- if (listener[kListener] === handler && !listener[kForOnEventAttribute]) {
1743
- this.removeListener(type, listener);
1744
- break;
1745
- }
1746
- }
1747
- }
1748
- };
1749
- module.exports = {
1750
- CloseEvent,
1751
- ErrorEvent,
1752
- Event,
1753
- EventTarget,
1754
- MessageEvent
1755
- };
1756
- function callListener(listener, thisArg, event) {
1757
- if (typeof listener === "object" && listener.handleEvent) {
1758
- listener.handleEvent.call(listener, event);
1759
- } else {
1760
- listener.call(thisArg, event);
1761
- }
1762
- }
1763
- });
1764
-
1765
- // node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/extension.js
1766
- var require_extension2 = __commonJS((exports, module) => {
1767
- var { tokenChars } = require_validation2();
1768
- function push(dest, name, elem) {
1769
- if (dest[name] === undefined)
1770
- dest[name] = [elem];
1771
- else
1772
- dest[name].push(elem);
1773
- }
1774
- function parse5(header) {
1775
- const offers = Object.create(null);
1776
- let params = Object.create(null);
1777
- let mustUnescape = false;
1778
- let isEscaping = false;
1779
- let inQuotes = false;
1780
- let extensionName;
1781
- let paramName;
1782
- let start = -1;
1783
- let code = -1;
1784
- let end = -1;
1785
- let i = 0;
1786
- for (;i < header.length; i++) {
1787
- code = header.charCodeAt(i);
1788
- if (extensionName === undefined) {
1789
- if (end === -1 && tokenChars[code] === 1) {
1790
- if (start === -1)
1791
- start = i;
1792
- } else if (i !== 0 && (code === 32 || code === 9)) {
1793
- if (end === -1 && start !== -1)
1794
- end = i;
1795
- } else if (code === 59 || code === 44) {
1796
- if (start === -1) {
1797
- throw new SyntaxError(`Unexpected character at index ${i}`);
1798
- }
1799
- if (end === -1)
1800
- end = i;
1801
- const name = header.slice(start, end);
1802
- if (code === 44) {
1803
- push(offers, name, params);
1804
- params = Object.create(null);
1805
- } else {
1806
- extensionName = name;
1807
- }
1808
- start = end = -1;
1809
- } else {
1810
- throw new SyntaxError(`Unexpected character at index ${i}`);
1811
- }
1812
- } else if (paramName === undefined) {
1813
- if (end === -1 && tokenChars[code] === 1) {
1814
- if (start === -1)
1815
- start = i;
1816
- } else if (code === 32 || code === 9) {
1817
- if (end === -1 && start !== -1)
1818
- end = i;
1819
- } else if (code === 59 || code === 44) {
1820
- if (start === -1) {
1821
- throw new SyntaxError(`Unexpected character at index ${i}`);
1822
- }
1823
- if (end === -1)
1824
- end = i;
1825
- push(params, header.slice(start, end), true);
1826
- if (code === 44) {
1827
- push(offers, extensionName, params);
1828
- params = Object.create(null);
1829
- extensionName = undefined;
1830
- }
1831
- start = end = -1;
1832
- } else if (code === 61 && start !== -1 && end === -1) {
1833
- paramName = header.slice(start, i);
1834
- start = end = -1;
1835
- } else {
1836
- throw new SyntaxError(`Unexpected character at index ${i}`);
1837
- }
1838
- } else {
1839
- if (isEscaping) {
1840
- if (tokenChars[code] !== 1) {
1841
- throw new SyntaxError(`Unexpected character at index ${i}`);
1842
- }
1843
- if (start === -1)
1844
- start = i;
1845
- else if (!mustUnescape)
1846
- mustUnescape = true;
1847
- isEscaping = false;
1848
- } else if (inQuotes) {
1849
- if (tokenChars[code] === 1) {
1850
- if (start === -1)
1851
- start = i;
1852
- } else if (code === 34 && start !== -1) {
1853
- inQuotes = false;
1854
- end = i;
1855
- } else if (code === 92) {
1856
- isEscaping = true;
1857
- } else {
1858
- throw new SyntaxError(`Unexpected character at index ${i}`);
1859
- }
1860
- } else if (code === 34 && header.charCodeAt(i - 1) === 61) {
1861
- inQuotes = true;
1862
- } else if (end === -1 && tokenChars[code] === 1) {
1863
- if (start === -1)
1864
- start = i;
1865
- } else if (start !== -1 && (code === 32 || code === 9)) {
1866
- if (end === -1)
1867
- end = i;
1868
- } else if (code === 59 || code === 44) {
1869
- if (start === -1) {
1870
- throw new SyntaxError(`Unexpected character at index ${i}`);
1871
- }
1872
- if (end === -1)
1873
- end = i;
1874
- let value = header.slice(start, end);
1875
- if (mustUnescape) {
1876
- value = value.replace(/\\/g, "");
1877
- mustUnescape = false;
1878
- }
1879
- push(params, paramName, value);
1880
- if (code === 44) {
1881
- push(offers, extensionName, params);
1882
- params = Object.create(null);
1883
- extensionName = undefined;
1884
- }
1885
- paramName = undefined;
1886
- start = end = -1;
1887
- } else {
1888
- throw new SyntaxError(`Unexpected character at index ${i}`);
1889
- }
1890
- }
1891
- }
1892
- if (start === -1 || inQuotes || code === 32 || code === 9) {
1893
- throw new SyntaxError("Unexpected end of input");
1894
- }
1895
- if (end === -1)
1896
- end = i;
1897
- const token = header.slice(start, end);
1898
- if (extensionName === undefined) {
1899
- push(offers, token, params);
1900
- } else {
1901
- if (paramName === undefined) {
1902
- push(params, token, true);
1903
- } else if (mustUnescape) {
1904
- push(params, paramName, token.replace(/\\/g, ""));
1905
- } else {
1906
- push(params, paramName, token);
1907
- }
1908
- push(offers, extensionName, params);
1909
- }
1910
- return offers;
1911
- }
1912
- function format(extensions) {
1913
- return Object.keys(extensions).map((extension) => {
1914
- let configurations = extensions[extension];
1915
- if (!Array.isArray(configurations))
1916
- configurations = [configurations];
1917
- return configurations.map((params) => {
1918
- return [extension].concat(Object.keys(params).map((k) => {
1919
- let values = params[k];
1920
- if (!Array.isArray(values))
1921
- values = [values];
1922
- return values.map((v) => v === true ? k : `${k}=${v}`).join("; ");
1923
- })).join("; ");
1924
- }).join(", ");
1925
- }).join(", ");
1926
- }
1927
- module.exports = { format, parse: parse5 };
1928
- });
1929
-
1930
- // node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/websocket.js
1931
- var require_websocket2 = __commonJS((exports, module) => {
1932
- var EventEmitter3 = __require("events");
1933
- var https = __require("https");
1934
- var http = __require("http");
1935
- var net = __require("net");
1936
- var tls = __require("tls");
1937
- var { randomBytes, createHash } = __require("crypto");
1938
- var { Duplex, Readable } = __require("stream");
1939
- var { URL: URL2 } = __require("url");
1940
- var PerMessageDeflate = require_permessage_deflate2();
1941
- var Receiver = require_receiver2();
1942
- var Sender = require_sender2();
1943
- var { isBlob } = require_validation2();
1944
- var {
1945
- BINARY_TYPES,
1946
- CLOSE_TIMEOUT,
1947
- EMPTY_BUFFER,
1948
- GUID,
1949
- kForOnEventAttribute,
1950
- kListener,
1951
- kStatusCode,
1952
- kWebSocket,
1953
- NOOP
1954
- } = require_constants2();
1955
- var {
1956
- EventTarget: { addEventListener, removeEventListener }
1957
- } = require_event_target2();
1958
- var { format, parse: parse5 } = require_extension2();
1959
- var { toBuffer } = require_buffer_util2();
1960
- var kAborted = Symbol("kAborted");
1961
- var protocolVersions = [8, 13];
1962
- var readyStates = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"];
1963
- var subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
1964
-
1965
- class WebSocket extends EventEmitter3 {
1966
- constructor(address, protocols, options) {
1967
- super();
1968
- this._binaryType = BINARY_TYPES[0];
1969
- this._closeCode = 1006;
1970
- this._closeFrameReceived = false;
1971
- this._closeFrameSent = false;
1972
- this._closeMessage = EMPTY_BUFFER;
1973
- this._closeTimer = null;
1974
- this._errorEmitted = false;
1975
- this._extensions = {};
1976
- this._paused = false;
1977
- this._protocol = "";
1978
- this._readyState = WebSocket.CONNECTING;
1979
- this._receiver = null;
1980
- this._sender = null;
1981
- this._socket = null;
1982
- if (address !== null) {
1983
- this._bufferedAmount = 0;
1984
- this._isServer = false;
1985
- this._redirects = 0;
1986
- if (protocols === undefined) {
1987
- protocols = [];
1988
- } else if (!Array.isArray(protocols)) {
1989
- if (typeof protocols === "object" && protocols !== null) {
1990
- options = protocols;
1991
- protocols = [];
1992
- } else {
1993
- protocols = [protocols];
1994
- }
1995
- }
1996
- initAsClient(this, address, protocols, options);
1997
- } else {
1998
- this._autoPong = options.autoPong;
1999
- this._closeTimeout = options.closeTimeout;
2000
- this._isServer = true;
2001
- }
2002
- }
2003
- get binaryType() {
2004
- return this._binaryType;
2005
- }
2006
- set binaryType(type) {
2007
- if (!BINARY_TYPES.includes(type))
2008
- return;
2009
- this._binaryType = type;
2010
- if (this._receiver)
2011
- this._receiver._binaryType = type;
2012
- }
2013
- get bufferedAmount() {
2014
- if (!this._socket)
2015
- return this._bufferedAmount;
2016
- return this._socket._writableState.length + this._sender._bufferedBytes;
2017
- }
2018
- get extensions() {
2019
- return Object.keys(this._extensions).join();
2020
- }
2021
- get isPaused() {
2022
- return this._paused;
2023
- }
2024
- get onclose() {
2025
- return null;
2026
- }
2027
- get onerror() {
2028
- return null;
2029
- }
2030
- get onopen() {
2031
- return null;
2032
- }
2033
- get onmessage() {
2034
- return null;
2035
- }
2036
- get protocol() {
2037
- return this._protocol;
2038
- }
2039
- get readyState() {
2040
- return this._readyState;
2041
- }
2042
- get url() {
2043
- return this._url;
2044
- }
2045
- setSocket(socket, head, options) {
2046
- const receiver = new Receiver({
2047
- allowSynchronousEvents: options.allowSynchronousEvents,
2048
- binaryType: this.binaryType,
2049
- extensions: this._extensions,
2050
- isServer: this._isServer,
2051
- maxPayload: options.maxPayload,
2052
- skipUTF8Validation: options.skipUTF8Validation
2053
- });
2054
- const sender = new Sender(socket, this._extensions, options.generateMask);
2055
- this._receiver = receiver;
2056
- this._sender = sender;
2057
- this._socket = socket;
2058
- receiver[kWebSocket] = this;
2059
- sender[kWebSocket] = this;
2060
- socket[kWebSocket] = this;
2061
- receiver.on("conclude", receiverOnConclude);
2062
- receiver.on("drain", receiverOnDrain);
2063
- receiver.on("error", receiverOnError);
2064
- receiver.on("message", receiverOnMessage);
2065
- receiver.on("ping", receiverOnPing);
2066
- receiver.on("pong", receiverOnPong);
2067
- sender.onerror = senderOnError;
2068
- if (socket.setTimeout)
2069
- socket.setTimeout(0);
2070
- if (socket.setNoDelay)
2071
- socket.setNoDelay();
2072
- if (head.length > 0)
2073
- socket.unshift(head);
2074
- socket.on("close", socketOnClose);
2075
- socket.on("data", socketOnData);
2076
- socket.on("end", socketOnEnd);
2077
- socket.on("error", socketOnError);
2078
- this._readyState = WebSocket.OPEN;
2079
- this.emit("open");
2080
- }
2081
- emitClose() {
2082
- if (!this._socket) {
2083
- this._readyState = WebSocket.CLOSED;
2084
- this.emit("close", this._closeCode, this._closeMessage);
2085
- return;
2086
- }
2087
- if (this._extensions[PerMessageDeflate.extensionName]) {
2088
- this._extensions[PerMessageDeflate.extensionName].cleanup();
2089
- }
2090
- this._receiver.removeAllListeners();
2091
- this._readyState = WebSocket.CLOSED;
2092
- this.emit("close", this._closeCode, this._closeMessage);
2093
- }
2094
- close(code, data) {
2095
- if (this.readyState === WebSocket.CLOSED)
2096
- return;
2097
- if (this.readyState === WebSocket.CONNECTING) {
2098
- const msg = "WebSocket was closed before the connection was established";
2099
- abortHandshake(this, this._req, msg);
2100
- return;
2101
- }
2102
- if (this.readyState === WebSocket.CLOSING) {
2103
- if (this._closeFrameSent && (this._closeFrameReceived || this._receiver._writableState.errorEmitted)) {
2104
- this._socket.end();
2105
- }
2106
- return;
2107
- }
2108
- this._readyState = WebSocket.CLOSING;
2109
- this._sender.close(code, data, !this._isServer, (err) => {
2110
- if (err)
2111
- return;
2112
- this._closeFrameSent = true;
2113
- if (this._closeFrameReceived || this._receiver._writableState.errorEmitted) {
2114
- this._socket.end();
2115
- }
2116
- });
2117
- setCloseTimer(this);
2118
- }
2119
- pause() {
2120
- if (this.readyState === WebSocket.CONNECTING || this.readyState === WebSocket.CLOSED) {
2121
- return;
2122
- }
2123
- this._paused = true;
2124
- this._socket.pause();
2125
- }
2126
- ping(data, mask, cb) {
2127
- if (this.readyState === WebSocket.CONNECTING) {
2128
- throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
2129
- }
2130
- if (typeof data === "function") {
2131
- cb = data;
2132
- data = mask = undefined;
2133
- } else if (typeof mask === "function") {
2134
- cb = mask;
2135
- mask = undefined;
2136
- }
2137
- if (typeof data === "number")
2138
- data = data.toString();
2139
- if (this.readyState !== WebSocket.OPEN) {
2140
- sendAfterClose(this, data, cb);
2141
- return;
2142
- }
2143
- if (mask === undefined)
2144
- mask = !this._isServer;
2145
- this._sender.ping(data || EMPTY_BUFFER, mask, cb);
2146
- }
2147
- pong(data, mask, cb) {
2148
- if (this.readyState === WebSocket.CONNECTING) {
2149
- throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
2150
- }
2151
- if (typeof data === "function") {
2152
- cb = data;
2153
- data = mask = undefined;
2154
- } else if (typeof mask === "function") {
2155
- cb = mask;
2156
- mask = undefined;
2157
- }
2158
- if (typeof data === "number")
2159
- data = data.toString();
2160
- if (this.readyState !== WebSocket.OPEN) {
2161
- sendAfterClose(this, data, cb);
2162
- return;
2163
- }
2164
- if (mask === undefined)
2165
- mask = !this._isServer;
2166
- this._sender.pong(data || EMPTY_BUFFER, mask, cb);
2167
- }
2168
- resume() {
2169
- if (this.readyState === WebSocket.CONNECTING || this.readyState === WebSocket.CLOSED) {
2170
- return;
2171
- }
2172
- this._paused = false;
2173
- if (!this._receiver._writableState.needDrain)
2174
- this._socket.resume();
2175
- }
2176
- send(data, options, cb) {
2177
- if (this.readyState === WebSocket.CONNECTING) {
2178
- throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
2179
- }
2180
- if (typeof options === "function") {
2181
- cb = options;
2182
- options = {};
2183
- }
2184
- if (typeof data === "number")
2185
- data = data.toString();
2186
- if (this.readyState !== WebSocket.OPEN) {
2187
- sendAfterClose(this, data, cb);
2188
- return;
2189
- }
2190
- const opts = {
2191
- binary: typeof data !== "string",
2192
- mask: !this._isServer,
2193
- compress: true,
2194
- fin: true,
2195
- ...options
2196
- };
2197
- if (!this._extensions[PerMessageDeflate.extensionName]) {
2198
- opts.compress = false;
2199
- }
2200
- this._sender.send(data || EMPTY_BUFFER, opts, cb);
2201
- }
2202
- terminate() {
2203
- if (this.readyState === WebSocket.CLOSED)
2204
- return;
2205
- if (this.readyState === WebSocket.CONNECTING) {
2206
- const msg = "WebSocket was closed before the connection was established";
2207
- abortHandshake(this, this._req, msg);
2208
- return;
2209
- }
2210
- if (this._socket) {
2211
- this._readyState = WebSocket.CLOSING;
2212
- this._socket.destroy();
2213
- }
2214
- }
2215
- }
2216
- Object.defineProperty(WebSocket, "CONNECTING", {
2217
- enumerable: true,
2218
- value: readyStates.indexOf("CONNECTING")
2219
- });
2220
- Object.defineProperty(WebSocket.prototype, "CONNECTING", {
2221
- enumerable: true,
2222
- value: readyStates.indexOf("CONNECTING")
2223
- });
2224
- Object.defineProperty(WebSocket, "OPEN", {
2225
- enumerable: true,
2226
- value: readyStates.indexOf("OPEN")
2227
- });
2228
- Object.defineProperty(WebSocket.prototype, "OPEN", {
2229
- enumerable: true,
2230
- value: readyStates.indexOf("OPEN")
2231
- });
2232
- Object.defineProperty(WebSocket, "CLOSING", {
2233
- enumerable: true,
2234
- value: readyStates.indexOf("CLOSING")
2235
- });
2236
- Object.defineProperty(WebSocket.prototype, "CLOSING", {
2237
- enumerable: true,
2238
- value: readyStates.indexOf("CLOSING")
2239
- });
2240
- Object.defineProperty(WebSocket, "CLOSED", {
2241
- enumerable: true,
2242
- value: readyStates.indexOf("CLOSED")
2243
- });
2244
- Object.defineProperty(WebSocket.prototype, "CLOSED", {
2245
- enumerable: true,
2246
- value: readyStates.indexOf("CLOSED")
2247
- });
2248
- [
2249
- "binaryType",
2250
- "bufferedAmount",
2251
- "extensions",
2252
- "isPaused",
2253
- "protocol",
2254
- "readyState",
2255
- "url"
2256
- ].forEach((property) => {
2257
- Object.defineProperty(WebSocket.prototype, property, { enumerable: true });
2258
- });
2259
- ["open", "error", "close", "message"].forEach((method) => {
2260
- Object.defineProperty(WebSocket.prototype, `on${method}`, {
2261
- enumerable: true,
2262
- get() {
2263
- for (const listener of this.listeners(method)) {
2264
- if (listener[kForOnEventAttribute])
2265
- return listener[kListener];
2266
- }
2267
- return null;
2268
- },
2269
- set(handler) {
2270
- for (const listener of this.listeners(method)) {
2271
- if (listener[kForOnEventAttribute]) {
2272
- this.removeListener(method, listener);
2273
- break;
2274
- }
2275
- }
2276
- if (typeof handler !== "function")
2277
- return;
2278
- this.addEventListener(method, handler, {
2279
- [kForOnEventAttribute]: true
2280
- });
2281
- }
2282
- });
2283
- });
2284
- WebSocket.prototype.addEventListener = addEventListener;
2285
- WebSocket.prototype.removeEventListener = removeEventListener;
2286
- module.exports = WebSocket;
2287
- function initAsClient(websocket, address, protocols, options) {
2288
- const opts = {
2289
- allowSynchronousEvents: true,
2290
- autoPong: true,
2291
- closeTimeout: CLOSE_TIMEOUT,
2292
- protocolVersion: protocolVersions[1],
2293
- maxPayload: 100 * 1024 * 1024,
2294
- skipUTF8Validation: false,
2295
- perMessageDeflate: true,
2296
- followRedirects: false,
2297
- maxRedirects: 10,
2298
- ...options,
2299
- socketPath: undefined,
2300
- hostname: undefined,
2301
- protocol: undefined,
2302
- timeout: undefined,
2303
- method: "GET",
2304
- host: undefined,
2305
- path: undefined,
2306
- port: undefined
2307
- };
2308
- websocket._autoPong = opts.autoPong;
2309
- websocket._closeTimeout = opts.closeTimeout;
2310
- if (!protocolVersions.includes(opts.protocolVersion)) {
2311
- throw new RangeError(`Unsupported protocol version: ${opts.protocolVersion} ` + `(supported versions: ${protocolVersions.join(", ")})`);
2312
- }
2313
- let parsedUrl;
2314
- if (address instanceof URL2) {
2315
- parsedUrl = address;
2316
- } else {
2317
- try {
2318
- parsedUrl = new URL2(address);
2319
- } catch (e) {
2320
- throw new SyntaxError(`Invalid URL: ${address}`);
2321
- }
2322
- }
2323
- if (parsedUrl.protocol === "http:") {
2324
- parsedUrl.protocol = "ws:";
2325
- } else if (parsedUrl.protocol === "https:") {
2326
- parsedUrl.protocol = "wss:";
2327
- }
2328
- websocket._url = parsedUrl.href;
2329
- const isSecure = parsedUrl.protocol === "wss:";
2330
- const isIpcUrl = parsedUrl.protocol === "ws+unix:";
2331
- let invalidUrlMessage;
2332
- if (parsedUrl.protocol !== "ws:" && !isSecure && !isIpcUrl) {
2333
- invalidUrlMessage = `The URL's protocol must be one of "ws:", "wss:", ` + '"http:", "https:", or "ws+unix:"';
2334
- } else if (isIpcUrl && !parsedUrl.pathname) {
2335
- invalidUrlMessage = "The URL's pathname is empty";
2336
- } else if (parsedUrl.hash) {
2337
- invalidUrlMessage = "The URL contains a fragment identifier";
2338
- }
2339
- if (invalidUrlMessage) {
2340
- const err = new SyntaxError(invalidUrlMessage);
2341
- if (websocket._redirects === 0) {
2342
- throw err;
2343
- } else {
2344
- emitErrorAndClose(websocket, err);
2345
- return;
2346
- }
2347
- }
2348
- const defaultPort = isSecure ? 443 : 80;
2349
- const key = randomBytes(16).toString("base64");
2350
- const request = isSecure ? https.request : http.request;
2351
- const protocolSet = new Set;
2352
- let perMessageDeflate;
2353
- opts.createConnection = opts.createConnection || (isSecure ? tlsConnect : netConnect);
2354
- opts.defaultPort = opts.defaultPort || defaultPort;
2355
- opts.port = parsedUrl.port || defaultPort;
2356
- opts.host = parsedUrl.hostname.startsWith("[") ? parsedUrl.hostname.slice(1, -1) : parsedUrl.hostname;
2357
- opts.headers = {
2358
- ...opts.headers,
2359
- "Sec-WebSocket-Version": opts.protocolVersion,
2360
- "Sec-WebSocket-Key": key,
2361
- Connection: "Upgrade",
2362
- Upgrade: "websocket"
2363
- };
2364
- opts.path = parsedUrl.pathname + parsedUrl.search;
2365
- opts.timeout = opts.handshakeTimeout;
2366
- if (opts.perMessageDeflate) {
2367
- perMessageDeflate = new PerMessageDeflate(opts.perMessageDeflate !== true ? opts.perMessageDeflate : {}, false, opts.maxPayload);
2368
- opts.headers["Sec-WebSocket-Extensions"] = format({
2369
- [PerMessageDeflate.extensionName]: perMessageDeflate.offer()
2370
- });
2371
- }
2372
- if (protocols.length) {
2373
- for (const protocol of protocols) {
2374
- if (typeof protocol !== "string" || !subprotocolRegex.test(protocol) || protocolSet.has(protocol)) {
2375
- throw new SyntaxError("An invalid or duplicated subprotocol was specified");
2376
- }
2377
- protocolSet.add(protocol);
2378
- }
2379
- opts.headers["Sec-WebSocket-Protocol"] = protocols.join(",");
2380
- }
2381
- if (opts.origin) {
2382
- if (opts.protocolVersion < 13) {
2383
- opts.headers["Sec-WebSocket-Origin"] = opts.origin;
2384
- } else {
2385
- opts.headers.Origin = opts.origin;
2386
- }
2387
- }
2388
- if (parsedUrl.username || parsedUrl.password) {
2389
- opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
2390
- }
2391
- if (isIpcUrl) {
2392
- const parts = opts.path.split(":");
2393
- opts.socketPath = parts[0];
2394
- opts.path = parts[1];
2395
- }
2396
- let req;
2397
- if (opts.followRedirects) {
2398
- if (websocket._redirects === 0) {
2399
- websocket._originalIpc = isIpcUrl;
2400
- websocket._originalSecure = isSecure;
2401
- websocket._originalHostOrSocketPath = isIpcUrl ? opts.socketPath : parsedUrl.host;
2402
- const headers = options && options.headers;
2403
- options = { ...options, headers: {} };
2404
- if (headers) {
2405
- for (const [key2, value] of Object.entries(headers)) {
2406
- options.headers[key2.toLowerCase()] = value;
2407
- }
2408
- }
2409
- } else if (websocket.listenerCount("redirect") === 0) {
2410
- const isSameHost = isIpcUrl ? websocket._originalIpc ? opts.socketPath === websocket._originalHostOrSocketPath : false : websocket._originalIpc ? false : parsedUrl.host === websocket._originalHostOrSocketPath;
2411
- if (!isSameHost || websocket._originalSecure && !isSecure) {
2412
- delete opts.headers.authorization;
2413
- delete opts.headers.cookie;
2414
- if (!isSameHost)
2415
- delete opts.headers.host;
2416
- opts.auth = undefined;
2417
- }
2418
- }
2419
- if (opts.auth && !options.headers.authorization) {
2420
- options.headers.authorization = "Basic " + Buffer.from(opts.auth).toString("base64");
2421
- }
2422
- req = websocket._req = request(opts);
2423
- if (websocket._redirects) {
2424
- websocket.emit("redirect", websocket.url, req);
2425
- }
2426
- } else {
2427
- req = websocket._req = request(opts);
2428
- }
2429
- if (opts.timeout) {
2430
- req.on("timeout", () => {
2431
- abortHandshake(websocket, req, "Opening handshake has timed out");
2432
- });
2433
- }
2434
- req.on("error", (err) => {
2435
- if (req === null || req[kAborted])
2436
- return;
2437
- req = websocket._req = null;
2438
- emitErrorAndClose(websocket, err);
2439
- });
2440
- req.on("response", (res) => {
2441
- const location2 = res.headers.location;
2442
- const statusCode = res.statusCode;
2443
- if (location2 && opts.followRedirects && statusCode >= 300 && statusCode < 400) {
2444
- if (++websocket._redirects > opts.maxRedirects) {
2445
- abortHandshake(websocket, req, "Maximum redirects exceeded");
2446
- return;
2447
- }
2448
- req.abort();
2449
- let addr;
2450
- try {
2451
- addr = new URL2(location2, address);
2452
- } catch (e) {
2453
- const err = new SyntaxError(`Invalid URL: ${location2}`);
2454
- emitErrorAndClose(websocket, err);
2455
- return;
2456
- }
2457
- initAsClient(websocket, addr, protocols, options);
2458
- } else if (!websocket.emit("unexpected-response", req, res)) {
2459
- abortHandshake(websocket, req, `Unexpected server response: ${res.statusCode}`);
2460
- }
2461
- });
2462
- req.on("upgrade", (res, socket, head) => {
2463
- websocket.emit("upgrade", res);
2464
- if (websocket.readyState !== WebSocket.CONNECTING)
2465
- return;
2466
- req = websocket._req = null;
2467
- const upgrade = res.headers.upgrade;
2468
- if (upgrade === undefined || upgrade.toLowerCase() !== "websocket") {
2469
- abortHandshake(websocket, socket, "Invalid Upgrade header");
2470
- return;
2471
- }
2472
- const digest = createHash("sha1").update(key + GUID).digest("base64");
2473
- if (res.headers["sec-websocket-accept"] !== digest) {
2474
- abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
2475
- return;
2476
- }
2477
- const serverProt = res.headers["sec-websocket-protocol"];
2478
- let protError;
2479
- if (serverProt !== undefined) {
2480
- if (!protocolSet.size) {
2481
- protError = "Server sent a subprotocol but none was requested";
2482
- } else if (!protocolSet.has(serverProt)) {
2483
- protError = "Server sent an invalid subprotocol";
2484
- }
2485
- } else if (protocolSet.size) {
2486
- protError = "Server sent no subprotocol";
2487
- }
2488
- if (protError) {
2489
- abortHandshake(websocket, socket, protError);
2490
- return;
2491
- }
2492
- if (serverProt)
2493
- websocket._protocol = serverProt;
2494
- const secWebSocketExtensions = res.headers["sec-websocket-extensions"];
2495
- if (secWebSocketExtensions !== undefined) {
2496
- if (!perMessageDeflate) {
2497
- const message = "Server sent a Sec-WebSocket-Extensions header but no extension " + "was requested";
2498
- abortHandshake(websocket, socket, message);
2499
- return;
2500
- }
2501
- let extensions;
2502
- try {
2503
- extensions = parse5(secWebSocketExtensions);
2504
- } catch (err) {
2505
- const message = "Invalid Sec-WebSocket-Extensions header";
2506
- abortHandshake(websocket, socket, message);
2507
- return;
2508
- }
2509
- const extensionNames = Object.keys(extensions);
2510
- if (extensionNames.length !== 1 || extensionNames[0] !== PerMessageDeflate.extensionName) {
2511
- const message = "Server indicated an extension that was not requested";
2512
- abortHandshake(websocket, socket, message);
2513
- return;
2514
- }
2515
- try {
2516
- perMessageDeflate.accept(extensions[PerMessageDeflate.extensionName]);
2517
- } catch (err) {
2518
- const message = "Invalid Sec-WebSocket-Extensions header";
2519
- abortHandshake(websocket, socket, message);
2520
- return;
2521
- }
2522
- websocket._extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
2523
- }
2524
- websocket.setSocket(socket, head, {
2525
- allowSynchronousEvents: opts.allowSynchronousEvents,
2526
- generateMask: opts.generateMask,
2527
- maxPayload: opts.maxPayload,
2528
- skipUTF8Validation: opts.skipUTF8Validation
2529
- });
2530
- });
2531
- if (opts.finishRequest) {
2532
- opts.finishRequest(req, websocket);
2533
- } else {
2534
- req.end();
2535
- }
2536
- }
2537
- function emitErrorAndClose(websocket, err) {
2538
- websocket._readyState = WebSocket.CLOSING;
2539
- websocket._errorEmitted = true;
2540
- websocket.emit("error", err);
2541
- websocket.emitClose();
2542
- }
2543
- function netConnect(options) {
2544
- options.path = options.socketPath;
2545
- return net.connect(options);
2546
- }
2547
- function tlsConnect(options) {
2548
- options.path = undefined;
2549
- if (!options.servername && options.servername !== "") {
2550
- options.servername = net.isIP(options.host) ? "" : options.host;
2551
- }
2552
- return tls.connect(options);
2553
- }
2554
- function abortHandshake(websocket, stream, message) {
2555
- websocket._readyState = WebSocket.CLOSING;
2556
- const err = new Error(message);
2557
- Error.captureStackTrace(err, abortHandshake);
2558
- if (stream.setHeader) {
2559
- stream[kAborted] = true;
2560
- stream.abort();
2561
- if (stream.socket && !stream.socket.destroyed) {
2562
- stream.socket.destroy();
2563
- }
2564
- process.nextTick(emitErrorAndClose, websocket, err);
2565
- } else {
2566
- stream.destroy(err);
2567
- stream.once("error", websocket.emit.bind(websocket, "error"));
2568
- stream.once("close", websocket.emitClose.bind(websocket));
2569
- }
2570
- }
2571
- function sendAfterClose(websocket, data, cb) {
2572
- if (data) {
2573
- const length = isBlob(data) ? data.size : toBuffer(data).length;
2574
- if (websocket._socket)
2575
- websocket._sender._bufferedBytes += length;
2576
- else
2577
- websocket._bufferedAmount += length;
2578
- }
2579
- if (cb) {
2580
- const err = new Error(`WebSocket is not open: readyState ${websocket.readyState} ` + `(${readyStates[websocket.readyState]})`);
2581
- process.nextTick(cb, err);
2582
- }
2583
- }
2584
- function receiverOnConclude(code, reason) {
2585
- const websocket = this[kWebSocket];
2586
- websocket._closeFrameReceived = true;
2587
- websocket._closeMessage = reason;
2588
- websocket._closeCode = code;
2589
- if (websocket._socket[kWebSocket] === undefined)
2590
- return;
2591
- websocket._socket.removeListener("data", socketOnData);
2592
- process.nextTick(resume, websocket._socket);
2593
- if (code === 1005)
2594
- websocket.close();
2595
- else
2596
- websocket.close(code, reason);
2597
- }
2598
- function receiverOnDrain() {
2599
- const websocket = this[kWebSocket];
2600
- if (!websocket.isPaused)
2601
- websocket._socket.resume();
2602
- }
2603
- function receiverOnError(err) {
2604
- const websocket = this[kWebSocket];
2605
- if (websocket._socket[kWebSocket] !== undefined) {
2606
- websocket._socket.removeListener("data", socketOnData);
2607
- process.nextTick(resume, websocket._socket);
2608
- websocket.close(err[kStatusCode]);
2609
- }
2610
- if (!websocket._errorEmitted) {
2611
- websocket._errorEmitted = true;
2612
- websocket.emit("error", err);
2613
- }
2614
- }
2615
- function receiverOnFinish() {
2616
- this[kWebSocket].emitClose();
2617
- }
2618
- function receiverOnMessage(data, isBinary) {
2619
- this[kWebSocket].emit("message", data, isBinary);
2620
- }
2621
- function receiverOnPing(data) {
2622
- const websocket = this[kWebSocket];
2623
- if (websocket._autoPong)
2624
- websocket.pong(data, !this._isServer, NOOP);
2625
- websocket.emit("ping", data);
2626
- }
2627
- function receiverOnPong(data) {
2628
- this[kWebSocket].emit("pong", data);
2629
- }
2630
- function resume(stream) {
2631
- stream.resume();
2632
- }
2633
- function senderOnError(err) {
2634
- const websocket = this[kWebSocket];
2635
- if (websocket.readyState === WebSocket.CLOSED)
2636
- return;
2637
- if (websocket.readyState === WebSocket.OPEN) {
2638
- websocket._readyState = WebSocket.CLOSING;
2639
- setCloseTimer(websocket);
2640
- }
2641
- this._socket.end();
2642
- if (!websocket._errorEmitted) {
2643
- websocket._errorEmitted = true;
2644
- websocket.emit("error", err);
2645
- }
2646
- }
2647
- function setCloseTimer(websocket) {
2648
- websocket._closeTimer = setTimeout(websocket._socket.destroy.bind(websocket._socket), websocket._closeTimeout);
2649
- }
2650
- function socketOnClose() {
2651
- const websocket = this[kWebSocket];
2652
- this.removeListener("close", socketOnClose);
2653
- this.removeListener("data", socketOnData);
2654
- this.removeListener("end", socketOnEnd);
2655
- websocket._readyState = WebSocket.CLOSING;
2656
- if (!this._readableState.endEmitted && !websocket._closeFrameReceived && !websocket._receiver._writableState.errorEmitted && this._readableState.length !== 0) {
2657
- const chunk = this.read(this._readableState.length);
2658
- websocket._receiver.write(chunk);
2659
- }
2660
- websocket._receiver.end();
2661
- this[kWebSocket] = undefined;
2662
- clearTimeout(websocket._closeTimer);
2663
- if (websocket._receiver._writableState.finished || websocket._receiver._writableState.errorEmitted) {
2664
- websocket.emitClose();
2665
- } else {
2666
- websocket._receiver.on("error", receiverOnFinish);
2667
- websocket._receiver.on("finish", receiverOnFinish);
2668
- }
2669
- }
2670
- function socketOnData(chunk) {
2671
- if (!this[kWebSocket]._receiver.write(chunk)) {
2672
- this.pause();
2673
- }
2674
- }
2675
- function socketOnEnd() {
2676
- const websocket = this[kWebSocket];
2677
- websocket._readyState = WebSocket.CLOSING;
2678
- websocket._receiver.end();
2679
- this.end();
2680
- }
2681
- function socketOnError() {
2682
- const websocket = this[kWebSocket];
2683
- this.removeListener("error", socketOnError);
2684
- this.on("error", NOOP);
2685
- if (websocket) {
2686
- websocket._readyState = WebSocket.CLOSING;
2687
- this.destroy();
2688
- }
2689
- }
2690
- });
2691
-
2692
- // node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/stream.js
2693
- var require_stream2 = __commonJS((exports, module) => {
2694
- var WebSocket = require_websocket2();
2695
- var { Duplex } = __require("stream");
2696
- function emitClose(stream) {
2697
- stream.emit("close");
2698
- }
2699
- function duplexOnEnd() {
2700
- if (!this.destroyed && this._writableState.finished) {
2701
- this.destroy();
2702
- }
2703
- }
2704
- function duplexOnError(err) {
2705
- this.removeListener("error", duplexOnError);
2706
- this.destroy();
2707
- if (this.listenerCount("error") === 0) {
2708
- this.emit("error", err);
2709
- }
2710
- }
2711
- function createWebSocketStream(ws, options) {
2712
- let terminateOnDestroy = true;
2713
- const duplex = new Duplex({
2714
- ...options,
2715
- autoDestroy: false,
2716
- emitClose: false,
2717
- objectMode: false,
2718
- writableObjectMode: false
2719
- });
2720
- ws.on("message", function message(msg, isBinary) {
2721
- const data = !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
2722
- if (!duplex.push(data))
2723
- ws.pause();
2724
- });
2725
- ws.once("error", function error49(err) {
2726
- if (duplex.destroyed)
2727
- return;
2728
- terminateOnDestroy = false;
2729
- duplex.destroy(err);
2730
- });
2731
- ws.once("close", function close() {
2732
- if (duplex.destroyed)
2733
- return;
2734
- duplex.push(null);
2735
- });
2736
- duplex._destroy = function(err, callback) {
2737
- if (ws.readyState === ws.CLOSED) {
2738
- callback(err);
2739
- process.nextTick(emitClose, duplex);
2740
- return;
2741
- }
2742
- let called = false;
2743
- ws.once("error", function error49(err2) {
2744
- called = true;
2745
- callback(err2);
2746
- });
2747
- ws.once("close", function close() {
2748
- if (!called)
2749
- callback(err);
2750
- process.nextTick(emitClose, duplex);
2751
- });
2752
- if (terminateOnDestroy)
2753
- ws.terminate();
2754
- };
2755
- duplex._final = function(callback) {
2756
- if (ws.readyState === ws.CONNECTING) {
2757
- ws.once("open", function open() {
2758
- duplex._final(callback);
2759
- });
2760
- return;
2761
- }
2762
- if (ws._socket === null)
2763
- return;
2764
- if (ws._socket._writableState.finished) {
2765
- callback();
2766
- if (duplex._readableState.endEmitted)
2767
- duplex.destroy();
2768
- } else {
2769
- ws._socket.once("finish", function finish() {
2770
- callback();
2771
- });
2772
- ws.close();
2773
- }
2774
- };
2775
- duplex._read = function() {
2776
- if (ws.isPaused)
2777
- ws.resume();
2778
- };
2779
- duplex._write = function(chunk, encoding, callback) {
2780
- if (ws.readyState === ws.CONNECTING) {
2781
- ws.once("open", function open() {
2782
- duplex._write(chunk, encoding, callback);
2783
- });
2784
- return;
2785
- }
2786
- ws.send(chunk, callback);
2787
- };
2788
- duplex.on("end", duplexOnEnd);
2789
- duplex.on("error", duplexOnError);
2790
- return duplex;
2791
- }
2792
- module.exports = createWebSocketStream;
2793
- });
2794
-
2795
- // node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/subprotocol.js
2796
- var require_subprotocol2 = __commonJS((exports, module) => {
2797
- var { tokenChars } = require_validation2();
2798
- function parse5(header) {
2799
- const protocols = new Set;
2800
- let start = -1;
2801
- let end = -1;
2802
- let i = 0;
2803
- for (i;i < header.length; i++) {
2804
- const code = header.charCodeAt(i);
2805
- if (end === -1 && tokenChars[code] === 1) {
2806
- if (start === -1)
2807
- start = i;
2808
- } else if (i !== 0 && (code === 32 || code === 9)) {
2809
- if (end === -1 && start !== -1)
2810
- end = i;
2811
- } else if (code === 44) {
2812
- if (start === -1) {
2813
- throw new SyntaxError(`Unexpected character at index ${i}`);
2814
- }
2815
- if (end === -1)
2816
- end = i;
2817
- const protocol2 = header.slice(start, end);
2818
- if (protocols.has(protocol2)) {
2819
- throw new SyntaxError(`The "${protocol2}" subprotocol is duplicated`);
2820
- }
2821
- protocols.add(protocol2);
2822
- start = end = -1;
2823
- } else {
2824
- throw new SyntaxError(`Unexpected character at index ${i}`);
2825
- }
2826
- }
2827
- if (start === -1 || end !== -1) {
2828
- throw new SyntaxError("Unexpected end of input");
2829
- }
2830
- const protocol = header.slice(start, i);
2831
- if (protocols.has(protocol)) {
2832
- throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
2833
- }
2834
- protocols.add(protocol);
2835
- return protocols;
2836
- }
2837
- module.exports = { parse: parse5 };
2838
- });
2839
-
2840
- // node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/websocket-server.js
2841
- var require_websocket_server2 = __commonJS((exports, module) => {
2842
- var EventEmitter3 = __require("events");
2843
- var http = __require("http");
2844
- var { Duplex } = __require("stream");
2845
- var { createHash } = __require("crypto");
2846
- var extension = require_extension2();
2847
- var PerMessageDeflate = require_permessage_deflate2();
2848
- var subprotocol = require_subprotocol2();
2849
- var WebSocket = require_websocket2();
2850
- var { CLOSE_TIMEOUT, GUID, kWebSocket } = require_constants2();
2851
- var keyRegex = /^[+/0-9A-Za-z]{22}==$/;
2852
- var RUNNING = 0;
2853
- var CLOSING = 1;
2854
- var CLOSED = 2;
2855
-
2856
- class WebSocketServer extends EventEmitter3 {
2857
- constructor(options, callback) {
2858
- super();
2859
- options = {
2860
- allowSynchronousEvents: true,
2861
- autoPong: true,
2862
- maxPayload: 100 * 1024 * 1024,
2863
- skipUTF8Validation: false,
2864
- perMessageDeflate: false,
2865
- handleProtocols: null,
2866
- clientTracking: true,
2867
- closeTimeout: CLOSE_TIMEOUT,
2868
- verifyClient: null,
2869
- noServer: false,
2870
- backlog: null,
2871
- server: null,
2872
- host: null,
2873
- path: null,
2874
- port: null,
2875
- WebSocket,
2876
- ...options
2877
- };
2878
- if (options.port == null && !options.server && !options.noServer || options.port != null && (options.server || options.noServer) || options.server && options.noServer) {
2879
- throw new TypeError('One and only one of the "port", "server", or "noServer" options ' + "must be specified");
2880
- }
2881
- if (options.port != null) {
2882
- this._server = http.createServer((req, res) => {
2883
- const body = http.STATUS_CODES[426];
2884
- res.writeHead(426, {
2885
- "Content-Length": body.length,
2886
- "Content-Type": "text/plain"
2887
- });
2888
- res.end(body);
2889
- });
2890
- this._server.listen(options.port, options.host, options.backlog, callback);
2891
- } else if (options.server) {
2892
- this._server = options.server;
2893
- }
2894
- if (this._server) {
2895
- const emitConnection = this.emit.bind(this, "connection");
2896
- this._removeListeners = addListeners(this._server, {
2897
- listening: this.emit.bind(this, "listening"),
2898
- error: this.emit.bind(this, "error"),
2899
- upgrade: (req, socket, head) => {
2900
- this.handleUpgrade(req, socket, head, emitConnection);
2901
- }
2902
- });
2903
- }
2904
- if (options.perMessageDeflate === true)
2905
- options.perMessageDeflate = {};
2906
- if (options.clientTracking) {
2907
- this.clients = new Set;
2908
- this._shouldEmitClose = false;
2909
- }
2910
- this.options = options;
2911
- this._state = RUNNING;
2912
- }
2913
- address() {
2914
- if (this.options.noServer) {
2915
- throw new Error('The server is operating in "noServer" mode');
2916
- }
2917
- if (!this._server)
2918
- return null;
2919
- return this._server.address();
2920
- }
2921
- close(cb) {
2922
- if (this._state === CLOSED) {
2923
- if (cb) {
2924
- this.once("close", () => {
2925
- cb(new Error("The server is not running"));
2926
- });
2927
- }
2928
- process.nextTick(emitClose, this);
2929
- return;
2930
- }
2931
- if (cb)
2932
- this.once("close", cb);
2933
- if (this._state === CLOSING)
2934
- return;
2935
- this._state = CLOSING;
2936
- if (this.options.noServer || this.options.server) {
2937
- if (this._server) {
2938
- this._removeListeners();
2939
- this._removeListeners = this._server = null;
2940
- }
2941
- if (this.clients) {
2942
- if (!this.clients.size) {
2943
- process.nextTick(emitClose, this);
2944
- } else {
2945
- this._shouldEmitClose = true;
2946
- }
2947
- } else {
2948
- process.nextTick(emitClose, this);
2949
- }
2950
- } else {
2951
- const server = this._server;
2952
- this._removeListeners();
2953
- this._removeListeners = this._server = null;
2954
- server.close(() => {
2955
- emitClose(this);
2956
- });
2957
- }
2958
- }
2959
- shouldHandle(req) {
2960
- if (this.options.path) {
2961
- const index = req.url.indexOf("?");
2962
- const pathname = index !== -1 ? req.url.slice(0, index) : req.url;
2963
- if (pathname !== this.options.path)
2964
- return false;
2965
- }
2966
- return true;
2967
- }
2968
- handleUpgrade(req, socket, head, cb) {
2969
- socket.on("error", socketOnError);
2970
- const key = req.headers["sec-websocket-key"];
2971
- const upgrade = req.headers.upgrade;
2972
- const version3 = +req.headers["sec-websocket-version"];
2973
- if (req.method !== "GET") {
2974
- const message = "Invalid HTTP method";
2975
- abortHandshakeOrEmitwsClientError(this, req, socket, 405, message);
2976
- return;
2977
- }
2978
- if (upgrade === undefined || upgrade.toLowerCase() !== "websocket") {
2979
- const message = "Invalid Upgrade header";
2980
- abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
2981
- return;
2982
- }
2983
- if (key === undefined || !keyRegex.test(key)) {
2984
- const message = "Missing or invalid Sec-WebSocket-Key header";
2985
- abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
2986
- return;
2987
- }
2988
- if (version3 !== 13 && version3 !== 8) {
2989
- const message = "Missing or invalid Sec-WebSocket-Version header";
2990
- abortHandshakeOrEmitwsClientError(this, req, socket, 400, message, {
2991
- "Sec-WebSocket-Version": "13, 8"
2992
- });
2993
- return;
2994
- }
2995
- if (!this.shouldHandle(req)) {
2996
- abortHandshake(socket, 400);
2997
- return;
2998
- }
2999
- const secWebSocketProtocol = req.headers["sec-websocket-protocol"];
3000
- let protocols = new Set;
3001
- if (secWebSocketProtocol !== undefined) {
3002
- try {
3003
- protocols = subprotocol.parse(secWebSocketProtocol);
3004
- } catch (err) {
3005
- const message = "Invalid Sec-WebSocket-Protocol header";
3006
- abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3007
- return;
3008
- }
3009
- }
3010
- const secWebSocketExtensions = req.headers["sec-websocket-extensions"];
3011
- const extensions = {};
3012
- if (this.options.perMessageDeflate && secWebSocketExtensions !== undefined) {
3013
- const perMessageDeflate = new PerMessageDeflate(this.options.perMessageDeflate, true, this.options.maxPayload);
3014
- try {
3015
- const offers = extension.parse(secWebSocketExtensions);
3016
- if (offers[PerMessageDeflate.extensionName]) {
3017
- perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]);
3018
- extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
3019
- }
3020
- } catch (err) {
3021
- const message = "Invalid or unacceptable Sec-WebSocket-Extensions header";
3022
- abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3023
- return;
3024
- }
3025
- }
3026
- if (this.options.verifyClient) {
3027
- const info = {
3028
- origin: req.headers[`${version3 === 8 ? "sec-websocket-origin" : "origin"}`],
3029
- secure: !!(req.socket.authorized || req.socket.encrypted),
3030
- req
3031
- };
3032
- if (this.options.verifyClient.length === 2) {
3033
- this.options.verifyClient(info, (verified, code, message, headers) => {
3034
- if (!verified) {
3035
- return abortHandshake(socket, code || 401, message, headers);
3036
- }
3037
- this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
3038
- });
3039
- return;
3040
- }
3041
- if (!this.options.verifyClient(info))
3042
- return abortHandshake(socket, 401);
3043
- }
3044
- this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
3045
- }
3046
- completeUpgrade(extensions, key, protocols, req, socket, head, cb) {
3047
- if (!socket.readable || !socket.writable)
3048
- return socket.destroy();
3049
- if (socket[kWebSocket]) {
3050
- throw new Error("server.handleUpgrade() was called more than once with the same " + "socket, possibly due to a misconfiguration");
3051
- }
3052
- if (this._state > RUNNING)
3053
- return abortHandshake(socket, 503);
3054
- const digest = createHash("sha1").update(key + GUID).digest("base64");
3055
- const headers = [
3056
- "HTTP/1.1 101 Switching Protocols",
3057
- "Upgrade: websocket",
3058
- "Connection: Upgrade",
3059
- `Sec-WebSocket-Accept: ${digest}`
3060
- ];
3061
- const ws = new this.options.WebSocket(null, undefined, this.options);
3062
- if (protocols.size) {
3063
- const protocol = this.options.handleProtocols ? this.options.handleProtocols(protocols, req) : protocols.values().next().value;
3064
- if (protocol) {
3065
- headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
3066
- ws._protocol = protocol;
3067
- }
3068
- }
3069
- if (extensions[PerMessageDeflate.extensionName]) {
3070
- const params = extensions[PerMessageDeflate.extensionName].params;
3071
- const value = extension.format({
3072
- [PerMessageDeflate.extensionName]: [params]
3073
- });
3074
- headers.push(`Sec-WebSocket-Extensions: ${value}`);
3075
- ws._extensions = extensions;
3076
- }
3077
- this.emit("headers", headers, req);
3078
- socket.write(headers.concat(`\r
3079
- `).join(`\r
3080
- `));
3081
- socket.removeListener("error", socketOnError);
3082
- ws.setSocket(socket, head, {
3083
- allowSynchronousEvents: this.options.allowSynchronousEvents,
3084
- maxPayload: this.options.maxPayload,
3085
- skipUTF8Validation: this.options.skipUTF8Validation
3086
- });
3087
- if (this.clients) {
3088
- this.clients.add(ws);
3089
- ws.on("close", () => {
3090
- this.clients.delete(ws);
3091
- if (this._shouldEmitClose && !this.clients.size) {
3092
- process.nextTick(emitClose, this);
3093
- }
3094
- });
3095
- }
3096
- cb(ws, req);
3097
- }
3098
- }
3099
- module.exports = WebSocketServer;
3100
- function addListeners(server, map3) {
3101
- for (const event of Object.keys(map3))
3102
- server.on(event, map3[event]);
3103
- return function removeListeners() {
3104
- for (const event of Object.keys(map3)) {
3105
- server.removeListener(event, map3[event]);
3106
- }
3107
- };
3108
- }
3109
- function emitClose(server) {
3110
- server._state = CLOSED;
3111
- server.emit("close");
3112
- }
3113
- function socketOnError() {
3114
- this.destroy();
3115
- }
3116
- function abortHandshake(socket, code, message, headers) {
3117
- message = message || http.STATUS_CODES[code];
3118
- headers = {
3119
- Connection: "close",
3120
- "Content-Type": "text/html",
3121
- "Content-Length": Buffer.byteLength(message),
3122
- ...headers
3123
- };
3124
- socket.once("finish", socket.destroy);
3125
- socket.end(`HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r
3126
- ` + Object.keys(headers).map((h) => `${h}: ${headers[h]}`).join(`\r
3127
- `) + `\r
3128
- \r
3129
- ` + message);
3130
- }
3131
- function abortHandshakeOrEmitwsClientError(server, req, socket, code, message, headers) {
3132
- if (server.listenerCount("wsClientError")) {
3133
- const err = new Error(message);
3134
- Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError);
3135
- server.emit("wsClientError", err, socket, req);
3136
- } else {
3137
- abortHandshake(socket, code, message, headers);
3138
- }
3139
- }
3140
- });
3141
-
3142
- // node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/wrapper.mjs
3143
- var exports_wrapper = {};
3144
- __export(exports_wrapper, {
3145
- default: () => wrapper_default,
3146
- createWebSocketStream: () => import_stream2.default,
3147
- WebSocketServer: () => import_websocket_server2.default,
3148
- WebSocket: () => import_websocket2.default,
3149
- Sender: () => import_sender2.default,
3150
- Receiver: () => import_receiver2.default
3151
- });
3152
- var import_stream2, import_receiver2, import_sender2, import_websocket2, import_websocket_server2, wrapper_default;
3153
- var init_wrapper = __esm(() => {
3154
- import_stream2 = __toESM(require_stream2(), 1);
3155
- import_receiver2 = __toESM(require_receiver2(), 1);
3156
- import_sender2 = __toESM(require_sender2(), 1);
3157
- import_websocket2 = __toESM(require_websocket2(), 1);
3158
- import_websocket_server2 = __toESM(require_websocket_server2(), 1);
3159
- wrapper_default = import_websocket2.default;
3160
- });
3161
-
3162
- // node_modules/.pnpm/@kevisual+router@0.0.84/node_modules/@kevisual/router/dist/router.js
3163
- import { createRequire as createRequire2 } from "node:module";
3164
- import { webcrypto as crypto2 } from "node:crypto";
3165
- import url2 from "node:url";
3166
- var __create2 = Object.create;
3167
- var __getProtoOf2 = Object.getPrototypeOf;
3168
- var __defProp2 = Object.defineProperty;
3169
- var __getOwnPropNames2 = Object.getOwnPropertyNames;
3170
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
3171
- var __toESM2 = (mod, isNodeMode, target) => {
3172
- target = mod != null ? __create2(__getProtoOf2(mod)) : {};
3173
- const to = isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target;
3174
- for (let key of __getOwnPropNames2(mod))
3175
- if (!__hasOwnProp2.call(to, key))
3176
- __defProp2(to, key, {
3177
- get: () => mod[key],
3178
- enumerable: true
3179
- });
3180
- return to;
3181
- };
3182
- var __commonJS2 = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
3183
- var __export2 = (target, all) => {
3184
- for (var name in all)
3185
- __defProp2(target, name, {
3186
- get: all[name],
3187
- enumerable: true,
3188
- configurable: true,
3189
- set: (newValue) => all[name] = () => newValue
3190
- });
3191
- };
3192
- var __require2 = /* @__PURE__ */ createRequire2(import.meta.url);
3193
- var require_eventemitter3 = __commonJS2((exports, module) => {
3194
- var has = Object.prototype.hasOwnProperty;
3195
- var prefix = "~";
3196
- function Events() {}
3197
- if (Object.create) {
3198
- Events.prototype = Object.create(null);
3199
- if (!new Events().__proto__)
3200
- prefix = false;
3201
- }
3202
- function EE(fn, context, once) {
3203
- this.fn = fn;
3204
- this.context = context;
3205
- this.once = once || false;
3206
- }
3207
- function addListener(emitter, event, fn, context, once) {
3208
- if (typeof fn !== "function") {
3209
- throw new TypeError("The listener must be a function");
3210
- }
3211
- var listener = new EE(fn, context || emitter, once), evt = prefix ? prefix + event : event;
3212
- if (!emitter._events[evt])
3213
- emitter._events[evt] = listener, emitter._eventsCount++;
3214
- else if (!emitter._events[evt].fn)
3215
- emitter._events[evt].push(listener);
3216
- else
3217
- emitter._events[evt] = [emitter._events[evt], listener];
3218
- return emitter;
3219
- }
3220
- function clearEvent(emitter, evt) {
3221
- if (--emitter._eventsCount === 0)
3222
- emitter._events = new Events;
3223
- else
3224
- delete emitter._events[evt];
3225
- }
3226
- function EventEmitter() {
3227
- this._events = new Events;
3228
- this._eventsCount = 0;
3229
- }
3230
- EventEmitter.prototype.eventNames = function eventNames() {
3231
- var names = [], events, name;
3232
- if (this._eventsCount === 0)
3233
- return names;
3234
- for (name in events = this._events) {
3235
- if (has.call(events, name))
3236
- names.push(prefix ? name.slice(1) : name);
3237
- }
3238
- if (Object.getOwnPropertySymbols) {
3239
- return names.concat(Object.getOwnPropertySymbols(events));
3240
- }
3241
- return names;
3242
- };
3243
- EventEmitter.prototype.listeners = function listeners(event) {
3244
- var evt = prefix ? prefix + event : event, handlers = this._events[evt];
3245
- if (!handlers)
3246
- return [];
3247
- if (handlers.fn)
3248
- return [handlers.fn];
3249
- for (var i = 0, l = handlers.length, ee = new Array(l);i < l; i++) {
3250
- ee[i] = handlers[i].fn;
3251
- }
3252
- return ee;
3253
- };
3254
- EventEmitter.prototype.listenerCount = function listenerCount(event) {
3255
- var evt = prefix ? prefix + event : event, listeners = this._events[evt];
3256
- if (!listeners)
3257
- return 0;
3258
- if (listeners.fn)
3259
- return 1;
3260
- return listeners.length;
3261
- };
3262
- EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
3263
- var evt = prefix ? prefix + event : event;
3264
- if (!this._events[evt])
3265
- return false;
3266
- var listeners = this._events[evt], len = arguments.length, args, i;
3267
- if (listeners.fn) {
3268
- if (listeners.once)
3269
- this.removeListener(event, listeners.fn, undefined, true);
3270
- switch (len) {
3271
- case 1:
3272
- return listeners.fn.call(listeners.context), true;
3273
- case 2:
3274
- return listeners.fn.call(listeners.context, a1), true;
3275
- case 3:
3276
- return listeners.fn.call(listeners.context, a1, a2), true;
3277
- case 4:
3278
- return listeners.fn.call(listeners.context, a1, a2, a3), true;
3279
- case 5:
3280
- return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
3281
- case 6:
3282
- return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
3283
- }
3284
- for (i = 1, args = new Array(len - 1);i < len; i++) {
3285
- args[i - 1] = arguments[i];
3286
- }
3287
- listeners.fn.apply(listeners.context, args);
3288
- } else {
3289
- var length = listeners.length, j;
3290
- for (i = 0;i < length; i++) {
3291
- if (listeners[i].once)
3292
- this.removeListener(event, listeners[i].fn, undefined, true);
3293
- switch (len) {
3294
- case 1:
3295
- listeners[i].fn.call(listeners[i].context);
3296
- break;
3297
- case 2:
3298
- listeners[i].fn.call(listeners[i].context, a1);
3299
- break;
3300
- case 3:
3301
- listeners[i].fn.call(listeners[i].context, a1, a2);
3302
- break;
3303
- case 4:
3304
- listeners[i].fn.call(listeners[i].context, a1, a2, a3);
3305
- break;
3306
- default:
3307
- if (!args)
3308
- for (j = 1, args = new Array(len - 1);j < len; j++) {
3309
- args[j - 1] = arguments[j];
3310
- }
3311
- listeners[i].fn.apply(listeners[i].context, args);
3312
- }
3313
- }
3314
- }
3315
- return true;
3316
- };
3317
- EventEmitter.prototype.on = function on(event, fn, context) {
3318
- return addListener(this, event, fn, context, false);
3319
- };
3320
- EventEmitter.prototype.once = function once(event, fn, context) {
3321
- return addListener(this, event, fn, context, true);
3322
- };
3323
- EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
3324
- var evt = prefix ? prefix + event : event;
3325
- if (!this._events[evt])
3326
- return this;
3327
- if (!fn) {
3328
- clearEvent(this, evt);
3329
- return this;
3330
- }
3331
- var listeners = this._events[evt];
3332
- if (listeners.fn) {
3333
- if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) {
3334
- clearEvent(this, evt);
3335
- }
3336
- } else {
3337
- for (var i = 0, events = [], length = listeners.length;i < length; i++) {
3338
- if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) {
3339
- events.push(listeners[i]);
3340
- }
3341
- }
3342
- if (events.length)
3343
- this._events[evt] = events.length === 1 ? events[0] : events;
3344
- else
3345
- clearEvent(this, evt);
3346
- }
3347
- return this;
3348
- };
3349
- EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
3350
- var evt;
3351
- if (event) {
3352
- evt = prefix ? prefix + event : event;
3353
- if (this._events[evt])
3354
- clearEvent(this, evt);
3355
- } else {
3356
- this._events = new Events;
3357
- this._eventsCount = 0;
3358
- }
3359
- return this;
3360
- };
3361
- EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
3362
- EventEmitter.prototype.addListener = EventEmitter.prototype.on;
3363
- EventEmitter.prefixed = prefix;
3364
- EventEmitter.EventEmitter = EventEmitter;
3365
- if (typeof module !== "undefined") {
3366
- module.exports = EventEmitter;
3367
- }
3368
- });
3369
- var require_constants = __commonJS2((exports, module) => {
3370
- var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
3371
- var hasBlob = typeof Blob !== "undefined";
3372
- if (hasBlob)
3373
- BINARY_TYPES.push("blob");
3374
- module.exports = {
3375
- BINARY_TYPES,
3376
- EMPTY_BUFFER: Buffer.alloc(0),
3377
- GUID: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
3378
- hasBlob,
3379
- kForOnEventAttribute: Symbol("kIsForOnEventAttribute"),
3380
- kListener: Symbol("kListener"),
3381
- kStatusCode: Symbol("status-code"),
3382
- kWebSocket: Symbol("websocket"),
3383
- NOOP: () => {}
3384
- };
3385
- });
3386
- var require_buffer_util = __commonJS2((exports, module) => {
3387
- var { EMPTY_BUFFER } = require_constants();
3388
- var FastBuffer = Buffer[Symbol.species];
3389
- function concat(list, totalLength) {
3390
- if (list.length === 0)
3391
- return EMPTY_BUFFER;
3392
- if (list.length === 1)
3393
- return list[0];
3394
- const target = Buffer.allocUnsafe(totalLength);
3395
- let offset = 0;
3396
- for (let i = 0;i < list.length; i++) {
3397
- const buf = list[i];
3398
- target.set(buf, offset);
3399
- offset += buf.length;
3400
- }
3401
- if (offset < totalLength) {
3402
- return new FastBuffer(target.buffer, target.byteOffset, offset);
3403
- }
3404
- return target;
3405
- }
3406
- function _mask(source, mask, output, offset, length) {
3407
- for (let i = 0;i < length; i++) {
3408
- output[offset + i] = source[i] ^ mask[i & 3];
3409
- }
3410
- }
3411
- function _unmask(buffer, mask) {
3412
- for (let i = 0;i < buffer.length; i++) {
3413
- buffer[i] ^= mask[i & 3];
3414
- }
3415
- }
3416
- function toArrayBuffer(buf) {
3417
- if (buf.length === buf.buffer.byteLength) {
3418
- return buf.buffer;
3419
- }
3420
- return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
3421
- }
3422
- function toBuffer(data) {
3423
- toBuffer.readOnly = true;
3424
- if (Buffer.isBuffer(data))
3425
- return data;
3426
- let buf;
3427
- if (data instanceof ArrayBuffer) {
3428
- buf = new FastBuffer(data);
3429
- } else if (ArrayBuffer.isView(data)) {
3430
- buf = new FastBuffer(data.buffer, data.byteOffset, data.byteLength);
3431
- } else {
3432
- buf = Buffer.from(data);
3433
- toBuffer.readOnly = false;
3434
- }
3435
- return buf;
3436
- }
3437
- module.exports = {
3438
- concat,
3439
- mask: _mask,
3440
- toArrayBuffer,
3441
- toBuffer,
3442
- unmask: _unmask
3443
- };
3444
- });
3445
- var require_limiter = __commonJS2((exports, module) => {
3446
- var kDone = Symbol("kDone");
3447
- var kRun = Symbol("kRun");
3448
-
3449
- class Limiter {
3450
- constructor(concurrency) {
3451
- this[kDone] = () => {
3452
- this.pending--;
3453
- this[kRun]();
3454
- };
3455
- this.concurrency = concurrency || Infinity;
3456
- this.jobs = [];
3457
- this.pending = 0;
3458
- }
3459
- add(job) {
3460
- this.jobs.push(job);
3461
- this[kRun]();
3462
- }
3463
- [kRun]() {
3464
- if (this.pending === this.concurrency)
3465
- return;
3466
- if (this.jobs.length) {
3467
- const job = this.jobs.shift();
3468
- this.pending++;
3469
- job(this[kDone]);
3470
- }
3471
- }
3472
- }
3473
- module.exports = Limiter;
3474
- });
3475
- var require_permessage_deflate = __commonJS2((exports, module) => {
3476
- var zlib = __require2("zlib");
3477
- var bufferUtil = require_buffer_util();
3478
- var Limiter = require_limiter();
3479
- var { kStatusCode } = require_constants();
3480
- var FastBuffer = Buffer[Symbol.species];
3481
- var TRAILER = Buffer.from([0, 0, 255, 255]);
3482
- var kPerMessageDeflate = Symbol("permessage-deflate");
3483
- var kTotalLength = Symbol("total-length");
3484
- var kCallback = Symbol("callback");
3485
- var kBuffers = Symbol("buffers");
3486
- var kError = Symbol("error");
3487
- var zlibLimiter;
3488
-
3489
- class PerMessageDeflate {
3490
- constructor(options, isServer, maxPayload) {
3491
- this._maxPayload = maxPayload | 0;
3492
- this._options = options || {};
3493
- this._threshold = this._options.threshold !== undefined ? this._options.threshold : 1024;
3494
- this._isServer = !!isServer;
3495
- this._deflate = null;
3496
- this._inflate = null;
3497
- this.params = null;
3498
- if (!zlibLimiter) {
3499
- const concurrency = this._options.concurrencyLimit !== undefined ? this._options.concurrencyLimit : 10;
3500
- zlibLimiter = new Limiter(concurrency);
3501
- }
3502
- }
3503
- static get extensionName() {
3504
- return "permessage-deflate";
3505
- }
3506
- offer() {
3507
- const params = {};
3508
- if (this._options.serverNoContextTakeover) {
3509
- params.server_no_context_takeover = true;
3510
- }
3511
- if (this._options.clientNoContextTakeover) {
3512
- params.client_no_context_takeover = true;
3513
- }
3514
- if (this._options.serverMaxWindowBits) {
3515
- params.server_max_window_bits = this._options.serverMaxWindowBits;
3516
- }
3517
- if (this._options.clientMaxWindowBits) {
3518
- params.client_max_window_bits = this._options.clientMaxWindowBits;
3519
- } else if (this._options.clientMaxWindowBits == null) {
3520
- params.client_max_window_bits = true;
3521
- }
3522
- return params;
3523
- }
3524
- accept(configurations) {
3525
- configurations = this.normalizeParams(configurations);
3526
- this.params = this._isServer ? this.acceptAsServer(configurations) : this.acceptAsClient(configurations);
3527
- return this.params;
3528
- }
3529
- cleanup() {
3530
- if (this._inflate) {
3531
- this._inflate.close();
3532
- this._inflate = null;
3533
- }
3534
- if (this._deflate) {
3535
- const callback = this._deflate[kCallback];
3536
- this._deflate.close();
3537
- this._deflate = null;
3538
- if (callback) {
3539
- callback(new Error("The deflate stream was closed while data was being processed"));
3540
- }
3541
- }
3542
- }
3543
- acceptAsServer(offers) {
3544
- const opts = this._options;
3545
- const accepted = offers.find((params) => {
3546
- 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) {
3547
- return false;
3548
- }
3549
- return true;
3550
- });
3551
- if (!accepted) {
3552
- throw new Error("None of the extension offers can be accepted");
3553
- }
3554
- if (opts.serverNoContextTakeover) {
3555
- accepted.server_no_context_takeover = true;
3556
- }
3557
- if (opts.clientNoContextTakeover) {
3558
- accepted.client_no_context_takeover = true;
3559
- }
3560
- if (typeof opts.serverMaxWindowBits === "number") {
3561
- accepted.server_max_window_bits = opts.serverMaxWindowBits;
3562
- }
3563
- if (typeof opts.clientMaxWindowBits === "number") {
3564
- accepted.client_max_window_bits = opts.clientMaxWindowBits;
3565
- } else if (accepted.client_max_window_bits === true || opts.clientMaxWindowBits === false) {
3566
- delete accepted.client_max_window_bits;
3567
- }
3568
- return accepted;
3569
- }
3570
- acceptAsClient(response) {
3571
- const params = response[0];
3572
- if (this._options.clientNoContextTakeover === false && params.client_no_context_takeover) {
3573
- throw new Error('Unexpected parameter "client_no_context_takeover"');
3574
- }
3575
- if (!params.client_max_window_bits) {
3576
- if (typeof this._options.clientMaxWindowBits === "number") {
3577
- params.client_max_window_bits = this._options.clientMaxWindowBits;
3578
- }
3579
- } else if (this._options.clientMaxWindowBits === false || typeof this._options.clientMaxWindowBits === "number" && params.client_max_window_bits > this._options.clientMaxWindowBits) {
3580
- throw new Error('Unexpected or invalid parameter "client_max_window_bits"');
3581
- }
3582
- return params;
3583
- }
3584
- normalizeParams(configurations) {
3585
- configurations.forEach((params) => {
3586
- Object.keys(params).forEach((key) => {
3587
- let value = params[key];
3588
- if (value.length > 1) {
3589
- throw new Error(`Parameter "${key}" must have only a single value`);
3590
- }
3591
- value = value[0];
3592
- if (key === "client_max_window_bits") {
3593
- if (value !== true) {
3594
- const num = +value;
3595
- if (!Number.isInteger(num) || num < 8 || num > 15) {
3596
- throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
3597
- }
3598
- value = num;
3599
- } else if (!this._isServer) {
3600
- throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
3601
- }
3602
- } else if (key === "server_max_window_bits") {
3603
- const num = +value;
3604
- if (!Number.isInteger(num) || num < 8 || num > 15) {
3605
- throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
3606
- }
3607
- value = num;
3608
- } else if (key === "client_no_context_takeover" || key === "server_no_context_takeover") {
3609
- if (value !== true) {
3610
- throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
3611
- }
3612
- } else {
3613
- throw new Error(`Unknown parameter "${key}"`);
3614
- }
3615
- params[key] = value;
3616
- });
3617
- });
3618
- return configurations;
3619
- }
3620
- decompress(data, fin, callback) {
3621
- zlibLimiter.add((done) => {
3622
- this._decompress(data, fin, (err, result) => {
3623
- done();
3624
- callback(err, result);
3625
- });
3626
- });
3627
- }
3628
- compress(data, fin, callback) {
3629
- zlibLimiter.add((done) => {
3630
- this._compress(data, fin, (err, result) => {
3631
- done();
3632
- callback(err, result);
3633
- });
3634
- });
3635
- }
3636
- _decompress(data, fin, callback) {
3637
- const endpoint = this._isServer ? "client" : "server";
3638
- if (!this._inflate) {
3639
- const key = `${endpoint}_max_window_bits`;
3640
- const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
3641
- this._inflate = zlib.createInflateRaw({
3642
- ...this._options.zlibInflateOptions,
3643
- windowBits
3644
- });
3645
- this._inflate[kPerMessageDeflate] = this;
3646
- this._inflate[kTotalLength] = 0;
3647
- this._inflate[kBuffers] = [];
3648
- this._inflate.on("error", inflateOnError);
3649
- this._inflate.on("data", inflateOnData);
3650
- }
3651
- this._inflate[kCallback] = callback;
3652
- this._inflate.write(data);
3653
- if (fin)
3654
- this._inflate.write(TRAILER);
3655
- this._inflate.flush(() => {
3656
- const err = this._inflate[kError];
3657
- if (err) {
3658
- this._inflate.close();
3659
- this._inflate = null;
3660
- callback(err);
3661
- return;
3662
- }
3663
- const data2 = bufferUtil.concat(this._inflate[kBuffers], this._inflate[kTotalLength]);
3664
- if (this._inflate._readableState.endEmitted) {
3665
- this._inflate.close();
3666
- this._inflate = null;
3667
- } else {
3668
- this._inflate[kTotalLength] = 0;
3669
- this._inflate[kBuffers] = [];
3670
- if (fin && this.params[`${endpoint}_no_context_takeover`]) {
3671
- this._inflate.reset();
3672
- }
3673
- }
3674
- callback(null, data2);
3675
- });
3676
- }
3677
- _compress(data, fin, callback) {
3678
- const endpoint = this._isServer ? "server" : "client";
3679
- if (!this._deflate) {
3680
- const key = `${endpoint}_max_window_bits`;
3681
- const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
3682
- this._deflate = zlib.createDeflateRaw({
3683
- ...this._options.zlibDeflateOptions,
3684
- windowBits
3685
- });
3686
- this._deflate[kTotalLength] = 0;
3687
- this._deflate[kBuffers] = [];
3688
- this._deflate.on("data", deflateOnData);
3689
- }
3690
- this._deflate[kCallback] = callback;
3691
- this._deflate.write(data);
3692
- this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
3693
- if (!this._deflate) {
3694
- return;
3695
- }
3696
- let data2 = bufferUtil.concat(this._deflate[kBuffers], this._deflate[kTotalLength]);
3697
- if (fin) {
3698
- data2 = new FastBuffer(data2.buffer, data2.byteOffset, data2.length - 4);
3699
- }
3700
- this._deflate[kCallback] = null;
3701
- this._deflate[kTotalLength] = 0;
3702
- this._deflate[kBuffers] = [];
3703
- if (fin && this.params[`${endpoint}_no_context_takeover`]) {
3704
- this._deflate.reset();
3705
- }
3706
- callback(null, data2);
3707
- });
3708
- }
3709
- }
3710
- module.exports = PerMessageDeflate;
3711
- function deflateOnData(chunk) {
3712
- this[kBuffers].push(chunk);
3713
- this[kTotalLength] += chunk.length;
3714
- }
3715
- function inflateOnData(chunk) {
3716
- this[kTotalLength] += chunk.length;
3717
- if (this[kPerMessageDeflate]._maxPayload < 1 || this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload) {
3718
- this[kBuffers].push(chunk);
3719
- return;
3720
- }
3721
- this[kError] = new RangeError("Max payload size exceeded");
3722
- this[kError].code = "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH";
3723
- this[kError][kStatusCode] = 1009;
3724
- this.removeListener("data", inflateOnData);
3725
- this.reset();
3726
- }
3727
- function inflateOnError(err) {
3728
- this[kPerMessageDeflate]._inflate = null;
3729
- err[kStatusCode] = 1007;
3730
- this[kCallback](err);
3731
- }
3732
- });
3733
- var require_validation = __commonJS2((exports, module) => {
3734
- var { isUtf8 } = __require2("buffer");
3735
- var { hasBlob } = require_constants();
3736
- var tokenChars = [
3737
- 0,
3738
- 0,
3739
- 0,
3740
- 0,
3741
- 0,
3742
- 0,
3743
- 0,
3744
- 0,
3745
- 0,
3746
- 0,
3747
- 0,
3748
- 0,
3749
- 0,
3750
- 0,
3751
- 0,
3752
- 0,
3753
- 0,
3754
- 0,
3755
- 0,
3756
- 0,
3757
- 0,
3758
- 0,
3759
- 0,
3760
- 0,
3761
- 0,
3762
- 0,
3763
- 0,
3764
- 0,
3765
- 0,
3766
- 0,
3767
- 0,
3768
- 0,
3769
- 0,
3770
- 1,
3771
- 0,
3772
- 1,
3773
- 1,
3774
- 1,
3775
- 1,
3776
- 1,
3777
- 0,
3778
- 0,
3779
- 1,
3780
- 1,
3781
- 0,
3782
- 1,
3783
- 1,
3784
- 0,
3785
- 1,
3786
- 1,
3787
- 1,
3788
- 1,
3789
- 1,
3790
- 1,
3791
- 1,
3792
- 1,
3793
- 1,
3794
- 1,
3795
- 0,
3796
- 0,
3797
- 0,
3798
- 0,
3799
- 0,
3800
- 0,
3801
- 0,
3802
- 1,
3803
- 1,
3804
- 1,
3805
- 1,
3806
- 1,
3807
- 1,
3808
- 1,
3809
- 1,
3810
- 1,
3811
- 1,
3812
- 1,
3813
- 1,
3814
- 1,
3815
- 1,
3816
- 1,
3817
- 1,
3818
- 1,
3819
- 1,
3820
- 1,
3821
- 1,
3822
- 1,
3823
- 1,
3824
- 1,
3825
- 1,
3826
- 1,
3827
- 1,
3828
- 0,
3829
- 0,
3830
- 0,
3831
- 1,
3832
- 1,
3833
- 1,
3834
- 1,
3835
- 1,
3836
- 1,
3837
- 1,
3838
- 1,
3839
- 1,
3840
- 1,
3841
- 1,
3842
- 1,
3843
- 1,
3844
- 1,
3845
- 1,
3846
- 1,
3847
- 1,
3848
- 1,
3849
- 1,
3850
- 1,
3851
- 1,
3852
- 1,
3853
- 1,
3854
- 1,
3855
- 1,
3856
- 1,
3857
- 1,
3858
- 1,
3859
- 1,
3860
- 0,
3861
- 1,
3862
- 0,
3863
- 1,
3864
- 0
3865
- ];
3866
- function isValidStatusCode(code) {
3867
- return code >= 1000 && code <= 1014 && code !== 1004 && code !== 1005 && code !== 1006 || code >= 3000 && code <= 4999;
3868
- }
3869
- function _isValidUTF8(buf) {
3870
- const len = buf.length;
3871
- let i = 0;
3872
- while (i < len) {
3873
- if ((buf[i] & 128) === 0) {
3874
- i++;
3875
- } else if ((buf[i] & 224) === 192) {
3876
- if (i + 1 === len || (buf[i + 1] & 192) !== 128 || (buf[i] & 254) === 192) {
3877
- return false;
3878
- }
3879
- i += 2;
3880
- } else if ((buf[i] & 240) === 224) {
3881
- 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) {
3882
- return false;
3883
- }
3884
- i += 3;
3885
- } else if ((buf[i] & 248) === 240) {
3886
- 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) {
3887
- return false;
3888
- }
3889
- i += 4;
3890
- } else {
3891
- return false;
3892
- }
3893
- }
3894
- return true;
3895
- }
3896
- function isBlob(value) {
3897
- 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");
3898
- }
3899
- module.exports = {
3900
- isBlob,
3901
- isValidStatusCode,
3902
- isValidUTF8: _isValidUTF8,
3903
- tokenChars
3904
- };
3905
- if (isUtf8) {
3906
- module.exports.isValidUTF8 = function(buf) {
3907
- return buf.length < 24 ? _isValidUTF8(buf) : isUtf8(buf);
3908
- };
3909
- }
3910
- });
3911
- var require_receiver = __commonJS2((exports, module) => {
3912
- var { Writable } = __require2("stream");
3913
- var PerMessageDeflate = require_permessage_deflate();
3914
- var {
3915
- BINARY_TYPES,
3916
- EMPTY_BUFFER,
3917
- kStatusCode,
3918
- kWebSocket
3919
- } = require_constants();
3920
- var { concat, toArrayBuffer, unmask } = require_buffer_util();
3921
- var { isValidStatusCode, isValidUTF8 } = require_validation();
3922
- var FastBuffer = Buffer[Symbol.species];
3923
- var GET_INFO = 0;
3924
- var GET_PAYLOAD_LENGTH_16 = 1;
3925
- var GET_PAYLOAD_LENGTH_64 = 2;
3926
- var GET_MASK = 3;
3927
- var GET_DATA = 4;
3928
- var INFLATING = 5;
3929
- var DEFER_EVENT = 6;
3930
-
3931
- class Receiver extends Writable {
3932
- constructor(options = {}) {
3933
- super();
3934
- this._allowSynchronousEvents = options.allowSynchronousEvents !== undefined ? options.allowSynchronousEvents : true;
3935
- this._binaryType = options.binaryType || BINARY_TYPES[0];
3936
- this._extensions = options.extensions || {};
3937
- this._isServer = !!options.isServer;
3938
- this._maxPayload = options.maxPayload | 0;
3939
- this._skipUTF8Validation = !!options.skipUTF8Validation;
3940
- this[kWebSocket] = undefined;
3941
- this._bufferedBytes = 0;
3942
- this._buffers = [];
3943
- this._compressed = false;
3944
- this._payloadLength = 0;
3945
- this._mask = undefined;
3946
- this._fragmented = 0;
3947
- this._masked = false;
3948
- this._fin = false;
3949
- this._opcode = 0;
3950
- this._totalPayloadLength = 0;
3951
- this._messageLength = 0;
3952
- this._fragments = [];
3953
- this._errored = false;
3954
- this._loop = false;
3955
- this._state = GET_INFO;
3956
- }
3957
- _write(chunk, encoding, cb) {
3958
- if (this._opcode === 8 && this._state == GET_INFO)
3959
- return cb();
3960
- this._bufferedBytes += chunk.length;
3961
- this._buffers.push(chunk);
3962
- this.startLoop(cb);
3963
- }
3964
- consume(n) {
3965
- this._bufferedBytes -= n;
3966
- if (n === this._buffers[0].length)
3967
- return this._buffers.shift();
3968
- if (n < this._buffers[0].length) {
3969
- const buf = this._buffers[0];
3970
- this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n);
3971
- return new FastBuffer(buf.buffer, buf.byteOffset, n);
3972
- }
3973
- const dst = Buffer.allocUnsafe(n);
3974
- do {
3975
- const buf = this._buffers[0];
3976
- const offset = dst.length - n;
3977
- if (n >= buf.length) {
3978
- dst.set(this._buffers.shift(), offset);
3979
- } else {
3980
- dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
3981
- this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n);
3982
- }
3983
- n -= buf.length;
3984
- } while (n > 0);
3985
- return dst;
3986
- }
3987
- startLoop(cb) {
3988
- this._loop = true;
3989
- do {
3990
- switch (this._state) {
3991
- case GET_INFO:
3992
- this.getInfo(cb);
3993
- break;
3994
- case GET_PAYLOAD_LENGTH_16:
3995
- this.getPayloadLength16(cb);
3996
- break;
3997
- case GET_PAYLOAD_LENGTH_64:
3998
- this.getPayloadLength64(cb);
3999
- break;
4000
- case GET_MASK:
4001
- this.getMask();
4002
- break;
4003
- case GET_DATA:
4004
- this.getData(cb);
4005
- break;
4006
- case INFLATING:
4007
- case DEFER_EVENT:
4008
- this._loop = false;
4009
- return;
4010
- }
4011
- } while (this._loop);
4012
- if (!this._errored)
4013
- cb();
4014
- }
4015
- getInfo(cb) {
4016
- if (this._bufferedBytes < 2) {
4017
- this._loop = false;
4018
- return;
4019
- }
4020
- const buf = this.consume(2);
4021
- if ((buf[0] & 48) !== 0) {
4022
- const error48 = this.createError(RangeError, "RSV2 and RSV3 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_2_3");
4023
- cb(error48);
4024
- return;
4025
- }
4026
- const compressed = (buf[0] & 64) === 64;
4027
- if (compressed && !this._extensions[PerMessageDeflate.extensionName]) {
4028
- const error48 = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
4029
- cb(error48);
4030
- return;
4031
- }
4032
- this._fin = (buf[0] & 128) === 128;
4033
- this._opcode = buf[0] & 15;
4034
- this._payloadLength = buf[1] & 127;
4035
- if (this._opcode === 0) {
4036
- if (compressed) {
4037
- const error48 = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
4038
- cb(error48);
4039
- return;
4040
- }
4041
- if (!this._fragmented) {
4042
- const error48 = this.createError(RangeError, "invalid opcode 0", true, 1002, "WS_ERR_INVALID_OPCODE");
4043
- cb(error48);
4044
- return;
4045
- }
4046
- this._opcode = this._fragmented;
4047
- } else if (this._opcode === 1 || this._opcode === 2) {
4048
- if (this._fragmented) {
4049
- const error48 = this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, "WS_ERR_INVALID_OPCODE");
4050
- cb(error48);
4051
- return;
4052
- }
4053
- this._compressed = compressed;
4054
- } else if (this._opcode > 7 && this._opcode < 11) {
4055
- if (!this._fin) {
4056
- const error48 = this.createError(RangeError, "FIN must be set", true, 1002, "WS_ERR_EXPECTED_FIN");
4057
- cb(error48);
4058
- return;
4059
- }
4060
- if (compressed) {
4061
- const error48 = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
4062
- cb(error48);
4063
- return;
4064
- }
4065
- if (this._payloadLength > 125 || this._opcode === 8 && this._payloadLength === 1) {
4066
- const error48 = this.createError(RangeError, `invalid payload length ${this._payloadLength}`, true, 1002, "WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");
4067
- cb(error48);
4068
- return;
4069
- }
4070
- } else {
4071
- const error48 = this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, "WS_ERR_INVALID_OPCODE");
4072
- cb(error48);
4073
- return;
4074
- }
4075
- if (!this._fin && !this._fragmented)
4076
- this._fragmented = this._opcode;
4077
- this._masked = (buf[1] & 128) === 128;
4078
- if (this._isServer) {
4079
- if (!this._masked) {
4080
- const error48 = this.createError(RangeError, "MASK must be set", true, 1002, "WS_ERR_EXPECTED_MASK");
4081
- cb(error48);
4082
- return;
4083
- }
4084
- } else if (this._masked) {
4085
- const error48 = this.createError(RangeError, "MASK must be clear", true, 1002, "WS_ERR_UNEXPECTED_MASK");
4086
- cb(error48);
4087
- return;
4088
- }
4089
- if (this._payloadLength === 126)
4090
- this._state = GET_PAYLOAD_LENGTH_16;
4091
- else if (this._payloadLength === 127)
4092
- this._state = GET_PAYLOAD_LENGTH_64;
4093
- else
4094
- this.haveLength(cb);
4095
- }
4096
- getPayloadLength16(cb) {
4097
- if (this._bufferedBytes < 2) {
4098
- this._loop = false;
4099
- return;
4100
- }
4101
- this._payloadLength = this.consume(2).readUInt16BE(0);
4102
- this.haveLength(cb);
4103
- }
4104
- getPayloadLength64(cb) {
4105
- if (this._bufferedBytes < 8) {
4106
- this._loop = false;
4107
- return;
4108
- }
4109
- const buf = this.consume(8);
4110
- const num = buf.readUInt32BE(0);
4111
- if (num > Math.pow(2, 53 - 32) - 1) {
4112
- const error48 = this.createError(RangeError, "Unsupported WebSocket frame: payload length > 2^53 - 1", false, 1009, "WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");
4113
- cb(error48);
4114
- return;
4115
- }
4116
- this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
4117
- this.haveLength(cb);
4118
- }
4119
- haveLength(cb) {
4120
- if (this._payloadLength && this._opcode < 8) {
4121
- this._totalPayloadLength += this._payloadLength;
4122
- if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
4123
- const error48 = this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");
4124
- cb(error48);
4125
- return;
4126
- }
4127
- }
4128
- if (this._masked)
4129
- this._state = GET_MASK;
4130
- else
4131
- this._state = GET_DATA;
4132
- }
4133
- getMask() {
4134
- if (this._bufferedBytes < 4) {
4135
- this._loop = false;
4136
- return;
4137
- }
4138
- this._mask = this.consume(4);
4139
- this._state = GET_DATA;
4140
- }
4141
- getData(cb) {
4142
- let data = EMPTY_BUFFER;
4143
- if (this._payloadLength) {
4144
- if (this._bufferedBytes < this._payloadLength) {
4145
- this._loop = false;
4146
- return;
4147
- }
4148
- data = this.consume(this._payloadLength);
4149
- if (this._masked && (this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0) {
4150
- unmask(data, this._mask);
4151
- }
4152
- }
4153
- if (this._opcode > 7) {
4154
- this.controlMessage(data, cb);
4155
- return;
4156
- }
4157
- if (this._compressed) {
4158
- this._state = INFLATING;
4159
- this.decompress(data, cb);
4160
- return;
4161
- }
4162
- if (data.length) {
4163
- this._messageLength = this._totalPayloadLength;
4164
- this._fragments.push(data);
4165
- }
4166
- this.dataMessage(cb);
4167
- }
4168
- decompress(data, cb) {
4169
- const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
4170
- perMessageDeflate.decompress(data, this._fin, (err, buf) => {
4171
- if (err)
4172
- return cb(err);
4173
- if (buf.length) {
4174
- this._messageLength += buf.length;
4175
- if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
4176
- const error48 = this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");
4177
- cb(error48);
1026
+ const error48 = this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");
1027
+ cb(error48);
4178
1028
  return;
4179
1029
  }
4180
1030
  this._fragments.push(buf);
@@ -4287,9 +1137,9 @@ var require_receiver = __commonJS2((exports, module) => {
4287
1137
  }
4288
1138
  module.exports = Receiver;
4289
1139
  });
4290
- var require_sender = __commonJS2((exports, module) => {
4291
- var { Duplex } = __require2("stream");
4292
- var { randomFillSync } = __require2("crypto");
1140
+ var require_sender = __commonJS((exports, module) => {
1141
+ var { Duplex } = __require("stream");
1142
+ var { randomFillSync } = __require("crypto");
4293
1143
  var PerMessageDeflate = require_permessage_deflate();
4294
1144
  var { EMPTY_BUFFER, kWebSocket, NOOP } = require_constants();
4295
1145
  var { isBlob, isValidStatusCode } = require_validation();
@@ -4639,7 +1489,7 @@ var require_sender = __commonJS2((exports, module) => {
4639
1489
  sender.onerror(err);
4640
1490
  }
4641
1491
  });
4642
- var require_event_target = __commonJS2((exports, module) => {
1492
+ var require_event_target = __commonJS((exports, module) => {
4643
1493
  var { kForOnEventAttribute, kListener } = require_constants();
4644
1494
  var kCode = Symbol("kCode");
4645
1495
  var kData = Symbol("kData");
@@ -4788,7 +1638,7 @@ var require_event_target = __commonJS2((exports, module) => {
4788
1638
  }
4789
1639
  }
4790
1640
  });
4791
- var require_extension = __commonJS2((exports, module) => {
1641
+ var require_extension = __commonJS((exports, module) => {
4792
1642
  var { tokenChars } = require_validation();
4793
1643
  function push(dest, name, elem) {
4794
1644
  if (dest[name] === undefined)
@@ -4951,15 +1801,15 @@ var require_extension = __commonJS2((exports, module) => {
4951
1801
  }
4952
1802
  module.exports = { format, parse: parse5 };
4953
1803
  });
4954
- var require_websocket = __commonJS2((exports, module) => {
4955
- var EventEmitter2 = __require2("events");
4956
- var https = __require2("https");
4957
- var http = __require2("http");
4958
- var net = __require2("net");
4959
- var tls = __require2("tls");
4960
- var { randomBytes, createHash } = __require2("crypto");
4961
- var { Duplex, Readable } = __require2("stream");
4962
- var { URL: URL2 } = __require2("url");
1804
+ var require_websocket = __commonJS((exports, module) => {
1805
+ var EventEmitter2 = __require("events");
1806
+ var https = __require("https");
1807
+ var http = __require("http");
1808
+ var net = __require("net");
1809
+ var tls = __require("tls");
1810
+ var { randomBytes, createHash } = __require("crypto");
1811
+ var { Duplex, Readable } = __require("stream");
1812
+ var { URL: URL2 } = __require("url");
4963
1813
  var PerMessageDeflate = require_permessage_deflate();
4964
1814
  var Receiver = require_receiver();
4965
1815
  var Sender = require_sender();
@@ -5708,9 +2558,9 @@ var require_websocket = __commonJS2((exports, module) => {
5708
2558
  }
5709
2559
  }
5710
2560
  });
5711
- var require_stream = __commonJS2((exports, module) => {
2561
+ var require_stream = __commonJS((exports, module) => {
5712
2562
  var WebSocket = require_websocket();
5713
- var { Duplex } = __require2("stream");
2563
+ var { Duplex } = __require("stream");
5714
2564
  function emitClose(stream) {
5715
2565
  stream.emit("close");
5716
2566
  }
@@ -5809,7 +2659,7 @@ var require_stream = __commonJS2((exports, module) => {
5809
2659
  }
5810
2660
  module.exports = createWebSocketStream;
5811
2661
  });
5812
- var require_subprotocol = __commonJS2((exports, module) => {
2662
+ var require_subprotocol = __commonJS((exports, module) => {
5813
2663
  var { tokenChars } = require_validation();
5814
2664
  function parse5(header) {
5815
2665
  const protocols = new Set;
@@ -5852,11 +2702,11 @@ var require_subprotocol = __commonJS2((exports, module) => {
5852
2702
  }
5853
2703
  module.exports = { parse: parse5 };
5854
2704
  });
5855
- var require_websocket_server = __commonJS2((exports, module) => {
5856
- var EventEmitter2 = __require2("events");
5857
- var http = __require2("http");
5858
- var { Duplex } = __require2("stream");
5859
- var { createHash } = __require2("crypto");
2705
+ var require_websocket_server = __commonJS((exports, module) => {
2706
+ var EventEmitter2 = __require("events");
2707
+ var http = __require("http");
2708
+ var { Duplex } = __require("stream");
2709
+ var { createHash } = __require("crypto");
5860
2710
  var extension = require_extension();
5861
2711
  var PerMessageDeflate = require_permessage_deflate();
5862
2712
  var subprotocol = require_subprotocol();
@@ -6220,7 +3070,7 @@ function pick(obj, keys) {
6220
3070
  });
6221
3071
  return result;
6222
3072
  }
6223
- var import__ = __toESM2(require_eventemitter3(), 1);
3073
+ var import__ = __toESM(require_eventemitter3(), 1);
6224
3074
  function isPlainObject(value) {
6225
3075
  if (!value || typeof value !== "object") {
6226
3076
  return false;
@@ -20931,11 +17781,11 @@ class ServerBase {
20931
17781
  ws.send(JSON.stringify({ type: "connected" }));
20932
17782
  }
20933
17783
  }
20934
- var import_stream = __toESM2(require_stream(), 1);
20935
- var import_receiver = __toESM2(require_receiver(), 1);
20936
- var import_sender = __toESM2(require_sender(), 1);
20937
- var import_websocket = __toESM2(require_websocket(), 1);
20938
- var import_websocket_server = __toESM2(require_websocket_server(), 1);
17784
+ var import_stream = __toESM(require_stream(), 1);
17785
+ var import_receiver = __toESM(require_receiver(), 1);
17786
+ var import_sender = __toESM(require_sender(), 1);
17787
+ var import_websocket = __toESM(require_websocket(), 1);
17788
+ var import_websocket_server = __toESM(require_websocket_server(), 1);
20939
17789
 
20940
17790
  // node_modules/.pnpm/@kevisual+context@0.0.8/node_modules/@kevisual/context/dist/app.js
20941
17791
  var isBrowser2 = typeof window !== "undefined" && typeof window.document !== "undefined";
@@ -21492,28 +18342,28 @@ class InitEnv {
21492
18342
  InitEnv.init();
21493
18343
 
21494
18344
  // node_modules/.pnpm/@kevisual+use-config@1.0.30_dotenv@17.3.1/node_modules/@kevisual/use-config/dist/app.js
21495
- import { createRequire as createRequire3 } from "node:module";
18345
+ import { createRequire as createRequire2 } from "node:module";
21496
18346
  import fs from "node:fs";
21497
18347
  import path from "node:path";
21498
- var __create3 = Object.create;
21499
- var __getProtoOf3 = Object.getPrototypeOf;
18348
+ var __create2 = Object.create;
18349
+ var __getProtoOf2 = Object.getPrototypeOf;
21500
18350
  var __defProp3 = Object.defineProperty;
21501
- var __getOwnPropNames3 = Object.getOwnPropertyNames;
21502
- var __hasOwnProp3 = Object.prototype.hasOwnProperty;
21503
- var __toESM3 = (mod, isNodeMode, target) => {
21504
- target = mod != null ? __create3(__getProtoOf3(mod)) : {};
18351
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
18352
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
18353
+ var __toESM2 = (mod, isNodeMode, target) => {
18354
+ target = mod != null ? __create2(__getProtoOf2(mod)) : {};
21505
18355
  const to = isNodeMode || !mod || !mod.__esModule ? __defProp3(target, "default", { value: mod, enumerable: true }) : target;
21506
- for (let key of __getOwnPropNames3(mod))
21507
- if (!__hasOwnProp3.call(to, key))
18356
+ for (let key of __getOwnPropNames2(mod))
18357
+ if (!__hasOwnProp2.call(to, key))
21508
18358
  __defProp3(to, key, {
21509
18359
  get: () => mod[key],
21510
18360
  enumerable: true
21511
18361
  });
21512
18362
  return to;
21513
18363
  };
21514
- var __commonJS3 = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
21515
- var __require3 = /* @__PURE__ */ createRequire3(import.meta.url);
21516
- var require_package = __commonJS3((exports, module) => {
18364
+ var __commonJS2 = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
18365
+ var __require2 = /* @__PURE__ */ createRequire2(import.meta.url);
18366
+ var require_package = __commonJS2((exports, module) => {
21517
18367
  module.exports = {
21518
18368
  name: "dotenv",
21519
18369
  version: "17.2.3",
@@ -21577,11 +18427,11 @@ var require_package = __commonJS3((exports, module) => {
21577
18427
  }
21578
18428
  };
21579
18429
  });
21580
- var require_main = __commonJS3((exports, module) => {
21581
- var fs2 = __require3("fs");
21582
- var path2 = __require3("path");
21583
- var os = __require3("os");
21584
- var crypto3 = __require3("crypto");
18430
+ var require_main = __commonJS2((exports, module) => {
18431
+ var fs2 = __require2("fs");
18432
+ var path2 = __require2("path");
18433
+ var os = __require2("os");
18434
+ var crypto3 = __require2("crypto");
21585
18435
  var packageJson = require_package();
21586
18436
  var version2 = packageJson.version;
21587
18437
  var TIPS = [
@@ -21904,7 +18754,7 @@ var require_main = __commonJS3((exports, module) => {
21904
18754
  exports.populate = DotenvModule.populate;
21905
18755
  module.exports = DotenvModule;
21906
18756
  });
21907
- var import_dotenv = __toESM3(require_main(), 1);
18757
+ var import_dotenv = __toESM2(require_main(), 1);
21908
18758
  var fileIsExist = (path2) => {
21909
18759
  try {
21910
18760
  fs.accessSync(path2, fs.constants.F_OK);
@@ -36970,410 +33820,163 @@ app.route({
36970
33820
  ctx.forward({ code: 200, message: "已关闭的工作空间删除完成", data: results });
36971
33821
  }).addTo(app);
36972
33822
 
36973
- // node_modules/.pnpm/nanoid@5.1.6/node_modules/nanoid/index.js
36974
- import { webcrypto as crypto3 } from "node:crypto";
36975
-
36976
- // node_modules/.pnpm/nanoid@5.1.6/node_modules/nanoid/url-alphabet/index.js
36977
- var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
36978
-
36979
- // node_modules/.pnpm/nanoid@5.1.6/node_modules/nanoid/index.js
36980
- var POOL_SIZE_MULTIPLIER2 = 128;
36981
- var pool2;
36982
- var poolOffset2;
36983
- function fillPool2(bytes) {
36984
- if (!pool2 || pool2.length < bytes) {
36985
- pool2 = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER2);
36986
- crypto3.getRandomValues(pool2);
36987
- poolOffset2 = 0;
36988
- } else if (poolOffset2 + bytes > pool2.length) {
36989
- crypto3.getRandomValues(pool2);
36990
- poolOffset2 = 0;
36991
- }
36992
- poolOffset2 += bytes;
36993
- }
36994
- function nanoid7(size = 21) {
36995
- fillPool2(size |= 0);
36996
- let id = "";
36997
- for (let i = poolOffset2 - size;i < poolOffset2; i++) {
36998
- id += urlAlphabet[pool2[i] & 63];
36999
- }
37000
- return id;
37001
- }
37002
-
37003
- // agent/routes/workspace/keep.ts
37004
- var import_dayjs = __toESM(require_dayjs_min(), 1);
37005
-
37006
- // src/workspace/keep-live.ts
37007
- var WebSocketModule;
37008
- if (typeof Bun !== "undefined") {
37009
- WebSocketModule = { WebSocket: globalThis.WebSocket };
37010
- } else {
37011
- WebSocketModule = await Promise.resolve().then(() => (init_wrapper(), exports_wrapper));
37012
- }
37013
- var WebSocket2 = WebSocketModule.WebSocket;
37014
-
37015
- class WSKeepAlive {
37016
- ws = null;
37017
- config;
37018
- reconnectAttempts = 0;
37019
- pingTimer = null;
37020
- messageHandlers = new Set;
37021
- url;
37022
- isBun;
37023
- constructor(config4) {
37024
- this.config = {
37025
- wsUrl: config4.wsUrl,
37026
- cookie: config4.cookie,
37027
- reconnectInterval: config4.reconnectInterval ?? 5000,
37028
- maxReconnectAttempts: config4.maxReconnectAttempts ?? 3,
37029
- pingInterval: config4.pingInterval ?? 30000,
37030
- onMessage: config4.onMessage ?? (() => {}),
37031
- onConnect: config4.onConnect ?? (() => {}),
37032
- onDisconnect: config4.onDisconnect ?? (() => {}),
37033
- onError: config4.onError ?? (() => {}),
37034
- onSign: config4.onSign ?? (() => {}),
37035
- onExit: config4.onExit ?? (() => {}),
37036
- debug: config4.debug ?? false
37037
- };
37038
- this.url = new URL(this.config.wsUrl);
37039
- this.isBun = typeof Bun !== "undefined";
33823
+ // src/workspace/keep-file-live.ts
33824
+ import path2 from "node:path";
33825
+ import fs2 from "node:fs";
33826
+ import os from "node:os";
33827
+ import { execSync } from "node:child_process";
33828
+ var keepAliveFilePath = path2.join(os.homedir(), ".cnb/keepAliveCache.json");
33829
+ var runLive = (filePath, pm2Name) => {
33830
+ const cmdArgs = `cnb live -c ${filePath}`;
33831
+ const stopCmd = `pm2 delete ${pm2Name} 2>/dev/null || true`;
33832
+ console.log("停止已存在的进程:", stopCmd);
33833
+ try {
33834
+ execSync(stopCmd, { stdio: "inherit" });
33835
+ } catch (error49) {
33836
+ console.log("停止进程失败或进程不存在:", error49);
37040
33837
  }
37041
- log(message) {
37042
- if (!this.config.debug)
37043
- return;
37044
- const timestamp = new Date().toISOString();
37045
- const msg = `[${timestamp}] ${message}`;
37046
- console.log(msg);
37047
- }
37048
- parseMessage(data) {
37049
- const result = { type: "unknown", raw: data };
37050
- if (data.length < 14) {
37051
- result.type = "raw";
37052
- return result;
37053
- }
37054
- const prefix = data.slice(0, 13);
37055
- const msgType = prefix[0];
37056
- const jsonStart = data.indexOf(113);
37057
- if (jsonStart !== -1) {
37058
- try {
37059
- const jsonStr = data.slice(jsonStart + 1).toString();
37060
- const payload = JSON.parse(jsonStr);
37061
- result.type = `binary(0x${msgType.toString(16)})`;
37062
- result.payload = payload;
37063
- if (payload.type === "sign" && this.config.onSign) {
37064
- this.config.onSign(payload);
37065
- }
37066
- return result;
37067
- } catch {
37068
- result.type = "binary(json-parse-error)";
37069
- return result;
37070
- }
37071
- }
37072
- result.type = "raw";
37073
- return result;
33838
+ const pm2Cmd = `pm2 start ev --name ${pm2Name} --no-autorestart -- ${cmdArgs}`;
33839
+ console.log("执行命令:", pm2Cmd);
33840
+ try {
33841
+ const result = execSync(pm2Cmd, { stdio: "pipe", encoding: "utf8" });
33842
+ console.log(result);
33843
+ } catch (error49) {
33844
+ console.error("状态码:", error49.status);
33845
+ console.error("错误详情:", error49.stderr.toString());
37074
33846
  }
37075
- connect() {
37076
- const { wsUrl, cookie, debug } = this.config;
37077
- this.log(`Connecting to ${wsUrl}...`);
37078
- this.ws = new WebSocket2(wsUrl, {
37079
- headers: {
37080
- Origin: this.url.origin,
37081
- Cookie: cookie,
37082
- "Cache-Control": "no-cache",
37083
- "Accept-Language": "zh-CN,zh;q=0.9",
37084
- Pragma: "no-cache",
37085
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
37086
- "Sec-WebSocket-Extensions": "permessage-deflate"
37087
- }
37088
- });
37089
- if (this.isBun) {
37090
- const ws = this.ws;
37091
- ws.onopen = () => {
37092
- debug && this.log("Connected!");
37093
- this.reconnectAttempts = 0;
37094
- this.config.onConnect();
37095
- this.startPing();
37096
- };
37097
- ws.onmessage = async (event) => {
37098
- let data;
37099
- if (event.data instanceof Blob) {
37100
- data = Buffer.from(await event.data.arrayBuffer());
37101
- } else if (event.data instanceof ArrayBuffer) {
37102
- data = Buffer.from(event.data);
37103
- } else if (typeof event.data === "string") {
37104
- data = event.data;
37105
- } else {
37106
- data = Buffer.from(event.data);
37107
- }
37108
- this.handleMessage(data);
37109
- };
37110
- ws.onclose = (event) => {
37111
- debug && this.log(`Disconnected (code: ${event.code})`);
37112
- this.stopPing();
37113
- this.config.onDisconnect(event.code);
37114
- this.handleReconnect();
37115
- };
37116
- ws.onerror = (event) => {
37117
- debug && this.log(`Error: ${event}`);
37118
- this.config.onError(new Error("WebSocket error"));
37119
- };
37120
- } else {
37121
- const ws = this.ws;
37122
- ws.on("open", () => {
37123
- debug && this.log("Connected!");
37124
- this.reconnectAttempts = 0;
37125
- this.config.onConnect();
37126
- this.startPing();
37127
- });
37128
- ws.on("message", (data) => {
37129
- this.handleMessage(data);
37130
- });
37131
- ws.on("close", (code) => {
37132
- debug && this.log(`Disconnected (code: ${code})`);
37133
- this.stopPing();
37134
- this.config.onDisconnect(code);
37135
- this.handleReconnect();
37136
- });
37137
- ws.on("error", (err) => {
37138
- debug && this.log(`Error: ${err.message}`);
37139
- this.config.onError(err);
37140
- });
37141
- }
33847
+ };
33848
+ var stopLive = (pm2Name) => {
33849
+ const stopCmd = `pm2 delete ${pm2Name} 2>/dev/null || true`;
33850
+ console.log("停止进程:", stopCmd);
33851
+ try {
33852
+ execSync(stopCmd, { stdio: "inherit" });
33853
+ console.log(`已停止 ${pm2Name} 的保持存活任务`);
33854
+ return true;
33855
+ } catch (error49) {
33856
+ console.error("停止进程失败:", error49);
37142
33857
  }
37143
- handleMessage(data) {
37144
- if (Buffer.isBuffer(data)) {
37145
- const parsed = this.parseMessage(data);
37146
- this.config.onMessage(parsed?.raw ?? data);
37147
- this.messageHandlers.forEach((handler) => {
37148
- if (parsed)
37149
- handler(parsed);
37150
- });
33858
+ return false;
33859
+ };
33860
+ function getKeepAliveCache() {
33861
+ try {
33862
+ if (fs2.existsSync(keepAliveFilePath)) {
33863
+ const data = fs2.readFileSync(keepAliveFilePath, "utf-8");
33864
+ const cache = JSON.parse(data);
33865
+ return cache;
37151
33866
  } else {
37152
- this.config.onMessage(data);
37153
- }
37154
- }
37155
- startPing() {
37156
- this.stopPing();
37157
- this.pingTimer = setInterval(() => {
37158
- if (this.ws && this.ws.readyState === WebSocket2.OPEN) {
37159
- this.ws.send(JSON.stringify({ type: "ping", timestamp: Date.now() }));
37160
- this.log("Sent ping");
37161
- }
37162
- }, this.config.pingInterval);
37163
- }
37164
- stopPing() {
37165
- if (this.pingTimer) {
37166
- clearInterval(this.pingTimer);
37167
- this.pingTimer = null;
37168
- }
37169
- }
37170
- handleReconnect() {
37171
- if (this.reconnectAttempts >= this.config.maxReconnectAttempts) {
37172
- this.log(`Max reconnect attempts (${this.config.maxReconnectAttempts}) reached. Giving up.`);
37173
- this.config.onExit(1);
37174
- return;
33867
+ return { data: [] };
37175
33868
  }
37176
- this.reconnectAttempts++;
37177
- this.log(`Reconnecting in ${this.config.reconnectInterval}ms... (attempt ${this.reconnectAttempts}/${this.config.maxReconnectAttempts})`);
37178
- setTimeout(() => this.connect(), this.config.reconnectInterval);
37179
- }
37180
- onMessage(handler) {
37181
- this.messageHandlers.add(handler);
37182
- return () => this.messageHandlers.delete(handler);
33869
+ } catch (error49) {
33870
+ console.error("读取保持存活缓存文件失败:", error49);
33871
+ return { data: [] };
37183
33872
  }
37184
- disconnect() {
37185
- this.stopPing();
37186
- if (this.ws) {
37187
- this.ws.close();
37188
- this.config.onExit(0);
37189
- this.ws = null;
33873
+ }
33874
+ function addKeepAliveData(data) {
33875
+ const cache = getKeepAliveCache();
33876
+ cache.data.push(data);
33877
+ runLive(data.filePath, data.pm2Name);
33878
+ try {
33879
+ if (!fs2.existsSync(path2.dirname(keepAliveFilePath))) {
33880
+ fs2.mkdirSync(path2.dirname(keepAliveFilePath), { recursive: true });
37190
33881
  }
33882
+ fs2.writeFileSync(keepAliveFilePath, JSON.stringify(cache, null, 2), "utf-8");
33883
+ return cache;
33884
+ } catch (error49) {
33885
+ console.error("写入保持存活缓存文件失败:", error49);
33886
+ return { data: [] };
37191
33887
  }
37192
33888
  }
37193
- function createKeepAlive(config4) {
37194
- const client = new WSKeepAlive(config4);
37195
- client.connect();
37196
- return client;
37197
- }
33889
+ function removeKeepAliveData(repo2, pipelineId) {
33890
+ const cache = getKeepAliveCache();
33891
+ const item = cache.data.find((item2) => item2.repo === repo2 && item2.pipelineId === pipelineId);
33892
+ if (item) {
33893
+ stopLive(item.pm2Name);
33894
+ }
33895
+ cache.data = cache.data.filter((item2) => item2.repo !== repo2 || item2.pipelineId !== pipelineId);
33896
+ try {
33897
+ fs2.writeFileSync(keepAliveFilePath, JSON.stringify(cache, null, 2), "utf-8");
33898
+ return cache;
33899
+ } catch (error49) {
33900
+ console.error("写入保持存活缓存文件失败:", error49);
33901
+ return { data: [] };
33902
+ }
33903
+ }
33904
+ var createLiveData = (data) => {
33905
+ const { cookie, repo: repo2, pipelineId } = data;
33906
+ const createdTime = Date.now();
33907
+ const wsUrl = `wss://${pipelineId}.cnb.space:443?skipWebSocketFrames=false`;
33908
+ const pm2Name = `${repo2}__${pipelineId}`.replace(/\//g, "__");
33909
+ const filePath = path2.join(os.homedir(), ".cnb", `${pm2Name}.json`);
33910
+ const _newData = { wss: wsUrl, wsUrl, cookie, repo: repo2, pipelineId, createdTime, filePath, pm2Name };
33911
+ if (!fs2.existsSync(path2.dirname(filePath))) {
33912
+ fs2.mkdirSync(path2.dirname(filePath), { recursive: true });
33913
+ }
33914
+ fs2.writeFileSync(filePath, JSON.stringify(_newData, null, 2), "utf-8");
33915
+ return _newData;
33916
+ };
33917
+
37198
33918
  // agent/routes/workspace/keep.ts
37199
- var keepAliveMap = new Map;
37200
33919
  app.route({
37201
33920
  path: "cnb",
37202
33921
  key: "keep-workspace-alive",
37203
- description: "保持工作空间存活技能,参数wsUrl:工作空间访问URLcookie:访问工作空间所需的cookie",
33922
+ description: "保持工作空间存活技能,参数repo:代码仓库路径,例如 user/repopipelineId:流水线ID,例如 cnb-708-1ji9sog7o-001",
37204
33923
  middleware: ["admin-auth"],
37205
33924
  metadata: {
37206
33925
  tags: [],
37207
33926
  ...{
37208
33927
  args: {
37209
- wsUrl: tool.schema.string().describe("工作空间的访问URL"),
37210
- cookie: tool.schema.string().describe("访问工作空间所需的cookie")
33928
+ repo: tool.schema.string().describe("代码仓库路径,例如 user/repo"),
33929
+ pipelineId: tool.schema.string().describe("流水线ID,例如 cnb-708-1ji9sog7o-001")
37211
33930
  }
37212
33931
  }
37213
33932
  }
37214
33933
  }).define(async (ctx) => {
37215
- const wsUrl = ctx.query?.wsUrl;
37216
- const cookie = ctx.query?.cookie;
37217
- if (!wsUrl) {
37218
- ctx.throw(400, "缺少工作空间访问URL参数");
33934
+ const repo2 = ctx.query?.repo;
33935
+ const pipelineId = ctx.query?.pipelineId;
33936
+ if (!repo2 || !pipelineId) {
33937
+ ctx.throw(400, "缺少参数 repo 或 pipelineId");
37219
33938
  }
37220
- if (!cookie) {
37221
- ctx.throw(400, "缺少访问工作空间所需的cookie参数");
33939
+ const validCookie = await cnb.user.checkCookieValid();
33940
+ if (validCookie.code !== 200) {
33941
+ ctx.throw(401, "CNB_COOKIE 环境变量无效或已过期,请重新登录获取新的cookie");
37222
33942
  }
37223
- const existing = Array.from(keepAliveMap.values()).find((info) => info.id && info.KeepAlive?.wsUrl === wsUrl);
37224
- if (existing) {
37225
- ctx.body = { message: `工作空间 ${wsUrl} 的保持存活任务已在运行中`, id: existing.id };
37226
- return;
33943
+ const res = await cnb.workspace.getWorkspaceCookie(repo2, pipelineId);
33944
+ let wsUrl = `wss://${pipelineId}.cnb.space:443?skipWebSocketFrames=false`;
33945
+ let cookie = "";
33946
+ if (res.code === 200) {
33947
+ cookie = res.data.value;
33948
+ console.log(`启动保持工作空间 ${wsUrl} 存活的任务`);
33949
+ } else {
33950
+ ctx.throw(500, `获取工作空间访问cookie失败: ${res.message}`);
37227
33951
  }
37228
33952
  console.log(`启动保持工作空间 ${wsUrl} 存活的任务`);
37229
- const keep = createKeepAlive({
37230
- wsUrl,
37231
- cookie,
37232
- onConnect: () => {
37233
- console.log(`工作空间 ${wsUrl} 保持存活任务已连接`);
37234
- },
37235
- onMessage: (data) => {
37236
- for (const info of keepAliveMap.values()) {
37237
- if (info.KeepAlive?.wsUrl === wsUrl) {
37238
- info.updatedTime = Date.now();
37239
- break;
37240
- }
37241
- }
37242
- },
37243
- debug: true,
37244
- onExit: (code) => {
37245
- console.log(`工作空间 ${wsUrl} 保持存活任务已退出,退出码: ${code}`);
37246
- for (const [id2, info] of keepAliveMap.entries()) {
37247
- if (info.KeepAlive?.wsUrl === wsUrl) {
37248
- keepAliveMap.delete(id2);
37249
- break;
37250
- }
37251
- }
37252
- }
37253
- });
37254
- const id = nanoid7(6).toLowerCase();
37255
- keepAliveMap.set(id, { startTime: Date.now(), updatedTime: Date.now(), KeepAlive: keep, id });
37256
- ctx.body = { content: `已启动保持工作空间 ${wsUrl} 存活的任务`, id };
37257
- }).addTo(app);
37258
- app.route({
37259
- path: "cnb",
37260
- key: "list-keep-alive-tasks",
37261
- description: "获取保持工作空间存活任务列表技能",
37262
- middleware: ["admin-auth"],
37263
- metadata: {
37264
- tags: []
37265
- }
37266
- }).define(async (ctx) => {
37267
- const list = Array.from(keepAliveMap.entries()).map(([id, info]) => {
37268
- const now = Date.now();
37269
- const duration4 = Math.floor((now - info.startTime) / 60000);
37270
- return {
37271
- id,
37272
- wsUrl: info.KeepAlive?.wsUrl,
37273
- startTime: info.startTime,
37274
- startTimeStr: import_dayjs.default(info.startTime).format("YYYY-MM-DD HH:mm"),
37275
- updatedTime: info.updatedTime,
37276
- updatedTimeStr: import_dayjs.default(info.updatedTime).format("YYYY-MM-DD HH:mm"),
37277
- duration: duration4
37278
- };
37279
- });
37280
- ctx.body = { list };
33953
+ const config4 = createLiveData({ cookie, repo: repo2, pipelineId });
33954
+ addKeepAliveData(config4);
33955
+ ctx.body = { content: `已启动保持工作空间 ${wsUrl} 存活的任务`, data: config4 };
37281
33956
  }).addTo(app);
37282
33957
  app.route({
37283
33958
  path: "cnb",
37284
33959
  key: "stop-keep-workspace-alive",
37285
- description: "停止保持工作空间存活技能, 参数wsUrl:工作空间访问URL或者id",
33960
+ description: "停止保持工作空间存活技能, 参数repo:代码仓库路径,例如 user/repo,pipelineId:流水线ID,例如 cnb-708-1ji9sog7o-001",
37286
33961
  middleware: ["admin-auth"],
37287
33962
  metadata: {
37288
33963
  tags: [],
37289
33964
  ...{
37290
33965
  args: {
37291
- wsUrl: tool.schema.string().optional().describe("工作空间的访问URL"),
37292
- id: tool.schema.string().optional().describe("保持存活任务的唯一标识符")
37293
- }
37294
- }
37295
- }
37296
- }).define(async (ctx) => {
37297
- const wsUrl = ctx.query?.wsUrl;
37298
- const id = ctx.query?.id;
37299
- if (!wsUrl && !id) {
37300
- ctx.throw(400, "缺少工作空间访问URL参数或唯一标识符");
37301
- }
37302
- let targetId;
37303
- let wsUrlFound;
37304
- if (id) {
37305
- const info = keepAliveMap.get(id);
37306
- if (info) {
37307
- targetId = id;
37308
- wsUrlFound = info.KeepAlive?.wsUrl;
37309
- }
37310
- } else if (wsUrl) {
37311
- for (const [key, info] of keepAliveMap.entries()) {
37312
- if (info.KeepAlive?.wsUrl === wsUrl) {
37313
- targetId = key;
37314
- wsUrlFound = wsUrl;
37315
- break;
33966
+ repo: tool.schema.string().describe("代码仓库路径,例如 user/repo"),
33967
+ pipelineId: tool.schema.string().describe("流水线ID,例如 cnb-708-1ji9sog7o-001")
37316
33968
  }
37317
33969
  }
37318
33970
  }
37319
- if (targetId) {
37320
- const keepAlive = keepAliveMap.get(targetId);
37321
- const endTime = Date.now();
37322
- const duration4 = endTime - keepAlive.startTime;
37323
- keepAlive?.KeepAlive?.disconnect();
37324
- keepAliveMap.delete(targetId);
37325
- ctx.body = { content: `已停止保持工作空间 ${wsUrlFound} 存活的任务,持续时间: ${duration4}ms`, id: targetId };
37326
- } else {
37327
- ctx.body = { content: `没有找到对应的工作空间保持存活任务` };
37328
- }
37329
- }).addTo(app);
37330
- app.route({
37331
- path: "cnb",
37332
- key: "reset-keep-workspace-alive",
37333
- description: "对存活的工作空间,startTime进行重置",
37334
- middleware: ["admin-auth"],
37335
- metadata: {
37336
- tags: []
37337
- }
37338
33971
  }).define(async (ctx) => {
37339
- const now = Date.now();
37340
- for (const info of keepAliveMap.values()) {
37341
- info.startTime = now;
37342
- }
37343
- ctx.body = { content: `已重置所有存活工作空间的开始时间` };
37344
- }).addTo(app);
37345
- app.route({
37346
- path: "cnb",
37347
- key: "clear-keep-workspace-alive",
37348
- description: "对存活的工作空间,超过5小时的进行清理",
37349
- middleware: ["admin-auth"],
37350
- metadata: {
37351
- tags: []
33972
+ const repo2 = ctx.query?.repo;
33973
+ const pipelineId = ctx.query?.pipelineId;
33974
+ if (!repo2 || !pipelineId) {
33975
+ ctx.throw(400, "缺少参数 repo 或 pipelineId");
37352
33976
  }
37353
- }).define(async (ctx) => {
37354
- const res = clearKeepAlive();
37355
- ctx.body = {
37356
- content: `已清理所有存活工作空间中超过5小时的任务` + (res.length ? `,清理项:${res.map((i) => i.wsUrl).join(", ")}` : ""),
37357
- list: res
37358
- };
33977
+ removeKeepAliveData(repo2, pipelineId);
33978
+ ctx.body = { content: `已停止保持工作空间 ${repo2}/${pipelineId} 存活的任务` };
37359
33979
  }).addTo(app);
37360
- var clearKeepAlive = () => {
37361
- const now = Date.now();
37362
- let clearedArr = [];
37363
- for (const [id, info] of keepAliveMap.entries()) {
37364
- if (now - info.startTime > FIVE_HOURS) {
37365
- console.log(`工作空间 ${info.KeepAlive?.wsUrl} 超过5小时,自动停止`);
37366
- info.KeepAlive?.disconnect?.();
37367
- keepAliveMap.delete(id);
37368
- clearedArr.push({ id, wsUrl: info.KeepAlive?.wsUrl });
37369
- }
37370
- }
37371
- return clearedArr;
37372
- };
37373
- var FIVE_HOURS = 5 * 60 * 60 * 1000;
37374
- setInterval(() => {
37375
- clearKeepAlive();
37376
- }, FIVE_HOURS);
37377
33980
 
37378
33981
  // agent/routes/workspace/index.ts
37379
33982
  app.route({
@@ -37550,12 +34153,12 @@ if (!app.hasRoute("call")) {
37550
34153
  })
37551
34154
  }
37552
34155
  }).define(async (ctx) => {
37553
- const { path: path2, key } = ctx.query;
34156
+ const { path: path3, key } = ctx.query;
37554
34157
  console.log("call app", ctx.query);
37555
- if (!path2) {
34158
+ if (!path3) {
37556
34159
  ctx.throw("路径path不能为空");
37557
34160
  }
37558
- const res = await ctx.run({ path: path2, key, payload: ctx.query.payload || {} });
34161
+ const res = await ctx.run({ path: path3, key, payload: ctx.query.payload || {} });
37559
34162
  ctx.forward(res);
37560
34163
  }).addTo(app);
37561
34164
  }
@@ -37711,17 +34314,17 @@ app.route({
37711
34314
  }).addTo(app);
37712
34315
 
37713
34316
  // node_modules/.pnpm/@kevisual+ai@0.0.24/node_modules/@kevisual/ai/dist/ai-provider-browser.js
37714
- var __create4 = Object.create;
37715
- var __getProtoOf4 = Object.getPrototypeOf;
34317
+ var __create3 = Object.create;
34318
+ var __getProtoOf3 = Object.getPrototypeOf;
37716
34319
  var __defProp4 = Object.defineProperty;
37717
- var __getOwnPropNames4 = Object.getOwnPropertyNames;
34320
+ var __getOwnPropNames3 = Object.getOwnPropertyNames;
37718
34321
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
37719
- var __hasOwnProp4 = Object.prototype.hasOwnProperty;
37720
- var __toESM4 = (mod, isNodeMode, target) => {
37721
- target = mod != null ? __create4(__getProtoOf4(mod)) : {};
34322
+ var __hasOwnProp3 = Object.prototype.hasOwnProperty;
34323
+ var __toESM3 = (mod, isNodeMode, target) => {
34324
+ target = mod != null ? __create3(__getProtoOf3(mod)) : {};
37722
34325
  const to = isNodeMode || !mod || !mod.__esModule ? __defProp4(target, "default", { value: mod, enumerable: true }) : target;
37723
- for (let key of __getOwnPropNames4(mod))
37724
- if (!__hasOwnProp4.call(to, key))
34326
+ for (let key of __getOwnPropNames3(mod))
34327
+ if (!__hasOwnProp3.call(to, key))
37725
34328
  __defProp4(to, key, {
37726
34329
  get: () => mod[key],
37727
34330
  enumerable: true
@@ -37735,14 +34338,14 @@ var __toCommonJS = (from) => {
37735
34338
  return entry;
37736
34339
  entry = __defProp4({}, "__esModule", { value: true });
37737
34340
  if (from && typeof from === "object" || typeof from === "function")
37738
- __getOwnPropNames4(from).map((key) => !__hasOwnProp4.call(entry, key) && __defProp4(entry, key, {
34341
+ __getOwnPropNames3(from).map((key) => !__hasOwnProp3.call(entry, key) && __defProp4(entry, key, {
37739
34342
  get: () => from[key],
37740
34343
  enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
37741
34344
  }));
37742
34345
  __moduleCache.set(from, entry);
37743
34346
  return entry;
37744
34347
  };
37745
- var __commonJS4 = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
34348
+ var __commonJS3 = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
37746
34349
  var __export3 = (target, all) => {
37747
34350
  for (var name in all)
37748
34351
  __defProp4(target, name, {
@@ -37752,7 +34355,7 @@ var __export3 = (target, all) => {
37752
34355
  set: (newValue) => all[name] = () => newValue
37753
34356
  });
37754
34357
  };
37755
- var __esm2 = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
34358
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
37756
34359
  var exports_buffer = {};
37757
34360
  __export3(exports_buffer, {
37758
34361
  transcode: () => transcode,
@@ -38467,7 +35070,7 @@ var isAscii = (str) => {
38467
35070
  };
38468
35071
  var transcode;
38469
35072
  var buffer_default;
38470
- var init_buffer = __esm2(() => {
35073
+ var init_buffer = __esm(() => {
38471
35074
  lookup = [];
38472
35075
  revLookup = [];
38473
35076
  for (i = 0, len = code.length;i < len; ++i)
@@ -39461,7 +36064,7 @@ var promisify;
39461
36064
  var TextEncoder;
39462
36065
  var TextDecoder2;
39463
36066
  var util_default;
39464
- var init_util = __esm2(() => {
36067
+ var init_util = __esm(() => {
39465
36068
  formatRegExp = /%[sdj%]/g;
39466
36069
  debuglog = ((debugs = {}, debugEnvRegex = {}, debugEnv) => ((debugEnv = typeof process < "u" && false) && (debugEnv = debugEnv.replace(/[|\\{}()[\]^$+?.]/g, "\\$&").replace(/\*/g, ".*").replace(/,/g, "$|^").toUpperCase()), debugEnvRegex = new RegExp("^" + debugEnv + "$", "i"), (set3) => {
39467
36070
  if (set3 = set3.toUpperCase(), !debugs[set3])
@@ -39761,7 +36364,7 @@ var emitWithRejectionCapture = function(type2, ...args) {
39761
36364
  };
39762
36365
  var AbortError;
39763
36366
  var events_default;
39764
- var init_events = __esm2(() => {
36367
+ var init_events = __esm(() => {
39765
36368
  SymbolFor = Symbol.for;
39766
36369
  kCapture = Symbol("kCapture");
39767
36370
  kErrorMonitor = SymbolFor("events.errorMonitor");
@@ -39912,7 +36515,7 @@ var init_events = __esm2(() => {
39912
36515
  Object.assign(EventEmitter3, { once: once2, getEventListeners, getMaxListeners: getMaxListeners2, setMaxListeners: setMaxListeners2, EventEmitter: EventEmitter3, usingDomains: false, captureRejectionSymbol, errorMonitor: kErrorMonitor, addAbortListener, init: EventEmitter3, listenerCount: listenerCount2 });
39913
36516
  events_default = EventEmitter3;
39914
36517
  });
39915
- var require_stream3 = __commonJS4((exports, module) => {
36518
+ var require_stream2 = __commonJS3((exports, module) => {
39916
36519
  var __commonJS22 = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
39917
36520
  var require_primordials = __commonJS22((exports2, module2) => {
39918
36521
 
@@ -43821,7 +40424,7 @@ var require_stream3 = __commonJS4((exports, module) => {
43821
40424
  };
43822
40425
  });
43823
40426
  var require_ours = __commonJS22((exports2, module2) => {
43824
- var Stream = require_stream3();
40427
+ var Stream = require_stream2();
43825
40428
  {
43826
40429
  let CustomStream = require_stream22(), promises = require_promises(), originalDestroy = CustomStream.Readable.destroy;
43827
40430
  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() {
@@ -44006,7 +40609,7 @@ var require_buffer;
44006
40609
  var require_node;
44007
40610
  var require_base2;
44008
40611
  var require_der;
44009
- var require_constants3;
40612
+ var require_constants2;
44010
40613
  var require_der2;
44011
40614
  var require_pem;
44012
40615
  var require_decoders;
@@ -44086,7 +40689,7 @@ var randomUUID = () => {
44086
40689
  var hardcoded_curves;
44087
40690
  var webcrypto;
44088
40691
  var crypto_default;
44089
- var init_crypto = __esm2(() => {
40692
+ var init_crypto = __esm(() => {
44090
40693
  __create22 = Object.create;
44091
40694
  ({ getPrototypeOf: __getProtoOf22, defineProperty: __defProp22, getOwnPropertyNames: __getOwnPropNames22 } = Object);
44092
40695
  __hasOwnProp22 = Object.prototype.hasOwnProperty;
@@ -51635,8 +48238,8 @@ var init_crypto = __esm2(() => {
51635
48238
  return result;
51636
48239
  return { result: this.isError(result) ? null : result, errors: state.errors };
51637
48240
  };
51638
- function ReporterError(path2, msg) {
51639
- this.path = path2, this.rethrow(msg);
48241
+ function ReporterError(path3, msg) {
48242
+ this.path = path3, this.rethrow(msg);
51640
48243
  }
51641
48244
  inherits2(ReporterError, Error);
51642
48245
  ReporterError.prototype.rethrow = function(msg) {
@@ -52086,13 +48689,13 @@ var init_crypto = __esm2(() => {
52086
48689
  base.Node = require_node();
52087
48690
  });
52088
48691
  require_der = __commonJS22((exports) => {
52089
- var constants22 = require_constants3();
48692
+ var constants22 = require_constants2();
52090
48693
  exports.tagClass = { 0: "universal", 1: "application", 2: "context", 3: "private" };
52091
48694
  exports.tagClassByName = constants22._reverse(exports.tagClass);
52092
48695
  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" };
52093
48696
  exports.tagByName = constants22._reverse(exports.tag);
52094
48697
  });
52095
- require_constants3 = __commonJS22((exports) => {
48698
+ require_constants2 = __commonJS22((exports) => {
52096
48699
  var constants22 = exports;
52097
48700
  constants22._reverse = function(map3) {
52098
48701
  var res = {};
@@ -52555,7 +49158,7 @@ var init_crypto = __esm2(() => {
52555
49158
  asn1.bignum = require_bn3();
52556
49159
  asn1.define = require_api().define;
52557
49160
  asn1.base = require_base2();
52558
- asn1.constants = require_constants3();
49161
+ asn1.constants = require_constants2();
52559
49162
  asn1.decoders = require_decoders();
52560
49163
  asn1.encoders = require_encoders();
52561
49164
  });
@@ -52631,7 +49234,7 @@ var init_crypto = __esm2(() => {
52631
49234
  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" };
52632
49235
  });
52633
49236
  require_hash_base = __commonJS22((exports, module) => {
52634
- var Buffer22 = require_safe_buffer().Buffer, Transform = require_stream3().Transform, inherits2 = require_inherits();
49237
+ var Buffer22 = require_safe_buffer().Buffer, Transform = require_stream2().Transform, inherits2 = require_inherits();
52635
49238
  function HashBase(blockSize) {
52636
49239
  Transform.call(this), this._block = Buffer22.allocUnsafe(blockSize), this._blockSize = blockSize, this._blockOffset = 0, this._length = [0, 0, 0, 0], this._finalized = false;
52637
49240
  }
@@ -56067,7 +52670,7 @@ https://github.com/browserify/crypto-browserify`);
56067
52670
  webcrypto = crypto;
56068
52671
  crypto_default = crypto;
56069
52672
  });
56070
- var require_core = __commonJS4((exports, module) => {
52673
+ var require_core = __commonJS3((exports, module) => {
56071
52674
  (function(root, factory) {
56072
52675
  if (typeof exports === "object") {
56073
52676
  module.exports = exports = factory();
@@ -56350,7 +52953,7 @@ var require_core = __commonJS4((exports, module) => {
56350
52953
  return CryptoJS;
56351
52954
  });
56352
52955
  });
56353
- var require_enc_base64 = __commonJS4((exports, module) => {
52956
+ var require_enc_base64 = __commonJS3((exports, module) => {
56354
52957
  (function(root, factory) {
56355
52958
  if (typeof exports === "object") {
56356
52959
  module.exports = exports = factory(require_core());
@@ -56428,7 +53031,7 @@ var require_enc_base64 = __commonJS4((exports, module) => {
56428
53031
  return CryptoJS.enc.Base64;
56429
53032
  });
56430
53033
  });
56431
- var require_md52 = __commonJS4((exports, module) => {
53034
+ var require_md52 = __commonJS3((exports, module) => {
56432
53035
  (function(root, factory) {
56433
53036
  if (typeof exports === "object") {
56434
53037
  module.exports = exports = factory(require_core());
@@ -56603,7 +53206,7 @@ var require_md52 = __commonJS4((exports, module) => {
56603
53206
  return CryptoJS.MD5;
56604
53207
  });
56605
53208
  });
56606
- var require_sha1 = __commonJS4((exports, module) => {
53209
+ var require_sha1 = __commonJS3((exports, module) => {
56607
53210
  (function(root, factory) {
56608
53211
  if (typeof exports === "object") {
56609
53212
  module.exports = exports = factory(require_core());
@@ -56690,7 +53293,7 @@ var require_sha1 = __commonJS4((exports, module) => {
56690
53293
  return CryptoJS.SHA1;
56691
53294
  });
56692
53295
  });
56693
- var require_hmac2 = __commonJS4((exports, module) => {
53296
+ var require_hmac2 = __commonJS3((exports, module) => {
56694
53297
  (function(root, factory) {
56695
53298
  if (typeof exports === "object") {
56696
53299
  module.exports = exports = factory(require_core());
@@ -56750,7 +53353,7 @@ var require_hmac2 = __commonJS4((exports, module) => {
56750
53353
  })();
56751
53354
  });
56752
53355
  });
56753
- var require_evpkdf = __commonJS4((exports, module) => {
53356
+ var require_evpkdf = __commonJS3((exports, module) => {
56754
53357
  (function(root, factory, undef) {
56755
53358
  if (typeof exports === "object") {
56756
53359
  module.exports = exports = factory(require_core(), require_sha1(), require_hmac2());
@@ -56807,7 +53410,7 @@ var require_evpkdf = __commonJS4((exports, module) => {
56807
53410
  return CryptoJS.EvpKDF;
56808
53411
  });
56809
53412
  });
56810
- var require_cipher_core = __commonJS4((exports, module) => {
53413
+ var require_cipher_core = __commonJS3((exports, module) => {
56811
53414
  (function(root, factory, undef) {
56812
53415
  if (typeof exports === "object") {
56813
53416
  module.exports = exports = factory(require_core(), require_evpkdf());
@@ -57103,7 +53706,7 @@ var require_cipher_core = __commonJS4((exports, module) => {
57103
53706
  }();
57104
53707
  });
57105
53708
  });
57106
- var require_aes = __commonJS4((exports, module) => {
53709
+ var require_aes = __commonJS3((exports, module) => {
57107
53710
  (function(root, factory, undef) {
57108
53711
  if (typeof exports === "object") {
57109
53712
  module.exports = exports = factory(require_core(), require_enc_base64(), require_md52(), require_evpkdf(), require_cipher_core());
@@ -57253,7 +53856,7 @@ var require_aes = __commonJS4((exports, module) => {
57253
53856
  return CryptoJS.AES;
57254
53857
  });
57255
53858
  });
57256
- var require_enc_utf8 = __commonJS4((exports, module) => {
53859
+ var require_enc_utf8 = __commonJS3((exports, module) => {
57257
53860
  (function(root, factory) {
57258
53861
  if (typeof exports === "object") {
57259
53862
  module.exports = exports = factory(require_core());
@@ -57556,8 +54159,8 @@ class CNBChat extends BaseChat {
57556
54159
  };
57557
54160
  }
57558
54161
  }
57559
- var import_aes = __toESM4(require_aes(), 1);
57560
- var import_enc_utf8 = __toESM4(require_enc_utf8(), 1);
54162
+ var import_aes = __toESM3(require_aes(), 1);
54163
+ var import_enc_utf8 = __toESM3(require_enc_utf8(), 1);
57561
54164
  var CryptoJS = { AES: import_aes.default, enc: { Utf8: import_enc_utf8.default } };
57562
54165
 
57563
54166
  // agent/routes/knowledge/ai.ts
@@ -57882,24 +54485,24 @@ if (!app.hasRoute("auth")) {
57882
54485
  }
57883
54486
 
57884
54487
  // node_modules/.pnpm/@kevisual+router@0.0.84/node_modules/@kevisual/router/dist/opencode.js
57885
- import { webcrypto as crypto4 } from "node:crypto";
57886
- var __create5 = Object.create;
57887
- var __getProtoOf5 = Object.getPrototypeOf;
54488
+ import { webcrypto as crypto3 } from "node:crypto";
54489
+ var __create4 = Object.create;
54490
+ var __getProtoOf4 = Object.getPrototypeOf;
57888
54491
  var __defProp5 = Object.defineProperty;
57889
- var __getOwnPropNames5 = Object.getOwnPropertyNames;
57890
- var __hasOwnProp5 = Object.prototype.hasOwnProperty;
57891
- var __toESM5 = (mod, isNodeMode, target) => {
57892
- target = mod != null ? __create5(__getProtoOf5(mod)) : {};
54492
+ var __getOwnPropNames4 = Object.getOwnPropertyNames;
54493
+ var __hasOwnProp4 = Object.prototype.hasOwnProperty;
54494
+ var __toESM4 = (mod, isNodeMode, target) => {
54495
+ target = mod != null ? __create4(__getProtoOf4(mod)) : {};
57893
54496
  const to = isNodeMode || !mod || !mod.__esModule ? __defProp5(target, "default", { value: mod, enumerable: true }) : target;
57894
- for (let key of __getOwnPropNames5(mod))
57895
- if (!__hasOwnProp5.call(to, key))
54497
+ for (let key of __getOwnPropNames4(mod))
54498
+ if (!__hasOwnProp4.call(to, key))
57896
54499
  __defProp5(to, key, {
57897
54500
  get: () => mod[key],
57898
54501
  enumerable: true
57899
54502
  });
57900
54503
  return to;
57901
54504
  };
57902
- var __commonJS5 = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
54505
+ var __commonJS4 = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
57903
54506
  var __export4 = (target, all) => {
57904
54507
  for (var name in all)
57905
54508
  __defProp5(target, name, {
@@ -57909,7 +54512,7 @@ var __export4 = (target, all) => {
57909
54512
  set: (newValue) => all[name] = () => newValue
57910
54513
  });
57911
54514
  };
57912
- var require_eventemitter32 = __commonJS5((exports, module) => {
54515
+ var require_eventemitter32 = __commonJS4((exports, module) => {
57913
54516
  var has = Object.prototype.hasOwnProperty;
57914
54517
  var prefix = "~";
57915
54518
  function Events() {}
@@ -58637,7 +55240,7 @@ class InitEnv3 {
58637
55240
  }
58638
55241
  }
58639
55242
  InitEnv3.init();
58640
- var import__2 = __toESM5(require_eventemitter32(), 1);
55243
+ var import__2 = __toESM4(require_eventemitter32(), 1);
58641
55244
  var exports_external3 = {};
58642
55245
  __export4(exports_external3, {
58643
55246
  xor: () => xor3,
@@ -59397,10 +56000,10 @@ function mergeDefs3(...defs) {
59397
56000
  function cloneDef3(schema) {
59398
56001
  return mergeDefs3(schema._zod.def);
59399
56002
  }
59400
- function getElementAtPath3(obj, path2) {
59401
- if (!path2)
56003
+ function getElementAtPath3(obj, path3) {
56004
+ if (!path3)
59402
56005
  return obj;
59403
- return path2.reduce((acc, key) => acc?.[key], obj);
56006
+ return path3.reduce((acc, key) => acc?.[key], obj);
59404
56007
  }
59405
56008
  function promiseAllObject3(promisesObj) {
59406
56009
  const keys = Object.keys(promisesObj);
@@ -59781,11 +56384,11 @@ function aborted3(x, startIndex = 0) {
59781
56384
  }
59782
56385
  return false;
59783
56386
  }
59784
- function prefixIssues3(path2, issues) {
56387
+ function prefixIssues3(path3, issues) {
59785
56388
  return issues.map((iss) => {
59786
56389
  var _a3;
59787
56390
  (_a3 = iss).path ?? (_a3.path = []);
59788
- iss.path.unshift(path2);
56391
+ iss.path.unshift(path3);
59789
56392
  return iss;
59790
56393
  });
59791
56394
  }
@@ -59966,7 +56569,7 @@ function formatError4(error49, mapper = (issue22) => issue22.message) {
59966
56569
  }
59967
56570
  function treeifyError3(error49, mapper = (issue22) => issue22.message) {
59968
56571
  const result = { errors: [] };
59969
- const processError = (error210, path2 = []) => {
56572
+ const processError = (error210, path3 = []) => {
59970
56573
  var _a3, _b;
59971
56574
  for (const issue22 of error210.issues) {
59972
56575
  if (issue22.code === "invalid_union" && issue22.errors.length) {
@@ -59976,7 +56579,7 @@ function treeifyError3(error49, mapper = (issue22) => issue22.message) {
59976
56579
  } else if (issue22.code === "invalid_element") {
59977
56580
  processError({ issues: issue22.issues }, issue22.path);
59978
56581
  } else {
59979
- const fullpath = [...path2, ...issue22.path];
56582
+ const fullpath = [...path3, ...issue22.path];
59980
56583
  if (fullpath.length === 0) {
59981
56584
  result.errors.push(mapper(issue22));
59982
56585
  continue;
@@ -60008,8 +56611,8 @@ function treeifyError3(error49, mapper = (issue22) => issue22.message) {
60008
56611
  }
60009
56612
  function toDotPath3(_path) {
60010
56613
  const segs = [];
60011
- const path2 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
60012
- for (const seg of path2) {
56614
+ const path3 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
56615
+ for (const seg of path3) {
60013
56616
  if (typeof seg === "number")
60014
56617
  segs.push(`[${seg}]`);
60015
56618
  else if (typeof seg === "symbol")
@@ -60149,7 +56752,7 @@ __export4(exports_regexes3, {
60149
56752
  rfc5322Email: () => rfc5322Email3,
60150
56753
  number: () => number8,
60151
56754
  null: () => _null8,
60152
- nanoid: () => nanoid8,
56755
+ nanoid: () => nanoid7,
60153
56756
  md5_hex: () => md5_hex3,
60154
56757
  md5_base64url: () => md5_base64url3,
60155
56758
  md5_base64: () => md5_base643,
@@ -60187,7 +56790,7 @@ var cuid26 = /^[0-9a-z]+$/;
60187
56790
  var ulid6 = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/;
60188
56791
  var xid6 = /^[0-9a-vA-V]{20}$/;
60189
56792
  var ksuid6 = /^[A-Za-z0-9]{27}$/;
60190
- var nanoid8 = /^[a-zA-Z0-9_-]{21}$/;
56793
+ var nanoid7 = /^[a-zA-Z0-9_-]{21}$/;
60191
56794
  var duration6 = /^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;
60192
56795
  var extendedDuration3 = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
60193
56796
  var guid6 = /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/;
@@ -61079,7 +57682,7 @@ var $ZodEmoji3 = /* @__PURE__ */ $constructor3("$ZodEmoji", (inst, def) => {
61079
57682
  $ZodStringFormat3.init(inst, def);
61080
57683
  });
61081
57684
  var $ZodNanoID3 = /* @__PURE__ */ $constructor3("$ZodNanoID", (inst, def) => {
61082
- def.pattern ?? (def.pattern = nanoid8);
57685
+ def.pattern ?? (def.pattern = nanoid7);
61083
57686
  $ZodStringFormat3.init(inst, def);
61084
57687
  });
61085
57688
  var $ZodCUID5 = /* @__PURE__ */ $constructor3("$ZodCUID", (inst, def) => {
@@ -71675,13 +68278,13 @@ function resolveRef3(ref, ctx) {
71675
68278
  if (!ref.startsWith("#")) {
71676
68279
  throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
71677
68280
  }
71678
- const path2 = ref.slice(1).split("/").filter(Boolean);
71679
- if (path2.length === 0) {
68281
+ const path3 = ref.slice(1).split("/").filter(Boolean);
68282
+ if (path3.length === 0) {
71680
68283
  return ctx.rootSchema;
71681
68284
  }
71682
68285
  const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
71683
- if (path2[0] === defsKey) {
71684
- const key = path2[1];
68286
+ if (path3[0] === defsKey) {
68287
+ const key = path3[1];
71685
68288
  if (!key || !ctx.defs[key]) {
71686
68289
  throw new Error(`Reference not found: ${ref}`);
71687
68290
  }
@@ -72078,23 +68681,23 @@ function date42(params) {
72078
68681
  return _coercedDate3(ZodDate3, params);
72079
68682
  }
72080
68683
  config4(en_default3());
72081
- var POOL_SIZE_MULTIPLIER3 = 128;
72082
- var pool3;
72083
- var poolOffset3;
72084
- function fillPool3(bytes) {
72085
- if (!pool3 || pool3.length < bytes) {
72086
- pool3 = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER3);
72087
- crypto4.getRandomValues(pool3);
72088
- poolOffset3 = 0;
72089
- } else if (poolOffset3 + bytes > pool3.length) {
72090
- crypto4.getRandomValues(pool3);
72091
- poolOffset3 = 0;
72092
- }
72093
- poolOffset3 += bytes;
68684
+ var POOL_SIZE_MULTIPLIER2 = 128;
68685
+ var pool2;
68686
+ var poolOffset2;
68687
+ function fillPool2(bytes) {
68688
+ if (!pool2 || pool2.length < bytes) {
68689
+ pool2 = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER2);
68690
+ crypto3.getRandomValues(pool2);
68691
+ poolOffset2 = 0;
68692
+ } else if (poolOffset2 + bytes > pool2.length) {
68693
+ crypto3.getRandomValues(pool2);
68694
+ poolOffset2 = 0;
68695
+ }
68696
+ poolOffset2 += bytes;
72094
68697
  }
72095
68698
  function random2(bytes) {
72096
- fillPool3(bytes |= 0);
72097
- return pool3.subarray(poolOffset3 - bytes, poolOffset3);
68699
+ fillPool2(bytes |= 0);
68700
+ return pool2.subarray(poolOffset2 - bytes, poolOffset2);
72098
68701
  }
72099
68702
  function customRandom2(alphabet, defaultSize, getRandom) {
72100
68703
  let mask = (2 << 31 - Math.clz32(alphabet.length - 1 | 1)) - 1;
@@ -72121,7 +68724,7 @@ var nanoid32 = customAlphabet2("abcdefghijklmnopqrstuvwxyz", 16);
72121
68724
  var tool4 = {
72122
68725
  schema: exports_external3
72123
68726
  };
72124
- var createSkill3 = (skill) => {
68727
+ var createSkill2 = (skill) => {
72125
68728
  if (skill.tags) {
72126
68729
  const hasOpencode = skill.tags.includes("opencode");
72127
68730
  if (!hasOpencode) {
@@ -72376,8 +68979,8 @@ class Parser {
72376
68979
  }
72377
68980
 
72378
68981
  class Executor {
72379
- getValueByPath(obj, path2) {
72380
- return path2.split(".").reduce((acc, part) => acc?.[part], obj);
68982
+ getValueByPath(obj, path3) {
68983
+ return path3.split(".").reduce((acc, part) => acc?.[part], obj);
72381
68984
  }
72382
68985
  likeToRegex(pattern) {
72383
68986
  let regex = "";
@@ -72483,7 +69086,7 @@ var addCallFn = (app3) => {
72483
69086
  middleware: ["auth-admin"],
72484
69087
  metadata: {
72485
69088
  tags: ["opencode"],
72486
- ...createSkill3({
69089
+ ...createSkill2({
72487
69090
  skill: "call-app",
72488
69091
  title: "调用app应用,非技能模块",
72489
69092
  summary: `调用router的应用(非技能模块),适用于需要直接调用应用而不是技能的场景
@@ -72499,11 +69102,11 @@ var addCallFn = (app3) => {
72499
69102
  })
72500
69103
  }
72501
69104
  }).define(async (ctx) => {
72502
- const { path: path2, key = "" } = ctx.query;
72503
- if (!path2) {
69105
+ const { path: path3, key = "" } = ctx.query;
69106
+ if (!path3) {
72504
69107
  ctx.throw("路径path不能为空");
72505
69108
  }
72506
- const res = await ctx.run({ path: path2, key, payload: ctx.query.payload || {} }, {
69109
+ const res = await ctx.run({ path: path3, key, payload: ctx.query.payload || {} }, {
72507
69110
  ...ctx
72508
69111
  });
72509
69112
  ctx.forward(res);