@dxos/client-services 0.1.53 → 0.1.54-main.270ec56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/dist/lib/browser/{chunk-6ITWCQIT.mjs → chunk-F4BHRFH4.mjs} +861 -702
  2. package/dist/lib/browser/chunk-F4BHRFH4.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +115 -173
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +24 -7
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/index.cjs +951 -853
  9. package/dist/lib/node/index.cjs.map +4 -4
  10. package/dist/lib/node/meta.json +1 -1
  11. package/dist/lib/node/packlets/testing/index.cjs +832 -708
  12. package/dist/lib/node/packlets/testing/index.cjs.map +4 -4
  13. package/dist/types/src/packlets/identity/authenticator.d.ts.map +1 -1
  14. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  15. package/dist/types/src/packlets/services/index.d.ts +1 -0
  16. package/dist/types/src/packlets/services/index.d.ts.map +1 -1
  17. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  18. package/dist/types/src/packlets/services/service-host.d.ts +7 -1
  19. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  20. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  21. package/dist/types/src/packlets/spaces/data-space.d.ts +11 -2
  22. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  23. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts +2 -1
  24. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
  25. package/dist/types/src/packlets/spaces/spaces-service.d.ts +1 -1
  26. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  27. package/dist/types/src/packlets/testing/test-builder.d.ts +7 -1
  28. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  29. package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts +1 -1
  30. package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts.map +1 -1
  31. package/dist/types/src/packlets/vault/iframe-proxy-runtime.d.ts +1 -1
  32. package/dist/types/src/packlets/vault/iframe-proxy-runtime.d.ts.map +1 -1
  33. package/dist/types/src/packlets/vault/shell-runtime.d.ts +1 -21
  34. package/dist/types/src/packlets/vault/shell-runtime.d.ts.map +1 -1
  35. package/dist/types/src/packlets/vault/worker-session.d.ts.map +1 -1
  36. package/package.json +33 -32
  37. package/src/packlets/identity/authenticator.ts +4 -2
  38. package/src/packlets/identity/identity-manager.test.ts +1 -1
  39. package/src/packlets/identity/identity-manager.ts +8 -8
  40. package/src/packlets/identity/identity-service.ts +2 -2
  41. package/src/packlets/identity/identity.test.ts +1 -1
  42. package/src/packlets/identity/identity.ts +22 -27
  43. package/src/packlets/invitations/device-invitation-protocol.ts +4 -4
  44. package/src/packlets/invitations/invitation-extension.ts +5 -5
  45. package/src/packlets/invitations/invitations-handler.ts +6 -6
  46. package/src/packlets/invitations/invitations-service.ts +3 -3
  47. package/src/packlets/invitations/space-invitation-protocol.ts +9 -9
  48. package/src/packlets/locks/node.ts +2 -2
  49. package/src/packlets/logging/logging-service.ts +4 -4
  50. package/src/packlets/services/index.ts +1 -0
  51. package/src/packlets/services/service-context.test.ts +1 -1
  52. package/src/packlets/services/service-context.ts +12 -10
  53. package/src/packlets/services/service-host.test.ts +50 -2
  54. package/src/packlets/services/service-host.ts +25 -9
  55. package/src/packlets/spaces/data-space-manager.test.ts +75 -119
  56. package/src/packlets/spaces/data-space-manager.ts +18 -9
  57. package/src/packlets/spaces/data-space.ts +66 -20
  58. package/src/packlets/spaces/notarization-plugin.test.ts +1 -1
  59. package/src/packlets/spaces/notarization-plugin.ts +9 -5
  60. package/src/packlets/spaces/spaces-service.test.ts +5 -3
  61. package/src/packlets/spaces/spaces-service.ts +26 -8
  62. package/src/packlets/testing/invitation-utils.ts +2 -2
  63. package/src/packlets/testing/test-builder.ts +36 -4
  64. package/src/packlets/vault/iframe-host-runtime.ts +2 -2
  65. package/src/packlets/vault/iframe-proxy-runtime.ts +2 -2
  66. package/src/packlets/vault/shell-runtime.ts +3 -49
  67. package/src/packlets/vault/worker-runtime.ts +1 -1
  68. package/src/packlets/vault/worker-session.ts +7 -6
  69. package/dist/lib/browser/chunk-6ITWCQIT.mjs.map +0 -7
@@ -1,4 +1,4 @@
1
- import "@dxos/node-std/globals"
1
+ import "@dxos/node-std/globals";
2
2
 
3
3
  // packages/sdk/client-services/src/packlets/devtools/feeds.ts
4
4
  import { EventSubscriptions } from "@dxos/async";
@@ -352,6 +352,8 @@ import { Context as Context2 } from "@dxos/context";
352
352
  import { verifyCredential } from "@dxos/credentials";
353
353
  import { log } from "@dxos/log";
354
354
  import { schema } from "@dxos/protocols";
355
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/authenticator.ts";
356
+ var Credential = schema.getCodecForType("dxos.halo.credentials.Credential");
355
357
  var createAuthProvider = (signer) => async (nonce) => {
356
358
  const credential = await signer.createCredential({
357
359
  assertion: {
@@ -360,7 +362,7 @@ var createAuthProvider = (signer) => async (nonce) => {
360
362
  subject: signer.getIssuer(),
361
363
  nonce
362
364
  });
363
- return schema.getCodecForType("dxos.halo.credentials.Credential").encode(credential);
365
+ return Credential.encode(credential);
364
366
  };
365
367
  var TrustedKeySetAuthVerifier = class {
366
368
  // prettier-ignore
@@ -373,24 +375,24 @@ var TrustedKeySetAuthVerifier = class {
373
375
  }
374
376
  get verifier() {
375
377
  return async (nonce, auth) => {
376
- const credential = schema.getCodecForType("dxos.halo.credentials.Credential").decode(auth);
378
+ const credential = Credential.decode(auth);
377
379
  log("authenticating...", {
378
380
  credential
379
381
  }, {
380
- file: "authenticator.ts",
381
- line: 57,
382
- scope: this,
383
- callSite: (f, a) => f(...a)
382
+ F: __dxlog_file,
383
+ L: 59,
384
+ S: this,
385
+ C: (f, a) => f(...a)
384
386
  });
385
387
  const result = await verifyCredential(credential);
386
388
  if (result.kind === "fail") {
387
389
  log("Invalid credential", {
388
390
  result
389
391
  }, {
390
- file: "authenticator.ts",
391
- line: 61,
392
- scope: this,
393
- callSite: (f, a) => f(...a)
392
+ F: __dxlog_file,
393
+ L: 63,
394
+ S: this,
395
+ C: (f, a) => f(...a)
394
396
  });
395
397
  return false;
396
398
  }
@@ -399,10 +401,10 @@ var TrustedKeySetAuthVerifier = class {
399
401
  nonce,
400
402
  credential
401
403
  }, {
402
- file: "authenticator.ts",
403
- line: 66,
404
- scope: this,
405
- callSite: (f, a) => f(...a)
404
+ F: __dxlog_file,
405
+ L: 68,
406
+ S: this,
407
+ C: (f, a) => f(...a)
406
408
  });
407
409
  return false;
408
410
  }
@@ -410,10 +412,10 @@ var TrustedKeySetAuthVerifier = class {
410
412
  log("key is not currently in trusted set, waiting...", {
411
413
  key: credential.issuer
412
414
  }, {
413
- file: "authenticator.ts",
414
- line: 71,
415
- scope: this,
416
- callSite: (f, a) => f(...a)
415
+ F: __dxlog_file,
416
+ L: 73,
417
+ S: this,
418
+ C: (f, a) => f(...a)
417
419
  });
418
420
  return true;
419
421
  }
@@ -426,20 +428,20 @@ var TrustedKeySetAuthVerifier = class {
426
428
  log("auth success", {
427
429
  key: credential.issuer
428
430
  }, {
429
- file: "authenticator.ts",
430
- line: 82,
431
- scope: this,
432
- callSite: (f, a) => f(...a)
431
+ F: __dxlog_file,
432
+ L: 84,
433
+ S: this,
434
+ C: (f, a) => f(...a)
433
435
  });
434
436
  trigger.wake(true);
435
437
  } else {
436
438
  log("key is not currently in trusted set, waiting...", {
437
439
  key: credential.issuer
438
440
  }, {
439
- file: "authenticator.ts",
440
- line: 85,
441
- scope: this,
442
- callSite: (f, a) => f(...a)
441
+ F: __dxlog_file,
442
+ L: 87,
443
+ S: this,
444
+ C: (f, a) => f(...a)
443
445
  });
444
446
  }
445
447
  });
@@ -461,7 +463,7 @@ var TrustedKeySetAuthVerifier = class {
461
463
  };
462
464
 
463
465
  // packages/sdk/client-services/src/packlets/identity/identity.ts
464
- import assert from "@dxos/node-std/assert";
466
+ import invariant from "tiny-invariant";
465
467
  import { Event } from "@dxos/async";
466
468
  import { AUTH_TIMEOUT, LOAD_CONTROL_FEEDS_TIMEOUT } from "@dxos/client-protocol";
467
469
  import { DeviceStateMachine, createCredentialSignerWithKey, createCredentialSignerWithChain, ProfileStateMachine } from "@dxos/credentials";
@@ -469,6 +471,7 @@ import { failUndefined } from "@dxos/debug";
469
471
  import { writeMessages } from "@dxos/feed-store";
470
472
  import { log as log2 } from "@dxos/log";
471
473
  import { AdmittedFeed } from "@dxos/protocols/proto/dxos/halo/credentials";
474
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity.ts";
472
475
  var Identity = class {
473
476
  constructor({ space, signer, identityKey, deviceKey }) {
474
477
  this.stateUpdate = new Event();
@@ -476,15 +479,15 @@ var Identity = class {
476
479
  this._signer = signer;
477
480
  this.identityKey = identityKey;
478
481
  this.deviceKey = deviceKey;
479
- this._deviceStateMachine = this.space.spaceState.registerProcessor(new DeviceStateMachine({
482
+ this._deviceStateMachine = new DeviceStateMachine({
480
483
  identityKey: this.identityKey,
481
484
  deviceKey: this.deviceKey,
482
485
  onUpdate: () => this.stateUpdate.emit()
483
- }));
484
- this._profileStateMachine = this.space.spaceState.registerProcessor(new ProfileStateMachine({
486
+ });
487
+ this._profileStateMachine = new ProfileStateMachine({
485
488
  identityKey: this.identityKey,
486
489
  onUpdate: () => this.stateUpdate.emit()
487
- }));
490
+ });
488
491
  this.authVerifier = new TrustedKeySetAuthVerifier({
489
492
  trustedKeysProvider: () => this.authorizedDeviceKeys,
490
493
  update: this.stateUpdate,
@@ -493,27 +496,27 @@ var Identity = class {
493
496
  }
494
497
  // TODO(burdon): Expose state object?
495
498
  get authorizedDeviceKeys() {
496
- return this._deviceStateMachine.processor.authorizedDeviceKeys;
499
+ return this._deviceStateMachine.authorizedDeviceKeys;
497
500
  }
498
501
  async open() {
499
- await this._deviceStateMachine.open();
500
- await this._profileStateMachine.open();
502
+ await this.space.spaceState.addCredentialProcessor(this._deviceStateMachine);
503
+ await this.space.spaceState.addCredentialProcessor(this._profileStateMachine);
501
504
  await this.space.open();
502
505
  }
503
506
  async close() {
504
507
  await this.authVerifier.close();
505
- await this._deviceStateMachine.close();
506
- await this._profileStateMachine.close();
508
+ await this.space.spaceState.removeCredentialProcessor(this._profileStateMachine);
509
+ await this.space.spaceState.removeCredentialProcessor(this._deviceStateMachine);
507
510
  await this.space.close();
508
511
  }
509
512
  async ready() {
510
- await this._deviceStateMachine.processor.deviceChainReady.wait();
513
+ await this._deviceStateMachine.deviceChainReady.wait();
511
514
  await this.controlPipeline.state.waitUntilReachedTargetTimeframe({
512
515
  timeout: LOAD_CONTROL_FEEDS_TIMEOUT
513
516
  });
514
517
  }
515
518
  get profileDocument() {
516
- return this._profileStateMachine.processor.profile;
519
+ return this._profileStateMachine.profile;
517
520
  }
518
521
  /**
519
522
  * @test-only
@@ -528,7 +531,7 @@ var Identity = class {
528
531
  return this.space.genesisFeedKey;
529
532
  }
530
533
  get deviceCredentialChain() {
531
- return this._deviceStateMachine.processor.deviceCredentialChain;
534
+ return this._deviceStateMachine.deviceCredentialChain;
532
535
  }
533
536
  getAdmissionCredentials() {
534
537
  var _a, _b;
@@ -543,8 +546,8 @@ var Identity = class {
543
546
  * Requires identity to be ready.
544
547
  */
545
548
  getIdentityCredentialSigner() {
546
- assert(this._deviceStateMachine.processor.deviceCredentialChain, "Device credential chain is not ready.");
547
- return createCredentialSignerWithChain(this._signer, this._deviceStateMachine.processor.deviceCredentialChain, this.deviceKey);
549
+ invariant(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.");
550
+ return createCredentialSignerWithChain(this._signer, this._deviceStateMachine.deviceCredentialChain, this.deviceKey);
548
551
  }
549
552
  /**
550
553
  * Issues credentials as device.
@@ -560,10 +563,10 @@ var Identity = class {
560
563
  controlFeedKey,
561
564
  dataFeedKey
562
565
  }, {
563
- file: "identity.ts",
564
- line: 156,
565
- scope: this,
566
- callSite: (f, a) => f(...a)
566
+ F: __dxlog_file2,
567
+ L: 151,
568
+ S: this,
569
+ C: (f, a) => f(...a)
567
570
  });
568
571
  const signer = this.getIdentityCredentialSigner();
569
572
  await writeMessages(this.controlPipeline.writer, [
@@ -604,7 +607,7 @@ var Identity = class {
604
607
  };
605
608
 
606
609
  // packages/sdk/client-services/src/packlets/identity/identity-manager.ts
607
- import assert2 from "@dxos/node-std/assert";
610
+ import invariant2 from "tiny-invariant";
608
611
  import { Event as Event2 } from "@dxos/async";
609
612
  import { createCredentialSignerWithKey as createCredentialSignerWithKey2, CredentialGenerator } from "@dxos/credentials";
610
613
  import { PublicKey as PublicKey3 } from "@dxos/keys";
@@ -612,6 +615,7 @@ import { log as log3 } from "@dxos/log";
612
615
  import { trace } from "@dxos/protocols";
613
616
  import { AdmittedFeed as AdmittedFeed2 } from "@dxos/protocols/proto/dxos/halo/credentials";
614
617
  import { deferFunction } from "@dxos/util";
618
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-manager.ts";
615
619
  var IdentityManager = class {
616
620
  // TODO(burdon): IdentityManagerParams.
617
621
  // TODO(dmaretskyi): Perhaps this should take/generate the peerKey outside of an initialized identity.
@@ -631,20 +635,20 @@ var IdentityManager = class {
631
635
  log3.trace("dxos.halo.identity-manager.open", trace.begin({
632
636
  id: traceId
633
637
  }), {
634
- file: "identity-manager.ts",
635
- line: 70,
636
- scope: this,
637
- callSite: (f, a) => f(...a)
638
+ F: __dxlog_file3,
639
+ L: 70,
640
+ S: this,
641
+ C: (f, a) => f(...a)
638
642
  });
639
643
  await this._metadataStore.load();
640
644
  const identityRecord = this._metadataStore.getIdentityRecord();
641
645
  log3("identity record", {
642
646
  identityRecord
643
647
  }, {
644
- file: "identity-manager.ts",
645
- line: 74,
646
- scope: this,
647
- callSite: (f, a) => f(...a)
648
+ F: __dxlog_file3,
649
+ L: 74,
650
+ S: this,
651
+ C: (f, a) => f(...a)
648
652
  });
649
653
  if (identityRecord) {
650
654
  this._identity = await this._constructIdentity(identityRecord);
@@ -654,20 +658,20 @@ var IdentityManager = class {
654
658
  identityKey: identityRecord.identityKey,
655
659
  displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
656
660
  }, {
657
- file: "identity-manager.ts",
658
- line: 79,
659
- scope: this,
660
- callSite: (f, a) => f(...a)
661
+ F: __dxlog_file3,
662
+ L: 79,
663
+ S: this,
664
+ C: (f, a) => f(...a)
661
665
  });
662
666
  this.stateUpdate.emit();
663
667
  }
664
668
  log3.trace("dxos.halo.identity-manager.open", trace.end({
665
669
  id: traceId
666
670
  }), {
667
- file: "identity-manager.ts",
668
- line: 85,
669
- scope: this,
670
- callSite: (f, a) => f(...a)
671
+ F: __dxlog_file3,
672
+ L: 85,
673
+ S: this,
674
+ C: (f, a) => f(...a)
671
675
  });
672
676
  }
673
677
  async close() {
@@ -676,12 +680,12 @@ var IdentityManager = class {
676
680
  }
677
681
  async createIdentity({ displayName } = {}) {
678
682
  var _a;
679
- assert2(!this._identity, "Identity already exists.");
680
- log3("creating identity...", {}, {
681
- file: "identity-manager.ts",
682
- line: 94,
683
- scope: this,
684
- callSite: (f, a) => f(...a)
683
+ invariant2(!this._identity, "Identity already exists.");
684
+ log3("creating identity...", void 0, {
685
+ F: __dxlog_file3,
686
+ L: 94,
687
+ S: this,
688
+ C: (f, a) => f(...a)
685
689
  });
686
690
  const controlFeedKey = await this._keyring.createKey();
687
691
  const identityRecord = {
@@ -698,8 +702,8 @@ var IdentityManager = class {
698
702
  await identity.open();
699
703
  {
700
704
  const generator = new CredentialGenerator(this._keyring, identityRecord.identityKey, identityRecord.deviceKey);
701
- assert2(identityRecord.haloSpace.genesisFeedKey, "Genesis feed key is required.");
702
- assert2(identityRecord.haloSpace.dataFeedKey, "Data feed key is required.");
705
+ invariant2(identityRecord.haloSpace.genesisFeedKey, "Genesis feed key is required.");
706
+ invariant2(identityRecord.haloSpace.dataFeedKey, "Data feed key is required.");
703
707
  const credentials = [
704
708
  // Space genesis.
705
709
  ...await generator.createSpaceGenesis(identityRecord.haloSpace.key, identityRecord.haloSpace.genesisFeedKey),
@@ -727,20 +731,20 @@ var IdentityManager = class {
727
731
  identityKey: identityRecord.identityKey,
728
732
  displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
729
733
  }, {
730
- file: "identity-manager.ts",
731
- line: 149,
732
- scope: this,
733
- callSite: (f, a) => f(...a)
734
+ F: __dxlog_file3,
735
+ L: 149,
736
+ S: this,
737
+ C: (f, a) => f(...a)
734
738
  });
735
739
  this.stateUpdate.emit();
736
740
  log3("created identity", {
737
741
  identityKey: identity.identityKey,
738
742
  deviceKey: identity.deviceKey
739
743
  }, {
740
- file: "identity-manager.ts",
741
- line: 155,
742
- scope: this,
743
- callSite: (f, a) => f(...a)
744
+ F: __dxlog_file3,
745
+ L: 155,
746
+ S: this,
747
+ C: (f, a) => f(...a)
744
748
  });
745
749
  return identity;
746
750
  }
@@ -752,12 +756,12 @@ var IdentityManager = class {
752
756
  log3("accepting identity", {
753
757
  params
754
758
  }, {
755
- file: "identity-manager.ts",
756
- line: 163,
757
- scope: this,
758
- callSite: (f, a) => f(...a)
759
+ F: __dxlog_file3,
760
+ L: 163,
761
+ S: this,
762
+ C: (f, a) => f(...a)
759
763
  });
760
- assert2(!this._identity, "Identity already exists.");
764
+ invariant2(!this._identity, "Identity already exists.");
761
765
  const identityRecord = {
762
766
  identityKey: params.identityKey,
763
767
  deviceKey: params.deviceKey,
@@ -778,38 +782,38 @@ var IdentityManager = class {
778
782
  identityKey: identityRecord.identityKey,
779
783
  displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
780
784
  }, {
781
- file: "identity-manager.ts",
782
- line: 183,
783
- scope: this,
784
- callSite: (f, a) => f(...a)
785
+ F: __dxlog_file3,
786
+ L: 183,
787
+ S: this,
788
+ C: (f, a) => f(...a)
785
789
  });
786
790
  this.stateUpdate.emit();
787
791
  log3("accepted identity", {
788
792
  identityKey: identity.identityKey,
789
793
  deviceKey: identity.deviceKey
790
794
  }, {
791
- file: "identity-manager.ts",
792
- line: 189,
793
- scope: this,
794
- callSite: (f, a) => f(...a)
795
+ F: __dxlog_file3,
796
+ L: 189,
797
+ S: this,
798
+ C: (f, a) => f(...a)
795
799
  });
796
800
  return identity;
797
801
  }
798
802
  async _constructIdentity(identityRecord) {
799
- assert2(!this._identity);
803
+ invariant2(!this._identity);
800
804
  log3("constructing identity", {
801
805
  identityRecord
802
806
  }, {
803
- file: "identity-manager.ts",
804
- line: 195,
805
- scope: this,
806
- callSite: (f, a) => f(...a)
807
+ F: __dxlog_file3,
808
+ L: 195,
809
+ S: this,
810
+ C: (f, a) => f(...a)
807
811
  });
808
- assert2(identityRecord.haloSpace.controlFeedKey);
812
+ invariant2(identityRecord.haloSpace.controlFeedKey);
809
813
  const controlFeed = await this._feedStore.openFeed(identityRecord.haloSpace.controlFeedKey, {
810
814
  writable: true
811
815
  });
812
- assert2(identityRecord.haloSpace.dataFeedKey);
816
+ invariant2(identityRecord.haloSpace.dataFeedKey);
813
817
  const dataFeed = await this._feedStore.openFeed(identityRecord.haloSpace.dataFeedKey, {
814
818
  writable: true,
815
819
  sparse: true
@@ -834,10 +838,10 @@ var IdentityManager = class {
834
838
  log3("done", {
835
839
  identityKey: identityRecord.identityKey
836
840
  }, {
837
- file: "identity-manager.ts",
838
- line: 226,
839
- scope: this,
840
- callSite: (f, a) => f(...a)
841
+ F: __dxlog_file3,
842
+ L: 226,
843
+ S: this,
844
+ C: (f, a) => f(...a)
841
845
  });
842
846
  if (identityRecord.haloSpace.controlTimeframe) {
843
847
  identity.controlPipeline.state.setTargetTimeframe(identityRecord.haloSpace.controlTimeframe);
@@ -854,11 +858,11 @@ var IdentityManager = class {
854
858
  onNetworkConnection: () => {
855
859
  },
856
860
  onAuthFailure: () => {
857
- log3.warn("auth failure", {}, {
858
- file: "identity-manager.ts",
859
- line: 245,
860
- scope: this,
861
- callSite: (f, a) => f(...a)
861
+ log3.warn("auth failure", void 0, {
862
+ F: __dxlog_file3,
863
+ L: 245,
864
+ S: this,
865
+ C: (f, a) => f(...a)
862
866
  });
863
867
  },
864
868
  memberKey: identityKey
@@ -867,7 +871,7 @@ var IdentityManager = class {
867
871
  };
868
872
 
869
873
  // packages/sdk/client-services/src/packlets/identity/identity-service.ts
870
- import assert3 from "@dxos/node-std/assert";
874
+ import invariant3 from "tiny-invariant";
871
875
  import { Stream as Stream7 } from "@dxos/codec-protobuf";
872
876
  import { signPresentation } from "@dxos/credentials";
873
877
  import { todo } from "@dxos/debug";
@@ -903,7 +907,7 @@ var IdentityServiceImpl = class {
903
907
  };
904
908
  }
905
909
  async signPresentation({ presentation, nonce }) {
906
- assert3(this._serviceContext.identityManager.identity, "Identity not initialized.");
910
+ invariant3(this._serviceContext.identityManager.identity, "Identity not initialized.");
907
911
  return await signPresentation({
908
912
  presentation,
909
913
  signer: this._serviceContext.keyring,
@@ -915,7 +919,7 @@ var IdentityServiceImpl = class {
915
919
  };
916
920
 
917
921
  // packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts
918
- import assert4 from "@dxos/node-std/assert";
922
+ import invariant4 from "tiny-invariant";
919
923
  import { Invitation } from "@dxos/protocols/proto/dxos/client/services";
920
924
  var DeviceInvitationProtocol = class {
921
925
  constructor(_keyring, _getIdentity, _acceptIdentity) {
@@ -932,7 +936,7 @@ var DeviceInvitationProtocol = class {
932
936
  };
933
937
  }
934
938
  async admit(request) {
935
- assert4(request.device);
939
+ invariant4(request.device);
936
940
  const identity = this._getIdentity();
937
941
  await identity.admitDevice(request.device);
938
942
  return {
@@ -960,9 +964,9 @@ var DeviceInvitationProtocol = class {
960
964
  };
961
965
  }
962
966
  async accept(response, request) {
963
- assert4(response.device);
967
+ invariant4(response.device);
964
968
  const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
965
- assert4(request.device);
969
+ invariant4(request.device);
966
970
  const { deviceKey, controlFeedKey, dataFeedKey } = request.device;
967
971
  await this._acceptIdentity({
968
972
  identityKey,
@@ -980,7 +984,7 @@ var DeviceInvitationProtocol = class {
980
984
  };
981
985
 
982
986
  // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
983
- import assert6 from "@dxos/node-std/assert";
987
+ import invariant6 from "tiny-invariant";
984
988
  import { PushStream, scheduleTask as scheduleTask2, TimeoutError, Trigger as Trigger3 } from "@dxos/async";
985
989
  import { AuthenticatingInvitationObservable, AUTHENTICATION_CODE_LENGTH, CancellableInvitationObservable, INVITATION_TIMEOUT } from "@dxos/client-protocol";
986
990
  import { Context as Context4 } from "@dxos/context";
@@ -994,7 +998,7 @@ import { Invitation as Invitation3 } from "@dxos/protocols/proto/dxos/client/ser
994
998
  import { AuthenticationResponse as AuthenticationResponse2 } from "@dxos/protocols/proto/dxos/halo/invitations";
995
999
 
996
1000
  // packages/sdk/client-services/src/packlets/invitations/invitation-extension.ts
997
- import assert5 from "@dxos/node-std/assert";
1001
+ import invariant5 from "tiny-invariant";
998
1002
  import { Trigger as Trigger2 } from "@dxos/async";
999
1003
  import { cancelWithContext, Context as Context3 } from "@dxos/context";
1000
1004
  import { InvalidInvitationExtensionRoleError } from "@dxos/errors";
@@ -1004,6 +1008,7 @@ import { schema as schema2, trace as trace2 } from "@dxos/protocols";
1004
1008
  import { Invitation as Invitation2 } from "@dxos/protocols/proto/dxos/client/services";
1005
1009
  import { AuthenticationResponse, Options } from "@dxos/protocols/proto/dxos/halo/invitations";
1006
1010
  import { RpcExtension } from "@dxos/teleport";
1011
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-extension.ts";
1007
1012
  var OPTIONS_TIMEOUT = 1e4;
1008
1013
  var MAX_OTP_ATTEMPTS = 3;
1009
1014
  var InvitationHostExtension = class extends RpcExtension {
@@ -1031,7 +1036,7 @@ var InvitationHostExtension = class extends RpcExtension {
1031
1036
  // Perhaps in the future we will have more complex logic here.
1032
1037
  InvitationHostService: {
1033
1038
  options: async (options) => {
1034
- assert5(!this._remoteOptions, "Remote options already set.");
1039
+ invariant5(!this._remoteOptions, "Remote options already set.");
1035
1040
  this._remoteOptions = options;
1036
1041
  this._remoteOptionsTrigger.wake();
1037
1042
  },
@@ -1041,20 +1046,20 @@ var InvitationHostExtension = class extends RpcExtension {
1041
1046
  log4.trace("dxos.sdk.invitation-handler.host.introduce", trace2.begin({
1042
1047
  id: traceId
1043
1048
  }), {
1044
- file: "invitation-extension.ts",
1045
- line: 98,
1046
- scope: this,
1047
- callSite: (f, a) => f(...a)
1049
+ F: __dxlog_file4,
1050
+ L: 98,
1051
+ S: this,
1052
+ C: (f, a) => f(...a)
1048
1053
  });
1049
1054
  const invitation = await this._callbacks.resolveInvitation(request);
1050
1055
  if (!invitation) {
1051
1056
  log4.warn("invitation not found", {
1052
1057
  invitationId
1053
1058
  }, {
1054
- file: "invitation-extension.ts",
1055
- line: 102,
1056
- scope: this,
1057
- callSite: (f, a) => f(...a)
1059
+ F: __dxlog_file4,
1060
+ L: 102,
1061
+ S: this,
1062
+ C: (f, a) => f(...a)
1058
1063
  });
1059
1064
  this._callbacks.onError(new Error("Invitation not found."));
1060
1065
  return {
@@ -1065,10 +1070,10 @@ var InvitationHostExtension = class extends RpcExtension {
1065
1070
  log4("guest introduced itself", {
1066
1071
  guestProfile: profile
1067
1072
  }, {
1068
- file: "invitation-extension.ts",
1069
- line: 111,
1070
- scope: this,
1071
- callSite: (f, a) => f(...a)
1073
+ F: __dxlog_file4,
1074
+ L: 111,
1075
+ S: this,
1076
+ C: (f, a) => f(...a)
1072
1077
  });
1073
1078
  this.guestProfile = profile;
1074
1079
  this._callbacks.onStateUpdate({
@@ -1078,10 +1083,10 @@ var InvitationHostExtension = class extends RpcExtension {
1078
1083
  log4.trace("dxos.sdk.invitation-handler.host.introduce", trace2.end({
1079
1084
  id: traceId
1080
1085
  }), {
1081
- file: "invitation-extension.ts",
1082
- line: 118,
1083
- scope: this,
1084
- callSite: (f, a) => f(...a)
1086
+ F: __dxlog_file4,
1087
+ L: 118,
1088
+ S: this,
1089
+ C: (f, a) => f(...a)
1085
1090
  });
1086
1091
  return {
1087
1092
  spaceKey: this.invitation.authMethod === Invitation2.AuthMethod.NONE ? this.invitation.spaceKey : void 0,
@@ -1093,28 +1098,28 @@ var InvitationHostExtension = class extends RpcExtension {
1093
1098
  log4.trace("dxos.sdk.invitation-handler.host.authenticate", trace2.begin({
1094
1099
  id: traceId
1095
1100
  }), {
1096
- file: "invitation-extension.ts",
1097
- line: 127,
1098
- scope: this,
1099
- callSite: (f, a) => f(...a)
1101
+ F: __dxlog_file4,
1102
+ L: 127,
1103
+ S: this,
1104
+ C: (f, a) => f(...a)
1100
1105
  });
1101
1106
  log4("received authentication request", {
1102
1107
  authCode: code
1103
1108
  }, {
1104
- file: "invitation-extension.ts",
1105
- line: 128,
1106
- scope: this,
1107
- callSite: (f, a) => f(...a)
1109
+ F: __dxlog_file4,
1110
+ L: 128,
1111
+ S: this,
1112
+ C: (f, a) => f(...a)
1108
1113
  });
1109
1114
  let status = AuthenticationResponse.Status.OK;
1110
- assert5(this.invitation, "Invitation is not set.");
1115
+ invariant5(this.invitation, "Invitation is not set.");
1111
1116
  switch (this.invitation.authMethod) {
1112
1117
  case Invitation2.AuthMethod.NONE: {
1113
- log4("authentication not required", {}, {
1114
- file: "invitation-extension.ts",
1115
- line: 134,
1116
- scope: this,
1117
- callSite: (f, a) => f(...a)
1118
+ log4("authentication not required", void 0, {
1119
+ F: __dxlog_file4,
1120
+ L: 134,
1121
+ S: this,
1122
+ C: (f, a) => f(...a)
1118
1123
  });
1119
1124
  return {
1120
1125
  status: AuthenticationResponse.Status.OK
@@ -1136,10 +1141,10 @@ var InvitationHostExtension = class extends RpcExtension {
1136
1141
  log4.error("invalid authentication method", {
1137
1142
  authMethod: this.invitation.authMethod
1138
1143
  }, {
1139
- file: "invitation-extension.ts",
1140
- line: 152,
1141
- scope: this,
1142
- callSite: (f, a) => f(...a)
1144
+ F: __dxlog_file4,
1145
+ L: 152,
1146
+ S: this,
1147
+ C: (f, a) => f(...a)
1143
1148
  });
1144
1149
  status = AuthenticationResponse.Status.INTERNAL_ERROR;
1145
1150
  break;
@@ -1151,10 +1156,10 @@ var InvitationHostExtension = class extends RpcExtension {
1151
1156
  status
1152
1157
  }
1153
1158
  }), {
1154
- file: "invitation-extension.ts",
1155
- line: 158,
1156
- scope: this,
1157
- callSite: (f, a) => f(...a)
1159
+ F: __dxlog_file4,
1160
+ L: 158,
1161
+ S: this,
1162
+ C: (f, a) => f(...a)
1158
1163
  });
1159
1164
  return {
1160
1165
  status
@@ -1165,13 +1170,13 @@ var InvitationHostExtension = class extends RpcExtension {
1165
1170
  log4.trace("dxos.sdk.invitation-handler.host.admit", trace2.begin({
1166
1171
  id: traceId
1167
1172
  }), {
1168
- file: "invitation-extension.ts",
1169
- line: 164,
1170
- scope: this,
1171
- callSite: (f, a) => f(...a)
1173
+ F: __dxlog_file4,
1174
+ L: 164,
1175
+ S: this,
1176
+ C: (f, a) => f(...a)
1172
1177
  });
1173
1178
  try {
1174
- assert5(this.invitation, "Invitation is not set.");
1179
+ invariant5(this.invitation, "Invitation is not set.");
1175
1180
  if (isAuthenticationRequired(this.invitation) && !this.authenticationPassed) {
1176
1181
  throw new Error("Not authenticated");
1177
1182
  }
@@ -1179,10 +1184,10 @@ var InvitationHostExtension = class extends RpcExtension {
1179
1184
  log4.trace("dxos.sdk.invitation-handler.host.admit", trace2.end({
1180
1185
  id: traceId
1181
1186
  }), {
1182
- file: "invitation-extension.ts",
1183
- line: 175,
1184
- scope: this,
1185
- callSite: (f, a) => f(...a)
1187
+ F: __dxlog_file4,
1188
+ L: 175,
1189
+ S: this,
1190
+ C: (f, a) => f(...a)
1186
1191
  });
1187
1192
  return response;
1188
1193
  } catch (err) {
@@ -1236,7 +1241,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1236
1241
  return {
1237
1242
  InvitationHostService: {
1238
1243
  options: async (options) => {
1239
- assert5(!this._remoteOptions, "Remote options already set.");
1244
+ invariant5(!this._remoteOptions, "Remote options already set.");
1240
1245
  this._remoteOptions = options;
1241
1246
  this._remoteOptionsTrigger.wake();
1242
1247
  },
@@ -1256,11 +1261,11 @@ var InvitationGuestExtension = class extends RpcExtension {
1256
1261
  var _a;
1257
1262
  await super.onOpen(context);
1258
1263
  try {
1259
- log4("begin options", {}, {
1260
- file: "invitation-extension.ts",
1261
- line: 263,
1262
- scope: this,
1263
- callSite: (f, a) => f(...a)
1264
+ log4("begin options", void 0, {
1265
+ F: __dxlog_file4,
1266
+ L: 263,
1267
+ S: this,
1268
+ C: (f, a) => f(...a)
1264
1269
  });
1265
1270
  await cancelWithContext(this._ctx, this.rpc.InvitationHostService.options({
1266
1271
  role: Options.Role.GUEST
@@ -1268,11 +1273,11 @@ var InvitationGuestExtension = class extends RpcExtension {
1268
1273
  await cancelWithContext(this._ctx, this._remoteOptionsTrigger.wait({
1269
1274
  timeout: OPTIONS_TIMEOUT
1270
1275
  }));
1271
- log4("end options", {}, {
1272
- file: "invitation-extension.ts",
1273
- line: 266,
1274
- scope: this,
1275
- callSite: (f, a) => f(...a)
1276
+ log4("end options", void 0, {
1277
+ F: __dxlog_file4,
1278
+ L: 266,
1279
+ S: this,
1280
+ C: (f, a) => f(...a)
1276
1281
  });
1277
1282
  if (((_a = this._remoteOptions) == null ? void 0 : _a.role) !== Options.Role.HOST) {
1278
1283
  throw new InvalidInvitationExtensionRoleError(void 0, {
@@ -1283,20 +1288,20 @@ var InvitationGuestExtension = class extends RpcExtension {
1283
1288
  this._callbacks.onOpen(this._ctx);
1284
1289
  } catch (err) {
1285
1290
  log4("openError", err, {
1286
- file: "invitation-extension.ts",
1287
- line: 276,
1288
- scope: this,
1289
- callSite: (f, a) => f(...a)
1291
+ F: __dxlog_file4,
1292
+ L: 276,
1293
+ S: this,
1294
+ C: (f, a) => f(...a)
1290
1295
  });
1291
1296
  this._callbacks.onError(err);
1292
1297
  }
1293
1298
  }
1294
1299
  async onClose() {
1295
- log4("onClose", {}, {
1296
- file: "invitation-extension.ts",
1297
- line: 282,
1298
- scope: this,
1299
- callSite: (f, a) => f(...a)
1300
+ log4("onClose", void 0, {
1301
+ F: __dxlog_file4,
1302
+ L: 282,
1303
+ S: this,
1304
+ C: (f, a) => f(...a)
1300
1305
  });
1301
1306
  await this._ctx.dispose();
1302
1307
  }
@@ -1304,6 +1309,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1304
1309
  var isAuthenticationRequired = (invitation) => invitation.authMethod !== Invitation2.AuthMethod.NONE;
1305
1310
 
1306
1311
  // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
1312
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts";
1307
1313
  var InvitationsHandler = class {
1308
1314
  /**
1309
1315
  * @internal
@@ -1315,7 +1321,7 @@ var InvitationsHandler = class {
1315
1321
  var _a;
1316
1322
  const { invitationId = PublicKey5.random().toHex(), type = Invitation3.Type.INTERACTIVE, authMethod = Invitation3.AuthMethod.SHARED_SECRET, state = Invitation3.State.INIT, timeout = INVITATION_TIMEOUT, swarmKey = PublicKey5.random() } = options != null ? options : {};
1317
1323
  const authCode = (_a = options == null ? void 0 : options.authCode) != null ? _a : authMethod === Invitation3.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0;
1318
- assert6(protocol);
1324
+ invariant6(protocol);
1319
1325
  const invitation = {
1320
1326
  invitationId,
1321
1327
  type,
@@ -1337,10 +1343,10 @@ var InvitationsHandler = class {
1337
1343
  log5("complete", {
1338
1344
  ...protocol.toJSON()
1339
1345
  }, {
1340
- file: "invitations-handler.ts",
1341
- line: 99,
1342
- scope: this,
1343
- callSite: (f, a) => f(...a)
1346
+ F: __dxlog_file5,
1347
+ L: 99,
1348
+ S: this,
1349
+ C: (f, a) => f(...a)
1344
1350
  });
1345
1351
  stream.complete();
1346
1352
  });
@@ -1362,7 +1368,7 @@ var InvitationsHandler = class {
1362
1368
  var _a2, _b, _c;
1363
1369
  try {
1364
1370
  const deviceKey = (_c = (_a2 = admissionRequest.device) == null ? void 0 : _a2.deviceKey) != null ? _c : (_b = admissionRequest.space) == null ? void 0 : _b.deviceKey;
1365
- assert6(deviceKey);
1371
+ invariant6(deviceKey);
1366
1372
  const admissionResponse = await protocol.admit(admissionRequest, extension.guestProfile);
1367
1373
  extension.completedTrigger.wake(deviceKey);
1368
1374
  return admissionResponse;
@@ -1378,18 +1384,18 @@ var InvitationsHandler = class {
1378
1384
  log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace3.begin({
1379
1385
  id: traceId
1380
1386
  }), {
1381
- file: "invitations-handler.ts",
1382
- line: 138,
1383
- scope: this,
1384
- callSite: (f, a) => f(...a)
1387
+ F: __dxlog_file5,
1388
+ L: 138,
1389
+ S: this,
1390
+ C: (f, a) => f(...a)
1385
1391
  });
1386
1392
  log5("connected", {
1387
1393
  ...protocol.toJSON()
1388
1394
  }, {
1389
- file: "invitations-handler.ts",
1390
- line: 139,
1391
- scope: this,
1392
- callSite: (f, a) => f(...a)
1395
+ F: __dxlog_file5,
1396
+ L: 139,
1397
+ S: this,
1398
+ C: (f, a) => f(...a)
1393
1399
  });
1394
1400
  stream.next({
1395
1401
  ...invitation,
@@ -1402,10 +1408,10 @@ var InvitationsHandler = class {
1402
1408
  guest: deviceKey,
1403
1409
  ...protocol.toJSON()
1404
1410
  }, {
1405
- file: "invitations-handler.ts",
1406
- line: 142,
1407
- scope: this,
1408
- callSite: (f, a) => f(...a)
1411
+ F: __dxlog_file5,
1412
+ L: 142,
1413
+ S: this,
1414
+ C: (f, a) => f(...a)
1409
1415
  });
1410
1416
  stream.next({
1411
1417
  ...invitation,
@@ -1414,20 +1420,20 @@ var InvitationsHandler = class {
1414
1420
  log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace3.end({
1415
1421
  id: traceId
1416
1422
  }), {
1417
- file: "invitations-handler.ts",
1418
- line: 144,
1419
- scope: this,
1420
- callSite: (f, a) => f(...a)
1423
+ F: __dxlog_file5,
1424
+ L: 144,
1425
+ S: this,
1426
+ C: (f, a) => f(...a)
1421
1427
  });
1422
1428
  } catch (err) {
1423
1429
  if (err instanceof TimeoutError) {
1424
1430
  log5("timeout", {
1425
1431
  ...protocol.toJSON()
1426
1432
  }, {
1427
- file: "invitations-handler.ts",
1428
- line: 147,
1429
- scope: this,
1430
- callSite: (f, a) => f(...a)
1433
+ F: __dxlog_file5,
1434
+ L: 147,
1435
+ S: this,
1436
+ C: (f, a) => f(...a)
1431
1437
  });
1432
1438
  stream.next({
1433
1439
  ...invitation,
@@ -1435,10 +1441,10 @@ var InvitationsHandler = class {
1435
1441
  });
1436
1442
  } else {
1437
1443
  log5.error("failed", err, {
1438
- file: "invitations-handler.ts",
1439
- line: 150,
1440
- scope: this,
1441
- callSite: (f, a) => f(...a)
1444
+ F: __dxlog_file5,
1445
+ L: 150,
1446
+ S: this,
1447
+ C: (f, a) => f(...a)
1442
1448
  });
1443
1449
  stream.error(err);
1444
1450
  }
@@ -1446,10 +1452,10 @@ var InvitationsHandler = class {
1446
1452
  id: traceId,
1447
1453
  error: err
1448
1454
  }), {
1449
- file: "invitations-handler.ts",
1450
- line: 153,
1451
- scope: this,
1452
- callSite: (f, a) => f(...a)
1455
+ F: __dxlog_file5,
1456
+ L: 153,
1457
+ S: this,
1458
+ C: (f, a) => f(...a)
1453
1459
  });
1454
1460
  } finally {
1455
1461
  if (type !== Invitation3.Type.MULTIUSE) {
@@ -1467,10 +1473,10 @@ var InvitationsHandler = class {
1467
1473
  log5("timeout", {
1468
1474
  ...protocol.toJSON()
1469
1475
  }, {
1470
- file: "invitations-handler.ts",
1471
- line: 168,
1472
- scope: this,
1473
- callSite: (f, a) => f(...a)
1476
+ F: __dxlog_file5,
1477
+ L: 168,
1478
+ S: this,
1479
+ C: (f, a) => f(...a)
1474
1480
  });
1475
1481
  stream.next({
1476
1482
  ...invitation,
@@ -1478,10 +1484,10 @@ var InvitationsHandler = class {
1478
1484
  });
1479
1485
  } else {
1480
1486
  log5.error("failed", err, {
1481
- file: "invitations-handler.ts",
1482
- line: 171,
1483
- scope: this,
1484
- callSite: (f, a) => f(...a)
1487
+ F: __dxlog_file5,
1488
+ L: 171,
1489
+ S: this,
1490
+ C: (f, a) => f(...a)
1485
1491
  });
1486
1492
  stream.error(err);
1487
1493
  }
@@ -1521,13 +1527,13 @@ var InvitationsHandler = class {
1521
1527
  }
1522
1528
  acceptInvitation(protocol, invitation) {
1523
1529
  const { timeout = INVITATION_TIMEOUT } = invitation;
1524
- assert6(protocol);
1530
+ invariant6(protocol);
1525
1531
  const authenticated = new Trigger3();
1526
1532
  let admitted = false;
1527
1533
  let currentState;
1528
1534
  const stream = new PushStream();
1529
1535
  const setState = (newData) => {
1530
- assert6(newData.state !== void 0);
1536
+ invariant6(newData.state !== void 0);
1531
1537
  currentState = newData.state;
1532
1538
  stream.next({
1533
1539
  ...invitation,
@@ -1540,20 +1546,20 @@ var InvitationsHandler = class {
1540
1546
  log5("timeout", {
1541
1547
  ...protocol.toJSON()
1542
1548
  }, {
1543
- file: "invitations-handler.ts",
1544
- line: 230,
1545
- scope: this,
1546
- callSite: (f, a) => f(...a)
1549
+ F: __dxlog_file5,
1550
+ L: 230,
1551
+ S: this,
1552
+ C: (f, a) => f(...a)
1547
1553
  });
1548
1554
  setState({
1549
1555
  state: Invitation3.State.TIMEOUT
1550
1556
  });
1551
1557
  } else {
1552
1558
  log5.warn("auth failed", err, {
1553
- file: "invitations-handler.ts",
1554
- line: 233,
1555
- scope: this,
1556
- callSite: (f, a) => f(...a)
1559
+ F: __dxlog_file5,
1560
+ L: 233,
1561
+ S: this,
1562
+ C: (f, a) => f(...a)
1557
1563
  });
1558
1564
  stream.error(err);
1559
1565
  }
@@ -1564,10 +1570,10 @@ var InvitationsHandler = class {
1564
1570
  log5("complete", {
1565
1571
  ...protocol.toJSON()
1566
1572
  }, {
1567
- file: "invitations-handler.ts",
1568
- line: 241,
1569
- scope: this,
1570
- callSite: (f, a) => f(...a)
1573
+ F: __dxlog_file5,
1574
+ L: 241,
1575
+ S: this,
1576
+ C: (f, a) => f(...a)
1571
1577
  });
1572
1578
  stream.complete();
1573
1579
  });
@@ -1579,10 +1585,10 @@ var InvitationsHandler = class {
1579
1585
  log5("extension disposed", {
1580
1586
  currentState
1581
1587
  }, {
1582
- file: "invitations-handler.ts",
1583
- line: 251,
1584
- scope: this,
1585
- callSite: (f, a) => f(...a)
1588
+ F: __dxlog_file5,
1589
+ L: 251,
1590
+ S: this,
1591
+ C: (f, a) => f(...a)
1586
1592
  });
1587
1593
  if (!admitted) {
1588
1594
  stream.error(new Error("Remote peer disconnected."));
@@ -1594,10 +1600,10 @@ var InvitationsHandler = class {
1594
1600
  log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace3.begin({
1595
1601
  id: traceId
1596
1602
  }), {
1597
- file: "invitations-handler.ts",
1598
- line: 260,
1599
- scope: this,
1600
- callSite: (f, a) => f(...a)
1603
+ F: __dxlog_file5,
1604
+ L: 260,
1605
+ S: this,
1606
+ C: (f, a) => f(...a)
1601
1607
  });
1602
1608
  if (++connectionCount > 1) {
1603
1609
  throw new Error(`multiple connections detected: ${connectionCount}`);
@@ -1606,10 +1612,10 @@ var InvitationsHandler = class {
1606
1612
  log5("connected", {
1607
1613
  ...protocol.toJSON()
1608
1614
  }, {
1609
- file: "invitations-handler.ts",
1610
- line: 268,
1611
- scope: this,
1612
- callSite: (f, a) => f(...a)
1615
+ F: __dxlog_file5,
1616
+ L: 268,
1617
+ S: this,
1618
+ C: (f, a) => f(...a)
1613
1619
  });
1614
1620
  setState({
1615
1621
  state: Invitation3.State.CONNECTED
@@ -1617,20 +1623,20 @@ var InvitationsHandler = class {
1617
1623
  log5("introduce", {
1618
1624
  ...protocol.toJSON()
1619
1625
  }, {
1620
- file: "invitations-handler.ts",
1621
- line: 272,
1622
- scope: this,
1623
- callSite: (f, a) => f(...a)
1626
+ F: __dxlog_file5,
1627
+ L: 272,
1628
+ S: this,
1629
+ C: (f, a) => f(...a)
1624
1630
  });
1625
1631
  const introductionResponse = await extension.rpc.InvitationHostService.introduce(protocol.createIntroduction());
1626
1632
  log5("introduce response", {
1627
1633
  ...protocol.toJSON(),
1628
1634
  response: introductionResponse
1629
1635
  }, {
1630
- file: "invitations-handler.ts",
1631
- line: 276,
1632
- scope: this,
1633
- callSite: (f, a) => f(...a)
1636
+ F: __dxlog_file5,
1637
+ L: 276,
1638
+ S: this,
1639
+ C: (f, a) => f(...a)
1634
1640
  });
1635
1641
  invitation.authMethod = introductionResponse.authMethod;
1636
1642
  if (introductionResponse.spaceKey) {
@@ -1638,11 +1644,11 @@ var InvitationsHandler = class {
1638
1644
  }
1639
1645
  if (isAuthenticationRequired(invitation)) {
1640
1646
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
1641
- log5("guest waiting for authentication code...", {}, {
1642
- file: "invitations-handler.ts",
1643
- line: 285,
1644
- scope: this,
1645
- callSite: (f, a) => f(...a)
1647
+ log5("guest waiting for authentication code...", void 0, {
1648
+ F: __dxlog_file5,
1649
+ L: 285,
1650
+ S: this,
1651
+ C: (f, a) => f(...a)
1646
1652
  });
1647
1653
  setState({
1648
1654
  state: Invitation3.State.READY_FOR_AUTHENTICATION
@@ -1650,11 +1656,11 @@ var InvitationsHandler = class {
1650
1656
  const authCode = await authenticated.wait({
1651
1657
  timeout
1652
1658
  });
1653
- log5("sending authentication request", {}, {
1654
- file: "invitations-handler.ts",
1655
- line: 289,
1656
- scope: this,
1657
- callSite: (f, a) => f(...a)
1659
+ log5("sending authentication request", void 0, {
1660
+ F: __dxlog_file5,
1661
+ L: 289,
1662
+ S: this,
1663
+ C: (f, a) => f(...a)
1658
1664
  });
1659
1665
  setState({
1660
1666
  state: Invitation3.State.AUTHENTICATING
@@ -1672,10 +1678,10 @@ var InvitationsHandler = class {
1672
1678
  log5("retrying invalid code", {
1673
1679
  attempt
1674
1680
  }, {
1675
- file: "invitations-handler.ts",
1676
- line: 300,
1677
- scope: this,
1678
- callSite: (f, a) => f(...a)
1681
+ F: __dxlog_file5,
1682
+ L: 300,
1683
+ S: this,
1684
+ C: (f, a) => f(...a)
1679
1685
  });
1680
1686
  authenticated.reset();
1681
1687
  }
@@ -1689,10 +1695,10 @@ var InvitationsHandler = class {
1689
1695
  log5("request admission", {
1690
1696
  ...protocol.toJSON()
1691
1697
  }, {
1692
- file: "invitations-handler.ts",
1693
- line: 311,
1694
- scope: this,
1695
- callSite: (f, a) => f(...a)
1698
+ F: __dxlog_file5,
1699
+ L: 311,
1700
+ S: this,
1701
+ C: (f, a) => f(...a)
1696
1702
  });
1697
1703
  const admissionRequest = await protocol.createAdmissionRequest();
1698
1704
  const admissionResponse = await extension.rpc.InvitationHostService.admit(admissionRequest);
@@ -1701,10 +1707,10 @@ var InvitationsHandler = class {
1701
1707
  log5("admitted by host", {
1702
1708
  ...protocol.toJSON()
1703
1709
  }, {
1704
- file: "invitations-handler.ts",
1705
- line: 322,
1706
- scope: this,
1707
- callSite: (f, a) => f(...a)
1710
+ F: __dxlog_file5,
1711
+ L: 322,
1712
+ S: this,
1713
+ C: (f, a) => f(...a)
1708
1714
  });
1709
1715
  setState({
1710
1716
  ...result,
@@ -1713,30 +1719,30 @@ var InvitationsHandler = class {
1713
1719
  log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace3.end({
1714
1720
  id: traceId
1715
1721
  }), {
1716
- file: "invitations-handler.ts",
1717
- line: 324,
1718
- scope: this,
1719
- callSite: (f, a) => f(...a)
1722
+ F: __dxlog_file5,
1723
+ L: 324,
1724
+ S: this,
1725
+ C: (f, a) => f(...a)
1720
1726
  });
1721
1727
  } catch (err) {
1722
1728
  if (err instanceof TimeoutError) {
1723
1729
  log5("timeout", {
1724
1730
  ...protocol.toJSON()
1725
1731
  }, {
1726
- file: "invitations-handler.ts",
1727
- line: 327,
1728
- scope: this,
1729
- callSite: (f, a) => f(...a)
1732
+ F: __dxlog_file5,
1733
+ L: 327,
1734
+ S: this,
1735
+ C: (f, a) => f(...a)
1730
1736
  });
1731
1737
  setState({
1732
1738
  state: Invitation3.State.TIMEOUT
1733
1739
  });
1734
1740
  } else {
1735
1741
  log5("auth failed", err, {
1736
- file: "invitations-handler.ts",
1737
- line: 330,
1738
- scope: this,
1739
- callSite: (f, a) => f(...a)
1742
+ F: __dxlog_file5,
1743
+ L: 330,
1744
+ S: this,
1745
+ C: (f, a) => f(...a)
1740
1746
  });
1741
1747
  stream.error(err);
1742
1748
  }
@@ -1744,10 +1750,10 @@ var InvitationsHandler = class {
1744
1750
  id: traceId,
1745
1751
  error: err
1746
1752
  }), {
1747
- file: "invitations-handler.ts",
1748
- line: 333,
1749
- scope: this,
1750
- callSite: (f, a) => f(...a)
1753
+ F: __dxlog_file5,
1754
+ L: 333,
1755
+ S: this,
1756
+ C: (f, a) => f(...a)
1751
1757
  });
1752
1758
  } finally {
1753
1759
  await ctx.dispose();
@@ -1762,20 +1768,20 @@ var InvitationsHandler = class {
1762
1768
  log5("timeout", {
1763
1769
  ...protocol.toJSON()
1764
1770
  }, {
1765
- file: "invitations-handler.ts",
1766
- line: 344,
1767
- scope: this,
1768
- callSite: (f, a) => f(...a)
1771
+ F: __dxlog_file5,
1772
+ L: 344,
1773
+ S: this,
1774
+ C: (f, a) => f(...a)
1769
1775
  });
1770
1776
  setState({
1771
1777
  state: Invitation3.State.TIMEOUT
1772
1778
  });
1773
1779
  } else {
1774
1780
  log5("auth failed", err, {
1775
- file: "invitations-handler.ts",
1776
- line: 347,
1777
- scope: this,
1778
- callSite: (f, a) => f(...a)
1781
+ F: __dxlog_file5,
1782
+ L: 347,
1783
+ S: this,
1784
+ C: (f, a) => f(...a)
1779
1785
  });
1780
1786
  stream.error(err);
1781
1787
  }
@@ -1784,7 +1790,7 @@ var InvitationsHandler = class {
1784
1790
  return extension;
1785
1791
  };
1786
1792
  scheduleTask2(ctx, async () => {
1787
- assert6(invitation.swarmKey);
1793
+ invariant6(invitation.swarmKey);
1788
1794
  const topic = invitation.swarmKey;
1789
1795
  const swarmConnection = await this._networkManager.joinSwarm({
1790
1796
  topic,
@@ -1817,11 +1823,12 @@ var InvitationsHandler = class {
1817
1823
  };
1818
1824
 
1819
1825
  // packages/sdk/client-services/src/packlets/invitations/invitations-service.ts
1820
- import assert7 from "@dxos/node-std/assert";
1826
+ import invariant7 from "tiny-invariant";
1821
1827
  import { Event as Event3 } from "@dxos/async";
1822
1828
  import { Stream as Stream8 } from "@dxos/codec-protobuf";
1823
1829
  import { log as log6 } from "@dxos/log";
1824
1830
  import { QueryInvitationsResponse } from "@dxos/protocols/proto/dxos/client/services";
1831
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-service.ts";
1825
1832
  var InvitationsServiceImpl = class {
1826
1833
  constructor(_invitationsHandler, _getHandler) {
1827
1834
  this._invitationsHandler = _invitationsHandler;
@@ -1882,35 +1889,35 @@ var InvitationsServiceImpl = class {
1882
1889
  });
1883
1890
  }
1884
1891
  async authenticate({ invitationId, authCode }) {
1885
- log6("authenticating...", {}, {
1886
- file: "invitations-service.ts",
1887
- line: 103,
1888
- scope: this,
1889
- callSite: (f, a) => f(...a)
1892
+ log6("authenticating...", void 0, {
1893
+ F: __dxlog_file6,
1894
+ L: 103,
1895
+ S: this,
1896
+ C: (f, a) => f(...a)
1890
1897
  });
1891
- assert7(invitationId);
1898
+ invariant7(invitationId);
1892
1899
  const observable = this._acceptInvitations.get(invitationId);
1893
1900
  if (!observable) {
1894
1901
  log6.warn("invalid invitation", {
1895
1902
  invitationId
1896
1903
  }, {
1897
- file: "invitations-service.ts",
1898
- line: 107,
1899
- scope: this,
1900
- callSite: (f, a) => f(...a)
1904
+ F: __dxlog_file6,
1905
+ L: 107,
1906
+ S: this,
1907
+ C: (f, a) => f(...a)
1901
1908
  });
1902
1909
  } else {
1903
1910
  await observable.authenticate(authCode);
1904
1911
  }
1905
1912
  }
1906
1913
  async cancelInvitation({ invitationId }) {
1907
- log6("deleting...", {}, {
1908
- file: "invitations-service.ts",
1909
- line: 114,
1910
- scope: this,
1911
- callSite: (f, a) => f(...a)
1914
+ log6("deleting...", void 0, {
1915
+ F: __dxlog_file6,
1916
+ L: 114,
1917
+ S: this,
1918
+ C: (f, a) => f(...a)
1912
1919
  });
1913
- assert7(invitationId);
1920
+ invariant7(invitationId);
1914
1921
  const created = this._createInvitations.get(invitationId);
1915
1922
  const accepted = this._acceptInvitations.get(invitationId);
1916
1923
  if (created) {
@@ -1925,10 +1932,10 @@ var InvitationsServiceImpl = class {
1925
1932
  log6.warn("invalid invitation", {
1926
1933
  invitationId
1927
1934
  }, {
1928
- file: "invitations-service.ts",
1929
- line: 127,
1930
- scope: this,
1931
- callSite: (f, a) => f(...a)
1935
+ F: __dxlog_file6,
1936
+ L: 127,
1937
+ S: this,
1938
+ C: (f, a) => f(...a)
1932
1939
  });
1933
1940
  }
1934
1941
  }
@@ -1985,11 +1992,12 @@ var InvitationsServiceImpl = class {
1985
1992
  };
1986
1993
 
1987
1994
  // packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts
1988
- import assert8 from "@dxos/node-std/assert";
1995
+ import invariant8 from "tiny-invariant";
1989
1996
  import { createAdmissionCredentials, getCredentialAssertion } from "@dxos/credentials";
1990
1997
  import { writeMessages as writeMessages2 } from "@dxos/feed-store";
1991
1998
  import { log as log7 } from "@dxos/log";
1992
1999
  import { Invitation as Invitation4 } from "@dxos/protocols/proto/dxos/client/services";
2000
+ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
1993
2001
  var SpaceInvitationProtocol = class {
1994
2002
  constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
1995
2003
  this._spaceManager = _spaceManager;
@@ -2011,24 +2019,24 @@ var SpaceInvitationProtocol = class {
2011
2019
  }
2012
2020
  async admit(request, guestProfile) {
2013
2021
  var _a;
2014
- assert8(this._spaceKey);
2022
+ invariant8(this._spaceKey);
2015
2023
  const space = await this._spaceManager.spaces.get(this._spaceKey);
2016
- assert8(space);
2017
- assert8(request.space);
2024
+ invariant8(space);
2025
+ invariant8(request.space);
2018
2026
  const { identityKey, deviceKey } = request.space;
2019
2027
  log7("writing guest credentials", {
2020
2028
  host: this._signingContext.deviceKey,
2021
2029
  guest: deviceKey
2022
2030
  }, {
2023
- file: "space-invitation-protocol.ts",
2024
- line: 50,
2025
- scope: this,
2026
- callSite: (f, a) => f(...a)
2031
+ F: __dxlog_file7,
2032
+ L: 50,
2033
+ S: this,
2034
+ C: (f, a) => f(...a)
2027
2035
  });
2028
2036
  const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile);
2029
- assert8(credentials[0].credential);
2037
+ invariant8(credentials[0].credential);
2030
2038
  const spaceMemberCredential = credentials[0].credential.credential;
2031
- assert8(getCredentialAssertion(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
2039
+ invariant8(getCredentialAssertion(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
2032
2040
  await writeMessages2(space.inner.controlPipeline.writer, credentials);
2033
2041
  return {
2034
2042
  space: {
@@ -2056,11 +2064,11 @@ var SpaceInvitationProtocol = class {
2056
2064
  };
2057
2065
  }
2058
2066
  async accept(response) {
2059
- assert8(response.space);
2067
+ invariant8(response.space);
2060
2068
  const { credential, controlTimeframe, dataTimeframe } = response.space;
2061
2069
  const assertion = getCredentialAssertion(credential);
2062
- assert8(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential");
2063
- assert8(credential.subject.id.equals(this._signingContext.identityKey));
2070
+ invariant8(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential");
2071
+ invariant8(credential.subject.id.equals(this._signingContext.identityKey));
2064
2072
  await this._spaceManager.acceptSpace({
2065
2073
  spaceKey: assertion.spaceKey,
2066
2074
  genesisFeedKey: assertion.genesisFeedKey,
@@ -2074,8 +2082,61 @@ var SpaceInvitationProtocol = class {
2074
2082
  }
2075
2083
  };
2076
2084
 
2085
+ // packages/sdk/client-services/src/packlets/services/client-rpc-server.ts
2086
+ import { Stream as Stream9 } from "@dxos/codec-protobuf";
2087
+ import { raise } from "@dxos/debug";
2088
+ import { parseMethodName, RpcPeer } from "@dxos/rpc";
2089
+ var ClientRpcServer = class {
2090
+ constructor(params) {
2091
+ this._handlerCache = /* @__PURE__ */ new Map();
2092
+ const { serviceRegistry, handleCall, handleStream, ...rpcOptions } = params;
2093
+ this._handleCall = handleCall;
2094
+ this._handleStream = handleStream;
2095
+ this._serviceRegistry = serviceRegistry;
2096
+ this._rpcPeer = new RpcPeer({
2097
+ ...rpcOptions,
2098
+ callHandler: (method, params2) => {
2099
+ const [serviceName, methodName] = parseMethodName(method);
2100
+ const handler = (method2, params3) => this._getServiceHandler(serviceName).call(method2, params3);
2101
+ if (this._handleCall) {
2102
+ return this._handleCall(methodName, params2, handler);
2103
+ } else {
2104
+ return handler(methodName, params2);
2105
+ }
2106
+ },
2107
+ streamHandler: (method, params2) => {
2108
+ const [serviceName, methodName] = parseMethodName(method);
2109
+ const handler = (method2, params3) => this._getServiceHandler(serviceName).callStream(method2, params3);
2110
+ if (this._handleStream) {
2111
+ return Stream9.unwrapPromise(this._handleStream(methodName, params2, handler));
2112
+ } else {
2113
+ return handler(methodName, params2);
2114
+ }
2115
+ }
2116
+ });
2117
+ }
2118
+ async open() {
2119
+ await this._rpcPeer.open();
2120
+ }
2121
+ async close() {
2122
+ await this._rpcPeer.close();
2123
+ }
2124
+ _getServiceHandler(serviceName) {
2125
+ var _a;
2126
+ if (!this._handlerCache.has(serviceName)) {
2127
+ const [key, descriptor] = (_a = Object.entries(this._serviceRegistry.descriptors).find(([key2, descriptor2]) => descriptor2.name === serviceName)) != null ? _a : raise(new Error(`Service not available: ${serviceName}`));
2128
+ const service = this._serviceRegistry.services[key];
2129
+ if (!service) {
2130
+ throw new Error(`Service not available: ${serviceName}`);
2131
+ }
2132
+ this._handlerCache.set(serviceName, descriptor.createServer(service));
2133
+ }
2134
+ return this._handlerCache.get(serviceName);
2135
+ }
2136
+ };
2137
+
2077
2138
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2078
- import { Event as Event5, scheduleTask as scheduleTask4, trackLeaks } from "@dxos/async";
2139
+ import { Event as Event5, scheduleTask as scheduleTask4, synchronized, trackLeaks } from "@dxos/async";
2079
2140
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
2080
2141
  import { cancelWithContext as cancelWithContext2, Context as Context6 } from "@dxos/context";
2081
2142
  import { timed } from "@dxos/debug";
@@ -2089,7 +2150,7 @@ import { Timeframe } from "@dxos/timeframe";
2089
2150
  import { ComplexSet as ComplexSet2 } from "@dxos/util";
2090
2151
 
2091
2152
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
2092
- import assert9 from "@dxos/node-std/assert";
2153
+ import invariant9 from "tiny-invariant";
2093
2154
  import { DeferredTask, Event as Event4, scheduleTask as scheduleTask3, sleep, TimeoutError as TimeoutError2, Trigger as Trigger4 } from "@dxos/async";
2094
2155
  import { Context as Context5, rejectOnDispose } from "@dxos/context";
2095
2156
  import { PublicKey as PublicKey6 } from "@dxos/keys";
@@ -2097,6 +2158,7 @@ import { log as log8 } from "@dxos/log";
2097
2158
  import { schema as schema3 } from "@dxos/protocols";
2098
2159
  import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
2099
2160
  import { ComplexMap as ComplexMap2, ComplexSet, entry } from "@dxos/util";
2161
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
2100
2162
  var DEFAULT_RETRY_TIMEOUT = 1e3;
2101
2163
  var DEFAULT_SUCCESS_DELAY = 1e3;
2102
2164
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
@@ -2109,6 +2171,9 @@ var NotarizationPlugin = class {
2109
2171
  this._processedCredentials = new ComplexSet(PublicKey6.hash);
2110
2172
  this._processCredentialsTriggers = new ComplexMap2(PublicKey6.hash);
2111
2173
  }
2174
+ get hasWriter() {
2175
+ return !!this._writer;
2176
+ }
2112
2177
  async open() {
2113
2178
  }
2114
2179
  async close() {
@@ -2121,22 +2186,22 @@ var NotarizationPlugin = class {
2121
2186
  log8("notarize", {
2122
2187
  credentials
2123
2188
  }, {
2124
- file: "notarization-plugin.ts",
2125
- line: 87,
2126
- scope: this,
2127
- callSite: (f, a) => f(...a)
2189
+ F: __dxlog_file8,
2190
+ L: 91,
2191
+ S: this,
2192
+ C: (f, a) => f(...a)
2128
2193
  });
2129
- assert9(credentials.every((credential) => credential.id), "Credentials must have an id");
2194
+ invariant9(credentials.every((credential) => credential.id), "Credentials must have an id");
2130
2195
  const errors = new Trigger4();
2131
2196
  const ctx = this._ctx.derive({
2132
2197
  onError: (err) => {
2133
2198
  log8.warn("Notarization error", {
2134
2199
  err
2135
2200
  }, {
2136
- file: "notarization-plugin.ts",
2137
- line: 96,
2138
- scope: this,
2139
- callSite: (f, a) => f(...a)
2201
+ F: __dxlog_file8,
2202
+ L: 100,
2203
+ S: this,
2204
+ C: (f, a) => f(...a)
2140
2205
  });
2141
2206
  void ctx.dispose();
2142
2207
  errors.throw(err);
@@ -2149,10 +2214,10 @@ var NotarizationPlugin = class {
2149
2214
  timeout,
2150
2215
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
2151
2216
  }, {
2152
- file: "notarization-plugin.ts",
2153
- line: 108,
2154
- scope: this,
2155
- callSite: (f, a) => f(...a)
2217
+ F: __dxlog_file8,
2218
+ L: 112,
2219
+ S: this,
2220
+ C: (f, a) => f(...a)
2156
2221
  });
2157
2222
  void ctx.dispose();
2158
2223
  errors.throw(new TimeoutError2(timeout, "Notarization timed out"));
@@ -2172,10 +2237,10 @@ var NotarizationPlugin = class {
2172
2237
  log8.warn("Exhausted all peers to notarize with", {
2173
2238
  retryIn: retryTimeout
2174
2239
  }, {
2175
- file: "notarization-plugin.ts",
2176
- line: 133,
2177
- scope: this,
2178
- callSite: (f, a) => f(...a)
2240
+ F: __dxlog_file8,
2241
+ L: 137,
2242
+ S: this,
2243
+ C: (f, a) => f(...a)
2179
2244
  });
2180
2245
  peersTried.clear();
2181
2246
  scheduleTask3(ctx, () => notarizeTask.schedule(), retryTimeout);
@@ -2186,28 +2251,28 @@ var NotarizationPlugin = class {
2186
2251
  peer: peer.localPeerId,
2187
2252
  credentialId: credentials.map((credential) => credential.id)
2188
2253
  }, {
2189
- file: "notarization-plugin.ts",
2190
- line: 140,
2191
- scope: this,
2192
- callSite: (f, a) => f(...a)
2254
+ F: __dxlog_file8,
2255
+ L: 144,
2256
+ S: this,
2257
+ C: (f, a) => f(...a)
2193
2258
  });
2194
2259
  await peer.rpc.NotarizationService.notarize({
2195
2260
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
2196
2261
  });
2197
- log8("success", {}, {
2198
- file: "notarization-plugin.ts",
2199
- line: 144,
2200
- scope: this,
2201
- callSite: (f, a) => f(...a)
2262
+ log8("success", void 0, {
2263
+ F: __dxlog_file8,
2264
+ L: 148,
2265
+ S: this,
2266
+ C: (f, a) => f(...a)
2202
2267
  });
2203
2268
  await sleep(successDelay);
2204
2269
  } catch (err) {
2205
2270
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
2206
2271
  log8.warn("error notarizing (recoverable)", err, {
2207
- file: "notarization-plugin.ts",
2208
- line: 148,
2209
- scope: this,
2210
- callSite: (f, a) => f(...a)
2272
+ F: __dxlog_file8,
2273
+ L: 152,
2274
+ S: this,
2275
+ C: (f, a) => f(...a)
2211
2276
  });
2212
2277
  }
2213
2278
  notarizeTask.schedule();
@@ -2221,11 +2286,11 @@ var NotarizationPlugin = class {
2221
2286
  allNotarized,
2222
2287
  errors.wait()
2223
2288
  ]);
2224
- log8("done", {}, {
2225
- file: "notarization-plugin.ts",
2226
- line: 159,
2227
- scope: this,
2228
- callSite: (f, a) => f(...a)
2289
+ log8("done", void 0, {
2290
+ F: __dxlog_file8,
2291
+ L: 163,
2292
+ S: this,
2293
+ C: (f, a) => f(...a)
2229
2294
  });
2230
2295
  } finally {
2231
2296
  await ctx.dispose();
@@ -2234,7 +2299,7 @@ var NotarizationPlugin = class {
2234
2299
  /**
2235
2300
  * Called with credentials arriving from the control pipeline.
2236
2301
  */
2237
- async process(credential) {
2302
+ async processCredential(credential) {
2238
2303
  var _a;
2239
2304
  if (!credential.id) {
2240
2305
  return;
@@ -2244,7 +2309,7 @@ var NotarizationPlugin = class {
2244
2309
  this._processCredentialsTriggers.delete(credential.id);
2245
2310
  }
2246
2311
  setWriter(writer) {
2247
- assert9(!this._writer, "Writer already set.");
2312
+ invariant9(!this._writer, "Writer already set.");
2248
2313
  this._writer = writer;
2249
2314
  }
2250
2315
  async _waitUntilProcessed(id) {
@@ -2262,7 +2327,7 @@ var NotarizationPlugin = class {
2262
2327
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
2263
2328
  }
2264
2329
  for (const credential of (_a = request.credentials) != null ? _a : []) {
2265
- assert9(credential.id, "Credential must have an id");
2330
+ invariant9(credential.id, "Credential must have an id");
2266
2331
  if (this._processedCredentials.has(credential.id)) {
2267
2332
  continue;
2268
2333
  }
@@ -2275,10 +2340,10 @@ var NotarizationPlugin = class {
2275
2340
  log8("extension opened", {
2276
2341
  peer: extension.localPeerId
2277
2342
  }, {
2278
- file: "notarization-plugin.ts",
2279
- line: 208,
2280
- scope: this,
2281
- callSite: (f, a) => f(...a)
2343
+ F: __dxlog_file8,
2344
+ L: 212,
2345
+ S: this,
2346
+ C: (f, a) => f(...a)
2282
2347
  });
2283
2348
  this._extensions.add(extension);
2284
2349
  this._extensionOpened.emit();
@@ -2287,10 +2352,10 @@ var NotarizationPlugin = class {
2287
2352
  log8("extension closed", {
2288
2353
  peer: extension.localPeerId
2289
2354
  }, {
2290
- file: "notarization-plugin.ts",
2291
- line: 213,
2292
- scope: this,
2293
- callSite: (f, a) => f(...a)
2355
+ F: __dxlog_file8,
2356
+ L: 217,
2357
+ S: this,
2358
+ C: (f, a) => f(...a)
2294
2359
  });
2295
2360
  this._extensions.delete(extension);
2296
2361
  },
@@ -2331,7 +2396,7 @@ var NotarizationTeleportExtension = class extends RpcExtension2 {
2331
2396
  };
2332
2397
 
2333
2398
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2334
- var __decorate = function(decorators, target, key, desc) {
2399
+ function _ts_decorate(decorators, target, key, desc) {
2335
2400
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2336
2401
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2337
2402
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2340,10 +2405,12 @@ var __decorate = function(decorators, target, key, desc) {
2340
2405
  if (d = decorators[i])
2341
2406
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2342
2407
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2343
- };
2408
+ }
2409
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
2344
2410
  var DataSpace = class DataSpace2 {
2345
2411
  constructor(params) {
2346
2412
  this._ctx = new Context6();
2413
+ this._notarizationPlugin = new NotarizationPlugin();
2347
2414
  this._state = SpaceState.CLOSED;
2348
2415
  /**
2349
2416
  * Error for _state === SpaceState.ERROR.
@@ -2366,8 +2433,8 @@ var DataSpace = class DataSpace2 {
2366
2433
  update: this._inner.stateUpdate,
2367
2434
  authTimeout: AUTH_TIMEOUT2
2368
2435
  });
2369
- this._notarizationPluginConsumer = this._inner.spaceState.registerProcessor(new NotarizationPlugin());
2370
2436
  this._cache = params.cache;
2437
+ this._state = params.initialState;
2371
2438
  }
2372
2439
  get key() {
2373
2440
  return this._inner.key;
@@ -2389,25 +2456,36 @@ var DataSpace = class DataSpace2 {
2389
2456
  return this._presence;
2390
2457
  }
2391
2458
  get notarizationPlugin() {
2392
- return this._notarizationPluginConsumer.processor;
2459
+ return this._notarizationPlugin;
2393
2460
  }
2394
2461
  get cache() {
2395
2462
  return this._cache;
2396
2463
  }
2397
2464
  async open() {
2398
- await this.notarizationPlugin.open();
2399
- await this._notarizationPluginConsumer.open();
2465
+ await this._open();
2466
+ }
2467
+ async _open() {
2468
+ await this._notarizationPlugin.open();
2469
+ await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
2400
2470
  await this._inner.open();
2401
- this._state = SpaceState.INACTIVE;
2471
+ this._state = SpaceState.CONTROL_ONLY;
2472
+ this.stateUpdate.emit();
2473
+ this.metrics = {};
2402
2474
  this.metrics.open = new Date();
2403
2475
  }
2404
2476
  async close() {
2477
+ await this._close();
2478
+ }
2479
+ async _close() {
2480
+ var _a, _b;
2481
+ await ((_b = (_a = this._callbacks).beforeClose) == null ? void 0 : _b.call(_a));
2405
2482
  this._state = SpaceState.CLOSED;
2406
2483
  await this._ctx.dispose();
2484
+ this._ctx = new Context6();
2407
2485
  await this.authVerifier.close();
2408
2486
  await this._inner.close();
2409
- await this._notarizationPluginConsumer.close();
2410
- await this.notarizationPlugin.close();
2487
+ await this._inner.spaceState.removeCredentialProcessor(this._notarizationPlugin);
2488
+ await this._notarizationPlugin.close();
2411
2489
  await this._presence.destroy();
2412
2490
  }
2413
2491
  async postMessage(channel, message) {
@@ -2427,18 +2505,18 @@ var DataSpace = class DataSpace2 {
2427
2505
  } catch (err) {
2428
2506
  if (err instanceof CancelledError) {
2429
2507
  log9("Data pipeline initialization cancelled", err, {
2430
- file: "data-space.ts",
2431
- line: 173,
2432
- scope: this,
2433
- callSite: (f, a) => f(...a)
2508
+ F: __dxlog_file9,
2509
+ L: 193,
2510
+ S: this,
2511
+ C: (f, a) => f(...a)
2434
2512
  });
2435
2513
  return;
2436
2514
  }
2437
2515
  log9.error("Error initializing data pipeline", err, {
2438
- file: "data-space.ts",
2439
- line: 177,
2440
- scope: this,
2441
- callSite: (f, a) => f(...a)
2516
+ F: __dxlog_file9,
2517
+ L: 197,
2518
+ S: this,
2519
+ C: (f, a) => f(...a)
2442
2520
  });
2443
2521
  this._state = SpaceState.ERROR;
2444
2522
  this.error = err;
@@ -2450,7 +2528,7 @@ var DataSpace = class DataSpace2 {
2450
2528
  }
2451
2529
  async initializeDataPipeline() {
2452
2530
  var _a, _b, _c, _d;
2453
- if (this._state !== SpaceState.INACTIVE) {
2531
+ if (this._state !== SpaceState.CONTROL_ONLY) {
2454
2532
  throw new SystemError("Invalid operation");
2455
2533
  }
2456
2534
  this._state = SpaceState.INITIALIZING;
@@ -2460,37 +2538,39 @@ var DataSpace = class DataSpace2 {
2460
2538
  });
2461
2539
  this.metrics.controlPipelineReady = new Date();
2462
2540
  await this._createWritableFeeds();
2463
- log9("Writable feeds created", {}, {
2464
- file: "data-space.ts",
2465
- line: 201,
2466
- scope: this,
2467
- callSite: (f, a) => f(...a)
2541
+ log9("Writable feeds created", void 0, {
2542
+ F: __dxlog_file9,
2543
+ L: 221,
2544
+ S: this,
2545
+ C: (f, a) => f(...a)
2468
2546
  });
2469
2547
  this.stateUpdate.emit();
2470
- this.notarizationPlugin.setWriter(createMappedFeedWriter((credential) => ({
2471
- credential: {
2472
- credential
2473
- }
2474
- }), this._inner.controlPipeline.writer));
2548
+ if (!this.notarizationPlugin.hasWriter) {
2549
+ this.notarizationPlugin.setWriter(createMappedFeedWriter((credential) => ({
2550
+ credential: {
2551
+ credential
2552
+ }
2553
+ }), this._inner.controlPipeline.writer));
2554
+ }
2475
2555
  await this._inner.initializeDataPipeline();
2476
2556
  this.metrics.dataPipelineOpen = new Date();
2477
2557
  await cancelWithContext2(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
2478
- log9("waiting for data pipeline to reach target timeframe", {}, {
2479
- file: "data-space.ts",
2480
- line: 220,
2481
- scope: this,
2482
- callSite: (f, a) => f(...a)
2558
+ log9("waiting for data pipeline to reach target timeframe", void 0, {
2559
+ F: __dxlog_file9,
2560
+ L: 242,
2561
+ S: this,
2562
+ C: (f, a) => f(...a)
2483
2563
  });
2484
2564
  await this._inner.dataPipeline.pipelineState.waitUntilReachedTargetTimeframe({
2485
2565
  ctx: this._ctx,
2486
2566
  breakOnStall: false
2487
2567
  });
2488
2568
  this.metrics.dataPipelineReady = new Date();
2489
- log9("data pipeline ready", {}, {
2490
- file: "data-space.ts",
2491
- line: 229,
2492
- scope: this,
2493
- callSite: (f, a) => f(...a)
2569
+ log9("data pipeline ready", void 0, {
2570
+ F: __dxlog_file9,
2571
+ L: 251,
2572
+ S: this,
2573
+ C: (f, a) => f(...a)
2494
2574
  });
2495
2575
  await ((_b = (_a = this._callbacks).beforeReady) == null ? void 0 : _b.call(_a));
2496
2576
  this._state = SpaceState.READY;
@@ -2568,17 +2648,46 @@ var DataSpace = class DataSpace2 {
2568
2648
  }
2569
2649
  }
2570
2650
  }
2651
+ async activate() {
2652
+ if (this._state !== SpaceState.INACTIVE) {
2653
+ throw new SystemError("Invalid operation");
2654
+ }
2655
+ await this._metadataStore.setSpaceState(this.key, SpaceState.ACTIVE);
2656
+ await this._open();
2657
+ this.initializeDataPipelineAsync();
2658
+ }
2659
+ async deactivate() {
2660
+ if (this._state === SpaceState.INACTIVE) {
2661
+ throw new SystemError("Invalid operation");
2662
+ }
2663
+ await this._metadataStore.setSpaceState(this.key, SpaceState.INACTIVE);
2664
+ await this._close();
2665
+ this._state = SpaceState.INACTIVE;
2666
+ this.stateUpdate.emit();
2667
+ }
2571
2668
  };
2572
- __decorate([
2669
+ _ts_decorate([
2670
+ synchronized
2671
+ ], DataSpace.prototype, "open", null);
2672
+ _ts_decorate([
2673
+ synchronized
2674
+ ], DataSpace.prototype, "close", null);
2675
+ _ts_decorate([
2573
2676
  timed(1e4)
2574
2677
  ], DataSpace.prototype, "_createWritableFeeds", null);
2575
- DataSpace = __decorate([
2678
+ _ts_decorate([
2679
+ synchronized
2680
+ ], DataSpace.prototype, "activate", null);
2681
+ _ts_decorate([
2682
+ synchronized
2683
+ ], DataSpace.prototype, "deactivate", null);
2684
+ DataSpace = _ts_decorate([
2576
2685
  trackLeaks("open", "close")
2577
2686
  ], DataSpace);
2578
2687
 
2579
2688
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
2580
- import assert10 from "@dxos/node-std/assert";
2581
- import { Event as Event6, synchronized, trackLeaks as trackLeaks2 } from "@dxos/async";
2689
+ import invariant10 from "tiny-invariant";
2690
+ import { Event as Event6, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
2582
2691
  import { cancelWithContext as cancelWithContext3, Context as Context7 } from "@dxos/context";
2583
2692
  import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
2584
2693
  import { PublicKey as PublicKey8 } from "@dxos/keys";
@@ -2659,7 +2768,7 @@ var spaceGenesis = async (keyring, signingContext, space) => {
2659
2768
  };
2660
2769
 
2661
2770
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
2662
- var __decorate2 = function(decorators, target, key, desc) {
2771
+ function _ts_decorate2(decorators, target, key, desc) {
2663
2772
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2664
2773
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2665
2774
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2668,7 +2777,8 @@ var __decorate2 = function(decorators, target, key, desc) {
2668
2777
  if (d = decorators[i])
2669
2778
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2670
2779
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2671
- };
2780
+ }
2781
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
2672
2782
  var DataSpaceManager = class DataSpaceManager2 {
2673
2783
  constructor(_spaceManager, _metadataStore, _dataServiceSubscriptions, _keyring, _signingContext, _feedStore) {
2674
2784
  this._spaceManager = _spaceManager;
@@ -2688,50 +2798,52 @@ var DataSpaceManager = class DataSpaceManager2 {
2688
2798
  return this._spaces;
2689
2799
  }
2690
2800
  async open() {
2691
- log10("open", {}, {
2692
- file: "data-space-manager.ts",
2693
- line: 80,
2694
- scope: this,
2695
- callSite: (f, a) => f(...a)
2801
+ log10("open", void 0, {
2802
+ F: __dxlog_file10,
2803
+ L: 80,
2804
+ S: this,
2805
+ C: (f, a) => f(...a)
2696
2806
  });
2697
2807
  log10.trace("dxos.echo.data-space-manager.open", trace4.begin({
2698
2808
  id: this._instanceId
2699
2809
  }), {
2700
- file: "data-space-manager.ts",
2701
- line: 81,
2702
- scope: this,
2703
- callSite: (f, a) => f(...a)
2810
+ F: __dxlog_file10,
2811
+ L: 81,
2812
+ S: this,
2813
+ C: (f, a) => f(...a)
2704
2814
  });
2705
2815
  await this._metadataStore.load();
2706
2816
  log10("metadata loaded", {
2707
2817
  spaces: this._metadataStore.spaces.length
2708
2818
  }, {
2709
- file: "data-space-manager.ts",
2710
- line: 83,
2711
- scope: this,
2712
- callSite: (f, a) => f(...a)
2819
+ F: __dxlog_file10,
2820
+ L: 83,
2821
+ S: this,
2822
+ C: (f, a) => f(...a)
2713
2823
  });
2714
2824
  for (const spaceMetadata of this._metadataStore.spaces) {
2715
2825
  try {
2716
2826
  log10("load space", {
2717
2827
  spaceMetadata
2718
2828
  }, {
2719
- file: "data-space-manager.ts",
2720
- line: 87,
2721
- scope: this,
2722
- callSite: (f, a) => f(...a)
2829
+ F: __dxlog_file10,
2830
+ L: 87,
2831
+ S: this,
2832
+ C: (f, a) => f(...a)
2723
2833
  });
2724
2834
  const space = await this._constructSpace(spaceMetadata);
2725
- space.initializeDataPipelineAsync();
2835
+ if (spaceMetadata.state !== SpaceState2.INACTIVE) {
2836
+ space.initializeDataPipelineAsync();
2837
+ }
2726
2838
  } catch (err) {
2727
2839
  log10.error("Error loading space", {
2728
2840
  spaceMetadata,
2729
2841
  err
2730
2842
  }, {
2731
- file: "data-space-manager.ts",
2732
- line: 91,
2733
- scope: this,
2734
- callSite: (f, a) => f(...a)
2843
+ F: __dxlog_file10,
2844
+ L: 93,
2845
+ S: this,
2846
+ C: (f, a) => f(...a)
2735
2847
  });
2736
2848
  }
2737
2849
  }
@@ -2740,18 +2852,18 @@ var DataSpaceManager = class DataSpaceManager2 {
2740
2852
  log10.trace("dxos.echo.data-space-manager.open", trace4.end({
2741
2853
  id: this._instanceId
2742
2854
  }), {
2743
- file: "data-space-manager.ts",
2744
- line: 97,
2745
- scope: this,
2746
- callSite: (f, a) => f(...a)
2855
+ F: __dxlog_file10,
2856
+ L: 99,
2857
+ S: this,
2858
+ C: (f, a) => f(...a)
2747
2859
  });
2748
2860
  }
2749
2861
  async close() {
2750
- log10("close", {}, {
2751
- file: "data-space-manager.ts",
2752
- line: 102,
2753
- scope: this,
2754
- callSite: (f, a) => f(...a)
2862
+ log10("close", void 0, {
2863
+ F: __dxlog_file10,
2864
+ L: 104,
2865
+ S: this,
2866
+ C: (f, a) => f(...a)
2755
2867
  });
2756
2868
  this._isOpen = false;
2757
2869
  await this._ctx.dispose();
@@ -2763,7 +2875,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2763
2875
  * Creates a new space writing the genesis credentials to the control feed.
2764
2876
  */
2765
2877
  async createSpace() {
2766
- assert10(this._isOpen, "Not open.");
2878
+ invariant10(this._isOpen, "Not open.");
2767
2879
  const spaceKey = await this._keyring.createKey();
2768
2880
  const controlFeedKey = await this._keyring.createKey();
2769
2881
  const dataFeedKey = await this._keyring.createKey();
@@ -2771,21 +2883,22 @@ var DataSpaceManager = class DataSpaceManager2 {
2771
2883
  key: spaceKey,
2772
2884
  genesisFeedKey: controlFeedKey,
2773
2885
  controlFeedKey,
2774
- dataFeedKey
2886
+ dataFeedKey,
2887
+ state: SpaceState2.ACTIVE
2775
2888
  };
2776
2889
  log10("creating space...", {
2777
2890
  spaceKey
2778
2891
  }, {
2779
- file: "data-space-manager.ts",
2780
- line: 126,
2781
- scope: this,
2782
- callSite: (f, a) => f(...a)
2892
+ F: __dxlog_file10,
2893
+ L: 129,
2894
+ S: this,
2895
+ C: (f, a) => f(...a)
2783
2896
  });
2784
2897
  const space = await this._constructSpace(metadata);
2785
2898
  const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner);
2786
2899
  await this._metadataStore.addSpace(metadata);
2787
2900
  const memberCredential = credentials[1];
2788
- assert10(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
2901
+ invariant10(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
2789
2902
  await this._signingContext.recordCredential(memberCredential);
2790
2903
  await space.initializeDataPipeline();
2791
2904
  this.updated.emit();
@@ -2796,13 +2909,13 @@ var DataSpaceManager = class DataSpaceManager2 {
2796
2909
  log10("accept space", {
2797
2910
  opts
2798
2911
  }, {
2799
- file: "data-space-manager.ts",
2800
- line: 145,
2801
- scope: this,
2802
- callSite: (f, a) => f(...a)
2912
+ F: __dxlog_file10,
2913
+ L: 148,
2914
+ S: this,
2915
+ C: (f, a) => f(...a)
2803
2916
  });
2804
- assert10(this._isOpen, "Not open.");
2805
- assert10(!this._spaces.has(opts.spaceKey), "Space already exists.");
2917
+ invariant10(this._isOpen, "Not open.");
2918
+ invariant10(!this._spaces.has(opts.spaceKey), "Space already exists.");
2806
2919
  const metadata = {
2807
2920
  key: opts.spaceKey,
2808
2921
  genesisFeedKey: opts.genesisFeedKey,
@@ -2830,10 +2943,10 @@ var DataSpaceManager = class DataSpaceManager2 {
2830
2943
  log10("construct space", {
2831
2944
  metadata
2832
2945
  }, {
2833
- file: "data-space-manager.ts",
2834
- line: 181,
2835
- scope: this,
2836
- callSite: (f, a) => f(...a)
2946
+ F: __dxlog_file10,
2947
+ L: 183,
2948
+ S: this,
2949
+ C: (f, a) => f(...a)
2837
2950
  });
2838
2951
  const gossip = new Gossip({
2839
2952
  localPeerId: this._signingContext.deviceKey
@@ -2865,11 +2978,11 @@ var DataSpaceManager = class DataSpaceManager2 {
2865
2978
  session.addExtension("dxos.mesh.teleport.notarization", dataSpace.notarizationPlugin.createExtension());
2866
2979
  },
2867
2980
  onAuthFailure: () => {
2868
- log10.warn("auth failure", {}, {
2869
- file: "data-space-manager.ts",
2870
- line: 212,
2871
- scope: this,
2872
- callSite: (f, a) => f(...a)
2981
+ log10.warn("auth failure", void 0, {
2982
+ F: __dxlog_file10,
2983
+ L: 214,
2984
+ S: this,
2985
+ C: (f, a) => f(...a)
2873
2986
  });
2874
2987
  },
2875
2988
  memberKey: this._signingContext.identityKey
@@ -2878,6 +2991,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2878
2991
  dataFeed && space.setDataFeed(dataFeed);
2879
2992
  const dataSpace = new DataSpace({
2880
2993
  inner: space,
2994
+ initialState: metadata.state === SpaceState2.INACTIVE ? SpaceState2.INACTIVE : SpaceState2.CLOSED,
2881
2995
  metadataStore: this._metadataStore,
2882
2996
  gossip,
2883
2997
  presence,
@@ -2889,31 +3003,44 @@ var DataSpaceManager = class DataSpaceManager2 {
2889
3003
  log10("before space ready", {
2890
3004
  space: space.key
2891
3005
  }, {
2892
- file: "data-space-manager.ts",
2893
- line: 229,
2894
- scope: this,
2895
- callSite: (f, a) => f(...a)
3006
+ F: __dxlog_file10,
3007
+ L: 232,
3008
+ S: this,
3009
+ C: (f, a) => f(...a)
2896
3010
  });
2897
- this._dataServiceSubscriptions.registerSpace(space.key, dataSpace.dataPipeline.databaseHost.createDataServiceHost());
3011
+ await this._dataServiceSubscriptions.registerSpace(space.key, dataSpace.dataPipeline.databaseHost.createDataServiceHost());
2898
3012
  },
2899
3013
  afterReady: async () => {
2900
3014
  log10("after space ready", {
2901
3015
  space: space.key,
2902
3016
  open: this._isOpen
2903
3017
  }, {
2904
- file: "data-space-manager.ts",
2905
- line: 236,
2906
- scope: this,
2907
- callSite: (f, a) => f(...a)
3018
+ F: __dxlog_file10,
3019
+ L: 239,
3020
+ S: this,
3021
+ C: (f, a) => f(...a)
2908
3022
  });
2909
3023
  if (this._isOpen) {
2910
3024
  this.updated.emit();
2911
3025
  }
3026
+ },
3027
+ beforeClose: async () => {
3028
+ log10("before space close", {
3029
+ space: space.key
3030
+ }, {
3031
+ F: __dxlog_file10,
3032
+ L: 245,
3033
+ S: this,
3034
+ C: (f, a) => f(...a)
3035
+ });
3036
+ await this._dataServiceSubscriptions.unregisterSpace(space.key);
2912
3037
  }
2913
3038
  },
2914
3039
  cache: metadata.cache
2915
3040
  });
2916
- await dataSpace.open();
3041
+ if (metadata.state !== SpaceState2.INACTIVE) {
3042
+ await dataSpace.open();
3043
+ }
2917
3044
  if (metadata.controlTimeframe) {
2918
3045
  dataSpace.inner.controlPipeline.state.setTargetTimeframe(metadata.controlTimeframe);
2919
3046
  }
@@ -2924,31 +3051,33 @@ var DataSpaceManager = class DataSpaceManager2 {
2924
3051
  return dataSpace;
2925
3052
  }
2926
3053
  };
2927
- __decorate2([
2928
- synchronized
3054
+ _ts_decorate2([
3055
+ synchronized2
2929
3056
  ], DataSpaceManager.prototype, "open", null);
2930
- __decorate2([
2931
- synchronized
3057
+ _ts_decorate2([
3058
+ synchronized2
2932
3059
  ], DataSpaceManager.prototype, "close", null);
2933
- __decorate2([
2934
- synchronized
3060
+ _ts_decorate2([
3061
+ synchronized2
2935
3062
  ], DataSpaceManager.prototype, "createSpace", null);
2936
- __decorate2([
2937
- synchronized
3063
+ _ts_decorate2([
3064
+ synchronized2
2938
3065
  ], DataSpaceManager.prototype, "acceptSpace", null);
2939
- DataSpaceManager = __decorate2([
3066
+ DataSpaceManager = _ts_decorate2([
2940
3067
  trackLeaks2("open", "close")
2941
3068
  ], DataSpaceManager);
2942
3069
 
2943
3070
  // packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
2944
3071
  import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTask as scheduleTask5 } from "@dxos/async";
2945
- import { Stream as Stream9 } from "@dxos/codec-protobuf";
2946
- import { raise, todo as todo2 } from "@dxos/debug";
3072
+ import { Stream as Stream10 } from "@dxos/codec-protobuf";
3073
+ import { raise as raise2 } from "@dxos/debug";
2947
3074
  import { SpaceNotFoundError } from "@dxos/echo-pipeline";
3075
+ import { ApiError } from "@dxos/errors";
2948
3076
  import { log as log11 } from "@dxos/log";
2949
3077
  import { encodeError } from "@dxos/protocols";
2950
- import { SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/client/services";
3078
+ import { SpaceMember as SpaceMember2, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
2951
3079
  import { humanize } from "@dxos/util";
3080
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
2952
3081
  var SpacesServiceImpl = class {
2953
3082
  constructor(_identityManager, _spaceManager, _dataServiceSubscriptions, _getDataSpaceManager) {
2954
3083
  this._identityManager = _identityManager;
@@ -2964,21 +3093,35 @@ var SpacesServiceImpl = class {
2964
3093
  const space = await dataSpaceManager.createSpace();
2965
3094
  return this._serializeSpace(space);
2966
3095
  }
2967
- async updateSpace(request) {
2968
- todo2();
3096
+ async updateSpace({ spaceKey, state }) {
3097
+ var _a;
3098
+ const dataSpaceManager = await this._getDataSpaceManager();
3099
+ const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3100
+ if (state) {
3101
+ switch (state) {
3102
+ case SpaceState3.ACTIVE:
3103
+ await space.activate();
3104
+ break;
3105
+ case SpaceState3.INACTIVE:
3106
+ await space.deactivate();
3107
+ break;
3108
+ default:
3109
+ throw new ApiError("Invalid space state");
3110
+ }
3111
+ }
2969
3112
  }
2970
3113
  querySpaces() {
2971
- return new Stream9(({ next, ctx }) => {
3114
+ return new Stream10(({ next, ctx }) => {
2972
3115
  const scheduler = new UpdateScheduler(ctx, async () => {
2973
3116
  const dataSpaceManager = await this._getDataSpaceManager();
2974
3117
  const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
2975
3118
  log11("update", {
2976
3119
  spaces
2977
3120
  }, {
2978
- file: "spaces-service.ts",
2979
- line: 60,
2980
- scope: this,
2981
- callSite: (f, a) => f(...a)
3121
+ F: __dxlog_file11,
3122
+ L: 78,
3123
+ S: this,
3124
+ C: (f, a) => f(...a)
2982
3125
  });
2983
3126
  next({
2984
3127
  spaces
@@ -3019,15 +3162,15 @@ var SpacesServiceImpl = class {
3019
3162
  async postMessage({ spaceKey, channel, message }) {
3020
3163
  var _a;
3021
3164
  const dataSpaceManager = await this._getDataSpaceManager();
3022
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise(new SpaceNotFoundError(spaceKey));
3165
+ const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3023
3166
  await space.postMessage(getChannelId(channel), message);
3024
3167
  }
3025
3168
  subscribeMessages({ spaceKey, channel }) {
3026
- return new Stream9(({ ctx, next }) => {
3169
+ return new Stream10(({ ctx, next }) => {
3027
3170
  scheduleTask5(ctx, async () => {
3028
3171
  var _a;
3029
3172
  const dataSpaceManager = await this._getDataSpaceManager();
3030
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise(new SpaceNotFoundError(spaceKey));
3173
+ const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3031
3174
  const handle = space.listen(getChannelId(channel), (message) => {
3032
3175
  next(message);
3033
3176
  });
@@ -3036,21 +3179,21 @@ var SpacesServiceImpl = class {
3036
3179
  });
3037
3180
  }
3038
3181
  queryCredentials({ spaceKey }) {
3039
- return new Stream9(({ ctx, next }) => {
3182
+ return new Stream10(({ ctx, next }) => {
3040
3183
  var _a;
3041
- const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : raise(new SpaceNotFoundError(spaceKey));
3042
- const processor = space.spaceState.registerProcessor({
3043
- process: async (credential) => {
3184
+ const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3185
+ const processor = {
3186
+ processCredential: async (credential) => {
3044
3187
  next(credential);
3045
3188
  }
3046
- });
3047
- ctx.onDispose(() => processor.close());
3048
- scheduleTask5(ctx, () => processor.open());
3189
+ };
3190
+ ctx.onDispose(() => space.spaceState.removeCredentialProcessor(processor));
3191
+ scheduleTask5(ctx, () => space.spaceState.addCredentialProcessor(processor));
3049
3192
  });
3050
3193
  }
3051
3194
  async writeCredentials({ spaceKey, credentials }) {
3052
3195
  var _a;
3053
- const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : raise(new SpaceNotFoundError(spaceKey));
3196
+ const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3054
3197
  for (const credential of credentials != null ? credentials : []) {
3055
3198
  await space.controlPipeline.writer.write({
3056
3199
  credential: {
@@ -3062,7 +3205,7 @@ var SpacesServiceImpl = class {
3062
3205
  async createEpoch({ spaceKey }) {
3063
3206
  var _a;
3064
3207
  const dataSpaceManager = await this._getDataSpaceManager();
3065
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise(new SpaceNotFoundError(spaceKey));
3208
+ const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3066
3209
  await space.createEpoch();
3067
3210
  }
3068
3211
  _serializeSpace(space) {
@@ -3105,7 +3248,7 @@ var SpacesServiceImpl = class {
3105
3248
  var getChannelId = (channel) => `user-channel/${channel}`;
3106
3249
 
3107
3250
  // packages/sdk/client-services/src/packlets/services/service-context.ts
3108
- import assert11 from "@dxos/node-std/assert";
3251
+ import invariant11 from "tiny-invariant";
3109
3252
  import { Trigger as Trigger5 } from "@dxos/async";
3110
3253
  import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
3111
3254
  import { failUndefined as failUndefined3 } from "@dxos/debug";
@@ -3117,6 +3260,7 @@ import { log as log12 } from "@dxos/log";
3117
3260
  import { STORAGE_VERSION, trace as trace5 } from "@dxos/protocols";
3118
3261
  import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
3119
3262
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
3263
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
3120
3264
  var ServiceContext = class {
3121
3265
  // prettier-ignore
3122
3266
  constructor(storage, networkManager, signalManager, modelFactory) {
@@ -3160,17 +3304,17 @@ var ServiceContext = class {
3160
3304
  log12.trace("dxos.sdk.service-context.open", trace5.begin({
3161
3305
  id: this._instanceId
3162
3306
  }), {
3163
- file: "service-context.ts",
3164
- line: 126,
3165
- scope: this,
3166
- callSite: (f, a) => f(...a)
3307
+ F: __dxlog_file12,
3308
+ L: 126,
3309
+ S: this,
3310
+ C: (f, a) => f(...a)
3167
3311
  });
3168
3312
  await this._checkStorageVersion();
3169
- log12("opening...", {}, {
3170
- file: "service-context.ts",
3171
- line: 130,
3172
- scope: this,
3173
- callSite: (f, a) => f(...a)
3313
+ log12("opening...", void 0, {
3314
+ F: __dxlog_file12,
3315
+ L: 130,
3316
+ S: this,
3317
+ C: (f, a) => f(...a)
3174
3318
  });
3175
3319
  await this.signalManager.open();
3176
3320
  await this.networkManager.open();
@@ -3179,42 +3323,44 @@ var ServiceContext = class {
3179
3323
  if (this.identityManager.identity) {
3180
3324
  await this._initialize();
3181
3325
  }
3182
- log12("opened", {}, {
3183
- file: "service-context.ts",
3184
- line: 138,
3185
- scope: this,
3186
- callSite: (f, a) => f(...a)
3326
+ log12("opened", void 0, {
3327
+ F: __dxlog_file12,
3328
+ L: 138,
3329
+ S: this,
3330
+ C: (f, a) => f(...a)
3187
3331
  });
3188
3332
  log12.trace("dxos.sdk.service-context.open", trace5.end({
3189
3333
  id: this._instanceId
3190
3334
  }), {
3191
- file: "service-context.ts",
3192
- line: 139,
3193
- scope: this,
3194
- callSite: (f, a) => f(...a)
3335
+ F: __dxlog_file12,
3336
+ L: 139,
3337
+ S: this,
3338
+ C: (f, a) => f(...a)
3195
3339
  });
3196
3340
  }
3197
3341
  async close() {
3198
- var _a, _b;
3199
- log12("closing...", {}, {
3200
- file: "service-context.ts",
3201
- line: 143,
3202
- scope: this,
3203
- callSite: (f, a) => f(...a)
3204
- });
3205
- await ((_a = this._deviceSpaceSync) == null ? void 0 : _a.close());
3206
- await ((_b = this.dataSpaceManager) == null ? void 0 : _b.close());
3342
+ var _a;
3343
+ log12("closing...", void 0, {
3344
+ F: __dxlog_file12,
3345
+ L: 143,
3346
+ S: this,
3347
+ C: (f, a) => f(...a)
3348
+ });
3349
+ if (this._deviceSpaceSync && this.identityManager.identity) {
3350
+ await this.identityManager.identity.space.spaceState.removeCredentialProcessor(this._deviceSpaceSync);
3351
+ }
3352
+ await ((_a = this.dataSpaceManager) == null ? void 0 : _a.close());
3207
3353
  await this.identityManager.close();
3208
3354
  await this.spaceManager.close();
3209
3355
  await this.feedStore.close();
3210
3356
  await this.networkManager.close();
3211
3357
  await this.signalManager.close();
3212
3358
  this.dataServiceSubscriptions.clear();
3213
- log12("closed", {}, {
3214
- file: "service-context.ts",
3215
- line: 152,
3216
- scope: this,
3217
- callSite: (f, a) => f(...a)
3359
+ log12("closed", void 0, {
3360
+ F: __dxlog_file12,
3361
+ L: 154,
3362
+ S: this,
3363
+ C: (f, a) => f(...a)
3218
3364
  });
3219
3365
  }
3220
3366
  async createIdentity(params = {}) {
@@ -3224,7 +3370,7 @@ var ServiceContext = class {
3224
3370
  }
3225
3371
  getInvitationHandler(invitation) {
3226
3372
  const factory = this._handlerFactories.get(invitation.kind);
3227
- assert11(factory, `Unknown invitation kind: ${invitation.kind}`);
3373
+ invariant11(factory, `Unknown invitation kind: ${invitation.kind}`);
3228
3374
  return factory(invitation);
3229
3375
  }
3230
3376
  async _acceptIdentity(params) {
@@ -3241,11 +3387,11 @@ var ServiceContext = class {
3241
3387
  // Called when identity is created.
3242
3388
  async _initialize() {
3243
3389
  var _a;
3244
- log12("initializing spaces...", {}, {
3245
- file: "service-context.ts",
3246
- line: 185,
3247
- scope: this,
3248
- callSite: (f, a) => f(...a)
3390
+ log12("initializing spaces...", void 0, {
3391
+ F: __dxlog_file12,
3392
+ L: 187,
3393
+ S: this,
3394
+ C: (f, a) => f(...a)
3249
3395
  });
3250
3396
  const identity = (_a = this.identityManager.identity) != null ? _a : failUndefined3();
3251
3397
  const signingContext = {
@@ -3264,12 +3410,12 @@ var ServiceContext = class {
3264
3410
  this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.dataServiceSubscriptions, this.keyring, signingContext, this.feedStore);
3265
3411
  await this.dataSpaceManager.open();
3266
3412
  this._handlerFactories.set(Invitation5.Kind.SPACE, (invitation) => {
3267
- assert11(this.dataSpaceManager, "dataSpaceManager not initialized yet");
3413
+ invariant11(this.dataSpaceManager, "dataSpaceManager not initialized yet");
3268
3414
  return new SpaceInvitationProtocol(this.dataSpaceManager, signingContext, this.keyring, invitation.spaceKey);
3269
3415
  });
3270
3416
  this.initialized.wake();
3271
- this._deviceSpaceSync = identity.space.spaceState.registerProcessor({
3272
- process: async (credential) => {
3417
+ this._deviceSpaceSync = {
3418
+ processCredential: async (credential) => {
3273
3419
  const assertion = getCredentialAssertion3(credential);
3274
3420
  if (assertion["@type"] !== "dxos.halo.credentials.SpaceMember") {
3275
3421
  return;
@@ -3281,10 +3427,10 @@ var ServiceContext = class {
3281
3427
  log12("dataSpaceManager not initialized yet, ignoring space admission", {
3282
3428
  details: assertion
3283
3429
  }, {
3284
- file: "service-context.ts",
3285
- line: 224,
3286
- scope: this,
3287
- callSite: (f, a) => f(...a)
3430
+ F: __dxlog_file12,
3431
+ L: 226,
3432
+ S: this,
3433
+ C: (f, a) => f(...a)
3288
3434
  });
3289
3435
  return;
3290
3436
  }
@@ -3292,10 +3438,10 @@ var ServiceContext = class {
3292
3438
  log12("space already exists, ignoring space admission", {
3293
3439
  details: assertion
3294
3440
  }, {
3295
- file: "service-context.ts",
3296
- line: 228,
3297
- scope: this,
3298
- callSite: (f, a) => f(...a)
3441
+ F: __dxlog_file12,
3442
+ L: 230,
3443
+ S: this,
3444
+ C: (f, a) => f(...a)
3299
3445
  });
3300
3446
  return;
3301
3447
  }
@@ -3303,26 +3449,26 @@ var ServiceContext = class {
3303
3449
  log12("accepting space recorded in halo", {
3304
3450
  details: assertion
3305
3451
  }, {
3306
- file: "service-context.ts",
3307
- line: 233,
3308
- scope: this,
3309
- callSite: (f, a) => f(...a)
3452
+ F: __dxlog_file12,
3453
+ L: 235,
3454
+ S: this,
3455
+ C: (f, a) => f(...a)
3310
3456
  });
3311
3457
  await this.dataSpaceManager.acceptSpace({
3312
3458
  spaceKey: assertion.spaceKey,
3313
3459
  genesisFeedKey: assertion.genesisFeedKey
3314
3460
  });
3315
3461
  } catch (err) {
3316
- log12.catch(err, {}, {
3317
- file: "service-context.ts",
3318
- line: 239,
3319
- scope: this,
3320
- callSite: (f, a) => f(...a)
3462
+ log12.catch(err, void 0, {
3463
+ F: __dxlog_file12,
3464
+ L: 241,
3465
+ S: this,
3466
+ C: (f, a) => f(...a)
3321
3467
  });
3322
3468
  }
3323
3469
  }
3324
- });
3325
- await this._deviceSpaceSync.open();
3470
+ };
3471
+ await identity.space.spaceState.addCredentialProcessor(this._deviceSpaceSync);
3326
3472
  }
3327
3473
  };
3328
3474
 
@@ -3330,7 +3476,7 @@ var ServiceContext = class {
3330
3476
  import { asyncTimeout, Trigger as Trigger6 } from "@dxos/async";
3331
3477
  import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
3332
3478
  import { log as log13, logInfo } from "@dxos/log";
3333
- var __decorate3 = function(decorators, target, key, desc) {
3479
+ function _ts_decorate3(decorators, target, key, desc) {
3334
3480
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3335
3481
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3336
3482
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3339,7 +3485,8 @@ var __decorate3 = function(decorators, target, key, desc) {
3339
3485
  if (d = decorators[i])
3340
3486
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3341
3487
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3342
- };
3488
+ }
3489
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
3343
3490
  var Message;
3344
3491
  (function(Message2) {
3345
3492
  Message2["ACQUIRING"] = "acquiring";
@@ -3361,32 +3508,32 @@ var Lock = class {
3361
3508
  message: Message.ACQUIRING
3362
3509
  });
3363
3510
  try {
3364
- log13("aquiring lock...", {}, {
3365
- file: "browser.ts",
3366
- line: 42,
3367
- scope: this,
3368
- callSite: (f, a) => f(...a)
3511
+ log13("aquiring lock...", void 0, {
3512
+ F: __dxlog_file13,
3513
+ L: 42,
3514
+ S: this,
3515
+ C: (f, a) => f(...a)
3369
3516
  });
3370
3517
  await asyncTimeout(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
3371
- log13("acquired lock", {}, {
3372
- file: "browser.ts",
3373
- line: 44,
3374
- scope: this,
3375
- callSite: (f, a) => f(...a)
3518
+ log13("acquired lock", void 0, {
3519
+ F: __dxlog_file13,
3520
+ L: 44,
3521
+ S: this,
3522
+ C: (f, a) => f(...a)
3376
3523
  });
3377
3524
  } catch (e) {
3378
- log13("stealing lock...", {}, {
3379
- file: "browser.ts",
3380
- line: 46,
3381
- scope: this,
3382
- callSite: (f, a) => f(...a)
3525
+ log13("stealing lock...", void 0, {
3526
+ F: __dxlog_file13,
3527
+ L: 46,
3528
+ S: this,
3529
+ C: (f, a) => f(...a)
3383
3530
  });
3384
3531
  await this._requestLock(true);
3385
- log13("stolen lock", {}, {
3386
- file: "browser.ts",
3387
- line: 48,
3388
- scope: this,
3389
- callSite: (f, a) => f(...a)
3532
+ log13("stolen lock", void 0, {
3533
+ F: __dxlog_file13,
3534
+ L: 48,
3535
+ S: this,
3536
+ C: (f, a) => f(...a)
3390
3537
  });
3391
3538
  }
3392
3539
  }
@@ -3402,10 +3549,10 @@ var Lock = class {
3402
3549
  log13("requesting lock...", {
3403
3550
  steal
3404
3551
  }, {
3405
- file: "browser.ts",
3406
- line: 63,
3407
- scope: this,
3408
- callSite: (f, a) => f(...a)
3552
+ F: __dxlog_file13,
3553
+ L: 63,
3554
+ S: this,
3555
+ C: (f, a) => f(...a)
3409
3556
  });
3410
3557
  const acquired = new Trigger6();
3411
3558
  void navigator.locks.request(this._lockKey, {
@@ -3416,18 +3563,18 @@ var Lock = class {
3416
3563
  acquired.wake();
3417
3564
  this._releaseTrigger = new Trigger6();
3418
3565
  await this._releaseTrigger.wait();
3419
- log13("releasing lock...", {}, {
3420
- file: "browser.ts",
3421
- line: 72,
3422
- scope: this,
3423
- callSite: (f, a) => f(...a)
3566
+ log13("releasing lock...", void 0, {
3567
+ F: __dxlog_file13,
3568
+ L: 72,
3569
+ S: this,
3570
+ C: (f, a) => f(...a)
3424
3571
  });
3425
3572
  await ((_b = this._onRelease) == null ? void 0 : _b.call(this));
3426
- log13("released lock", {}, {
3427
- file: "browser.ts",
3428
- line: 74,
3429
- scope: this,
3430
- callSite: (f, a) => f(...a)
3573
+ log13("released lock", void 0, {
3574
+ F: __dxlog_file13,
3575
+ L: 74,
3576
+ S: this,
3577
+ C: (f, a) => f(...a)
3431
3578
  });
3432
3579
  }).catch(async () => {
3433
3580
  var _a;
@@ -3437,14 +3584,14 @@ var Lock = class {
3437
3584
  log13("recieved lock", {
3438
3585
  steal
3439
3586
  }, {
3440
- file: "browser.ts",
3441
- line: 81,
3442
- scope: this,
3443
- callSite: (f, a) => f(...a)
3587
+ F: __dxlog_file13,
3588
+ L: 81,
3589
+ S: this,
3590
+ C: (f, a) => f(...a)
3444
3591
  });
3445
3592
  }
3446
3593
  };
3447
- __decorate3([
3594
+ _ts_decorate3([
3448
3595
  logInfo
3449
3596
  ], Lock.prototype, "lockKey", null);
3450
3597
  var isLocked = (lockPath) => {
@@ -3525,20 +3672,23 @@ var ServiceRegistry = class {
3525
3672
  };
3526
3673
 
3527
3674
  // packages/sdk/client-services/src/packlets/services/service-host.ts
3528
- import assert12 from "@dxos/node-std/assert";
3529
- import { Event as Event8, synchronized as synchronized2 } from "@dxos/async";
3530
- import { clientServiceBundle, createDefaultModelFactory } from "@dxos/client-protocol";
3675
+ import invariant12 from "tiny-invariant";
3676
+ import { Event as Event8, synchronized as synchronized3 } from "@dxos/async";
3677
+ import { clientServiceBundle } from "@dxos/client-protocol";
3678
+ import { DocumentModel } from "@dxos/document-model";
3531
3679
  import { DataServiceImpl } from "@dxos/echo-pipeline";
3532
3680
  import { PublicKey as PublicKey10 } from "@dxos/keys";
3533
3681
  import { log as log15 } from "@dxos/log";
3534
3682
  import { WebsocketSignalManager } from "@dxos/messaging";
3683
+ import { ModelFactory } from "@dxos/model-factory";
3535
3684
  import { createWebRTCTransportFactory, NetworkManager } from "@dxos/network-manager";
3536
3685
  import { trace as trace6 } from "@dxos/protocols";
3537
3686
  import { SystemStatus } from "@dxos/protocols/proto/dxos/client/services";
3687
+ import { TextModel } from "@dxos/text-model";
3538
3688
 
3539
3689
  // packages/sdk/client-services/src/packlets/devices/devices-service.ts
3540
3690
  import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
3541
- import { Stream as Stream10 } from "@dxos/codec-protobuf";
3691
+ import { Stream as Stream11 } from "@dxos/codec-protobuf";
3542
3692
  import { DeviceKind } from "@dxos/protocols/proto/dxos/client/services";
3543
3693
  var DevicesServiceImpl = class {
3544
3694
  constructor(_identityManager) {
@@ -3548,7 +3698,7 @@ var DevicesServiceImpl = class {
3548
3698
  throw new Error("Method not implemented.");
3549
3699
  }
3550
3700
  queryDevices() {
3551
- return new Stream10(({ next }) => {
3701
+ return new Stream11(({ next }) => {
3552
3702
  const update = () => {
3553
3703
  var _a;
3554
3704
  const deviceKeys = (_a = this._identityManager.identity) == null ? void 0 : _a.authorizedDeviceKeys;
@@ -3585,7 +3735,7 @@ var DevicesServiceImpl = class {
3585
3735
 
3586
3736
  // packages/sdk/client-services/src/packlets/logging/logging-service.ts
3587
3737
  import { Event as Event7 } from "@dxos/async";
3588
- import { Stream as Stream11 } from "@dxos/codec-protobuf";
3738
+ import { Stream as Stream12 } from "@dxos/codec-protobuf";
3589
3739
  import { getContextFromEntry, log as log14 } from "@dxos/log";
3590
3740
  import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
3591
3741
  import { jsonify } from "@dxos/util";
@@ -3604,13 +3754,13 @@ var LoggingServiceImpl = class {
3604
3754
  log14.runtimeConfig.processors.splice(index, 1);
3605
3755
  }
3606
3756
  queryLogs(request) {
3607
- return new Stream11(({ ctx, next }) => {
3757
+ return new Stream12(({ ctx, next }) => {
3608
3758
  const handler = (entry2) => {
3609
3759
  var _a, _b, _c, _d, _e;
3610
3760
  if (LOG_PROCESSING > 0) {
3611
3761
  return;
3612
3762
  }
3613
- if (((_a = entry2.meta) == null ? void 0 : _a.file.includes("logging-service")) || entry2.context && Object.values(entry2.context).some((value) => typeof value === "string" && value.includes("LoggingService"))) {
3763
+ if (((_a = entry2.meta) == null ? void 0 : _a.F.includes("logging-service")) || entry2.context && Object.values(entry2.context).some((value) => typeof value === "string" && value.includes("LoggingService"))) {
3614
3764
  return;
3615
3765
  }
3616
3766
  if (!shouldLog(entry2, request)) {
@@ -3622,8 +3772,8 @@ var LoggingServiceImpl = class {
3622
3772
  timestamp: new Date(),
3623
3773
  meta: {
3624
3774
  // TODO(dmaretskyi): Fix proto.
3625
- file: (_c = (_b = entry2.meta) == null ? void 0 : _b.file) != null ? _c : "",
3626
- line: (_e = (_d = entry2.meta) == null ? void 0 : _d.line) != null ? _e : 0
3775
+ file: (_c = (_b = entry2.meta) == null ? void 0 : _b.F) != null ? _c : "",
3776
+ line: (_e = (_d = entry2.meta) == null ? void 0 : _d.L) != null ? _e : 0
3627
3777
  }
3628
3778
  };
3629
3779
  try {
@@ -3653,21 +3803,21 @@ var shouldLog = (entry2, request) => {
3653
3803
  } else {
3654
3804
  return request.filters.some((filter) => {
3655
3805
  var _a2, _b;
3656
- return matchFilter(filter, entry2.level, (_b = (_a2 = entry2.meta) == null ? void 0 : _a2.file) != null ? _b : "", options);
3806
+ return matchFilter(filter, entry2.level, (_b = (_a2 = entry2.meta) == null ? void 0 : _a2.F) != null ? _b : "", options);
3657
3807
  });
3658
3808
  }
3659
3809
  };
3660
3810
  var LOG_PROCESSING = 0;
3661
3811
 
3662
3812
  // packages/sdk/client-services/src/packlets/network/network-service.ts
3663
- import { Stream as Stream12 } from "@dxos/codec-protobuf";
3813
+ import { Stream as Stream13 } from "@dxos/codec-protobuf";
3664
3814
  var NetworkServiceImpl = class {
3665
3815
  constructor(networkManager, signalManager) {
3666
3816
  this.networkManager = networkManager;
3667
3817
  this.signalManager = signalManager;
3668
3818
  }
3669
3819
  queryStatus() {
3670
- return new Stream12(({ next }) => {
3820
+ return new Stream13(({ next }) => {
3671
3821
  const update = () => {
3672
3822
  next({
3673
3823
  swarm: this.networkManager.connectionState,
@@ -3692,7 +3842,7 @@ var NetworkServiceImpl = class {
3692
3842
  };
3693
3843
 
3694
3844
  // packages/sdk/client-services/src/packlets/system/system-service.ts
3695
- import { Stream as Stream13 } from "@dxos/codec-protobuf";
3845
+ import { Stream as Stream14 } from "@dxos/codec-protobuf";
3696
3846
  var SystemServiceImpl = class {
3697
3847
  constructor({ config, statusUpdate, onUpdateStatus, getCurrentStatus, onReset }) {
3698
3848
  this._config = config;
@@ -3709,7 +3859,7 @@ var SystemServiceImpl = class {
3709
3859
  await this._onUpdateStatus(status);
3710
3860
  }
3711
3861
  queryStatus() {
3712
- return new Stream13(({ next }) => {
3862
+ return new Stream14(({ next }) => {
3713
3863
  const update = () => {
3714
3864
  next({
3715
3865
  status: this._getCurrentStatus()
@@ -3730,7 +3880,7 @@ var SystemServiceImpl = class {
3730
3880
  };
3731
3881
 
3732
3882
  // packages/sdk/client-services/src/packlets/services/service-host.ts
3733
- var __decorate4 = function(decorators, target, key, desc) {
3883
+ function _ts_decorate4(decorators, target, key, desc) {
3734
3884
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3735
3885
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3736
3886
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3739,6 +3889,10 @@ var __decorate4 = function(decorators, target, key, desc) {
3739
3889
  if (d = decorators[i])
3740
3890
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3741
3891
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3892
+ }
3893
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
3894
+ var createDefaultModelFactory = () => {
3895
+ return new ModelFactory().registerModel(DocumentModel).registerModel(TextModel);
3742
3896
  };
3743
3897
  var ClientServicesHost = class {
3744
3898
  constructor({
@@ -3750,13 +3904,15 @@ var ClientServicesHost = class {
3750
3904
  connectionLog,
3751
3905
  storage,
3752
3906
  // TODO(wittjosiah): Turn this on by default.
3753
- lockKey
3907
+ lockKey,
3908
+ callbacks
3754
3909
  } = {}) {
3755
3910
  this._statusUpdate = new Event8();
3756
3911
  this._opening = false;
3757
3912
  this._open = false;
3758
3913
  this._storage = storage;
3759
3914
  this._modelFactory = modelFactory;
3915
+ this._callbacks = callbacks;
3760
3916
  if (config) {
3761
3917
  this.initialize({
3762
3918
  config,
@@ -3815,9 +3971,9 @@ var ClientServicesHost = class {
3815
3971
  */
3816
3972
  initialize({ config, ...options }) {
3817
3973
  var _a, _b, _c;
3818
- assert12(!this._open, "service host is open");
3974
+ invariant12(!this._open, "service host is open");
3819
3975
  if (config) {
3820
- assert12(!this._config, "config already set");
3976
+ invariant12(!this._config, "config already set");
3821
3977
  this._config = config;
3822
3978
  if (!this._storage) {
3823
3979
  this._storage = createStorageObjects(config.get("runtime.client.storage", {})).storage;
@@ -3827,7 +3983,7 @@ var ClientServicesHost = class {
3827
3983
  iceServers: (_a = this._config) == null ? void 0 : _a.get("runtime.services.ice")
3828
3984
  }), signalManager = new WebsocketSignalManager((_c = (_b = this._config) == null ? void 0 : _b.get("runtime.services.signaling")) != null ? _c : []) } = options;
3829
3985
  this._signalManager = signalManager;
3830
- assert12(!this._networkManager, "network manager already set");
3986
+ invariant12(!this._networkManager, "network manager already set");
3831
3987
  this._networkManager = new NetworkManager({
3832
3988
  log: connectionLog,
3833
3989
  transportFactory,
@@ -3843,23 +3999,23 @@ var ClientServicesHost = class {
3843
3999
  log15.trace("dxos.sdk.client-services-host.open", trace6.begin({
3844
4000
  id: traceId
3845
4001
  }), {
3846
- file: "service-host.ts",
3847
- line: 188,
3848
- scope: this,
3849
- callSite: (f, a) => f(...a)
3850
- });
3851
- assert12(this._config, "config not set");
3852
- assert12(this._storage, "storage not set");
3853
- assert12(this._signalManager, "signal manager not set");
3854
- assert12(this._networkManager, "network manager not set");
4002
+ F: __dxlog_file14,
4003
+ L: 203,
4004
+ S: this,
4005
+ C: (f, a) => f(...a)
4006
+ });
4007
+ invariant12(this._config, "config not set");
4008
+ invariant12(this._storage, "storage not set");
4009
+ invariant12(this._signalManager, "signal manager not set");
4010
+ invariant12(this._networkManager, "network manager not set");
3855
4011
  this._opening = true;
3856
4012
  log15("opening...", {
3857
4013
  lockKey: (_a = this._resourceLock) == null ? void 0 : _a.lockKey
3858
4014
  }, {
3859
- file: "service-host.ts",
3860
- line: 196,
3861
- scope: this,
3862
- callSite: (f, a) => f(...a)
4015
+ F: __dxlog_file14,
4016
+ L: 211,
4017
+ S: this,
4018
+ C: (f, a) => f(...a)
3863
4019
  });
3864
4020
  await ((_b = this._resourceLock) == null ? void 0 : _b.acquire());
3865
4021
  await this._loggingService.open();
@@ -3891,18 +4047,18 @@ var ClientServicesHost = class {
3891
4047
  log15("opened", {
3892
4048
  deviceKey
3893
4049
  }, {
3894
- file: "service-host.ts",
3895
- line: 251,
3896
- scope: this,
3897
- callSite: (f, a) => f(...a)
4050
+ F: __dxlog_file14,
4051
+ L: 266,
4052
+ S: this,
4053
+ C: (f, a) => f(...a)
3898
4054
  });
3899
4055
  log15.trace("dxos.sdk.client-services-host.open", trace6.end({
3900
4056
  id: traceId
3901
4057
  }), {
3902
- file: "service-host.ts",
3903
- line: 252,
3904
- scope: this,
3905
- callSite: (f, a) => f(...a)
4058
+ F: __dxlog_file14,
4059
+ L: 267,
4060
+ S: this,
4061
+ C: (f, a) => f(...a)
3906
4062
  });
3907
4063
  }
3908
4064
  async close() {
@@ -3914,10 +4070,10 @@ var ClientServicesHost = class {
3914
4070
  log15("closing...", {
3915
4071
  deviceKey
3916
4072
  }, {
3917
- file: "service-host.ts",
3918
- line: 262,
3919
- scope: this,
3920
- callSite: (f, a) => f(...a)
4073
+ F: __dxlog_file14,
4074
+ L: 277,
4075
+ S: this,
4076
+ C: (f, a) => f(...a)
3921
4077
  });
3922
4078
  this._serviceRegistry.setServices({
3923
4079
  SystemService: this._systemService
@@ -3929,52 +4085,53 @@ var ClientServicesHost = class {
3929
4085
  log15("closed", {
3930
4086
  deviceKey
3931
4087
  }, {
3932
- file: "service-host.ts",
3933
- line: 268,
3934
- scope: this,
3935
- callSite: (f, a) => f(...a)
4088
+ F: __dxlog_file14,
4089
+ L: 283,
4090
+ S: this,
4091
+ C: (f, a) => f(...a)
3936
4092
  });
3937
4093
  }
3938
4094
  async reset() {
3939
- var _a;
4095
+ var _a, _b, _c;
3940
4096
  const traceId = PublicKey10.random().toHex();
3941
4097
  log15.trace("dxos.sdk.client-services-host.reset", trace6.begin({
3942
4098
  id: traceId
3943
4099
  }), {
3944
- file: "service-host.ts",
3945
- line: 273,
3946
- scope: this,
3947
- callSite: (f, a) => f(...a)
4100
+ F: __dxlog_file14,
4101
+ L: 288,
4102
+ S: this,
4103
+ C: (f, a) => f(...a)
3948
4104
  });
3949
- log15("resetting...", {}, {
3950
- file: "service-host.ts",
3951
- line: 275,
3952
- scope: this,
3953
- callSite: (f, a) => f(...a)
4105
+ log15("resetting...", void 0, {
4106
+ F: __dxlog_file14,
4107
+ L: 290,
4108
+ S: this,
4109
+ C: (f, a) => f(...a)
3954
4110
  });
3955
4111
  await ((_a = this._serviceContext) == null ? void 0 : _a.close());
3956
4112
  await this._storage.reset();
3957
- log15("reset", {}, {
3958
- file: "service-host.ts",
3959
- line: 278,
3960
- scope: this,
3961
- callSite: (f, a) => f(...a)
4113
+ log15("reset", void 0, {
4114
+ F: __dxlog_file14,
4115
+ L: 293,
4116
+ S: this,
4117
+ C: (f, a) => f(...a)
3962
4118
  });
3963
4119
  log15.trace("dxos.sdk.client-services-host.reset", trace6.end({
3964
4120
  id: traceId
3965
4121
  }), {
3966
- file: "service-host.ts",
3967
- line: 279,
3968
- scope: this,
3969
- callSite: (f, a) => f(...a)
4122
+ F: __dxlog_file14,
4123
+ L: 294,
4124
+ S: this,
4125
+ C: (f, a) => f(...a)
3970
4126
  });
4127
+ await ((_c = (_b = this._callbacks) == null ? void 0 : _b.onReset) == null ? void 0 : _c.call(_b));
3971
4128
  }
3972
4129
  };
3973
- __decorate4([
3974
- synchronized2
4130
+ _ts_decorate4([
4131
+ synchronized3
3975
4132
  ], ClientServicesHost.prototype, "open", null);
3976
- __decorate4([
3977
- synchronized2
4133
+ _ts_decorate4([
4134
+ synchronized3
3978
4135
  ], ClientServicesHost.prototype, "close", null);
3979
4136
 
3980
4137
  export {
@@ -3997,6 +4154,7 @@ export {
3997
4154
  InvitationsHandler,
3998
4155
  InvitationsServiceImpl,
3999
4156
  SpaceInvitationProtocol,
4157
+ ClientRpcServer,
4000
4158
  DataSpace,
4001
4159
  DataSpaceManager,
4002
4160
  SpacesServiceImpl,
@@ -4005,6 +4163,7 @@ export {
4005
4163
  isLocked,
4006
4164
  createStorageObjects,
4007
4165
  ServiceRegistry,
4166
+ createDefaultModelFactory,
4008
4167
  ClientServicesHost
4009
4168
  };
4010
- //# sourceMappingURL=chunk-6ITWCQIT.mjs.map
4169
+ //# sourceMappingURL=chunk-F4BHRFH4.mjs.map