@dxos/client-services 0.3.11-main.e0dc42b → 0.3.11-main.e19f39d

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-IUMG3QPZ.mjs → chunk-LUXAN22G.mjs} +211 -108
  2. package/dist/lib/browser/chunk-LUXAN22G.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-SCZDMYY2.cjs → chunk-45NL4DNZ.cjs} +343 -240
  9. package/dist/lib/node/chunk-45NL4DNZ.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 +5 -2
  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 +1 -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 +2 -1
  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 +1 -0
  50. package/src/packlets/services/diagnostics.ts +20 -1
  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 +21 -1
  56. package/src/packlets/spaces/spaces-service.ts +1 -1
  57. package/src/packlets/system/system-service.ts +6 -0
  58. package/src/packlets/testing/invitation-utils.ts +2 -10
  59. package/src/version.ts +1 -1
  60. package/dist/lib/browser/chunk-IUMG3QPZ.mjs.map +0 -7
  61. package/dist/lib/node/chunk-SCZDMYY2.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_SCZDMYY2_exports = {};
30
- __export(chunk_SCZDMYY2_exports, {
29
+ var chunk_45NL4DNZ_exports = {};
30
+ __export(chunk_45NL4DNZ_exports, {
31
31
  ClientRpcServer: () => ClientRpcServer,
32
32
  ClientServicesHost: () => ClientServicesHost,
33
33
  DataSpace: () => DataSpace,
@@ -60,7 +60,7 @@ __export(chunk_SCZDMYY2_exports, {
60
60
  subscribeToSpaces: () => subscribeToSpaces,
61
61
  subscribeToSwarmInfo: () => subscribeToSwarmInfo
62
62
  });
63
- module.exports = __toCommonJS(chunk_SCZDMYY2_exports);
63
+ module.exports = __toCommonJS(chunk_45NL4DNZ_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,17 +151,19 @@ 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_services7 = require("@dxos/protocols/proto/dxos/client/services");
154
157
  var import_async10 = require("@dxos/async");
155
158
  var import_client_protocol3 = require("@dxos/client-protocol");
156
159
  var import_context6 = require("@dxos/context");
157
160
  var import_debug4 = require("@dxos/debug");
158
161
  var import_echo_pipeline = require("@dxos/echo-pipeline");
162
+ var import_invariant10 = require("@dxos/invariant");
159
163
  var import_keys7 = require("@dxos/keys");
160
164
  var import_log9 = require("@dxos/log");
161
- var import_protocols6 = require("@dxos/protocols");
162
- var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
165
+ var import_protocols8 = require("@dxos/protocols");
166
+ var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
163
167
  var import_credentials10 = require("@dxos/protocols/proto/dxos/halo/credentials");
164
168
  var import_timeframe2 = require("@dxos/timeframe");
165
169
  var import_tracing4 = require("@dxos/tracing");
@@ -167,20 +171,20 @@ var import_util4 = require("@dxos/util");
167
171
  var import_credentials11 = require("@dxos/credentials");
168
172
  var import_async11 = require("@dxos/async");
169
173
  var import_context7 = require("@dxos/context");
170
- var import_invariant10 = require("@dxos/invariant");
174
+ var import_invariant11 = require("@dxos/invariant");
171
175
  var import_keys8 = require("@dxos/keys");
172
176
  var import_log10 = require("@dxos/log");
173
- var import_protocols7 = require("@dxos/protocols");
177
+ var import_protocols9 = require("@dxos/protocols");
174
178
  var import_teleport2 = require("@dxos/teleport");
175
179
  var import_util5 = require("@dxos/util");
176
180
  var import_async12 = require("@dxos/async");
177
181
  var import_context8 = require("@dxos/context");
178
182
  var import_credentials12 = require("@dxos/credentials");
179
- var import_invariant11 = require("@dxos/invariant");
183
+ var import_invariant12 = require("@dxos/invariant");
180
184
  var import_keys9 = require("@dxos/keys");
181
185
  var import_log11 = require("@dxos/log");
182
- var import_protocols8 = require("@dxos/protocols");
183
- var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
186
+ var import_protocols10 = require("@dxos/protocols");
187
+ var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
184
188
  var import_teleport_extension_gossip = require("@dxos/teleport-extension-gossip");
185
189
  var import_util6 = require("@dxos/util");
186
190
  var import_credentials13 = require("@dxos/credentials");
@@ -190,30 +194,30 @@ var import_timeframe3 = require("@dxos/timeframe");
190
194
  var import_async13 = require("@dxos/async");
191
195
  var import_codec_protobuf11 = require("@dxos/codec-protobuf");
192
196
  var import_debug6 = require("@dxos/debug");
193
- var import_invariant12 = require("@dxos/invariant");
197
+ var import_invariant13 = require("@dxos/invariant");
194
198
  var import_log12 = require("@dxos/log");
195
- var import_protocols9 = require("@dxos/protocols");
196
- var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
199
+ var import_protocols11 = require("@dxos/protocols");
200
+ var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
197
201
  var import_async14 = require("@dxos/async");
198
202
  var import_context9 = require("@dxos/context");
199
203
  var import_credentials15 = require("@dxos/credentials");
200
204
  var import_debug7 = require("@dxos/debug");
201
205
  var import_echo_pipeline2 = require("@dxos/echo-pipeline");
202
206
  var import_feed_store4 = require("@dxos/feed-store");
203
- var import_invariant13 = require("@dxos/invariant");
207
+ var import_invariant14 = require("@dxos/invariant");
204
208
  var import_keyring = require("@dxos/keyring");
205
209
  var import_keys10 = require("@dxos/keys");
206
210
  var import_log13 = require("@dxos/log");
207
- var import_protocols10 = require("@dxos/protocols");
208
- var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
211
+ var import_protocols12 = require("@dxos/protocols");
212
+ var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
209
213
  var import_teleport_extension_object_sync = require("@dxos/teleport-extension-object-sync");
210
214
  var import_tracing5 = require("@dxos/tracing");
211
215
  var import_util7 = require("@dxos/util");
212
- var import_invariant14 = require("@dxos/invariant");
216
+ var import_invariant15 = require("@dxos/invariant");
213
217
  var import_lock_file = require("@dxos/lock-file");
214
218
  var import_log14 = require("@dxos/log");
215
219
  var import_client_protocol4 = require("@dxos/client-protocol");
216
- var import_protocols11 = require("@dxos/protocols");
220
+ var import_protocols13 = require("@dxos/protocols");
217
221
  var import_config = require("@dxos/protocols/proto/dxos/config");
218
222
  var import_random_access_storage = require("@dxos/random-access-storage");
219
223
  var import_util8 = require("@dxos/util");
@@ -223,28 +227,28 @@ var import_context10 = require("@dxos/context");
223
227
  var import_document_model2 = require("@dxos/document-model");
224
228
  var import_echo_pipeline3 = require("@dxos/echo-pipeline");
225
229
  var import_echo_schema = require("@dxos/echo-schema");
226
- var import_invariant15 = require("@dxos/invariant");
230
+ var import_invariant16 = require("@dxos/invariant");
227
231
  var import_keys11 = require("@dxos/keys");
228
232
  var import_log15 = require("@dxos/log");
229
233
  var import_messaging = require("@dxos/messaging");
230
234
  var import_model_factory = require("@dxos/model-factory");
231
235
  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");
236
+ var import_protocols14 = require("@dxos/protocols");
237
+ var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
234
238
  var import_text_model = require("@dxos/text-model");
235
239
  var import_tracing6 = require("@dxos/tracing");
236
240
  var import_websocket_rpc = require("@dxos/websocket-rpc");
237
241
  var import_async16 = require("@dxos/async");
238
242
  var import_codec_protobuf12 = require("@dxos/codec-protobuf");
239
- var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
243
+ var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
240
244
  var import_async17 = require("@dxos/async");
241
245
  var import_codec_protobuf13 = require("@dxos/codec-protobuf");
242
246
  var import_log16 = require("@dxos/log");
243
- var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
247
+ var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
244
248
  var import_util9 = require("@dxos/util");
245
249
  var import_codec_protobuf14 = require("@dxos/codec-protobuf");
246
250
  var import_codec_protobuf15 = require("@dxos/codec-protobuf");
247
- var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
251
+ var import_services15 = require("@dxos/protocols/proto/dxos/client/services");
248
252
  var import_util10 = require("@dxos/util");
249
253
  var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
250
254
  return new import_codec_protobuf.Stream(({ next }) => {
@@ -675,7 +679,7 @@ function _ts_decorate(decorators, target, key, desc) {
675
679
  return c > 3 && r && Object.defineProperty(target, key, r), r;
676
680
  }
677
681
  var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity.ts";
678
- var Identity = class Identity2 {
682
+ var Identity = class {
679
683
  constructor({ space, signer, identityKey, deviceKey }) {
680
684
  this.stateUpdate = new import_async5.Event();
681
685
  this.space = space;
@@ -843,7 +847,7 @@ function _ts_decorate2(decorators, target, key, desc) {
843
847
  return c > 3 && r && Object.defineProperty(target, key, r), r;
844
848
  }
845
849
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-manager.ts";
846
- var IdentityManager = class IdentityManager2 {
850
+ var IdentityManager = class {
847
851
  // TODO(burdon): IdentityManagerParams.
848
852
  // TODO(dmaretskyi): Perhaps this should take/generate the peerKey outside of an initialized identity.
849
853
  constructor(_metadataStore, _keyring, _feedStore, _spaceManager) {
@@ -1174,7 +1178,7 @@ var IdentityManager = class IdentityManager2 {
1174
1178
  genesisFeedKey: spaceRecord.genesisFeedKey
1175
1179
  },
1176
1180
  swarmIdentity,
1177
- onNetworkConnection: () => {
1181
+ onAuthorizedConnection: () => {
1178
1182
  },
1179
1183
  onAuthFailure: () => {
1180
1184
  import_log3.log.warn("auth failure", void 0, {
@@ -1197,6 +1201,7 @@ IdentityManager = _ts_decorate2([
1197
1201
  import_tracing2.trace.resource()
1198
1202
  ], IdentityManager);
1199
1203
  var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
1204
+ var CREATE_PROFILE_WITH_AUTOMERGE_DEFAULT = true;
1200
1205
  var IdentityServiceImpl = class {
1201
1206
  constructor(_createIdentity, _identityManager, _keyring, _onProfileUpdate) {
1202
1207
  this._createIdentity = _createIdentity;
@@ -1205,7 +1210,7 @@ var IdentityServiceImpl = class {
1205
1210
  this._onProfileUpdate = _onProfileUpdate;
1206
1211
  }
1207
1212
  async createIdentity(request) {
1208
- await this._createIdentity(request);
1213
+ await this._createIdentity(request.profile ?? {}, request.useAutomerge ?? CREATE_PROFILE_WITH_AUTOMERGE_DEFAULT);
1209
1214
  return this._getIdentity();
1210
1215
  }
1211
1216
  async recoverIdentity(request) {
@@ -1233,7 +1238,7 @@ var IdentityServiceImpl = class {
1233
1238
  async updateProfile(profile) {
1234
1239
  (0, import_invariant3.invariant)(this._identityManager.identity, "Identity not initialized.", {
1235
1240
  F: __dxlog_file4,
1236
- L: 60,
1241
+ L: 63,
1237
1242
  S: this,
1238
1243
  A: [
1239
1244
  "this._identityManager.identity",
@@ -1247,7 +1252,7 @@ var IdentityServiceImpl = class {
1247
1252
  async signPresentation({ presentation, nonce }) {
1248
1253
  (0, import_invariant3.invariant)(this._identityManager.identity, "Identity not initialized.", {
1249
1254
  F: __dxlog_file4,
1250
- L: 67,
1255
+ L: 70,
1251
1256
  S: this,
1252
1257
  A: [
1253
1258
  "this._identityManager.identity",
@@ -1281,7 +1286,7 @@ var DeviceInvitationProtocol = class {
1281
1286
  async admit(request) {
1282
1287
  (0, import_invariant4.invariant)(request.device, void 0, {
1283
1288
  F: __dxlog_file5,
1284
- L: 35,
1289
+ L: 36,
1285
1290
  S: this,
1286
1291
  A: [
1287
1292
  "request.device",
@@ -1299,6 +1304,15 @@ var DeviceInvitationProtocol = class {
1299
1304
  }
1300
1305
  };
1301
1306
  }
1307
+ checkInvitation(invitation) {
1308
+ try {
1309
+ const identity = this._getIdentity();
1310
+ if (identity) {
1311
+ return new import_protocols3.AlreadyJoinedError("Currently only one identity per client is supported.");
1312
+ }
1313
+ } catch {
1314
+ }
1315
+ }
1302
1316
  createIntroduction() {
1303
1317
  return {};
1304
1318
  }
@@ -1317,7 +1331,7 @@ var DeviceInvitationProtocol = class {
1317
1331
  async accept(response, request) {
1318
1332
  (0, import_invariant4.invariant)(response.device, void 0, {
1319
1333
  F: __dxlog_file5,
1320
- L: 68,
1334
+ L: 80,
1321
1335
  S: this,
1322
1336
  A: [
1323
1337
  "response.device",
@@ -1327,7 +1341,7 @@ var DeviceInvitationProtocol = class {
1327
1341
  const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
1328
1342
  (0, import_invariant4.invariant)(request.device, void 0, {
1329
1343
  F: __dxlog_file5,
1330
- L: 71,
1344
+ L: 83,
1331
1345
  S: this,
1332
1346
  A: [
1333
1347
  "request.device",
@@ -1356,10 +1370,10 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1356
1370
  constructor(_callbacks) {
1357
1371
  super({
1358
1372
  requested: {
1359
- InvitationHostService: import_protocols4.schema.getService("dxos.halo.invitations.InvitationHostService")
1373
+ InvitationHostService: import_protocols5.schema.getService("dxos.halo.invitations.InvitationHostService")
1360
1374
  },
1361
1375
  exposed: {
1362
- InvitationHostService: import_protocols4.schema.getService("dxos.halo.invitations.InvitationHostService")
1376
+ InvitationHostService: import_protocols5.schema.getService("dxos.halo.invitations.InvitationHostService")
1363
1377
  }
1364
1378
  });
1365
1379
  this._callbacks = _callbacks;
@@ -1392,7 +1406,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1392
1406
  introduce: async (request) => {
1393
1407
  const { profile, invitationId } = request;
1394
1408
  const traceId = import_keys6.PublicKey.random().toHex();
1395
- import_log5.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols4.trace.begin({
1409
+ import_log5.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols5.trace.begin({
1396
1410
  id: traceId
1397
1411
  }), {
1398
1412
  F: __dxlog_file6,
@@ -1429,7 +1443,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1429
1443
  ...this.invitation,
1430
1444
  state: import_services3.Invitation.State.READY_FOR_AUTHENTICATION
1431
1445
  });
1432
- import_log5.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols4.trace.end({
1446
+ import_log5.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols5.trace.end({
1433
1447
  id: traceId
1434
1448
  }), {
1435
1449
  F: __dxlog_file6,
@@ -1443,7 +1457,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1443
1457
  },
1444
1458
  authenticate: async ({ authCode: code }) => {
1445
1459
  const traceId = import_keys6.PublicKey.random().toHex();
1446
- import_log5.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols4.trace.begin({
1460
+ import_log5.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols5.trace.begin({
1447
1461
  id: traceId
1448
1462
  }), {
1449
1463
  F: __dxlog_file6,
@@ -1506,7 +1520,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1506
1520
  break;
1507
1521
  }
1508
1522
  }
1509
- import_log5.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols4.trace.end({
1523
+ import_log5.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols5.trace.end({
1510
1524
  id: traceId,
1511
1525
  data: {
1512
1526
  status
@@ -1523,7 +1537,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1523
1537
  },
1524
1538
  admit: async (request) => {
1525
1539
  const traceId = import_keys6.PublicKey.random().toHex();
1526
- import_log5.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols4.trace.begin({
1540
+ import_log5.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols5.trace.begin({
1527
1541
  id: traceId
1528
1542
  }), {
1529
1543
  F: __dxlog_file6,
@@ -1545,7 +1559,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1545
1559
  throw new Error("Not authenticated");
1546
1560
  }
1547
1561
  const response = await this._callbacks.admit(request);
1548
- import_log5.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols4.trace.end({
1562
+ import_log5.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols5.trace.end({
1549
1563
  id: traceId
1550
1564
  }), {
1551
1565
  F: __dxlog_file6,
@@ -1572,7 +1586,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1572
1586
  timeout: OPTIONS_TIMEOUT
1573
1587
  }));
1574
1588
  if (this._remoteOptions?.role !== import_invitations2.Options.Role.GUEST) {
1575
- throw new import_protocols4.InvalidInvitationExtensionRoleError(void 0, {
1589
+ throw new import_protocols5.InvalidInvitationExtensionRoleError(void 0, {
1576
1590
  expected: import_invitations2.Options.Role.GUEST,
1577
1591
  remoteOptions: this._remoteOptions
1578
1592
  });
@@ -1590,10 +1604,10 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1590
1604
  constructor(_callbacks) {
1591
1605
  super({
1592
1606
  requested: {
1593
- InvitationHostService: import_protocols4.schema.getService("dxos.halo.invitations.InvitationHostService")
1607
+ InvitationHostService: import_protocols5.schema.getService("dxos.halo.invitations.InvitationHostService")
1594
1608
  },
1595
1609
  exposed: {
1596
- InvitationHostService: import_protocols4.schema.getService("dxos.halo.invitations.InvitationHostService")
1610
+ InvitationHostService: import_protocols5.schema.getService("dxos.halo.invitations.InvitationHostService")
1597
1611
  }
1598
1612
  });
1599
1613
  this._callbacks = _callbacks;
@@ -1650,7 +1664,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1650
1664
  C: (f, a) => f(...a)
1651
1665
  });
1652
1666
  if (this._remoteOptions?.role !== import_invitations2.Options.Role.HOST) {
1653
- throw new import_protocols4.InvalidInvitationExtensionRoleError(void 0, {
1667
+ throw new import_protocols5.InvalidInvitationExtensionRoleError(void 0, {
1654
1668
  expected: import_invitations2.Options.Role.HOST,
1655
1669
  remoteOptions: this._remoteOptions
1656
1670
  });
@@ -1763,7 +1777,7 @@ var InvitationsHandler = class {
1763
1777
  (0, import_async7.scheduleTask)(ctx, async () => {
1764
1778
  const traceId = import_keys5.PublicKey.random().toHex();
1765
1779
  try {
1766
- import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols3.trace.begin({
1780
+ import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.begin({
1767
1781
  id: traceId
1768
1782
  }), {
1769
1783
  F: __dxlog_file7,
@@ -1799,7 +1813,7 @@ var InvitationsHandler = class {
1799
1813
  ...invitation,
1800
1814
  state: import_services2.Invitation.State.SUCCESS
1801
1815
  });
1802
- import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols3.trace.end({
1816
+ import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.end({
1803
1817
  id: traceId
1804
1818
  }), {
1805
1819
  F: __dxlog_file7,
@@ -1830,7 +1844,7 @@ var InvitationsHandler = class {
1830
1844
  });
1831
1845
  stream.error(err);
1832
1846
  }
1833
- import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols3.trace.error({
1847
+ import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.error({
1834
1848
  id: traceId,
1835
1849
  error: err
1836
1850
  }), {
@@ -1848,7 +1862,7 @@ var InvitationsHandler = class {
1848
1862
  });
1849
1863
  },
1850
1864
  onError: (err) => {
1851
- if (err instanceof import_protocols3.InvalidInvitationExtensionRoleError) {
1865
+ if (err instanceof import_protocols4.InvalidInvitationExtensionRoleError) {
1852
1866
  return;
1853
1867
  }
1854
1868
  if (err instanceof import_async7.TimeoutError) {
@@ -1996,7 +2010,7 @@ var InvitationsHandler = class {
1996
2010
  (0, import_async7.scheduleTask)(ctx, async () => {
1997
2011
  const traceId = import_keys5.PublicKey.random().toHex();
1998
2012
  try {
1999
- import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols3.trace.begin({
2013
+ import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.begin({
2000
2014
  id: traceId
2001
2015
  }), {
2002
2016
  F: __dxlog_file7,
@@ -2083,16 +2097,12 @@ var InvitationsHandler = class {
2083
2097
  }
2084
2098
  }
2085
2099
  }
2086
- } else {
2087
- setState({
2088
- state: import_services2.Invitation.State.READY_FOR_AUTHENTICATION
2089
- });
2090
2100
  }
2091
2101
  (0, import_log4.log)("request admission", {
2092
2102
  ...protocol.toJSON()
2093
2103
  }, {
2094
2104
  F: __dxlog_file7,
2095
- L: 312,
2105
+ L: 309,
2096
2106
  S: this,
2097
2107
  C: (f, a) => f(...a)
2098
2108
  });
@@ -2104,19 +2114,20 @@ var InvitationsHandler = class {
2104
2114
  ...protocol.toJSON()
2105
2115
  }, {
2106
2116
  F: __dxlog_file7,
2107
- L: 323,
2117
+ L: 320,
2108
2118
  S: this,
2109
2119
  C: (f, a) => f(...a)
2110
2120
  });
2111
2121
  setState({
2112
2122
  ...result,
2123
+ target: invitation.target,
2113
2124
  state: import_services2.Invitation.State.SUCCESS
2114
2125
  });
2115
- import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols3.trace.end({
2126
+ import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.end({
2116
2127
  id: traceId
2117
2128
  }), {
2118
2129
  F: __dxlog_file7,
2119
- L: 325,
2130
+ L: 322,
2120
2131
  S: this,
2121
2132
  C: (f, a) => f(...a)
2122
2133
  });
@@ -2126,7 +2137,7 @@ var InvitationsHandler = class {
2126
2137
  ...protocol.toJSON()
2127
2138
  }, {
2128
2139
  F: __dxlog_file7,
2129
- L: 328,
2140
+ L: 325,
2130
2141
  S: this,
2131
2142
  C: (f, a) => f(...a)
2132
2143
  });
@@ -2136,18 +2147,18 @@ var InvitationsHandler = class {
2136
2147
  } else {
2137
2148
  (0, import_log4.log)("auth failed", err, {
2138
2149
  F: __dxlog_file7,
2139
- L: 331,
2150
+ L: 328,
2140
2151
  S: this,
2141
2152
  C: (f, a) => f(...a)
2142
2153
  });
2143
2154
  stream.error(err);
2144
2155
  }
2145
- import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols3.trace.error({
2156
+ import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.error({
2146
2157
  id: traceId,
2147
2158
  error: err
2148
2159
  }), {
2149
2160
  F: __dxlog_file7,
2150
- L: 334,
2161
+ L: 331,
2151
2162
  S: this,
2152
2163
  C: (f, a) => f(...a)
2153
2164
  });
@@ -2157,7 +2168,7 @@ var InvitationsHandler = class {
2157
2168
  });
2158
2169
  },
2159
2170
  onError: (err) => {
2160
- if (err instanceof import_protocols3.InvalidInvitationExtensionRoleError) {
2171
+ if (err instanceof import_protocols4.InvalidInvitationExtensionRoleError) {
2161
2172
  return;
2162
2173
  }
2163
2174
  if (err instanceof import_async7.TimeoutError) {
@@ -2165,7 +2176,7 @@ var InvitationsHandler = class {
2165
2176
  ...protocol.toJSON()
2166
2177
  }, {
2167
2178
  F: __dxlog_file7,
2168
- L: 345,
2179
+ L: 342,
2169
2180
  S: this,
2170
2181
  C: (f, a) => f(...a)
2171
2182
  });
@@ -2175,7 +2186,7 @@ var InvitationsHandler = class {
2175
2186
  } else {
2176
2187
  (0, import_log4.log)("auth failed", err, {
2177
2188
  F: __dxlog_file7,
2178
- L: 348,
2189
+ L: 345,
2179
2190
  S: this,
2180
2191
  C: (f, a) => f(...a)
2181
2192
  });
@@ -2186,29 +2197,34 @@ var InvitationsHandler = class {
2186
2197
  return extension;
2187
2198
  };
2188
2199
  (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
- });
2200
+ const error = protocol.checkInvitation(invitation);
2201
+ if (error) {
2202
+ stream.error(error);
2203
+ } else {
2204
+ (0, import_invariant5.invariant)(invitation.swarmKey, void 0, {
2205
+ F: __dxlog_file7,
2206
+ L: 359,
2207
+ S: this,
2208
+ A: [
2209
+ "invitation.swarmKey",
2210
+ ""
2211
+ ]
2212
+ });
2213
+ const topic = invitation.swarmKey;
2214
+ const swarmConnection = await this._networkManager.joinSwarm({
2215
+ topic,
2216
+ peerId: import_keys5.PublicKey.random(),
2217
+ protocolProvider: (0, import_network_manager.createTeleportProtocolFactory)(async (teleport) => {
2218
+ teleport.addExtension("dxos.halo.invitations", createExtension());
2219
+ }),
2220
+ topology: new import_network_manager.StarTopology(topic),
2221
+ label: "invitation guest"
2222
+ });
2223
+ ctx.onDispose(() => swarmConnection.close());
2224
+ setState({
2225
+ state: import_services2.Invitation.State.CONNECTING
2226
+ });
2227
+ }
2212
2228
  });
2213
2229
  const observable = new import_client_protocol2.AuthenticatingInvitation({
2214
2230
  initialInvitation: invitation,
@@ -2424,7 +2440,7 @@ var SpaceInvitationProtocol = class {
2424
2440
  async admit(request, guestProfile) {
2425
2441
  (0, import_invariant8.invariant)(this._spaceKey, void 0, {
2426
2442
  F: __dxlog_file9,
2427
- L: 46,
2443
+ L: 47,
2428
2444
  S: this,
2429
2445
  A: [
2430
2446
  "this._spaceKey",
@@ -2434,7 +2450,7 @@ var SpaceInvitationProtocol = class {
2434
2450
  const space = await this._spaceManager.spaces.get(this._spaceKey);
2435
2451
  (0, import_invariant8.invariant)(space, void 0, {
2436
2452
  F: __dxlog_file9,
2437
- L: 48,
2453
+ L: 49,
2438
2454
  S: this,
2439
2455
  A: [
2440
2456
  "space",
@@ -2443,7 +2459,7 @@ var SpaceInvitationProtocol = class {
2443
2459
  });
2444
2460
  (0, import_invariant8.invariant)(request.space, void 0, {
2445
2461
  F: __dxlog_file9,
2446
- L: 50,
2462
+ L: 51,
2447
2463
  S: this,
2448
2464
  A: [
2449
2465
  "request.space",
@@ -2456,14 +2472,14 @@ var SpaceInvitationProtocol = class {
2456
2472
  guest: deviceKey
2457
2473
  }, {
2458
2474
  F: __dxlog_file9,
2459
- L: 53,
2475
+ L: 54,
2460
2476
  S: this,
2461
2477
  C: (f, a) => f(...a)
2462
2478
  });
2463
2479
  const credentials = await (0, import_credentials8.createAdmissionCredentials)(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile);
2464
2480
  (0, import_invariant8.invariant)(credentials[0].credential, void 0, {
2465
2481
  F: __dxlog_file9,
2466
- L: 64,
2482
+ L: 65,
2467
2483
  S: this,
2468
2484
  A: [
2469
2485
  "credentials[0].credential",
@@ -2473,7 +2489,7 @@ var SpaceInvitationProtocol = class {
2473
2489
  const spaceMemberCredential = credentials[0].credential.credential;
2474
2490
  (0, import_invariant8.invariant)((0, import_credentials8.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2475
2491
  F: __dxlog_file9,
2476
- L: 66,
2492
+ L: 67,
2477
2493
  S: this,
2478
2494
  A: [
2479
2495
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2489,6 +2505,11 @@ var SpaceInvitationProtocol = class {
2489
2505
  }
2490
2506
  };
2491
2507
  }
2508
+ checkInvitation(invitation) {
2509
+ if (invitation.spaceKey && this._spaceManager.spaces.has(invitation.spaceKey)) {
2510
+ return new import_protocols6.AlreadyJoinedError("Already joined space.");
2511
+ }
2512
+ }
2492
2513
  createIntroduction() {
2493
2514
  return {
2494
2515
  profile: this._signingContext.getProfile()
@@ -2509,7 +2530,7 @@ var SpaceInvitationProtocol = class {
2509
2530
  async accept(response) {
2510
2531
  (0, import_invariant8.invariant)(response.space, void 0, {
2511
2532
  F: __dxlog_file9,
2512
- L: 101,
2533
+ L: 108,
2513
2534
  S: this,
2514
2535
  A: [
2515
2536
  "response.space",
@@ -2520,7 +2541,7 @@ var SpaceInvitationProtocol = class {
2520
2541
  const assertion = (0, import_credentials8.getCredentialAssertion)(credential);
2521
2542
  (0, import_invariant8.invariant)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2522
2543
  F: __dxlog_file9,
2523
- L: 104,
2544
+ L: 111,
2524
2545
  S: this,
2525
2546
  A: [
2526
2547
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2529,13 +2550,16 @@ var SpaceInvitationProtocol = class {
2529
2550
  });
2530
2551
  (0, import_invariant8.invariant)(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
2531
2552
  F: __dxlog_file9,
2532
- L: 105,
2553
+ L: 112,
2533
2554
  S: this,
2534
2555
  A: [
2535
2556
  "credential.subject.id.equals(this._signingContext.identityKey)",
2536
2557
  ""
2537
2558
  ]
2538
2559
  });
2560
+ if (this._spaceManager.spaces.has(assertion.spaceKey)) {
2561
+ throw new import_protocols6.AlreadyJoinedError("Already joined space.");
2562
+ }
2539
2563
  await this._spaceManager.acceptSpace({
2540
2564
  spaceKey: assertion.spaceKey,
2541
2565
  genesisFeedKey: assertion.genesisFeedKey,
@@ -2558,7 +2582,7 @@ function _ts_decorate3(decorators, target, key, desc) {
2558
2582
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2559
2583
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2560
2584
  }
2561
- var ClientRpcServer = class ClientRpcServer2 {
2585
+ var ClientRpcServer = class {
2562
2586
  constructor(params) {
2563
2587
  this._handlerCache = /* @__PURE__ */ new Map();
2564
2588
  this._callMetrics = new import_tracing3.MapCounter();
@@ -2628,28 +2652,29 @@ var getPlatform = () => {
2628
2652
  if (typeof window !== "undefined") {
2629
2653
  const { userAgent } = window.navigator;
2630
2654
  return {
2631
- type: "browser",
2655
+ type: import_services7.Platform.PLATFORM_TYPE.BROWSER,
2632
2656
  userAgent,
2633
2657
  uptime: Math.floor((Date.now() - window.performance.timeOrigin) / 1e3)
2634
2658
  };
2635
2659
  } else {
2636
2660
  return {
2637
- type: "shared-worker",
2661
+ type: import_services7.Platform.PLATFORM_TYPE.SHARED_WORKER,
2638
2662
  uptime: Math.floor((Date.now() - performance.timeOrigin) / 1e3)
2639
2663
  };
2640
2664
  }
2641
2665
  } else {
2642
2666
  const { platform: platform2, version, arch } = process;
2643
2667
  return {
2644
- type: "node",
2645
- platform: `${platform2} ${version} ${arch}`,
2646
- runtime: process.version,
2668
+ type: import_services7.Platform.PLATFORM_TYPE.NODE,
2669
+ platform: platform2,
2670
+ arch,
2671
+ runtime: version,
2647
2672
  uptime: Math.floor(process.uptime()),
2648
2673
  memory: process.memoryUsage()
2649
2674
  };
2650
2675
  }
2651
2676
  };
2652
- var DXOS_VERSION = "0.3.11-main.e0dc42b";
2677
+ var DXOS_VERSION = "0.3.11-main.e19f39d";
2653
2678
  var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
2654
2679
  var DEFAULT_TIMEOUT = 1e3;
2655
2680
  var createDiagnostics = async (clientServices, serviceContext, config) => {
@@ -2659,14 +2684,14 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
2659
2684
  client: {
2660
2685
  version: DXOS_VERSION,
2661
2686
  storage: {
2662
- version: import_protocols5.STORAGE_VERSION
2687
+ version: import_protocols7.STORAGE_VERSION
2663
2688
  }
2664
2689
  }
2665
2690
  };
2666
2691
  {
2667
2692
  (0, import_invariant9.invariant)(clientServices.LoggingService, "SystemService is not available.", {
2668
2693
  F: __dxlog_file10,
2669
- L: 92,
2694
+ L: 94,
2670
2695
  S: void 0,
2671
2696
  A: [
2672
2697
  "clientServices.LoggingService",
@@ -2677,6 +2702,21 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
2677
2702
  timeout: DEFAULT_TIMEOUT
2678
2703
  }).catch(() => void 0);
2679
2704
  }
2705
+ if (typeof navigator !== "undefined" && navigator.storage) {
2706
+ const map = /* @__PURE__ */ new Map();
2707
+ const dir = await navigator.storage.getDirectory();
2708
+ for await (const filename of dir?.keys()) {
2709
+ const idx = filename.indexOf("-", filename.indexOf("-") + 1);
2710
+ if (idx === -1) {
2711
+ continue;
2712
+ }
2713
+ map.set(filename.slice(0, idx), (map.get(filename.slice(0, idx)) ?? 0) + 1);
2714
+ }
2715
+ diagnostics.storage = Array.from(map.entries()).sort((a, b) => b[1] - a[1]).map(([file, count]) => ({
2716
+ file,
2717
+ count
2718
+ }));
2719
+ }
2680
2720
  const identity = serviceContext.identityManager.identity;
2681
2721
  if (identity) {
2682
2722
  diagnostics.identity = {
@@ -2717,7 +2757,7 @@ var getProperties = (space) => {
2717
2757
  } catch (err) {
2718
2758
  import_log8.log.warn(err.message, void 0, {
2719
2759
  F: __dxlog_file10,
2720
- L: 160,
2760
+ L: 179,
2721
2761
  S: void 0,
2722
2762
  C: (f, a) => f(...a)
2723
2763
  });
@@ -2772,7 +2812,8 @@ var getSpaceStats = async (space) => {
2772
2812
  return stats;
2773
2813
  };
2774
2814
  var AutomergeSpaceState = class {
2775
- constructor() {
2815
+ constructor(_onNewRoot) {
2816
+ this._onNewRoot = _onNewRoot;
2776
2817
  this.rootUrl = void 0;
2777
2818
  this.lastEpoch = void 0;
2778
2819
  }
@@ -2783,6 +2824,7 @@ var AutomergeSpaceState = class {
2783
2824
  this.lastEpoch = credential;
2784
2825
  if (credential.subject.assertion.automergeRoot) {
2785
2826
  this.rootUrl = credential.subject.assertion.automergeRoot;
2827
+ this._onNewRoot(this.rootUrl);
2786
2828
  }
2787
2829
  }
2788
2830
  };
@@ -2819,7 +2861,7 @@ var NotarizationPlugin = class {
2819
2861
  S: this,
2820
2862
  C: (f, a) => f(...a)
2821
2863
  });
2822
- (0, import_invariant10.invariant)(credentials.every((credential) => credential.id), "Credentials must have an id", {
2864
+ (0, import_invariant11.invariant)(credentials.every((credential) => credential.id), "Credentials must have an id", {
2823
2865
  F: __dxlog_file11,
2824
2866
  L: 91,
2825
2867
  S: this,
@@ -2944,7 +2986,7 @@ var NotarizationPlugin = class {
2944
2986
  this._processCredentialsTriggers.delete(credential.id);
2945
2987
  }
2946
2988
  setWriter(writer) {
2947
- (0, import_invariant10.invariant)(!this._writer, "Writer already set.", {
2989
+ (0, import_invariant11.invariant)(!this._writer, "Writer already set.", {
2948
2990
  F: __dxlog_file11,
2949
2991
  L: 181,
2950
2992
  S: this,
@@ -2969,7 +3011,7 @@ var NotarizationPlugin = class {
2969
3011
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
2970
3012
  }
2971
3013
  for (const credential of request.credentials ?? []) {
2972
- (0, import_invariant10.invariant)(credential.id, "Credential must have an id", {
3014
+ (0, import_invariant11.invariant)(credential.id, "Credential must have an id", {
2973
3015
  F: __dxlog_file11,
2974
3016
  L: 200,
2975
3017
  S: this,
@@ -3018,10 +3060,10 @@ var NotarizationTeleportExtension = class extends import_teleport2.RpcExtension
3018
3060
  constructor(_params) {
3019
3061
  super({
3020
3062
  requested: {
3021
- NotarizationService: import_protocols7.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3063
+ NotarizationService: import_protocols9.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3022
3064
  },
3023
3065
  exposed: {
3024
- NotarizationService: import_protocols7.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3066
+ NotarizationService: import_protocols9.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3025
3067
  }
3026
3068
  });
3027
3069
  this._params = _params;
@@ -3056,13 +3098,13 @@ function _ts_decorate4(decorators, target, key, desc) {
3056
3098
  }
3057
3099
  var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
3058
3100
  var ENABLE_FEED_PURGE = false;
3059
- var DataSpace = class DataSpace2 {
3101
+ var DataSpace = class {
3060
3102
  constructor(params) {
3061
3103
  this._ctx = new import_context6.Context();
3062
3104
  this._notarizationPlugin = new NotarizationPlugin();
3063
3105
  this._cache = void 0;
3064
- this._automergeSpaceState = new AutomergeSpaceState();
3065
- this._state = import_services7.SpaceState.CLOSED;
3106
+ this._automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
3107
+ this._state = import_services8.SpaceState.CLOSED;
3066
3108
  this.error = void 0;
3067
3109
  this.stateUpdate = new import_async10.Event();
3068
3110
  this.metrics = {};
@@ -3084,10 +3126,10 @@ var DataSpace = class DataSpace2 {
3084
3126
  this._cache = params.cache;
3085
3127
  this._state = params.initialState;
3086
3128
  (0, import_log9.log)("new state", {
3087
- state: import_services7.SpaceState[this._state]
3129
+ state: import_services8.SpaceState[this._state]
3088
3130
  }, {
3089
3131
  F: __dxlog_file12,
3090
- L: 137,
3132
+ L: 138,
3091
3133
  S: this,
3092
3134
  C: (f, a) => f(...a)
3093
3135
  });
@@ -3129,12 +3171,12 @@ var DataSpace = class DataSpace2 {
3129
3171
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
3130
3172
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
3131
3173
  await this._inner.open(new import_context6.Context());
3132
- this._state = import_services7.SpaceState.CONTROL_ONLY;
3174
+ this._state = import_services8.SpaceState.CONTROL_ONLY;
3133
3175
  (0, import_log9.log)("new state", {
3134
- state: import_services7.SpaceState[this._state]
3176
+ state: import_services8.SpaceState[this._state]
3135
3177
  }, {
3136
3178
  F: __dxlog_file12,
3137
- L: 189,
3179
+ L: 190,
3138
3180
  S: this,
3139
3181
  C: (f, a) => f(...a)
3140
3182
  });
@@ -3147,12 +3189,12 @@ var DataSpace = class DataSpace2 {
3147
3189
  }
3148
3190
  async _close() {
3149
3191
  await this._callbacks.beforeClose?.();
3150
- this._state = import_services7.SpaceState.CLOSED;
3192
+ this._state = import_services8.SpaceState.CLOSED;
3151
3193
  (0, import_log9.log)("new state", {
3152
- state: import_services7.SpaceState[this._state]
3194
+ state: import_services8.SpaceState[this._state]
3153
3195
  }, {
3154
3196
  F: __dxlog_file12,
3155
- L: 203,
3197
+ L: 204,
3156
3198
  S: this,
3157
3199
  C: (f, a) => f(...a)
3158
3200
  });
@@ -3181,10 +3223,10 @@ var DataSpace = class DataSpace2 {
3181
3223
  this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
3182
3224
  await this.initializeDataPipeline();
3183
3225
  } catch (err) {
3184
- if (err instanceof import_protocols6.CancelledError) {
3226
+ if (err instanceof import_protocols8.CancelledError) {
3185
3227
  (0, import_log9.log)("data pipeline initialization cancelled", err, {
3186
3228
  F: __dxlog_file12,
3187
- L: 236,
3229
+ L: 237,
3188
3230
  S: this,
3189
3231
  C: (f, a) => f(...a)
3190
3232
  });
@@ -3192,16 +3234,16 @@ var DataSpace = class DataSpace2 {
3192
3234
  }
3193
3235
  import_log9.log.error("Error initializing data pipeline", err, {
3194
3236
  F: __dxlog_file12,
3195
- L: 240,
3237
+ L: 241,
3196
3238
  S: this,
3197
3239
  C: (f, a) => f(...a)
3198
3240
  });
3199
- this._state = import_services7.SpaceState.ERROR;
3241
+ this._state = import_services8.SpaceState.ERROR;
3200
3242
  (0, import_log9.log)("new state", {
3201
- state: import_services7.SpaceState[this._state]
3243
+ state: import_services8.SpaceState[this._state]
3202
3244
  }, {
3203
3245
  F: __dxlog_file12,
3204
- L: 242,
3246
+ L: 243,
3205
3247
  S: this,
3206
3248
  C: (f, a) => f(...a)
3207
3249
  });
@@ -3213,15 +3255,15 @@ var DataSpace = class DataSpace2 {
3213
3255
  });
3214
3256
  }
3215
3257
  async initializeDataPipeline() {
3216
- if (this._state !== import_services7.SpaceState.CONTROL_ONLY) {
3217
- throw new import_protocols6.SystemError("Invalid operation");
3258
+ if (this._state !== import_services8.SpaceState.CONTROL_ONLY) {
3259
+ throw new import_protocols8.SystemError("Invalid operation");
3218
3260
  }
3219
- this._state = import_services7.SpaceState.INITIALIZING;
3261
+ this._state = import_services8.SpaceState.INITIALIZING;
3220
3262
  (0, import_log9.log)("new state", {
3221
- state: import_services7.SpaceState[this._state]
3263
+ state: import_services8.SpaceState[this._state]
3222
3264
  }, {
3223
3265
  F: __dxlog_file12,
3224
- L: 258,
3266
+ L: 259,
3225
3267
  S: this,
3226
3268
  C: (f, a) => f(...a)
3227
3269
  });
@@ -3232,7 +3274,7 @@ var DataSpace = class DataSpace2 {
3232
3274
  await (0, import_context6.cancelWithContext)(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
3233
3275
  (0, import_log9.log)("waiting for data pipeline to reach target timeframe", void 0, {
3234
3276
  F: __dxlog_file12,
3235
- L: 272,
3277
+ L: 273,
3236
3278
  S: this,
3237
3279
  C: (f, a) => f(...a)
3238
3280
  });
@@ -3243,17 +3285,17 @@ var DataSpace = class DataSpace2 {
3243
3285
  this.metrics.dataPipelineReady = /* @__PURE__ */ new Date();
3244
3286
  (0, import_log9.log)("data pipeline ready", void 0, {
3245
3287
  F: __dxlog_file12,
3246
- L: 281,
3288
+ L: 282,
3247
3289
  S: this,
3248
3290
  C: (f, a) => f(...a)
3249
3291
  });
3250
3292
  await this._callbacks.beforeReady?.();
3251
- this._state = import_services7.SpaceState.READY;
3293
+ this._state = import_services8.SpaceState.READY;
3252
3294
  (0, import_log9.log)("new state", {
3253
- state: import_services7.SpaceState[this._state]
3295
+ state: import_services8.SpaceState[this._state]
3254
3296
  }, {
3255
3297
  F: __dxlog_file12,
3256
- L: 285,
3298
+ L: 286,
3257
3299
  S: this,
3258
3300
  C: (f, a) => f(...a)
3259
3301
  });
@@ -3269,7 +3311,7 @@ var DataSpace = class DataSpace2 {
3269
3311
  await this._createWritableFeeds();
3270
3312
  (0, import_log9.log)("writable feeds created", void 0, {
3271
3313
  F: __dxlog_file12,
3272
- L: 301,
3314
+ L: 302,
3273
3315
  S: this,
3274
3316
  C: (f, a) => f(...a)
3275
3317
  });
@@ -3326,6 +3368,40 @@ var DataSpace = class DataSpace2 {
3326
3368
  await this._metadataStore.setWritableFeedKeys(this.key, this.inner.controlFeedKey, this.inner.dataFeedKey);
3327
3369
  }
3328
3370
  }
3371
+ _onNewAutomergeRoot(rootUrl) {
3372
+ import_log9.log.info("loading automerge root doc for space", {
3373
+ space: this.key,
3374
+ rootUrl
3375
+ }, {
3376
+ F: __dxlog_file12,
3377
+ L: 368,
3378
+ S: this,
3379
+ C: (f, a) => f(...a)
3380
+ });
3381
+ const handle = this._automergeHost.repo.find(rootUrl);
3382
+ queueMicrotask(async () => {
3383
+ try {
3384
+ await handle.whenReady();
3385
+ const doc = handle.docSync() ?? (0, import_invariant10.failedInvariant)();
3386
+ if (!doc.experimental_spaceKey) {
3387
+ handle.change((doc2) => {
3388
+ doc2.experimental_spaceKey = this.key.toHex();
3389
+ });
3390
+ }
3391
+ } catch (err) {
3392
+ import_log9.log.warn("error loading automerge root doc", {
3393
+ space: this.key,
3394
+ rootUrl,
3395
+ err
3396
+ }, {
3397
+ F: __dxlog_file12,
3398
+ L: 381,
3399
+ S: this,
3400
+ C: (f, a) => f(...a)
3401
+ });
3402
+ }
3403
+ });
3404
+ }
3329
3405
  // TODO(dmaretskyi): Use profile from signing context.
3330
3406
  async updateOwnProfile(profile) {
3331
3407
  const credential = await this._signingContext.credentialSigner.createCredential({
@@ -3345,12 +3421,12 @@ var DataSpace = class DataSpace2 {
3345
3421
  let epoch;
3346
3422
  switch (options?.migration) {
3347
3423
  case void 0:
3348
- case import_services7.CreateEpochRequest.Migration.NONE:
3424
+ case import_services8.CreateEpochRequest.Migration.NONE:
3349
3425
  {
3350
3426
  epoch = await this.dataPipeline.createEpoch();
3351
3427
  }
3352
3428
  break;
3353
- case import_services7.CreateEpochRequest.Migration.INIT_AUTOMERGE: {
3429
+ case import_services8.CreateEpochRequest.Migration.INIT_AUTOMERGE: {
3354
3430
  const document = this._automergeHost.repo.create();
3355
3431
  epoch = {
3356
3432
  previousId: this._automergeSpaceState.lastEpoch?.id,
@@ -3391,25 +3467,25 @@ var DataSpace = class DataSpace2 {
3391
3467
  }
3392
3468
  }
3393
3469
  async activate() {
3394
- if (this._state !== import_services7.SpaceState.INACTIVE) {
3470
+ if (this._state !== import_services8.SpaceState.INACTIVE) {
3395
3471
  return;
3396
3472
  }
3397
- await this._metadataStore.setSpaceState(this.key, import_services7.SpaceState.ACTIVE);
3473
+ await this._metadataStore.setSpaceState(this.key, import_services8.SpaceState.ACTIVE);
3398
3474
  await this._open();
3399
3475
  this.initializeDataPipelineAsync();
3400
3476
  }
3401
3477
  async deactivate() {
3402
- if (this._state === import_services7.SpaceState.INACTIVE) {
3478
+ if (this._state === import_services8.SpaceState.INACTIVE) {
3403
3479
  return;
3404
3480
  }
3405
- await this._metadataStore.setSpaceState(this.key, import_services7.SpaceState.INACTIVE);
3481
+ await this._metadataStore.setSpaceState(this.key, import_services8.SpaceState.INACTIVE);
3406
3482
  await this._close();
3407
- this._state = import_services7.SpaceState.INACTIVE;
3483
+ this._state = import_services8.SpaceState.INACTIVE;
3408
3484
  (0, import_log9.log)("new state", {
3409
- state: import_services7.SpaceState[this._state]
3485
+ state: import_services8.SpaceState[this._state]
3410
3486
  }, {
3411
3487
  F: __dxlog_file12,
3412
- L: 450,
3488
+ L: 470,
3413
3489
  S: this,
3414
3490
  C: (f, a) => f(...a)
3415
3491
  });
@@ -3521,7 +3597,7 @@ function _ts_decorate5(decorators, target, key, desc) {
3521
3597
  var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
3522
3598
  var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
3523
3599
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
3524
- var DataSpaceManager = class DataSpaceManager2 {
3600
+ var DataSpaceManager = class {
3525
3601
  constructor(_spaceManager, _metadataStore, _dataServiceSubscriptions, _keyring, _signingContext, _feedStore, _automergeHost) {
3526
3602
  this._spaceManager = _spaceManager;
3527
3603
  this._metadataStore = _metadataStore;
@@ -3547,7 +3623,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3547
3623
  S: this,
3548
3624
  C: (f, a) => f(...a)
3549
3625
  });
3550
- import_log11.log.trace("dxos.echo.data-space-manager.open", import_protocols8.trace.begin({
3626
+ import_log11.log.trace("dxos.echo.data-space-manager.open", import_protocols10.trace.begin({
3551
3627
  id: this._instanceId
3552
3628
  }), {
3553
3629
  F: __dxlog_file13,
@@ -3589,11 +3665,11 @@ var DataSpaceManager = class DataSpaceManager2 {
3589
3665
  this._isOpen = true;
3590
3666
  this.updated.emit();
3591
3667
  for (const space of this._spaces.values()) {
3592
- if (space.state !== import_services8.SpaceState.INACTIVE) {
3668
+ if (space.state !== import_services9.SpaceState.INACTIVE) {
3593
3669
  space.initializeDataPipelineAsync();
3594
3670
  }
3595
3671
  }
3596
- import_log11.log.trace("dxos.echo.data-space-manager.open", import_protocols8.trace.end({
3672
+ import_log11.log.trace("dxos.echo.data-space-manager.open", import_protocols10.trace.end({
3597
3673
  id: this._instanceId
3598
3674
  }), {
3599
3675
  F: __dxlog_file13,
@@ -3619,7 +3695,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3619
3695
  * Creates a new space writing the genesis credentials to the control feed.
3620
3696
  */
3621
3697
  async createSpace() {
3622
- (0, import_invariant11.invariant)(this._isOpen, "Not open.", {
3698
+ (0, import_invariant12.invariant)(this._isOpen, "Not open.", {
3623
3699
  F: __dxlog_file13,
3624
3700
  L: 130,
3625
3701
  S: this,
@@ -3636,7 +3712,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3636
3712
  genesisFeedKey: controlFeedKey,
3637
3713
  controlFeedKey,
3638
3714
  dataFeedKey,
3639
- state: import_services8.SpaceState.ACTIVE
3715
+ state: import_services9.SpaceState.ACTIVE
3640
3716
  };
3641
3717
  (0, import_log11.log)("creating space...", {
3642
3718
  spaceKey
@@ -3648,12 +3724,15 @@ var DataSpaceManager = class DataSpaceManager2 {
3648
3724
  });
3649
3725
  const space = await this._constructSpace(metadata);
3650
3726
  const automergeRoot = this._automergeHost.repo.create();
3727
+ automergeRoot.change((doc) => {
3728
+ doc.experimental_spaceKey = spaceKey.toHex();
3729
+ });
3651
3730
  const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRoot.url);
3652
3731
  await this._metadataStore.addSpace(metadata);
3653
3732
  const memberCredential = credentials[1];
3654
- (0, import_invariant11.invariant)((0, import_credentials12.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3733
+ (0, import_invariant12.invariant)((0, import_credentials12.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3655
3734
  F: __dxlog_file13,
3656
- L: 151,
3735
+ L: 154,
3657
3736
  S: this,
3658
3737
  A: [
3659
3738
  "getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -3671,22 +3750,22 @@ var DataSpaceManager = class DataSpaceManager2 {
3671
3750
  opts
3672
3751
  }, {
3673
3752
  F: __dxlog_file13,
3674
- L: 163,
3753
+ L: 166,
3675
3754
  S: this,
3676
3755
  C: (f, a) => f(...a)
3677
3756
  });
3678
- (0, import_invariant11.invariant)(this._isOpen, "Not open.", {
3757
+ (0, import_invariant12.invariant)(this._isOpen, "Not open.", {
3679
3758
  F: __dxlog_file13,
3680
- L: 164,
3759
+ L: 167,
3681
3760
  S: this,
3682
3761
  A: [
3683
3762
  "this._isOpen",
3684
3763
  "'Not open.'"
3685
3764
  ]
3686
3765
  });
3687
- (0, import_invariant11.invariant)(!this._spaces.has(opts.spaceKey), "Space already exists.", {
3766
+ (0, import_invariant12.invariant)(!this._spaces.has(opts.spaceKey), "Space already exists.", {
3688
3767
  F: __dxlog_file13,
3689
- L: 165,
3768
+ L: 168,
3690
3769
  S: this,
3691
3770
  A: [
3692
3771
  "!this._spaces.has(opts.spaceKey)",
@@ -3713,7 +3792,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3713
3792
  async waitUntilSpaceReady(spaceKey) {
3714
3793
  await (0, import_context8.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
3715
3794
  const space = this._spaces.get(spaceKey);
3716
- return !!space && space.state === import_services8.SpaceState.READY;
3795
+ return !!space && space.state === import_services9.SpaceState.READY;
3717
3796
  }));
3718
3797
  }
3719
3798
  async _constructSpace(metadata) {
@@ -3721,7 +3800,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3721
3800
  metadata
3722
3801
  }, {
3723
3802
  F: __dxlog_file13,
3724
- L: 198,
3803
+ L: 201,
3725
3804
  S: this,
3726
3805
  C: (f, a) => f(...a)
3727
3806
  });
@@ -3748,17 +3827,18 @@ var DataSpaceManager = class DataSpaceManager2 {
3748
3827
  credentialProvider: createAuthProvider(this._signingContext.credentialSigner),
3749
3828
  credentialAuthenticator: (0, import_util6.deferFunction)(() => dataSpace.authVerifier.verifier)
3750
3829
  },
3751
- onNetworkConnection: (session) => {
3830
+ onAuthorizedConnection: (session) => {
3752
3831
  session.addExtension("dxos.mesh.teleport.gossip", gossip.createExtension({
3753
3832
  remotePeerId: session.remotePeerId
3754
3833
  }));
3755
3834
  session.addExtension("dxos.mesh.teleport.notarization", dataSpace.notarizationPlugin.createExtension());
3835
+ this._automergeHost.authorizeDevice(space.key, session.remotePeerId);
3756
3836
  session.addExtension("dxos.mesh.teleport.automerge", this._automergeHost.createExtension());
3757
3837
  },
3758
3838
  onAuthFailure: () => {
3759
3839
  import_log11.log.warn("auth failure", void 0, {
3760
3840
  F: __dxlog_file13,
3761
- L: 234,
3841
+ L: 238,
3762
3842
  S: this,
3763
3843
  C: (f, a) => f(...a)
3764
3844
  });
@@ -3769,7 +3849,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3769
3849
  dataFeed && space.setDataFeed(dataFeed);
3770
3850
  const dataSpace = new DataSpace({
3771
3851
  inner: space,
3772
- initialState: metadata.state === import_services8.SpaceState.INACTIVE ? import_services8.SpaceState.INACTIVE : import_services8.SpaceState.CLOSED,
3852
+ initialState: metadata.state === import_services9.SpaceState.INACTIVE ? import_services9.SpaceState.INACTIVE : import_services9.SpaceState.CLOSED,
3773
3853
  metadataStore: this._metadataStore,
3774
3854
  gossip,
3775
3855
  presence,
@@ -3782,7 +3862,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3782
3862
  space: space.key
3783
3863
  }, {
3784
3864
  F: __dxlog_file13,
3785
- L: 252,
3865
+ L: 256,
3786
3866
  S: this,
3787
3867
  C: (f, a) => f(...a)
3788
3868
  });
@@ -3794,7 +3874,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3794
3874
  open: this._isOpen
3795
3875
  }, {
3796
3876
  F: __dxlog_file13,
3797
- L: 259,
3877
+ L: 263,
3798
3878
  S: this,
3799
3879
  C: (f, a) => f(...a)
3800
3880
  });
@@ -3807,7 +3887,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3807
3887
  space: space.key
3808
3888
  }, {
3809
3889
  F: __dxlog_file13,
3810
- L: 265,
3890
+ L: 269,
3811
3891
  S: this,
3812
3892
  C: (f, a) => f(...a)
3813
3893
  });
@@ -3817,7 +3897,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3817
3897
  cache: metadata.cache,
3818
3898
  automergeHost: this._automergeHost
3819
3899
  });
3820
- if (metadata.state !== import_services8.SpaceState.INACTIVE) {
3900
+ if (metadata.state !== import_services9.SpaceState.INACTIVE) {
3821
3901
  await dataSpace.open();
3822
3902
  }
3823
3903
  if (metadata.controlTimeframe) {
@@ -3855,7 +3935,7 @@ var SpacesServiceImpl = class {
3855
3935
  }
3856
3936
  async createSpace() {
3857
3937
  if (!this._identityManager.identity) {
3858
- throw new Error("This device has no HALO identity available. See https://docs.dxos.org/guide/halo");
3938
+ throw new Error("This device has no HALO identity available. See https://docs.dxos.org/guide/platform/halo");
3859
3939
  }
3860
3940
  const dataSpaceManager = await this._getDataSpaceManager();
3861
3941
  const space = await dataSpaceManager.createSpace();
@@ -3863,17 +3943,17 @@ var SpacesServiceImpl = class {
3863
3943
  }
3864
3944
  async updateSpace({ spaceKey, state }) {
3865
3945
  const dataSpaceManager = await this._getDataSpaceManager();
3866
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols9.SpaceNotFoundError(spaceKey));
3946
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
3867
3947
  if (state) {
3868
3948
  switch (state) {
3869
- case import_services9.SpaceState.ACTIVE:
3949
+ case import_services10.SpaceState.ACTIVE:
3870
3950
  await space.activate();
3871
3951
  break;
3872
- case import_services9.SpaceState.INACTIVE:
3952
+ case import_services10.SpaceState.INACTIVE:
3873
3953
  await space.deactivate();
3874
3954
  break;
3875
3955
  default:
3876
- throw new import_protocols9.ApiError("Invalid space state");
3956
+ throw new import_protocols11.ApiError("Invalid space state");
3877
3957
  }
3878
3958
  }
3879
3959
  }
@@ -3928,14 +4008,14 @@ var SpacesServiceImpl = class {
3928
4008
  }
3929
4009
  async postMessage({ spaceKey, channel, message }) {
3930
4010
  const dataSpaceManager = await this._getDataSpaceManager();
3931
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols9.SpaceNotFoundError(spaceKey));
4011
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
3932
4012
  await space.postMessage(getChannelId(channel), message);
3933
4013
  }
3934
4014
  subscribeMessages({ spaceKey, channel }) {
3935
4015
  return new import_codec_protobuf11.Stream(({ ctx, next }) => {
3936
4016
  (0, import_async13.scheduleTask)(ctx, async () => {
3937
4017
  const dataSpaceManager = await this._getDataSpaceManager();
3938
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols9.SpaceNotFoundError(spaceKey));
4018
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
3939
4019
  const handle = space.listen(getChannelId(channel), (message) => {
3940
4020
  next(message);
3941
4021
  });
@@ -3945,7 +4025,7 @@ var SpacesServiceImpl = class {
3945
4025
  }
3946
4026
  queryCredentials({ spaceKey, noTail }) {
3947
4027
  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));
4028
+ const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
3949
4029
  const processor = {
3950
4030
  processCredential: async (credential) => {
3951
4031
  next(credential);
@@ -3961,7 +4041,7 @@ var SpacesServiceImpl = class {
3961
4041
  });
3962
4042
  }
3963
4043
  async writeCredentials({ spaceKey, credentials }) {
3964
- const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols9.SpaceNotFoundError(spaceKey));
4044
+ const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
3965
4045
  for (const credential of credentials ?? []) {
3966
4046
  if (credential.proof) {
3967
4047
  await space.controlPipeline.writer.write({
@@ -3970,7 +4050,7 @@ var SpacesServiceImpl = class {
3970
4050
  }
3971
4051
  });
3972
4052
  } else {
3973
- (0, import_invariant12.invariant)(!credential.id, "Id on unsigned credentials is not allowed", {
4053
+ (0, import_invariant13.invariant)(!credential.id, "Id on unsigned credentials is not allowed", {
3974
4054
  F: __dxlog_file14,
3975
4055
  L: 168,
3976
4056
  S: this,
@@ -3979,7 +4059,7 @@ var SpacesServiceImpl = class {
3979
4059
  "'Id on unsigned credentials is not allowed'"
3980
4060
  ]
3981
4061
  });
3982
- (0, import_invariant12.invariant)(this._identityManager.identity, "Identity is not available", {
4062
+ (0, import_invariant13.invariant)(this._identityManager.identity, "Identity is not available", {
3983
4063
  F: __dxlog_file14,
3984
4064
  L: 169,
3985
4065
  S: this,
@@ -3989,7 +4069,7 @@ var SpacesServiceImpl = class {
3989
4069
  ]
3990
4070
  });
3991
4071
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
3992
- (0, import_invariant12.invariant)(credential.issuer.equals(signer.getIssuer()), void 0, {
4072
+ (0, import_invariant13.invariant)(credential.issuer.equals(signer.getIssuer()), void 0, {
3993
4073
  F: __dxlog_file14,
3994
4074
  L: 171,
3995
4075
  S: this,
@@ -4012,14 +4092,14 @@ var SpacesServiceImpl = class {
4012
4092
  }
4013
4093
  async createEpoch({ spaceKey }) {
4014
4094
  const dataSpaceManager = await this._getDataSpaceManager();
4015
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols9.SpaceNotFoundError(spaceKey));
4095
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4016
4096
  await space.createEpoch();
4017
4097
  }
4018
4098
  _serializeSpace(space) {
4019
4099
  return {
4020
4100
  spaceKey: space.key,
4021
4101
  state: space.state,
4022
- error: space.error ? (0, import_protocols9.encodeError)(space.error) : void 0,
4102
+ error: space.error ? (0, import_protocols11.encodeError)(space.error) : void 0,
4023
4103
  pipeline: {
4024
4104
  currentEpoch: space.dataPipeline.currentEpoch,
4025
4105
  appliedEpoch: space.dataPipeline.appliedEpoch,
@@ -4046,7 +4126,7 @@ var SpacesServiceImpl = class {
4046
4126
  displayName: member.profile?.displayName
4047
4127
  }
4048
4128
  },
4049
- presence: member.removed ? import_services9.SpaceMember.PresenceState.REMOVED : isMe || peers.length > 0 ? import_services9.SpaceMember.PresenceState.ONLINE : import_services9.SpaceMember.PresenceState.OFFLINE,
4129
+ presence: member.removed ? import_services10.SpaceMember.PresenceState.REMOVED : isMe || peers.length > 0 ? import_services10.SpaceMember.PresenceState.ONLINE : import_services10.SpaceMember.PresenceState.OFFLINE,
4050
4130
  peerStates: peers
4051
4131
  };
4052
4132
  }),
@@ -4068,7 +4148,7 @@ function _ts_decorate6(decorators, target, key, desc) {
4068
4148
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4069
4149
  }
4070
4150
  var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
4071
- var ServiceContext = class ServiceContext2 {
4151
+ var ServiceContext = class {
4072
4152
  constructor(storage, networkManager, signalManager, modelFactory) {
4073
4153
  this.storage = storage;
4074
4154
  this.networkManager = networkManager;
@@ -4103,7 +4183,7 @@ var ServiceContext = class ServiceContext2 {
4103
4183
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager);
4104
4184
  this.automergeHost = new import_echo_pipeline2.AutomergeHost(storage.createDirectory("automerge"));
4105
4185
  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)));
4186
+ this._handlerFactories.set(import_services11.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug7.failUndefined)(), this._acceptIdentity.bind(this)));
4107
4187
  }
4108
4188
  async open(ctx) {
4109
4189
  await this._checkStorageVersion();
@@ -4113,7 +4193,7 @@ var ServiceContext = class ServiceContext2 {
4113
4193
  S: this,
4114
4194
  C: (f, a) => f(...a)
4115
4195
  });
4116
- import_log13.log.trace("dxos.sdk.service-context.open", import_protocols10.trace.begin({
4196
+ import_log13.log.trace("dxos.sdk.service-context.open", import_protocols12.trace.begin({
4117
4197
  id: this._instanceId
4118
4198
  }), {
4119
4199
  F: __dxlog_file15,
@@ -4129,7 +4209,7 @@ var ServiceContext = class ServiceContext2 {
4129
4209
  if (this.identityManager.identity) {
4130
4210
  await this._initialize(ctx);
4131
4211
  }
4132
- import_log13.log.trace("dxos.sdk.service-context.open", import_protocols10.trace.end({
4212
+ import_log13.log.trace("dxos.sdk.service-context.open", import_protocols12.trace.end({
4133
4213
  id: this._instanceId
4134
4214
  }), {
4135
4215
  F: __dxlog_file15,
@@ -4177,7 +4257,7 @@ var ServiceContext = class ServiceContext2 {
4177
4257
  }
4178
4258
  getInvitationHandler(invitation) {
4179
4259
  const factory = this._handlerFactories.get(invitation.kind);
4180
- (0, import_invariant13.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
4260
+ (0, import_invariant14.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
4181
4261
  F: __dxlog_file15,
4182
4262
  L: 173,
4183
4263
  S: this,
@@ -4203,8 +4283,8 @@ var ServiceContext = class ServiceContext2 {
4203
4283
  }
4204
4284
  async _checkStorageVersion() {
4205
4285
  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);
4286
+ if (this.metadataStore.version !== import_protocols12.STORAGE_VERSION) {
4287
+ throw new import_protocols12.InvalidStorageVersionError(import_protocols12.STORAGE_VERSION, this.metadataStore.version);
4208
4288
  }
4209
4289
  }
4210
4290
  // Called when identity is created.
@@ -4231,8 +4311,8 @@ var ServiceContext = class ServiceContext2 {
4231
4311
  };
4232
4312
  this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.dataServiceSubscriptions, this.keyring, signingContext, this.feedStore, this.automergeHost);
4233
4313
  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", {
4314
+ this._handlerFactories.set(import_services11.Invitation.Kind.SPACE, (invitation) => {
4315
+ (0, import_invariant14.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4236
4316
  F: __dxlog_file15,
4237
4317
  L: 228,
4238
4318
  S: this,
@@ -4371,7 +4451,7 @@ var Lock = class {
4371
4451
  }
4372
4452
  async release() {
4373
4453
  await this._onRelease?.();
4374
- (0, import_invariant14.invariant)(this._fileHandle, "Lock is not acquired", {
4454
+ (0, import_invariant15.invariant)(this._fileHandle, "Lock is not acquired", {
4375
4455
  F: __dxlog_file16,
4376
4456
  L: 42,
4377
4457
  S: this,
@@ -4391,16 +4471,16 @@ var StorageDriver = import_config.Runtime.Client.Storage.StorageDriver;
4391
4471
  var createStorageObjects = (config) => {
4392
4472
  const { persistent = false, keyStore, dataStore, dataRoot = (0, import_util8.isNode)() ? import_client_protocol4.DX_DATA : "dxos/storage" } = config ?? {};
4393
4473
  if (persistent && dataStore === StorageDriver.RAM) {
4394
- throw new import_protocols11.InvalidConfigError("RAM storage cannot be used in persistent mode.");
4474
+ throw new import_protocols13.InvalidConfigError("RAM storage cannot be used in persistent mode.");
4395
4475
  }
4396
4476
  if (!persistent && dataStore !== void 0 && dataStore !== StorageDriver.RAM) {
4397
- throw new import_protocols11.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
4477
+ throw new import_protocols13.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
4398
4478
  }
4399
4479
  if (persistent && keyStore === StorageDriver.RAM) {
4400
- throw new import_protocols11.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
4480
+ throw new import_protocols13.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
4401
4481
  }
4402
4482
  if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== void 0) {
4403
- throw new import_protocols11.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
4483
+ throw new import_protocols13.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
4404
4484
  }
4405
4485
  return {
4406
4486
  storage: (0, import_random_access_storage.createStorage)({
@@ -4448,7 +4528,7 @@ var DevicesServiceImpl = class {
4448
4528
  next({
4449
4529
  devices: Array.from(deviceKeys.entries()).map(([key, profile]) => ({
4450
4530
  deviceKey: key,
4451
- kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services12.DeviceKind.CURRENT : import_services12.DeviceKind.TRUSTED,
4531
+ kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services13.DeviceKind.CURRENT : import_services13.DeviceKind.TRUSTED,
4452
4532
  profile
4453
4533
  }))
4454
4534
  });
@@ -4563,16 +4643,16 @@ var LoggingServiceImpl = class {
4563
4643
  };
4564
4644
  var matchFilter = (filter, level, path, options) => {
4565
4645
  switch (options) {
4566
- case import_services13.QueryLogsRequest.MatchingOptions.INCLUSIVE:
4646
+ case import_services14.QueryLogsRequest.MatchingOptions.INCLUSIVE:
4567
4647
  return level >= filter.level && (!filter.pattern || path.includes(filter.pattern));
4568
- case import_services13.QueryLogsRequest.MatchingOptions.EXPLICIT:
4648
+ case import_services14.QueryLogsRequest.MatchingOptions.EXPLICIT:
4569
4649
  return level === filter.level && (!filter.pattern || path.includes(filter.pattern));
4570
4650
  }
4571
4651
  };
4572
4652
  var shouldLog = (entry2, request) => {
4573
- const options = request.options ?? import_services13.QueryLogsRequest.MatchingOptions.INCLUSIVE;
4653
+ const options = request.options ?? import_services14.QueryLogsRequest.MatchingOptions.INCLUSIVE;
4574
4654
  if (request.filters === void 0) {
4575
- return options === import_services13.QueryLogsRequest.MatchingOptions.INCLUSIVE;
4655
+ return options === import_services14.QueryLogsRequest.MatchingOptions.INCLUSIVE;
4576
4656
  } else {
4577
4657
  return request.filters.some((filter) => matchFilter(filter, entry2.level, entry2.meta?.F ?? "", options));
4578
4658
  }
@@ -4588,6 +4668,7 @@ var NetworkServiceImpl = class {
4588
4668
  const update = () => {
4589
4669
  next({
4590
4670
  swarm: this.networkManager.connectionState,
4671
+ connectionInfo: this.networkManager.connectionLog?.swarms,
4591
4672
  signaling: this.signalManager.getStatus().map(({ host, state }) => ({
4592
4673
  server: host,
4593
4674
  state
@@ -4627,11 +4708,14 @@ var SystemServiceImpl = class {
4627
4708
  return {
4628
4709
  timestamp: /* @__PURE__ */ new Date(),
4629
4710
  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
4711
+ truncate: keys === import_services15.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
4712
+ humanize: keys === import_services15.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
4632
4713
  })))
4633
4714
  };
4634
4715
  }
4716
+ async getPlatform() {
4717
+ return getPlatform();
4718
+ }
4635
4719
  async updateStatus({ status }) {
4636
4720
  await this._onUpdateStatus(status);
4637
4721
  }
@@ -4682,7 +4766,7 @@ var createGenesisMutationFromTypedObject = (obj) => {
4682
4766
  }
4683
4767
  };
4684
4768
  };
4685
- var ClientServicesHost = class ClientServicesHost2 {
4769
+ var ClientServicesHost = class {
4686
4770
  constructor({
4687
4771
  config,
4688
4772
  modelFactory = createDefaultModelFactory(),
@@ -4721,14 +4805,14 @@ var ClientServicesHost = class ClientServicesHost2 {
4721
4805
  this._systemService = new SystemServiceImpl({
4722
4806
  config: this._config,
4723
4807
  statusUpdate: this._statusUpdate,
4724
- getCurrentStatus: () => this.isOpen ? import_services11.SystemStatus.ACTIVE : import_services11.SystemStatus.INACTIVE,
4808
+ getCurrentStatus: () => this.isOpen ? import_services12.SystemStatus.ACTIVE : import_services12.SystemStatus.INACTIVE,
4725
4809
  getDiagnostics: () => {
4726
4810
  return createDiagnostics(this._serviceRegistry.services, this._serviceContext, this._config);
4727
4811
  },
4728
4812
  onUpdateStatus: async (status) => {
4729
- if (!this.isOpen && status === import_services11.SystemStatus.ACTIVE) {
4813
+ if (!this.isOpen && status === import_services12.SystemStatus.ACTIVE) {
4730
4814
  await this._resourceLock?.acquire();
4731
- } else if (this.isOpen && status === import_services11.SystemStatus.INACTIVE) {
4815
+ } else if (this.isOpen && status === import_services12.SystemStatus.INACTIVE) {
4732
4816
  await this._resourceLock?.release();
4733
4817
  }
4734
4818
  },
@@ -4766,7 +4850,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4766
4850
  * Can only be called once.
4767
4851
  */
4768
4852
  initialize({ config, ...options }) {
4769
- (0, import_invariant15.invariant)(!this._open, "service host is open", {
4853
+ (0, import_invariant16.invariant)(!this._open, "service host is open", {
4770
4854
  F: __dxlog_file17,
4771
4855
  L: 201,
4772
4856
  S: this,
@@ -4782,7 +4866,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4782
4866
  C: (f, a) => f(...a)
4783
4867
  });
4784
4868
  if (config) {
4785
- (0, import_invariant15.invariant)(!this._config, "config already set", {
4869
+ (0, import_invariant16.invariant)(!this._config, "config already set", {
4786
4870
  F: __dxlog_file17,
4787
4871
  L: 205,
4788
4872
  S: this,
@@ -4800,7 +4884,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4800
4884
  iceServers: this._config?.get("runtime.services.ice")
4801
4885
  }), signalManager = new import_messaging.WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
4802
4886
  this._signalManager = signalManager;
4803
- (0, import_invariant15.invariant)(!this._networkManager, "network manager already set", {
4887
+ (0, import_invariant16.invariant)(!this._networkManager, "network manager already set", {
4804
4888
  F: __dxlog_file17,
4805
4889
  L: 221,
4806
4890
  S: this,
@@ -4826,7 +4910,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4826
4910
  return;
4827
4911
  }
4828
4912
  const traceId = import_keys11.PublicKey.random().toHex();
4829
- import_log15.log.trace("dxos.client-services.host.open", import_protocols12.trace.begin({
4913
+ import_log15.log.trace("dxos.client-services.host.open", import_protocols14.trace.begin({
4830
4914
  id: traceId
4831
4915
  }), {
4832
4916
  F: __dxlog_file17,
@@ -4834,7 +4918,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4834
4918
  S: this,
4835
4919
  C: (f, a) => f(...a)
4836
4920
  });
4837
- (0, import_invariant15.invariant)(this._config, "config not set", {
4921
+ (0, import_invariant16.invariant)(this._config, "config not set", {
4838
4922
  F: __dxlog_file17,
4839
4923
  L: 241,
4840
4924
  S: this,
@@ -4843,7 +4927,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4843
4927
  "'config not set'"
4844
4928
  ]
4845
4929
  });
4846
- (0, import_invariant15.invariant)(this._storage, "storage not set", {
4930
+ (0, import_invariant16.invariant)(this._storage, "storage not set", {
4847
4931
  F: __dxlog_file17,
4848
4932
  L: 242,
4849
4933
  S: this,
@@ -4852,7 +4936,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4852
4936
  "'storage not set'"
4853
4937
  ]
4854
4938
  });
4855
- (0, import_invariant15.invariant)(this._signalManager, "signal manager not set", {
4939
+ (0, import_invariant16.invariant)(this._signalManager, "signal manager not set", {
4856
4940
  F: __dxlog_file17,
4857
4941
  L: 243,
4858
4942
  S: this,
@@ -4861,7 +4945,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4861
4945
  "'signal manager not set'"
4862
4946
  ]
4863
4947
  });
4864
- (0, import_invariant15.invariant)(this._networkManager, "network manager not set", {
4948
+ (0, import_invariant16.invariant)(this._networkManager, "network manager not set", {
4865
4949
  F: __dxlog_file17,
4866
4950
  L: 244,
4867
4951
  S: this,
@@ -4884,7 +4968,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4884
4968
  this._serviceContext = new ServiceContext(this._storage, this._networkManager, this._signalManager, this._modelFactory);
4885
4969
  this._serviceRegistry.setServices({
4886
4970
  SystemService: this._systemService,
4887
- IdentityService: new IdentityServiceImpl((params) => this._createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring, (profile) => this._serviceContext.broadcastProfileUpdate(profile)),
4971
+ IdentityService: new IdentityServiceImpl((params, useAutomerge) => this._createIdentity(params, useAutomerge), this._serviceContext.identityManager, this._serviceContext.keyring, (profile) => this._serviceContext.broadcastProfileUpdate(profile)),
4888
4972
  InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitations, (invitation) => this._serviceContext.getInvitationHandler(invitation)),
4889
4973
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
4890
4974
  SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, this._serviceContext.dataServiceSubscriptions, async () => {
@@ -4925,7 +5009,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4925
5009
  S: this,
4926
5010
  C: (f, a) => f(...a)
4927
5011
  });
4928
- import_log15.log.trace("dxos.client-services.host.open", import_protocols12.trace.end({
5012
+ import_log15.log.trace("dxos.client-services.host.open", import_protocols14.trace.end({
4929
5013
  id: traceId
4930
5014
  }), {
4931
5015
  F: __dxlog_file17,
@@ -4966,7 +5050,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4966
5050
  }
4967
5051
  async reset() {
4968
5052
  const traceId = import_keys11.PublicKey.random().toHex();
4969
- import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols12.trace.begin({
5053
+ import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols14.trace.begin({
4970
5054
  id: traceId
4971
5055
  }), {
4972
5056
  F: __dxlog_file17,
@@ -4988,7 +5072,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4988
5072
  S: this,
4989
5073
  C: (f, a) => f(...a)
4990
5074
  });
4991
- import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols12.trace.end({
5075
+ import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols14.trace.end({
4992
5076
  id: traceId
4993
5077
  }), {
4994
5078
  F: __dxlog_file17,
@@ -4998,25 +5082,44 @@ var ClientServicesHost = class ClientServicesHost2 {
4998
5082
  });
4999
5083
  await this._callbacks?.onReset?.();
5000
5084
  }
5001
- async _createIdentity(params) {
5085
+ async _createIdentity(params, useAutomerge) {
5002
5086
  const identity = await this._serviceContext.createIdentity(params);
5003
5087
  await this._serviceContext.initialized.wait();
5004
5088
  const space = await this._serviceContext.dataSpaceManager.createSpace();
5005
5089
  const obj = new import_client_protocol5.Properties(void 0, {
5006
- automerge: false
5090
+ automerge: useAutomerge
5007
5091
  });
5008
5092
  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)
5093
+ if (!useAutomerge) {
5094
+ await this._serviceRegistry.services.DataService.write({
5095
+ spaceKey: space.key,
5096
+ batch: {
5097
+ objects: [
5098
+ createGenesisMutationFromTypedObject(obj)
5099
+ ]
5100
+ }
5101
+ });
5102
+ await this._serviceRegistry.services.DataService.flush({
5103
+ spaceKey: space.key
5104
+ });
5105
+ } else {
5106
+ const automergeIndex = space.automergeSpaceState.rootUrl;
5107
+ (0, import_invariant16.invariant)(automergeIndex, void 0, {
5108
+ F: __dxlog_file17,
5109
+ L: 375,
5110
+ S: this,
5111
+ A: [
5112
+ "automergeIndex",
5113
+ ""
5014
5114
  ]
5015
- }
5016
- });
5017
- await this._serviceRegistry.services.DataService.flush({
5018
- spaceKey: space.key
5019
- });
5115
+ });
5116
+ const document = await this._serviceContext.automergeHost.repo.find(automergeIndex);
5117
+ await document.whenReady();
5118
+ document.change((doc) => {
5119
+ doc.objects ??= {};
5120
+ doc.objects[obj[import_echo_schema.base]._id] = (0, import_echo_schema.getRawDoc)(obj).handle.docSync();
5121
+ });
5122
+ }
5020
5123
  return identity;
5021
5124
  }
5022
5125
  };
@@ -5071,4 +5174,4 @@ ClientServicesHost = _ts_decorate8([
5071
5174
  subscribeToSpaces,
5072
5175
  subscribeToSwarmInfo
5073
5176
  });
5074
- //# sourceMappingURL=chunk-SCZDMYY2.cjs.map
5177
+ //# sourceMappingURL=chunk-45NL4DNZ.cjs.map