@dxos/client-services 0.1.28 → 0.1.29-next.1bc50d4

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 (150) hide show
  1. package/dist/lib/browser/{chunk-OTSGRZZI.mjs → chunk-ILMYW75X.mjs} +740 -1043
  2. package/dist/lib/browser/chunk-ILMYW75X.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +7 -41
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/packlets/testing/index.mjs +163 -50
  6. package/dist/lib/browser/packlets/testing/index.mjs.map +4 -4
  7. package/dist/lib/node/index.cjs +645 -969
  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 +2686 -2637
  11. package/dist/lib/node/packlets/testing/index.cjs.map +4 -4
  12. package/dist/types/src/packlets/devices/devices-service.test.d.ts +2 -0
  13. package/dist/types/src/packlets/devices/devices-service.test.d.ts.map +1 -0
  14. package/dist/types/src/packlets/identity/identity-service.test.d.ts +2 -0
  15. package/dist/types/src/packlets/identity/identity-service.test.d.ts.map +1 -0
  16. package/dist/types/src/packlets/invitations/device-invitations-handler.d.ts +1 -2
  17. package/dist/types/src/packlets/invitations/device-invitations-handler.d.ts.map +1 -1
  18. package/dist/types/src/packlets/invitations/device-invitations-service.d.ts +1 -1
  19. package/dist/types/src/packlets/invitations/device-invitations-service.d.ts.map +1 -1
  20. package/dist/types/src/packlets/invitations/index.d.ts +0 -6
  21. package/dist/types/src/packlets/invitations/index.d.ts.map +1 -1
  22. package/dist/types/src/packlets/invitations/invitations-service.d.ts +2 -3
  23. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  24. package/dist/types/src/packlets/invitations/space-invitations-handler.d.ts +2 -4
  25. package/dist/types/src/packlets/invitations/space-invitations-handler.d.ts.map +1 -1
  26. package/dist/types/src/packlets/invitations/space-invitations-service.d.ts +2 -3
  27. package/dist/types/src/packlets/invitations/space-invitations-service.d.ts.map +1 -1
  28. package/dist/types/src/packlets/network/network-service.test.d.ts +2 -0
  29. package/dist/types/src/packlets/network/network-service.test.d.ts.map +1 -0
  30. package/dist/types/src/packlets/services/index.d.ts +2 -2
  31. package/dist/types/src/packlets/services/index.d.ts.map +1 -1
  32. package/dist/types/src/packlets/services/local-client-services.d.ts +15 -0
  33. package/dist/types/src/packlets/services/local-client-services.d.ts.map +1 -0
  34. package/dist/types/src/packlets/services/service-context.d.ts +1 -1
  35. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  36. package/dist/types/src/packlets/services/service-host.d.ts +3 -5
  37. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  38. package/dist/types/src/packlets/services/utils.d.ts +7 -0
  39. package/dist/types/src/packlets/services/utils.d.ts.map +1 -0
  40. package/dist/types/src/packlets/spaces/index.d.ts +2 -0
  41. package/dist/types/src/packlets/spaces/index.d.ts.map +1 -1
  42. package/dist/types/src/packlets/spaces/spaces-service.test.d.ts +2 -0
  43. package/dist/types/src/packlets/spaces/spaces-service.test.d.ts.map +1 -0
  44. package/dist/types/src/packlets/testing/host-test-builder.d.ts +43 -0
  45. package/dist/types/src/packlets/testing/host-test-builder.d.ts.map +1 -0
  46. package/dist/types/src/packlets/testing/index.d.ts +1 -0
  47. package/dist/types/src/packlets/testing/index.d.ts.map +1 -1
  48. package/dist/types/src/packlets/testing/invitation-utils.d.ts +1 -1
  49. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  50. package/dist/types/src/packlets/testing/test-builder.d.ts +30 -34
  51. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  52. package/dist/types/src/packlets/tests/client-services.test.d.ts +2 -0
  53. package/dist/types/src/packlets/tests/client-services.test.d.ts.map +1 -0
  54. package/dist/types/src/packlets/tests/client.test.d.ts +2 -0
  55. package/dist/types/src/packlets/tests/client.test.d.ts.map +1 -0
  56. package/dist/types/src/packlets/tests/halo-credentials.test.d.ts +2 -0
  57. package/dist/types/src/packlets/tests/halo-credentials.test.d.ts.map +1 -0
  58. package/dist/types/src/packlets/tests/halo-persistent.test.d.ts +2 -0
  59. package/dist/types/src/packlets/tests/halo-persistent.test.d.ts.map +1 -0
  60. package/dist/types/src/packlets/tests/halo-profile.test.d.ts +2 -0
  61. package/dist/types/src/packlets/tests/halo-profile.test.d.ts.map +1 -0
  62. package/dist/types/src/packlets/tests/shared-worker.test.d.ts +2 -0
  63. package/dist/types/src/packlets/tests/shared-worker.test.d.ts.map +1 -0
  64. package/dist/types/src/packlets/tests/spaces-invitations.test.d.ts +2 -0
  65. package/dist/types/src/packlets/tests/spaces-invitations.test.d.ts.map +1 -0
  66. package/dist/types/src/packlets/tests/spaces.test.d.ts +2 -0
  67. package/dist/types/src/packlets/tests/spaces.test.d.ts.map +1 -0
  68. package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts +2 -2
  69. package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts.map +1 -1
  70. package/dist/types/src/packlets/vault/iframe-proxy-runtime.d.ts.map +1 -1
  71. package/dist/types/src/packlets/vault/index.d.ts +0 -2
  72. package/dist/types/src/packlets/vault/index.d.ts.map +1 -1
  73. package/dist/types/src/packlets/vault/shell-runtime.d.ts.map +1 -1
  74. package/dist/types/src/packlets/vault/worker-session.d.ts +1 -1
  75. package/dist/types/src/packlets/vault/worker-session.d.ts.map +1 -1
  76. package/package.json +30 -30
  77. package/src/packlets/devices/devices-service.test.ts +56 -0
  78. package/src/packlets/identity/identity-service.test.ts +82 -0
  79. package/src/packlets/invitations/device-invitations-handler.ts +10 -9
  80. package/src/packlets/invitations/device-invitations-service.test.ts +1 -1
  81. package/src/packlets/invitations/device-invitations-service.ts +1 -1
  82. package/src/packlets/invitations/index.ts +0 -6
  83. package/src/packlets/invitations/invitations-service.ts +7 -2
  84. package/src/packlets/invitations/space-invitations-handler.test.ts +3 -3
  85. package/src/packlets/invitations/space-invitations-handler.ts +11 -11
  86. package/src/packlets/invitations/space-invitations-service.test.ts +1 -1
  87. package/src/packlets/invitations/space-invitations-service.ts +2 -3
  88. package/src/packlets/network/network-service.test.ts +52 -0
  89. package/src/packlets/services/index.ts +2 -2
  90. package/src/packlets/services/local-client-services.ts +35 -0
  91. package/src/packlets/services/service-context.test.ts +4 -4
  92. package/src/packlets/services/service-context.ts +1 -1
  93. package/src/packlets/services/service-host.ts +3 -11
  94. package/src/packlets/services/service-registry.test.ts +2 -2
  95. package/src/packlets/services/utils.ts +53 -0
  96. package/src/packlets/spaces/data-space-manager.test.ts +4 -4
  97. package/src/packlets/spaces/data-space-manager.ts +1 -1
  98. package/src/packlets/spaces/index.ts +2 -0
  99. package/src/packlets/spaces/spaces-service.test.ts +107 -0
  100. package/src/packlets/testing/host-test-builder.ts +163 -0
  101. package/src/packlets/testing/index.ts +1 -0
  102. package/src/packlets/testing/invitation-utils.ts +1 -2
  103. package/src/packlets/testing/test-builder.ts +118 -140
  104. package/src/packlets/tests/client-services.test.ts +252 -0
  105. package/src/packlets/tests/client.test.ts +143 -0
  106. package/src/packlets/tests/halo-credentials.test.ts +94 -0
  107. package/src/packlets/tests/halo-persistent.test.ts +53 -0
  108. package/src/packlets/tests/halo-profile.test.ts +74 -0
  109. package/src/packlets/tests/shared-worker.test.ts +96 -0
  110. package/src/packlets/tests/spaces-invitations.test.ts +24 -0
  111. package/src/packlets/tests/spaces.test.ts +68 -0
  112. package/src/packlets/vault/iframe-host-runtime.ts +6 -3
  113. package/src/packlets/vault/iframe-proxy-runtime.ts +1 -1
  114. package/src/packlets/vault/index.ts +0 -2
  115. package/src/packlets/vault/shell-runtime.ts +1 -2
  116. package/src/packlets/vault/worker-session.ts +7 -3
  117. package/dist/lib/browser/chunk-OTSGRZZI.mjs.map +0 -7
  118. package/dist/types/src/packlets/invitations/device-invitations-proxy.d.ts +0 -8
  119. package/dist/types/src/packlets/invitations/device-invitations-proxy.d.ts.map +0 -1
  120. package/dist/types/src/packlets/invitations/encoder.d.ts +0 -9
  121. package/dist/types/src/packlets/invitations/encoder.d.ts.map +0 -1
  122. package/dist/types/src/packlets/invitations/encoder.test.d.ts +0 -2
  123. package/dist/types/src/packlets/invitations/encoder.test.d.ts.map +0 -1
  124. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +0 -56
  125. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +0 -1
  126. package/dist/types/src/packlets/invitations/invitations-proxy.d.ts +0 -18
  127. package/dist/types/src/packlets/invitations/invitations-proxy.d.ts.map +0 -1
  128. package/dist/types/src/packlets/invitations/invitations.d.ts +0 -55
  129. package/dist/types/src/packlets/invitations/invitations.d.ts.map +0 -1
  130. package/dist/types/src/packlets/invitations/space-invitations-proxy.d.ts +0 -11
  131. package/dist/types/src/packlets/invitations/space-invitations-proxy.d.ts.map +0 -1
  132. package/dist/types/src/packlets/services/service-definitions.d.ts +0 -30
  133. package/dist/types/src/packlets/services/service-definitions.d.ts.map +0 -1
  134. package/dist/types/src/packlets/services/service-proxy.d.ts +0 -17
  135. package/dist/types/src/packlets/services/service-proxy.d.ts.map +0 -1
  136. package/dist/types/src/packlets/vault/services.d.ts +0 -21
  137. package/dist/types/src/packlets/vault/services.d.ts.map +0 -1
  138. package/dist/types/src/packlets/vault/shell-controller.d.ts +0 -18
  139. package/dist/types/src/packlets/vault/shell-controller.d.ts.map +0 -1
  140. package/src/packlets/invitations/device-invitations-proxy.ts +0 -14
  141. package/src/packlets/invitations/encoder.test.ts +0 -23
  142. package/src/packlets/invitations/encoder.ts +0 -26
  143. package/src/packlets/invitations/invitations-handler.ts +0 -68
  144. package/src/packlets/invitations/invitations-proxy.ts +0 -159
  145. package/src/packlets/invitations/invitations.ts +0 -113
  146. package/src/packlets/invitations/space-invitations-proxy.ts +0 -16
  147. package/src/packlets/services/service-definitions.ts +0 -68
  148. package/src/packlets/services/service-proxy.ts +0 -54
  149. package/src/packlets/vault/services.ts +0 -42
  150. package/src/packlets/vault/shell-controller.ts +0 -56
@@ -30,56 +30,39 @@ 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
- AUTHENTICATION_CODE_LENGTH: () => AUTHENTICATION_CODE_LENGTH,
34
- AbstractInvitationsHandler: () => AbstractInvitationsHandler,
35
- AbstractInvitationsProxy: () => AbstractInvitationsProxy,
36
33
  AbstractInvitationsService: () => AbstractInvitationsService,
37
- AuthenticatingInvitationProvider: () => AuthenticatingInvitationProvider,
38
34
  ClientServicesHost: () => ClientServicesHost,
39
- ClientServicesProxy: () => ClientServicesProxy,
40
35
  DeviceInvitationsHandler: () => DeviceInvitationsHandler,
41
- DeviceInvitationsProxy: () => DeviceInvitationsProxy,
42
36
  DeviceInvitationsServiceImpl: () => DeviceInvitationsServiceImpl,
43
37
  DevtoolsHostEvents: () => DevtoolsHostEvents,
44
38
  DevtoolsServiceImpl: () => DevtoolsServiceImpl,
45
39
  IFrameHostRuntime: () => IFrameHostRuntime,
46
40
  IFrameProxyRuntime: () => IFrameProxyRuntime,
47
- INVITATION_TIMEOUT: () => INVITATION_TIMEOUT,
48
41
  Identity: () => Identity,
49
42
  IdentityManager: () => IdentityManager,
50
43
  IdentityServiceImpl: () => IdentityServiceImpl,
51
- InvitationEncoder: () => InvitationEncoder,
52
- InvitationObservableProvider: () => InvitationObservableProvider,
44
+ LocalClientServices: () => LocalClientServices,
53
45
  MemoryShellRuntime: () => MemoryShellRuntime,
54
- ON_CLOSE_DELAY: () => ON_CLOSE_DELAY,
55
46
  ServiceContext: () => ServiceContext,
56
47
  ServiceRegistry: () => ServiceRegistry,
57
- ShellController: () => ShellController,
58
48
  ShellRuntimeImpl: () => ShellRuntimeImpl,
59
49
  SpaceInvitationsHandler: () => SpaceInvitationsHandler,
60
- SpaceInvitationsProxy: () => SpaceInvitationsProxy,
61
50
  SpaceInvitationsServiceImpl: () => SpaceInvitationsServiceImpl,
62
51
  TrustedKeySetAuthVerifier: () => TrustedKeySetAuthVerifier,
63
52
  VaultResourceLock: () => VaultResourceLock,
64
53
  WorkerRuntime: () => WorkerRuntime,
65
54
  WorkerSession: () => WorkerSession,
66
- appServiceBundle: () => appServiceBundle,
67
- clientServiceBundle: () => clientServiceBundle,
68
55
  createAuthProvider: () => createAuthProvider,
69
- createDefaultModelFactory: () => createDefaultModelFactory,
70
56
  createStorageObjects: () => createStorageObjects,
57
+ fromHost: () => fromHost,
71
58
  getNetworkPeers: () => getNetworkPeers,
72
- iframeServiceBundle: () => iframeServiceBundle,
73
- shellServiceBundle: () => shellServiceBundle,
74
59
  subscribeToFeedBlocks: () => subscribeToFeedBlocks,
75
60
  subscribeToFeeds: () => subscribeToFeeds,
76
61
  subscribeToNetworkStatus: () => subscribeToNetworkStatus,
77
62
  subscribeToNetworkTopics: () => subscribeToNetworkTopics,
78
63
  subscribeToSignal: () => subscribeToSignal,
79
64
  subscribeToSpaces: () => subscribeToSpaces,
80
- subscribeToSwarmInfo: () => subscribeToSwarmInfo,
81
- workerServiceBundle: () => workerServiceBundle,
82
- wrapObservable: () => wrapObservable
65
+ subscribeToSwarmInfo: () => subscribeToSwarmInfo
83
66
  });
84
67
  module.exports = __toCommonJS(src_exports);
85
68
 
@@ -887,84 +870,20 @@ var IdentityServiceImpl = class {
887
870
  }
888
871
  };
889
872
 
890
- // packages/sdk/client-services/src/packlets/invitations/encoder.ts
891
- var import_base_x = __toESM(require("base-x"));
892
- var import_protocols2 = require("@dxos/protocols");
893
- var base62 = (0, import_base_x.default)("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
894
- var codec = import_protocols2.schema.getCodecForType("dxos.client.services.Invitation");
895
- var InvitationEncoder = class {
896
- static decode(text) {
897
- return codec.decode(base62.decode(text));
898
- }
899
- static encode(invitation) {
900
- return base62.encode(codec.encode(invitation));
901
- }
902
- };
903
-
904
873
  // packages/sdk/client-services/src/packlets/invitations/device-invitations-handler.ts
905
- var import_node_assert5 = __toESM(require("node:assert"));
906
- var import_async7 = require("@dxos/async");
874
+ var import_node_assert4 = __toESM(require("node:assert"));
875
+ var import_async6 = require("@dxos/async");
876
+ var import_client = require("@dxos/client");
907
877
  var import_context3 = require("@dxos/context");
908
878
  var import_credentials7 = require("@dxos/credentials");
909
879
  var import_keys4 = require("@dxos/keys");
910
880
  var import_log4 = require("@dxos/log");
911
881
  var import_network_manager = require("@dxos/network-manager");
912
- var import_protocols3 = require("@dxos/protocols");
913
- var import_services2 = require("@dxos/protocols/proto/dxos/client/services");
882
+ var import_protocols2 = require("@dxos/protocols");
883
+ var import_services = require("@dxos/protocols/proto/dxos/client/services");
914
884
  var import_invitations = require("@dxos/protocols/proto/dxos/halo/invitations");
915
885
  var import_teleport = require("@dxos/teleport");
916
-
917
- // packages/sdk/client-services/src/packlets/invitations/invitations.ts
918
- var import_node_assert4 = __toESM(require("node:assert"));
919
- var import_async6 = require("@dxos/async");
920
- var import_services = require("@dxos/protocols/proto/dxos/client/services");
921
- var AUTHENTICATION_CODE_LENGTH = 6;
922
- var INVITATION_TIMEOUT = 3 * 6e4;
923
- var ON_CLOSE_DELAY = 1e3;
924
- var InvitationObservableProvider = class extends import_async6.CancellableObservableProvider {
925
- get invitation() {
926
- return this._invitation;
927
- }
928
- setInvitation(invitation) {
929
- this._invitation = invitation;
930
- }
931
- };
932
- var AuthenticatingInvitationProvider = class extends InvitationObservableProvider {
933
- // prettier-ignore
934
- constructor(_actions) {
935
- super(() => this._actions.onCancel());
936
- this._actions = _actions;
937
- }
938
- async authenticate(authenticationCode) {
939
- return this._actions.onAuthenticate(authenticationCode);
940
- }
941
- };
942
- var wrapObservable = async (observable) => {
943
- return new Promise((resolve, reject) => {
944
- const unsubscribe = observable.subscribe({
945
- onSuccess: (invitation) => {
946
- (0, import_node_assert4.default)(invitation.state === import_services.Invitation.State.SUCCESS);
947
- unsubscribe();
948
- resolve(invitation);
949
- },
950
- onError: (err) => {
951
- unsubscribe();
952
- reject(err);
953
- }
954
- });
955
- });
956
- };
957
-
958
- // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
959
- var AbstractInvitationsHandler = class {
960
- // prettier-ignore
961
- constructor(_networkManager) {
962
- this._networkManager = _networkManager;
963
- }
964
- };
965
-
966
- // packages/sdk/client-services/src/packlets/invitations/device-invitations-handler.ts
967
- var DeviceInvitationsHandler = class extends AbstractInvitationsHandler {
886
+ var DeviceInvitationsHandler = class extends import_client.AbstractInvitationsHandler {
968
887
  // prettier-ignore
969
888
  constructor(_params) {
970
889
  super(_params.networkManager);
@@ -974,14 +893,14 @@ var DeviceInvitationsHandler = class extends AbstractInvitationsHandler {
974
893
  * Creates an invitation and listens for a join request from the invited (guest) peer.
975
894
  */
976
895
  createInvitation(context, options) {
977
- const { type, timeout = INVITATION_TIMEOUT, swarmKey } = options != null ? options : {};
978
- (0, import_node_assert5.default)(type !== import_services2.Invitation.Type.OFFLINE);
896
+ const { type, timeout = import_client.INVITATION_TIMEOUT, swarmKey } = options != null ? options : {};
897
+ (0, import_node_assert4.default)(type !== import_services.Invitation.Type.OFFLINE);
979
898
  const identity = this._params.getIdentity();
980
899
  const invitation = {
981
900
  type,
982
901
  invitationId: import_keys4.PublicKey.random().toHex(),
983
902
  swarmKey: swarmKey != null ? swarmKey : import_keys4.PublicKey.random(),
984
- authenticationCode: (0, import_credentials7.generatePasscode)(AUTHENTICATION_CODE_LENGTH)
903
+ authenticationCode: (0, import_credentials7.generatePasscode)(import_client.AUTHENTICATION_CODE_LENGTH)
985
904
  };
986
905
  const ctx = new import_context3.Context({
987
906
  onError: (err) => {
@@ -989,11 +908,11 @@ var DeviceInvitationsHandler = class extends AbstractInvitationsHandler {
989
908
  observable.callback.onError(err);
990
909
  }
991
910
  });
992
- const observable = new InvitationObservableProvider(async () => {
911
+ const observable = new import_client.InvitationObservableProvider(async () => {
993
912
  await ctx.dispose();
994
913
  });
995
914
  let authenticationCode;
996
- const complete = new import_async7.Trigger();
915
+ const complete = new import_async6.Trigger();
997
916
  const createExtension = () => new HostHaloInvitationExtension({
998
917
  requestAdmission: async () => {
999
918
  var _a, _b;
@@ -1001,7 +920,7 @@ var DeviceInvitationsHandler = class extends AbstractInvitationsHandler {
1001
920
  host: identity.deviceKey
1002
921
  }, {
1003
922
  file: "device-invitations-handler.ts",
1004
- line: 91,
923
+ line: 92,
1005
924
  scope: this,
1006
925
  callSite: (f, a) => f(...a)
1007
926
  });
@@ -1017,7 +936,7 @@ var DeviceInvitationsHandler = class extends AbstractInvitationsHandler {
1017
936
  authenticationCode: code
1018
937
  }, {
1019
938
  file: "device-invitations-handler.ts",
1020
- line: 105,
939
+ line: 106,
1021
940
  scope: this,
1022
941
  callSite: (f, a) => f(...a)
1023
942
  });
@@ -1029,7 +948,7 @@ var DeviceInvitationsHandler = class extends AbstractInvitationsHandler {
1029
948
  // TODO(burdon): Not used: controlFeedKey, dataFeedKey.
1030
949
  presentAdmissionCredentials: async (credentials) => {
1031
950
  try {
1032
- if (invitation.type !== import_services2.Invitation.Type.INTERACTIVE_TESTING) {
951
+ if (invitation.type !== import_services.Invitation.Type.INTERACTIVE_TESTING) {
1033
952
  if (invitation.authenticationCode === void 0 || invitation.authenticationCode !== authenticationCode) {
1034
953
  throw new Error(`invalid authentication code: ${authenticationCode}`);
1035
954
  }
@@ -1039,7 +958,7 @@ var DeviceInvitationsHandler = class extends AbstractInvitationsHandler {
1039
958
  guest: credentials.deviceKey
1040
959
  }, {
1041
960
  file: "device-invitations-handler.ts",
1042
- line: 120,
961
+ line: 121,
1043
962
  scope: this,
1044
963
  callSite: (f, a) => f(...a)
1045
964
  });
@@ -1051,14 +970,14 @@ var DeviceInvitationsHandler = class extends AbstractInvitationsHandler {
1051
970
  }
1052
971
  },
1053
972
  onOpen: () => {
1054
- (0, import_async7.scheduleTask)(ctx, async () => {
973
+ (0, import_async6.scheduleTask)(ctx, async () => {
1055
974
  var _a, _b;
1056
975
  try {
1057
976
  (0, import_log4.log)("connected", {
1058
977
  host: identity.deviceKey
1059
978
  }, {
1060
979
  file: "device-invitations-handler.ts",
1061
- line: 136,
980
+ line: 137,
1062
981
  scope: this,
1063
982
  callSite: (f, a) => f(...a)
1064
983
  });
@@ -1071,7 +990,7 @@ var DeviceInvitationsHandler = class extends AbstractInvitationsHandler {
1071
990
  guest: deviceKey
1072
991
  }, {
1073
992
  file: "device-invitations-handler.ts",
1074
- line: 139,
993
+ line: 140,
1075
994
  scope: this,
1076
995
  callSite: (f, a) => f(...a)
1077
996
  });
@@ -1080,20 +999,20 @@ var DeviceInvitationsHandler = class extends AbstractInvitationsHandler {
1080
999
  if (!observable.cancelled) {
1081
1000
  import_log4.log.error("failed", err, {
1082
1001
  file: "device-invitations-handler.ts",
1083
- line: 143,
1002
+ line: 144,
1084
1003
  scope: this,
1085
1004
  callSite: (f, a) => f(...a)
1086
1005
  });
1087
1006
  observable.callback.onError(err);
1088
1007
  }
1089
1008
  } finally {
1090
- await (0, import_async7.sleep)(ON_CLOSE_DELAY);
1009
+ await (0, import_async6.sleep)(import_client.ON_CLOSE_DELAY);
1091
1010
  await ctx.dispose();
1092
1011
  }
1093
1012
  });
1094
1013
  }
1095
1014
  });
1096
- (0, import_async7.scheduleTask)(ctx, async () => {
1015
+ (0, import_async6.scheduleTask)(ctx, async () => {
1097
1016
  var _a, _b;
1098
1017
  const topic = invitation.swarmKey;
1099
1018
  const swarmConnection = await this._networkManager.joinSwarm({
@@ -1115,15 +1034,15 @@ var DeviceInvitationsHandler = class extends AbstractInvitationsHandler {
1115
1034
  * which then writes the guest's credentials to the halo.
1116
1035
  */
1117
1036
  acceptInvitation(invitation, options) {
1118
- const { timeout = INVITATION_TIMEOUT } = options != null ? options : {};
1037
+ const { timeout = import_client.INVITATION_TIMEOUT } = options != null ? options : {};
1119
1038
  const ctx = new import_context3.Context({
1120
1039
  onError: (err) => {
1121
1040
  void ctx.dispose();
1122
1041
  observable.callback.onError(err);
1123
1042
  }
1124
1043
  });
1125
- const authenticated = new import_async7.Trigger();
1126
- const observable = new AuthenticatingInvitationProvider({
1044
+ const authenticated = new import_async6.Trigger();
1045
+ const observable = new import_client.AuthenticatingInvitationProvider({
1127
1046
  onCancel: async () => {
1128
1047
  await ctx.dispose();
1129
1048
  },
@@ -1133,11 +1052,11 @@ var DeviceInvitationsHandler = class extends AbstractInvitationsHandler {
1133
1052
  }
1134
1053
  });
1135
1054
  let connectionCount = 0;
1136
- const complete = new import_async7.Trigger();
1055
+ const complete = new import_async6.Trigger();
1137
1056
  const createExtension = () => {
1138
1057
  const extension = new GuestHaloInvitationExtension({
1139
1058
  onOpen: () => {
1140
- (0, import_async7.scheduleTask)(ctx, async () => {
1059
+ (0, import_async6.scheduleTask)(ctx, async () => {
1141
1060
  var _a, _b, _c, _d;
1142
1061
  try {
1143
1062
  if (++connectionCount > 1) {
@@ -1145,22 +1064,22 @@ var DeviceInvitationsHandler = class extends AbstractInvitationsHandler {
1145
1064
  }
1146
1065
  (0, import_log4.log)("connected", {}, {
1147
1066
  file: "device-invitations-handler.ts",
1148
- line: 214,
1067
+ line: 215,
1149
1068
  scope: this,
1150
1069
  callSite: (f, a) => f(...a)
1151
1070
  });
1152
1071
  (_b = (_a = observable.callback).onConnected) == null ? void 0 : _b.call(_a, invitation);
1153
1072
  (0, import_log4.log)("sending admission request", {}, {
1154
1073
  file: "device-invitations-handler.ts",
1155
- line: 218,
1074
+ line: 219,
1156
1075
  scope: this,
1157
1076
  callSite: (f, a) => f(...a)
1158
1077
  });
1159
1078
  const { identityKey, haloSpaceKey, genesisFeedKey } = await extension.rpc.HaloHostService.requestAdmission();
1160
- if (invitation.type === void 0 || invitation.type === import_services2.Invitation.Type.INTERACTIVE) {
1079
+ if (invitation.type === void 0 || invitation.type === import_services.Invitation.Type.INTERACTIVE) {
1161
1080
  (0, import_log4.log)("guest waiting for authentication code...", {}, {
1162
1081
  file: "device-invitations-handler.ts",
1163
- line: 225,
1082
+ line: 226,
1164
1083
  scope: this,
1165
1084
  callSite: (f, a) => f(...a)
1166
1085
  });
@@ -1170,7 +1089,7 @@ var DeviceInvitationsHandler = class extends AbstractInvitationsHandler {
1170
1089
  });
1171
1090
  (0, import_log4.log)("sending authentication request", {}, {
1172
1091
  file: "device-invitations-handler.ts",
1173
- line: 228,
1092
+ line: 229,
1174
1093
  scope: this,
1175
1094
  callSite: (f, a) => f(...a)
1176
1095
  });
@@ -1188,7 +1107,7 @@ var DeviceInvitationsHandler = class extends AbstractInvitationsHandler {
1188
1107
  dataFeedKey
1189
1108
  }, {
1190
1109
  file: "device-invitations-handler.ts",
1191
- line: 237,
1110
+ line: 238,
1192
1111
  scope: this,
1193
1112
  callSite: (f, a) => f(...a)
1194
1113
  });
@@ -1210,7 +1129,7 @@ var DeviceInvitationsHandler = class extends AbstractInvitationsHandler {
1210
1129
  identityKey
1211
1130
  }, {
1212
1131
  file: "device-invitations-handler.ts",
1213
- line: 256,
1132
+ line: 257,
1214
1133
  scope: this,
1215
1134
  callSite: (f, a) => f(...a)
1216
1135
  });
@@ -1219,7 +1138,7 @@ var DeviceInvitationsHandler = class extends AbstractInvitationsHandler {
1219
1138
  if (!observable.cancelled) {
1220
1139
  import_log4.log.warn("auth failed", err, {
1221
1140
  file: "device-invitations-handler.ts",
1222
- line: 260,
1141
+ line: 261,
1223
1142
  scope: this,
1224
1143
  callSite: (f, a) => f(...a)
1225
1144
  });
@@ -1233,9 +1152,9 @@ var DeviceInvitationsHandler = class extends AbstractInvitationsHandler {
1233
1152
  });
1234
1153
  return extension;
1235
1154
  };
1236
- (0, import_async7.scheduleTask)(ctx, async () => {
1155
+ (0, import_async6.scheduleTask)(ctx, async () => {
1237
1156
  var _a, _b;
1238
- (0, import_node_assert5.default)(invitation.swarmKey);
1157
+ (0, import_node_assert4.default)(invitation.swarmKey);
1239
1158
  const topic = invitation.swarmKey;
1240
1159
  const swarmConnection = await this._networkManager.joinSwarm({
1241
1160
  topic,
@@ -1258,7 +1177,7 @@ var HostHaloInvitationExtension = class extends import_teleport.RpcExtension {
1258
1177
  constructor(_callbacks) {
1259
1178
  super({
1260
1179
  exposed: {
1261
- HaloHostService: import_protocols3.schema.getService("dxos.halo.invitations.HaloHostService")
1180
+ HaloHostService: import_protocols2.schema.getService("dxos.halo.invitations.HaloHostService")
1262
1181
  }
1263
1182
  });
1264
1183
  this._callbacks = _callbacks;
@@ -1290,7 +1209,7 @@ var GuestHaloInvitationExtension = class extends import_teleport.RpcExtension {
1290
1209
  constructor(_callbacks) {
1291
1210
  super({
1292
1211
  requested: {
1293
- HaloHostService: import_protocols3.schema.getService("dxos.halo.invitations.HaloHostService")
1212
+ HaloHostService: import_protocols2.schema.getService("dxos.halo.invitations.HaloHostService")
1294
1213
  }
1295
1214
  });
1296
1215
  this._callbacks = _callbacks;
@@ -1304,152 +1223,11 @@ var GuestHaloInvitationExtension = class extends import_teleport.RpcExtension {
1304
1223
  }
1305
1224
  };
1306
1225
 
1307
- // packages/sdk/client-services/src/packlets/invitations/invitations-proxy.ts
1308
- var import_node_assert6 = __toESM(require("node:assert"));
1309
- var import_async8 = require("@dxos/async");
1310
- var import_log5 = require("@dxos/log");
1311
- var import_services3 = require("@dxos/protocols/proto/dxos/client/services");
1312
- var AbstractInvitationsProxy = class {
1313
- // prettier-ignore
1314
- constructor(_invitationsService) {
1315
- this._invitationsService = _invitationsService;
1316
- }
1317
- createInvitation(context, options) {
1318
- let invitationId;
1319
- const observable = new InvitationObservableProvider(async () => {
1320
- if (invitationId) {
1321
- await this._invitationsService.cancelInvitation({
1322
- invitationId
1323
- });
1324
- }
1325
- });
1326
- const invitation = {
1327
- ...this.getInvitationOptions(context),
1328
- ...options
1329
- };
1330
- const stream = this._invitationsService.createInvitation(invitation);
1331
- stream.subscribe((invitation2) => {
1332
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1333
- observable.setInvitation(invitation2);
1334
- switch (invitation2.state) {
1335
- case import_services3.Invitation.State.CONNECTING: {
1336
- (0, import_node_assert6.default)(invitation2.invitationId);
1337
- invitationId = invitation2.invitationId;
1338
- (_b = (_a = observable.callback).onConnecting) == null ? void 0 : _b.call(_a, invitation2);
1339
- break;
1340
- }
1341
- case import_services3.Invitation.State.CONNECTED: {
1342
- (_d = (_c = observable.callback).onConnected) == null ? void 0 : _d.call(_c, invitation2);
1343
- break;
1344
- }
1345
- case import_services3.Invitation.State.AUTHENTICATING: {
1346
- (_f = (_e = observable.callback).onAuthenticating) == null ? void 0 : _f.call(_e, invitation2);
1347
- break;
1348
- }
1349
- case import_services3.Invitation.State.SUCCESS: {
1350
- (_h = (_g = observable.callback).onSuccess) == null ? void 0 : _h.call(_g, invitation2);
1351
- break;
1352
- }
1353
- case import_services3.Invitation.State.CANCELLED: {
1354
- (_j = (_i = observable.callback).onCancelled) == null ? void 0 : _j.call(_i);
1355
- break;
1356
- }
1357
- default: {
1358
- import_log5.log.error(`Invalid state: ${invitation2.state}`, {}, {
1359
- file: "invitations-proxy.ts",
1360
- line: 81,
1361
- scope: this,
1362
- callSite: (f, a) => f(...a)
1363
- });
1364
- }
1365
- }
1366
- }, (err) => {
1367
- if (err) {
1368
- (0, import_async8.observableError)(observable, err);
1369
- }
1370
- });
1371
- return observable;
1372
- }
1373
- acceptInvitation(invitation, options) {
1374
- (0, import_node_assert6.default)(invitation && invitation.swarmKey);
1375
- const observable = new AuthenticatingInvitationProvider({
1376
- onCancel: async () => {
1377
- var _a;
1378
- const invitationId = (_a = observable.invitation) == null ? void 0 : _a.invitationId;
1379
- (0, import_node_assert6.default)(invitationId);
1380
- await this._invitationsService.cancelInvitation({
1381
- invitationId
1382
- });
1383
- },
1384
- onAuthenticate: async (authenticationCode) => {
1385
- var _a;
1386
- const invitationId = (_a = observable.invitation) == null ? void 0 : _a.invitationId;
1387
- (0, import_node_assert6.default)(invitationId);
1388
- await this._invitationsService.authenticate({
1389
- invitationId,
1390
- authenticationCode
1391
- });
1392
- }
1393
- });
1394
- const stream = this._invitationsService.acceptInvitation({
1395
- ...invitation,
1396
- ...options
1397
- });
1398
- stream.subscribe((invitation2) => {
1399
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1400
- (0, import_node_assert6.default)(invitation2.invitationId);
1401
- observable.setInvitation(invitation2);
1402
- switch (invitation2.state) {
1403
- case import_services3.Invitation.State.CONNECTING: {
1404
- (_b = (_a = observable.callback).onConnecting) == null ? void 0 : _b.call(_a, invitation2);
1405
- break;
1406
- }
1407
- case import_services3.Invitation.State.CONNECTED: {
1408
- (_d = (_c = observable.callback).onConnected) == null ? void 0 : _d.call(_c, invitation2);
1409
- break;
1410
- }
1411
- case import_services3.Invitation.State.AUTHENTICATING: {
1412
- (_f = (_e = observable.callback).onAuthenticating) == null ? void 0 : _f.call(_e, invitation2);
1413
- break;
1414
- }
1415
- case import_services3.Invitation.State.SUCCESS: {
1416
- (_h = (_g = observable.callback).onSuccess) == null ? void 0 : _h.call(_g, invitation2);
1417
- break;
1418
- }
1419
- case import_services3.Invitation.State.CANCELLED: {
1420
- (_j = (_i = observable.callback).onCancelled) == null ? void 0 : _j.call(_i);
1421
- break;
1422
- }
1423
- default: {
1424
- import_log5.log.error(`Invalid state: ${invitation2.state}`, {}, {
1425
- file: "invitations-proxy.ts",
1426
- line: 146,
1427
- scope: this,
1428
- callSite: (f, a) => f(...a)
1429
- });
1430
- }
1431
- }
1432
- }, (err) => {
1433
- if (err) {
1434
- (0, import_async8.observableError)(observable, err);
1435
- }
1436
- });
1437
- return observable;
1438
- }
1439
- };
1440
-
1441
- // packages/sdk/client-services/src/packlets/invitations/device-invitations-proxy.ts
1442
- var DeviceInvitationsProxy = class extends AbstractInvitationsProxy {
1443
- getInvitationOptions() {
1444
- return {};
1445
- }
1446
- };
1447
-
1448
1226
  // packages/sdk/client-services/src/packlets/invitations/invitations-service.ts
1449
- var import_node_assert7 = __toESM(require("node:assert"));
1227
+ var import_node_assert5 = __toESM(require("node:assert"));
1450
1228
  var import_codec_protobuf7 = require("@dxos/codec-protobuf");
1451
- var import_log6 = require("@dxos/log");
1452
- var import_services4 = require("@dxos/protocols/proto/dxos/client/services");
1229
+ var import_log5 = require("@dxos/log");
1230
+ var import_services2 = require("@dxos/protocols/proto/dxos/client/services");
1453
1231
  var AbstractInvitationsService = class {
1454
1232
  // prettier-ignore
1455
1233
  constructor(_identityManager, _getInvitationsHandler) {
@@ -1469,9 +1247,9 @@ var AbstractInvitationsService = class {
1469
1247
  return new import_codec_protobuf7.Stream(({ next, close }) => {
1470
1248
  const invitationsHandler = this._getInvitationsHandler();
1471
1249
  const context = this.getContext(invitation);
1472
- (0, import_log6.log)("stream opened", this.getLoggingContext(), {
1250
+ (0, import_log5.log)("stream opened", this.getLoggingContext(), {
1473
1251
  file: "invitations-service.ts",
1474
- line: 43,
1252
+ line: 48,
1475
1253
  scope: this,
1476
1254
  callSite: (f, a) => f(...a)
1477
1255
  });
@@ -1484,60 +1262,60 @@ var AbstractInvitationsService = class {
1484
1262
  });
1485
1263
  observable.subscribe({
1486
1264
  onConnecting: (invitation2) => {
1487
- (0, import_node_assert7.default)(invitation2.invitationId);
1265
+ (0, import_node_assert5.default)(invitation2.invitationId);
1488
1266
  invitationId = invitation2.invitationId;
1489
1267
  this._createInvitations.set(invitation2.invitationId, observable);
1490
- invitation2.state = import_services4.Invitation.State.CONNECTING;
1268
+ invitation2.state = import_services2.Invitation.State.CONNECTING;
1491
1269
  next(invitation2);
1492
1270
  },
1493
1271
  onConnected: (invitation2) => {
1494
- (0, import_node_assert7.default)(invitation2.invitationId);
1495
- invitation2.state = import_services4.Invitation.State.CONNECTED;
1272
+ (0, import_node_assert5.default)(invitation2.invitationId);
1273
+ invitation2.state = import_services2.Invitation.State.CONNECTED;
1496
1274
  next(invitation2);
1497
1275
  },
1498
1276
  onAuthenticating: (invitation2) => {
1499
- (0, import_node_assert7.default)(invitation2.invitationId);
1500
- invitation2.state = import_services4.Invitation.State.AUTHENTICATING;
1277
+ (0, import_node_assert5.default)(invitation2.invitationId);
1278
+ invitation2.state = import_services2.Invitation.State.AUTHENTICATING;
1501
1279
  next(invitation2);
1502
1280
  },
1503
1281
  onSuccess: (invitation2) => {
1504
- (0, import_node_assert7.default)(invitation2.invitationId);
1505
- invitation2.state = import_services4.Invitation.State.SUCCESS;
1282
+ (0, import_node_assert5.default)(invitation2.invitationId);
1283
+ invitation2.state = import_services2.Invitation.State.SUCCESS;
1506
1284
  next(invitation2);
1507
1285
  close();
1508
1286
  },
1509
1287
  onCancelled: () => {
1510
- (0, import_node_assert7.default)(invitationId);
1288
+ (0, import_node_assert5.default)(invitationId);
1511
1289
  invitation.invitationId = invitationId;
1512
- invitation.state = import_services4.Invitation.State.CANCELLED;
1290
+ invitation.state = import_services2.Invitation.State.CANCELLED;
1513
1291
  next(invitation);
1514
1292
  close();
1515
1293
  },
1516
1294
  onTimeout: (err) => {
1517
- invitation.state = import_services4.Invitation.State.TIMEOUT;
1295
+ invitation.state = import_services2.Invitation.State.TIMEOUT;
1518
1296
  close(err);
1519
1297
  },
1520
1298
  onError: (err) => {
1521
- invitation.state = import_services4.Invitation.State.ERROR;
1299
+ invitation.state = import_services2.Invitation.State.ERROR;
1522
1300
  close(err);
1523
1301
  }
1524
1302
  });
1525
1303
  return (err) => {
1526
1304
  const context2 = this.getLoggingContext();
1527
1305
  if (err) {
1528
- import_log6.log.warn("stream closed", {
1306
+ import_log5.log.warn("stream closed", {
1529
1307
  ...context2,
1530
1308
  err
1531
1309
  }, {
1532
1310
  file: "invitations-service.ts",
1533
- line: 92,
1311
+ line: 97,
1534
1312
  scope: this,
1535
1313
  callSite: (f, a) => f(...a)
1536
1314
  });
1537
1315
  } else {
1538
- (0, import_log6.log)("stream closed", context2, {
1316
+ (0, import_log5.log)("stream closed", context2, {
1539
1317
  file: "invitations-service.ts",
1540
- line: 94,
1318
+ line: 99,
1541
1319
  scope: this,
1542
1320
  callSite: (f, a) => f(...a)
1543
1321
  });
@@ -1548,9 +1326,9 @@ var AbstractInvitationsService = class {
1548
1326
  }
1549
1327
  acceptInvitation(invitation, options) {
1550
1328
  return new import_codec_protobuf7.Stream(({ next, close }) => {
1551
- (0, import_log6.log)("stream opened", this.getLoggingContext(), {
1329
+ (0, import_log5.log)("stream opened", this.getLoggingContext(), {
1552
1330
  file: "invitations-service.ts",
1553
- line: 104,
1331
+ line: 109,
1554
1332
  scope: this,
1555
1333
  callSite: (f, a) => f(...a)
1556
1334
  });
@@ -1559,59 +1337,59 @@ var AbstractInvitationsService = class {
1559
1337
  const observable = invitationsHandler.acceptInvitation(invitation, options);
1560
1338
  observable.subscribe({
1561
1339
  onConnecting: (invitation2) => {
1562
- (0, import_node_assert7.default)(invitation2.invitationId);
1340
+ (0, import_node_assert5.default)(invitation2.invitationId);
1563
1341
  invitationId = invitation2.invitationId;
1564
1342
  this._acceptInvitations.set(invitation2.invitationId, observable);
1565
- invitation2.state = import_services4.Invitation.State.CONNECTING;
1343
+ invitation2.state = import_services2.Invitation.State.CONNECTING;
1566
1344
  next(invitation2);
1567
1345
  },
1568
1346
  onConnected: (invitation2) => {
1569
- (0, import_node_assert7.default)(invitation2.invitationId);
1570
- invitation2.state = import_services4.Invitation.State.CONNECTED;
1347
+ (0, import_node_assert5.default)(invitation2.invitationId);
1348
+ invitation2.state = import_services2.Invitation.State.CONNECTED;
1571
1349
  next(invitation2);
1572
1350
  },
1573
1351
  onAuthenticating: (invitation2) => {
1574
- (0, import_node_assert7.default)(invitation2.invitationId);
1575
- invitation2.state = import_services4.Invitation.State.AUTHENTICATING;
1352
+ (0, import_node_assert5.default)(invitation2.invitationId);
1353
+ invitation2.state = import_services2.Invitation.State.AUTHENTICATING;
1576
1354
  next(invitation2);
1577
1355
  },
1578
1356
  onSuccess: (invitation2) => {
1579
- invitation2.state = import_services4.Invitation.State.SUCCESS;
1357
+ invitation2.state = import_services2.Invitation.State.SUCCESS;
1580
1358
  next(invitation2);
1581
1359
  close();
1582
1360
  },
1583
1361
  onCancelled: () => {
1584
- (0, import_node_assert7.default)(invitationId);
1362
+ (0, import_node_assert5.default)(invitationId);
1585
1363
  invitation.invitationId = invitationId;
1586
- invitation.state = import_services4.Invitation.State.CANCELLED;
1364
+ invitation.state = import_services2.Invitation.State.CANCELLED;
1587
1365
  next(invitation);
1588
1366
  close();
1589
1367
  },
1590
1368
  onTimeout: (err) => {
1591
- invitation.state = import_services4.Invitation.State.TIMEOUT;
1369
+ invitation.state = import_services2.Invitation.State.TIMEOUT;
1592
1370
  close(err);
1593
1371
  },
1594
1372
  onError: (err) => {
1595
- invitation.state = import_services4.Invitation.State.ERROR;
1373
+ invitation.state = import_services2.Invitation.State.ERROR;
1596
1374
  close(err);
1597
1375
  }
1598
1376
  });
1599
1377
  return (err) => {
1600
1378
  const context = this.getLoggingContext();
1601
1379
  if (err) {
1602
- import_log6.log.warn("stream closed", {
1380
+ import_log5.log.warn("stream closed", {
1603
1381
  ...context,
1604
1382
  err
1605
1383
  }, {
1606
1384
  file: "invitations-service.ts",
1607
- line: 152,
1385
+ line: 157,
1608
1386
  scope: this,
1609
1387
  callSite: (f, a) => f(...a)
1610
1388
  });
1611
1389
  } else {
1612
- (0, import_log6.log)("stream closed", context, {
1390
+ (0, import_log5.log)("stream closed", context, {
1613
1391
  file: "invitations-service.ts",
1614
- line: 154,
1392
+ line: 159,
1615
1393
  scope: this,
1616
1394
  callSite: (f, a) => f(...a)
1617
1395
  });
@@ -1621,20 +1399,20 @@ var AbstractInvitationsService = class {
1621
1399
  });
1622
1400
  }
1623
1401
  async authenticate({ invitationId, authenticationCode }) {
1624
- (0, import_log6.log)("authenticating...", {}, {
1402
+ (0, import_log5.log)("authenticating...", {}, {
1625
1403
  file: "invitations-service.ts",
1626
- line: 163,
1404
+ line: 168,
1627
1405
  scope: this,
1628
1406
  callSite: (f, a) => f(...a)
1629
1407
  });
1630
- (0, import_node_assert7.default)(invitationId);
1408
+ (0, import_node_assert5.default)(invitationId);
1631
1409
  const observable = this._acceptInvitations.get(invitationId);
1632
1410
  if (!observable) {
1633
- import_log6.log.warn("invalid invitation", {
1411
+ import_log5.log.warn("invalid invitation", {
1634
1412
  invitationId
1635
1413
  }, {
1636
1414
  file: "invitations-service.ts",
1637
- line: 167,
1415
+ line: 172,
1638
1416
  scope: this,
1639
1417
  callSite: (f, a) => f(...a)
1640
1418
  });
@@ -1644,20 +1422,20 @@ var AbstractInvitationsService = class {
1644
1422
  }
1645
1423
  async cancelInvitation(invitation) {
1646
1424
  var _a;
1647
- (0, import_log6.log)("cancelling...", {}, {
1425
+ (0, import_log5.log)("cancelling...", {}, {
1648
1426
  file: "invitations-service.ts",
1649
- line: 174,
1427
+ line: 179,
1650
1428
  scope: this,
1651
1429
  callSite: (f, a) => f(...a)
1652
1430
  });
1653
- (0, import_node_assert7.default)(invitation.invitationId);
1431
+ (0, import_node_assert5.default)(invitation.invitationId);
1654
1432
  const observable = (_a = this._createInvitations.get(invitation.invitationId)) != null ? _a : this._acceptInvitations.get(invitation.invitationId);
1655
1433
  if (!observable) {
1656
- import_log6.log.warn("invalid invitation", {
1434
+ import_log5.log.warn("invalid invitation", {
1657
1435
  invitationId: invitation.invitationId
1658
1436
  }, {
1659
1437
  file: "invitations-service.ts",
1660
- line: 179,
1438
+ line: 184,
1661
1439
  scope: this,
1662
1440
  callSite: (f, a) => f(...a)
1663
1441
  });
@@ -1679,20 +1457,21 @@ var DeviceInvitationsServiceImpl = class extends AbstractInvitationsService {
1679
1457
  };
1680
1458
 
1681
1459
  // packages/sdk/client-services/src/packlets/invitations/space-invitations-handler.ts
1682
- var import_node_assert8 = __toESM(require("node:assert"));
1683
- var import_async9 = require("@dxos/async");
1460
+ var import_node_assert6 = __toESM(require("node:assert"));
1461
+ var import_async7 = require("@dxos/async");
1462
+ var import_client2 = require("@dxos/client");
1684
1463
  var import_context4 = require("@dxos/context");
1685
1464
  var import_credentials8 = require("@dxos/credentials");
1686
1465
  var import_feed_store3 = require("@dxos/feed-store");
1687
1466
  var import_keys5 = require("@dxos/keys");
1688
- var import_log7 = require("@dxos/log");
1467
+ var import_log6 = require("@dxos/log");
1689
1468
  var import_network_manager2 = require("@dxos/network-manager");
1690
- var import_protocols4 = require("@dxos/protocols");
1691
- var import_services5 = require("@dxos/protocols/proto/dxos/client/services");
1692
- var import_invitations4 = require("@dxos/protocols/proto/dxos/halo/invitations");
1469
+ var import_protocols3 = require("@dxos/protocols");
1470
+ var import_services3 = require("@dxos/protocols/proto/dxos/client/services");
1471
+ var import_invitations2 = require("@dxos/protocols/proto/dxos/halo/invitations");
1693
1472
  var import_teleport2 = require("@dxos/teleport");
1694
1473
  var MAX_OTP_ATTEMPTS = 3;
1695
- var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1474
+ var SpaceInvitationsHandler = class extends import_client2.AbstractInvitationsHandler {
1696
1475
  constructor(networkManager, _spaceManager, _signingContext, _keyring) {
1697
1476
  super(networkManager);
1698
1477
  this._spaceManager = _spaceManager;
@@ -1705,16 +1484,16 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1705
1484
  createInvitation(space, options) {
1706
1485
  var _a;
1707
1486
  let swarmConnection;
1708
- const { type, timeout = INVITATION_TIMEOUT, swarmKey } = options != null ? options : {};
1709
- (0, import_node_assert8.default)(type !== import_services5.Invitation.Type.OFFLINE);
1710
- (0, import_node_assert8.default)(space);
1487
+ const { type, timeout = import_client2.INVITATION_TIMEOUT, swarmKey } = options != null ? options : {};
1488
+ (0, import_node_assert6.default)(type !== import_services3.Invitation.Type.OFFLINE);
1489
+ (0, import_node_assert6.default)(space);
1711
1490
  const invitation = {
1712
1491
  type,
1713
1492
  invitationId: import_keys5.PublicKey.random().toHex(),
1714
1493
  swarmKey: swarmKey != null ? swarmKey : import_keys5.PublicKey.random(),
1715
1494
  spaceKey: space.key,
1716
- authMethod: (_a = options == null ? void 0 : options.authMethod) != null ? _a : import_invitations4.AuthMethod.SHARED_SECRET,
1717
- authenticationCode: (0, import_credentials8.generatePasscode)(AUTHENTICATION_CODE_LENGTH)
1495
+ authMethod: (_a = options == null ? void 0 : options.authMethod) != null ? _a : import_invitations2.AuthMethod.SHARED_SECRET,
1496
+ authenticationCode: (0, import_credentials8.generatePasscode)(import_client2.AUTHENTICATION_CODE_LENGTH)
1718
1497
  // TODO(dmaretskyi): Don't generate if authMethod === NONE .
1719
1498
  };
1720
1499
  const ctx = new import_context4.Context({
@@ -1723,18 +1502,18 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1723
1502
  observable.callback.onError(err);
1724
1503
  }
1725
1504
  });
1726
- const observable = new InvitationObservableProvider(async () => {
1505
+ const observable = new import_client2.InvitationObservableProvider(async () => {
1727
1506
  await (swarmConnection == null ? void 0 : swarmConnection.close());
1728
1507
  });
1729
1508
  let authenticationPassed = false;
1730
1509
  let authenticationRetry = 0;
1731
1510
  const createExtension = () => {
1732
- const complete = new import_async9.Trigger();
1511
+ const complete = new import_async7.Trigger();
1733
1512
  let guestProfile;
1734
1513
  const hostInvitationExtension = new HostSpaceInvitationExtension({
1735
1514
  introduce: async ({ profile }) => {
1736
1515
  var _a2, _b;
1737
- (0, import_log7.log)("guest introduced itself", {
1516
+ (0, import_log6.log)("guest introduced itself", {
1738
1517
  guestProfile: profile,
1739
1518
  host: this._signingContext.deviceKey,
1740
1519
  spaceKey: space.key
@@ -1747,12 +1526,12 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1747
1526
  guestProfile = profile;
1748
1527
  (_b = (_a2 = observable.callback).onAuthenticating) == null ? void 0 : _b.call(_a2, invitation);
1749
1528
  return {
1750
- spaceKey: type === import_services5.Invitation.Type.INTERACTIVE_TESTING || type === import_services5.Invitation.Type.MULTIUSE_TESTING ? space.key : void 0,
1529
+ spaceKey: type === import_services3.Invitation.Type.INTERACTIVE_TESTING || type === import_services3.Invitation.Type.MULTIUSE_TESTING ? space.key : void 0,
1751
1530
  authMethod: invitation.authMethod
1752
1531
  };
1753
1532
  },
1754
1533
  authenticate: async ({ authenticationCode: code }) => {
1755
- (0, import_log7.log)("received authentication request", {
1534
+ (0, import_log6.log)("received authentication request", {
1756
1535
  authenticationCode: code
1757
1536
  }, {
1758
1537
  file: "space-invitations-handler.ts",
@@ -1760,25 +1539,25 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1760
1539
  scope: this,
1761
1540
  callSite: (f, a) => f(...a)
1762
1541
  });
1763
- let status = import_invitations4.AuthenticationResponse.Status.OK;
1542
+ let status = import_invitations2.AuthenticationResponse.Status.OK;
1764
1543
  switch (invitation.authMethod) {
1765
- case import_invitations4.AuthMethod.NONE: {
1766
- (0, import_log7.log)("authentication not required", {}, {
1544
+ case import_invitations2.AuthMethod.NONE: {
1545
+ (0, import_log6.log)("authentication not required", {}, {
1767
1546
  file: "space-invitations-handler.ts",
1768
1547
  line: 128,
1769
1548
  scope: this,
1770
1549
  callSite: (f, a) => f(...a)
1771
1550
  });
1772
1551
  return {
1773
- status: import_invitations4.AuthenticationResponse.Status.OK
1552
+ status: import_invitations2.AuthenticationResponse.Status.OK
1774
1553
  };
1775
1554
  }
1776
- case import_invitations4.AuthMethod.SHARED_SECRET: {
1555
+ case import_invitations2.AuthMethod.SHARED_SECRET: {
1777
1556
  if (invitation.authenticationCode) {
1778
1557
  if (authenticationRetry++ > MAX_OTP_ATTEMPTS) {
1779
- status = import_invitations4.AuthenticationResponse.Status.INVALID_OPT_ATTEMPTS;
1558
+ status = import_invitations2.AuthenticationResponse.Status.INVALID_OPT_ATTEMPTS;
1780
1559
  } else if (code !== invitation.authenticationCode) {
1781
- status = import_invitations4.AuthenticationResponse.Status.INVALID_OTP;
1560
+ status = import_invitations2.AuthenticationResponse.Status.INVALID_OTP;
1782
1561
  } else {
1783
1562
  authenticationPassed = true;
1784
1563
  }
@@ -1786,7 +1565,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1786
1565
  break;
1787
1566
  }
1788
1567
  default: {
1789
- import_log7.log.error("invalid authentication method", {
1568
+ import_log6.log.error("invalid authentication method", {
1790
1569
  authMethod: invitation.authMethod
1791
1570
  }, {
1792
1571
  file: "space-invitations-handler.ts",
@@ -1794,7 +1573,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1794
1573
  scope: this,
1795
1574
  callSite: (f, a) => f(...a)
1796
1575
  });
1797
- status = import_invitations4.AuthenticationResponse.Status.INTERNAL_ERROR;
1576
+ status = import_invitations2.AuthenticationResponse.Status.INTERNAL_ERROR;
1798
1577
  break;
1799
1578
  }
1800
1579
  }
@@ -1807,7 +1586,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1807
1586
  if (isAuthenticationRequired(invitation) && !authenticationPassed) {
1808
1587
  throw new Error("Not authenticated");
1809
1588
  }
1810
- (0, import_log7.log)("writing guest credentials", {
1589
+ (0, import_log6.log)("writing guest credentials", {
1811
1590
  host: this._signingContext.deviceKey,
1812
1591
  guest: deviceKey
1813
1592
  }, {
@@ -1817,9 +1596,9 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1817
1596
  callSite: (f, a) => f(...a)
1818
1597
  });
1819
1598
  const credentials = await (0, import_credentials8.createAdmissionCredentials)(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile);
1820
- (0, import_node_assert8.default)(credentials[0].credential);
1599
+ (0, import_node_assert6.default)(credentials[0].credential);
1821
1600
  const spaceMemberCredential = credentials[0].credential.credential;
1822
- (0, import_node_assert8.default)((0, import_credentials8.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
1601
+ (0, import_node_assert6.default)((0, import_credentials8.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
1823
1602
  await (0, import_feed_store3.writeMessages)(space.inner.controlPipeline.writer, credentials);
1824
1603
  complete.wake(deviceKey);
1825
1604
  return {
@@ -1831,10 +1610,10 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1831
1610
  }
1832
1611
  },
1833
1612
  onOpen: () => {
1834
- (0, import_async9.scheduleTask)(ctx, async () => {
1613
+ (0, import_async7.scheduleTask)(ctx, async () => {
1835
1614
  var _a2, _b;
1836
1615
  try {
1837
- (0, import_log7.log)("connected", {
1616
+ (0, import_log6.log)("connected", {
1838
1617
  host: this._signingContext.deviceKey
1839
1618
  }, {
1840
1619
  file: "space-invitations-handler.ts",
@@ -1846,7 +1625,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1846
1625
  const deviceKey = await complete.wait({
1847
1626
  timeout
1848
1627
  });
1849
- (0, import_log7.log)("admitted guest", {
1628
+ (0, import_log6.log)("admitted guest", {
1850
1629
  host: this._signingContext.deviceKey,
1851
1630
  guest: deviceKey
1852
1631
  }, {
@@ -1858,7 +1637,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1858
1637
  observable.callback.onSuccess(invitation);
1859
1638
  } catch (err) {
1860
1639
  if (!observable.cancelled) {
1861
- import_log7.log.error("failed", err, {
1640
+ import_log6.log.error("failed", err, {
1862
1641
  file: "space-invitations-handler.ts",
1863
1642
  line: 198,
1864
1643
  scope: this,
@@ -1867,8 +1646,8 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1867
1646
  observable.callback.onError(err);
1868
1647
  }
1869
1648
  } finally {
1870
- if (type !== import_services5.Invitation.Type.MULTIUSE_TESTING) {
1871
- await (0, import_async9.sleep)(ON_CLOSE_DELAY);
1649
+ if (type !== import_services3.Invitation.Type.MULTIUSE_TESTING) {
1650
+ await (0, import_async7.sleep)(import_client2.ON_CLOSE_DELAY);
1872
1651
  await ctx.dispose();
1873
1652
  }
1874
1653
  }
@@ -1877,7 +1656,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1877
1656
  });
1878
1657
  return hostInvitationExtension;
1879
1658
  };
1880
- (0, import_async9.scheduleTask)(ctx, async () => {
1659
+ (0, import_async7.scheduleTask)(ctx, async () => {
1881
1660
  var _a2, _b;
1882
1661
  const topic = invitation.swarmKey;
1883
1662
  const swarmConnection2 = await this._networkManager.joinSwarm({
@@ -1899,15 +1678,15 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1899
1678
  * which then writes the guest's credentials to the space.
1900
1679
  */
1901
1680
  acceptInvitation(invitation, options) {
1902
- const { timeout = INVITATION_TIMEOUT } = options != null ? options : {};
1681
+ const { timeout = import_client2.INVITATION_TIMEOUT } = options != null ? options : {};
1903
1682
  const ctx = new import_context4.Context({
1904
1683
  onError: (err) => {
1905
1684
  void ctx.dispose();
1906
1685
  observable.callback.onError(err);
1907
1686
  }
1908
1687
  });
1909
- const authenticated = new import_async9.Trigger();
1910
- const observable = new AuthenticatingInvitationProvider({
1688
+ const authenticated = new import_async7.Trigger();
1689
+ const observable = new import_client2.AuthenticatingInvitationProvider({
1911
1690
  onCancel: async () => {
1912
1691
  await ctx.dispose();
1913
1692
  },
@@ -1916,17 +1695,17 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1916
1695
  }
1917
1696
  });
1918
1697
  let connectionCount = 0;
1919
- const complete = new import_async9.Trigger();
1698
+ const complete = new import_async7.Trigger();
1920
1699
  const createExtension = () => {
1921
1700
  const extension = new GuestSpaceInvitationExtension({
1922
1701
  onOpen: () => {
1923
- (0, import_async9.scheduleTask)(ctx, async () => {
1702
+ (0, import_async7.scheduleTask)(ctx, async () => {
1924
1703
  var _a, _b, _c, _d, _e, _f;
1925
1704
  try {
1926
1705
  if (++connectionCount > 1) {
1927
1706
  throw new Error(`multiple connections detected: ${connectionCount}`);
1928
1707
  }
1929
- (0, import_log7.log)("connected", {
1708
+ (0, import_log6.log)("connected", {
1930
1709
  guest: this._signingContext.deviceKey
1931
1710
  }, {
1932
1711
  file: "space-invitations-handler.ts",
@@ -1935,7 +1714,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1935
1714
  callSite: (f, a) => f(...a)
1936
1715
  });
1937
1716
  (_b = (_a = observable.callback).onConnected) == null ? void 0 : _b.call(_a, invitation);
1938
- (0, import_log7.log)("introduce", {
1717
+ (0, import_log6.log)("introduce", {
1939
1718
  guest: this._signingContext.deviceKey
1940
1719
  }, {
1941
1720
  file: "space-invitations-handler.ts",
@@ -1946,7 +1725,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1946
1725
  const introductionResponse = await extension.rpc.SpaceHostService.introduce({
1947
1726
  profile: this._signingContext.profile
1948
1727
  });
1949
- (0, import_log7.log)("introduce response", {
1728
+ (0, import_log6.log)("introduce response", {
1950
1729
  guest: this._signingContext.deviceKey,
1951
1730
  response: introductionResponse
1952
1731
  }, {
@@ -1962,7 +1741,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1962
1741
  if (isAuthenticationRequired(invitation)) {
1963
1742
  (_d = (_c = observable.callback).onAuthenticating) == null ? void 0 : _d.call(_c, invitation);
1964
1743
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
1965
- (0, import_log7.log)("guest waiting for authentication code...", {}, {
1744
+ (0, import_log6.log)("guest waiting for authentication code...", {}, {
1966
1745
  file: "space-invitations-handler.ts",
1967
1746
  line: 293,
1968
1747
  scope: this,
@@ -1972,7 +1751,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1972
1751
  const authenticationCode = await authenticated.wait({
1973
1752
  timeout
1974
1753
  });
1975
- (0, import_log7.log)("sending authentication request", {}, {
1754
+ (0, import_log6.log)("sending authentication request", {}, {
1976
1755
  file: "space-invitations-handler.ts",
1977
1756
  line: 297,
1978
1757
  scope: this,
@@ -1981,14 +1760,14 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1981
1760
  const response = await extension.rpc.SpaceHostService.authenticate({
1982
1761
  authenticationCode
1983
1762
  });
1984
- if (response.status === void 0 || response.status === import_invitations4.AuthenticationResponse.Status.OK) {
1763
+ if (response.status === void 0 || response.status === import_invitations2.AuthenticationResponse.Status.OK) {
1985
1764
  break;
1986
1765
  }
1987
- if (response.status === import_invitations4.AuthenticationResponse.Status.INVALID_OTP) {
1766
+ if (response.status === import_invitations2.AuthenticationResponse.Status.INVALID_OTP) {
1988
1767
  if (attempt === MAX_OTP_ATTEMPTS) {
1989
1768
  throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
1990
1769
  } else {
1991
- (0, import_log7.log)("retrying invalid code", {
1770
+ (0, import_log6.log)("retrying invalid code", {
1992
1771
  attempt
1993
1772
  }, {
1994
1773
  file: "space-invitations-handler.ts",
@@ -2003,7 +1782,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
2003
1782
  }
2004
1783
  const controlFeedKey = await this._keyring.createKey();
2005
1784
  const dataFeedKey = await this._keyring.createKey();
2006
- (0, import_log7.log)("request admission", {
1785
+ (0, import_log6.log)("request admission", {
2007
1786
  guest: this._signingContext.deviceKey
2008
1787
  }, {
2009
1788
  file: "space-invitations-handler.ts",
@@ -2018,14 +1797,14 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
2018
1797
  dataFeedKey
2019
1798
  });
2020
1799
  const assertion = (0, import_credentials8.getCredentialAssertion)(credential);
2021
- (0, import_node_assert8.default)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential");
2022
- (0, import_node_assert8.default)(credential.subject.id.equals(this._signingContext.identityKey));
1800
+ (0, import_node_assert6.default)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential");
1801
+ (0, import_node_assert6.default)(credential.subject.id.equals(this._signingContext.identityKey));
2023
1802
  const space = await this._spaceManager.acceptSpace({
2024
1803
  spaceKey: assertion.spaceKey,
2025
1804
  genesisFeedKey: assertion.genesisFeedKey
2026
1805
  });
2027
1806
  await this._signingContext.recordCredential(credential);
2028
- (0, import_log7.log)("admitted by host", {
1807
+ (0, import_log6.log)("admitted by host", {
2029
1808
  guest: this._signingContext.deviceKey,
2030
1809
  spaceKey: space.key
2031
1810
  }, {
@@ -2037,7 +1816,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
2037
1816
  complete.wake();
2038
1817
  } catch (err) {
2039
1818
  if (!observable.cancelled) {
2040
- import_log7.log.warn("auth failed", err, {
1819
+ import_log6.log.warn("auth failed", err, {
2041
1820
  file: "space-invitations-handler.ts",
2042
1821
  line: 344,
2043
1822
  scope: this,
@@ -2053,9 +1832,9 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
2053
1832
  });
2054
1833
  return extension;
2055
1834
  };
2056
- (0, import_async9.scheduleTask)(ctx, async () => {
1835
+ (0, import_async7.scheduleTask)(ctx, async () => {
2057
1836
  var _a, _b;
2058
- (0, import_node_assert8.default)(invitation.swarmKey);
1837
+ (0, import_node_assert6.default)(invitation.swarmKey);
2059
1838
  const topic = invitation.swarmKey;
2060
1839
  const swarmConnection = await this._networkManager.joinSwarm({
2061
1840
  topic,
@@ -2074,12 +1853,12 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
2074
1853
  return observable;
2075
1854
  }
2076
1855
  };
2077
- var isAuthenticationRequired = (invitation) => invitation.authMethod !== import_invitations4.AuthMethod.NONE && invitation.type !== import_services5.Invitation.Type.INTERACTIVE_TESTING && invitation.type !== import_services5.Invitation.Type.MULTIUSE_TESTING;
1856
+ 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;
2078
1857
  var HostSpaceInvitationExtension = class extends import_teleport2.RpcExtension {
2079
1858
  constructor(_callbacks) {
2080
1859
  super({
2081
1860
  exposed: {
2082
- SpaceHostService: import_protocols4.schema.getService("dxos.halo.invitations.SpaceHostService")
1861
+ SpaceHostService: import_protocols3.schema.getService("dxos.halo.invitations.SpaceHostService")
2083
1862
  }
2084
1863
  });
2085
1864
  this._callbacks = _callbacks;
@@ -2110,7 +1889,7 @@ var GuestSpaceInvitationExtension = class extends import_teleport2.RpcExtension
2110
1889
  constructor(_callbacks) {
2111
1890
  super({
2112
1891
  requested: {
2113
- SpaceHostService: import_protocols4.schema.getService("dxos.halo.invitations.SpaceHostService")
1892
+ SpaceHostService: import_protocols3.schema.getService("dxos.halo.invitations.SpaceHostService")
2114
1893
  }
2115
1894
  });
2116
1895
  this._callbacks = _callbacks;
@@ -2124,17 +1903,8 @@ var GuestSpaceInvitationExtension = class extends import_teleport2.RpcExtension
2124
1903
  }
2125
1904
  };
2126
1905
 
2127
- // packages/sdk/client-services/src/packlets/invitations/space-invitations-proxy.ts
2128
- var SpaceInvitationsProxy = class extends AbstractInvitationsProxy {
2129
- getInvitationOptions(context) {
2130
- return {
2131
- spaceKey: context
2132
- };
2133
- }
2134
- };
2135
-
2136
1906
  // packages/sdk/client-services/src/packlets/invitations/space-invitations-service.ts
2137
- var import_node_assert9 = __toESM(require("node:assert"));
1907
+ var import_node_assert7 = __toESM(require("node:assert"));
2138
1908
  var SpaceInvitationsServiceImpl = class extends AbstractInvitationsService {
2139
1909
  // prettier-ignore
2140
1910
  constructor(identityManager, invitationsHandler, _getSpaceManager) {
@@ -2143,36 +1913,118 @@ var SpaceInvitationsServiceImpl = class extends AbstractInvitationsService {
2143
1913
  this._getSpaceManager = _getSpaceManager;
2144
1914
  }
2145
1915
  getContext(invitation) {
2146
- (0, import_node_assert9.default)(invitation.spaceKey);
1916
+ (0, import_node_assert7.default)(invitation.spaceKey);
2147
1917
  const spaceManager = this._getSpaceManager();
2148
1918
  const space = spaceManager.spaces.get(invitation.spaceKey);
2149
- (0, import_node_assert9.default)(space);
1919
+ (0, import_node_assert7.default)(space);
2150
1920
  return space;
2151
1921
  }
2152
1922
  };
2153
1923
 
2154
- // packages/sdk/client-services/src/packlets/services/service-context.ts
2155
- var import_async13 = require("@dxos/async");
2156
- var import_credentials11 = require("@dxos/credentials");
2157
- var import_debug4 = require("@dxos/debug");
2158
- var import_echo_pipeline3 = require("@dxos/echo-pipeline");
2159
- var import_feed_store4 = require("@dxos/feed-store");
2160
- var import_keyring = require("@dxos/keyring");
2161
- var import_log10 = require("@dxos/log");
1924
+ // packages/sdk/client-services/src/packlets/services/service-host.ts
1925
+ var import_node_assert12 = __toESM(require("node:assert"));
1926
+ var import_async19 = require("@dxos/async");
1927
+ var import_client7 = require("@dxos/client");
1928
+ var import_debug6 = require("@dxos/debug");
1929
+ var import_echo_pipeline5 = require("@dxos/echo-pipeline");
1930
+ var import_log15 = require("@dxos/log");
1931
+ var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
1932
+
1933
+ // packages/sdk/client-services/src/packlets/deprecated/tracing.ts
1934
+ var TracingServiceImpl = class {
1935
+ constructor(_config) {
1936
+ this._config = _config;
1937
+ }
1938
+ async setTracingOptions() {
1939
+ throw new Error("Tracing not available.");
1940
+ }
1941
+ subscribeToRpcTrace() {
1942
+ throw new Error("Tracing not available.");
1943
+ }
1944
+ };
1945
+
1946
+ // packages/sdk/client-services/src/packlets/devices/devices-service.ts
1947
+ var import_async8 = require("@dxos/async");
1948
+ var import_codec_protobuf8 = require("@dxos/codec-protobuf");
1949
+ var import_services4 = require("@dxos/protocols/proto/dxos/client/services");
1950
+ var DevicesServiceImpl = class {
1951
+ constructor(_identityManager) {
1952
+ this._identityManager = _identityManager;
1953
+ }
1954
+ updateDevice(request) {
1955
+ throw new Error("Method not implemented.");
1956
+ }
1957
+ queryDevices() {
1958
+ return new import_codec_protobuf8.Stream(({ next }) => {
1959
+ const update = () => {
1960
+ var _a;
1961
+ const deviceKeys = (_a = this._identityManager.identity) == null ? void 0 : _a.authorizedDeviceKeys;
1962
+ if (!deviceKeys) {
1963
+ next({
1964
+ devices: []
1965
+ });
1966
+ } else {
1967
+ next({
1968
+ devices: Array.from(deviceKeys.values()).map((key) => {
1969
+ var _a2;
1970
+ return {
1971
+ deviceKey: key,
1972
+ kind: ((_a2 = this._identityManager.identity) == null ? void 0 : _a2.deviceKey.equals(key)) ? import_services4.DeviceKind.CURRENT : import_services4.DeviceKind.TRUSTED
1973
+ };
1974
+ })
1975
+ });
1976
+ }
1977
+ };
1978
+ const subscriptions = new import_async8.EventSubscriptions();
1979
+ subscriptions.add(this._identityManager.stateUpdate.on(() => {
1980
+ update();
1981
+ if (this._identityManager.identity) {
1982
+ subscriptions.add(this._identityManager.identity.stateUpdate.on(() => {
1983
+ update();
1984
+ }));
1985
+ }
1986
+ }));
1987
+ update();
1988
+ return () => subscriptions.clear();
1989
+ });
1990
+ }
1991
+ };
1992
+
1993
+ // packages/sdk/client-services/src/packlets/network/network-service.ts
1994
+ var import_codec_protobuf9 = require("@dxos/codec-protobuf");
1995
+ var NetworkServiceImpl = class {
1996
+ constructor(networkManager) {
1997
+ this.networkManager = networkManager;
1998
+ }
1999
+ subscribeToNetworkStatus() {
2000
+ return new import_codec_protobuf9.Stream(({ next }) => {
2001
+ const unsubscribe = this.networkManager.connectionStateChanged.on((state) => next({
2002
+ state
2003
+ }));
2004
+ next({
2005
+ state: this.networkManager.connectionState
2006
+ });
2007
+ return unsubscribe;
2008
+ });
2009
+ }
2010
+ async setNetworkOptions(request) {
2011
+ await this.networkManager.setConnectionState(request.state);
2012
+ }
2013
+ };
2162
2014
 
2163
2015
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
2164
- var import_node_assert11 = __toESM(require("node:assert"));
2165
- var import_async12 = require("@dxos/async");
2016
+ var import_node_assert9 = __toESM(require("node:assert"));
2017
+ var import_async11 = require("@dxos/async");
2166
2018
  var import_context7 = require("@dxos/context");
2167
2019
  var import_credentials10 = require("@dxos/credentials");
2168
2020
  var import_echo_pipeline2 = require("@dxos/echo-pipeline");
2169
2021
  var import_keys8 = require("@dxos/keys");
2170
- var import_log9 = require("@dxos/log");
2022
+ var import_log8 = require("@dxos/log");
2171
2023
  var import_teleport_extension_presence = require("@dxos/teleport-extension-presence");
2172
2024
  var import_util5 = require("@dxos/util");
2173
2025
 
2174
2026
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2175
- var import_async11 = require("@dxos/async");
2027
+ var import_async10 = require("@dxos/async");
2176
2028
  var import_context6 = require("@dxos/context");
2177
2029
  var import_debug3 = require("@dxos/debug");
2178
2030
  var import_echo_pipeline = require("@dxos/echo-pipeline");
@@ -2181,12 +2033,12 @@ var import_credentials9 = require("@dxos/protocols/proto/dxos/halo/credentials")
2181
2033
  var import_util4 = require("@dxos/util");
2182
2034
 
2183
2035
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
2184
- var import_node_assert10 = __toESM(require("node:assert"));
2185
- var import_async10 = require("@dxos/async");
2036
+ var import_node_assert8 = __toESM(require("node:assert"));
2037
+ var import_async9 = require("@dxos/async");
2186
2038
  var import_context5 = require("@dxos/context");
2187
2039
  var import_keys6 = require("@dxos/keys");
2188
- var import_log8 = require("@dxos/log");
2189
- var import_protocols5 = require("@dxos/protocols");
2040
+ var import_log7 = require("@dxos/log");
2041
+ var import_protocols4 = require("@dxos/protocols");
2190
2042
  var import_teleport3 = require("@dxos/teleport");
2191
2043
  var import_util3 = require("@dxos/util");
2192
2044
  var RETRY_TIMEOUT = 1e3;
@@ -2194,7 +2046,7 @@ var NOTARIZE_TIMEOUT = 1e4;
2194
2046
  var NotarizationPlugin = class {
2195
2047
  constructor() {
2196
2048
  this._ctx = new import_context5.Context();
2197
- this._extensionOpened = new import_async10.Event();
2049
+ this._extensionOpened = new import_async9.Event();
2198
2050
  this._extensions = /* @__PURE__ */ new Set();
2199
2051
  this._processedCredentials = new import_util3.ComplexSet(import_keys6.PublicKey.hash);
2200
2052
  this._processCredentialsTriggers = new import_util3.ComplexMap(import_keys6.PublicKey.hash);
@@ -2208,7 +2060,7 @@ var NotarizationPlugin = class {
2208
2060
  * Request credentials to be notarized.
2209
2061
  */
2210
2062
  async notarize(credentials) {
2211
- (0, import_log8.log)("notarize", {
2063
+ (0, import_log7.log)("notarize", {
2212
2064
  credentials
2213
2065
  }, {
2214
2066
  file: "notarization-plugin.ts",
@@ -2216,11 +2068,11 @@ var NotarizationPlugin = class {
2216
2068
  scope: this,
2217
2069
  callSite: (f, a) => f(...a)
2218
2070
  });
2219
- (0, import_node_assert10.default)(credentials.every((credential) => credential.id), "Credentials must have an id");
2220
- const errors = new import_async10.Trigger();
2071
+ (0, import_node_assert8.default)(credentials.every((credential) => credential.id), "Credentials must have an id");
2072
+ const errors = new import_async9.Trigger();
2221
2073
  const ctx = this._ctx.derive({
2222
2074
  onError: (err) => {
2223
- import_log8.log.warn("Notarization error", {
2075
+ import_log7.log.warn("Notarization error", {
2224
2076
  err
2225
2077
  }, {
2226
2078
  file: "notarization-plugin.ts",
@@ -2232,22 +2084,22 @@ var NotarizationPlugin = class {
2232
2084
  errors.throw(err);
2233
2085
  }
2234
2086
  });
2235
- (0, import_async10.scheduleTask)(ctx, () => {
2236
- import_log8.log.warn("Notarization timeout", {}, {
2087
+ (0, import_async9.scheduleTask)(ctx, () => {
2088
+ import_log7.log.warn("Notarization timeout", {}, {
2237
2089
  file: "notarization-plugin.ts",
2238
2090
  line: 61,
2239
2091
  scope: this,
2240
2092
  callSite: (f, a) => f(...a)
2241
2093
  });
2242
2094
  void ctx.dispose();
2243
- errors.throw(new import_async10.TimeoutError(NOTARIZE_TIMEOUT, "Notarization timed out"));
2095
+ errors.throw(new import_async9.TimeoutError(NOTARIZE_TIMEOUT, "Notarization timed out"));
2244
2096
  }, NOTARIZE_TIMEOUT);
2245
2097
  const allNotarized = Promise.all(credentials.map((credential) => this._waitUntilProcessed(credential.id)));
2246
2098
  const peersTried = /* @__PURE__ */ new Set();
2247
- const notarizeTask = new import_async10.DeferredTask(ctx, async () => {
2099
+ const notarizeTask = new import_async9.DeferredTask(ctx, async () => {
2248
2100
  try {
2249
2101
  if (this._extensions.size === 0) {
2250
- import_log8.log.warn("No peers to notarize with", {}, {
2102
+ import_log7.log.warn("No peers to notarize with", {}, {
2251
2103
  file: "notarization-plugin.ts",
2252
2104
  line: 76,
2253
2105
  scope: this,
@@ -2259,7 +2111,7 @@ var NotarizationPlugin = class {
2259
2111
  ...this._extensions
2260
2112
  ].find((peer2) => !peersTried.has(peer2));
2261
2113
  if (!peer) {
2262
- import_log8.log.warn("Exhausted all peers to notarize with", {
2114
+ import_log7.log.warn("Exhausted all peers to notarize with", {
2263
2115
  retryIn: RETRY_TIMEOUT
2264
2116
  }, {
2265
2117
  file: "notarization-plugin.ts",
@@ -2268,11 +2120,11 @@ var NotarizationPlugin = class {
2268
2120
  callSite: (f, a) => f(...a)
2269
2121
  });
2270
2122
  peersTried.clear();
2271
- (0, import_async10.scheduleTask)(ctx, () => notarizeTask.schedule(), RETRY_TIMEOUT);
2123
+ (0, import_async9.scheduleTask)(ctx, () => notarizeTask.schedule(), RETRY_TIMEOUT);
2272
2124
  return;
2273
2125
  }
2274
2126
  peersTried.add(peer);
2275
- (0, import_log8.log)("try notarizing", {
2127
+ (0, import_log7.log)("try notarizing", {
2276
2128
  peer: peer.localPeerId,
2277
2129
  credentialId: credentials.map((credential) => credential.id)
2278
2130
  }, {
@@ -2284,14 +2136,14 @@ var NotarizationPlugin = class {
2284
2136
  await peer.rpc.NotarizationService.notarize({
2285
2137
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
2286
2138
  });
2287
- (0, import_log8.log)("success", {}, {
2139
+ (0, import_log7.log)("success", {}, {
2288
2140
  file: "notarization-plugin.ts",
2289
2141
  line: 94,
2290
2142
  scope: this,
2291
2143
  callSite: (f, a) => f(...a)
2292
2144
  });
2293
2145
  } catch (err) {
2294
- import_log8.log.warn("error notarizing (recoverable)", err, {
2146
+ import_log7.log.warn("error notarizing (recoverable)", err, {
2295
2147
  file: "notarization-plugin.ts",
2296
2148
  line: 96,
2297
2149
  scope: this,
@@ -2307,7 +2159,7 @@ var NotarizationPlugin = class {
2307
2159
  allNotarized,
2308
2160
  errors.wait()
2309
2161
  ]);
2310
- (0, import_log8.log)("done", {}, {
2162
+ (0, import_log7.log)("done", {}, {
2311
2163
  file: "notarization-plugin.ts",
2312
2164
  line: 107,
2313
2165
  scope: this,
@@ -2330,14 +2182,14 @@ var NotarizationPlugin = class {
2330
2182
  this._processCredentialsTriggers.delete(credential.id);
2331
2183
  }
2332
2184
  setWriter(writer) {
2333
- (0, import_node_assert10.default)(!this._writer, "Writer already set.");
2185
+ (0, import_node_assert8.default)(!this._writer, "Writer already set.");
2334
2186
  this._writer = writer;
2335
2187
  }
2336
2188
  async _waitUntilProcessed(id) {
2337
2189
  if (this._processedCredentials.has(id)) {
2338
2190
  return;
2339
2191
  }
2340
- await (0, import_util3.entry)(this._processCredentialsTriggers, id).orInsert(new import_async10.Trigger()).value.wait();
2192
+ await (0, import_util3.entry)(this._processCredentialsTriggers, id).orInsert(new import_async9.Trigger()).value.wait();
2341
2193
  }
2342
2194
  /**
2343
2195
  * Requests from other peers to notarize credentials.
@@ -2348,7 +2200,7 @@ var NotarizationPlugin = class {
2348
2200
  throw new Error("Writer not set");
2349
2201
  }
2350
2202
  for (const credential of (_a = request.credentials) != null ? _a : []) {
2351
- (0, import_node_assert10.default)(credential.id, "Credential must have an id");
2203
+ (0, import_node_assert8.default)(credential.id, "Credential must have an id");
2352
2204
  if (this._processedCredentials.has(credential.id)) {
2353
2205
  continue;
2354
2206
  }
@@ -2358,7 +2210,7 @@ var NotarizationPlugin = class {
2358
2210
  createExtension() {
2359
2211
  const extension = new NotarizationTeleportExtension({
2360
2212
  onOpen: async () => {
2361
- (0, import_log8.log)("extension opened", {
2213
+ (0, import_log7.log)("extension opened", {
2362
2214
  peer: extension.localPeerId
2363
2215
  }, {
2364
2216
  file: "notarization-plugin.ts",
@@ -2370,7 +2222,7 @@ var NotarizationPlugin = class {
2370
2222
  this._extensionOpened.emit();
2371
2223
  },
2372
2224
  onClose: async () => {
2373
- (0, import_log8.log)("extension closed", {
2225
+ (0, import_log7.log)("extension closed", {
2374
2226
  peer: extension.localPeerId
2375
2227
  }, {
2376
2228
  file: "notarization-plugin.ts",
@@ -2389,10 +2241,10 @@ var NotarizationTeleportExtension = class extends import_teleport3.RpcExtension
2389
2241
  constructor(_params) {
2390
2242
  super({
2391
2243
  requested: {
2392
- NotarizationService: import_protocols5.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
2244
+ NotarizationService: import_protocols4.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
2393
2245
  },
2394
2246
  exposed: {
2395
- NotarizationService: import_protocols5.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
2247
+ NotarizationService: import_protocols4.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
2396
2248
  }
2397
2249
  });
2398
2250
  this._params = _params;
@@ -2545,7 +2397,7 @@ __decorate([
2545
2397
  (0, import_debug3.timed)(1e4)
2546
2398
  ], DataSpace.prototype, "_createWritableFeeds", null);
2547
2399
  DataSpace = __decorate([
2548
- (0, import_async11.trackLeaks)("open", "close")
2400
+ (0, import_async10.trackLeaks)("open", "close")
2549
2401
  ], DataSpace);
2550
2402
 
2551
2403
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
@@ -2571,7 +2423,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2571
2423
  this._feedStore = _feedStore;
2572
2424
  this._snapshotStore = _snapshotStore;
2573
2425
  this._ctx = new import_context7.Context();
2574
- this.updated = new import_async12.Event();
2426
+ this.updated = new import_async11.Event();
2575
2427
  this._spaces = new import_util5.ComplexMap(import_keys8.PublicKey.hash);
2576
2428
  }
2577
2429
  // TODO(burdon): Remove.
@@ -2580,7 +2432,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2580
2432
  }
2581
2433
  async open() {
2582
2434
  await this._metadataStore.load();
2583
- (0, import_log9.log)("metadata loaded", {
2435
+ (0, import_log8.log)("metadata loaded", {
2584
2436
  spaces: this._metadataStore.spaces.length
2585
2437
  }, {
2586
2438
  file: "data-space-manager.ts",
@@ -2589,7 +2441,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2589
2441
  callSite: (f, a) => f(...a)
2590
2442
  });
2591
2443
  for (const spaceMetadata of this._metadataStore.spaces) {
2592
- (0, import_log9.log)("load space", {
2444
+ (0, import_log8.log)("load space", {
2593
2445
  spaceMetadata
2594
2446
  }, {
2595
2447
  file: "data-space-manager.ts",
@@ -2600,7 +2452,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2600
2452
  const space = await this._constructSpace(spaceMetadata);
2601
2453
  await space.initializeDataPipeline();
2602
2454
  if (spaceMetadata.dataTimeframe) {
2603
- (0, import_log9.log)("waiting for latest timeframe", {
2455
+ (0, import_log8.log)("waiting for latest timeframe", {
2604
2456
  spaceMetadata
2605
2457
  }, {
2606
2458
  file: "data-space-manager.ts",
@@ -2635,7 +2487,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2635
2487
  controlFeedKey,
2636
2488
  dataFeedKey
2637
2489
  };
2638
- (0, import_log9.log)("creating space...", {
2490
+ (0, import_log8.log)("creating space...", {
2639
2491
  spaceKey
2640
2492
  }, {
2641
2493
  file: "data-space-manager.ts",
@@ -2647,7 +2499,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2647
2499
  const credentials = await (0, import_echo_pipeline2.spaceGenesis)(this._keyring, this._signingContext, space.inner);
2648
2500
  await this._metadataStore.addSpace(metadata);
2649
2501
  const memberCredential = credentials[1];
2650
- (0, import_node_assert11.default)((0, import_credentials10.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
2502
+ (0, import_node_assert9.default)((0, import_credentials10.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
2651
2503
  await this._signingContext.recordCredential(memberCredential);
2652
2504
  await space.initializeDataPipeline();
2653
2505
  this._dataServiceSubscriptions.registerSpace(space.key, space.dataPipelineController.databaseBackend.createDataServiceHost());
@@ -2656,7 +2508,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2656
2508
  }
2657
2509
  // TODO(burdon): Rename join space.
2658
2510
  async acceptSpace(opts) {
2659
- (0, import_node_assert11.default)(!this._spaces.has(opts.spaceKey), "Space already exists.");
2511
+ (0, import_node_assert9.default)(!this._spaces.has(opts.spaceKey), "Space already exists.");
2660
2512
  const metadata = {
2661
2513
  key: opts.spaceKey,
2662
2514
  genesisFeedKey: opts.genesisFeedKey
@@ -2672,7 +2524,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2672
2524
  const presence = new import_teleport_extension_presence.Presence({
2673
2525
  localPeerId: this._signingContext.deviceKey,
2674
2526
  announceInterval: 1e3,
2675
- offlineTimeout: 3e4,
2527
+ offlineTimeout: 1e4,
2676
2528
  identityKey: this._signingContext.identityKey
2677
2529
  });
2678
2530
  const snapshotManager = new import_echo_pipeline2.SnapshotManager(this._snapshotStore);
@@ -2717,327 +2569,28 @@ var DataSpaceManager = class DataSpaceManager2 {
2717
2569
  }
2718
2570
  };
2719
2571
  __decorate2([
2720
- import_async12.synchronized
2572
+ import_async11.synchronized
2721
2573
  ], DataSpaceManager.prototype, "open", null);
2722
2574
  __decorate2([
2723
- import_async12.synchronized
2575
+ import_async11.synchronized
2724
2576
  ], DataSpaceManager.prototype, "close", null);
2725
2577
  __decorate2([
2726
- import_async12.synchronized
2578
+ import_async11.synchronized
2727
2579
  ], DataSpaceManager.prototype, "createSpace", null);
2728
2580
  __decorate2([
2729
- import_async12.synchronized
2581
+ import_async11.synchronized
2730
2582
  ], DataSpaceManager.prototype, "acceptSpace", null);
2731
2583
  DataSpaceManager = __decorate2([
2732
- (0, import_async12.trackLeaks)("open", "close")
2584
+ (0, import_async11.trackLeaks)("open", "close")
2733
2585
  ], DataSpaceManager);
2734
2586
 
2735
- // packages/sdk/client-services/src/packlets/services/service-context.ts
2736
- var ServiceContext = class {
2737
- // prettier-ignore
2738
- constructor(storage, networkManager, modelFactory) {
2739
- this.storage = storage;
2740
- this.networkManager = networkManager;
2741
- this.modelFactory = modelFactory;
2742
- this.initialized = new import_async13.Trigger();
2743
- this.dataServiceSubscriptions = new import_echo_pipeline3.DataServiceSubscriptions();
2744
- this.metadataStore = new import_echo_pipeline3.MetadataStore(storage.createDirectory("metadata"));
2745
- this.snapshotStore = new import_echo_pipeline3.SnapshotStore(storage.createDirectory("snapshots"));
2746
- this.keyring = new import_keyring.Keyring(storage.createDirectory("keyring"));
2747
- this.feedStore = new import_feed_store4.FeedStore({
2748
- factory: new import_feed_store4.FeedFactory({
2749
- root: storage.createDirectory("feeds"),
2750
- signer: this.keyring,
2751
- hypercore: {
2752
- valueEncoding: import_echo_pipeline3.valueEncoding
2753
- }
2754
- })
2755
- });
2756
- this.spaceManager = new import_echo_pipeline3.SpaceManager({
2757
- feedStore: this.feedStore,
2758
- networkManager: this.networkManager
2759
- });
2760
- this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager);
2761
- this.deviceInvitations = new DeviceInvitationsHandler({
2762
- networkManager: this.networkManager,
2763
- getIdentity: () => {
2764
- var _a;
2765
- return (_a = this.identityManager.identity) != null ? _a : (0, import_debug4.failUndefined)();
2766
- },
2767
- acceptIdentity: this._acceptIdentity.bind(this),
2768
- keyring: this.keyring
2769
- });
2770
- }
2771
- async open() {
2772
- (0, import_log10.log)("opening...", {}, {
2773
- file: "service-context.ts",
2774
- line: 94,
2775
- scope: this,
2776
- callSite: (f, a) => f(...a)
2777
- });
2778
- await this.networkManager.open();
2779
- await this.spaceManager.open();
2780
- await this.identityManager.open();
2781
- if (this.identityManager.identity) {
2782
- await this._initialize();
2783
- }
2784
- (0, import_log10.log)("opened", {}, {
2785
- file: "service-context.ts",
2786
- line: 101,
2787
- scope: this,
2788
- callSite: (f, a) => f(...a)
2789
- });
2790
- }
2791
- async close() {
2792
- var _a, _b;
2793
- (0, import_log10.log)("closing...", {}, {
2794
- file: "service-context.ts",
2795
- line: 105,
2796
- scope: this,
2797
- callSite: (f, a) => f(...a)
2798
- });
2799
- await ((_a = this._deviceSpaceSync) == null ? void 0 : _a.close());
2800
- await ((_b = this.dataSpaceManager) == null ? void 0 : _b.close());
2801
- await this.identityManager.close();
2802
- await this.spaceManager.close();
2803
- await this.feedStore.close();
2804
- await this.networkManager.close();
2805
- this.dataServiceSubscriptions.clear();
2806
- (0, import_log10.log)("closed", {}, {
2807
- file: "service-context.ts",
2808
- line: 113,
2809
- scope: this,
2810
- callSite: (f, a) => f(...a)
2811
- });
2812
- }
2813
- async reset() {
2814
- (0, import_log10.log)("resetting...", {}, {
2815
- file: "service-context.ts",
2816
- line: 117,
2817
- scope: this,
2818
- callSite: (f, a) => f(...a)
2819
- });
2820
- await this.close();
2821
- await this.storage.reset();
2822
- (0, import_log10.log)("reset", {}, {
2823
- file: "service-context.ts",
2824
- line: 120,
2825
- scope: this,
2826
- callSite: (f, a) => f(...a)
2827
- });
2828
- }
2829
- async createIdentity(params = {}) {
2830
- const identity = await this.identityManager.createIdentity(params);
2831
- await this._initialize();
2832
- return identity;
2833
- }
2834
- async _acceptIdentity(params) {
2835
- const identity = await this.identityManager.acceptIdentity(params);
2836
- await this._initialize();
2837
- return identity;
2838
- }
2839
- // Called when identity is created.
2840
- async _initialize() {
2841
- var _a;
2842
- (0, import_log10.log)("initializing spaces...", {}, {
2843
- file: "service-context.ts",
2844
- line: 139,
2845
- scope: this,
2846
- callSite: (f, a) => f(...a)
2847
- });
2848
- const identity = (_a = this.identityManager.identity) != null ? _a : (0, import_debug4.failUndefined)();
2849
- const signingContext = {
2850
- credentialSigner: identity.getIdentityCredentialSigner(),
2851
- identityKey: identity.identityKey,
2852
- deviceKey: identity.deviceKey,
2853
- profile: identity.profileDocument,
2854
- recordCredential: async (credential) => {
2855
- await identity.controlPipeline.writer.write({
2856
- credential: {
2857
- credential
2858
- }
2859
- });
2860
- }
2861
- };
2862
- this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.dataServiceSubscriptions, this.keyring, signingContext, this.modelFactory, this.feedStore, this.snapshotStore);
2863
- await this.dataSpaceManager.open();
2864
- this.spaceInvitations = new SpaceInvitationsHandler(this.networkManager, this.dataSpaceManager, signingContext, this.keyring);
2865
- this.initialized.wake();
2866
- this._deviceSpaceSync = identity.space.spaceState.registerProcessor({
2867
- process: async (credential) => {
2868
- const assertion = (0, import_credentials11.getCredentialAssertion)(credential);
2869
- if (assertion["@type"] !== "dxos.halo.credentials.SpaceMember") {
2870
- return;
2871
- }
2872
- if (assertion.spaceKey.equals(identity.space.key)) {
2873
- return;
2874
- }
2875
- if (!this.dataSpaceManager) {
2876
- (0, import_log10.log)("dataSpaceManager not initialized yet, ignoring space admission", {
2877
- details: assertion
2878
- }, {
2879
- file: "service-context.ts",
2880
- line: 182,
2881
- scope: this,
2882
- callSite: (f, a) => f(...a)
2883
- });
2884
- return;
2885
- }
2886
- if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
2887
- (0, import_log10.log)("space already exists, ignoring space admission", {
2888
- details: assertion
2889
- }, {
2890
- file: "service-context.ts",
2891
- line: 186,
2892
- scope: this,
2893
- callSite: (f, a) => f(...a)
2894
- });
2895
- return;
2896
- }
2897
- try {
2898
- (0, import_log10.log)("accepting space recorded in halo", {
2899
- details: assertion
2900
- }, {
2901
- file: "service-context.ts",
2902
- line: 191,
2903
- scope: this,
2904
- callSite: (f, a) => f(...a)
2905
- });
2906
- await this.dataSpaceManager.acceptSpace({
2907
- spaceKey: assertion.spaceKey,
2908
- genesisFeedKey: assertion.genesisFeedKey
2909
- });
2910
- } catch (err) {
2911
- import_log10.log.catch(err, {}, {
2912
- file: "service-context.ts",
2913
- line: 197,
2914
- scope: this,
2915
- callSite: (f, a) => f(...a)
2916
- });
2917
- }
2918
- }
2919
- });
2920
- await this._deviceSpaceSync.open();
2921
- }
2922
- };
2923
-
2924
- // packages/sdk/client-services/src/packlets/services/service-definitions.ts
2925
- var import_protocols6 = require("@dxos/protocols");
2926
- var import_rpc = require("@dxos/rpc");
2927
- var clientServiceBundle = (0, import_rpc.createServiceBundle)({
2928
- SystemService: import_protocols6.schema.getService("dxos.client.services.SystemService"),
2929
- IdentityService: import_protocols6.schema.getService("dxos.client.services.IdentityService"),
2930
- DeviceInvitationsService: import_protocols6.schema.getService("dxos.client.services.DeviceInvitationsService"),
2931
- DevicesService: import_protocols6.schema.getService("dxos.client.services.DevicesService"),
2932
- SpaceInvitationsService: import_protocols6.schema.getService("dxos.client.services.SpaceInvitationsService"),
2933
- SpacesService: import_protocols6.schema.getService("dxos.client.services.SpacesService"),
2934
- DataService: import_protocols6.schema.getService("dxos.echo.service.DataService"),
2935
- NetworkService: import_protocols6.schema.getService("dxos.client.services.NetworkService"),
2936
- // TODO(burdon): Deprecated.
2937
- DevtoolsHost: import_protocols6.schema.getService("dxos.devtools.host.DevtoolsHost"),
2938
- TracingService: import_protocols6.schema.getService("dxos.devtools.host.TracingService")
2939
- });
2940
-
2941
- // packages/sdk/client-services/src/packlets/services/service-host.ts
2942
- var import_node_assert14 = __toESM(require("node:assert"));
2943
- var import_async22 = require("@dxos/async");
2944
- var import_debug6 = require("@dxos/debug");
2945
- var import_document_model = require("@dxos/document-model");
2946
- var import_echo_pipeline5 = require("@dxos/echo-pipeline");
2947
- var import_log17 = require("@dxos/log");
2948
- var import_model_factory = require("@dxos/model-factory");
2949
- var import_services15 = require("@dxos/protocols/proto/dxos/client/services");
2950
- var import_text_model = require("@dxos/text-model");
2951
-
2952
- // packages/sdk/client-services/src/packlets/deprecated/tracing.ts
2953
- var TracingServiceImpl = class {
2954
- constructor(_config) {
2955
- this._config = _config;
2956
- }
2957
- async setTracingOptions() {
2958
- throw new Error("Tracing not available.");
2959
- }
2960
- subscribeToRpcTrace() {
2961
- throw new Error("Tracing not available.");
2962
- }
2963
- };
2964
-
2965
- // packages/sdk/client-services/src/packlets/devices/devices-service.ts
2966
- var import_async14 = require("@dxos/async");
2967
- var import_codec_protobuf8 = require("@dxos/codec-protobuf");
2968
- var import_services6 = require("@dxos/protocols/proto/dxos/client/services");
2969
- var DevicesServiceImpl = class {
2970
- constructor(_identityManager) {
2971
- this._identityManager = _identityManager;
2972
- }
2973
- updateDevice(request) {
2974
- throw new Error("Method not implemented.");
2975
- }
2976
- queryDevices() {
2977
- return new import_codec_protobuf8.Stream(({ next }) => {
2978
- const update = () => {
2979
- var _a;
2980
- const deviceKeys = (_a = this._identityManager.identity) == null ? void 0 : _a.authorizedDeviceKeys;
2981
- if (!deviceKeys) {
2982
- next({
2983
- devices: []
2984
- });
2985
- } else {
2986
- next({
2987
- devices: Array.from(deviceKeys.values()).map((key) => {
2988
- var _a2;
2989
- return {
2990
- deviceKey: key,
2991
- kind: ((_a2 = this._identityManager.identity) == null ? void 0 : _a2.deviceKey.equals(key)) ? import_services6.DeviceKind.CURRENT : import_services6.DeviceKind.TRUSTED
2992
- };
2993
- })
2994
- });
2995
- }
2996
- };
2997
- const subscriptions = new import_async14.EventSubscriptions();
2998
- subscriptions.add(this._identityManager.stateUpdate.on(() => {
2999
- update();
3000
- if (this._identityManager.identity) {
3001
- subscriptions.add(this._identityManager.identity.stateUpdate.on(() => {
3002
- update();
3003
- }));
3004
- }
3005
- }));
3006
- update();
3007
- return () => subscriptions.clear();
3008
- });
3009
- }
3010
- };
3011
-
3012
- // packages/sdk/client-services/src/packlets/network/network-service.ts
3013
- var import_codec_protobuf9 = require("@dxos/codec-protobuf");
3014
- var NetworkServiceImpl = class {
3015
- constructor(networkManager) {
3016
- this.networkManager = networkManager;
3017
- }
3018
- subscribeToNetworkStatus() {
3019
- return new import_codec_protobuf9.Stream(({ next }) => {
3020
- const unsubscribe = this.networkManager.connectionStateChanged.on((state) => next({
3021
- state
3022
- }));
3023
- next({
3024
- state: this.networkManager.connectionState
3025
- });
3026
- return unsubscribe;
3027
- });
3028
- }
3029
- async setNetworkOptions(request) {
3030
- await this.networkManager.setConnectionState(request.state);
3031
- }
3032
- };
3033
-
3034
2587
  // packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
3035
- var import_async15 = require("@dxos/async");
2588
+ var import_async12 = require("@dxos/async");
3036
2589
  var import_codec_protobuf10 = require("@dxos/codec-protobuf");
3037
- var import_debug5 = require("@dxos/debug");
3038
- var import_echo_pipeline4 = require("@dxos/echo-pipeline");
3039
- var import_log11 = require("@dxos/log");
3040
- var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
2590
+ var import_debug4 = require("@dxos/debug");
2591
+ var import_echo_pipeline3 = require("@dxos/echo-pipeline");
2592
+ var import_log9 = require("@dxos/log");
2593
+ var import_services5 = require("@dxos/protocols/proto/dxos/client/services");
3041
2594
  var import_util6 = require("@dxos/util");
3042
2595
  var SpacesServiceImpl = class {
3043
2596
  constructor(_identityManager, _spaceManager, _dataServiceSubscriptions, _getDataSpaceManager) {
@@ -3055,14 +2608,14 @@ var SpacesServiceImpl = class {
3055
2608
  return this._transformSpace(space);
3056
2609
  }
3057
2610
  async updateSpace(request) {
3058
- (0, import_debug5.todo)();
2611
+ (0, import_debug4.todo)();
3059
2612
  }
3060
2613
  querySpaces() {
3061
2614
  return new import_codec_protobuf10.Stream(({ next, ctx }) => {
3062
2615
  const onUpdate = async () => {
3063
2616
  const dataSpaceManager = await this._getDataSpaceManager();
3064
2617
  const spaces = Array.from(dataSpaceManager.spaces.values()).filter((space) => this._dataServiceSubscriptions.getDataService(space.key)).map((space) => this._transformSpace(space));
3065
- (0, import_log11.log)("update", {
2618
+ (0, import_log9.log)("update", {
3066
2619
  spaces
3067
2620
  }, {
3068
2621
  file: "spaces-service.ts",
@@ -3076,7 +2629,7 @@ var SpacesServiceImpl = class {
3076
2629
  };
3077
2630
  setTimeout(async () => {
3078
2631
  const dataSpaceManager = await this._getDataSpaceManager();
3079
- const subscriptions = new import_async15.EventSubscriptions();
2632
+ const subscriptions = new import_async12.EventSubscriptions();
3080
2633
  const subscribeSpaces = () => {
3081
2634
  subscriptions.clear();
3082
2635
  for (const space of dataSpaceManager.spaces.values()) {
@@ -3092,7 +2645,7 @@ var SpacesServiceImpl = class {
3092
2645
  void onUpdate();
3093
2646
  });
3094
2647
  ctx.onDispose(() => subscriptions.clear());
3095
- (0, import_async15.scheduleTask)(ctx, () => {
2648
+ (0, import_async12.scheduleTask)(ctx, () => {
3096
2649
  subscribeSpaces();
3097
2650
  void onUpdate();
3098
2651
  });
@@ -3107,19 +2660,19 @@ var SpacesServiceImpl = class {
3107
2660
  queryCredentials({ spaceKey }) {
3108
2661
  return new import_codec_protobuf10.Stream(({ ctx, next }) => {
3109
2662
  var _a;
3110
- const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug5.raise)(new import_echo_pipeline4.SpaceNotFoundError(spaceKey));
2663
+ const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug4.raise)(new import_echo_pipeline3.SpaceNotFoundError(spaceKey));
3111
2664
  const processor = space.spaceState.registerProcessor({
3112
2665
  process: async (credential) => {
3113
2666
  next(credential);
3114
2667
  }
3115
2668
  });
3116
2669
  ctx.onDispose(() => processor.close());
3117
- (0, import_async15.scheduleTask)(ctx, () => processor.open());
2670
+ (0, import_async12.scheduleTask)(ctx, () => processor.open());
3118
2671
  });
3119
2672
  }
3120
2673
  async writeCredentials({ spaceKey, credentials }) {
3121
2674
  var _a;
3122
- const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug5.raise)(new import_echo_pipeline4.SpaceNotFoundError(spaceKey));
2675
+ const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug4.raise)(new import_echo_pipeline3.SpaceNotFoundError(spaceKey));
3123
2676
  for (const credential of credentials != null ? credentials : []) {
3124
2677
  await space.controlPipeline.writer.write({
3125
2678
  credential: {
@@ -3131,7 +2684,7 @@ var SpacesServiceImpl = class {
3131
2684
  _transformSpace(space) {
3132
2685
  return {
3133
2686
  spaceKey: space.key,
3134
- status: space.isOpen ? import_services7.SpaceStatus.ACTIVE : import_services7.SpaceStatus.INACTIVE,
2687
+ status: space.isOpen ? import_services5.SpaceStatus.ACTIVE : import_services5.SpaceStatus.INACTIVE,
3135
2688
  members: Array.from(space.inner.spaceState.members.values()).map((member) => {
3136
2689
  var _a, _b, _c;
3137
2690
  return {
@@ -3141,7 +2694,7 @@ var SpacesServiceImpl = class {
3141
2694
  displayName: (_b = (_a = member.assertion.profile) == null ? void 0 : _a.displayName) != null ? _b : (0, import_util6.humanize)(member.key)
3142
2695
  }
3143
2696
  },
3144
- 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_services7.SpaceMember.PresenceState.ONLINE : import_services7.SpaceMember.PresenceState.OFFLINE
2697
+ 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
3145
2698
  };
3146
2699
  })
3147
2700
  };
@@ -3231,40 +2784,24 @@ var SystemServiceImpl = class {
3231
2784
  };
3232
2785
 
3233
2786
  // packages/sdk/client-services/src/packlets/vault/iframe-host-runtime.ts
3234
- var import_async17 = require("@dxos/async");
3235
- var import_log12 = require("@dxos/log");
2787
+ var import_async14 = require("@dxos/async");
2788
+ var import_client4 = require("@dxos/client");
2789
+ var import_log10 = require("@dxos/log");
3236
2790
  var import_messaging = require("@dxos/messaging");
3237
- var import_network_manager3 = require("@dxos/network-manager");
3238
- var import_rpc3 = require("@dxos/rpc");
3239
- var import_util7 = require("@dxos/util");
3240
-
3241
- // packages/sdk/client-services/src/packlets/vault/shell-runtime.ts
3242
- var import_node_assert12 = __toESM(require("node:assert"));
3243
- var import_async16 = require("@dxos/async");
3244
- var import_iframe = require("@dxos/protocols/proto/dxos/iframe");
3245
- var import_rpc2 = require("@dxos/rpc");
3246
-
3247
- // packages/sdk/client-services/src/packlets/vault/services.ts
3248
- var import_protocols7 = require("@dxos/protocols");
3249
- var iframeServiceBundle = {
3250
- IframeService: import_protocols7.schema.getService("dxos.iframe.IframeService"),
3251
- BridgeService: import_protocols7.schema.getService("dxos.mesh.bridge.BridgeService")
3252
- };
3253
- var workerServiceBundle = {
3254
- WorkerService: import_protocols7.schema.getService("dxos.iframe.WorkerService")
3255
- };
3256
- var appServiceBundle = {
3257
- AppService: import_protocols7.schema.getService("dxos.iframe.AppService")
3258
- };
3259
- var shellServiceBundle = {
3260
- ShellService: import_protocols7.schema.getService("dxos.iframe.ShellService")
3261
- };
2791
+ var import_network_manager3 = require("@dxos/network-manager");
2792
+ var import_rpc2 = require("@dxos/rpc");
2793
+ var import_util7 = require("@dxos/util");
3262
2794
 
3263
2795
  // packages/sdk/client-services/src/packlets/vault/shell-runtime.ts
2796
+ var import_node_assert10 = __toESM(require("node:assert"));
2797
+ var import_async13 = require("@dxos/async");
2798
+ var import_client3 = require("@dxos/client");
2799
+ var import_iframe = require("@dxos/protocols/proto/dxos/iframe");
2800
+ var import_rpc = require("@dxos/rpc");
3264
2801
  var ShellRuntimeImpl = class {
3265
2802
  constructor(_port) {
3266
2803
  this._port = _port;
3267
- this.layoutUpdate = new import_async16.Event();
2804
+ this.layoutUpdate = new import_async13.Event();
3268
2805
  this._layout = import_iframe.ShellLayout.DEFAULT;
3269
2806
  }
3270
2807
  get layout() {
@@ -3286,13 +2823,13 @@ var ShellRuntimeImpl = class {
3286
2823
  });
3287
2824
  }
3288
2825
  async setAppContext(context) {
3289
- (0, import_node_assert12.default)(this._appRpc, "runtime not open");
2826
+ (0, import_node_assert10.default)(this._appRpc, "runtime not open");
3290
2827
  await this._appRpc.rpc.AppService.setContext(context);
3291
2828
  }
3292
2829
  async open() {
3293
- this._appRpc = (0, import_rpc2.createProtoRpcPeer)({
3294
- requested: appServiceBundle,
3295
- exposed: shellServiceBundle,
2830
+ this._appRpc = (0, import_rpc.createProtoRpcPeer)({
2831
+ requested: import_client3.appServiceBundle,
2832
+ exposed: import_client3.shellServiceBundle,
3296
2833
  handlers: {
3297
2834
  ShellService: {
3298
2835
  setLayout: async (request) => {
@@ -3315,8 +2852,8 @@ var ShellRuntimeImpl = class {
3315
2852
  };
3316
2853
  var MemoryShellRuntime = class {
3317
2854
  constructor({ layout, invitationCode, spaceKey } = {}) {
3318
- this.layoutUpdate = new import_async16.Event();
3319
- this.contextUpdate = new import_async16.Event();
2855
+ this.layoutUpdate = new import_async13.Event();
2856
+ this.contextUpdate = new import_async13.Event();
3320
2857
  this._layout = layout != null ? layout : import_iframe.ShellLayout.DEFAULT;
3321
2858
  this._invitationCode = invitationCode;
3322
2859
  this._spaceKey = spaceKey;
@@ -3359,7 +2896,7 @@ var LOCK_KEY = "DXOS_RESOURCE_LOCK";
3359
2896
  var IFrameHostRuntime = class {
3360
2897
  constructor({ configProvider, appPort, shellPort }) {
3361
2898
  this._transportFactory = (0, import_network_manager3.createWebRTCTransportFactory)();
3362
- this._ready = new import_async17.Trigger();
2899
+ this._ready = new import_async14.Trigger();
3363
2900
  this._configProvider = configProvider;
3364
2901
  this._appPort = appPort;
3365
2902
  this._shellPort = shellPort;
@@ -3386,16 +2923,16 @@ var IFrameHostRuntime = class {
3386
2923
  }
3387
2924
  async start() {
3388
2925
  var _a;
3389
- (0, import_log12.log)("starting...", {}, {
2926
+ (0, import_log10.log)("starting...", {}, {
3390
2927
  file: "iframe-host-runtime.ts",
3391
- line: 81,
2928
+ line: 84,
3392
2929
  scope: this,
3393
2930
  callSite: (f, a) => f(...a)
3394
2931
  });
3395
2932
  try {
3396
2933
  this._config = await (0, import_util7.getAsyncValue)(this._configProvider);
3397
2934
  const signalServer = this._config.get("runtime.services.signal.server");
3398
- this._clientServices = new ClientServicesHost({
2935
+ this._clientServices = new LocalClientServices({
3399
2936
  lockKey: LOCK_KEY,
3400
2937
  config: this._config,
3401
2938
  networkManager: new import_network_manager3.NetworkManager({
@@ -3406,8 +2943,8 @@ var IFrameHostRuntime = class {
3406
2943
  transportFactory: this._transportFactory
3407
2944
  })
3408
2945
  });
3409
- this._clientRpc = (0, import_rpc3.createProtoRpcPeer)({
3410
- exposed: clientServiceBundle,
2946
+ this._clientRpc = (0, import_rpc2.createProtoRpcPeer)({
2947
+ exposed: import_client4.clientServiceBundle,
3411
2948
  handlers: {
3412
2949
  DataService: async () => await this._getService((services) => services.DataService),
3413
2950
  DeviceInvitationsService: async () => await this._getService((services) => services.DeviceInvitationsService),
@@ -3428,17 +2965,17 @@ var IFrameHostRuntime = class {
3428
2965
  (_a = this._shellRuntime) == null ? void 0 : _a.open()
3429
2966
  ]);
3430
2967
  this._ready.wake(void 0);
3431
- (0, import_log12.log)("started", {}, {
2968
+ (0, import_log10.log)("started", {}, {
3432
2969
  file: "iframe-host-runtime.ts",
3433
- line: 116,
2970
+ line: 119,
3434
2971
  scope: this,
3435
2972
  callSite: (f, a) => f(...a)
3436
2973
  });
3437
2974
  } catch (err) {
3438
2975
  this._ready.wake(err);
3439
- import_log12.log.catch(err, {}, {
2976
+ import_log10.log.catch(err, {}, {
3440
2977
  file: "iframe-host-runtime.ts",
3441
- line: 119,
2978
+ line: 122,
3442
2979
  scope: this,
3443
2980
  callSite: (f, a) => f(...a)
3444
2981
  });
@@ -3446,30 +2983,31 @@ var IFrameHostRuntime = class {
3446
2983
  }
3447
2984
  async stop() {
3448
2985
  var _a;
3449
- (0, import_log12.log)("stopping...", {}, {
2986
+ (0, import_log10.log)("stopping...", {}, {
3450
2987
  file: "iframe-host-runtime.ts",
3451
- line: 124,
2988
+ line: 127,
3452
2989
  scope: this,
3453
2990
  callSite: (f, a) => f(...a)
3454
2991
  });
3455
2992
  await this._clientRpc.close();
3456
2993
  await this._clientServices.close();
3457
2994
  await ((_a = this._shellRuntime) == null ? void 0 : _a.close());
3458
- (0, import_log12.log)("stopped", {}, {
2995
+ (0, import_log10.log)("stopped", {}, {
3459
2996
  file: "iframe-host-runtime.ts",
3460
- line: 128,
2997
+ line: 131,
3461
2998
  scope: this,
3462
2999
  callSite: (f, a) => f(...a)
3463
3000
  });
3464
3001
  }
3465
3002
  };
3466
3003
  __decorate3([
3467
- import_log12.logInfo
3004
+ import_log10.logInfo
3468
3005
  ], IFrameHostRuntime.prototype, "origin", void 0);
3469
3006
 
3470
3007
  // packages/sdk/client-services/src/packlets/vault/iframe-proxy-runtime.ts
3008
+ var import_client5 = require("@dxos/client");
3471
3009
  var import_network_manager4 = require("@dxos/network-manager");
3472
- var import_rpc4 = require("@dxos/rpc");
3010
+ var import_rpc3 = require("@dxos/rpc");
3473
3011
  var IFrameProxyRuntime = class {
3474
3012
  constructor({ systemPort, workerAppPort, windowAppPort, shellPort }) {
3475
3013
  this._transportService = new import_network_manager4.WebRTCTransportService();
@@ -3477,9 +3015,9 @@ var IFrameProxyRuntime = class {
3477
3015
  this._windowAppPort = windowAppPort;
3478
3016
  this._workerAppPort = workerAppPort;
3479
3017
  this._shellPort = shellPort;
3480
- this._systemRpc = (0, import_rpc4.createProtoRpcPeer)({
3481
- requested: workerServiceBundle,
3482
- exposed: iframeServiceBundle,
3018
+ this._systemRpc = (0, import_rpc3.createProtoRpcPeer)({
3019
+ requested: import_client5.workerServiceBundle,
3020
+ exposed: import_client5.iframeServiceBundle,
3483
3021
  handlers: {
3484
3022
  BridgeService: this._transportService,
3485
3023
  IframeService: {
@@ -3515,72 +3053,9 @@ var IFrameProxyRuntime = class {
3515
3053
  }
3516
3054
  };
3517
3055
 
3518
- // packages/sdk/client-services/src/packlets/vault/shell-controller.ts
3519
- var import_async18 = require("@dxos/async");
3520
- var import_log13 = require("@dxos/log");
3521
- var import_iframe2 = require("@dxos/protocols/proto/dxos/iframe");
3522
- var import_rpc5 = require("@dxos/rpc");
3523
- var ShellController = class {
3524
- constructor(_port) {
3525
- this._port = _port;
3526
- this.contextUpdate = new import_async18.Event();
3527
- this._display = import_iframe2.ShellDisplay.NONE;
3528
- }
3529
- get display() {
3530
- return this._display;
3531
- }
3532
- async setLayout(layout, options = {}) {
3533
- var _a;
3534
- (0, import_log13.log)("set layout", {
3535
- layout,
3536
- ...options
3537
- }, {
3538
- file: "shell-controller.ts",
3539
- line: 27,
3540
- scope: this,
3541
- callSite: (f, a) => f(...a)
3542
- });
3543
- this._display = import_iframe2.ShellDisplay.FULLSCREEN;
3544
- this.contextUpdate.emit({
3545
- display: this._display
3546
- });
3547
- await ((_a = this._shellRpc) == null ? void 0 : _a.rpc.ShellService.setLayout({
3548
- layout,
3549
- ...options
3550
- }));
3551
- }
3552
- async open() {
3553
- this._shellRpc = (0, import_rpc5.createProtoRpcPeer)({
3554
- requested: shellServiceBundle,
3555
- exposed: appServiceBundle,
3556
- handlers: {
3557
- AppService: {
3558
- setContext: async (request) => {
3559
- (0, import_log13.log)("set context", request, {
3560
- file: "shell-controller.ts",
3561
- line: 40,
3562
- scope: this,
3563
- callSite: (f, a) => f(...a)
3564
- });
3565
- this._display = request.display;
3566
- this.contextUpdate.emit(request);
3567
- }
3568
- }
3569
- },
3570
- port: this._port
3571
- });
3572
- await this._shellRpc.open();
3573
- }
3574
- async close() {
3575
- var _a;
3576
- await ((_a = this._shellRpc) == null ? void 0 : _a.close());
3577
- this._shellRpc = void 0;
3578
- }
3579
- };
3580
-
3581
3056
  // packages/sdk/client-services/src/packlets/vault/vault-resource-lock.ts
3582
- var import_async19 = require("@dxos/async");
3583
- var import_log14 = require("@dxos/log");
3057
+ var import_async15 = require("@dxos/async");
3058
+ var import_log11 = require("@dxos/log");
3584
3059
  var Message;
3585
3060
  (function(Message2) {
3586
3061
  Message2["ACQUIRING"] = "acquiring";
@@ -3588,7 +3063,7 @@ var Message;
3588
3063
  var VaultResourceLock = class {
3589
3064
  constructor({ lockKey, onAcquire, onRelease }) {
3590
3065
  this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
3591
- this._releaseTrigger = new import_async19.Trigger();
3066
+ this._releaseTrigger = new import_async15.Trigger();
3592
3067
  this._lockKey = lockKey;
3593
3068
  this._onAcquire = onAcquire;
3594
3069
  this._onRelease = onRelease;
@@ -3599,7 +3074,7 @@ var VaultResourceLock = class {
3599
3074
  message: Message.ACQUIRING
3600
3075
  });
3601
3076
  try {
3602
- await (0, import_async19.asyncTimeout)(this._requestLock(), 3e3);
3077
+ await (0, import_async15.asyncTimeout)(this._requestLock(), 3e3);
3603
3078
  } catch (e) {
3604
3079
  await this._requestLock(true);
3605
3080
  }
@@ -3613,7 +3088,7 @@ var VaultResourceLock = class {
3613
3088
  }
3614
3089
  }
3615
3090
  async _requestLock(steal = false) {
3616
- (0, import_log14.log)("requesting lock...", {
3091
+ (0, import_log11.log)("requesting lock...", {
3617
3092
  steal
3618
3093
  }, {
3619
3094
  file: "vault-resource-lock.ts",
@@ -3621,23 +3096,23 @@ var VaultResourceLock = class {
3621
3096
  scope: this,
3622
3097
  callSite: (f, a) => f(...a)
3623
3098
  });
3624
- const acquired = new import_async19.Trigger();
3099
+ const acquired = new import_async15.Trigger();
3625
3100
  void navigator.locks.request(this._lockKey, {
3626
3101
  steal
3627
3102
  }, async () => {
3628
3103
  var _a, _b;
3629
3104
  await ((_a = this._onAcquire) == null ? void 0 : _a.call(this));
3630
3105
  acquired.wake();
3631
- this._releaseTrigger = new import_async19.Trigger();
3106
+ this._releaseTrigger = new import_async15.Trigger();
3632
3107
  await this._releaseTrigger.wait();
3633
- (0, import_log14.log)("releasing lock...", {}, {
3108
+ (0, import_log11.log)("releasing lock...", {}, {
3634
3109
  file: "vault-resource-lock.ts",
3635
3110
  line: 65,
3636
3111
  scope: this,
3637
3112
  callSite: (f, a) => f(...a)
3638
3113
  });
3639
3114
  await ((_b = this._onRelease) == null ? void 0 : _b.call(this));
3640
- (0, import_log14.log)("released lock", {}, {
3115
+ (0, import_log11.log)("released lock", {}, {
3641
3116
  file: "vault-resource-lock.ts",
3642
3117
  line: 67,
3643
3118
  scope: this,
@@ -3648,7 +3123,7 @@ var VaultResourceLock = class {
3648
3123
  await ((_a = this._onRelease) == null ? void 0 : _a.call(this));
3649
3124
  });
3650
3125
  await acquired.wait();
3651
- (0, import_log14.log)("recieved lock", {
3126
+ (0, import_log11.log)("recieved lock", {
3652
3127
  steal
3653
3128
  }, {
3654
3129
  file: "vault-resource-lock.ts",
@@ -3660,16 +3135,17 @@ var VaultResourceLock = class {
3660
3135
  };
3661
3136
 
3662
3137
  // packages/sdk/client-services/src/packlets/vault/worker-runtime.ts
3663
- var import_async21 = require("@dxos/async");
3664
- var import_log16 = require("@dxos/log");
3138
+ var import_async17 = require("@dxos/async");
3139
+ var import_log13 = require("@dxos/log");
3665
3140
  var import_messaging2 = require("@dxos/messaging");
3666
3141
  var import_network_manager5 = require("@dxos/network-manager");
3667
3142
 
3668
3143
  // packages/sdk/client-services/src/packlets/vault/worker-session.ts
3669
- var import_node_assert13 = __toESM(require("node:assert"));
3670
- var import_async20 = require("@dxos/async");
3671
- var import_log15 = require("@dxos/log");
3672
- var import_rpc6 = require("@dxos/rpc");
3144
+ var import_node_assert11 = __toESM(require("node:assert"));
3145
+ var import_async16 = require("@dxos/async");
3146
+ var import_client6 = require("@dxos/client");
3147
+ var import_log12 = require("@dxos/log");
3148
+ var import_rpc4 = require("@dxos/rpc");
3673
3149
  var import_util8 = require("@dxos/util");
3674
3150
  var __decorate4 = function(decorators, target, key, desc) {
3675
3151
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -3685,10 +3161,10 @@ var WorkerSession = class {
3685
3161
  constructor({ getService, systemPort, appPort, shellPort, options = {
3686
3162
  heartbeatInterval: 1e3
3687
3163
  } }) {
3688
- this._startTrigger = new import_async20.Trigger();
3164
+ this._startTrigger = new import_async16.Trigger();
3689
3165
  this.onClose = new import_util8.Callback();
3690
- (0, import_node_assert13.default)(options);
3691
- (0, import_node_assert13.default)(getService);
3166
+ (0, import_node_assert11.default)(options);
3167
+ (0, import_node_assert11.default)(getService);
3692
3168
  this._options = options;
3693
3169
  this._getService = getService;
3694
3170
  const handlers = {
@@ -3703,19 +3179,19 @@ var WorkerSession = class {
3703
3179
  SystemService: () => this._getService((services) => services.SystemService),
3704
3180
  TracingService: () => this._getService((services) => services.TracingService)
3705
3181
  };
3706
- this._clientRpc = (0, import_rpc6.createProtoRpcPeer)({
3707
- exposed: clientServiceBundle,
3182
+ this._clientRpc = (0, import_rpc4.createProtoRpcPeer)({
3183
+ exposed: import_client6.clientServiceBundle,
3708
3184
  handlers,
3709
3185
  port: appPort
3710
3186
  });
3711
- this._shellClientRpc = (0, import_rpc6.createProtoRpcPeer)({
3712
- exposed: clientServiceBundle,
3187
+ this._shellClientRpc = (0, import_rpc4.createProtoRpcPeer)({
3188
+ exposed: import_client6.clientServiceBundle,
3713
3189
  handlers,
3714
3190
  port: shellPort
3715
3191
  });
3716
- this._iframeRpc = (0, import_rpc6.createProtoRpcPeer)({
3717
- requested: iframeServiceBundle,
3718
- exposed: workerServiceBundle,
3192
+ this._iframeRpc = (0, import_rpc4.createProtoRpcPeer)({
3193
+ requested: import_client6.iframeServiceBundle,
3194
+ exposed: import_client6.workerServiceBundle,
3719
3195
  handlers: {
3720
3196
  WorkerService: {
3721
3197
  start: async (request) => {
@@ -3727,9 +3203,9 @@ var WorkerSession = class {
3727
3203
  try {
3728
3204
  await this.close();
3729
3205
  } catch (err) {
3730
- import_log15.log.catch(err, {}, {
3206
+ import_log12.log.catch(err, {}, {
3731
3207
  file: "worker-session.ts",
3732
- line: 91,
3208
+ line: 95,
3733
3209
  scope: this,
3734
3210
  callSite: (f, a) => f(...a)
3735
3211
  });
@@ -3745,9 +3221,9 @@ var WorkerSession = class {
3745
3221
  this.bridgeService = this._iframeRpc.rpc.BridgeService;
3746
3222
  }
3747
3223
  async open() {
3748
- import_log15.log.info("opening..", {}, {
3224
+ import_log12.log.info("opening..", {}, {
3749
3225
  file: "worker-session.ts",
3750
- line: 105,
3226
+ line: 109,
3751
3227
  scope: this,
3752
3228
  callSite: (f, a) => f(...a)
3753
3229
  });
@@ -3763,20 +3239,20 @@ var WorkerSession = class {
3763
3239
  try {
3764
3240
  await this._iframeRpc.rpc.IframeService.heartbeat();
3765
3241
  } catch (err1) {
3766
- import_log15.log.warn("Heartbeat failed", {
3242
+ import_log12.log.warn("Heartbeat failed", {
3767
3243
  err: err1
3768
3244
  }, {
3769
3245
  file: "worker-session.ts",
3770
- line: 117,
3246
+ line: 121,
3771
3247
  scope: this,
3772
3248
  callSite: (f, a) => f(...a)
3773
3249
  });
3774
3250
  try {
3775
3251
  await this.close();
3776
3252
  } catch (err) {
3777
- import_log15.log.catch(err, {}, {
3253
+ import_log12.log.catch(err, {}, {
3778
3254
  file: "worker-session.ts",
3779
- line: 121,
3255
+ line: 125,
3780
3256
  scope: this,
3781
3257
  callSite: (f, a) => f(...a)
3782
3258
  });
@@ -3785,18 +3261,18 @@ var WorkerSession = class {
3785
3261
  }, this._options.heartbeatInterval);
3786
3262
  }
3787
3263
  async close() {
3788
- import_log15.log.info("closing..", {}, {
3264
+ import_log12.log.info("closing..", {}, {
3789
3265
  file: "worker-session.ts",
3790
- line: 128,
3266
+ line: 132,
3791
3267
  scope: this,
3792
3268
  callSite: (f, a) => f(...a)
3793
3269
  });
3794
3270
  try {
3795
3271
  await this.onClose.callIfSet();
3796
3272
  } catch (err) {
3797
- import_log15.log.catch(err, {}, {
3273
+ import_log12.log.catch(err, {}, {
3798
3274
  file: "worker-session.ts",
3799
- line: 132,
3275
+ line: 136,
3800
3276
  scope: this,
3801
3277
  callSite: (f, a) => f(...a)
3802
3278
  });
@@ -3811,11 +3287,11 @@ var WorkerSession = class {
3811
3287
  }
3812
3288
  async _maybeOpenShell() {
3813
3289
  try {
3814
- await (0, import_async20.asyncTimeout)(this._shellClientRpc.open(), 1e3);
3290
+ await (0, import_async16.asyncTimeout)(this._shellClientRpc.open(), 1e3);
3815
3291
  } catch (e) {
3816
- import_log15.log.info("No shell connected.", {}, {
3292
+ import_log12.log.info("No shell connected.", {}, {
3817
3293
  file: "worker-session.ts",
3818
- line: 146,
3294
+ line: 150,
3819
3295
  scope: this,
3820
3296
  callSite: (f, a) => f(...a)
3821
3297
  });
@@ -3823,7 +3299,7 @@ var WorkerSession = class {
3823
3299
  }
3824
3300
  };
3825
3301
  __decorate4([
3826
- import_log15.logInfo
3302
+ import_log12.logInfo
3827
3303
  ], WorkerSession.prototype, "origin", void 0);
3828
3304
 
3829
3305
  // packages/sdk/client-services/src/packlets/vault/worker-runtime.ts
@@ -3832,11 +3308,11 @@ var WorkerRuntime = class {
3832
3308
  constructor(_configProvider) {
3833
3309
  this._configProvider = _configProvider;
3834
3310
  this._transportFactory = new import_network_manager5.WebRTCTransportProxyFactory();
3835
- this._ready = new import_async21.Trigger();
3311
+ this._ready = new import_async17.Trigger();
3836
3312
  this.sessions = /* @__PURE__ */ new Set();
3837
3313
  }
3838
3314
  async start() {
3839
- (0, import_log16.log)("starting...", {}, {
3315
+ (0, import_log13.log)("starting...", {}, {
3840
3316
  file: "worker-runtime.ts",
3841
3317
  line: 42,
3842
3318
  scope: this,
@@ -3857,7 +3333,7 @@ var WorkerRuntime = class {
3857
3333
  });
3858
3334
  await this._clientServices.open();
3859
3335
  this._ready.wake(void 0);
3860
- (0, import_log16.log)("started", {}, {
3336
+ (0, import_log13.log)("started", {}, {
3861
3337
  file: "worker-runtime.ts",
3862
3338
  line: 59,
3863
3339
  scope: this,
@@ -3865,7 +3341,7 @@ var WorkerRuntime = class {
3865
3341
  });
3866
3342
  } catch (err) {
3867
3343
  this._ready.wake(err);
3868
- import_log16.log.catch(err, {}, {
3344
+ import_log13.log.catch(err, {}, {
3869
3345
  file: "worker-runtime.ts",
3870
3346
  line: 62,
3871
3347
  scope: this,
@@ -3926,6 +3402,202 @@ var WorkerRuntime = class {
3926
3402
  }
3927
3403
  };
3928
3404
 
3405
+ // packages/sdk/client-services/src/packlets/services/service-context.ts
3406
+ var import_async18 = require("@dxos/async");
3407
+ var import_credentials11 = require("@dxos/credentials");
3408
+ var import_debug5 = require("@dxos/debug");
3409
+ var import_echo_pipeline4 = require("@dxos/echo-pipeline");
3410
+ var import_feed_store4 = require("@dxos/feed-store");
3411
+ var import_keyring = require("@dxos/keyring");
3412
+ var import_log14 = require("@dxos/log");
3413
+ var ServiceContext = class {
3414
+ // prettier-ignore
3415
+ constructor(storage, networkManager, modelFactory) {
3416
+ this.storage = storage;
3417
+ this.networkManager = networkManager;
3418
+ this.modelFactory = modelFactory;
3419
+ this.initialized = new import_async18.Trigger();
3420
+ this.dataServiceSubscriptions = new import_echo_pipeline4.DataServiceSubscriptions();
3421
+ this.metadataStore = new import_echo_pipeline4.MetadataStore(storage.createDirectory("metadata"));
3422
+ this.snapshotStore = new import_echo_pipeline4.SnapshotStore(storage.createDirectory("snapshots"));
3423
+ this.keyring = new import_keyring.Keyring(storage.createDirectory("keyring"));
3424
+ this.feedStore = new import_feed_store4.FeedStore({
3425
+ factory: new import_feed_store4.FeedFactory({
3426
+ root: storage.createDirectory("feeds"),
3427
+ signer: this.keyring,
3428
+ hypercore: {
3429
+ valueEncoding: import_echo_pipeline4.valueEncoding
3430
+ }
3431
+ })
3432
+ });
3433
+ this.spaceManager = new import_echo_pipeline4.SpaceManager({
3434
+ feedStore: this.feedStore,
3435
+ networkManager: this.networkManager
3436
+ });
3437
+ this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager);
3438
+ this.deviceInvitations = new DeviceInvitationsHandler({
3439
+ networkManager: this.networkManager,
3440
+ getIdentity: () => {
3441
+ var _a;
3442
+ return (_a = this.identityManager.identity) != null ? _a : (0, import_debug5.failUndefined)();
3443
+ },
3444
+ acceptIdentity: this._acceptIdentity.bind(this),
3445
+ keyring: this.keyring
3446
+ });
3447
+ }
3448
+ async open() {
3449
+ (0, import_log14.log)("opening...", {}, {
3450
+ file: "service-context.ts",
3451
+ line: 94,
3452
+ scope: this,
3453
+ callSite: (f, a) => f(...a)
3454
+ });
3455
+ await this.networkManager.open();
3456
+ await this.spaceManager.open();
3457
+ await this.identityManager.open();
3458
+ if (this.identityManager.identity) {
3459
+ await this._initialize();
3460
+ }
3461
+ (0, import_log14.log)("opened", {}, {
3462
+ file: "service-context.ts",
3463
+ line: 101,
3464
+ scope: this,
3465
+ callSite: (f, a) => f(...a)
3466
+ });
3467
+ }
3468
+ async close() {
3469
+ var _a, _b;
3470
+ (0, import_log14.log)("closing...", {}, {
3471
+ file: "service-context.ts",
3472
+ line: 105,
3473
+ scope: this,
3474
+ callSite: (f, a) => f(...a)
3475
+ });
3476
+ await ((_a = this._deviceSpaceSync) == null ? void 0 : _a.close());
3477
+ await ((_b = this.dataSpaceManager) == null ? void 0 : _b.close());
3478
+ await this.identityManager.close();
3479
+ await this.spaceManager.close();
3480
+ await this.feedStore.close();
3481
+ await this.networkManager.close();
3482
+ this.dataServiceSubscriptions.clear();
3483
+ (0, import_log14.log)("closed", {}, {
3484
+ file: "service-context.ts",
3485
+ line: 113,
3486
+ scope: this,
3487
+ callSite: (f, a) => f(...a)
3488
+ });
3489
+ }
3490
+ async reset() {
3491
+ (0, import_log14.log)("resetting...", {}, {
3492
+ file: "service-context.ts",
3493
+ line: 117,
3494
+ scope: this,
3495
+ callSite: (f, a) => f(...a)
3496
+ });
3497
+ await this.close();
3498
+ await this.storage.reset();
3499
+ (0, import_log14.log)("reset", {}, {
3500
+ file: "service-context.ts",
3501
+ line: 120,
3502
+ scope: this,
3503
+ callSite: (f, a) => f(...a)
3504
+ });
3505
+ }
3506
+ async createIdentity(params = {}) {
3507
+ const identity = await this.identityManager.createIdentity(params);
3508
+ await this._initialize();
3509
+ return identity;
3510
+ }
3511
+ async _acceptIdentity(params) {
3512
+ const identity = await this.identityManager.acceptIdentity(params);
3513
+ await this._initialize();
3514
+ return identity;
3515
+ }
3516
+ // Called when identity is created.
3517
+ async _initialize() {
3518
+ var _a;
3519
+ (0, import_log14.log)("initializing spaces...", {}, {
3520
+ file: "service-context.ts",
3521
+ line: 139,
3522
+ scope: this,
3523
+ callSite: (f, a) => f(...a)
3524
+ });
3525
+ const identity = (_a = this.identityManager.identity) != null ? _a : (0, import_debug5.failUndefined)();
3526
+ const signingContext = {
3527
+ credentialSigner: identity.getIdentityCredentialSigner(),
3528
+ identityKey: identity.identityKey,
3529
+ deviceKey: identity.deviceKey,
3530
+ profile: identity.profileDocument,
3531
+ recordCredential: async (credential) => {
3532
+ await identity.controlPipeline.writer.write({
3533
+ credential: {
3534
+ credential
3535
+ }
3536
+ });
3537
+ }
3538
+ };
3539
+ this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.dataServiceSubscriptions, this.keyring, signingContext, this.modelFactory, this.feedStore, this.snapshotStore);
3540
+ await this.dataSpaceManager.open();
3541
+ this.spaceInvitations = new SpaceInvitationsHandler(this.networkManager, this.dataSpaceManager, signingContext, this.keyring);
3542
+ this.initialized.wake();
3543
+ this._deviceSpaceSync = identity.space.spaceState.registerProcessor({
3544
+ process: async (credential) => {
3545
+ const assertion = (0, import_credentials11.getCredentialAssertion)(credential);
3546
+ if (assertion["@type"] !== "dxos.halo.credentials.SpaceMember") {
3547
+ return;
3548
+ }
3549
+ if (assertion.spaceKey.equals(identity.space.key)) {
3550
+ return;
3551
+ }
3552
+ if (!this.dataSpaceManager) {
3553
+ (0, import_log14.log)("dataSpaceManager not initialized yet, ignoring space admission", {
3554
+ details: assertion
3555
+ }, {
3556
+ file: "service-context.ts",
3557
+ line: 182,
3558
+ scope: this,
3559
+ callSite: (f, a) => f(...a)
3560
+ });
3561
+ return;
3562
+ }
3563
+ if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
3564
+ (0, import_log14.log)("space already exists, ignoring space admission", {
3565
+ details: assertion
3566
+ }, {
3567
+ file: "service-context.ts",
3568
+ line: 186,
3569
+ scope: this,
3570
+ callSite: (f, a) => f(...a)
3571
+ });
3572
+ return;
3573
+ }
3574
+ try {
3575
+ (0, import_log14.log)("accepting space recorded in halo", {
3576
+ details: assertion
3577
+ }, {
3578
+ file: "service-context.ts",
3579
+ line: 191,
3580
+ scope: this,
3581
+ callSite: (f, a) => f(...a)
3582
+ });
3583
+ await this.dataSpaceManager.acceptSpace({
3584
+ spaceKey: assertion.spaceKey,
3585
+ genesisFeedKey: assertion.genesisFeedKey
3586
+ });
3587
+ } catch (err) {
3588
+ import_log14.log.catch(err, {}, {
3589
+ file: "service-context.ts",
3590
+ line: 197,
3591
+ scope: this,
3592
+ callSite: (f, a) => f(...a)
3593
+ });
3594
+ }
3595
+ }
3596
+ });
3597
+ await this._deviceSpaceSync.open();
3598
+ }
3599
+ };
3600
+
3929
3601
  // packages/sdk/client-services/src/packlets/services/service-registry.ts
3930
3602
  var ServiceRegistry = class {
3931
3603
  // prettier-ignore
@@ -3945,20 +3617,17 @@ var ServiceRegistry = class {
3945
3617
  };
3946
3618
 
3947
3619
  // packages/sdk/client-services/src/packlets/services/service-host.ts
3948
- var createDefaultModelFactory = () => {
3949
- return new import_model_factory.ModelFactory().registerModel(import_document_model.DocumentModel).registerModel(import_text_model.TextModel);
3950
- };
3951
3620
  var ClientServicesHost = class {
3952
3621
  constructor({
3953
3622
  config,
3954
- modelFactory = createDefaultModelFactory(),
3623
+ modelFactory = (0, import_client7.createDefaultModelFactory)(),
3955
3624
  // TODO(burdon): Create ApolloLink abstraction (see Client).
3956
3625
  networkManager,
3957
3626
  storage = createStorageObjects(config.get("runtime.client.storage", {})).storage,
3958
3627
  // TODO(wittjosiah): Turn this on by default.
3959
3628
  lockKey
3960
3629
  }) {
3961
- this._statusUpdate = new import_async22.Event();
3630
+ this._statusUpdate = new import_async19.Event();
3962
3631
  this._open = false;
3963
3632
  this._config = config;
3964
3633
  this._modelFactory = modelFactory;
@@ -3972,21 +3641,21 @@ var ClientServicesHost = class {
3972
3641
  this._systemService = new SystemServiceImpl({
3973
3642
  config: this._config,
3974
3643
  statusUpdate: this._statusUpdate,
3975
- getCurrentStatus: () => this.isOpen ? import_services15.SystemStatus.ACTIVE : import_services15.SystemStatus.INACTIVE,
3644
+ getCurrentStatus: () => this.isOpen ? import_services8.SystemStatus.ACTIVE : import_services8.SystemStatus.INACTIVE,
3976
3645
  onUpdateStatus: async (status) => {
3977
3646
  var _a, _b;
3978
- if (!this.isOpen && status === import_services15.SystemStatus.ACTIVE) {
3647
+ if (!this.isOpen && status === import_services8.SystemStatus.ACTIVE) {
3979
3648
  await ((_a = this._resourceLock) == null ? void 0 : _a.acquire());
3980
- } else if (this.isOpen && status === import_services15.SystemStatus.INACTIVE) {
3649
+ } else if (this.isOpen && status === import_services8.SystemStatus.INACTIVE) {
3981
3650
  await ((_b = this._resourceLock) == null ? void 0 : _b.release());
3982
3651
  }
3983
3652
  },
3984
3653
  onReset: async () => {
3985
- (0, import_node_assert14.default)(this._serviceContext, "service host is closed");
3654
+ (0, import_node_assert12.default)(this._serviceContext, "service host is closed");
3986
3655
  await this._serviceContext.reset();
3987
3656
  }
3988
3657
  });
3989
- this._serviceRegistry = new ServiceRegistry(clientServiceBundle, {
3658
+ this._serviceRegistry = new ServiceRegistry(import_client7.clientServiceBundle, {
3990
3659
  SystemService: this._systemService
3991
3660
  });
3992
3661
  }
@@ -4004,9 +3673,9 @@ var ClientServicesHost = class {
4004
3673
  if (this._open) {
4005
3674
  return;
4006
3675
  }
4007
- (0, import_log17.log)("opening...", {}, {
3676
+ (0, import_log15.log)("opening...", {}, {
4008
3677
  file: "service-host.ts",
4009
- line: 133,
3678
+ line: 125,
4010
3679
  scope: this,
4011
3680
  callSite: (f, a) => f(...a)
4012
3681
  });
@@ -4042,11 +3711,11 @@ var ClientServicesHost = class {
4042
3711
  this._open = true;
4043
3712
  this._statusUpdate.emit();
4044
3713
  const deviceKey = (_b = this._serviceContext.identityManager.identity) == null ? void 0 : _b.deviceKey;
4045
- (0, import_log17.log)("opened", {
3714
+ (0, import_log15.log)("opened", {
4046
3715
  deviceKey
4047
3716
  }, {
4048
3717
  file: "service-host.ts",
4049
- line: 186,
3718
+ line: 178,
4050
3719
  scope: this,
4051
3720
  callSite: (f, a) => f(...a)
4052
3721
  });
@@ -4057,11 +3726,11 @@ var ClientServicesHost = class {
4057
3726
  return;
4058
3727
  }
4059
3728
  const deviceKey = (_a = this._serviceContext.identityManager.identity) == null ? void 0 : _a.deviceKey;
4060
- (0, import_log17.log)("closing...", {
3729
+ (0, import_log15.log)("closing...", {
4061
3730
  deviceKey
4062
3731
  }, {
4063
3732
  file: "service-host.ts",
4064
- line: 195,
3733
+ line: 187,
4065
3734
  scope: this,
4066
3735
  callSite: (f, a) => f(...a)
4067
3736
  });
@@ -4071,99 +3740,106 @@ var ClientServicesHost = class {
4071
3740
  await this._serviceContext.close();
4072
3741
  this._open = false;
4073
3742
  this._statusUpdate.emit();
4074
- (0, import_log17.log)("closed", {
3743
+ (0, import_log15.log)("closed", {
4075
3744
  deviceKey
4076
3745
  }, {
4077
3746
  file: "service-host.ts",
4078
- line: 200,
3747
+ line: 192,
4079
3748
  scope: this,
4080
3749
  callSite: (f, a) => f(...a)
4081
3750
  });
4082
3751
  }
4083
3752
  };
4084
3753
 
4085
- // packages/sdk/client-services/src/packlets/services/service-proxy.ts
4086
- var import_async23 = require("@dxos/async");
4087
- var import_errors2 = require("@dxos/errors");
4088
- var import_rpc7 = require("@dxos/rpc");
4089
- var ClientServicesProxy = class {
4090
- // prettier-ignore
4091
- constructor(port, _timeout = 3e4) {
4092
- this._timeout = _timeout;
4093
- this._proxy = (0, import_rpc7.createProtoRpcPeer)({
4094
- requested: clientServiceBundle,
4095
- exposed: {},
4096
- handlers: {},
4097
- port
4098
- });
4099
- }
4100
- get proxy() {
4101
- return this._proxy;
3754
+ // packages/sdk/client-services/src/packlets/services/local-client-services.ts
3755
+ var LocalClientServices = class {
3756
+ constructor(params) {
3757
+ this._host = new ClientServicesHost(params);
4102
3758
  }
4103
3759
  get descriptors() {
4104
- return clientServiceBundle;
3760
+ return this._host.descriptors;
4105
3761
  }
4106
3762
  get services() {
4107
- return this._proxy.rpc;
3763
+ return this._host.services;
4108
3764
  }
4109
3765
  async open() {
4110
- await (0, import_async23.asyncTimeout)(this._proxy.open(), this._timeout, new import_errors2.RemoteServiceConnectionTimeout());
3766
+ await this._host.open();
4111
3767
  }
4112
3768
  async close() {
4113
- await this._proxy.close();
3769
+ await this._host.close();
4114
3770
  }
4115
3771
  };
3772
+
3773
+ // packages/sdk/client-services/src/packlets/services/utils.ts
3774
+ var import_config2 = require("@dxos/config");
3775
+ var import_log16 = require("@dxos/log");
3776
+ var import_messaging3 = require("@dxos/messaging");
3777
+ var import_network_manager6 = require("@dxos/network-manager");
3778
+ var fromHost = (config = new import_config2.Config()) => {
3779
+ return new LocalClientServices({
3780
+ config,
3781
+ networkManager: createNetworkManager(config)
3782
+ });
3783
+ };
3784
+ var createNetworkManager = (config, options = {}) => {
3785
+ const signalServer = config.get("runtime.services.signal.server");
3786
+ if (signalServer) {
3787
+ const { log: log1 = true, signalManager = new import_messaging3.WebsocketSignalManager([
3788
+ signalServer
3789
+ ]), transportFactory = (0, import_network_manager6.createWebRTCTransportFactory)({
3790
+ iceServers: config.get("runtime.services.ice")
3791
+ }) } = options;
3792
+ return new import_network_manager6.NetworkManager({
3793
+ log: log1,
3794
+ signalManager,
3795
+ transportFactory
3796
+ });
3797
+ }
3798
+ import_log16.log.warn("P2P network is not configured.", {}, {
3799
+ file: "utils.ts",
3800
+ line: 48,
3801
+ scope: void 0,
3802
+ callSite: (f, a) => f(...a)
3803
+ });
3804
+ return new import_network_manager6.NetworkManager({
3805
+ signalManager: new import_messaging3.MemorySignalManager(new import_messaging3.MemorySignalManagerContext()),
3806
+ transportFactory: import_network_manager6.MemoryTransportFactory
3807
+ });
3808
+ };
4116
3809
  // Annotate the CommonJS export names for ESM import in node:
4117
3810
  0 && (module.exports = {
4118
- AUTHENTICATION_CODE_LENGTH,
4119
- AbstractInvitationsHandler,
4120
- AbstractInvitationsProxy,
4121
3811
  AbstractInvitationsService,
4122
- AuthenticatingInvitationProvider,
4123
3812
  ClientServicesHost,
4124
- ClientServicesProxy,
4125
3813
  DeviceInvitationsHandler,
4126
- DeviceInvitationsProxy,
4127
3814
  DeviceInvitationsServiceImpl,
4128
3815
  DevtoolsHostEvents,
4129
3816
  DevtoolsServiceImpl,
4130
3817
  IFrameHostRuntime,
4131
3818
  IFrameProxyRuntime,
4132
- INVITATION_TIMEOUT,
4133
3819
  Identity,
4134
3820
  IdentityManager,
4135
3821
  IdentityServiceImpl,
4136
- InvitationEncoder,
4137
- InvitationObservableProvider,
3822
+ LocalClientServices,
4138
3823
  MemoryShellRuntime,
4139
- ON_CLOSE_DELAY,
4140
3824
  ServiceContext,
4141
3825
  ServiceRegistry,
4142
- ShellController,
4143
3826
  ShellRuntimeImpl,
4144
3827
  SpaceInvitationsHandler,
4145
- SpaceInvitationsProxy,
4146
3828
  SpaceInvitationsServiceImpl,
4147
3829
  TrustedKeySetAuthVerifier,
4148
3830
  VaultResourceLock,
4149
3831
  WorkerRuntime,
4150
3832
  WorkerSession,
4151
- appServiceBundle,
4152
- clientServiceBundle,
4153
3833
  createAuthProvider,
4154
- createDefaultModelFactory,
4155
3834
  createStorageObjects,
3835
+ fromHost,
4156
3836
  getNetworkPeers,
4157
- iframeServiceBundle,
4158
- shellServiceBundle,
4159
3837
  subscribeToFeedBlocks,
4160
3838
  subscribeToFeeds,
4161
3839
  subscribeToNetworkStatus,
4162
3840
  subscribeToNetworkTopics,
4163
3841
  subscribeToSignal,
4164
3842
  subscribeToSpaces,
4165
- subscribeToSwarmInfo,
4166
- workerServiceBundle,
4167
- wrapObservable
3843
+ subscribeToSwarmInfo
4168
3844
  });
4169
3845
  //# sourceMappingURL=index.cjs.map