@dxos/client-services 0.3.11-next.0fb359e → 0.3.11-next.ee2b64c

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 (61) hide show
  1. package/dist/lib/browser/{chunk-UPV7MXNN.mjs → chunk-45E23CYC.mjs} +245 -117
  2. package/dist/lib/browser/chunk-45E23CYC.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -1
  4. package/dist/lib/browser/index.mjs.map +1 -1
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +4 -11
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/{chunk-PJPQHWZH.cjs → chunk-BRIW2QR3.cjs} +384 -256
  9. package/dist/lib/node/chunk-BRIW2QR3.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +37 -37
  11. package/dist/lib/node/index.cjs.map +1 -1
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/packlets/testing/index.cjs +11 -18
  14. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  15. package/dist/types/src/packlets/identity/identity-service.d.ts +3 -3
  16. package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
  17. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +2 -0
  18. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
  19. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +28 -3
  20. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
  21. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  22. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +2 -0
  23. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  24. package/dist/types/src/packlets/network/network-service.d.ts.map +1 -1
  25. package/dist/types/src/packlets/services/diagnostics.d.ts +32 -16
  26. package/dist/types/src/packlets/services/diagnostics.d.ts.map +1 -1
  27. package/dist/types/src/packlets/services/platform.d.ts +1 -14
  28. package/dist/types/src/packlets/services/platform.d.ts.map +1 -1
  29. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  30. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts +2 -0
  31. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts.map +1 -1
  32. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  33. package/dist/types/src/packlets/spaces/data-space.d.ts +2 -0
  34. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  35. package/dist/types/src/packlets/system/system-service.d.ts +3 -2
  36. package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
  37. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  38. package/dist/types/src/version.d.ts +1 -1
  39. package/package.json +35 -35
  40. package/src/packlets/identity/identity-manager.ts +1 -1
  41. package/src/packlets/identity/identity-service.test.ts +1 -1
  42. package/src/packlets/identity/identity-service.ts +6 -3
  43. package/src/packlets/invitations/device-invitation-protocol.test.ts +14 -0
  44. package/src/packlets/invitations/device-invitation-protocol.ts +14 -0
  45. package/src/packlets/invitations/invitation-protocol.ts +44 -6
  46. package/src/packlets/invitations/invitations-handler.ts +20 -18
  47. package/src/packlets/invitations/space-invitation-protocol.test.ts +28 -0
  48. package/src/packlets/invitations/space-invitation-protocol.ts +11 -0
  49. package/src/packlets/network/network-service.ts +5 -1
  50. package/src/packlets/services/diagnostics.ts +52 -16
  51. package/src/packlets/services/platform.ts +7 -19
  52. package/src/packlets/services/service-host.ts +27 -12
  53. package/src/packlets/spaces/automerge-space-state.ts +4 -0
  54. package/src/packlets/spaces/data-space-manager.ts +5 -1
  55. package/src/packlets/spaces/data-space.ts +37 -4
  56. package/src/packlets/spaces/spaces-service.ts +3 -3
  57. package/src/packlets/system/system-service.ts +7 -1
  58. package/src/packlets/testing/invitation-utils.ts +2 -10
  59. package/src/version.ts +1 -1
  60. package/dist/lib/browser/chunk-UPV7MXNN.mjs.map +0 -7
  61. package/dist/lib/node/chunk-PJPQHWZH.cjs.map +0 -7
@@ -26,8 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var chunk_PJPQHWZH_exports = {};
30
- __export(chunk_PJPQHWZH_exports, {
29
+ var chunk_BRIW2QR3_exports = {};
30
+ __export(chunk_BRIW2QR3_exports, {
31
31
  ClientRpcServer: () => ClientRpcServer,
32
32
  ClientServicesHost: () => ClientServicesHost,
33
33
  DataSpace: () => DataSpace,
@@ -60,7 +60,7 @@ __export(chunk_PJPQHWZH_exports, {
60
60
  subscribeToSpaces: () => subscribeToSpaces,
61
61
  subscribeToSwarmInfo: () => subscribeToSwarmInfo
62
62
  });
63
- module.exports = __toCommonJS(chunk_PJPQHWZH_exports);
63
+ module.exports = __toCommonJS(chunk_BRIW2QR3_exports);
64
64
  var import_async = require("@dxos/async");
65
65
  var import_codec_protobuf = require("@dxos/codec-protobuf");
66
66
  var import_feed_store = require("@dxos/feed-store");
@@ -108,6 +108,7 @@ var import_credentials6 = require("@dxos/credentials");
108
108
  var import_debug2 = require("@dxos/debug");
109
109
  var import_invariant3 = require("@dxos/invariant");
110
110
  var import_invariant4 = require("@dxos/invariant");
111
+ var import_protocols3 = require("@dxos/protocols");
111
112
  var import_services = require("@dxos/protocols/proto/dxos/client/services");
112
113
  var import_async7 = require("@dxos/async");
113
114
  var import_client_protocol2 = require("@dxos/client-protocol");
@@ -117,7 +118,7 @@ var import_invariant5 = require("@dxos/invariant");
117
118
  var import_keys5 = require("@dxos/keys");
118
119
  var import_log4 = require("@dxos/log");
119
120
  var import_network_manager = require("@dxos/network-manager");
120
- var import_protocols3 = require("@dxos/protocols");
121
+ var import_protocols4 = require("@dxos/protocols");
121
122
  var import_services2 = require("@dxos/protocols/proto/dxos/client/services");
122
123
  var import_invitations = require("@dxos/protocols/proto/dxos/halo/invitations");
123
124
  var import_async8 = require("@dxos/async");
@@ -125,7 +126,7 @@ var import_context5 = require("@dxos/context");
125
126
  var import_invariant6 = require("@dxos/invariant");
126
127
  var import_keys6 = require("@dxos/keys");
127
128
  var import_log5 = require("@dxos/log");
128
- var import_protocols4 = require("@dxos/protocols");
129
+ var import_protocols5 = require("@dxos/protocols");
129
130
  var import_services3 = require("@dxos/protocols/proto/dxos/client/services");
130
131
  var import_invitations2 = require("@dxos/protocols/proto/dxos/halo/invitations");
131
132
  var import_teleport = require("@dxos/teleport");
@@ -138,6 +139,7 @@ var import_credentials8 = require("@dxos/credentials");
138
139
  var import_feed_store3 = require("@dxos/feed-store");
139
140
  var import_invariant8 = require("@dxos/invariant");
140
141
  var import_log7 = require("@dxos/log");
142
+ var import_protocols6 = require("@dxos/protocols");
141
143
  var import_services5 = require("@dxos/protocols/proto/dxos/client/services");
142
144
  var import_codec_protobuf9 = require("@dxos/codec-protobuf");
143
145
  var import_debug3 = require("@dxos/debug");
@@ -149,38 +151,41 @@ var import_document_model = require("@dxos/document-model");
149
151
  var import_echo_db = require("@dxos/echo-db");
150
152
  var import_invariant9 = require("@dxos/invariant");
151
153
  var import_log8 = require("@dxos/log");
152
- var import_protocols5 = require("@dxos/protocols");
154
+ var import_protocols7 = require("@dxos/protocols");
153
155
  var import_services6 = require("@dxos/protocols/proto/dxos/client/services");
156
+ var import_tracing4 = require("@dxos/tracing");
157
+ var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
154
158
  var import_async10 = require("@dxos/async");
155
159
  var import_client_protocol3 = require("@dxos/client-protocol");
156
160
  var import_context6 = require("@dxos/context");
157
161
  var import_debug4 = require("@dxos/debug");
158
162
  var import_echo_pipeline = require("@dxos/echo-pipeline");
163
+ var import_invariant10 = require("@dxos/invariant");
159
164
  var import_keys7 = require("@dxos/keys");
160
165
  var import_log9 = require("@dxos/log");
161
- var import_protocols6 = require("@dxos/protocols");
162
- var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
166
+ var import_protocols8 = require("@dxos/protocols");
167
+ var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
163
168
  var import_credentials10 = require("@dxos/protocols/proto/dxos/halo/credentials");
164
169
  var import_timeframe2 = require("@dxos/timeframe");
165
- var import_tracing4 = require("@dxos/tracing");
170
+ var import_tracing5 = require("@dxos/tracing");
166
171
  var import_util4 = require("@dxos/util");
167
172
  var import_credentials11 = require("@dxos/credentials");
168
173
  var import_async11 = require("@dxos/async");
169
174
  var import_context7 = require("@dxos/context");
170
- var import_invariant10 = require("@dxos/invariant");
175
+ var import_invariant11 = require("@dxos/invariant");
171
176
  var import_keys8 = require("@dxos/keys");
172
177
  var import_log10 = require("@dxos/log");
173
- var import_protocols7 = require("@dxos/protocols");
178
+ var import_protocols9 = require("@dxos/protocols");
174
179
  var import_teleport2 = require("@dxos/teleport");
175
180
  var import_util5 = require("@dxos/util");
176
181
  var import_async12 = require("@dxos/async");
177
182
  var import_context8 = require("@dxos/context");
178
183
  var import_credentials12 = require("@dxos/credentials");
179
- var import_invariant11 = require("@dxos/invariant");
184
+ var import_invariant12 = require("@dxos/invariant");
180
185
  var import_keys9 = require("@dxos/keys");
181
186
  var import_log11 = require("@dxos/log");
182
- var import_protocols8 = require("@dxos/protocols");
183
- var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
187
+ var import_protocols10 = require("@dxos/protocols");
188
+ var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
184
189
  var import_teleport_extension_gossip = require("@dxos/teleport-extension-gossip");
185
190
  var import_util6 = require("@dxos/util");
186
191
  var import_credentials13 = require("@dxos/credentials");
@@ -190,30 +195,30 @@ var import_timeframe3 = require("@dxos/timeframe");
190
195
  var import_async13 = require("@dxos/async");
191
196
  var import_codec_protobuf11 = require("@dxos/codec-protobuf");
192
197
  var import_debug6 = require("@dxos/debug");
193
- var import_invariant12 = require("@dxos/invariant");
198
+ var import_invariant13 = require("@dxos/invariant");
194
199
  var import_log12 = require("@dxos/log");
195
- var import_protocols9 = require("@dxos/protocols");
196
- var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
200
+ var import_protocols11 = require("@dxos/protocols");
201
+ var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
197
202
  var import_async14 = require("@dxos/async");
198
203
  var import_context9 = require("@dxos/context");
199
204
  var import_credentials15 = require("@dxos/credentials");
200
205
  var import_debug7 = require("@dxos/debug");
201
206
  var import_echo_pipeline2 = require("@dxos/echo-pipeline");
202
207
  var import_feed_store4 = require("@dxos/feed-store");
203
- var import_invariant13 = require("@dxos/invariant");
208
+ var import_invariant14 = require("@dxos/invariant");
204
209
  var import_keyring = require("@dxos/keyring");
205
210
  var import_keys10 = require("@dxos/keys");
206
211
  var import_log13 = require("@dxos/log");
207
- var import_protocols10 = require("@dxos/protocols");
208
- var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
212
+ var import_protocols12 = require("@dxos/protocols");
213
+ var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
209
214
  var import_teleport_extension_object_sync = require("@dxos/teleport-extension-object-sync");
210
- var import_tracing5 = require("@dxos/tracing");
215
+ var import_tracing6 = require("@dxos/tracing");
211
216
  var import_util7 = require("@dxos/util");
212
- var import_invariant14 = require("@dxos/invariant");
217
+ var import_invariant15 = require("@dxos/invariant");
213
218
  var import_lock_file = require("@dxos/lock-file");
214
219
  var import_log14 = require("@dxos/log");
215
220
  var import_client_protocol4 = require("@dxos/client-protocol");
216
- var import_protocols11 = require("@dxos/protocols");
221
+ var import_protocols13 = require("@dxos/protocols");
217
222
  var import_config = require("@dxos/protocols/proto/dxos/config");
218
223
  var import_random_access_storage = require("@dxos/random-access-storage");
219
224
  var import_util8 = require("@dxos/util");
@@ -223,28 +228,28 @@ var import_context10 = require("@dxos/context");
223
228
  var import_document_model2 = require("@dxos/document-model");
224
229
  var import_echo_pipeline3 = require("@dxos/echo-pipeline");
225
230
  var import_echo_schema = require("@dxos/echo-schema");
226
- var import_invariant15 = require("@dxos/invariant");
231
+ var import_invariant16 = require("@dxos/invariant");
227
232
  var import_keys11 = require("@dxos/keys");
228
233
  var import_log15 = require("@dxos/log");
229
234
  var import_messaging = require("@dxos/messaging");
230
235
  var import_model_factory = require("@dxos/model-factory");
231
236
  var import_network_manager2 = require("@dxos/network-manager");
232
- var import_protocols12 = require("@dxos/protocols");
233
- var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
237
+ var import_protocols14 = require("@dxos/protocols");
238
+ var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
234
239
  var import_text_model = require("@dxos/text-model");
235
- var import_tracing6 = require("@dxos/tracing");
240
+ var import_tracing7 = require("@dxos/tracing");
236
241
  var import_websocket_rpc = require("@dxos/websocket-rpc");
237
242
  var import_async16 = require("@dxos/async");
238
243
  var import_codec_protobuf12 = require("@dxos/codec-protobuf");
239
- var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
244
+ var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
240
245
  var import_async17 = require("@dxos/async");
241
246
  var import_codec_protobuf13 = require("@dxos/codec-protobuf");
242
247
  var import_log16 = require("@dxos/log");
243
- var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
248
+ var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
244
249
  var import_util9 = require("@dxos/util");
245
250
  var import_codec_protobuf14 = require("@dxos/codec-protobuf");
246
251
  var import_codec_protobuf15 = require("@dxos/codec-protobuf");
247
- var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
252
+ var import_services15 = require("@dxos/protocols/proto/dxos/client/services");
248
253
  var import_util10 = require("@dxos/util");
249
254
  var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
250
255
  return new import_codec_protobuf.Stream(({ next }) => {
@@ -675,7 +680,7 @@ function _ts_decorate(decorators, target, key, desc) {
675
680
  return c > 3 && r && Object.defineProperty(target, key, r), r;
676
681
  }
677
682
  var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity.ts";
678
- var Identity = class Identity2 {
683
+ var Identity = class {
679
684
  constructor({ space, signer, identityKey, deviceKey }) {
680
685
  this.stateUpdate = new import_async5.Event();
681
686
  this.space = space;
@@ -843,7 +848,7 @@ function _ts_decorate2(decorators, target, key, desc) {
843
848
  return c > 3 && r && Object.defineProperty(target, key, r), r;
844
849
  }
845
850
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-manager.ts";
846
- var IdentityManager = class IdentityManager2 {
851
+ var IdentityManager = class {
847
852
  // TODO(burdon): IdentityManagerParams.
848
853
  // TODO(dmaretskyi): Perhaps this should take/generate the peerKey outside of an initialized identity.
849
854
  constructor(_metadataStore, _keyring, _feedStore, _spaceManager) {
@@ -1174,7 +1179,7 @@ var IdentityManager = class IdentityManager2 {
1174
1179
  genesisFeedKey: spaceRecord.genesisFeedKey
1175
1180
  },
1176
1181
  swarmIdentity,
1177
- onNetworkConnection: () => {
1182
+ onAuthorizedConnection: () => {
1178
1183
  },
1179
1184
  onAuthFailure: () => {
1180
1185
  import_log3.log.warn("auth failure", void 0, {
@@ -1197,6 +1202,7 @@ IdentityManager = _ts_decorate2([
1197
1202
  import_tracing2.trace.resource()
1198
1203
  ], IdentityManager);
1199
1204
  var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
1205
+ var CREATE_PROFILE_WITH_AUTOMERGE_DEFAULT = true;
1200
1206
  var IdentityServiceImpl = class {
1201
1207
  constructor(_createIdentity, _identityManager, _keyring, _onProfileUpdate) {
1202
1208
  this._createIdentity = _createIdentity;
@@ -1205,7 +1211,7 @@ var IdentityServiceImpl = class {
1205
1211
  this._onProfileUpdate = _onProfileUpdate;
1206
1212
  }
1207
1213
  async createIdentity(request) {
1208
- await this._createIdentity(request);
1214
+ await this._createIdentity(request.profile ?? {}, request.useAutomerge ?? CREATE_PROFILE_WITH_AUTOMERGE_DEFAULT);
1209
1215
  return this._getIdentity();
1210
1216
  }
1211
1217
  async recoverIdentity(request) {
@@ -1233,7 +1239,7 @@ var IdentityServiceImpl = class {
1233
1239
  async updateProfile(profile) {
1234
1240
  (0, import_invariant3.invariant)(this._identityManager.identity, "Identity not initialized.", {
1235
1241
  F: __dxlog_file4,
1236
- L: 60,
1242
+ L: 63,
1237
1243
  S: this,
1238
1244
  A: [
1239
1245
  "this._identityManager.identity",
@@ -1247,7 +1253,7 @@ var IdentityServiceImpl = class {
1247
1253
  async signPresentation({ presentation, nonce }) {
1248
1254
  (0, import_invariant3.invariant)(this._identityManager.identity, "Identity not initialized.", {
1249
1255
  F: __dxlog_file4,
1250
- L: 67,
1256
+ L: 70,
1251
1257
  S: this,
1252
1258
  A: [
1253
1259
  "this._identityManager.identity",
@@ -1281,7 +1287,7 @@ var DeviceInvitationProtocol = class {
1281
1287
  async admit(request) {
1282
1288
  (0, import_invariant4.invariant)(request.device, void 0, {
1283
1289
  F: __dxlog_file5,
1284
- L: 35,
1290
+ L: 36,
1285
1291
  S: this,
1286
1292
  A: [
1287
1293
  "request.device",
@@ -1299,6 +1305,15 @@ var DeviceInvitationProtocol = class {
1299
1305
  }
1300
1306
  };
1301
1307
  }
1308
+ checkInvitation(invitation) {
1309
+ try {
1310
+ const identity = this._getIdentity();
1311
+ if (identity) {
1312
+ return new import_protocols3.AlreadyJoinedError("Currently only one identity per client is supported.");
1313
+ }
1314
+ } catch {
1315
+ }
1316
+ }
1302
1317
  createIntroduction() {
1303
1318
  return {};
1304
1319
  }
@@ -1317,7 +1332,7 @@ var DeviceInvitationProtocol = class {
1317
1332
  async accept(response, request) {
1318
1333
  (0, import_invariant4.invariant)(response.device, void 0, {
1319
1334
  F: __dxlog_file5,
1320
- L: 68,
1335
+ L: 80,
1321
1336
  S: this,
1322
1337
  A: [
1323
1338
  "response.device",
@@ -1327,7 +1342,7 @@ var DeviceInvitationProtocol = class {
1327
1342
  const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
1328
1343
  (0, import_invariant4.invariant)(request.device, void 0, {
1329
1344
  F: __dxlog_file5,
1330
- L: 71,
1345
+ L: 83,
1331
1346
  S: this,
1332
1347
  A: [
1333
1348
  "request.device",
@@ -1356,10 +1371,10 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1356
1371
  constructor(_callbacks) {
1357
1372
  super({
1358
1373
  requested: {
1359
- InvitationHostService: import_protocols4.schema.getService("dxos.halo.invitations.InvitationHostService")
1374
+ InvitationHostService: import_protocols5.schema.getService("dxos.halo.invitations.InvitationHostService")
1360
1375
  },
1361
1376
  exposed: {
1362
- InvitationHostService: import_protocols4.schema.getService("dxos.halo.invitations.InvitationHostService")
1377
+ InvitationHostService: import_protocols5.schema.getService("dxos.halo.invitations.InvitationHostService")
1363
1378
  }
1364
1379
  });
1365
1380
  this._callbacks = _callbacks;
@@ -1392,7 +1407,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1392
1407
  introduce: async (request) => {
1393
1408
  const { profile, invitationId } = request;
1394
1409
  const traceId = import_keys6.PublicKey.random().toHex();
1395
- import_log5.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols4.trace.begin({
1410
+ import_log5.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols5.trace.begin({
1396
1411
  id: traceId
1397
1412
  }), {
1398
1413
  F: __dxlog_file6,
@@ -1429,7 +1444,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1429
1444
  ...this.invitation,
1430
1445
  state: import_services3.Invitation.State.READY_FOR_AUTHENTICATION
1431
1446
  });
1432
- import_log5.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols4.trace.end({
1447
+ import_log5.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols5.trace.end({
1433
1448
  id: traceId
1434
1449
  }), {
1435
1450
  F: __dxlog_file6,
@@ -1443,7 +1458,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1443
1458
  },
1444
1459
  authenticate: async ({ authCode: code }) => {
1445
1460
  const traceId = import_keys6.PublicKey.random().toHex();
1446
- import_log5.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols4.trace.begin({
1461
+ import_log5.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols5.trace.begin({
1447
1462
  id: traceId
1448
1463
  }), {
1449
1464
  F: __dxlog_file6,
@@ -1506,7 +1521,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1506
1521
  break;
1507
1522
  }
1508
1523
  }
1509
- import_log5.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols4.trace.end({
1524
+ import_log5.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols5.trace.end({
1510
1525
  id: traceId,
1511
1526
  data: {
1512
1527
  status
@@ -1523,7 +1538,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1523
1538
  },
1524
1539
  admit: async (request) => {
1525
1540
  const traceId = import_keys6.PublicKey.random().toHex();
1526
- import_log5.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols4.trace.begin({
1541
+ import_log5.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols5.trace.begin({
1527
1542
  id: traceId
1528
1543
  }), {
1529
1544
  F: __dxlog_file6,
@@ -1545,7 +1560,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1545
1560
  throw new Error("Not authenticated");
1546
1561
  }
1547
1562
  const response = await this._callbacks.admit(request);
1548
- import_log5.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols4.trace.end({
1563
+ import_log5.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols5.trace.end({
1549
1564
  id: traceId
1550
1565
  }), {
1551
1566
  F: __dxlog_file6,
@@ -1572,7 +1587,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1572
1587
  timeout: OPTIONS_TIMEOUT
1573
1588
  }));
1574
1589
  if (this._remoteOptions?.role !== import_invitations2.Options.Role.GUEST) {
1575
- throw new import_protocols4.InvalidInvitationExtensionRoleError(void 0, {
1590
+ throw new import_protocols5.InvalidInvitationExtensionRoleError(void 0, {
1576
1591
  expected: import_invitations2.Options.Role.GUEST,
1577
1592
  remoteOptions: this._remoteOptions
1578
1593
  });
@@ -1590,10 +1605,10 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1590
1605
  constructor(_callbacks) {
1591
1606
  super({
1592
1607
  requested: {
1593
- InvitationHostService: import_protocols4.schema.getService("dxos.halo.invitations.InvitationHostService")
1608
+ InvitationHostService: import_protocols5.schema.getService("dxos.halo.invitations.InvitationHostService")
1594
1609
  },
1595
1610
  exposed: {
1596
- InvitationHostService: import_protocols4.schema.getService("dxos.halo.invitations.InvitationHostService")
1611
+ InvitationHostService: import_protocols5.schema.getService("dxos.halo.invitations.InvitationHostService")
1597
1612
  }
1598
1613
  });
1599
1614
  this._callbacks = _callbacks;
@@ -1650,7 +1665,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1650
1665
  C: (f, a) => f(...a)
1651
1666
  });
1652
1667
  if (this._remoteOptions?.role !== import_invitations2.Options.Role.HOST) {
1653
- throw new import_protocols4.InvalidInvitationExtensionRoleError(void 0, {
1668
+ throw new import_protocols5.InvalidInvitationExtensionRoleError(void 0, {
1654
1669
  expected: import_invitations2.Options.Role.HOST,
1655
1670
  remoteOptions: this._remoteOptions
1656
1671
  });
@@ -1763,7 +1778,7 @@ var InvitationsHandler = class {
1763
1778
  (0, import_async7.scheduleTask)(ctx, async () => {
1764
1779
  const traceId = import_keys5.PublicKey.random().toHex();
1765
1780
  try {
1766
- import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols3.trace.begin({
1781
+ import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.begin({
1767
1782
  id: traceId
1768
1783
  }), {
1769
1784
  F: __dxlog_file7,
@@ -1799,7 +1814,7 @@ var InvitationsHandler = class {
1799
1814
  ...invitation,
1800
1815
  state: import_services2.Invitation.State.SUCCESS
1801
1816
  });
1802
- import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols3.trace.end({
1817
+ import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.end({
1803
1818
  id: traceId
1804
1819
  }), {
1805
1820
  F: __dxlog_file7,
@@ -1830,7 +1845,7 @@ var InvitationsHandler = class {
1830
1845
  });
1831
1846
  stream.error(err);
1832
1847
  }
1833
- import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols3.trace.error({
1848
+ import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.error({
1834
1849
  id: traceId,
1835
1850
  error: err
1836
1851
  }), {
@@ -1848,7 +1863,7 @@ var InvitationsHandler = class {
1848
1863
  });
1849
1864
  },
1850
1865
  onError: (err) => {
1851
- if (err instanceof import_protocols3.InvalidInvitationExtensionRoleError) {
1866
+ if (err instanceof import_protocols4.InvalidInvitationExtensionRoleError) {
1852
1867
  return;
1853
1868
  }
1854
1869
  if (err instanceof import_async7.TimeoutError) {
@@ -1996,7 +2011,7 @@ var InvitationsHandler = class {
1996
2011
  (0, import_async7.scheduleTask)(ctx, async () => {
1997
2012
  const traceId = import_keys5.PublicKey.random().toHex();
1998
2013
  try {
1999
- import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols3.trace.begin({
2014
+ import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.begin({
2000
2015
  id: traceId
2001
2016
  }), {
2002
2017
  F: __dxlog_file7,
@@ -2083,16 +2098,12 @@ var InvitationsHandler = class {
2083
2098
  }
2084
2099
  }
2085
2100
  }
2086
- } else {
2087
- setState({
2088
- state: import_services2.Invitation.State.READY_FOR_AUTHENTICATION
2089
- });
2090
2101
  }
2091
2102
  (0, import_log4.log)("request admission", {
2092
2103
  ...protocol.toJSON()
2093
2104
  }, {
2094
2105
  F: __dxlog_file7,
2095
- L: 312,
2106
+ L: 309,
2096
2107
  S: this,
2097
2108
  C: (f, a) => f(...a)
2098
2109
  });
@@ -2104,19 +2115,20 @@ var InvitationsHandler = class {
2104
2115
  ...protocol.toJSON()
2105
2116
  }, {
2106
2117
  F: __dxlog_file7,
2107
- L: 323,
2118
+ L: 320,
2108
2119
  S: this,
2109
2120
  C: (f, a) => f(...a)
2110
2121
  });
2111
2122
  setState({
2112
2123
  ...result,
2124
+ target: invitation.target,
2113
2125
  state: import_services2.Invitation.State.SUCCESS
2114
2126
  });
2115
- import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols3.trace.end({
2127
+ import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.end({
2116
2128
  id: traceId
2117
2129
  }), {
2118
2130
  F: __dxlog_file7,
2119
- L: 325,
2131
+ L: 322,
2120
2132
  S: this,
2121
2133
  C: (f, a) => f(...a)
2122
2134
  });
@@ -2126,7 +2138,7 @@ var InvitationsHandler = class {
2126
2138
  ...protocol.toJSON()
2127
2139
  }, {
2128
2140
  F: __dxlog_file7,
2129
- L: 328,
2141
+ L: 325,
2130
2142
  S: this,
2131
2143
  C: (f, a) => f(...a)
2132
2144
  });
@@ -2136,18 +2148,18 @@ var InvitationsHandler = class {
2136
2148
  } else {
2137
2149
  (0, import_log4.log)("auth failed", err, {
2138
2150
  F: __dxlog_file7,
2139
- L: 331,
2151
+ L: 328,
2140
2152
  S: this,
2141
2153
  C: (f, a) => f(...a)
2142
2154
  });
2143
2155
  stream.error(err);
2144
2156
  }
2145
- import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols3.trace.error({
2157
+ import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.error({
2146
2158
  id: traceId,
2147
2159
  error: err
2148
2160
  }), {
2149
2161
  F: __dxlog_file7,
2150
- L: 334,
2162
+ L: 331,
2151
2163
  S: this,
2152
2164
  C: (f, a) => f(...a)
2153
2165
  });
@@ -2157,7 +2169,7 @@ var InvitationsHandler = class {
2157
2169
  });
2158
2170
  },
2159
2171
  onError: (err) => {
2160
- if (err instanceof import_protocols3.InvalidInvitationExtensionRoleError) {
2172
+ if (err instanceof import_protocols4.InvalidInvitationExtensionRoleError) {
2161
2173
  return;
2162
2174
  }
2163
2175
  if (err instanceof import_async7.TimeoutError) {
@@ -2165,7 +2177,7 @@ var InvitationsHandler = class {
2165
2177
  ...protocol.toJSON()
2166
2178
  }, {
2167
2179
  F: __dxlog_file7,
2168
- L: 345,
2180
+ L: 342,
2169
2181
  S: this,
2170
2182
  C: (f, a) => f(...a)
2171
2183
  });
@@ -2175,7 +2187,7 @@ var InvitationsHandler = class {
2175
2187
  } else {
2176
2188
  (0, import_log4.log)("auth failed", err, {
2177
2189
  F: __dxlog_file7,
2178
- L: 348,
2190
+ L: 345,
2179
2191
  S: this,
2180
2192
  C: (f, a) => f(...a)
2181
2193
  });
@@ -2186,29 +2198,34 @@ var InvitationsHandler = class {
2186
2198
  return extension;
2187
2199
  };
2188
2200
  (0, import_async7.scheduleTask)(ctx, async () => {
2189
- (0, import_invariant5.invariant)(invitation.swarmKey, void 0, {
2190
- F: __dxlog_file7,
2191
- L: 358,
2192
- S: this,
2193
- A: [
2194
- "invitation.swarmKey",
2195
- ""
2196
- ]
2197
- });
2198
- const topic = invitation.swarmKey;
2199
- const swarmConnection = await this._networkManager.joinSwarm({
2200
- topic,
2201
- peerId: import_keys5.PublicKey.random(),
2202
- protocolProvider: (0, import_network_manager.createTeleportProtocolFactory)(async (teleport) => {
2203
- teleport.addExtension("dxos.halo.invitations", createExtension());
2204
- }),
2205
- topology: new import_network_manager.StarTopology(topic),
2206
- label: "invitation guest"
2207
- });
2208
- ctx.onDispose(() => swarmConnection.close());
2209
- setState({
2210
- state: import_services2.Invitation.State.CONNECTING
2211
- });
2201
+ const error = protocol.checkInvitation(invitation);
2202
+ if (error) {
2203
+ stream.error(error);
2204
+ } else {
2205
+ (0, import_invariant5.invariant)(invitation.swarmKey, void 0, {
2206
+ F: __dxlog_file7,
2207
+ L: 359,
2208
+ S: this,
2209
+ A: [
2210
+ "invitation.swarmKey",
2211
+ ""
2212
+ ]
2213
+ });
2214
+ const topic = invitation.swarmKey;
2215
+ const swarmConnection = await this._networkManager.joinSwarm({
2216
+ topic,
2217
+ peerId: import_keys5.PublicKey.random(),
2218
+ protocolProvider: (0, import_network_manager.createTeleportProtocolFactory)(async (teleport) => {
2219
+ teleport.addExtension("dxos.halo.invitations", createExtension());
2220
+ }),
2221
+ topology: new import_network_manager.StarTopology(topic),
2222
+ label: "invitation guest"
2223
+ });
2224
+ ctx.onDispose(() => swarmConnection.close());
2225
+ setState({
2226
+ state: import_services2.Invitation.State.CONNECTING
2227
+ });
2228
+ }
2212
2229
  });
2213
2230
  const observable = new import_client_protocol2.AuthenticatingInvitation({
2214
2231
  initialInvitation: invitation,
@@ -2424,7 +2441,7 @@ var SpaceInvitationProtocol = class {
2424
2441
  async admit(request, guestProfile) {
2425
2442
  (0, import_invariant8.invariant)(this._spaceKey, void 0, {
2426
2443
  F: __dxlog_file9,
2427
- L: 46,
2444
+ L: 47,
2428
2445
  S: this,
2429
2446
  A: [
2430
2447
  "this._spaceKey",
@@ -2434,7 +2451,7 @@ var SpaceInvitationProtocol = class {
2434
2451
  const space = await this._spaceManager.spaces.get(this._spaceKey);
2435
2452
  (0, import_invariant8.invariant)(space, void 0, {
2436
2453
  F: __dxlog_file9,
2437
- L: 48,
2454
+ L: 49,
2438
2455
  S: this,
2439
2456
  A: [
2440
2457
  "space",
@@ -2443,7 +2460,7 @@ var SpaceInvitationProtocol = class {
2443
2460
  });
2444
2461
  (0, import_invariant8.invariant)(request.space, void 0, {
2445
2462
  F: __dxlog_file9,
2446
- L: 50,
2463
+ L: 51,
2447
2464
  S: this,
2448
2465
  A: [
2449
2466
  "request.space",
@@ -2456,14 +2473,14 @@ var SpaceInvitationProtocol = class {
2456
2473
  guest: deviceKey
2457
2474
  }, {
2458
2475
  F: __dxlog_file9,
2459
- L: 53,
2476
+ L: 54,
2460
2477
  S: this,
2461
2478
  C: (f, a) => f(...a)
2462
2479
  });
2463
2480
  const credentials = await (0, import_credentials8.createAdmissionCredentials)(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile);
2464
2481
  (0, import_invariant8.invariant)(credentials[0].credential, void 0, {
2465
2482
  F: __dxlog_file9,
2466
- L: 64,
2483
+ L: 65,
2467
2484
  S: this,
2468
2485
  A: [
2469
2486
  "credentials[0].credential",
@@ -2473,7 +2490,7 @@ var SpaceInvitationProtocol = class {
2473
2490
  const spaceMemberCredential = credentials[0].credential.credential;
2474
2491
  (0, import_invariant8.invariant)((0, import_credentials8.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2475
2492
  F: __dxlog_file9,
2476
- L: 66,
2493
+ L: 67,
2477
2494
  S: this,
2478
2495
  A: [
2479
2496
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2489,6 +2506,11 @@ var SpaceInvitationProtocol = class {
2489
2506
  }
2490
2507
  };
2491
2508
  }
2509
+ checkInvitation(invitation) {
2510
+ if (invitation.spaceKey && this._spaceManager.spaces.has(invitation.spaceKey)) {
2511
+ return new import_protocols6.AlreadyJoinedError("Already joined space.");
2512
+ }
2513
+ }
2492
2514
  createIntroduction() {
2493
2515
  return {
2494
2516
  profile: this._signingContext.getProfile()
@@ -2509,7 +2531,7 @@ var SpaceInvitationProtocol = class {
2509
2531
  async accept(response) {
2510
2532
  (0, import_invariant8.invariant)(response.space, void 0, {
2511
2533
  F: __dxlog_file9,
2512
- L: 101,
2534
+ L: 108,
2513
2535
  S: this,
2514
2536
  A: [
2515
2537
  "response.space",
@@ -2520,7 +2542,7 @@ var SpaceInvitationProtocol = class {
2520
2542
  const assertion = (0, import_credentials8.getCredentialAssertion)(credential);
2521
2543
  (0, import_invariant8.invariant)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2522
2544
  F: __dxlog_file9,
2523
- L: 104,
2545
+ L: 111,
2524
2546
  S: this,
2525
2547
  A: [
2526
2548
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2529,13 +2551,16 @@ var SpaceInvitationProtocol = class {
2529
2551
  });
2530
2552
  (0, import_invariant8.invariant)(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
2531
2553
  F: __dxlog_file9,
2532
- L: 105,
2554
+ L: 112,
2533
2555
  S: this,
2534
2556
  A: [
2535
2557
  "credential.subject.id.equals(this._signingContext.identityKey)",
2536
2558
  ""
2537
2559
  ]
2538
2560
  });
2561
+ if (this._spaceManager.spaces.has(assertion.spaceKey)) {
2562
+ throw new import_protocols6.AlreadyJoinedError("Already joined space.");
2563
+ }
2539
2564
  await this._spaceManager.acceptSpace({
2540
2565
  spaceKey: assertion.spaceKey,
2541
2566
  genesisFeedKey: assertion.genesisFeedKey,
@@ -2558,7 +2583,7 @@ function _ts_decorate3(decorators, target, key, desc) {
2558
2583
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2559
2584
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2560
2585
  }
2561
- var ClientRpcServer = class ClientRpcServer2 {
2586
+ var ClientRpcServer = class {
2562
2587
  constructor(params) {
2563
2588
  this._handlerCache = /* @__PURE__ */ new Map();
2564
2589
  this._callMetrics = new import_tracing3.MapCounter();
@@ -2628,28 +2653,29 @@ var getPlatform = () => {
2628
2653
  if (typeof window !== "undefined") {
2629
2654
  const { userAgent } = window.navigator;
2630
2655
  return {
2631
- type: "browser",
2656
+ type: import_services7.Platform.PLATFORM_TYPE.BROWSER,
2632
2657
  userAgent,
2633
2658
  uptime: Math.floor((Date.now() - window.performance.timeOrigin) / 1e3)
2634
2659
  };
2635
2660
  } else {
2636
2661
  return {
2637
- type: "shared-worker",
2662
+ type: import_services7.Platform.PLATFORM_TYPE.SHARED_WORKER,
2638
2663
  uptime: Math.floor((Date.now() - performance.timeOrigin) / 1e3)
2639
2664
  };
2640
2665
  }
2641
2666
  } else {
2642
2667
  const { platform: platform2, version, arch } = process;
2643
2668
  return {
2644
- type: "node",
2645
- platform: `${platform2} ${version} ${arch}`,
2646
- runtime: process.version,
2669
+ type: import_services7.Platform.PLATFORM_TYPE.NODE,
2670
+ platform: platform2,
2671
+ arch,
2672
+ runtime: version,
2647
2673
  uptime: Math.floor(process.uptime()),
2648
2674
  memory: process.memoryUsage()
2649
2675
  };
2650
2676
  }
2651
2677
  };
2652
- var DXOS_VERSION = "0.3.11-next.0fb359e";
2678
+ var DXOS_VERSION = "0.3.11-next.ee2b64c";
2653
2679
  var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
2654
2680
  var DEFAULT_TIMEOUT = 1e3;
2655
2681
  var createDiagnostics = async (clientServices, serviceContext, config) => {
@@ -2659,14 +2685,15 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
2659
2685
  client: {
2660
2686
  version: DXOS_VERSION,
2661
2687
  storage: {
2662
- version: import_protocols5.STORAGE_VERSION
2688
+ version: import_protocols7.STORAGE_VERSION
2663
2689
  }
2664
- }
2690
+ },
2691
+ trace: import_tracing4.TRACE_PROCESSOR.getDiagnostics()
2665
2692
  };
2666
2693
  {
2667
2694
  (0, import_invariant9.invariant)(clientServices.LoggingService, "SystemService is not available.", {
2668
2695
  F: __dxlog_file10,
2669
- L: 92,
2696
+ L: 111,
2670
2697
  S: void 0,
2671
2698
  A: [
2672
2699
  "clientServices.LoggingService",
@@ -2677,6 +2704,21 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
2677
2704
  timeout: DEFAULT_TIMEOUT
2678
2705
  }).catch(() => void 0);
2679
2706
  }
2707
+ if (typeof navigator !== "undefined" && navigator.storage) {
2708
+ const map = /* @__PURE__ */ new Map();
2709
+ const dir = await navigator.storage.getDirectory();
2710
+ for await (const filename of dir?.keys()) {
2711
+ const idx = filename.indexOf("-", filename.indexOf("-") + 1);
2712
+ if (idx === -1) {
2713
+ continue;
2714
+ }
2715
+ map.set(filename.slice(0, idx), (map.get(filename.slice(0, idx)) ?? 0) + 1);
2716
+ }
2717
+ diagnostics.storage = Array.from(map.entries()).sort((a, b) => b[1] - a[1]).map(([file, count]) => ({
2718
+ file,
2719
+ count
2720
+ }));
2721
+ }
2680
2722
  const identity = serviceContext.identityManager.identity;
2681
2723
  if (identity) {
2682
2724
  diagnostics.identity = {
@@ -2717,7 +2759,7 @@ var getProperties = (space) => {
2717
2759
  } catch (err) {
2718
2760
  import_log8.log.warn(err.message, void 0, {
2719
2761
  F: __dxlog_file10,
2720
- L: 160,
2762
+ L: 196,
2721
2763
  S: void 0,
2722
2764
  C: (f, a) => f(...a)
2723
2765
  });
@@ -2772,7 +2814,8 @@ var getSpaceStats = async (space) => {
2772
2814
  return stats;
2773
2815
  };
2774
2816
  var AutomergeSpaceState = class {
2775
- constructor() {
2817
+ constructor(_onNewRoot) {
2818
+ this._onNewRoot = _onNewRoot;
2776
2819
  this.rootUrl = void 0;
2777
2820
  this.lastEpoch = void 0;
2778
2821
  }
@@ -2783,6 +2826,7 @@ var AutomergeSpaceState = class {
2783
2826
  this.lastEpoch = credential;
2784
2827
  if (credential.subject.assertion.automergeRoot) {
2785
2828
  this.rootUrl = credential.subject.assertion.automergeRoot;
2829
+ this._onNewRoot(this.rootUrl);
2786
2830
  }
2787
2831
  }
2788
2832
  };
@@ -2819,7 +2863,7 @@ var NotarizationPlugin = class {
2819
2863
  S: this,
2820
2864
  C: (f, a) => f(...a)
2821
2865
  });
2822
- (0, import_invariant10.invariant)(credentials.every((credential) => credential.id), "Credentials must have an id", {
2866
+ (0, import_invariant11.invariant)(credentials.every((credential) => credential.id), "Credentials must have an id", {
2823
2867
  F: __dxlog_file11,
2824
2868
  L: 91,
2825
2869
  S: this,
@@ -2944,7 +2988,7 @@ var NotarizationPlugin = class {
2944
2988
  this._processCredentialsTriggers.delete(credential.id);
2945
2989
  }
2946
2990
  setWriter(writer) {
2947
- (0, import_invariant10.invariant)(!this._writer, "Writer already set.", {
2991
+ (0, import_invariant11.invariant)(!this._writer, "Writer already set.", {
2948
2992
  F: __dxlog_file11,
2949
2993
  L: 181,
2950
2994
  S: this,
@@ -2969,7 +3013,7 @@ var NotarizationPlugin = class {
2969
3013
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
2970
3014
  }
2971
3015
  for (const credential of request.credentials ?? []) {
2972
- (0, import_invariant10.invariant)(credential.id, "Credential must have an id", {
3016
+ (0, import_invariant11.invariant)(credential.id, "Credential must have an id", {
2973
3017
  F: __dxlog_file11,
2974
3018
  L: 200,
2975
3019
  S: this,
@@ -3018,10 +3062,10 @@ var NotarizationTeleportExtension = class extends import_teleport2.RpcExtension
3018
3062
  constructor(_params) {
3019
3063
  super({
3020
3064
  requested: {
3021
- NotarizationService: import_protocols7.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3065
+ NotarizationService: import_protocols9.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3022
3066
  },
3023
3067
  exposed: {
3024
- NotarizationService: import_protocols7.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3068
+ NotarizationService: import_protocols9.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3025
3069
  }
3026
3070
  });
3027
3071
  this._params = _params;
@@ -3056,13 +3100,13 @@ function _ts_decorate4(decorators, target, key, desc) {
3056
3100
  }
3057
3101
  var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
3058
3102
  var ENABLE_FEED_PURGE = false;
3059
- var DataSpace = class DataSpace2 {
3103
+ var DataSpace = class {
3060
3104
  constructor(params) {
3061
3105
  this._ctx = new import_context6.Context();
3062
3106
  this._notarizationPlugin = new NotarizationPlugin();
3063
3107
  this._cache = void 0;
3064
- this._automergeSpaceState = new AutomergeSpaceState();
3065
- this._state = import_services7.SpaceState.CLOSED;
3108
+ this._automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
3109
+ this._state = import_services8.SpaceState.CLOSED;
3066
3110
  this.error = void 0;
3067
3111
  this.stateUpdate = new import_async10.Event();
3068
3112
  this.metrics = {};
@@ -3084,10 +3128,10 @@ var DataSpace = class DataSpace2 {
3084
3128
  this._cache = params.cache;
3085
3129
  this._state = params.initialState;
3086
3130
  (0, import_log9.log)("new state", {
3087
- state: import_services7.SpaceState[this._state]
3131
+ state: import_services8.SpaceState[this._state]
3088
3132
  }, {
3089
3133
  F: __dxlog_file12,
3090
- L: 137,
3134
+ L: 141,
3091
3135
  S: this,
3092
3136
  C: (f, a) => f(...a)
3093
3137
  });
@@ -3120,6 +3164,12 @@ var DataSpace = class DataSpace2 {
3120
3164
  get automergeSpaceState() {
3121
3165
  return this._automergeSpaceState;
3122
3166
  }
3167
+ get _automergeInfo() {
3168
+ return {
3169
+ rootUrl: this._automergeSpaceState.rootUrl,
3170
+ lastEpoch: this._automergeSpaceState.lastEpoch
3171
+ };
3172
+ }
3123
3173
  async open() {
3124
3174
  await this._open();
3125
3175
  }
@@ -3129,12 +3179,12 @@ var DataSpace = class DataSpace2 {
3129
3179
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
3130
3180
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
3131
3181
  await this._inner.open(new import_context6.Context());
3132
- this._state = import_services7.SpaceState.CONTROL_ONLY;
3182
+ this._state = import_services8.SpaceState.CONTROL_ONLY;
3133
3183
  (0, import_log9.log)("new state", {
3134
- state: import_services7.SpaceState[this._state]
3184
+ state: import_services8.SpaceState[this._state]
3135
3185
  }, {
3136
3186
  F: __dxlog_file12,
3137
- L: 189,
3187
+ L: 203,
3138
3188
  S: this,
3139
3189
  C: (f, a) => f(...a)
3140
3190
  });
@@ -3147,12 +3197,12 @@ var DataSpace = class DataSpace2 {
3147
3197
  }
3148
3198
  async _close() {
3149
3199
  await this._callbacks.beforeClose?.();
3150
- this._state = import_services7.SpaceState.CLOSED;
3200
+ this._state = import_services8.SpaceState.CLOSED;
3151
3201
  (0, import_log9.log)("new state", {
3152
- state: import_services7.SpaceState[this._state]
3202
+ state: import_services8.SpaceState[this._state]
3153
3203
  }, {
3154
3204
  F: __dxlog_file12,
3155
- L: 203,
3205
+ L: 217,
3156
3206
  S: this,
3157
3207
  C: (f, a) => f(...a)
3158
3208
  });
@@ -3181,10 +3231,10 @@ var DataSpace = class DataSpace2 {
3181
3231
  this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
3182
3232
  await this.initializeDataPipeline();
3183
3233
  } catch (err) {
3184
- if (err instanceof import_protocols6.CancelledError) {
3234
+ if (err instanceof import_protocols8.CancelledError || err instanceof import_context6.ContextDisposedError) {
3185
3235
  (0, import_log9.log)("data pipeline initialization cancelled", err, {
3186
3236
  F: __dxlog_file12,
3187
- L: 236,
3237
+ L: 250,
3188
3238
  S: this,
3189
3239
  C: (f, a) => f(...a)
3190
3240
  });
@@ -3192,16 +3242,16 @@ var DataSpace = class DataSpace2 {
3192
3242
  }
3193
3243
  import_log9.log.error("Error initializing data pipeline", err, {
3194
3244
  F: __dxlog_file12,
3195
- L: 240,
3245
+ L: 254,
3196
3246
  S: this,
3197
3247
  C: (f, a) => f(...a)
3198
3248
  });
3199
- this._state = import_services7.SpaceState.ERROR;
3249
+ this._state = import_services8.SpaceState.ERROR;
3200
3250
  (0, import_log9.log)("new state", {
3201
- state: import_services7.SpaceState[this._state]
3251
+ state: import_services8.SpaceState[this._state]
3202
3252
  }, {
3203
3253
  F: __dxlog_file12,
3204
- L: 242,
3254
+ L: 256,
3205
3255
  S: this,
3206
3256
  C: (f, a) => f(...a)
3207
3257
  });
@@ -3213,15 +3263,15 @@ var DataSpace = class DataSpace2 {
3213
3263
  });
3214
3264
  }
3215
3265
  async initializeDataPipeline() {
3216
- if (this._state !== import_services7.SpaceState.CONTROL_ONLY) {
3217
- throw new import_protocols6.SystemError("Invalid operation");
3266
+ if (this._state !== import_services8.SpaceState.CONTROL_ONLY) {
3267
+ throw new import_protocols8.SystemError("Invalid operation");
3218
3268
  }
3219
- this._state = import_services7.SpaceState.INITIALIZING;
3269
+ this._state = import_services8.SpaceState.INITIALIZING;
3220
3270
  (0, import_log9.log)("new state", {
3221
- state: import_services7.SpaceState[this._state]
3271
+ state: import_services8.SpaceState[this._state]
3222
3272
  }, {
3223
3273
  F: __dxlog_file12,
3224
- L: 258,
3274
+ L: 272,
3225
3275
  S: this,
3226
3276
  C: (f, a) => f(...a)
3227
3277
  });
@@ -3232,7 +3282,7 @@ var DataSpace = class DataSpace2 {
3232
3282
  await (0, import_context6.cancelWithContext)(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
3233
3283
  (0, import_log9.log)("waiting for data pipeline to reach target timeframe", void 0, {
3234
3284
  F: __dxlog_file12,
3235
- L: 272,
3285
+ L: 286,
3236
3286
  S: this,
3237
3287
  C: (f, a) => f(...a)
3238
3288
  });
@@ -3243,17 +3293,17 @@ var DataSpace = class DataSpace2 {
3243
3293
  this.metrics.dataPipelineReady = /* @__PURE__ */ new Date();
3244
3294
  (0, import_log9.log)("data pipeline ready", void 0, {
3245
3295
  F: __dxlog_file12,
3246
- L: 281,
3296
+ L: 295,
3247
3297
  S: this,
3248
3298
  C: (f, a) => f(...a)
3249
3299
  });
3250
3300
  await this._callbacks.beforeReady?.();
3251
- this._state = import_services7.SpaceState.READY;
3301
+ this._state = import_services8.SpaceState.READY;
3252
3302
  (0, import_log9.log)("new state", {
3253
- state: import_services7.SpaceState[this._state]
3303
+ state: import_services8.SpaceState[this._state]
3254
3304
  }, {
3255
3305
  F: __dxlog_file12,
3256
- L: 285,
3306
+ L: 299,
3257
3307
  S: this,
3258
3308
  C: (f, a) => f(...a)
3259
3309
  });
@@ -3269,7 +3319,7 @@ var DataSpace = class DataSpace2 {
3269
3319
  await this._createWritableFeeds();
3270
3320
  (0, import_log9.log)("writable feeds created", void 0, {
3271
3321
  F: __dxlog_file12,
3272
- L: 301,
3322
+ L: 315,
3273
3323
  S: this,
3274
3324
  C: (f, a) => f(...a)
3275
3325
  });
@@ -3326,6 +3376,40 @@ var DataSpace = class DataSpace2 {
3326
3376
  await this._metadataStore.setWritableFeedKeys(this.key, this.inner.controlFeedKey, this.inner.dataFeedKey);
3327
3377
  }
3328
3378
  }
3379
+ _onNewAutomergeRoot(rootUrl) {
3380
+ (0, import_log9.log)("loading automerge root doc for space", {
3381
+ space: this.key,
3382
+ rootUrl
3383
+ }, {
3384
+ F: __dxlog_file12,
3385
+ L: 381,
3386
+ S: this,
3387
+ C: (f, a) => f(...a)
3388
+ });
3389
+ const handle = this._automergeHost.repo.find(rootUrl);
3390
+ queueMicrotask(async () => {
3391
+ try {
3392
+ await (0, import_async10.asyncTimeout)(handle.whenReady(), 5e3);
3393
+ const doc = handle.docSync() ?? (0, import_invariant10.failedInvariant)();
3394
+ if (!doc.experimental_spaceKey) {
3395
+ handle.change((doc2) => {
3396
+ doc2.experimental_spaceKey = this.key.toHex();
3397
+ });
3398
+ }
3399
+ } catch (err) {
3400
+ import_log9.log.warn("error loading automerge root doc", {
3401
+ space: this.key,
3402
+ rootUrl,
3403
+ err
3404
+ }, {
3405
+ F: __dxlog_file12,
3406
+ L: 394,
3407
+ S: this,
3408
+ C: (f, a) => f(...a)
3409
+ });
3410
+ }
3411
+ });
3412
+ }
3329
3413
  // TODO(dmaretskyi): Use profile from signing context.
3330
3414
  async updateOwnProfile(profile) {
3331
3415
  const credential = await this._signingContext.credentialSigner.createCredential({
@@ -3345,12 +3429,12 @@ var DataSpace = class DataSpace2 {
3345
3429
  let epoch;
3346
3430
  switch (options?.migration) {
3347
3431
  case void 0:
3348
- case import_services7.CreateEpochRequest.Migration.NONE:
3432
+ case import_services8.CreateEpochRequest.Migration.NONE:
3349
3433
  {
3350
3434
  epoch = await this.dataPipeline.createEpoch();
3351
3435
  }
3352
3436
  break;
3353
- case import_services7.CreateEpochRequest.Migration.INIT_AUTOMERGE: {
3437
+ case import_services8.CreateEpochRequest.Migration.INIT_AUTOMERGE: {
3354
3438
  const document = this._automergeHost.repo.create();
3355
3439
  epoch = {
3356
3440
  previousId: this._automergeSpaceState.lastEpoch?.id,
@@ -3391,31 +3475,47 @@ var DataSpace = class DataSpace2 {
3391
3475
  }
3392
3476
  }
3393
3477
  async activate() {
3394
- if (this._state !== import_services7.SpaceState.INACTIVE) {
3478
+ if (this._state !== import_services8.SpaceState.INACTIVE) {
3395
3479
  return;
3396
3480
  }
3397
- await this._metadataStore.setSpaceState(this.key, import_services7.SpaceState.ACTIVE);
3481
+ await this._metadataStore.setSpaceState(this.key, import_services8.SpaceState.ACTIVE);
3398
3482
  await this._open();
3399
3483
  this.initializeDataPipelineAsync();
3400
3484
  }
3401
3485
  async deactivate() {
3402
- if (this._state === import_services7.SpaceState.INACTIVE) {
3486
+ if (this._state === import_services8.SpaceState.INACTIVE) {
3403
3487
  return;
3404
3488
  }
3405
- await this._metadataStore.setSpaceState(this.key, import_services7.SpaceState.INACTIVE);
3489
+ await this._metadataStore.setSpaceState(this.key, import_services8.SpaceState.INACTIVE);
3406
3490
  await this._close();
3407
- this._state = import_services7.SpaceState.INACTIVE;
3491
+ this._state = import_services8.SpaceState.INACTIVE;
3408
3492
  (0, import_log9.log)("new state", {
3409
- state: import_services7.SpaceState[this._state]
3493
+ state: import_services8.SpaceState[this._state]
3410
3494
  }, {
3411
3495
  F: __dxlog_file12,
3412
- L: 450,
3496
+ L: 483,
3413
3497
  S: this,
3414
3498
  C: (f, a) => f(...a)
3415
3499
  });
3416
3500
  this.stateUpdate.emit();
3417
3501
  }
3418
3502
  };
3503
+ _ts_decorate4([
3504
+ import_tracing5.trace.info()
3505
+ ], DataSpace.prototype, "_inner", void 0);
3506
+ _ts_decorate4([
3507
+ import_tracing5.trace.info()
3508
+ ], DataSpace.prototype, "key", null);
3509
+ _ts_decorate4([
3510
+ import_tracing5.trace.info({
3511
+ enum: import_services8.SpaceState
3512
+ })
3513
+ ], DataSpace.prototype, "state", null);
3514
+ _ts_decorate4([
3515
+ import_tracing5.trace.info({
3516
+ depth: null
3517
+ })
3518
+ ], DataSpace.prototype, "_automergeInfo", null);
3419
3519
  _ts_decorate4([
3420
3520
  import_async10.synchronized
3421
3521
  ], DataSpace.prototype, "open", null);
@@ -3423,12 +3523,12 @@ _ts_decorate4([
3423
3523
  import_async10.synchronized
3424
3524
  ], DataSpace.prototype, "close", null);
3425
3525
  _ts_decorate4([
3426
- import_tracing4.trace.span({
3526
+ import_tracing5.trace.span({
3427
3527
  showInBrowserTimeline: true
3428
3528
  })
3429
3529
  ], DataSpace.prototype, "initializeDataPipeline", null);
3430
3530
  _ts_decorate4([
3431
- import_tracing4.trace.span({
3531
+ import_tracing5.trace.span({
3432
3532
  showInBrowserTimeline: true
3433
3533
  })
3434
3534
  ], DataSpace.prototype, "_initializeAndReadControlPipeline", null);
@@ -3442,7 +3542,8 @@ _ts_decorate4([
3442
3542
  import_async10.synchronized
3443
3543
  ], DataSpace.prototype, "deactivate", null);
3444
3544
  DataSpace = _ts_decorate4([
3445
- (0, import_async10.trackLeaks)("open", "close")
3545
+ (0, import_async10.trackLeaks)("open", "close"),
3546
+ import_tracing5.trace.resource()
3446
3547
  ], DataSpace);
3447
3548
  var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3448
3549
  const credentials = [
@@ -3521,7 +3622,7 @@ function _ts_decorate5(decorators, target, key, desc) {
3521
3622
  var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
3522
3623
  var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
3523
3624
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
3524
- var DataSpaceManager = class DataSpaceManager2 {
3625
+ var DataSpaceManager = class {
3525
3626
  constructor(_spaceManager, _metadataStore, _dataServiceSubscriptions, _keyring, _signingContext, _feedStore, _automergeHost) {
3526
3627
  this._spaceManager = _spaceManager;
3527
3628
  this._metadataStore = _metadataStore;
@@ -3547,7 +3648,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3547
3648
  S: this,
3548
3649
  C: (f, a) => f(...a)
3549
3650
  });
3550
- import_log11.log.trace("dxos.echo.data-space-manager.open", import_protocols8.trace.begin({
3651
+ import_log11.log.trace("dxos.echo.data-space-manager.open", import_protocols10.trace.begin({
3551
3652
  id: this._instanceId
3552
3653
  }), {
3553
3654
  F: __dxlog_file13,
@@ -3589,11 +3690,11 @@ var DataSpaceManager = class DataSpaceManager2 {
3589
3690
  this._isOpen = true;
3590
3691
  this.updated.emit();
3591
3692
  for (const space of this._spaces.values()) {
3592
- if (space.state !== import_services8.SpaceState.INACTIVE) {
3693
+ if (space.state !== import_services9.SpaceState.INACTIVE) {
3593
3694
  space.initializeDataPipelineAsync();
3594
3695
  }
3595
3696
  }
3596
- import_log11.log.trace("dxos.echo.data-space-manager.open", import_protocols8.trace.end({
3697
+ import_log11.log.trace("dxos.echo.data-space-manager.open", import_protocols10.trace.end({
3597
3698
  id: this._instanceId
3598
3699
  }), {
3599
3700
  F: __dxlog_file13,
@@ -3619,7 +3720,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3619
3720
  * Creates a new space writing the genesis credentials to the control feed.
3620
3721
  */
3621
3722
  async createSpace() {
3622
- (0, import_invariant11.invariant)(this._isOpen, "Not open.", {
3723
+ (0, import_invariant12.invariant)(this._isOpen, "Not open.", {
3623
3724
  F: __dxlog_file13,
3624
3725
  L: 130,
3625
3726
  S: this,
@@ -3636,7 +3737,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3636
3737
  genesisFeedKey: controlFeedKey,
3637
3738
  controlFeedKey,
3638
3739
  dataFeedKey,
3639
- state: import_services8.SpaceState.ACTIVE
3740
+ state: import_services9.SpaceState.ACTIVE
3640
3741
  };
3641
3742
  (0, import_log11.log)("creating space...", {
3642
3743
  spaceKey
@@ -3648,12 +3749,15 @@ var DataSpaceManager = class DataSpaceManager2 {
3648
3749
  });
3649
3750
  const space = await this._constructSpace(metadata);
3650
3751
  const automergeRoot = this._automergeHost.repo.create();
3752
+ automergeRoot.change((doc) => {
3753
+ doc.experimental_spaceKey = spaceKey.toHex();
3754
+ });
3651
3755
  const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRoot.url);
3652
3756
  await this._metadataStore.addSpace(metadata);
3653
3757
  const memberCredential = credentials[1];
3654
- (0, import_invariant11.invariant)((0, import_credentials12.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3758
+ (0, import_invariant12.invariant)((0, import_credentials12.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3655
3759
  F: __dxlog_file13,
3656
- L: 151,
3760
+ L: 154,
3657
3761
  S: this,
3658
3762
  A: [
3659
3763
  "getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -3671,22 +3775,22 @@ var DataSpaceManager = class DataSpaceManager2 {
3671
3775
  opts
3672
3776
  }, {
3673
3777
  F: __dxlog_file13,
3674
- L: 163,
3778
+ L: 166,
3675
3779
  S: this,
3676
3780
  C: (f, a) => f(...a)
3677
3781
  });
3678
- (0, import_invariant11.invariant)(this._isOpen, "Not open.", {
3782
+ (0, import_invariant12.invariant)(this._isOpen, "Not open.", {
3679
3783
  F: __dxlog_file13,
3680
- L: 164,
3784
+ L: 167,
3681
3785
  S: this,
3682
3786
  A: [
3683
3787
  "this._isOpen",
3684
3788
  "'Not open.'"
3685
3789
  ]
3686
3790
  });
3687
- (0, import_invariant11.invariant)(!this._spaces.has(opts.spaceKey), "Space already exists.", {
3791
+ (0, import_invariant12.invariant)(!this._spaces.has(opts.spaceKey), "Space already exists.", {
3688
3792
  F: __dxlog_file13,
3689
- L: 165,
3793
+ L: 168,
3690
3794
  S: this,
3691
3795
  A: [
3692
3796
  "!this._spaces.has(opts.spaceKey)",
@@ -3713,7 +3817,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3713
3817
  async waitUntilSpaceReady(spaceKey) {
3714
3818
  await (0, import_context8.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
3715
3819
  const space = this._spaces.get(spaceKey);
3716
- return !!space && space.state === import_services8.SpaceState.READY;
3820
+ return !!space && space.state === import_services9.SpaceState.READY;
3717
3821
  }));
3718
3822
  }
3719
3823
  async _constructSpace(metadata) {
@@ -3721,7 +3825,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3721
3825
  metadata
3722
3826
  }, {
3723
3827
  F: __dxlog_file13,
3724
- L: 198,
3828
+ L: 201,
3725
3829
  S: this,
3726
3830
  C: (f, a) => f(...a)
3727
3831
  });
@@ -3748,17 +3852,18 @@ var DataSpaceManager = class DataSpaceManager2 {
3748
3852
  credentialProvider: createAuthProvider(this._signingContext.credentialSigner),
3749
3853
  credentialAuthenticator: (0, import_util6.deferFunction)(() => dataSpace.authVerifier.verifier)
3750
3854
  },
3751
- onNetworkConnection: (session) => {
3855
+ onAuthorizedConnection: (session) => {
3752
3856
  session.addExtension("dxos.mesh.teleport.gossip", gossip.createExtension({
3753
3857
  remotePeerId: session.remotePeerId
3754
3858
  }));
3755
3859
  session.addExtension("dxos.mesh.teleport.notarization", dataSpace.notarizationPlugin.createExtension());
3860
+ this._automergeHost.authorizeDevice(space.key, session.remotePeerId);
3756
3861
  session.addExtension("dxos.mesh.teleport.automerge", this._automergeHost.createExtension());
3757
3862
  },
3758
3863
  onAuthFailure: () => {
3759
3864
  import_log11.log.warn("auth failure", void 0, {
3760
3865
  F: __dxlog_file13,
3761
- L: 234,
3866
+ L: 238,
3762
3867
  S: this,
3763
3868
  C: (f, a) => f(...a)
3764
3869
  });
@@ -3769,7 +3874,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3769
3874
  dataFeed && space.setDataFeed(dataFeed);
3770
3875
  const dataSpace = new DataSpace({
3771
3876
  inner: space,
3772
- initialState: metadata.state === import_services8.SpaceState.INACTIVE ? import_services8.SpaceState.INACTIVE : import_services8.SpaceState.CLOSED,
3877
+ initialState: metadata.state === import_services9.SpaceState.INACTIVE ? import_services9.SpaceState.INACTIVE : import_services9.SpaceState.CLOSED,
3773
3878
  metadataStore: this._metadataStore,
3774
3879
  gossip,
3775
3880
  presence,
@@ -3782,7 +3887,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3782
3887
  space: space.key
3783
3888
  }, {
3784
3889
  F: __dxlog_file13,
3785
- L: 252,
3890
+ L: 256,
3786
3891
  S: this,
3787
3892
  C: (f, a) => f(...a)
3788
3893
  });
@@ -3794,7 +3899,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3794
3899
  open: this._isOpen
3795
3900
  }, {
3796
3901
  F: __dxlog_file13,
3797
- L: 259,
3902
+ L: 263,
3798
3903
  S: this,
3799
3904
  C: (f, a) => f(...a)
3800
3905
  });
@@ -3807,7 +3912,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3807
3912
  space: space.key
3808
3913
  }, {
3809
3914
  F: __dxlog_file13,
3810
- L: 265,
3915
+ L: 269,
3811
3916
  S: this,
3812
3917
  C: (f, a) => f(...a)
3813
3918
  });
@@ -3817,7 +3922,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3817
3922
  cache: metadata.cache,
3818
3923
  automergeHost: this._automergeHost
3819
3924
  });
3820
- if (metadata.state !== import_services8.SpaceState.INACTIVE) {
3925
+ if (metadata.state !== import_services9.SpaceState.INACTIVE) {
3821
3926
  await dataSpace.open();
3822
3927
  }
3823
3928
  if (metadata.controlTimeframe) {
@@ -3855,7 +3960,7 @@ var SpacesServiceImpl = class {
3855
3960
  }
3856
3961
  async createSpace() {
3857
3962
  if (!this._identityManager.identity) {
3858
- throw new Error("This device has no HALO identity available. See https://docs.dxos.org/guide/halo");
3963
+ throw new Error("This device has no HALO identity available. See https://docs.dxos.org/guide/platform/halo");
3859
3964
  }
3860
3965
  const dataSpaceManager = await this._getDataSpaceManager();
3861
3966
  const space = await dataSpaceManager.createSpace();
@@ -3863,17 +3968,17 @@ var SpacesServiceImpl = class {
3863
3968
  }
3864
3969
  async updateSpace({ spaceKey, state }) {
3865
3970
  const dataSpaceManager = await this._getDataSpaceManager();
3866
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols9.SpaceNotFoundError(spaceKey));
3971
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
3867
3972
  if (state) {
3868
3973
  switch (state) {
3869
- case import_services9.SpaceState.ACTIVE:
3974
+ case import_services10.SpaceState.ACTIVE:
3870
3975
  await space.activate();
3871
3976
  break;
3872
- case import_services9.SpaceState.INACTIVE:
3977
+ case import_services10.SpaceState.INACTIVE:
3873
3978
  await space.deactivate();
3874
3979
  break;
3875
3980
  default:
3876
- throw new import_protocols9.ApiError("Invalid space state");
3981
+ throw new import_protocols11.ApiError("Invalid space state");
3877
3982
  }
3878
3983
  }
3879
3984
  }
@@ -3928,14 +4033,14 @@ var SpacesServiceImpl = class {
3928
4033
  }
3929
4034
  async postMessage({ spaceKey, channel, message }) {
3930
4035
  const dataSpaceManager = await this._getDataSpaceManager();
3931
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols9.SpaceNotFoundError(spaceKey));
4036
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
3932
4037
  await space.postMessage(getChannelId(channel), message);
3933
4038
  }
3934
4039
  subscribeMessages({ spaceKey, channel }) {
3935
4040
  return new import_codec_protobuf11.Stream(({ ctx, next }) => {
3936
4041
  (0, import_async13.scheduleTask)(ctx, async () => {
3937
4042
  const dataSpaceManager = await this._getDataSpaceManager();
3938
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols9.SpaceNotFoundError(spaceKey));
4043
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
3939
4044
  const handle = space.listen(getChannelId(channel), (message) => {
3940
4045
  next(message);
3941
4046
  });
@@ -3945,7 +4050,7 @@ var SpacesServiceImpl = class {
3945
4050
  }
3946
4051
  queryCredentials({ spaceKey, noTail }) {
3947
4052
  return new import_codec_protobuf11.Stream(({ ctx, next, close }) => {
3948
- const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols9.SpaceNotFoundError(spaceKey));
4053
+ const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
3949
4054
  const processor = {
3950
4055
  processCredential: async (credential) => {
3951
4056
  next(credential);
@@ -3961,7 +4066,7 @@ var SpacesServiceImpl = class {
3961
4066
  });
3962
4067
  }
3963
4068
  async writeCredentials({ spaceKey, credentials }) {
3964
- const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols9.SpaceNotFoundError(spaceKey));
4069
+ const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
3965
4070
  for (const credential of credentials ?? []) {
3966
4071
  if (credential.proof) {
3967
4072
  await space.controlPipeline.writer.write({
@@ -3970,7 +4075,7 @@ var SpacesServiceImpl = class {
3970
4075
  }
3971
4076
  });
3972
4077
  } else {
3973
- (0, import_invariant12.invariant)(!credential.id, "Id on unsigned credentials is not allowed", {
4078
+ (0, import_invariant13.invariant)(!credential.id, "Id on unsigned credentials is not allowed", {
3974
4079
  F: __dxlog_file14,
3975
4080
  L: 168,
3976
4081
  S: this,
@@ -3979,7 +4084,7 @@ var SpacesServiceImpl = class {
3979
4084
  "'Id on unsigned credentials is not allowed'"
3980
4085
  ]
3981
4086
  });
3982
- (0, import_invariant12.invariant)(this._identityManager.identity, "Identity is not available", {
4087
+ (0, import_invariant13.invariant)(this._identityManager.identity, "Identity is not available", {
3983
4088
  F: __dxlog_file14,
3984
4089
  L: 169,
3985
4090
  S: this,
@@ -3989,7 +4094,7 @@ var SpacesServiceImpl = class {
3989
4094
  ]
3990
4095
  });
3991
4096
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
3992
- (0, import_invariant12.invariant)(credential.issuer.equals(signer.getIssuer()), void 0, {
4097
+ (0, import_invariant13.invariant)(credential.issuer.equals(signer.getIssuer()), void 0, {
3993
4098
  F: __dxlog_file14,
3994
4099
  L: 171,
3995
4100
  S: this,
@@ -4012,14 +4117,14 @@ var SpacesServiceImpl = class {
4012
4117
  }
4013
4118
  async createEpoch({ spaceKey }) {
4014
4119
  const dataSpaceManager = await this._getDataSpaceManager();
4015
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols9.SpaceNotFoundError(spaceKey));
4120
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4016
4121
  await space.createEpoch();
4017
4122
  }
4018
4123
  _serializeSpace(space) {
4019
4124
  return {
4020
4125
  spaceKey: space.key,
4021
4126
  state: space.state,
4022
- error: space.error ? (0, import_protocols9.encodeError)(space.error) : void 0,
4127
+ error: space.error ? (0, import_protocols11.encodeError)(space.error) : void 0,
4023
4128
  pipeline: {
4024
4129
  currentEpoch: space.dataPipeline.currentEpoch,
4025
4130
  appliedEpoch: space.dataPipeline.appliedEpoch,
@@ -4046,7 +4151,7 @@ var SpacesServiceImpl = class {
4046
4151
  displayName: member.profile?.displayName
4047
4152
  }
4048
4153
  },
4049
- presence: member.removed ? import_services9.SpaceMember.PresenceState.REMOVED : isMe || peers.length > 0 ? import_services9.SpaceMember.PresenceState.ONLINE : import_services9.SpaceMember.PresenceState.OFFLINE,
4154
+ presence: member.removed ? import_services10.SpaceMember.PresenceState.REMOVED : isMe || peers.length > 0 ? import_services10.SpaceMember.PresenceState.ONLINE : import_services10.SpaceMember.PresenceState.OFFLINE,
4050
4155
  peerStates: peers
4051
4156
  };
4052
4157
  }),
@@ -4068,7 +4173,7 @@ function _ts_decorate6(decorators, target, key, desc) {
4068
4173
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4069
4174
  }
4070
4175
  var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
4071
- var ServiceContext = class ServiceContext2 {
4176
+ var ServiceContext = class {
4072
4177
  constructor(storage, networkManager, signalManager, modelFactory) {
4073
4178
  this.storage = storage;
4074
4179
  this.networkManager = networkManager;
@@ -4103,7 +4208,7 @@ var ServiceContext = class ServiceContext2 {
4103
4208
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager);
4104
4209
  this.automergeHost = new import_echo_pipeline2.AutomergeHost(storage.createDirectory("automerge"));
4105
4210
  this.invitations = new InvitationsHandler(this.networkManager);
4106
- this._handlerFactories.set(import_services10.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug7.failUndefined)(), this._acceptIdentity.bind(this)));
4211
+ this._handlerFactories.set(import_services11.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug7.failUndefined)(), this._acceptIdentity.bind(this)));
4107
4212
  }
4108
4213
  async open(ctx) {
4109
4214
  await this._checkStorageVersion();
@@ -4113,7 +4218,7 @@ var ServiceContext = class ServiceContext2 {
4113
4218
  S: this,
4114
4219
  C: (f, a) => f(...a)
4115
4220
  });
4116
- import_log13.log.trace("dxos.sdk.service-context.open", import_protocols10.trace.begin({
4221
+ import_log13.log.trace("dxos.sdk.service-context.open", import_protocols12.trace.begin({
4117
4222
  id: this._instanceId
4118
4223
  }), {
4119
4224
  F: __dxlog_file15,
@@ -4129,7 +4234,7 @@ var ServiceContext = class ServiceContext2 {
4129
4234
  if (this.identityManager.identity) {
4130
4235
  await this._initialize(ctx);
4131
4236
  }
4132
- import_log13.log.trace("dxos.sdk.service-context.open", import_protocols10.trace.end({
4237
+ import_log13.log.trace("dxos.sdk.service-context.open", import_protocols12.trace.end({
4133
4238
  id: this._instanceId
4134
4239
  }), {
4135
4240
  F: __dxlog_file15,
@@ -4177,7 +4282,7 @@ var ServiceContext = class ServiceContext2 {
4177
4282
  }
4178
4283
  getInvitationHandler(invitation) {
4179
4284
  const factory = this._handlerFactories.get(invitation.kind);
4180
- (0, import_invariant13.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
4285
+ (0, import_invariant14.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
4181
4286
  F: __dxlog_file15,
4182
4287
  L: 173,
4183
4288
  S: this,
@@ -4203,8 +4308,8 @@ var ServiceContext = class ServiceContext2 {
4203
4308
  }
4204
4309
  async _checkStorageVersion() {
4205
4310
  await this.metadataStore.load();
4206
- if (this.metadataStore.version !== import_protocols10.STORAGE_VERSION) {
4207
- throw new import_protocols10.InvalidStorageVersionError(import_protocols10.STORAGE_VERSION, this.metadataStore.version);
4311
+ if (this.metadataStore.version !== import_protocols12.STORAGE_VERSION) {
4312
+ throw new import_protocols12.InvalidStorageVersionError(import_protocols12.STORAGE_VERSION, this.metadataStore.version);
4208
4313
  }
4209
4314
  }
4210
4315
  // Called when identity is created.
@@ -4231,8 +4336,8 @@ var ServiceContext = class ServiceContext2 {
4231
4336
  };
4232
4337
  this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.dataServiceSubscriptions, this.keyring, signingContext, this.feedStore, this.automergeHost);
4233
4338
  await this.dataSpaceManager.open();
4234
- this._handlerFactories.set(import_services10.Invitation.Kind.SPACE, (invitation) => {
4235
- (0, import_invariant13.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4339
+ this._handlerFactories.set(import_services11.Invitation.Kind.SPACE, (invitation) => {
4340
+ (0, import_invariant14.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4236
4341
  F: __dxlog_file15,
4237
4342
  L: 228,
4238
4343
  S: this,
@@ -4302,14 +4407,14 @@ var ServiceContext = class ServiceContext2 {
4302
4407
  }
4303
4408
  };
4304
4409
  _ts_decorate6([
4305
- import_tracing5.trace.span()
4410
+ import_tracing6.trace.span()
4306
4411
  ], ServiceContext.prototype, "open", null);
4307
4412
  _ts_decorate6([
4308
- import_tracing5.trace.span()
4413
+ import_tracing6.trace.span()
4309
4414
  ], ServiceContext.prototype, "_initialize", null);
4310
4415
  ServiceContext = _ts_decorate6([
4311
4416
  (0, import_util7.safeInstanceof)("dxos.client-services.ServiceContext"),
4312
- import_tracing5.trace.resource()
4417
+ import_tracing6.trace.resource()
4313
4418
  ], ServiceContext);
4314
4419
  var ServiceRegistry = class {
4315
4420
  // prettier-ignore
@@ -4371,7 +4476,7 @@ var Lock = class {
4371
4476
  }
4372
4477
  async release() {
4373
4478
  await this._onRelease?.();
4374
- (0, import_invariant14.invariant)(this._fileHandle, "Lock is not acquired", {
4479
+ (0, import_invariant15.invariant)(this._fileHandle, "Lock is not acquired", {
4375
4480
  F: __dxlog_file16,
4376
4481
  L: 42,
4377
4482
  S: this,
@@ -4391,16 +4496,16 @@ var StorageDriver = import_config.Runtime.Client.Storage.StorageDriver;
4391
4496
  var createStorageObjects = (config) => {
4392
4497
  const { persistent = false, keyStore, dataStore, dataRoot = (0, import_util8.isNode)() ? import_client_protocol4.DX_DATA : "dxos/storage" } = config ?? {};
4393
4498
  if (persistent && dataStore === StorageDriver.RAM) {
4394
- throw new import_protocols11.InvalidConfigError("RAM storage cannot be used in persistent mode.");
4499
+ throw new import_protocols13.InvalidConfigError("RAM storage cannot be used in persistent mode.");
4395
4500
  }
4396
4501
  if (!persistent && dataStore !== void 0 && dataStore !== StorageDriver.RAM) {
4397
- throw new import_protocols11.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
4502
+ throw new import_protocols13.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
4398
4503
  }
4399
4504
  if (persistent && keyStore === StorageDriver.RAM) {
4400
- throw new import_protocols11.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
4505
+ throw new import_protocols13.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
4401
4506
  }
4402
4507
  if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== void 0) {
4403
- throw new import_protocols11.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
4508
+ throw new import_protocols13.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
4404
4509
  }
4405
4510
  return {
4406
4511
  storage: (0, import_random_access_storage.createStorage)({
@@ -4448,7 +4553,7 @@ var DevicesServiceImpl = class {
4448
4553
  next({
4449
4554
  devices: Array.from(deviceKeys.entries()).map(([key, profile]) => ({
4450
4555
  deviceKey: key,
4451
- kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services12.DeviceKind.CURRENT : import_services12.DeviceKind.TRUSTED,
4556
+ kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services13.DeviceKind.CURRENT : import_services13.DeviceKind.TRUSTED,
4452
4557
  profile
4453
4558
  }))
4454
4559
  });
@@ -4563,16 +4668,16 @@ var LoggingServiceImpl = class {
4563
4668
  };
4564
4669
  var matchFilter = (filter, level, path, options) => {
4565
4670
  switch (options) {
4566
- case import_services13.QueryLogsRequest.MatchingOptions.INCLUSIVE:
4671
+ case import_services14.QueryLogsRequest.MatchingOptions.INCLUSIVE:
4567
4672
  return level >= filter.level && (!filter.pattern || path.includes(filter.pattern));
4568
- case import_services13.QueryLogsRequest.MatchingOptions.EXPLICIT:
4673
+ case import_services14.QueryLogsRequest.MatchingOptions.EXPLICIT:
4569
4674
  return level === filter.level && (!filter.pattern || path.includes(filter.pattern));
4570
4675
  }
4571
4676
  };
4572
4677
  var shouldLog = (entry2, request) => {
4573
- const options = request.options ?? import_services13.QueryLogsRequest.MatchingOptions.INCLUSIVE;
4678
+ const options = request.options ?? import_services14.QueryLogsRequest.MatchingOptions.INCLUSIVE;
4574
4679
  if (request.filters === void 0) {
4575
- return options === import_services13.QueryLogsRequest.MatchingOptions.INCLUSIVE;
4680
+ return options === import_services14.QueryLogsRequest.MatchingOptions.INCLUSIVE;
4576
4681
  } else {
4577
4682
  return request.filters.some((filter) => matchFilter(filter, entry2.level, entry2.meta?.F ?? "", options));
4578
4683
  }
@@ -4588,6 +4693,7 @@ var NetworkServiceImpl = class {
4588
4693
  const update = () => {
4589
4694
  next({
4590
4695
  swarm: this.networkManager.connectionState,
4696
+ connectionInfo: this.networkManager.connectionLog?.swarms,
4591
4697
  signaling: this.signalManager.getStatus().map(({ host, state }) => ({
4592
4698
  server: host,
4593
4699
  state
@@ -4627,11 +4733,14 @@ var SystemServiceImpl = class {
4627
4733
  return {
4628
4734
  timestamp: /* @__PURE__ */ new Date(),
4629
4735
  diagnostics: JSON.parse(JSON.stringify(diagnostics, (0, import_util10.jsonKeyReplacer)({
4630
- truncate: keys === import_services14.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
4631
- humanize: keys === import_services14.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
4736
+ truncate: keys === import_services15.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
4737
+ humanize: keys === import_services15.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
4632
4738
  })))
4633
4739
  };
4634
4740
  }
4741
+ async getPlatform() {
4742
+ return getPlatform();
4743
+ }
4635
4744
  async updateStatus({ status }) {
4636
4745
  await this._onUpdateStatus(status);
4637
4746
  }
@@ -4682,7 +4791,7 @@ var createGenesisMutationFromTypedObject = (obj) => {
4682
4791
  }
4683
4792
  };
4684
4793
  };
4685
- var ClientServicesHost = class ClientServicesHost2 {
4794
+ var ClientServicesHost = class {
4686
4795
  constructor({
4687
4796
  config,
4688
4797
  modelFactory = createDefaultModelFactory(),
@@ -4693,7 +4802,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4693
4802
  lockKey,
4694
4803
  callbacks
4695
4804
  } = {}) {
4696
- this._tracingService = import_tracing6.TRACE_PROCESSOR.createTraceSender();
4805
+ this._tracingService = import_tracing7.TRACE_PROCESSOR.createTraceSender();
4697
4806
  this._statusUpdate = new import_async15.Event();
4698
4807
  this._opening = false;
4699
4808
  this._open = false;
@@ -4721,14 +4830,14 @@ var ClientServicesHost = class ClientServicesHost2 {
4721
4830
  this._systemService = new SystemServiceImpl({
4722
4831
  config: this._config,
4723
4832
  statusUpdate: this._statusUpdate,
4724
- getCurrentStatus: () => this.isOpen ? import_services11.SystemStatus.ACTIVE : import_services11.SystemStatus.INACTIVE,
4833
+ getCurrentStatus: () => this.isOpen ? import_services12.SystemStatus.ACTIVE : import_services12.SystemStatus.INACTIVE,
4725
4834
  getDiagnostics: () => {
4726
4835
  return createDiagnostics(this._serviceRegistry.services, this._serviceContext, this._config);
4727
4836
  },
4728
4837
  onUpdateStatus: async (status) => {
4729
- if (!this.isOpen && status === import_services11.SystemStatus.ACTIVE) {
4838
+ if (!this.isOpen && status === import_services12.SystemStatus.ACTIVE) {
4730
4839
  await this._resourceLock?.acquire();
4731
- } else if (this.isOpen && status === import_services11.SystemStatus.INACTIVE) {
4840
+ } else if (this.isOpen && status === import_services12.SystemStatus.INACTIVE) {
4732
4841
  await this._resourceLock?.release();
4733
4842
  }
4734
4843
  },
@@ -4766,7 +4875,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4766
4875
  * Can only be called once.
4767
4876
  */
4768
4877
  initialize({ config, ...options }) {
4769
- (0, import_invariant15.invariant)(!this._open, "service host is open", {
4878
+ (0, import_invariant16.invariant)(!this._open, "service host is open", {
4770
4879
  F: __dxlog_file17,
4771
4880
  L: 201,
4772
4881
  S: this,
@@ -4782,7 +4891,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4782
4891
  C: (f, a) => f(...a)
4783
4892
  });
4784
4893
  if (config) {
4785
- (0, import_invariant15.invariant)(!this._config, "config already set", {
4894
+ (0, import_invariant16.invariant)(!this._config, "config already set", {
4786
4895
  F: __dxlog_file17,
4787
4896
  L: 205,
4788
4897
  S: this,
@@ -4800,7 +4909,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4800
4909
  iceServers: this._config?.get("runtime.services.ice")
4801
4910
  }), signalManager = new import_messaging.WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
4802
4911
  this._signalManager = signalManager;
4803
- (0, import_invariant15.invariant)(!this._networkManager, "network manager already set", {
4912
+ (0, import_invariant16.invariant)(!this._networkManager, "network manager already set", {
4804
4913
  F: __dxlog_file17,
4805
4914
  L: 221,
4806
4915
  S: this,
@@ -4826,7 +4935,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4826
4935
  return;
4827
4936
  }
4828
4937
  const traceId = import_keys11.PublicKey.random().toHex();
4829
- import_log15.log.trace("dxos.client-services.host.open", import_protocols12.trace.begin({
4938
+ import_log15.log.trace("dxos.client-services.host.open", import_protocols14.trace.begin({
4830
4939
  id: traceId
4831
4940
  }), {
4832
4941
  F: __dxlog_file17,
@@ -4834,7 +4943,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4834
4943
  S: this,
4835
4944
  C: (f, a) => f(...a)
4836
4945
  });
4837
- (0, import_invariant15.invariant)(this._config, "config not set", {
4946
+ (0, import_invariant16.invariant)(this._config, "config not set", {
4838
4947
  F: __dxlog_file17,
4839
4948
  L: 241,
4840
4949
  S: this,
@@ -4843,7 +4952,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4843
4952
  "'config not set'"
4844
4953
  ]
4845
4954
  });
4846
- (0, import_invariant15.invariant)(this._storage, "storage not set", {
4955
+ (0, import_invariant16.invariant)(this._storage, "storage not set", {
4847
4956
  F: __dxlog_file17,
4848
4957
  L: 242,
4849
4958
  S: this,
@@ -4852,7 +4961,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4852
4961
  "'storage not set'"
4853
4962
  ]
4854
4963
  });
4855
- (0, import_invariant15.invariant)(this._signalManager, "signal manager not set", {
4964
+ (0, import_invariant16.invariant)(this._signalManager, "signal manager not set", {
4856
4965
  F: __dxlog_file17,
4857
4966
  L: 243,
4858
4967
  S: this,
@@ -4861,7 +4970,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4861
4970
  "'signal manager not set'"
4862
4971
  ]
4863
4972
  });
4864
- (0, import_invariant15.invariant)(this._networkManager, "network manager not set", {
4973
+ (0, import_invariant16.invariant)(this._networkManager, "network manager not set", {
4865
4974
  F: __dxlog_file17,
4866
4975
  L: 244,
4867
4976
  S: this,
@@ -4884,7 +4993,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4884
4993
  this._serviceContext = new ServiceContext(this._storage, this._networkManager, this._signalManager, this._modelFactory);
4885
4994
  this._serviceRegistry.setServices({
4886
4995
  SystemService: this._systemService,
4887
- IdentityService: new IdentityServiceImpl((params) => this._createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring, (profile) => this._serviceContext.broadcastProfileUpdate(profile)),
4996
+ IdentityService: new IdentityServiceImpl((params, useAutomerge) => this._createIdentity(params, useAutomerge), this._serviceContext.identityManager, this._serviceContext.keyring, (profile) => this._serviceContext.broadcastProfileUpdate(profile)),
4888
4997
  InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitations, (invitation) => this._serviceContext.getInvitationHandler(invitation)),
4889
4998
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
4890
4999
  SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, this._serviceContext.dataServiceSubscriptions, async () => {
@@ -4925,7 +5034,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4925
5034
  S: this,
4926
5035
  C: (f, a) => f(...a)
4927
5036
  });
4928
- import_log15.log.trace("dxos.client-services.host.open", import_protocols12.trace.end({
5037
+ import_log15.log.trace("dxos.client-services.host.open", import_protocols14.trace.end({
4929
5038
  id: traceId
4930
5039
  }), {
4931
5040
  F: __dxlog_file17,
@@ -4966,7 +5075,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4966
5075
  }
4967
5076
  async reset() {
4968
5077
  const traceId = import_keys11.PublicKey.random().toHex();
4969
- import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols12.trace.begin({
5078
+ import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols14.trace.begin({
4970
5079
  id: traceId
4971
5080
  }), {
4972
5081
  F: __dxlog_file17,
@@ -4988,7 +5097,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4988
5097
  S: this,
4989
5098
  C: (f, a) => f(...a)
4990
5099
  });
4991
- import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols12.trace.end({
5100
+ import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols14.trace.end({
4992
5101
  id: traceId
4993
5102
  }), {
4994
5103
  F: __dxlog_file17,
@@ -4998,44 +5107,63 @@ var ClientServicesHost = class ClientServicesHost2 {
4998
5107
  });
4999
5108
  await this._callbacks?.onReset?.();
5000
5109
  }
5001
- async _createIdentity(params) {
5110
+ async _createIdentity(params, useAutomerge) {
5002
5111
  const identity = await this._serviceContext.createIdentity(params);
5003
5112
  await this._serviceContext.initialized.wait();
5004
5113
  const space = await this._serviceContext.dataSpaceManager.createSpace();
5005
5114
  const obj = new import_client_protocol5.Properties(void 0, {
5006
- automerge: false
5115
+ automerge: useAutomerge
5007
5116
  });
5008
5117
  obj[import_client_protocol5.defaultKey] = identity.identityKey.toHex();
5009
- await this._serviceRegistry.services.DataService.write({
5010
- spaceKey: space.key,
5011
- batch: {
5012
- objects: [
5013
- createGenesisMutationFromTypedObject(obj)
5118
+ if (!useAutomerge) {
5119
+ await this._serviceRegistry.services.DataService.write({
5120
+ spaceKey: space.key,
5121
+ batch: {
5122
+ objects: [
5123
+ createGenesisMutationFromTypedObject(obj)
5124
+ ]
5125
+ }
5126
+ });
5127
+ await this._serviceRegistry.services.DataService.flush({
5128
+ spaceKey: space.key
5129
+ });
5130
+ } else {
5131
+ const automergeIndex = space.automergeSpaceState.rootUrl;
5132
+ (0, import_invariant16.invariant)(automergeIndex, void 0, {
5133
+ F: __dxlog_file17,
5134
+ L: 375,
5135
+ S: this,
5136
+ A: [
5137
+ "automergeIndex",
5138
+ ""
5014
5139
  ]
5015
- }
5016
- });
5017
- await this._serviceRegistry.services.DataService.flush({
5018
- spaceKey: space.key
5019
- });
5140
+ });
5141
+ const document = await this._serviceContext.automergeHost.repo.find(automergeIndex);
5142
+ await document.whenReady();
5143
+ document.change((doc) => {
5144
+ doc.objects ??= {};
5145
+ doc.objects[obj[import_echo_schema.base]._id] = (0, import_echo_schema.getRawDoc)(obj).handle.docSync();
5146
+ });
5147
+ }
5020
5148
  return identity;
5021
5149
  }
5022
5150
  };
5023
5151
  _ts_decorate8([
5024
- import_tracing6.trace.info()
5152
+ import_tracing7.trace.info()
5025
5153
  ], ClientServicesHost.prototype, "_opening", void 0);
5026
5154
  _ts_decorate8([
5027
- import_tracing6.trace.info()
5155
+ import_tracing7.trace.info()
5028
5156
  ], ClientServicesHost.prototype, "_open", void 0);
5029
5157
  _ts_decorate8([
5030
5158
  import_async15.synchronized,
5031
- import_tracing6.trace.span()
5159
+ import_tracing7.trace.span()
5032
5160
  ], ClientServicesHost.prototype, "open", null);
5033
5161
  _ts_decorate8([
5034
5162
  import_async15.synchronized,
5035
- import_tracing6.trace.span()
5163
+ import_tracing7.trace.span()
5036
5164
  ], ClientServicesHost.prototype, "close", null);
5037
5165
  ClientServicesHost = _ts_decorate8([
5038
- import_tracing6.trace.resource()
5166
+ import_tracing7.trace.resource()
5039
5167
  ], ClientServicesHost);
5040
5168
  // Annotate the CommonJS export names for ESM import in node:
5041
5169
  0 && (module.exports = {
@@ -5071,4 +5199,4 @@ ClientServicesHost = _ts_decorate8([
5071
5199
  subscribeToSpaces,
5072
5200
  subscribeToSwarmInfo
5073
5201
  });
5074
- //# sourceMappingURL=chunk-PJPQHWZH.cjs.map
5202
+ //# sourceMappingURL=chunk-BRIW2QR3.cjs.map