@dxos/teleport 0.3.5-main.8a2ebe5 → 0.3.5-main.8a3798d

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.
@@ -215,13 +215,14 @@ var import_node_stream2 = require("node:stream");
215
215
  var import_async3 = require("@dxos/async");
216
216
  var import_context = require("@dxos/context");
217
217
  var import_debug = require("@dxos/debug");
218
- var import_invariant2 = require("@dxos/invariant");
218
+ var import_invariant3 = require("@dxos/invariant");
219
219
  var import_log3 = require("@dxos/log");
220
220
  var import_protocols = require("@dxos/protocols");
221
221
 
222
222
  // packages/core/mesh/teleport/src/muxing/balancer.ts
223
223
  var varint = __toESM(require("varint"));
224
224
  var import_async2 = require("@dxos/async");
225
+ var import_invariant2 = require("@dxos/invariant");
225
226
  var import_log2 = require("@dxos/log");
226
227
  var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/muxing/balancer.ts";
227
228
  var MAX_CHUNK_SIZE = 8192;
@@ -233,6 +234,7 @@ var Balancer = class {
233
234
  this._framer = new Framer();
234
235
  this._sendBuffers = /* @__PURE__ */ new Map();
235
236
  this._receiveBuffers = /* @__PURE__ */ new Map();
237
+ this._sending = false;
236
238
  this.incomingData = new import_async2.Event();
237
239
  this.stream = this._framer.stream;
238
240
  this._channels.push(_sysChannelId);
@@ -251,43 +253,19 @@ var Balancer = class {
251
253
  this._channels.push(channel);
252
254
  }
253
255
  pushData(data, trigger, channelId) {
254
- const noCalls = this._sendBuffers.size === 0;
255
- if (!this._channels.includes(channelId)) {
256
- throw new Error(`Unknown channel ${channelId}`);
257
- }
258
- if (!this._sendBuffers.has(channelId)) {
259
- this._sendBuffers.set(channelId, []);
260
- }
261
- const sendBuffer = this._sendBuffers.get(channelId);
262
- const chunks = [];
263
- for (let idx = 0; idx < data.length; idx += MAX_CHUNK_SIZE) {
264
- chunks.push(data.subarray(idx, idx + MAX_CHUNK_SIZE));
265
- }
266
- chunks.forEach((chunk, index) => {
267
- const msg = encodeChunk({
268
- chunk,
269
- channelId,
270
- dataLength: index === 0 ? data.length : void 0
271
- });
272
- sendBuffer.push({
273
- msg,
274
- trigger: index === chunks.length - 1 ? trigger : void 0
275
- });
276
- });
277
- if (noCalls) {
278
- this._sendChunk().catch((err) => import_log2.log.catch(err, void 0, {
279
- F: __dxlog_file2,
280
- L: 100,
281
- S: this,
282
- C: (f, a) => f(...a)
283
- }));
284
- }
256
+ this._enqueueChunk(data, trigger, channelId);
257
+ this._sendChunks().catch((err) => import_log2.log.catch(err, void 0, {
258
+ F: __dxlog_file2,
259
+ L: 75,
260
+ S: this,
261
+ C: (f, a) => f(...a)
262
+ }));
285
263
  }
286
264
  destroy() {
287
265
  if (this._sendBuffers.size !== 0) {
288
266
  import_log2.log.warn("destroying balancer with pending calls", void 0, {
289
267
  F: __dxlog_file2,
290
- L: 106,
268
+ L: 80,
291
269
  S: this,
292
270
  C: (f, a) => f(...a)
293
271
  });
@@ -328,36 +306,99 @@ var Balancer = class {
328
306
  this._lastCallerIndex = (this._lastCallerIndex + 1) % this._channels.length;
329
307
  return this._channels[index];
330
308
  }
309
+ _enqueueChunk(data, trigger, channelId) {
310
+ if (!this._channels.includes(channelId)) {
311
+ throw new Error(`Unknown channel ${channelId}`);
312
+ }
313
+ if (!this._sendBuffers.has(channelId)) {
314
+ this._sendBuffers.set(channelId, []);
315
+ }
316
+ const sendBuffer = this._sendBuffers.get(channelId);
317
+ const chunks = [];
318
+ for (let idx = 0; idx < data.length; idx += MAX_CHUNK_SIZE) {
319
+ chunks.push(data.subarray(idx, idx + MAX_CHUNK_SIZE));
320
+ }
321
+ chunks.forEach((chunk, index) => {
322
+ const msg = encodeChunk({
323
+ chunk,
324
+ channelId,
325
+ dataLength: index === 0 ? data.length : void 0
326
+ });
327
+ sendBuffer.push({
328
+ msg,
329
+ trigger: index === chunks.length - 1 ? trigger : void 0
330
+ });
331
+ });
332
+ }
333
+ // get the next chunk or null if there are no chunks remaining
331
334
  _getNextChunk() {
332
335
  let chunk;
333
- while (!chunk) {
336
+ while (this._sendBuffers.size > 0) {
334
337
  const channelId = this._getNextCallerId();
335
338
  const sendBuffer = this._sendBuffers.get(channelId);
336
339
  if (!sendBuffer) {
337
340
  continue;
338
341
  }
339
342
  chunk = sendBuffer.shift();
343
+ if (!chunk) {
344
+ continue;
345
+ }
340
346
  if (sendBuffer.length === 0) {
341
347
  this._sendBuffers.delete(channelId);
342
348
  }
349
+ return chunk;
343
350
  }
344
- return chunk;
351
+ return null;
345
352
  }
346
- async _sendChunk() {
347
- if (this._sendBuffers.size === 0) {
353
+ async _sendChunks() {
354
+ if (this._sending) {
348
355
  return;
349
356
  }
350
- if (!this._framer.writable) {
351
- await this._framer.drain.waitForCount(1);
352
- }
353
- const chunk = this._getNextChunk();
354
- try {
355
- await this._framer.port.send(chunk.msg);
356
- chunk.trigger?.wake();
357
- } catch (err) {
358
- chunk.trigger?.throw(err);
357
+ this._sending = true;
358
+ let chunk;
359
+ chunk = this._getNextChunk();
360
+ while (chunk) {
361
+ if (!this._framer.writable) {
362
+ (0, import_log2.log)("PAUSE for drain", void 0, {
363
+ F: __dxlog_file2,
364
+ L: 179,
365
+ S: this,
366
+ C: (f, a) => f(...a)
367
+ });
368
+ await this._framer.drain.waitForCount(1);
369
+ (0, import_log2.log)("RESUME for drain", void 0, {
370
+ F: __dxlog_file2,
371
+ L: 181,
372
+ S: this,
373
+ C: (f, a) => f(...a)
374
+ });
375
+ }
376
+ try {
377
+ await this._framer.port.send(chunk.msg);
378
+ chunk.trigger?.wake();
379
+ } catch (err) {
380
+ (0, import_log2.log)("Error sending chunk", {
381
+ err
382
+ }, {
383
+ F: __dxlog_file2,
384
+ L: 187,
385
+ S: this,
386
+ C: (f, a) => f(...a)
387
+ });
388
+ chunk.trigger?.throw(err);
389
+ }
390
+ chunk = this._getNextChunk();
359
391
  }
360
- await this._sendChunk();
392
+ (0, import_invariant2.invariant)(this._sendBuffers.size === 0, "sendBuffers not empty", {
393
+ F: __dxlog_file2,
394
+ L: 192,
395
+ S: this,
396
+ A: [
397
+ "this._sendBuffers.size === 0",
398
+ "'sendBuffers not empty'"
399
+ ]
400
+ });
401
+ this._sending = false;
361
402
  }
362
403
  };
363
404
  var encodeChunk = ({ channelId, dataLength, chunk }) => {
@@ -390,6 +431,8 @@ var decodeChunk = (data, withLength) => {
390
431
  // packages/core/mesh/teleport/src/muxing/muxer.ts
391
432
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/muxing/muxer.ts";
392
433
  var Command = import_protocols.schema.getCodecForType("dxos.mesh.muxer.Command");
434
+ var DEFAULT_SEND_COMMAND_TIMEOUT = 6e4;
435
+ var DESTROY_COMMAND_SEND_TIMEOUT = 5e3;
393
436
  var STATS_INTERVAL = 1e3;
394
437
  var MAX_SAFE_FRAME_SIZE = 1e6;
395
438
  var SYSTEM_CHANNEL_ID = 0;
@@ -401,9 +444,9 @@ var Muxer = class {
401
444
  this._channelsByTag = /* @__PURE__ */ new Map();
402
445
  this._ctx = new import_context.Context();
403
446
  this._nextId = 1;
404
- this._destroyed = false;
405
- this._destroying = false;
406
447
  this._closing = false;
448
+ this._destroying = false;
449
+ this._disposed = false;
407
450
  this._lastStats = void 0;
408
451
  this._lastChannelStats = /* @__PURE__ */ new Map();
409
452
  this.afterClosed = new import_async3.Event();
@@ -412,7 +455,6 @@ var Muxer = class {
412
455
  this._balancer.incomingData.on(async (msg) => {
413
456
  await this._handleCommand(Command.decode(msg));
414
457
  });
415
- (0, import_async3.scheduleTaskInterval)(this._ctx, async () => this._emitStats(), STATS_INTERVAL);
416
458
  }
417
459
  /**
418
460
  * Creates a duplex Node.js-style stream.
@@ -425,9 +467,9 @@ var Muxer = class {
425
467
  tag,
426
468
  contentType: opts.contentType
427
469
  });
428
- (0, import_invariant2.invariant)(!channel.push, `Channel already open: ${tag}`, {
470
+ (0, import_invariant3.invariant)(!channel.push, `Channel already open: ${tag}`, {
429
471
  F: __dxlog_file3,
430
- L: 138,
472
+ L: 140,
431
473
  S: this,
432
474
  A: [
433
475
  "!channel.push",
@@ -473,9 +515,9 @@ var Muxer = class {
473
515
  tag,
474
516
  contentType: opts.contentType
475
517
  });
476
- (0, import_invariant2.invariant)(!channel.push, `Channel already open: ${tag}`, {
518
+ (0, import_invariant3.invariant)(!channel.push, `Channel already open: ${tag}`, {
477
519
  F: __dxlog_file3,
478
- L: 190,
520
+ L: 192,
479
521
  S: this,
480
522
  A: [
481
523
  "!channel.push",
@@ -493,13 +535,13 @@ var Muxer = class {
493
535
  }
494
536
  };
495
537
  const port = {
496
- send: async (data) => {
497
- await this._sendData(channel, data);
538
+ send: async (data, timeout) => {
539
+ await this._sendData(channel, data, timeout);
498
540
  },
499
541
  subscribe: (cb) => {
500
- (0, import_invariant2.invariant)(!callback, "Only one subscriber is allowed", {
542
+ (0, import_invariant3.invariant)(!callback, "Only one subscriber is allowed", {
501
543
  F: __dxlog_file3,
502
- L: 212,
544
+ L: 214,
503
545
  S: this,
504
546
  A: [
505
547
  "!callback",
@@ -532,7 +574,7 @@ var Muxer = class {
532
574
  if (this._destroying) {
533
575
  (0, import_log3.log)("already destroying, ignoring graceful close request", void 0, {
534
576
  F: __dxlog_file3,
535
- L: 245,
577
+ L: 247,
536
578
  S: this,
537
579
  C: (f, a) => f(...a)
538
580
  });
@@ -541,7 +583,7 @@ var Muxer = class {
541
583
  if (this._closing) {
542
584
  (0, import_log3.log)("already closing, ignoring graceful close request", void 0, {
543
585
  F: __dxlog_file3,
544
- L: 249,
586
+ L: 251,
545
587
  S: this,
546
588
  C: (f, a) => f(...a)
547
589
  });
@@ -552,12 +594,12 @@ var Muxer = class {
552
594
  close: {
553
595
  error: err?.message
554
596
  }
555
- }, SYSTEM_CHANNEL_ID).catch(async (err2) => {
597
+ }, SYSTEM_CHANNEL_ID, DESTROY_COMMAND_SEND_TIMEOUT).catch(async (err2) => {
556
598
  (0, import_log3.log)("error sending close command", {
557
599
  err: err2
558
600
  }, {
559
601
  F: __dxlog_file3,
560
- L: 263,
602
+ L: 266,
561
603
  S: this,
562
604
  C: (f, a) => f(...a)
563
605
  });
@@ -579,7 +621,7 @@ var Muxer = class {
579
621
  if (this._destroying) {
580
622
  (0, import_log3.log)("already destroying, ignoring destroy request", void 0, {
581
623
  F: __dxlog_file3,
582
- L: 284,
624
+ L: 287,
583
625
  S: this,
584
626
  C: (f, a) => f(...a)
585
627
  });
@@ -590,7 +632,7 @@ var Muxer = class {
590
632
  if (this._closing) {
591
633
  (0, import_log3.log)("destroy cancelling graceful close", void 0, {
592
634
  F: __dxlog_file3,
593
- L: 290,
635
+ L: 293,
594
636
  S: this,
595
637
  C: (f, a) => f(...a)
596
638
  });
@@ -605,7 +647,7 @@ var Muxer = class {
605
647
  err: err2
606
648
  }, {
607
649
  F: __dxlog_file3,
608
- L: 303,
650
+ L: 306,
609
651
  S: this,
610
652
  C: (f, a) => f(...a)
611
653
  });
@@ -616,7 +658,7 @@ var Muxer = class {
616
658
  err: err2
617
659
  }, {
618
660
  F: __dxlog_file3,
619
- L: 308,
661
+ L: 311,
620
662
  S: this,
621
663
  C: (f, a) => f(...a)
622
664
  });
@@ -624,10 +666,10 @@ var Muxer = class {
624
666
  }
625
667
  // complete the termination, graceful or otherwise
626
668
  async dispose(err) {
627
- if (this._destroyed) {
669
+ if (this._disposed) {
628
670
  (0, import_log3.log)("already destroyed, ignoring dispose request", void 0, {
629
671
  F: __dxlog_file3,
630
- L: 316,
672
+ L: 319,
631
673
  S: this,
632
674
  C: (f, a) => f(...a)
633
675
  });
@@ -638,18 +680,18 @@ var Muxer = class {
638
680
  for (const channel of this._channelsByTag.values()) {
639
681
  channel.destroy?.(err);
640
682
  }
641
- this._destroyed = true;
683
+ this._disposed = true;
642
684
  this.afterClosed.emit(err);
643
685
  this._channelsByLocalId.clear();
644
686
  this._channelsByTag.clear();
645
687
  }
646
688
  async _handleCommand(cmd) {
647
- if (this._destroyed) {
689
+ if (this._disposed) {
648
690
  import_log3.log.warn("Received command after destroy", {
649
691
  cmd
650
692
  }, {
651
693
  F: __dxlog_file3,
652
- L: 338,
694
+ L: 341,
653
695
  S: this,
654
696
  C: (f, a) => f(...a)
655
697
  });
@@ -659,7 +701,7 @@ var Muxer = class {
659
701
  if (!this._closing) {
660
702
  (0, import_log3.log)("received peer close, initiating my own graceful close", void 0, {
661
703
  F: __dxlog_file3,
662
- L: 344,
704
+ L: 347,
663
705
  S: this,
664
706
  C: (f, a) => f(...a)
665
707
  });
@@ -667,7 +709,7 @@ var Muxer = class {
667
709
  } else {
668
710
  (0, import_log3.log)("received close from peer, already closing", void 0, {
669
711
  F: __dxlog_file3,
670
- L: 347,
712
+ L: 350,
671
713
  S: this,
672
714
  C: (f, a) => f(...a)
673
715
  });
@@ -696,7 +738,7 @@ var Muxer = class {
696
738
  tag: stream.tag
697
739
  }, {
698
740
  F: __dxlog_file3,
699
- L: 376,
741
+ L: 379,
700
742
  S: this,
701
743
  C: (f, a) => f(...a)
702
744
  });
@@ -705,16 +747,21 @@ var Muxer = class {
705
747
  stream.push(cmd.data.data);
706
748
  }
707
749
  }
708
- async _sendCommand(cmd, channelId = -1) {
750
+ async _sendCommand(cmd, channelId = -1, timeout = DEFAULT_SEND_COMMAND_TIMEOUT) {
709
751
  try {
710
752
  const trigger = new import_async3.Trigger();
711
753
  this._balancer.pushData(Command.encode(cmd), trigger, channelId);
712
- await trigger.wait();
754
+ await trigger.wait({
755
+ timeout
756
+ });
713
757
  } catch (err) {
714
758
  await this.destroy(err);
715
759
  }
716
760
  }
717
761
  _getOrCreateStream(params) {
762
+ if (this._channelsByTag.size === 0) {
763
+ (0, import_async3.scheduleTaskInterval)(this._ctx, async () => this._emitStats(), STATS_INTERVAL);
764
+ }
718
765
  let channel = this._channelsByTag.get(params.tag);
719
766
  if (!channel) {
720
767
  channel = {
@@ -736,14 +783,14 @@ var Muxer = class {
736
783
  }
737
784
  return channel;
738
785
  }
739
- async _sendData(channel, data) {
786
+ async _sendData(channel, data, timeout) {
740
787
  if (data.length > MAX_SAFE_FRAME_SIZE) {
741
788
  import_log3.log.warn("frame size exceeds maximum safe value", {
742
789
  size: data.length,
743
790
  threshold: MAX_SAFE_FRAME_SIZE
744
791
  }, {
745
792
  F: __dxlog_file3,
746
- L: 419,
793
+ L: 425,
747
794
  S: this,
748
795
  C: (f, a) => f(...a)
749
796
  });
@@ -758,7 +805,7 @@ var Muxer = class {
758
805
  channelId: channel.remoteId,
759
806
  data
760
807
  }
761
- }, channel.id);
808
+ }, channel.id, timeout);
762
809
  }
763
810
  _destroyChannel(channel, err) {
764
811
  if (channel.destroy) {
@@ -768,7 +815,7 @@ var Muxer = class {
768
815
  this._channelsByTag.delete(channel.tag);
769
816
  }
770
817
  async _emitStats() {
771
- if (this._destroyed || this._destroying) {
818
+ if (this._disposed || this._destroying) {
772
819
  this._lastStats = void 0;
773
820
  this._lastChannelStats.clear();
774
821
  return;
@@ -813,7 +860,7 @@ var Muxer = class {
813
860
  var import_async4 = require("@dxos/async");
814
861
  var import_context2 = require("@dxos/context");
815
862
  var import_debug2 = require("@dxos/debug");
816
- var import_invariant3 = require("@dxos/invariant");
863
+ var import_invariant4 = require("@dxos/invariant");
817
864
  var import_keys = require("@dxos/keys");
818
865
  var import_log4 = require("@dxos/log");
819
866
  var import_protocols2 = require("@dxos/protocols");
@@ -830,6 +877,8 @@ function _ts_decorate(decorators, target, key, desc) {
830
877
  return c > 3 && r && Object.defineProperty(target, key, r), r;
831
878
  }
832
879
  var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/teleport.ts";
880
+ var CONTROL_HEARTBEAT_INTERVAL = 1e4;
881
+ var CONTROL_HEARTBEAT_TIMEOUT = 6e4;
833
882
  var Teleport = class {
834
883
  constructor({ initiator, localPeerId, remotePeerId }) {
835
884
  this._ctx = new import_context2.Context({
@@ -837,7 +886,7 @@ var Teleport = class {
837
886
  void this.destroy(err).catch(() => {
838
887
  import_log4.log.error("Error during destroy", err, {
839
888
  F: __dxlog_file4,
840
- L: 44,
889
+ L: 47,
841
890
  S: this,
842
891
  C: (f, a) => f(...a)
843
892
  });
@@ -846,21 +895,21 @@ var Teleport = class {
846
895
  });
847
896
  this._muxer = new Muxer();
848
897
  this._control = new ControlExtension({
849
- heartbeatInterval: 1e4,
850
- heartbeatTimeout: 1e4,
898
+ heartbeatInterval: CONTROL_HEARTBEAT_INTERVAL,
899
+ heartbeatTimeout: CONTROL_HEARTBEAT_TIMEOUT,
851
900
  onTimeout: () => {
852
901
  if (this._destroying || this._aborting) {
853
902
  return;
854
903
  }
855
- (0, import_log4.log)("destroy teleport due to onTimeout in ControlExtension", void 0, {
904
+ (0, import_log4.log)("abort teleport due to onTimeout in ControlExtension", void 0, {
856
905
  F: __dxlog_file4,
857
- L: 59,
906
+ L: 62,
858
907
  S: this,
859
908
  C: (f, a) => f(...a)
860
909
  });
861
- this.destroy(new import_protocols2.TimeoutError("control extension")).catch((err) => import_log4.log.catch(err, void 0, {
910
+ this.abort(new import_protocols2.TimeoutError("control extension")).catch((err) => import_log4.log.catch(err, void 0, {
862
911
  F: __dxlog_file4,
863
- L: 60,
912
+ L: 63,
864
913
  S: this,
865
914
  C: (f, a) => f(...a)
866
915
  }));
@@ -871,27 +920,27 @@ var Teleport = class {
871
920
  this._open = false;
872
921
  this._destroying = false;
873
922
  this._aborting = false;
874
- (0, import_invariant3.invariant)(typeof initiator === "boolean", void 0, {
923
+ (0, import_invariant4.invariant)(typeof initiator === "boolean", void 0, {
875
924
  F: __dxlog_file4,
876
- L: 72,
925
+ L: 75,
877
926
  S: this,
878
927
  A: [
879
928
  "typeof initiator === 'boolean'",
880
929
  ""
881
930
  ]
882
931
  });
883
- (0, import_invariant3.invariant)(import_keys.PublicKey.isPublicKey(localPeerId), void 0, {
932
+ (0, import_invariant4.invariant)(import_keys.PublicKey.isPublicKey(localPeerId), void 0, {
884
933
  F: __dxlog_file4,
885
- L: 73,
934
+ L: 76,
886
935
  S: this,
887
936
  A: [
888
937
  "PublicKey.isPublicKey(localPeerId)",
889
938
  ""
890
939
  ]
891
940
  });
892
- (0, import_invariant3.invariant)(import_keys.PublicKey.isPublicKey(remotePeerId), void 0, {
941
+ (0, import_invariant4.invariant)(import_keys.PublicKey.isPublicKey(remotePeerId), void 0, {
893
942
  F: __dxlog_file4,
894
- L: 74,
943
+ L: 77,
895
944
  S: this,
896
945
  A: [
897
946
  "PublicKey.isPublicKey(remotePeerId)",
@@ -906,13 +955,13 @@ var Teleport = class {
906
955
  name
907
956
  }, {
908
957
  F: __dxlog_file4,
909
- L: 80,
958
+ L: 83,
910
959
  S: this,
911
960
  C: (f, a) => f(...a)
912
961
  });
913
- (0, import_invariant3.invariant)(!this._remoteExtensions.has(name), "Remote extension already exists", {
962
+ (0, import_invariant4.invariant)(!this._remoteExtensions.has(name), "Remote extension already exists", {
914
963
  F: __dxlog_file4,
915
- L: 81,
964
+ L: 84,
916
965
  S: this,
917
966
  A: [
918
967
  "!this._remoteExtensions.has(name)",
@@ -933,7 +982,7 @@ var Teleport = class {
933
982
  if (this._destroying || this._aborting) {
934
983
  (0, import_log4.log)("destroy teleport due to muxer stream close, skipping due to already destroying/aborting", void 0, {
935
984
  F: __dxlog_file4,
936
- L: 97,
985
+ L: 100,
937
986
  S: this,
938
987
  C: (f, a) => f(...a)
939
988
  });
@@ -956,7 +1005,7 @@ var Teleport = class {
956
1005
  channels: stats.channels
957
1006
  }, {
958
1007
  F: __dxlog_file4,
959
- L: 110,
1008
+ L: 113,
960
1009
  S: this,
961
1010
  C: (f, a) => f(...a)
962
1011
  });
@@ -994,7 +1043,7 @@ var Teleport = class {
994
1043
  } catch (err2) {
995
1044
  import_log4.log.catch(err2, void 0, {
996
1045
  F: __dxlog_file4,
997
- L: 163,
1046
+ L: 166,
998
1047
  S: this,
999
1048
  C: (f, a) => f(...a)
1000
1049
  });
@@ -1017,7 +1066,7 @@ var Teleport = class {
1017
1066
  } catch (err2) {
1018
1067
  import_log4.log.catch(err2, void 0, {
1019
1068
  F: __dxlog_file4,
1020
- L: 187,
1069
+ L: 190,
1021
1070
  S: this,
1022
1071
  C: (f, a) => f(...a)
1023
1072
  });
@@ -1033,7 +1082,7 @@ var Teleport = class {
1033
1082
  name
1034
1083
  }, {
1035
1084
  F: __dxlog_file4,
1036
- L: 199,
1085
+ L: 202,
1037
1086
  S: this,
1038
1087
  C: (f, a) => f(...a)
1039
1088
  });
@@ -1055,18 +1104,18 @@ var Teleport = class {
1055
1104
  }
1056
1105
  }
1057
1106
  _setExtension(extensionName, extension) {
1058
- (0, import_invariant3.invariant)(!extensionName.includes("/"), "Invalid extension name", {
1107
+ (0, import_invariant4.invariant)(!extensionName.includes("/"), "Invalid extension name", {
1059
1108
  F: __dxlog_file4,
1060
- L: 223,
1109
+ L: 226,
1061
1110
  S: this,
1062
1111
  A: [
1063
1112
  "!extensionName.includes('/')",
1064
1113
  "'Invalid extension name'"
1065
1114
  ]
1066
1115
  });
1067
- (0, import_invariant3.invariant)(!this._extensions.has(extensionName), "Extension already exists", {
1116
+ (0, import_invariant4.invariant)(!this._extensions.has(extensionName), "Extension already exists", {
1068
1117
  F: __dxlog_file4,
1069
- L: 224,
1118
+ L: 227,
1070
1119
  S: this,
1071
1120
  A: [
1072
1121
  "!this._extensions.has(extensionName)",
@@ -1080,7 +1129,7 @@ var Teleport = class {
1080
1129
  extensionName
1081
1130
  }, {
1082
1131
  F: __dxlog_file4,
1083
- L: 229,
1132
+ L: 232,
1084
1133
  S: this,
1085
1134
  C: (f, a) => f(...a)
1086
1135
  });
@@ -1090,9 +1139,9 @@ var Teleport = class {
1090
1139
  localPeerId: this.localPeerId,
1091
1140
  remotePeerId: this.remotePeerId,
1092
1141
  createPort: async (channelName, opts) => {
1093
- (0, import_invariant3.invariant)(!channelName.includes("/"), "Invalid channel name", {
1142
+ (0, import_invariant4.invariant)(!channelName.includes("/"), "Invalid channel name", {
1094
1143
  F: __dxlog_file4,
1095
- L: 237,
1144
+ L: 240,
1096
1145
  S: this,
1097
1146
  A: [
1098
1147
  "!channelName.includes('/')",
@@ -1102,9 +1151,9 @@ var Teleport = class {
1102
1151
  return this._muxer.createPort(`${extensionName}/${channelName}`, opts);
1103
1152
  },
1104
1153
  createStream: async (channelName, opts) => {
1105
- (0, import_invariant3.invariant)(!channelName.includes("/"), "Invalid channel name", {
1154
+ (0, import_invariant4.invariant)(!channelName.includes("/"), "Invalid channel name", {
1106
1155
  F: __dxlog_file4,
1107
- L: 241,
1156
+ L: 244,
1108
1157
  S: this,
1109
1158
  A: [
1110
1159
  "!channelName.includes('/')",
@@ -1124,7 +1173,7 @@ var Teleport = class {
1124
1173
  extensionName
1125
1174
  }, {
1126
1175
  F: __dxlog_file4,
1127
- L: 252,
1176
+ L: 255,
1128
1177
  S: this,
1129
1178
  C: (f, a) => f(...a)
1130
1179
  });
@@ -1194,7 +1243,7 @@ var ControlExtension = class {
1194
1243
 
1195
1244
  // packages/core/mesh/teleport/src/testing/test-builder.ts
1196
1245
  var import_node_stream3 = require("node:stream");
1197
- var import_invariant4 = require("@dxos/invariant");
1246
+ var import_invariant5 = require("@dxos/invariant");
1198
1247
  var import_keys2 = require("@dxos/keys");
1199
1248
  var import_log5 = require("@dxos/log");
1200
1249
  var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/testing/test-builder.ts";
@@ -1216,7 +1265,7 @@ var TestBuilder = class {
1216
1265
  await Promise.all(Array.from(this._peers).map((agent) => agent.destroy()));
1217
1266
  }
1218
1267
  async connect(peer1, peer2) {
1219
- (0, import_invariant4.invariant)(peer1 !== peer2, void 0, {
1268
+ (0, import_invariant5.invariant)(peer1 !== peer2, void 0, {
1220
1269
  F: __dxlog_file5,
1221
1270
  L: 37,
1222
1271
  S: this,
@@ -1225,7 +1274,7 @@ var TestBuilder = class {
1225
1274
  ""
1226
1275
  ]
1227
1276
  });
1228
- (0, import_invariant4.invariant)(this._peers.has(peer1), void 0, {
1277
+ (0, import_invariant5.invariant)(this._peers.has(peer1), void 0, {
1229
1278
  F: __dxlog_file5,
1230
1279
  L: 38,
1231
1280
  S: this,
@@ -1234,7 +1283,7 @@ var TestBuilder = class {
1234
1283
  ""
1235
1284
  ]
1236
1285
  });
1237
- (0, import_invariant4.invariant)(this._peers.has(peer1), void 0, {
1286
+ (0, import_invariant5.invariant)(this._peers.has(peer1), void 0, {
1238
1287
  F: __dxlog_file5,
1239
1288
  L: 39,
1240
1289
  S: this,
@@ -1262,7 +1311,7 @@ var TestBuilder = class {
1262
1311
  ];
1263
1312
  }
1264
1313
  async disconnect(peer1, peer2) {
1265
- (0, import_invariant4.invariant)(peer1 !== peer2, void 0, {
1314
+ (0, import_invariant5.invariant)(peer1 !== peer2, void 0, {
1266
1315
  F: __dxlog_file5,
1267
1316
  L: 51,
1268
1317
  S: this,
@@ -1271,7 +1320,7 @@ var TestBuilder = class {
1271
1320
  ""
1272
1321
  ]
1273
1322
  });
1274
- (0, import_invariant4.invariant)(this._peers.has(peer1), void 0, {
1323
+ (0, import_invariant5.invariant)(this._peers.has(peer1), void 0, {
1275
1324
  F: __dxlog_file5,
1276
1325
  L: 52,
1277
1326
  S: this,
@@ -1280,7 +1329,7 @@ var TestBuilder = class {
1280
1329
  ""
1281
1330
  ]
1282
1331
  });
1283
- (0, import_invariant4.invariant)(this._peers.has(peer1), void 0, {
1332
+ (0, import_invariant5.invariant)(this._peers.has(peer1), void 0, {
1284
1333
  F: __dxlog_file5,
1285
1334
  L: 53,
1286
1335
  S: this,
@@ -1291,7 +1340,7 @@ var TestBuilder = class {
1291
1340
  });
1292
1341
  const connection1 = Array.from(peer1.connections).find((connection) => connection.remotePeerId.equals(peer2.peerId));
1293
1342
  const connection2 = Array.from(peer2.connections).find((connection) => connection.remotePeerId.equals(peer1.peerId));
1294
- (0, import_invariant4.invariant)(connection1, void 0, {
1343
+ (0, import_invariant5.invariant)(connection1, void 0, {
1295
1344
  F: __dxlog_file5,
1296
1345
  L: 62,
1297
1346
  S: this,
@@ -1300,7 +1349,7 @@ var TestBuilder = class {
1300
1349
  ""
1301
1350
  ]
1302
1351
  });
1303
- (0, import_invariant4.invariant)(connection2, void 0, {
1352
+ (0, import_invariant5.invariant)(connection2, void 0, {
1304
1353
  F: __dxlog_file5,
1305
1354
  L: 63,
1306
1355
  S: this,
@@ -1330,7 +1379,7 @@ var TestPeer = class {
1330
1379
  return connection;
1331
1380
  }
1332
1381
  async openConnection(connection) {
1333
- (0, import_invariant4.invariant)(this.connections.has(connection), void 0, {
1382
+ (0, import_invariant5.invariant)(this.connections.has(connection), void 0, {
1334
1383
  F: __dxlog_file5,
1335
1384
  L: 84,
1336
1385
  S: this,
@@ -1343,7 +1392,7 @@ var TestPeer = class {
1343
1392
  await this.onOpen(connection);
1344
1393
  }
1345
1394
  async closeConnection(connection) {
1346
- (0, import_invariant4.invariant)(this.connections.has(connection), void 0, {
1395
+ (0, import_invariant5.invariant)(this.connections.has(connection), void 0, {
1347
1396
  F: __dxlog_file5,
1348
1397
  L: 90,
1349
1398
  S: this,
@@ -1399,7 +1448,7 @@ var TestConnection = class {
1399
1448
 
1400
1449
  // packages/core/mesh/teleport/src/testing/test-extension.ts
1401
1450
  var import_async5 = require("@dxos/async");
1402
- var import_invariant5 = require("@dxos/invariant");
1451
+ var import_invariant6 = require("@dxos/invariant");
1403
1452
  var import_log6 = require("@dxos/log");
1404
1453
  var import_protocols3 = require("@dxos/protocols");
1405
1454
  var import_rpc2 = require("@dxos/rpc");
@@ -1485,7 +1534,7 @@ var TestExtension = class {
1485
1534
  const res = await (0, import_async5.asyncTimeout)(this._rpc.rpc.TestService.testCall({
1486
1535
  data: message
1487
1536
  }), 1500);
1488
- (0, import_invariant5.invariant)(res.data === message, void 0, {
1537
+ (0, import_invariant6.invariant)(res.data === message, void 0, {
1489
1538
  F: __dxlog_file6,
1490
1539
  L: 84,
1491
1540
  S: this,
@@ -1506,7 +1555,7 @@ var TestExtension = class {
1506
1555
  // packages/core/mesh/teleport/src/testing/test-extension-with-streams.ts
1507
1556
  var import_node_crypto = require("node:crypto");
1508
1557
  var import_async6 = require("@dxos/async");
1509
- var import_invariant6 = require("@dxos/invariant");
1558
+ var import_invariant7 = require("@dxos/invariant");
1510
1559
  var import_log7 = require("@dxos/log");
1511
1560
  var import_protocols4 = require("@dxos/protocols");
1512
1561
  var import_rpc3 = require("@dxos/rpc");
@@ -1523,7 +1572,7 @@ var TestExtensionWithStreams = class {
1523
1572
  return this.extensionContext?.remotePeerId;
1524
1573
  }
1525
1574
  async _openStream(streamTag, interval = 5, chunkSize = 2048) {
1526
- (0, import_invariant6.invariant)(!this._streams.has(streamTag), `Stream already exists: ${streamTag}`, {
1575
+ (0, import_invariant7.invariant)(!this._streams.has(streamTag), `Stream already exists: ${streamTag}`, {
1527
1576
  F: __dxlog_file7,
1528
1577
  L: 39,
1529
1578
  S: this,
@@ -1589,7 +1638,7 @@ var TestExtensionWithStreams = class {
1589
1638
  }, 100);
1590
1639
  }
1591
1640
  _closeStream(streamTag) {
1592
- (0, import_invariant6.invariant)(this._streams.has(streamTag), `Stream does not exist: ${streamTag}`, {
1641
+ (0, import_invariant7.invariant)(this._streams.has(streamTag), `Stream does not exist: ${streamTag}`, {
1593
1642
  F: __dxlog_file7,
1594
1643
  L: 106,
1595
1644
  S: this,
@@ -1712,7 +1761,7 @@ var TestExtensionWithStreams = class {
1712
1761
  streamLoadInterval,
1713
1762
  streamLoadChunkSize
1714
1763
  });
1715
- (0, import_invariant6.invariant)(data === streamTag, void 0, {
1764
+ (0, import_invariant7.invariant)(data === streamTag, void 0, {
1716
1765
  F: __dxlog_file7,
1717
1766
  L: 207,
1718
1767
  S: this,
@@ -1731,7 +1780,7 @@ var TestExtensionWithStreams = class {
1731
1780
  const { data, bytesSent, bytesReceived, sendErrors, receiveErrors, runningTime } = await this._rpc.rpc.TestServiceWithStreams.closeTestStream({
1732
1781
  data: streamTag
1733
1782
  });
1734
- (0, import_invariant6.invariant)(data === streamTag, void 0, {
1783
+ (0, import_invariant7.invariant)(data === streamTag, void 0, {
1735
1784
  F: __dxlog_file7,
1736
1785
  L: 220,
1737
1786
  S: this,
@@ -1764,7 +1813,7 @@ var TestExtensionWithStreams = class {
1764
1813
  };
1765
1814
 
1766
1815
  // packages/core/mesh/teleport/src/rpc-extension.ts
1767
- var import_invariant7 = require("@dxos/invariant");
1816
+ var import_invariant8 = require("@dxos/invariant");
1768
1817
  var import_rpc4 = require("@dxos/rpc");
1769
1818
  var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/rpc-extension.ts";
1770
1819
  var RpcExtension = class {
@@ -1782,7 +1831,7 @@ var RpcExtension = class {
1782
1831
  return this._extensionContext.remotePeerId;
1783
1832
  }
1784
1833
  get rpc() {
1785
- (0, import_invariant7.invariant)(this._rpc, void 0, {
1834
+ (0, import_invariant8.invariant)(this._rpc, void 0, {
1786
1835
  F: __dxlog_file8,
1787
1836
  L: 32,
1788
1837
  S: this,