@inkeep/agents-work-apps 0.50.1 → 0.50.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/dist/_virtual/rolldown_runtime.js +32 -0
  2. package/dist/env.d.ts +4 -2
  3. package/dist/env.js +2 -1
  4. package/dist/github/mcp/index.d.ts +2 -2
  5. package/dist/github/routes/setup.d.ts +2 -2
  6. package/dist/github/routes/tokenExchange.d.ts +2 -2
  7. package/dist/github/routes/webhooks.d.ts +2 -2
  8. package/dist/node_modules/.pnpm/@slack_logger@4.0.0/node_modules/@slack/logger/dist/index.js +89 -0
  9. package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/package.js +85 -0
  10. package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/SlackWebSocket.js +223 -0
  11. package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/SocketModeClient.js +367 -0
  12. package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/UnrecoverableSocketModeStartError.js +20 -0
  13. package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/errors.js +71 -0
  14. package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/index.js +44 -0
  15. package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/logger.js +32 -0
  16. package/dist/node_modules/.pnpm/eventemitter3@5.0.1/node_modules/eventemitter3/index.js +241 -0
  17. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/index.js +23 -0
  18. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/buffer-util.js +107 -0
  19. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/constants.js +29 -0
  20. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/event-target.js +226 -0
  21. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/extension.js +150 -0
  22. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/limiter.js +57 -0
  23. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/permessage-deflate.js +342 -0
  24. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/receiver.js +457 -0
  25. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/sender.js +505 -0
  26. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/stream.js +123 -0
  27. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/subprotocol.js +46 -0
  28. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/validation.js +203 -0
  29. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/websocket-server.js +385 -0
  30. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/websocket.js +985 -0
  31. package/dist/slack/dispatcher.d.ts +16 -0
  32. package/dist/slack/dispatcher.js +335 -0
  33. package/dist/slack/i18n/strings.d.ts +5 -5
  34. package/dist/slack/i18n/strings.js +9 -9
  35. package/dist/slack/index.d.ts +3 -1
  36. package/dist/slack/index.js +4 -2
  37. package/dist/slack/middleware/permissions.js +120 -107
  38. package/dist/slack/routes/events.js +10 -328
  39. package/dist/slack/routes/oauth.js +6 -3
  40. package/dist/slack/routes/users.js +12 -6
  41. package/dist/slack/routes/workspaces.js +39 -39
  42. package/dist/slack/services/agent-resolution.d.ts +1 -0
  43. package/dist/slack/services/agent-resolution.js +8 -4
  44. package/dist/slack/services/blocks/index.js +7 -11
  45. package/dist/slack/services/commands/index.js +15 -7
  46. package/dist/slack/services/dev-config.d.ts +23 -0
  47. package/dist/slack/services/dev-config.js +91 -0
  48. package/dist/slack/services/events/app-mention.js +25 -21
  49. package/dist/slack/services/events/index.d.ts +2 -2
  50. package/dist/slack/services/events/index.js +2 -2
  51. package/dist/slack/services/events/modal-submission.js +18 -10
  52. package/dist/slack/services/events/streaming.js +7 -5
  53. package/dist/slack/services/events/utils.d.ts +2 -1
  54. package/dist/slack/services/events/utils.js +16 -9
  55. package/dist/slack/services/index.d.ts +2 -2
  56. package/dist/slack/services/index.js +3 -3
  57. package/dist/slack/services/modals.js +4 -4
  58. package/dist/slack/services/nango.d.ts +3 -0
  59. package/dist/slack/services/nango.js +84 -2
  60. package/dist/slack/socket-mode.d.ts +4 -0
  61. package/dist/slack/socket-mode.js +130 -0
  62. package/dist/slack/tracer.d.ts +2 -0
  63. package/dist/slack/tracer.js +3 -1
  64. package/package.json +3 -2
@@ -0,0 +1,505 @@
1
+ import { __commonJSMin, __require } from "../../../../../../_virtual/rolldown_runtime.js";
2
+ import { require_constants } from "./constants.js";
3
+ import { require_buffer_util } from "./buffer-util.js";
4
+ import { require_permessage_deflate } from "./permessage-deflate.js";
5
+ import { require_validation } from "./validation.js";
6
+
7
+ //#region ../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/sender.js
8
+ var require_sender = /* @__PURE__ */ __commonJSMin(((exports, module) => {
9
+ const { Duplex } = __require("stream");
10
+ const { randomFillSync } = __require("crypto");
11
+ const PerMessageDeflate = require_permessage_deflate();
12
+ const { EMPTY_BUFFER, kWebSocket, NOOP } = require_constants();
13
+ const { isBlob, isValidStatusCode } = require_validation();
14
+ const { mask: applyMask, toBuffer } = require_buffer_util();
15
+ const kByteLength = Symbol("kByteLength");
16
+ const maskBuffer = Buffer.alloc(4);
17
+ const RANDOM_POOL_SIZE = 8 * 1024;
18
+ let randomPool;
19
+ let randomPoolPointer = RANDOM_POOL_SIZE;
20
+ const DEFAULT = 0;
21
+ const DEFLATING = 1;
22
+ const GET_BLOB_DATA = 2;
23
+ /**
24
+ * HyBi Sender implementation.
25
+ */
26
+ var Sender = class Sender {
27
+ /**
28
+ * Creates a Sender instance.
29
+ *
30
+ * @param {Duplex} socket The connection socket
31
+ * @param {Object} [extensions] An object containing the negotiated extensions
32
+ * @param {Function} [generateMask] The function used to generate the masking
33
+ * key
34
+ */
35
+ constructor(socket, extensions, generateMask) {
36
+ this._extensions = extensions || {};
37
+ if (generateMask) {
38
+ this._generateMask = generateMask;
39
+ this._maskBuffer = Buffer.alloc(4);
40
+ }
41
+ this._socket = socket;
42
+ this._firstFragment = true;
43
+ this._compress = false;
44
+ this._bufferedBytes = 0;
45
+ this._queue = [];
46
+ this._state = DEFAULT;
47
+ this.onerror = NOOP;
48
+ this[kWebSocket] = void 0;
49
+ }
50
+ /**
51
+ * Frames a piece of data according to the HyBi WebSocket protocol.
52
+ *
53
+ * @param {(Buffer|String)} data The data to frame
54
+ * @param {Object} options Options object
55
+ * @param {Boolean} [options.fin=false] Specifies whether or not to set the
56
+ * FIN bit
57
+ * @param {Function} [options.generateMask] The function used to generate the
58
+ * masking key
59
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
60
+ * `data`
61
+ * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
62
+ * key
63
+ * @param {Number} options.opcode The opcode
64
+ * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
65
+ * modified
66
+ * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
67
+ * RSV1 bit
68
+ * @return {(Buffer|String)[]} The framed data
69
+ * @public
70
+ */
71
+ static frame(data, options) {
72
+ let mask;
73
+ let merge = false;
74
+ let offset = 2;
75
+ let skipMasking = false;
76
+ if (options.mask) {
77
+ mask = options.maskBuffer || maskBuffer;
78
+ if (options.generateMask) options.generateMask(mask);
79
+ else {
80
+ if (randomPoolPointer === RANDOM_POOL_SIZE) {
81
+ /* istanbul ignore else */
82
+ if (randomPool === void 0) randomPool = Buffer.alloc(RANDOM_POOL_SIZE);
83
+ randomFillSync(randomPool, 0, RANDOM_POOL_SIZE);
84
+ randomPoolPointer = 0;
85
+ }
86
+ mask[0] = randomPool[randomPoolPointer++];
87
+ mask[1] = randomPool[randomPoolPointer++];
88
+ mask[2] = randomPool[randomPoolPointer++];
89
+ mask[3] = randomPool[randomPoolPointer++];
90
+ }
91
+ skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) === 0;
92
+ offset = 6;
93
+ }
94
+ let dataLength;
95
+ if (typeof data === "string") if ((!options.mask || skipMasking) && options[kByteLength] !== void 0) dataLength = options[kByteLength];
96
+ else {
97
+ data = Buffer.from(data);
98
+ dataLength = data.length;
99
+ }
100
+ else {
101
+ dataLength = data.length;
102
+ merge = options.mask && options.readOnly && !skipMasking;
103
+ }
104
+ let payloadLength = dataLength;
105
+ if (dataLength >= 65536) {
106
+ offset += 8;
107
+ payloadLength = 127;
108
+ } else if (dataLength > 125) {
109
+ offset += 2;
110
+ payloadLength = 126;
111
+ }
112
+ const target = Buffer.allocUnsafe(merge ? dataLength + offset : offset);
113
+ target[0] = options.fin ? options.opcode | 128 : options.opcode;
114
+ if (options.rsv1) target[0] |= 64;
115
+ target[1] = payloadLength;
116
+ if (payloadLength === 126) target.writeUInt16BE(dataLength, 2);
117
+ else if (payloadLength === 127) {
118
+ target[2] = target[3] = 0;
119
+ target.writeUIntBE(dataLength, 4, 6);
120
+ }
121
+ if (!options.mask) return [target, data];
122
+ target[1] |= 128;
123
+ target[offset - 4] = mask[0];
124
+ target[offset - 3] = mask[1];
125
+ target[offset - 2] = mask[2];
126
+ target[offset - 1] = mask[3];
127
+ if (skipMasking) return [target, data];
128
+ if (merge) {
129
+ applyMask(data, mask, target, offset, dataLength);
130
+ return [target];
131
+ }
132
+ applyMask(data, mask, data, 0, dataLength);
133
+ return [target, data];
134
+ }
135
+ /**
136
+ * Sends a close message to the other peer.
137
+ *
138
+ * @param {Number} [code] The status code component of the body
139
+ * @param {(String|Buffer)} [data] The message component of the body
140
+ * @param {Boolean} [mask=false] Specifies whether or not to mask the message
141
+ * @param {Function} [cb] Callback
142
+ * @public
143
+ */
144
+ close(code, data, mask, cb) {
145
+ let buf;
146
+ if (code === void 0) buf = EMPTY_BUFFER;
147
+ else if (typeof code !== "number" || !isValidStatusCode(code)) throw new TypeError("First argument must be a valid error code number");
148
+ else if (data === void 0 || !data.length) {
149
+ buf = Buffer.allocUnsafe(2);
150
+ buf.writeUInt16BE(code, 0);
151
+ } else {
152
+ const length = Buffer.byteLength(data);
153
+ if (length > 123) throw new RangeError("The message must not be greater than 123 bytes");
154
+ buf = Buffer.allocUnsafe(2 + length);
155
+ buf.writeUInt16BE(code, 0);
156
+ if (typeof data === "string") buf.write(data, 2);
157
+ else buf.set(data, 2);
158
+ }
159
+ const options = {
160
+ [kByteLength]: buf.length,
161
+ fin: true,
162
+ generateMask: this._generateMask,
163
+ mask,
164
+ maskBuffer: this._maskBuffer,
165
+ opcode: 8,
166
+ readOnly: false,
167
+ rsv1: false
168
+ };
169
+ if (this._state !== DEFAULT) this.enqueue([
170
+ this.dispatch,
171
+ buf,
172
+ false,
173
+ options,
174
+ cb
175
+ ]);
176
+ else this.sendFrame(Sender.frame(buf, options), cb);
177
+ }
178
+ /**
179
+ * Sends a ping message to the other peer.
180
+ *
181
+ * @param {*} data The message to send
182
+ * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
183
+ * @param {Function} [cb] Callback
184
+ * @public
185
+ */
186
+ ping(data, mask, cb) {
187
+ let byteLength;
188
+ let readOnly;
189
+ if (typeof data === "string") {
190
+ byteLength = Buffer.byteLength(data);
191
+ readOnly = false;
192
+ } else if (isBlob(data)) {
193
+ byteLength = data.size;
194
+ readOnly = false;
195
+ } else {
196
+ data = toBuffer(data);
197
+ byteLength = data.length;
198
+ readOnly = toBuffer.readOnly;
199
+ }
200
+ if (byteLength > 125) throw new RangeError("The data size must not be greater than 125 bytes");
201
+ const options = {
202
+ [kByteLength]: byteLength,
203
+ fin: true,
204
+ generateMask: this._generateMask,
205
+ mask,
206
+ maskBuffer: this._maskBuffer,
207
+ opcode: 9,
208
+ readOnly,
209
+ rsv1: false
210
+ };
211
+ if (isBlob(data)) if (this._state !== DEFAULT) this.enqueue([
212
+ this.getBlobData,
213
+ data,
214
+ false,
215
+ options,
216
+ cb
217
+ ]);
218
+ else this.getBlobData(data, false, options, cb);
219
+ else if (this._state !== DEFAULT) this.enqueue([
220
+ this.dispatch,
221
+ data,
222
+ false,
223
+ options,
224
+ cb
225
+ ]);
226
+ else this.sendFrame(Sender.frame(data, options), cb);
227
+ }
228
+ /**
229
+ * Sends a pong message to the other peer.
230
+ *
231
+ * @param {*} data The message to send
232
+ * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
233
+ * @param {Function} [cb] Callback
234
+ * @public
235
+ */
236
+ pong(data, mask, cb) {
237
+ let byteLength;
238
+ let readOnly;
239
+ if (typeof data === "string") {
240
+ byteLength = Buffer.byteLength(data);
241
+ readOnly = false;
242
+ } else if (isBlob(data)) {
243
+ byteLength = data.size;
244
+ readOnly = false;
245
+ } else {
246
+ data = toBuffer(data);
247
+ byteLength = data.length;
248
+ readOnly = toBuffer.readOnly;
249
+ }
250
+ if (byteLength > 125) throw new RangeError("The data size must not be greater than 125 bytes");
251
+ const options = {
252
+ [kByteLength]: byteLength,
253
+ fin: true,
254
+ generateMask: this._generateMask,
255
+ mask,
256
+ maskBuffer: this._maskBuffer,
257
+ opcode: 10,
258
+ readOnly,
259
+ rsv1: false
260
+ };
261
+ if (isBlob(data)) if (this._state !== DEFAULT) this.enqueue([
262
+ this.getBlobData,
263
+ data,
264
+ false,
265
+ options,
266
+ cb
267
+ ]);
268
+ else this.getBlobData(data, false, options, cb);
269
+ else if (this._state !== DEFAULT) this.enqueue([
270
+ this.dispatch,
271
+ data,
272
+ false,
273
+ options,
274
+ cb
275
+ ]);
276
+ else this.sendFrame(Sender.frame(data, options), cb);
277
+ }
278
+ /**
279
+ * Sends a data message to the other peer.
280
+ *
281
+ * @param {*} data The message to send
282
+ * @param {Object} options Options object
283
+ * @param {Boolean} [options.binary=false] Specifies whether `data` is binary
284
+ * or text
285
+ * @param {Boolean} [options.compress=false] Specifies whether or not to
286
+ * compress `data`
287
+ * @param {Boolean} [options.fin=false] Specifies whether the fragment is the
288
+ * last one
289
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
290
+ * `data`
291
+ * @param {Function} [cb] Callback
292
+ * @public
293
+ */
294
+ send(data, options, cb) {
295
+ const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
296
+ let opcode = options.binary ? 2 : 1;
297
+ let rsv1 = options.compress;
298
+ let byteLength;
299
+ let readOnly;
300
+ if (typeof data === "string") {
301
+ byteLength = Buffer.byteLength(data);
302
+ readOnly = false;
303
+ } else if (isBlob(data)) {
304
+ byteLength = data.size;
305
+ readOnly = false;
306
+ } else {
307
+ data = toBuffer(data);
308
+ byteLength = data.length;
309
+ readOnly = toBuffer.readOnly;
310
+ }
311
+ if (this._firstFragment) {
312
+ this._firstFragment = false;
313
+ if (rsv1 && perMessageDeflate && perMessageDeflate.params[perMessageDeflate._isServer ? "server_no_context_takeover" : "client_no_context_takeover"]) rsv1 = byteLength >= perMessageDeflate._threshold;
314
+ this._compress = rsv1;
315
+ } else {
316
+ rsv1 = false;
317
+ opcode = 0;
318
+ }
319
+ if (options.fin) this._firstFragment = true;
320
+ const opts = {
321
+ [kByteLength]: byteLength,
322
+ fin: options.fin,
323
+ generateMask: this._generateMask,
324
+ mask: options.mask,
325
+ maskBuffer: this._maskBuffer,
326
+ opcode,
327
+ readOnly,
328
+ rsv1
329
+ };
330
+ if (isBlob(data)) if (this._state !== DEFAULT) this.enqueue([
331
+ this.getBlobData,
332
+ data,
333
+ this._compress,
334
+ opts,
335
+ cb
336
+ ]);
337
+ else this.getBlobData(data, this._compress, opts, cb);
338
+ else if (this._state !== DEFAULT) this.enqueue([
339
+ this.dispatch,
340
+ data,
341
+ this._compress,
342
+ opts,
343
+ cb
344
+ ]);
345
+ else this.dispatch(data, this._compress, opts, cb);
346
+ }
347
+ /**
348
+ * Gets the contents of a blob as binary data.
349
+ *
350
+ * @param {Blob} blob The blob
351
+ * @param {Boolean} [compress=false] Specifies whether or not to compress
352
+ * the data
353
+ * @param {Object} options Options object
354
+ * @param {Boolean} [options.fin=false] Specifies whether or not to set the
355
+ * FIN bit
356
+ * @param {Function} [options.generateMask] The function used to generate the
357
+ * masking key
358
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
359
+ * `data`
360
+ * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
361
+ * key
362
+ * @param {Number} options.opcode The opcode
363
+ * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
364
+ * modified
365
+ * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
366
+ * RSV1 bit
367
+ * @param {Function} [cb] Callback
368
+ * @private
369
+ */
370
+ getBlobData(blob, compress, options, cb) {
371
+ this._bufferedBytes += options[kByteLength];
372
+ this._state = GET_BLOB_DATA;
373
+ blob.arrayBuffer().then((arrayBuffer) => {
374
+ if (this._socket.destroyed) {
375
+ const err = /* @__PURE__ */ new Error("The socket was closed while the blob was being read");
376
+ process.nextTick(callCallbacks, this, err, cb);
377
+ return;
378
+ }
379
+ this._bufferedBytes -= options[kByteLength];
380
+ const data = toBuffer(arrayBuffer);
381
+ if (!compress) {
382
+ this._state = DEFAULT;
383
+ this.sendFrame(Sender.frame(data, options), cb);
384
+ this.dequeue();
385
+ } else this.dispatch(data, compress, options, cb);
386
+ }).catch((err) => {
387
+ process.nextTick(onError, this, err, cb);
388
+ });
389
+ }
390
+ /**
391
+ * Dispatches a message.
392
+ *
393
+ * @param {(Buffer|String)} data The message to send
394
+ * @param {Boolean} [compress=false] Specifies whether or not to compress
395
+ * `data`
396
+ * @param {Object} options Options object
397
+ * @param {Boolean} [options.fin=false] Specifies whether or not to set the
398
+ * FIN bit
399
+ * @param {Function} [options.generateMask] The function used to generate the
400
+ * masking key
401
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
402
+ * `data`
403
+ * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
404
+ * key
405
+ * @param {Number} options.opcode The opcode
406
+ * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
407
+ * modified
408
+ * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
409
+ * RSV1 bit
410
+ * @param {Function} [cb] Callback
411
+ * @private
412
+ */
413
+ dispatch(data, compress, options, cb) {
414
+ if (!compress) {
415
+ this.sendFrame(Sender.frame(data, options), cb);
416
+ return;
417
+ }
418
+ const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
419
+ this._bufferedBytes += options[kByteLength];
420
+ this._state = DEFLATING;
421
+ perMessageDeflate.compress(data, options.fin, (_, buf) => {
422
+ if (this._socket.destroyed) {
423
+ callCallbacks(this, /* @__PURE__ */ new Error("The socket was closed while data was being compressed"), cb);
424
+ return;
425
+ }
426
+ this._bufferedBytes -= options[kByteLength];
427
+ this._state = DEFAULT;
428
+ options.readOnly = false;
429
+ this.sendFrame(Sender.frame(buf, options), cb);
430
+ this.dequeue();
431
+ });
432
+ }
433
+ /**
434
+ * Executes queued send operations.
435
+ *
436
+ * @private
437
+ */
438
+ dequeue() {
439
+ while (this._state === DEFAULT && this._queue.length) {
440
+ const params = this._queue.shift();
441
+ this._bufferedBytes -= params[3][kByteLength];
442
+ Reflect.apply(params[0], this, params.slice(1));
443
+ }
444
+ }
445
+ /**
446
+ * Enqueues a send operation.
447
+ *
448
+ * @param {Array} params Send operation parameters.
449
+ * @private
450
+ */
451
+ enqueue(params) {
452
+ this._bufferedBytes += params[3][kByteLength];
453
+ this._queue.push(params);
454
+ }
455
+ /**
456
+ * Sends a frame.
457
+ *
458
+ * @param {(Buffer | String)[]} list The frame to send
459
+ * @param {Function} [cb] Callback
460
+ * @private
461
+ */
462
+ sendFrame(list, cb) {
463
+ if (list.length === 2) {
464
+ this._socket.cork();
465
+ this._socket.write(list[0]);
466
+ this._socket.write(list[1], cb);
467
+ this._socket.uncork();
468
+ } else this._socket.write(list[0], cb);
469
+ }
470
+ };
471
+ module.exports = Sender;
472
+ /**
473
+ * Calls queued callbacks with an error.
474
+ *
475
+ * @param {Sender} sender The `Sender` instance
476
+ * @param {Error} err The error to call the callbacks with
477
+ * @param {Function} [cb] The first callback
478
+ * @private
479
+ */
480
+ function callCallbacks(sender, err, cb) {
481
+ if (typeof cb === "function") cb(err);
482
+ for (let i = 0; i < sender._queue.length; i++) {
483
+ const params = sender._queue[i];
484
+ const callback = params[params.length - 1];
485
+ if (typeof callback === "function") callback(err);
486
+ }
487
+ }
488
+ /**
489
+ * Handles a `Sender` error.
490
+ *
491
+ * @param {Sender} sender The `Sender` instance
492
+ * @param {Error} err The error
493
+ * @param {Function} [cb] The first pending callback
494
+ * @private
495
+ */
496
+ function onError(sender, err, cb) {
497
+ callCallbacks(sender, err, cb);
498
+ sender.onerror(err);
499
+ }
500
+ }));
501
+
502
+ //#endregion
503
+ export default require_sender();
504
+
505
+ export { require_sender };
@@ -0,0 +1,123 @@
1
+ import { __commonJSMin, __require } from "../../../../../../_virtual/rolldown_runtime.js";
2
+ import { require_websocket } from "./websocket.js";
3
+
4
+ //#region ../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/stream.js
5
+ var require_stream = /* @__PURE__ */ __commonJSMin(((exports, module) => {
6
+ require_websocket();
7
+ const { Duplex } = __require("stream");
8
+ /**
9
+ * Emits the `'close'` event on a stream.
10
+ *
11
+ * @param {Duplex} stream The stream.
12
+ * @private
13
+ */
14
+ function emitClose(stream) {
15
+ stream.emit("close");
16
+ }
17
+ /**
18
+ * The listener of the `'end'` event.
19
+ *
20
+ * @private
21
+ */
22
+ function duplexOnEnd() {
23
+ if (!this.destroyed && this._writableState.finished) this.destroy();
24
+ }
25
+ /**
26
+ * The listener of the `'error'` event.
27
+ *
28
+ * @param {Error} err The error
29
+ * @private
30
+ */
31
+ function duplexOnError(err) {
32
+ this.removeListener("error", duplexOnError);
33
+ this.destroy();
34
+ if (this.listenerCount("error") === 0) this.emit("error", err);
35
+ }
36
+ /**
37
+ * Wraps a `WebSocket` in a duplex stream.
38
+ *
39
+ * @param {WebSocket} ws The `WebSocket` to wrap
40
+ * @param {Object} [options] The options for the `Duplex` constructor
41
+ * @return {Duplex} The duplex stream
42
+ * @public
43
+ */
44
+ function createWebSocketStream(ws, options) {
45
+ let terminateOnDestroy = true;
46
+ const duplex = new Duplex({
47
+ ...options,
48
+ autoDestroy: false,
49
+ emitClose: false,
50
+ objectMode: false,
51
+ writableObjectMode: false
52
+ });
53
+ ws.on("message", function message(msg, isBinary) {
54
+ const data = !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
55
+ if (!duplex.push(data)) ws.pause();
56
+ });
57
+ ws.once("error", function error(err) {
58
+ if (duplex.destroyed) return;
59
+ terminateOnDestroy = false;
60
+ duplex.destroy(err);
61
+ });
62
+ ws.once("close", function close() {
63
+ if (duplex.destroyed) return;
64
+ duplex.push(null);
65
+ });
66
+ duplex._destroy = function(err, callback) {
67
+ if (ws.readyState === ws.CLOSED) {
68
+ callback(err);
69
+ process.nextTick(emitClose, duplex);
70
+ return;
71
+ }
72
+ let called = false;
73
+ ws.once("error", function error(err$1) {
74
+ called = true;
75
+ callback(err$1);
76
+ });
77
+ ws.once("close", function close() {
78
+ if (!called) callback(err);
79
+ process.nextTick(emitClose, duplex);
80
+ });
81
+ if (terminateOnDestroy) ws.terminate();
82
+ };
83
+ duplex._final = function(callback) {
84
+ if (ws.readyState === ws.CONNECTING) {
85
+ ws.once("open", function open() {
86
+ duplex._final(callback);
87
+ });
88
+ return;
89
+ }
90
+ if (ws._socket === null) return;
91
+ if (ws._socket._writableState.finished) {
92
+ callback();
93
+ if (duplex._readableState.endEmitted) duplex.destroy();
94
+ } else {
95
+ ws._socket.once("finish", function finish() {
96
+ callback();
97
+ });
98
+ ws.close();
99
+ }
100
+ };
101
+ duplex._read = function() {
102
+ if (ws.isPaused) ws.resume();
103
+ };
104
+ duplex._write = function(chunk, encoding, callback) {
105
+ if (ws.readyState === ws.CONNECTING) {
106
+ ws.once("open", function open() {
107
+ duplex._write(chunk, encoding, callback);
108
+ });
109
+ return;
110
+ }
111
+ ws.send(chunk, callback);
112
+ };
113
+ duplex.on("end", duplexOnEnd);
114
+ duplex.on("error", duplexOnError);
115
+ return duplex;
116
+ }
117
+ module.exports = createWebSocketStream;
118
+ }));
119
+
120
+ //#endregion
121
+ export default require_stream();
122
+
123
+ export { require_stream };
@@ -0,0 +1,46 @@
1
+ import { __commonJSMin } from "../../../../../../_virtual/rolldown_runtime.js";
2
+ import { require_validation } from "./validation.js";
3
+
4
+ //#region ../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/subprotocol.js
5
+ var require_subprotocol = /* @__PURE__ */ __commonJSMin(((exports, module) => {
6
+ const { tokenChars } = require_validation();
7
+ /**
8
+ * Parses the `Sec-WebSocket-Protocol` header into a set of subprotocol names.
9
+ *
10
+ * @param {String} header The field value of the header
11
+ * @return {Set} The subprotocol names
12
+ * @public
13
+ */
14
+ function parse(header) {
15
+ const protocols = /* @__PURE__ */ new Set();
16
+ let start = -1;
17
+ let end = -1;
18
+ let i = 0;
19
+ for (; i < header.length; i++) {
20
+ const code = header.charCodeAt(i);
21
+ if (end === -1 && tokenChars[code] === 1) {
22
+ if (start === -1) start = i;
23
+ } else if (i !== 0 && (code === 32 || code === 9)) {
24
+ if (end === -1 && start !== -1) end = i;
25
+ } else if (code === 44) {
26
+ if (start === -1) throw new SyntaxError(`Unexpected character at index ${i}`);
27
+ if (end === -1) end = i;
28
+ const protocol$1 = header.slice(start, end);
29
+ if (protocols.has(protocol$1)) throw new SyntaxError(`The "${protocol$1}" subprotocol is duplicated`);
30
+ protocols.add(protocol$1);
31
+ start = end = -1;
32
+ } else throw new SyntaxError(`Unexpected character at index ${i}`);
33
+ }
34
+ if (start === -1 || end !== -1) throw new SyntaxError("Unexpected end of input");
35
+ const protocol = header.slice(start, i);
36
+ if (protocols.has(protocol)) throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
37
+ protocols.add(protocol);
38
+ return protocols;
39
+ }
40
+ module.exports = { parse };
41
+ }));
42
+
43
+ //#endregion
44
+ export default require_subprotocol();
45
+
46
+ export { require_subprotocol };