@dxos/client-services 0.1.35 → 0.1.36

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 (95) hide show
  1. package/dist/lib/browser/{chunk-H5IXSSI7.mjs → chunk-2AYYVPWN.mjs} +835 -950
  2. package/dist/lib/browser/chunk-2AYYVPWN.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +9 -11
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/packlets/testing/index.mjs +212 -74
  6. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  7. package/dist/lib/node/index.cjs +942 -1058
  8. package/dist/lib/node/index.cjs.map +4 -4
  9. package/dist/lib/node/meta.json +1 -1
  10. package/dist/lib/node/packlets/testing/index.cjs +1089 -1067
  11. package/dist/lib/node/packlets/testing/index.cjs.map +4 -4
  12. package/dist/types/src/packlets/identity/identity-manager.d.ts +1 -0
  13. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  14. package/dist/types/src/packlets/identity/identity.d.ts +3 -3
  15. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  16. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +18 -0
  17. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -0
  18. package/dist/types/src/packlets/invitations/device-invitation-protocol.test.d.ts +2 -0
  19. package/dist/types/src/packlets/invitations/device-invitation-protocol.test.d.ts.map +1 -0
  20. package/dist/types/src/packlets/invitations/index.d.ts +4 -4
  21. package/dist/types/src/packlets/invitations/index.d.ts.map +1 -1
  22. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +12 -0
  23. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -0
  24. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +38 -0
  25. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -0
  26. package/dist/types/src/packlets/invitations/invitations-service.d.ts +13 -15
  27. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  28. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +22 -0
  29. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -0
  30. package/dist/types/src/packlets/invitations/space-invitation-protocol.test.d.ts +2 -0
  31. package/dist/types/src/packlets/invitations/space-invitation-protocol.test.d.ts.map +1 -0
  32. package/dist/types/src/packlets/services/service-context.d.ts +6 -4
  33. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  34. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  35. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +2 -0
  36. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  37. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  38. package/dist/types/src/packlets/testing/invitation-utils.d.ts +31 -2
  39. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  40. package/dist/types/src/packlets/testing/test-builder.d.ts +3 -3
  41. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  42. package/dist/types/src/packlets/tests/invitations.test.d.ts +2 -0
  43. package/dist/types/src/packlets/tests/invitations.test.d.ts.map +1 -0
  44. package/dist/types/src/packlets/vault/worker-runtime.d.ts +2 -0
  45. package/dist/types/src/packlets/vault/worker-runtime.d.ts.map +1 -1
  46. package/package.json +30 -30
  47. package/src/packlets/identity/identity-manager.ts +2 -1
  48. package/src/packlets/identity/identity.ts +3 -3
  49. package/src/packlets/invitations/{device-invitations-handler.test.ts → device-invitation-protocol.test.ts} +3 -3
  50. package/src/packlets/invitations/device-invitation-protocol.ts +83 -0
  51. package/src/packlets/invitations/index.ts +4 -4
  52. package/src/packlets/invitations/invitation-protocol.ts +21 -0
  53. package/src/packlets/invitations/invitations-handler.ts +462 -0
  54. package/src/packlets/invitations/invitations-service.ts +127 -104
  55. package/src/packlets/invitations/space-invitation-protocol.test.ts +221 -0
  56. package/src/packlets/invitations/space-invitation-protocol.ts +117 -0
  57. package/src/packlets/services/service-context.test.ts +11 -4
  58. package/src/packlets/services/service-context.ts +40 -19
  59. package/src/packlets/services/service-host.ts +4 -12
  60. package/src/packlets/services/service-registry.test.ts +23 -25
  61. package/src/packlets/spaces/data-space-manager.ts +5 -0
  62. package/src/packlets/spaces/spaces-service.ts +7 -2
  63. package/src/packlets/storage/storage.ts +2 -0
  64. package/src/packlets/testing/invitation-utils.ts +219 -31
  65. package/src/packlets/testing/test-builder.ts +33 -22
  66. package/src/packlets/tests/client-services.test.ts +33 -76
  67. package/src/packlets/tests/halo-profile.test.ts +2 -28
  68. package/src/packlets/tests/invitations.test.ts +389 -0
  69. package/src/packlets/tests/spaces-invitations.test.ts +12 -30
  70. package/src/packlets/tests/spaces.test.ts +30 -28
  71. package/src/packlets/vault/worker-runtime.ts +4 -0
  72. package/dist/lib/browser/chunk-H5IXSSI7.mjs.map +0 -7
  73. package/dist/types/src/packlets/invitations/device-invitations-handler.d.ts +0 -30
  74. package/dist/types/src/packlets/invitations/device-invitations-handler.d.ts.map +0 -1
  75. package/dist/types/src/packlets/invitations/device-invitations-handler.test.d.ts +0 -2
  76. package/dist/types/src/packlets/invitations/device-invitations-handler.test.d.ts.map +0 -1
  77. package/dist/types/src/packlets/invitations/device-invitations-service.d.ts +0 -13
  78. package/dist/types/src/packlets/invitations/device-invitations-service.d.ts.map +0 -1
  79. package/dist/types/src/packlets/invitations/device-invitations-service.test.d.ts +0 -2
  80. package/dist/types/src/packlets/invitations/device-invitations-service.test.d.ts.map +0 -1
  81. package/dist/types/src/packlets/invitations/space-invitations-handler.d.ts +0 -26
  82. package/dist/types/src/packlets/invitations/space-invitations-handler.d.ts.map +0 -1
  83. package/dist/types/src/packlets/invitations/space-invitations-handler.test.d.ts +0 -2
  84. package/dist/types/src/packlets/invitations/space-invitations-handler.test.d.ts.map +0 -1
  85. package/dist/types/src/packlets/invitations/space-invitations-service.d.ts +0 -16
  86. package/dist/types/src/packlets/invitations/space-invitations-service.d.ts.map +0 -1
  87. package/dist/types/src/packlets/invitations/space-invitations-service.test.d.ts +0 -2
  88. package/dist/types/src/packlets/invitations/space-invitations-service.test.d.ts.map +0 -1
  89. package/src/packlets/invitations/device-invitations-handler.ts +0 -370
  90. package/src/packlets/invitations/device-invitations-service.test.ts +0 -96
  91. package/src/packlets/invitations/device-invitations-service.ts +0 -24
  92. package/src/packlets/invitations/space-invitations-handler.test.ts +0 -246
  93. package/src/packlets/invitations/space-invitations-handler.ts +0 -463
  94. package/src/packlets/invitations/space-invitations-service.test.ts +0 -129
  95. package/src/packlets/invitations/space-invitations-service.ts +0 -35
@@ -30,10 +30,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // packages/sdk/client-services/src/index.ts
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
- AbstractInvitationsService: () => AbstractInvitationsService,
34
33
  ClientServicesHost: () => ClientServicesHost,
35
- DeviceInvitationsHandler: () => DeviceInvitationsHandler,
36
- DeviceInvitationsServiceImpl: () => DeviceInvitationsServiceImpl,
34
+ DeviceInvitationProtocol: () => DeviceInvitationProtocol,
37
35
  DevtoolsHostEvents: () => DevtoolsHostEvents,
38
36
  DevtoolsServiceImpl: () => DevtoolsServiceImpl,
39
37
  IFrameHostRuntime: () => IFrameHostRuntime,
@@ -41,13 +39,14 @@ __export(src_exports, {
41
39
  Identity: () => Identity,
42
40
  IdentityManager: () => IdentityManager,
43
41
  IdentityServiceImpl: () => IdentityServiceImpl,
42
+ InvitationsHandler: () => InvitationsHandler,
43
+ InvitationsServiceImpl: () => InvitationsServiceImpl,
44
44
  LocalClientServices: () => LocalClientServices,
45
45
  MemoryShellRuntime: () => MemoryShellRuntime,
46
46
  ServiceContext: () => ServiceContext,
47
47
  ServiceRegistry: () => ServiceRegistry,
48
48
  ShellRuntimeImpl: () => ShellRuntimeImpl,
49
- SpaceInvitationsHandler: () => SpaceInvitationsHandler,
50
- SpaceInvitationsServiceImpl: () => SpaceInvitationsServiceImpl,
49
+ SpaceInvitationProtocol: () => SpaceInvitationProtocol,
51
50
  TrustedKeySetAuthVerifier: () => TrustedKeySetAuthVerifier,
52
51
  VaultResourceLock: () => VaultResourceLock,
53
52
  WorkerRuntime: () => WorkerRuntime,
@@ -652,10 +651,11 @@ var IdentityManager = class {
652
651
  async open() {
653
652
  var _a;
654
653
  import_log3.log.trace("dxos.halo.identity-manager", import_protocols2.trace.begin({
655
- id: this._instanceId
654
+ id: this._instanceId,
655
+ parentId: this._traceParent
656
656
  }), {
657
657
  file: "identity-manager.ts",
658
- line: 71,
658
+ line: 72,
659
659
  scope: this,
660
660
  callSite: (f, a) => f(...a)
661
661
  });
@@ -665,7 +665,7 @@ var IdentityManager = class {
665
665
  identityRecord
666
666
  }, {
667
667
  file: "identity-manager.ts",
668
- line: 75,
668
+ line: 76,
669
669
  scope: this,
670
670
  callSite: (f, a) => f(...a)
671
671
  });
@@ -678,7 +678,7 @@ var IdentityManager = class {
678
678
  displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
679
679
  }, {
680
680
  file: "identity-manager.ts",
681
- line: 80,
681
+ line: 81,
682
682
  scope: this,
683
683
  callSite: (f, a) => f(...a)
684
684
  });
@@ -692,7 +692,7 @@ var IdentityManager = class {
692
692
  id: this._instanceId
693
693
  }), {
694
694
  file: "identity-manager.ts",
695
- line: 90,
695
+ line: 91,
696
696
  scope: this,
697
697
  callSite: (f, a) => f(...a)
698
698
  });
@@ -702,7 +702,7 @@ var IdentityManager = class {
702
702
  (0, import_node_assert2.default)(!this._identity, "Identity already exists.");
703
703
  (0, import_log3.log)("creating identity...", {}, {
704
704
  file: "identity-manager.ts",
705
- line: 95,
705
+ line: 96,
706
706
  scope: this,
707
707
  callSite: (f, a) => f(...a)
708
708
  });
@@ -751,7 +751,7 @@ var IdentityManager = class {
751
751
  displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
752
752
  }, {
753
753
  file: "identity-manager.ts",
754
- line: 150,
754
+ line: 151,
755
755
  scope: this,
756
756
  callSite: (f, a) => f(...a)
757
757
  });
@@ -761,7 +761,7 @@ var IdentityManager = class {
761
761
  deviceKey: identity.deviceKey
762
762
  }, {
763
763
  file: "identity-manager.ts",
764
- line: 156,
764
+ line: 157,
765
765
  scope: this,
766
766
  callSite: (f, a) => f(...a)
767
767
  });
@@ -776,7 +776,7 @@ var IdentityManager = class {
776
776
  params
777
777
  }, {
778
778
  file: "identity-manager.ts",
779
- line: 164,
779
+ line: 165,
780
780
  scope: this,
781
781
  callSite: (f, a) => f(...a)
782
782
  });
@@ -802,7 +802,7 @@ var IdentityManager = class {
802
802
  displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
803
803
  }, {
804
804
  file: "identity-manager.ts",
805
- line: 184,
805
+ line: 185,
806
806
  scope: this,
807
807
  callSite: (f, a) => f(...a)
808
808
  });
@@ -812,7 +812,7 @@ var IdentityManager = class {
812
812
  deviceKey: identity.deviceKey
813
813
  }, {
814
814
  file: "identity-manager.ts",
815
- line: 190,
815
+ line: 191,
816
816
  scope: this,
817
817
  callSite: (f, a) => f(...a)
818
818
  });
@@ -824,7 +824,7 @@ var IdentityManager = class {
824
824
  identityRecord
825
825
  }, {
826
826
  file: "identity-manager.ts",
827
- line: 196,
827
+ line: 197,
828
828
  scope: this,
829
829
  callSite: (f, a) => f(...a)
830
830
  });
@@ -857,7 +857,7 @@ var IdentityManager = class {
857
857
  identityKey: identityRecord.identityKey
858
858
  }, {
859
859
  file: "identity-manager.ts",
860
- line: 224,
860
+ line: 225,
861
861
  scope: this,
862
862
  callSite: (f, a) => f(...a)
863
863
  });
@@ -927,8 +927,73 @@ var IdentityServiceImpl = class {
927
927
  }
928
928
  };
929
929
 
930
- // packages/sdk/client-services/src/packlets/invitations/device-invitations-handler.ts
930
+ // packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts
931
931
  var import_node_assert4 = __toESM(require("node:assert"));
932
+ var import_services = require("@dxos/protocols/proto/dxos/client/services");
933
+ var DeviceInvitationProtocol = class {
934
+ constructor(_keyring, _getIdentity, _acceptIdentity) {
935
+ this._keyring = _keyring;
936
+ this._getIdentity = _getIdentity;
937
+ this._acceptIdentity = _acceptIdentity;
938
+ }
939
+ toJSON() {
940
+ return {};
941
+ }
942
+ getInvitationContext() {
943
+ return {
944
+ kind: import_services.Invitation.Kind.DEVICE
945
+ };
946
+ }
947
+ async admit(request) {
948
+ (0, import_node_assert4.default)(request.device);
949
+ const identity = this._getIdentity();
950
+ await identity.admitDevice(request.device);
951
+ return {
952
+ device: {
953
+ identityKey: identity.identityKey,
954
+ haloSpaceKey: identity.haloSpaceKey,
955
+ genesisFeedKey: identity.haloGenesisFeedKey,
956
+ controlTimeframe: identity.controlPipeline.state.timeframe
957
+ }
958
+ };
959
+ }
960
+ createIntroduction() {
961
+ return {};
962
+ }
963
+ async createAdmissionRequest() {
964
+ const deviceKey = await this._keyring.createKey();
965
+ const controlFeedKey = await this._keyring.createKey();
966
+ const dataFeedKey = await this._keyring.createKey();
967
+ return {
968
+ device: {
969
+ deviceKey,
970
+ controlFeedKey,
971
+ dataFeedKey
972
+ }
973
+ };
974
+ }
975
+ async accept(response, request) {
976
+ (0, import_node_assert4.default)(response.device);
977
+ const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
978
+ (0, import_node_assert4.default)(request.device);
979
+ const { deviceKey, controlFeedKey, dataFeedKey } = request.device;
980
+ await this._acceptIdentity({
981
+ identityKey,
982
+ deviceKey,
983
+ haloSpaceKey,
984
+ haloGenesisFeedKey: genesisFeedKey,
985
+ controlFeedKey,
986
+ dataFeedKey,
987
+ controlTimeframe
988
+ });
989
+ return {
990
+ identityKey
991
+ };
992
+ }
993
+ };
994
+
995
+ // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
996
+ var import_node_assert5 = __toESM(require("node:assert"));
932
997
  var import_async6 = require("@dxos/async");
933
998
  var import_client = require("@dxos/client");
934
999
  var import_context3 = require("@dxos/context");
@@ -937,141 +1002,206 @@ var import_keys5 = require("@dxos/keys");
937
1002
  var import_log4 = require("@dxos/log");
938
1003
  var import_network_manager = require("@dxos/network-manager");
939
1004
  var import_protocols3 = require("@dxos/protocols");
940
- var import_services = require("@dxos/protocols/proto/dxos/client/services");
1005
+ var import_services2 = require("@dxos/protocols/proto/dxos/client/services");
941
1006
  var import_invitations = require("@dxos/protocols/proto/dxos/halo/invitations");
942
1007
  var import_teleport = require("@dxos/teleport");
943
- var DeviceInvitationsHandler = class extends import_client.AbstractInvitationsHandler {
944
- // prettier-ignore
945
- constructor(_params) {
946
- super(_params.networkManager);
947
- this._params = _params;
1008
+ var MAX_OTP_ATTEMPTS = 3;
1009
+ var InvitationsHandler = class {
1010
+ constructor(_networkManager) {
1011
+ this._networkManager = _networkManager;
948
1012
  }
949
- /**
950
- * Creates an invitation and listens for a join request from the invited (guest) peer.
951
- */
952
- createInvitation(context, options) {
953
- const { type, timeout = import_client.INVITATION_TIMEOUT, swarmKey } = options != null ? options : {};
954
- (0, import_node_assert4.default)(type !== import_services.Invitation.Type.OFFLINE);
955
- const identity = this._params.getIdentity();
1013
+ createInvitation(protocol, options) {
1014
+ var _a;
1015
+ const { invitationId = import_keys5.PublicKey.random().toHex(), type = import_services2.Invitation.Type.INTERACTIVE, authMethod = import_services2.Invitation.AuthMethod.SHARED_SECRET, state = import_services2.Invitation.State.INIT, timeout = import_client.INVITATION_TIMEOUT, swarmKey = import_keys5.PublicKey.random() } = options != null ? options : {};
1016
+ const authCode = (_a = options == null ? void 0 : options.authCode) != null ? _a : authMethod === import_services2.Invitation.AuthMethod.SHARED_SECRET ? (0, import_credentials7.generatePasscode)(import_client.AUTHENTICATION_CODE_LENGTH) : void 0;
1017
+ (0, import_node_assert5.default)(protocol);
956
1018
  const invitation = {
1019
+ invitationId,
957
1020
  type,
958
- invitationId: import_keys5.PublicKey.random().toHex(),
959
- swarmKey: swarmKey != null ? swarmKey : import_keys5.PublicKey.random(),
960
- authenticationCode: (0, import_credentials7.generatePasscode)(import_client.AUTHENTICATION_CODE_LENGTH)
1021
+ authMethod,
1022
+ state,
1023
+ swarmKey,
1024
+ authCode,
1025
+ timeout,
1026
+ ...protocol.getInvitationContext()
961
1027
  };
1028
+ const stream = new import_async6.PushStream();
962
1029
  const ctx = new import_context3.Context({
963
1030
  onError: (err) => {
964
1031
  void ctx.dispose();
965
- observable.callback.onError(err);
1032
+ stream.error(err);
966
1033
  }
967
1034
  });
968
- const observable = new import_client.InvitationObservableProvider(async () => {
969
- await ctx.dispose();
1035
+ ctx.onDispose(() => {
1036
+ (0, import_log4.log)("complete", {
1037
+ ...protocol.toJSON()
1038
+ }, {
1039
+ file: "invitations-handler.ts",
1040
+ line: 102,
1041
+ scope: this,
1042
+ callSite: (f, a) => f(...a)
1043
+ });
1044
+ stream.complete();
970
1045
  });
971
- let authenticationCode;
972
- const complete = new import_async6.Trigger();
973
- const createExtension = () => new HostHaloInvitationExtension({
974
- requestAdmission: async () => {
975
- var _a, _b;
976
- (0, import_log4.log)("responding with admission offer", {
977
- host: identity.deviceKey
978
- }, {
979
- file: "device-invitations-handler.ts",
980
- line: 92,
981
- scope: this,
982
- callSite: (f, a) => f(...a)
983
- });
984
- (_b = (_a = observable.callback).onAuthenticating) == null ? void 0 : _b.call(_a, invitation);
985
- return {
986
- identityKey: identity.identityKey,
987
- haloSpaceKey: identity.haloSpaceKey,
988
- genesisFeedKey: identity.haloGenesisFeedKey,
989
- controlTimeframe: identity.controlPipeline.state.timeframe
990
- };
991
- },
992
- authenticate: async ({ authenticationCode: code }) => {
993
- (0, import_log4.log)("received authentication request", {
994
- authenticationCode: code
995
- }, {
996
- file: "device-invitations-handler.ts",
997
- line: 107,
998
- scope: this,
999
- callSite: (f, a) => f(...a)
1000
- });
1001
- authenticationCode = code;
1002
- return {
1003
- status: import_invitations.AuthenticationResponse.Status.OK
1004
- };
1005
- },
1006
- // TODO(burdon): Not used: controlFeedKey, dataFeedKey.
1007
- presentAdmissionCredentials: async (credentials) => {
1008
- try {
1009
- if (invitation.type !== import_services.Invitation.Type.INTERACTIVE_TESTING) {
1010
- if (invitation.authenticationCode === void 0 || invitation.authenticationCode !== authenticationCode) {
1011
- throw new Error(`invalid authentication code: ${authenticationCode}`);
1012
- }
1013
- }
1014
- (0, import_log4.log)("writing guest credentials", {
1015
- host: identity.deviceKey,
1016
- guest: credentials.deviceKey
1046
+ const createExtension = () => {
1047
+ const success = new import_async6.Trigger();
1048
+ let guestProfile;
1049
+ let authenticationPassed = false;
1050
+ let authenticationRetry = 0;
1051
+ const extension = new InvitationHostExtension({
1052
+ introduce: async ({ profile }) => {
1053
+ (0, import_log4.log)("guest introduced itself", {
1054
+ guestProfile: profile,
1055
+ ...protocol.toJSON()
1017
1056
  }, {
1018
- file: "device-invitations-handler.ts",
1019
- line: 122,
1057
+ file: "invitations-handler.ts",
1058
+ line: 115,
1020
1059
  scope: this,
1021
1060
  callSite: (f, a) => f(...a)
1022
1061
  });
1023
- await identity.admitDevice(credentials);
1024
- complete.wake(credentials.deviceKey);
1025
- } catch (err) {
1026
- observable.callback.onError(err);
1027
- throw err;
1028
- }
1029
- },
1030
- onOpen: () => {
1031
- (0, import_async6.scheduleTask)(ctx, async () => {
1032
- var _a, _b;
1062
+ guestProfile = profile;
1063
+ stream.next({
1064
+ ...invitation,
1065
+ state: import_services2.Invitation.State.READY_FOR_AUTHENTICATION
1066
+ });
1067
+ return {
1068
+ spaceKey: authMethod === import_services2.Invitation.AuthMethod.NONE ? protocol.getInvitationContext().spaceKey : void 0,
1069
+ authMethod
1070
+ };
1071
+ },
1072
+ authenticate: async ({ authCode: code }) => {
1073
+ (0, import_log4.log)("received authentication request", {
1074
+ authCode: code
1075
+ }, {
1076
+ file: "invitations-handler.ts",
1077
+ line: 134,
1078
+ scope: this,
1079
+ callSite: (f, a) => f(...a)
1080
+ });
1081
+ let status = import_invitations.AuthenticationResponse.Status.OK;
1082
+ switch (invitation.authMethod) {
1083
+ case import_services2.Invitation.AuthMethod.NONE: {
1084
+ (0, import_log4.log)("authentication not required", {}, {
1085
+ file: "invitations-handler.ts",
1086
+ line: 139,
1087
+ scope: this,
1088
+ callSite: (f, a) => f(...a)
1089
+ });
1090
+ return {
1091
+ status: import_invitations.AuthenticationResponse.Status.OK
1092
+ };
1093
+ }
1094
+ case import_services2.Invitation.AuthMethod.SHARED_SECRET: {
1095
+ if (invitation.authCode) {
1096
+ if (authenticationRetry++ > MAX_OTP_ATTEMPTS) {
1097
+ status = import_invitations.AuthenticationResponse.Status.INVALID_OPT_ATTEMPTS;
1098
+ } else if (code !== invitation.authCode) {
1099
+ status = import_invitations.AuthenticationResponse.Status.INVALID_OTP;
1100
+ } else {
1101
+ authenticationPassed = true;
1102
+ }
1103
+ }
1104
+ break;
1105
+ }
1106
+ default: {
1107
+ import_log4.log.error("invalid authentication method", {
1108
+ authMethod: invitation.authMethod
1109
+ }, {
1110
+ file: "invitations-handler.ts",
1111
+ line: 157,
1112
+ scope: this,
1113
+ callSite: (f, a) => f(...a)
1114
+ });
1115
+ status = import_invitations.AuthenticationResponse.Status.INTERNAL_ERROR;
1116
+ break;
1117
+ }
1118
+ }
1119
+ return {
1120
+ status
1121
+ };
1122
+ },
1123
+ admit: async (admissionRequest) => {
1124
+ var _a2, _b, _c;
1033
1125
  try {
1034
- (0, import_log4.log)("connected", {
1035
- host: identity.deviceKey
1036
- }, {
1037
- file: "device-invitations-handler.ts",
1038
- line: 138,
1039
- scope: this,
1040
- callSite: (f, a) => f(...a)
1041
- });
1042
- (_b = (_a = observable.callback).onConnected) == null ? void 0 : _b.call(_a, invitation);
1043
- const deviceKey = await complete.wait({
1044
- timeout
1045
- });
1046
- (0, import_log4.log)("admitted guest", {
1047
- host: identity.deviceKey,
1048
- guest: deviceKey
1049
- }, {
1050
- file: "device-invitations-handler.ts",
1051
- line: 141,
1052
- scope: this,
1053
- callSite: (f, a) => f(...a)
1054
- });
1055
- observable.callback.onSuccess(invitation);
1126
+ if (isAuthenticationRequired(invitation) && !authenticationPassed) {
1127
+ throw new Error("Not authenticated");
1128
+ }
1129
+ const deviceKey = (_c = (_a2 = admissionRequest.device) == null ? void 0 : _a2.deviceKey) != null ? _c : (_b = admissionRequest.space) == null ? void 0 : _b.deviceKey;
1130
+ (0, import_node_assert5.default)(deviceKey);
1131
+ const admissionResponse = await protocol.admit(admissionRequest, guestProfile);
1132
+ success.wake(deviceKey);
1133
+ return admissionResponse;
1056
1134
  } catch (err) {
1057
- if (!observable.cancelled) {
1058
- import_log4.log.error("failed", err, {
1059
- file: "device-invitations-handler.ts",
1060
- line: 145,
1135
+ stream.error(err);
1136
+ throw err;
1137
+ }
1138
+ },
1139
+ onOpen: () => {
1140
+ (0, import_async6.scheduleTask)(ctx, async () => {
1141
+ try {
1142
+ (0, import_log4.log)("connected", {
1143
+ ...protocol.toJSON()
1144
+ }, {
1145
+ file: "invitations-handler.ts",
1146
+ line: 191,
1061
1147
  scope: this,
1062
1148
  callSite: (f, a) => f(...a)
1063
1149
  });
1064
- observable.callback.onError(err);
1150
+ stream.next({
1151
+ ...invitation,
1152
+ state: import_services2.Invitation.State.CONNECTED
1153
+ });
1154
+ const deviceKey = await success.wait({
1155
+ timeout
1156
+ });
1157
+ (0, import_log4.log)("admitted guest", {
1158
+ guest: deviceKey,
1159
+ ...protocol.toJSON()
1160
+ }, {
1161
+ file: "invitations-handler.ts",
1162
+ line: 194,
1163
+ scope: this,
1164
+ callSite: (f, a) => f(...a)
1165
+ });
1166
+ stream.next({
1167
+ ...invitation,
1168
+ state: import_services2.Invitation.State.SUCCESS
1169
+ });
1170
+ } catch (err) {
1171
+ if (err instanceof import_async6.TimeoutError) {
1172
+ (0, import_log4.log)("timeout", {
1173
+ ...protocol.toJSON()
1174
+ }, {
1175
+ file: "invitations-handler.ts",
1176
+ line: 198,
1177
+ scope: this,
1178
+ callSite: (f, a) => f(...a)
1179
+ });
1180
+ stream.next({
1181
+ ...invitation,
1182
+ state: import_services2.Invitation.State.TIMEOUT
1183
+ });
1184
+ } else {
1185
+ import_log4.log.error("failed", err, {
1186
+ file: "invitations-handler.ts",
1187
+ line: 201,
1188
+ scope: this,
1189
+ callSite: (f, a) => f(...a)
1190
+ });
1191
+ stream.error(err);
1192
+ }
1193
+ } finally {
1194
+ if (type !== import_services2.Invitation.Type.MULTIUSE) {
1195
+ await (0, import_async6.sleep)(import_client.ON_CLOSE_DELAY);
1196
+ await ctx.dispose();
1197
+ }
1065
1198
  }
1066
- } finally {
1067
- await (0, import_async6.sleep)(import_client.ON_CLOSE_DELAY);
1068
- await ctx.dispose();
1069
- }
1070
- });
1071
- }
1072
- });
1199
+ });
1200
+ }
1201
+ });
1202
+ return extension;
1203
+ };
1073
1204
  (0, import_async6.scheduleTask)(ctx, async () => {
1074
- var _a, _b;
1075
1205
  const topic = invitation.swarmKey;
1076
1206
  const swarmConnection = await this._networkManager.joinSwarm({
1077
1207
  topic,
@@ -1082,126 +1212,210 @@ var DeviceInvitationsHandler = class extends import_client.AbstractInvitationsHa
1082
1212
  topology: new import_network_manager.StarTopology(topic)
1083
1213
  });
1084
1214
  ctx.onDispose(() => swarmConnection.close());
1085
- (_b = (_a = observable.callback).onConnecting) == null ? void 0 : _b.call(_a, invitation);
1215
+ stream.next({
1216
+ ...invitation,
1217
+ state: import_services2.Invitation.State.CONNECTING
1218
+ });
1219
+ });
1220
+ const observable = new import_client.CancellableInvitationObservable({
1221
+ initialInvitation: invitation,
1222
+ subscriber: stream.observable,
1223
+ onCancel: async () => {
1224
+ stream.next({
1225
+ ...invitation,
1226
+ state: import_services2.Invitation.State.CANCELLED
1227
+ });
1228
+ await ctx.dispose();
1229
+ }
1086
1230
  });
1087
1231
  return observable;
1088
1232
  }
1089
- /**
1090
- * Waits for the host peer (inviter) to accept our join request.
1091
- * The local guest peer (invitee) then sends the local halo invitation to the host,
1092
- * which then writes the guest's credentials to the halo.
1093
- */
1094
- acceptInvitation(invitation, options) {
1095
- const { timeout = import_client.INVITATION_TIMEOUT } = options != null ? options : {};
1233
+ acceptInvitation(protocol, invitation) {
1234
+ const { timeout = import_client.INVITATION_TIMEOUT } = invitation;
1235
+ (0, import_node_assert5.default)(protocol);
1236
+ const authenticated = new import_async6.Trigger();
1237
+ const stream = new import_async6.PushStream();
1096
1238
  const ctx = new import_context3.Context({
1097
1239
  onError: (err) => {
1240
+ if (err instanceof import_async6.TimeoutError) {
1241
+ (0, import_log4.log)("timeout", {
1242
+ ...protocol.toJSON()
1243
+ }, {
1244
+ file: "invitations-handler.ts",
1245
+ line: 255,
1246
+ scope: this,
1247
+ callSite: (f, a) => f(...a)
1248
+ });
1249
+ stream.next({
1250
+ ...invitation,
1251
+ state: import_services2.Invitation.State.TIMEOUT
1252
+ });
1253
+ } else {
1254
+ import_log4.log.warn("auth failed", err, {
1255
+ file: "invitations-handler.ts",
1256
+ line: 258,
1257
+ scope: this,
1258
+ callSite: (f, a) => f(...a)
1259
+ });
1260
+ stream.error(err);
1261
+ }
1098
1262
  void ctx.dispose();
1099
- observable.callback.onError(err);
1100
1263
  }
1101
1264
  });
1102
- const authenticated = new import_async6.Trigger();
1103
- const observable = new import_client.AuthenticatingInvitationProvider({
1104
- onCancel: async () => {
1105
- await ctx.dispose();
1106
- },
1107
- // TODO(burdon): Consider retry.
1108
- onAuthenticate: async (code) => {
1109
- authenticated.wake(code);
1110
- }
1265
+ ctx.onDispose(() => {
1266
+ (0, import_log4.log)("complete", {
1267
+ ...protocol.toJSON()
1268
+ }, {
1269
+ file: "invitations-handler.ts",
1270
+ line: 266,
1271
+ scope: this,
1272
+ callSite: (f, a) => f(...a)
1273
+ });
1274
+ stream.complete();
1111
1275
  });
1112
- let connectionCount = 0;
1113
- const complete = new import_async6.Trigger();
1114
1276
  const createExtension = () => {
1115
- const extension = new GuestHaloInvitationExtension({
1277
+ let connectionCount = 0;
1278
+ const extension = new InvitationGuestExtension({
1116
1279
  onOpen: () => {
1117
1280
  (0, import_async6.scheduleTask)(ctx, async () => {
1118
- var _a, _b, _c, _d;
1119
1281
  try {
1120
1282
  if (++connectionCount > 1) {
1121
1283
  throw new Error(`multiple connections detected: ${connectionCount}`);
1122
1284
  }
1123
- (0, import_log4.log)("connected", {}, {
1124
- file: "device-invitations-handler.ts",
1125
- line: 216,
1285
+ (0, import_async6.scheduleTask)(ctx, () => ctx.raise(new import_async6.TimeoutError(timeout)), timeout);
1286
+ (0, import_log4.log)("connected", {
1287
+ ...protocol.toJSON()
1288
+ }, {
1289
+ file: "invitations-handler.ts",
1290
+ line: 284,
1126
1291
  scope: this,
1127
1292
  callSite: (f, a) => f(...a)
1128
1293
  });
1129
- (_b = (_a = observable.callback).onConnected) == null ? void 0 : _b.call(_a, invitation);
1130
- (0, import_log4.log)("sending admission request", {}, {
1131
- file: "device-invitations-handler.ts",
1132
- line: 220,
1294
+ stream.next({
1295
+ ...invitation,
1296
+ state: import_services2.Invitation.State.CONNECTED
1297
+ });
1298
+ (0, import_log4.log)("introduce", {
1299
+ ...protocol.toJSON()
1300
+ }, {
1301
+ file: "invitations-handler.ts",
1302
+ line: 288,
1133
1303
  scope: this,
1134
1304
  callSite: (f, a) => f(...a)
1135
1305
  });
1136
- const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = await extension.rpc.HaloHostService.requestAdmission();
1137
- if (invitation.type === void 0 || invitation.type === import_services.Invitation.Type.INTERACTIVE) {
1138
- (0, import_log4.log)("guest waiting for authentication code...", {}, {
1139
- file: "device-invitations-handler.ts",
1140
- line: 227,
1141
- scope: this,
1142
- callSite: (f, a) => f(...a)
1143
- });
1144
- (_d = (_c = observable.callback).onAuthenticating) == null ? void 0 : _d.call(_c, invitation);
1145
- const authenticationCode = await authenticated.wait({
1146
- timeout
1147
- });
1148
- (0, import_log4.log)("sending authentication request", {}, {
1149
- file: "device-invitations-handler.ts",
1150
- line: 230,
1151
- scope: this,
1152
- callSite: (f, a) => f(...a)
1153
- });
1154
- await extension.rpc.HaloHostService.authenticate({
1155
- authenticationCode
1306
+ const introductionResponse = await extension.rpc.InvitationHostService.introduce(protocol.createIntroduction());
1307
+ (0, import_log4.log)("introduce response", {
1308
+ ...protocol.toJSON(),
1309
+ response: introductionResponse
1310
+ }, {
1311
+ file: "invitations-handler.ts",
1312
+ line: 292,
1313
+ scope: this,
1314
+ callSite: (f, a) => f(...a)
1315
+ });
1316
+ invitation.authMethod = introductionResponse.authMethod;
1317
+ if (introductionResponse.spaceKey) {
1318
+ invitation.spaceKey = introductionResponse.spaceKey;
1319
+ }
1320
+ if (isAuthenticationRequired(invitation)) {
1321
+ for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
1322
+ (0, import_log4.log)("guest waiting for authentication code...", {}, {
1323
+ file: "invitations-handler.ts",
1324
+ line: 301,
1325
+ scope: this,
1326
+ callSite: (f, a) => f(...a)
1327
+ });
1328
+ stream.next({
1329
+ ...invitation,
1330
+ state: import_services2.Invitation.State.READY_FOR_AUTHENTICATION
1331
+ });
1332
+ const authCode = await authenticated.wait({
1333
+ timeout
1334
+ });
1335
+ (0, import_log4.log)("sending authentication request", {}, {
1336
+ file: "invitations-handler.ts",
1337
+ line: 305,
1338
+ scope: this,
1339
+ callSite: (f, a) => f(...a)
1340
+ });
1341
+ stream.next({
1342
+ ...invitation,
1343
+ state: import_services2.Invitation.State.AUTHENTICATING
1344
+ });
1345
+ const response = await extension.rpc.InvitationHostService.authenticate({
1346
+ authCode
1347
+ });
1348
+ if (response.status === void 0 || response.status === import_invitations.AuthenticationResponse.Status.OK) {
1349
+ break;
1350
+ }
1351
+ if (response.status === import_invitations.AuthenticationResponse.Status.INVALID_OTP) {
1352
+ if (attempt === MAX_OTP_ATTEMPTS) {
1353
+ throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
1354
+ } else {
1355
+ (0, import_log4.log)("retrying invalid code", {
1356
+ attempt
1357
+ }, {
1358
+ file: "invitations-handler.ts",
1359
+ line: 316,
1360
+ scope: this,
1361
+ callSite: (f, a) => f(...a)
1362
+ });
1363
+ authenticated.reset();
1364
+ }
1365
+ }
1366
+ }
1367
+ } else {
1368
+ stream.next({
1369
+ ...invitation,
1370
+ state: import_services2.Invitation.State.READY_FOR_AUTHENTICATION
1156
1371
  });
1157
1372
  }
1158
- const deviceKey = await this._params.keyring.createKey();
1159
- const controlFeedKey = await this._params.keyring.createKey();
1160
- const dataFeedKey = await this._params.keyring.createKey();
1161
- (0, import_log4.log)("presenting admission credentials", {
1162
- identityKey,
1163
- deviceKey,
1164
- controlFeedKey,
1165
- dataFeedKey
1373
+ (0, import_log4.log)("request admission", {
1374
+ ...protocol.toJSON()
1166
1375
  }, {
1167
- file: "device-invitations-handler.ts",
1168
- line: 239,
1376
+ file: "invitations-handler.ts",
1377
+ line: 327,
1169
1378
  scope: this,
1170
1379
  callSite: (f, a) => f(...a)
1171
1380
  });
1172
- await extension.rpc.HaloHostService.presentAdmissionCredentials({
1173
- deviceKey,
1174
- controlFeedKey,
1175
- dataFeedKey
1176
- });
1177
- const identity = await this._params.acceptIdentity({
1178
- identityKey,
1179
- deviceKey,
1180
- haloSpaceKey,
1181
- haloGenesisFeedKey: genesisFeedKey,
1182
- controlFeedKey,
1183
- dataFeedKey,
1184
- controlTimeframe
1185
- });
1381
+ const admissionRequest = await protocol.createAdmissionRequest();
1382
+ const admissionResponse = await extension.rpc.InvitationHostService.admit(admissionRequest);
1383
+ const result = await protocol.accept(admissionResponse, admissionRequest);
1186
1384
  (0, import_log4.log)("admitted by host", {
1187
- guest: identity.deviceKey,
1188
- identityKey
1385
+ ...protocol.toJSON()
1189
1386
  }, {
1190
- file: "device-invitations-handler.ts",
1191
- line: 259,
1387
+ file: "invitations-handler.ts",
1388
+ line: 335,
1192
1389
  scope: this,
1193
1390
  callSite: (f, a) => f(...a)
1194
1391
  });
1195
- complete.wake(identityKey);
1392
+ stream.next({
1393
+ ...invitation,
1394
+ ...result,
1395
+ state: import_services2.Invitation.State.SUCCESS
1396
+ });
1196
1397
  } catch (err) {
1197
- if (!observable.cancelled) {
1398
+ if (err instanceof import_async6.TimeoutError) {
1399
+ (0, import_log4.log)("timeout", {
1400
+ ...protocol.toJSON()
1401
+ }, {
1402
+ file: "invitations-handler.ts",
1403
+ line: 339,
1404
+ scope: this,
1405
+ callSite: (f, a) => f(...a)
1406
+ });
1407
+ stream.next({
1408
+ ...invitation,
1409
+ state: import_services2.Invitation.State.TIMEOUT
1410
+ });
1411
+ } else {
1198
1412
  import_log4.log.warn("auth failed", err, {
1199
- file: "device-invitations-handler.ts",
1200
- line: 263,
1413
+ file: "invitations-handler.ts",
1414
+ line: 342,
1201
1415
  scope: this,
1202
1416
  callSite: (f, a) => f(...a)
1203
1417
  });
1204
- observable.callback.onError(err);
1418
+ stream.error(err);
1205
1419
  }
1206
1420
  } finally {
1207
1421
  await ctx.dispose();
@@ -1212,8 +1426,7 @@ var DeviceInvitationsHandler = class extends import_client.AbstractInvitationsHa
1212
1426
  return extension;
1213
1427
  };
1214
1428
  (0, import_async6.scheduleTask)(ctx, async () => {
1215
- var _a, _b;
1216
- (0, import_node_assert4.default)(invitation.swarmKey);
1429
+ (0, import_node_assert5.default)(invitation.swarmKey);
1217
1430
  const topic = invitation.swarmKey;
1218
1431
  const swarmConnection = await this._networkManager.joinSwarm({
1219
1432
  topic,
@@ -1224,19 +1437,34 @@ var DeviceInvitationsHandler = class extends import_client.AbstractInvitationsHa
1224
1437
  topology: new import_network_manager.StarTopology(topic)
1225
1438
  });
1226
1439
  ctx.onDispose(() => swarmConnection.close());
1227
- (_b = (_a = observable.callback).onConnecting) == null ? void 0 : _b.call(_a, invitation);
1228
- invitation.identityKey = await complete.wait();
1229
- observable.callback.onSuccess(invitation);
1230
- await ctx.dispose();
1440
+ stream.next({
1441
+ ...invitation,
1442
+ state: import_services2.Invitation.State.CONNECTING
1443
+ });
1444
+ });
1445
+ const observable = new import_client.AuthenticatingInvitationObservable({
1446
+ initialInvitation: invitation,
1447
+ subscriber: stream.observable,
1448
+ onCancel: async () => {
1449
+ stream.next({
1450
+ ...invitation,
1451
+ state: import_services2.Invitation.State.CANCELLED
1452
+ });
1453
+ await ctx.dispose();
1454
+ },
1455
+ onAuthenticate: async (code) => {
1456
+ authenticated.wake(code);
1457
+ }
1231
1458
  });
1232
1459
  return observable;
1233
1460
  }
1234
1461
  };
1235
- var HostHaloInvitationExtension = class extends import_teleport.RpcExtension {
1462
+ var isAuthenticationRequired = (invitation) => invitation.authMethod !== import_services2.Invitation.AuthMethod.NONE;
1463
+ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1236
1464
  constructor(_callbacks) {
1237
1465
  super({
1238
1466
  exposed: {
1239
- HaloHostService: import_protocols3.schema.getService("dxos.halo.invitations.HaloHostService")
1467
+ InvitationHostService: import_protocols3.schema.getService("dxos.halo.invitations.InvitationHostService")
1240
1468
  }
1241
1469
  });
1242
1470
  this._callbacks = _callbacks;
@@ -1245,16 +1473,15 @@ var HostHaloInvitationExtension = class extends import_teleport.RpcExtension {
1245
1473
  return {
1246
1474
  // TODO(dmaretskyi): For now this is just forwarding the data to callbacks since we don't have session-specific logic.
1247
1475
  // Perhaps in the future we will have more complex logic here.
1248
- HaloHostService: {
1249
- requestAdmission: async () => {
1250
- return this._callbacks.requestAdmission();
1476
+ InvitationHostService: {
1477
+ introduce: async (request) => {
1478
+ return this._callbacks.introduce(request);
1251
1479
  },
1252
- authenticate: async (credentials) => {
1253
- return this._callbacks.authenticate(credentials);
1480
+ authenticate: async (request) => {
1481
+ return this._callbacks.authenticate(request);
1254
1482
  },
1255
- // TODO(burdon): Not used: controlFeedKey, dataFeedKey.
1256
- presentAdmissionCredentials: async (credentials) => {
1257
- return this._callbacks.presentAdmissionCredentials(credentials);
1483
+ admit: async (request) => {
1484
+ return this._callbacks.admit(request);
1258
1485
  }
1259
1486
  }
1260
1487
  };
@@ -1264,11 +1491,11 @@ var HostHaloInvitationExtension = class extends import_teleport.RpcExtension {
1264
1491
  this._callbacks.onOpen();
1265
1492
  }
1266
1493
  };
1267
- var GuestHaloInvitationExtension = class extends import_teleport.RpcExtension {
1494
+ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1268
1495
  constructor(_callbacks) {
1269
1496
  super({
1270
1497
  requested: {
1271
- HaloHostService: import_protocols3.schema.getService("dxos.halo.invitations.HaloHostService")
1498
+ InvitationHostService: import_protocols3.schema.getService("dxos.halo.invitations.InvitationHostService")
1272
1499
  }
1273
1500
  });
1274
1501
  this._callbacks = _callbacks;
@@ -1283,155 +1510,85 @@ var GuestHaloInvitationExtension = class extends import_teleport.RpcExtension {
1283
1510
  };
1284
1511
 
1285
1512
  // packages/sdk/client-services/src/packlets/invitations/invitations-service.ts
1286
- var import_node_assert5 = __toESM(require("node:assert"));
1513
+ var import_node_assert6 = __toESM(require("node:assert"));
1287
1514
  var import_codec_protobuf7 = require("@dxos/codec-protobuf");
1288
1515
  var import_log5 = require("@dxos/log");
1289
- var import_services2 = require("@dxos/protocols/proto/dxos/client/services");
1290
- var AbstractInvitationsService = class {
1291
- // prettier-ignore
1292
- constructor(_identityManager, _getInvitationsHandler) {
1293
- this._identityManager = _identityManager;
1294
- this._getInvitationsHandler = _getInvitationsHandler;
1516
+ var import_services3 = require("@dxos/protocols/proto/dxos/client/services");
1517
+ var InvitationsServiceImpl = class {
1518
+ constructor(_invitationsHandler, _getHandler) {
1519
+ this._invitationsHandler = _invitationsHandler;
1520
+ this._getHandler = _getHandler;
1295
1521
  this._createInvitations = /* @__PURE__ */ new Map();
1296
1522
  this._acceptInvitations = /* @__PURE__ */ new Map();
1297
1523
  }
1298
1524
  // TODO(burdon): Guest/host label.
1299
1525
  getLoggingContext() {
1300
- var _a;
1301
- return {
1302
- deviceKey: (_a = this._identityManager.identity) == null ? void 0 : _a.deviceKey
1303
- };
1526
+ return {};
1304
1527
  }
1305
1528
  createInvitation(invitation) {
1306
1529
  return new import_codec_protobuf7.Stream(({ next, close }) => {
1307
- const invitationsHandler = this._getInvitationsHandler();
1308
- const context = this.getContext(invitation);
1530
+ const handler = this._getHandler(invitation);
1309
1531
  (0, import_log5.log)("stream opened", this.getLoggingContext(), {
1310
1532
  file: "invitations-service.ts",
1311
- line: 48,
1533
+ line: 37,
1312
1534
  scope: this,
1313
1535
  callSite: (f, a) => f(...a)
1314
1536
  });
1315
1537
  let invitationId;
1316
- const { type, swarmKey, authMethod } = invitation;
1317
- const observable = invitationsHandler.createInvitation(context, {
1318
- type,
1319
- swarmKey,
1320
- authMethod
1321
- });
1322
- observable.subscribe({
1323
- onConnecting: (invitation2) => {
1324
- (0, import_node_assert5.default)(invitation2.invitationId);
1325
- invitationId = invitation2.invitationId;
1326
- this._createInvitations.set(invitation2.invitationId, observable);
1327
- invitation2.state = import_services2.Invitation.State.CONNECTING;
1328
- next(invitation2);
1329
- },
1330
- onConnected: (invitation2) => {
1331
- (0, import_node_assert5.default)(invitation2.invitationId);
1332
- invitation2.state = import_services2.Invitation.State.CONNECTED;
1333
- next(invitation2);
1334
- },
1335
- onAuthenticating: (invitation2) => {
1336
- (0, import_node_assert5.default)(invitation2.invitationId);
1337
- invitation2.state = import_services2.Invitation.State.AUTHENTICATING;
1338
- next(invitation2);
1339
- },
1340
- onSuccess: (invitation2) => {
1341
- (0, import_node_assert5.default)(invitation2.invitationId);
1342
- invitation2.state = import_services2.Invitation.State.SUCCESS;
1343
- next(invitation2);
1344
- close();
1345
- },
1346
- onCancelled: () => {
1347
- (0, import_node_assert5.default)(invitationId);
1348
- invitation.invitationId = invitationId;
1349
- invitation.state = import_services2.Invitation.State.CANCELLED;
1350
- next(invitation);
1351
- close();
1352
- },
1353
- onTimeout: (err) => {
1354
- invitation.state = import_services2.Invitation.State.TIMEOUT;
1355
- close(err);
1356
- },
1357
- onError: (err) => {
1358
- invitation.state = import_services2.Invitation.State.ERROR;
1359
- close(err);
1360
- }
1361
- });
1362
- return (err) => {
1363
- const context2 = this.getLoggingContext();
1364
- if (err) {
1365
- import_log5.log.warn("stream closed", {
1366
- ...context2,
1367
- err
1368
- }, {
1369
- file: "invitations-service.ts",
1370
- line: 97,
1371
- scope: this,
1372
- callSite: (f, a) => f(...a)
1373
- });
1374
- } else {
1375
- (0, import_log5.log)("stream closed", context2, {
1376
- file: "invitations-service.ts",
1377
- line: 99,
1378
- scope: this,
1379
- callSite: (f, a) => f(...a)
1380
- });
1381
- }
1382
- this._createInvitations.delete(invitation.invitationId);
1383
- };
1384
- });
1385
- }
1386
- acceptInvitation(invitation, options) {
1387
- return new import_codec_protobuf7.Stream(({ next, close }) => {
1388
- (0, import_log5.log)("stream opened", this.getLoggingContext(), {
1389
- file: "invitations-service.ts",
1390
- line: 109,
1391
- scope: this,
1392
- callSite: (f, a) => f(...a)
1393
- });
1394
- const invitationsHandler = this._getInvitationsHandler();
1395
- let invitationId;
1396
- const observable = invitationsHandler.acceptInvitation(invitation, options);
1397
- observable.subscribe({
1398
- onConnecting: (invitation2) => {
1399
- (0, import_node_assert5.default)(invitation2.invitationId);
1400
- invitationId = invitation2.invitationId;
1401
- this._acceptInvitations.set(invitation2.invitationId, observable);
1402
- invitation2.state = import_services2.Invitation.State.CONNECTING;
1403
- next(invitation2);
1404
- },
1405
- onConnected: (invitation2) => {
1406
- (0, import_node_assert5.default)(invitation2.invitationId);
1407
- invitation2.state = import_services2.Invitation.State.CONNECTED;
1408
- next(invitation2);
1409
- },
1410
- onAuthenticating: (invitation2) => {
1411
- (0, import_node_assert5.default)(invitation2.invitationId);
1412
- invitation2.state = import_services2.Invitation.State.AUTHENTICATING;
1413
- next(invitation2);
1414
- },
1415
- onSuccess: (invitation2) => {
1416
- invitation2.state = import_services2.Invitation.State.SUCCESS;
1417
- next(invitation2);
1418
- close();
1419
- },
1420
- onCancelled: () => {
1421
- (0, import_node_assert5.default)(invitationId);
1422
- invitation.invitationId = invitationId;
1423
- invitation.state = import_services2.Invitation.State.CANCELLED;
1424
- next(invitation);
1425
- close();
1426
- },
1427
- onTimeout: (err) => {
1428
- invitation.state = import_services2.Invitation.State.TIMEOUT;
1429
- close(err);
1430
- },
1431
- onError: (err) => {
1432
- invitation.state = import_services2.Invitation.State.ERROR;
1433
- close(err);
1538
+ const observable = this._invitationsHandler.createInvitation(handler, invitation);
1539
+ observable.subscribe((invitation2) => {
1540
+ switch (invitation2.state) {
1541
+ case import_services3.Invitation.State.CONNECTING: {
1542
+ (0, import_node_assert6.default)(invitation2.invitationId);
1543
+ invitationId = invitation2.invitationId;
1544
+ this._createInvitations.set(invitation2.invitationId, observable);
1545
+ invitation2.state = import_services3.Invitation.State.CONNECTING;
1546
+ next(invitation2);
1547
+ break;
1548
+ }
1549
+ case import_services3.Invitation.State.CONNECTED: {
1550
+ (0, import_node_assert6.default)(invitation2.invitationId);
1551
+ invitation2.state = import_services3.Invitation.State.CONNECTED;
1552
+ next(invitation2);
1553
+ break;
1554
+ }
1555
+ case import_services3.Invitation.State.READY_FOR_AUTHENTICATION: {
1556
+ (0, import_node_assert6.default)(invitation2.invitationId);
1557
+ invitation2.state = import_services3.Invitation.State.READY_FOR_AUTHENTICATION;
1558
+ next(invitation2);
1559
+ break;
1560
+ }
1561
+ case import_services3.Invitation.State.AUTHENTICATING: {
1562
+ (0, import_node_assert6.default)(invitation2.invitationId);
1563
+ invitation2.state = import_services3.Invitation.State.AUTHENTICATING;
1564
+ next(invitation2);
1565
+ break;
1566
+ }
1567
+ case import_services3.Invitation.State.SUCCESS: {
1568
+ (0, import_node_assert6.default)(invitation2.invitationId);
1569
+ invitation2.state = import_services3.Invitation.State.SUCCESS;
1570
+ next(invitation2);
1571
+ break;
1572
+ }
1573
+ case import_services3.Invitation.State.CANCELLED: {
1574
+ (0, import_node_assert6.default)(invitationId);
1575
+ invitation2.invitationId = invitationId;
1576
+ invitation2.state = import_services3.Invitation.State.CANCELLED;
1577
+ next(invitation2);
1578
+ break;
1579
+ }
1580
+ case import_services3.Invitation.State.TIMEOUT: {
1581
+ (0, import_node_assert6.default)(invitationId);
1582
+ invitation2.invitationId = invitationId;
1583
+ invitation2.state = import_services3.Invitation.State.TIMEOUT;
1584
+ next(invitation2);
1585
+ break;
1586
+ }
1434
1587
  }
1588
+ }, (err) => {
1589
+ close(err);
1590
+ }, () => {
1591
+ close();
1435
1592
  });
1436
1593
  return (err) => {
1437
1594
  const context = this.getLoggingContext();
@@ -1441,559 +1598,255 @@ var AbstractInvitationsService = class {
1441
1598
  err
1442
1599
  }, {
1443
1600
  file: "invitations-service.ts",
1444
- line: 157,
1601
+ line: 103,
1445
1602
  scope: this,
1446
1603
  callSite: (f, a) => f(...a)
1447
1604
  });
1448
1605
  } else {
1449
1606
  (0, import_log5.log)("stream closed", context, {
1450
1607
  file: "invitations-service.ts",
1451
- line: 159,
1452
- scope: this,
1453
- callSite: (f, a) => f(...a)
1454
- });
1455
- }
1456
- this._acceptInvitations.delete(invitation.invitationId);
1457
- };
1458
- });
1459
- }
1460
- async authenticate({ invitationId, authenticationCode }) {
1461
- (0, import_log5.log)("authenticating...", {}, {
1462
- file: "invitations-service.ts",
1463
- line: 168,
1464
- scope: this,
1465
- callSite: (f, a) => f(...a)
1466
- });
1467
- (0, import_node_assert5.default)(invitationId);
1468
- const observable = this._acceptInvitations.get(invitationId);
1469
- if (!observable) {
1470
- import_log5.log.warn("invalid invitation", {
1471
- invitationId
1472
- }, {
1473
- file: "invitations-service.ts",
1474
- line: 172,
1475
- scope: this,
1476
- callSite: (f, a) => f(...a)
1477
- });
1478
- } else {
1479
- await observable.authenticate(authenticationCode);
1480
- }
1481
- }
1482
- async cancelInvitation(invitation) {
1483
- var _a;
1484
- (0, import_log5.log)("cancelling...", {}, {
1485
- file: "invitations-service.ts",
1486
- line: 179,
1487
- scope: this,
1488
- callSite: (f, a) => f(...a)
1489
- });
1490
- (0, import_node_assert5.default)(invitation.invitationId);
1491
- const observable = (_a = this._createInvitations.get(invitation.invitationId)) != null ? _a : this._acceptInvitations.get(invitation.invitationId);
1492
- if (!observable) {
1493
- import_log5.log.warn("invalid invitation", {
1494
- invitationId: invitation.invitationId
1495
- }, {
1496
- file: "invitations-service.ts",
1497
- line: 184,
1498
- scope: this,
1499
- callSite: (f, a) => f(...a)
1500
- });
1501
- } else {
1502
- await (observable == null ? void 0 : observable.cancel());
1503
- }
1504
- }
1505
- };
1506
-
1507
- // packages/sdk/client-services/src/packlets/invitations/device-invitations-service.ts
1508
- var DeviceInvitationsServiceImpl = class extends AbstractInvitationsService {
1509
- // prettier-ignore
1510
- constructor(identityManager, invitationsHandler) {
1511
- super(identityManager, () => invitationsHandler);
1512
- this.invitationsHandler = invitationsHandler;
1513
- }
1514
- getContext(invitation) {
1515
- }
1516
- };
1517
-
1518
- // packages/sdk/client-services/src/packlets/invitations/space-invitations-handler.ts
1519
- var import_node_assert6 = __toESM(require("node:assert"));
1520
- var import_async7 = require("@dxos/async");
1521
- var import_client2 = require("@dxos/client");
1522
- var import_context4 = require("@dxos/context");
1523
- var import_credentials8 = require("@dxos/credentials");
1524
- var import_feed_store3 = require("@dxos/feed-store");
1525
- var import_keys6 = require("@dxos/keys");
1526
- var import_log6 = require("@dxos/log");
1527
- var import_network_manager2 = require("@dxos/network-manager");
1528
- var import_protocols4 = require("@dxos/protocols");
1529
- var import_services3 = require("@dxos/protocols/proto/dxos/client/services");
1530
- var import_invitations2 = require("@dxos/protocols/proto/dxos/halo/invitations");
1531
- var import_teleport2 = require("@dxos/teleport");
1532
- var MAX_OTP_ATTEMPTS = 3;
1533
- var SpaceInvitationsHandler = class extends import_client2.AbstractInvitationsHandler {
1534
- constructor(networkManager, _spaceManager, _signingContext, _keyring) {
1535
- super(networkManager);
1536
- this._spaceManager = _spaceManager;
1537
- this._signingContext = _signingContext;
1538
- this._keyring = _keyring;
1539
- }
1540
- /**
1541
- * Creates an invitation and listens for a join request from the invited (guest) peer.
1542
- */
1543
- createInvitation(space, options) {
1544
- var _a;
1545
- let swarmConnection;
1546
- const { type, timeout = import_client2.INVITATION_TIMEOUT, swarmKey } = options != null ? options : {};
1547
- (0, import_node_assert6.default)(type !== import_services3.Invitation.Type.OFFLINE);
1548
- (0, import_node_assert6.default)(space);
1549
- const invitation = {
1550
- type,
1551
- invitationId: import_keys6.PublicKey.random().toHex(),
1552
- swarmKey: swarmKey != null ? swarmKey : import_keys6.PublicKey.random(),
1553
- spaceKey: space.key,
1554
- authMethod: (_a = options == null ? void 0 : options.authMethod) != null ? _a : import_invitations2.AuthMethod.SHARED_SECRET,
1555
- authenticationCode: (0, import_credentials8.generatePasscode)(import_client2.AUTHENTICATION_CODE_LENGTH)
1556
- // TODO(dmaretskyi): Don't generate if authMethod === NONE .
1557
- };
1558
- const ctx = new import_context4.Context({
1559
- onError: (err) => {
1560
- void ctx.dispose();
1561
- observable.callback.onError(err);
1562
- }
1563
- });
1564
- const observable = new import_client2.InvitationObservableProvider(async () => {
1565
- await (swarmConnection == null ? void 0 : swarmConnection.close());
1566
- });
1567
- let authenticationPassed = false;
1568
- let authenticationRetry = 0;
1569
- const createExtension = () => {
1570
- const complete = new import_async7.Trigger();
1571
- let guestProfile;
1572
- const hostInvitationExtension = new HostSpaceInvitationExtension({
1573
- introduce: async ({ profile }) => {
1574
- var _a2, _b;
1575
- (0, import_log6.log)("guest introduced itself", {
1576
- guestProfile: profile,
1577
- host: this._signingContext.deviceKey,
1578
- spaceKey: space.key
1579
- }, {
1580
- file: "space-invitations-handler.ts",
1581
- line: 101,
1582
- scope: this,
1583
- callSite: (f, a) => f(...a)
1584
- });
1585
- guestProfile = profile;
1586
- (_b = (_a2 = observable.callback).onAuthenticating) == null ? void 0 : _b.call(_a2, invitation);
1587
- return {
1588
- spaceKey: type === import_services3.Invitation.Type.INTERACTIVE_TESTING || type === import_services3.Invitation.Type.MULTIUSE_TESTING ? space.key : void 0,
1589
- authMethod: invitation.authMethod
1590
- };
1591
- },
1592
- authenticate: async ({ authenticationCode: code }) => {
1593
- (0, import_log6.log)("received authentication request", {
1594
- authenticationCode: code
1595
- }, {
1596
- file: "space-invitations-handler.ts",
1597
- line: 123,
1608
+ line: 105,
1598
1609
  scope: this,
1599
1610
  callSite: (f, a) => f(...a)
1600
1611
  });
1601
- let status = import_invitations2.AuthenticationResponse.Status.OK;
1602
- switch (invitation.authMethod) {
1603
- case import_invitations2.AuthMethod.NONE: {
1604
- (0, import_log6.log)("authentication not required", {}, {
1605
- file: "space-invitations-handler.ts",
1606
- line: 128,
1607
- scope: this,
1608
- callSite: (f, a) => f(...a)
1609
- });
1610
- return {
1611
- status: import_invitations2.AuthenticationResponse.Status.OK
1612
- };
1613
- }
1614
- case import_invitations2.AuthMethod.SHARED_SECRET: {
1615
- if (invitation.authenticationCode) {
1616
- if (authenticationRetry++ > MAX_OTP_ATTEMPTS) {
1617
- status = import_invitations2.AuthenticationResponse.Status.INVALID_OPT_ATTEMPTS;
1618
- } else if (code !== invitation.authenticationCode) {
1619
- status = import_invitations2.AuthenticationResponse.Status.INVALID_OTP;
1620
- } else {
1621
- authenticationPassed = true;
1622
- }
1623
- }
1624
- break;
1625
- }
1626
- default: {
1627
- import_log6.log.error("invalid authentication method", {
1628
- authMethod: invitation.authMethod
1629
- }, {
1630
- file: "space-invitations-handler.ts",
1631
- line: 144,
1632
- scope: this,
1633
- callSite: (f, a) => f(...a)
1634
- });
1635
- status = import_invitations2.AuthenticationResponse.Status.INTERNAL_ERROR;
1636
- break;
1637
- }
1638
- }
1639
- return {
1640
- status
1641
- };
1642
- },
1643
- requestAdmission: async ({ identityKey, deviceKey, controlFeedKey, dataFeedKey }) => {
1644
- var _a2;
1645
- try {
1646
- if (isAuthenticationRequired(invitation) && !authenticationPassed) {
1647
- throw new Error("Not authenticated");
1648
- }
1649
- (0, import_log6.log)("writing guest credentials", {
1650
- host: this._signingContext.deviceKey,
1651
- guest: deviceKey
1652
- }, {
1653
- file: "space-invitations-handler.ts",
1654
- line: 160,
1655
- scope: this,
1656
- callSite: (f, a) => f(...a)
1657
- });
1658
- const credentials = await (0, import_credentials8.createAdmissionCredentials)(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile);
1659
- (0, import_node_assert6.default)(credentials[0].credential);
1660
- const spaceMemberCredential = credentials[0].credential.credential;
1661
- (0, import_node_assert6.default)((0, import_credentials8.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
1662
- await (0, import_feed_store3.writeMessages)(space.inner.controlPipeline.writer, credentials);
1663
- complete.wake(deviceKey);
1664
- return {
1665
- credential: spaceMemberCredential,
1666
- controlTimeframe: space.inner.controlPipeline.state.timeframe,
1667
- dataTimeframe: (_a2 = space.dataPipeline.pipelineState) == null ? void 0 : _a2.timeframe
1668
- };
1669
- } catch (err) {
1670
- observable.callback.onError(err);
1671
- throw err;
1672
- }
1673
- },
1674
- onOpen: () => {
1675
- (0, import_async7.scheduleTask)(ctx, async () => {
1676
- var _a2, _b;
1677
- try {
1678
- (0, import_log6.log)("connected", {
1679
- host: this._signingContext.deviceKey
1680
- }, {
1681
- file: "space-invitations-handler.ts",
1682
- line: 195,
1683
- scope: this,
1684
- callSite: (f, a) => f(...a)
1685
- });
1686
- (_b = (_a2 = observable.callback).onConnected) == null ? void 0 : _b.call(_a2, invitation);
1687
- const deviceKey = await complete.wait({
1688
- timeout
1689
- });
1690
- (0, import_log6.log)("admitted guest", {
1691
- host: this._signingContext.deviceKey,
1692
- guest: deviceKey
1693
- }, {
1694
- file: "space-invitations-handler.ts",
1695
- line: 198,
1696
- scope: this,
1697
- callSite: (f, a) => f(...a)
1698
- });
1699
- observable.callback.onSuccess(invitation);
1700
- } catch (err) {
1701
- if (!observable.cancelled) {
1702
- import_log6.log.error("failed", err, {
1703
- file: "space-invitations-handler.ts",
1704
- line: 202,
1705
- scope: this,
1706
- callSite: (f, a) => f(...a)
1707
- });
1708
- observable.callback.onError(err);
1709
- }
1710
- } finally {
1711
- if (type !== import_services3.Invitation.Type.MULTIUSE_TESTING) {
1712
- await (0, import_async7.sleep)(import_client2.ON_CLOSE_DELAY);
1713
- await ctx.dispose();
1714
- }
1715
- }
1716
- });
1717
- }
1718
- });
1719
- return hostInvitationExtension;
1720
- };
1721
- (0, import_async7.scheduleTask)(ctx, async () => {
1722
- var _a2, _b;
1723
- const topic = invitation.swarmKey;
1724
- const swarmConnection2 = await this._networkManager.joinSwarm({
1725
- topic,
1726
- peerId: topic,
1727
- protocolProvider: (0, import_network_manager2.createTeleportProtocolFactory)(async (teleport) => {
1728
- teleport.addExtension("dxos.halo.invitations", createExtension());
1729
- }),
1730
- topology: new import_network_manager2.StarTopology(topic)
1731
- });
1732
- ctx.onDispose(() => swarmConnection2.close());
1733
- (_b = (_a2 = observable.callback).onConnecting) == null ? void 0 : _b.call(_a2, invitation);
1734
- });
1735
- return observable;
1736
- }
1737
- /**
1738
- * Waits for the host peer (inviter) to accept our join request.
1739
- * The local guest peer (invitee) then sends the local space invitation to the host,
1740
- * which then writes the guest's credentials to the space.
1741
- */
1742
- acceptInvitation(invitation, options) {
1743
- const { timeout = import_client2.INVITATION_TIMEOUT } = options != null ? options : {};
1744
- const ctx = new import_context4.Context({
1745
- onError: (err) => {
1746
- void ctx.dispose();
1747
- observable.callback.onError(err);
1748
- }
1749
- });
1750
- const authenticated = new import_async7.Trigger();
1751
- const observable = new import_client2.AuthenticatingInvitationProvider({
1752
- onCancel: async () => {
1753
- await ctx.dispose();
1754
- },
1755
- onAuthenticate: async (code) => {
1756
- authenticated.wake(code);
1757
- }
1758
- });
1759
- let connectionCount = 0;
1760
- const complete = new import_async7.Trigger();
1761
- const createExtension = () => {
1762
- const extension = new GuestSpaceInvitationExtension({
1763
- onOpen: () => {
1764
- (0, import_async7.scheduleTask)(ctx, async () => {
1765
- var _a, _b, _c, _d, _e, _f;
1766
- try {
1767
- if (++connectionCount > 1) {
1768
- throw new Error(`multiple connections detected: ${connectionCount}`);
1769
- }
1770
- (0, import_log6.log)("connected", {
1771
- guest: this._signingContext.deviceKey
1772
- }, {
1773
- file: "space-invitations-handler.ts",
1774
- line: 275,
1775
- scope: this,
1776
- callSite: (f, a) => f(...a)
1777
- });
1778
- (_b = (_a = observable.callback).onConnected) == null ? void 0 : _b.call(_a, invitation);
1779
- (0, import_log6.log)("introduce", {
1780
- guest: this._signingContext.deviceKey
1781
- }, {
1782
- file: "space-invitations-handler.ts",
1783
- line: 279,
1784
- scope: this,
1785
- callSite: (f, a) => f(...a)
1786
- });
1787
- const introductionResponse = await extension.rpc.SpaceHostService.introduce({
1788
- profile: this._signingContext.profile
1789
- });
1790
- (0, import_log6.log)("introduce response", {
1791
- guest: this._signingContext.deviceKey,
1792
- response: introductionResponse
1793
- }, {
1794
- file: "space-invitations-handler.ts",
1795
- line: 283,
1796
- scope: this,
1797
- callSite: (f, a) => f(...a)
1798
- });
1799
- invitation.authMethod = introductionResponse.authMethod;
1800
- if (introductionResponse.spaceKey) {
1801
- invitation.spaceKey = introductionResponse.spaceKey;
1802
- }
1803
- if (isAuthenticationRequired(invitation)) {
1804
- (_d = (_c = observable.callback).onAuthenticating) == null ? void 0 : _d.call(_c, invitation);
1805
- for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
1806
- (0, import_log6.log)("guest waiting for authentication code...", {}, {
1807
- file: "space-invitations-handler.ts",
1808
- line: 297,
1809
- scope: this,
1810
- callSite: (f, a) => f(...a)
1811
- });
1812
- (_f = (_e = observable.callback).onAuthenticating) == null ? void 0 : _f.call(_e, invitation);
1813
- const authenticationCode = await authenticated.wait({
1814
- timeout
1815
- });
1816
- (0, import_log6.log)("sending authentication request", {}, {
1817
- file: "space-invitations-handler.ts",
1818
- line: 301,
1819
- scope: this,
1820
- callSite: (f, a) => f(...a)
1821
- });
1822
- const response = await extension.rpc.SpaceHostService.authenticate({
1823
- authenticationCode
1824
- });
1825
- if (response.status === void 0 || response.status === import_invitations2.AuthenticationResponse.Status.OK) {
1826
- break;
1827
- }
1828
- if (response.status === import_invitations2.AuthenticationResponse.Status.INVALID_OTP) {
1829
- if (attempt === MAX_OTP_ATTEMPTS) {
1830
- throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
1831
- } else {
1832
- (0, import_log6.log)("retrying invalid code", {
1833
- attempt
1834
- }, {
1835
- file: "space-invitations-handler.ts",
1836
- line: 311,
1837
- scope: this,
1838
- callSite: (f, a) => f(...a)
1839
- });
1840
- authenticated.reset();
1841
- }
1842
- }
1843
- }
1844
- }
1845
- const controlFeedKey = await this._keyring.createKey();
1846
- const dataFeedKey = await this._keyring.createKey();
1847
- (0, import_log6.log)("request admission", {
1848
- guest: this._signingContext.deviceKey
1849
- }, {
1850
- file: "space-invitations-handler.ts",
1851
- line: 322,
1852
- scope: this,
1853
- callSite: (f, a) => f(...a)
1854
- });
1855
- const { credential, controlTimeframe, dataTimeframe } = await extension.rpc.SpaceHostService.requestAdmission({
1856
- identityKey: this._signingContext.identityKey,
1857
- deviceKey: this._signingContext.deviceKey,
1858
- controlFeedKey,
1859
- dataFeedKey
1860
- });
1861
- const assertion = (0, import_credentials8.getCredentialAssertion)(credential);
1862
- (0, import_node_assert6.default)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential");
1863
- (0, import_node_assert6.default)(credential.subject.id.equals(this._signingContext.identityKey));
1864
- const space = await this._spaceManager.acceptSpace({
1865
- spaceKey: assertion.spaceKey,
1866
- genesisFeedKey: assertion.genesisFeedKey,
1867
- controlTimeframe,
1868
- dataTimeframe
1869
- });
1870
- await this._signingContext.recordCredential(credential);
1871
- (0, import_log6.log)("admitted by host", {
1872
- guest: this._signingContext.deviceKey,
1873
- spaceKey: space.key
1874
- }, {
1875
- file: "space-invitations-handler.ts",
1876
- line: 347,
1877
- scope: this,
1878
- callSite: (f, a) => f(...a)
1879
- });
1880
- complete.wake();
1881
- } catch (err) {
1882
- if (!observable.cancelled) {
1883
- import_log6.log.warn("auth failed", err, {
1884
- file: "space-invitations-handler.ts",
1885
- line: 351,
1886
- scope: this,
1887
- callSite: (f, a) => f(...a)
1888
- });
1889
- observable.callback.onError(err);
1890
- }
1891
- } finally {
1892
- await ctx.dispose();
1893
- }
1894
- });
1895
1612
  }
1613
+ this._createInvitations.delete(invitation.invitationId);
1614
+ };
1615
+ });
1616
+ }
1617
+ acceptInvitation(invitation) {
1618
+ return new import_codec_protobuf7.Stream(({ next, close }) => {
1619
+ (0, import_log5.log)("stream opened", this.getLoggingContext(), {
1620
+ file: "invitations-service.ts",
1621
+ line: 115,
1622
+ scope: this,
1623
+ callSite: (f, a) => f(...a)
1896
1624
  });
1897
- return extension;
1898
- };
1899
- (0, import_async7.scheduleTask)(ctx, async () => {
1900
- var _a, _b;
1901
- (0, import_node_assert6.default)(invitation.swarmKey);
1902
- const topic = invitation.swarmKey;
1903
- const swarmConnection = await this._networkManager.joinSwarm({
1904
- topic,
1905
- peerId: import_keys6.PublicKey.random(),
1906
- protocolProvider: (0, import_network_manager2.createTeleportProtocolFactory)(async (teleport) => {
1907
- teleport.addExtension("dxos.halo.invitations", createExtension());
1908
- }),
1909
- topology: new import_network_manager2.StarTopology(topic)
1625
+ const handler = this._getHandler(invitation);
1626
+ let invitationId;
1627
+ const observable = this._invitationsHandler.acceptInvitation(handler, invitation);
1628
+ observable.subscribe((invitation2) => {
1629
+ switch (invitation2.state) {
1630
+ case import_services3.Invitation.State.CONNECTING: {
1631
+ (0, import_node_assert6.default)(invitation2.invitationId);
1632
+ invitationId = invitation2.invitationId;
1633
+ this._acceptInvitations.set(invitation2.invitationId, observable);
1634
+ invitation2.state = import_services3.Invitation.State.CONNECTING;
1635
+ next(invitation2);
1636
+ break;
1637
+ }
1638
+ case import_services3.Invitation.State.CONNECTED: {
1639
+ (0, import_node_assert6.default)(invitation2.invitationId);
1640
+ invitation2.state = import_services3.Invitation.State.CONNECTED;
1641
+ next(invitation2);
1642
+ break;
1643
+ }
1644
+ case import_services3.Invitation.State.READY_FOR_AUTHENTICATION: {
1645
+ (0, import_node_assert6.default)(invitation2.invitationId);
1646
+ invitation2.state = import_services3.Invitation.State.READY_FOR_AUTHENTICATION;
1647
+ next(invitation2);
1648
+ break;
1649
+ }
1650
+ case import_services3.Invitation.State.AUTHENTICATING: {
1651
+ (0, import_node_assert6.default)(invitation2.invitationId);
1652
+ invitation2.state = import_services3.Invitation.State.AUTHENTICATING;
1653
+ next(invitation2);
1654
+ break;
1655
+ }
1656
+ case import_services3.Invitation.State.SUCCESS: {
1657
+ invitation2.state = import_services3.Invitation.State.SUCCESS;
1658
+ next(invitation2);
1659
+ break;
1660
+ }
1661
+ case import_services3.Invitation.State.CANCELLED: {
1662
+ (0, import_node_assert6.default)(invitationId);
1663
+ invitation2.invitationId = invitationId;
1664
+ invitation2.state = import_services3.Invitation.State.CANCELLED;
1665
+ next(invitation2);
1666
+ break;
1667
+ }
1668
+ case import_services3.Invitation.State.TIMEOUT: {
1669
+ (0, import_node_assert6.default)(invitationId);
1670
+ invitation2.invitationId = invitationId;
1671
+ invitation2.state = import_services3.Invitation.State.TIMEOUT;
1672
+ next(invitation2);
1673
+ break;
1674
+ }
1675
+ }
1676
+ }, (err) => {
1677
+ close(err);
1678
+ }, () => {
1679
+ close();
1910
1680
  });
1911
- ctx.onDispose(() => swarmConnection.close());
1912
- (_b = (_a = observable.callback).onConnecting) == null ? void 0 : _b.call(_a, invitation);
1913
- await complete.wait();
1914
- observable.callback.onSuccess(invitation);
1915
- await ctx.dispose();
1681
+ return (err) => {
1682
+ const context = this.getLoggingContext();
1683
+ if (err) {
1684
+ import_log5.log.warn("stream closed", {
1685
+ ...context,
1686
+ err
1687
+ }, {
1688
+ file: "invitations-service.ts",
1689
+ line: 181,
1690
+ scope: this,
1691
+ callSite: (f, a) => f(...a)
1692
+ });
1693
+ } else {
1694
+ (0, import_log5.log)("stream closed", context, {
1695
+ file: "invitations-service.ts",
1696
+ line: 183,
1697
+ scope: this,
1698
+ callSite: (f, a) => f(...a)
1699
+ });
1700
+ }
1701
+ this._acceptInvitations.delete(invitation.invitationId);
1702
+ };
1916
1703
  });
1917
- return observable;
1918
1704
  }
1919
- };
1920
- var isAuthenticationRequired = (invitation) => invitation.authMethod !== import_invitations2.AuthMethod.NONE && invitation.type !== import_services3.Invitation.Type.INTERACTIVE_TESTING && invitation.type !== import_services3.Invitation.Type.MULTIUSE_TESTING;
1921
- var HostSpaceInvitationExtension = class extends import_teleport2.RpcExtension {
1922
- constructor(_callbacks) {
1923
- super({
1924
- exposed: {
1925
- SpaceHostService: import_protocols4.schema.getService("dxos.halo.invitations.SpaceHostService")
1926
- }
1705
+ async authenticate({ invitationId, authCode }) {
1706
+ (0, import_log5.log)("authenticating...", {}, {
1707
+ file: "invitations-service.ts",
1708
+ line: 192,
1709
+ scope: this,
1710
+ callSite: (f, a) => f(...a)
1927
1711
  });
1928
- this._callbacks = _callbacks;
1712
+ (0, import_node_assert6.default)(invitationId);
1713
+ const observable = this._acceptInvitations.get(invitationId);
1714
+ if (!observable) {
1715
+ import_log5.log.warn("invalid invitation", {
1716
+ invitationId
1717
+ }, {
1718
+ file: "invitations-service.ts",
1719
+ line: 196,
1720
+ scope: this,
1721
+ callSite: (f, a) => f(...a)
1722
+ });
1723
+ } else {
1724
+ await observable.authenticate(authCode);
1725
+ }
1929
1726
  }
1930
- async getHandlers() {
1727
+ async cancelInvitation({ invitationId }) {
1728
+ var _a;
1729
+ (0, import_log5.log)("cancelling...", {}, {
1730
+ file: "invitations-service.ts",
1731
+ line: 203,
1732
+ scope: this,
1733
+ callSite: (f, a) => f(...a)
1734
+ });
1735
+ (0, import_node_assert6.default)(invitationId);
1736
+ const observable = (_a = this._createInvitations.get(invitationId)) != null ? _a : this._acceptInvitations.get(invitationId);
1737
+ if (!observable) {
1738
+ import_log5.log.warn("invalid invitation", {
1739
+ invitationId
1740
+ }, {
1741
+ file: "invitations-service.ts",
1742
+ line: 207,
1743
+ scope: this,
1744
+ callSite: (f, a) => f(...a)
1745
+ });
1746
+ } else {
1747
+ await (observable == null ? void 0 : observable.cancel());
1748
+ }
1749
+ }
1750
+ };
1751
+
1752
+ // packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts
1753
+ var import_node_assert7 = __toESM(require("node:assert"));
1754
+ var import_credentials8 = require("@dxos/credentials");
1755
+ var import_feed_store3 = require("@dxos/feed-store");
1756
+ var import_log6 = require("@dxos/log");
1757
+ var import_services4 = require("@dxos/protocols/proto/dxos/client/services");
1758
+ var SpaceInvitationProtocol = class {
1759
+ constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
1760
+ this._spaceManager = _spaceManager;
1761
+ this._signingContext = _signingContext;
1762
+ this._keyring = _keyring;
1763
+ this._spaceKey = _spaceKey;
1764
+ }
1765
+ toJSON() {
1931
1766
  return {
1932
- // TODO(dmaretskyi): For now this is just forwarding the data to callbacks since we don't have session-specific logic.
1933
- // Perhaps in the future we will have more complex logic here.
1934
- SpaceHostService: {
1935
- introduce: async (params) => {
1936
- return this._callbacks.introduce(params);
1937
- },
1938
- authenticate: async (credentials) => {
1939
- return this._callbacks.authenticate(credentials);
1940
- },
1941
- requestAdmission: async (credentials) => {
1942
- return this._callbacks.requestAdmission(credentials);
1943
- }
1944
- }
1767
+ deviceKey: this._signingContext.deviceKey,
1768
+ spaceKey: this._spaceKey
1945
1769
  };
1946
1770
  }
1947
- async onOpen(context) {
1948
- await super.onOpen(context);
1949
- this._callbacks.onOpen();
1771
+ getInvitationContext() {
1772
+ return {
1773
+ kind: import_services4.Invitation.Kind.SPACE,
1774
+ spaceKey: this._spaceKey
1775
+ };
1950
1776
  }
1951
- };
1952
- var GuestSpaceInvitationExtension = class extends import_teleport2.RpcExtension {
1953
- constructor(_callbacks) {
1954
- super({
1955
- requested: {
1956
- SpaceHostService: import_protocols4.schema.getService("dxos.halo.invitations.SpaceHostService")
1957
- }
1777
+ async admit(request, guestProfile) {
1778
+ var _a;
1779
+ (0, import_node_assert7.default)(this._spaceKey);
1780
+ const space = await this._spaceManager.spaces.get(this._spaceKey);
1781
+ (0, import_node_assert7.default)(space);
1782
+ (0, import_node_assert7.default)(request.space);
1783
+ const { identityKey, deviceKey } = request.space;
1784
+ (0, import_log6.log)("writing guest credentials", {
1785
+ host: this._signingContext.deviceKey,
1786
+ guest: deviceKey
1787
+ }, {
1788
+ file: "space-invitation-protocol.ts",
1789
+ line: 51,
1790
+ scope: this,
1791
+ callSite: (f, a) => f(...a)
1958
1792
  });
1959
- this._callbacks = _callbacks;
1793
+ const credentials = await (0, import_credentials8.createAdmissionCredentials)(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile);
1794
+ (0, import_node_assert7.default)(credentials[0].credential);
1795
+ const spaceMemberCredential = credentials[0].credential.credential;
1796
+ (0, import_node_assert7.default)((0, import_credentials8.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
1797
+ await (0, import_feed_store3.writeMessages)(space.inner.controlPipeline.writer, credentials);
1798
+ return {
1799
+ space: {
1800
+ credential: spaceMemberCredential,
1801
+ controlTimeframe: space.inner.controlPipeline.state.timeframe,
1802
+ dataTimeframe: (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.timeframe
1803
+ }
1804
+ };
1960
1805
  }
1961
- async getHandlers() {
1962
- return {};
1806
+ createIntroduction() {
1807
+ return {
1808
+ profile: this._signingContext.profile
1809
+ };
1963
1810
  }
1964
- async onOpen(context) {
1965
- await super.onOpen(context);
1966
- this._callbacks.onOpen();
1811
+ async createAdmissionRequest() {
1812
+ const controlFeedKey = await this._keyring.createKey();
1813
+ const dataFeedKey = await this._keyring.createKey();
1814
+ return {
1815
+ space: {
1816
+ identityKey: this._signingContext.identityKey,
1817
+ deviceKey: this._signingContext.deviceKey,
1818
+ controlFeedKey,
1819
+ dataFeedKey
1820
+ }
1821
+ };
1967
1822
  }
1968
- };
1969
-
1970
- // packages/sdk/client-services/src/packlets/invitations/space-invitations-service.ts
1971
- var import_node_assert7 = __toESM(require("node:assert"));
1972
- var SpaceInvitationsServiceImpl = class extends AbstractInvitationsService {
1973
- // prettier-ignore
1974
- constructor(identityManager, invitationsHandler, _getSpaceManager) {
1975
- super(identityManager, invitationsHandler);
1976
- this.invitationsHandler = invitationsHandler;
1977
- this._getSpaceManager = _getSpaceManager;
1978
- }
1979
- getContext(invitation) {
1980
- (0, import_node_assert7.default)(invitation.spaceKey);
1981
- const spaceManager = this._getSpaceManager();
1982
- const space = spaceManager.spaces.get(invitation.spaceKey);
1983
- (0, import_node_assert7.default)(space);
1984
- return space;
1823
+ async accept(response) {
1824
+ (0, import_node_assert7.default)(response.space);
1825
+ const { credential, controlTimeframe, dataTimeframe } = response.space;
1826
+ const assertion = (0, import_credentials8.getCredentialAssertion)(credential);
1827
+ (0, import_node_assert7.default)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential");
1828
+ (0, import_node_assert7.default)(credential.subject.id.equals(this._signingContext.identityKey));
1829
+ await this._spaceManager.acceptSpace({
1830
+ spaceKey: assertion.spaceKey,
1831
+ genesisFeedKey: assertion.genesisFeedKey,
1832
+ controlTimeframe,
1833
+ dataTimeframe
1834
+ });
1835
+ await this._signingContext.recordCredential(credential);
1836
+ return {
1837
+ spaceKey: assertion.spaceKey
1838
+ };
1985
1839
  }
1986
1840
  };
1987
1841
 
1988
1842
  // packages/sdk/client-services/src/packlets/services/service-host.ts
1989
- var import_node_assert12 = __toESM(require("node:assert"));
1990
- var import_async19 = require("@dxos/async");
1843
+ var import_node_assert13 = __toESM(require("node:assert"));
1844
+ var import_async18 = require("@dxos/async");
1991
1845
  var import_client8 = require("@dxos/client");
1992
- var import_debug7 = require("@dxos/debug");
1993
1846
  var import_echo_pipeline5 = require("@dxos/echo-pipeline");
1994
1847
  var import_log16 = require("@dxos/log");
1995
1848
  var import_protocols7 = require("@dxos/protocols");
1996
- var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
1849
+ var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
1997
1850
 
1998
1851
  // packages/sdk/client-services/src/packlets/deprecated/tracing.ts
1999
1852
  var TracingServiceImpl = class {
@@ -2009,9 +1862,9 @@ var TracingServiceImpl = class {
2009
1862
  };
2010
1863
 
2011
1864
  // packages/sdk/client-services/src/packlets/devices/devices-service.ts
2012
- var import_async8 = require("@dxos/async");
1865
+ var import_async7 = require("@dxos/async");
2013
1866
  var import_codec_protobuf8 = require("@dxos/codec-protobuf");
2014
- var import_services4 = require("@dxos/protocols/proto/dxos/client/services");
1867
+ var import_services5 = require("@dxos/protocols/proto/dxos/client/services");
2015
1868
  var DevicesServiceImpl = class {
2016
1869
  constructor(_identityManager) {
2017
1870
  this._identityManager = _identityManager;
@@ -2034,13 +1887,13 @@ var DevicesServiceImpl = class {
2034
1887
  var _a2;
2035
1888
  return {
2036
1889
  deviceKey: key,
2037
- kind: ((_a2 = this._identityManager.identity) == null ? void 0 : _a2.deviceKey.equals(key)) ? import_services4.DeviceKind.CURRENT : import_services4.DeviceKind.TRUSTED
1890
+ kind: ((_a2 = this._identityManager.identity) == null ? void 0 : _a2.deviceKey.equals(key)) ? import_services5.DeviceKind.CURRENT : import_services5.DeviceKind.TRUSTED
2038
1891
  };
2039
1892
  })
2040
1893
  });
2041
1894
  }
2042
1895
  };
2043
- const subscriptions = new import_async8.EventSubscriptions();
1896
+ const subscriptions = new import_async7.EventSubscriptions();
2044
1897
  subscriptions.add(this._identityManager.stateUpdate.on(() => {
2045
1898
  update();
2046
1899
  if (this._identityManager.identity) {
@@ -2079,47 +1932,48 @@ var NetworkServiceImpl = class {
2079
1932
 
2080
1933
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
2081
1934
  var import_node_assert9 = __toESM(require("node:assert"));
2082
- var import_async11 = require("@dxos/async");
2083
- var import_client4 = require("@dxos/client");
2084
- var import_context7 = require("@dxos/context");
1935
+ var import_async10 = require("@dxos/async");
1936
+ var import_client3 = require("@dxos/client");
1937
+ var import_context6 = require("@dxos/context");
2085
1938
  var import_credentials10 = require("@dxos/credentials");
2086
1939
  var import_echo_pipeline2 = require("@dxos/echo-pipeline");
2087
- var import_keys9 = require("@dxos/keys");
1940
+ var import_keys8 = require("@dxos/keys");
2088
1941
  var import_log9 = require("@dxos/log");
1942
+ var import_protocols5 = require("@dxos/protocols");
2089
1943
  var import_teleport_extension_gossip = require("@dxos/teleport-extension-gossip");
2090
1944
  var import_util5 = require("@dxos/util");
2091
1945
 
2092
1946
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2093
- var import_async10 = require("@dxos/async");
2094
- var import_client3 = require("@dxos/client");
2095
- var import_context6 = require("@dxos/context");
1947
+ var import_async9 = require("@dxos/async");
1948
+ var import_client2 = require("@dxos/client");
1949
+ var import_context5 = require("@dxos/context");
2096
1950
  var import_debug3 = require("@dxos/debug");
2097
1951
  var import_echo_pipeline = require("@dxos/echo-pipeline");
2098
1952
  var import_errors = require("@dxos/errors");
2099
- var import_keys8 = require("@dxos/keys");
1953
+ var import_keys7 = require("@dxos/keys");
2100
1954
  var import_log8 = require("@dxos/log");
2101
1955
  var import_credentials9 = require("@dxos/protocols/proto/dxos/halo/credentials");
2102
1956
  var import_util4 = require("@dxos/util");
2103
1957
 
2104
1958
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
2105
1959
  var import_node_assert8 = __toESM(require("node:assert"));
2106
- var import_async9 = require("@dxos/async");
2107
- var import_context5 = require("@dxos/context");
2108
- var import_keys7 = require("@dxos/keys");
1960
+ var import_async8 = require("@dxos/async");
1961
+ var import_context4 = require("@dxos/context");
1962
+ var import_keys6 = require("@dxos/keys");
2109
1963
  var import_log7 = require("@dxos/log");
2110
- var import_protocols5 = require("@dxos/protocols");
2111
- var import_teleport3 = require("@dxos/teleport");
1964
+ var import_protocols4 = require("@dxos/protocols");
1965
+ var import_teleport2 = require("@dxos/teleport");
2112
1966
  var import_util3 = require("@dxos/util");
2113
1967
  var DEFAULT_RETRY_TIMEOUT = 1e3;
2114
1968
  var DEFAULT_SUCCESS_DELAY = 1e3;
2115
1969
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
2116
1970
  var NotarizationPlugin = class {
2117
1971
  constructor() {
2118
- this._ctx = new import_context5.Context();
2119
- this._extensionOpened = new import_async9.Event();
1972
+ this._ctx = new import_context4.Context();
1973
+ this._extensionOpened = new import_async8.Event();
2120
1974
  this._extensions = /* @__PURE__ */ new Set();
2121
- this._processedCredentials = new import_util3.ComplexSet(import_keys7.PublicKey.hash);
2122
- this._processCredentialsTriggers = new import_util3.ComplexMap(import_keys7.PublicKey.hash);
1975
+ this._processedCredentials = new import_util3.ComplexSet(import_keys6.PublicKey.hash);
1976
+ this._processCredentialsTriggers = new import_util3.ComplexMap(import_keys6.PublicKey.hash);
2123
1977
  }
2124
1978
  async open() {
2125
1979
  }
@@ -2139,7 +1993,7 @@ var NotarizationPlugin = class {
2139
1993
  callSite: (f, a) => f(...a)
2140
1994
  });
2141
1995
  (0, import_node_assert8.default)(credentials.every((credential) => credential.id), "Credentials must have an id");
2142
- const errors = new import_async9.Trigger();
1996
+ const errors = new import_async8.Trigger();
2143
1997
  const ctx = this._ctx.derive({
2144
1998
  onError: (err) => {
2145
1999
  import_log7.log.warn("Notarization error", {
@@ -2156,7 +2010,7 @@ var NotarizationPlugin = class {
2156
2010
  });
2157
2011
  opCtx == null ? void 0 : opCtx.onDispose(() => ctx.dispose());
2158
2012
  if (timeout !== 0) {
2159
- (0, import_async9.scheduleTask)(ctx, () => {
2013
+ (0, import_async8.scheduleTask)(ctx, () => {
2160
2014
  import_log7.log.warn("Notarization timeout", {
2161
2015
  timeout,
2162
2016
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
@@ -2167,12 +2021,12 @@ var NotarizationPlugin = class {
2167
2021
  callSite: (f, a) => f(...a)
2168
2022
  });
2169
2023
  void ctx.dispose();
2170
- errors.throw(new import_async9.TimeoutError(timeout, "Notarization timed out"));
2024
+ errors.throw(new import_async8.TimeoutError(timeout, "Notarization timed out"));
2171
2025
  }, timeout);
2172
2026
  }
2173
2027
  const allNotarized = Promise.all(credentials.map((credential) => this._waitUntilProcessed(credential.id)));
2174
2028
  const peersTried = /* @__PURE__ */ new Set();
2175
- const notarizeTask = new import_async9.DeferredTask(ctx, async () => {
2029
+ const notarizeTask = new import_async8.DeferredTask(ctx, async () => {
2176
2030
  try {
2177
2031
  if (this._extensions.size === 0) {
2178
2032
  return;
@@ -2190,7 +2044,7 @@ var NotarizationPlugin = class {
2190
2044
  callSite: (f, a) => f(...a)
2191
2045
  });
2192
2046
  peersTried.clear();
2193
- (0, import_async9.scheduleTask)(ctx, () => notarizeTask.schedule(), retryTimeout);
2047
+ (0, import_async8.scheduleTask)(ctx, () => notarizeTask.schedule(), retryTimeout);
2194
2048
  return;
2195
2049
  }
2196
2050
  peersTried.add(peer);
@@ -2212,7 +2066,7 @@ var NotarizationPlugin = class {
2212
2066
  scope: this,
2213
2067
  callSite: (f, a) => f(...a)
2214
2068
  });
2215
- await (0, import_async9.sleep)(successDelay);
2069
+ await (0, import_async8.sleep)(successDelay);
2216
2070
  } catch (err) {
2217
2071
  import_log7.log.warn("error notarizing (recoverable)", err, {
2218
2072
  file: "notarization-plugin.ts",
@@ -2227,7 +2081,7 @@ var NotarizationPlugin = class {
2227
2081
  this._extensionOpened.on(ctx, () => notarizeTask.schedule());
2228
2082
  try {
2229
2083
  await Promise.race([
2230
- (0, import_context5.rejectOnDispose)(ctx),
2084
+ (0, import_context4.rejectOnDispose)(ctx),
2231
2085
  allNotarized,
2232
2086
  errors.wait()
2233
2087
  ]);
@@ -2261,7 +2115,7 @@ var NotarizationPlugin = class {
2261
2115
  if (this._processedCredentials.has(id)) {
2262
2116
  return;
2263
2117
  }
2264
- await (0, import_util3.entry)(this._processCredentialsTriggers, id).orInsert(new import_async9.Trigger()).value.wait();
2118
+ await (0, import_util3.entry)(this._processCredentialsTriggers, id).orInsert(new import_async8.Trigger()).value.wait();
2265
2119
  }
2266
2120
  /**
2267
2121
  * Requests from other peers to notarize credentials.
@@ -2309,14 +2163,14 @@ var NotarizationPlugin = class {
2309
2163
  return extension;
2310
2164
  }
2311
2165
  };
2312
- var NotarizationTeleportExtension = class extends import_teleport3.RpcExtension {
2166
+ var NotarizationTeleportExtension = class extends import_teleport2.RpcExtension {
2313
2167
  constructor(_params) {
2314
2168
  super({
2315
2169
  requested: {
2316
- NotarizationService: import_protocols5.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
2170
+ NotarizationService: import_protocols4.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
2317
2171
  },
2318
2172
  exposed: {
2319
- NotarizationService: import_protocols5.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
2173
+ NotarizationService: import_protocols4.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
2320
2174
  }
2321
2175
  });
2322
2176
  this._params = _params;
@@ -2354,9 +2208,9 @@ var __decorate = function(decorators, target, key, desc) {
2354
2208
  var AUTH_TIMEOUT2 = 3e4;
2355
2209
  var DataSpace = class DataSpace2 {
2356
2210
  constructor(params) {
2357
- this._ctx = new import_context6.Context();
2358
- this._state = import_client3.SpaceState.CLOSED;
2359
- this.stateUpdate = new import_async10.Event();
2211
+ this._ctx = new import_context5.Context();
2212
+ this._state = import_client2.SpaceState.CLOSED;
2213
+ this.stateUpdate = new import_async9.Event();
2360
2214
  var _a;
2361
2215
  this._inner = params.inner;
2362
2216
  this._inner.stateUpdate.on(this._ctx, () => this.stateUpdate.emit());
@@ -2377,7 +2231,7 @@ var DataSpace = class DataSpace2 {
2377
2231
  snapshotId: params.snapshotId
2378
2232
  });
2379
2233
  this.authVerifier = new TrustedKeySetAuthVerifier({
2380
- trustedKeysProvider: () => new import_util4.ComplexSet(import_keys8.PublicKey.hash, Array.from(this._inner.spaceState.members.keys())),
2234
+ trustedKeysProvider: () => new import_util4.ComplexSet(import_keys7.PublicKey.hash, Array.from(this._inner.spaceState.members.keys())),
2381
2235
  update: this._inner.stateUpdate,
2382
2236
  authTimeout: AUTH_TIMEOUT2
2383
2237
  });
@@ -2409,10 +2263,10 @@ var DataSpace = class DataSpace2 {
2409
2263
  await this.notarizationPlugin.open();
2410
2264
  await this._notarizationPluginConsumer.open();
2411
2265
  await this._inner.open();
2412
- this._state = import_client3.SpaceState.INACTIVE;
2266
+ this._state = import_client2.SpaceState.INACTIVE;
2413
2267
  }
2414
2268
  async close() {
2415
- this._state = import_client3.SpaceState.CLOSED;
2269
+ this._state = import_client2.SpaceState.CLOSED;
2416
2270
  await this._ctx.dispose();
2417
2271
  await this._dataPipeline.close();
2418
2272
  await this.authVerifier.close();
@@ -2431,7 +2285,7 @@ var DataSpace = class DataSpace2 {
2431
2285
  * Initialize the data pipeline in a separate task.
2432
2286
  */
2433
2287
  initializeDataPipelineAsync() {
2434
- (0, import_async10.scheduleTask)(this._ctx, async () => {
2288
+ (0, import_async9.scheduleTask)(this._ctx, async () => {
2435
2289
  try {
2436
2290
  await this.initializeDataPipeline();
2437
2291
  } catch (err) {
@@ -2455,10 +2309,10 @@ var DataSpace = class DataSpace2 {
2455
2309
  }
2456
2310
  async initializeDataPipeline() {
2457
2311
  var _a, _b, _c, _d;
2458
- if (this._state !== import_client3.SpaceState.INACTIVE) {
2312
+ if (this._state !== import_client2.SpaceState.INACTIVE) {
2459
2313
  throw new import_errors.SystemError("Invalid operation");
2460
2314
  }
2461
- this._state = import_client3.SpaceState.INITIALIZING;
2315
+ this._state = import_client2.SpaceState.INITIALIZING;
2462
2316
  await this._inner.controlPipeline.state.waitUntilReachedTargetTimeframe({
2463
2317
  ctx: this._ctx,
2464
2318
  breakOnStall: false
@@ -2502,7 +2356,7 @@ var DataSpace = class DataSpace2 {
2502
2356
  callSite: (f, a) => f(...a)
2503
2357
  });
2504
2358
  await ((_b = (_a = this._callbacks).beforeReady) == null ? void 0 : _b.call(_a));
2505
- this._state = import_client3.SpaceState.READY;
2359
+ this._state = import_client2.SpaceState.READY;
2506
2360
  this.stateUpdate.emit();
2507
2361
  await ((_d = (_c = this._callbacks).afterReady) == null ? void 0 : _d.call(_c));
2508
2362
  }
@@ -2554,7 +2408,7 @@ __decorate([
2554
2408
  (0, import_debug3.timed)(1e4)
2555
2409
  ], DataSpace.prototype, "_createWritableFeeds", null);
2556
2410
  DataSpace = __decorate([
2557
- (0, import_async10.trackLeaks)("open", "close")
2411
+ (0, import_async9.trackLeaks)("open", "close")
2558
2412
  ], DataSpace);
2559
2413
 
2560
2414
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
@@ -2578,10 +2432,11 @@ var DataSpaceManager = class DataSpaceManager2 {
2578
2432
  this._modelFactory = _modelFactory;
2579
2433
  this._feedStore = _feedStore;
2580
2434
  this._snapshotStore = _snapshotStore;
2581
- this._ctx = new import_context7.Context();
2582
- this.updated = new import_async11.Event();
2583
- this._spaces = new import_util5.ComplexMap(import_keys9.PublicKey.hash);
2435
+ this._ctx = new import_context6.Context();
2436
+ this.updated = new import_async10.Event();
2437
+ this._spaces = new import_util5.ComplexMap(import_keys8.PublicKey.hash);
2584
2438
  this._isOpen = false;
2439
+ this._instanceId = import_keys8.PublicKey.random().toHex();
2585
2440
  }
2586
2441
  // TODO(burdon): Remove.
2587
2442
  get spaces() {
@@ -2590,7 +2445,16 @@ var DataSpaceManager = class DataSpaceManager2 {
2590
2445
  async open() {
2591
2446
  (0, import_log9.log)("open", {}, {
2592
2447
  file: "data-space-manager.ts",
2593
- line: 80,
2448
+ line: 83,
2449
+ scope: this,
2450
+ callSite: (f, a) => f(...a)
2451
+ });
2452
+ import_log9.log.trace("dxos.echo.data-space-manager", import_protocols5.trace.begin({
2453
+ id: this._instanceId,
2454
+ parentId: this._traceParent
2455
+ }), {
2456
+ file: "data-space-manager.ts",
2457
+ line: 84,
2594
2458
  scope: this,
2595
2459
  callSite: (f, a) => f(...a)
2596
2460
  });
@@ -2599,7 +2463,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2599
2463
  spaces: this._metadataStore.spaces.length
2600
2464
  }, {
2601
2465
  file: "data-space-manager.ts",
2602
- line: 82,
2466
+ line: 86,
2603
2467
  scope: this,
2604
2468
  callSite: (f, a) => f(...a)
2605
2469
  });
@@ -2608,7 +2472,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2608
2472
  spaceMetadata
2609
2473
  }, {
2610
2474
  file: "data-space-manager.ts",
2611
- line: 85,
2475
+ line: 89,
2612
2476
  scope: this,
2613
2477
  callSite: (f, a) => f(...a)
2614
2478
  });
@@ -2621,7 +2485,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2621
2485
  async close() {
2622
2486
  (0, import_log9.log)("close", {}, {
2623
2487
  file: "data-space-manager.ts",
2624
- line: 96,
2488
+ line: 100,
2625
2489
  scope: this,
2626
2490
  callSite: (f, a) => f(...a)
2627
2491
  });
@@ -2630,6 +2494,14 @@ var DataSpaceManager = class DataSpaceManager2 {
2630
2494
  for (const space of this._spaces.values()) {
2631
2495
  await space.close();
2632
2496
  }
2497
+ import_log9.log.trace("dxos.echo.data-space-manager", import_protocols5.trace.end({
2498
+ id: this._instanceId
2499
+ }), {
2500
+ file: "data-space-manager.ts",
2501
+ line: 106,
2502
+ scope: this,
2503
+ callSite: (f, a) => f(...a)
2504
+ });
2633
2505
  }
2634
2506
  /**
2635
2507
  * Creates a new space writing the genesis credentials to the control feed.
@@ -2649,7 +2521,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2649
2521
  spaceKey
2650
2522
  }, {
2651
2523
  file: "data-space-manager.ts",
2652
- line: 120,
2524
+ line: 125,
2653
2525
  scope: this,
2654
2526
  callSite: (f, a) => f(...a)
2655
2527
  });
@@ -2669,7 +2541,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2669
2541
  opts
2670
2542
  }, {
2671
2543
  file: "data-space-manager.ts",
2672
- line: 139,
2544
+ line: 144,
2673
2545
  scope: this,
2674
2546
  callSite: (f, a) => f(...a)
2675
2547
  });
@@ -2693,9 +2565,9 @@ var DataSpaceManager = class DataSpaceManager2 {
2693
2565
  * TODO(dmaretskyi): Consider removing.
2694
2566
  */
2695
2567
  async waitUntilSpaceReady(spaceKey) {
2696
- await (0, import_context7.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
2568
+ await (0, import_context6.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
2697
2569
  const space = this._spaces.get(spaceKey);
2698
- return !!space && space.state === import_client4.SpaceState.READY;
2570
+ return !!space && space.state === import_client3.SpaceState.READY;
2699
2571
  }));
2700
2572
  }
2701
2573
  async _constructSpace(metadata) {
@@ -2703,7 +2575,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2703
2575
  metadata
2704
2576
  }, {
2705
2577
  file: "data-space-manager.ts",
2706
- line: 175,
2578
+ line: 180,
2707
2579
  scope: this,
2708
2580
  callSite: (f, a) => f(...a)
2709
2581
  });
@@ -2758,7 +2630,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2758
2630
  space: space.key
2759
2631
  }, {
2760
2632
  file: "data-space-manager.ts",
2761
- line: 224,
2633
+ line: 229,
2762
2634
  scope: this,
2763
2635
  callSite: (f, a) => f(...a)
2764
2636
  });
@@ -2770,7 +2642,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2770
2642
  open: this._isOpen
2771
2643
  }, {
2772
2644
  file: "data-space-manager.ts",
2773
- line: 231,
2645
+ line: 236,
2774
2646
  scope: this,
2775
2647
  callSite: (f, a) => f(...a)
2776
2648
  });
@@ -2792,28 +2664,28 @@ var DataSpaceManager = class DataSpaceManager2 {
2792
2664
  }
2793
2665
  };
2794
2666
  __decorate2([
2795
- import_async11.synchronized
2667
+ import_async10.synchronized
2796
2668
  ], DataSpaceManager.prototype, "open", null);
2797
2669
  __decorate2([
2798
- import_async11.synchronized
2670
+ import_async10.synchronized
2799
2671
  ], DataSpaceManager.prototype, "close", null);
2800
2672
  __decorate2([
2801
- import_async11.synchronized
2673
+ import_async10.synchronized
2802
2674
  ], DataSpaceManager.prototype, "createSpace", null);
2803
2675
  __decorate2([
2804
- import_async11.synchronized
2676
+ import_async10.synchronized
2805
2677
  ], DataSpaceManager.prototype, "acceptSpace", null);
2806
2678
  DataSpaceManager = __decorate2([
2807
- (0, import_async11.trackLeaks)("open", "close")
2679
+ (0, import_async10.trackLeaks)("open", "close")
2808
2680
  ], DataSpaceManager);
2809
2681
 
2810
2682
  // packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
2811
- var import_async12 = require("@dxos/async");
2683
+ var import_async11 = require("@dxos/async");
2812
2684
  var import_codec_protobuf10 = require("@dxos/codec-protobuf");
2813
2685
  var import_debug4 = require("@dxos/debug");
2814
2686
  var import_echo_pipeline3 = require("@dxos/echo-pipeline");
2815
2687
  var import_log10 = require("@dxos/log");
2816
- var import_services5 = require("@dxos/protocols/proto/dxos/client/services");
2688
+ var import_services6 = require("@dxos/protocols/proto/dxos/client/services");
2817
2689
  var import_util6 = require("@dxos/util");
2818
2690
  var TIMEFRAME_UPDATE_DEBOUNCE_TIME = 500;
2819
2691
  var SpacesServiceImpl = class {
@@ -2851,9 +2723,9 @@ var SpacesServiceImpl = class {
2851
2723
  spaces
2852
2724
  });
2853
2725
  };
2854
- (0, import_async12.scheduleTask)(ctx, async () => {
2726
+ (0, import_async11.scheduleTask)(ctx, async () => {
2855
2727
  const dataSpaceManager = await this._getDataSpaceManager();
2856
- const subscriptions = new import_async12.EventSubscriptions();
2728
+ const subscriptions = new import_async11.EventSubscriptions();
2857
2729
  ctx.onDispose(() => subscriptions.clear());
2858
2730
  const subscribeSpaces = () => {
2859
2731
  subscriptions.clear();
@@ -2888,7 +2760,7 @@ var SpacesServiceImpl = class {
2888
2760
  }
2889
2761
  subscribeMessages({ spaceKey, channel }) {
2890
2762
  return new import_codec_protobuf10.Stream(({ ctx, next }) => {
2891
- (0, import_async12.scheduleTask)(ctx, async () => {
2763
+ (0, import_async11.scheduleTask)(ctx, async () => {
2892
2764
  var _a;
2893
2765
  const dataSpaceManager = await this._getDataSpaceManager();
2894
2766
  const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug4.raise)(new import_echo_pipeline3.SpaceNotFoundError(spaceKey));
@@ -2909,7 +2781,7 @@ var SpacesServiceImpl = class {
2909
2781
  }
2910
2782
  });
2911
2783
  ctx.onDispose(() => processor.close());
2912
- (0, import_async12.scheduleTask)(ctx, () => processor.open());
2784
+ (0, import_async11.scheduleTask)(ctx, () => processor.open());
2913
2785
  });
2914
2786
  }
2915
2787
  async writeCredentials({ spaceKey, credentials }) {
@@ -2924,18 +2796,22 @@ var SpacesServiceImpl = class {
2924
2796
  }
2925
2797
  }
2926
2798
  _transformSpace(space) {
2927
- var _a, _b;
2799
+ var _a, _b, _c, _d, _e;
2928
2800
  return {
2929
2801
  spaceKey: space.key,
2930
2802
  state: space.state,
2931
2803
  pipeline: {
2932
- targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
2804
+ controlFeeds: space.inner.controlPipeline.state.feeds.map((feed) => feed.key),
2933
2805
  currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
2934
- currentDataTimeframe: (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.timeframe,
2935
- targetDataTimeframe: (_b = space.dataPipeline.pipelineState) == null ? void 0 : _b.targetTimeframe
2806
+ targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
2807
+ totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe,
2808
+ dataFeeds: (_b = (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.feeds.map((feed) => feed.key)) != null ? _b : [],
2809
+ currentDataTimeframe: (_c = space.dataPipeline.pipelineState) == null ? void 0 : _c.timeframe,
2810
+ targetDataTimeframe: (_d = space.dataPipeline.pipelineState) == null ? void 0 : _d.targetTimeframe,
2811
+ totalDataTimeframe: (_e = space.dataPipeline.pipelineState) == null ? void 0 : _e.endTimeframe
2936
2812
  },
2937
2813
  members: Array.from(space.inner.spaceState.members.values()).map((member) => {
2938
- var _a2, _b2, _c;
2814
+ var _a2, _b2, _c2;
2939
2815
  return {
2940
2816
  identity: {
2941
2817
  identityKey: member.key,
@@ -2943,7 +2819,7 @@ var SpacesServiceImpl = class {
2943
2819
  displayName: (_b2 = (_a2 = member.assertion.profile) == null ? void 0 : _a2.displayName) != null ? _b2 : (0, import_util6.humanize)(member.key)
2944
2820
  }
2945
2821
  },
2946
- presence: ((_c = this._identityManager.identity) == null ? void 0 : _c.identityKey.equals(member.key)) || space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? import_services5.SpaceMember.PresenceState.ONLINE : import_services5.SpaceMember.PresenceState.OFFLINE
2822
+ presence: ((_c2 = this._identityManager.identity) == null ? void 0 : _c2.identityKey.equals(member.key)) || space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? import_services6.SpaceMember.PresenceState.ONLINE : import_services6.SpaceMember.PresenceState.OFFLINE
2947
2823
  };
2948
2824
  })
2949
2825
  };
@@ -2991,6 +2867,8 @@ var toStorageType = (type) => {
2991
2867
  return import_random_access_storage.StorageType.IDB;
2992
2868
  case StorageDriver.NODE:
2993
2869
  return import_random_access_storage.StorageType.NODE;
2870
+ case StorageDriver.WEBFS:
2871
+ return import_random_access_storage.StorageType.WEBFS;
2994
2872
  default:
2995
2873
  throw new Error(`Invalid storage type: ${StorageDriver[type]}`);
2996
2874
  }
@@ -3035,10 +2913,10 @@ var SystemServiceImpl = class {
3035
2913
  };
3036
2914
 
3037
2915
  // packages/sdk/client-services/src/packlets/vault/iframe-host-runtime.ts
3038
- var import_async14 = require("@dxos/async");
2916
+ var import_async13 = require("@dxos/async");
3039
2917
  var import_log11 = require("@dxos/log");
3040
2918
  var import_messaging = require("@dxos/messaging");
3041
- var import_network_manager3 = require("@dxos/network-manager");
2919
+ var import_network_manager2 = require("@dxos/network-manager");
3042
2920
  var import_util7 = require("@dxos/util");
3043
2921
 
3044
2922
  // packages/sdk/client-services/src/packlets/services/client-rpc-server.ts
@@ -3096,14 +2974,14 @@ var ClientRpcServer = class {
3096
2974
 
3097
2975
  // packages/sdk/client-services/src/packlets/vault/shell-runtime.ts
3098
2976
  var import_node_assert10 = __toESM(require("node:assert"));
3099
- var import_async13 = require("@dxos/async");
3100
- var import_client5 = require("@dxos/client");
2977
+ var import_async12 = require("@dxos/async");
2978
+ var import_client4 = require("@dxos/client");
3101
2979
  var import_iframe = require("@dxos/protocols/proto/dxos/iframe");
3102
2980
  var import_rpc2 = require("@dxos/rpc");
3103
2981
  var ShellRuntimeImpl = class {
3104
2982
  constructor(_port) {
3105
2983
  this._port = _port;
3106
- this.layoutUpdate = new import_async13.Event();
2984
+ this.layoutUpdate = new import_async12.Event();
3107
2985
  this._layout = import_iframe.ShellLayout.DEFAULT;
3108
2986
  }
3109
2987
  get layout() {
@@ -3130,8 +3008,8 @@ var ShellRuntimeImpl = class {
3130
3008
  }
3131
3009
  async open() {
3132
3010
  this._appRpc = (0, import_rpc2.createProtoRpcPeer)({
3133
- requested: import_client5.appServiceBundle,
3134
- exposed: import_client5.shellServiceBundle,
3011
+ requested: import_client4.appServiceBundle,
3012
+ exposed: import_client4.shellServiceBundle,
3135
3013
  handlers: {
3136
3014
  ShellService: {
3137
3015
  setLayout: async (request) => {
@@ -3154,8 +3032,8 @@ var ShellRuntimeImpl = class {
3154
3032
  };
3155
3033
  var MemoryShellRuntime = class {
3156
3034
  constructor({ layout, invitationCode, spaceKey } = {}) {
3157
- this.layoutUpdate = new import_async13.Event();
3158
- this.contextUpdate = new import_async13.Event();
3035
+ this.layoutUpdate = new import_async12.Event();
3036
+ this.contextUpdate = new import_async12.Event();
3159
3037
  this._layout = layout != null ? layout : import_iframe.ShellLayout.DEFAULT;
3160
3038
  this._invitationCode = invitationCode;
3161
3039
  this._spaceKey = spaceKey;
@@ -3197,8 +3075,8 @@ var __decorate3 = function(decorators, target, key, desc) {
3197
3075
  var LOCK_KEY = "DXOS_RESOURCE_LOCK";
3198
3076
  var IFrameHostRuntime = class {
3199
3077
  constructor({ configProvider, appPort, shellPort }) {
3200
- this._transportFactory = (0, import_network_manager3.createWebRTCTransportFactory)();
3201
- this._ready = new import_async14.Trigger();
3078
+ this._transportFactory = (0, import_network_manager2.createWebRTCTransportFactory)();
3079
+ this._ready = new import_async13.Trigger();
3202
3080
  this._configProvider = configProvider;
3203
3081
  this._appPort = appPort;
3204
3082
  this._shellPort = shellPort;
@@ -3226,7 +3104,7 @@ var IFrameHostRuntime = class {
3226
3104
  this._clientServices = new LocalClientServices({
3227
3105
  lockKey: LOCK_KEY,
3228
3106
  config: this._config,
3229
- networkManager: new import_network_manager3.NetworkManager({
3107
+ networkManager: new import_network_manager2.NetworkManager({
3230
3108
  log: true,
3231
3109
  signalManager: signalServer ? new import_messaging.WebsocketSignalManager([
3232
3110
  signalServer
@@ -3305,19 +3183,19 @@ __decorate3([
3305
3183
  ], IFrameHostRuntime.prototype, "origin", void 0);
3306
3184
 
3307
3185
  // packages/sdk/client-services/src/packlets/vault/iframe-proxy-runtime.ts
3308
- var import_client6 = require("@dxos/client");
3309
- var import_network_manager4 = require("@dxos/network-manager");
3186
+ var import_client5 = require("@dxos/client");
3187
+ var import_network_manager3 = require("@dxos/network-manager");
3310
3188
  var import_rpc3 = require("@dxos/rpc");
3311
3189
  var IFrameProxyRuntime = class {
3312
3190
  constructor({ systemPort, workerAppPort, windowAppPort, shellPort }) {
3313
- this._transportService = new import_network_manager4.WebRTCTransportService();
3191
+ this._transportService = new import_network_manager3.WebRTCTransportService();
3314
3192
  this._systemPort = systemPort;
3315
3193
  this._windowAppPort = windowAppPort;
3316
3194
  this._workerAppPort = workerAppPort;
3317
3195
  this._shellPort = shellPort;
3318
3196
  this._systemRpc = (0, import_rpc3.createProtoRpcPeer)({
3319
- requested: import_client6.workerServiceBundle,
3320
- exposed: import_client6.iframeServiceBundle,
3197
+ requested: import_client5.workerServiceBundle,
3198
+ exposed: import_client5.iframeServiceBundle,
3321
3199
  handlers: {
3322
3200
  BridgeService: this._transportService,
3323
3201
  IframeService: {
@@ -3354,7 +3232,7 @@ var IFrameProxyRuntime = class {
3354
3232
  };
3355
3233
 
3356
3234
  // packages/sdk/client-services/src/packlets/vault/vault-resource-lock.ts
3357
- var import_async15 = require("@dxos/async");
3235
+ var import_async14 = require("@dxos/async");
3358
3236
  var import_log12 = require("@dxos/log");
3359
3237
  var __decorate4 = function(decorators, target, key, desc) {
3360
3238
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -3373,7 +3251,7 @@ var Message;
3373
3251
  var VaultResourceLock = class {
3374
3252
  constructor({ lockKey, onAcquire, onRelease }) {
3375
3253
  this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
3376
- this._releaseTrigger = new import_async15.Trigger();
3254
+ this._releaseTrigger = new import_async14.Trigger();
3377
3255
  this._lockKey = lockKey;
3378
3256
  this._onAcquire = onAcquire;
3379
3257
  this._onRelease = onRelease;
@@ -3393,7 +3271,7 @@ var VaultResourceLock = class {
3393
3271
  scope: this,
3394
3272
  callSite: (f, a) => f(...a)
3395
3273
  });
3396
- await (0, import_async15.asyncTimeout)(this._requestLock(), 3e3);
3274
+ await (0, import_async14.asyncTimeout)(this._requestLock(), 3e3);
3397
3275
  (0, import_log12.log)("acquired lock", {}, {
3398
3276
  file: "vault-resource-lock.ts",
3399
3277
  line: 46,
@@ -3433,14 +3311,14 @@ var VaultResourceLock = class {
3433
3311
  scope: this,
3434
3312
  callSite: (f, a) => f(...a)
3435
3313
  });
3436
- const acquired = new import_async15.Trigger();
3314
+ const acquired = new import_async14.Trigger();
3437
3315
  void navigator.locks.request(this._lockKey, {
3438
3316
  steal
3439
3317
  }, async () => {
3440
3318
  var _a, _b;
3441
3319
  await ((_a = this._onAcquire) == null ? void 0 : _a.call(this));
3442
3320
  acquired.wake();
3443
- this._releaseTrigger = new import_async15.Trigger();
3321
+ this._releaseTrigger = new import_async14.Trigger();
3444
3322
  await this._releaseTrigger.wait();
3445
3323
  (0, import_log12.log)("releasing lock...", {}, {
3446
3324
  file: "vault-resource-lock.ts",
@@ -3475,15 +3353,15 @@ __decorate4([
3475
3353
  ], VaultResourceLock.prototype, "lockKey", null);
3476
3354
 
3477
3355
  // packages/sdk/client-services/src/packlets/vault/worker-runtime.ts
3478
- var import_async17 = require("@dxos/async");
3356
+ var import_async16 = require("@dxos/async");
3479
3357
  var import_log14 = require("@dxos/log");
3480
3358
  var import_messaging2 = require("@dxos/messaging");
3481
- var import_network_manager5 = require("@dxos/network-manager");
3359
+ var import_network_manager4 = require("@dxos/network-manager");
3482
3360
 
3483
3361
  // packages/sdk/client-services/src/packlets/vault/worker-session.ts
3484
3362
  var import_node_assert11 = __toESM(require("node:assert"));
3485
- var import_async16 = require("@dxos/async");
3486
- var import_client7 = require("@dxos/client");
3363
+ var import_async15 = require("@dxos/async");
3364
+ var import_client6 = require("@dxos/client");
3487
3365
  var import_log13 = require("@dxos/log");
3488
3366
  var import_rpc4 = require("@dxos/rpc");
3489
3367
  var import_util8 = require("@dxos/util");
@@ -3501,7 +3379,7 @@ var WorkerSession = class {
3501
3379
  constructor({ serviceHost, systemPort, appPort, shellPort, readySignal, options = {
3502
3380
  heartbeatInterval: 1e3
3503
3381
  } }) {
3504
- this._startTrigger = new import_async16.Trigger();
3382
+ this._startTrigger = new import_async15.Trigger();
3505
3383
  this.onClose = new import_util8.Callback();
3506
3384
  (0, import_node_assert11.default)(options);
3507
3385
  (0, import_node_assert11.default)(serviceHost);
@@ -3538,8 +3416,8 @@ var WorkerSession = class {
3538
3416
  ...middleware
3539
3417
  });
3540
3418
  this._iframeRpc = (0, import_rpc4.createProtoRpcPeer)({
3541
- requested: import_client7.iframeServiceBundle,
3542
- exposed: import_client7.workerServiceBundle,
3419
+ requested: import_client6.iframeServiceBundle,
3420
+ exposed: import_client6.workerServiceBundle,
3543
3421
  handlers: {
3544
3422
  WorkerService: {
3545
3423
  start: async (request) => {
@@ -3635,7 +3513,7 @@ var WorkerSession = class {
3635
3513
  }
3636
3514
  async _maybeOpenShell() {
3637
3515
  try {
3638
- await (0, import_async16.asyncTimeout)(this._shellClientRpc.open(), 1e3);
3516
+ await (0, import_async15.asyncTimeout)(this._shellClientRpc.open(), 1e3);
3639
3517
  } catch (e) {
3640
3518
  import_log13.log.info("No shell connected.", {}, {
3641
3519
  file: "worker-session.ts",
@@ -3655,15 +3533,18 @@ var WorkerRuntime = class {
3655
3533
  // prettier-ignore
3656
3534
  constructor(_configProvider) {
3657
3535
  this._configProvider = _configProvider;
3658
- this._transportFactory = new import_network_manager5.WebRTCTransportProxyFactory();
3659
- this._ready = new import_async17.Trigger();
3536
+ this._transportFactory = new import_network_manager4.WebRTCTransportProxyFactory();
3537
+ this._ready = new import_async16.Trigger();
3660
3538
  this.sessions = /* @__PURE__ */ new Set();
3661
3539
  this._clientServices = new ClientServicesHost();
3662
3540
  }
3541
+ get host() {
3542
+ return this._clientServices;
3543
+ }
3663
3544
  async start() {
3664
3545
  (0, import_log14.log)("starting...", {}, {
3665
3546
  file: "worker-runtime.ts",
3666
- line: 44,
3547
+ line: 48,
3667
3548
  scope: this,
3668
3549
  callSite: (f, a) => f(...a)
3669
3550
  });
@@ -3672,7 +3553,7 @@ var WorkerRuntime = class {
3672
3553
  const signalServer = this._config.get("runtime.services.signal.server");
3673
3554
  this._clientServices.initialize({
3674
3555
  config: this._config,
3675
- networkManager: new import_network_manager5.NetworkManager({
3556
+ networkManager: new import_network_manager4.NetworkManager({
3676
3557
  log: true,
3677
3558
  signalManager: signalServer ? new import_messaging2.WebsocketSignalManager([
3678
3559
  signalServer
@@ -3684,7 +3565,7 @@ var WorkerRuntime = class {
3684
3565
  this._ready.wake(void 0);
3685
3566
  (0, import_log14.log)("started", {}, {
3686
3567
  file: "worker-runtime.ts",
3687
- line: 61,
3568
+ line: 65,
3688
3569
  scope: this,
3689
3570
  callSite: (f, a) => f(...a)
3690
3571
  });
@@ -3692,7 +3573,7 @@ var WorkerRuntime = class {
3692
3573
  this._ready.wake(err);
3693
3574
  import_log14.log.catch(err, {}, {
3694
3575
  file: "worker-runtime.ts",
3695
- line: 64,
3576
+ line: 68,
3696
3577
  scope: this,
3697
3578
  callSite: (f, a) => f(...a)
3698
3579
  });
@@ -3742,13 +3623,15 @@ var WorkerRuntime = class {
3742
3623
  };
3743
3624
 
3744
3625
  // packages/sdk/client-services/src/packlets/services/service-context.ts
3745
- var import_async18 = require("@dxos/async");
3626
+ var import_node_assert12 = __toESM(require("node:assert"));
3627
+ var import_async17 = require("@dxos/async");
3628
+ var import_client7 = require("@dxos/client");
3746
3629
  var import_credentials11 = require("@dxos/credentials");
3747
3630
  var import_debug6 = require("@dxos/debug");
3748
3631
  var import_echo_pipeline4 = require("@dxos/echo-pipeline");
3749
3632
  var import_feed_store4 = require("@dxos/feed-store");
3750
3633
  var import_keyring = require("@dxos/keyring");
3751
- var import_keys10 = require("@dxos/keys");
3634
+ var import_keys9 = require("@dxos/keys");
3752
3635
  var import_log15 = require("@dxos/log");
3753
3636
  var import_protocols6 = require("@dxos/protocols");
3754
3637
  var ServiceContext = class {
@@ -3757,9 +3640,11 @@ var ServiceContext = class {
3757
3640
  this.storage = storage;
3758
3641
  this.networkManager = networkManager;
3759
3642
  this.modelFactory = modelFactory;
3760
- this.initialized = new import_async18.Trigger();
3643
+ this.initialized = new import_async17.Trigger();
3761
3644
  this.dataServiceSubscriptions = new import_echo_pipeline4.DataServiceSubscriptions();
3762
- this._instanceId = import_keys10.PublicKey.random().toHex();
3645
+ this._handlerFactories = /* @__PURE__ */ new Map();
3646
+ this._instanceId = import_keys9.PublicKey.random().toHex();
3647
+ networkManager._traceParent = this._instanceId;
3763
3648
  this.metadataStore = new import_echo_pipeline4.MetadataStore(storage.createDirectory("metadata"));
3764
3649
  this.snapshotStore = new import_echo_pipeline4.SnapshotStore(storage.createDirectory("snapshots"));
3765
3650
  this.keyring = new import_keyring.Keyring(storage.createDirectory("keyring"));
@@ -3776,29 +3661,27 @@ var ServiceContext = class {
3776
3661
  feedStore: this.feedStore,
3777
3662
  networkManager: this.networkManager
3778
3663
  });
3664
+ this.spaceManager._traceParent = this._instanceId;
3779
3665
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager);
3780
- this.deviceInvitations = new DeviceInvitationsHandler({
3781
- networkManager: this.networkManager,
3782
- getIdentity: () => {
3783
- var _a;
3784
- return (_a = this.identityManager.identity) != null ? _a : (0, import_debug6.failUndefined)();
3785
- },
3786
- acceptIdentity: this._acceptIdentity.bind(this),
3787
- keyring: this.keyring
3788
- });
3666
+ this.identityManager._traceParent = this._instanceId;
3667
+ this.invitations = new InvitationsHandler(this.networkManager);
3668
+ this._handlerFactories.set(import_client7.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => {
3669
+ var _a;
3670
+ return (_a = this.identityManager.identity) != null ? _a : (0, import_debug6.failUndefined)();
3671
+ }, this._acceptIdentity.bind(this)));
3789
3672
  }
3790
3673
  async open() {
3791
- import_log15.log.trace("dxos.sdk.client-services", import_protocols6.trace.begin({
3674
+ import_log15.log.trace("dxos.sdk.service-context", import_protocols6.trace.begin({
3792
3675
  id: this._instanceId
3793
3676
  }), {
3794
3677
  file: "service-context.ts",
3795
- line: 98,
3678
+ line: 114,
3796
3679
  scope: this,
3797
3680
  callSite: (f, a) => f(...a)
3798
3681
  });
3799
3682
  (0, import_log15.log)("opening...", {}, {
3800
3683
  file: "service-context.ts",
3801
- line: 100,
3684
+ line: 116,
3802
3685
  scope: this,
3803
3686
  callSite: (f, a) => f(...a)
3804
3687
  });
@@ -3810,7 +3693,7 @@ var ServiceContext = class {
3810
3693
  }
3811
3694
  (0, import_log15.log)("opened", {}, {
3812
3695
  file: "service-context.ts",
3813
- line: 107,
3696
+ line: 123,
3814
3697
  scope: this,
3815
3698
  callSite: (f, a) => f(...a)
3816
3699
  });
@@ -3819,7 +3702,7 @@ var ServiceContext = class {
3819
3702
  var _a, _b;
3820
3703
  (0, import_log15.log)("closing...", {}, {
3821
3704
  file: "service-context.ts",
3822
- line: 111,
3705
+ line: 127,
3823
3706
  scope: this,
3824
3707
  callSite: (f, a) => f(...a)
3825
3708
  });
@@ -3832,15 +3715,15 @@ var ServiceContext = class {
3832
3715
  this.dataServiceSubscriptions.clear();
3833
3716
  (0, import_log15.log)("closed", {}, {
3834
3717
  file: "service-context.ts",
3835
- line: 119,
3718
+ line: 135,
3836
3719
  scope: this,
3837
3720
  callSite: (f, a) => f(...a)
3838
3721
  });
3839
- import_log15.log.trace("dxos.sdk.client-services", import_protocols6.trace.end({
3722
+ import_log15.log.trace("dxos.sdk.service-context", import_protocols6.trace.end({
3840
3723
  id: this._instanceId
3841
3724
  }), {
3842
3725
  file: "service-context.ts",
3843
- line: 121,
3726
+ line: 137,
3844
3727
  scope: this,
3845
3728
  callSite: (f, a) => f(...a)
3846
3729
  });
@@ -3848,7 +3731,7 @@ var ServiceContext = class {
3848
3731
  async reset() {
3849
3732
  (0, import_log15.log)("resetting...", {}, {
3850
3733
  file: "service-context.ts",
3851
- line: 125,
3734
+ line: 141,
3852
3735
  scope: this,
3853
3736
  callSite: (f, a) => f(...a)
3854
3737
  });
@@ -3856,7 +3739,7 @@ var ServiceContext = class {
3856
3739
  await this.storage.reset();
3857
3740
  (0, import_log15.log)("reset", {}, {
3858
3741
  file: "service-context.ts",
3859
- line: 128,
3742
+ line: 144,
3860
3743
  scope: this,
3861
3744
  callSite: (f, a) => f(...a)
3862
3745
  });
@@ -3866,6 +3749,11 @@ var ServiceContext = class {
3866
3749
  await this._initialize();
3867
3750
  return identity;
3868
3751
  }
3752
+ getInvitationHandler(invitation) {
3753
+ const factory = this._handlerFactories.get(invitation.kind);
3754
+ (0, import_node_assert12.default)(factory, `Unknown invitation kind: ${invitation.kind}`);
3755
+ return factory(invitation);
3756
+ }
3869
3757
  async _acceptIdentity(params) {
3870
3758
  const identity = await this.identityManager.acceptIdentity(params);
3871
3759
  await this._initialize();
@@ -3876,7 +3764,7 @@ var ServiceContext = class {
3876
3764
  var _a;
3877
3765
  (0, import_log15.log)("initializing spaces...", {}, {
3878
3766
  file: "service-context.ts",
3879
- line: 147,
3767
+ line: 169,
3880
3768
  scope: this,
3881
3769
  callSite: (f, a) => f(...a)
3882
3770
  });
@@ -3895,8 +3783,12 @@ var ServiceContext = class {
3895
3783
  }
3896
3784
  };
3897
3785
  this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.dataServiceSubscriptions, this.keyring, signingContext, this.modelFactory, this.feedStore, this.snapshotStore);
3786
+ this.dataSpaceManager._traceParent = this._instanceId;
3898
3787
  await this.dataSpaceManager.open();
3899
- this.spaceInvitations = new SpaceInvitationsHandler(this.networkManager, this.dataSpaceManager, signingContext, this.keyring);
3788
+ this._handlerFactories.set(import_client7.Invitation.Kind.SPACE, (invitation) => {
3789
+ (0, import_node_assert12.default)(this.dataSpaceManager, "dataSpaceManager not initialized yet");
3790
+ return new SpaceInvitationProtocol(this.dataSpaceManager, signingContext, this.keyring, invitation.spaceKey);
3791
+ });
3900
3792
  this.initialized.wake();
3901
3793
  this._deviceSpaceSync = identity.space.spaceState.registerProcessor({
3902
3794
  process: async (credential) => {
@@ -3912,7 +3804,7 @@ var ServiceContext = class {
3912
3804
  details: assertion
3913
3805
  }, {
3914
3806
  file: "service-context.ts",
3915
- line: 190,
3807
+ line: 211,
3916
3808
  scope: this,
3917
3809
  callSite: (f, a) => f(...a)
3918
3810
  });
@@ -3923,7 +3815,7 @@ var ServiceContext = class {
3923
3815
  details: assertion
3924
3816
  }, {
3925
3817
  file: "service-context.ts",
3926
- line: 194,
3818
+ line: 215,
3927
3819
  scope: this,
3928
3820
  callSite: (f, a) => f(...a)
3929
3821
  });
@@ -3934,7 +3826,7 @@ var ServiceContext = class {
3934
3826
  details: assertion
3935
3827
  }, {
3936
3828
  file: "service-context.ts",
3937
- line: 199,
3829
+ line: 220,
3938
3830
  scope: this,
3939
3831
  callSite: (f, a) => f(...a)
3940
3832
  });
@@ -3945,7 +3837,7 @@ var ServiceContext = class {
3945
3837
  } catch (err) {
3946
3838
  import_log15.log.catch(err, {}, {
3947
3839
  file: "service-context.ts",
3948
- line: 205,
3840
+ line: 226,
3949
3841
  scope: this,
3950
3842
  callSite: (f, a) => f(...a)
3951
3843
  });
@@ -3991,7 +3883,7 @@ var ClientServicesHost = class {
3991
3883
  // TODO(wittjosiah): Turn this on by default.
3992
3884
  lockKey
3993
3885
  } = {}) {
3994
- this._statusUpdate = new import_async19.Event();
3886
+ this._statusUpdate = new import_async18.Event();
3995
3887
  this._opening = false;
3996
3888
  this._open = false;
3997
3889
  this._instanceId = import_client8.PublicKey.random().toHex();
@@ -4013,17 +3905,17 @@ var ClientServicesHost = class {
4013
3905
  this._systemService = new SystemServiceImpl({
4014
3906
  config: this._config,
4015
3907
  statusUpdate: this._statusUpdate,
4016
- getCurrentStatus: () => this.isOpen ? import_services8.SystemStatus.ACTIVE : import_services8.SystemStatus.INACTIVE,
3908
+ getCurrentStatus: () => this.isOpen ? import_services9.SystemStatus.ACTIVE : import_services9.SystemStatus.INACTIVE,
4017
3909
  onUpdateStatus: async (status) => {
4018
3910
  var _a, _b;
4019
- if (!this.isOpen && status === import_services8.SystemStatus.ACTIVE) {
3911
+ if (!this.isOpen && status === import_services9.SystemStatus.ACTIVE) {
4020
3912
  await ((_a = this._resourceLock) == null ? void 0 : _a.acquire());
4021
- } else if (this.isOpen && status === import_services8.SystemStatus.INACTIVE) {
3913
+ } else if (this.isOpen && status === import_services9.SystemStatus.INACTIVE) {
4022
3914
  await ((_b = this._resourceLock) == null ? void 0 : _b.release());
4023
3915
  }
4024
3916
  },
4025
3917
  onReset: async () => {
4026
- (0, import_node_assert12.default)(this._serviceContext, "service host is closed");
3918
+ (0, import_node_assert13.default)(this._serviceContext, "service host is closed");
4027
3919
  await this._serviceContext.reset();
4028
3920
  }
4029
3921
  });
@@ -4049,16 +3941,16 @@ var ClientServicesHost = class {
4049
3941
  * Can only be called once.
4050
3942
  */
4051
3943
  initialize({ config, networkManager }) {
4052
- (0, import_node_assert12.default)(!this._open, "service host is open");
3944
+ (0, import_node_assert13.default)(!this._open, "service host is open");
4053
3945
  if (config) {
4054
- (0, import_node_assert12.default)(!this._config, "config already set");
3946
+ (0, import_node_assert13.default)(!this._config, "config already set");
4055
3947
  this._config = config;
4056
3948
  if (!this._storage) {
4057
3949
  this._storage = createStorageObjects(config.get("runtime.client.storage", {})).storage;
4058
3950
  }
4059
3951
  }
4060
3952
  if (networkManager) {
4061
- (0, import_node_assert12.default)(!this._networkManager, "network manager already set");
3953
+ (0, import_node_assert13.default)(!this._networkManager, "network manager already set");
4062
3954
  this._networkManager = networkManager;
4063
3955
  }
4064
3956
  }
@@ -4071,19 +3963,19 @@ var ClientServicesHost = class {
4071
3963
  id: this._instanceId
4072
3964
  }), {
4073
3965
  file: "service-host.ts",
4074
- line: 168,
3966
+ line: 167,
4075
3967
  scope: this,
4076
3968
  callSite: (f, a) => f(...a)
4077
3969
  });
4078
- (0, import_node_assert12.default)(this._config, "config not set");
4079
- (0, import_node_assert12.default)(this._storage, "storage not set");
4080
- (0, import_node_assert12.default)(this._networkManager, "network manager not set");
3970
+ (0, import_node_assert13.default)(this._config, "config not set");
3971
+ (0, import_node_assert13.default)(this._storage, "storage not set");
3972
+ (0, import_node_assert13.default)(this._networkManager, "network manager not set");
4081
3973
  this._opening = true;
4082
3974
  (0, import_log16.log)("opening...", {
4083
3975
  lockKey: (_a = this._resourceLock) == null ? void 0 : _a.lockKey
4084
3976
  }, {
4085
3977
  file: "service-host.ts",
4086
- line: 175,
3978
+ line: 174,
4087
3979
  scope: this,
4088
3980
  callSite: (f, a) => f(...a)
4089
3981
  });
@@ -4092,15 +3984,8 @@ var ClientServicesHost = class {
4092
3984
  this._serviceRegistry.setServices({
4093
3985
  SystemService: this._systemService,
4094
3986
  IdentityService: new IdentityServiceImpl(this._serviceContext),
3987
+ InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitations, (invitation) => this._serviceContext.getInvitationHandler(invitation)),
4095
3988
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
4096
- DeviceInvitationsService: new DeviceInvitationsServiceImpl(this._serviceContext.identityManager, this._serviceContext.deviceInvitations),
4097
- SpaceInvitationsService: new SpaceInvitationsServiceImpl(this._serviceContext.identityManager, () => {
4098
- var _a2;
4099
- return (_a2 = this._serviceContext.spaceInvitations) != null ? _a2 : (0, import_debug7.raise)(new Error("SpaceInvitations not initialized"));
4100
- }, () => {
4101
- var _a2;
4102
- return (_a2 = this._serviceContext.dataSpaceManager) != null ? _a2 : (0, import_debug7.raise)(new Error("SpaceManager not initialized"));
4103
- }),
4104
3989
  SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, this._serviceContext.dataServiceSubscriptions, async () => {
4105
3990
  await this._serviceContext.initialized.wait();
4106
3991
  return this._serviceContext.dataSpaceManager;
@@ -4124,7 +4009,7 @@ var ClientServicesHost = class {
4124
4009
  deviceKey
4125
4010
  }, {
4126
4011
  file: "service-host.ts",
4127
- line: 229,
4012
+ line: 221,
4128
4013
  scope: this,
4129
4014
  callSite: (f, a) => f(...a)
4130
4015
  });
@@ -4139,7 +4024,7 @@ var ClientServicesHost = class {
4139
4024
  deviceKey
4140
4025
  }, {
4141
4026
  file: "service-host.ts",
4142
- line: 238,
4027
+ line: 230,
4143
4028
  scope: this,
4144
4029
  callSite: (f, a) => f(...a)
4145
4030
  });
@@ -4153,7 +4038,7 @@ var ClientServicesHost = class {
4153
4038
  deviceKey
4154
4039
  }, {
4155
4040
  file: "service-host.ts",
4156
- line: 243,
4041
+ line: 235,
4157
4042
  scope: this,
4158
4043
  callSite: (f, a) => f(...a)
4159
4044
  });
@@ -4161,7 +4046,7 @@ var ClientServicesHost = class {
4161
4046
  id: this._instanceId
4162
4047
  }), {
4163
4048
  file: "service-host.ts",
4164
- line: 245,
4049
+ line: 237,
4165
4050
  scope: this,
4166
4051
  callSite: (f, a) => f(...a)
4167
4052
  });
@@ -4194,7 +4079,7 @@ var LocalClientServices = class {
4194
4079
  var import_config2 = require("@dxos/config");
4195
4080
  var import_log17 = require("@dxos/log");
4196
4081
  var import_messaging3 = require("@dxos/messaging");
4197
- var import_network_manager6 = require("@dxos/network-manager");
4082
+ var import_network_manager5 = require("@dxos/network-manager");
4198
4083
  var fromHost = (config = new import_config2.Config()) => {
4199
4084
  return new LocalClientServices({
4200
4085
  config,
@@ -4206,10 +4091,10 @@ var createNetworkManager = (config, options = {}) => {
4206
4091
  if (signalServer) {
4207
4092
  const { log: log1 = true, signalManager = new import_messaging3.WebsocketSignalManager([
4208
4093
  signalServer
4209
- ]), transportFactory = (0, import_network_manager6.createWebRTCTransportFactory)({
4094
+ ]), transportFactory = (0, import_network_manager5.createWebRTCTransportFactory)({
4210
4095
  iceServers: config.get("runtime.services.ice")
4211
4096
  }) } = options;
4212
- return new import_network_manager6.NetworkManager({
4097
+ return new import_network_manager5.NetworkManager({
4213
4098
  log: log1,
4214
4099
  signalManager,
4215
4100
  transportFactory
@@ -4221,17 +4106,15 @@ var createNetworkManager = (config, options = {}) => {
4221
4106
  scope: void 0,
4222
4107
  callSite: (f, a) => f(...a)
4223
4108
  });
4224
- return new import_network_manager6.NetworkManager({
4109
+ return new import_network_manager5.NetworkManager({
4225
4110
  signalManager: new import_messaging3.MemorySignalManager(new import_messaging3.MemorySignalManagerContext()),
4226
- transportFactory: import_network_manager6.MemoryTransportFactory
4111
+ transportFactory: import_network_manager5.MemoryTransportFactory
4227
4112
  });
4228
4113
  };
4229
4114
  // Annotate the CommonJS export names for ESM import in node:
4230
4115
  0 && (module.exports = {
4231
- AbstractInvitationsService,
4232
4116
  ClientServicesHost,
4233
- DeviceInvitationsHandler,
4234
- DeviceInvitationsServiceImpl,
4117
+ DeviceInvitationProtocol,
4235
4118
  DevtoolsHostEvents,
4236
4119
  DevtoolsServiceImpl,
4237
4120
  IFrameHostRuntime,
@@ -4239,13 +4122,14 @@ var createNetworkManager = (config, options = {}) => {
4239
4122
  Identity,
4240
4123
  IdentityManager,
4241
4124
  IdentityServiceImpl,
4125
+ InvitationsHandler,
4126
+ InvitationsServiceImpl,
4242
4127
  LocalClientServices,
4243
4128
  MemoryShellRuntime,
4244
4129
  ServiceContext,
4245
4130
  ServiceRegistry,
4246
4131
  ShellRuntimeImpl,
4247
- SpaceInvitationsHandler,
4248
- SpaceInvitationsServiceImpl,
4132
+ SpaceInvitationProtocol,
4249
4133
  TrustedKeySetAuthVerifier,
4250
4134
  VaultResourceLock,
4251
4135
  WorkerRuntime,