@kodama-run/sdk 0.2.1 → 0.3.1
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/bin/cli.js +2973 -3
- package/bin/mcp.js +3121 -5
- package/package.json +1 -1
- package/src/adapters/mcp.ts +2 -2
- package/src/room.ts +9 -3
package/bin/cli.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
|
|
2
3
|
// @bun
|
|
3
4
|
import { createRequire } from "node:module";
|
|
4
5
|
var __create = Object.create;
|
|
@@ -33,6 +34,7 @@ var __toESM = (mod, isNodeMode, target) => {
|
|
|
33
34
|
};
|
|
34
35
|
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
35
36
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
37
|
+
|
|
36
38
|
// ../../node_modules/.pnpm/commander@13.1.0/node_modules/commander/lib/error.js
|
|
37
39
|
var require_error = __commonJS((exports) => {
|
|
38
40
|
class CommanderError extends Error {
|
|
@@ -45,6 +47,7 @@ var require_error = __commonJS((exports) => {
|
|
|
45
47
|
this.nestedError = undefined;
|
|
46
48
|
}
|
|
47
49
|
}
|
|
50
|
+
|
|
48
51
|
class InvalidArgumentError extends CommanderError {
|
|
49
52
|
constructor(message) {
|
|
50
53
|
super(1, "commander.invalidArgument", message);
|
|
@@ -55,9 +58,11 @@ var require_error = __commonJS((exports) => {
|
|
|
55
58
|
exports.CommanderError = CommanderError;
|
|
56
59
|
exports.InvalidArgumentError = InvalidArgumentError;
|
|
57
60
|
});
|
|
61
|
+
|
|
58
62
|
// ../../node_modules/.pnpm/commander@13.1.0/node_modules/commander/lib/argument.js
|
|
59
63
|
var require_argument = __commonJS((exports) => {
|
|
60
64
|
var { InvalidArgumentError } = require_error();
|
|
65
|
+
|
|
61
66
|
class Argument {
|
|
62
67
|
constructor(name, description) {
|
|
63
68
|
this.description = description || "";
|
|
@@ -132,9 +137,11 @@ var require_argument = __commonJS((exports) => {
|
|
|
132
137
|
exports.Argument = Argument;
|
|
133
138
|
exports.humanReadableArgName = humanReadableArgName;
|
|
134
139
|
});
|
|
140
|
+
|
|
135
141
|
// ../../node_modules/.pnpm/commander@13.1.0/node_modules/commander/lib/help.js
|
|
136
142
|
var require_help = __commonJS((exports) => {
|
|
137
143
|
var { humanReadableArgName } = require_argument();
|
|
144
|
+
|
|
138
145
|
class Help {
|
|
139
146
|
constructor() {
|
|
140
147
|
this.helpWidth = undefined;
|
|
@@ -480,9 +487,11 @@ ${itemIndentStr}`);
|
|
|
480
487
|
exports.Help = Help;
|
|
481
488
|
exports.stripColor = stripColor;
|
|
482
489
|
});
|
|
490
|
+
|
|
483
491
|
// ../../node_modules/.pnpm/commander@13.1.0/node_modules/commander/lib/option.js
|
|
484
492
|
var require_option = __commonJS((exports) => {
|
|
485
493
|
var { InvalidArgumentError } = require_error();
|
|
494
|
+
|
|
486
495
|
class Option {
|
|
487
496
|
constructor(flags, description) {
|
|
488
497
|
this.flags = flags;
|
|
@@ -583,6 +592,7 @@ var require_option = __commonJS((exports) => {
|
|
|
583
592
|
return !this.required && !this.optional && !this.negate;
|
|
584
593
|
}
|
|
585
594
|
}
|
|
595
|
+
|
|
586
596
|
class DualOptions {
|
|
587
597
|
constructor(options) {
|
|
588
598
|
this.positiveOptions = new Map;
|
|
@@ -655,6 +665,7 @@ var require_option = __commonJS((exports) => {
|
|
|
655
665
|
exports.Option = Option;
|
|
656
666
|
exports.DualOptions = DualOptions;
|
|
657
667
|
});
|
|
668
|
+
|
|
658
669
|
// ../../node_modules/.pnpm/commander@13.1.0/node_modules/commander/lib/suggestSimilar.js
|
|
659
670
|
var require_suggestSimilar = __commonJS((exports) => {
|
|
660
671
|
var maxDistance = 3;
|
|
@@ -727,6 +738,7 @@ var require_suggestSimilar = __commonJS((exports) => {
|
|
|
727
738
|
}
|
|
728
739
|
exports.suggestSimilar = suggestSimilar;
|
|
729
740
|
});
|
|
741
|
+
|
|
730
742
|
// ../../node_modules/.pnpm/commander@13.1.0/node_modules/commander/lib/command.js
|
|
731
743
|
var require_command = __commonJS((exports) => {
|
|
732
744
|
var EventEmitter = __require("node:events").EventEmitter;
|
|
@@ -739,6 +751,7 @@ var require_command = __commonJS((exports) => {
|
|
|
739
751
|
var { Help, stripColor } = require_help();
|
|
740
752
|
var { Option, DualOptions } = require_option();
|
|
741
753
|
var { suggestSimilar } = require_suggestSimilar();
|
|
754
|
+
|
|
742
755
|
class Command extends EventEmitter {
|
|
743
756
|
constructor(name) {
|
|
744
757
|
super();
|
|
@@ -2035,6 +2048,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2035
2048
|
exports.Command = Command;
|
|
2036
2049
|
exports.useColor = useColor;
|
|
2037
2050
|
});
|
|
2051
|
+
|
|
2038
2052
|
// ../../node_modules/.pnpm/commander@13.1.0/node_modules/commander/index.js
|
|
2039
2053
|
var require_commander = __commonJS((exports) => {
|
|
2040
2054
|
var { Argument } = require_argument();
|
|
@@ -2054,6 +2068,2881 @@ var require_commander = __commonJS((exports) => {
|
|
|
2054
2068
|
exports.InvalidArgumentError = InvalidArgumentError;
|
|
2055
2069
|
exports.InvalidOptionArgumentError = InvalidArgumentError;
|
|
2056
2070
|
});
|
|
2071
|
+
|
|
2072
|
+
// ../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/constants.js
|
|
2073
|
+
var require_constants = __commonJS((exports, module) => {
|
|
2074
|
+
var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
|
|
2075
|
+
var hasBlob = typeof Blob !== "undefined";
|
|
2076
|
+
if (hasBlob)
|
|
2077
|
+
BINARY_TYPES.push("blob");
|
|
2078
|
+
module.exports = {
|
|
2079
|
+
BINARY_TYPES,
|
|
2080
|
+
CLOSE_TIMEOUT: 30000,
|
|
2081
|
+
EMPTY_BUFFER: Buffer.alloc(0),
|
|
2082
|
+
GUID: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
|
|
2083
|
+
hasBlob,
|
|
2084
|
+
kForOnEventAttribute: Symbol("kIsForOnEventAttribute"),
|
|
2085
|
+
kListener: Symbol("kListener"),
|
|
2086
|
+
kStatusCode: Symbol("status-code"),
|
|
2087
|
+
kWebSocket: Symbol("websocket"),
|
|
2088
|
+
NOOP: () => {}
|
|
2089
|
+
};
|
|
2090
|
+
});
|
|
2091
|
+
|
|
2092
|
+
// ../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/buffer-util.js
|
|
2093
|
+
var require_buffer_util = __commonJS((exports, module) => {
|
|
2094
|
+
var { EMPTY_BUFFER } = require_constants();
|
|
2095
|
+
var FastBuffer = Buffer[Symbol.species];
|
|
2096
|
+
function concat(list, totalLength) {
|
|
2097
|
+
if (list.length === 0)
|
|
2098
|
+
return EMPTY_BUFFER;
|
|
2099
|
+
if (list.length === 1)
|
|
2100
|
+
return list[0];
|
|
2101
|
+
const target = Buffer.allocUnsafe(totalLength);
|
|
2102
|
+
let offset = 0;
|
|
2103
|
+
for (let i = 0;i < list.length; i++) {
|
|
2104
|
+
const buf = list[i];
|
|
2105
|
+
target.set(buf, offset);
|
|
2106
|
+
offset += buf.length;
|
|
2107
|
+
}
|
|
2108
|
+
if (offset < totalLength) {
|
|
2109
|
+
return new FastBuffer(target.buffer, target.byteOffset, offset);
|
|
2110
|
+
}
|
|
2111
|
+
return target;
|
|
2112
|
+
}
|
|
2113
|
+
function _mask(source, mask, output, offset, length) {
|
|
2114
|
+
for (let i = 0;i < length; i++) {
|
|
2115
|
+
output[offset + i] = source[i] ^ mask[i & 3];
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
2118
|
+
function _unmask(buffer, mask) {
|
|
2119
|
+
for (let i = 0;i < buffer.length; i++) {
|
|
2120
|
+
buffer[i] ^= mask[i & 3];
|
|
2121
|
+
}
|
|
2122
|
+
}
|
|
2123
|
+
function toArrayBuffer(buf) {
|
|
2124
|
+
if (buf.length === buf.buffer.byteLength) {
|
|
2125
|
+
return buf.buffer;
|
|
2126
|
+
}
|
|
2127
|
+
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
|
|
2128
|
+
}
|
|
2129
|
+
function toBuffer(data) {
|
|
2130
|
+
toBuffer.readOnly = true;
|
|
2131
|
+
if (Buffer.isBuffer(data))
|
|
2132
|
+
return data;
|
|
2133
|
+
let buf;
|
|
2134
|
+
if (data instanceof ArrayBuffer) {
|
|
2135
|
+
buf = new FastBuffer(data);
|
|
2136
|
+
} else if (ArrayBuffer.isView(data)) {
|
|
2137
|
+
buf = new FastBuffer(data.buffer, data.byteOffset, data.byteLength);
|
|
2138
|
+
} else {
|
|
2139
|
+
buf = Buffer.from(data);
|
|
2140
|
+
toBuffer.readOnly = false;
|
|
2141
|
+
}
|
|
2142
|
+
return buf;
|
|
2143
|
+
}
|
|
2144
|
+
module.exports = {
|
|
2145
|
+
concat,
|
|
2146
|
+
mask: _mask,
|
|
2147
|
+
toArrayBuffer,
|
|
2148
|
+
toBuffer,
|
|
2149
|
+
unmask: _unmask
|
|
2150
|
+
};
|
|
2151
|
+
if (!process.env.WS_NO_BUFFER_UTIL) {
|
|
2152
|
+
try {
|
|
2153
|
+
const bufferUtil = (()=>{throw new Error("Cannot require module "+"bufferutil");})();
|
|
2154
|
+
module.exports.mask = function(source, mask, output, offset, length) {
|
|
2155
|
+
if (length < 48)
|
|
2156
|
+
_mask(source, mask, output, offset, length);
|
|
2157
|
+
else
|
|
2158
|
+
bufferUtil.mask(source, mask, output, offset, length);
|
|
2159
|
+
};
|
|
2160
|
+
module.exports.unmask = function(buffer, mask) {
|
|
2161
|
+
if (buffer.length < 32)
|
|
2162
|
+
_unmask(buffer, mask);
|
|
2163
|
+
else
|
|
2164
|
+
bufferUtil.unmask(buffer, mask);
|
|
2165
|
+
};
|
|
2166
|
+
} catch (e) {}
|
|
2167
|
+
}
|
|
2168
|
+
});
|
|
2169
|
+
|
|
2170
|
+
// ../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/limiter.js
|
|
2171
|
+
var require_limiter = __commonJS((exports, module) => {
|
|
2172
|
+
var kDone = Symbol("kDone");
|
|
2173
|
+
var kRun = Symbol("kRun");
|
|
2174
|
+
|
|
2175
|
+
class Limiter {
|
|
2176
|
+
constructor(concurrency) {
|
|
2177
|
+
this[kDone] = () => {
|
|
2178
|
+
this.pending--;
|
|
2179
|
+
this[kRun]();
|
|
2180
|
+
};
|
|
2181
|
+
this.concurrency = concurrency || Infinity;
|
|
2182
|
+
this.jobs = [];
|
|
2183
|
+
this.pending = 0;
|
|
2184
|
+
}
|
|
2185
|
+
add(job) {
|
|
2186
|
+
this.jobs.push(job);
|
|
2187
|
+
this[kRun]();
|
|
2188
|
+
}
|
|
2189
|
+
[kRun]() {
|
|
2190
|
+
if (this.pending === this.concurrency)
|
|
2191
|
+
return;
|
|
2192
|
+
if (this.jobs.length) {
|
|
2193
|
+
const job = this.jobs.shift();
|
|
2194
|
+
this.pending++;
|
|
2195
|
+
job(this[kDone]);
|
|
2196
|
+
}
|
|
2197
|
+
}
|
|
2198
|
+
}
|
|
2199
|
+
module.exports = Limiter;
|
|
2200
|
+
});
|
|
2201
|
+
|
|
2202
|
+
// ../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/permessage-deflate.js
|
|
2203
|
+
var require_permessage_deflate = __commonJS((exports, module) => {
|
|
2204
|
+
var zlib = __require("zlib");
|
|
2205
|
+
var bufferUtil = require_buffer_util();
|
|
2206
|
+
var Limiter = require_limiter();
|
|
2207
|
+
var { kStatusCode } = require_constants();
|
|
2208
|
+
var FastBuffer = Buffer[Symbol.species];
|
|
2209
|
+
var TRAILER = Buffer.from([0, 0, 255, 255]);
|
|
2210
|
+
var kPerMessageDeflate = Symbol("permessage-deflate");
|
|
2211
|
+
var kTotalLength = Symbol("total-length");
|
|
2212
|
+
var kCallback = Symbol("callback");
|
|
2213
|
+
var kBuffers = Symbol("buffers");
|
|
2214
|
+
var kError = Symbol("error");
|
|
2215
|
+
var zlibLimiter;
|
|
2216
|
+
|
|
2217
|
+
class PerMessageDeflate {
|
|
2218
|
+
constructor(options) {
|
|
2219
|
+
this._options = options || {};
|
|
2220
|
+
this._threshold = this._options.threshold !== undefined ? this._options.threshold : 1024;
|
|
2221
|
+
this._maxPayload = this._options.maxPayload | 0;
|
|
2222
|
+
this._isServer = !!this._options.isServer;
|
|
2223
|
+
this._deflate = null;
|
|
2224
|
+
this._inflate = null;
|
|
2225
|
+
this.params = null;
|
|
2226
|
+
if (!zlibLimiter) {
|
|
2227
|
+
const concurrency = this._options.concurrencyLimit !== undefined ? this._options.concurrencyLimit : 10;
|
|
2228
|
+
zlibLimiter = new Limiter(concurrency);
|
|
2229
|
+
}
|
|
2230
|
+
}
|
|
2231
|
+
static get extensionName() {
|
|
2232
|
+
return "permessage-deflate";
|
|
2233
|
+
}
|
|
2234
|
+
offer() {
|
|
2235
|
+
const params = {};
|
|
2236
|
+
if (this._options.serverNoContextTakeover) {
|
|
2237
|
+
params.server_no_context_takeover = true;
|
|
2238
|
+
}
|
|
2239
|
+
if (this._options.clientNoContextTakeover) {
|
|
2240
|
+
params.client_no_context_takeover = true;
|
|
2241
|
+
}
|
|
2242
|
+
if (this._options.serverMaxWindowBits) {
|
|
2243
|
+
params.server_max_window_bits = this._options.serverMaxWindowBits;
|
|
2244
|
+
}
|
|
2245
|
+
if (this._options.clientMaxWindowBits) {
|
|
2246
|
+
params.client_max_window_bits = this._options.clientMaxWindowBits;
|
|
2247
|
+
} else if (this._options.clientMaxWindowBits == null) {
|
|
2248
|
+
params.client_max_window_bits = true;
|
|
2249
|
+
}
|
|
2250
|
+
return params;
|
|
2251
|
+
}
|
|
2252
|
+
accept(configurations) {
|
|
2253
|
+
configurations = this.normalizeParams(configurations);
|
|
2254
|
+
this.params = this._isServer ? this.acceptAsServer(configurations) : this.acceptAsClient(configurations);
|
|
2255
|
+
return this.params;
|
|
2256
|
+
}
|
|
2257
|
+
cleanup() {
|
|
2258
|
+
if (this._inflate) {
|
|
2259
|
+
this._inflate.close();
|
|
2260
|
+
this._inflate = null;
|
|
2261
|
+
}
|
|
2262
|
+
if (this._deflate) {
|
|
2263
|
+
const callback = this._deflate[kCallback];
|
|
2264
|
+
this._deflate.close();
|
|
2265
|
+
this._deflate = null;
|
|
2266
|
+
if (callback) {
|
|
2267
|
+
callback(new Error("The deflate stream was closed while data was being processed"));
|
|
2268
|
+
}
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2271
|
+
acceptAsServer(offers) {
|
|
2272
|
+
const opts = this._options;
|
|
2273
|
+
const accepted = offers.find((params) => {
|
|
2274
|
+
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) {
|
|
2275
|
+
return false;
|
|
2276
|
+
}
|
|
2277
|
+
return true;
|
|
2278
|
+
});
|
|
2279
|
+
if (!accepted) {
|
|
2280
|
+
throw new Error("None of the extension offers can be accepted");
|
|
2281
|
+
}
|
|
2282
|
+
if (opts.serverNoContextTakeover) {
|
|
2283
|
+
accepted.server_no_context_takeover = true;
|
|
2284
|
+
}
|
|
2285
|
+
if (opts.clientNoContextTakeover) {
|
|
2286
|
+
accepted.client_no_context_takeover = true;
|
|
2287
|
+
}
|
|
2288
|
+
if (typeof opts.serverMaxWindowBits === "number") {
|
|
2289
|
+
accepted.server_max_window_bits = opts.serverMaxWindowBits;
|
|
2290
|
+
}
|
|
2291
|
+
if (typeof opts.clientMaxWindowBits === "number") {
|
|
2292
|
+
accepted.client_max_window_bits = opts.clientMaxWindowBits;
|
|
2293
|
+
} else if (accepted.client_max_window_bits === true || opts.clientMaxWindowBits === false) {
|
|
2294
|
+
delete accepted.client_max_window_bits;
|
|
2295
|
+
}
|
|
2296
|
+
return accepted;
|
|
2297
|
+
}
|
|
2298
|
+
acceptAsClient(response) {
|
|
2299
|
+
const params = response[0];
|
|
2300
|
+
if (this._options.clientNoContextTakeover === false && params.client_no_context_takeover) {
|
|
2301
|
+
throw new Error('Unexpected parameter "client_no_context_takeover"');
|
|
2302
|
+
}
|
|
2303
|
+
if (!params.client_max_window_bits) {
|
|
2304
|
+
if (typeof this._options.clientMaxWindowBits === "number") {
|
|
2305
|
+
params.client_max_window_bits = this._options.clientMaxWindowBits;
|
|
2306
|
+
}
|
|
2307
|
+
} else if (this._options.clientMaxWindowBits === false || typeof this._options.clientMaxWindowBits === "number" && params.client_max_window_bits > this._options.clientMaxWindowBits) {
|
|
2308
|
+
throw new Error('Unexpected or invalid parameter "client_max_window_bits"');
|
|
2309
|
+
}
|
|
2310
|
+
return params;
|
|
2311
|
+
}
|
|
2312
|
+
normalizeParams(configurations) {
|
|
2313
|
+
configurations.forEach((params) => {
|
|
2314
|
+
Object.keys(params).forEach((key) => {
|
|
2315
|
+
let value = params[key];
|
|
2316
|
+
if (value.length > 1) {
|
|
2317
|
+
throw new Error(`Parameter "${key}" must have only a single value`);
|
|
2318
|
+
}
|
|
2319
|
+
value = value[0];
|
|
2320
|
+
if (key === "client_max_window_bits") {
|
|
2321
|
+
if (value !== true) {
|
|
2322
|
+
const num = +value;
|
|
2323
|
+
if (!Number.isInteger(num) || num < 8 || num > 15) {
|
|
2324
|
+
throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
2325
|
+
}
|
|
2326
|
+
value = num;
|
|
2327
|
+
} else if (!this._isServer) {
|
|
2328
|
+
throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
2329
|
+
}
|
|
2330
|
+
} else if (key === "server_max_window_bits") {
|
|
2331
|
+
const num = +value;
|
|
2332
|
+
if (!Number.isInteger(num) || num < 8 || num > 15) {
|
|
2333
|
+
throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
2334
|
+
}
|
|
2335
|
+
value = num;
|
|
2336
|
+
} else if (key === "client_no_context_takeover" || key === "server_no_context_takeover") {
|
|
2337
|
+
if (value !== true) {
|
|
2338
|
+
throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
2339
|
+
}
|
|
2340
|
+
} else {
|
|
2341
|
+
throw new Error(`Unknown parameter "${key}"`);
|
|
2342
|
+
}
|
|
2343
|
+
params[key] = value;
|
|
2344
|
+
});
|
|
2345
|
+
});
|
|
2346
|
+
return configurations;
|
|
2347
|
+
}
|
|
2348
|
+
decompress(data, fin, callback) {
|
|
2349
|
+
zlibLimiter.add((done) => {
|
|
2350
|
+
this._decompress(data, fin, (err, result) => {
|
|
2351
|
+
done();
|
|
2352
|
+
callback(err, result);
|
|
2353
|
+
});
|
|
2354
|
+
});
|
|
2355
|
+
}
|
|
2356
|
+
compress(data, fin, callback) {
|
|
2357
|
+
zlibLimiter.add((done) => {
|
|
2358
|
+
this._compress(data, fin, (err, result) => {
|
|
2359
|
+
done();
|
|
2360
|
+
callback(err, result);
|
|
2361
|
+
});
|
|
2362
|
+
});
|
|
2363
|
+
}
|
|
2364
|
+
_decompress(data, fin, callback) {
|
|
2365
|
+
const endpoint = this._isServer ? "client" : "server";
|
|
2366
|
+
if (!this._inflate) {
|
|
2367
|
+
const key = `${endpoint}_max_window_bits`;
|
|
2368
|
+
const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
|
|
2369
|
+
this._inflate = zlib.createInflateRaw({
|
|
2370
|
+
...this._options.zlibInflateOptions,
|
|
2371
|
+
windowBits
|
|
2372
|
+
});
|
|
2373
|
+
this._inflate[kPerMessageDeflate] = this;
|
|
2374
|
+
this._inflate[kTotalLength] = 0;
|
|
2375
|
+
this._inflate[kBuffers] = [];
|
|
2376
|
+
this._inflate.on("error", inflateOnError);
|
|
2377
|
+
this._inflate.on("data", inflateOnData);
|
|
2378
|
+
}
|
|
2379
|
+
this._inflate[kCallback] = callback;
|
|
2380
|
+
this._inflate.write(data);
|
|
2381
|
+
if (fin)
|
|
2382
|
+
this._inflate.write(TRAILER);
|
|
2383
|
+
this._inflate.flush(() => {
|
|
2384
|
+
const err = this._inflate[kError];
|
|
2385
|
+
if (err) {
|
|
2386
|
+
this._inflate.close();
|
|
2387
|
+
this._inflate = null;
|
|
2388
|
+
callback(err);
|
|
2389
|
+
return;
|
|
2390
|
+
}
|
|
2391
|
+
const data2 = bufferUtil.concat(this._inflate[kBuffers], this._inflate[kTotalLength]);
|
|
2392
|
+
if (this._inflate._readableState.endEmitted) {
|
|
2393
|
+
this._inflate.close();
|
|
2394
|
+
this._inflate = null;
|
|
2395
|
+
} else {
|
|
2396
|
+
this._inflate[kTotalLength] = 0;
|
|
2397
|
+
this._inflate[kBuffers] = [];
|
|
2398
|
+
if (fin && this.params[`${endpoint}_no_context_takeover`]) {
|
|
2399
|
+
this._inflate.reset();
|
|
2400
|
+
}
|
|
2401
|
+
}
|
|
2402
|
+
callback(null, data2);
|
|
2403
|
+
});
|
|
2404
|
+
}
|
|
2405
|
+
_compress(data, fin, callback) {
|
|
2406
|
+
const endpoint = this._isServer ? "server" : "client";
|
|
2407
|
+
if (!this._deflate) {
|
|
2408
|
+
const key = `${endpoint}_max_window_bits`;
|
|
2409
|
+
const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
|
|
2410
|
+
this._deflate = zlib.createDeflateRaw({
|
|
2411
|
+
...this._options.zlibDeflateOptions,
|
|
2412
|
+
windowBits
|
|
2413
|
+
});
|
|
2414
|
+
this._deflate[kTotalLength] = 0;
|
|
2415
|
+
this._deflate[kBuffers] = [];
|
|
2416
|
+
this._deflate.on("data", deflateOnData);
|
|
2417
|
+
}
|
|
2418
|
+
this._deflate[kCallback] = callback;
|
|
2419
|
+
this._deflate.write(data);
|
|
2420
|
+
this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
|
|
2421
|
+
if (!this._deflate) {
|
|
2422
|
+
return;
|
|
2423
|
+
}
|
|
2424
|
+
let data2 = bufferUtil.concat(this._deflate[kBuffers], this._deflate[kTotalLength]);
|
|
2425
|
+
if (fin) {
|
|
2426
|
+
data2 = new FastBuffer(data2.buffer, data2.byteOffset, data2.length - 4);
|
|
2427
|
+
}
|
|
2428
|
+
this._deflate[kCallback] = null;
|
|
2429
|
+
this._deflate[kTotalLength] = 0;
|
|
2430
|
+
this._deflate[kBuffers] = [];
|
|
2431
|
+
if (fin && this.params[`${endpoint}_no_context_takeover`]) {
|
|
2432
|
+
this._deflate.reset();
|
|
2433
|
+
}
|
|
2434
|
+
callback(null, data2);
|
|
2435
|
+
});
|
|
2436
|
+
}
|
|
2437
|
+
}
|
|
2438
|
+
module.exports = PerMessageDeflate;
|
|
2439
|
+
function deflateOnData(chunk) {
|
|
2440
|
+
this[kBuffers].push(chunk);
|
|
2441
|
+
this[kTotalLength] += chunk.length;
|
|
2442
|
+
}
|
|
2443
|
+
function inflateOnData(chunk) {
|
|
2444
|
+
this[kTotalLength] += chunk.length;
|
|
2445
|
+
if (this[kPerMessageDeflate]._maxPayload < 1 || this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload) {
|
|
2446
|
+
this[kBuffers].push(chunk);
|
|
2447
|
+
return;
|
|
2448
|
+
}
|
|
2449
|
+
this[kError] = new RangeError("Max payload size exceeded");
|
|
2450
|
+
this[kError].code = "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH";
|
|
2451
|
+
this[kError][kStatusCode] = 1009;
|
|
2452
|
+
this.removeListener("data", inflateOnData);
|
|
2453
|
+
this.reset();
|
|
2454
|
+
}
|
|
2455
|
+
function inflateOnError(err) {
|
|
2456
|
+
this[kPerMessageDeflate]._inflate = null;
|
|
2457
|
+
if (this[kError]) {
|
|
2458
|
+
this[kCallback](this[kError]);
|
|
2459
|
+
return;
|
|
2460
|
+
}
|
|
2461
|
+
err[kStatusCode] = 1007;
|
|
2462
|
+
this[kCallback](err);
|
|
2463
|
+
}
|
|
2464
|
+
});
|
|
2465
|
+
|
|
2466
|
+
// ../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/validation.js
|
|
2467
|
+
var require_validation = __commonJS((exports, module) => {
|
|
2468
|
+
var { isUtf8 } = __require("buffer");
|
|
2469
|
+
var { hasBlob } = require_constants();
|
|
2470
|
+
var tokenChars = [
|
|
2471
|
+
0,
|
|
2472
|
+
0,
|
|
2473
|
+
0,
|
|
2474
|
+
0,
|
|
2475
|
+
0,
|
|
2476
|
+
0,
|
|
2477
|
+
0,
|
|
2478
|
+
0,
|
|
2479
|
+
0,
|
|
2480
|
+
0,
|
|
2481
|
+
0,
|
|
2482
|
+
0,
|
|
2483
|
+
0,
|
|
2484
|
+
0,
|
|
2485
|
+
0,
|
|
2486
|
+
0,
|
|
2487
|
+
0,
|
|
2488
|
+
0,
|
|
2489
|
+
0,
|
|
2490
|
+
0,
|
|
2491
|
+
0,
|
|
2492
|
+
0,
|
|
2493
|
+
0,
|
|
2494
|
+
0,
|
|
2495
|
+
0,
|
|
2496
|
+
0,
|
|
2497
|
+
0,
|
|
2498
|
+
0,
|
|
2499
|
+
0,
|
|
2500
|
+
0,
|
|
2501
|
+
0,
|
|
2502
|
+
0,
|
|
2503
|
+
0,
|
|
2504
|
+
1,
|
|
2505
|
+
0,
|
|
2506
|
+
1,
|
|
2507
|
+
1,
|
|
2508
|
+
1,
|
|
2509
|
+
1,
|
|
2510
|
+
1,
|
|
2511
|
+
0,
|
|
2512
|
+
0,
|
|
2513
|
+
1,
|
|
2514
|
+
1,
|
|
2515
|
+
0,
|
|
2516
|
+
1,
|
|
2517
|
+
1,
|
|
2518
|
+
0,
|
|
2519
|
+
1,
|
|
2520
|
+
1,
|
|
2521
|
+
1,
|
|
2522
|
+
1,
|
|
2523
|
+
1,
|
|
2524
|
+
1,
|
|
2525
|
+
1,
|
|
2526
|
+
1,
|
|
2527
|
+
1,
|
|
2528
|
+
1,
|
|
2529
|
+
0,
|
|
2530
|
+
0,
|
|
2531
|
+
0,
|
|
2532
|
+
0,
|
|
2533
|
+
0,
|
|
2534
|
+
0,
|
|
2535
|
+
0,
|
|
2536
|
+
1,
|
|
2537
|
+
1,
|
|
2538
|
+
1,
|
|
2539
|
+
1,
|
|
2540
|
+
1,
|
|
2541
|
+
1,
|
|
2542
|
+
1,
|
|
2543
|
+
1,
|
|
2544
|
+
1,
|
|
2545
|
+
1,
|
|
2546
|
+
1,
|
|
2547
|
+
1,
|
|
2548
|
+
1,
|
|
2549
|
+
1,
|
|
2550
|
+
1,
|
|
2551
|
+
1,
|
|
2552
|
+
1,
|
|
2553
|
+
1,
|
|
2554
|
+
1,
|
|
2555
|
+
1,
|
|
2556
|
+
1,
|
|
2557
|
+
1,
|
|
2558
|
+
1,
|
|
2559
|
+
1,
|
|
2560
|
+
1,
|
|
2561
|
+
1,
|
|
2562
|
+
0,
|
|
2563
|
+
0,
|
|
2564
|
+
0,
|
|
2565
|
+
1,
|
|
2566
|
+
1,
|
|
2567
|
+
1,
|
|
2568
|
+
1,
|
|
2569
|
+
1,
|
|
2570
|
+
1,
|
|
2571
|
+
1,
|
|
2572
|
+
1,
|
|
2573
|
+
1,
|
|
2574
|
+
1,
|
|
2575
|
+
1,
|
|
2576
|
+
1,
|
|
2577
|
+
1,
|
|
2578
|
+
1,
|
|
2579
|
+
1,
|
|
2580
|
+
1,
|
|
2581
|
+
1,
|
|
2582
|
+
1,
|
|
2583
|
+
1,
|
|
2584
|
+
1,
|
|
2585
|
+
1,
|
|
2586
|
+
1,
|
|
2587
|
+
1,
|
|
2588
|
+
1,
|
|
2589
|
+
1,
|
|
2590
|
+
1,
|
|
2591
|
+
1,
|
|
2592
|
+
1,
|
|
2593
|
+
1,
|
|
2594
|
+
0,
|
|
2595
|
+
1,
|
|
2596
|
+
0,
|
|
2597
|
+
1,
|
|
2598
|
+
0
|
|
2599
|
+
];
|
|
2600
|
+
function isValidStatusCode(code) {
|
|
2601
|
+
return code >= 1000 && code <= 1014 && code !== 1004 && code !== 1005 && code !== 1006 || code >= 3000 && code <= 4999;
|
|
2602
|
+
}
|
|
2603
|
+
function _isValidUTF8(buf) {
|
|
2604
|
+
const len = buf.length;
|
|
2605
|
+
let i = 0;
|
|
2606
|
+
while (i < len) {
|
|
2607
|
+
if ((buf[i] & 128) === 0) {
|
|
2608
|
+
i++;
|
|
2609
|
+
} else if ((buf[i] & 224) === 192) {
|
|
2610
|
+
if (i + 1 === len || (buf[i + 1] & 192) !== 128 || (buf[i] & 254) === 192) {
|
|
2611
|
+
return false;
|
|
2612
|
+
}
|
|
2613
|
+
i += 2;
|
|
2614
|
+
} else if ((buf[i] & 240) === 224) {
|
|
2615
|
+
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) {
|
|
2616
|
+
return false;
|
|
2617
|
+
}
|
|
2618
|
+
i += 3;
|
|
2619
|
+
} else if ((buf[i] & 248) === 240) {
|
|
2620
|
+
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) {
|
|
2621
|
+
return false;
|
|
2622
|
+
}
|
|
2623
|
+
i += 4;
|
|
2624
|
+
} else {
|
|
2625
|
+
return false;
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
return true;
|
|
2629
|
+
}
|
|
2630
|
+
function isBlob(value) {
|
|
2631
|
+
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");
|
|
2632
|
+
}
|
|
2633
|
+
module.exports = {
|
|
2634
|
+
isBlob,
|
|
2635
|
+
isValidStatusCode,
|
|
2636
|
+
isValidUTF8: _isValidUTF8,
|
|
2637
|
+
tokenChars
|
|
2638
|
+
};
|
|
2639
|
+
if (isUtf8) {
|
|
2640
|
+
module.exports.isValidUTF8 = function(buf) {
|
|
2641
|
+
return buf.length < 24 ? _isValidUTF8(buf) : isUtf8(buf);
|
|
2642
|
+
};
|
|
2643
|
+
} else if (!process.env.WS_NO_UTF_8_VALIDATE) {
|
|
2644
|
+
try {
|
|
2645
|
+
const isValidUTF8 = (()=>{throw new Error("Cannot require module "+"utf-8-validate");})();
|
|
2646
|
+
module.exports.isValidUTF8 = function(buf) {
|
|
2647
|
+
return buf.length < 32 ? _isValidUTF8(buf) : isValidUTF8(buf);
|
|
2648
|
+
};
|
|
2649
|
+
} catch (e) {}
|
|
2650
|
+
}
|
|
2651
|
+
});
|
|
2652
|
+
|
|
2653
|
+
// ../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/receiver.js
|
|
2654
|
+
var require_receiver = __commonJS((exports, module) => {
|
|
2655
|
+
var { Writable } = __require("stream");
|
|
2656
|
+
var PerMessageDeflate = require_permessage_deflate();
|
|
2657
|
+
var {
|
|
2658
|
+
BINARY_TYPES,
|
|
2659
|
+
EMPTY_BUFFER,
|
|
2660
|
+
kStatusCode,
|
|
2661
|
+
kWebSocket
|
|
2662
|
+
} = require_constants();
|
|
2663
|
+
var { concat, toArrayBuffer, unmask } = require_buffer_util();
|
|
2664
|
+
var { isValidStatusCode, isValidUTF8 } = require_validation();
|
|
2665
|
+
var FastBuffer = Buffer[Symbol.species];
|
|
2666
|
+
var GET_INFO = 0;
|
|
2667
|
+
var GET_PAYLOAD_LENGTH_16 = 1;
|
|
2668
|
+
var GET_PAYLOAD_LENGTH_64 = 2;
|
|
2669
|
+
var GET_MASK = 3;
|
|
2670
|
+
var GET_DATA = 4;
|
|
2671
|
+
var INFLATING = 5;
|
|
2672
|
+
var DEFER_EVENT = 6;
|
|
2673
|
+
|
|
2674
|
+
class Receiver extends Writable {
|
|
2675
|
+
constructor(options = {}) {
|
|
2676
|
+
super();
|
|
2677
|
+
this._allowSynchronousEvents = options.allowSynchronousEvents !== undefined ? options.allowSynchronousEvents : true;
|
|
2678
|
+
this._binaryType = options.binaryType || BINARY_TYPES[0];
|
|
2679
|
+
this._extensions = options.extensions || {};
|
|
2680
|
+
this._isServer = !!options.isServer;
|
|
2681
|
+
this._maxPayload = options.maxPayload | 0;
|
|
2682
|
+
this._skipUTF8Validation = !!options.skipUTF8Validation;
|
|
2683
|
+
this[kWebSocket] = undefined;
|
|
2684
|
+
this._bufferedBytes = 0;
|
|
2685
|
+
this._buffers = [];
|
|
2686
|
+
this._compressed = false;
|
|
2687
|
+
this._payloadLength = 0;
|
|
2688
|
+
this._mask = undefined;
|
|
2689
|
+
this._fragmented = 0;
|
|
2690
|
+
this._masked = false;
|
|
2691
|
+
this._fin = false;
|
|
2692
|
+
this._opcode = 0;
|
|
2693
|
+
this._totalPayloadLength = 0;
|
|
2694
|
+
this._messageLength = 0;
|
|
2695
|
+
this._fragments = [];
|
|
2696
|
+
this._errored = false;
|
|
2697
|
+
this._loop = false;
|
|
2698
|
+
this._state = GET_INFO;
|
|
2699
|
+
}
|
|
2700
|
+
_write(chunk, encoding, cb) {
|
|
2701
|
+
if (this._opcode === 8 && this._state == GET_INFO)
|
|
2702
|
+
return cb();
|
|
2703
|
+
this._bufferedBytes += chunk.length;
|
|
2704
|
+
this._buffers.push(chunk);
|
|
2705
|
+
this.startLoop(cb);
|
|
2706
|
+
}
|
|
2707
|
+
consume(n) {
|
|
2708
|
+
this._bufferedBytes -= n;
|
|
2709
|
+
if (n === this._buffers[0].length)
|
|
2710
|
+
return this._buffers.shift();
|
|
2711
|
+
if (n < this._buffers[0].length) {
|
|
2712
|
+
const buf = this._buffers[0];
|
|
2713
|
+
this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n);
|
|
2714
|
+
return new FastBuffer(buf.buffer, buf.byteOffset, n);
|
|
2715
|
+
}
|
|
2716
|
+
const dst = Buffer.allocUnsafe(n);
|
|
2717
|
+
do {
|
|
2718
|
+
const buf = this._buffers[0];
|
|
2719
|
+
const offset = dst.length - n;
|
|
2720
|
+
if (n >= buf.length) {
|
|
2721
|
+
dst.set(this._buffers.shift(), offset);
|
|
2722
|
+
} else {
|
|
2723
|
+
dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
|
|
2724
|
+
this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n);
|
|
2725
|
+
}
|
|
2726
|
+
n -= buf.length;
|
|
2727
|
+
} while (n > 0);
|
|
2728
|
+
return dst;
|
|
2729
|
+
}
|
|
2730
|
+
startLoop(cb) {
|
|
2731
|
+
this._loop = true;
|
|
2732
|
+
do {
|
|
2733
|
+
switch (this._state) {
|
|
2734
|
+
case GET_INFO:
|
|
2735
|
+
this.getInfo(cb);
|
|
2736
|
+
break;
|
|
2737
|
+
case GET_PAYLOAD_LENGTH_16:
|
|
2738
|
+
this.getPayloadLength16(cb);
|
|
2739
|
+
break;
|
|
2740
|
+
case GET_PAYLOAD_LENGTH_64:
|
|
2741
|
+
this.getPayloadLength64(cb);
|
|
2742
|
+
break;
|
|
2743
|
+
case GET_MASK:
|
|
2744
|
+
this.getMask();
|
|
2745
|
+
break;
|
|
2746
|
+
case GET_DATA:
|
|
2747
|
+
this.getData(cb);
|
|
2748
|
+
break;
|
|
2749
|
+
case INFLATING:
|
|
2750
|
+
case DEFER_EVENT:
|
|
2751
|
+
this._loop = false;
|
|
2752
|
+
return;
|
|
2753
|
+
}
|
|
2754
|
+
} while (this._loop);
|
|
2755
|
+
if (!this._errored)
|
|
2756
|
+
cb();
|
|
2757
|
+
}
|
|
2758
|
+
getInfo(cb) {
|
|
2759
|
+
if (this._bufferedBytes < 2) {
|
|
2760
|
+
this._loop = false;
|
|
2761
|
+
return;
|
|
2762
|
+
}
|
|
2763
|
+
const buf = this.consume(2);
|
|
2764
|
+
if ((buf[0] & 48) !== 0) {
|
|
2765
|
+
const error2 = this.createError(RangeError, "RSV2 and RSV3 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_2_3");
|
|
2766
|
+
cb(error2);
|
|
2767
|
+
return;
|
|
2768
|
+
}
|
|
2769
|
+
const compressed = (buf[0] & 64) === 64;
|
|
2770
|
+
if (compressed && !this._extensions[PerMessageDeflate.extensionName]) {
|
|
2771
|
+
const error2 = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
|
|
2772
|
+
cb(error2);
|
|
2773
|
+
return;
|
|
2774
|
+
}
|
|
2775
|
+
this._fin = (buf[0] & 128) === 128;
|
|
2776
|
+
this._opcode = buf[0] & 15;
|
|
2777
|
+
this._payloadLength = buf[1] & 127;
|
|
2778
|
+
if (this._opcode === 0) {
|
|
2779
|
+
if (compressed) {
|
|
2780
|
+
const error2 = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
|
|
2781
|
+
cb(error2);
|
|
2782
|
+
return;
|
|
2783
|
+
}
|
|
2784
|
+
if (!this._fragmented) {
|
|
2785
|
+
const error2 = this.createError(RangeError, "invalid opcode 0", true, 1002, "WS_ERR_INVALID_OPCODE");
|
|
2786
|
+
cb(error2);
|
|
2787
|
+
return;
|
|
2788
|
+
}
|
|
2789
|
+
this._opcode = this._fragmented;
|
|
2790
|
+
} else if (this._opcode === 1 || this._opcode === 2) {
|
|
2791
|
+
if (this._fragmented) {
|
|
2792
|
+
const error2 = this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, "WS_ERR_INVALID_OPCODE");
|
|
2793
|
+
cb(error2);
|
|
2794
|
+
return;
|
|
2795
|
+
}
|
|
2796
|
+
this._compressed = compressed;
|
|
2797
|
+
} else if (this._opcode > 7 && this._opcode < 11) {
|
|
2798
|
+
if (!this._fin) {
|
|
2799
|
+
const error2 = this.createError(RangeError, "FIN must be set", true, 1002, "WS_ERR_EXPECTED_FIN");
|
|
2800
|
+
cb(error2);
|
|
2801
|
+
return;
|
|
2802
|
+
}
|
|
2803
|
+
if (compressed) {
|
|
2804
|
+
const error2 = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
|
|
2805
|
+
cb(error2);
|
|
2806
|
+
return;
|
|
2807
|
+
}
|
|
2808
|
+
if (this._payloadLength > 125 || this._opcode === 8 && this._payloadLength === 1) {
|
|
2809
|
+
const error2 = this.createError(RangeError, `invalid payload length ${this._payloadLength}`, true, 1002, "WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");
|
|
2810
|
+
cb(error2);
|
|
2811
|
+
return;
|
|
2812
|
+
}
|
|
2813
|
+
} else {
|
|
2814
|
+
const error2 = this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, "WS_ERR_INVALID_OPCODE");
|
|
2815
|
+
cb(error2);
|
|
2816
|
+
return;
|
|
2817
|
+
}
|
|
2818
|
+
if (!this._fin && !this._fragmented)
|
|
2819
|
+
this._fragmented = this._opcode;
|
|
2820
|
+
this._masked = (buf[1] & 128) === 128;
|
|
2821
|
+
if (this._isServer) {
|
|
2822
|
+
if (!this._masked) {
|
|
2823
|
+
const error2 = this.createError(RangeError, "MASK must be set", true, 1002, "WS_ERR_EXPECTED_MASK");
|
|
2824
|
+
cb(error2);
|
|
2825
|
+
return;
|
|
2826
|
+
}
|
|
2827
|
+
} else if (this._masked) {
|
|
2828
|
+
const error2 = this.createError(RangeError, "MASK must be clear", true, 1002, "WS_ERR_UNEXPECTED_MASK");
|
|
2829
|
+
cb(error2);
|
|
2830
|
+
return;
|
|
2831
|
+
}
|
|
2832
|
+
if (this._payloadLength === 126)
|
|
2833
|
+
this._state = GET_PAYLOAD_LENGTH_16;
|
|
2834
|
+
else if (this._payloadLength === 127)
|
|
2835
|
+
this._state = GET_PAYLOAD_LENGTH_64;
|
|
2836
|
+
else
|
|
2837
|
+
this.haveLength(cb);
|
|
2838
|
+
}
|
|
2839
|
+
getPayloadLength16(cb) {
|
|
2840
|
+
if (this._bufferedBytes < 2) {
|
|
2841
|
+
this._loop = false;
|
|
2842
|
+
return;
|
|
2843
|
+
}
|
|
2844
|
+
this._payloadLength = this.consume(2).readUInt16BE(0);
|
|
2845
|
+
this.haveLength(cb);
|
|
2846
|
+
}
|
|
2847
|
+
getPayloadLength64(cb) {
|
|
2848
|
+
if (this._bufferedBytes < 8) {
|
|
2849
|
+
this._loop = false;
|
|
2850
|
+
return;
|
|
2851
|
+
}
|
|
2852
|
+
const buf = this.consume(8);
|
|
2853
|
+
const num = buf.readUInt32BE(0);
|
|
2854
|
+
if (num > Math.pow(2, 53 - 32) - 1) {
|
|
2855
|
+
const error2 = this.createError(RangeError, "Unsupported WebSocket frame: payload length > 2^53 - 1", false, 1009, "WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");
|
|
2856
|
+
cb(error2);
|
|
2857
|
+
return;
|
|
2858
|
+
}
|
|
2859
|
+
this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
|
|
2860
|
+
this.haveLength(cb);
|
|
2861
|
+
}
|
|
2862
|
+
haveLength(cb) {
|
|
2863
|
+
if (this._payloadLength && this._opcode < 8) {
|
|
2864
|
+
this._totalPayloadLength += this._payloadLength;
|
|
2865
|
+
if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
|
|
2866
|
+
const error2 = this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");
|
|
2867
|
+
cb(error2);
|
|
2868
|
+
return;
|
|
2869
|
+
}
|
|
2870
|
+
}
|
|
2871
|
+
if (this._masked)
|
|
2872
|
+
this._state = GET_MASK;
|
|
2873
|
+
else
|
|
2874
|
+
this._state = GET_DATA;
|
|
2875
|
+
}
|
|
2876
|
+
getMask() {
|
|
2877
|
+
if (this._bufferedBytes < 4) {
|
|
2878
|
+
this._loop = false;
|
|
2879
|
+
return;
|
|
2880
|
+
}
|
|
2881
|
+
this._mask = this.consume(4);
|
|
2882
|
+
this._state = GET_DATA;
|
|
2883
|
+
}
|
|
2884
|
+
getData(cb) {
|
|
2885
|
+
let data = EMPTY_BUFFER;
|
|
2886
|
+
if (this._payloadLength) {
|
|
2887
|
+
if (this._bufferedBytes < this._payloadLength) {
|
|
2888
|
+
this._loop = false;
|
|
2889
|
+
return;
|
|
2890
|
+
}
|
|
2891
|
+
data = this.consume(this._payloadLength);
|
|
2892
|
+
if (this._masked && (this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0) {
|
|
2893
|
+
unmask(data, this._mask);
|
|
2894
|
+
}
|
|
2895
|
+
}
|
|
2896
|
+
if (this._opcode > 7) {
|
|
2897
|
+
this.controlMessage(data, cb);
|
|
2898
|
+
return;
|
|
2899
|
+
}
|
|
2900
|
+
if (this._compressed) {
|
|
2901
|
+
this._state = INFLATING;
|
|
2902
|
+
this.decompress(data, cb);
|
|
2903
|
+
return;
|
|
2904
|
+
}
|
|
2905
|
+
if (data.length) {
|
|
2906
|
+
this._messageLength = this._totalPayloadLength;
|
|
2907
|
+
this._fragments.push(data);
|
|
2908
|
+
}
|
|
2909
|
+
this.dataMessage(cb);
|
|
2910
|
+
}
|
|
2911
|
+
decompress(data, cb) {
|
|
2912
|
+
const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
|
|
2913
|
+
perMessageDeflate.decompress(data, this._fin, (err, buf) => {
|
|
2914
|
+
if (err)
|
|
2915
|
+
return cb(err);
|
|
2916
|
+
if (buf.length) {
|
|
2917
|
+
this._messageLength += buf.length;
|
|
2918
|
+
if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
|
|
2919
|
+
const error2 = this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");
|
|
2920
|
+
cb(error2);
|
|
2921
|
+
return;
|
|
2922
|
+
}
|
|
2923
|
+
this._fragments.push(buf);
|
|
2924
|
+
}
|
|
2925
|
+
this.dataMessage(cb);
|
|
2926
|
+
if (this._state === GET_INFO)
|
|
2927
|
+
this.startLoop(cb);
|
|
2928
|
+
});
|
|
2929
|
+
}
|
|
2930
|
+
dataMessage(cb) {
|
|
2931
|
+
if (!this._fin) {
|
|
2932
|
+
this._state = GET_INFO;
|
|
2933
|
+
return;
|
|
2934
|
+
}
|
|
2935
|
+
const messageLength = this._messageLength;
|
|
2936
|
+
const fragments = this._fragments;
|
|
2937
|
+
this._totalPayloadLength = 0;
|
|
2938
|
+
this._messageLength = 0;
|
|
2939
|
+
this._fragmented = 0;
|
|
2940
|
+
this._fragments = [];
|
|
2941
|
+
if (this._opcode === 2) {
|
|
2942
|
+
let data;
|
|
2943
|
+
if (this._binaryType === "nodebuffer") {
|
|
2944
|
+
data = concat(fragments, messageLength);
|
|
2945
|
+
} else if (this._binaryType === "arraybuffer") {
|
|
2946
|
+
data = toArrayBuffer(concat(fragments, messageLength));
|
|
2947
|
+
} else if (this._binaryType === "blob") {
|
|
2948
|
+
data = new Blob(fragments);
|
|
2949
|
+
} else {
|
|
2950
|
+
data = fragments;
|
|
2951
|
+
}
|
|
2952
|
+
if (this._allowSynchronousEvents) {
|
|
2953
|
+
this.emit("message", data, true);
|
|
2954
|
+
this._state = GET_INFO;
|
|
2955
|
+
} else {
|
|
2956
|
+
this._state = DEFER_EVENT;
|
|
2957
|
+
setImmediate(() => {
|
|
2958
|
+
this.emit("message", data, true);
|
|
2959
|
+
this._state = GET_INFO;
|
|
2960
|
+
this.startLoop(cb);
|
|
2961
|
+
});
|
|
2962
|
+
}
|
|
2963
|
+
} else {
|
|
2964
|
+
const buf = concat(fragments, messageLength);
|
|
2965
|
+
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
|
|
2966
|
+
const error2 = this.createError(Error, "invalid UTF-8 sequence", true, 1007, "WS_ERR_INVALID_UTF8");
|
|
2967
|
+
cb(error2);
|
|
2968
|
+
return;
|
|
2969
|
+
}
|
|
2970
|
+
if (this._state === INFLATING || this._allowSynchronousEvents) {
|
|
2971
|
+
this.emit("message", buf, false);
|
|
2972
|
+
this._state = GET_INFO;
|
|
2973
|
+
} else {
|
|
2974
|
+
this._state = DEFER_EVENT;
|
|
2975
|
+
setImmediate(() => {
|
|
2976
|
+
this.emit("message", buf, false);
|
|
2977
|
+
this._state = GET_INFO;
|
|
2978
|
+
this.startLoop(cb);
|
|
2979
|
+
});
|
|
2980
|
+
}
|
|
2981
|
+
}
|
|
2982
|
+
}
|
|
2983
|
+
controlMessage(data, cb) {
|
|
2984
|
+
if (this._opcode === 8) {
|
|
2985
|
+
if (data.length === 0) {
|
|
2986
|
+
this._loop = false;
|
|
2987
|
+
this.emit("conclude", 1005, EMPTY_BUFFER);
|
|
2988
|
+
this.end();
|
|
2989
|
+
} else {
|
|
2990
|
+
const code = data.readUInt16BE(0);
|
|
2991
|
+
if (!isValidStatusCode(code)) {
|
|
2992
|
+
const error2 = this.createError(RangeError, `invalid status code ${code}`, true, 1002, "WS_ERR_INVALID_CLOSE_CODE");
|
|
2993
|
+
cb(error2);
|
|
2994
|
+
return;
|
|
2995
|
+
}
|
|
2996
|
+
const buf = new FastBuffer(data.buffer, data.byteOffset + 2, data.length - 2);
|
|
2997
|
+
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
|
|
2998
|
+
const error2 = this.createError(Error, "invalid UTF-8 sequence", true, 1007, "WS_ERR_INVALID_UTF8");
|
|
2999
|
+
cb(error2);
|
|
3000
|
+
return;
|
|
3001
|
+
}
|
|
3002
|
+
this._loop = false;
|
|
3003
|
+
this.emit("conclude", code, buf);
|
|
3004
|
+
this.end();
|
|
3005
|
+
}
|
|
3006
|
+
this._state = GET_INFO;
|
|
3007
|
+
return;
|
|
3008
|
+
}
|
|
3009
|
+
if (this._allowSynchronousEvents) {
|
|
3010
|
+
this.emit(this._opcode === 9 ? "ping" : "pong", data);
|
|
3011
|
+
this._state = GET_INFO;
|
|
3012
|
+
} else {
|
|
3013
|
+
this._state = DEFER_EVENT;
|
|
3014
|
+
setImmediate(() => {
|
|
3015
|
+
this.emit(this._opcode === 9 ? "ping" : "pong", data);
|
|
3016
|
+
this._state = GET_INFO;
|
|
3017
|
+
this.startLoop(cb);
|
|
3018
|
+
});
|
|
3019
|
+
}
|
|
3020
|
+
}
|
|
3021
|
+
createError(ErrorCtor, message, prefix, statusCode, errorCode) {
|
|
3022
|
+
this._loop = false;
|
|
3023
|
+
this._errored = true;
|
|
3024
|
+
const err = new ErrorCtor(prefix ? `Invalid WebSocket frame: ${message}` : message);
|
|
3025
|
+
Error.captureStackTrace(err, this.createError);
|
|
3026
|
+
err.code = errorCode;
|
|
3027
|
+
err[kStatusCode] = statusCode;
|
|
3028
|
+
return err;
|
|
3029
|
+
}
|
|
3030
|
+
}
|
|
3031
|
+
module.exports = Receiver;
|
|
3032
|
+
});
|
|
3033
|
+
|
|
3034
|
+
// ../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/sender.js
|
|
3035
|
+
var require_sender = __commonJS((exports, module) => {
|
|
3036
|
+
var { Duplex } = __require("stream");
|
|
3037
|
+
var { randomFillSync } = __require("crypto");
|
|
3038
|
+
var PerMessageDeflate = require_permessage_deflate();
|
|
3039
|
+
var { EMPTY_BUFFER, kWebSocket, NOOP } = require_constants();
|
|
3040
|
+
var { isBlob, isValidStatusCode } = require_validation();
|
|
3041
|
+
var { mask: applyMask, toBuffer } = require_buffer_util();
|
|
3042
|
+
var kByteLength = Symbol("kByteLength");
|
|
3043
|
+
var maskBuffer = Buffer.alloc(4);
|
|
3044
|
+
var RANDOM_POOL_SIZE = 8 * 1024;
|
|
3045
|
+
var randomPool;
|
|
3046
|
+
var randomPoolPointer = RANDOM_POOL_SIZE;
|
|
3047
|
+
var DEFAULT = 0;
|
|
3048
|
+
var DEFLATING = 1;
|
|
3049
|
+
var GET_BLOB_DATA = 2;
|
|
3050
|
+
|
|
3051
|
+
class Sender {
|
|
3052
|
+
constructor(socket, extensions, generateMask) {
|
|
3053
|
+
this._extensions = extensions || {};
|
|
3054
|
+
if (generateMask) {
|
|
3055
|
+
this._generateMask = generateMask;
|
|
3056
|
+
this._maskBuffer = Buffer.alloc(4);
|
|
3057
|
+
}
|
|
3058
|
+
this._socket = socket;
|
|
3059
|
+
this._firstFragment = true;
|
|
3060
|
+
this._compress = false;
|
|
3061
|
+
this._bufferedBytes = 0;
|
|
3062
|
+
this._queue = [];
|
|
3063
|
+
this._state = DEFAULT;
|
|
3064
|
+
this.onerror = NOOP;
|
|
3065
|
+
this[kWebSocket] = undefined;
|
|
3066
|
+
}
|
|
3067
|
+
static frame(data, options) {
|
|
3068
|
+
let mask;
|
|
3069
|
+
let merge = false;
|
|
3070
|
+
let offset = 2;
|
|
3071
|
+
let skipMasking = false;
|
|
3072
|
+
if (options.mask) {
|
|
3073
|
+
mask = options.maskBuffer || maskBuffer;
|
|
3074
|
+
if (options.generateMask) {
|
|
3075
|
+
options.generateMask(mask);
|
|
3076
|
+
} else {
|
|
3077
|
+
if (randomPoolPointer === RANDOM_POOL_SIZE) {
|
|
3078
|
+
if (randomPool === undefined) {
|
|
3079
|
+
randomPool = Buffer.alloc(RANDOM_POOL_SIZE);
|
|
3080
|
+
}
|
|
3081
|
+
randomFillSync(randomPool, 0, RANDOM_POOL_SIZE);
|
|
3082
|
+
randomPoolPointer = 0;
|
|
3083
|
+
}
|
|
3084
|
+
mask[0] = randomPool[randomPoolPointer++];
|
|
3085
|
+
mask[1] = randomPool[randomPoolPointer++];
|
|
3086
|
+
mask[2] = randomPool[randomPoolPointer++];
|
|
3087
|
+
mask[3] = randomPool[randomPoolPointer++];
|
|
3088
|
+
}
|
|
3089
|
+
skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) === 0;
|
|
3090
|
+
offset = 6;
|
|
3091
|
+
}
|
|
3092
|
+
let dataLength;
|
|
3093
|
+
if (typeof data === "string") {
|
|
3094
|
+
if ((!options.mask || skipMasking) && options[kByteLength] !== undefined) {
|
|
3095
|
+
dataLength = options[kByteLength];
|
|
3096
|
+
} else {
|
|
3097
|
+
data = Buffer.from(data);
|
|
3098
|
+
dataLength = data.length;
|
|
3099
|
+
}
|
|
3100
|
+
} else {
|
|
3101
|
+
dataLength = data.length;
|
|
3102
|
+
merge = options.mask && options.readOnly && !skipMasking;
|
|
3103
|
+
}
|
|
3104
|
+
let payloadLength = dataLength;
|
|
3105
|
+
if (dataLength >= 65536) {
|
|
3106
|
+
offset += 8;
|
|
3107
|
+
payloadLength = 127;
|
|
3108
|
+
} else if (dataLength > 125) {
|
|
3109
|
+
offset += 2;
|
|
3110
|
+
payloadLength = 126;
|
|
3111
|
+
}
|
|
3112
|
+
const target = Buffer.allocUnsafe(merge ? dataLength + offset : offset);
|
|
3113
|
+
target[0] = options.fin ? options.opcode | 128 : options.opcode;
|
|
3114
|
+
if (options.rsv1)
|
|
3115
|
+
target[0] |= 64;
|
|
3116
|
+
target[1] = payloadLength;
|
|
3117
|
+
if (payloadLength === 126) {
|
|
3118
|
+
target.writeUInt16BE(dataLength, 2);
|
|
3119
|
+
} else if (payloadLength === 127) {
|
|
3120
|
+
target[2] = target[3] = 0;
|
|
3121
|
+
target.writeUIntBE(dataLength, 4, 6);
|
|
3122
|
+
}
|
|
3123
|
+
if (!options.mask)
|
|
3124
|
+
return [target, data];
|
|
3125
|
+
target[1] |= 128;
|
|
3126
|
+
target[offset - 4] = mask[0];
|
|
3127
|
+
target[offset - 3] = mask[1];
|
|
3128
|
+
target[offset - 2] = mask[2];
|
|
3129
|
+
target[offset - 1] = mask[3];
|
|
3130
|
+
if (skipMasking)
|
|
3131
|
+
return [target, data];
|
|
3132
|
+
if (merge) {
|
|
3133
|
+
applyMask(data, mask, target, offset, dataLength);
|
|
3134
|
+
return [target];
|
|
3135
|
+
}
|
|
3136
|
+
applyMask(data, mask, data, 0, dataLength);
|
|
3137
|
+
return [target, data];
|
|
3138
|
+
}
|
|
3139
|
+
close(code, data, mask, cb) {
|
|
3140
|
+
let buf;
|
|
3141
|
+
if (code === undefined) {
|
|
3142
|
+
buf = EMPTY_BUFFER;
|
|
3143
|
+
} else if (typeof code !== "number" || !isValidStatusCode(code)) {
|
|
3144
|
+
throw new TypeError("First argument must be a valid error code number");
|
|
3145
|
+
} else if (data === undefined || !data.length) {
|
|
3146
|
+
buf = Buffer.allocUnsafe(2);
|
|
3147
|
+
buf.writeUInt16BE(code, 0);
|
|
3148
|
+
} else {
|
|
3149
|
+
const length = Buffer.byteLength(data);
|
|
3150
|
+
if (length > 123) {
|
|
3151
|
+
throw new RangeError("The message must not be greater than 123 bytes");
|
|
3152
|
+
}
|
|
3153
|
+
buf = Buffer.allocUnsafe(2 + length);
|
|
3154
|
+
buf.writeUInt16BE(code, 0);
|
|
3155
|
+
if (typeof data === "string") {
|
|
3156
|
+
buf.write(data, 2);
|
|
3157
|
+
} else {
|
|
3158
|
+
buf.set(data, 2);
|
|
3159
|
+
}
|
|
3160
|
+
}
|
|
3161
|
+
const options = {
|
|
3162
|
+
[kByteLength]: buf.length,
|
|
3163
|
+
fin: true,
|
|
3164
|
+
generateMask: this._generateMask,
|
|
3165
|
+
mask,
|
|
3166
|
+
maskBuffer: this._maskBuffer,
|
|
3167
|
+
opcode: 8,
|
|
3168
|
+
readOnly: false,
|
|
3169
|
+
rsv1: false
|
|
3170
|
+
};
|
|
3171
|
+
if (this._state !== DEFAULT) {
|
|
3172
|
+
this.enqueue([this.dispatch, buf, false, options, cb]);
|
|
3173
|
+
} else {
|
|
3174
|
+
this.sendFrame(Sender.frame(buf, options), cb);
|
|
3175
|
+
}
|
|
3176
|
+
}
|
|
3177
|
+
ping(data, mask, cb) {
|
|
3178
|
+
let byteLength;
|
|
3179
|
+
let readOnly;
|
|
3180
|
+
if (typeof data === "string") {
|
|
3181
|
+
byteLength = Buffer.byteLength(data);
|
|
3182
|
+
readOnly = false;
|
|
3183
|
+
} else if (isBlob(data)) {
|
|
3184
|
+
byteLength = data.size;
|
|
3185
|
+
readOnly = false;
|
|
3186
|
+
} else {
|
|
3187
|
+
data = toBuffer(data);
|
|
3188
|
+
byteLength = data.length;
|
|
3189
|
+
readOnly = toBuffer.readOnly;
|
|
3190
|
+
}
|
|
3191
|
+
if (byteLength > 125) {
|
|
3192
|
+
throw new RangeError("The data size must not be greater than 125 bytes");
|
|
3193
|
+
}
|
|
3194
|
+
const options = {
|
|
3195
|
+
[kByteLength]: byteLength,
|
|
3196
|
+
fin: true,
|
|
3197
|
+
generateMask: this._generateMask,
|
|
3198
|
+
mask,
|
|
3199
|
+
maskBuffer: this._maskBuffer,
|
|
3200
|
+
opcode: 9,
|
|
3201
|
+
readOnly,
|
|
3202
|
+
rsv1: false
|
|
3203
|
+
};
|
|
3204
|
+
if (isBlob(data)) {
|
|
3205
|
+
if (this._state !== DEFAULT) {
|
|
3206
|
+
this.enqueue([this.getBlobData, data, false, options, cb]);
|
|
3207
|
+
} else {
|
|
3208
|
+
this.getBlobData(data, false, options, cb);
|
|
3209
|
+
}
|
|
3210
|
+
} else if (this._state !== DEFAULT) {
|
|
3211
|
+
this.enqueue([this.dispatch, data, false, options, cb]);
|
|
3212
|
+
} else {
|
|
3213
|
+
this.sendFrame(Sender.frame(data, options), cb);
|
|
3214
|
+
}
|
|
3215
|
+
}
|
|
3216
|
+
pong(data, mask, cb) {
|
|
3217
|
+
let byteLength;
|
|
3218
|
+
let readOnly;
|
|
3219
|
+
if (typeof data === "string") {
|
|
3220
|
+
byteLength = Buffer.byteLength(data);
|
|
3221
|
+
readOnly = false;
|
|
3222
|
+
} else if (isBlob(data)) {
|
|
3223
|
+
byteLength = data.size;
|
|
3224
|
+
readOnly = false;
|
|
3225
|
+
} else {
|
|
3226
|
+
data = toBuffer(data);
|
|
3227
|
+
byteLength = data.length;
|
|
3228
|
+
readOnly = toBuffer.readOnly;
|
|
3229
|
+
}
|
|
3230
|
+
if (byteLength > 125) {
|
|
3231
|
+
throw new RangeError("The data size must not be greater than 125 bytes");
|
|
3232
|
+
}
|
|
3233
|
+
const options = {
|
|
3234
|
+
[kByteLength]: byteLength,
|
|
3235
|
+
fin: true,
|
|
3236
|
+
generateMask: this._generateMask,
|
|
3237
|
+
mask,
|
|
3238
|
+
maskBuffer: this._maskBuffer,
|
|
3239
|
+
opcode: 10,
|
|
3240
|
+
readOnly,
|
|
3241
|
+
rsv1: false
|
|
3242
|
+
};
|
|
3243
|
+
if (isBlob(data)) {
|
|
3244
|
+
if (this._state !== DEFAULT) {
|
|
3245
|
+
this.enqueue([this.getBlobData, data, false, options, cb]);
|
|
3246
|
+
} else {
|
|
3247
|
+
this.getBlobData(data, false, options, cb);
|
|
3248
|
+
}
|
|
3249
|
+
} else if (this._state !== DEFAULT) {
|
|
3250
|
+
this.enqueue([this.dispatch, data, false, options, cb]);
|
|
3251
|
+
} else {
|
|
3252
|
+
this.sendFrame(Sender.frame(data, options), cb);
|
|
3253
|
+
}
|
|
3254
|
+
}
|
|
3255
|
+
send(data, options, cb) {
|
|
3256
|
+
const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
|
|
3257
|
+
let opcode = options.binary ? 2 : 1;
|
|
3258
|
+
let rsv1 = options.compress;
|
|
3259
|
+
let byteLength;
|
|
3260
|
+
let readOnly;
|
|
3261
|
+
if (typeof data === "string") {
|
|
3262
|
+
byteLength = Buffer.byteLength(data);
|
|
3263
|
+
readOnly = false;
|
|
3264
|
+
} else if (isBlob(data)) {
|
|
3265
|
+
byteLength = data.size;
|
|
3266
|
+
readOnly = false;
|
|
3267
|
+
} else {
|
|
3268
|
+
data = toBuffer(data);
|
|
3269
|
+
byteLength = data.length;
|
|
3270
|
+
readOnly = toBuffer.readOnly;
|
|
3271
|
+
}
|
|
3272
|
+
if (this._firstFragment) {
|
|
3273
|
+
this._firstFragment = false;
|
|
3274
|
+
if (rsv1 && perMessageDeflate && perMessageDeflate.params[perMessageDeflate._isServer ? "server_no_context_takeover" : "client_no_context_takeover"]) {
|
|
3275
|
+
rsv1 = byteLength >= perMessageDeflate._threshold;
|
|
3276
|
+
}
|
|
3277
|
+
this._compress = rsv1;
|
|
3278
|
+
} else {
|
|
3279
|
+
rsv1 = false;
|
|
3280
|
+
opcode = 0;
|
|
3281
|
+
}
|
|
3282
|
+
if (options.fin)
|
|
3283
|
+
this._firstFragment = true;
|
|
3284
|
+
const opts = {
|
|
3285
|
+
[kByteLength]: byteLength,
|
|
3286
|
+
fin: options.fin,
|
|
3287
|
+
generateMask: this._generateMask,
|
|
3288
|
+
mask: options.mask,
|
|
3289
|
+
maskBuffer: this._maskBuffer,
|
|
3290
|
+
opcode,
|
|
3291
|
+
readOnly,
|
|
3292
|
+
rsv1
|
|
3293
|
+
};
|
|
3294
|
+
if (isBlob(data)) {
|
|
3295
|
+
if (this._state !== DEFAULT) {
|
|
3296
|
+
this.enqueue([this.getBlobData, data, this._compress, opts, cb]);
|
|
3297
|
+
} else {
|
|
3298
|
+
this.getBlobData(data, this._compress, opts, cb);
|
|
3299
|
+
}
|
|
3300
|
+
} else if (this._state !== DEFAULT) {
|
|
3301
|
+
this.enqueue([this.dispatch, data, this._compress, opts, cb]);
|
|
3302
|
+
} else {
|
|
3303
|
+
this.dispatch(data, this._compress, opts, cb);
|
|
3304
|
+
}
|
|
3305
|
+
}
|
|
3306
|
+
getBlobData(blob, compress, options, cb) {
|
|
3307
|
+
this._bufferedBytes += options[kByteLength];
|
|
3308
|
+
this._state = GET_BLOB_DATA;
|
|
3309
|
+
blob.arrayBuffer().then((arrayBuffer) => {
|
|
3310
|
+
if (this._socket.destroyed) {
|
|
3311
|
+
const err = new Error("The socket was closed while the blob was being read");
|
|
3312
|
+
process.nextTick(callCallbacks, this, err, cb);
|
|
3313
|
+
return;
|
|
3314
|
+
}
|
|
3315
|
+
this._bufferedBytes -= options[kByteLength];
|
|
3316
|
+
const data = toBuffer(arrayBuffer);
|
|
3317
|
+
if (!compress) {
|
|
3318
|
+
this._state = DEFAULT;
|
|
3319
|
+
this.sendFrame(Sender.frame(data, options), cb);
|
|
3320
|
+
this.dequeue();
|
|
3321
|
+
} else {
|
|
3322
|
+
this.dispatch(data, compress, options, cb);
|
|
3323
|
+
}
|
|
3324
|
+
}).catch((err) => {
|
|
3325
|
+
process.nextTick(onError, this, err, cb);
|
|
3326
|
+
});
|
|
3327
|
+
}
|
|
3328
|
+
dispatch(data, compress, options, cb) {
|
|
3329
|
+
if (!compress) {
|
|
3330
|
+
this.sendFrame(Sender.frame(data, options), cb);
|
|
3331
|
+
return;
|
|
3332
|
+
}
|
|
3333
|
+
const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
|
|
3334
|
+
this._bufferedBytes += options[kByteLength];
|
|
3335
|
+
this._state = DEFLATING;
|
|
3336
|
+
perMessageDeflate.compress(data, options.fin, (_, buf) => {
|
|
3337
|
+
if (this._socket.destroyed) {
|
|
3338
|
+
const err = new Error("The socket was closed while data was being compressed");
|
|
3339
|
+
callCallbacks(this, err, cb);
|
|
3340
|
+
return;
|
|
3341
|
+
}
|
|
3342
|
+
this._bufferedBytes -= options[kByteLength];
|
|
3343
|
+
this._state = DEFAULT;
|
|
3344
|
+
options.readOnly = false;
|
|
3345
|
+
this.sendFrame(Sender.frame(buf, options), cb);
|
|
3346
|
+
this.dequeue();
|
|
3347
|
+
});
|
|
3348
|
+
}
|
|
3349
|
+
dequeue() {
|
|
3350
|
+
while (this._state === DEFAULT && this._queue.length) {
|
|
3351
|
+
const params = this._queue.shift();
|
|
3352
|
+
this._bufferedBytes -= params[3][kByteLength];
|
|
3353
|
+
Reflect.apply(params[0], this, params.slice(1));
|
|
3354
|
+
}
|
|
3355
|
+
}
|
|
3356
|
+
enqueue(params) {
|
|
3357
|
+
this._bufferedBytes += params[3][kByteLength];
|
|
3358
|
+
this._queue.push(params);
|
|
3359
|
+
}
|
|
3360
|
+
sendFrame(list, cb) {
|
|
3361
|
+
if (list.length === 2) {
|
|
3362
|
+
this._socket.cork();
|
|
3363
|
+
this._socket.write(list[0]);
|
|
3364
|
+
this._socket.write(list[1], cb);
|
|
3365
|
+
this._socket.uncork();
|
|
3366
|
+
} else {
|
|
3367
|
+
this._socket.write(list[0], cb);
|
|
3368
|
+
}
|
|
3369
|
+
}
|
|
3370
|
+
}
|
|
3371
|
+
module.exports = Sender;
|
|
3372
|
+
function callCallbacks(sender, err, cb) {
|
|
3373
|
+
if (typeof cb === "function")
|
|
3374
|
+
cb(err);
|
|
3375
|
+
for (let i = 0;i < sender._queue.length; i++) {
|
|
3376
|
+
const params = sender._queue[i];
|
|
3377
|
+
const callback = params[params.length - 1];
|
|
3378
|
+
if (typeof callback === "function")
|
|
3379
|
+
callback(err);
|
|
3380
|
+
}
|
|
3381
|
+
}
|
|
3382
|
+
function onError(sender, err, cb) {
|
|
3383
|
+
callCallbacks(sender, err, cb);
|
|
3384
|
+
sender.onerror(err);
|
|
3385
|
+
}
|
|
3386
|
+
});
|
|
3387
|
+
|
|
3388
|
+
// ../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/event-target.js
|
|
3389
|
+
var require_event_target = __commonJS((exports, module) => {
|
|
3390
|
+
var { kForOnEventAttribute, kListener } = require_constants();
|
|
3391
|
+
var kCode = Symbol("kCode");
|
|
3392
|
+
var kData = Symbol("kData");
|
|
3393
|
+
var kError = Symbol("kError");
|
|
3394
|
+
var kMessage = Symbol("kMessage");
|
|
3395
|
+
var kReason = Symbol("kReason");
|
|
3396
|
+
var kTarget = Symbol("kTarget");
|
|
3397
|
+
var kType = Symbol("kType");
|
|
3398
|
+
var kWasClean = Symbol("kWasClean");
|
|
3399
|
+
|
|
3400
|
+
class Event {
|
|
3401
|
+
constructor(type) {
|
|
3402
|
+
this[kTarget] = null;
|
|
3403
|
+
this[kType] = type;
|
|
3404
|
+
}
|
|
3405
|
+
get target() {
|
|
3406
|
+
return this[kTarget];
|
|
3407
|
+
}
|
|
3408
|
+
get type() {
|
|
3409
|
+
return this[kType];
|
|
3410
|
+
}
|
|
3411
|
+
}
|
|
3412
|
+
Object.defineProperty(Event.prototype, "target", { enumerable: true });
|
|
3413
|
+
Object.defineProperty(Event.prototype, "type", { enumerable: true });
|
|
3414
|
+
|
|
3415
|
+
class CloseEvent extends Event {
|
|
3416
|
+
constructor(type, options = {}) {
|
|
3417
|
+
super(type);
|
|
3418
|
+
this[kCode] = options.code === undefined ? 0 : options.code;
|
|
3419
|
+
this[kReason] = options.reason === undefined ? "" : options.reason;
|
|
3420
|
+
this[kWasClean] = options.wasClean === undefined ? false : options.wasClean;
|
|
3421
|
+
}
|
|
3422
|
+
get code() {
|
|
3423
|
+
return this[kCode];
|
|
3424
|
+
}
|
|
3425
|
+
get reason() {
|
|
3426
|
+
return this[kReason];
|
|
3427
|
+
}
|
|
3428
|
+
get wasClean() {
|
|
3429
|
+
return this[kWasClean];
|
|
3430
|
+
}
|
|
3431
|
+
}
|
|
3432
|
+
Object.defineProperty(CloseEvent.prototype, "code", { enumerable: true });
|
|
3433
|
+
Object.defineProperty(CloseEvent.prototype, "reason", { enumerable: true });
|
|
3434
|
+
Object.defineProperty(CloseEvent.prototype, "wasClean", { enumerable: true });
|
|
3435
|
+
|
|
3436
|
+
class ErrorEvent extends Event {
|
|
3437
|
+
constructor(type, options = {}) {
|
|
3438
|
+
super(type);
|
|
3439
|
+
this[kError] = options.error === undefined ? null : options.error;
|
|
3440
|
+
this[kMessage] = options.message === undefined ? "" : options.message;
|
|
3441
|
+
}
|
|
3442
|
+
get error() {
|
|
3443
|
+
return this[kError];
|
|
3444
|
+
}
|
|
3445
|
+
get message() {
|
|
3446
|
+
return this[kMessage];
|
|
3447
|
+
}
|
|
3448
|
+
}
|
|
3449
|
+
Object.defineProperty(ErrorEvent.prototype, "error", { enumerable: true });
|
|
3450
|
+
Object.defineProperty(ErrorEvent.prototype, "message", { enumerable: true });
|
|
3451
|
+
|
|
3452
|
+
class MessageEvent extends Event {
|
|
3453
|
+
constructor(type, options = {}) {
|
|
3454
|
+
super(type);
|
|
3455
|
+
this[kData] = options.data === undefined ? null : options.data;
|
|
3456
|
+
}
|
|
3457
|
+
get data() {
|
|
3458
|
+
return this[kData];
|
|
3459
|
+
}
|
|
3460
|
+
}
|
|
3461
|
+
Object.defineProperty(MessageEvent.prototype, "data", { enumerable: true });
|
|
3462
|
+
var EventTarget = {
|
|
3463
|
+
addEventListener(type, handler, options = {}) {
|
|
3464
|
+
for (const listener of this.listeners(type)) {
|
|
3465
|
+
if (!options[kForOnEventAttribute] && listener[kListener] === handler && !listener[kForOnEventAttribute]) {
|
|
3466
|
+
return;
|
|
3467
|
+
}
|
|
3468
|
+
}
|
|
3469
|
+
let wrapper;
|
|
3470
|
+
if (type === "message") {
|
|
3471
|
+
wrapper = function onMessage(data, isBinary) {
|
|
3472
|
+
const event = new MessageEvent("message", {
|
|
3473
|
+
data: isBinary ? data : data.toString()
|
|
3474
|
+
});
|
|
3475
|
+
event[kTarget] = this;
|
|
3476
|
+
callListener(handler, this, event);
|
|
3477
|
+
};
|
|
3478
|
+
} else if (type === "close") {
|
|
3479
|
+
wrapper = function onClose(code, message) {
|
|
3480
|
+
const event = new CloseEvent("close", {
|
|
3481
|
+
code,
|
|
3482
|
+
reason: message.toString(),
|
|
3483
|
+
wasClean: this._closeFrameReceived && this._closeFrameSent
|
|
3484
|
+
});
|
|
3485
|
+
event[kTarget] = this;
|
|
3486
|
+
callListener(handler, this, event);
|
|
3487
|
+
};
|
|
3488
|
+
} else if (type === "error") {
|
|
3489
|
+
wrapper = function onError(error2) {
|
|
3490
|
+
const event = new ErrorEvent("error", {
|
|
3491
|
+
error: error2,
|
|
3492
|
+
message: error2.message
|
|
3493
|
+
});
|
|
3494
|
+
event[kTarget] = this;
|
|
3495
|
+
callListener(handler, this, event);
|
|
3496
|
+
};
|
|
3497
|
+
} else if (type === "open") {
|
|
3498
|
+
wrapper = function onOpen() {
|
|
3499
|
+
const event = new Event("open");
|
|
3500
|
+
event[kTarget] = this;
|
|
3501
|
+
callListener(handler, this, event);
|
|
3502
|
+
};
|
|
3503
|
+
} else {
|
|
3504
|
+
return;
|
|
3505
|
+
}
|
|
3506
|
+
wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute];
|
|
3507
|
+
wrapper[kListener] = handler;
|
|
3508
|
+
if (options.once) {
|
|
3509
|
+
this.once(type, wrapper);
|
|
3510
|
+
} else {
|
|
3511
|
+
this.on(type, wrapper);
|
|
3512
|
+
}
|
|
3513
|
+
},
|
|
3514
|
+
removeEventListener(type, handler) {
|
|
3515
|
+
for (const listener of this.listeners(type)) {
|
|
3516
|
+
if (listener[kListener] === handler && !listener[kForOnEventAttribute]) {
|
|
3517
|
+
this.removeListener(type, listener);
|
|
3518
|
+
break;
|
|
3519
|
+
}
|
|
3520
|
+
}
|
|
3521
|
+
}
|
|
3522
|
+
};
|
|
3523
|
+
module.exports = {
|
|
3524
|
+
CloseEvent,
|
|
3525
|
+
ErrorEvent,
|
|
3526
|
+
Event,
|
|
3527
|
+
EventTarget,
|
|
3528
|
+
MessageEvent
|
|
3529
|
+
};
|
|
3530
|
+
function callListener(listener, thisArg, event) {
|
|
3531
|
+
if (typeof listener === "object" && listener.handleEvent) {
|
|
3532
|
+
listener.handleEvent.call(listener, event);
|
|
3533
|
+
} else {
|
|
3534
|
+
listener.call(thisArg, event);
|
|
3535
|
+
}
|
|
3536
|
+
}
|
|
3537
|
+
});
|
|
3538
|
+
|
|
3539
|
+
// ../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/extension.js
|
|
3540
|
+
var require_extension = __commonJS((exports, module) => {
|
|
3541
|
+
var { tokenChars } = require_validation();
|
|
3542
|
+
function push(dest, name, elem) {
|
|
3543
|
+
if (dest[name] === undefined)
|
|
3544
|
+
dest[name] = [elem];
|
|
3545
|
+
else
|
|
3546
|
+
dest[name].push(elem);
|
|
3547
|
+
}
|
|
3548
|
+
function parse(header) {
|
|
3549
|
+
const offers = Object.create(null);
|
|
3550
|
+
let params = Object.create(null);
|
|
3551
|
+
let mustUnescape = false;
|
|
3552
|
+
let isEscaping = false;
|
|
3553
|
+
let inQuotes = false;
|
|
3554
|
+
let extensionName;
|
|
3555
|
+
let paramName;
|
|
3556
|
+
let start = -1;
|
|
3557
|
+
let code = -1;
|
|
3558
|
+
let end = -1;
|
|
3559
|
+
let i = 0;
|
|
3560
|
+
for (;i < header.length; i++) {
|
|
3561
|
+
code = header.charCodeAt(i);
|
|
3562
|
+
if (extensionName === undefined) {
|
|
3563
|
+
if (end === -1 && tokenChars[code] === 1) {
|
|
3564
|
+
if (start === -1)
|
|
3565
|
+
start = i;
|
|
3566
|
+
} else if (i !== 0 && (code === 32 || code === 9)) {
|
|
3567
|
+
if (end === -1 && start !== -1)
|
|
3568
|
+
end = i;
|
|
3569
|
+
} else if (code === 59 || code === 44) {
|
|
3570
|
+
if (start === -1) {
|
|
3571
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
3572
|
+
}
|
|
3573
|
+
if (end === -1)
|
|
3574
|
+
end = i;
|
|
3575
|
+
const name = header.slice(start, end);
|
|
3576
|
+
if (code === 44) {
|
|
3577
|
+
push(offers, name, params);
|
|
3578
|
+
params = Object.create(null);
|
|
3579
|
+
} else {
|
|
3580
|
+
extensionName = name;
|
|
3581
|
+
}
|
|
3582
|
+
start = end = -1;
|
|
3583
|
+
} else {
|
|
3584
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
3585
|
+
}
|
|
3586
|
+
} else if (paramName === undefined) {
|
|
3587
|
+
if (end === -1 && tokenChars[code] === 1) {
|
|
3588
|
+
if (start === -1)
|
|
3589
|
+
start = i;
|
|
3590
|
+
} else if (code === 32 || code === 9) {
|
|
3591
|
+
if (end === -1 && start !== -1)
|
|
3592
|
+
end = i;
|
|
3593
|
+
} else if (code === 59 || code === 44) {
|
|
3594
|
+
if (start === -1) {
|
|
3595
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
3596
|
+
}
|
|
3597
|
+
if (end === -1)
|
|
3598
|
+
end = i;
|
|
3599
|
+
push(params, header.slice(start, end), true);
|
|
3600
|
+
if (code === 44) {
|
|
3601
|
+
push(offers, extensionName, params);
|
|
3602
|
+
params = Object.create(null);
|
|
3603
|
+
extensionName = undefined;
|
|
3604
|
+
}
|
|
3605
|
+
start = end = -1;
|
|
3606
|
+
} else if (code === 61 && start !== -1 && end === -1) {
|
|
3607
|
+
paramName = header.slice(start, i);
|
|
3608
|
+
start = end = -1;
|
|
3609
|
+
} else {
|
|
3610
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
3611
|
+
}
|
|
3612
|
+
} else {
|
|
3613
|
+
if (isEscaping) {
|
|
3614
|
+
if (tokenChars[code] !== 1) {
|
|
3615
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
3616
|
+
}
|
|
3617
|
+
if (start === -1)
|
|
3618
|
+
start = i;
|
|
3619
|
+
else if (!mustUnescape)
|
|
3620
|
+
mustUnescape = true;
|
|
3621
|
+
isEscaping = false;
|
|
3622
|
+
} else if (inQuotes) {
|
|
3623
|
+
if (tokenChars[code] === 1) {
|
|
3624
|
+
if (start === -1)
|
|
3625
|
+
start = i;
|
|
3626
|
+
} else if (code === 34 && start !== -1) {
|
|
3627
|
+
inQuotes = false;
|
|
3628
|
+
end = i;
|
|
3629
|
+
} else if (code === 92) {
|
|
3630
|
+
isEscaping = true;
|
|
3631
|
+
} else {
|
|
3632
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
3633
|
+
}
|
|
3634
|
+
} else if (code === 34 && header.charCodeAt(i - 1) === 61) {
|
|
3635
|
+
inQuotes = true;
|
|
3636
|
+
} else if (end === -1 && tokenChars[code] === 1) {
|
|
3637
|
+
if (start === -1)
|
|
3638
|
+
start = i;
|
|
3639
|
+
} else if (start !== -1 && (code === 32 || code === 9)) {
|
|
3640
|
+
if (end === -1)
|
|
3641
|
+
end = i;
|
|
3642
|
+
} else if (code === 59 || code === 44) {
|
|
3643
|
+
if (start === -1) {
|
|
3644
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
3645
|
+
}
|
|
3646
|
+
if (end === -1)
|
|
3647
|
+
end = i;
|
|
3648
|
+
let value = header.slice(start, end);
|
|
3649
|
+
if (mustUnescape) {
|
|
3650
|
+
value = value.replace(/\\/g, "");
|
|
3651
|
+
mustUnescape = false;
|
|
3652
|
+
}
|
|
3653
|
+
push(params, paramName, value);
|
|
3654
|
+
if (code === 44) {
|
|
3655
|
+
push(offers, extensionName, params);
|
|
3656
|
+
params = Object.create(null);
|
|
3657
|
+
extensionName = undefined;
|
|
3658
|
+
}
|
|
3659
|
+
paramName = undefined;
|
|
3660
|
+
start = end = -1;
|
|
3661
|
+
} else {
|
|
3662
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
3663
|
+
}
|
|
3664
|
+
}
|
|
3665
|
+
}
|
|
3666
|
+
if (start === -1 || inQuotes || code === 32 || code === 9) {
|
|
3667
|
+
throw new SyntaxError("Unexpected end of input");
|
|
3668
|
+
}
|
|
3669
|
+
if (end === -1)
|
|
3670
|
+
end = i;
|
|
3671
|
+
const token = header.slice(start, end);
|
|
3672
|
+
if (extensionName === undefined) {
|
|
3673
|
+
push(offers, token, params);
|
|
3674
|
+
} else {
|
|
3675
|
+
if (paramName === undefined) {
|
|
3676
|
+
push(params, token, true);
|
|
3677
|
+
} else if (mustUnescape) {
|
|
3678
|
+
push(params, paramName, token.replace(/\\/g, ""));
|
|
3679
|
+
} else {
|
|
3680
|
+
push(params, paramName, token);
|
|
3681
|
+
}
|
|
3682
|
+
push(offers, extensionName, params);
|
|
3683
|
+
}
|
|
3684
|
+
return offers;
|
|
3685
|
+
}
|
|
3686
|
+
function format(extensions) {
|
|
3687
|
+
return Object.keys(extensions).map((extension) => {
|
|
3688
|
+
let configurations = extensions[extension];
|
|
3689
|
+
if (!Array.isArray(configurations))
|
|
3690
|
+
configurations = [configurations];
|
|
3691
|
+
return configurations.map((params) => {
|
|
3692
|
+
return [extension].concat(Object.keys(params).map((k) => {
|
|
3693
|
+
let values = params[k];
|
|
3694
|
+
if (!Array.isArray(values))
|
|
3695
|
+
values = [values];
|
|
3696
|
+
return values.map((v) => v === true ? k : `${k}=${v}`).join("; ");
|
|
3697
|
+
})).join("; ");
|
|
3698
|
+
}).join(", ");
|
|
3699
|
+
}).join(", ");
|
|
3700
|
+
}
|
|
3701
|
+
module.exports = { format, parse };
|
|
3702
|
+
});
|
|
3703
|
+
|
|
3704
|
+
// ../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/websocket.js
|
|
3705
|
+
var require_websocket = __commonJS((exports, module) => {
|
|
3706
|
+
var EventEmitter = __require("events");
|
|
3707
|
+
var https = __require("https");
|
|
3708
|
+
var http = __require("http");
|
|
3709
|
+
var net = __require("net");
|
|
3710
|
+
var tls = __require("tls");
|
|
3711
|
+
var { randomBytes, createHash } = __require("crypto");
|
|
3712
|
+
var { Duplex, Readable } = __require("stream");
|
|
3713
|
+
var { URL: URL2 } = __require("url");
|
|
3714
|
+
var PerMessageDeflate = require_permessage_deflate();
|
|
3715
|
+
var Receiver = require_receiver();
|
|
3716
|
+
var Sender = require_sender();
|
|
3717
|
+
var { isBlob } = require_validation();
|
|
3718
|
+
var {
|
|
3719
|
+
BINARY_TYPES,
|
|
3720
|
+
CLOSE_TIMEOUT,
|
|
3721
|
+
EMPTY_BUFFER,
|
|
3722
|
+
GUID,
|
|
3723
|
+
kForOnEventAttribute,
|
|
3724
|
+
kListener,
|
|
3725
|
+
kStatusCode,
|
|
3726
|
+
kWebSocket,
|
|
3727
|
+
NOOP
|
|
3728
|
+
} = require_constants();
|
|
3729
|
+
var {
|
|
3730
|
+
EventTarget: { addEventListener, removeEventListener }
|
|
3731
|
+
} = require_event_target();
|
|
3732
|
+
var { format, parse } = require_extension();
|
|
3733
|
+
var { toBuffer } = require_buffer_util();
|
|
3734
|
+
var kAborted = Symbol("kAborted");
|
|
3735
|
+
var protocolVersions = [8, 13];
|
|
3736
|
+
var readyStates = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"];
|
|
3737
|
+
var subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
|
|
3738
|
+
|
|
3739
|
+
class WebSocket extends EventEmitter {
|
|
3740
|
+
constructor(address, protocols, options) {
|
|
3741
|
+
super();
|
|
3742
|
+
this._binaryType = BINARY_TYPES[0];
|
|
3743
|
+
this._closeCode = 1006;
|
|
3744
|
+
this._closeFrameReceived = false;
|
|
3745
|
+
this._closeFrameSent = false;
|
|
3746
|
+
this._closeMessage = EMPTY_BUFFER;
|
|
3747
|
+
this._closeTimer = null;
|
|
3748
|
+
this._errorEmitted = false;
|
|
3749
|
+
this._extensions = {};
|
|
3750
|
+
this._paused = false;
|
|
3751
|
+
this._protocol = "";
|
|
3752
|
+
this._readyState = WebSocket.CONNECTING;
|
|
3753
|
+
this._receiver = null;
|
|
3754
|
+
this._sender = null;
|
|
3755
|
+
this._socket = null;
|
|
3756
|
+
if (address !== null) {
|
|
3757
|
+
this._bufferedAmount = 0;
|
|
3758
|
+
this._isServer = false;
|
|
3759
|
+
this._redirects = 0;
|
|
3760
|
+
if (protocols === undefined) {
|
|
3761
|
+
protocols = [];
|
|
3762
|
+
} else if (!Array.isArray(protocols)) {
|
|
3763
|
+
if (typeof protocols === "object" && protocols !== null) {
|
|
3764
|
+
options = protocols;
|
|
3765
|
+
protocols = [];
|
|
3766
|
+
} else {
|
|
3767
|
+
protocols = [protocols];
|
|
3768
|
+
}
|
|
3769
|
+
}
|
|
3770
|
+
initAsClient(this, address, protocols, options);
|
|
3771
|
+
} else {
|
|
3772
|
+
this._autoPong = options.autoPong;
|
|
3773
|
+
this._closeTimeout = options.closeTimeout;
|
|
3774
|
+
this._isServer = true;
|
|
3775
|
+
}
|
|
3776
|
+
}
|
|
3777
|
+
get binaryType() {
|
|
3778
|
+
return this._binaryType;
|
|
3779
|
+
}
|
|
3780
|
+
set binaryType(type) {
|
|
3781
|
+
if (!BINARY_TYPES.includes(type))
|
|
3782
|
+
return;
|
|
3783
|
+
this._binaryType = type;
|
|
3784
|
+
if (this._receiver)
|
|
3785
|
+
this._receiver._binaryType = type;
|
|
3786
|
+
}
|
|
3787
|
+
get bufferedAmount() {
|
|
3788
|
+
if (!this._socket)
|
|
3789
|
+
return this._bufferedAmount;
|
|
3790
|
+
return this._socket._writableState.length + this._sender._bufferedBytes;
|
|
3791
|
+
}
|
|
3792
|
+
get extensions() {
|
|
3793
|
+
return Object.keys(this._extensions).join();
|
|
3794
|
+
}
|
|
3795
|
+
get isPaused() {
|
|
3796
|
+
return this._paused;
|
|
3797
|
+
}
|
|
3798
|
+
get onclose() {
|
|
3799
|
+
return null;
|
|
3800
|
+
}
|
|
3801
|
+
get onerror() {
|
|
3802
|
+
return null;
|
|
3803
|
+
}
|
|
3804
|
+
get onopen() {
|
|
3805
|
+
return null;
|
|
3806
|
+
}
|
|
3807
|
+
get onmessage() {
|
|
3808
|
+
return null;
|
|
3809
|
+
}
|
|
3810
|
+
get protocol() {
|
|
3811
|
+
return this._protocol;
|
|
3812
|
+
}
|
|
3813
|
+
get readyState() {
|
|
3814
|
+
return this._readyState;
|
|
3815
|
+
}
|
|
3816
|
+
get url() {
|
|
3817
|
+
return this._url;
|
|
3818
|
+
}
|
|
3819
|
+
setSocket(socket, head, options) {
|
|
3820
|
+
const receiver = new Receiver({
|
|
3821
|
+
allowSynchronousEvents: options.allowSynchronousEvents,
|
|
3822
|
+
binaryType: this.binaryType,
|
|
3823
|
+
extensions: this._extensions,
|
|
3824
|
+
isServer: this._isServer,
|
|
3825
|
+
maxPayload: options.maxPayload,
|
|
3826
|
+
skipUTF8Validation: options.skipUTF8Validation
|
|
3827
|
+
});
|
|
3828
|
+
const sender = new Sender(socket, this._extensions, options.generateMask);
|
|
3829
|
+
this._receiver = receiver;
|
|
3830
|
+
this._sender = sender;
|
|
3831
|
+
this._socket = socket;
|
|
3832
|
+
receiver[kWebSocket] = this;
|
|
3833
|
+
sender[kWebSocket] = this;
|
|
3834
|
+
socket[kWebSocket] = this;
|
|
3835
|
+
receiver.on("conclude", receiverOnConclude);
|
|
3836
|
+
receiver.on("drain", receiverOnDrain);
|
|
3837
|
+
receiver.on("error", receiverOnError);
|
|
3838
|
+
receiver.on("message", receiverOnMessage);
|
|
3839
|
+
receiver.on("ping", receiverOnPing);
|
|
3840
|
+
receiver.on("pong", receiverOnPong);
|
|
3841
|
+
sender.onerror = senderOnError;
|
|
3842
|
+
if (socket.setTimeout)
|
|
3843
|
+
socket.setTimeout(0);
|
|
3844
|
+
if (socket.setNoDelay)
|
|
3845
|
+
socket.setNoDelay();
|
|
3846
|
+
if (head.length > 0)
|
|
3847
|
+
socket.unshift(head);
|
|
3848
|
+
socket.on("close", socketOnClose);
|
|
3849
|
+
socket.on("data", socketOnData);
|
|
3850
|
+
socket.on("end", socketOnEnd);
|
|
3851
|
+
socket.on("error", socketOnError);
|
|
3852
|
+
this._readyState = WebSocket.OPEN;
|
|
3853
|
+
this.emit("open");
|
|
3854
|
+
}
|
|
3855
|
+
emitClose() {
|
|
3856
|
+
if (!this._socket) {
|
|
3857
|
+
this._readyState = WebSocket.CLOSED;
|
|
3858
|
+
this.emit("close", this._closeCode, this._closeMessage);
|
|
3859
|
+
return;
|
|
3860
|
+
}
|
|
3861
|
+
if (this._extensions[PerMessageDeflate.extensionName]) {
|
|
3862
|
+
this._extensions[PerMessageDeflate.extensionName].cleanup();
|
|
3863
|
+
}
|
|
3864
|
+
this._receiver.removeAllListeners();
|
|
3865
|
+
this._readyState = WebSocket.CLOSED;
|
|
3866
|
+
this.emit("close", this._closeCode, this._closeMessage);
|
|
3867
|
+
}
|
|
3868
|
+
close(code, data) {
|
|
3869
|
+
if (this.readyState === WebSocket.CLOSED)
|
|
3870
|
+
return;
|
|
3871
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
3872
|
+
const msg = "WebSocket was closed before the connection was established";
|
|
3873
|
+
abortHandshake(this, this._req, msg);
|
|
3874
|
+
return;
|
|
3875
|
+
}
|
|
3876
|
+
if (this.readyState === WebSocket.CLOSING) {
|
|
3877
|
+
if (this._closeFrameSent && (this._closeFrameReceived || this._receiver._writableState.errorEmitted)) {
|
|
3878
|
+
this._socket.end();
|
|
3879
|
+
}
|
|
3880
|
+
return;
|
|
3881
|
+
}
|
|
3882
|
+
this._readyState = WebSocket.CLOSING;
|
|
3883
|
+
this._sender.close(code, data, !this._isServer, (err) => {
|
|
3884
|
+
if (err)
|
|
3885
|
+
return;
|
|
3886
|
+
this._closeFrameSent = true;
|
|
3887
|
+
if (this._closeFrameReceived || this._receiver._writableState.errorEmitted) {
|
|
3888
|
+
this._socket.end();
|
|
3889
|
+
}
|
|
3890
|
+
});
|
|
3891
|
+
setCloseTimer(this);
|
|
3892
|
+
}
|
|
3893
|
+
pause() {
|
|
3894
|
+
if (this.readyState === WebSocket.CONNECTING || this.readyState === WebSocket.CLOSED) {
|
|
3895
|
+
return;
|
|
3896
|
+
}
|
|
3897
|
+
this._paused = true;
|
|
3898
|
+
this._socket.pause();
|
|
3899
|
+
}
|
|
3900
|
+
ping(data, mask, cb) {
|
|
3901
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
3902
|
+
throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
3903
|
+
}
|
|
3904
|
+
if (typeof data === "function") {
|
|
3905
|
+
cb = data;
|
|
3906
|
+
data = mask = undefined;
|
|
3907
|
+
} else if (typeof mask === "function") {
|
|
3908
|
+
cb = mask;
|
|
3909
|
+
mask = undefined;
|
|
3910
|
+
}
|
|
3911
|
+
if (typeof data === "number")
|
|
3912
|
+
data = data.toString();
|
|
3913
|
+
if (this.readyState !== WebSocket.OPEN) {
|
|
3914
|
+
sendAfterClose(this, data, cb);
|
|
3915
|
+
return;
|
|
3916
|
+
}
|
|
3917
|
+
if (mask === undefined)
|
|
3918
|
+
mask = !this._isServer;
|
|
3919
|
+
this._sender.ping(data || EMPTY_BUFFER, mask, cb);
|
|
3920
|
+
}
|
|
3921
|
+
pong(data, mask, cb) {
|
|
3922
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
3923
|
+
throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
3924
|
+
}
|
|
3925
|
+
if (typeof data === "function") {
|
|
3926
|
+
cb = data;
|
|
3927
|
+
data = mask = undefined;
|
|
3928
|
+
} else if (typeof mask === "function") {
|
|
3929
|
+
cb = mask;
|
|
3930
|
+
mask = undefined;
|
|
3931
|
+
}
|
|
3932
|
+
if (typeof data === "number")
|
|
3933
|
+
data = data.toString();
|
|
3934
|
+
if (this.readyState !== WebSocket.OPEN) {
|
|
3935
|
+
sendAfterClose(this, data, cb);
|
|
3936
|
+
return;
|
|
3937
|
+
}
|
|
3938
|
+
if (mask === undefined)
|
|
3939
|
+
mask = !this._isServer;
|
|
3940
|
+
this._sender.pong(data || EMPTY_BUFFER, mask, cb);
|
|
3941
|
+
}
|
|
3942
|
+
resume() {
|
|
3943
|
+
if (this.readyState === WebSocket.CONNECTING || this.readyState === WebSocket.CLOSED) {
|
|
3944
|
+
return;
|
|
3945
|
+
}
|
|
3946
|
+
this._paused = false;
|
|
3947
|
+
if (!this._receiver._writableState.needDrain)
|
|
3948
|
+
this._socket.resume();
|
|
3949
|
+
}
|
|
3950
|
+
send(data, options, cb) {
|
|
3951
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
3952
|
+
throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
3953
|
+
}
|
|
3954
|
+
if (typeof options === "function") {
|
|
3955
|
+
cb = options;
|
|
3956
|
+
options = {};
|
|
3957
|
+
}
|
|
3958
|
+
if (typeof data === "number")
|
|
3959
|
+
data = data.toString();
|
|
3960
|
+
if (this.readyState !== WebSocket.OPEN) {
|
|
3961
|
+
sendAfterClose(this, data, cb);
|
|
3962
|
+
return;
|
|
3963
|
+
}
|
|
3964
|
+
const opts = {
|
|
3965
|
+
binary: typeof data !== "string",
|
|
3966
|
+
mask: !this._isServer,
|
|
3967
|
+
compress: true,
|
|
3968
|
+
fin: true,
|
|
3969
|
+
...options
|
|
3970
|
+
};
|
|
3971
|
+
if (!this._extensions[PerMessageDeflate.extensionName]) {
|
|
3972
|
+
opts.compress = false;
|
|
3973
|
+
}
|
|
3974
|
+
this._sender.send(data || EMPTY_BUFFER, opts, cb);
|
|
3975
|
+
}
|
|
3976
|
+
terminate() {
|
|
3977
|
+
if (this.readyState === WebSocket.CLOSED)
|
|
3978
|
+
return;
|
|
3979
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
3980
|
+
const msg = "WebSocket was closed before the connection was established";
|
|
3981
|
+
abortHandshake(this, this._req, msg);
|
|
3982
|
+
return;
|
|
3983
|
+
}
|
|
3984
|
+
if (this._socket) {
|
|
3985
|
+
this._readyState = WebSocket.CLOSING;
|
|
3986
|
+
this._socket.destroy();
|
|
3987
|
+
}
|
|
3988
|
+
}
|
|
3989
|
+
}
|
|
3990
|
+
Object.defineProperty(WebSocket, "CONNECTING", {
|
|
3991
|
+
enumerable: true,
|
|
3992
|
+
value: readyStates.indexOf("CONNECTING")
|
|
3993
|
+
});
|
|
3994
|
+
Object.defineProperty(WebSocket.prototype, "CONNECTING", {
|
|
3995
|
+
enumerable: true,
|
|
3996
|
+
value: readyStates.indexOf("CONNECTING")
|
|
3997
|
+
});
|
|
3998
|
+
Object.defineProperty(WebSocket, "OPEN", {
|
|
3999
|
+
enumerable: true,
|
|
4000
|
+
value: readyStates.indexOf("OPEN")
|
|
4001
|
+
});
|
|
4002
|
+
Object.defineProperty(WebSocket.prototype, "OPEN", {
|
|
4003
|
+
enumerable: true,
|
|
4004
|
+
value: readyStates.indexOf("OPEN")
|
|
4005
|
+
});
|
|
4006
|
+
Object.defineProperty(WebSocket, "CLOSING", {
|
|
4007
|
+
enumerable: true,
|
|
4008
|
+
value: readyStates.indexOf("CLOSING")
|
|
4009
|
+
});
|
|
4010
|
+
Object.defineProperty(WebSocket.prototype, "CLOSING", {
|
|
4011
|
+
enumerable: true,
|
|
4012
|
+
value: readyStates.indexOf("CLOSING")
|
|
4013
|
+
});
|
|
4014
|
+
Object.defineProperty(WebSocket, "CLOSED", {
|
|
4015
|
+
enumerable: true,
|
|
4016
|
+
value: readyStates.indexOf("CLOSED")
|
|
4017
|
+
});
|
|
4018
|
+
Object.defineProperty(WebSocket.prototype, "CLOSED", {
|
|
4019
|
+
enumerable: true,
|
|
4020
|
+
value: readyStates.indexOf("CLOSED")
|
|
4021
|
+
});
|
|
4022
|
+
[
|
|
4023
|
+
"binaryType",
|
|
4024
|
+
"bufferedAmount",
|
|
4025
|
+
"extensions",
|
|
4026
|
+
"isPaused",
|
|
4027
|
+
"protocol",
|
|
4028
|
+
"readyState",
|
|
4029
|
+
"url"
|
|
4030
|
+
].forEach((property) => {
|
|
4031
|
+
Object.defineProperty(WebSocket.prototype, property, { enumerable: true });
|
|
4032
|
+
});
|
|
4033
|
+
["open", "error", "close", "message"].forEach((method) => {
|
|
4034
|
+
Object.defineProperty(WebSocket.prototype, `on${method}`, {
|
|
4035
|
+
enumerable: true,
|
|
4036
|
+
get() {
|
|
4037
|
+
for (const listener of this.listeners(method)) {
|
|
4038
|
+
if (listener[kForOnEventAttribute])
|
|
4039
|
+
return listener[kListener];
|
|
4040
|
+
}
|
|
4041
|
+
return null;
|
|
4042
|
+
},
|
|
4043
|
+
set(handler) {
|
|
4044
|
+
for (const listener of this.listeners(method)) {
|
|
4045
|
+
if (listener[kForOnEventAttribute]) {
|
|
4046
|
+
this.removeListener(method, listener);
|
|
4047
|
+
break;
|
|
4048
|
+
}
|
|
4049
|
+
}
|
|
4050
|
+
if (typeof handler !== "function")
|
|
4051
|
+
return;
|
|
4052
|
+
this.addEventListener(method, handler, {
|
|
4053
|
+
[kForOnEventAttribute]: true
|
|
4054
|
+
});
|
|
4055
|
+
}
|
|
4056
|
+
});
|
|
4057
|
+
});
|
|
4058
|
+
WebSocket.prototype.addEventListener = addEventListener;
|
|
4059
|
+
WebSocket.prototype.removeEventListener = removeEventListener;
|
|
4060
|
+
module.exports = WebSocket;
|
|
4061
|
+
function initAsClient(websocket, address, protocols, options) {
|
|
4062
|
+
const opts = {
|
|
4063
|
+
allowSynchronousEvents: true,
|
|
4064
|
+
autoPong: true,
|
|
4065
|
+
closeTimeout: CLOSE_TIMEOUT,
|
|
4066
|
+
protocolVersion: protocolVersions[1],
|
|
4067
|
+
maxPayload: 100 * 1024 * 1024,
|
|
4068
|
+
skipUTF8Validation: false,
|
|
4069
|
+
perMessageDeflate: true,
|
|
4070
|
+
followRedirects: false,
|
|
4071
|
+
maxRedirects: 10,
|
|
4072
|
+
...options,
|
|
4073
|
+
socketPath: undefined,
|
|
4074
|
+
hostname: undefined,
|
|
4075
|
+
protocol: undefined,
|
|
4076
|
+
timeout: undefined,
|
|
4077
|
+
method: "GET",
|
|
4078
|
+
host: undefined,
|
|
4079
|
+
path: undefined,
|
|
4080
|
+
port: undefined
|
|
4081
|
+
};
|
|
4082
|
+
websocket._autoPong = opts.autoPong;
|
|
4083
|
+
websocket._closeTimeout = opts.closeTimeout;
|
|
4084
|
+
if (!protocolVersions.includes(opts.protocolVersion)) {
|
|
4085
|
+
throw new RangeError(`Unsupported protocol version: ${opts.protocolVersion} ` + `(supported versions: ${protocolVersions.join(", ")})`);
|
|
4086
|
+
}
|
|
4087
|
+
let parsedUrl;
|
|
4088
|
+
if (address instanceof URL2) {
|
|
4089
|
+
parsedUrl = address;
|
|
4090
|
+
} else {
|
|
4091
|
+
try {
|
|
4092
|
+
parsedUrl = new URL2(address);
|
|
4093
|
+
} catch {
|
|
4094
|
+
throw new SyntaxError(`Invalid URL: ${address}`);
|
|
4095
|
+
}
|
|
4096
|
+
}
|
|
4097
|
+
if (parsedUrl.protocol === "http:") {
|
|
4098
|
+
parsedUrl.protocol = "ws:";
|
|
4099
|
+
} else if (parsedUrl.protocol === "https:") {
|
|
4100
|
+
parsedUrl.protocol = "wss:";
|
|
4101
|
+
}
|
|
4102
|
+
websocket._url = parsedUrl.href;
|
|
4103
|
+
const isSecure = parsedUrl.protocol === "wss:";
|
|
4104
|
+
const isIpcUrl = parsedUrl.protocol === "ws+unix:";
|
|
4105
|
+
let invalidUrlMessage;
|
|
4106
|
+
if (parsedUrl.protocol !== "ws:" && !isSecure && !isIpcUrl) {
|
|
4107
|
+
invalidUrlMessage = `The URL's protocol must be one of "ws:", "wss:", ` + '"http:", "https:", or "ws+unix:"';
|
|
4108
|
+
} else if (isIpcUrl && !parsedUrl.pathname) {
|
|
4109
|
+
invalidUrlMessage = "The URL's pathname is empty";
|
|
4110
|
+
} else if (parsedUrl.hash) {
|
|
4111
|
+
invalidUrlMessage = "The URL contains a fragment identifier";
|
|
4112
|
+
}
|
|
4113
|
+
if (invalidUrlMessage) {
|
|
4114
|
+
const err = new SyntaxError(invalidUrlMessage);
|
|
4115
|
+
if (websocket._redirects === 0) {
|
|
4116
|
+
throw err;
|
|
4117
|
+
} else {
|
|
4118
|
+
emitErrorAndClose(websocket, err);
|
|
4119
|
+
return;
|
|
4120
|
+
}
|
|
4121
|
+
}
|
|
4122
|
+
const defaultPort = isSecure ? 443 : 80;
|
|
4123
|
+
const key = randomBytes(16).toString("base64");
|
|
4124
|
+
const request = isSecure ? https.request : http.request;
|
|
4125
|
+
const protocolSet = new Set;
|
|
4126
|
+
let perMessageDeflate;
|
|
4127
|
+
opts.createConnection = opts.createConnection || (isSecure ? tlsConnect : netConnect);
|
|
4128
|
+
opts.defaultPort = opts.defaultPort || defaultPort;
|
|
4129
|
+
opts.port = parsedUrl.port || defaultPort;
|
|
4130
|
+
opts.host = parsedUrl.hostname.startsWith("[") ? parsedUrl.hostname.slice(1, -1) : parsedUrl.hostname;
|
|
4131
|
+
opts.headers = {
|
|
4132
|
+
...opts.headers,
|
|
4133
|
+
"Sec-WebSocket-Version": opts.protocolVersion,
|
|
4134
|
+
"Sec-WebSocket-Key": key,
|
|
4135
|
+
Connection: "Upgrade",
|
|
4136
|
+
Upgrade: "websocket"
|
|
4137
|
+
};
|
|
4138
|
+
opts.path = parsedUrl.pathname + parsedUrl.search;
|
|
4139
|
+
opts.timeout = opts.handshakeTimeout;
|
|
4140
|
+
if (opts.perMessageDeflate) {
|
|
4141
|
+
perMessageDeflate = new PerMessageDeflate({
|
|
4142
|
+
...opts.perMessageDeflate,
|
|
4143
|
+
isServer: false,
|
|
4144
|
+
maxPayload: opts.maxPayload
|
|
4145
|
+
});
|
|
4146
|
+
opts.headers["Sec-WebSocket-Extensions"] = format({
|
|
4147
|
+
[PerMessageDeflate.extensionName]: perMessageDeflate.offer()
|
|
4148
|
+
});
|
|
4149
|
+
}
|
|
4150
|
+
if (protocols.length) {
|
|
4151
|
+
for (const protocol of protocols) {
|
|
4152
|
+
if (typeof protocol !== "string" || !subprotocolRegex.test(protocol) || protocolSet.has(protocol)) {
|
|
4153
|
+
throw new SyntaxError("An invalid or duplicated subprotocol was specified");
|
|
4154
|
+
}
|
|
4155
|
+
protocolSet.add(protocol);
|
|
4156
|
+
}
|
|
4157
|
+
opts.headers["Sec-WebSocket-Protocol"] = protocols.join(",");
|
|
4158
|
+
}
|
|
4159
|
+
if (opts.origin) {
|
|
4160
|
+
if (opts.protocolVersion < 13) {
|
|
4161
|
+
opts.headers["Sec-WebSocket-Origin"] = opts.origin;
|
|
4162
|
+
} else {
|
|
4163
|
+
opts.headers.Origin = opts.origin;
|
|
4164
|
+
}
|
|
4165
|
+
}
|
|
4166
|
+
if (parsedUrl.username || parsedUrl.password) {
|
|
4167
|
+
opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
|
|
4168
|
+
}
|
|
4169
|
+
if (isIpcUrl) {
|
|
4170
|
+
const parts = opts.path.split(":");
|
|
4171
|
+
opts.socketPath = parts[0];
|
|
4172
|
+
opts.path = parts[1];
|
|
4173
|
+
}
|
|
4174
|
+
let req;
|
|
4175
|
+
if (opts.followRedirects) {
|
|
4176
|
+
if (websocket._redirects === 0) {
|
|
4177
|
+
websocket._originalIpc = isIpcUrl;
|
|
4178
|
+
websocket._originalSecure = isSecure;
|
|
4179
|
+
websocket._originalHostOrSocketPath = isIpcUrl ? opts.socketPath : parsedUrl.host;
|
|
4180
|
+
const headers = options && options.headers;
|
|
4181
|
+
options = { ...options, headers: {} };
|
|
4182
|
+
if (headers) {
|
|
4183
|
+
for (const [key2, value] of Object.entries(headers)) {
|
|
4184
|
+
options.headers[key2.toLowerCase()] = value;
|
|
4185
|
+
}
|
|
4186
|
+
}
|
|
4187
|
+
} else if (websocket.listenerCount("redirect") === 0) {
|
|
4188
|
+
const isSameHost = isIpcUrl ? websocket._originalIpc ? opts.socketPath === websocket._originalHostOrSocketPath : false : websocket._originalIpc ? false : parsedUrl.host === websocket._originalHostOrSocketPath;
|
|
4189
|
+
if (!isSameHost || websocket._originalSecure && !isSecure) {
|
|
4190
|
+
delete opts.headers.authorization;
|
|
4191
|
+
delete opts.headers.cookie;
|
|
4192
|
+
if (!isSameHost)
|
|
4193
|
+
delete opts.headers.host;
|
|
4194
|
+
opts.auth = undefined;
|
|
4195
|
+
}
|
|
4196
|
+
}
|
|
4197
|
+
if (opts.auth && !options.headers.authorization) {
|
|
4198
|
+
options.headers.authorization = "Basic " + Buffer.from(opts.auth).toString("base64");
|
|
4199
|
+
}
|
|
4200
|
+
req = websocket._req = request(opts);
|
|
4201
|
+
if (websocket._redirects) {
|
|
4202
|
+
websocket.emit("redirect", websocket.url, req);
|
|
4203
|
+
}
|
|
4204
|
+
} else {
|
|
4205
|
+
req = websocket._req = request(opts);
|
|
4206
|
+
}
|
|
4207
|
+
if (opts.timeout) {
|
|
4208
|
+
req.on("timeout", () => {
|
|
4209
|
+
abortHandshake(websocket, req, "Opening handshake has timed out");
|
|
4210
|
+
});
|
|
4211
|
+
}
|
|
4212
|
+
req.on("error", (err) => {
|
|
4213
|
+
if (req === null || req[kAborted])
|
|
4214
|
+
return;
|
|
4215
|
+
req = websocket._req = null;
|
|
4216
|
+
emitErrorAndClose(websocket, err);
|
|
4217
|
+
});
|
|
4218
|
+
req.on("response", (res) => {
|
|
4219
|
+
const location = res.headers.location;
|
|
4220
|
+
const statusCode = res.statusCode;
|
|
4221
|
+
if (location && opts.followRedirects && statusCode >= 300 && statusCode < 400) {
|
|
4222
|
+
if (++websocket._redirects > opts.maxRedirects) {
|
|
4223
|
+
abortHandshake(websocket, req, "Maximum redirects exceeded");
|
|
4224
|
+
return;
|
|
4225
|
+
}
|
|
4226
|
+
req.abort();
|
|
4227
|
+
let addr;
|
|
4228
|
+
try {
|
|
4229
|
+
addr = new URL2(location, address);
|
|
4230
|
+
} catch (e) {
|
|
4231
|
+
const err = new SyntaxError(`Invalid URL: ${location}`);
|
|
4232
|
+
emitErrorAndClose(websocket, err);
|
|
4233
|
+
return;
|
|
4234
|
+
}
|
|
4235
|
+
initAsClient(websocket, addr, protocols, options);
|
|
4236
|
+
} else if (!websocket.emit("unexpected-response", req, res)) {
|
|
4237
|
+
abortHandshake(websocket, req, `Unexpected server response: ${res.statusCode}`);
|
|
4238
|
+
}
|
|
4239
|
+
});
|
|
4240
|
+
req.on("upgrade", (res, socket, head) => {
|
|
4241
|
+
websocket.emit("upgrade", res);
|
|
4242
|
+
if (websocket.readyState !== WebSocket.CONNECTING)
|
|
4243
|
+
return;
|
|
4244
|
+
req = websocket._req = null;
|
|
4245
|
+
const upgrade = res.headers.upgrade;
|
|
4246
|
+
if (upgrade === undefined || upgrade.toLowerCase() !== "websocket") {
|
|
4247
|
+
abortHandshake(websocket, socket, "Invalid Upgrade header");
|
|
4248
|
+
return;
|
|
4249
|
+
}
|
|
4250
|
+
const digest = createHash("sha1").update(key + GUID).digest("base64");
|
|
4251
|
+
if (res.headers["sec-websocket-accept"] !== digest) {
|
|
4252
|
+
abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
|
|
4253
|
+
return;
|
|
4254
|
+
}
|
|
4255
|
+
const serverProt = res.headers["sec-websocket-protocol"];
|
|
4256
|
+
let protError;
|
|
4257
|
+
if (serverProt !== undefined) {
|
|
4258
|
+
if (!protocolSet.size) {
|
|
4259
|
+
protError = "Server sent a subprotocol but none was requested";
|
|
4260
|
+
} else if (!protocolSet.has(serverProt)) {
|
|
4261
|
+
protError = "Server sent an invalid subprotocol";
|
|
4262
|
+
}
|
|
4263
|
+
} else if (protocolSet.size) {
|
|
4264
|
+
protError = "Server sent no subprotocol";
|
|
4265
|
+
}
|
|
4266
|
+
if (protError) {
|
|
4267
|
+
abortHandshake(websocket, socket, protError);
|
|
4268
|
+
return;
|
|
4269
|
+
}
|
|
4270
|
+
if (serverProt)
|
|
4271
|
+
websocket._protocol = serverProt;
|
|
4272
|
+
const secWebSocketExtensions = res.headers["sec-websocket-extensions"];
|
|
4273
|
+
if (secWebSocketExtensions !== undefined) {
|
|
4274
|
+
if (!perMessageDeflate) {
|
|
4275
|
+
const message = "Server sent a Sec-WebSocket-Extensions header but no extension " + "was requested";
|
|
4276
|
+
abortHandshake(websocket, socket, message);
|
|
4277
|
+
return;
|
|
4278
|
+
}
|
|
4279
|
+
let extensions;
|
|
4280
|
+
try {
|
|
4281
|
+
extensions = parse(secWebSocketExtensions);
|
|
4282
|
+
} catch (err) {
|
|
4283
|
+
const message = "Invalid Sec-WebSocket-Extensions header";
|
|
4284
|
+
abortHandshake(websocket, socket, message);
|
|
4285
|
+
return;
|
|
4286
|
+
}
|
|
4287
|
+
const extensionNames = Object.keys(extensions);
|
|
4288
|
+
if (extensionNames.length !== 1 || extensionNames[0] !== PerMessageDeflate.extensionName) {
|
|
4289
|
+
const message = "Server indicated an extension that was not requested";
|
|
4290
|
+
abortHandshake(websocket, socket, message);
|
|
4291
|
+
return;
|
|
4292
|
+
}
|
|
4293
|
+
try {
|
|
4294
|
+
perMessageDeflate.accept(extensions[PerMessageDeflate.extensionName]);
|
|
4295
|
+
} catch (err) {
|
|
4296
|
+
const message = "Invalid Sec-WebSocket-Extensions header";
|
|
4297
|
+
abortHandshake(websocket, socket, message);
|
|
4298
|
+
return;
|
|
4299
|
+
}
|
|
4300
|
+
websocket._extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
|
|
4301
|
+
}
|
|
4302
|
+
websocket.setSocket(socket, head, {
|
|
4303
|
+
allowSynchronousEvents: opts.allowSynchronousEvents,
|
|
4304
|
+
generateMask: opts.generateMask,
|
|
4305
|
+
maxPayload: opts.maxPayload,
|
|
4306
|
+
skipUTF8Validation: opts.skipUTF8Validation
|
|
4307
|
+
});
|
|
4308
|
+
});
|
|
4309
|
+
if (opts.finishRequest) {
|
|
4310
|
+
opts.finishRequest(req, websocket);
|
|
4311
|
+
} else {
|
|
4312
|
+
req.end();
|
|
4313
|
+
}
|
|
4314
|
+
}
|
|
4315
|
+
function emitErrorAndClose(websocket, err) {
|
|
4316
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
4317
|
+
websocket._errorEmitted = true;
|
|
4318
|
+
websocket.emit("error", err);
|
|
4319
|
+
websocket.emitClose();
|
|
4320
|
+
}
|
|
4321
|
+
function netConnect(options) {
|
|
4322
|
+
options.path = options.socketPath;
|
|
4323
|
+
return net.connect(options);
|
|
4324
|
+
}
|
|
4325
|
+
function tlsConnect(options) {
|
|
4326
|
+
options.path = undefined;
|
|
4327
|
+
if (!options.servername && options.servername !== "") {
|
|
4328
|
+
options.servername = net.isIP(options.host) ? "" : options.host;
|
|
4329
|
+
}
|
|
4330
|
+
return tls.connect(options);
|
|
4331
|
+
}
|
|
4332
|
+
function abortHandshake(websocket, stream, message) {
|
|
4333
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
4334
|
+
const err = new Error(message);
|
|
4335
|
+
Error.captureStackTrace(err, abortHandshake);
|
|
4336
|
+
if (stream.setHeader) {
|
|
4337
|
+
stream[kAborted] = true;
|
|
4338
|
+
stream.abort();
|
|
4339
|
+
if (stream.socket && !stream.socket.destroyed) {
|
|
4340
|
+
stream.socket.destroy();
|
|
4341
|
+
}
|
|
4342
|
+
process.nextTick(emitErrorAndClose, websocket, err);
|
|
4343
|
+
} else {
|
|
4344
|
+
stream.destroy(err);
|
|
4345
|
+
stream.once("error", websocket.emit.bind(websocket, "error"));
|
|
4346
|
+
stream.once("close", websocket.emitClose.bind(websocket));
|
|
4347
|
+
}
|
|
4348
|
+
}
|
|
4349
|
+
function sendAfterClose(websocket, data, cb) {
|
|
4350
|
+
if (data) {
|
|
4351
|
+
const length = isBlob(data) ? data.size : toBuffer(data).length;
|
|
4352
|
+
if (websocket._socket)
|
|
4353
|
+
websocket._sender._bufferedBytes += length;
|
|
4354
|
+
else
|
|
4355
|
+
websocket._bufferedAmount += length;
|
|
4356
|
+
}
|
|
4357
|
+
if (cb) {
|
|
4358
|
+
const err = new Error(`WebSocket is not open: readyState ${websocket.readyState} ` + `(${readyStates[websocket.readyState]})`);
|
|
4359
|
+
process.nextTick(cb, err);
|
|
4360
|
+
}
|
|
4361
|
+
}
|
|
4362
|
+
function receiverOnConclude(code, reason) {
|
|
4363
|
+
const websocket = this[kWebSocket];
|
|
4364
|
+
websocket._closeFrameReceived = true;
|
|
4365
|
+
websocket._closeMessage = reason;
|
|
4366
|
+
websocket._closeCode = code;
|
|
4367
|
+
if (websocket._socket[kWebSocket] === undefined)
|
|
4368
|
+
return;
|
|
4369
|
+
websocket._socket.removeListener("data", socketOnData);
|
|
4370
|
+
process.nextTick(resume, websocket._socket);
|
|
4371
|
+
if (code === 1005)
|
|
4372
|
+
websocket.close();
|
|
4373
|
+
else
|
|
4374
|
+
websocket.close(code, reason);
|
|
4375
|
+
}
|
|
4376
|
+
function receiverOnDrain() {
|
|
4377
|
+
const websocket = this[kWebSocket];
|
|
4378
|
+
if (!websocket.isPaused)
|
|
4379
|
+
websocket._socket.resume();
|
|
4380
|
+
}
|
|
4381
|
+
function receiverOnError(err) {
|
|
4382
|
+
const websocket = this[kWebSocket];
|
|
4383
|
+
if (websocket._socket[kWebSocket] !== undefined) {
|
|
4384
|
+
websocket._socket.removeListener("data", socketOnData);
|
|
4385
|
+
process.nextTick(resume, websocket._socket);
|
|
4386
|
+
websocket.close(err[kStatusCode]);
|
|
4387
|
+
}
|
|
4388
|
+
if (!websocket._errorEmitted) {
|
|
4389
|
+
websocket._errorEmitted = true;
|
|
4390
|
+
websocket.emit("error", err);
|
|
4391
|
+
}
|
|
4392
|
+
}
|
|
4393
|
+
function receiverOnFinish() {
|
|
4394
|
+
this[kWebSocket].emitClose();
|
|
4395
|
+
}
|
|
4396
|
+
function receiverOnMessage(data, isBinary) {
|
|
4397
|
+
this[kWebSocket].emit("message", data, isBinary);
|
|
4398
|
+
}
|
|
4399
|
+
function receiverOnPing(data) {
|
|
4400
|
+
const websocket = this[kWebSocket];
|
|
4401
|
+
if (websocket._autoPong)
|
|
4402
|
+
websocket.pong(data, !this._isServer, NOOP);
|
|
4403
|
+
websocket.emit("ping", data);
|
|
4404
|
+
}
|
|
4405
|
+
function receiverOnPong(data) {
|
|
4406
|
+
this[kWebSocket].emit("pong", data);
|
|
4407
|
+
}
|
|
4408
|
+
function resume(stream) {
|
|
4409
|
+
stream.resume();
|
|
4410
|
+
}
|
|
4411
|
+
function senderOnError(err) {
|
|
4412
|
+
const websocket = this[kWebSocket];
|
|
4413
|
+
if (websocket.readyState === WebSocket.CLOSED)
|
|
4414
|
+
return;
|
|
4415
|
+
if (websocket.readyState === WebSocket.OPEN) {
|
|
4416
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
4417
|
+
setCloseTimer(websocket);
|
|
4418
|
+
}
|
|
4419
|
+
this._socket.end();
|
|
4420
|
+
if (!websocket._errorEmitted) {
|
|
4421
|
+
websocket._errorEmitted = true;
|
|
4422
|
+
websocket.emit("error", err);
|
|
4423
|
+
}
|
|
4424
|
+
}
|
|
4425
|
+
function setCloseTimer(websocket) {
|
|
4426
|
+
websocket._closeTimer = setTimeout(websocket._socket.destroy.bind(websocket._socket), websocket._closeTimeout);
|
|
4427
|
+
}
|
|
4428
|
+
function socketOnClose() {
|
|
4429
|
+
const websocket = this[kWebSocket];
|
|
4430
|
+
this.removeListener("close", socketOnClose);
|
|
4431
|
+
this.removeListener("data", socketOnData);
|
|
4432
|
+
this.removeListener("end", socketOnEnd);
|
|
4433
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
4434
|
+
if (!this._readableState.endEmitted && !websocket._closeFrameReceived && !websocket._receiver._writableState.errorEmitted && this._readableState.length !== 0) {
|
|
4435
|
+
const chunk = this.read(this._readableState.length);
|
|
4436
|
+
websocket._receiver.write(chunk);
|
|
4437
|
+
}
|
|
4438
|
+
websocket._receiver.end();
|
|
4439
|
+
this[kWebSocket] = undefined;
|
|
4440
|
+
clearTimeout(websocket._closeTimer);
|
|
4441
|
+
if (websocket._receiver._writableState.finished || websocket._receiver._writableState.errorEmitted) {
|
|
4442
|
+
websocket.emitClose();
|
|
4443
|
+
} else {
|
|
4444
|
+
websocket._receiver.on("error", receiverOnFinish);
|
|
4445
|
+
websocket._receiver.on("finish", receiverOnFinish);
|
|
4446
|
+
}
|
|
4447
|
+
}
|
|
4448
|
+
function socketOnData(chunk) {
|
|
4449
|
+
if (!this[kWebSocket]._receiver.write(chunk)) {
|
|
4450
|
+
this.pause();
|
|
4451
|
+
}
|
|
4452
|
+
}
|
|
4453
|
+
function socketOnEnd() {
|
|
4454
|
+
const websocket = this[kWebSocket];
|
|
4455
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
4456
|
+
websocket._receiver.end();
|
|
4457
|
+
this.end();
|
|
4458
|
+
}
|
|
4459
|
+
function socketOnError() {
|
|
4460
|
+
const websocket = this[kWebSocket];
|
|
4461
|
+
this.removeListener("error", socketOnError);
|
|
4462
|
+
this.on("error", NOOP);
|
|
4463
|
+
if (websocket) {
|
|
4464
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
4465
|
+
this.destroy();
|
|
4466
|
+
}
|
|
4467
|
+
}
|
|
4468
|
+
});
|
|
4469
|
+
|
|
4470
|
+
// ../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/stream.js
|
|
4471
|
+
var require_stream = __commonJS((exports, module) => {
|
|
4472
|
+
var WebSocket = require_websocket();
|
|
4473
|
+
var { Duplex } = __require("stream");
|
|
4474
|
+
function emitClose(stream) {
|
|
4475
|
+
stream.emit("close");
|
|
4476
|
+
}
|
|
4477
|
+
function duplexOnEnd() {
|
|
4478
|
+
if (!this.destroyed && this._writableState.finished) {
|
|
4479
|
+
this.destroy();
|
|
4480
|
+
}
|
|
4481
|
+
}
|
|
4482
|
+
function duplexOnError(err) {
|
|
4483
|
+
this.removeListener("error", duplexOnError);
|
|
4484
|
+
this.destroy();
|
|
4485
|
+
if (this.listenerCount("error") === 0) {
|
|
4486
|
+
this.emit("error", err);
|
|
4487
|
+
}
|
|
4488
|
+
}
|
|
4489
|
+
function createWebSocketStream(ws, options) {
|
|
4490
|
+
let terminateOnDestroy = true;
|
|
4491
|
+
const duplex = new Duplex({
|
|
4492
|
+
...options,
|
|
4493
|
+
autoDestroy: false,
|
|
4494
|
+
emitClose: false,
|
|
4495
|
+
objectMode: false,
|
|
4496
|
+
writableObjectMode: false
|
|
4497
|
+
});
|
|
4498
|
+
ws.on("message", function message(msg, isBinary) {
|
|
4499
|
+
const data = !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
|
|
4500
|
+
if (!duplex.push(data))
|
|
4501
|
+
ws.pause();
|
|
4502
|
+
});
|
|
4503
|
+
ws.once("error", function error2(err) {
|
|
4504
|
+
if (duplex.destroyed)
|
|
4505
|
+
return;
|
|
4506
|
+
terminateOnDestroy = false;
|
|
4507
|
+
duplex.destroy(err);
|
|
4508
|
+
});
|
|
4509
|
+
ws.once("close", function close() {
|
|
4510
|
+
if (duplex.destroyed)
|
|
4511
|
+
return;
|
|
4512
|
+
duplex.push(null);
|
|
4513
|
+
});
|
|
4514
|
+
duplex._destroy = function(err, callback) {
|
|
4515
|
+
if (ws.readyState === ws.CLOSED) {
|
|
4516
|
+
callback(err);
|
|
4517
|
+
process.nextTick(emitClose, duplex);
|
|
4518
|
+
return;
|
|
4519
|
+
}
|
|
4520
|
+
let called = false;
|
|
4521
|
+
ws.once("error", function error2(err2) {
|
|
4522
|
+
called = true;
|
|
4523
|
+
callback(err2);
|
|
4524
|
+
});
|
|
4525
|
+
ws.once("close", function close() {
|
|
4526
|
+
if (!called)
|
|
4527
|
+
callback(err);
|
|
4528
|
+
process.nextTick(emitClose, duplex);
|
|
4529
|
+
});
|
|
4530
|
+
if (terminateOnDestroy)
|
|
4531
|
+
ws.terminate();
|
|
4532
|
+
};
|
|
4533
|
+
duplex._final = function(callback) {
|
|
4534
|
+
if (ws.readyState === ws.CONNECTING) {
|
|
4535
|
+
ws.once("open", function open() {
|
|
4536
|
+
duplex._final(callback);
|
|
4537
|
+
});
|
|
4538
|
+
return;
|
|
4539
|
+
}
|
|
4540
|
+
if (ws._socket === null)
|
|
4541
|
+
return;
|
|
4542
|
+
if (ws._socket._writableState.finished) {
|
|
4543
|
+
callback();
|
|
4544
|
+
if (duplex._readableState.endEmitted)
|
|
4545
|
+
duplex.destroy();
|
|
4546
|
+
} else {
|
|
4547
|
+
ws._socket.once("finish", function finish() {
|
|
4548
|
+
callback();
|
|
4549
|
+
});
|
|
4550
|
+
ws.close();
|
|
4551
|
+
}
|
|
4552
|
+
};
|
|
4553
|
+
duplex._read = function() {
|
|
4554
|
+
if (ws.isPaused)
|
|
4555
|
+
ws.resume();
|
|
4556
|
+
};
|
|
4557
|
+
duplex._write = function(chunk, encoding, callback) {
|
|
4558
|
+
if (ws.readyState === ws.CONNECTING) {
|
|
4559
|
+
ws.once("open", function open() {
|
|
4560
|
+
duplex._write(chunk, encoding, callback);
|
|
4561
|
+
});
|
|
4562
|
+
return;
|
|
4563
|
+
}
|
|
4564
|
+
ws.send(chunk, callback);
|
|
4565
|
+
};
|
|
4566
|
+
duplex.on("end", duplexOnEnd);
|
|
4567
|
+
duplex.on("error", duplexOnError);
|
|
4568
|
+
return duplex;
|
|
4569
|
+
}
|
|
4570
|
+
module.exports = createWebSocketStream;
|
|
4571
|
+
});
|
|
4572
|
+
|
|
4573
|
+
// ../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/subprotocol.js
|
|
4574
|
+
var require_subprotocol = __commonJS((exports, module) => {
|
|
4575
|
+
var { tokenChars } = require_validation();
|
|
4576
|
+
function parse(header) {
|
|
4577
|
+
const protocols = new Set;
|
|
4578
|
+
let start = -1;
|
|
4579
|
+
let end = -1;
|
|
4580
|
+
let i = 0;
|
|
4581
|
+
for (i;i < header.length; i++) {
|
|
4582
|
+
const code = header.charCodeAt(i);
|
|
4583
|
+
if (end === -1 && tokenChars[code] === 1) {
|
|
4584
|
+
if (start === -1)
|
|
4585
|
+
start = i;
|
|
4586
|
+
} else if (i !== 0 && (code === 32 || code === 9)) {
|
|
4587
|
+
if (end === -1 && start !== -1)
|
|
4588
|
+
end = i;
|
|
4589
|
+
} else if (code === 44) {
|
|
4590
|
+
if (start === -1) {
|
|
4591
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
4592
|
+
}
|
|
4593
|
+
if (end === -1)
|
|
4594
|
+
end = i;
|
|
4595
|
+
const protocol2 = header.slice(start, end);
|
|
4596
|
+
if (protocols.has(protocol2)) {
|
|
4597
|
+
throw new SyntaxError(`The "${protocol2}" subprotocol is duplicated`);
|
|
4598
|
+
}
|
|
4599
|
+
protocols.add(protocol2);
|
|
4600
|
+
start = end = -1;
|
|
4601
|
+
} else {
|
|
4602
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
4603
|
+
}
|
|
4604
|
+
}
|
|
4605
|
+
if (start === -1 || end !== -1) {
|
|
4606
|
+
throw new SyntaxError("Unexpected end of input");
|
|
4607
|
+
}
|
|
4608
|
+
const protocol = header.slice(start, i);
|
|
4609
|
+
if (protocols.has(protocol)) {
|
|
4610
|
+
throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
|
|
4611
|
+
}
|
|
4612
|
+
protocols.add(protocol);
|
|
4613
|
+
return protocols;
|
|
4614
|
+
}
|
|
4615
|
+
module.exports = { parse };
|
|
4616
|
+
});
|
|
4617
|
+
|
|
4618
|
+
// ../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/websocket-server.js
|
|
4619
|
+
var require_websocket_server = __commonJS((exports, module) => {
|
|
4620
|
+
var EventEmitter = __require("events");
|
|
4621
|
+
var http = __require("http");
|
|
4622
|
+
var { Duplex } = __require("stream");
|
|
4623
|
+
var { createHash } = __require("crypto");
|
|
4624
|
+
var extension = require_extension();
|
|
4625
|
+
var PerMessageDeflate = require_permessage_deflate();
|
|
4626
|
+
var subprotocol = require_subprotocol();
|
|
4627
|
+
var WebSocket = require_websocket();
|
|
4628
|
+
var { CLOSE_TIMEOUT, GUID, kWebSocket } = require_constants();
|
|
4629
|
+
var keyRegex = /^[+/0-9A-Za-z]{22}==$/;
|
|
4630
|
+
var RUNNING = 0;
|
|
4631
|
+
var CLOSING = 1;
|
|
4632
|
+
var CLOSED = 2;
|
|
4633
|
+
|
|
4634
|
+
class WebSocketServer extends EventEmitter {
|
|
4635
|
+
constructor(options, callback) {
|
|
4636
|
+
super();
|
|
4637
|
+
options = {
|
|
4638
|
+
allowSynchronousEvents: true,
|
|
4639
|
+
autoPong: true,
|
|
4640
|
+
maxPayload: 100 * 1024 * 1024,
|
|
4641
|
+
skipUTF8Validation: false,
|
|
4642
|
+
perMessageDeflate: false,
|
|
4643
|
+
handleProtocols: null,
|
|
4644
|
+
clientTracking: true,
|
|
4645
|
+
closeTimeout: CLOSE_TIMEOUT,
|
|
4646
|
+
verifyClient: null,
|
|
4647
|
+
noServer: false,
|
|
4648
|
+
backlog: null,
|
|
4649
|
+
server: null,
|
|
4650
|
+
host: null,
|
|
4651
|
+
path: null,
|
|
4652
|
+
port: null,
|
|
4653
|
+
WebSocket,
|
|
4654
|
+
...options
|
|
4655
|
+
};
|
|
4656
|
+
if (options.port == null && !options.server && !options.noServer || options.port != null && (options.server || options.noServer) || options.server && options.noServer) {
|
|
4657
|
+
throw new TypeError('One and only one of the "port", "server", or "noServer" options ' + "must be specified");
|
|
4658
|
+
}
|
|
4659
|
+
if (options.port != null) {
|
|
4660
|
+
this._server = http.createServer((req, res) => {
|
|
4661
|
+
const body = http.STATUS_CODES[426];
|
|
4662
|
+
res.writeHead(426, {
|
|
4663
|
+
"Content-Length": body.length,
|
|
4664
|
+
"Content-Type": "text/plain"
|
|
4665
|
+
});
|
|
4666
|
+
res.end(body);
|
|
4667
|
+
});
|
|
4668
|
+
this._server.listen(options.port, options.host, options.backlog, callback);
|
|
4669
|
+
} else if (options.server) {
|
|
4670
|
+
this._server = options.server;
|
|
4671
|
+
}
|
|
4672
|
+
if (this._server) {
|
|
4673
|
+
const emitConnection = this.emit.bind(this, "connection");
|
|
4674
|
+
this._removeListeners = addListeners(this._server, {
|
|
4675
|
+
listening: this.emit.bind(this, "listening"),
|
|
4676
|
+
error: this.emit.bind(this, "error"),
|
|
4677
|
+
upgrade: (req, socket, head) => {
|
|
4678
|
+
this.handleUpgrade(req, socket, head, emitConnection);
|
|
4679
|
+
}
|
|
4680
|
+
});
|
|
4681
|
+
}
|
|
4682
|
+
if (options.perMessageDeflate === true)
|
|
4683
|
+
options.perMessageDeflate = {};
|
|
4684
|
+
if (options.clientTracking) {
|
|
4685
|
+
this.clients = new Set;
|
|
4686
|
+
this._shouldEmitClose = false;
|
|
4687
|
+
}
|
|
4688
|
+
this.options = options;
|
|
4689
|
+
this._state = RUNNING;
|
|
4690
|
+
}
|
|
4691
|
+
address() {
|
|
4692
|
+
if (this.options.noServer) {
|
|
4693
|
+
throw new Error('The server is operating in "noServer" mode');
|
|
4694
|
+
}
|
|
4695
|
+
if (!this._server)
|
|
4696
|
+
return null;
|
|
4697
|
+
return this._server.address();
|
|
4698
|
+
}
|
|
4699
|
+
close(cb) {
|
|
4700
|
+
if (this._state === CLOSED) {
|
|
4701
|
+
if (cb) {
|
|
4702
|
+
this.once("close", () => {
|
|
4703
|
+
cb(new Error("The server is not running"));
|
|
4704
|
+
});
|
|
4705
|
+
}
|
|
4706
|
+
process.nextTick(emitClose, this);
|
|
4707
|
+
return;
|
|
4708
|
+
}
|
|
4709
|
+
if (cb)
|
|
4710
|
+
this.once("close", cb);
|
|
4711
|
+
if (this._state === CLOSING)
|
|
4712
|
+
return;
|
|
4713
|
+
this._state = CLOSING;
|
|
4714
|
+
if (this.options.noServer || this.options.server) {
|
|
4715
|
+
if (this._server) {
|
|
4716
|
+
this._removeListeners();
|
|
4717
|
+
this._removeListeners = this._server = null;
|
|
4718
|
+
}
|
|
4719
|
+
if (this.clients) {
|
|
4720
|
+
if (!this.clients.size) {
|
|
4721
|
+
process.nextTick(emitClose, this);
|
|
4722
|
+
} else {
|
|
4723
|
+
this._shouldEmitClose = true;
|
|
4724
|
+
}
|
|
4725
|
+
} else {
|
|
4726
|
+
process.nextTick(emitClose, this);
|
|
4727
|
+
}
|
|
4728
|
+
} else {
|
|
4729
|
+
const server = this._server;
|
|
4730
|
+
this._removeListeners();
|
|
4731
|
+
this._removeListeners = this._server = null;
|
|
4732
|
+
server.close(() => {
|
|
4733
|
+
emitClose(this);
|
|
4734
|
+
});
|
|
4735
|
+
}
|
|
4736
|
+
}
|
|
4737
|
+
shouldHandle(req) {
|
|
4738
|
+
if (this.options.path) {
|
|
4739
|
+
const index = req.url.indexOf("?");
|
|
4740
|
+
const pathname = index !== -1 ? req.url.slice(0, index) : req.url;
|
|
4741
|
+
if (pathname !== this.options.path)
|
|
4742
|
+
return false;
|
|
4743
|
+
}
|
|
4744
|
+
return true;
|
|
4745
|
+
}
|
|
4746
|
+
handleUpgrade(req, socket, head, cb) {
|
|
4747
|
+
socket.on("error", socketOnError);
|
|
4748
|
+
const key = req.headers["sec-websocket-key"];
|
|
4749
|
+
const upgrade = req.headers.upgrade;
|
|
4750
|
+
const version = +req.headers["sec-websocket-version"];
|
|
4751
|
+
if (req.method !== "GET") {
|
|
4752
|
+
const message = "Invalid HTTP method";
|
|
4753
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 405, message);
|
|
4754
|
+
return;
|
|
4755
|
+
}
|
|
4756
|
+
if (upgrade === undefined || upgrade.toLowerCase() !== "websocket") {
|
|
4757
|
+
const message = "Invalid Upgrade header";
|
|
4758
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
4759
|
+
return;
|
|
4760
|
+
}
|
|
4761
|
+
if (key === undefined || !keyRegex.test(key)) {
|
|
4762
|
+
const message = "Missing or invalid Sec-WebSocket-Key header";
|
|
4763
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
4764
|
+
return;
|
|
4765
|
+
}
|
|
4766
|
+
if (version !== 13 && version !== 8) {
|
|
4767
|
+
const message = "Missing or invalid Sec-WebSocket-Version header";
|
|
4768
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message, {
|
|
4769
|
+
"Sec-WebSocket-Version": "13, 8"
|
|
4770
|
+
});
|
|
4771
|
+
return;
|
|
4772
|
+
}
|
|
4773
|
+
if (!this.shouldHandle(req)) {
|
|
4774
|
+
abortHandshake(socket, 400);
|
|
4775
|
+
return;
|
|
4776
|
+
}
|
|
4777
|
+
const secWebSocketProtocol = req.headers["sec-websocket-protocol"];
|
|
4778
|
+
let protocols = new Set;
|
|
4779
|
+
if (secWebSocketProtocol !== undefined) {
|
|
4780
|
+
try {
|
|
4781
|
+
protocols = subprotocol.parse(secWebSocketProtocol);
|
|
4782
|
+
} catch (err) {
|
|
4783
|
+
const message = "Invalid Sec-WebSocket-Protocol header";
|
|
4784
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
4785
|
+
return;
|
|
4786
|
+
}
|
|
4787
|
+
}
|
|
4788
|
+
const secWebSocketExtensions = req.headers["sec-websocket-extensions"];
|
|
4789
|
+
const extensions = {};
|
|
4790
|
+
if (this.options.perMessageDeflate && secWebSocketExtensions !== undefined) {
|
|
4791
|
+
const perMessageDeflate = new PerMessageDeflate({
|
|
4792
|
+
...this.options.perMessageDeflate,
|
|
4793
|
+
isServer: true,
|
|
4794
|
+
maxPayload: this.options.maxPayload
|
|
4795
|
+
});
|
|
4796
|
+
try {
|
|
4797
|
+
const offers = extension.parse(secWebSocketExtensions);
|
|
4798
|
+
if (offers[PerMessageDeflate.extensionName]) {
|
|
4799
|
+
perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]);
|
|
4800
|
+
extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
|
|
4801
|
+
}
|
|
4802
|
+
} catch (err) {
|
|
4803
|
+
const message = "Invalid or unacceptable Sec-WebSocket-Extensions header";
|
|
4804
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
4805
|
+
return;
|
|
4806
|
+
}
|
|
4807
|
+
}
|
|
4808
|
+
if (this.options.verifyClient) {
|
|
4809
|
+
const info = {
|
|
4810
|
+
origin: req.headers[`${version === 8 ? "sec-websocket-origin" : "origin"}`],
|
|
4811
|
+
secure: !!(req.socket.authorized || req.socket.encrypted),
|
|
4812
|
+
req
|
|
4813
|
+
};
|
|
4814
|
+
if (this.options.verifyClient.length === 2) {
|
|
4815
|
+
this.options.verifyClient(info, (verified, code, message, headers) => {
|
|
4816
|
+
if (!verified) {
|
|
4817
|
+
return abortHandshake(socket, code || 401, message, headers);
|
|
4818
|
+
}
|
|
4819
|
+
this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
|
|
4820
|
+
});
|
|
4821
|
+
return;
|
|
4822
|
+
}
|
|
4823
|
+
if (!this.options.verifyClient(info))
|
|
4824
|
+
return abortHandshake(socket, 401);
|
|
4825
|
+
}
|
|
4826
|
+
this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
|
|
4827
|
+
}
|
|
4828
|
+
completeUpgrade(extensions, key, protocols, req, socket, head, cb) {
|
|
4829
|
+
if (!socket.readable || !socket.writable)
|
|
4830
|
+
return socket.destroy();
|
|
4831
|
+
if (socket[kWebSocket]) {
|
|
4832
|
+
throw new Error("server.handleUpgrade() was called more than once with the same " + "socket, possibly due to a misconfiguration");
|
|
4833
|
+
}
|
|
4834
|
+
if (this._state > RUNNING)
|
|
4835
|
+
return abortHandshake(socket, 503);
|
|
4836
|
+
const digest = createHash("sha1").update(key + GUID).digest("base64");
|
|
4837
|
+
const headers = [
|
|
4838
|
+
"HTTP/1.1 101 Switching Protocols",
|
|
4839
|
+
"Upgrade: websocket",
|
|
4840
|
+
"Connection: Upgrade",
|
|
4841
|
+
`Sec-WebSocket-Accept: ${digest}`
|
|
4842
|
+
];
|
|
4843
|
+
const ws = new this.options.WebSocket(null, undefined, this.options);
|
|
4844
|
+
if (protocols.size) {
|
|
4845
|
+
const protocol = this.options.handleProtocols ? this.options.handleProtocols(protocols, req) : protocols.values().next().value;
|
|
4846
|
+
if (protocol) {
|
|
4847
|
+
headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
|
|
4848
|
+
ws._protocol = protocol;
|
|
4849
|
+
}
|
|
4850
|
+
}
|
|
4851
|
+
if (extensions[PerMessageDeflate.extensionName]) {
|
|
4852
|
+
const params = extensions[PerMessageDeflate.extensionName].params;
|
|
4853
|
+
const value = extension.format({
|
|
4854
|
+
[PerMessageDeflate.extensionName]: [params]
|
|
4855
|
+
});
|
|
4856
|
+
headers.push(`Sec-WebSocket-Extensions: ${value}`);
|
|
4857
|
+
ws._extensions = extensions;
|
|
4858
|
+
}
|
|
4859
|
+
this.emit("headers", headers, req);
|
|
4860
|
+
socket.write(headers.concat(`\r
|
|
4861
|
+
`).join(`\r
|
|
4862
|
+
`));
|
|
4863
|
+
socket.removeListener("error", socketOnError);
|
|
4864
|
+
ws.setSocket(socket, head, {
|
|
4865
|
+
allowSynchronousEvents: this.options.allowSynchronousEvents,
|
|
4866
|
+
maxPayload: this.options.maxPayload,
|
|
4867
|
+
skipUTF8Validation: this.options.skipUTF8Validation
|
|
4868
|
+
});
|
|
4869
|
+
if (this.clients) {
|
|
4870
|
+
this.clients.add(ws);
|
|
4871
|
+
ws.on("close", () => {
|
|
4872
|
+
this.clients.delete(ws);
|
|
4873
|
+
if (this._shouldEmitClose && !this.clients.size) {
|
|
4874
|
+
process.nextTick(emitClose, this);
|
|
4875
|
+
}
|
|
4876
|
+
});
|
|
4877
|
+
}
|
|
4878
|
+
cb(ws, req);
|
|
4879
|
+
}
|
|
4880
|
+
}
|
|
4881
|
+
module.exports = WebSocketServer;
|
|
4882
|
+
function addListeners(server, map) {
|
|
4883
|
+
for (const event of Object.keys(map))
|
|
4884
|
+
server.on(event, map[event]);
|
|
4885
|
+
return function removeListeners() {
|
|
4886
|
+
for (const event of Object.keys(map)) {
|
|
4887
|
+
server.removeListener(event, map[event]);
|
|
4888
|
+
}
|
|
4889
|
+
};
|
|
4890
|
+
}
|
|
4891
|
+
function emitClose(server) {
|
|
4892
|
+
server._state = CLOSED;
|
|
4893
|
+
server.emit("close");
|
|
4894
|
+
}
|
|
4895
|
+
function socketOnError() {
|
|
4896
|
+
this.destroy();
|
|
4897
|
+
}
|
|
4898
|
+
function abortHandshake(socket, code, message, headers) {
|
|
4899
|
+
message = message || http.STATUS_CODES[code];
|
|
4900
|
+
headers = {
|
|
4901
|
+
Connection: "close",
|
|
4902
|
+
"Content-Type": "text/html",
|
|
4903
|
+
"Content-Length": Buffer.byteLength(message),
|
|
4904
|
+
...headers
|
|
4905
|
+
};
|
|
4906
|
+
socket.once("finish", socket.destroy);
|
|
4907
|
+
socket.end(`HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r
|
|
4908
|
+
` + Object.keys(headers).map((h) => `${h}: ${headers[h]}`).join(`\r
|
|
4909
|
+
`) + `\r
|
|
4910
|
+
\r
|
|
4911
|
+
` + message);
|
|
4912
|
+
}
|
|
4913
|
+
function abortHandshakeOrEmitwsClientError(server, req, socket, code, message, headers) {
|
|
4914
|
+
if (server.listenerCount("wsClientError")) {
|
|
4915
|
+
const err = new Error(message);
|
|
4916
|
+
Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError);
|
|
4917
|
+
server.emit("wsClientError", err, socket, req);
|
|
4918
|
+
} else {
|
|
4919
|
+
abortHandshake(socket, code, message, headers);
|
|
4920
|
+
}
|
|
4921
|
+
}
|
|
4922
|
+
});
|
|
4923
|
+
|
|
4924
|
+
// ../../node_modules/.pnpm/ws@8.20.0/node_modules/ws/index.js
|
|
4925
|
+
var require_ws = __commonJS((exports, module) => {
|
|
4926
|
+
var createWebSocketStream = require_stream();
|
|
4927
|
+
var extension = require_extension();
|
|
4928
|
+
var PerMessageDeflate = require_permessage_deflate();
|
|
4929
|
+
var Receiver = require_receiver();
|
|
4930
|
+
var Sender = require_sender();
|
|
4931
|
+
var subprotocol = require_subprotocol();
|
|
4932
|
+
var WebSocket = require_websocket();
|
|
4933
|
+
var WebSocketServer = require_websocket_server();
|
|
4934
|
+
WebSocket.createWebSocketStream = createWebSocketStream;
|
|
4935
|
+
WebSocket.extension = extension;
|
|
4936
|
+
WebSocket.PerMessageDeflate = PerMessageDeflate;
|
|
4937
|
+
WebSocket.Receiver = Receiver;
|
|
4938
|
+
WebSocket.Sender = Sender;
|
|
4939
|
+
WebSocket.Server = WebSocketServer;
|
|
4940
|
+
WebSocket.subprotocol = subprotocol;
|
|
4941
|
+
WebSocket.WebSocket = WebSocket;
|
|
4942
|
+
WebSocket.WebSocketServer = WebSocketServer;
|
|
4943
|
+
module.exports = WebSocket;
|
|
4944
|
+
});
|
|
4945
|
+
|
|
2057
4946
|
// ../../node_modules/.pnpm/commander@13.1.0/node_modules/commander/esm.mjs
|
|
2058
4947
|
var import__ = __toESM(require_commander(), 1);
|
|
2059
4948
|
var {
|
|
@@ -2069,6 +4958,7 @@ var {
|
|
|
2069
4958
|
Option,
|
|
2070
4959
|
Help
|
|
2071
4960
|
} = import__.default;
|
|
4961
|
+
|
|
2072
4962
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/internal/tslib.mjs
|
|
2073
4963
|
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
2074
4964
|
if (kind === "m")
|
|
@@ -2086,6 +4976,7 @@ function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
|
2086
4976
|
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
2087
4977
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
2088
4978
|
}
|
|
4979
|
+
|
|
2089
4980
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/internal/utils/uuid.mjs
|
|
2090
4981
|
var uuid4 = function() {
|
|
2091
4982
|
const { crypto: crypto2 } = globalThis;
|
|
@@ -2097,6 +4988,7 @@ var uuid4 = function() {
|
|
|
2097
4988
|
const randomByte = crypto2 ? () => crypto2.getRandomValues(u8)[0] : () => Math.random() * 255 & 255;
|
|
2098
4989
|
return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, (c) => (+c ^ randomByte() & 15 >> +c / 4).toString(16));
|
|
2099
4990
|
};
|
|
4991
|
+
|
|
2100
4992
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/internal/errors.mjs
|
|
2101
4993
|
function isAbortError(err) {
|
|
2102
4994
|
return typeof err === "object" && err !== null && (("name" in err) && err.name === "AbortError" || ("message" in err) && String(err.message).includes("FetchRequestCanceledException"));
|
|
@@ -2123,9 +5015,11 @@ var castToError = (err) => {
|
|
|
2123
5015
|
}
|
|
2124
5016
|
return new Error(err);
|
|
2125
5017
|
};
|
|
5018
|
+
|
|
2126
5019
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/core/error.mjs
|
|
2127
5020
|
class AnthropicError extends Error {
|
|
2128
5021
|
}
|
|
5022
|
+
|
|
2129
5023
|
class APIError extends AnthropicError {
|
|
2130
5024
|
constructor(status, error, message, headers, type) {
|
|
2131
5025
|
super(`${APIError.makeMessage(status, error, message)}`);
|
|
@@ -2181,11 +5075,13 @@ class APIError extends AnthropicError {
|
|
|
2181
5075
|
return new APIError(status, error, message, headers, type);
|
|
2182
5076
|
}
|
|
2183
5077
|
}
|
|
5078
|
+
|
|
2184
5079
|
class APIUserAbortError extends APIError {
|
|
2185
5080
|
constructor({ message } = {}) {
|
|
2186
5081
|
super(undefined, undefined, message || "Request was aborted.", undefined);
|
|
2187
5082
|
}
|
|
2188
5083
|
}
|
|
5084
|
+
|
|
2189
5085
|
class APIConnectionError extends APIError {
|
|
2190
5086
|
constructor({ message, cause }) {
|
|
2191
5087
|
super(undefined, undefined, message || "Connection error.", undefined);
|
|
@@ -2193,27 +5089,37 @@ class APIConnectionError extends APIError {
|
|
|
2193
5089
|
this.cause = cause;
|
|
2194
5090
|
}
|
|
2195
5091
|
}
|
|
5092
|
+
|
|
2196
5093
|
class APIConnectionTimeoutError extends APIConnectionError {
|
|
2197
5094
|
constructor({ message } = {}) {
|
|
2198
5095
|
super({ message: message ?? "Request timed out." });
|
|
2199
5096
|
}
|
|
2200
5097
|
}
|
|
5098
|
+
|
|
2201
5099
|
class BadRequestError extends APIError {
|
|
2202
5100
|
}
|
|
5101
|
+
|
|
2203
5102
|
class AuthenticationError extends APIError {
|
|
2204
5103
|
}
|
|
5104
|
+
|
|
2205
5105
|
class PermissionDeniedError extends APIError {
|
|
2206
5106
|
}
|
|
5107
|
+
|
|
2207
5108
|
class NotFoundError extends APIError {
|
|
2208
5109
|
}
|
|
5110
|
+
|
|
2209
5111
|
class ConflictError extends APIError {
|
|
2210
5112
|
}
|
|
5113
|
+
|
|
2211
5114
|
class UnprocessableEntityError extends APIError {
|
|
2212
5115
|
}
|
|
5116
|
+
|
|
2213
5117
|
class RateLimitError extends APIError {
|
|
2214
5118
|
}
|
|
5119
|
+
|
|
2215
5120
|
class InternalServerError extends APIError {
|
|
2216
5121
|
}
|
|
5122
|
+
|
|
2217
5123
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/internal/utils/values.mjs
|
|
2218
5124
|
var startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
|
|
2219
5125
|
var isAbsoluteURL = (url) => {
|
|
@@ -2253,10 +5159,13 @@ var safeJSON = (text) => {
|
|
|
2253
5159
|
return;
|
|
2254
5160
|
}
|
|
2255
5161
|
};
|
|
5162
|
+
|
|
2256
5163
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/internal/utils/sleep.mjs
|
|
2257
5164
|
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
5165
|
+
|
|
2258
5166
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/version.mjs
|
|
2259
5167
|
var VERSION = "0.82.0";
|
|
5168
|
+
|
|
2260
5169
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/internal/detect-platform.mjs
|
|
2261
5170
|
var isRunningInBrowser = () => {
|
|
2262
5171
|
return typeof window !== "undefined" && typeof window.document !== "undefined" && typeof navigator !== "undefined";
|
|
@@ -2385,6 +5294,7 @@ var _platformHeaders;
|
|
|
2385
5294
|
var getPlatformHeaders = () => {
|
|
2386
5295
|
return _platformHeaders ?? (_platformHeaders = getPlatformProperties());
|
|
2387
5296
|
};
|
|
5297
|
+
|
|
2388
5298
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/internal/shims.mjs
|
|
2389
5299
|
function getDefaultFetch() {
|
|
2390
5300
|
if (typeof fetch !== "undefined") {
|
|
@@ -2455,6 +5365,7 @@ async function CancelReadableStream(stream) {
|
|
|
2455
5365
|
reader.releaseLock();
|
|
2456
5366
|
await cancelPromise;
|
|
2457
5367
|
}
|
|
5368
|
+
|
|
2458
5369
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/internal/request-options.mjs
|
|
2459
5370
|
var FallbackEncoder = ({ headers, body }) => {
|
|
2460
5371
|
return {
|
|
@@ -2464,6 +5375,7 @@ var FallbackEncoder = ({ headers, body }) => {
|
|
|
2464
5375
|
body: JSON.stringify(body)
|
|
2465
5376
|
};
|
|
2466
5377
|
};
|
|
5378
|
+
|
|
2467
5379
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/internal/utils/query.mjs
|
|
2468
5380
|
function stringifyQuery(query) {
|
|
2469
5381
|
return Object.entries(query).filter(([_, value]) => typeof value !== "undefined").map(([key, value]) => {
|
|
@@ -2476,6 +5388,7 @@ function stringifyQuery(query) {
|
|
|
2476
5388
|
throw new AnthropicError(`Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`);
|
|
2477
5389
|
}).join("&");
|
|
2478
5390
|
}
|
|
5391
|
+
|
|
2479
5392
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/internal/utils/bytes.mjs
|
|
2480
5393
|
function concatBytes(buffers) {
|
|
2481
5394
|
let length = 0;
|
|
@@ -2500,9 +5413,11 @@ function decodeUTF8(bytes) {
|
|
|
2500
5413
|
let decoder;
|
|
2501
5414
|
return (decodeUTF8_ ?? (decoder = new globalThis.TextDecoder, decodeUTF8_ = decoder.decode.bind(decoder)))(bytes);
|
|
2502
5415
|
}
|
|
5416
|
+
|
|
2503
5417
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/internal/decoders/line.mjs
|
|
2504
5418
|
var _LineDecoder_buffer;
|
|
2505
5419
|
var _LineDecoder_carriageReturnIndex;
|
|
5420
|
+
|
|
2506
5421
|
class LineDecoder {
|
|
2507
5422
|
constructor() {
|
|
2508
5423
|
_LineDecoder_buffer.set(this, undefined);
|
|
@@ -2578,6 +5493,7 @@ function findDoubleNewlineIndex(buffer) {
|
|
|
2578
5493
|
}
|
|
2579
5494
|
return -1;
|
|
2580
5495
|
}
|
|
5496
|
+
|
|
2581
5497
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/internal/utils/log.mjs
|
|
2582
5498
|
var levelNumbers = {
|
|
2583
5499
|
off: 0,
|
|
@@ -2649,8 +5565,10 @@ var formatRequestDetails = (details) => {
|
|
|
2649
5565
|
}
|
|
2650
5566
|
return details;
|
|
2651
5567
|
};
|
|
5568
|
+
|
|
2652
5569
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/core/streaming.mjs
|
|
2653
5570
|
var _Stream_client;
|
|
5571
|
+
|
|
2654
5572
|
class Stream {
|
|
2655
5573
|
constructor(iterator, controller, client) {
|
|
2656
5574
|
this.iterator = iterator;
|
|
@@ -2841,6 +5759,7 @@ async function* iterSSEChunks(iterator) {
|
|
|
2841
5759
|
yield data;
|
|
2842
5760
|
}
|
|
2843
5761
|
}
|
|
5762
|
+
|
|
2844
5763
|
class SSEDecoder {
|
|
2845
5764
|
constructor() {
|
|
2846
5765
|
this.event = null;
|
|
@@ -2888,6 +5807,7 @@ function partition(str, delimiter) {
|
|
|
2888
5807
|
}
|
|
2889
5808
|
return [str, "", ""];
|
|
2890
5809
|
}
|
|
5810
|
+
|
|
2891
5811
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/internal/parse.mjs
|
|
2892
5812
|
async function defaultParseResponse(client, props) {
|
|
2893
5813
|
const { response, requestLogID, retryOfRequestLogID, startTime } = props;
|
|
@@ -2937,8 +5857,10 @@ function addRequestID(value, response) {
|
|
|
2937
5857
|
enumerable: false
|
|
2938
5858
|
});
|
|
2939
5859
|
}
|
|
5860
|
+
|
|
2940
5861
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/core/api-promise.mjs
|
|
2941
5862
|
var _APIPromise_client;
|
|
5863
|
+
|
|
2942
5864
|
class APIPromise extends Promise {
|
|
2943
5865
|
constructor(client, responsePromise, parseResponse = defaultParseResponse) {
|
|
2944
5866
|
super((resolve) => {
|
|
@@ -2976,8 +5898,10 @@ class APIPromise extends Promise {
|
|
|
2976
5898
|
}
|
|
2977
5899
|
}
|
|
2978
5900
|
_APIPromise_client = new WeakMap;
|
|
5901
|
+
|
|
2979
5902
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/core/pagination.mjs
|
|
2980
5903
|
var _AbstractPage_client;
|
|
5904
|
+
|
|
2981
5905
|
class AbstractPage {
|
|
2982
5906
|
constructor(client, response, body, options) {
|
|
2983
5907
|
_AbstractPage_client.set(this, undefined);
|
|
@@ -3015,6 +5939,7 @@ class AbstractPage {
|
|
|
3015
5939
|
}
|
|
3016
5940
|
}
|
|
3017
5941
|
}
|
|
5942
|
+
|
|
3018
5943
|
class PagePromise extends APIPromise {
|
|
3019
5944
|
constructor(client, request, Page) {
|
|
3020
5945
|
super(client, request, async (client2, props) => new Page(client2, props.response, await defaultParseResponse(client2, props), props.options));
|
|
@@ -3026,6 +5951,7 @@ class PagePromise extends APIPromise {
|
|
|
3026
5951
|
}
|
|
3027
5952
|
}
|
|
3028
5953
|
}
|
|
5954
|
+
|
|
3029
5955
|
class Page extends AbstractPage {
|
|
3030
5956
|
constructor(client, response, body, options) {
|
|
3031
5957
|
super(client, response, body, options);
|
|
@@ -3100,6 +6026,7 @@ class PageCursor extends AbstractPage {
|
|
|
3100
6026
|
};
|
|
3101
6027
|
}
|
|
3102
6028
|
}
|
|
6029
|
+
|
|
3103
6030
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/internal/uploads.mjs
|
|
3104
6031
|
var checkFileSupport = () => {
|
|
3105
6032
|
if (typeof File === "undefined") {
|
|
@@ -3177,6 +6104,7 @@ var addFormValue = async (form, key, value, stripFilenames) => {
|
|
|
3177
6104
|
throw new TypeError(`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${value} instead`);
|
|
3178
6105
|
}
|
|
3179
6106
|
};
|
|
6107
|
+
|
|
3180
6108
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/internal/to-file.mjs
|
|
3181
6109
|
var isBlobLike = (value) => value != null && typeof value === "object" && typeof value.size === "number" && typeof value.type === "string" && typeof value.text === "function" && typeof value.slice === "function" && typeof value.arrayBuffer === "function";
|
|
3182
6110
|
var isFileLike = (value) => value != null && typeof value === "object" && typeof value.name === "string" && typeof value.lastModified === "number" && isBlobLike(value);
|
|
@@ -3237,6 +6165,7 @@ class APIResource {
|
|
|
3237
6165
|
this._client = client;
|
|
3238
6166
|
}
|
|
3239
6167
|
}
|
|
6168
|
+
|
|
3240
6169
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/internal/headers.mjs
|
|
3241
6170
|
var brand_privateNullableHeaders = Symbol.for("brand.privateNullableHeaders");
|
|
3242
6171
|
function* iterateHeaders(headers) {
|
|
@@ -3299,6 +6228,7 @@ var buildHeaders = (newHeaders) => {
|
|
|
3299
6228
|
}
|
|
3300
6229
|
return { [brand_privateNullableHeaders]: true, values: targetHeaders, nulls: nullHeaders };
|
|
3301
6230
|
};
|
|
6231
|
+
|
|
3302
6232
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/lib/stainless-helper-header.mjs
|
|
3303
6233
|
var SDK_HELPER_SYMBOL = Symbol("anthropic.sdk.stainlessHelper");
|
|
3304
6234
|
function wasCreatedByStainlessHelper(value) {
|
|
@@ -3341,6 +6271,7 @@ function stainlessHelperHeaderFromFile(file) {
|
|
|
3341
6271
|
}
|
|
3342
6272
|
return {};
|
|
3343
6273
|
}
|
|
6274
|
+
|
|
3344
6275
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/internal/utils/path.mjs
|
|
3345
6276
|
function encodeURIPath(str) {
|
|
3346
6277
|
return str.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
|
|
@@ -3395,6 +6326,7 @@ ${underline}`);
|
|
|
3395
6326
|
return path2;
|
|
3396
6327
|
};
|
|
3397
6328
|
var path = /* @__PURE__ */ createPathTagFunction(encodeURIPath);
|
|
6329
|
+
|
|
3398
6330
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/resources/beta/files.mjs
|
|
3399
6331
|
class Files extends APIResource {
|
|
3400
6332
|
list(params = {}, options) {
|
|
@@ -3455,6 +6387,7 @@ class Files extends APIResource {
|
|
|
3455
6387
|
}, this._client));
|
|
3456
6388
|
}
|
|
3457
6389
|
}
|
|
6390
|
+
|
|
3458
6391
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/resources/beta/models.mjs
|
|
3459
6392
|
class Models extends APIResource {
|
|
3460
6393
|
retrieve(modelID, params = {}, options) {
|
|
@@ -3490,6 +6423,7 @@ var MODEL_NONSTREAMING_TOKENS = {
|
|
|
3490
6423
|
"anthropic.claude-opus-4-1-20250805-v1:0": 8192,
|
|
3491
6424
|
"claude-opus-4-1@20250805": 8192
|
|
3492
6425
|
};
|
|
6426
|
+
|
|
3493
6427
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/lib/beta-parser.mjs
|
|
3494
6428
|
function getOutputFormat(params) {
|
|
3495
6429
|
return params?.output_format ?? params?.output_config?.format;
|
|
@@ -3562,6 +6496,7 @@ function parseBetaOutputFormat(params, content) {
|
|
|
3562
6496
|
throw new AnthropicError(`Failed to parse structured output: ${error2}`);
|
|
3563
6497
|
}
|
|
3564
6498
|
}
|
|
6499
|
+
|
|
3565
6500
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/_vendor/partial-json-parser/parser.mjs
|
|
3566
6501
|
var tokenize = (input) => {
|
|
3567
6502
|
let current = 0;
|
|
@@ -3810,6 +6745,7 @@ var JSON_BUF_PROPERTY = "__json_buf";
|
|
|
3810
6745
|
function tracksToolInput(content) {
|
|
3811
6746
|
return content.type === "tool_use" || content.type === "server_tool_use" || content.type === "mcp_tool_use";
|
|
3812
6747
|
}
|
|
6748
|
+
|
|
3813
6749
|
class BetaMessageStream {
|
|
3814
6750
|
constructor(params, opts) {
|
|
3815
6751
|
_BetaMessageStream_instances.add(this);
|
|
@@ -4331,6 +7267,7 @@ class BetaMessageStream {
|
|
|
4331
7267
|
}
|
|
4332
7268
|
}
|
|
4333
7269
|
function checkNever(x) {}
|
|
7270
|
+
|
|
4334
7271
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/lib/tools/ToolError.mjs
|
|
4335
7272
|
class ToolError extends Error {
|
|
4336
7273
|
constructor(content) {
|
|
@@ -4344,6 +7281,7 @@ class ToolError extends Error {
|
|
|
4344
7281
|
this.content = content;
|
|
4345
7282
|
}
|
|
4346
7283
|
}
|
|
7284
|
+
|
|
4347
7285
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/lib/tools/CompactionControl.mjs
|
|
4348
7286
|
var DEFAULT_TOKEN_THRESHOLD = 1e5;
|
|
4349
7287
|
var DEFAULT_SUMMARY_PROMPT = `You have been working on the task described above but have not yet completed it. Write a continuation summary that will allow you (or another instance of yourself) to resume work efficiently in a future context window where the conversation history will be replaced with this summary. Your summary should be structured, concise, and actionable. Include:
|
|
@@ -4369,6 +7307,7 @@ Domain-specific details that aren't obvious
|
|
|
4369
7307
|
Any promises made to the user
|
|
4370
7308
|
Be concise but complete—err on the side of including information that would prevent duplicate work or repeated mistakes. Write in a way that enables immediate resumption of the task.
|
|
4371
7309
|
Wrap your summary in <summary></summary> tags.`;
|
|
7310
|
+
|
|
4372
7311
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/lib/tools/BetaToolRunner.mjs
|
|
4373
7312
|
var _BetaToolRunner_instances;
|
|
4374
7313
|
var _BetaToolRunner_consumed;
|
|
@@ -4390,6 +7329,7 @@ function promiseWithResolvers() {
|
|
|
4390
7329
|
});
|
|
4391
7330
|
return { promise, resolve, reject };
|
|
4392
7331
|
}
|
|
7332
|
+
|
|
4393
7333
|
class BetaToolRunner {
|
|
4394
7334
|
constructor(client, params, options) {
|
|
4395
7335
|
_BetaToolRunner_instances.add(this);
|
|
@@ -4625,6 +7565,7 @@ async function generateToolResponse(params, lastMessage = params.messages.at(-1)
|
|
|
4625
7565
|
content: toolResults
|
|
4626
7566
|
};
|
|
4627
7567
|
}
|
|
7568
|
+
|
|
4628
7569
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/internal/decoders/jsonl.mjs
|
|
4629
7570
|
class JSONLDecoder {
|
|
4630
7571
|
constructor(iterator, controller) {
|
|
@@ -4656,6 +7597,7 @@ class JSONLDecoder {
|
|
|
4656
7597
|
return new JSONLDecoder(ReadableStreamToAsyncIterable(response.body), controller);
|
|
4657
7598
|
}
|
|
4658
7599
|
}
|
|
7600
|
+
|
|
4659
7601
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/resources/beta/messages/batches.mjs
|
|
4660
7602
|
class Batches extends APIResource {
|
|
4661
7603
|
create(params, options) {
|
|
@@ -4730,6 +7672,7 @@ class Batches extends APIResource {
|
|
|
4730
7672
|
})._thenUnwrap((_, props) => JSONLDecoder.fromResponse(props.response, props.controller));
|
|
4731
7673
|
}
|
|
4732
7674
|
}
|
|
7675
|
+
|
|
4733
7676
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/resources/beta/messages/messages.mjs
|
|
4734
7677
|
var DEPRECATED_MODELS = {
|
|
4735
7678
|
"claude-1.3": "November 6th, 2024",
|
|
@@ -4745,6 +7688,7 @@ var DEPRECATED_MODELS = {
|
|
|
4745
7688
|
"claude-3-7-sonnet-20250219": "February 19th, 2026"
|
|
4746
7689
|
};
|
|
4747
7690
|
var MODELS_TO_WARN_WITH_THINKING_ENABLED = ["claude-opus-4-6"];
|
|
7691
|
+
|
|
4748
7692
|
class Messages extends APIResource {
|
|
4749
7693
|
constructor() {
|
|
4750
7694
|
super(...arguments);
|
|
@@ -4826,6 +7770,7 @@ function transformOutputFormat(params) {
|
|
|
4826
7770
|
Messages.Batches = Batches;
|
|
4827
7771
|
Messages.BetaToolRunner = BetaToolRunner;
|
|
4828
7772
|
Messages.ToolError = ToolError;
|
|
7773
|
+
|
|
4829
7774
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/resources/beta/skills/versions.mjs
|
|
4830
7775
|
class Versions extends APIResource {
|
|
4831
7776
|
create(skillID, params = {}, options) {
|
|
@@ -4871,6 +7816,7 @@ class Versions extends APIResource {
|
|
|
4871
7816
|
});
|
|
4872
7817
|
}
|
|
4873
7818
|
}
|
|
7819
|
+
|
|
4874
7820
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/resources/beta/skills/skills.mjs
|
|
4875
7821
|
class Skills extends APIResource {
|
|
4876
7822
|
constructor() {
|
|
@@ -4921,6 +7867,7 @@ class Skills extends APIResource {
|
|
|
4921
7867
|
}
|
|
4922
7868
|
}
|
|
4923
7869
|
Skills.Versions = Versions;
|
|
7870
|
+
|
|
4924
7871
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/resources/beta/beta.mjs
|
|
4925
7872
|
class Beta extends APIResource {
|
|
4926
7873
|
constructor() {
|
|
@@ -5011,6 +7958,7 @@ function parseOutputFormat(params, content) {
|
|
|
5011
7958
|
throw new AnthropicError(`Failed to parse structured output: ${error2}`);
|
|
5012
7959
|
}
|
|
5013
7960
|
}
|
|
7961
|
+
|
|
5014
7962
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/lib/MessageStream.mjs
|
|
5015
7963
|
var _MessageStream_instances;
|
|
5016
7964
|
var _MessageStream_currentMessageSnapshot;
|
|
@@ -5040,6 +7988,7 @@ var JSON_BUF_PROPERTY2 = "__json_buf";
|
|
|
5040
7988
|
function tracksToolInput2(content) {
|
|
5041
7989
|
return content.type === "tool_use" || content.type === "server_tool_use";
|
|
5042
7990
|
}
|
|
7991
|
+
|
|
5043
7992
|
class MessageStream {
|
|
5044
7993
|
constructor(params, opts) {
|
|
5045
7994
|
_MessageStream_instances.add(this);
|
|
@@ -5536,6 +8485,7 @@ class MessageStream {
|
|
|
5536
8485
|
}
|
|
5537
8486
|
}
|
|
5538
8487
|
function checkNever2(x) {}
|
|
8488
|
+
|
|
5539
8489
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/resources/messages/batches.mjs
|
|
5540
8490
|
class Batches2 extends APIResource {
|
|
5541
8491
|
create(body, options) {
|
|
@@ -5566,6 +8516,7 @@ class Batches2 extends APIResource {
|
|
|
5566
8516
|
})._thenUnwrap((_, props) => JSONLDecoder.fromResponse(props.response, props.controller));
|
|
5567
8517
|
}
|
|
5568
8518
|
}
|
|
8519
|
+
|
|
5569
8520
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/resources/messages/messages.mjs
|
|
5570
8521
|
class Messages2 extends APIResource {
|
|
5571
8522
|
constructor() {
|
|
@@ -5655,6 +8606,7 @@ var readEnv = (env) => {
|
|
|
5655
8606
|
}
|
|
5656
8607
|
return;
|
|
5657
8608
|
};
|
|
8609
|
+
|
|
5658
8610
|
// ../../node_modules/.pnpm/@anthropic-ai+sdk@0.82.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/client.mjs
|
|
5659
8611
|
var _BaseAnthropic_instances;
|
|
5660
8612
|
var _a;
|
|
@@ -5662,6 +8614,7 @@ var _BaseAnthropic_encoder;
|
|
|
5662
8614
|
var _BaseAnthropic_baseURLOverridden;
|
|
5663
8615
|
var HUMAN_PROMPT = "\\n\\nHuman:";
|
|
5664
8616
|
var AI_PROMPT = "\\n\\nAssistant:";
|
|
8617
|
+
|
|
5665
8618
|
class BaseAnthropic {
|
|
5666
8619
|
constructor({ baseURL = readEnv("ANTHROPIC_BASE_URL"), apiKey = readEnv("ANTHROPIC_API_KEY") ?? null, authToken = readEnv("ANTHROPIC_AUTH_TOKEN") ?? null, ...opts } = {}) {
|
|
5667
8620
|
_BaseAnthropic_instances.add(this);
|
|
@@ -5674,9 +8627,11 @@ class BaseAnthropic {
|
|
|
5674
8627
|
};
|
|
5675
8628
|
if (!options.dangerouslyAllowBrowser && isRunningInBrowser()) {
|
|
5676
8629
|
throw new AnthropicError(`It looks like you're running in a browser-like environment.
|
|
8630
|
+
|
|
5677
8631
|
This is disabled by default, as it risks exposing your secret API credentials to attackers.
|
|
5678
8632
|
If you understand the risks and have appropriate mitigations in place,
|
|
5679
8633
|
you can set the \`dangerouslyAllowBrowser\` option to \`true\`, e.g.,
|
|
8634
|
+
|
|
5680
8635
|
new Anthropic({ apiKey, dangerouslyAllowBrowser: true });
|
|
5681
8636
|
`);
|
|
5682
8637
|
}
|
|
@@ -6078,6 +9033,7 @@ BaseAnthropic.InternalServerError = InternalServerError;
|
|
|
6078
9033
|
BaseAnthropic.PermissionDeniedError = PermissionDeniedError;
|
|
6079
9034
|
BaseAnthropic.UnprocessableEntityError = UnprocessableEntityError;
|
|
6080
9035
|
BaseAnthropic.toFile = toFile;
|
|
9036
|
+
|
|
6081
9037
|
class Anthropic extends BaseAnthropic {
|
|
6082
9038
|
constructor() {
|
|
6083
9039
|
super(...arguments);
|
|
@@ -6111,6 +9067,7 @@ function fromBase64(b64) {
|
|
|
6111
9067
|
}
|
|
6112
9068
|
return bytes;
|
|
6113
9069
|
}
|
|
9070
|
+
|
|
6114
9071
|
class KodamaCrypto {
|
|
6115
9072
|
static async generateKey() {
|
|
6116
9073
|
const key = await crypto.subtle.generateKey({ name: ALGO, length: KEY_LENGTH }, true, ["encrypt", "decrypt"]);
|
|
@@ -6139,6 +9096,7 @@ class KodamaCrypto {
|
|
|
6139
9096
|
return crypto.subtle.importKey("raw", raw, { name: ALGO, length: KEY_LENGTH }, false, ["encrypt", "decrypt"]);
|
|
6140
9097
|
}
|
|
6141
9098
|
}
|
|
9099
|
+
|
|
6142
9100
|
// src/permissions.ts
|
|
6143
9101
|
import { readFile } from "node:fs/promises";
|
|
6144
9102
|
// ../shared/src/constants.ts
|
|
@@ -6155,6 +9113,7 @@ var AUTO_DENY_PATTERNS = [
|
|
|
6155
9113
|
];
|
|
6156
9114
|
// ../shared/src/index.ts
|
|
6157
9115
|
var VALID_CODE_RE = new RegExp(`^${ROOM_CODE_PREFIX}-[${ROOM_CODE_CHARS}]{${ROOM_CODE_LENGTH}}$`);
|
|
9116
|
+
|
|
6158
9117
|
// src/permissions.ts
|
|
6159
9118
|
function globToRegex(pattern) {
|
|
6160
9119
|
let re = "";
|
|
@@ -6185,6 +9144,7 @@ function globToRegex(pattern) {
|
|
|
6185
9144
|
function matchesAny(filePath, patterns) {
|
|
6186
9145
|
return patterns.some((pattern) => globToRegex(pattern).test(filePath));
|
|
6187
9146
|
}
|
|
9147
|
+
|
|
6188
9148
|
class PermissionChecker {
|
|
6189
9149
|
allowPatterns;
|
|
6190
9150
|
denyPatterns;
|
|
@@ -6251,10 +9211,19 @@ class PermissionChecker {
|
|
|
6251
9211
|
}
|
|
6252
9212
|
}
|
|
6253
9213
|
}
|
|
9214
|
+
|
|
6254
9215
|
// src/room.ts
|
|
9216
|
+
var WS = typeof globalThis.WebSocket !== "undefined" ? globalThis.WebSocket : (() => {
|
|
9217
|
+
try {
|
|
9218
|
+
return require_ws();
|
|
9219
|
+
} catch {
|
|
9220
|
+
return null;
|
|
9221
|
+
}
|
|
9222
|
+
})();
|
|
6255
9223
|
var INITIAL_BACKOFF_MS = 1000;
|
|
6256
9224
|
var MAX_BACKOFF_MS = 30000;
|
|
6257
9225
|
var MAX_RECONNECT_ATTEMPTS = 10;
|
|
9226
|
+
|
|
6258
9227
|
class Kodama {
|
|
6259
9228
|
roomCode;
|
|
6260
9229
|
relayUrl;
|
|
@@ -6298,7 +9267,7 @@ class Kodama {
|
|
|
6298
9267
|
}
|
|
6299
9268
|
leave() {
|
|
6300
9269
|
this.closed = true;
|
|
6301
|
-
if (this.ws && this.ws.readyState ===
|
|
9270
|
+
if (this.ws && this.ws.readyState === WS.OPEN) {
|
|
6302
9271
|
this.ws.send(JSON.stringify({ action: "leave" }));
|
|
6303
9272
|
this.ws.close();
|
|
6304
9273
|
}
|
|
@@ -6314,7 +9283,7 @@ class Kodama {
|
|
|
6314
9283
|
return this.roomState;
|
|
6315
9284
|
}
|
|
6316
9285
|
connect() {
|
|
6317
|
-
const ws = new
|
|
9286
|
+
const ws = new WS(this.relayUrl);
|
|
6318
9287
|
this.ws = ws;
|
|
6319
9288
|
ws.addEventListener("open", () => {
|
|
6320
9289
|
this.reconnectAttempts = 0;
|
|
@@ -6442,7 +9411,7 @@ class Kodama {
|
|
|
6442
9411
|
const content = typeof response === "string" ? response : response.content;
|
|
6443
9412
|
const done = typeof response === "string" ? undefined : response.done;
|
|
6444
9413
|
const filtered = this.permissions.filterMessage(content);
|
|
6445
|
-
if (this.ws && this.ws.readyState ===
|
|
9414
|
+
if (this.ws && this.ws.readyState === WS.OPEN) {
|
|
6446
9415
|
this.ws.send(JSON.stringify({
|
|
6447
9416
|
action: "message",
|
|
6448
9417
|
content: filtered,
|
|
@@ -6477,6 +9446,7 @@ class Kodama {
|
|
|
6477
9446
|
}, delay);
|
|
6478
9447
|
}
|
|
6479
9448
|
}
|
|
9449
|
+
|
|
6480
9450
|
// src/adapters/cli.ts
|
|
6481
9451
|
import * as readline from "readline";
|
|
6482
9452
|
function readLine(prompt) {
|