@phpsandbox/sdk 0.0.51 → 0.0.52
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/LICENSE +21 -0
- package/README.md +1 -1
- package/dist/auth.d.ts +0 -1
- package/dist/auth.js +0 -1
- package/dist/beacon/index.d.ts +4 -5
- package/dist/beacon/index.js +11 -12
- package/dist/beacon/navigator.d.ts +1 -2
- package/dist/beacon/navigator.js +0 -1
- package/dist/beacon/types.d.ts +12 -13
- package/dist/beacon/types.js +0 -1
- package/dist/browser/phpsandbox-sdk.esm.js +282 -479
- package/dist/browser/phpsandbox-sdk.esm.min.js +2 -3
- package/dist/browser/phpsandbox-sdk.iife.js +277 -479
- package/dist/browser/phpsandbox-sdk.iife.min.js +2 -3
- package/dist/composer.d.ts +2 -3
- package/dist/composer.js +0 -1
- package/dist/config.d.ts +0 -1
- package/dist/config.js +0 -1
- package/dist/container.d.ts +0 -1
- package/dist/container.js +0 -1
- package/dist/errors/index.d.ts +0 -1
- package/dist/errors/index.js +0 -1
- package/dist/events/index.d.ts +15 -15
- package/dist/events/index.js +16 -9
- package/dist/filesystem.d.ts +6 -7
- package/dist/filesystem.js +36 -14
- package/dist/git.d.ts +0 -1
- package/dist/git.js +0 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +38 -25
- package/dist/laravel.d.ts +1 -2
- package/dist/laravel.js +1 -2
- package/dist/log.d.ts +3 -4
- package/dist/log.js +1 -2
- package/dist/lsp.d.ts +10 -11
- package/dist/lsp.js +9 -10
- package/dist/repl.d.ts +3 -4
- package/dist/repl.js +2 -3
- package/dist/services.d.ts +0 -1
- package/dist/services.js +0 -1
- package/dist/shell.d.ts +1 -2
- package/dist/shell.js +1 -2
- package/dist/socket/index.d.ts +23 -129
- package/dist/socket/index.js +60 -350
- package/dist/terminal.d.ts +2 -3
- package/dist/terminal.js +45 -26
- package/dist/types.d.ts +0 -1
- package/dist/types.js +0 -1
- package/dist/utils/disposable.d.ts +0 -1
- package/dist/utils/disposable.js +0 -1
- package/dist/utils/promise.d.ts +0 -1
- package/dist/utils/promise.js +0 -1
- package/dist/utils/retry.d.ts +0 -1
- package/dist/utils/retry.js +0 -1
- package/dist/utils/websocket.d.ts +0 -1
- package/dist/utils/websocket.js +0 -1
- package/docs/api-summary.md +136 -0
- package/docs/cdn-usage.md +80 -0
- package/docs/getting-started.md +152 -0
- package/examples/README.md +206 -0
- package/examples/basic.ts +24 -0
- package/examples/get.ts +21 -0
- package/examples/git-merge-smoke.ts +415 -0
- package/examples/laravel-load-test.ts +2829 -0
- package/examples/notebook-readonly-smoke.ts +823 -0
- package/package.json +13 -7
- package/dist/auth.d.ts.map +0 -1
- package/dist/auth.js.map +0 -1
- package/dist/beacon/index.d.ts.map +0 -1
- package/dist/beacon/index.js.map +0 -1
- package/dist/beacon/navigator.d.ts.map +0 -1
- package/dist/beacon/navigator.js.map +0 -1
- package/dist/beacon/types.d.ts.map +0 -1
- package/dist/beacon/types.js.map +0 -1
- package/dist/browser/phpsandbox-sdk.esm.js.map +0 -7
- package/dist/browser/phpsandbox-sdk.esm.min.js.map +0 -7
- package/dist/browser/phpsandbox-sdk.iife.js.map +0 -7
- package/dist/browser/phpsandbox-sdk.iife.min.js.map +0 -7
- package/dist/composer.d.ts.map +0 -1
- package/dist/composer.js.map +0 -1
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/container.d.ts.map +0 -1
- package/dist/container.js.map +0 -1
- package/dist/errors/index.d.ts.map +0 -1
- package/dist/errors/index.js.map +0 -1
- package/dist/events/index.d.ts.map +0 -1
- package/dist/events/index.js.map +0 -1
- package/dist/filesystem.d.ts.map +0 -1
- package/dist/filesystem.js.map +0 -1
- package/dist/git.d.ts.map +0 -1
- package/dist/git.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/laravel.d.ts.map +0 -1
- package/dist/laravel.js.map +0 -1
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js.map +0 -1
- package/dist/lsp.d.ts.map +0 -1
- package/dist/lsp.js.map +0 -1
- package/dist/repl.d.ts.map +0 -1
- package/dist/repl.js.map +0 -1
- package/dist/services.d.ts.map +0 -1
- package/dist/services.js.map +0 -1
- package/dist/shell.d.ts.map +0 -1
- package/dist/shell.js.map +0 -1
- package/dist/socket/index.d.ts.map +0 -1
- package/dist/socket/index.js.map +0 -1
- package/dist/terminal.d.ts.map +0 -1
- package/dist/terminal.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils/disposable.d.ts.map +0 -1
- package/dist/utils/disposable.js.map +0 -1
- package/dist/utils/promise.d.ts.map +0 -1
- package/dist/utils/promise.js.map +0 -1
- package/dist/utils/retry.d.ts.map +0 -1
- package/dist/utils/retry.js.map +0 -1
- package/dist/utils/websocket.d.ts.map +0 -1
- package/dist/utils/websocket.js.map +0 -1
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
1
2
|
var __typeError = (msg) => {
|
|
2
3
|
throw TypeError(msg);
|
|
3
4
|
};
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
4
9
|
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
10
|
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
11
|
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
@@ -45,6 +50,12 @@ var FileType = /* @__PURE__ */ ((FileType2) => {
|
|
|
45
50
|
FileType2[FileType2["SymbolicLink"] = 64] = "SymbolicLink";
|
|
46
51
|
return FileType2;
|
|
47
52
|
})(FileType || {});
|
|
53
|
+
var FileChangeFilter = /* @__PURE__ */ ((FileChangeFilter2) => {
|
|
54
|
+
FileChangeFilter2[FileChangeFilter2["UPDATED"] = 2] = "UPDATED";
|
|
55
|
+
FileChangeFilter2[FileChangeFilter2["ADDED"] = 4] = "ADDED";
|
|
56
|
+
FileChangeFilter2[FileChangeFilter2["DELETED"] = 8] = "DELETED";
|
|
57
|
+
return FileChangeFilter2;
|
|
58
|
+
})(FileChangeFilter || {});
|
|
48
59
|
var FileChangeType = /* @__PURE__ */ ((FileChangeType2) => {
|
|
49
60
|
FileChangeType2[FileChangeType2["UPDATED"] = 1] = "UPDATED";
|
|
50
61
|
FileChangeType2[FileChangeType2["ADDED"] = 2] = "ADDED";
|
|
@@ -67,14 +78,18 @@ var FilesystemError = class extends ErrorEvent {
|
|
|
67
78
|
}
|
|
68
79
|
};
|
|
69
80
|
var FilesystemSubscription = class {
|
|
70
|
-
constructor(
|
|
71
|
-
this.path = path;
|
|
72
|
-
this.okra = okra;
|
|
81
|
+
constructor(disposable, onDispose) {
|
|
73
82
|
this.disposable = disposable;
|
|
83
|
+
this.onDispose = onDispose;
|
|
84
|
+
this.disposed = false;
|
|
74
85
|
}
|
|
75
86
|
dispose() {
|
|
76
|
-
this.
|
|
87
|
+
if (this.disposed) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
this.disposed = true;
|
|
77
91
|
this.disposable.dispose();
|
|
92
|
+
this.onDispose();
|
|
78
93
|
}
|
|
79
94
|
};
|
|
80
95
|
var Filesystem = class {
|
|
@@ -85,8 +100,9 @@ var Filesystem = class {
|
|
|
85
100
|
}
|
|
86
101
|
watchOkraConnection() {
|
|
87
102
|
this.okra.onDidConnect(() => {
|
|
88
|
-
for (const { path, options
|
|
89
|
-
this.watch
|
|
103
|
+
for (const { path, options } of this.watches.values()) {
|
|
104
|
+
void this.okra.invoke("fs.watch", { path, options }).catch(() => {
|
|
105
|
+
});
|
|
90
106
|
}
|
|
91
107
|
});
|
|
92
108
|
}
|
|
@@ -104,7 +120,7 @@ var Filesystem = class {
|
|
|
104
120
|
}) {
|
|
105
121
|
return this.okra.invoke("fs.find", {
|
|
106
122
|
query,
|
|
107
|
-
options:
|
|
123
|
+
options: {
|
|
108
124
|
includes: [],
|
|
109
125
|
excludes: [
|
|
110
126
|
"**/storage",
|
|
@@ -121,8 +137,9 @@ var Filesystem = class {
|
|
|
121
137
|
useIgnoreFiles: false,
|
|
122
138
|
followSymlinks: false,
|
|
123
139
|
useGlobalIgnoreFiles: false,
|
|
124
|
-
useParentIgnoreFiles: false
|
|
125
|
-
|
|
140
|
+
useParentIgnoreFiles: false,
|
|
141
|
+
...options
|
|
142
|
+
}
|
|
126
143
|
});
|
|
127
144
|
}
|
|
128
145
|
search(query, options, onMatch) {
|
|
@@ -228,12 +245,21 @@ var Filesystem = class {
|
|
|
228
245
|
const wrappedDisposable = {
|
|
229
246
|
dispose: () => {
|
|
230
247
|
disposable.dispose();
|
|
231
|
-
this.okra.invoke("fs.unwatch", { path })
|
|
248
|
+
void this.okra.invoke("fs.unwatch", { path }).catch(() => {
|
|
249
|
+
});
|
|
232
250
|
}
|
|
233
251
|
};
|
|
234
|
-
const subscription = new FilesystemSubscription(
|
|
252
|
+
const subscription = new FilesystemSubscription(wrappedDisposable, () => {
|
|
253
|
+
const watch = this.watches.get(path);
|
|
254
|
+
if (watch?.onDidChange === onDidChange) {
|
|
255
|
+
this.watches.delete(path);
|
|
256
|
+
}
|
|
257
|
+
});
|
|
235
258
|
this.watches.set(path, { options, path, onDidChange });
|
|
236
|
-
return this.okra.invoke("fs.watch", { path, options }).then(() => subscription)
|
|
259
|
+
return this.okra.invoke("fs.watch", { path, options }).then(() => subscription).catch((error) => {
|
|
260
|
+
subscription.dispose();
|
|
261
|
+
throw error;
|
|
262
|
+
});
|
|
237
263
|
}
|
|
238
264
|
exists(path) {
|
|
239
265
|
return this.stat(path).then(() => true).catch(() => false);
|
|
@@ -242,13 +268,13 @@ var Filesystem = class {
|
|
|
242
268
|
const id = nanoid();
|
|
243
269
|
const stream = !!chunk;
|
|
244
270
|
const chunks = [];
|
|
245
|
-
this.okra.listen(
|
|
271
|
+
const disposable = this.okra.listen(
|
|
246
272
|
`fs.download.${id}`,
|
|
247
273
|
stream ? chunk : (data) => {
|
|
248
274
|
chunks.push(data);
|
|
249
275
|
}
|
|
250
276
|
);
|
|
251
|
-
return this.okra.invoke("fs.download", { id, exclude, include }).then(() => new Blob(chunks, { type: "application/octet-stream" }));
|
|
277
|
+
return this.okra.invoke("fs.download", { id, exclude, include }).then(() => new Blob(chunks, { type: "application/octet-stream" })).finally(() => disposable.dispose());
|
|
252
278
|
}
|
|
253
279
|
tree(path = "/") {
|
|
254
280
|
return this.okra.invoke("fs.tree", { path });
|
|
@@ -313,13 +339,13 @@ var Terminal = class {
|
|
|
313
339
|
return this.okra.invoke("terminal.create", input);
|
|
314
340
|
}
|
|
315
341
|
onStarted(handler) {
|
|
316
|
-
this.okra.listen("terminal.started", handler);
|
|
342
|
+
return this.okra.listen("terminal.started", handler);
|
|
317
343
|
}
|
|
318
344
|
resize(id, size) {
|
|
319
345
|
return this.okra.invoke("terminal.resize", { id, width: size[0], height: size[1] });
|
|
320
346
|
}
|
|
321
347
|
onOutput(id, handler) {
|
|
322
|
-
this.okra.listen(`terminal.output.${id}`, handler);
|
|
348
|
+
return this.okra.listen(`terminal.output.${id}`, handler);
|
|
323
349
|
}
|
|
324
350
|
input(id, input) {
|
|
325
351
|
return Promise.resolve(this.okra.send("terminal.input", { id, input }));
|
|
@@ -329,46 +355,61 @@ var Terminal = class {
|
|
|
329
355
|
}
|
|
330
356
|
async attach(id, opts) {
|
|
331
357
|
const handle = this.processHandle(id, opts?.abortSignal);
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
358
|
+
try {
|
|
359
|
+
const task = await this.okra.invoke(
|
|
360
|
+
"terminal.attach",
|
|
361
|
+
{
|
|
362
|
+
id,
|
|
363
|
+
replayHistory: opts?.replayHistory
|
|
364
|
+
},
|
|
365
|
+
{ abortSignal: opts?.abortSignal }
|
|
366
|
+
);
|
|
367
|
+
if (!task) {
|
|
368
|
+
handle.dispose();
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
return {
|
|
372
|
+
...handle.process,
|
|
373
|
+
...task
|
|
374
|
+
};
|
|
375
|
+
} catch (error) {
|
|
341
376
|
handle.dispose();
|
|
342
|
-
|
|
377
|
+
throw error;
|
|
343
378
|
}
|
|
344
|
-
return {
|
|
345
|
-
...handle.process,
|
|
346
|
-
...task
|
|
347
|
-
};
|
|
348
379
|
}
|
|
349
380
|
async spawn(command, args, opts) {
|
|
350
381
|
const id = opts?.id || nanoid();
|
|
351
382
|
const handle = this.processHandle(id, opts?.abortSignal);
|
|
352
383
|
const { abortSignal, ...otherOpts } = opts ?? {};
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
384
|
+
try {
|
|
385
|
+
const result = await this.okra.invoke(
|
|
386
|
+
"terminal.spawn",
|
|
387
|
+
{
|
|
388
|
+
command: [command, ...args],
|
|
389
|
+
opts: {
|
|
390
|
+
id,
|
|
391
|
+
...otherOpts
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
{ abortSignal }
|
|
395
|
+
);
|
|
396
|
+
return {
|
|
397
|
+
...handle.process,
|
|
398
|
+
...result
|
|
399
|
+
};
|
|
400
|
+
} catch (error) {
|
|
401
|
+
handle.dispose();
|
|
402
|
+
throw error;
|
|
403
|
+
}
|
|
368
404
|
}
|
|
369
405
|
processHandle(id, abortSignal) {
|
|
370
406
|
const disposables = /* @__PURE__ */ new Set();
|
|
407
|
+
let abortHandler;
|
|
371
408
|
const dispose = () => {
|
|
409
|
+
if (abortHandler) {
|
|
410
|
+
abortSignal?.removeEventListener("abort", abortHandler);
|
|
411
|
+
abortHandler = void 0;
|
|
412
|
+
}
|
|
372
413
|
for (const disposable of disposables) {
|
|
373
414
|
disposable.dispose();
|
|
374
415
|
}
|
|
@@ -447,8 +488,11 @@ var Terminal = class {
|
|
|
447
488
|
const resize = (dimensions) => {
|
|
448
489
|
this.okra.invoke("terminal.resize", { id, width: dimensions.cols, height: dimensions.rows });
|
|
449
490
|
};
|
|
450
|
-
if (abortSignal) {
|
|
451
|
-
|
|
491
|
+
if (abortSignal && !abortSignal.aborted) {
|
|
492
|
+
abortHandler = () => {
|
|
493
|
+
void kill();
|
|
494
|
+
};
|
|
495
|
+
abortSignal.addEventListener("abort", abortHandler, { once: true });
|
|
452
496
|
}
|
|
453
497
|
return {
|
|
454
498
|
process: {
|
|
@@ -542,19 +586,19 @@ var Lsp = class {
|
|
|
542
586
|
return this.okra.invoke("lsp.message", { id, message });
|
|
543
587
|
}
|
|
544
588
|
listen(id, event, cb) {
|
|
545
|
-
this.okra.listen(`${event}.${id}`, (e) => cb(e));
|
|
589
|
+
return this.okra.listen(`${event}.${id}`, (e) => cb(e));
|
|
546
590
|
}
|
|
547
591
|
onClose(id, cb) {
|
|
548
|
-
this.listen(id, "lsp.closed", (e) => cb(e.code, e.reason));
|
|
592
|
+
return this.listen(id, "lsp.closed", (e) => cb(e.code, e.reason));
|
|
549
593
|
}
|
|
550
594
|
onError(id, cb) {
|
|
551
|
-
this.listen(id, "lsp.error", (e) => cb(e.message));
|
|
595
|
+
return this.listen(id, "lsp.error", (e) => cb(e.message));
|
|
552
596
|
}
|
|
553
597
|
onClientDisconnect(cb) {
|
|
554
|
-
this.okra.onDidDisconnect(() => cb(1e3, "OKRA DISCONNECTED"));
|
|
598
|
+
return this.okra.onDidDisconnect(() => cb(1e3, "OKRA DISCONNECTED"));
|
|
555
599
|
}
|
|
556
600
|
onResponse(id, cb) {
|
|
557
|
-
this.listen(id, "lsp.response", (e) => cb(JSON.stringify(e)));
|
|
601
|
+
return this.listen(id, "lsp.response", (e) => cb(JSON.stringify(e)));
|
|
558
602
|
}
|
|
559
603
|
close(id) {
|
|
560
604
|
return this.okra.invoke("lsp.close", { id });
|
|
@@ -578,13 +622,13 @@ var LspConnection = class _LspConnection {
|
|
|
578
622
|
return this.lsp.message(this.id, content);
|
|
579
623
|
}
|
|
580
624
|
onMessage(cb) {
|
|
581
|
-
this.lsp.onResponse(this.id, cb);
|
|
625
|
+
return this.lsp.onResponse(this.id, cb);
|
|
582
626
|
}
|
|
583
627
|
onError(cb) {
|
|
584
|
-
this.lsp.onError(this.id, cb);
|
|
628
|
+
return this.lsp.onError(this.id, cb);
|
|
585
629
|
}
|
|
586
630
|
onClose(cb) {
|
|
587
|
-
this.lsp.onClose(this.id, cb);
|
|
631
|
+
return this.lsp.onClose(this.id, cb);
|
|
588
632
|
}
|
|
589
633
|
dispose() {
|
|
590
634
|
this.lsp.close(this.id);
|
|
@@ -593,7 +637,7 @@ var LspConnection = class _LspConnection {
|
|
|
593
637
|
this.lsp.start(this.id);
|
|
594
638
|
}
|
|
595
639
|
onClientDisconnect(cb) {
|
|
596
|
-
this.lsp.onClientDisconnect(cb);
|
|
640
|
+
return this.lsp.onClientDisconnect(cb);
|
|
597
641
|
}
|
|
598
642
|
whenSocketConnected() {
|
|
599
643
|
return this.lsp.whenSocketConnected();
|
|
@@ -643,12 +687,12 @@ var Log = class {
|
|
|
643
687
|
return this.okra.listen("notebook.log", fn);
|
|
644
688
|
}
|
|
645
689
|
listen(event, handler) {
|
|
646
|
-
this.okra.listen(event, handler);
|
|
690
|
+
return this.okra.listen(event, handler);
|
|
647
691
|
}
|
|
648
692
|
};
|
|
649
693
|
|
|
650
694
|
// src/laravel.ts
|
|
651
|
-
var
|
|
695
|
+
var Laravel = class {
|
|
652
696
|
constructor(okra) {
|
|
653
697
|
this.okra = okra;
|
|
654
698
|
}
|
|
@@ -681,10 +725,10 @@ var Repl = class {
|
|
|
681
725
|
return this.okra.invoke("repl.resize", { cols, rows });
|
|
682
726
|
}
|
|
683
727
|
listen(event, handler) {
|
|
684
|
-
this.okra.listen(event, handler);
|
|
728
|
+
return this.okra.listen(event, handler);
|
|
685
729
|
}
|
|
686
730
|
onOutput(handler) {
|
|
687
|
-
this.okra.listen("repl.output", handler);
|
|
731
|
+
return this.okra.listen("repl.output", handler);
|
|
688
732
|
}
|
|
689
733
|
};
|
|
690
734
|
|
|
@@ -721,7 +765,7 @@ var Shell = class {
|
|
|
721
765
|
this.okra = okra;
|
|
722
766
|
}
|
|
723
767
|
onOutput(id, handler) {
|
|
724
|
-
this.okra.listen(`shell.output.${id}`, handler);
|
|
768
|
+
return this.okra.listen(`shell.output.${id}`, handler);
|
|
725
769
|
}
|
|
726
770
|
listen(event, handler) {
|
|
727
771
|
return this.okra.listen(event, handler);
|
|
@@ -2374,6 +2418,10 @@ async function retry(fn, options = {}) {
|
|
|
2374
2418
|
}
|
|
2375
2419
|
|
|
2376
2420
|
// node_modules/reconnecting-websocket/dist/reconnecting-websocket-mjs.js
|
|
2421
|
+
var reconnecting_websocket_mjs_exports = {};
|
|
2422
|
+
__export(reconnecting_websocket_mjs_exports, {
|
|
2423
|
+
default: () => reconnecting_websocket_mjs_default
|
|
2424
|
+
});
|
|
2377
2425
|
var extendStatics = function(d, b) {
|
|
2378
2426
|
extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
|
|
2379
2427
|
d2.__proto__ = b2;
|
|
@@ -2486,7 +2534,7 @@ var DEFAULT = {
|
|
|
2486
2534
|
var ReconnectingWebSocket = (
|
|
2487
2535
|
/** @class */
|
|
2488
2536
|
(function() {
|
|
2489
|
-
function
|
|
2537
|
+
function ReconnectingWebSocket3(url, protocols, options) {
|
|
2490
2538
|
var _this = this;
|
|
2491
2539
|
if (options === void 0) {
|
|
2492
2540
|
options = {};
|
|
@@ -2568,63 +2616,63 @@ var ReconnectingWebSocket = (
|
|
|
2568
2616
|
}
|
|
2569
2617
|
this._connect();
|
|
2570
2618
|
}
|
|
2571
|
-
Object.defineProperty(
|
|
2619
|
+
Object.defineProperty(ReconnectingWebSocket3, "CONNECTING", {
|
|
2572
2620
|
get: function() {
|
|
2573
2621
|
return 0;
|
|
2574
2622
|
},
|
|
2575
2623
|
enumerable: true,
|
|
2576
2624
|
configurable: true
|
|
2577
2625
|
});
|
|
2578
|
-
Object.defineProperty(
|
|
2626
|
+
Object.defineProperty(ReconnectingWebSocket3, "OPEN", {
|
|
2579
2627
|
get: function() {
|
|
2580
2628
|
return 1;
|
|
2581
2629
|
},
|
|
2582
2630
|
enumerable: true,
|
|
2583
2631
|
configurable: true
|
|
2584
2632
|
});
|
|
2585
|
-
Object.defineProperty(
|
|
2633
|
+
Object.defineProperty(ReconnectingWebSocket3, "CLOSING", {
|
|
2586
2634
|
get: function() {
|
|
2587
2635
|
return 2;
|
|
2588
2636
|
},
|
|
2589
2637
|
enumerable: true,
|
|
2590
2638
|
configurable: true
|
|
2591
2639
|
});
|
|
2592
|
-
Object.defineProperty(
|
|
2640
|
+
Object.defineProperty(ReconnectingWebSocket3, "CLOSED", {
|
|
2593
2641
|
get: function() {
|
|
2594
2642
|
return 3;
|
|
2595
2643
|
},
|
|
2596
2644
|
enumerable: true,
|
|
2597
2645
|
configurable: true
|
|
2598
2646
|
});
|
|
2599
|
-
Object.defineProperty(
|
|
2647
|
+
Object.defineProperty(ReconnectingWebSocket3.prototype, "CONNECTING", {
|
|
2600
2648
|
get: function() {
|
|
2601
|
-
return
|
|
2649
|
+
return ReconnectingWebSocket3.CONNECTING;
|
|
2602
2650
|
},
|
|
2603
2651
|
enumerable: true,
|
|
2604
2652
|
configurable: true
|
|
2605
2653
|
});
|
|
2606
|
-
Object.defineProperty(
|
|
2654
|
+
Object.defineProperty(ReconnectingWebSocket3.prototype, "OPEN", {
|
|
2607
2655
|
get: function() {
|
|
2608
|
-
return
|
|
2656
|
+
return ReconnectingWebSocket3.OPEN;
|
|
2609
2657
|
},
|
|
2610
2658
|
enumerable: true,
|
|
2611
2659
|
configurable: true
|
|
2612
2660
|
});
|
|
2613
|
-
Object.defineProperty(
|
|
2661
|
+
Object.defineProperty(ReconnectingWebSocket3.prototype, "CLOSING", {
|
|
2614
2662
|
get: function() {
|
|
2615
|
-
return
|
|
2663
|
+
return ReconnectingWebSocket3.CLOSING;
|
|
2616
2664
|
},
|
|
2617
2665
|
enumerable: true,
|
|
2618
2666
|
configurable: true
|
|
2619
2667
|
});
|
|
2620
|
-
Object.defineProperty(
|
|
2668
|
+
Object.defineProperty(ReconnectingWebSocket3.prototype, "CLOSED", {
|
|
2621
2669
|
get: function() {
|
|
2622
|
-
return
|
|
2670
|
+
return ReconnectingWebSocket3.CLOSED;
|
|
2623
2671
|
},
|
|
2624
2672
|
enumerable: true,
|
|
2625
2673
|
configurable: true
|
|
2626
2674
|
});
|
|
2627
|
-
Object.defineProperty(
|
|
2675
|
+
Object.defineProperty(ReconnectingWebSocket3.prototype, "binaryType", {
|
|
2628
2676
|
get: function() {
|
|
2629
2677
|
return this._ws ? this._ws.binaryType : this._binaryType;
|
|
2630
2678
|
},
|
|
@@ -2637,7 +2685,7 @@ var ReconnectingWebSocket = (
|
|
|
2637
2685
|
enumerable: true,
|
|
2638
2686
|
configurable: true
|
|
2639
2687
|
});
|
|
2640
|
-
Object.defineProperty(
|
|
2688
|
+
Object.defineProperty(ReconnectingWebSocket3.prototype, "retryCount", {
|
|
2641
2689
|
/**
|
|
2642
2690
|
* Returns the number or connection retries
|
|
2643
2691
|
*/
|
|
@@ -2647,7 +2695,7 @@ var ReconnectingWebSocket = (
|
|
|
2647
2695
|
enumerable: true,
|
|
2648
2696
|
configurable: true
|
|
2649
2697
|
});
|
|
2650
|
-
Object.defineProperty(
|
|
2698
|
+
Object.defineProperty(ReconnectingWebSocket3.prototype, "bufferedAmount", {
|
|
2651
2699
|
/**
|
|
2652
2700
|
* The number of bytes of data that have been queued using calls to send() but not yet
|
|
2653
2701
|
* transmitted to the network. This value resets to zero once all queued data has been sent.
|
|
@@ -2670,7 +2718,7 @@ var ReconnectingWebSocket = (
|
|
|
2670
2718
|
enumerable: true,
|
|
2671
2719
|
configurable: true
|
|
2672
2720
|
});
|
|
2673
|
-
Object.defineProperty(
|
|
2721
|
+
Object.defineProperty(ReconnectingWebSocket3.prototype, "extensions", {
|
|
2674
2722
|
/**
|
|
2675
2723
|
* The extensions selected by the server. This is currently only the empty string or a list of
|
|
2676
2724
|
* extensions as negotiated by the connection
|
|
@@ -2681,7 +2729,7 @@ var ReconnectingWebSocket = (
|
|
|
2681
2729
|
enumerable: true,
|
|
2682
2730
|
configurable: true
|
|
2683
2731
|
});
|
|
2684
|
-
Object.defineProperty(
|
|
2732
|
+
Object.defineProperty(ReconnectingWebSocket3.prototype, "protocol", {
|
|
2685
2733
|
/**
|
|
2686
2734
|
* A string indicating the name of the sub-protocol the server selected;
|
|
2687
2735
|
* this will be one of the strings specified in the protocols parameter when creating the
|
|
@@ -2693,7 +2741,7 @@ var ReconnectingWebSocket = (
|
|
|
2693
2741
|
enumerable: true,
|
|
2694
2742
|
configurable: true
|
|
2695
2743
|
});
|
|
2696
|
-
Object.defineProperty(
|
|
2744
|
+
Object.defineProperty(ReconnectingWebSocket3.prototype, "readyState", {
|
|
2697
2745
|
/**
|
|
2698
2746
|
* The current state of the connection; this is one of the Ready state constants
|
|
2699
2747
|
*/
|
|
@@ -2701,12 +2749,12 @@ var ReconnectingWebSocket = (
|
|
|
2701
2749
|
if (this._ws) {
|
|
2702
2750
|
return this._ws.readyState;
|
|
2703
2751
|
}
|
|
2704
|
-
return this._options.startClosed ?
|
|
2752
|
+
return this._options.startClosed ? ReconnectingWebSocket3.CLOSED : ReconnectingWebSocket3.CONNECTING;
|
|
2705
2753
|
},
|
|
2706
2754
|
enumerable: true,
|
|
2707
2755
|
configurable: true
|
|
2708
2756
|
});
|
|
2709
|
-
Object.defineProperty(
|
|
2757
|
+
Object.defineProperty(ReconnectingWebSocket3.prototype, "url", {
|
|
2710
2758
|
/**
|
|
2711
2759
|
* The URL as resolved by the constructor
|
|
2712
2760
|
*/
|
|
@@ -2716,7 +2764,7 @@ var ReconnectingWebSocket = (
|
|
|
2716
2764
|
enumerable: true,
|
|
2717
2765
|
configurable: true
|
|
2718
2766
|
});
|
|
2719
|
-
|
|
2767
|
+
ReconnectingWebSocket3.prototype.close = function(code, reason) {
|
|
2720
2768
|
if (code === void 0) {
|
|
2721
2769
|
code = 1e3;
|
|
2722
2770
|
}
|
|
@@ -2733,7 +2781,7 @@ var ReconnectingWebSocket = (
|
|
|
2733
2781
|
}
|
|
2734
2782
|
this._ws.close(code, reason);
|
|
2735
2783
|
};
|
|
2736
|
-
|
|
2784
|
+
ReconnectingWebSocket3.prototype.reconnect = function(code, reason) {
|
|
2737
2785
|
this._shouldReconnect = true;
|
|
2738
2786
|
this._closeCalled = false;
|
|
2739
2787
|
this._retryCount = -1;
|
|
@@ -2744,7 +2792,7 @@ var ReconnectingWebSocket = (
|
|
|
2744
2792
|
this._connect();
|
|
2745
2793
|
}
|
|
2746
2794
|
};
|
|
2747
|
-
|
|
2795
|
+
ReconnectingWebSocket3.prototype.send = function(data) {
|
|
2748
2796
|
if (this._ws && this._ws.readyState === this.OPEN) {
|
|
2749
2797
|
this._debug("send", data);
|
|
2750
2798
|
this._ws.send(data);
|
|
@@ -2756,12 +2804,12 @@ var ReconnectingWebSocket = (
|
|
|
2756
2804
|
}
|
|
2757
2805
|
}
|
|
2758
2806
|
};
|
|
2759
|
-
|
|
2807
|
+
ReconnectingWebSocket3.prototype.addEventListener = function(type, listener) {
|
|
2760
2808
|
if (this._listeners[type]) {
|
|
2761
2809
|
this._listeners[type].push(listener);
|
|
2762
2810
|
}
|
|
2763
2811
|
};
|
|
2764
|
-
|
|
2812
|
+
ReconnectingWebSocket3.prototype.dispatchEvent = function(event) {
|
|
2765
2813
|
var e_1, _a;
|
|
2766
2814
|
var listeners = this._listeners[event.type];
|
|
2767
2815
|
if (listeners) {
|
|
@@ -2782,14 +2830,14 @@ var ReconnectingWebSocket = (
|
|
|
2782
2830
|
}
|
|
2783
2831
|
return true;
|
|
2784
2832
|
};
|
|
2785
|
-
|
|
2833
|
+
ReconnectingWebSocket3.prototype.removeEventListener = function(type, listener) {
|
|
2786
2834
|
if (this._listeners[type]) {
|
|
2787
2835
|
this._listeners[type] = this._listeners[type].filter(function(l) {
|
|
2788
2836
|
return l !== listener;
|
|
2789
2837
|
});
|
|
2790
2838
|
}
|
|
2791
2839
|
};
|
|
2792
|
-
|
|
2840
|
+
ReconnectingWebSocket3.prototype._debug = function() {
|
|
2793
2841
|
var args = [];
|
|
2794
2842
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2795
2843
|
args[_i] = arguments[_i];
|
|
@@ -2798,7 +2846,7 @@ var ReconnectingWebSocket = (
|
|
|
2798
2846
|
console.log.apply(console, __spread(["RWS>"], args));
|
|
2799
2847
|
}
|
|
2800
2848
|
};
|
|
2801
|
-
|
|
2849
|
+
ReconnectingWebSocket3.prototype._getNextDelay = function() {
|
|
2802
2850
|
var _a = this._options, _b = _a.reconnectionDelayGrowFactor, reconnectionDelayGrowFactor = _b === void 0 ? DEFAULT.reconnectionDelayGrowFactor : _b, _c = _a.minReconnectionDelay, minReconnectionDelay = _c === void 0 ? DEFAULT.minReconnectionDelay : _c, _d = _a.maxReconnectionDelay, maxReconnectionDelay = _d === void 0 ? DEFAULT.maxReconnectionDelay : _d;
|
|
2803
2851
|
var delay = 0;
|
|
2804
2852
|
if (this._retryCount > 0) {
|
|
@@ -2810,13 +2858,13 @@ var ReconnectingWebSocket = (
|
|
|
2810
2858
|
this._debug("next delay", delay);
|
|
2811
2859
|
return delay;
|
|
2812
2860
|
};
|
|
2813
|
-
|
|
2861
|
+
ReconnectingWebSocket3.prototype._wait = function() {
|
|
2814
2862
|
var _this = this;
|
|
2815
2863
|
return new Promise(function(resolve) {
|
|
2816
2864
|
setTimeout(resolve, _this._getNextDelay());
|
|
2817
2865
|
});
|
|
2818
2866
|
};
|
|
2819
|
-
|
|
2867
|
+
ReconnectingWebSocket3.prototype._getNextUrl = function(urlProvider) {
|
|
2820
2868
|
if (typeof urlProvider === "string") {
|
|
2821
2869
|
return Promise.resolve(urlProvider);
|
|
2822
2870
|
}
|
|
@@ -2831,7 +2879,7 @@ var ReconnectingWebSocket = (
|
|
|
2831
2879
|
}
|
|
2832
2880
|
throw Error("Invalid URL");
|
|
2833
2881
|
};
|
|
2834
|
-
|
|
2882
|
+
ReconnectingWebSocket3.prototype._connect = function() {
|
|
2835
2883
|
var _this = this;
|
|
2836
2884
|
if (this._connectLock || !this._shouldReconnect) {
|
|
2837
2885
|
return;
|
|
@@ -2864,11 +2912,11 @@ var ReconnectingWebSocket = (
|
|
|
2864
2912
|
}, connectionTimeout);
|
|
2865
2913
|
});
|
|
2866
2914
|
};
|
|
2867
|
-
|
|
2915
|
+
ReconnectingWebSocket3.prototype._handleTimeout = function() {
|
|
2868
2916
|
this._debug("timeout event");
|
|
2869
2917
|
this._handleError(new ErrorEvent2(Error("TIMEOUT"), this));
|
|
2870
2918
|
};
|
|
2871
|
-
|
|
2919
|
+
ReconnectingWebSocket3.prototype._disconnect = function(code, reason) {
|
|
2872
2920
|
if (code === void 0) {
|
|
2873
2921
|
code = 1e3;
|
|
2874
2922
|
}
|
|
@@ -2883,18 +2931,18 @@ var ReconnectingWebSocket = (
|
|
|
2883
2931
|
} catch (error) {
|
|
2884
2932
|
}
|
|
2885
2933
|
};
|
|
2886
|
-
|
|
2934
|
+
ReconnectingWebSocket3.prototype._acceptOpen = function() {
|
|
2887
2935
|
this._debug("accept open");
|
|
2888
2936
|
this._retryCount = 0;
|
|
2889
2937
|
};
|
|
2890
|
-
|
|
2938
|
+
ReconnectingWebSocket3.prototype._callEventListener = function(event, listener) {
|
|
2891
2939
|
if ("handleEvent" in listener) {
|
|
2892
2940
|
listener.handleEvent(event);
|
|
2893
2941
|
} else {
|
|
2894
2942
|
listener(event);
|
|
2895
2943
|
}
|
|
2896
2944
|
};
|
|
2897
|
-
|
|
2945
|
+
ReconnectingWebSocket3.prototype._removeListeners = function() {
|
|
2898
2946
|
if (!this._ws) {
|
|
2899
2947
|
return;
|
|
2900
2948
|
}
|
|
@@ -2904,7 +2952,7 @@ var ReconnectingWebSocket = (
|
|
|
2904
2952
|
this._ws.removeEventListener("message", this._handleMessage);
|
|
2905
2953
|
this._ws.removeEventListener("error", this._handleError);
|
|
2906
2954
|
};
|
|
2907
|
-
|
|
2955
|
+
ReconnectingWebSocket3.prototype._addListeners = function() {
|
|
2908
2956
|
if (!this._ws) {
|
|
2909
2957
|
return;
|
|
2910
2958
|
}
|
|
@@ -2914,11 +2962,11 @@ var ReconnectingWebSocket = (
|
|
|
2914
2962
|
this._ws.addEventListener("message", this._handleMessage);
|
|
2915
2963
|
this._ws.addEventListener("error", this._handleError);
|
|
2916
2964
|
};
|
|
2917
|
-
|
|
2965
|
+
ReconnectingWebSocket3.prototype._clearTimeouts = function() {
|
|
2918
2966
|
clearTimeout(this._connectTimeout);
|
|
2919
2967
|
clearTimeout(this._uptimeTimeout);
|
|
2920
2968
|
};
|
|
2921
|
-
return
|
|
2969
|
+
return ReconnectingWebSocket3;
|
|
2922
2970
|
})()
|
|
2923
2971
|
);
|
|
2924
2972
|
var reconnecting_websocket_mjs_default = ReconnectingWebSocket;
|
|
@@ -3043,6 +3091,7 @@ var NamedDisposable = class {
|
|
|
3043
3091
|
};
|
|
3044
3092
|
|
|
3045
3093
|
// src/socket/index.ts
|
|
3094
|
+
var ReconnectingWebSocket2 = reconnecting_websocket_mjs_default ?? reconnecting_websocket_mjs_exports;
|
|
3046
3095
|
var ConnectionTimeoutError = class extends Error {
|
|
3047
3096
|
constructor(message = "WebSocket connection timeout") {
|
|
3048
3097
|
super(message);
|
|
@@ -3081,30 +3130,13 @@ var Transport = class {
|
|
|
3081
3130
|
this.connectPromise = null;
|
|
3082
3131
|
this.terminalError = null;
|
|
3083
3132
|
this.pingIntervalStarted = false;
|
|
3084
|
-
// Connection health monitoring
|
|
3085
|
-
this.connectionStats = {
|
|
3086
|
-
connectTime: 0,
|
|
3087
|
-
reconnectCount: 0,
|
|
3088
|
-
lastPingTime: 0,
|
|
3089
|
-
lastPongTime: 0,
|
|
3090
|
-
avgResponseTime: 0,
|
|
3091
|
-
totalMessages: 0,
|
|
3092
|
-
totalErrors: 0,
|
|
3093
|
-
connectionStartTime: 0
|
|
3094
|
-
};
|
|
3095
|
-
// Message queue for disconnection handling
|
|
3096
|
-
this.messageQueue = [];
|
|
3097
|
-
this.MAX_QUEUE_SIZE = 100;
|
|
3098
|
-
this.QUEUE_TIMEOUT = 3e4;
|
|
3099
|
-
// 30 seconds
|
|
3100
3133
|
this.incomingMessageChain = Promise.resolve();
|
|
3101
3134
|
this.validateConfiguration(options);
|
|
3102
3135
|
this.url = new URL(url);
|
|
3103
3136
|
this.PING_INTERVAL = options.pingInterval ?? 3e4;
|
|
3104
3137
|
this.CONNECT_WAIT_TIMEOUT = options.connectWaitTimeout ?? 3e4;
|
|
3105
|
-
this.connectionStats.connectionStartTime = Date.now();
|
|
3106
3138
|
const startClosed = options.startClosed !== false;
|
|
3107
|
-
this.rws = new
|
|
3139
|
+
this.rws = new ReconnectingWebSocket2(this.url.toString(), [], {
|
|
3108
3140
|
WebSocket: options.webSocket ?? globalThis.WebSocket ?? browser_default,
|
|
3109
3141
|
connectionTimeout: options.connectionTimeout,
|
|
3110
3142
|
maxReconnectionDelay: 2e3,
|
|
@@ -3118,8 +3150,6 @@ var Transport = class {
|
|
|
3118
3150
|
options
|
|
3119
3151
|
});
|
|
3120
3152
|
this.registerWatchers();
|
|
3121
|
-
this.setupConnectionHealthMonitoring();
|
|
3122
|
-
this.startPeriodicMaintenance();
|
|
3123
3153
|
}
|
|
3124
3154
|
/**
|
|
3125
3155
|
* Validate configuration options
|
|
@@ -3163,7 +3193,6 @@ var Transport = class {
|
|
|
3163
3193
|
async registerWatchers() {
|
|
3164
3194
|
const onMessage = (ev) => {
|
|
3165
3195
|
this.incomingMessageChain = this.incomingMessageChain.catch(() => void 0).then(() => this.processIncomingMessage(ev)).catch((error) => {
|
|
3166
|
-
this.connectionStats.totalErrors++;
|
|
3167
3196
|
this.log("error", "Failed to process queued WebSocket frame", {
|
|
3168
3197
|
error: error instanceof Error ? error.message : String(error)
|
|
3169
3198
|
});
|
|
@@ -3183,11 +3212,12 @@ var Transport = class {
|
|
|
3183
3212
|
});
|
|
3184
3213
|
}
|
|
3185
3214
|
async processIncomingMessage(ev) {
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
this.
|
|
3215
|
+
let buffer;
|
|
3216
|
+
try {
|
|
3217
|
+
buffer = await this.toArrayBuffer(ev.data);
|
|
3218
|
+
} catch (error) {
|
|
3189
3219
|
this.log("error", "Unexpected WebSocket message type", {
|
|
3190
|
-
error: error.message,
|
|
3220
|
+
error: error instanceof Error ? error.message : String(error),
|
|
3191
3221
|
messageType: typeof ev.data
|
|
3192
3222
|
});
|
|
3193
3223
|
this.eventEmitter.emit("transport.error", {
|
|
@@ -3198,7 +3228,6 @@ var Transport = class {
|
|
|
3198
3228
|
});
|
|
3199
3229
|
return;
|
|
3200
3230
|
}
|
|
3201
|
-
const buffer = await ev.data.arrayBuffer();
|
|
3202
3231
|
if (buffer.byteLength === 0) {
|
|
3203
3232
|
this.log("warn", "Ignoring empty WebSocket frame");
|
|
3204
3233
|
return;
|
|
@@ -3207,7 +3236,6 @@ var Transport = class {
|
|
|
3207
3236
|
try {
|
|
3208
3237
|
decoded = decode(buffer);
|
|
3209
3238
|
} catch (error) {
|
|
3210
|
-
this.connectionStats.totalErrors++;
|
|
3211
3239
|
this.log("error", "Failed to decode WebSocket frame", {
|
|
3212
3240
|
error: error instanceof Error ? error.message : String(error),
|
|
3213
3241
|
byteLength: buffer.byteLength
|
|
@@ -3223,7 +3251,6 @@ var Transport = class {
|
|
|
3223
3251
|
try {
|
|
3224
3252
|
await this.handleRawMessage(decoded);
|
|
3225
3253
|
} catch (error) {
|
|
3226
|
-
this.connectionStats.totalErrors++;
|
|
3227
3254
|
this.log("error", "Failed to process WebSocket frame", {
|
|
3228
3255
|
error: error instanceof Error ? error.message : String(error),
|
|
3229
3256
|
byteLength: buffer.byteLength
|
|
@@ -3236,6 +3263,19 @@ var Transport = class {
|
|
|
3236
3263
|
});
|
|
3237
3264
|
}
|
|
3238
3265
|
}
|
|
3266
|
+
async toArrayBuffer(data) {
|
|
3267
|
+
if (data instanceof Blob) {
|
|
3268
|
+
return data.arrayBuffer();
|
|
3269
|
+
}
|
|
3270
|
+
if (data instanceof ArrayBuffer) {
|
|
3271
|
+
return data;
|
|
3272
|
+
}
|
|
3273
|
+
if (ArrayBuffer.isView(data)) {
|
|
3274
|
+
const bytes = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
3275
|
+
return bytes.slice().buffer;
|
|
3276
|
+
}
|
|
3277
|
+
throw new Error("Unexpected message type: " + typeof data);
|
|
3278
|
+
}
|
|
3239
3279
|
async handleRawMessage(ev) {
|
|
3240
3280
|
if (this.closed) {
|
|
3241
3281
|
this.log("debug", "Ignoring message received after transport was closed");
|
|
@@ -3257,9 +3297,10 @@ var Transport = class {
|
|
|
3257
3297
|
return;
|
|
3258
3298
|
}
|
|
3259
3299
|
if (event === "Events.BootError" /* BootError */) {
|
|
3300
|
+
const errorData = data;
|
|
3260
3301
|
const error = new NotebookUnavailableError(
|
|
3261
|
-
|
|
3262
|
-
|
|
3302
|
+
errorData?.message || "Notebook is no longer available",
|
|
3303
|
+
errorData || {}
|
|
3263
3304
|
);
|
|
3264
3305
|
this.log("error", "Boot error received", { data });
|
|
3265
3306
|
this.terminate(error, 4e3, error.message);
|
|
@@ -3288,18 +3329,15 @@ var Transport = class {
|
|
|
3288
3329
|
}
|
|
3289
3330
|
await this.handleMessage(event, data, as);
|
|
3290
3331
|
} catch (e) {
|
|
3291
|
-
this.connectionStats.totalErrors++;
|
|
3292
3332
|
if (e instanceof InvalidMessageError) {
|
|
3293
3333
|
this.log("error", "Invalid message format", {
|
|
3294
3334
|
error: e.message,
|
|
3295
|
-
data: e.data
|
|
3296
|
-
totalErrors: this.connectionStats.totalErrors
|
|
3335
|
+
data: e.data
|
|
3297
3336
|
});
|
|
3298
3337
|
} else {
|
|
3299
3338
|
this.log("error", "Failed to parse message", {
|
|
3300
3339
|
ev,
|
|
3301
|
-
error: e instanceof Error ? e.message : String(e)
|
|
3302
|
-
totalErrors: this.connectionStats.totalErrors
|
|
3340
|
+
error: e instanceof Error ? e.message : String(e)
|
|
3303
3341
|
});
|
|
3304
3342
|
}
|
|
3305
3343
|
this.eventEmitter.emit("transport.error", {
|
|
@@ -3313,7 +3351,7 @@ var Transport = class {
|
|
|
3313
3351
|
async handleMessage(event, data, as) {
|
|
3314
3352
|
if (event === "App.Actions.GetClientId" /* ClientId */) {
|
|
3315
3353
|
this.clientId = data.id;
|
|
3316
|
-
this.eventEmitter.emit(event,
|
|
3354
|
+
this.eventEmitter.emit(event, this.clientId);
|
|
3317
3355
|
return;
|
|
3318
3356
|
}
|
|
3319
3357
|
event && this.eventEmitter.emit(as || event, data);
|
|
@@ -3322,7 +3360,7 @@ var Transport = class {
|
|
|
3322
3360
|
return this.eventEmitter.listen(event, listener);
|
|
3323
3361
|
}
|
|
3324
3362
|
onDidBootError(listener) {
|
|
3325
|
-
this.eventEmitter.listen("transport.boot_error", (event) => {
|
|
3363
|
+
return this.eventEmitter.listen("transport.boot_error", (event) => {
|
|
3326
3364
|
listener(event.error);
|
|
3327
3365
|
});
|
|
3328
3366
|
}
|
|
@@ -3330,12 +3368,7 @@ var Transport = class {
|
|
|
3330
3368
|
this.eventEmitter.removeListener(event, listener);
|
|
3331
3369
|
}
|
|
3332
3370
|
listenOnce(event, listener, context) {
|
|
3333
|
-
this.eventEmitter.once(event, listener, context);
|
|
3334
|
-
this.disposables.add(`once_${event}_${nanoid()}`, {
|
|
3335
|
-
dispose: () => {
|
|
3336
|
-
this.eventEmitter.removeListener(event, listener);
|
|
3337
|
-
}
|
|
3338
|
-
});
|
|
3371
|
+
return this.eventEmitter.once(event, listener, context);
|
|
3339
3372
|
}
|
|
3340
3373
|
emit(event, ...data) {
|
|
3341
3374
|
this.eventEmitter.emit(event, ...data);
|
|
@@ -3367,19 +3400,23 @@ var Transport = class {
|
|
|
3367
3400
|
if (this.terminalError) {
|
|
3368
3401
|
throw this.terminalError;
|
|
3369
3402
|
}
|
|
3370
|
-
this.clearOldQueuedMessages();
|
|
3371
3403
|
const responseEvent = options.responseEvent || `${action}_${nanoid()}_response`;
|
|
3372
3404
|
const errorEvent = `${responseEvent}_error`;
|
|
3373
3405
|
let closeHandler;
|
|
3406
|
+
let abortHandler;
|
|
3374
3407
|
const removeListeners = () => {
|
|
3375
3408
|
if (closeHandler) {
|
|
3376
3409
|
this.rws.removeEventListener("close", closeHandler);
|
|
3377
3410
|
this.rws.removeEventListener("error", closeHandler);
|
|
3378
3411
|
}
|
|
3412
|
+
if (abortHandler) {
|
|
3413
|
+
options.abortSignal?.removeEventListener("abort", abortHandler);
|
|
3414
|
+
abortHandler = void 0;
|
|
3415
|
+
}
|
|
3379
3416
|
this.eventEmitter.removeListener(responseEvent);
|
|
3380
3417
|
this.eventEmitter.removeListener(errorEvent);
|
|
3381
3418
|
};
|
|
3382
|
-
const handler =
|
|
3419
|
+
const handler = (resolve, reject) => {
|
|
3383
3420
|
if (this.terminalError) {
|
|
3384
3421
|
reject(this.terminalError);
|
|
3385
3422
|
return;
|
|
@@ -3387,48 +3424,28 @@ var Transport = class {
|
|
|
3387
3424
|
const abortError = new DOMException("Request aborted", "AbortError");
|
|
3388
3425
|
if (options.abortSignal?.aborted) {
|
|
3389
3426
|
reject(abortError);
|
|
3427
|
+
return;
|
|
3390
3428
|
}
|
|
3391
3429
|
if (options.abortSignal) {
|
|
3392
|
-
|
|
3430
|
+
abortHandler = () => {
|
|
3393
3431
|
reject(abortError);
|
|
3394
|
-
}
|
|
3432
|
+
};
|
|
3433
|
+
options.abortSignal.addEventListener("abort", abortHandler, { once: true });
|
|
3395
3434
|
}
|
|
3396
|
-
if (!this.isConnected
|
|
3397
|
-
|
|
3398
|
-
action
|
|
3399
|
-
});
|
|
3400
|
-
if (this.messageQueue.length >= this.MAX_QUEUE_SIZE) {
|
|
3401
|
-
const oldestMessage = this.messageQueue.shift();
|
|
3402
|
-
if (oldestMessage) {
|
|
3403
|
-
oldestMessage.reject(new Error("Message queue full, oldest message dropped"));
|
|
3404
|
-
}
|
|
3405
|
-
}
|
|
3406
|
-
this.messageQueue.push({
|
|
3407
|
-
action,
|
|
3408
|
-
data,
|
|
3409
|
-
options,
|
|
3410
|
-
resolve,
|
|
3411
|
-
reject,
|
|
3412
|
-
timestamp: Date.now()
|
|
3413
|
-
});
|
|
3435
|
+
if (!this.isConnected || this.isClosed) {
|
|
3436
|
+
reject(new ConnectionFailedError(`Connection is not open while sending ${action}. Current status: ${this.status}`));
|
|
3414
3437
|
return;
|
|
3415
3438
|
}
|
|
3416
|
-
const startTime = Date.now();
|
|
3417
3439
|
this.listenOnce(responseEvent, (response) => {
|
|
3418
|
-
const responseTime = Date.now() - startTime;
|
|
3419
|
-
this.connectionStats.avgResponseTime = (this.connectionStats.avgResponseTime + responseTime) / 2;
|
|
3420
|
-
this.connectionStats.totalMessages++;
|
|
3421
3440
|
this.log("debug", "Message response received", {
|
|
3422
|
-
action
|
|
3423
|
-
responseTime,
|
|
3424
|
-
avgResponseTime: this.connectionStats.avgResponseTime
|
|
3441
|
+
action
|
|
3425
3442
|
});
|
|
3426
3443
|
resolve(response);
|
|
3427
3444
|
});
|
|
3428
3445
|
this.listenOnce(errorEvent, (e) => {
|
|
3429
|
-
this.connectionStats.totalErrors++;
|
|
3430
3446
|
this.log("error", "Message error received", { action, error: e });
|
|
3431
|
-
|
|
3447
|
+
const error = e;
|
|
3448
|
+
reject(new ErrorEvent(error.code, error.message, error));
|
|
3432
3449
|
});
|
|
3433
3450
|
closeHandler = (_ev) => {
|
|
3434
3451
|
if (_ev.code === 1008 && (_ev.reason || "").includes("rate limit")) {
|
|
@@ -3445,11 +3462,17 @@ var Transport = class {
|
|
|
3445
3462
|
this.log("debug", "Message sent", { action, data });
|
|
3446
3463
|
} catch (error) {
|
|
3447
3464
|
this.log("error", "Failed to send message", { action, error });
|
|
3448
|
-
|
|
3465
|
+
reject(error);
|
|
3449
3466
|
}
|
|
3450
3467
|
};
|
|
3451
3468
|
const send = async () => {
|
|
3469
|
+
if (options.abortSignal?.aborted) {
|
|
3470
|
+
throw new DOMException("Request aborted", "AbortError");
|
|
3471
|
+
}
|
|
3452
3472
|
await __privateMethod(this, _Transport_instances, connect_fn).call(this);
|
|
3473
|
+
if (options.abortSignal?.aborted) {
|
|
3474
|
+
throw new DOMException("Request aborted", "AbortError");
|
|
3475
|
+
}
|
|
3453
3476
|
const promise = new Promise(handler).finally(removeListeners);
|
|
3454
3477
|
if (!options.timeout) {
|
|
3455
3478
|
return promise;
|
|
@@ -3461,7 +3484,8 @@ var Transport = class {
|
|
|
3461
3484
|
throw error;
|
|
3462
3485
|
}).finally(removeListeners);
|
|
3463
3486
|
};
|
|
3464
|
-
|
|
3487
|
+
const retries = options.retries === false ? 0 : options.retries ?? 0;
|
|
3488
|
+
return this.sendWithRetry(async () => await send(), retries);
|
|
3465
3489
|
}
|
|
3466
3490
|
send(action, data = {}) {
|
|
3467
3491
|
if (this.terminalError) {
|
|
@@ -3475,11 +3499,9 @@ var Transport = class {
|
|
|
3475
3499
|
}
|
|
3476
3500
|
try {
|
|
3477
3501
|
this.rws.send(this.pack({ action, data }));
|
|
3478
|
-
this.connectionStats.totalMessages++;
|
|
3479
3502
|
this.log("debug", "One-way message sent", { action, data });
|
|
3480
3503
|
return true;
|
|
3481
3504
|
} catch (error) {
|
|
3482
|
-
this.connectionStats.totalErrors++;
|
|
3483
3505
|
this.log("error", "Failed to send one-way message", { action, error });
|
|
3484
3506
|
return false;
|
|
3485
3507
|
}
|
|
@@ -3487,7 +3509,7 @@ var Transport = class {
|
|
|
3487
3509
|
pack(data) {
|
|
3488
3510
|
return new Blob([encode(data)]);
|
|
3489
3511
|
}
|
|
3490
|
-
sendWithRetry(sender, retries
|
|
3512
|
+
sendWithRetry(sender, retries) {
|
|
3491
3513
|
return retry(
|
|
3492
3514
|
async (bail, attempt) => {
|
|
3493
3515
|
try {
|
|
@@ -3510,8 +3532,7 @@ var Transport = class {
|
|
|
3510
3532
|
}
|
|
3511
3533
|
this.log("debug", "Retrying send operation", {
|
|
3512
3534
|
attempt,
|
|
3513
|
-
error: e instanceof Error ? e.message : String(e)
|
|
3514
|
-
nextDelay: this.getBackoffDelay(attempt - 1)
|
|
3535
|
+
error: e instanceof Error ? e.message : String(e)
|
|
3515
3536
|
});
|
|
3516
3537
|
throw e;
|
|
3517
3538
|
}
|
|
@@ -3557,7 +3578,6 @@ var Transport = class {
|
|
|
3557
3578
|
}
|
|
3558
3579
|
disconnect() {
|
|
3559
3580
|
if (this.closed) {
|
|
3560
|
-
console.trace("Transport is already closed, cannot disconnect again");
|
|
3561
3581
|
return;
|
|
3562
3582
|
}
|
|
3563
3583
|
this.close();
|
|
@@ -3578,15 +3598,6 @@ var Transport = class {
|
|
|
3578
3598
|
}
|
|
3579
3599
|
this.log("info", "Closing transport connection", { code, reason });
|
|
3580
3600
|
this.connectPromise = null;
|
|
3581
|
-
const queuedCount = this.messageQueue.length;
|
|
3582
|
-
const closeError = this.terminalError || new Error("Connection closed while message was queued");
|
|
3583
|
-
this.messageQueue.forEach((msg) => {
|
|
3584
|
-
msg.reject(closeError);
|
|
3585
|
-
});
|
|
3586
|
-
this.messageQueue = [];
|
|
3587
|
-
if (queuedCount > 0) {
|
|
3588
|
-
this.log("debug", `Rejected ${queuedCount} queued messages due to connection close`);
|
|
3589
|
-
}
|
|
3590
3601
|
this.disposables.dispose();
|
|
3591
3602
|
try {
|
|
3592
3603
|
this.rws.close(code, reason);
|
|
@@ -3598,7 +3609,6 @@ var Transport = class {
|
|
|
3598
3609
|
this.eventEmitter.emit("transport.closed", {
|
|
3599
3610
|
code,
|
|
3600
3611
|
reason,
|
|
3601
|
-
metrics: this.getConnectionMetrics(),
|
|
3602
3612
|
timestamp: Date.now()
|
|
3603
3613
|
});
|
|
3604
3614
|
this.eventEmitter.removeListener("*");
|
|
@@ -3607,250 +3617,23 @@ var Transport = class {
|
|
|
3607
3617
|
}
|
|
3608
3618
|
onDidConnect(listener) {
|
|
3609
3619
|
this.rws.addEventListener("open", listener);
|
|
3610
|
-
|
|
3620
|
+
const disposable = {
|
|
3611
3621
|
dispose: () => {
|
|
3612
3622
|
this.rws.removeEventListener("open", listener);
|
|
3613
3623
|
}
|
|
3614
|
-
}
|
|
3624
|
+
};
|
|
3625
|
+
this.disposables.add(`connect_${nanoid()}`, disposable);
|
|
3626
|
+
return disposable;
|
|
3615
3627
|
}
|
|
3616
3628
|
onDidClose(listener) {
|
|
3617
3629
|
this.rws.addEventListener("close", listener);
|
|
3618
|
-
|
|
3630
|
+
const disposable = {
|
|
3619
3631
|
dispose: () => {
|
|
3620
3632
|
this.rws.removeEventListener("close", listener);
|
|
3621
3633
|
}
|
|
3622
|
-
});
|
|
3623
|
-
}
|
|
3624
|
-
/**
|
|
3625
|
-
* Setup connection health monitoring
|
|
3626
|
-
*/
|
|
3627
|
-
setupConnectionHealthMonitoring() {
|
|
3628
|
-
this.rws.addEventListener("open", () => {
|
|
3629
|
-
this.connectionStats.connectTime = Date.now();
|
|
3630
|
-
this.connectionStats.reconnectCount++;
|
|
3631
|
-
this.log("info", "Connection established", {
|
|
3632
|
-
reconnectCount: this.connectionStats.reconnectCount,
|
|
3633
|
-
timeSinceStart: Date.now() - this.connectionStats.connectionStartTime
|
|
3634
|
-
});
|
|
3635
|
-
this.processMessageQueue();
|
|
3636
|
-
});
|
|
3637
|
-
this.rws.addEventListener("close", (event) => {
|
|
3638
|
-
this.log("warn", "Connection closed", {
|
|
3639
|
-
code: event.code,
|
|
3640
|
-
reason: event.reason,
|
|
3641
|
-
wasClean: event.wasClean
|
|
3642
|
-
});
|
|
3643
|
-
this.handleConnectionClose(event.code);
|
|
3644
|
-
});
|
|
3645
|
-
this.rws.addEventListener("error", (event) => {
|
|
3646
|
-
this.connectionStats.totalErrors++;
|
|
3647
|
-
const detail = describeWebSocketEvent(event);
|
|
3648
|
-
this.log("error", "Connection error", {
|
|
3649
|
-
error: detail,
|
|
3650
|
-
rawError: event,
|
|
3651
|
-
totalErrors: this.connectionStats.totalErrors
|
|
3652
|
-
});
|
|
3653
|
-
});
|
|
3654
|
-
}
|
|
3655
|
-
/**
|
|
3656
|
-
* Handle different WebSocket close codes appropriately
|
|
3657
|
-
*/
|
|
3658
|
-
handleConnectionClose(code) {
|
|
3659
|
-
switch (code) {
|
|
3660
|
-
case 1e3:
|
|
3661
|
-
this.log("info", "Normal connection closure");
|
|
3662
|
-
return "stop";
|
|
3663
|
-
case 1001:
|
|
3664
|
-
this.log("info", "Connection going away, will reconnect");
|
|
3665
|
-
return "reconnect";
|
|
3666
|
-
case 1006:
|
|
3667
|
-
this.log("warn", "Abnormal connection closure, will retry");
|
|
3668
|
-
return "retry";
|
|
3669
|
-
case 1008:
|
|
3670
|
-
this.log("error", "Connection closed due to policy violation");
|
|
3671
|
-
this.clearOldQueuedMessages();
|
|
3672
|
-
return "stop";
|
|
3673
|
-
case 4e3:
|
|
3674
|
-
this.log("info", "Connection closed due to terminal notebook error");
|
|
3675
|
-
return "stop";
|
|
3676
|
-
default:
|
|
3677
|
-
this.log("warn", `Unknown close code: ${code}, will reconnect`);
|
|
3678
|
-
return "reconnect";
|
|
3679
|
-
}
|
|
3680
|
-
}
|
|
3681
|
-
/**
|
|
3682
|
-
* Process queued messages when connection is restored
|
|
3683
|
-
*/
|
|
3684
|
-
processMessageQueue() {
|
|
3685
|
-
if (this.messageQueue.length === 0) {
|
|
3686
|
-
return;
|
|
3687
|
-
}
|
|
3688
|
-
this.log("debug", `Processing ${this.messageQueue.length} queued messages`);
|
|
3689
|
-
const queue = [...this.messageQueue];
|
|
3690
|
-
this.messageQueue = [];
|
|
3691
|
-
for (const queuedMessage of queue) {
|
|
3692
|
-
if (Date.now() - queuedMessage.timestamp > this.QUEUE_TIMEOUT) {
|
|
3693
|
-
queuedMessage.reject(new Error("Queued message timed out"));
|
|
3694
|
-
continue;
|
|
3695
|
-
}
|
|
3696
|
-
this.call(queuedMessage.action, queuedMessage.data, queuedMessage.options).then(queuedMessage.resolve).catch(queuedMessage.reject);
|
|
3697
|
-
}
|
|
3698
|
-
}
|
|
3699
|
-
/**
|
|
3700
|
-
* Clear old queued messages to prevent memory leaks
|
|
3701
|
-
*/
|
|
3702
|
-
clearOldQueuedMessages() {
|
|
3703
|
-
const now = Date.now();
|
|
3704
|
-
const originalLength = this.messageQueue.length;
|
|
3705
|
-
this.messageQueue = this.messageQueue.filter((msg) => {
|
|
3706
|
-
const isExpired = now - msg.timestamp > this.QUEUE_TIMEOUT;
|
|
3707
|
-
if (isExpired) {
|
|
3708
|
-
msg.reject(new Error("Queued message expired"));
|
|
3709
|
-
}
|
|
3710
|
-
return !isExpired;
|
|
3711
|
-
});
|
|
3712
|
-
if (originalLength !== this.messageQueue.length) {
|
|
3713
|
-
this.log("debug", `Cleared ${originalLength - this.messageQueue.length} expired messages`);
|
|
3714
|
-
}
|
|
3715
|
-
}
|
|
3716
|
-
/**
|
|
3717
|
-
* Calculate exponential backoff delay
|
|
3718
|
-
*/
|
|
3719
|
-
getBackoffDelay(retryCount) {
|
|
3720
|
-
const baseDelay = 1e3;
|
|
3721
|
-
const maxDelay = 3e4;
|
|
3722
|
-
const delay = Math.min(baseDelay * Math.pow(2, retryCount), maxDelay);
|
|
3723
|
-
return delay + Math.random() * 1e3;
|
|
3724
|
-
}
|
|
3725
|
-
/**
|
|
3726
|
-
* Get comprehensive connection metrics
|
|
3727
|
-
*/
|
|
3728
|
-
getConnectionMetrics() {
|
|
3729
|
-
const now = Date.now();
|
|
3730
|
-
const connectionDuration = this.connectionStats.connectTime > 0 ? now - this.connectionStats.connectTime : 0;
|
|
3731
|
-
return {
|
|
3732
|
-
status: this.status,
|
|
3733
|
-
clientId: this.clientId,
|
|
3734
|
-
isConnected: this.isConnected,
|
|
3735
|
-
isConnecting: this.isConnecting,
|
|
3736
|
-
connectionStats: {
|
|
3737
|
-
...this.connectionStats,
|
|
3738
|
-
connectionDuration,
|
|
3739
|
-
uptime: now - this.connectionStats.connectionStartTime,
|
|
3740
|
-
messagesPerSecond: connectionDuration > 0 ? (this.connectionStats.totalMessages / (connectionDuration / 1e3)).toFixed(2) : "0",
|
|
3741
|
-
errorRate: this.connectionStats.totalMessages > 0 ? (this.connectionStats.totalErrors / this.connectionStats.totalMessages * 100).toFixed(2) + "%" : "0%",
|
|
3742
|
-
timeSinceLastPing: this.connectionStats.lastPingTime > 0 ? now - this.connectionStats.lastPingTime : 0,
|
|
3743
|
-
timeSinceLastPong: this.connectionStats.lastPongTime > 0 ? now - this.connectionStats.lastPongTime : 0
|
|
3744
|
-
},
|
|
3745
|
-
messageQueue: {
|
|
3746
|
-
length: this.messageQueue.length,
|
|
3747
|
-
maxSize: this.MAX_QUEUE_SIZE,
|
|
3748
|
-
oldestMessageAge: this.messageQueue.length > 0 ? now - Math.min(...this.messageQueue.map((m) => m.timestamp)) : 0
|
|
3749
|
-
},
|
|
3750
|
-
config: {
|
|
3751
|
-
pingInterval: this.PING_INTERVAL,
|
|
3752
|
-
queueTimeout: this.QUEUE_TIMEOUT,
|
|
3753
|
-
url: this.url.toString()
|
|
3754
|
-
}
|
|
3755
|
-
};
|
|
3756
|
-
}
|
|
3757
|
-
/**
|
|
3758
|
-
* Get connection health status
|
|
3759
|
-
*/
|
|
3760
|
-
getHealthStatus() {
|
|
3761
|
-
const metrics = this.getConnectionMetrics();
|
|
3762
|
-
const stats = metrics.connectionStats;
|
|
3763
|
-
if (!this.isConnected || stats.timeSinceLastPong > this.PING_INTERVAL * 2 || Number.parseFloat(stats.errorRate) > 50) {
|
|
3764
|
-
return "unhealthy";
|
|
3765
|
-
}
|
|
3766
|
-
if (stats.avgResponseTime > 5e3 || Number.parseFloat(stats.errorRate) > 10 || stats.timeSinceLastPong > this.PING_INTERVAL * 1.5) {
|
|
3767
|
-
return "degraded";
|
|
3768
|
-
}
|
|
3769
|
-
return "healthy";
|
|
3770
|
-
}
|
|
3771
|
-
/**
|
|
3772
|
-
* Reset connection statistics
|
|
3773
|
-
*/
|
|
3774
|
-
resetStats() {
|
|
3775
|
-
this.connectionStats = {
|
|
3776
|
-
connectTime: Date.now(),
|
|
3777
|
-
reconnectCount: 0,
|
|
3778
|
-
lastPingTime: 0,
|
|
3779
|
-
lastPongTime: 0,
|
|
3780
|
-
avgResponseTime: 0,
|
|
3781
|
-
totalMessages: 0,
|
|
3782
|
-
totalErrors: 0,
|
|
3783
|
-
connectionStartTime: Date.now()
|
|
3784
|
-
};
|
|
3785
|
-
this.log("debug", "Connection statistics reset");
|
|
3786
|
-
}
|
|
3787
|
-
/**
|
|
3788
|
-
* Run connection diagnostics
|
|
3789
|
-
*/
|
|
3790
|
-
async runDiagnostics() {
|
|
3791
|
-
const metrics = this.getConnectionMetrics();
|
|
3792
|
-
const status = this.getHealthStatus();
|
|
3793
|
-
const issues = [];
|
|
3794
|
-
const recommendations = [];
|
|
3795
|
-
if (!this.isConnected) {
|
|
3796
|
-
issues.push("Connection is not established");
|
|
3797
|
-
recommendations.push("Check network connectivity and server availability");
|
|
3798
|
-
}
|
|
3799
|
-
if (metrics.connectionStats.timeSinceLastPong > this.PING_INTERVAL * 2) {
|
|
3800
|
-
issues.push("No pong received recently - connection may be stale");
|
|
3801
|
-
recommendations.push("Consider forcing a reconnection");
|
|
3802
|
-
}
|
|
3803
|
-
if (Number.parseFloat(metrics.connectionStats.errorRate) > 10) {
|
|
3804
|
-
issues.push(`High error rate: ${metrics.connectionStats.errorRate}`);
|
|
3805
|
-
recommendations.push("Check server logs and network stability");
|
|
3806
|
-
}
|
|
3807
|
-
if (metrics.messageQueue.length > this.MAX_QUEUE_SIZE * 0.8) {
|
|
3808
|
-
issues.push("Message queue is nearly full");
|
|
3809
|
-
recommendations.push("Check connection stability and consider reducing message frequency");
|
|
3810
|
-
}
|
|
3811
|
-
if (metrics.connectionStats.avgResponseTime > 5e3) {
|
|
3812
|
-
issues.push("High average response time");
|
|
3813
|
-
recommendations.push("Check network latency and server performance");
|
|
3814
|
-
}
|
|
3815
|
-
this.log("info", "Connection diagnostics completed", {
|
|
3816
|
-
status,
|
|
3817
|
-
issueCount: issues.length,
|
|
3818
|
-
recommendationCount: recommendations.length
|
|
3819
|
-
});
|
|
3820
|
-
return {
|
|
3821
|
-
status,
|
|
3822
|
-
metrics,
|
|
3823
|
-
issues,
|
|
3824
|
-
recommendations
|
|
3825
3634
|
};
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
* Periodic maintenance - clean up old data, run health checks
|
|
3829
|
-
*/
|
|
3830
|
-
startPeriodicMaintenance() {
|
|
3831
|
-
this.disposables.add("maintenance", () => {
|
|
3832
|
-
const maintenanceInterval = setInterval(
|
|
3833
|
-
() => {
|
|
3834
|
-
this.clearOldQueuedMessages();
|
|
3835
|
-
if (this.options.debug) {
|
|
3836
|
-
const health = this.getHealthStatus();
|
|
3837
|
-
const metrics = this.getConnectionMetrics();
|
|
3838
|
-
this.log("debug", "Periodic health check", {
|
|
3839
|
-
health,
|
|
3840
|
-
messageCount: metrics.connectionStats.totalMessages,
|
|
3841
|
-
errorCount: metrics.connectionStats.totalErrors,
|
|
3842
|
-
queueLength: metrics.messageQueue.length
|
|
3843
|
-
});
|
|
3844
|
-
}
|
|
3845
|
-
},
|
|
3846
|
-
5 * 60 * 1e3
|
|
3847
|
-
);
|
|
3848
|
-
return {
|
|
3849
|
-
dispose: () => {
|
|
3850
|
-
clearInterval(maintenanceInterval);
|
|
3851
|
-
}
|
|
3852
|
-
};
|
|
3853
|
-
});
|
|
3635
|
+
this.disposables.add(`close_${nanoid()}`, disposable);
|
|
3636
|
+
return disposable;
|
|
3854
3637
|
}
|
|
3855
3638
|
};
|
|
3856
3639
|
_Transport_instances = new WeakSet();
|
|
@@ -3900,7 +3683,7 @@ connect_fn = function() {
|
|
|
3900
3683
|
};
|
|
3901
3684
|
const closeHandler = (event) => {
|
|
3902
3685
|
const detail = describeWebSocketEvent(event);
|
|
3903
|
-
if (
|
|
3686
|
+
if (event.code === 1008 || event.code === 4e3) {
|
|
3904
3687
|
cleanup();
|
|
3905
3688
|
this.connectPromise = null;
|
|
3906
3689
|
reject(new ConnectionFailedError(`WebSocket connection failed: ${detail}`, event));
|
|
@@ -3932,21 +3715,13 @@ startPeriodicPing_fn = function() {
|
|
|
3932
3715
|
this.disposables.add("pingInterval", () => {
|
|
3933
3716
|
const interval = setInterval(async () => {
|
|
3934
3717
|
try {
|
|
3935
|
-
this.connectionStats.lastPingTime = Date.now();
|
|
3936
3718
|
this.log("debug", "Sending periodic ping");
|
|
3937
|
-
const startTime = Date.now();
|
|
3938
3719
|
await this.invoke("ping");
|
|
3939
|
-
this.
|
|
3940
|
-
const pingTime = this.connectionStats.lastPongTime - startTime;
|
|
3941
|
-
this.log("debug", `Ping successful`, { pingTime });
|
|
3720
|
+
this.log("debug", "Ping successful");
|
|
3942
3721
|
} catch (error) {
|
|
3943
3722
|
this.log("error", "Ping failed", {
|
|
3944
3723
|
error: error instanceof Error ? error.message : String(error)
|
|
3945
3724
|
});
|
|
3946
|
-
if (Date.now() - this.connectionStats.lastPongTime > this.PING_INTERVAL * 3) {
|
|
3947
|
-
this.log("warn", "Connection appears dead, forcing reconnection");
|
|
3948
|
-
this.rws.reconnect();
|
|
3949
|
-
}
|
|
3950
3725
|
}
|
|
3951
3726
|
}, this.PING_INTERVAL);
|
|
3952
3727
|
return {
|
|
@@ -3959,6 +3734,10 @@ startPeriodicPing_fn = function() {
|
|
|
3959
3734
|
};
|
|
3960
3735
|
|
|
3961
3736
|
// node_modules/mitt/dist/mitt.mjs
|
|
3737
|
+
var mitt_exports = {};
|
|
3738
|
+
__export(mitt_exports, {
|
|
3739
|
+
default: () => mitt_default
|
|
3740
|
+
});
|
|
3962
3741
|
function mitt_default(n) {
|
|
3963
3742
|
return { all: n = n || /* @__PURE__ */ new Map(), on: function(t, e) {
|
|
3964
3743
|
var i = n.get(t);
|
|
@@ -3977,11 +3756,20 @@ function mitt_default(n) {
|
|
|
3977
3756
|
}
|
|
3978
3757
|
|
|
3979
3758
|
// src/events/index.ts
|
|
3759
|
+
var createMitt = mitt_default ?? mitt_exports;
|
|
3980
3760
|
function mittWithOnce(all) {
|
|
3981
|
-
const inst =
|
|
3761
|
+
const inst = createMitt(all);
|
|
3982
3762
|
inst.once = (type, fn) => {
|
|
3983
|
-
|
|
3984
|
-
|
|
3763
|
+
const onceHandler = (event) => {
|
|
3764
|
+
inst.off(type, onceHandler);
|
|
3765
|
+
fn(event);
|
|
3766
|
+
};
|
|
3767
|
+
inst.on(type, onceHandler);
|
|
3768
|
+
return {
|
|
3769
|
+
dispose: () => {
|
|
3770
|
+
inst.off(type, onceHandler);
|
|
3771
|
+
}
|
|
3772
|
+
};
|
|
3985
3773
|
};
|
|
3986
3774
|
return inst;
|
|
3987
3775
|
}
|
|
@@ -3996,11 +3784,11 @@ var EventManager = class _EventManager {
|
|
|
3996
3784
|
this.emitter.on(event, callback);
|
|
3997
3785
|
return { dispose };
|
|
3998
3786
|
}
|
|
3999
|
-
emit(event, data) {
|
|
4000
|
-
this.emitter.emit(event, data);
|
|
3787
|
+
emit(event, ...data) {
|
|
3788
|
+
this.emitter.emit(event, data.length > 1 ? data : data[0]);
|
|
4001
3789
|
}
|
|
4002
3790
|
once(event, callback) {
|
|
4003
|
-
this.emitter.once(event, callback);
|
|
3791
|
+
return this.emitter.once(event, callback);
|
|
4004
3792
|
}
|
|
4005
3793
|
static make() {
|
|
4006
3794
|
return new _EventManager();
|
|
@@ -4500,11 +4288,11 @@ var Beacon = class {
|
|
|
4500
4288
|
});
|
|
4501
4289
|
},
|
|
4502
4290
|
{
|
|
4503
|
-
retries: this.options.retry?.retries
|
|
4504
|
-
minTimeout: this.options.retry?.minTimeout
|
|
4505
|
-
maxTimeout: this.options.retry?.maxTimeout
|
|
4506
|
-
factor: this.options.retry?.factor
|
|
4507
|
-
randomize: this.options.retry?.randomize
|
|
4291
|
+
retries: this.options.retry?.retries ?? 3,
|
|
4292
|
+
minTimeout: this.options.retry?.minTimeout ?? 1e3,
|
|
4293
|
+
maxTimeout: this.options.retry?.maxTimeout ?? 5e3,
|
|
4294
|
+
factor: this.options.retry?.factor ?? 2,
|
|
4295
|
+
randomize: this.options.retry?.randomize ?? true,
|
|
4508
4296
|
onRetry: (error, attempt) => {
|
|
4509
4297
|
if (this.options.debug) {
|
|
4510
4298
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -4574,11 +4362,11 @@ var Beacon = class {
|
|
|
4574
4362
|
});
|
|
4575
4363
|
},
|
|
4576
4364
|
{
|
|
4577
|
-
retries: this.options.retry?.retries
|
|
4578
|
-
minTimeout: this.options.retry?.minTimeout
|
|
4579
|
-
maxTimeout: this.options.retry?.maxTimeout
|
|
4580
|
-
factor: this.options.retry?.factor
|
|
4581
|
-
randomize: this.options.retry?.randomize
|
|
4365
|
+
retries: this.options.retry?.retries ?? 3,
|
|
4366
|
+
minTimeout: this.options.retry?.minTimeout ?? 1e3,
|
|
4367
|
+
maxTimeout: this.options.retry?.maxTimeout ?? 5e3,
|
|
4368
|
+
factor: this.options.retry?.factor ?? 2,
|
|
4369
|
+
randomize: this.options.retry?.randomize ?? true,
|
|
4582
4370
|
onRetry: (error, attempt) => {
|
|
4583
4371
|
if (this.options.debug) {
|
|
4584
4372
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -4639,7 +4427,7 @@ var Beacon = class {
|
|
|
4639
4427
|
* Listen for beacon events (one-time)
|
|
4640
4428
|
*/
|
|
4641
4429
|
once(event, handler) {
|
|
4642
|
-
this.eventEmitter.once(event, handler);
|
|
4430
|
+
return this.eventEmitter.once(event, handler);
|
|
4643
4431
|
}
|
|
4644
4432
|
/**
|
|
4645
4433
|
* Ping the beacon to check if it's responsive
|
|
@@ -4872,12 +4660,20 @@ var NotebookApi = class {
|
|
|
4872
4660
|
return instance;
|
|
4873
4661
|
}
|
|
4874
4662
|
};
|
|
4663
|
+
function normalizeApiBaseUrl(url) {
|
|
4664
|
+
const baseUrl = new URL(url);
|
|
4665
|
+
const pathname = baseUrl.pathname.replace(/\/+$/, "");
|
|
4666
|
+
baseUrl.pathname = pathname === "" || pathname === "/" ? "/v1/" : `${pathname}/`;
|
|
4667
|
+
baseUrl.search = "";
|
|
4668
|
+
baseUrl.hash = "";
|
|
4669
|
+
return baseUrl.toString();
|
|
4670
|
+
}
|
|
4875
4671
|
var Client = class {
|
|
4876
4672
|
constructor(token, url = "https://api.phpsandbox.io/v1", options = {}) {
|
|
4877
4673
|
this.fetch = globalThis.fetch;
|
|
4878
4674
|
this.notebook = new NotebookApi(this);
|
|
4879
4675
|
this.options = Object.assign({ startClosed: true }, options);
|
|
4880
|
-
this.baseUrl = url;
|
|
4676
|
+
this.baseUrl = normalizeApiBaseUrl(url);
|
|
4881
4677
|
if (options.fetch) {
|
|
4882
4678
|
this.fetch = options.fetch;
|
|
4883
4679
|
}
|
|
@@ -4891,17 +4687,17 @@ var Client = class {
|
|
|
4891
4687
|
return this.makeRequest("GET", path);
|
|
4892
4688
|
}
|
|
4893
4689
|
post(path, body) {
|
|
4894
|
-
return this.makeRequest("POST", path, { body: body ? JSON.stringify(body)
|
|
4690
|
+
return this.makeRequest("POST", path, { body: body === void 0 ? void 0 : JSON.stringify(body) });
|
|
4895
4691
|
}
|
|
4896
4692
|
delete(path) {
|
|
4897
4693
|
return this.makeRequest("DELETE", path);
|
|
4898
4694
|
}
|
|
4899
4695
|
put(path, body) {
|
|
4900
|
-
return this.makeRequest("PUT", path, { body: body ? JSON.stringify(body)
|
|
4696
|
+
return this.makeRequest("PUT", path, { body: body === void 0 ? void 0 : JSON.stringify(body) });
|
|
4901
4697
|
}
|
|
4902
4698
|
async makeRequest(method, path, init) {
|
|
4903
4699
|
const response = await this.fetch(
|
|
4904
|
-
new Request(new URL(
|
|
4700
|
+
new Request(new URL(path.replace(/^\//, ""), this.baseUrl), {
|
|
4905
4701
|
method,
|
|
4906
4702
|
...init,
|
|
4907
4703
|
headers: this.headers
|
|
@@ -5020,7 +4816,7 @@ var NotebookInstance = class {
|
|
|
5020
4816
|
this.log = new Log(this);
|
|
5021
4817
|
this.repl = new Repl(this);
|
|
5022
4818
|
this.container = new Container(this);
|
|
5023
|
-
this.laravel = new
|
|
4819
|
+
this.laravel = new Laravel(this);
|
|
5024
4820
|
this.shell = new Shell(this);
|
|
5025
4821
|
this.git = new Git(this);
|
|
5026
4822
|
this.services = new Services(this);
|
|
@@ -5078,24 +4874,12 @@ var NotebookInstance = class {
|
|
|
5078
4874
|
!this.socket.isClosed && this.socket.disconnect();
|
|
5079
4875
|
}
|
|
5080
4876
|
connected() {
|
|
5081
|
-
|
|
5082
|
-
if (terminalError) {
|
|
5083
|
-
return Promise.reject(terminalError);
|
|
5084
|
-
}
|
|
5085
|
-
if (this.socket.isConnected) {
|
|
5086
|
-
return Promise.resolve(this);
|
|
5087
|
-
}
|
|
5088
|
-
return new Promise((resolve, reject) => {
|
|
5089
|
-
try {
|
|
5090
|
-
this.socket.onDidConnect(() => resolve(this));
|
|
5091
|
-
this.socket.onDidClose(() => reject(new Error("Connection closed")));
|
|
5092
|
-
this.socket.onDidBootError((error) => reject(error));
|
|
5093
|
-
} catch (e) {
|
|
5094
|
-
reject(e);
|
|
5095
|
-
}
|
|
5096
|
-
});
|
|
4877
|
+
return this.waitForSocketConnection({ rejectOnClose: true });
|
|
5097
4878
|
}
|
|
5098
4879
|
whenConnected() {
|
|
4880
|
+
return this.waitForSocketConnection({ rejectOnClose: false });
|
|
4881
|
+
}
|
|
4882
|
+
waitForSocketConnection(options) {
|
|
5099
4883
|
const terminalError = this.socket.getTerminalError();
|
|
5100
4884
|
if (terminalError) {
|
|
5101
4885
|
return Promise.reject(terminalError);
|
|
@@ -5104,11 +4888,30 @@ var NotebookInstance = class {
|
|
|
5104
4888
|
return Promise.resolve(this);
|
|
5105
4889
|
}
|
|
5106
4890
|
return new Promise((resolve, reject) => {
|
|
4891
|
+
const disposables = [];
|
|
4892
|
+
let settled = false;
|
|
4893
|
+
const cleanup = () => {
|
|
4894
|
+
for (const disposable of disposables) {
|
|
4895
|
+
disposable.dispose();
|
|
4896
|
+
}
|
|
4897
|
+
disposables.length = 0;
|
|
4898
|
+
};
|
|
4899
|
+
const settle = (callback) => {
|
|
4900
|
+
if (settled) {
|
|
4901
|
+
return;
|
|
4902
|
+
}
|
|
4903
|
+
settled = true;
|
|
4904
|
+
cleanup();
|
|
4905
|
+
callback();
|
|
4906
|
+
};
|
|
5107
4907
|
try {
|
|
5108
|
-
this.socket.onDidConnect(() => resolve(this));
|
|
5109
|
-
|
|
4908
|
+
disposables.push(this.socket.onDidConnect(() => settle(() => resolve(this))));
|
|
4909
|
+
if (options.rejectOnClose) {
|
|
4910
|
+
disposables.push(this.socket.onDidClose(() => settle(() => reject(new Error("Connection closed")))));
|
|
4911
|
+
}
|
|
4912
|
+
disposables.push(this.socket.onDidBootError((error) => settle(() => reject(error))));
|
|
5110
4913
|
} catch (e) {
|
|
5111
|
-
reject(e);
|
|
4914
|
+
settle(() => reject(e));
|
|
5112
4915
|
}
|
|
5113
4916
|
});
|
|
5114
4917
|
}
|
|
@@ -5271,6 +5074,7 @@ export {
|
|
|
5271
5074
|
Client,
|
|
5272
5075
|
CommandError,
|
|
5273
5076
|
ErrorEvent,
|
|
5077
|
+
FileChangeFilter,
|
|
5274
5078
|
FileChangeType,
|
|
5275
5079
|
FileType,
|
|
5276
5080
|
Filesystem,
|
|
@@ -5326,4 +5130,3 @@ reconnecting-websocket/dist/reconnecting-websocket-mjs.js:
|
|
|
5326
5130
|
* License MIT
|
|
5327
5131
|
*)
|
|
5328
5132
|
*/
|
|
5329
|
-
//# sourceMappingURL=phpsandbox-sdk.esm.js.map
|