@dxos/client-services 0.1.53-main.b9267b1 → 0.1.53-main.bb44a18

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