@kevisual/cnb 0.0.12 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agent/routes/call/index.ts +30 -28
- package/agent/routes/cnb-env/check.ts +1 -1
- package/agent/routes/cnb-env/env.ts +2 -2
- package/agent/routes/cnb-env/vscode.ts +2 -2
- package/agent/routes/issues/issue.ts +2 -2
- package/agent/routes/issues/list.ts +1 -1
- package/agent/routes/knowledge/ai.ts +2 -2
- package/agent/routes/repo/list.ts +1 -1
- package/agent/routes/repo/repo.ts +3 -3
- package/agent/routes/workspace/index.ts +5 -5
- package/agent/routes/workspace/keep.ts +121 -28
- package/agent/routes/workspace/skills.ts +1 -1
- package/dist/keep.js +2850 -4
- package/dist/opencode.js +3562 -212
- package/dist/routes.d.ts +11 -2
- package/dist/routes.js +3558 -208
- package/package.json +8 -6
- package/src/cnb-core.ts +8 -0
- package/src/git/index.ts +676 -0
- package/src/repo/index.ts +2 -2
- package/src/user/index.ts +4 -4
package/dist/routes.js
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
1
4
|
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
8
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
+
for (let key of __getOwnPropNames(mod))
|
|
11
|
+
if (!__hasOwnProp.call(to, key))
|
|
12
|
+
__defProp(to, key, {
|
|
13
|
+
get: () => mod[key],
|
|
14
|
+
enumerable: true
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
2
19
|
var __export = (target, all) => {
|
|
3
20
|
for (var name in all)
|
|
4
21
|
__defProp(target, name, {
|
|
@@ -7,9 +24,3121 @@ var __export = (target, all) => {
|
|
|
7
24
|
configurable: true,
|
|
8
25
|
set: (newValue) => all[name] = () => newValue
|
|
9
26
|
});
|
|
10
|
-
};
|
|
27
|
+
};
|
|
28
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
29
|
+
|
|
30
|
+
// node_modules/.pnpm/dayjs@1.11.19/node_modules/dayjs/dayjs.min.js
|
|
31
|
+
var require_dayjs_min = __commonJS((exports, module) => {
|
|
32
|
+
(function(t, e) {
|
|
33
|
+
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();
|
|
34
|
+
})(exports, function() {
|
|
35
|
+
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) {
|
|
36
|
+
var e2 = ["th", "st", "nd", "rd"], n2 = t2 % 100;
|
|
37
|
+
return "[" + t2 + (e2[(n2 - 20) % 10] || e2[n2] || e2[0]) + "]";
|
|
38
|
+
} }, m = function(t2, e2, n2) {
|
|
39
|
+
var r2 = String(t2);
|
|
40
|
+
return !r2 || r2.length >= e2 ? t2 : "" + Array(e2 + 1 - r2.length).join(n2) + t2;
|
|
41
|
+
}, v = { s: m, z: function(t2) {
|
|
42
|
+
var e2 = -t2.utcOffset(), n2 = Math.abs(e2), r2 = Math.floor(n2 / 60), i2 = n2 % 60;
|
|
43
|
+
return (e2 <= 0 ? "+" : "-") + m(r2, 2, "0") + ":" + m(i2, 2, "0");
|
|
44
|
+
}, m: function t2(e2, n2) {
|
|
45
|
+
if (e2.date() < n2.date())
|
|
46
|
+
return -t2(n2, e2);
|
|
47
|
+
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);
|
|
48
|
+
return +(-(r2 + (n2 - i2) / (s2 ? i2 - u2 : u2 - i2)) || 0);
|
|
49
|
+
}, a: function(t2) {
|
|
50
|
+
return t2 < 0 ? Math.ceil(t2) || 0 : Math.floor(t2);
|
|
51
|
+
}, p: function(t2) {
|
|
52
|
+
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$/, "");
|
|
53
|
+
}, u: function(t2) {
|
|
54
|
+
return t2 === undefined;
|
|
55
|
+
} }, g = "en", D = {};
|
|
56
|
+
D[g] = M;
|
|
57
|
+
var p = "$isDayjsObject", S = function(t2) {
|
|
58
|
+
return t2 instanceof _ || !(!t2 || !t2[p]);
|
|
59
|
+
}, w = function t2(e2, n2, r2) {
|
|
60
|
+
var i2;
|
|
61
|
+
if (!e2)
|
|
62
|
+
return g;
|
|
63
|
+
if (typeof e2 == "string") {
|
|
64
|
+
var s2 = e2.toLowerCase();
|
|
65
|
+
D[s2] && (i2 = s2), n2 && (D[s2] = n2, i2 = s2);
|
|
66
|
+
var u2 = e2.split("-");
|
|
67
|
+
if (!i2 && u2.length > 1)
|
|
68
|
+
return t2(u2[0]);
|
|
69
|
+
} else {
|
|
70
|
+
var a2 = e2.name;
|
|
71
|
+
D[a2] = e2, i2 = a2;
|
|
72
|
+
}
|
|
73
|
+
return !r2 && i2 && (g = i2), i2 || !r2 && g;
|
|
74
|
+
}, O = function(t2, e2) {
|
|
75
|
+
if (S(t2))
|
|
76
|
+
return t2.clone();
|
|
77
|
+
var n2 = typeof e2 == "object" ? e2 : {};
|
|
78
|
+
return n2.date = t2, n2.args = arguments, new _(n2);
|
|
79
|
+
}, b = v;
|
|
80
|
+
b.l = w, b.i = S, b.w = function(t2, e2) {
|
|
81
|
+
return O(t2, { locale: e2.$L, utc: e2.$u, x: e2.$x, $offset: e2.$offset });
|
|
82
|
+
};
|
|
83
|
+
var _ = function() {
|
|
84
|
+
function M2(t2) {
|
|
85
|
+
this.$L = w(t2.locale, null, true), this.parse(t2), this.$x = this.$x || t2.x || {}, this[p] = true;
|
|
86
|
+
}
|
|
87
|
+
var m2 = M2.prototype;
|
|
88
|
+
return m2.parse = function(t2) {
|
|
89
|
+
this.$d = function(t3) {
|
|
90
|
+
var { date: e2, utc: n2 } = t3;
|
|
91
|
+
if (e2 === null)
|
|
92
|
+
return new Date(NaN);
|
|
93
|
+
if (b.u(e2))
|
|
94
|
+
return new Date;
|
|
95
|
+
if (e2 instanceof Date)
|
|
96
|
+
return new Date(e2);
|
|
97
|
+
if (typeof e2 == "string" && !/Z$/i.test(e2)) {
|
|
98
|
+
var r2 = e2.match($);
|
|
99
|
+
if (r2) {
|
|
100
|
+
var i2 = r2[2] - 1 || 0, s2 = (r2[7] || "0").substring(0, 3);
|
|
101
|
+
return n2 ? new Date(Date.UTC(r2[1], i2, r2[3] || 1, r2[4] || 0, r2[5] || 0, r2[6] || 0, s2)) : new Date(r2[1], i2, r2[3] || 1, r2[4] || 0, r2[5] || 0, r2[6] || 0, s2);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return new Date(e2);
|
|
105
|
+
}(t2), this.init();
|
|
106
|
+
}, m2.init = function() {
|
|
107
|
+
var t2 = this.$d;
|
|
108
|
+
this.$y = t2.getFullYear(), this.$M = t2.getMonth(), this.$D = t2.getDate(), this.$W = t2.getDay(), this.$H = t2.getHours(), this.$m = t2.getMinutes(), this.$s = t2.getSeconds(), this.$ms = t2.getMilliseconds();
|
|
109
|
+
}, m2.$utils = function() {
|
|
110
|
+
return b;
|
|
111
|
+
}, m2.isValid = function() {
|
|
112
|
+
return !(this.$d.toString() === l);
|
|
113
|
+
}, m2.isSame = function(t2, e2) {
|
|
114
|
+
var n2 = O(t2);
|
|
115
|
+
return this.startOf(e2) <= n2 && n2 <= this.endOf(e2);
|
|
116
|
+
}, m2.isAfter = function(t2, e2) {
|
|
117
|
+
return O(t2) < this.startOf(e2);
|
|
118
|
+
}, m2.isBefore = function(t2, e2) {
|
|
119
|
+
return this.endOf(e2) < O(t2);
|
|
120
|
+
}, m2.$g = function(t2, e2, n2) {
|
|
121
|
+
return b.u(t2) ? this[e2] : this.set(n2, t2);
|
|
122
|
+
}, m2.unix = function() {
|
|
123
|
+
return Math.floor(this.valueOf() / 1000);
|
|
124
|
+
}, m2.valueOf = function() {
|
|
125
|
+
return this.$d.getTime();
|
|
126
|
+
}, m2.startOf = function(t2, e2) {
|
|
127
|
+
var n2 = this, r2 = !!b.u(e2) || e2, f2 = b.p(t2), l2 = function(t3, e3) {
|
|
128
|
+
var i2 = b.w(n2.$u ? Date.UTC(n2.$y, e3, t3) : new Date(n2.$y, e3, t3), n2);
|
|
129
|
+
return r2 ? i2 : i2.endOf(a);
|
|
130
|
+
}, $2 = function(t3, e3) {
|
|
131
|
+
return b.w(n2.toDate()[t3].apply(n2.toDate("s"), (r2 ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(e3)), n2);
|
|
132
|
+
}, y2 = this.$W, M3 = this.$M, m3 = this.$D, v2 = "set" + (this.$u ? "UTC" : "");
|
|
133
|
+
switch (f2) {
|
|
134
|
+
case h:
|
|
135
|
+
return r2 ? l2(1, 0) : l2(31, 11);
|
|
136
|
+
case c:
|
|
137
|
+
return r2 ? l2(1, M3) : l2(0, M3 + 1);
|
|
138
|
+
case o:
|
|
139
|
+
var g2 = this.$locale().weekStart || 0, D2 = (y2 < g2 ? y2 + 7 : y2) - g2;
|
|
140
|
+
return l2(r2 ? m3 - D2 : m3 + (6 - D2), M3);
|
|
141
|
+
case a:
|
|
142
|
+
case d:
|
|
143
|
+
return $2(v2 + "Hours", 0);
|
|
144
|
+
case u:
|
|
145
|
+
return $2(v2 + "Minutes", 1);
|
|
146
|
+
case s:
|
|
147
|
+
return $2(v2 + "Seconds", 2);
|
|
148
|
+
case i:
|
|
149
|
+
return $2(v2 + "Milliseconds", 3);
|
|
150
|
+
default:
|
|
151
|
+
return this.clone();
|
|
152
|
+
}
|
|
153
|
+
}, m2.endOf = function(t2) {
|
|
154
|
+
return this.startOf(t2, false);
|
|
155
|
+
}, m2.$set = function(t2, e2) {
|
|
156
|
+
var n2, o2 = b.p(t2), f2 = "set" + (this.$u ? "UTC" : ""), l2 = (n2 = {}, n2[a] = f2 + "Date", n2[d] = f2 + "Date", n2[c] = f2 + "Month", n2[h] = f2 + "FullYear", n2[u] = f2 + "Hours", n2[s] = f2 + "Minutes", n2[i] = f2 + "Seconds", n2[r] = f2 + "Milliseconds", n2)[o2], $2 = o2 === a ? this.$D + (e2 - this.$W) : e2;
|
|
157
|
+
if (o2 === c || o2 === h) {
|
|
158
|
+
var y2 = this.clone().set(d, 1);
|
|
159
|
+
y2.$d[l2]($2), y2.init(), this.$d = y2.set(d, Math.min(this.$D, y2.daysInMonth())).$d;
|
|
160
|
+
} else
|
|
161
|
+
l2 && this.$d[l2]($2);
|
|
162
|
+
return this.init(), this;
|
|
163
|
+
}, m2.set = function(t2, e2) {
|
|
164
|
+
return this.clone().$set(t2, e2);
|
|
165
|
+
}, m2.get = function(t2) {
|
|
166
|
+
return this[b.p(t2)]();
|
|
167
|
+
}, m2.add = function(r2, f2) {
|
|
168
|
+
var d2, l2 = this;
|
|
169
|
+
r2 = Number(r2);
|
|
170
|
+
var $2 = b.p(f2), y2 = function(t2) {
|
|
171
|
+
var e2 = O(l2);
|
|
172
|
+
return b.w(e2.date(e2.date() + Math.round(t2 * r2)), l2);
|
|
173
|
+
};
|
|
174
|
+
if ($2 === c)
|
|
175
|
+
return this.set(c, this.$M + r2);
|
|
176
|
+
if ($2 === h)
|
|
177
|
+
return this.set(h, this.$y + r2);
|
|
178
|
+
if ($2 === a)
|
|
179
|
+
return y2(1);
|
|
180
|
+
if ($2 === o)
|
|
181
|
+
return y2(7);
|
|
182
|
+
var M3 = (d2 = {}, d2[s] = e, d2[u] = n, d2[i] = t, d2)[$2] || 1, m3 = this.$d.getTime() + r2 * M3;
|
|
183
|
+
return b.w(m3, this);
|
|
184
|
+
}, m2.subtract = function(t2, e2) {
|
|
185
|
+
return this.add(-1 * t2, e2);
|
|
186
|
+
}, m2.format = function(t2) {
|
|
187
|
+
var e2 = this, n2 = this.$locale();
|
|
188
|
+
if (!this.isValid())
|
|
189
|
+
return n2.invalidDate || l;
|
|
190
|
+
var r2 = t2 || "YYYY-MM-DDTHH:mm:ssZ", i2 = b.z(this), s2 = this.$H, u2 = this.$m, a2 = this.$M, o2 = n2.weekdays, c2 = n2.months, f2 = n2.meridiem, h2 = function(t3, n3, i3, s3) {
|
|
191
|
+
return t3 && (t3[n3] || t3(e2, r2)) || i3[n3].slice(0, s3);
|
|
192
|
+
}, d2 = function(t3) {
|
|
193
|
+
return b.s(s2 % 12 || 12, t3, "0");
|
|
194
|
+
}, $2 = f2 || function(t3, e3, n3) {
|
|
195
|
+
var r3 = t3 < 12 ? "AM" : "PM";
|
|
196
|
+
return n3 ? r3.toLowerCase() : r3;
|
|
197
|
+
};
|
|
198
|
+
return r2.replace(y, function(t3, r3) {
|
|
199
|
+
return r3 || function(t4) {
|
|
200
|
+
switch (t4) {
|
|
201
|
+
case "YY":
|
|
202
|
+
return String(e2.$y).slice(-2);
|
|
203
|
+
case "YYYY":
|
|
204
|
+
return b.s(e2.$y, 4, "0");
|
|
205
|
+
case "M":
|
|
206
|
+
return a2 + 1;
|
|
207
|
+
case "MM":
|
|
208
|
+
return b.s(a2 + 1, 2, "0");
|
|
209
|
+
case "MMM":
|
|
210
|
+
return h2(n2.monthsShort, a2, c2, 3);
|
|
211
|
+
case "MMMM":
|
|
212
|
+
return h2(c2, a2);
|
|
213
|
+
case "D":
|
|
214
|
+
return e2.$D;
|
|
215
|
+
case "DD":
|
|
216
|
+
return b.s(e2.$D, 2, "0");
|
|
217
|
+
case "d":
|
|
218
|
+
return String(e2.$W);
|
|
219
|
+
case "dd":
|
|
220
|
+
return h2(n2.weekdaysMin, e2.$W, o2, 2);
|
|
221
|
+
case "ddd":
|
|
222
|
+
return h2(n2.weekdaysShort, e2.$W, o2, 3);
|
|
223
|
+
case "dddd":
|
|
224
|
+
return o2[e2.$W];
|
|
225
|
+
case "H":
|
|
226
|
+
return String(s2);
|
|
227
|
+
case "HH":
|
|
228
|
+
return b.s(s2, 2, "0");
|
|
229
|
+
case "h":
|
|
230
|
+
return d2(1);
|
|
231
|
+
case "hh":
|
|
232
|
+
return d2(2);
|
|
233
|
+
case "a":
|
|
234
|
+
return $2(s2, u2, true);
|
|
235
|
+
case "A":
|
|
236
|
+
return $2(s2, u2, false);
|
|
237
|
+
case "m":
|
|
238
|
+
return String(u2);
|
|
239
|
+
case "mm":
|
|
240
|
+
return b.s(u2, 2, "0");
|
|
241
|
+
case "s":
|
|
242
|
+
return String(e2.$s);
|
|
243
|
+
case "ss":
|
|
244
|
+
return b.s(e2.$s, 2, "0");
|
|
245
|
+
case "SSS":
|
|
246
|
+
return b.s(e2.$ms, 3, "0");
|
|
247
|
+
case "Z":
|
|
248
|
+
return i2;
|
|
249
|
+
}
|
|
250
|
+
return null;
|
|
251
|
+
}(t3) || i2.replace(":", "");
|
|
252
|
+
});
|
|
253
|
+
}, m2.utcOffset = function() {
|
|
254
|
+
return 15 * -Math.round(this.$d.getTimezoneOffset() / 15);
|
|
255
|
+
}, m2.diff = function(r2, d2, l2) {
|
|
256
|
+
var $2, y2 = this, M3 = b.p(d2), m3 = O(r2), v2 = (m3.utcOffset() - this.utcOffset()) * e, g2 = this - m3, D2 = function() {
|
|
257
|
+
return b.m(y2, m3);
|
|
258
|
+
};
|
|
259
|
+
switch (M3) {
|
|
260
|
+
case h:
|
|
261
|
+
$2 = D2() / 12;
|
|
262
|
+
break;
|
|
263
|
+
case c:
|
|
264
|
+
$2 = D2();
|
|
265
|
+
break;
|
|
266
|
+
case f:
|
|
267
|
+
$2 = D2() / 3;
|
|
268
|
+
break;
|
|
269
|
+
case o:
|
|
270
|
+
$2 = (g2 - v2) / 604800000;
|
|
271
|
+
break;
|
|
272
|
+
case a:
|
|
273
|
+
$2 = (g2 - v2) / 86400000;
|
|
274
|
+
break;
|
|
275
|
+
case u:
|
|
276
|
+
$2 = g2 / n;
|
|
277
|
+
break;
|
|
278
|
+
case s:
|
|
279
|
+
$2 = g2 / e;
|
|
280
|
+
break;
|
|
281
|
+
case i:
|
|
282
|
+
$2 = g2 / t;
|
|
283
|
+
break;
|
|
284
|
+
default:
|
|
285
|
+
$2 = g2;
|
|
286
|
+
}
|
|
287
|
+
return l2 ? $2 : b.a($2);
|
|
288
|
+
}, m2.daysInMonth = function() {
|
|
289
|
+
return this.endOf(c).$D;
|
|
290
|
+
}, m2.$locale = function() {
|
|
291
|
+
return D[this.$L];
|
|
292
|
+
}, m2.locale = function(t2, e2) {
|
|
293
|
+
if (!t2)
|
|
294
|
+
return this.$L;
|
|
295
|
+
var n2 = this.clone(), r2 = w(t2, e2, true);
|
|
296
|
+
return r2 && (n2.$L = r2), n2;
|
|
297
|
+
}, m2.clone = function() {
|
|
298
|
+
return b.w(this.$d, this);
|
|
299
|
+
}, m2.toDate = function() {
|
|
300
|
+
return new Date(this.valueOf());
|
|
301
|
+
}, m2.toJSON = function() {
|
|
302
|
+
return this.isValid() ? this.toISOString() : null;
|
|
303
|
+
}, m2.toISOString = function() {
|
|
304
|
+
return this.$d.toISOString();
|
|
305
|
+
}, m2.toString = function() {
|
|
306
|
+
return this.$d.toUTCString();
|
|
307
|
+
}, M2;
|
|
308
|
+
}(), k = _.prototype;
|
|
309
|
+
return O.prototype = k, [["$ms", r], ["$s", i], ["$m", s], ["$H", u], ["$W", a], ["$M", c], ["$y", h], ["$D", d]].forEach(function(t2) {
|
|
310
|
+
k[t2[1]] = function(e2) {
|
|
311
|
+
return this.$g(e2, t2[0], t2[1]);
|
|
312
|
+
};
|
|
313
|
+
}), O.extend = function(t2, e2) {
|
|
314
|
+
return t2.$i || (t2(e2, _, O), t2.$i = true), O;
|
|
315
|
+
}, O.locale = w, O.isDayjs = S, O.unix = function(t2) {
|
|
316
|
+
return O(1000 * t2);
|
|
317
|
+
}, O.en = D[g], O.Ls = D, O.p = {}, O;
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
// node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/constants.js
|
|
322
|
+
var require_constants = __commonJS((exports, module) => {
|
|
323
|
+
var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
|
|
324
|
+
var hasBlob = typeof Blob !== "undefined";
|
|
325
|
+
if (hasBlob)
|
|
326
|
+
BINARY_TYPES.push("blob");
|
|
327
|
+
module.exports = {
|
|
328
|
+
BINARY_TYPES,
|
|
329
|
+
CLOSE_TIMEOUT: 30000,
|
|
330
|
+
EMPTY_BUFFER: Buffer.alloc(0),
|
|
331
|
+
GUID: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
|
|
332
|
+
hasBlob,
|
|
333
|
+
kForOnEventAttribute: Symbol("kIsForOnEventAttribute"),
|
|
334
|
+
kListener: Symbol("kListener"),
|
|
335
|
+
kStatusCode: Symbol("status-code"),
|
|
336
|
+
kWebSocket: Symbol("websocket"),
|
|
337
|
+
NOOP: () => {}
|
|
338
|
+
};
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
// node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/buffer-util.js
|
|
342
|
+
var require_buffer_util = __commonJS((exports, module) => {
|
|
343
|
+
var { EMPTY_BUFFER } = require_constants();
|
|
344
|
+
var FastBuffer = Buffer[Symbol.species];
|
|
345
|
+
function concat(list, totalLength) {
|
|
346
|
+
if (list.length === 0)
|
|
347
|
+
return EMPTY_BUFFER;
|
|
348
|
+
if (list.length === 1)
|
|
349
|
+
return list[0];
|
|
350
|
+
const target = Buffer.allocUnsafe(totalLength);
|
|
351
|
+
let offset = 0;
|
|
352
|
+
for (let i = 0;i < list.length; i++) {
|
|
353
|
+
const buf = list[i];
|
|
354
|
+
target.set(buf, offset);
|
|
355
|
+
offset += buf.length;
|
|
356
|
+
}
|
|
357
|
+
if (offset < totalLength) {
|
|
358
|
+
return new FastBuffer(target.buffer, target.byteOffset, offset);
|
|
359
|
+
}
|
|
360
|
+
return target;
|
|
361
|
+
}
|
|
362
|
+
function _mask(source, mask, output, offset, length) {
|
|
363
|
+
for (let i = 0;i < length; i++) {
|
|
364
|
+
output[offset + i] = source[i] ^ mask[i & 3];
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
function _unmask(buffer, mask) {
|
|
368
|
+
for (let i = 0;i < buffer.length; i++) {
|
|
369
|
+
buffer[i] ^= mask[i & 3];
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
function toArrayBuffer(buf) {
|
|
373
|
+
if (buf.length === buf.buffer.byteLength) {
|
|
374
|
+
return buf.buffer;
|
|
375
|
+
}
|
|
376
|
+
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
|
|
377
|
+
}
|
|
378
|
+
function toBuffer(data) {
|
|
379
|
+
toBuffer.readOnly = true;
|
|
380
|
+
if (Buffer.isBuffer(data))
|
|
381
|
+
return data;
|
|
382
|
+
let buf;
|
|
383
|
+
if (data instanceof ArrayBuffer) {
|
|
384
|
+
buf = new FastBuffer(data);
|
|
385
|
+
} else if (ArrayBuffer.isView(data)) {
|
|
386
|
+
buf = new FastBuffer(data.buffer, data.byteOffset, data.byteLength);
|
|
387
|
+
} else {
|
|
388
|
+
buf = Buffer.from(data);
|
|
389
|
+
toBuffer.readOnly = false;
|
|
390
|
+
}
|
|
391
|
+
return buf;
|
|
392
|
+
}
|
|
393
|
+
module.exports = {
|
|
394
|
+
concat,
|
|
395
|
+
mask: _mask,
|
|
396
|
+
toArrayBuffer,
|
|
397
|
+
toBuffer,
|
|
398
|
+
unmask: _unmask
|
|
399
|
+
};
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
// node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/limiter.js
|
|
403
|
+
var require_limiter = __commonJS((exports, module) => {
|
|
404
|
+
var kDone = Symbol("kDone");
|
|
405
|
+
var kRun = Symbol("kRun");
|
|
406
|
+
|
|
407
|
+
class Limiter {
|
|
408
|
+
constructor(concurrency) {
|
|
409
|
+
this[kDone] = () => {
|
|
410
|
+
this.pending--;
|
|
411
|
+
this[kRun]();
|
|
412
|
+
};
|
|
413
|
+
this.concurrency = concurrency || Infinity;
|
|
414
|
+
this.jobs = [];
|
|
415
|
+
this.pending = 0;
|
|
416
|
+
}
|
|
417
|
+
add(job) {
|
|
418
|
+
this.jobs.push(job);
|
|
419
|
+
this[kRun]();
|
|
420
|
+
}
|
|
421
|
+
[kRun]() {
|
|
422
|
+
if (this.pending === this.concurrency)
|
|
423
|
+
return;
|
|
424
|
+
if (this.jobs.length) {
|
|
425
|
+
const job = this.jobs.shift();
|
|
426
|
+
this.pending++;
|
|
427
|
+
job(this[kDone]);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
module.exports = Limiter;
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
// node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/permessage-deflate.js
|
|
435
|
+
var require_permessage_deflate = __commonJS((exports, module) => {
|
|
436
|
+
var zlib = __require("zlib");
|
|
437
|
+
var bufferUtil2 = require_buffer_util();
|
|
438
|
+
var Limiter = require_limiter();
|
|
439
|
+
var { kStatusCode } = require_constants();
|
|
440
|
+
var FastBuffer = Buffer[Symbol.species];
|
|
441
|
+
var TRAILER = Buffer.from([0, 0, 255, 255]);
|
|
442
|
+
var kPerMessageDeflate = Symbol("permessage-deflate");
|
|
443
|
+
var kTotalLength = Symbol("total-length");
|
|
444
|
+
var kCallback = Symbol("callback");
|
|
445
|
+
var kBuffers = Symbol("buffers");
|
|
446
|
+
var kError = Symbol("error");
|
|
447
|
+
var zlibLimiter;
|
|
448
|
+
|
|
449
|
+
class PerMessageDeflate {
|
|
450
|
+
constructor(options, isServer, maxPayload) {
|
|
451
|
+
this._maxPayload = maxPayload | 0;
|
|
452
|
+
this._options = options || {};
|
|
453
|
+
this._threshold = this._options.threshold !== undefined ? this._options.threshold : 1024;
|
|
454
|
+
this._isServer = !!isServer;
|
|
455
|
+
this._deflate = null;
|
|
456
|
+
this._inflate = null;
|
|
457
|
+
this.params = null;
|
|
458
|
+
if (!zlibLimiter) {
|
|
459
|
+
const concurrency = this._options.concurrencyLimit !== undefined ? this._options.concurrencyLimit : 10;
|
|
460
|
+
zlibLimiter = new Limiter(concurrency);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
static get extensionName() {
|
|
464
|
+
return "permessage-deflate";
|
|
465
|
+
}
|
|
466
|
+
offer() {
|
|
467
|
+
const params = {};
|
|
468
|
+
if (this._options.serverNoContextTakeover) {
|
|
469
|
+
params.server_no_context_takeover = true;
|
|
470
|
+
}
|
|
471
|
+
if (this._options.clientNoContextTakeover) {
|
|
472
|
+
params.client_no_context_takeover = true;
|
|
473
|
+
}
|
|
474
|
+
if (this._options.serverMaxWindowBits) {
|
|
475
|
+
params.server_max_window_bits = this._options.serverMaxWindowBits;
|
|
476
|
+
}
|
|
477
|
+
if (this._options.clientMaxWindowBits) {
|
|
478
|
+
params.client_max_window_bits = this._options.clientMaxWindowBits;
|
|
479
|
+
} else if (this._options.clientMaxWindowBits == null) {
|
|
480
|
+
params.client_max_window_bits = true;
|
|
481
|
+
}
|
|
482
|
+
return params;
|
|
483
|
+
}
|
|
484
|
+
accept(configurations) {
|
|
485
|
+
configurations = this.normalizeParams(configurations);
|
|
486
|
+
this.params = this._isServer ? this.acceptAsServer(configurations) : this.acceptAsClient(configurations);
|
|
487
|
+
return this.params;
|
|
488
|
+
}
|
|
489
|
+
cleanup() {
|
|
490
|
+
if (this._inflate) {
|
|
491
|
+
this._inflate.close();
|
|
492
|
+
this._inflate = null;
|
|
493
|
+
}
|
|
494
|
+
if (this._deflate) {
|
|
495
|
+
const callback = this._deflate[kCallback];
|
|
496
|
+
this._deflate.close();
|
|
497
|
+
this._deflate = null;
|
|
498
|
+
if (callback) {
|
|
499
|
+
callback(new Error("The deflate stream was closed while data was being processed"));
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
acceptAsServer(offers) {
|
|
504
|
+
const opts = this._options;
|
|
505
|
+
const accepted = offers.find((params) => {
|
|
506
|
+
if (opts.serverNoContextTakeover === false && params.server_no_context_takeover || params.server_max_window_bits && (opts.serverMaxWindowBits === false || typeof opts.serverMaxWindowBits === "number" && opts.serverMaxWindowBits > params.server_max_window_bits) || typeof opts.clientMaxWindowBits === "number" && !params.client_max_window_bits) {
|
|
507
|
+
return false;
|
|
508
|
+
}
|
|
509
|
+
return true;
|
|
510
|
+
});
|
|
511
|
+
if (!accepted) {
|
|
512
|
+
throw new Error("None of the extension offers can be accepted");
|
|
513
|
+
}
|
|
514
|
+
if (opts.serverNoContextTakeover) {
|
|
515
|
+
accepted.server_no_context_takeover = true;
|
|
516
|
+
}
|
|
517
|
+
if (opts.clientNoContextTakeover) {
|
|
518
|
+
accepted.client_no_context_takeover = true;
|
|
519
|
+
}
|
|
520
|
+
if (typeof opts.serverMaxWindowBits === "number") {
|
|
521
|
+
accepted.server_max_window_bits = opts.serverMaxWindowBits;
|
|
522
|
+
}
|
|
523
|
+
if (typeof opts.clientMaxWindowBits === "number") {
|
|
524
|
+
accepted.client_max_window_bits = opts.clientMaxWindowBits;
|
|
525
|
+
} else if (accepted.client_max_window_bits === true || opts.clientMaxWindowBits === false) {
|
|
526
|
+
delete accepted.client_max_window_bits;
|
|
527
|
+
}
|
|
528
|
+
return accepted;
|
|
529
|
+
}
|
|
530
|
+
acceptAsClient(response) {
|
|
531
|
+
const params = response[0];
|
|
532
|
+
if (this._options.clientNoContextTakeover === false && params.client_no_context_takeover) {
|
|
533
|
+
throw new Error('Unexpected parameter "client_no_context_takeover"');
|
|
534
|
+
}
|
|
535
|
+
if (!params.client_max_window_bits) {
|
|
536
|
+
if (typeof this._options.clientMaxWindowBits === "number") {
|
|
537
|
+
params.client_max_window_bits = this._options.clientMaxWindowBits;
|
|
538
|
+
}
|
|
539
|
+
} else if (this._options.clientMaxWindowBits === false || typeof this._options.clientMaxWindowBits === "number" && params.client_max_window_bits > this._options.clientMaxWindowBits) {
|
|
540
|
+
throw new Error('Unexpected or invalid parameter "client_max_window_bits"');
|
|
541
|
+
}
|
|
542
|
+
return params;
|
|
543
|
+
}
|
|
544
|
+
normalizeParams(configurations) {
|
|
545
|
+
configurations.forEach((params) => {
|
|
546
|
+
Object.keys(params).forEach((key) => {
|
|
547
|
+
let value = params[key];
|
|
548
|
+
if (value.length > 1) {
|
|
549
|
+
throw new Error(`Parameter "${key}" must have only a single value`);
|
|
550
|
+
}
|
|
551
|
+
value = value[0];
|
|
552
|
+
if (key === "client_max_window_bits") {
|
|
553
|
+
if (value !== true) {
|
|
554
|
+
const num = +value;
|
|
555
|
+
if (!Number.isInteger(num) || num < 8 || num > 15) {
|
|
556
|
+
throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
557
|
+
}
|
|
558
|
+
value = num;
|
|
559
|
+
} else if (!this._isServer) {
|
|
560
|
+
throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
561
|
+
}
|
|
562
|
+
} else if (key === "server_max_window_bits") {
|
|
563
|
+
const num = +value;
|
|
564
|
+
if (!Number.isInteger(num) || num < 8 || num > 15) {
|
|
565
|
+
throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
566
|
+
}
|
|
567
|
+
value = num;
|
|
568
|
+
} else if (key === "client_no_context_takeover" || key === "server_no_context_takeover") {
|
|
569
|
+
if (value !== true) {
|
|
570
|
+
throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
571
|
+
}
|
|
572
|
+
} else {
|
|
573
|
+
throw new Error(`Unknown parameter "${key}"`);
|
|
574
|
+
}
|
|
575
|
+
params[key] = value;
|
|
576
|
+
});
|
|
577
|
+
});
|
|
578
|
+
return configurations;
|
|
579
|
+
}
|
|
580
|
+
decompress(data, fin, callback) {
|
|
581
|
+
zlibLimiter.add((done) => {
|
|
582
|
+
this._decompress(data, fin, (err, result) => {
|
|
583
|
+
done();
|
|
584
|
+
callback(err, result);
|
|
585
|
+
});
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
compress(data, fin, callback) {
|
|
589
|
+
zlibLimiter.add((done) => {
|
|
590
|
+
this._compress(data, fin, (err, result) => {
|
|
591
|
+
done();
|
|
592
|
+
callback(err, result);
|
|
593
|
+
});
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
_decompress(data, fin, callback) {
|
|
597
|
+
const endpoint = this._isServer ? "client" : "server";
|
|
598
|
+
if (!this._inflate) {
|
|
599
|
+
const key = `${endpoint}_max_window_bits`;
|
|
600
|
+
const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
|
|
601
|
+
this._inflate = zlib.createInflateRaw({
|
|
602
|
+
...this._options.zlibInflateOptions,
|
|
603
|
+
windowBits
|
|
604
|
+
});
|
|
605
|
+
this._inflate[kPerMessageDeflate] = this;
|
|
606
|
+
this._inflate[kTotalLength] = 0;
|
|
607
|
+
this._inflate[kBuffers] = [];
|
|
608
|
+
this._inflate.on("error", inflateOnError);
|
|
609
|
+
this._inflate.on("data", inflateOnData);
|
|
610
|
+
}
|
|
611
|
+
this._inflate[kCallback] = callback;
|
|
612
|
+
this._inflate.write(data);
|
|
613
|
+
if (fin)
|
|
614
|
+
this._inflate.write(TRAILER);
|
|
615
|
+
this._inflate.flush(() => {
|
|
616
|
+
const err = this._inflate[kError];
|
|
617
|
+
if (err) {
|
|
618
|
+
this._inflate.close();
|
|
619
|
+
this._inflate = null;
|
|
620
|
+
callback(err);
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
const data2 = bufferUtil2.concat(this._inflate[kBuffers], this._inflate[kTotalLength]);
|
|
624
|
+
if (this._inflate._readableState.endEmitted) {
|
|
625
|
+
this._inflate.close();
|
|
626
|
+
this._inflate = null;
|
|
627
|
+
} else {
|
|
628
|
+
this._inflate[kTotalLength] = 0;
|
|
629
|
+
this._inflate[kBuffers] = [];
|
|
630
|
+
if (fin && this.params[`${endpoint}_no_context_takeover`]) {
|
|
631
|
+
this._inflate.reset();
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
callback(null, data2);
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
_compress(data, fin, callback) {
|
|
638
|
+
const endpoint = this._isServer ? "server" : "client";
|
|
639
|
+
if (!this._deflate) {
|
|
640
|
+
const key = `${endpoint}_max_window_bits`;
|
|
641
|
+
const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
|
|
642
|
+
this._deflate = zlib.createDeflateRaw({
|
|
643
|
+
...this._options.zlibDeflateOptions,
|
|
644
|
+
windowBits
|
|
645
|
+
});
|
|
646
|
+
this._deflate[kTotalLength] = 0;
|
|
647
|
+
this._deflate[kBuffers] = [];
|
|
648
|
+
this._deflate.on("data", deflateOnData);
|
|
649
|
+
}
|
|
650
|
+
this._deflate[kCallback] = callback;
|
|
651
|
+
this._deflate.write(data);
|
|
652
|
+
this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
|
|
653
|
+
if (!this._deflate) {
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
656
|
+
let data2 = bufferUtil2.concat(this._deflate[kBuffers], this._deflate[kTotalLength]);
|
|
657
|
+
if (fin) {
|
|
658
|
+
data2 = new FastBuffer(data2.buffer, data2.byteOffset, data2.length - 4);
|
|
659
|
+
}
|
|
660
|
+
this._deflate[kCallback] = null;
|
|
661
|
+
this._deflate[kTotalLength] = 0;
|
|
662
|
+
this._deflate[kBuffers] = [];
|
|
663
|
+
if (fin && this.params[`${endpoint}_no_context_takeover`]) {
|
|
664
|
+
this._deflate.reset();
|
|
665
|
+
}
|
|
666
|
+
callback(null, data2);
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
module.exports = PerMessageDeflate;
|
|
671
|
+
function deflateOnData(chunk) {
|
|
672
|
+
this[kBuffers].push(chunk);
|
|
673
|
+
this[kTotalLength] += chunk.length;
|
|
674
|
+
}
|
|
675
|
+
function inflateOnData(chunk) {
|
|
676
|
+
this[kTotalLength] += chunk.length;
|
|
677
|
+
if (this[kPerMessageDeflate]._maxPayload < 1 || this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload) {
|
|
678
|
+
this[kBuffers].push(chunk);
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
this[kError] = new RangeError("Max payload size exceeded");
|
|
682
|
+
this[kError].code = "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH";
|
|
683
|
+
this[kError][kStatusCode] = 1009;
|
|
684
|
+
this.removeListener("data", inflateOnData);
|
|
685
|
+
this.reset();
|
|
686
|
+
}
|
|
687
|
+
function inflateOnError(err) {
|
|
688
|
+
this[kPerMessageDeflate]._inflate = null;
|
|
689
|
+
if (this[kError]) {
|
|
690
|
+
this[kCallback](this[kError]);
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
err[kStatusCode] = 1007;
|
|
694
|
+
this[kCallback](err);
|
|
695
|
+
}
|
|
696
|
+
});
|
|
697
|
+
|
|
698
|
+
// node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/validation.js
|
|
699
|
+
var require_validation = __commonJS((exports, module) => {
|
|
700
|
+
var { isUtf8 } = __require("buffer");
|
|
701
|
+
var { hasBlob } = require_constants();
|
|
702
|
+
var tokenChars = [
|
|
703
|
+
0,
|
|
704
|
+
0,
|
|
705
|
+
0,
|
|
706
|
+
0,
|
|
707
|
+
0,
|
|
708
|
+
0,
|
|
709
|
+
0,
|
|
710
|
+
0,
|
|
711
|
+
0,
|
|
712
|
+
0,
|
|
713
|
+
0,
|
|
714
|
+
0,
|
|
715
|
+
0,
|
|
716
|
+
0,
|
|
717
|
+
0,
|
|
718
|
+
0,
|
|
719
|
+
0,
|
|
720
|
+
0,
|
|
721
|
+
0,
|
|
722
|
+
0,
|
|
723
|
+
0,
|
|
724
|
+
0,
|
|
725
|
+
0,
|
|
726
|
+
0,
|
|
727
|
+
0,
|
|
728
|
+
0,
|
|
729
|
+
0,
|
|
730
|
+
0,
|
|
731
|
+
0,
|
|
732
|
+
0,
|
|
733
|
+
0,
|
|
734
|
+
0,
|
|
735
|
+
0,
|
|
736
|
+
1,
|
|
737
|
+
0,
|
|
738
|
+
1,
|
|
739
|
+
1,
|
|
740
|
+
1,
|
|
741
|
+
1,
|
|
742
|
+
1,
|
|
743
|
+
0,
|
|
744
|
+
0,
|
|
745
|
+
1,
|
|
746
|
+
1,
|
|
747
|
+
0,
|
|
748
|
+
1,
|
|
749
|
+
1,
|
|
750
|
+
0,
|
|
751
|
+
1,
|
|
752
|
+
1,
|
|
753
|
+
1,
|
|
754
|
+
1,
|
|
755
|
+
1,
|
|
756
|
+
1,
|
|
757
|
+
1,
|
|
758
|
+
1,
|
|
759
|
+
1,
|
|
760
|
+
1,
|
|
761
|
+
0,
|
|
762
|
+
0,
|
|
763
|
+
0,
|
|
764
|
+
0,
|
|
765
|
+
0,
|
|
766
|
+
0,
|
|
767
|
+
0,
|
|
768
|
+
1,
|
|
769
|
+
1,
|
|
770
|
+
1,
|
|
771
|
+
1,
|
|
772
|
+
1,
|
|
773
|
+
1,
|
|
774
|
+
1,
|
|
775
|
+
1,
|
|
776
|
+
1,
|
|
777
|
+
1,
|
|
778
|
+
1,
|
|
779
|
+
1,
|
|
780
|
+
1,
|
|
781
|
+
1,
|
|
782
|
+
1,
|
|
783
|
+
1,
|
|
784
|
+
1,
|
|
785
|
+
1,
|
|
786
|
+
1,
|
|
787
|
+
1,
|
|
788
|
+
1,
|
|
789
|
+
1,
|
|
790
|
+
1,
|
|
791
|
+
1,
|
|
792
|
+
1,
|
|
793
|
+
1,
|
|
794
|
+
0,
|
|
795
|
+
0,
|
|
796
|
+
0,
|
|
797
|
+
1,
|
|
798
|
+
1,
|
|
799
|
+
1,
|
|
800
|
+
1,
|
|
801
|
+
1,
|
|
802
|
+
1,
|
|
803
|
+
1,
|
|
804
|
+
1,
|
|
805
|
+
1,
|
|
806
|
+
1,
|
|
807
|
+
1,
|
|
808
|
+
1,
|
|
809
|
+
1,
|
|
810
|
+
1,
|
|
811
|
+
1,
|
|
812
|
+
1,
|
|
813
|
+
1,
|
|
814
|
+
1,
|
|
815
|
+
1,
|
|
816
|
+
1,
|
|
817
|
+
1,
|
|
818
|
+
1,
|
|
819
|
+
1,
|
|
820
|
+
1,
|
|
821
|
+
1,
|
|
822
|
+
1,
|
|
823
|
+
1,
|
|
824
|
+
1,
|
|
825
|
+
1,
|
|
826
|
+
0,
|
|
827
|
+
1,
|
|
828
|
+
0,
|
|
829
|
+
1,
|
|
830
|
+
0
|
|
831
|
+
];
|
|
832
|
+
function isValidStatusCode(code) {
|
|
833
|
+
return code >= 1000 && code <= 1014 && code !== 1004 && code !== 1005 && code !== 1006 || code >= 3000 && code <= 4999;
|
|
834
|
+
}
|
|
835
|
+
function _isValidUTF8(buf) {
|
|
836
|
+
const len = buf.length;
|
|
837
|
+
let i = 0;
|
|
838
|
+
while (i < len) {
|
|
839
|
+
if ((buf[i] & 128) === 0) {
|
|
840
|
+
i++;
|
|
841
|
+
} else if ((buf[i] & 224) === 192) {
|
|
842
|
+
if (i + 1 === len || (buf[i + 1] & 192) !== 128 || (buf[i] & 254) === 192) {
|
|
843
|
+
return false;
|
|
844
|
+
}
|
|
845
|
+
i += 2;
|
|
846
|
+
} else if ((buf[i] & 240) === 224) {
|
|
847
|
+
if (i + 2 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || buf[i] === 224 && (buf[i + 1] & 224) === 128 || buf[i] === 237 && (buf[i + 1] & 224) === 160) {
|
|
848
|
+
return false;
|
|
849
|
+
}
|
|
850
|
+
i += 3;
|
|
851
|
+
} else if ((buf[i] & 248) === 240) {
|
|
852
|
+
if (i + 3 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || (buf[i + 3] & 192) !== 128 || buf[i] === 240 && (buf[i + 1] & 240) === 128 || buf[i] === 244 && buf[i + 1] > 143 || buf[i] > 244) {
|
|
853
|
+
return false;
|
|
854
|
+
}
|
|
855
|
+
i += 4;
|
|
856
|
+
} else {
|
|
857
|
+
return false;
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
return true;
|
|
861
|
+
}
|
|
862
|
+
function isBlob(value) {
|
|
863
|
+
return hasBlob && typeof value === "object" && typeof value.arrayBuffer === "function" && typeof value.type === "string" && typeof value.stream === "function" && (value[Symbol.toStringTag] === "Blob" || value[Symbol.toStringTag] === "File");
|
|
864
|
+
}
|
|
865
|
+
module.exports = {
|
|
866
|
+
isBlob,
|
|
867
|
+
isValidStatusCode,
|
|
868
|
+
isValidUTF8: _isValidUTF8,
|
|
869
|
+
tokenChars
|
|
870
|
+
};
|
|
871
|
+
if (isUtf8) {
|
|
872
|
+
module.exports.isValidUTF8 = function(buf) {
|
|
873
|
+
return buf.length < 24 ? _isValidUTF8(buf) : isUtf8(buf);
|
|
874
|
+
};
|
|
875
|
+
}
|
|
876
|
+
});
|
|
877
|
+
|
|
878
|
+
// node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/receiver.js
|
|
879
|
+
var require_receiver = __commonJS((exports, module) => {
|
|
880
|
+
var { Writable } = __require("stream");
|
|
881
|
+
var PerMessageDeflate = require_permessage_deflate();
|
|
882
|
+
var {
|
|
883
|
+
BINARY_TYPES,
|
|
884
|
+
EMPTY_BUFFER,
|
|
885
|
+
kStatusCode,
|
|
886
|
+
kWebSocket
|
|
887
|
+
} = require_constants();
|
|
888
|
+
var { concat, toArrayBuffer, unmask } = require_buffer_util();
|
|
889
|
+
var { isValidStatusCode, isValidUTF8 } = require_validation();
|
|
890
|
+
var FastBuffer = Buffer[Symbol.species];
|
|
891
|
+
var GET_INFO = 0;
|
|
892
|
+
var GET_PAYLOAD_LENGTH_16 = 1;
|
|
893
|
+
var GET_PAYLOAD_LENGTH_64 = 2;
|
|
894
|
+
var GET_MASK = 3;
|
|
895
|
+
var GET_DATA = 4;
|
|
896
|
+
var INFLATING = 5;
|
|
897
|
+
var DEFER_EVENT = 6;
|
|
898
|
+
|
|
899
|
+
class Receiver extends Writable {
|
|
900
|
+
constructor(options = {}) {
|
|
901
|
+
super();
|
|
902
|
+
this._allowSynchronousEvents = options.allowSynchronousEvents !== undefined ? options.allowSynchronousEvents : true;
|
|
903
|
+
this._binaryType = options.binaryType || BINARY_TYPES[0];
|
|
904
|
+
this._extensions = options.extensions || {};
|
|
905
|
+
this._isServer = !!options.isServer;
|
|
906
|
+
this._maxPayload = options.maxPayload | 0;
|
|
907
|
+
this._skipUTF8Validation = !!options.skipUTF8Validation;
|
|
908
|
+
this[kWebSocket] = undefined;
|
|
909
|
+
this._bufferedBytes = 0;
|
|
910
|
+
this._buffers = [];
|
|
911
|
+
this._compressed = false;
|
|
912
|
+
this._payloadLength = 0;
|
|
913
|
+
this._mask = undefined;
|
|
914
|
+
this._fragmented = 0;
|
|
915
|
+
this._masked = false;
|
|
916
|
+
this._fin = false;
|
|
917
|
+
this._opcode = 0;
|
|
918
|
+
this._totalPayloadLength = 0;
|
|
919
|
+
this._messageLength = 0;
|
|
920
|
+
this._fragments = [];
|
|
921
|
+
this._errored = false;
|
|
922
|
+
this._loop = false;
|
|
923
|
+
this._state = GET_INFO;
|
|
924
|
+
}
|
|
925
|
+
_write(chunk, encoding, cb) {
|
|
926
|
+
if (this._opcode === 8 && this._state == GET_INFO)
|
|
927
|
+
return cb();
|
|
928
|
+
this._bufferedBytes += chunk.length;
|
|
929
|
+
this._buffers.push(chunk);
|
|
930
|
+
this.startLoop(cb);
|
|
931
|
+
}
|
|
932
|
+
consume(n) {
|
|
933
|
+
this._bufferedBytes -= n;
|
|
934
|
+
if (n === this._buffers[0].length)
|
|
935
|
+
return this._buffers.shift();
|
|
936
|
+
if (n < this._buffers[0].length) {
|
|
937
|
+
const buf = this._buffers[0];
|
|
938
|
+
this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n);
|
|
939
|
+
return new FastBuffer(buf.buffer, buf.byteOffset, n);
|
|
940
|
+
}
|
|
941
|
+
const dst = Buffer.allocUnsafe(n);
|
|
942
|
+
do {
|
|
943
|
+
const buf = this._buffers[0];
|
|
944
|
+
const offset = dst.length - n;
|
|
945
|
+
if (n >= buf.length) {
|
|
946
|
+
dst.set(this._buffers.shift(), offset);
|
|
947
|
+
} else {
|
|
948
|
+
dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
|
|
949
|
+
this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n);
|
|
950
|
+
}
|
|
951
|
+
n -= buf.length;
|
|
952
|
+
} while (n > 0);
|
|
953
|
+
return dst;
|
|
954
|
+
}
|
|
955
|
+
startLoop(cb) {
|
|
956
|
+
this._loop = true;
|
|
957
|
+
do {
|
|
958
|
+
switch (this._state) {
|
|
959
|
+
case GET_INFO:
|
|
960
|
+
this.getInfo(cb);
|
|
961
|
+
break;
|
|
962
|
+
case GET_PAYLOAD_LENGTH_16:
|
|
963
|
+
this.getPayloadLength16(cb);
|
|
964
|
+
break;
|
|
965
|
+
case GET_PAYLOAD_LENGTH_64:
|
|
966
|
+
this.getPayloadLength64(cb);
|
|
967
|
+
break;
|
|
968
|
+
case GET_MASK:
|
|
969
|
+
this.getMask();
|
|
970
|
+
break;
|
|
971
|
+
case GET_DATA:
|
|
972
|
+
this.getData(cb);
|
|
973
|
+
break;
|
|
974
|
+
case INFLATING:
|
|
975
|
+
case DEFER_EVENT:
|
|
976
|
+
this._loop = false;
|
|
977
|
+
return;
|
|
978
|
+
}
|
|
979
|
+
} while (this._loop);
|
|
980
|
+
if (!this._errored)
|
|
981
|
+
cb();
|
|
982
|
+
}
|
|
983
|
+
getInfo(cb) {
|
|
984
|
+
if (this._bufferedBytes < 2) {
|
|
985
|
+
this._loop = false;
|
|
986
|
+
return;
|
|
987
|
+
}
|
|
988
|
+
const buf = this.consume(2);
|
|
989
|
+
if ((buf[0] & 48) !== 0) {
|
|
990
|
+
const error49 = this.createError(RangeError, "RSV2 and RSV3 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_2_3");
|
|
991
|
+
cb(error49);
|
|
992
|
+
return;
|
|
993
|
+
}
|
|
994
|
+
const compressed = (buf[0] & 64) === 64;
|
|
995
|
+
if (compressed && !this._extensions[PerMessageDeflate.extensionName]) {
|
|
996
|
+
const error49 = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
|
|
997
|
+
cb(error49);
|
|
998
|
+
return;
|
|
999
|
+
}
|
|
1000
|
+
this._fin = (buf[0] & 128) === 128;
|
|
1001
|
+
this._opcode = buf[0] & 15;
|
|
1002
|
+
this._payloadLength = buf[1] & 127;
|
|
1003
|
+
if (this._opcode === 0) {
|
|
1004
|
+
if (compressed) {
|
|
1005
|
+
const error49 = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
|
|
1006
|
+
cb(error49);
|
|
1007
|
+
return;
|
|
1008
|
+
}
|
|
1009
|
+
if (!this._fragmented) {
|
|
1010
|
+
const error49 = this.createError(RangeError, "invalid opcode 0", true, 1002, "WS_ERR_INVALID_OPCODE");
|
|
1011
|
+
cb(error49);
|
|
1012
|
+
return;
|
|
1013
|
+
}
|
|
1014
|
+
this._opcode = this._fragmented;
|
|
1015
|
+
} else if (this._opcode === 1 || this._opcode === 2) {
|
|
1016
|
+
if (this._fragmented) {
|
|
1017
|
+
const error49 = this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, "WS_ERR_INVALID_OPCODE");
|
|
1018
|
+
cb(error49);
|
|
1019
|
+
return;
|
|
1020
|
+
}
|
|
1021
|
+
this._compressed = compressed;
|
|
1022
|
+
} else if (this._opcode > 7 && this._opcode < 11) {
|
|
1023
|
+
if (!this._fin) {
|
|
1024
|
+
const error49 = this.createError(RangeError, "FIN must be set", true, 1002, "WS_ERR_EXPECTED_FIN");
|
|
1025
|
+
cb(error49);
|
|
1026
|
+
return;
|
|
1027
|
+
}
|
|
1028
|
+
if (compressed) {
|
|
1029
|
+
const error49 = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
|
|
1030
|
+
cb(error49);
|
|
1031
|
+
return;
|
|
1032
|
+
}
|
|
1033
|
+
if (this._payloadLength > 125 || this._opcode === 8 && this._payloadLength === 1) {
|
|
1034
|
+
const error49 = this.createError(RangeError, `invalid payload length ${this._payloadLength}`, true, 1002, "WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");
|
|
1035
|
+
cb(error49);
|
|
1036
|
+
return;
|
|
1037
|
+
}
|
|
1038
|
+
} else {
|
|
1039
|
+
const error49 = this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, "WS_ERR_INVALID_OPCODE");
|
|
1040
|
+
cb(error49);
|
|
1041
|
+
return;
|
|
1042
|
+
}
|
|
1043
|
+
if (!this._fin && !this._fragmented)
|
|
1044
|
+
this._fragmented = this._opcode;
|
|
1045
|
+
this._masked = (buf[1] & 128) === 128;
|
|
1046
|
+
if (this._isServer) {
|
|
1047
|
+
if (!this._masked) {
|
|
1048
|
+
const error49 = this.createError(RangeError, "MASK must be set", true, 1002, "WS_ERR_EXPECTED_MASK");
|
|
1049
|
+
cb(error49);
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
1052
|
+
} else if (this._masked) {
|
|
1053
|
+
const error49 = this.createError(RangeError, "MASK must be clear", true, 1002, "WS_ERR_UNEXPECTED_MASK");
|
|
1054
|
+
cb(error49);
|
|
1055
|
+
return;
|
|
1056
|
+
}
|
|
1057
|
+
if (this._payloadLength === 126)
|
|
1058
|
+
this._state = GET_PAYLOAD_LENGTH_16;
|
|
1059
|
+
else if (this._payloadLength === 127)
|
|
1060
|
+
this._state = GET_PAYLOAD_LENGTH_64;
|
|
1061
|
+
else
|
|
1062
|
+
this.haveLength(cb);
|
|
1063
|
+
}
|
|
1064
|
+
getPayloadLength16(cb) {
|
|
1065
|
+
if (this._bufferedBytes < 2) {
|
|
1066
|
+
this._loop = false;
|
|
1067
|
+
return;
|
|
1068
|
+
}
|
|
1069
|
+
this._payloadLength = this.consume(2).readUInt16BE(0);
|
|
1070
|
+
this.haveLength(cb);
|
|
1071
|
+
}
|
|
1072
|
+
getPayloadLength64(cb) {
|
|
1073
|
+
if (this._bufferedBytes < 8) {
|
|
1074
|
+
this._loop = false;
|
|
1075
|
+
return;
|
|
1076
|
+
}
|
|
1077
|
+
const buf = this.consume(8);
|
|
1078
|
+
const num = buf.readUInt32BE(0);
|
|
1079
|
+
if (num > Math.pow(2, 53 - 32) - 1) {
|
|
1080
|
+
const error49 = this.createError(RangeError, "Unsupported WebSocket frame: payload length > 2^53 - 1", false, 1009, "WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");
|
|
1081
|
+
cb(error49);
|
|
1082
|
+
return;
|
|
1083
|
+
}
|
|
1084
|
+
this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
|
|
1085
|
+
this.haveLength(cb);
|
|
1086
|
+
}
|
|
1087
|
+
haveLength(cb) {
|
|
1088
|
+
if (this._payloadLength && this._opcode < 8) {
|
|
1089
|
+
this._totalPayloadLength += this._payloadLength;
|
|
1090
|
+
if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
|
|
1091
|
+
const error49 = this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");
|
|
1092
|
+
cb(error49);
|
|
1093
|
+
return;
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
if (this._masked)
|
|
1097
|
+
this._state = GET_MASK;
|
|
1098
|
+
else
|
|
1099
|
+
this._state = GET_DATA;
|
|
1100
|
+
}
|
|
1101
|
+
getMask() {
|
|
1102
|
+
if (this._bufferedBytes < 4) {
|
|
1103
|
+
this._loop = false;
|
|
1104
|
+
return;
|
|
1105
|
+
}
|
|
1106
|
+
this._mask = this.consume(4);
|
|
1107
|
+
this._state = GET_DATA;
|
|
1108
|
+
}
|
|
1109
|
+
getData(cb) {
|
|
1110
|
+
let data = EMPTY_BUFFER;
|
|
1111
|
+
if (this._payloadLength) {
|
|
1112
|
+
if (this._bufferedBytes < this._payloadLength) {
|
|
1113
|
+
this._loop = false;
|
|
1114
|
+
return;
|
|
1115
|
+
}
|
|
1116
|
+
data = this.consume(this._payloadLength);
|
|
1117
|
+
if (this._masked && (this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0) {
|
|
1118
|
+
unmask(data, this._mask);
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
if (this._opcode > 7) {
|
|
1122
|
+
this.controlMessage(data, cb);
|
|
1123
|
+
return;
|
|
1124
|
+
}
|
|
1125
|
+
if (this._compressed) {
|
|
1126
|
+
this._state = INFLATING;
|
|
1127
|
+
this.decompress(data, cb);
|
|
1128
|
+
return;
|
|
1129
|
+
}
|
|
1130
|
+
if (data.length) {
|
|
1131
|
+
this._messageLength = this._totalPayloadLength;
|
|
1132
|
+
this._fragments.push(data);
|
|
1133
|
+
}
|
|
1134
|
+
this.dataMessage(cb);
|
|
1135
|
+
}
|
|
1136
|
+
decompress(data, cb) {
|
|
1137
|
+
const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
|
|
1138
|
+
perMessageDeflate.decompress(data, this._fin, (err, buf) => {
|
|
1139
|
+
if (err)
|
|
1140
|
+
return cb(err);
|
|
1141
|
+
if (buf.length) {
|
|
1142
|
+
this._messageLength += buf.length;
|
|
1143
|
+
if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
|
|
1144
|
+
const error49 = this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");
|
|
1145
|
+
cb(error49);
|
|
1146
|
+
return;
|
|
1147
|
+
}
|
|
1148
|
+
this._fragments.push(buf);
|
|
1149
|
+
}
|
|
1150
|
+
this.dataMessage(cb);
|
|
1151
|
+
if (this._state === GET_INFO)
|
|
1152
|
+
this.startLoop(cb);
|
|
1153
|
+
});
|
|
1154
|
+
}
|
|
1155
|
+
dataMessage(cb) {
|
|
1156
|
+
if (!this._fin) {
|
|
1157
|
+
this._state = GET_INFO;
|
|
1158
|
+
return;
|
|
1159
|
+
}
|
|
1160
|
+
const messageLength = this._messageLength;
|
|
1161
|
+
const fragments = this._fragments;
|
|
1162
|
+
this._totalPayloadLength = 0;
|
|
1163
|
+
this._messageLength = 0;
|
|
1164
|
+
this._fragmented = 0;
|
|
1165
|
+
this._fragments = [];
|
|
1166
|
+
if (this._opcode === 2) {
|
|
1167
|
+
let data;
|
|
1168
|
+
if (this._binaryType === "nodebuffer") {
|
|
1169
|
+
data = concat(fragments, messageLength);
|
|
1170
|
+
} else if (this._binaryType === "arraybuffer") {
|
|
1171
|
+
data = toArrayBuffer(concat(fragments, messageLength));
|
|
1172
|
+
} else if (this._binaryType === "blob") {
|
|
1173
|
+
data = new Blob(fragments);
|
|
1174
|
+
} else {
|
|
1175
|
+
data = fragments;
|
|
1176
|
+
}
|
|
1177
|
+
if (this._allowSynchronousEvents) {
|
|
1178
|
+
this.emit("message", data, true);
|
|
1179
|
+
this._state = GET_INFO;
|
|
1180
|
+
} else {
|
|
1181
|
+
this._state = DEFER_EVENT;
|
|
1182
|
+
setImmediate(() => {
|
|
1183
|
+
this.emit("message", data, true);
|
|
1184
|
+
this._state = GET_INFO;
|
|
1185
|
+
this.startLoop(cb);
|
|
1186
|
+
});
|
|
1187
|
+
}
|
|
1188
|
+
} else {
|
|
1189
|
+
const buf = concat(fragments, messageLength);
|
|
1190
|
+
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
|
|
1191
|
+
const error49 = this.createError(Error, "invalid UTF-8 sequence", true, 1007, "WS_ERR_INVALID_UTF8");
|
|
1192
|
+
cb(error49);
|
|
1193
|
+
return;
|
|
1194
|
+
}
|
|
1195
|
+
if (this._state === INFLATING || this._allowSynchronousEvents) {
|
|
1196
|
+
this.emit("message", buf, false);
|
|
1197
|
+
this._state = GET_INFO;
|
|
1198
|
+
} else {
|
|
1199
|
+
this._state = DEFER_EVENT;
|
|
1200
|
+
setImmediate(() => {
|
|
1201
|
+
this.emit("message", buf, false);
|
|
1202
|
+
this._state = GET_INFO;
|
|
1203
|
+
this.startLoop(cb);
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
controlMessage(data, cb) {
|
|
1209
|
+
if (this._opcode === 8) {
|
|
1210
|
+
if (data.length === 0) {
|
|
1211
|
+
this._loop = false;
|
|
1212
|
+
this.emit("conclude", 1005, EMPTY_BUFFER);
|
|
1213
|
+
this.end();
|
|
1214
|
+
} else {
|
|
1215
|
+
const code = data.readUInt16BE(0);
|
|
1216
|
+
if (!isValidStatusCode(code)) {
|
|
1217
|
+
const error49 = this.createError(RangeError, `invalid status code ${code}`, true, 1002, "WS_ERR_INVALID_CLOSE_CODE");
|
|
1218
|
+
cb(error49);
|
|
1219
|
+
return;
|
|
1220
|
+
}
|
|
1221
|
+
const buf = new FastBuffer(data.buffer, data.byteOffset + 2, data.length - 2);
|
|
1222
|
+
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
|
|
1223
|
+
const error49 = this.createError(Error, "invalid UTF-8 sequence", true, 1007, "WS_ERR_INVALID_UTF8");
|
|
1224
|
+
cb(error49);
|
|
1225
|
+
return;
|
|
1226
|
+
}
|
|
1227
|
+
this._loop = false;
|
|
1228
|
+
this.emit("conclude", code, buf);
|
|
1229
|
+
this.end();
|
|
1230
|
+
}
|
|
1231
|
+
this._state = GET_INFO;
|
|
1232
|
+
return;
|
|
1233
|
+
}
|
|
1234
|
+
if (this._allowSynchronousEvents) {
|
|
1235
|
+
this.emit(this._opcode === 9 ? "ping" : "pong", data);
|
|
1236
|
+
this._state = GET_INFO;
|
|
1237
|
+
} else {
|
|
1238
|
+
this._state = DEFER_EVENT;
|
|
1239
|
+
setImmediate(() => {
|
|
1240
|
+
this.emit(this._opcode === 9 ? "ping" : "pong", data);
|
|
1241
|
+
this._state = GET_INFO;
|
|
1242
|
+
this.startLoop(cb);
|
|
1243
|
+
});
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
createError(ErrorCtor, message, prefix, statusCode, errorCode) {
|
|
1247
|
+
this._loop = false;
|
|
1248
|
+
this._errored = true;
|
|
1249
|
+
const err = new ErrorCtor(prefix ? `Invalid WebSocket frame: ${message}` : message);
|
|
1250
|
+
Error.captureStackTrace(err, this.createError);
|
|
1251
|
+
err.code = errorCode;
|
|
1252
|
+
err[kStatusCode] = statusCode;
|
|
1253
|
+
return err;
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
module.exports = Receiver;
|
|
1257
|
+
});
|
|
1258
|
+
|
|
1259
|
+
// node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/sender.js
|
|
1260
|
+
var require_sender = __commonJS((exports, module) => {
|
|
1261
|
+
var { Duplex } = __require("stream");
|
|
1262
|
+
var { randomFillSync } = __require("crypto");
|
|
1263
|
+
var PerMessageDeflate = require_permessage_deflate();
|
|
1264
|
+
var { EMPTY_BUFFER, kWebSocket, NOOP } = require_constants();
|
|
1265
|
+
var { isBlob, isValidStatusCode } = require_validation();
|
|
1266
|
+
var { mask: applyMask, toBuffer } = require_buffer_util();
|
|
1267
|
+
var kByteLength = Symbol("kByteLength");
|
|
1268
|
+
var maskBuffer = Buffer.alloc(4);
|
|
1269
|
+
var RANDOM_POOL_SIZE = 8 * 1024;
|
|
1270
|
+
var randomPool;
|
|
1271
|
+
var randomPoolPointer = RANDOM_POOL_SIZE;
|
|
1272
|
+
var DEFAULT = 0;
|
|
1273
|
+
var DEFLATING = 1;
|
|
1274
|
+
var GET_BLOB_DATA = 2;
|
|
1275
|
+
|
|
1276
|
+
class Sender {
|
|
1277
|
+
constructor(socket, extensions, generateMask) {
|
|
1278
|
+
this._extensions = extensions || {};
|
|
1279
|
+
if (generateMask) {
|
|
1280
|
+
this._generateMask = generateMask;
|
|
1281
|
+
this._maskBuffer = Buffer.alloc(4);
|
|
1282
|
+
}
|
|
1283
|
+
this._socket = socket;
|
|
1284
|
+
this._firstFragment = true;
|
|
1285
|
+
this._compress = false;
|
|
1286
|
+
this._bufferedBytes = 0;
|
|
1287
|
+
this._queue = [];
|
|
1288
|
+
this._state = DEFAULT;
|
|
1289
|
+
this.onerror = NOOP;
|
|
1290
|
+
this[kWebSocket] = undefined;
|
|
1291
|
+
}
|
|
1292
|
+
static frame(data, options) {
|
|
1293
|
+
let mask;
|
|
1294
|
+
let merge3 = false;
|
|
1295
|
+
let offset = 2;
|
|
1296
|
+
let skipMasking = false;
|
|
1297
|
+
if (options.mask) {
|
|
1298
|
+
mask = options.maskBuffer || maskBuffer;
|
|
1299
|
+
if (options.generateMask) {
|
|
1300
|
+
options.generateMask(mask);
|
|
1301
|
+
} else {
|
|
1302
|
+
if (randomPoolPointer === RANDOM_POOL_SIZE) {
|
|
1303
|
+
if (randomPool === undefined) {
|
|
1304
|
+
randomPool = Buffer.alloc(RANDOM_POOL_SIZE);
|
|
1305
|
+
}
|
|
1306
|
+
randomFillSync(randomPool, 0, RANDOM_POOL_SIZE);
|
|
1307
|
+
randomPoolPointer = 0;
|
|
1308
|
+
}
|
|
1309
|
+
mask[0] = randomPool[randomPoolPointer++];
|
|
1310
|
+
mask[1] = randomPool[randomPoolPointer++];
|
|
1311
|
+
mask[2] = randomPool[randomPoolPointer++];
|
|
1312
|
+
mask[3] = randomPool[randomPoolPointer++];
|
|
1313
|
+
}
|
|
1314
|
+
skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) === 0;
|
|
1315
|
+
offset = 6;
|
|
1316
|
+
}
|
|
1317
|
+
let dataLength;
|
|
1318
|
+
if (typeof data === "string") {
|
|
1319
|
+
if ((!options.mask || skipMasking) && options[kByteLength] !== undefined) {
|
|
1320
|
+
dataLength = options[kByteLength];
|
|
1321
|
+
} else {
|
|
1322
|
+
data = Buffer.from(data);
|
|
1323
|
+
dataLength = data.length;
|
|
1324
|
+
}
|
|
1325
|
+
} else {
|
|
1326
|
+
dataLength = data.length;
|
|
1327
|
+
merge3 = options.mask && options.readOnly && !skipMasking;
|
|
1328
|
+
}
|
|
1329
|
+
let payloadLength = dataLength;
|
|
1330
|
+
if (dataLength >= 65536) {
|
|
1331
|
+
offset += 8;
|
|
1332
|
+
payloadLength = 127;
|
|
1333
|
+
} else if (dataLength > 125) {
|
|
1334
|
+
offset += 2;
|
|
1335
|
+
payloadLength = 126;
|
|
1336
|
+
}
|
|
1337
|
+
const target = Buffer.allocUnsafe(merge3 ? dataLength + offset : offset);
|
|
1338
|
+
target[0] = options.fin ? options.opcode | 128 : options.opcode;
|
|
1339
|
+
if (options.rsv1)
|
|
1340
|
+
target[0] |= 64;
|
|
1341
|
+
target[1] = payloadLength;
|
|
1342
|
+
if (payloadLength === 126) {
|
|
1343
|
+
target.writeUInt16BE(dataLength, 2);
|
|
1344
|
+
} else if (payloadLength === 127) {
|
|
1345
|
+
target[2] = target[3] = 0;
|
|
1346
|
+
target.writeUIntBE(dataLength, 4, 6);
|
|
1347
|
+
}
|
|
1348
|
+
if (!options.mask)
|
|
1349
|
+
return [target, data];
|
|
1350
|
+
target[1] |= 128;
|
|
1351
|
+
target[offset - 4] = mask[0];
|
|
1352
|
+
target[offset - 3] = mask[1];
|
|
1353
|
+
target[offset - 2] = mask[2];
|
|
1354
|
+
target[offset - 1] = mask[3];
|
|
1355
|
+
if (skipMasking)
|
|
1356
|
+
return [target, data];
|
|
1357
|
+
if (merge3) {
|
|
1358
|
+
applyMask(data, mask, target, offset, dataLength);
|
|
1359
|
+
return [target];
|
|
1360
|
+
}
|
|
1361
|
+
applyMask(data, mask, data, 0, dataLength);
|
|
1362
|
+
return [target, data];
|
|
1363
|
+
}
|
|
1364
|
+
close(code, data, mask, cb) {
|
|
1365
|
+
let buf;
|
|
1366
|
+
if (code === undefined) {
|
|
1367
|
+
buf = EMPTY_BUFFER;
|
|
1368
|
+
} else if (typeof code !== "number" || !isValidStatusCode(code)) {
|
|
1369
|
+
throw new TypeError("First argument must be a valid error code number");
|
|
1370
|
+
} else if (data === undefined || !data.length) {
|
|
1371
|
+
buf = Buffer.allocUnsafe(2);
|
|
1372
|
+
buf.writeUInt16BE(code, 0);
|
|
1373
|
+
} else {
|
|
1374
|
+
const length = Buffer.byteLength(data);
|
|
1375
|
+
if (length > 123) {
|
|
1376
|
+
throw new RangeError("The message must not be greater than 123 bytes");
|
|
1377
|
+
}
|
|
1378
|
+
buf = Buffer.allocUnsafe(2 + length);
|
|
1379
|
+
buf.writeUInt16BE(code, 0);
|
|
1380
|
+
if (typeof data === "string") {
|
|
1381
|
+
buf.write(data, 2);
|
|
1382
|
+
} else {
|
|
1383
|
+
buf.set(data, 2);
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
const options = {
|
|
1387
|
+
[kByteLength]: buf.length,
|
|
1388
|
+
fin: true,
|
|
1389
|
+
generateMask: this._generateMask,
|
|
1390
|
+
mask,
|
|
1391
|
+
maskBuffer: this._maskBuffer,
|
|
1392
|
+
opcode: 8,
|
|
1393
|
+
readOnly: false,
|
|
1394
|
+
rsv1: false
|
|
1395
|
+
};
|
|
1396
|
+
if (this._state !== DEFAULT) {
|
|
1397
|
+
this.enqueue([this.dispatch, buf, false, options, cb]);
|
|
1398
|
+
} else {
|
|
1399
|
+
this.sendFrame(Sender.frame(buf, options), cb);
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
ping(data, mask, cb) {
|
|
1403
|
+
let byteLength;
|
|
1404
|
+
let readOnly;
|
|
1405
|
+
if (typeof data === "string") {
|
|
1406
|
+
byteLength = Buffer.byteLength(data);
|
|
1407
|
+
readOnly = false;
|
|
1408
|
+
} else if (isBlob(data)) {
|
|
1409
|
+
byteLength = data.size;
|
|
1410
|
+
readOnly = false;
|
|
1411
|
+
} else {
|
|
1412
|
+
data = toBuffer(data);
|
|
1413
|
+
byteLength = data.length;
|
|
1414
|
+
readOnly = toBuffer.readOnly;
|
|
1415
|
+
}
|
|
1416
|
+
if (byteLength > 125) {
|
|
1417
|
+
throw new RangeError("The data size must not be greater than 125 bytes");
|
|
1418
|
+
}
|
|
1419
|
+
const options = {
|
|
1420
|
+
[kByteLength]: byteLength,
|
|
1421
|
+
fin: true,
|
|
1422
|
+
generateMask: this._generateMask,
|
|
1423
|
+
mask,
|
|
1424
|
+
maskBuffer: this._maskBuffer,
|
|
1425
|
+
opcode: 9,
|
|
1426
|
+
readOnly,
|
|
1427
|
+
rsv1: false
|
|
1428
|
+
};
|
|
1429
|
+
if (isBlob(data)) {
|
|
1430
|
+
if (this._state !== DEFAULT) {
|
|
1431
|
+
this.enqueue([this.getBlobData, data, false, options, cb]);
|
|
1432
|
+
} else {
|
|
1433
|
+
this.getBlobData(data, false, options, cb);
|
|
1434
|
+
}
|
|
1435
|
+
} else if (this._state !== DEFAULT) {
|
|
1436
|
+
this.enqueue([this.dispatch, data, false, options, cb]);
|
|
1437
|
+
} else {
|
|
1438
|
+
this.sendFrame(Sender.frame(data, options), cb);
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
pong(data, mask, cb) {
|
|
1442
|
+
let byteLength;
|
|
1443
|
+
let readOnly;
|
|
1444
|
+
if (typeof data === "string") {
|
|
1445
|
+
byteLength = Buffer.byteLength(data);
|
|
1446
|
+
readOnly = false;
|
|
1447
|
+
} else if (isBlob(data)) {
|
|
1448
|
+
byteLength = data.size;
|
|
1449
|
+
readOnly = false;
|
|
1450
|
+
} else {
|
|
1451
|
+
data = toBuffer(data);
|
|
1452
|
+
byteLength = data.length;
|
|
1453
|
+
readOnly = toBuffer.readOnly;
|
|
1454
|
+
}
|
|
1455
|
+
if (byteLength > 125) {
|
|
1456
|
+
throw new RangeError("The data size must not be greater than 125 bytes");
|
|
1457
|
+
}
|
|
1458
|
+
const options = {
|
|
1459
|
+
[kByteLength]: byteLength,
|
|
1460
|
+
fin: true,
|
|
1461
|
+
generateMask: this._generateMask,
|
|
1462
|
+
mask,
|
|
1463
|
+
maskBuffer: this._maskBuffer,
|
|
1464
|
+
opcode: 10,
|
|
1465
|
+
readOnly,
|
|
1466
|
+
rsv1: false
|
|
1467
|
+
};
|
|
1468
|
+
if (isBlob(data)) {
|
|
1469
|
+
if (this._state !== DEFAULT) {
|
|
1470
|
+
this.enqueue([this.getBlobData, data, false, options, cb]);
|
|
1471
|
+
} else {
|
|
1472
|
+
this.getBlobData(data, false, options, cb);
|
|
1473
|
+
}
|
|
1474
|
+
} else if (this._state !== DEFAULT) {
|
|
1475
|
+
this.enqueue([this.dispatch, data, false, options, cb]);
|
|
1476
|
+
} else {
|
|
1477
|
+
this.sendFrame(Sender.frame(data, options), cb);
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
send(data, options, cb) {
|
|
1481
|
+
const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
|
|
1482
|
+
let opcode = options.binary ? 2 : 1;
|
|
1483
|
+
let rsv1 = options.compress;
|
|
1484
|
+
let byteLength;
|
|
1485
|
+
let readOnly;
|
|
1486
|
+
if (typeof data === "string") {
|
|
1487
|
+
byteLength = Buffer.byteLength(data);
|
|
1488
|
+
readOnly = false;
|
|
1489
|
+
} else if (isBlob(data)) {
|
|
1490
|
+
byteLength = data.size;
|
|
1491
|
+
readOnly = false;
|
|
1492
|
+
} else {
|
|
1493
|
+
data = toBuffer(data);
|
|
1494
|
+
byteLength = data.length;
|
|
1495
|
+
readOnly = toBuffer.readOnly;
|
|
1496
|
+
}
|
|
1497
|
+
if (this._firstFragment) {
|
|
1498
|
+
this._firstFragment = false;
|
|
1499
|
+
if (rsv1 && perMessageDeflate && perMessageDeflate.params[perMessageDeflate._isServer ? "server_no_context_takeover" : "client_no_context_takeover"]) {
|
|
1500
|
+
rsv1 = byteLength >= perMessageDeflate._threshold;
|
|
1501
|
+
}
|
|
1502
|
+
this._compress = rsv1;
|
|
1503
|
+
} else {
|
|
1504
|
+
rsv1 = false;
|
|
1505
|
+
opcode = 0;
|
|
1506
|
+
}
|
|
1507
|
+
if (options.fin)
|
|
1508
|
+
this._firstFragment = true;
|
|
1509
|
+
const opts = {
|
|
1510
|
+
[kByteLength]: byteLength,
|
|
1511
|
+
fin: options.fin,
|
|
1512
|
+
generateMask: this._generateMask,
|
|
1513
|
+
mask: options.mask,
|
|
1514
|
+
maskBuffer: this._maskBuffer,
|
|
1515
|
+
opcode,
|
|
1516
|
+
readOnly,
|
|
1517
|
+
rsv1
|
|
1518
|
+
};
|
|
1519
|
+
if (isBlob(data)) {
|
|
1520
|
+
if (this._state !== DEFAULT) {
|
|
1521
|
+
this.enqueue([this.getBlobData, data, this._compress, opts, cb]);
|
|
1522
|
+
} else {
|
|
1523
|
+
this.getBlobData(data, this._compress, opts, cb);
|
|
1524
|
+
}
|
|
1525
|
+
} else if (this._state !== DEFAULT) {
|
|
1526
|
+
this.enqueue([this.dispatch, data, this._compress, opts, cb]);
|
|
1527
|
+
} else {
|
|
1528
|
+
this.dispatch(data, this._compress, opts, cb);
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
getBlobData(blob, compress, options, cb) {
|
|
1532
|
+
this._bufferedBytes += options[kByteLength];
|
|
1533
|
+
this._state = GET_BLOB_DATA;
|
|
1534
|
+
blob.arrayBuffer().then((arrayBuffer) => {
|
|
1535
|
+
if (this._socket.destroyed) {
|
|
1536
|
+
const err = new Error("The socket was closed while the blob was being read");
|
|
1537
|
+
process.nextTick(callCallbacks, this, err, cb);
|
|
1538
|
+
return;
|
|
1539
|
+
}
|
|
1540
|
+
this._bufferedBytes -= options[kByteLength];
|
|
1541
|
+
const data = toBuffer(arrayBuffer);
|
|
1542
|
+
if (!compress) {
|
|
1543
|
+
this._state = DEFAULT;
|
|
1544
|
+
this.sendFrame(Sender.frame(data, options), cb);
|
|
1545
|
+
this.dequeue();
|
|
1546
|
+
} else {
|
|
1547
|
+
this.dispatch(data, compress, options, cb);
|
|
1548
|
+
}
|
|
1549
|
+
}).catch((err) => {
|
|
1550
|
+
process.nextTick(onError, this, err, cb);
|
|
1551
|
+
});
|
|
1552
|
+
}
|
|
1553
|
+
dispatch(data, compress, options, cb) {
|
|
1554
|
+
if (!compress) {
|
|
1555
|
+
this.sendFrame(Sender.frame(data, options), cb);
|
|
1556
|
+
return;
|
|
1557
|
+
}
|
|
1558
|
+
const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
|
|
1559
|
+
this._bufferedBytes += options[kByteLength];
|
|
1560
|
+
this._state = DEFLATING;
|
|
1561
|
+
perMessageDeflate.compress(data, options.fin, (_, buf) => {
|
|
1562
|
+
if (this._socket.destroyed) {
|
|
1563
|
+
const err = new Error("The socket was closed while data was being compressed");
|
|
1564
|
+
callCallbacks(this, err, cb);
|
|
1565
|
+
return;
|
|
1566
|
+
}
|
|
1567
|
+
this._bufferedBytes -= options[kByteLength];
|
|
1568
|
+
this._state = DEFAULT;
|
|
1569
|
+
options.readOnly = false;
|
|
1570
|
+
this.sendFrame(Sender.frame(buf, options), cb);
|
|
1571
|
+
this.dequeue();
|
|
1572
|
+
});
|
|
1573
|
+
}
|
|
1574
|
+
dequeue() {
|
|
1575
|
+
while (this._state === DEFAULT && this._queue.length) {
|
|
1576
|
+
const params = this._queue.shift();
|
|
1577
|
+
this._bufferedBytes -= params[3][kByteLength];
|
|
1578
|
+
Reflect.apply(params[0], this, params.slice(1));
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
enqueue(params) {
|
|
1582
|
+
this._bufferedBytes += params[3][kByteLength];
|
|
1583
|
+
this._queue.push(params);
|
|
1584
|
+
}
|
|
1585
|
+
sendFrame(list, cb) {
|
|
1586
|
+
if (list.length === 2) {
|
|
1587
|
+
this._socket.cork();
|
|
1588
|
+
this._socket.write(list[0]);
|
|
1589
|
+
this._socket.write(list[1], cb);
|
|
1590
|
+
this._socket.uncork();
|
|
1591
|
+
} else {
|
|
1592
|
+
this._socket.write(list[0], cb);
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
module.exports = Sender;
|
|
1597
|
+
function callCallbacks(sender2, err, cb) {
|
|
1598
|
+
if (typeof cb === "function")
|
|
1599
|
+
cb(err);
|
|
1600
|
+
for (let i = 0;i < sender2._queue.length; i++) {
|
|
1601
|
+
const params = sender2._queue[i];
|
|
1602
|
+
const callback = params[params.length - 1];
|
|
1603
|
+
if (typeof callback === "function")
|
|
1604
|
+
callback(err);
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
function onError(sender2, err, cb) {
|
|
1608
|
+
callCallbacks(sender2, err, cb);
|
|
1609
|
+
sender2.onerror(err);
|
|
1610
|
+
}
|
|
1611
|
+
});
|
|
1612
|
+
|
|
1613
|
+
// node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/event-target.js
|
|
1614
|
+
var require_event_target = __commonJS((exports, module) => {
|
|
1615
|
+
var { kForOnEventAttribute, kListener } = require_constants();
|
|
1616
|
+
var kCode = Symbol("kCode");
|
|
1617
|
+
var kData = Symbol("kData");
|
|
1618
|
+
var kError = Symbol("kError");
|
|
1619
|
+
var kMessage = Symbol("kMessage");
|
|
1620
|
+
var kReason = Symbol("kReason");
|
|
1621
|
+
var kTarget = Symbol("kTarget");
|
|
1622
|
+
var kType = Symbol("kType");
|
|
1623
|
+
var kWasClean = Symbol("kWasClean");
|
|
1624
|
+
|
|
1625
|
+
class Event {
|
|
1626
|
+
constructor(type) {
|
|
1627
|
+
this[kTarget] = null;
|
|
1628
|
+
this[kType] = type;
|
|
1629
|
+
}
|
|
1630
|
+
get target() {
|
|
1631
|
+
return this[kTarget];
|
|
1632
|
+
}
|
|
1633
|
+
get type() {
|
|
1634
|
+
return this[kType];
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
Object.defineProperty(Event.prototype, "target", { enumerable: true });
|
|
1638
|
+
Object.defineProperty(Event.prototype, "type", { enumerable: true });
|
|
1639
|
+
|
|
1640
|
+
class CloseEvent extends Event {
|
|
1641
|
+
constructor(type, options = {}) {
|
|
1642
|
+
super(type);
|
|
1643
|
+
this[kCode] = options.code === undefined ? 0 : options.code;
|
|
1644
|
+
this[kReason] = options.reason === undefined ? "" : options.reason;
|
|
1645
|
+
this[kWasClean] = options.wasClean === undefined ? false : options.wasClean;
|
|
1646
|
+
}
|
|
1647
|
+
get code() {
|
|
1648
|
+
return this[kCode];
|
|
1649
|
+
}
|
|
1650
|
+
get reason() {
|
|
1651
|
+
return this[kReason];
|
|
1652
|
+
}
|
|
1653
|
+
get wasClean() {
|
|
1654
|
+
return this[kWasClean];
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
Object.defineProperty(CloseEvent.prototype, "code", { enumerable: true });
|
|
1658
|
+
Object.defineProperty(CloseEvent.prototype, "reason", { enumerable: true });
|
|
1659
|
+
Object.defineProperty(CloseEvent.prototype, "wasClean", { enumerable: true });
|
|
1660
|
+
|
|
1661
|
+
class ErrorEvent extends Event {
|
|
1662
|
+
constructor(type, options = {}) {
|
|
1663
|
+
super(type);
|
|
1664
|
+
this[kError] = options.error === undefined ? null : options.error;
|
|
1665
|
+
this[kMessage] = options.message === undefined ? "" : options.message;
|
|
1666
|
+
}
|
|
1667
|
+
get error() {
|
|
1668
|
+
return this[kError];
|
|
1669
|
+
}
|
|
1670
|
+
get message() {
|
|
1671
|
+
return this[kMessage];
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
Object.defineProperty(ErrorEvent.prototype, "error", { enumerable: true });
|
|
1675
|
+
Object.defineProperty(ErrorEvent.prototype, "message", { enumerable: true });
|
|
1676
|
+
|
|
1677
|
+
class MessageEvent extends Event {
|
|
1678
|
+
constructor(type, options = {}) {
|
|
1679
|
+
super(type);
|
|
1680
|
+
this[kData] = options.data === undefined ? null : options.data;
|
|
1681
|
+
}
|
|
1682
|
+
get data() {
|
|
1683
|
+
return this[kData];
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
Object.defineProperty(MessageEvent.prototype, "data", { enumerable: true });
|
|
1687
|
+
var EventTarget = {
|
|
1688
|
+
addEventListener(type, handler, options = {}) {
|
|
1689
|
+
for (const listener of this.listeners(type)) {
|
|
1690
|
+
if (!options[kForOnEventAttribute] && listener[kListener] === handler && !listener[kForOnEventAttribute]) {
|
|
1691
|
+
return;
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
let wrapper;
|
|
1695
|
+
if (type === "message") {
|
|
1696
|
+
wrapper = function onMessage(data, isBinary) {
|
|
1697
|
+
const event = new MessageEvent("message", {
|
|
1698
|
+
data: isBinary ? data : data.toString()
|
|
1699
|
+
});
|
|
1700
|
+
event[kTarget] = this;
|
|
1701
|
+
callListener(handler, this, event);
|
|
1702
|
+
};
|
|
1703
|
+
} else if (type === "close") {
|
|
1704
|
+
wrapper = function onClose(code, message) {
|
|
1705
|
+
const event = new CloseEvent("close", {
|
|
1706
|
+
code,
|
|
1707
|
+
reason: message.toString(),
|
|
1708
|
+
wasClean: this._closeFrameReceived && this._closeFrameSent
|
|
1709
|
+
});
|
|
1710
|
+
event[kTarget] = this;
|
|
1711
|
+
callListener(handler, this, event);
|
|
1712
|
+
};
|
|
1713
|
+
} else if (type === "error") {
|
|
1714
|
+
wrapper = function onError(error49) {
|
|
1715
|
+
const event = new ErrorEvent("error", {
|
|
1716
|
+
error: error49,
|
|
1717
|
+
message: error49.message
|
|
1718
|
+
});
|
|
1719
|
+
event[kTarget] = this;
|
|
1720
|
+
callListener(handler, this, event);
|
|
1721
|
+
};
|
|
1722
|
+
} else if (type === "open") {
|
|
1723
|
+
wrapper = function onOpen() {
|
|
1724
|
+
const event = new Event("open");
|
|
1725
|
+
event[kTarget] = this;
|
|
1726
|
+
callListener(handler, this, event);
|
|
1727
|
+
};
|
|
1728
|
+
} else {
|
|
1729
|
+
return;
|
|
1730
|
+
}
|
|
1731
|
+
wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute];
|
|
1732
|
+
wrapper[kListener] = handler;
|
|
1733
|
+
if (options.once) {
|
|
1734
|
+
this.once(type, wrapper);
|
|
1735
|
+
} else {
|
|
1736
|
+
this.on(type, wrapper);
|
|
1737
|
+
}
|
|
1738
|
+
},
|
|
1739
|
+
removeEventListener(type, handler) {
|
|
1740
|
+
for (const listener of this.listeners(type)) {
|
|
1741
|
+
if (listener[kListener] === handler && !listener[kForOnEventAttribute]) {
|
|
1742
|
+
this.removeListener(type, listener);
|
|
1743
|
+
break;
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
};
|
|
1748
|
+
module.exports = {
|
|
1749
|
+
CloseEvent,
|
|
1750
|
+
ErrorEvent,
|
|
1751
|
+
Event,
|
|
1752
|
+
EventTarget,
|
|
1753
|
+
MessageEvent
|
|
1754
|
+
};
|
|
1755
|
+
function callListener(listener, thisArg, event) {
|
|
1756
|
+
if (typeof listener === "object" && listener.handleEvent) {
|
|
1757
|
+
listener.handleEvent.call(listener, event);
|
|
1758
|
+
} else {
|
|
1759
|
+
listener.call(thisArg, event);
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
});
|
|
1763
|
+
|
|
1764
|
+
// node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/extension.js
|
|
1765
|
+
var require_extension = __commonJS((exports, module) => {
|
|
1766
|
+
var { tokenChars } = require_validation();
|
|
1767
|
+
function push(dest, name, elem) {
|
|
1768
|
+
if (dest[name] === undefined)
|
|
1769
|
+
dest[name] = [elem];
|
|
1770
|
+
else
|
|
1771
|
+
dest[name].push(elem);
|
|
1772
|
+
}
|
|
1773
|
+
function parse6(header) {
|
|
1774
|
+
const offers = Object.create(null);
|
|
1775
|
+
let params = Object.create(null);
|
|
1776
|
+
let mustUnescape = false;
|
|
1777
|
+
let isEscaping = false;
|
|
1778
|
+
let inQuotes = false;
|
|
1779
|
+
let extensionName;
|
|
1780
|
+
let paramName;
|
|
1781
|
+
let start = -1;
|
|
1782
|
+
let code = -1;
|
|
1783
|
+
let end = -1;
|
|
1784
|
+
let i = 0;
|
|
1785
|
+
for (;i < header.length; i++) {
|
|
1786
|
+
code = header.charCodeAt(i);
|
|
1787
|
+
if (extensionName === undefined) {
|
|
1788
|
+
if (end === -1 && tokenChars[code] === 1) {
|
|
1789
|
+
if (start === -1)
|
|
1790
|
+
start = i;
|
|
1791
|
+
} else if (i !== 0 && (code === 32 || code === 9)) {
|
|
1792
|
+
if (end === -1 && start !== -1)
|
|
1793
|
+
end = i;
|
|
1794
|
+
} else if (code === 59 || code === 44) {
|
|
1795
|
+
if (start === -1) {
|
|
1796
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
1797
|
+
}
|
|
1798
|
+
if (end === -1)
|
|
1799
|
+
end = i;
|
|
1800
|
+
const name = header.slice(start, end);
|
|
1801
|
+
if (code === 44) {
|
|
1802
|
+
push(offers, name, params);
|
|
1803
|
+
params = Object.create(null);
|
|
1804
|
+
} else {
|
|
1805
|
+
extensionName = name;
|
|
1806
|
+
}
|
|
1807
|
+
start = end = -1;
|
|
1808
|
+
} else {
|
|
1809
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
1810
|
+
}
|
|
1811
|
+
} else if (paramName === undefined) {
|
|
1812
|
+
if (end === -1 && tokenChars[code] === 1) {
|
|
1813
|
+
if (start === -1)
|
|
1814
|
+
start = i;
|
|
1815
|
+
} else if (code === 32 || code === 9) {
|
|
1816
|
+
if (end === -1 && start !== -1)
|
|
1817
|
+
end = i;
|
|
1818
|
+
} else if (code === 59 || code === 44) {
|
|
1819
|
+
if (start === -1) {
|
|
1820
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
1821
|
+
}
|
|
1822
|
+
if (end === -1)
|
|
1823
|
+
end = i;
|
|
1824
|
+
push(params, header.slice(start, end), true);
|
|
1825
|
+
if (code === 44) {
|
|
1826
|
+
push(offers, extensionName, params);
|
|
1827
|
+
params = Object.create(null);
|
|
1828
|
+
extensionName = undefined;
|
|
1829
|
+
}
|
|
1830
|
+
start = end = -1;
|
|
1831
|
+
} else if (code === 61 && start !== -1 && end === -1) {
|
|
1832
|
+
paramName = header.slice(start, i);
|
|
1833
|
+
start = end = -1;
|
|
1834
|
+
} else {
|
|
1835
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
1836
|
+
}
|
|
1837
|
+
} else {
|
|
1838
|
+
if (isEscaping) {
|
|
1839
|
+
if (tokenChars[code] !== 1) {
|
|
1840
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
1841
|
+
}
|
|
1842
|
+
if (start === -1)
|
|
1843
|
+
start = i;
|
|
1844
|
+
else if (!mustUnescape)
|
|
1845
|
+
mustUnescape = true;
|
|
1846
|
+
isEscaping = false;
|
|
1847
|
+
} else if (inQuotes) {
|
|
1848
|
+
if (tokenChars[code] === 1) {
|
|
1849
|
+
if (start === -1)
|
|
1850
|
+
start = i;
|
|
1851
|
+
} else if (code === 34 && start !== -1) {
|
|
1852
|
+
inQuotes = false;
|
|
1853
|
+
end = i;
|
|
1854
|
+
} else if (code === 92) {
|
|
1855
|
+
isEscaping = true;
|
|
1856
|
+
} else {
|
|
1857
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
1858
|
+
}
|
|
1859
|
+
} else if (code === 34 && header.charCodeAt(i - 1) === 61) {
|
|
1860
|
+
inQuotes = true;
|
|
1861
|
+
} else if (end === -1 && tokenChars[code] === 1) {
|
|
1862
|
+
if (start === -1)
|
|
1863
|
+
start = i;
|
|
1864
|
+
} else if (start !== -1 && (code === 32 || code === 9)) {
|
|
1865
|
+
if (end === -1)
|
|
1866
|
+
end = i;
|
|
1867
|
+
} else if (code === 59 || code === 44) {
|
|
1868
|
+
if (start === -1) {
|
|
1869
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
1870
|
+
}
|
|
1871
|
+
if (end === -1)
|
|
1872
|
+
end = i;
|
|
1873
|
+
let value = header.slice(start, end);
|
|
1874
|
+
if (mustUnescape) {
|
|
1875
|
+
value = value.replace(/\\/g, "");
|
|
1876
|
+
mustUnescape = false;
|
|
1877
|
+
}
|
|
1878
|
+
push(params, paramName, value);
|
|
1879
|
+
if (code === 44) {
|
|
1880
|
+
push(offers, extensionName, params);
|
|
1881
|
+
params = Object.create(null);
|
|
1882
|
+
extensionName = undefined;
|
|
1883
|
+
}
|
|
1884
|
+
paramName = undefined;
|
|
1885
|
+
start = end = -1;
|
|
1886
|
+
} else {
|
|
1887
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
if (start === -1 || inQuotes || code === 32 || code === 9) {
|
|
1892
|
+
throw new SyntaxError("Unexpected end of input");
|
|
1893
|
+
}
|
|
1894
|
+
if (end === -1)
|
|
1895
|
+
end = i;
|
|
1896
|
+
const token = header.slice(start, end);
|
|
1897
|
+
if (extensionName === undefined) {
|
|
1898
|
+
push(offers, token, params);
|
|
1899
|
+
} else {
|
|
1900
|
+
if (paramName === undefined) {
|
|
1901
|
+
push(params, token, true);
|
|
1902
|
+
} else if (mustUnescape) {
|
|
1903
|
+
push(params, paramName, token.replace(/\\/g, ""));
|
|
1904
|
+
} else {
|
|
1905
|
+
push(params, paramName, token);
|
|
1906
|
+
}
|
|
1907
|
+
push(offers, extensionName, params);
|
|
1908
|
+
}
|
|
1909
|
+
return offers;
|
|
1910
|
+
}
|
|
1911
|
+
function format(extensions) {
|
|
1912
|
+
return Object.keys(extensions).map((extension2) => {
|
|
1913
|
+
let configurations = extensions[extension2];
|
|
1914
|
+
if (!Array.isArray(configurations))
|
|
1915
|
+
configurations = [configurations];
|
|
1916
|
+
return configurations.map((params) => {
|
|
1917
|
+
return [extension2].concat(Object.keys(params).map((k) => {
|
|
1918
|
+
let values = params[k];
|
|
1919
|
+
if (!Array.isArray(values))
|
|
1920
|
+
values = [values];
|
|
1921
|
+
return values.map((v) => v === true ? k : `${k}=${v}`).join("; ");
|
|
1922
|
+
})).join("; ");
|
|
1923
|
+
}).join(", ");
|
|
1924
|
+
}).join(", ");
|
|
1925
|
+
}
|
|
1926
|
+
module.exports = { format, parse: parse6 };
|
|
1927
|
+
});
|
|
1928
|
+
|
|
1929
|
+
// node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/websocket.js
|
|
1930
|
+
var require_websocket = __commonJS((exports, module) => {
|
|
1931
|
+
var EventEmitter4 = __require("events");
|
|
1932
|
+
var https = __require("https");
|
|
1933
|
+
var http = __require("http");
|
|
1934
|
+
var net = __require("net");
|
|
1935
|
+
var tls = __require("tls");
|
|
1936
|
+
var { randomBytes, createHash } = __require("crypto");
|
|
1937
|
+
var { Duplex, Readable } = __require("stream");
|
|
1938
|
+
var { URL: URL2 } = __require("url");
|
|
1939
|
+
var PerMessageDeflate = require_permessage_deflate();
|
|
1940
|
+
var Receiver = require_receiver();
|
|
1941
|
+
var Sender = require_sender();
|
|
1942
|
+
var { isBlob } = require_validation();
|
|
1943
|
+
var {
|
|
1944
|
+
BINARY_TYPES,
|
|
1945
|
+
CLOSE_TIMEOUT,
|
|
1946
|
+
EMPTY_BUFFER,
|
|
1947
|
+
GUID,
|
|
1948
|
+
kForOnEventAttribute,
|
|
1949
|
+
kListener,
|
|
1950
|
+
kStatusCode,
|
|
1951
|
+
kWebSocket,
|
|
1952
|
+
NOOP
|
|
1953
|
+
} = require_constants();
|
|
1954
|
+
var {
|
|
1955
|
+
EventTarget: { addEventListener, removeEventListener }
|
|
1956
|
+
} = require_event_target();
|
|
1957
|
+
var { format, parse: parse6 } = require_extension();
|
|
1958
|
+
var { toBuffer } = require_buffer_util();
|
|
1959
|
+
var kAborted = Symbol("kAborted");
|
|
1960
|
+
var protocolVersions = [8, 13];
|
|
1961
|
+
var readyStates = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"];
|
|
1962
|
+
var subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
|
|
1963
|
+
|
|
1964
|
+
class WebSocket extends EventEmitter4 {
|
|
1965
|
+
constructor(address, protocols, options) {
|
|
1966
|
+
super();
|
|
1967
|
+
this._binaryType = BINARY_TYPES[0];
|
|
1968
|
+
this._closeCode = 1006;
|
|
1969
|
+
this._closeFrameReceived = false;
|
|
1970
|
+
this._closeFrameSent = false;
|
|
1971
|
+
this._closeMessage = EMPTY_BUFFER;
|
|
1972
|
+
this._closeTimer = null;
|
|
1973
|
+
this._errorEmitted = false;
|
|
1974
|
+
this._extensions = {};
|
|
1975
|
+
this._paused = false;
|
|
1976
|
+
this._protocol = "";
|
|
1977
|
+
this._readyState = WebSocket.CONNECTING;
|
|
1978
|
+
this._receiver = null;
|
|
1979
|
+
this._sender = null;
|
|
1980
|
+
this._socket = null;
|
|
1981
|
+
if (address !== null) {
|
|
1982
|
+
this._bufferedAmount = 0;
|
|
1983
|
+
this._isServer = false;
|
|
1984
|
+
this._redirects = 0;
|
|
1985
|
+
if (protocols === undefined) {
|
|
1986
|
+
protocols = [];
|
|
1987
|
+
} else if (!Array.isArray(protocols)) {
|
|
1988
|
+
if (typeof protocols === "object" && protocols !== null) {
|
|
1989
|
+
options = protocols;
|
|
1990
|
+
protocols = [];
|
|
1991
|
+
} else {
|
|
1992
|
+
protocols = [protocols];
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
initAsClient(this, address, protocols, options);
|
|
1996
|
+
} else {
|
|
1997
|
+
this._autoPong = options.autoPong;
|
|
1998
|
+
this._closeTimeout = options.closeTimeout;
|
|
1999
|
+
this._isServer = true;
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
get binaryType() {
|
|
2003
|
+
return this._binaryType;
|
|
2004
|
+
}
|
|
2005
|
+
set binaryType(type) {
|
|
2006
|
+
if (!BINARY_TYPES.includes(type))
|
|
2007
|
+
return;
|
|
2008
|
+
this._binaryType = type;
|
|
2009
|
+
if (this._receiver)
|
|
2010
|
+
this._receiver._binaryType = type;
|
|
2011
|
+
}
|
|
2012
|
+
get bufferedAmount() {
|
|
2013
|
+
if (!this._socket)
|
|
2014
|
+
return this._bufferedAmount;
|
|
2015
|
+
return this._socket._writableState.length + this._sender._bufferedBytes;
|
|
2016
|
+
}
|
|
2017
|
+
get extensions() {
|
|
2018
|
+
return Object.keys(this._extensions).join();
|
|
2019
|
+
}
|
|
2020
|
+
get isPaused() {
|
|
2021
|
+
return this._paused;
|
|
2022
|
+
}
|
|
2023
|
+
get onclose() {
|
|
2024
|
+
return null;
|
|
2025
|
+
}
|
|
2026
|
+
get onerror() {
|
|
2027
|
+
return null;
|
|
2028
|
+
}
|
|
2029
|
+
get onopen() {
|
|
2030
|
+
return null;
|
|
2031
|
+
}
|
|
2032
|
+
get onmessage() {
|
|
2033
|
+
return null;
|
|
2034
|
+
}
|
|
2035
|
+
get protocol() {
|
|
2036
|
+
return this._protocol;
|
|
2037
|
+
}
|
|
2038
|
+
get readyState() {
|
|
2039
|
+
return this._readyState;
|
|
2040
|
+
}
|
|
2041
|
+
get url() {
|
|
2042
|
+
return this._url;
|
|
2043
|
+
}
|
|
2044
|
+
setSocket(socket, head, options) {
|
|
2045
|
+
const receiver2 = new Receiver({
|
|
2046
|
+
allowSynchronousEvents: options.allowSynchronousEvents,
|
|
2047
|
+
binaryType: this.binaryType,
|
|
2048
|
+
extensions: this._extensions,
|
|
2049
|
+
isServer: this._isServer,
|
|
2050
|
+
maxPayload: options.maxPayload,
|
|
2051
|
+
skipUTF8Validation: options.skipUTF8Validation
|
|
2052
|
+
});
|
|
2053
|
+
const sender2 = new Sender(socket, this._extensions, options.generateMask);
|
|
2054
|
+
this._receiver = receiver2;
|
|
2055
|
+
this._sender = sender2;
|
|
2056
|
+
this._socket = socket;
|
|
2057
|
+
receiver2[kWebSocket] = this;
|
|
2058
|
+
sender2[kWebSocket] = this;
|
|
2059
|
+
socket[kWebSocket] = this;
|
|
2060
|
+
receiver2.on("conclude", receiverOnConclude);
|
|
2061
|
+
receiver2.on("drain", receiverOnDrain);
|
|
2062
|
+
receiver2.on("error", receiverOnError);
|
|
2063
|
+
receiver2.on("message", receiverOnMessage);
|
|
2064
|
+
receiver2.on("ping", receiverOnPing);
|
|
2065
|
+
receiver2.on("pong", receiverOnPong);
|
|
2066
|
+
sender2.onerror = senderOnError;
|
|
2067
|
+
if (socket.setTimeout)
|
|
2068
|
+
socket.setTimeout(0);
|
|
2069
|
+
if (socket.setNoDelay)
|
|
2070
|
+
socket.setNoDelay();
|
|
2071
|
+
if (head.length > 0)
|
|
2072
|
+
socket.unshift(head);
|
|
2073
|
+
socket.on("close", socketOnClose);
|
|
2074
|
+
socket.on("data", socketOnData);
|
|
2075
|
+
socket.on("end", socketOnEnd);
|
|
2076
|
+
socket.on("error", socketOnError);
|
|
2077
|
+
this._readyState = WebSocket.OPEN;
|
|
2078
|
+
this.emit("open");
|
|
2079
|
+
}
|
|
2080
|
+
emitClose() {
|
|
2081
|
+
if (!this._socket) {
|
|
2082
|
+
this._readyState = WebSocket.CLOSED;
|
|
2083
|
+
this.emit("close", this._closeCode, this._closeMessage);
|
|
2084
|
+
return;
|
|
2085
|
+
}
|
|
2086
|
+
if (this._extensions[PerMessageDeflate.extensionName]) {
|
|
2087
|
+
this._extensions[PerMessageDeflate.extensionName].cleanup();
|
|
2088
|
+
}
|
|
2089
|
+
this._receiver.removeAllListeners();
|
|
2090
|
+
this._readyState = WebSocket.CLOSED;
|
|
2091
|
+
this.emit("close", this._closeCode, this._closeMessage);
|
|
2092
|
+
}
|
|
2093
|
+
close(code, data) {
|
|
2094
|
+
if (this.readyState === WebSocket.CLOSED)
|
|
2095
|
+
return;
|
|
2096
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
2097
|
+
const msg = "WebSocket was closed before the connection was established";
|
|
2098
|
+
abortHandshake(this, this._req, msg);
|
|
2099
|
+
return;
|
|
2100
|
+
}
|
|
2101
|
+
if (this.readyState === WebSocket.CLOSING) {
|
|
2102
|
+
if (this._closeFrameSent && (this._closeFrameReceived || this._receiver._writableState.errorEmitted)) {
|
|
2103
|
+
this._socket.end();
|
|
2104
|
+
}
|
|
2105
|
+
return;
|
|
2106
|
+
}
|
|
2107
|
+
this._readyState = WebSocket.CLOSING;
|
|
2108
|
+
this._sender.close(code, data, !this._isServer, (err) => {
|
|
2109
|
+
if (err)
|
|
2110
|
+
return;
|
|
2111
|
+
this._closeFrameSent = true;
|
|
2112
|
+
if (this._closeFrameReceived || this._receiver._writableState.errorEmitted) {
|
|
2113
|
+
this._socket.end();
|
|
2114
|
+
}
|
|
2115
|
+
});
|
|
2116
|
+
setCloseTimer(this);
|
|
2117
|
+
}
|
|
2118
|
+
pause() {
|
|
2119
|
+
if (this.readyState === WebSocket.CONNECTING || this.readyState === WebSocket.CLOSED) {
|
|
2120
|
+
return;
|
|
2121
|
+
}
|
|
2122
|
+
this._paused = true;
|
|
2123
|
+
this._socket.pause();
|
|
2124
|
+
}
|
|
2125
|
+
ping(data, mask, cb) {
|
|
2126
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
2127
|
+
throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
2128
|
+
}
|
|
2129
|
+
if (typeof data === "function") {
|
|
2130
|
+
cb = data;
|
|
2131
|
+
data = mask = undefined;
|
|
2132
|
+
} else if (typeof mask === "function") {
|
|
2133
|
+
cb = mask;
|
|
2134
|
+
mask = undefined;
|
|
2135
|
+
}
|
|
2136
|
+
if (typeof data === "number")
|
|
2137
|
+
data = data.toString();
|
|
2138
|
+
if (this.readyState !== WebSocket.OPEN) {
|
|
2139
|
+
sendAfterClose(this, data, cb);
|
|
2140
|
+
return;
|
|
2141
|
+
}
|
|
2142
|
+
if (mask === undefined)
|
|
2143
|
+
mask = !this._isServer;
|
|
2144
|
+
this._sender.ping(data || EMPTY_BUFFER, mask, cb);
|
|
2145
|
+
}
|
|
2146
|
+
pong(data, mask, cb) {
|
|
2147
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
2148
|
+
throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
2149
|
+
}
|
|
2150
|
+
if (typeof data === "function") {
|
|
2151
|
+
cb = data;
|
|
2152
|
+
data = mask = undefined;
|
|
2153
|
+
} else if (typeof mask === "function") {
|
|
2154
|
+
cb = mask;
|
|
2155
|
+
mask = undefined;
|
|
2156
|
+
}
|
|
2157
|
+
if (typeof data === "number")
|
|
2158
|
+
data = data.toString();
|
|
2159
|
+
if (this.readyState !== WebSocket.OPEN) {
|
|
2160
|
+
sendAfterClose(this, data, cb);
|
|
2161
|
+
return;
|
|
2162
|
+
}
|
|
2163
|
+
if (mask === undefined)
|
|
2164
|
+
mask = !this._isServer;
|
|
2165
|
+
this._sender.pong(data || EMPTY_BUFFER, mask, cb);
|
|
2166
|
+
}
|
|
2167
|
+
resume() {
|
|
2168
|
+
if (this.readyState === WebSocket.CONNECTING || this.readyState === WebSocket.CLOSED) {
|
|
2169
|
+
return;
|
|
2170
|
+
}
|
|
2171
|
+
this._paused = false;
|
|
2172
|
+
if (!this._receiver._writableState.needDrain)
|
|
2173
|
+
this._socket.resume();
|
|
2174
|
+
}
|
|
2175
|
+
send(data, options, cb) {
|
|
2176
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
2177
|
+
throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
2178
|
+
}
|
|
2179
|
+
if (typeof options === "function") {
|
|
2180
|
+
cb = options;
|
|
2181
|
+
options = {};
|
|
2182
|
+
}
|
|
2183
|
+
if (typeof data === "number")
|
|
2184
|
+
data = data.toString();
|
|
2185
|
+
if (this.readyState !== WebSocket.OPEN) {
|
|
2186
|
+
sendAfterClose(this, data, cb);
|
|
2187
|
+
return;
|
|
2188
|
+
}
|
|
2189
|
+
const opts = {
|
|
2190
|
+
binary: typeof data !== "string",
|
|
2191
|
+
mask: !this._isServer,
|
|
2192
|
+
compress: true,
|
|
2193
|
+
fin: true,
|
|
2194
|
+
...options
|
|
2195
|
+
};
|
|
2196
|
+
if (!this._extensions[PerMessageDeflate.extensionName]) {
|
|
2197
|
+
opts.compress = false;
|
|
2198
|
+
}
|
|
2199
|
+
this._sender.send(data || EMPTY_BUFFER, opts, cb);
|
|
2200
|
+
}
|
|
2201
|
+
terminate() {
|
|
2202
|
+
if (this.readyState === WebSocket.CLOSED)
|
|
2203
|
+
return;
|
|
2204
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
2205
|
+
const msg = "WebSocket was closed before the connection was established";
|
|
2206
|
+
abortHandshake(this, this._req, msg);
|
|
2207
|
+
return;
|
|
2208
|
+
}
|
|
2209
|
+
if (this._socket) {
|
|
2210
|
+
this._readyState = WebSocket.CLOSING;
|
|
2211
|
+
this._socket.destroy();
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
Object.defineProperty(WebSocket, "CONNECTING", {
|
|
2216
|
+
enumerable: true,
|
|
2217
|
+
value: readyStates.indexOf("CONNECTING")
|
|
2218
|
+
});
|
|
2219
|
+
Object.defineProperty(WebSocket.prototype, "CONNECTING", {
|
|
2220
|
+
enumerable: true,
|
|
2221
|
+
value: readyStates.indexOf("CONNECTING")
|
|
2222
|
+
});
|
|
2223
|
+
Object.defineProperty(WebSocket, "OPEN", {
|
|
2224
|
+
enumerable: true,
|
|
2225
|
+
value: readyStates.indexOf("OPEN")
|
|
2226
|
+
});
|
|
2227
|
+
Object.defineProperty(WebSocket.prototype, "OPEN", {
|
|
2228
|
+
enumerable: true,
|
|
2229
|
+
value: readyStates.indexOf("OPEN")
|
|
2230
|
+
});
|
|
2231
|
+
Object.defineProperty(WebSocket, "CLOSING", {
|
|
2232
|
+
enumerable: true,
|
|
2233
|
+
value: readyStates.indexOf("CLOSING")
|
|
2234
|
+
});
|
|
2235
|
+
Object.defineProperty(WebSocket.prototype, "CLOSING", {
|
|
2236
|
+
enumerable: true,
|
|
2237
|
+
value: readyStates.indexOf("CLOSING")
|
|
2238
|
+
});
|
|
2239
|
+
Object.defineProperty(WebSocket, "CLOSED", {
|
|
2240
|
+
enumerable: true,
|
|
2241
|
+
value: readyStates.indexOf("CLOSED")
|
|
2242
|
+
});
|
|
2243
|
+
Object.defineProperty(WebSocket.prototype, "CLOSED", {
|
|
2244
|
+
enumerable: true,
|
|
2245
|
+
value: readyStates.indexOf("CLOSED")
|
|
2246
|
+
});
|
|
2247
|
+
[
|
|
2248
|
+
"binaryType",
|
|
2249
|
+
"bufferedAmount",
|
|
2250
|
+
"extensions",
|
|
2251
|
+
"isPaused",
|
|
2252
|
+
"protocol",
|
|
2253
|
+
"readyState",
|
|
2254
|
+
"url"
|
|
2255
|
+
].forEach((property) => {
|
|
2256
|
+
Object.defineProperty(WebSocket.prototype, property, { enumerable: true });
|
|
2257
|
+
});
|
|
2258
|
+
["open", "error", "close", "message"].forEach((method) => {
|
|
2259
|
+
Object.defineProperty(WebSocket.prototype, `on${method}`, {
|
|
2260
|
+
enumerable: true,
|
|
2261
|
+
get() {
|
|
2262
|
+
for (const listener of this.listeners(method)) {
|
|
2263
|
+
if (listener[kForOnEventAttribute])
|
|
2264
|
+
return listener[kListener];
|
|
2265
|
+
}
|
|
2266
|
+
return null;
|
|
2267
|
+
},
|
|
2268
|
+
set(handler) {
|
|
2269
|
+
for (const listener of this.listeners(method)) {
|
|
2270
|
+
if (listener[kForOnEventAttribute]) {
|
|
2271
|
+
this.removeListener(method, listener);
|
|
2272
|
+
break;
|
|
2273
|
+
}
|
|
2274
|
+
}
|
|
2275
|
+
if (typeof handler !== "function")
|
|
2276
|
+
return;
|
|
2277
|
+
this.addEventListener(method, handler, {
|
|
2278
|
+
[kForOnEventAttribute]: true
|
|
2279
|
+
});
|
|
2280
|
+
}
|
|
2281
|
+
});
|
|
2282
|
+
});
|
|
2283
|
+
WebSocket.prototype.addEventListener = addEventListener;
|
|
2284
|
+
WebSocket.prototype.removeEventListener = removeEventListener;
|
|
2285
|
+
module.exports = WebSocket;
|
|
2286
|
+
function initAsClient(websocket2, address, protocols, options) {
|
|
2287
|
+
const opts = {
|
|
2288
|
+
allowSynchronousEvents: true,
|
|
2289
|
+
autoPong: true,
|
|
2290
|
+
closeTimeout: CLOSE_TIMEOUT,
|
|
2291
|
+
protocolVersion: protocolVersions[1],
|
|
2292
|
+
maxPayload: 100 * 1024 * 1024,
|
|
2293
|
+
skipUTF8Validation: false,
|
|
2294
|
+
perMessageDeflate: true,
|
|
2295
|
+
followRedirects: false,
|
|
2296
|
+
maxRedirects: 10,
|
|
2297
|
+
...options,
|
|
2298
|
+
socketPath: undefined,
|
|
2299
|
+
hostname: undefined,
|
|
2300
|
+
protocol: undefined,
|
|
2301
|
+
timeout: undefined,
|
|
2302
|
+
method: "GET",
|
|
2303
|
+
host: undefined,
|
|
2304
|
+
path: undefined,
|
|
2305
|
+
port: undefined
|
|
2306
|
+
};
|
|
2307
|
+
websocket2._autoPong = opts.autoPong;
|
|
2308
|
+
websocket2._closeTimeout = opts.closeTimeout;
|
|
2309
|
+
if (!protocolVersions.includes(opts.protocolVersion)) {
|
|
2310
|
+
throw new RangeError(`Unsupported protocol version: ${opts.protocolVersion} ` + `(supported versions: ${protocolVersions.join(", ")})`);
|
|
2311
|
+
}
|
|
2312
|
+
let parsedUrl;
|
|
2313
|
+
if (address instanceof URL2) {
|
|
2314
|
+
parsedUrl = address;
|
|
2315
|
+
} else {
|
|
2316
|
+
try {
|
|
2317
|
+
parsedUrl = new URL2(address);
|
|
2318
|
+
} catch (e) {
|
|
2319
|
+
throw new SyntaxError(`Invalid URL: ${address}`);
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
if (parsedUrl.protocol === "http:") {
|
|
2323
|
+
parsedUrl.protocol = "ws:";
|
|
2324
|
+
} else if (parsedUrl.protocol === "https:") {
|
|
2325
|
+
parsedUrl.protocol = "wss:";
|
|
2326
|
+
}
|
|
2327
|
+
websocket2._url = parsedUrl.href;
|
|
2328
|
+
const isSecure = parsedUrl.protocol === "wss:";
|
|
2329
|
+
const isIpcUrl = parsedUrl.protocol === "ws+unix:";
|
|
2330
|
+
let invalidUrlMessage;
|
|
2331
|
+
if (parsedUrl.protocol !== "ws:" && !isSecure && !isIpcUrl) {
|
|
2332
|
+
invalidUrlMessage = `The URL's protocol must be one of "ws:", "wss:", ` + '"http:", "https:", or "ws+unix:"';
|
|
2333
|
+
} else if (isIpcUrl && !parsedUrl.pathname) {
|
|
2334
|
+
invalidUrlMessage = "The URL's pathname is empty";
|
|
2335
|
+
} else if (parsedUrl.hash) {
|
|
2336
|
+
invalidUrlMessage = "The URL contains a fragment identifier";
|
|
2337
|
+
}
|
|
2338
|
+
if (invalidUrlMessage) {
|
|
2339
|
+
const err = new SyntaxError(invalidUrlMessage);
|
|
2340
|
+
if (websocket2._redirects === 0) {
|
|
2341
|
+
throw err;
|
|
2342
|
+
} else {
|
|
2343
|
+
emitErrorAndClose(websocket2, err);
|
|
2344
|
+
return;
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
const defaultPort = isSecure ? 443 : 80;
|
|
2348
|
+
const key = randomBytes(16).toString("base64");
|
|
2349
|
+
const request = isSecure ? https.request : http.request;
|
|
2350
|
+
const protocolSet = new Set;
|
|
2351
|
+
let perMessageDeflate;
|
|
2352
|
+
opts.createConnection = opts.createConnection || (isSecure ? tlsConnect : netConnect);
|
|
2353
|
+
opts.defaultPort = opts.defaultPort || defaultPort;
|
|
2354
|
+
opts.port = parsedUrl.port || defaultPort;
|
|
2355
|
+
opts.host = parsedUrl.hostname.startsWith("[") ? parsedUrl.hostname.slice(1, -1) : parsedUrl.hostname;
|
|
2356
|
+
opts.headers = {
|
|
2357
|
+
...opts.headers,
|
|
2358
|
+
"Sec-WebSocket-Version": opts.protocolVersion,
|
|
2359
|
+
"Sec-WebSocket-Key": key,
|
|
2360
|
+
Connection: "Upgrade",
|
|
2361
|
+
Upgrade: "websocket"
|
|
2362
|
+
};
|
|
2363
|
+
opts.path = parsedUrl.pathname + parsedUrl.search;
|
|
2364
|
+
opts.timeout = opts.handshakeTimeout;
|
|
2365
|
+
if (opts.perMessageDeflate) {
|
|
2366
|
+
perMessageDeflate = new PerMessageDeflate(opts.perMessageDeflate !== true ? opts.perMessageDeflate : {}, false, opts.maxPayload);
|
|
2367
|
+
opts.headers["Sec-WebSocket-Extensions"] = format({
|
|
2368
|
+
[PerMessageDeflate.extensionName]: perMessageDeflate.offer()
|
|
2369
|
+
});
|
|
2370
|
+
}
|
|
2371
|
+
if (protocols.length) {
|
|
2372
|
+
for (const protocol of protocols) {
|
|
2373
|
+
if (typeof protocol !== "string" || !subprotocolRegex.test(protocol) || protocolSet.has(protocol)) {
|
|
2374
|
+
throw new SyntaxError("An invalid or duplicated subprotocol was specified");
|
|
2375
|
+
}
|
|
2376
|
+
protocolSet.add(protocol);
|
|
2377
|
+
}
|
|
2378
|
+
opts.headers["Sec-WebSocket-Protocol"] = protocols.join(",");
|
|
2379
|
+
}
|
|
2380
|
+
if (opts.origin) {
|
|
2381
|
+
if (opts.protocolVersion < 13) {
|
|
2382
|
+
opts.headers["Sec-WebSocket-Origin"] = opts.origin;
|
|
2383
|
+
} else {
|
|
2384
|
+
opts.headers.Origin = opts.origin;
|
|
2385
|
+
}
|
|
2386
|
+
}
|
|
2387
|
+
if (parsedUrl.username || parsedUrl.password) {
|
|
2388
|
+
opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
|
|
2389
|
+
}
|
|
2390
|
+
if (isIpcUrl) {
|
|
2391
|
+
const parts = opts.path.split(":");
|
|
2392
|
+
opts.socketPath = parts[0];
|
|
2393
|
+
opts.path = parts[1];
|
|
2394
|
+
}
|
|
2395
|
+
let req;
|
|
2396
|
+
if (opts.followRedirects) {
|
|
2397
|
+
if (websocket2._redirects === 0) {
|
|
2398
|
+
websocket2._originalIpc = isIpcUrl;
|
|
2399
|
+
websocket2._originalSecure = isSecure;
|
|
2400
|
+
websocket2._originalHostOrSocketPath = isIpcUrl ? opts.socketPath : parsedUrl.host;
|
|
2401
|
+
const headers = options && options.headers;
|
|
2402
|
+
options = { ...options, headers: {} };
|
|
2403
|
+
if (headers) {
|
|
2404
|
+
for (const [key2, value] of Object.entries(headers)) {
|
|
2405
|
+
options.headers[key2.toLowerCase()] = value;
|
|
2406
|
+
}
|
|
2407
|
+
}
|
|
2408
|
+
} else if (websocket2.listenerCount("redirect") === 0) {
|
|
2409
|
+
const isSameHost = isIpcUrl ? websocket2._originalIpc ? opts.socketPath === websocket2._originalHostOrSocketPath : false : websocket2._originalIpc ? false : parsedUrl.host === websocket2._originalHostOrSocketPath;
|
|
2410
|
+
if (!isSameHost || websocket2._originalSecure && !isSecure) {
|
|
2411
|
+
delete opts.headers.authorization;
|
|
2412
|
+
delete opts.headers.cookie;
|
|
2413
|
+
if (!isSameHost)
|
|
2414
|
+
delete opts.headers.host;
|
|
2415
|
+
opts.auth = undefined;
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
if (opts.auth && !options.headers.authorization) {
|
|
2419
|
+
options.headers.authorization = "Basic " + Buffer.from(opts.auth).toString("base64");
|
|
2420
|
+
}
|
|
2421
|
+
req = websocket2._req = request(opts);
|
|
2422
|
+
if (websocket2._redirects) {
|
|
2423
|
+
websocket2.emit("redirect", websocket2.url, req);
|
|
2424
|
+
}
|
|
2425
|
+
} else {
|
|
2426
|
+
req = websocket2._req = request(opts);
|
|
2427
|
+
}
|
|
2428
|
+
if (opts.timeout) {
|
|
2429
|
+
req.on("timeout", () => {
|
|
2430
|
+
abortHandshake(websocket2, req, "Opening handshake has timed out");
|
|
2431
|
+
});
|
|
2432
|
+
}
|
|
2433
|
+
req.on("error", (err) => {
|
|
2434
|
+
if (req === null || req[kAborted])
|
|
2435
|
+
return;
|
|
2436
|
+
req = websocket2._req = null;
|
|
2437
|
+
emitErrorAndClose(websocket2, err);
|
|
2438
|
+
});
|
|
2439
|
+
req.on("response", (res) => {
|
|
2440
|
+
const location2 = res.headers.location;
|
|
2441
|
+
const statusCode = res.statusCode;
|
|
2442
|
+
if (location2 && opts.followRedirects && statusCode >= 300 && statusCode < 400) {
|
|
2443
|
+
if (++websocket2._redirects > opts.maxRedirects) {
|
|
2444
|
+
abortHandshake(websocket2, req, "Maximum redirects exceeded");
|
|
2445
|
+
return;
|
|
2446
|
+
}
|
|
2447
|
+
req.abort();
|
|
2448
|
+
let addr;
|
|
2449
|
+
try {
|
|
2450
|
+
addr = new URL2(location2, address);
|
|
2451
|
+
} catch (e) {
|
|
2452
|
+
const err = new SyntaxError(`Invalid URL: ${location2}`);
|
|
2453
|
+
emitErrorAndClose(websocket2, err);
|
|
2454
|
+
return;
|
|
2455
|
+
}
|
|
2456
|
+
initAsClient(websocket2, addr, protocols, options);
|
|
2457
|
+
} else if (!websocket2.emit("unexpected-response", req, res)) {
|
|
2458
|
+
abortHandshake(websocket2, req, `Unexpected server response: ${res.statusCode}`);
|
|
2459
|
+
}
|
|
2460
|
+
});
|
|
2461
|
+
req.on("upgrade", (res, socket, head) => {
|
|
2462
|
+
websocket2.emit("upgrade", res);
|
|
2463
|
+
if (websocket2.readyState !== WebSocket.CONNECTING)
|
|
2464
|
+
return;
|
|
2465
|
+
req = websocket2._req = null;
|
|
2466
|
+
const upgrade = res.headers.upgrade;
|
|
2467
|
+
if (upgrade === undefined || upgrade.toLowerCase() !== "websocket") {
|
|
2468
|
+
abortHandshake(websocket2, socket, "Invalid Upgrade header");
|
|
2469
|
+
return;
|
|
2470
|
+
}
|
|
2471
|
+
const digest = createHash("sha1").update(key + GUID).digest("base64");
|
|
2472
|
+
if (res.headers["sec-websocket-accept"] !== digest) {
|
|
2473
|
+
abortHandshake(websocket2, socket, "Invalid Sec-WebSocket-Accept header");
|
|
2474
|
+
return;
|
|
2475
|
+
}
|
|
2476
|
+
const serverProt = res.headers["sec-websocket-protocol"];
|
|
2477
|
+
let protError;
|
|
2478
|
+
if (serverProt !== undefined) {
|
|
2479
|
+
if (!protocolSet.size) {
|
|
2480
|
+
protError = "Server sent a subprotocol but none was requested";
|
|
2481
|
+
} else if (!protocolSet.has(serverProt)) {
|
|
2482
|
+
protError = "Server sent an invalid subprotocol";
|
|
2483
|
+
}
|
|
2484
|
+
} else if (protocolSet.size) {
|
|
2485
|
+
protError = "Server sent no subprotocol";
|
|
2486
|
+
}
|
|
2487
|
+
if (protError) {
|
|
2488
|
+
abortHandshake(websocket2, socket, protError);
|
|
2489
|
+
return;
|
|
2490
|
+
}
|
|
2491
|
+
if (serverProt)
|
|
2492
|
+
websocket2._protocol = serverProt;
|
|
2493
|
+
const secWebSocketExtensions = res.headers["sec-websocket-extensions"];
|
|
2494
|
+
if (secWebSocketExtensions !== undefined) {
|
|
2495
|
+
if (!perMessageDeflate) {
|
|
2496
|
+
const message = "Server sent a Sec-WebSocket-Extensions header but no extension " + "was requested";
|
|
2497
|
+
abortHandshake(websocket2, socket, message);
|
|
2498
|
+
return;
|
|
2499
|
+
}
|
|
2500
|
+
let extensions;
|
|
2501
|
+
try {
|
|
2502
|
+
extensions = parse6(secWebSocketExtensions);
|
|
2503
|
+
} catch (err) {
|
|
2504
|
+
const message = "Invalid Sec-WebSocket-Extensions header";
|
|
2505
|
+
abortHandshake(websocket2, socket, message);
|
|
2506
|
+
return;
|
|
2507
|
+
}
|
|
2508
|
+
const extensionNames = Object.keys(extensions);
|
|
2509
|
+
if (extensionNames.length !== 1 || extensionNames[0] !== PerMessageDeflate.extensionName) {
|
|
2510
|
+
const message = "Server indicated an extension that was not requested";
|
|
2511
|
+
abortHandshake(websocket2, socket, message);
|
|
2512
|
+
return;
|
|
2513
|
+
}
|
|
2514
|
+
try {
|
|
2515
|
+
perMessageDeflate.accept(extensions[PerMessageDeflate.extensionName]);
|
|
2516
|
+
} catch (err) {
|
|
2517
|
+
const message = "Invalid Sec-WebSocket-Extensions header";
|
|
2518
|
+
abortHandshake(websocket2, socket, message);
|
|
2519
|
+
return;
|
|
2520
|
+
}
|
|
2521
|
+
websocket2._extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
|
|
2522
|
+
}
|
|
2523
|
+
websocket2.setSocket(socket, head, {
|
|
2524
|
+
allowSynchronousEvents: opts.allowSynchronousEvents,
|
|
2525
|
+
generateMask: opts.generateMask,
|
|
2526
|
+
maxPayload: opts.maxPayload,
|
|
2527
|
+
skipUTF8Validation: opts.skipUTF8Validation
|
|
2528
|
+
});
|
|
2529
|
+
});
|
|
2530
|
+
if (opts.finishRequest) {
|
|
2531
|
+
opts.finishRequest(req, websocket2);
|
|
2532
|
+
} else {
|
|
2533
|
+
req.end();
|
|
2534
|
+
}
|
|
2535
|
+
}
|
|
2536
|
+
function emitErrorAndClose(websocket2, err) {
|
|
2537
|
+
websocket2._readyState = WebSocket.CLOSING;
|
|
2538
|
+
websocket2._errorEmitted = true;
|
|
2539
|
+
websocket2.emit("error", err);
|
|
2540
|
+
websocket2.emitClose();
|
|
2541
|
+
}
|
|
2542
|
+
function netConnect(options) {
|
|
2543
|
+
options.path = options.socketPath;
|
|
2544
|
+
return net.connect(options);
|
|
2545
|
+
}
|
|
2546
|
+
function tlsConnect(options) {
|
|
2547
|
+
options.path = undefined;
|
|
2548
|
+
if (!options.servername && options.servername !== "") {
|
|
2549
|
+
options.servername = net.isIP(options.host) ? "" : options.host;
|
|
2550
|
+
}
|
|
2551
|
+
return tls.connect(options);
|
|
2552
|
+
}
|
|
2553
|
+
function abortHandshake(websocket2, stream2, message) {
|
|
2554
|
+
websocket2._readyState = WebSocket.CLOSING;
|
|
2555
|
+
const err = new Error(message);
|
|
2556
|
+
Error.captureStackTrace(err, abortHandshake);
|
|
2557
|
+
if (stream2.setHeader) {
|
|
2558
|
+
stream2[kAborted] = true;
|
|
2559
|
+
stream2.abort();
|
|
2560
|
+
if (stream2.socket && !stream2.socket.destroyed) {
|
|
2561
|
+
stream2.socket.destroy();
|
|
2562
|
+
}
|
|
2563
|
+
process.nextTick(emitErrorAndClose, websocket2, err);
|
|
2564
|
+
} else {
|
|
2565
|
+
stream2.destroy(err);
|
|
2566
|
+
stream2.once("error", websocket2.emit.bind(websocket2, "error"));
|
|
2567
|
+
stream2.once("close", websocket2.emitClose.bind(websocket2));
|
|
2568
|
+
}
|
|
2569
|
+
}
|
|
2570
|
+
function sendAfterClose(websocket2, data, cb) {
|
|
2571
|
+
if (data) {
|
|
2572
|
+
const length = isBlob(data) ? data.size : toBuffer(data).length;
|
|
2573
|
+
if (websocket2._socket)
|
|
2574
|
+
websocket2._sender._bufferedBytes += length;
|
|
2575
|
+
else
|
|
2576
|
+
websocket2._bufferedAmount += length;
|
|
2577
|
+
}
|
|
2578
|
+
if (cb) {
|
|
2579
|
+
const err = new Error(`WebSocket is not open: readyState ${websocket2.readyState} ` + `(${readyStates[websocket2.readyState]})`);
|
|
2580
|
+
process.nextTick(cb, err);
|
|
2581
|
+
}
|
|
2582
|
+
}
|
|
2583
|
+
function receiverOnConclude(code, reason) {
|
|
2584
|
+
const websocket2 = this[kWebSocket];
|
|
2585
|
+
websocket2._closeFrameReceived = true;
|
|
2586
|
+
websocket2._closeMessage = reason;
|
|
2587
|
+
websocket2._closeCode = code;
|
|
2588
|
+
if (websocket2._socket[kWebSocket] === undefined)
|
|
2589
|
+
return;
|
|
2590
|
+
websocket2._socket.removeListener("data", socketOnData);
|
|
2591
|
+
process.nextTick(resume, websocket2._socket);
|
|
2592
|
+
if (code === 1005)
|
|
2593
|
+
websocket2.close();
|
|
2594
|
+
else
|
|
2595
|
+
websocket2.close(code, reason);
|
|
2596
|
+
}
|
|
2597
|
+
function receiverOnDrain() {
|
|
2598
|
+
const websocket2 = this[kWebSocket];
|
|
2599
|
+
if (!websocket2.isPaused)
|
|
2600
|
+
websocket2._socket.resume();
|
|
2601
|
+
}
|
|
2602
|
+
function receiverOnError(err) {
|
|
2603
|
+
const websocket2 = this[kWebSocket];
|
|
2604
|
+
if (websocket2._socket[kWebSocket] !== undefined) {
|
|
2605
|
+
websocket2._socket.removeListener("data", socketOnData);
|
|
2606
|
+
process.nextTick(resume, websocket2._socket);
|
|
2607
|
+
websocket2.close(err[kStatusCode]);
|
|
2608
|
+
}
|
|
2609
|
+
if (!websocket2._errorEmitted) {
|
|
2610
|
+
websocket2._errorEmitted = true;
|
|
2611
|
+
websocket2.emit("error", err);
|
|
2612
|
+
}
|
|
2613
|
+
}
|
|
2614
|
+
function receiverOnFinish() {
|
|
2615
|
+
this[kWebSocket].emitClose();
|
|
2616
|
+
}
|
|
2617
|
+
function receiverOnMessage(data, isBinary) {
|
|
2618
|
+
this[kWebSocket].emit("message", data, isBinary);
|
|
2619
|
+
}
|
|
2620
|
+
function receiverOnPing(data) {
|
|
2621
|
+
const websocket2 = this[kWebSocket];
|
|
2622
|
+
if (websocket2._autoPong)
|
|
2623
|
+
websocket2.pong(data, !this._isServer, NOOP);
|
|
2624
|
+
websocket2.emit("ping", data);
|
|
2625
|
+
}
|
|
2626
|
+
function receiverOnPong(data) {
|
|
2627
|
+
this[kWebSocket].emit("pong", data);
|
|
2628
|
+
}
|
|
2629
|
+
function resume(stream2) {
|
|
2630
|
+
stream2.resume();
|
|
2631
|
+
}
|
|
2632
|
+
function senderOnError(err) {
|
|
2633
|
+
const websocket2 = this[kWebSocket];
|
|
2634
|
+
if (websocket2.readyState === WebSocket.CLOSED)
|
|
2635
|
+
return;
|
|
2636
|
+
if (websocket2.readyState === WebSocket.OPEN) {
|
|
2637
|
+
websocket2._readyState = WebSocket.CLOSING;
|
|
2638
|
+
setCloseTimer(websocket2);
|
|
2639
|
+
}
|
|
2640
|
+
this._socket.end();
|
|
2641
|
+
if (!websocket2._errorEmitted) {
|
|
2642
|
+
websocket2._errorEmitted = true;
|
|
2643
|
+
websocket2.emit("error", err);
|
|
2644
|
+
}
|
|
2645
|
+
}
|
|
2646
|
+
function setCloseTimer(websocket2) {
|
|
2647
|
+
websocket2._closeTimer = setTimeout(websocket2._socket.destroy.bind(websocket2._socket), websocket2._closeTimeout);
|
|
2648
|
+
}
|
|
2649
|
+
function socketOnClose() {
|
|
2650
|
+
const websocket2 = this[kWebSocket];
|
|
2651
|
+
this.removeListener("close", socketOnClose);
|
|
2652
|
+
this.removeListener("data", socketOnData);
|
|
2653
|
+
this.removeListener("end", socketOnEnd);
|
|
2654
|
+
websocket2._readyState = WebSocket.CLOSING;
|
|
2655
|
+
if (!this._readableState.endEmitted && !websocket2._closeFrameReceived && !websocket2._receiver._writableState.errorEmitted && this._readableState.length !== 0) {
|
|
2656
|
+
const chunk = this.read(this._readableState.length);
|
|
2657
|
+
websocket2._receiver.write(chunk);
|
|
2658
|
+
}
|
|
2659
|
+
websocket2._receiver.end();
|
|
2660
|
+
this[kWebSocket] = undefined;
|
|
2661
|
+
clearTimeout(websocket2._closeTimer);
|
|
2662
|
+
if (websocket2._receiver._writableState.finished || websocket2._receiver._writableState.errorEmitted) {
|
|
2663
|
+
websocket2.emitClose();
|
|
2664
|
+
} else {
|
|
2665
|
+
websocket2._receiver.on("error", receiverOnFinish);
|
|
2666
|
+
websocket2._receiver.on("finish", receiverOnFinish);
|
|
2667
|
+
}
|
|
2668
|
+
}
|
|
2669
|
+
function socketOnData(chunk) {
|
|
2670
|
+
if (!this[kWebSocket]._receiver.write(chunk)) {
|
|
2671
|
+
this.pause();
|
|
2672
|
+
}
|
|
2673
|
+
}
|
|
2674
|
+
function socketOnEnd() {
|
|
2675
|
+
const websocket2 = this[kWebSocket];
|
|
2676
|
+
websocket2._readyState = WebSocket.CLOSING;
|
|
2677
|
+
websocket2._receiver.end();
|
|
2678
|
+
this.end();
|
|
2679
|
+
}
|
|
2680
|
+
function socketOnError() {
|
|
2681
|
+
const websocket2 = this[kWebSocket];
|
|
2682
|
+
this.removeListener("error", socketOnError);
|
|
2683
|
+
this.on("error", NOOP);
|
|
2684
|
+
if (websocket2) {
|
|
2685
|
+
websocket2._readyState = WebSocket.CLOSING;
|
|
2686
|
+
this.destroy();
|
|
2687
|
+
}
|
|
2688
|
+
}
|
|
2689
|
+
});
|
|
2690
|
+
|
|
2691
|
+
// node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/stream.js
|
|
2692
|
+
var require_stream = __commonJS((exports, module) => {
|
|
2693
|
+
var WebSocket = require_websocket();
|
|
2694
|
+
var { Duplex } = __require("stream");
|
|
2695
|
+
function emitClose(stream2) {
|
|
2696
|
+
stream2.emit("close");
|
|
2697
|
+
}
|
|
2698
|
+
function duplexOnEnd() {
|
|
2699
|
+
if (!this.destroyed && this._writableState.finished) {
|
|
2700
|
+
this.destroy();
|
|
2701
|
+
}
|
|
2702
|
+
}
|
|
2703
|
+
function duplexOnError(err) {
|
|
2704
|
+
this.removeListener("error", duplexOnError);
|
|
2705
|
+
this.destroy();
|
|
2706
|
+
if (this.listenerCount("error") === 0) {
|
|
2707
|
+
this.emit("error", err);
|
|
2708
|
+
}
|
|
2709
|
+
}
|
|
2710
|
+
function createWebSocketStream(ws, options) {
|
|
2711
|
+
let terminateOnDestroy = true;
|
|
2712
|
+
const duplex = new Duplex({
|
|
2713
|
+
...options,
|
|
2714
|
+
autoDestroy: false,
|
|
2715
|
+
emitClose: false,
|
|
2716
|
+
objectMode: false,
|
|
2717
|
+
writableObjectMode: false
|
|
2718
|
+
});
|
|
2719
|
+
ws.on("message", function message(msg, isBinary) {
|
|
2720
|
+
const data = !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
|
|
2721
|
+
if (!duplex.push(data))
|
|
2722
|
+
ws.pause();
|
|
2723
|
+
});
|
|
2724
|
+
ws.once("error", function error49(err) {
|
|
2725
|
+
if (duplex.destroyed)
|
|
2726
|
+
return;
|
|
2727
|
+
terminateOnDestroy = false;
|
|
2728
|
+
duplex.destroy(err);
|
|
2729
|
+
});
|
|
2730
|
+
ws.once("close", function close() {
|
|
2731
|
+
if (duplex.destroyed)
|
|
2732
|
+
return;
|
|
2733
|
+
duplex.push(null);
|
|
2734
|
+
});
|
|
2735
|
+
duplex._destroy = function(err, callback) {
|
|
2736
|
+
if (ws.readyState === ws.CLOSED) {
|
|
2737
|
+
callback(err);
|
|
2738
|
+
process.nextTick(emitClose, duplex);
|
|
2739
|
+
return;
|
|
2740
|
+
}
|
|
2741
|
+
let called = false;
|
|
2742
|
+
ws.once("error", function error49(err2) {
|
|
2743
|
+
called = true;
|
|
2744
|
+
callback(err2);
|
|
2745
|
+
});
|
|
2746
|
+
ws.once("close", function close() {
|
|
2747
|
+
if (!called)
|
|
2748
|
+
callback(err);
|
|
2749
|
+
process.nextTick(emitClose, duplex);
|
|
2750
|
+
});
|
|
2751
|
+
if (terminateOnDestroy)
|
|
2752
|
+
ws.terminate();
|
|
2753
|
+
};
|
|
2754
|
+
duplex._final = function(callback) {
|
|
2755
|
+
if (ws.readyState === ws.CONNECTING) {
|
|
2756
|
+
ws.once("open", function open() {
|
|
2757
|
+
duplex._final(callback);
|
|
2758
|
+
});
|
|
2759
|
+
return;
|
|
2760
|
+
}
|
|
2761
|
+
if (ws._socket === null)
|
|
2762
|
+
return;
|
|
2763
|
+
if (ws._socket._writableState.finished) {
|
|
2764
|
+
callback();
|
|
2765
|
+
if (duplex._readableState.endEmitted)
|
|
2766
|
+
duplex.destroy();
|
|
2767
|
+
} else {
|
|
2768
|
+
ws._socket.once("finish", function finish() {
|
|
2769
|
+
callback();
|
|
2770
|
+
});
|
|
2771
|
+
ws.close();
|
|
2772
|
+
}
|
|
2773
|
+
};
|
|
2774
|
+
duplex._read = function() {
|
|
2775
|
+
if (ws.isPaused)
|
|
2776
|
+
ws.resume();
|
|
2777
|
+
};
|
|
2778
|
+
duplex._write = function(chunk, encoding, callback) {
|
|
2779
|
+
if (ws.readyState === ws.CONNECTING) {
|
|
2780
|
+
ws.once("open", function open() {
|
|
2781
|
+
duplex._write(chunk, encoding, callback);
|
|
2782
|
+
});
|
|
2783
|
+
return;
|
|
2784
|
+
}
|
|
2785
|
+
ws.send(chunk, callback);
|
|
2786
|
+
};
|
|
2787
|
+
duplex.on("end", duplexOnEnd);
|
|
2788
|
+
duplex.on("error", duplexOnError);
|
|
2789
|
+
return duplex;
|
|
2790
|
+
}
|
|
2791
|
+
module.exports = createWebSocketStream;
|
|
2792
|
+
});
|
|
2793
|
+
|
|
2794
|
+
// node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/subprotocol.js
|
|
2795
|
+
var require_subprotocol = __commonJS((exports, module) => {
|
|
2796
|
+
var { tokenChars } = require_validation();
|
|
2797
|
+
function parse6(header) {
|
|
2798
|
+
const protocols = new Set;
|
|
2799
|
+
let start = -1;
|
|
2800
|
+
let end = -1;
|
|
2801
|
+
let i = 0;
|
|
2802
|
+
for (i;i < header.length; i++) {
|
|
2803
|
+
const code = header.charCodeAt(i);
|
|
2804
|
+
if (end === -1 && tokenChars[code] === 1) {
|
|
2805
|
+
if (start === -1)
|
|
2806
|
+
start = i;
|
|
2807
|
+
} else if (i !== 0 && (code === 32 || code === 9)) {
|
|
2808
|
+
if (end === -1 && start !== -1)
|
|
2809
|
+
end = i;
|
|
2810
|
+
} else if (code === 44) {
|
|
2811
|
+
if (start === -1) {
|
|
2812
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
2813
|
+
}
|
|
2814
|
+
if (end === -1)
|
|
2815
|
+
end = i;
|
|
2816
|
+
const protocol2 = header.slice(start, end);
|
|
2817
|
+
if (protocols.has(protocol2)) {
|
|
2818
|
+
throw new SyntaxError(`The "${protocol2}" subprotocol is duplicated`);
|
|
2819
|
+
}
|
|
2820
|
+
protocols.add(protocol2);
|
|
2821
|
+
start = end = -1;
|
|
2822
|
+
} else {
|
|
2823
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
2824
|
+
}
|
|
2825
|
+
}
|
|
2826
|
+
if (start === -1 || end !== -1) {
|
|
2827
|
+
throw new SyntaxError("Unexpected end of input");
|
|
2828
|
+
}
|
|
2829
|
+
const protocol = header.slice(start, i);
|
|
2830
|
+
if (protocols.has(protocol)) {
|
|
2831
|
+
throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
|
|
2832
|
+
}
|
|
2833
|
+
protocols.add(protocol);
|
|
2834
|
+
return protocols;
|
|
2835
|
+
}
|
|
2836
|
+
module.exports = { parse: parse6 };
|
|
2837
|
+
});
|
|
2838
|
+
|
|
2839
|
+
// node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/lib/websocket-server.js
|
|
2840
|
+
var require_websocket_server = __commonJS((exports, module) => {
|
|
2841
|
+
var EventEmitter4 = __require("events");
|
|
2842
|
+
var http = __require("http");
|
|
2843
|
+
var { Duplex } = __require("stream");
|
|
2844
|
+
var { createHash } = __require("crypto");
|
|
2845
|
+
var extension2 = require_extension();
|
|
2846
|
+
var PerMessageDeflate = require_permessage_deflate();
|
|
2847
|
+
var subprotocol2 = require_subprotocol();
|
|
2848
|
+
var WebSocket = require_websocket();
|
|
2849
|
+
var { CLOSE_TIMEOUT, GUID, kWebSocket } = require_constants();
|
|
2850
|
+
var keyRegex = /^[+/0-9A-Za-z]{22}==$/;
|
|
2851
|
+
var RUNNING = 0;
|
|
2852
|
+
var CLOSING = 1;
|
|
2853
|
+
var CLOSED = 2;
|
|
2854
|
+
|
|
2855
|
+
class WebSocketServer extends EventEmitter4 {
|
|
2856
|
+
constructor(options, callback) {
|
|
2857
|
+
super();
|
|
2858
|
+
options = {
|
|
2859
|
+
allowSynchronousEvents: true,
|
|
2860
|
+
autoPong: true,
|
|
2861
|
+
maxPayload: 100 * 1024 * 1024,
|
|
2862
|
+
skipUTF8Validation: false,
|
|
2863
|
+
perMessageDeflate: false,
|
|
2864
|
+
handleProtocols: null,
|
|
2865
|
+
clientTracking: true,
|
|
2866
|
+
closeTimeout: CLOSE_TIMEOUT,
|
|
2867
|
+
verifyClient: null,
|
|
2868
|
+
noServer: false,
|
|
2869
|
+
backlog: null,
|
|
2870
|
+
server: null,
|
|
2871
|
+
host: null,
|
|
2872
|
+
path: null,
|
|
2873
|
+
port: null,
|
|
2874
|
+
WebSocket,
|
|
2875
|
+
...options
|
|
2876
|
+
};
|
|
2877
|
+
if (options.port == null && !options.server && !options.noServer || options.port != null && (options.server || options.noServer) || options.server && options.noServer) {
|
|
2878
|
+
throw new TypeError('One and only one of the "port", "server", or "noServer" options ' + "must be specified");
|
|
2879
|
+
}
|
|
2880
|
+
if (options.port != null) {
|
|
2881
|
+
this._server = http.createServer((req, res) => {
|
|
2882
|
+
const body = http.STATUS_CODES[426];
|
|
2883
|
+
res.writeHead(426, {
|
|
2884
|
+
"Content-Length": body.length,
|
|
2885
|
+
"Content-Type": "text/plain"
|
|
2886
|
+
});
|
|
2887
|
+
res.end(body);
|
|
2888
|
+
});
|
|
2889
|
+
this._server.listen(options.port, options.host, options.backlog, callback);
|
|
2890
|
+
} else if (options.server) {
|
|
2891
|
+
this._server = options.server;
|
|
2892
|
+
}
|
|
2893
|
+
if (this._server) {
|
|
2894
|
+
const emitConnection = this.emit.bind(this, "connection");
|
|
2895
|
+
this._removeListeners = addListeners(this._server, {
|
|
2896
|
+
listening: this.emit.bind(this, "listening"),
|
|
2897
|
+
error: this.emit.bind(this, "error"),
|
|
2898
|
+
upgrade: (req, socket, head) => {
|
|
2899
|
+
this.handleUpgrade(req, socket, head, emitConnection);
|
|
2900
|
+
}
|
|
2901
|
+
});
|
|
2902
|
+
}
|
|
2903
|
+
if (options.perMessageDeflate === true)
|
|
2904
|
+
options.perMessageDeflate = {};
|
|
2905
|
+
if (options.clientTracking) {
|
|
2906
|
+
this.clients = new Set;
|
|
2907
|
+
this._shouldEmitClose = false;
|
|
2908
|
+
}
|
|
2909
|
+
this.options = options;
|
|
2910
|
+
this._state = RUNNING;
|
|
2911
|
+
}
|
|
2912
|
+
address() {
|
|
2913
|
+
if (this.options.noServer) {
|
|
2914
|
+
throw new Error('The server is operating in "noServer" mode');
|
|
2915
|
+
}
|
|
2916
|
+
if (!this._server)
|
|
2917
|
+
return null;
|
|
2918
|
+
return this._server.address();
|
|
2919
|
+
}
|
|
2920
|
+
close(cb) {
|
|
2921
|
+
if (this._state === CLOSED) {
|
|
2922
|
+
if (cb) {
|
|
2923
|
+
this.once("close", () => {
|
|
2924
|
+
cb(new Error("The server is not running"));
|
|
2925
|
+
});
|
|
2926
|
+
}
|
|
2927
|
+
process.nextTick(emitClose, this);
|
|
2928
|
+
return;
|
|
2929
|
+
}
|
|
2930
|
+
if (cb)
|
|
2931
|
+
this.once("close", cb);
|
|
2932
|
+
if (this._state === CLOSING)
|
|
2933
|
+
return;
|
|
2934
|
+
this._state = CLOSING;
|
|
2935
|
+
if (this.options.noServer || this.options.server) {
|
|
2936
|
+
if (this._server) {
|
|
2937
|
+
this._removeListeners();
|
|
2938
|
+
this._removeListeners = this._server = null;
|
|
2939
|
+
}
|
|
2940
|
+
if (this.clients) {
|
|
2941
|
+
if (!this.clients.size) {
|
|
2942
|
+
process.nextTick(emitClose, this);
|
|
2943
|
+
} else {
|
|
2944
|
+
this._shouldEmitClose = true;
|
|
2945
|
+
}
|
|
2946
|
+
} else {
|
|
2947
|
+
process.nextTick(emitClose, this);
|
|
2948
|
+
}
|
|
2949
|
+
} else {
|
|
2950
|
+
const server = this._server;
|
|
2951
|
+
this._removeListeners();
|
|
2952
|
+
this._removeListeners = this._server = null;
|
|
2953
|
+
server.close(() => {
|
|
2954
|
+
emitClose(this);
|
|
2955
|
+
});
|
|
2956
|
+
}
|
|
2957
|
+
}
|
|
2958
|
+
shouldHandle(req) {
|
|
2959
|
+
if (this.options.path) {
|
|
2960
|
+
const index2 = req.url.indexOf("?");
|
|
2961
|
+
const pathname = index2 !== -1 ? req.url.slice(0, index2) : req.url;
|
|
2962
|
+
if (pathname !== this.options.path)
|
|
2963
|
+
return false;
|
|
2964
|
+
}
|
|
2965
|
+
return true;
|
|
2966
|
+
}
|
|
2967
|
+
handleUpgrade(req, socket, head, cb) {
|
|
2968
|
+
socket.on("error", socketOnError);
|
|
2969
|
+
const key = req.headers["sec-websocket-key"];
|
|
2970
|
+
const upgrade = req.headers.upgrade;
|
|
2971
|
+
const version3 = +req.headers["sec-websocket-version"];
|
|
2972
|
+
if (req.method !== "GET") {
|
|
2973
|
+
const message = "Invalid HTTP method";
|
|
2974
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 405, message);
|
|
2975
|
+
return;
|
|
2976
|
+
}
|
|
2977
|
+
if (upgrade === undefined || upgrade.toLowerCase() !== "websocket") {
|
|
2978
|
+
const message = "Invalid Upgrade header";
|
|
2979
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
2980
|
+
return;
|
|
2981
|
+
}
|
|
2982
|
+
if (key === undefined || !keyRegex.test(key)) {
|
|
2983
|
+
const message = "Missing or invalid Sec-WebSocket-Key header";
|
|
2984
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
2985
|
+
return;
|
|
2986
|
+
}
|
|
2987
|
+
if (version3 !== 13 && version3 !== 8) {
|
|
2988
|
+
const message = "Missing or invalid Sec-WebSocket-Version header";
|
|
2989
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message, {
|
|
2990
|
+
"Sec-WebSocket-Version": "13, 8"
|
|
2991
|
+
});
|
|
2992
|
+
return;
|
|
2993
|
+
}
|
|
2994
|
+
if (!this.shouldHandle(req)) {
|
|
2995
|
+
abortHandshake(socket, 400);
|
|
2996
|
+
return;
|
|
2997
|
+
}
|
|
2998
|
+
const secWebSocketProtocol = req.headers["sec-websocket-protocol"];
|
|
2999
|
+
let protocols = new Set;
|
|
3000
|
+
if (secWebSocketProtocol !== undefined) {
|
|
3001
|
+
try {
|
|
3002
|
+
protocols = subprotocol2.parse(secWebSocketProtocol);
|
|
3003
|
+
} catch (err) {
|
|
3004
|
+
const message = "Invalid Sec-WebSocket-Protocol header";
|
|
3005
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
3006
|
+
return;
|
|
3007
|
+
}
|
|
3008
|
+
}
|
|
3009
|
+
const secWebSocketExtensions = req.headers["sec-websocket-extensions"];
|
|
3010
|
+
const extensions = {};
|
|
3011
|
+
if (this.options.perMessageDeflate && secWebSocketExtensions !== undefined) {
|
|
3012
|
+
const perMessageDeflate = new PerMessageDeflate(this.options.perMessageDeflate, true, this.options.maxPayload);
|
|
3013
|
+
try {
|
|
3014
|
+
const offers = extension2.parse(secWebSocketExtensions);
|
|
3015
|
+
if (offers[PerMessageDeflate.extensionName]) {
|
|
3016
|
+
perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]);
|
|
3017
|
+
extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
|
|
3018
|
+
}
|
|
3019
|
+
} catch (err) {
|
|
3020
|
+
const message = "Invalid or unacceptable Sec-WebSocket-Extensions header";
|
|
3021
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
3022
|
+
return;
|
|
3023
|
+
}
|
|
3024
|
+
}
|
|
3025
|
+
if (this.options.verifyClient) {
|
|
3026
|
+
const info = {
|
|
3027
|
+
origin: req.headers[`${version3 === 8 ? "sec-websocket-origin" : "origin"}`],
|
|
3028
|
+
secure: !!(req.socket.authorized || req.socket.encrypted),
|
|
3029
|
+
req
|
|
3030
|
+
};
|
|
3031
|
+
if (this.options.verifyClient.length === 2) {
|
|
3032
|
+
this.options.verifyClient(info, (verified, code, message, headers) => {
|
|
3033
|
+
if (!verified) {
|
|
3034
|
+
return abortHandshake(socket, code || 401, message, headers);
|
|
3035
|
+
}
|
|
3036
|
+
this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
|
|
3037
|
+
});
|
|
3038
|
+
return;
|
|
3039
|
+
}
|
|
3040
|
+
if (!this.options.verifyClient(info))
|
|
3041
|
+
return abortHandshake(socket, 401);
|
|
3042
|
+
}
|
|
3043
|
+
this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
|
|
3044
|
+
}
|
|
3045
|
+
completeUpgrade(extensions, key, protocols, req, socket, head, cb) {
|
|
3046
|
+
if (!socket.readable || !socket.writable)
|
|
3047
|
+
return socket.destroy();
|
|
3048
|
+
if (socket[kWebSocket]) {
|
|
3049
|
+
throw new Error("server.handleUpgrade() was called more than once with the same " + "socket, possibly due to a misconfiguration");
|
|
3050
|
+
}
|
|
3051
|
+
if (this._state > RUNNING)
|
|
3052
|
+
return abortHandshake(socket, 503);
|
|
3053
|
+
const digest = createHash("sha1").update(key + GUID).digest("base64");
|
|
3054
|
+
const headers = [
|
|
3055
|
+
"HTTP/1.1 101 Switching Protocols",
|
|
3056
|
+
"Upgrade: websocket",
|
|
3057
|
+
"Connection: Upgrade",
|
|
3058
|
+
`Sec-WebSocket-Accept: ${digest}`
|
|
3059
|
+
];
|
|
3060
|
+
const ws = new this.options.WebSocket(null, undefined, this.options);
|
|
3061
|
+
if (protocols.size) {
|
|
3062
|
+
const protocol = this.options.handleProtocols ? this.options.handleProtocols(protocols, req) : protocols.values().next().value;
|
|
3063
|
+
if (protocol) {
|
|
3064
|
+
headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
|
|
3065
|
+
ws._protocol = protocol;
|
|
3066
|
+
}
|
|
3067
|
+
}
|
|
3068
|
+
if (extensions[PerMessageDeflate.extensionName]) {
|
|
3069
|
+
const params = extensions[PerMessageDeflate.extensionName].params;
|
|
3070
|
+
const value = extension2.format({
|
|
3071
|
+
[PerMessageDeflate.extensionName]: [params]
|
|
3072
|
+
});
|
|
3073
|
+
headers.push(`Sec-WebSocket-Extensions: ${value}`);
|
|
3074
|
+
ws._extensions = extensions;
|
|
3075
|
+
}
|
|
3076
|
+
this.emit("headers", headers, req);
|
|
3077
|
+
socket.write(headers.concat(`\r
|
|
3078
|
+
`).join(`\r
|
|
3079
|
+
`));
|
|
3080
|
+
socket.removeListener("error", socketOnError);
|
|
3081
|
+
ws.setSocket(socket, head, {
|
|
3082
|
+
allowSynchronousEvents: this.options.allowSynchronousEvents,
|
|
3083
|
+
maxPayload: this.options.maxPayload,
|
|
3084
|
+
skipUTF8Validation: this.options.skipUTF8Validation
|
|
3085
|
+
});
|
|
3086
|
+
if (this.clients) {
|
|
3087
|
+
this.clients.add(ws);
|
|
3088
|
+
ws.on("close", () => {
|
|
3089
|
+
this.clients.delete(ws);
|
|
3090
|
+
if (this._shouldEmitClose && !this.clients.size) {
|
|
3091
|
+
process.nextTick(emitClose, this);
|
|
3092
|
+
}
|
|
3093
|
+
});
|
|
3094
|
+
}
|
|
3095
|
+
cb(ws, req);
|
|
3096
|
+
}
|
|
3097
|
+
}
|
|
3098
|
+
module.exports = WebSocketServer;
|
|
3099
|
+
function addListeners(server, map3) {
|
|
3100
|
+
for (const event of Object.keys(map3))
|
|
3101
|
+
server.on(event, map3[event]);
|
|
3102
|
+
return function removeListeners() {
|
|
3103
|
+
for (const event of Object.keys(map3)) {
|
|
3104
|
+
server.removeListener(event, map3[event]);
|
|
3105
|
+
}
|
|
3106
|
+
};
|
|
3107
|
+
}
|
|
3108
|
+
function emitClose(server) {
|
|
3109
|
+
server._state = CLOSED;
|
|
3110
|
+
server.emit("close");
|
|
3111
|
+
}
|
|
3112
|
+
function socketOnError() {
|
|
3113
|
+
this.destroy();
|
|
3114
|
+
}
|
|
3115
|
+
function abortHandshake(socket, code, message, headers) {
|
|
3116
|
+
message = message || http.STATUS_CODES[code];
|
|
3117
|
+
headers = {
|
|
3118
|
+
Connection: "close",
|
|
3119
|
+
"Content-Type": "text/html",
|
|
3120
|
+
"Content-Length": Buffer.byteLength(message),
|
|
3121
|
+
...headers
|
|
3122
|
+
};
|
|
3123
|
+
socket.once("finish", socket.destroy);
|
|
3124
|
+
socket.end(`HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r
|
|
3125
|
+
` + Object.keys(headers).map((h) => `${h}: ${headers[h]}`).join(`\r
|
|
3126
|
+
`) + `\r
|
|
3127
|
+
\r
|
|
3128
|
+
` + message);
|
|
3129
|
+
}
|
|
3130
|
+
function abortHandshakeOrEmitwsClientError(server, req, socket, code, message, headers) {
|
|
3131
|
+
if (server.listenerCount("wsClientError")) {
|
|
3132
|
+
const err = new Error(message);
|
|
3133
|
+
Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError);
|
|
3134
|
+
server.emit("wsClientError", err, socket, req);
|
|
3135
|
+
} else {
|
|
3136
|
+
abortHandshake(socket, code, message, headers);
|
|
3137
|
+
}
|
|
3138
|
+
}
|
|
3139
|
+
});
|
|
11
3140
|
|
|
12
|
-
// node_modules/.pnpm/@kevisual+router@0.0.
|
|
3141
|
+
// node_modules/.pnpm/@kevisual+router@0.0.70/node_modules/@kevisual/router/dist/router.js
|
|
13
3142
|
import require$$1, { webcrypto } from "node:crypto";
|
|
14
3143
|
import require$$2 from "node:http";
|
|
15
3144
|
import require$$1$1 from "node:https";
|
|
@@ -292,6 +3421,44 @@ function requireEventemitter3() {
|
|
|
292
3421
|
}
|
|
293
3422
|
var eventemitter3Exports = requireEventemitter3();
|
|
294
3423
|
var EventEmitter = /* @__PURE__ */ getDefaultExportFromCjs(eventemitter3Exports);
|
|
3424
|
+
function isPlainObject$1(value) {
|
|
3425
|
+
if (!value || typeof value !== "object") {
|
|
3426
|
+
return false;
|
|
3427
|
+
}
|
|
3428
|
+
const proto = Object.getPrototypeOf(value);
|
|
3429
|
+
const hasObjectPrototype = proto === null || proto === Object.prototype || Object.getPrototypeOf(proto) === null;
|
|
3430
|
+
if (!hasObjectPrototype) {
|
|
3431
|
+
return false;
|
|
3432
|
+
}
|
|
3433
|
+
return Object.prototype.toString.call(value) === "[object Object]";
|
|
3434
|
+
}
|
|
3435
|
+
function isUnsafeProperty(key) {
|
|
3436
|
+
return key === "__proto__";
|
|
3437
|
+
}
|
|
3438
|
+
function merge$1(target, source) {
|
|
3439
|
+
const sourceKeys = Object.keys(source);
|
|
3440
|
+
for (let i = 0;i < sourceKeys.length; i++) {
|
|
3441
|
+
const key = sourceKeys[i];
|
|
3442
|
+
if (isUnsafeProperty(key)) {
|
|
3443
|
+
continue;
|
|
3444
|
+
}
|
|
3445
|
+
const sourceValue = source[key];
|
|
3446
|
+
const targetValue = target[key];
|
|
3447
|
+
if (isMergeableValue(sourceValue) && isMergeableValue(targetValue)) {
|
|
3448
|
+
target[key] = merge$1(targetValue, sourceValue);
|
|
3449
|
+
} else if (Array.isArray(sourceValue)) {
|
|
3450
|
+
target[key] = merge$1([], sourceValue);
|
|
3451
|
+
} else if (isPlainObject$1(sourceValue)) {
|
|
3452
|
+
target[key] = merge$1({}, sourceValue);
|
|
3453
|
+
} else if (targetValue === undefined || sourceValue !== undefined) {
|
|
3454
|
+
target[key] = sourceValue;
|
|
3455
|
+
}
|
|
3456
|
+
}
|
|
3457
|
+
return target;
|
|
3458
|
+
}
|
|
3459
|
+
function isMergeableValue(value) {
|
|
3460
|
+
return isPlainObject$1(value) || Array.isArray(value);
|
|
3461
|
+
}
|
|
295
3462
|
|
|
296
3463
|
class MockProcess {
|
|
297
3464
|
emitter;
|
|
@@ -330,7 +3497,7 @@ class MockProcess {
|
|
|
330
3497
|
this.process = undefined;
|
|
331
3498
|
}
|
|
332
3499
|
}
|
|
333
|
-
var listenProcess = async ({ app, mockProcess, params, timeout = 10 * 60 * 60 * 1000 }) => {
|
|
3500
|
+
var listenProcess = async ({ app, mockProcess, params = {}, timeout = 10 * 60 * 60 * 1000 }) => {
|
|
334
3501
|
const process2 = mockProcess || new MockProcess;
|
|
335
3502
|
let isEnd = false;
|
|
336
3503
|
const timer = setTimeout(() => {
|
|
@@ -343,23 +3510,25 @@ var listenProcess = async ({ app, mockProcess, params, timeout = 10 * 60 * 60 *
|
|
|
343
3510
|
}, timeout);
|
|
344
3511
|
const getParams = async () => {
|
|
345
3512
|
return new Promise((resolve) => {
|
|
346
|
-
process2.on((
|
|
3513
|
+
process2.on((params2) => {
|
|
347
3514
|
if (isEnd)
|
|
348
3515
|
return;
|
|
349
3516
|
isEnd = true;
|
|
350
3517
|
clearTimeout(timer);
|
|
351
|
-
resolve(
|
|
3518
|
+
resolve(params2 || {});
|
|
352
3519
|
});
|
|
353
3520
|
});
|
|
354
3521
|
};
|
|
355
3522
|
try {
|
|
356
|
-
const
|
|
357
|
-
const
|
|
3523
|
+
const _params = await getParams();
|
|
3524
|
+
const mergeParams = merge$1(params, _params);
|
|
3525
|
+
const msg = mergeParams?.message || {};
|
|
3526
|
+
const ctx = mergeParams?.context || {};
|
|
358
3527
|
if (!msg.path && !msg.id) {
|
|
359
3528
|
const route = app.routes.find((r) => r.path !== "router");
|
|
360
3529
|
msg.id = route?.id;
|
|
361
3530
|
}
|
|
362
|
-
const result = await app.run(msg);
|
|
3531
|
+
const result = await app.run(msg, ctx);
|
|
363
3532
|
const response = {
|
|
364
3533
|
success: true,
|
|
365
3534
|
data: result,
|
|
@@ -369,6 +3538,7 @@ var listenProcess = async ({ app, mockProcess, params, timeout = 10 * 60 * 60 *
|
|
|
369
3538
|
process2.exit?.(0);
|
|
370
3539
|
});
|
|
371
3540
|
} catch (error) {
|
|
3541
|
+
console.error("Error in listenProcess:", error);
|
|
372
3542
|
process2.send?.({
|
|
373
3543
|
success: false,
|
|
374
3544
|
error: error.message
|
|
@@ -11348,7 +14518,7 @@ var allProcessors = {
|
|
|
11348
14518
|
optional: optionalProcessor,
|
|
11349
14519
|
lazy: lazyProcessor
|
|
11350
14520
|
};
|
|
11351
|
-
function toJSONSchema(input, params) {
|
|
14521
|
+
function toJSONSchema$1(input, params) {
|
|
11352
14522
|
if ("_idmap" in input) {
|
|
11353
14523
|
const registry2 = input;
|
|
11354
14524
|
const ctx2 = initializeContext({ ...params, processors: allProcessors });
|
|
@@ -11715,7 +14885,7 @@ var index = /* @__PURE__ */ Object.freeze({
|
|
|
11715
14885
|
safeParse: safeParse$1,
|
|
11716
14886
|
safeParseAsync: safeParseAsync$1,
|
|
11717
14887
|
toDotPath,
|
|
11718
|
-
toJSONSchema,
|
|
14888
|
+
toJSONSchema: toJSONSchema$1,
|
|
11719
14889
|
treeifyError,
|
|
11720
14890
|
util: util$1,
|
|
11721
14891
|
version
|
|
@@ -13545,7 +16715,7 @@ function convertSchema(schema, ctx) {
|
|
|
13545
16715
|
}
|
|
13546
16716
|
return baseSchema;
|
|
13547
16717
|
}
|
|
13548
|
-
function fromJSONSchema(schema, params) {
|
|
16718
|
+
function fromJSONSchema$1(schema, params) {
|
|
13549
16719
|
if (typeof schema === "boolean") {
|
|
13550
16720
|
return schema ? z$1.any() : z$1.never();
|
|
13551
16721
|
}
|
|
@@ -13709,7 +16879,7 @@ var z = /* @__PURE__ */ Object.freeze({
|
|
|
13709
16879
|
float32,
|
|
13710
16880
|
float64,
|
|
13711
16881
|
formatError,
|
|
13712
|
-
fromJSONSchema,
|
|
16882
|
+
fromJSONSchema: fromJSONSchema$1,
|
|
13713
16883
|
function: _function,
|
|
13714
16884
|
getErrorMap,
|
|
13715
16885
|
globalRegistry,
|
|
@@ -13802,7 +16972,7 @@ var z = /* @__PURE__ */ Object.freeze({
|
|
|
13802
16972
|
superRefine,
|
|
13803
16973
|
symbol,
|
|
13804
16974
|
templateLiteral,
|
|
13805
|
-
toJSONSchema,
|
|
16975
|
+
toJSONSchema: toJSONSchema$1,
|
|
13806
16976
|
toLowerCase: _toLowerCase,
|
|
13807
16977
|
toUpperCase: _toUpperCase,
|
|
13808
16978
|
transform,
|
|
@@ -13936,8 +17106,8 @@ class Route {
|
|
|
13936
17106
|
}
|
|
13937
17107
|
return this;
|
|
13938
17108
|
}
|
|
13939
|
-
addTo(router) {
|
|
13940
|
-
router.add(this);
|
|
17109
|
+
addTo(router, opts) {
|
|
17110
|
+
router.add(this, opts);
|
|
13941
17111
|
}
|
|
13942
17112
|
setData(data) {
|
|
13943
17113
|
this.data = data;
|
|
@@ -13947,6 +17117,37 @@ class Route {
|
|
|
13947
17117
|
throw new CustomError(...args);
|
|
13948
17118
|
}
|
|
13949
17119
|
}
|
|
17120
|
+
var toJSONSchema = (route) => {
|
|
17121
|
+
const pickValues = pick$1(route, pickValue);
|
|
17122
|
+
if (pickValues?.metadata?.args) {
|
|
17123
|
+
const args = pickValues.metadata.args;
|
|
17124
|
+
const keys = Object.keys(args);
|
|
17125
|
+
const newArgs = {};
|
|
17126
|
+
for (let key of keys) {
|
|
17127
|
+
const item = args[key];
|
|
17128
|
+
if (item && typeof item === "object" && typeof item.toJSONSchema === "function") {
|
|
17129
|
+
newArgs[key] = item.toJSONSchema();
|
|
17130
|
+
} else {
|
|
17131
|
+
newArgs[key] = args[key];
|
|
17132
|
+
}
|
|
17133
|
+
}
|
|
17134
|
+
pickValues.metadata.args = newArgs;
|
|
17135
|
+
}
|
|
17136
|
+
return pickValues;
|
|
17137
|
+
};
|
|
17138
|
+
var fromJSONSchema = (route) => {
|
|
17139
|
+
const args = route?.metadata?.args;
|
|
17140
|
+
if (!args)
|
|
17141
|
+
return route;
|
|
17142
|
+
const keys = Object.keys(args);
|
|
17143
|
+
const newArgs = {};
|
|
17144
|
+
for (let key of keys) {
|
|
17145
|
+
const item = args[key];
|
|
17146
|
+
newArgs[key] = fromJSONSchema$1(item);
|
|
17147
|
+
}
|
|
17148
|
+
route.metadata.args = newArgs;
|
|
17149
|
+
return route;
|
|
17150
|
+
};
|
|
13950
17151
|
|
|
13951
17152
|
class QueryRouter {
|
|
13952
17153
|
appId = "";
|
|
@@ -13956,9 +17157,13 @@ class QueryRouter {
|
|
|
13956
17157
|
constructor() {
|
|
13957
17158
|
this.routes = [];
|
|
13958
17159
|
}
|
|
13959
|
-
add(route) {
|
|
17160
|
+
add(route, opts) {
|
|
17161
|
+
const overwrite = opts?.overwrite ?? true;
|
|
13960
17162
|
const has = this.routes.findIndex((r) => r.path === route.path && r.key === route.key);
|
|
13961
17163
|
if (has !== -1) {
|
|
17164
|
+
if (!overwrite) {
|
|
17165
|
+
return;
|
|
17166
|
+
}
|
|
13962
17167
|
this.routes.splice(has, 1);
|
|
13963
17168
|
}
|
|
13964
17169
|
this.routes.push(route);
|
|
@@ -14192,7 +17397,22 @@ class QueryRouter {
|
|
|
14192
17397
|
}
|
|
14193
17398
|
getList(filter) {
|
|
14194
17399
|
return this.routes.filter(filter || (() => true)).map((r) => {
|
|
14195
|
-
|
|
17400
|
+
const pickValues = pick$1(r, pickValue);
|
|
17401
|
+
if (pickValues?.metadata?.args) {
|
|
17402
|
+
const args = pickValues.metadata.args;
|
|
17403
|
+
const keys = Object.keys(args);
|
|
17404
|
+
const newArgs = {};
|
|
17405
|
+
for (let key of keys) {
|
|
17406
|
+
const item = args[key];
|
|
17407
|
+
if (item && typeof item === "object" && typeof item.toJSONSchema === "function") {
|
|
17408
|
+
newArgs[key] = item.toJSONSchema();
|
|
17409
|
+
} else {
|
|
17410
|
+
newArgs[key] = args[key];
|
|
17411
|
+
}
|
|
17412
|
+
}
|
|
17413
|
+
pickValues.metadata.args = newArgs;
|
|
17414
|
+
}
|
|
17415
|
+
return pickValues;
|
|
14196
17416
|
});
|
|
14197
17417
|
}
|
|
14198
17418
|
getHandle(router, wrapperFn, ctx) {
|
|
@@ -14265,6 +17485,8 @@ class QueryRouter {
|
|
|
14265
17485
|
}
|
|
14266
17486
|
return listenProcess({ app: this, params, ...opts });
|
|
14267
17487
|
}
|
|
17488
|
+
toJSONSchema = toJSONSchema;
|
|
17489
|
+
fromJSONSchema = fromJSONSchema;
|
|
14268
17490
|
}
|
|
14269
17491
|
|
|
14270
17492
|
class QueryRouterServer extends QueryRouter {
|
|
@@ -14282,8 +17504,8 @@ class QueryRouterServer extends QueryRouter {
|
|
|
14282
17504
|
setHandle(wrapperFn, ctx) {
|
|
14283
17505
|
this.handle = this.getHandle(this, wrapperFn, ctx);
|
|
14284
17506
|
}
|
|
14285
|
-
addRoute(route) {
|
|
14286
|
-
this.add(route);
|
|
17507
|
+
addRoute(route, opts) {
|
|
17508
|
+
this.add(route, opts);
|
|
14287
17509
|
}
|
|
14288
17510
|
Route = Route;
|
|
14289
17511
|
route(...args) {
|
|
@@ -18222,29 +21444,29 @@ class InitEnv {
|
|
|
18222
21444
|
}
|
|
18223
21445
|
InitEnv.init();
|
|
18224
21446
|
|
|
18225
|
-
// node_modules/.pnpm/@kevisual+use-config@1.0.
|
|
18226
|
-
import { createRequire } from "node:module";
|
|
21447
|
+
// node_modules/.pnpm/@kevisual+use-config@1.0.30_dotenv@17.2.3/node_modules/@kevisual/use-config/dist/app.js
|
|
21448
|
+
import { createRequire as createRequire2 } from "node:module";
|
|
18227
21449
|
import fs from "node:fs";
|
|
18228
21450
|
import path from "node:path";
|
|
18229
|
-
var
|
|
18230
|
-
var
|
|
21451
|
+
var __create2 = Object.create;
|
|
21452
|
+
var __getProtoOf2 = Object.getPrototypeOf;
|
|
18231
21453
|
var __defProp2 = Object.defineProperty;
|
|
18232
|
-
var
|
|
18233
|
-
var
|
|
18234
|
-
var
|
|
18235
|
-
target = mod != null ?
|
|
21454
|
+
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
21455
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
21456
|
+
var __toESM2 = (mod, isNodeMode, target) => {
|
|
21457
|
+
target = mod != null ? __create2(__getProtoOf2(mod)) : {};
|
|
18236
21458
|
const to = isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target;
|
|
18237
|
-
for (let key of
|
|
18238
|
-
if (!
|
|
21459
|
+
for (let key of __getOwnPropNames2(mod))
|
|
21460
|
+
if (!__hasOwnProp2.call(to, key))
|
|
18239
21461
|
__defProp2(to, key, {
|
|
18240
21462
|
get: () => mod[key],
|
|
18241
21463
|
enumerable: true
|
|
18242
21464
|
});
|
|
18243
21465
|
return to;
|
|
18244
21466
|
};
|
|
18245
|
-
var
|
|
18246
|
-
var
|
|
18247
|
-
var require_package =
|
|
21467
|
+
var __commonJS2 = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
21468
|
+
var __require2 = /* @__PURE__ */ createRequire2(import.meta.url);
|
|
21469
|
+
var require_package = __commonJS2((exports, module) => {
|
|
18248
21470
|
module.exports = {
|
|
18249
21471
|
name: "dotenv",
|
|
18250
21472
|
version: "17.2.3",
|
|
@@ -18308,11 +21530,11 @@ var require_package = __commonJS((exports, module) => {
|
|
|
18308
21530
|
}
|
|
18309
21531
|
};
|
|
18310
21532
|
});
|
|
18311
|
-
var require_main =
|
|
18312
|
-
var fs2 =
|
|
18313
|
-
var path2 =
|
|
18314
|
-
var os =
|
|
18315
|
-
var crypto2 =
|
|
21533
|
+
var require_main = __commonJS2((exports, module) => {
|
|
21534
|
+
var fs2 = __require2("fs");
|
|
21535
|
+
var path2 = __require2("path");
|
|
21536
|
+
var os = __require2("os");
|
|
21537
|
+
var crypto2 = __require2("crypto");
|
|
18316
21538
|
var packageJson = require_package();
|
|
18317
21539
|
var version2 = packageJson.version;
|
|
18318
21540
|
var TIPS = [
|
|
@@ -18635,7 +21857,7 @@ var require_main = __commonJS((exports, module) => {
|
|
|
18635
21857
|
exports.populate = DotenvModule.populate;
|
|
18636
21858
|
module.exports = DotenvModule;
|
|
18637
21859
|
});
|
|
18638
|
-
var import_dotenv =
|
|
21860
|
+
var import_dotenv = __toESM2(require_main(), 1);
|
|
18639
21861
|
var fileIsExist = (path2) => {
|
|
18640
21862
|
try {
|
|
18641
21863
|
fs.accessSync(path2, fs.constants.F_OK);
|
|
@@ -18725,7 +21947,7 @@ var useKey = (key, opts) => {
|
|
|
18725
21947
|
v = process.env[key];
|
|
18726
21948
|
}
|
|
18727
21949
|
if (!v) {
|
|
18728
|
-
return opts?.defaultValue ||
|
|
21950
|
+
return opts?.defaultValue || "";
|
|
18729
21951
|
}
|
|
18730
21952
|
if (opts?.isNumber && typeof v === "string") {
|
|
18731
21953
|
return Number(v);
|
|
@@ -19289,6 +22511,7 @@ InitEnv2.init();
|
|
|
19289
22511
|
// src/cnb-core.ts
|
|
19290
22512
|
class CNBCore {
|
|
19291
22513
|
baseURL = "https://api.cnb.cool";
|
|
22514
|
+
hackURL = "https://cnb.cool";
|
|
19292
22515
|
token;
|
|
19293
22516
|
cookie;
|
|
19294
22517
|
constructor(options) {
|
|
@@ -19302,6 +22525,10 @@ class CNBCore {
|
|
|
19302
22525
|
this.cookie = options.cnb.cookie;
|
|
19303
22526
|
}
|
|
19304
22527
|
}
|
|
22528
|
+
if (options?.cors?.baseUrl) {
|
|
22529
|
+
this.baseURL = options.cors.baseUrl + "/" + this.baseURL;
|
|
22530
|
+
this.hackURL = options.cors.baseUrl + "/" + this.hackURL;
|
|
22531
|
+
}
|
|
19305
22532
|
}
|
|
19306
22533
|
async request({ url: url2, method = "GET", data, params, headers, body, useCookie, useOrigin }) {
|
|
19307
22534
|
const defaultHeaders = {
|
|
@@ -19490,7 +22717,7 @@ class Repo extends CNBCore {
|
|
|
19490
22717
|
return this.post({ url: url2, data: postData });
|
|
19491
22718
|
}
|
|
19492
22719
|
deleteRepo(name) {
|
|
19493
|
-
const url2 =
|
|
22720
|
+
const url2 = `${this.hackURL}/${name}`;
|
|
19494
22721
|
return this.delete({ url: url2, useCookie: true });
|
|
19495
22722
|
}
|
|
19496
22723
|
async createCommit(repo, data) {
|
|
@@ -19504,7 +22731,7 @@ class Repo extends CNBCore {
|
|
|
19504
22731
|
if (!data.parent_commit_sha && preCommitSha) {
|
|
19505
22732
|
data.parent_commit_sha = preCommitSha;
|
|
19506
22733
|
}
|
|
19507
|
-
const url2 =
|
|
22734
|
+
const url2 = `${this.hackURL}/${repo}/-/git/commits`;
|
|
19508
22735
|
const postData = {
|
|
19509
22736
|
...data,
|
|
19510
22737
|
base_branch: data.base_branch || "refs/heads/main",
|
|
@@ -19564,7 +22791,7 @@ class User extends CNBCore {
|
|
|
19564
22791
|
super({ token: options.token, cookie: options.cookie });
|
|
19565
22792
|
}
|
|
19566
22793
|
getCurrentUser() {
|
|
19567
|
-
const url2 =
|
|
22794
|
+
const url2 = `${this.hackURL}/user`;
|
|
19568
22795
|
return this.get({
|
|
19569
22796
|
url: url2,
|
|
19570
22797
|
useCookie: true
|
|
@@ -19576,7 +22803,7 @@ class User extends CNBCore {
|
|
|
19576
22803
|
}
|
|
19577
22804
|
createAccessToken(data) {
|
|
19578
22805
|
const scope = data?.scope || "mission-manage:rw,mission-delete:rw,group-delete:rw,group-manage:rw,group-resource:rw,account-engage:rw,account-email:r,account-profile:rw,registry-delete:rw,registry-manage:rw,registry-package-delete:rw,registry-package:rw,repo-security:r,repo-delete:rw,repo-manage:rw,repo-basic-info:r,repo-cnb-detail:rw,repo-cnb-history:r,repo-cnb-trigger:rw,repo-commit-status:rw,repo-contents:rw,repo-notes:rw,repo-issue:rw,repo-pr:rw,repo-code:rw";
|
|
19579
|
-
const url2 =
|
|
22806
|
+
const url2 = `${this.hackURL}/user/personal_access_tokens`;
|
|
19580
22807
|
return this.post({
|
|
19581
22808
|
url: url2,
|
|
19582
22809
|
useCookie: true,
|
|
@@ -19587,7 +22814,7 @@ class User extends CNBCore {
|
|
|
19587
22814
|
});
|
|
19588
22815
|
}
|
|
19589
22816
|
getAccessTokens(params) {
|
|
19590
|
-
const url2 =
|
|
22817
|
+
const url2 = `${this.hackURL}/user/personal_access_tokens`;
|
|
19591
22818
|
return this.get({
|
|
19592
22819
|
url: url2,
|
|
19593
22820
|
useCookie: true,
|
|
@@ -19599,7 +22826,7 @@ class User extends CNBCore {
|
|
|
19599
22826
|
});
|
|
19600
22827
|
}
|
|
19601
22828
|
deleteAccessToken(tokenId) {
|
|
19602
|
-
const url2 =
|
|
22829
|
+
const url2 = `${this.hackURL}/user/personal_access_tokens/${tokenId}`;
|
|
19603
22830
|
return this.delete({
|
|
19604
22831
|
url: url2,
|
|
19605
22832
|
useCookie: true
|
|
@@ -33348,7 +36575,7 @@ config3(en_default());
|
|
|
33348
36575
|
// node_modules/.pnpm/zod@4.3.6/node_modules/zod/index.js
|
|
33349
36576
|
var zod_default = exports_external;
|
|
33350
36577
|
|
|
33351
|
-
// node_modules/.pnpm/@opencode-ai+plugin@1.1.
|
|
36578
|
+
// node_modules/.pnpm/@opencode-ai+plugin@1.1.51/node_modules/@opencode-ai/plugin/dist/tool.js
|
|
33352
36579
|
function tool2(input) {
|
|
33353
36580
|
return input;
|
|
33354
36581
|
}
|
|
@@ -33359,7 +36586,7 @@ app.route({
|
|
|
33359
36586
|
path: "cnb",
|
|
33360
36587
|
key: "user-check",
|
|
33361
36588
|
description: "检查用户登录状态,参数checkToken,default true; checkCookie, default false",
|
|
33362
|
-
middleware: ["auth"],
|
|
36589
|
+
middleware: ["admin-auth"],
|
|
33363
36590
|
metadata: {
|
|
33364
36591
|
tags: ["opencode"],
|
|
33365
36592
|
...createSkill({
|
|
@@ -33404,7 +36631,7 @@ app.route({
|
|
|
33404
36631
|
path: "cnb",
|
|
33405
36632
|
key: "list-repos",
|
|
33406
36633
|
description: "列出我的代码仓库",
|
|
33407
|
-
middleware: ["auth"],
|
|
36634
|
+
middleware: ["admin-auth"],
|
|
33408
36635
|
metadata: {
|
|
33409
36636
|
tags: ["opencode"],
|
|
33410
36637
|
...createSkill({
|
|
@@ -33445,7 +36672,7 @@ app.route({
|
|
|
33445
36672
|
path: "cnb",
|
|
33446
36673
|
key: "create-repo",
|
|
33447
36674
|
description: "创建代码仓库, 参数name, visibility, description",
|
|
33448
|
-
middleware: ["auth"],
|
|
36675
|
+
middleware: ["admin-auth"],
|
|
33449
36676
|
metadata: {
|
|
33450
36677
|
tags: ["opencode"],
|
|
33451
36678
|
...createSkill({
|
|
@@ -33482,7 +36709,7 @@ app.route({
|
|
|
33482
36709
|
path: "cnb",
|
|
33483
36710
|
key: "create-repo-file",
|
|
33484
36711
|
description: "在代码仓库中创建文件, repoName, filePath, content, encoding",
|
|
33485
|
-
middleware: ["auth"],
|
|
36712
|
+
middleware: ["admin-auth"],
|
|
33486
36713
|
metadata: {
|
|
33487
36714
|
tags: ["opencode"],
|
|
33488
36715
|
...createSkill({
|
|
@@ -33517,7 +36744,7 @@ app.route({
|
|
|
33517
36744
|
path: "cnb",
|
|
33518
36745
|
key: "delete-repo",
|
|
33519
36746
|
description: "删除代码仓库, 参数name",
|
|
33520
|
-
middleware: ["auth"],
|
|
36747
|
+
middleware: ["admin-auth"],
|
|
33521
36748
|
metadata: {
|
|
33522
36749
|
tags: ["opencode"],
|
|
33523
36750
|
...createSkill({
|
|
@@ -33543,7 +36770,7 @@ app.route({
|
|
|
33543
36770
|
path: "cnb",
|
|
33544
36771
|
key: "clean-closed-workspace",
|
|
33545
36772
|
description: "批量删除已停止的cnb工作空间",
|
|
33546
|
-
middleware: ["auth"],
|
|
36773
|
+
middleware: ["admin-auth"],
|
|
33547
36774
|
metadata: {
|
|
33548
36775
|
tags: ["opencode"],
|
|
33549
36776
|
...createSkill({
|
|
@@ -33571,9 +36798,48 @@ app.route({
|
|
|
33571
36798
|
ctx.forward({ code: 200, message: "已关闭的工作空间删除完成", data: results });
|
|
33572
36799
|
}).addTo(app);
|
|
33573
36800
|
|
|
33574
|
-
//
|
|
33575
|
-
import
|
|
36801
|
+
// node_modules/.pnpm/nanoid@5.1.6/node_modules/nanoid/index.js
|
|
36802
|
+
import { webcrypto as crypto2 } from "node:crypto";
|
|
36803
|
+
|
|
36804
|
+
// node_modules/.pnpm/nanoid@5.1.6/node_modules/nanoid/url-alphabet/index.js
|
|
36805
|
+
var urlAlphabet2 = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
36806
|
+
|
|
36807
|
+
// node_modules/.pnpm/nanoid@5.1.6/node_modules/nanoid/index.js
|
|
36808
|
+
var POOL_SIZE_MULTIPLIER2 = 128;
|
|
36809
|
+
var pool2;
|
|
36810
|
+
var poolOffset2;
|
|
36811
|
+
function fillPool2(bytes) {
|
|
36812
|
+
if (!pool2 || pool2.length < bytes) {
|
|
36813
|
+
pool2 = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER2);
|
|
36814
|
+
crypto2.getRandomValues(pool2);
|
|
36815
|
+
poolOffset2 = 0;
|
|
36816
|
+
} else if (poolOffset2 + bytes > pool2.length) {
|
|
36817
|
+
crypto2.getRandomValues(pool2);
|
|
36818
|
+
poolOffset2 = 0;
|
|
36819
|
+
}
|
|
36820
|
+
poolOffset2 += bytes;
|
|
36821
|
+
}
|
|
36822
|
+
function nanoid4(size = 21) {
|
|
36823
|
+
fillPool2(size |= 0);
|
|
36824
|
+
let id2 = "";
|
|
36825
|
+
for (let i = poolOffset2 - size;i < poolOffset2; i++) {
|
|
36826
|
+
id2 += urlAlphabet2[pool2[i] & 63];
|
|
36827
|
+
}
|
|
36828
|
+
return id2;
|
|
36829
|
+
}
|
|
36830
|
+
|
|
36831
|
+
// agent/routes/workspace/keep.ts
|
|
36832
|
+
var import_dayjs = __toESM(require_dayjs_min(), 1);
|
|
36833
|
+
|
|
36834
|
+
// node_modules/.pnpm/@kevisual+ws@8.19.0/node_modules/@kevisual/ws/wrapper.mjs
|
|
36835
|
+
var import_stream = __toESM(require_stream(), 1);
|
|
36836
|
+
var import_receiver = __toESM(require_receiver(), 1);
|
|
36837
|
+
var import_sender = __toESM(require_sender(), 1);
|
|
36838
|
+
var import_websocket = __toESM(require_websocket(), 1);
|
|
36839
|
+
var import_websocket_server = __toESM(require_websocket_server(), 1);
|
|
36840
|
+
var wrapper_default = import_websocket.default;
|
|
33576
36841
|
|
|
36842
|
+
// src/workspace/keep-live.ts
|
|
33577
36843
|
class WSKeepAlive {
|
|
33578
36844
|
ws = null;
|
|
33579
36845
|
config;
|
|
@@ -33635,7 +36901,7 @@ class WSKeepAlive {
|
|
|
33635
36901
|
connect() {
|
|
33636
36902
|
const { wsUrl, cookie, debug } = this.config;
|
|
33637
36903
|
this.log(`Connecting to ${wsUrl}...`);
|
|
33638
|
-
this.ws = new
|
|
36904
|
+
this.ws = new wrapper_default(wsUrl, {
|
|
33639
36905
|
headers: {
|
|
33640
36906
|
Origin: this.url.origin,
|
|
33641
36907
|
Cookie: cookie,
|
|
@@ -33678,7 +36944,7 @@ class WSKeepAlive {
|
|
|
33678
36944
|
startPing() {
|
|
33679
36945
|
this.stopPing();
|
|
33680
36946
|
this.pingTimer = setInterval(() => {
|
|
33681
|
-
if (this.ws && this.ws.readyState ===
|
|
36947
|
+
if (this.ws && this.ws.readyState === wrapper_default.OPEN) {
|
|
33682
36948
|
this.ws.ping();
|
|
33683
36949
|
this.log("Sent ping");
|
|
33684
36950
|
}
|
|
@@ -33724,7 +36990,7 @@ app.route({
|
|
|
33724
36990
|
path: "cnb",
|
|
33725
36991
|
key: "keep-workspace-alive",
|
|
33726
36992
|
description: "保持工作空间存活技能,参数wsUrl:工作空间访问URL,cookie:访问工作空间所需的cookie",
|
|
33727
|
-
middleware: ["auth"],
|
|
36993
|
+
middleware: ["admin-auth"],
|
|
33728
36994
|
metadata: {
|
|
33729
36995
|
tags: [],
|
|
33730
36996
|
...{
|
|
@@ -33743,9 +37009,9 @@ app.route({
|
|
|
33743
37009
|
if (!cookie) {
|
|
33744
37010
|
ctx.throw(400, "缺少访问工作空间所需的cookie参数");
|
|
33745
37011
|
}
|
|
33746
|
-
const existing = keepAliveMap.
|
|
37012
|
+
const existing = Array.from(keepAliveMap.values()).find((info) => info.id && info.KeepAlive?.wsUrl === wsUrl);
|
|
33747
37013
|
if (existing) {
|
|
33748
|
-
ctx.body = { message: `工作空间 ${wsUrl}
|
|
37014
|
+
ctx.body = { message: `工作空间 ${wsUrl} 的保持存活任务已在运行中`, id: existing.id };
|
|
33749
37015
|
return;
|
|
33750
37016
|
}
|
|
33751
37017
|
console.log(`启动保持工作空间 ${wsUrl} 存活的任务`);
|
|
@@ -33756,72 +37022,154 @@ app.route({
|
|
|
33756
37022
|
console.log(`工作空间 ${wsUrl} 保持存活任务已连接`);
|
|
33757
37023
|
},
|
|
33758
37024
|
onMessage: (data) => {
|
|
33759
|
-
const
|
|
33760
|
-
|
|
33761
|
-
|
|
37025
|
+
for (const info of keepAliveMap.values()) {
|
|
37026
|
+
if (info.KeepAlive?.wsUrl === wsUrl) {
|
|
37027
|
+
info.updatedTime = Date.now();
|
|
37028
|
+
break;
|
|
37029
|
+
}
|
|
33762
37030
|
}
|
|
33763
37031
|
},
|
|
33764
37032
|
debug: true,
|
|
33765
37033
|
onExit: (code) => {
|
|
33766
37034
|
console.log(`工作空间 ${wsUrl} 保持存活任务已退出,退出码: ${code}`);
|
|
33767
|
-
keepAliveMap.
|
|
37035
|
+
for (const [id3, info] of keepAliveMap.entries()) {
|
|
37036
|
+
if (info.KeepAlive?.wsUrl === wsUrl) {
|
|
37037
|
+
keepAliveMap.delete(id3);
|
|
37038
|
+
break;
|
|
37039
|
+
}
|
|
37040
|
+
}
|
|
33768
37041
|
}
|
|
33769
37042
|
});
|
|
33770
|
-
|
|
33771
|
-
|
|
37043
|
+
const id2 = nanoid4(6).toLowerCase();
|
|
37044
|
+
keepAliveMap.set(id2, { startTime: Date.now(), updatedTime: Date.now(), KeepAlive: keep, id: id2 });
|
|
37045
|
+
ctx.body = { content: `已启动保持工作空间 ${wsUrl} 存活的任务`, id: id2 };
|
|
33772
37046
|
}).addTo(app);
|
|
33773
37047
|
app.route({
|
|
33774
37048
|
path: "cnb",
|
|
33775
37049
|
key: "list-keep-alive-tasks",
|
|
33776
37050
|
description: "获取保持工作空间存活任务列表技能",
|
|
33777
|
-
middleware: ["auth"],
|
|
37051
|
+
middleware: ["admin-auth"],
|
|
33778
37052
|
metadata: {
|
|
33779
37053
|
tags: []
|
|
33780
37054
|
}
|
|
33781
37055
|
}).define(async (ctx) => {
|
|
33782
|
-
const list = Array.from(keepAliveMap.entries()).map(([
|
|
33783
|
-
|
|
33784
|
-
|
|
33785
|
-
|
|
33786
|
-
|
|
37056
|
+
const list = Array.from(keepAliveMap.entries()).map(([id2, info]) => {
|
|
37057
|
+
const now = Date.now();
|
|
37058
|
+
const duration4 = Math.floor((now - info.startTime) / 60000);
|
|
37059
|
+
return {
|
|
37060
|
+
id: id2,
|
|
37061
|
+
wsUrl: info.KeepAlive?.wsUrl,
|
|
37062
|
+
startTime: info.startTime,
|
|
37063
|
+
startTimeStr: import_dayjs.default(info.startTime).format("YYYY-MM-DD HH:mm"),
|
|
37064
|
+
updatedTime: info.updatedTime,
|
|
37065
|
+
updatedTimeStr: import_dayjs.default(info.updatedTime).format("YYYY-MM-DD HH:mm"),
|
|
37066
|
+
duration: duration4
|
|
37067
|
+
};
|
|
37068
|
+
});
|
|
33787
37069
|
ctx.body = { list };
|
|
33788
37070
|
}).addTo(app);
|
|
33789
37071
|
app.route({
|
|
33790
37072
|
path: "cnb",
|
|
33791
37073
|
key: "stop-keep-workspace-alive",
|
|
33792
|
-
description: "停止保持工作空间存活技能, 参数wsUrl:工作空间访问URL",
|
|
33793
|
-
middleware: ["auth"],
|
|
37074
|
+
description: "停止保持工作空间存活技能, 参数wsUrl:工作空间访问URL或者id",
|
|
37075
|
+
middleware: ["admin-auth"],
|
|
33794
37076
|
metadata: {
|
|
33795
37077
|
tags: [],
|
|
33796
37078
|
...{
|
|
33797
37079
|
args: {
|
|
33798
|
-
wsUrl: tool.schema.string().describe("工作空间的访问URL")
|
|
37080
|
+
wsUrl: tool.schema.string().optional().describe("工作空间的访问URL"),
|
|
37081
|
+
id: tool.schema.string().optional().describe("保持存活任务的唯一标识符")
|
|
33799
37082
|
}
|
|
33800
37083
|
}
|
|
33801
37084
|
}
|
|
33802
37085
|
}).define(async (ctx) => {
|
|
33803
37086
|
const wsUrl = ctx.query?.wsUrl;
|
|
33804
|
-
|
|
33805
|
-
|
|
37087
|
+
const id2 = ctx.query?.id;
|
|
37088
|
+
if (!wsUrl && !id2) {
|
|
37089
|
+
ctx.throw(400, "缺少工作空间访问URL参数或唯一标识符");
|
|
37090
|
+
}
|
|
37091
|
+
let targetId;
|
|
37092
|
+
let wsUrlFound;
|
|
37093
|
+
if (id2) {
|
|
37094
|
+
const info = keepAliveMap.get(id2);
|
|
37095
|
+
if (info) {
|
|
37096
|
+
targetId = id2;
|
|
37097
|
+
wsUrlFound = info.KeepAlive?.wsUrl;
|
|
37098
|
+
}
|
|
37099
|
+
} else if (wsUrl) {
|
|
37100
|
+
for (const [key, info] of keepAliveMap.entries()) {
|
|
37101
|
+
if (info.KeepAlive?.wsUrl === wsUrl) {
|
|
37102
|
+
targetId = key;
|
|
37103
|
+
wsUrlFound = wsUrl;
|
|
37104
|
+
break;
|
|
37105
|
+
}
|
|
37106
|
+
}
|
|
33806
37107
|
}
|
|
33807
|
-
|
|
33808
|
-
|
|
37108
|
+
if (targetId) {
|
|
37109
|
+
const keepAlive = keepAliveMap.get(targetId);
|
|
33809
37110
|
const endTime = Date.now();
|
|
33810
37111
|
const duration4 = endTime - keepAlive.startTime;
|
|
33811
37112
|
keepAlive?.KeepAlive?.disconnect();
|
|
33812
|
-
keepAliveMap.delete(
|
|
33813
|
-
ctx.body = {
|
|
37113
|
+
keepAliveMap.delete(targetId);
|
|
37114
|
+
ctx.body = { content: `已停止保持工作空间 ${wsUrlFound} 存活的任务,持续时间: ${duration4}ms`, id: targetId };
|
|
33814
37115
|
} else {
|
|
33815
|
-
ctx.body = {
|
|
37116
|
+
ctx.body = { content: `没有找到对应的工作空间保持存活任务` };
|
|
37117
|
+
}
|
|
37118
|
+
}).addTo(app);
|
|
37119
|
+
app.route({
|
|
37120
|
+
path: "cnb",
|
|
37121
|
+
key: "reset-keep-workspace-alive",
|
|
37122
|
+
description: "对存活的工作空间,startTime进行重置",
|
|
37123
|
+
middleware: ["admin-auth"],
|
|
37124
|
+
metadata: {
|
|
37125
|
+
tags: []
|
|
37126
|
+
}
|
|
37127
|
+
}).define(async (ctx) => {
|
|
37128
|
+
const now = Date.now();
|
|
37129
|
+
for (const info of keepAliveMap.values()) {
|
|
37130
|
+
info.startTime = now;
|
|
37131
|
+
}
|
|
37132
|
+
ctx.body = { content: `已重置所有存活工作空间的开始时间` };
|
|
37133
|
+
}).addTo(app);
|
|
37134
|
+
app.route({
|
|
37135
|
+
path: "cnb",
|
|
37136
|
+
key: "clear-keep-workspace-alive",
|
|
37137
|
+
description: "对存活的工作空间,超过5小时的进行清理",
|
|
37138
|
+
middleware: ["admin-auth"],
|
|
37139
|
+
metadata: {
|
|
37140
|
+
tags: []
|
|
33816
37141
|
}
|
|
37142
|
+
}).define(async (ctx) => {
|
|
37143
|
+
const res = clearKeepAlive();
|
|
37144
|
+
ctx.body = {
|
|
37145
|
+
content: `已清理所有存活工作空间中超过5小时的任务` + (res.length ? `,清理项:${res.map((i) => i.wsUrl).join(", ")}` : ""),
|
|
37146
|
+
list: res
|
|
37147
|
+
};
|
|
33817
37148
|
}).addTo(app);
|
|
37149
|
+
var clearKeepAlive = () => {
|
|
37150
|
+
const now = Date.now();
|
|
37151
|
+
let clearedArr = [];
|
|
37152
|
+
for (const [id2, info] of keepAliveMap.entries()) {
|
|
37153
|
+
if (now - info.startTime > FIVE_HOURS) {
|
|
37154
|
+
console.log(`工作空间 ${info.KeepAlive?.wsUrl} 超过5小时,自动停止`);
|
|
37155
|
+
info.KeepAlive?.disconnect?.();
|
|
37156
|
+
keepAliveMap.delete(id2);
|
|
37157
|
+
clearedArr.push({ id: id2, wsUrl: info.KeepAlive?.wsUrl });
|
|
37158
|
+
}
|
|
37159
|
+
}
|
|
37160
|
+
return clearedArr;
|
|
37161
|
+
};
|
|
37162
|
+
var FIVE_HOURS = 5 * 60 * 60 * 1000;
|
|
37163
|
+
setInterval(() => {
|
|
37164
|
+
clearKeepAlive();
|
|
37165
|
+
}, FIVE_HOURS);
|
|
33818
37166
|
|
|
33819
37167
|
// agent/routes/workspace/index.ts
|
|
33820
37168
|
app.route({
|
|
33821
37169
|
path: "cnb",
|
|
33822
37170
|
key: "start-workspace",
|
|
33823
37171
|
description: "启动开发工作空间, 参数 repo",
|
|
33824
|
-
middleware: ["auth"],
|
|
37172
|
+
middleware: ["admin-auth"],
|
|
33825
37173
|
metadata: {
|
|
33826
37174
|
tags: ["opencode"],
|
|
33827
37175
|
...createSkill({
|
|
@@ -33852,7 +37200,7 @@ app.route({
|
|
|
33852
37200
|
path: "cnb",
|
|
33853
37201
|
key: "list-workspace",
|
|
33854
37202
|
description: "获取cnb开发工作空间列表,可选参数 status=running 获取运行中的环境",
|
|
33855
|
-
middleware: ["auth"],
|
|
37203
|
+
middleware: ["admin-auth"],
|
|
33856
37204
|
metadata: {
|
|
33857
37205
|
tags: ["opencode"],
|
|
33858
37206
|
...createSkill({
|
|
@@ -33881,7 +37229,7 @@ app.route({
|
|
|
33881
37229
|
path: "cnb",
|
|
33882
37230
|
key: "get-workspace",
|
|
33883
37231
|
description: "获取工作空间详情,通过 repo 和 sn 获取",
|
|
33884
|
-
middleware: ["auth"],
|
|
37232
|
+
middleware: ["admin-auth"],
|
|
33885
37233
|
metadata: {
|
|
33886
37234
|
tags: ["opencode"],
|
|
33887
37235
|
...createSkill({
|
|
@@ -33910,7 +37258,7 @@ app.route({
|
|
|
33910
37258
|
path: "cnb",
|
|
33911
37259
|
key: "delete-workspace",
|
|
33912
37260
|
description: "删除工作空间,通过 pipelineId 或 sn",
|
|
33913
|
-
middleware: ["auth"],
|
|
37261
|
+
middleware: ["admin-auth"],
|
|
33914
37262
|
metadata: {
|
|
33915
37263
|
tags: ["opencode"],
|
|
33916
37264
|
...createSkill({
|
|
@@ -33947,7 +37295,7 @@ app.route({
|
|
|
33947
37295
|
path: "cnb",
|
|
33948
37296
|
key: "stop-workspace",
|
|
33949
37297
|
description: "停止工作空间,通过 pipelineId 或 sn",
|
|
33950
|
-
middleware: ["auth"],
|
|
37298
|
+
middleware: ["admin-auth"],
|
|
33951
37299
|
metadata: {
|
|
33952
37300
|
tags: ["opencode"],
|
|
33953
37301
|
...createSkill({
|
|
@@ -33971,33 +37319,35 @@ app.route({
|
|
|
33971
37319
|
}).addTo(app);
|
|
33972
37320
|
|
|
33973
37321
|
// agent/routes/call/index.ts
|
|
33974
|
-
app.
|
|
33975
|
-
|
|
33976
|
-
|
|
33977
|
-
|
|
33978
|
-
|
|
33979
|
-
|
|
33980
|
-
|
|
33981
|
-
|
|
33982
|
-
|
|
33983
|
-
|
|
33984
|
-
|
|
33985
|
-
|
|
33986
|
-
|
|
33987
|
-
|
|
33988
|
-
|
|
33989
|
-
|
|
33990
|
-
|
|
33991
|
-
|
|
33992
|
-
}
|
|
33993
|
-
|
|
33994
|
-
|
|
33995
|
-
|
|
33996
|
-
|
|
33997
|
-
|
|
33998
|
-
|
|
33999
|
-
|
|
34000
|
-
|
|
37322
|
+
if (!app.hasRoute("call")) {
|
|
37323
|
+
app.route({
|
|
37324
|
+
path: "call",
|
|
37325
|
+
key: "",
|
|
37326
|
+
description: "调用",
|
|
37327
|
+
middleware: ["admin-auth"],
|
|
37328
|
+
metadata: {
|
|
37329
|
+
tags: ["opencode"],
|
|
37330
|
+
...createSkill({
|
|
37331
|
+
skill: "call-app",
|
|
37332
|
+
title: "调用app应用",
|
|
37333
|
+
summary: "调用router的应用, 参数path, key, payload",
|
|
37334
|
+
args: {
|
|
37335
|
+
path: tool2.schema.string().describe("应用路径,例如 cnb"),
|
|
37336
|
+
key: tool2.schema.string().optional().describe("应用key,例如 list-repos"),
|
|
37337
|
+
payload: tool2.schema.object({}).optional().describe("调用参数")
|
|
37338
|
+
}
|
|
37339
|
+
})
|
|
37340
|
+
}
|
|
37341
|
+
}).define(async (ctx) => {
|
|
37342
|
+
const { path: path2, key } = ctx.query;
|
|
37343
|
+
console.log("call app", ctx.query);
|
|
37344
|
+
if (!path2) {
|
|
37345
|
+
ctx.throw("路径path不能为空");
|
|
37346
|
+
}
|
|
37347
|
+
const res = await ctx.run({ path: path2, key, payload: ctx.query.payload || {} });
|
|
37348
|
+
ctx.forward(res);
|
|
37349
|
+
}).addTo(app);
|
|
37350
|
+
}
|
|
34001
37351
|
|
|
34002
37352
|
// src/common/cnb-env.ts
|
|
34003
37353
|
var CNB_ENV = {
|
|
@@ -34024,7 +37374,7 @@ app.route({
|
|
|
34024
37374
|
path: "cnb",
|
|
34025
37375
|
key: "get-cnb-port-uri",
|
|
34026
37376
|
description: "获取当前cnb工作空间的port代理uri",
|
|
34027
|
-
middleware: ["auth"],
|
|
37377
|
+
middleware: ["admin-auth"],
|
|
34028
37378
|
metadata: {
|
|
34029
37379
|
tags: ["opencode"],
|
|
34030
37380
|
...createSkill({
|
|
@@ -34049,7 +37399,7 @@ app.route({
|
|
|
34049
37399
|
path: "cnb",
|
|
34050
37400
|
key: "get-cnb-vscode-uri",
|
|
34051
37401
|
description: "获取当前cnb工作空间的vscode代理uri, 包括多种访问方式, 如web、vscode、codebuddy、cursor、ssh",
|
|
34052
|
-
middleware: ["auth"],
|
|
37402
|
+
middleware: ["admin-auth"],
|
|
34053
37403
|
metadata: {
|
|
34054
37404
|
tags: ["opencode"],
|
|
34055
37405
|
...createSkill({
|
|
@@ -34110,7 +37460,7 @@ app.route({
|
|
|
34110
37460
|
path: "cnb",
|
|
34111
37461
|
key: "set-cnb-cookie",
|
|
34112
37462
|
description: "设置当前cnb工作空间的cookie环境变量",
|
|
34113
|
-
middleware: ["auth"],
|
|
37463
|
+
middleware: ["admin-auth"],
|
|
34114
37464
|
metadata: {
|
|
34115
37465
|
tags: ["opencode"],
|
|
34116
37466
|
...createSkill({
|
|
@@ -34135,7 +37485,7 @@ app.route({
|
|
|
34135
37485
|
path: "cnb",
|
|
34136
37486
|
key: "get-cnb-cookie",
|
|
34137
37487
|
description: "获取当前cnb工作空间的cookie环境变量",
|
|
34138
|
-
middleware: ["auth"],
|
|
37488
|
+
middleware: ["admin-auth"],
|
|
34139
37489
|
metadata: {
|
|
34140
37490
|
tags: ["opencode"],
|
|
34141
37491
|
...createSkill({
|
|
@@ -34150,17 +37500,17 @@ app.route({
|
|
|
34150
37500
|
}).addTo(app);
|
|
34151
37501
|
|
|
34152
37502
|
// node_modules/.pnpm/@kevisual+ai@0.0.24/node_modules/@kevisual/ai/dist/ai-provider-browser.js
|
|
34153
|
-
var
|
|
34154
|
-
var
|
|
37503
|
+
var __create3 = Object.create;
|
|
37504
|
+
var __getProtoOf3 = Object.getPrototypeOf;
|
|
34155
37505
|
var __defProp3 = Object.defineProperty;
|
|
34156
|
-
var
|
|
37506
|
+
var __getOwnPropNames3 = Object.getOwnPropertyNames;
|
|
34157
37507
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
34158
|
-
var
|
|
34159
|
-
var
|
|
34160
|
-
target = mod != null ?
|
|
37508
|
+
var __hasOwnProp3 = Object.prototype.hasOwnProperty;
|
|
37509
|
+
var __toESM3 = (mod, isNodeMode, target) => {
|
|
37510
|
+
target = mod != null ? __create3(__getProtoOf3(mod)) : {};
|
|
34161
37511
|
const to = isNodeMode || !mod || !mod.__esModule ? __defProp3(target, "default", { value: mod, enumerable: true }) : target;
|
|
34162
|
-
for (let key of
|
|
34163
|
-
if (!
|
|
37512
|
+
for (let key of __getOwnPropNames3(mod))
|
|
37513
|
+
if (!__hasOwnProp3.call(to, key))
|
|
34164
37514
|
__defProp3(to, key, {
|
|
34165
37515
|
get: () => mod[key],
|
|
34166
37516
|
enumerable: true
|
|
@@ -34174,14 +37524,14 @@ var __toCommonJS = (from) => {
|
|
|
34174
37524
|
return entry;
|
|
34175
37525
|
entry = __defProp3({}, "__esModule", { value: true });
|
|
34176
37526
|
if (from && typeof from === "object" || typeof from === "function")
|
|
34177
|
-
|
|
37527
|
+
__getOwnPropNames3(from).map((key) => !__hasOwnProp3.call(entry, key) && __defProp3(entry, key, {
|
|
34178
37528
|
get: () => from[key],
|
|
34179
37529
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
34180
37530
|
}));
|
|
34181
37531
|
__moduleCache.set(from, entry);
|
|
34182
37532
|
return entry;
|
|
34183
37533
|
};
|
|
34184
|
-
var
|
|
37534
|
+
var __commonJS3 = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
34185
37535
|
var __export2 = (target, all) => {
|
|
34186
37536
|
for (var name in all)
|
|
34187
37537
|
__defProp3(target, name, {
|
|
@@ -36351,7 +39701,7 @@ var init_events = __esm(() => {
|
|
|
36351
39701
|
Object.assign(EventEmitter4, { once: once2, getEventListeners, getMaxListeners: getMaxListeners2, setMaxListeners: setMaxListeners2, EventEmitter: EventEmitter4, usingDomains: false, captureRejectionSymbol, errorMonitor: kErrorMonitor, addAbortListener, init: EventEmitter4, listenerCount: listenerCount2 });
|
|
36352
39702
|
events_default = EventEmitter4;
|
|
36353
39703
|
});
|
|
36354
|
-
var
|
|
39704
|
+
var require_stream2 = __commonJS3((exports, module) => {
|
|
36355
39705
|
var __commonJS22 = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
36356
39706
|
var require_primordials = __commonJS22((exports2, module2) => {
|
|
36357
39707
|
|
|
@@ -40188,7 +43538,7 @@ var require_stream = __commonJS2((exports, module) => {
|
|
|
40188
43538
|
});
|
|
40189
43539
|
var require_promises = __commonJS22((exports2, module2) => {
|
|
40190
43540
|
var { ArrayPrototypePop, Promise: Promise2 } = require_primordials(), { isIterable, isNodeStream, isWebStream } = require_utils(), { pipelineImpl: pl2 } = require_pipeline(), { finished } = require_end_of_stream();
|
|
40191
|
-
|
|
43541
|
+
require_stream22();
|
|
40192
43542
|
function pipeline(...streams) {
|
|
40193
43543
|
return new Promise2((resolve, reject) => {
|
|
40194
43544
|
let signal, end, lastArg = streams[streams.length - 1];
|
|
@@ -40206,7 +43556,7 @@ var require_stream = __commonJS2((exports, module) => {
|
|
|
40206
43556
|
}
|
|
40207
43557
|
module2.exports = { finished, pipeline };
|
|
40208
43558
|
});
|
|
40209
|
-
var
|
|
43559
|
+
var require_stream22 = __commonJS22((exports2, module2) => {
|
|
40210
43560
|
var { Buffer: Buffer3 } = (init_buffer(), __toCommonJS(exports_buffer)), { ObjectDefineProperty, ObjectKeys, ReflectApply } = require_primordials(), { promisify: { custom: customPromisify } } = require_util(), { streamReturningOperators, promiseReturningOperators } = require_operators(), { codes: { ERR_ILLEGAL_CONSTRUCTOR } } = require_errors(), compose = require_compose(), { setDefaultHighWaterMark, getDefaultHighWaterMark } = require_state(), { pipeline } = require_pipeline(), { destroyer } = require_destroy(), eos = require_end_of_stream(), promises = require_promises(), utils = require_utils(), Stream = module2.exports = require_legacy().Stream;
|
|
40211
43561
|
Stream.isDestroyed = utils.isDestroyed;
|
|
40212
43562
|
Stream.isDisturbed = utils.isDisturbed;
|
|
@@ -40260,9 +43610,9 @@ var require_stream = __commonJS2((exports, module) => {
|
|
|
40260
43610
|
};
|
|
40261
43611
|
});
|
|
40262
43612
|
var require_ours = __commonJS22((exports2, module2) => {
|
|
40263
|
-
var Stream =
|
|
43613
|
+
var Stream = require_stream2();
|
|
40264
43614
|
{
|
|
40265
|
-
let CustomStream =
|
|
43615
|
+
let CustomStream = require_stream22(), promises = require_promises(), originalDestroy = CustomStream.Readable.destroy;
|
|
40266
43616
|
module2.exports = CustomStream.Readable, module2.exports._uint8ArrayToBuffer = CustomStream._uint8ArrayToBuffer, module2.exports._isUint8Array = CustomStream._isUint8Array, module2.exports.isDisturbed = CustomStream.isDisturbed, module2.exports.isErrored = CustomStream.isErrored, module2.exports.isReadable = CustomStream.isReadable, module2.exports.Readable = CustomStream.Readable, module2.exports.Writable = CustomStream.Writable, module2.exports.Duplex = CustomStream.Duplex, module2.exports.Transform = CustomStream.Transform, module2.exports.PassThrough = CustomStream.PassThrough, module2.exports.addAbortSignal = CustomStream.addAbortSignal, module2.exports.finished = CustomStream.finished, module2.exports.destroy = CustomStream.destroy, module2.exports.destroy = originalDestroy, module2.exports.pipeline = CustomStream.pipeline, module2.exports.compose = CustomStream.compose, Object.defineProperty(CustomStream, "promises", { configurable: true, enumerable: true, get() {
|
|
40267
43617
|
return promises;
|
|
40268
43618
|
} }), module2.exports.Stream = CustomStream.Stream;
|
|
@@ -40445,7 +43795,7 @@ var require_buffer;
|
|
|
40445
43795
|
var require_node;
|
|
40446
43796
|
var require_base2;
|
|
40447
43797
|
var require_der;
|
|
40448
|
-
var
|
|
43798
|
+
var require_constants2;
|
|
40449
43799
|
var require_der2;
|
|
40450
43800
|
var require_pem;
|
|
40451
43801
|
var require_decoders;
|
|
@@ -41412,27 +44762,27 @@ var init_crypto = __esm(() => {
|
|
|
41412
44762
|
exports.pbkdf2Sync = nativePBKDF2Sync, exports.pbkdf2 = nativePBKDF2;
|
|
41413
44763
|
});
|
|
41414
44764
|
require_browserify_cipher = __commonJS22((exports) => {
|
|
41415
|
-
var
|
|
41416
|
-
exports.createCipher = exports.Cipher =
|
|
41417
|
-
exports.createCipheriv = exports.Cipheriv =
|
|
41418
|
-
exports.createDecipher = exports.Decipher =
|
|
41419
|
-
exports.createDecipheriv = exports.Decipheriv =
|
|
41420
|
-
exports.listCiphers = exports.getCiphers =
|
|
44765
|
+
var crypto22 = (init_crypto(), __toCommonJS(exports_crypto));
|
|
44766
|
+
exports.createCipher = exports.Cipher = crypto22.createCipher;
|
|
44767
|
+
exports.createCipheriv = exports.Cipheriv = crypto22.createCipheriv;
|
|
44768
|
+
exports.createDecipher = exports.Decipher = crypto22.createDecipher;
|
|
44769
|
+
exports.createDecipheriv = exports.Decipheriv = crypto22.createDecipheriv;
|
|
44770
|
+
exports.listCiphers = exports.getCiphers = crypto22.getCiphers;
|
|
41421
44771
|
});
|
|
41422
44772
|
require_diffie_hellman = __commonJS22((exports) => {
|
|
41423
|
-
var
|
|
41424
|
-
exports.DiffieHellmanGroup =
|
|
41425
|
-
exports.createDiffieHellmanGroup =
|
|
41426
|
-
exports.getDiffieHellman =
|
|
41427
|
-
exports.createDiffieHellman =
|
|
41428
|
-
exports.DiffieHellman =
|
|
44773
|
+
var crypto22 = (init_crypto(), __toCommonJS(exports_crypto));
|
|
44774
|
+
exports.DiffieHellmanGroup = crypto22.DiffieHellmanGroup;
|
|
44775
|
+
exports.createDiffieHellmanGroup = crypto22.createDiffieHellmanGroup;
|
|
44776
|
+
exports.getDiffieHellman = crypto22.getDiffieHellman;
|
|
44777
|
+
exports.createDiffieHellman = crypto22.createDiffieHellman;
|
|
44778
|
+
exports.DiffieHellman = crypto22.DiffieHellman;
|
|
41429
44779
|
});
|
|
41430
44780
|
require_browserify_sign = __commonJS22((exports) => {
|
|
41431
|
-
var
|
|
41432
|
-
exports.createSign =
|
|
41433
|
-
exports.Sign =
|
|
41434
|
-
exports.createVerify =
|
|
41435
|
-
exports.Verify =
|
|
44781
|
+
var crypto22 = (init_crypto(), __toCommonJS(exports_crypto));
|
|
44782
|
+
exports.createSign = crypto22.createSign;
|
|
44783
|
+
exports.Sign = crypto22.Sign;
|
|
44784
|
+
exports.createVerify = crypto22.createVerify;
|
|
44785
|
+
exports.Verify = crypto22.Verify;
|
|
41436
44786
|
});
|
|
41437
44787
|
require_package2 = __commonJS22((exports, module) => {
|
|
41438
44788
|
module.exports = { name: "elliptic", version: "6.6.1", description: "EC cryptography", main: "lib/elliptic.js", files: ["lib"], scripts: { lint: "eslint lib test", "lint:fix": "npm run lint -- --fix", unit: "istanbul test _mocha --reporter=spec test/index.js", test: "npm run lint && npm run unit", version: "grunt dist && git add dist/" }, repository: { type: "git", url: "git@github.com:indutny/elliptic" }, keywords: ["EC", "Elliptic", "curve", "Cryptography"], author: "Fedor Indutny <fedor@indutny.com>", license: "MIT", bugs: { url: "https://github.com/indutny/elliptic/issues" }, homepage: "https://github.com/indutny/elliptic", devDependencies: { brfs: "^2.0.2", coveralls: "^3.1.0", eslint: "^7.6.0", grunt: "^1.2.1", "grunt-browserify": "^5.3.0", "grunt-cli": "^1.3.2", "grunt-contrib-connect": "^3.0.0", "grunt-contrib-copy": "^1.0.0", "grunt-contrib-uglify": "^5.0.0", "grunt-mocha-istanbul": "^5.0.2", "grunt-saucelabs": "^9.0.1", istanbul: "^0.4.5", mocha: "^8.0.1" }, dependencies: { "bn.js": "^4.11.9", brorand: "^1.1.0", "hash.js": "^1.0.0", "hmac-drbg": "^1.0.1", inherits: "^2.0.4", "minimalistic-assert": "^1.0.1", "minimalistic-crypto-utils": "^1.0.1" } };
|
|
@@ -43011,13 +46361,13 @@ var init_crypto = __esm(() => {
|
|
|
43011
46361
|
};
|
|
43012
46362
|
} else
|
|
43013
46363
|
try {
|
|
43014
|
-
if (
|
|
46364
|
+
if (crypto22 = (init_crypto(), __toCommonJS(exports_crypto)), typeof crypto22.randomBytes !== "function")
|
|
43015
46365
|
throw Error("Not supported");
|
|
43016
46366
|
Rand.prototype._rand = function(n) {
|
|
43017
|
-
return
|
|
46367
|
+
return crypto22.randomBytes(n);
|
|
43018
46368
|
};
|
|
43019
46369
|
} catch (e) {}
|
|
43020
|
-
var
|
|
46370
|
+
var crypto22;
|
|
43021
46371
|
});
|
|
43022
46372
|
require_base = __commonJS22((exports, module) => {
|
|
43023
46373
|
var BN = require_bn(), utils = require_utils2(), getNAF = utils.getNAF, getJSF = utils.getJSF, assert3 = utils.assert;
|
|
@@ -48525,13 +51875,13 @@ var init_crypto = __esm(() => {
|
|
|
48525
51875
|
base.Node = require_node();
|
|
48526
51876
|
});
|
|
48527
51877
|
require_der = __commonJS22((exports) => {
|
|
48528
|
-
var constants23 =
|
|
51878
|
+
var constants23 = require_constants2();
|
|
48529
51879
|
exports.tagClass = { 0: "universal", 1: "application", 2: "context", 3: "private" };
|
|
48530
51880
|
exports.tagClassByName = constants23._reverse(exports.tagClass);
|
|
48531
51881
|
exports.tag = { 0: "end", 1: "bool", 2: "int", 3: "bitstr", 4: "octstr", 5: "null_", 6: "objid", 7: "objDesc", 8: "external", 9: "real", 10: "enum", 11: "embed", 12: "utf8str", 13: "relativeOid", 16: "seq", 17: "set", 18: "numstr", 19: "printstr", 20: "t61str", 21: "videostr", 22: "ia5str", 23: "utctime", 24: "gentime", 25: "graphstr", 26: "iso646str", 27: "genstr", 28: "unistr", 29: "charstr", 30: "bmpstr" };
|
|
48532
51882
|
exports.tagByName = constants23._reverse(exports.tag);
|
|
48533
51883
|
});
|
|
48534
|
-
|
|
51884
|
+
require_constants2 = __commonJS22((exports) => {
|
|
48535
51885
|
var constants23 = exports;
|
|
48536
51886
|
constants23._reverse = function(map3) {
|
|
48537
51887
|
var res = {};
|
|
@@ -48994,7 +52344,7 @@ var init_crypto = __esm(() => {
|
|
|
48994
52344
|
asn1.bignum = require_bn3();
|
|
48995
52345
|
asn1.define = require_api().define;
|
|
48996
52346
|
asn1.base = require_base2();
|
|
48997
|
-
asn1.constants =
|
|
52347
|
+
asn1.constants = require_constants2();
|
|
48998
52348
|
asn1.decoders = require_decoders();
|
|
48999
52349
|
asn1.encoders = require_encoders();
|
|
49000
52350
|
});
|
|
@@ -49070,7 +52420,7 @@ var init_crypto = __esm(() => {
|
|
|
49070
52420
|
module.exports = { "2.16.840.1.101.3.4.1.1": "aes-128-ecb", "2.16.840.1.101.3.4.1.2": "aes-128-cbc", "2.16.840.1.101.3.4.1.3": "aes-128-ofb", "2.16.840.1.101.3.4.1.4": "aes-128-cfb", "2.16.840.1.101.3.4.1.21": "aes-192-ecb", "2.16.840.1.101.3.4.1.22": "aes-192-cbc", "2.16.840.1.101.3.4.1.23": "aes-192-ofb", "2.16.840.1.101.3.4.1.24": "aes-192-cfb", "2.16.840.1.101.3.4.1.41": "aes-256-ecb", "2.16.840.1.101.3.4.1.42": "aes-256-cbc", "2.16.840.1.101.3.4.1.43": "aes-256-ofb", "2.16.840.1.101.3.4.1.44": "aes-256-cfb" };
|
|
49071
52421
|
});
|
|
49072
52422
|
require_hash_base = __commonJS22((exports, module) => {
|
|
49073
|
-
var Buffer22 = require_safe_buffer().Buffer, Transform =
|
|
52423
|
+
var Buffer22 = require_safe_buffer().Buffer, Transform = require_stream2().Transform, inherits2 = require_inherits();
|
|
49074
52424
|
function HashBase(blockSize) {
|
|
49075
52425
|
Transform.call(this), this._block = Buffer22.allocUnsafe(blockSize), this._blockSize = blockSize, this._blockOffset = 0, this._length = [0, 0, 0, 0], this._finalized = false;
|
|
49076
52426
|
}
|
|
@@ -49218,12 +52568,12 @@ var init_crypto = __esm(() => {
|
|
|
49218
52568
|
module.exports = EVP_BytesToKey;
|
|
49219
52569
|
});
|
|
49220
52570
|
require_browserify_aes = __commonJS22((exports) => {
|
|
49221
|
-
var
|
|
49222
|
-
exports.createCipher = exports.Cipher =
|
|
49223
|
-
exports.createCipheriv = exports.Cipheriv =
|
|
49224
|
-
exports.createDecipher = exports.Decipher =
|
|
49225
|
-
exports.createDecipheriv = exports.Decipheriv =
|
|
49226
|
-
exports.listCiphers = exports.getCiphers =
|
|
52571
|
+
var crypto22 = (init_crypto(), __toCommonJS(exports_crypto));
|
|
52572
|
+
exports.createCipher = exports.Cipher = crypto22.createCipher;
|
|
52573
|
+
exports.createCipheriv = exports.Cipheriv = crypto22.createCipheriv;
|
|
52574
|
+
exports.createDecipher = exports.Decipher = crypto22.createDecipher;
|
|
52575
|
+
exports.createDecipheriv = exports.Decipheriv = crypto22.createDecipheriv;
|
|
52576
|
+
exports.listCiphers = exports.getCiphers = crypto22.getCiphers;
|
|
49227
52577
|
});
|
|
49228
52578
|
require_fixProc = __commonJS22((exports, module) => {
|
|
49229
52579
|
var findProc = /Proc-Type: 4,ENCRYPTED[\n\r]+DEK-Info: AES-((?:128)|(?:192)|(?:256))-CBC,([0-9A-H]+)[\n\r]+([0-9A-z\n\r+/=]+)[\n\r]+/m, startRegex = /^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----/m, fullRegex = /^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----([0-9A-z\n\r+/=]+)-----END \1-----$/m, evp = require_evp_bytestokey(), ciphers = require_browserify_aes(), Buffer22 = require_safe_buffer().Buffer;
|
|
@@ -52338,22 +55688,22 @@ var init_crypto = __esm(() => {
|
|
|
52338
55688
|
};
|
|
52339
55689
|
});
|
|
52340
55690
|
require_public_encrypt = __commonJS22((exports) => {
|
|
52341
|
-
var
|
|
52342
|
-
if (typeof
|
|
52343
|
-
|
|
52344
|
-
exports.publicEncrypt =
|
|
52345
|
-
exports.privateDecrypt =
|
|
52346
|
-
if (typeof
|
|
55691
|
+
var crypto22 = (init_crypto(), __toCommonJS(exports_crypto));
|
|
55692
|
+
if (typeof crypto22.publicEncrypt !== "function")
|
|
55693
|
+
crypto22 = require_browser2();
|
|
55694
|
+
exports.publicEncrypt = crypto22.publicEncrypt;
|
|
55695
|
+
exports.privateDecrypt = crypto22.privateDecrypt;
|
|
55696
|
+
if (typeof crypto22.privateEncrypt !== "function")
|
|
52347
55697
|
exports.privateEncrypt = require_browser2().privateEncrypt;
|
|
52348
55698
|
else
|
|
52349
|
-
exports.privateEncrypt =
|
|
52350
|
-
if (typeof
|
|
55699
|
+
exports.privateEncrypt = crypto22.privateEncrypt;
|
|
55700
|
+
if (typeof crypto22.publicDecrypt !== "function")
|
|
52351
55701
|
exports.publicDecrypt = require_browser2().publicDecrypt;
|
|
52352
55702
|
else
|
|
52353
|
-
exports.publicDecrypt =
|
|
55703
|
+
exports.publicDecrypt = crypto22.publicDecrypt;
|
|
52354
55704
|
});
|
|
52355
55705
|
require_browser3 = __commonJS22((exports) => {
|
|
52356
|
-
var safeBuffer = require_safe_buffer(), randombytes = require_randombytes(), Buffer22 = safeBuffer.Buffer, kBufferMaxLength = safeBuffer.kMaxLength,
|
|
55706
|
+
var safeBuffer = require_safe_buffer(), randombytes = require_randombytes(), Buffer22 = safeBuffer.Buffer, kBufferMaxLength = safeBuffer.kMaxLength, crypto22 = globalThis.crypto || globalThis.msCrypto, kMaxUint32 = Math.pow(2, 32) - 1;
|
|
52357
55707
|
function assertOffset(offset, length) {
|
|
52358
55708
|
if (typeof offset !== "number" || offset !== offset)
|
|
52359
55709
|
throw TypeError("offset must be a number");
|
|
@@ -52370,7 +55720,7 @@ var init_crypto = __esm(() => {
|
|
|
52370
55720
|
if (size + offset > length || size > kBufferMaxLength)
|
|
52371
55721
|
throw RangeError("buffer too small");
|
|
52372
55722
|
}
|
|
52373
|
-
|
|
55723
|
+
crypto22 && crypto22.getRandomValues, exports.randomFill = randomFill, exports.randomFillSync = randomFillSync;
|
|
52374
55724
|
function randomFill(buf, offset, size, cb) {
|
|
52375
55725
|
if (!Buffer22.isBuffer(buf) && !(buf instanceof globalThis.Uint8Array))
|
|
52376
55726
|
throw TypeError('"buf" argument must be a Buffer or Uint8Array');
|
|
@@ -52407,9 +55757,9 @@ var init_crypto = __esm(() => {
|
|
|
52407
55757
|
}
|
|
52408
55758
|
});
|
|
52409
55759
|
require_randomfill = __commonJS22((exports, module) => {
|
|
52410
|
-
var
|
|
52411
|
-
if (typeof
|
|
52412
|
-
exports.randomFill =
|
|
55760
|
+
var crypto22 = (init_crypto(), __toCommonJS(exports_crypto));
|
|
55761
|
+
if (typeof crypto22.randomFill === "function" && typeof crypto22.randomFillSync === "function")
|
|
55762
|
+
exports.randomFill = crypto22.randomFill, exports.randomFillSync = crypto22.randomFillSync;
|
|
52413
55763
|
else
|
|
52414
55764
|
module.exports = require_browser3();
|
|
52415
55765
|
});
|
|
@@ -52506,7 +55856,7 @@ https://github.com/browserify/crypto-browserify`);
|
|
|
52506
55856
|
webcrypto2 = crypto;
|
|
52507
55857
|
crypto_default = crypto;
|
|
52508
55858
|
});
|
|
52509
|
-
var require_core =
|
|
55859
|
+
var require_core = __commonJS3((exports, module) => {
|
|
52510
55860
|
(function(root, factory) {
|
|
52511
55861
|
if (typeof exports === "object") {
|
|
52512
55862
|
module.exports = exports = factory();
|
|
@@ -52517,37 +55867,37 @@ var require_core = __commonJS2((exports, module) => {
|
|
|
52517
55867
|
}
|
|
52518
55868
|
})(exports, function() {
|
|
52519
55869
|
var CryptoJS = CryptoJS || function(Math2, undefined2) {
|
|
52520
|
-
var
|
|
55870
|
+
var crypto22;
|
|
52521
55871
|
if (typeof window !== "undefined" && window.crypto) {
|
|
52522
|
-
|
|
55872
|
+
crypto22 = window.crypto;
|
|
52523
55873
|
}
|
|
52524
55874
|
if (typeof self !== "undefined" && self.crypto) {
|
|
52525
|
-
|
|
55875
|
+
crypto22 = self.crypto;
|
|
52526
55876
|
}
|
|
52527
55877
|
if (typeof globalThis !== "undefined" && globalThis.crypto) {
|
|
52528
|
-
|
|
55878
|
+
crypto22 = globalThis.crypto;
|
|
52529
55879
|
}
|
|
52530
|
-
if (!
|
|
52531
|
-
|
|
55880
|
+
if (!crypto22 && typeof window !== "undefined" && window.msCrypto) {
|
|
55881
|
+
crypto22 = window.msCrypto;
|
|
52532
55882
|
}
|
|
52533
|
-
if (!
|
|
52534
|
-
|
|
55883
|
+
if (!crypto22 && typeof global !== "undefined" && global.crypto) {
|
|
55884
|
+
crypto22 = global.crypto;
|
|
52535
55885
|
}
|
|
52536
|
-
if (!
|
|
55886
|
+
if (!crypto22 && true) {
|
|
52537
55887
|
try {
|
|
52538
|
-
|
|
55888
|
+
crypto22 = (init_crypto(), __toCommonJS(exports_crypto));
|
|
52539
55889
|
} catch (err) {}
|
|
52540
55890
|
}
|
|
52541
55891
|
var cryptoSecureRandomInt = function() {
|
|
52542
|
-
if (
|
|
52543
|
-
if (typeof
|
|
55892
|
+
if (crypto22) {
|
|
55893
|
+
if (typeof crypto22.getRandomValues === "function") {
|
|
52544
55894
|
try {
|
|
52545
|
-
return
|
|
55895
|
+
return crypto22.getRandomValues(new Uint32Array(1))[0];
|
|
52546
55896
|
} catch (err) {}
|
|
52547
55897
|
}
|
|
52548
|
-
if (typeof
|
|
55898
|
+
if (typeof crypto22.randomBytes === "function") {
|
|
52549
55899
|
try {
|
|
52550
|
-
return
|
|
55900
|
+
return crypto22.randomBytes(4).readInt32LE();
|
|
52551
55901
|
} catch (err) {}
|
|
52552
55902
|
}
|
|
52553
55903
|
}
|
|
@@ -52789,7 +56139,7 @@ var require_core = __commonJS2((exports, module) => {
|
|
|
52789
56139
|
return CryptoJS;
|
|
52790
56140
|
});
|
|
52791
56141
|
});
|
|
52792
|
-
var require_enc_base64 =
|
|
56142
|
+
var require_enc_base64 = __commonJS3((exports, module) => {
|
|
52793
56143
|
(function(root, factory) {
|
|
52794
56144
|
if (typeof exports === "object") {
|
|
52795
56145
|
module.exports = exports = factory(require_core());
|
|
@@ -52867,7 +56217,7 @@ var require_enc_base64 = __commonJS2((exports, module) => {
|
|
|
52867
56217
|
return CryptoJS.enc.Base64;
|
|
52868
56218
|
});
|
|
52869
56219
|
});
|
|
52870
|
-
var require_md52 =
|
|
56220
|
+
var require_md52 = __commonJS3((exports, module) => {
|
|
52871
56221
|
(function(root, factory) {
|
|
52872
56222
|
if (typeof exports === "object") {
|
|
52873
56223
|
module.exports = exports = factory(require_core());
|
|
@@ -53042,7 +56392,7 @@ var require_md52 = __commonJS2((exports, module) => {
|
|
|
53042
56392
|
return CryptoJS.MD5;
|
|
53043
56393
|
});
|
|
53044
56394
|
});
|
|
53045
|
-
var require_sha1 =
|
|
56395
|
+
var require_sha1 = __commonJS3((exports, module) => {
|
|
53046
56396
|
(function(root, factory) {
|
|
53047
56397
|
if (typeof exports === "object") {
|
|
53048
56398
|
module.exports = exports = factory(require_core());
|
|
@@ -53129,7 +56479,7 @@ var require_sha1 = __commonJS2((exports, module) => {
|
|
|
53129
56479
|
return CryptoJS.SHA1;
|
|
53130
56480
|
});
|
|
53131
56481
|
});
|
|
53132
|
-
var require_hmac2 =
|
|
56482
|
+
var require_hmac2 = __commonJS3((exports, module) => {
|
|
53133
56483
|
(function(root, factory) {
|
|
53134
56484
|
if (typeof exports === "object") {
|
|
53135
56485
|
module.exports = exports = factory(require_core());
|
|
@@ -53189,7 +56539,7 @@ var require_hmac2 = __commonJS2((exports, module) => {
|
|
|
53189
56539
|
})();
|
|
53190
56540
|
});
|
|
53191
56541
|
});
|
|
53192
|
-
var require_evpkdf =
|
|
56542
|
+
var require_evpkdf = __commonJS3((exports, module) => {
|
|
53193
56543
|
(function(root, factory, undef) {
|
|
53194
56544
|
if (typeof exports === "object") {
|
|
53195
56545
|
module.exports = exports = factory(require_core(), require_sha1(), require_hmac2());
|
|
@@ -53246,7 +56596,7 @@ var require_evpkdf = __commonJS2((exports, module) => {
|
|
|
53246
56596
|
return CryptoJS.EvpKDF;
|
|
53247
56597
|
});
|
|
53248
56598
|
});
|
|
53249
|
-
var require_cipher_core =
|
|
56599
|
+
var require_cipher_core = __commonJS3((exports, module) => {
|
|
53250
56600
|
(function(root, factory, undef) {
|
|
53251
56601
|
if (typeof exports === "object") {
|
|
53252
56602
|
module.exports = exports = factory(require_core(), require_evpkdf());
|
|
@@ -53542,7 +56892,7 @@ var require_cipher_core = __commonJS2((exports, module) => {
|
|
|
53542
56892
|
}();
|
|
53543
56893
|
});
|
|
53544
56894
|
});
|
|
53545
|
-
var require_aes =
|
|
56895
|
+
var require_aes = __commonJS3((exports, module) => {
|
|
53546
56896
|
(function(root, factory, undef) {
|
|
53547
56897
|
if (typeof exports === "object") {
|
|
53548
56898
|
module.exports = exports = factory(require_core(), require_enc_base64(), require_md52(), require_evpkdf(), require_cipher_core());
|
|
@@ -53692,7 +57042,7 @@ var require_aes = __commonJS2((exports, module) => {
|
|
|
53692
57042
|
return CryptoJS.AES;
|
|
53693
57043
|
});
|
|
53694
57044
|
});
|
|
53695
|
-
var require_enc_utf8 =
|
|
57045
|
+
var require_enc_utf8 = __commonJS3((exports, module) => {
|
|
53696
57046
|
(function(root, factory) {
|
|
53697
57047
|
if (typeof exports === "object") {
|
|
53698
57048
|
module.exports = exports = factory(require_core());
|
|
@@ -53995,8 +57345,8 @@ class CNBChat extends BaseChat {
|
|
|
53995
57345
|
};
|
|
53996
57346
|
}
|
|
53997
57347
|
}
|
|
53998
|
-
var import_aes =
|
|
53999
|
-
var import_enc_utf8 =
|
|
57348
|
+
var import_aes = __toESM3(require_aes(), 1);
|
|
57349
|
+
var import_enc_utf8 = __toESM3(require_enc_utf8(), 1);
|
|
54000
57350
|
var CryptoJS = { AES: import_aes.default, enc: { Utf8: import_enc_utf8.default } };
|
|
54001
57351
|
|
|
54002
57352
|
// agent/routes/knowledge/ai.ts
|
|
@@ -54004,7 +57354,7 @@ app.route({
|
|
|
54004
57354
|
path: "cnb",
|
|
54005
57355
|
key: "cnb-ai-chat",
|
|
54006
57356
|
description: "调用cnb的知识库ai对话功能进行聊天",
|
|
54007
|
-
middleware: ["auth"],
|
|
57357
|
+
middleware: ["admin-auth"],
|
|
54008
57358
|
metadata: {
|
|
54009
57359
|
tags: ["opencode"],
|
|
54010
57360
|
...createSkill({
|
|
@@ -54106,7 +57456,7 @@ app.route({
|
|
|
54106
57456
|
path: "cnb",
|
|
54107
57457
|
key: "cnb-rag-query",
|
|
54108
57458
|
description: "调用cnb的知识库RAG查询功能进行问答",
|
|
54109
|
-
middleware: ["auth"],
|
|
57459
|
+
middleware: ["admin-auth"],
|
|
54110
57460
|
metadata: {
|
|
54111
57461
|
tags: ["opencode"],
|
|
54112
57462
|
...createSkill({
|
|
@@ -54169,7 +57519,7 @@ app.route({
|
|
|
54169
57519
|
path: "cnb",
|
|
54170
57520
|
key: "list-issues",
|
|
54171
57521
|
description: "查询 Issue 列表, 参数 repo, state, keyword, labels, page, page_size 等",
|
|
54172
|
-
middleware: ["auth"],
|
|
57522
|
+
middleware: ["admin-auth"],
|
|
54173
57523
|
metadata: {
|
|
54174
57524
|
tags: ["opencode"],
|
|
54175
57525
|
...createSkill({
|
|
@@ -54220,7 +57570,7 @@ app.route({
|
|
|
54220
57570
|
path: "cnb",
|
|
54221
57571
|
key: "create-issue",
|
|
54222
57572
|
description: "创建 Issue, 参数 repo, title, body, assignees, labels, priority",
|
|
54223
|
-
middleware: ["auth"],
|
|
57573
|
+
middleware: ["admin-auth"],
|
|
54224
57574
|
metadata: {
|
|
54225
57575
|
tags: ["opencode"],
|
|
54226
57576
|
...createSkill({
|
|
@@ -54260,7 +57610,7 @@ app.route({
|
|
|
54260
57610
|
path: "cnb",
|
|
54261
57611
|
key: "complete-issue",
|
|
54262
57612
|
description: "完成 Issue, 参数 repo, issueNumber",
|
|
54263
|
-
middleware: ["auth"],
|
|
57613
|
+
middleware: ["admin-auth"],
|
|
54264
57614
|
metadata: {
|
|
54265
57615
|
tags: ["opencode"],
|
|
54266
57616
|
...createSkill({
|