@dxos/client-services 0.5.9-main.bfee100 → 0.5.9-main.d63ef8d

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 (33) hide show
  1. package/dist/lib/browser/{chunk-TZL7PJDX.mjs → chunk-C2VXW65X.mjs} +691 -536
  2. package/dist/lib/browser/chunk-C2VXW65X.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -3
  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 +1 -1
  7. package/dist/lib/node/{chunk-STUWVNPH.cjs → chunk-OD7BTUYY.cjs} +842 -690
  8. package/dist/lib/node/chunk-OD7BTUYY.cjs.map +7 -0
  9. package/dist/lib/node/index.cjs +41 -43
  10. package/dist/lib/node/index.cjs.map +1 -1
  11. package/dist/lib/node/meta.json +1 -1
  12. package/dist/lib/node/packlets/testing/index.cjs +8 -8
  13. package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
  14. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts +4 -1
  15. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts.map +1 -1
  16. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  17. package/dist/types/src/packlets/spaces/data-space.d.ts +9 -9
  18. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  19. package/dist/types/src/packlets/spaces/epoch-migrations.d.ts +23 -0
  20. package/dist/types/src/packlets/spaces/epoch-migrations.d.ts.map +1 -0
  21. package/dist/types/src/packlets/spaces/spaces-service.d.ts +2 -2
  22. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  23. package/dist/types/src/version.d.ts +1 -1
  24. package/package.json +36 -36
  25. package/src/packlets/identity/identity-service.ts +33 -7
  26. package/src/packlets/spaces/automerge-space-state.ts +11 -2
  27. package/src/packlets/spaces/data-space-manager.ts +34 -13
  28. package/src/packlets/spaces/data-space.ts +73 -145
  29. package/src/packlets/spaces/epoch-migrations.ts +135 -0
  30. package/src/packlets/spaces/spaces-service.ts +4 -2
  31. package/src/version.ts +1 -1
  32. package/dist/lib/browser/chunk-TZL7PJDX.mjs.map +0 -7
  33. package/dist/lib/node/chunk-STUWVNPH.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_STUWVNPH_exports = {};
30
- __export(chunk_STUWVNPH_exports, {
29
+ var chunk_OD7BTUYY_exports = {};
30
+ __export(chunk_OD7BTUYY_exports, {
31
31
  ClientRpcServer: () => ClientRpcServer,
32
32
  ClientServicesHost: () => ClientServicesHost,
33
33
  ClientServicesProviderResource: () => ClientServicesProviderResource,
@@ -56,7 +56,6 @@ __export(chunk_STUWVNPH_exports, {
56
56
  createDiagnostics: () => createDiagnostics,
57
57
  createLevel: () => createLevel,
58
58
  createStorageObjects: () => createStorageObjects,
59
- findPropertiesObject: () => findPropertiesObject,
60
59
  getNetworkPeers: () => getNetworkPeers,
61
60
  isLocked: () => isLocked,
62
61
  subscribeToFeedBlocks: () => subscribeToFeedBlocks,
@@ -67,7 +66,7 @@ __export(chunk_STUWVNPH_exports, {
67
66
  subscribeToSpaces: () => subscribeToSpaces,
68
67
  subscribeToSwarmInfo: () => subscribeToSwarmInfo
69
68
  });
70
- module.exports = __toCommonJS(chunk_STUWVNPH_exports);
69
+ module.exports = __toCommonJS(chunk_OD7BTUYY_exports);
71
70
  var import_async = require("@dxos/async");
72
71
  var import_codec_protobuf = require("@dxos/codec-protobuf");
73
72
  var import_feed_store = require("@dxos/feed-store");
@@ -127,186 +126,201 @@ var import_teleport_extension_gossip = require("@dxos/teleport-extension-gossip"
127
126
  var import_timeframe2 = require("@dxos/timeframe");
128
127
  var import_tracing4 = require("@dxos/tracing");
129
128
  var import_util3 = require("@dxos/util");
129
+ var import_async8 = require("@dxos/async");
130
130
  var import_codec_protobuf9 = require("@dxos/codec-protobuf");
131
131
  var import_context4 = require("@dxos/context");
132
132
  var import_credentials8 = require("@dxos/credentials");
133
133
  var import_debug2 = require("@dxos/debug");
134
134
  var import_invariant4 = require("@dxos/invariant");
135
+ var import_log5 = require("@dxos/log");
135
136
  var import_services4 = require("@dxos/protocols/proto/dxos/client/services");
137
+ var import_util4 = require("@dxos/util");
136
138
  var import_invariant5 = require("@dxos/invariant");
137
139
  var import_protocols4 = require("@dxos/protocols");
138
140
  var import_services5 = require("@dxos/protocols/proto/dxos/client/services");
139
- var import_async8 = require("@dxos/async");
141
+ var import_async9 = require("@dxos/async");
140
142
  var import_client_protocol2 = require("@dxos/client-protocol");
141
143
  var import_context5 = require("@dxos/context");
142
144
  var import_crypto = require("@dxos/crypto");
143
145
  var import_invariant6 = require("@dxos/invariant");
144
146
  var import_keys6 = require("@dxos/keys");
145
- var import_log5 = require("@dxos/log");
147
+ var import_log6 = require("@dxos/log");
146
148
  var import_network_manager = require("@dxos/network-manager");
147
149
  var import_protocols5 = require("@dxos/protocols");
148
150
  var import_services6 = require("@dxos/protocols/proto/dxos/client/services");
149
151
  var import_invitations = require("@dxos/protocols/proto/dxos/halo/invitations");
150
152
  var import_invitations2 = require("@dxos/protocols/proto/dxos/halo/invitations");
151
- var import_util4 = require("@dxos/util");
152
- var import_async9 = require("@dxos/async");
153
+ var import_util5 = require("@dxos/util");
154
+ var import_async10 = require("@dxos/async");
153
155
  var import_context6 = require("@dxos/context");
154
156
  var import_invariant7 = require("@dxos/invariant");
155
- var import_log6 = require("@dxos/log");
157
+ var import_log7 = require("@dxos/log");
156
158
  var import_protocols6 = require("@dxos/protocols");
157
159
  var import_invitations3 = require("@dxos/protocols/proto/dxos/halo/invitations");
158
160
  var import_teleport = require("@dxos/teleport");
159
161
  var import_context7 = require("@dxos/context");
160
162
  var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
161
- var import_async10 = require("@dxos/async");
163
+ var import_async11 = require("@dxos/async");
162
164
  var import_context8 = require("@dxos/context");
163
165
  var import_crypto2 = require("@dxos/crypto");
164
166
  var import_invariant8 = require("@dxos/invariant");
165
167
  var import_keys7 = require("@dxos/keys");
166
- var import_log7 = require("@dxos/log");
168
+ var import_log8 = require("@dxos/log");
167
169
  var import_protocols7 = require("@dxos/protocols");
168
170
  var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
169
171
  var import_invitations4 = require("@dxos/protocols/proto/dxos/halo/invitations");
170
172
  var import_teleport2 = require("@dxos/teleport");
171
173
  var import_invariant9 = require("@dxos/invariant");
172
174
  var import_keys8 = require("@dxos/keys");
173
- var import_log8 = require("@dxos/log");
175
+ var import_log9 = require("@dxos/log");
174
176
  var import_invitations5 = require("@dxos/protocols/proto/dxos/halo/invitations");
175
- var import_util5 = require("@dxos/util");
177
+ var import_util6 = require("@dxos/util");
176
178
  var import_codec_protobuf10 = require("@dxos/codec-protobuf");
177
179
  var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
178
180
  var import_credentials9 = require("@dxos/credentials");
179
181
  var import_feed_store3 = require("@dxos/feed-store");
180
182
  var import_invariant10 = require("@dxos/invariant");
181
- var import_log9 = require("@dxos/log");
183
+ var import_log10 = require("@dxos/log");
182
184
  var import_protocols8 = require("@dxos/protocols");
183
185
  var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
184
186
  var import_credentials10 = require("@dxos/protocols/proto/dxos/halo/credentials");
185
- var import_async11 = require("@dxos/async");
187
+ var import_async12 = require("@dxos/async");
186
188
  var import_client_protocol3 = require("@dxos/client-protocol");
187
189
  var import_context9 = require("@dxos/context");
188
190
  var import_credentials11 = require("@dxos/credentials");
189
191
  var import_echo_pipeline = require("@dxos/echo-pipeline");
190
192
  var import_invariant11 = require("@dxos/invariant");
191
193
  var import_keys9 = require("@dxos/keys");
192
- var import_log10 = require("@dxos/log");
194
+ var import_log11 = require("@dxos/log");
193
195
  var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
194
196
  var import_credentials12 = require("@dxos/protocols/proto/dxos/halo/credentials");
195
- var import_async12 = require("@dxos/async");
197
+ var import_async13 = require("@dxos/async");
196
198
  var import_client_protocol4 = require("@dxos/client-protocol");
197
199
  var import_context10 = require("@dxos/context");
198
200
  var import_debug3 = require("@dxos/debug");
199
201
  var import_echo_pipeline2 = require("@dxos/echo-pipeline");
200
- var import_echo_schema = require("@dxos/echo-schema");
202
+ var import_echo_protocol = require("@dxos/echo-protocol");
201
203
  var import_invariant12 = require("@dxos/invariant");
202
204
  var import_keys10 = require("@dxos/keys");
203
- var import_log11 = require("@dxos/log");
205
+ var import_log12 = require("@dxos/log");
204
206
  var import_protocols9 = require("@dxos/protocols");
205
207
  var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
206
208
  var import_credentials13 = require("@dxos/protocols/proto/dxos/halo/credentials");
207
209
  var import_timeframe3 = require("@dxos/timeframe");
208
210
  var import_tracing5 = require("@dxos/tracing");
209
- var import_util6 = require("@dxos/util");
210
- var import_async13 = require("@dxos/async");
211
- var import_credentials14 = require("@dxos/credentials");
211
+ var import_util7 = require("@dxos/util");
212
212
  var import_async14 = require("@dxos/async");
213
213
  var import_context11 = require("@dxos/context");
214
+ var import_credentials14 = require("@dxos/credentials");
215
+ var import_async15 = require("@dxos/async");
216
+ var import_automerge = require("@dxos/automerge/automerge");
217
+ var import_context12 = require("@dxos/context");
218
+ var import_echo_db = require("@dxos/echo-db");
219
+ var import_echo_pipeline3 = require("@dxos/echo-pipeline");
220
+ var import_echo_schema = require("@dxos/echo-schema");
214
221
  var import_invariant13 = require("@dxos/invariant");
222
+ var import_log13 = require("@dxos/log");
223
+ var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
224
+ var import_util8 = require("@dxos/util");
225
+ var import_async16 = require("@dxos/async");
226
+ var import_context13 = require("@dxos/context");
227
+ var import_invariant14 = require("@dxos/invariant");
215
228
  var import_keys11 = require("@dxos/keys");
216
- var import_log12 = require("@dxos/log");
229
+ var import_log14 = require("@dxos/log");
217
230
  var import_protocols10 = require("@dxos/protocols");
218
231
  var import_teleport3 = require("@dxos/teleport");
219
- var import_util7 = require("@dxos/util");
220
- var import_async15 = require("@dxos/async");
232
+ var import_util9 = require("@dxos/util");
233
+ var import_async17 = require("@dxos/async");
221
234
  var import_client_protocol5 = require("@dxos/client-protocol");
222
- var import_context12 = require("@dxos/context");
235
+ var import_context14 = require("@dxos/context");
223
236
  var import_credentials15 = require("@dxos/credentials");
224
- var import_echo_pipeline3 = require("@dxos/echo-pipeline");
225
- var import_echo_protocol = require("@dxos/echo-protocol");
237
+ var import_echo_db2 = require("@dxos/echo-db");
238
+ var import_echo_pipeline4 = require("@dxos/echo-pipeline");
239
+ var import_echo_protocol2 = require("@dxos/echo-protocol");
226
240
  var import_echo_schema2 = require("@dxos/echo-schema");
227
- var import_invariant14 = require("@dxos/invariant");
241
+ var import_invariant15 = require("@dxos/invariant");
228
242
  var import_keys12 = require("@dxos/keys");
229
- var import_log13 = require("@dxos/log");
243
+ var import_log15 = require("@dxos/log");
230
244
  var import_protocols11 = require("@dxos/protocols");
231
- var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
245
+ var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
232
246
  var import_credentials16 = require("@dxos/protocols/proto/dxos/halo/credentials");
233
247
  var import_teleport_extension_gossip2 = require("@dxos/teleport-extension-gossip");
234
248
  var import_tracing6 = require("@dxos/tracing");
235
- var import_util8 = require("@dxos/util");
249
+ var import_util10 = require("@dxos/util");
236
250
  var import_credentials17 = require("@dxos/credentials");
237
251
  var import_debug4 = require("@dxos/debug");
238
252
  var import_credentials18 = require("@dxos/protocols/proto/dxos/halo/credentials");
239
253
  var import_timeframe4 = require("@dxos/timeframe");
240
- var import_async16 = require("@dxos/async");
254
+ var import_async18 = require("@dxos/async");
241
255
  var import_codec_protobuf11 = require("@dxos/codec-protobuf");
242
256
  var import_credentials19 = require("@dxos/credentials");
243
257
  var import_debug5 = require("@dxos/debug");
244
258
  var import_feed_store4 = require("@dxos/feed-store");
245
- var import_invariant15 = require("@dxos/invariant");
246
- var import_log14 = require("@dxos/log");
259
+ var import_invariant16 = require("@dxos/invariant");
260
+ var import_log16 = require("@dxos/log");
247
261
  var import_protocols12 = require("@dxos/protocols");
248
- var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
262
+ var import_services15 = require("@dxos/protocols/proto/dxos/client/services");
249
263
  var import_tracing7 = require("@dxos/tracing");
250
- var import_async17 = require("@dxos/async");
251
- var import_context13 = require("@dxos/context");
264
+ var import_async19 = require("@dxos/async");
265
+ var import_context15 = require("@dxos/context");
252
266
  var import_credentials20 = require("@dxos/credentials");
253
267
  var import_debug6 = require("@dxos/debug");
254
- var import_echo_db = require("@dxos/echo-db");
255
- var import_echo_pipeline4 = require("@dxos/echo-pipeline");
268
+ var import_echo_db3 = require("@dxos/echo-db");
269
+ var import_echo_pipeline5 = require("@dxos/echo-pipeline");
256
270
  var import_feed_store5 = require("@dxos/feed-store");
257
- var import_invariant16 = require("@dxos/invariant");
271
+ var import_invariant17 = require("@dxos/invariant");
258
272
  var import_keyring = require("@dxos/keyring");
259
273
  var import_keys13 = require("@dxos/keys");
260
- var import_log15 = require("@dxos/log");
274
+ var import_log17 = require("@dxos/log");
261
275
  var import_protocols13 = require("@dxos/protocols");
262
- var import_services15 = require("@dxos/protocols/proto/dxos/client/services");
276
+ var import_services16 = require("@dxos/protocols/proto/dxos/client/services");
263
277
  var import_teleport_extension_object_sync = require("@dxos/teleport-extension-object-sync");
264
278
  var import_tracing8 = require("@dxos/tracing");
265
- var import_util9 = require("@dxos/util");
266
- var import_invariant17 = require("@dxos/invariant");
279
+ var import_util11 = require("@dxos/util");
280
+ var import_invariant18 = require("@dxos/invariant");
267
281
  var import_lock_file = require("@dxos/lock-file");
268
- var import_log16 = require("@dxos/log");
282
+ var import_log18 = require("@dxos/log");
269
283
  var import_protocols14 = require("@dxos/protocols");
270
284
  var import_config = require("@dxos/protocols/proto/dxos/config");
271
285
  var import_random_access_storage = require("@dxos/random-access-storage");
272
286
  var import_client_protocol6 = require("@dxos/client-protocol");
273
287
  var import_config2 = require("@dxos/protocols/proto/dxos/config");
274
- var import_util10 = require("@dxos/util");
288
+ var import_util12 = require("@dxos/util");
275
289
  var import_node_path = __toESM(require("node:path"));
276
290
  var import_keys14 = require("@dxos/keys");
277
291
  var import_kv_store = require("@dxos/kv-store");
278
- var import_async18 = require("@dxos/async");
292
+ var import_async20 = require("@dxos/async");
279
293
  var import_client_protocol7 = require("@dxos/client-protocol");
280
- var import_context14 = require("@dxos/context");
281
- var import_invariant18 = require("@dxos/invariant");
294
+ var import_context16 = require("@dxos/context");
295
+ var import_invariant19 = require("@dxos/invariant");
282
296
  var import_keys15 = require("@dxos/keys");
283
- var import_log17 = require("@dxos/log");
297
+ var import_log19 = require("@dxos/log");
284
298
  var import_messaging = require("@dxos/messaging");
285
299
  var import_network_manager2 = require("@dxos/network-manager");
286
300
  var import_protocols15 = require("@dxos/protocols");
287
- var import_services16 = require("@dxos/protocols/proto/dxos/client/services");
301
+ var import_services17 = require("@dxos/protocols/proto/dxos/client/services");
288
302
  var import_tracing9 = require("@dxos/tracing");
289
303
  var import_websocket_rpc = require("@dxos/websocket-rpc");
290
- var import_async19 = require("@dxos/async");
304
+ var import_async21 = require("@dxos/async");
291
305
  var import_codec_protobuf12 = require("@dxos/codec-protobuf");
292
- var import_invariant19 = require("@dxos/invariant");
293
- var import_services17 = require("@dxos/protocols/proto/dxos/client/services");
294
- var import_config3 = require("@dxos/config");
306
+ var import_invariant20 = require("@dxos/invariant");
295
307
  var import_services18 = require("@dxos/protocols/proto/dxos/client/services");
308
+ var import_config3 = require("@dxos/config");
309
+ var import_services19 = require("@dxos/protocols/proto/dxos/client/services");
296
310
  var import_tracing10 = require("@dxos/tracing");
297
- var import_util11 = require("@dxos/util");
311
+ var import_util13 = require("@dxos/util");
298
312
  var import_keys16 = require("@dxos/keys");
299
- var import_util12 = require("@dxos/util");
300
- var import_async20 = require("@dxos/async");
313
+ var import_util14 = require("@dxos/util");
314
+ var import_async22 = require("@dxos/async");
301
315
  var import_codec_protobuf13 = require("@dxos/codec-protobuf");
302
316
  var import_keys17 = require("@dxos/keys");
303
- var import_log18 = require("@dxos/log");
304
- var import_services19 = require("@dxos/protocols/proto/dxos/client/services");
305
- var import_util13 = require("@dxos/util");
317
+ var import_log20 = require("@dxos/log");
318
+ var import_services20 = require("@dxos/protocols/proto/dxos/client/services");
319
+ var import_util15 = require("@dxos/util");
306
320
  var import_codec_protobuf14 = require("@dxos/codec-protobuf");
307
321
  var import_codec_protobuf15 = require("@dxos/codec-protobuf");
308
- var import_services20 = require("@dxos/protocols/proto/dxos/client/services");
309
- var import_util14 = require("@dxos/util");
322
+ var import_services21 = require("@dxos/protocols/proto/dxos/client/services");
323
+ var import_util16 = require("@dxos/util");
310
324
  var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
311
325
  return new import_codec_protobuf.Stream(({ next }) => {
312
326
  const subscriptions = new import_async.EventSubscriptions();
@@ -617,7 +631,7 @@ var DevtoolsServiceImpl = class {
617
631
  });
618
632
  }
619
633
  };
620
- var DXOS_VERSION = "0.5.9-main.bfee100";
634
+ var DXOS_VERSION = "0.5.9-main.d63ef8d";
621
635
  var getPlatform = () => {
622
636
  if (process.browser) {
623
637
  if (typeof window !== "undefined") {
@@ -1646,6 +1660,7 @@ IdentityManager = _ts_decorate3([
1646
1660
  import_tracing4.trace.resource()
1647
1661
  ], IdentityManager);
1648
1662
  var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
1663
+ var DEFAULT_SPACE_SEARCH_TIMEOUT = 1e4;
1649
1664
  var IdentityServiceImpl = class extends import_context4.Resource {
1650
1665
  constructor(_identityManager, _keyring, _dataSpaceManagerProvider, _createIdentity, _onProfileUpdate) {
1651
1666
  super();
@@ -1675,7 +1690,7 @@ var IdentityServiceImpl = class extends import_context4.Resource {
1675
1690
  const identity = this._identityManager.identity;
1676
1691
  (0, import_invariant4.invariant)(identity, void 0, {
1677
1692
  F: __dxlog_file6,
1678
- L: 54,
1693
+ L: 59,
1679
1694
  S: this,
1680
1695
  A: [
1681
1696
  "identity",
@@ -1709,7 +1724,7 @@ var IdentityServiceImpl = class extends import_context4.Resource {
1709
1724
  async updateProfile(profile) {
1710
1725
  (0, import_invariant4.invariant)(this._identityManager.identity, "Identity not initialized.", {
1711
1726
  F: __dxlog_file6,
1712
- L: 84,
1727
+ L: 89,
1713
1728
  S: this,
1714
1729
  A: [
1715
1730
  "this._identityManager.identity",
@@ -1723,7 +1738,7 @@ var IdentityServiceImpl = class extends import_context4.Resource {
1723
1738
  async signPresentation({ presentation, nonce }) {
1724
1739
  (0, import_invariant4.invariant)(this._identityManager.identity, "Identity not initialized.", {
1725
1740
  F: __dxlog_file6,
1726
- L: 91,
1741
+ L: 96,
1727
1742
  S: this,
1728
1743
  A: [
1729
1744
  "this._identityManager.identity",
@@ -1739,20 +1754,43 @@ var IdentityServiceImpl = class extends import_context4.Resource {
1739
1754
  });
1740
1755
  }
1741
1756
  async _fixIdentityWithoutDefaultSpace(identity) {
1742
- let hasDefaultSpace = false;
1757
+ let recodedDefaultSpace = false;
1758
+ let foundDefaultSpace = false;
1743
1759
  const dataSpaceManager = this._dataSpaceManagerProvider();
1744
- for (const space of dataSpaceManager.spaces.values()) {
1760
+ const recordedDefaultSpaceTrigger = new import_async8.Trigger();
1761
+ const allProcessed = (0, import_util4.safeAwaitAll)(dataSpaceManager.spaces.values(), async (space) => {
1745
1762
  if (space.state === import_services4.SpaceState.CLOSED) {
1746
1763
  await space.open();
1747
- await space.initializeDataPipeline();
1764
+ const requiresMigration = space.stateUpdate.waitForCondition(() => space.state === import_services4.SpaceState.REQUIRES_MIGRATION);
1765
+ await Promise.race([
1766
+ space.initializeDataPipeline(),
1767
+ requiresMigration
1768
+ ]);
1748
1769
  }
1749
1770
  if (await dataSpaceManager.isDefaultSpace(space)) {
1771
+ if (foundDefaultSpace) {
1772
+ import_log5.log.warn("Multiple default spaces found. Using the first one.", {
1773
+ duplicate: space.id
1774
+ }, {
1775
+ F: __dxlog_file6,
1776
+ L: 127,
1777
+ S: this,
1778
+ C: (f, a) => f(...a)
1779
+ });
1780
+ return;
1781
+ }
1782
+ foundDefaultSpace = true;
1750
1783
  await identity.updateDefaultSpace(space.id);
1751
- hasDefaultSpace = true;
1752
- break;
1784
+ recodedDefaultSpace = true;
1785
+ recordedDefaultSpaceTrigger.wake();
1753
1786
  }
1754
- }
1755
- if (!hasDefaultSpace) {
1787
+ });
1788
+ await Promise.race([
1789
+ allProcessed,
1790
+ recordedDefaultSpaceTrigger.wait(),
1791
+ (0, import_async8.sleep)(DEFAULT_SPACE_SEARCH_TIMEOUT)
1792
+ ]);
1793
+ if (!recodedDefaultSpace) {
1756
1794
  await this._createDefaultSpace(dataSpaceManager);
1757
1795
  }
1758
1796
  }
@@ -1893,7 +1931,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1893
1931
  this._invitationFlowMutex = _invitationFlowMutex;
1894
1932
  this._callbacks = _callbacks;
1895
1933
  this._ctx = new import_context6.Context();
1896
- this._remoteOptionsTrigger = new import_async9.Trigger();
1934
+ this._remoteOptionsTrigger = new import_async10.Trigger();
1897
1935
  this._invitationFlowLock = null;
1898
1936
  }
1899
1937
  hasFlowLock() {
@@ -1930,14 +1968,14 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1930
1968
  async onOpen(context) {
1931
1969
  await super.onOpen(context);
1932
1970
  try {
1933
- (0, import_log6.log)("guest acquire lock", void 0, {
1971
+ (0, import_log7.log)("guest acquire lock", void 0, {
1934
1972
  F: __dxlog_file8,
1935
1973
  L: 84,
1936
1974
  S: this,
1937
1975
  C: (f, a) => f(...a)
1938
1976
  });
1939
1977
  this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
1940
- (0, import_log6.log)("guest lock acquired", void 0, {
1978
+ (0, import_log7.log)("guest lock acquired", void 0, {
1941
1979
  F: __dxlog_file8,
1942
1980
  L: 86,
1943
1981
  S: this,
@@ -1946,7 +1984,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1946
1984
  await (0, import_context6.cancelWithContext)(this._ctx, this.rpc.InvitationHostService.options({
1947
1985
  role: import_invitations3.Options.Role.GUEST
1948
1986
  }));
1949
- (0, import_log6.log)("options sent", void 0, {
1987
+ (0, import_log7.log)("options sent", void 0, {
1950
1988
  F: __dxlog_file8,
1951
1989
  L: 88,
1952
1990
  S: this,
@@ -1955,7 +1993,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1955
1993
  await (0, import_context6.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
1956
1994
  timeout: OPTIONS_TIMEOUT
1957
1995
  }));
1958
- (0, import_log6.log)("options received", void 0, {
1996
+ (0, import_log7.log)("options received", void 0, {
1959
1997
  F: __dxlog_file8,
1960
1998
  L: 90,
1961
1999
  S: this,
@@ -1989,7 +2027,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1989
2027
  if (this._invitationFlowLock != null) {
1990
2028
  this._invitationFlowLock.release();
1991
2029
  this._invitationFlowLock = null;
1992
- (0, import_log6.log)("invitation flow lock released", void 0, {
2030
+ (0, import_log7.log)("invitation flow lock released", void 0, {
1993
2031
  F: __dxlog_file8,
1994
2032
  L: 123,
1995
2033
  S: this,
@@ -2014,12 +2052,12 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2014
2052
  this._invitationFlowMutex = _invitationFlowMutex;
2015
2053
  this._callbacks = _callbacks;
2016
2054
  this._ctx = new import_context8.Context();
2017
- this._remoteOptionsTrigger = new import_async10.Trigger();
2055
+ this._remoteOptionsTrigger = new import_async11.Trigger();
2018
2056
  this._challenge = void 0;
2019
2057
  this.guestProfile = void 0;
2020
2058
  this.authenticationPassed = false;
2021
2059
  this.authenticationRetry = 0;
2022
- this.completedTrigger = new import_async10.Trigger();
2060
+ this.completedTrigger = new import_async11.Trigger();
2023
2061
  this._invitationFlowLock = null;
2024
2062
  }
2025
2063
  hasFlowLock() {
@@ -2046,7 +2084,7 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2046
2084
  introduce: async (request) => {
2047
2085
  const { profile, invitationId } = request;
2048
2086
  const traceId = import_keys7.PublicKey.random().toHex();
2049
- import_log7.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols7.trace.begin({
2087
+ import_log8.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols7.trace.begin({
2050
2088
  id: traceId
2051
2089
  }), {
2052
2090
  F: __dxlog_file9,
@@ -2057,7 +2095,7 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2057
2095
  const invitation = this._requireActiveInvitation();
2058
2096
  this._assertInvitationState(import_services8.Invitation.State.CONNECTED);
2059
2097
  if (invitationId !== invitation?.invitationId) {
2060
- import_log7.log.warn("incorrect invitationId", {
2098
+ import_log8.log.warn("incorrect invitationId", {
2061
2099
  expected: invitation.invitationId,
2062
2100
  actual: invitationId
2063
2101
  }, {
@@ -2067,12 +2105,12 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2067
2105
  C: (f, a) => f(...a)
2068
2106
  });
2069
2107
  this._callbacks.onError(new Error("Incorrect invitationId."));
2070
- (0, import_async10.scheduleTask)(this._ctx, () => this.close());
2108
+ (0, import_async11.scheduleTask)(this._ctx, () => this.close());
2071
2109
  return {
2072
2110
  authMethod: import_services8.Invitation.AuthMethod.NONE
2073
2111
  };
2074
2112
  }
2075
- (0, import_log7.log)("guest introduced themselves", {
2113
+ (0, import_log8.log)("guest introduced themselves", {
2076
2114
  guestProfile: profile
2077
2115
  }, {
2078
2116
  F: __dxlog_file9,
@@ -2083,7 +2121,7 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2083
2121
  this.guestProfile = profile;
2084
2122
  this._callbacks.onStateUpdate(import_services8.Invitation.State.READY_FOR_AUTHENTICATION);
2085
2123
  this._challenge = invitation.authMethod === import_services8.Invitation.AuthMethod.KNOWN_PUBLIC_KEY ? (0, import_crypto2.randomBytes)(32) : void 0;
2086
- import_log7.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols7.trace.end({
2124
+ import_log8.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols7.trace.end({
2087
2125
  id: traceId
2088
2126
  }), {
2089
2127
  F: __dxlog_file9,
@@ -2098,7 +2136,7 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2098
2136
  },
2099
2137
  authenticate: async ({ authCode: code, signedChallenge }) => {
2100
2138
  const traceId = import_keys7.PublicKey.random().toHex();
2101
- import_log7.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols7.trace.begin({
2139
+ import_log8.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols7.trace.begin({
2102
2140
  id: traceId
2103
2141
  }), {
2104
2142
  F: __dxlog_file9,
@@ -2107,7 +2145,7 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2107
2145
  C: (f, a) => f(...a)
2108
2146
  });
2109
2147
  const invitation = this._requireActiveInvitation();
2110
- (0, import_log7.log)("received authentication request", {
2148
+ (0, import_log8.log)("received authentication request", {
2111
2149
  authCode: code
2112
2150
  }, {
2113
2151
  F: __dxlog_file9,
@@ -2123,7 +2161,7 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2123
2161
  this._callbacks.onStateUpdate(import_services8.Invitation.State.AUTHENTICATING);
2124
2162
  switch (invitation.authMethod) {
2125
2163
  case import_services8.Invitation.AuthMethod.NONE: {
2126
- (0, import_log7.log)("authentication not required", void 0, {
2164
+ (0, import_log8.log)("authentication not required", void 0, {
2127
2165
  F: __dxlog_file9,
2128
2166
  L: 152,
2129
2167
  S: this,
@@ -2159,7 +2197,7 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2159
2197
  break;
2160
2198
  }
2161
2199
  default: {
2162
- import_log7.log.error("invalid authentication method", {
2200
+ import_log8.log.error("invalid authentication method", {
2163
2201
  authMethod: invitation.authMethod
2164
2202
  }, {
2165
2203
  F: __dxlog_file9,
@@ -2176,12 +2214,12 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2176
2214
  import_invitations4.AuthenticationResponse.Status.INVALID_OTP
2177
2215
  ].includes(status)) {
2178
2216
  this._callbacks.onError(new Error(`Authentication failed, with status=${status}`));
2179
- (0, import_async10.scheduleTask)(this._ctx, () => this.close());
2217
+ (0, import_async11.scheduleTask)(this._ctx, () => this.close());
2180
2218
  return {
2181
2219
  status
2182
2220
  };
2183
2221
  }
2184
- import_log7.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols7.trace.end({
2222
+ import_log8.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols7.trace.end({
2185
2223
  id: traceId,
2186
2224
  data: {
2187
2225
  status
@@ -2198,7 +2236,7 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2198
2236
  },
2199
2237
  admit: async (request) => {
2200
2238
  const traceId = import_keys7.PublicKey.random().toHex();
2201
- import_log7.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols7.trace.begin({
2239
+ import_log8.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols7.trace.begin({
2202
2240
  id: traceId
2203
2241
  }), {
2204
2242
  F: __dxlog_file9,
@@ -2215,7 +2253,7 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2215
2253
  }
2216
2254
  }
2217
2255
  const response = await this._callbacks.admit(request);
2218
- import_log7.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols7.trace.end({
2256
+ import_log8.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols7.trace.end({
2219
2257
  id: traceId
2220
2258
  }), {
2221
2259
  F: __dxlog_file9,
@@ -2235,14 +2273,14 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2235
2273
  async onOpen(context) {
2236
2274
  await super.onOpen(context);
2237
2275
  try {
2238
- (0, import_log7.log)("host acquire lock", void 0, {
2276
+ (0, import_log8.log)("host acquire lock", void 0, {
2239
2277
  F: __dxlog_file9,
2240
2278
  L: 237,
2241
2279
  S: this,
2242
2280
  C: (f, a) => f(...a)
2243
2281
  });
2244
2282
  this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
2245
- (0, import_log7.log)("host lock acquired", void 0, {
2283
+ (0, import_log8.log)("host lock acquired", void 0, {
2246
2284
  F: __dxlog_file9,
2247
2285
  L: 239,
2248
2286
  S: this,
@@ -2253,7 +2291,7 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2253
2291
  await this.rpc.InvitationHostService.options({
2254
2292
  role: import_invitations4.Options.Role.HOST
2255
2293
  });
2256
- (0, import_log7.log)("options sent", void 0, {
2294
+ (0, import_log8.log)("options sent", void 0, {
2257
2295
  F: __dxlog_file9,
2258
2296
  L: 243,
2259
2297
  S: this,
@@ -2262,7 +2300,7 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2262
2300
  await (0, import_context8.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
2263
2301
  timeout: OPTIONS_TIMEOUT2
2264
2302
  }));
2265
- (0, import_log7.log)("options received", void 0, {
2303
+ (0, import_log8.log)("options received", void 0, {
2266
2304
  F: __dxlog_file9,
2267
2305
  L: 245,
2268
2306
  S: this,
@@ -2290,7 +2328,7 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2290
2328
  _requireActiveInvitation() {
2291
2329
  const invitation = this._callbacks.activeInvitation;
2292
2330
  if (invitation == null) {
2293
- (0, import_async10.scheduleTask)(this._ctx, () => this.close());
2331
+ (0, import_async11.scheduleTask)(this._ctx, () => this.close());
2294
2332
  throw new Error("Active invitation not found");
2295
2333
  }
2296
2334
  return invitation;
@@ -2301,7 +2339,7 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2301
2339
  stateOrMany
2302
2340
  ];
2303
2341
  if (!validStates.includes(invitation.state)) {
2304
- (0, import_async10.scheduleTask)(this._ctx, () => this.close());
2342
+ (0, import_async11.scheduleTask)(this._ctx, () => this.close());
2305
2343
  throw new import_invariant8.InvariantViolation(`Expected ${stateToString(invitation.state)} to be one of [${validStates.map(stateToString).join(", ")}]`);
2306
2344
  }
2307
2345
  }
@@ -2316,7 +2354,7 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2316
2354
  if (this._invitationFlowLock != null) {
2317
2355
  this._invitationFlowLock?.release();
2318
2356
  this._invitationFlowLock = null;
2319
- (0, import_log7.log)("invitation flow lock released", void 0, {
2357
+ (0, import_log8.log)("invitation flow lock released", void 0, {
2320
2358
  F: __dxlog_file9,
2321
2359
  L: 300,
2322
2360
  S: this,
@@ -2330,7 +2368,7 @@ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/s
2330
2368
  var InvitationTopology = class {
2331
2369
  constructor(_role) {
2332
2370
  this._role = _role;
2333
- this._seenPeers = new import_util5.ComplexSet(import_keys8.PublicKey.hash);
2371
+ this._seenPeers = new import_util6.ComplexSet(import_keys8.PublicKey.hash);
2334
2372
  }
2335
2373
  init(controller) {
2336
2374
  (0, import_invariant9.invariant)(!this._controller, "Already initialized.", {
@@ -2363,9 +2401,9 @@ var InvitationTopology = class {
2363
2401
  return;
2364
2402
  }
2365
2403
  const firstUnknownPeer = candidates.find((peerId) => !this._seenPeers.has(peerId));
2366
- this._seenPeers = new import_util5.ComplexSet(import_keys8.PublicKey.hash, allPeers.filter((peerId) => this._seenPeers.has(peerId)));
2404
+ this._seenPeers = new import_util6.ComplexSet(import_keys8.PublicKey.hash, allPeers.filter((peerId) => this._seenPeers.has(peerId)));
2367
2405
  if (firstUnknownPeer != null) {
2368
- (0, import_log8.log)("invitation connect", {
2406
+ (0, import_log9.log)("invitation connect", {
2369
2407
  ownPeerId,
2370
2408
  remotePeerId: firstUnknownPeer
2371
2409
  }, {
@@ -2445,10 +2483,10 @@ var InvitationsHandler = class {
2445
2483
  guardedState.error(extension, new import_context5.ContextDisposedError());
2446
2484
  }
2447
2485
  });
2448
- (0, import_async8.scheduleTask)(connectionCtx, async () => {
2486
+ (0, import_async9.scheduleTask)(connectionCtx, async () => {
2449
2487
  const traceId = import_keys6.PublicKey.random().toHex();
2450
2488
  try {
2451
- import_log5.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols5.trace.begin({
2489
+ import_log6.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols5.trace.begin({
2452
2490
  id: traceId
2453
2491
  }), {
2454
2492
  F: __dxlog_file11,
@@ -2456,7 +2494,7 @@ var InvitationsHandler = class {
2456
2494
  S: this,
2457
2495
  C: (f, a) => f(...a)
2458
2496
  });
2459
- (0, import_log5.log)("connected", {
2497
+ (0, import_log6.log)("connected", {
2460
2498
  ...protocol.toJSON()
2461
2499
  }, {
2462
2500
  F: __dxlog_file11,
@@ -2467,7 +2505,7 @@ var InvitationsHandler = class {
2467
2505
  const deviceKey = await extension.completedTrigger.wait({
2468
2506
  timeout: invitation.timeout
2469
2507
  });
2470
- (0, import_log5.log)("admitted guest", {
2508
+ (0, import_log6.log)("admitted guest", {
2471
2509
  guest: deviceKey,
2472
2510
  ...protocol.toJSON()
2473
2511
  }, {
@@ -2477,7 +2515,7 @@ var InvitationsHandler = class {
2477
2515
  C: (f, a) => f(...a)
2478
2516
  });
2479
2517
  guardedState.set(extension, import_services6.Invitation.State.SUCCESS);
2480
- import_log5.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols5.trace.end({
2518
+ import_log6.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols5.trace.end({
2481
2519
  id: traceId
2482
2520
  }), {
2483
2521
  F: __dxlog_file11,
@@ -2490,9 +2528,9 @@ var InvitationsHandler = class {
2490
2528
  await ctx.dispose();
2491
2529
  }
2492
2530
  } catch (err) {
2493
- if (err instanceof import_async8.TimeoutError) {
2531
+ if (err instanceof import_async9.TimeoutError) {
2494
2532
  if (guardedState.set(extension, import_services6.Invitation.State.TIMEOUT)) {
2495
- (0, import_log5.log)("timeout", {
2533
+ (0, import_log6.log)("timeout", {
2496
2534
  ...protocol.toJSON()
2497
2535
  }, {
2498
2536
  F: __dxlog_file11,
@@ -2503,7 +2541,7 @@ var InvitationsHandler = class {
2503
2541
  }
2504
2542
  } else {
2505
2543
  if (guardedState.error(extension, err)) {
2506
- import_log5.log.error("failed", err, {
2544
+ import_log6.log.error("failed", err, {
2507
2545
  F: __dxlog_file11,
2508
2546
  L: 133,
2509
2547
  S: this,
@@ -2511,7 +2549,7 @@ var InvitationsHandler = class {
2511
2549
  });
2512
2550
  }
2513
2551
  }
2514
- import_log5.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols5.trace.error({
2552
+ import_log6.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols5.trace.error({
2515
2553
  id: traceId,
2516
2554
  error: err
2517
2555
  }), {
@@ -2526,7 +2564,7 @@ var InvitationsHandler = class {
2526
2564
  },
2527
2565
  onError: (err) => {
2528
2566
  if (err instanceof import_protocols5.InvalidInvitationExtensionRoleError) {
2529
- (0, import_log5.log)("invalid role", {
2567
+ (0, import_log6.log)("invalid role", {
2530
2568
  ...err.context
2531
2569
  }, {
2532
2570
  F: __dxlog_file11,
@@ -2536,9 +2574,9 @@ var InvitationsHandler = class {
2536
2574
  });
2537
2575
  return;
2538
2576
  }
2539
- if (err instanceof import_async8.TimeoutError) {
2577
+ if (err instanceof import_async9.TimeoutError) {
2540
2578
  if (guardedState.set(extension, import_services6.Invitation.State.TIMEOUT)) {
2541
- (0, import_log5.log)("timeout", {
2579
+ (0, import_log6.log)("timeout", {
2542
2580
  err
2543
2581
  }, {
2544
2582
  F: __dxlog_file11,
@@ -2549,7 +2587,7 @@ var InvitationsHandler = class {
2549
2587
  }
2550
2588
  } else {
2551
2589
  if (guardedState.error(extension, err)) {
2552
- import_log5.log.error("failed", err, {
2590
+ import_log6.log.error("failed", err, {
2553
2591
  F: __dxlog_file11,
2554
2592
  L: 153,
2555
2593
  S: this,
@@ -2563,14 +2601,14 @@ var InvitationsHandler = class {
2563
2601
  };
2564
2602
  if (invitation.lifetime && invitation.created) {
2565
2603
  if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
2566
- import_log5.log.warn("invitation has already expired", void 0, {
2604
+ import_log6.log.warn("invitation has already expired", void 0, {
2567
2605
  F: __dxlog_file11,
2568
2606
  L: 164,
2569
2607
  S: this,
2570
2608
  C: (f, a) => f(...a)
2571
2609
  });
2572
2610
  } else {
2573
- (0, import_async8.scheduleTask)(ctx, async () => {
2611
+ (0, import_async9.scheduleTask)(ctx, async () => {
2574
2612
  await swarmConnection.close();
2575
2613
  guardedState.set(null, import_services6.Invitation.State.EXPIRED);
2576
2614
  await ctx.dispose();
@@ -2578,7 +2616,7 @@ var InvitationsHandler = class {
2578
2616
  }
2579
2617
  }
2580
2618
  let swarmConnection;
2581
- (0, import_async8.scheduleTask)(ctx, async () => {
2619
+ (0, import_async9.scheduleTask)(ctx, async () => {
2582
2620
  swarmConnection = await this._joinSwarm(ctx, invitation, import_invitations2.Options.Role.HOST, createExtension);
2583
2621
  guardedState.set(null, import_services6.Invitation.State.CONNECTING);
2584
2622
  });
@@ -2596,11 +2634,11 @@ var InvitationsHandler = class {
2596
2634
  ]
2597
2635
  });
2598
2636
  }
2599
- const triedPeersIds = new import_util4.ComplexSet(import_keys6.PublicKey.hash);
2637
+ const triedPeersIds = new import_util5.ComplexSet(import_keys6.PublicKey.hash);
2600
2638
  const guardedState = this._createGuardedState(ctx, invitation, stream);
2601
2639
  const shouldCancelInvitationFlow = (extension) => {
2602
2640
  const isLockedByAnotherConnection = guardedState.mutex.isLocked() && !extension.hasFlowLock();
2603
- (0, import_log5.log)("should cancel invitation flow", {
2641
+ (0, import_log6.log)("should cancel invitation flow", {
2604
2642
  isLockedByAnotherConnection,
2605
2643
  invitationType: import_services6.Invitation.Type.DELEGATED,
2606
2644
  triedPeers: triedPeersIds.size
@@ -2628,7 +2666,7 @@ var InvitationsHandler = class {
2628
2666
  return;
2629
2667
  }
2630
2668
  connectionCtx.onDispose(async () => {
2631
- (0, import_log5.log)("extension disposed", {
2669
+ (0, import_log6.log)("extension disposed", {
2632
2670
  admitted,
2633
2671
  currentState: guardedState.current.state
2634
2672
  }, {
@@ -2644,10 +2682,10 @@ var InvitationsHandler = class {
2644
2682
  }
2645
2683
  }
2646
2684
  });
2647
- (0, import_async8.scheduleTask)(connectionCtx, async () => {
2685
+ (0, import_async9.scheduleTask)(connectionCtx, async () => {
2648
2686
  const traceId = import_keys6.PublicKey.random().toHex();
2649
2687
  try {
2650
- import_log5.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols5.trace.begin({
2688
+ import_log6.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols5.trace.begin({
2651
2689
  id: traceId
2652
2690
  }), {
2653
2691
  F: __dxlog_file11,
@@ -2655,11 +2693,11 @@ var InvitationsHandler = class {
2655
2693
  S: this,
2656
2694
  C: (f, a) => f(...a)
2657
2695
  });
2658
- (0, import_async8.scheduleTask)(connectionCtx, () => {
2696
+ (0, import_async9.scheduleTask)(connectionCtx, () => {
2659
2697
  guardedState.set(extension, import_services6.Invitation.State.TIMEOUT);
2660
2698
  extensionCtx.close();
2661
2699
  }, timeout);
2662
- (0, import_log5.log)("connected", {
2700
+ (0, import_log6.log)("connected", {
2663
2701
  ...protocol.toJSON()
2664
2702
  }, {
2665
2703
  F: __dxlog_file11,
@@ -2668,7 +2706,7 @@ var InvitationsHandler = class {
2668
2706
  C: (f, a) => f(...a)
2669
2707
  });
2670
2708
  guardedState.set(extension, import_services6.Invitation.State.CONNECTED);
2671
- (0, import_log5.log)("introduce", {
2709
+ (0, import_log6.log)("introduce", {
2672
2710
  ...protocol.toJSON()
2673
2711
  }, {
2674
2712
  F: __dxlog_file11,
@@ -2680,7 +2718,7 @@ var InvitationsHandler = class {
2680
2718
  invitationId: invitation.invitationId,
2681
2719
  ...protocol.createIntroduction()
2682
2720
  });
2683
- (0, import_log5.log)("introduce response", {
2721
+ (0, import_log6.log)("introduce response", {
2684
2722
  ...protocol.toJSON(),
2685
2723
  response: introductionResponse
2686
2724
  }, {
@@ -2702,7 +2740,7 @@ var InvitationsHandler = class {
2702
2740
  break;
2703
2741
  }
2704
2742
  }
2705
- (0, import_log5.log)("request admission", {
2743
+ (0, import_log6.log)("request admission", {
2706
2744
  ...protocol.toJSON()
2707
2745
  }, {
2708
2746
  F: __dxlog_file11,
@@ -2714,7 +2752,7 @@ var InvitationsHandler = class {
2714
2752
  const admissionResponse = await extension.rpc.InvitationHostService.admit(admissionRequest);
2715
2753
  admitted = true;
2716
2754
  const result = await protocol.accept(admissionResponse, admissionRequest);
2717
- (0, import_log5.log)("admitted by host", {
2755
+ (0, import_log6.log)("admitted by host", {
2718
2756
  ...protocol.toJSON()
2719
2757
  }, {
2720
2758
  F: __dxlog_file11,
@@ -2727,7 +2765,7 @@ var InvitationsHandler = class {
2727
2765
  ...result,
2728
2766
  state: import_services6.Invitation.State.SUCCESS
2729
2767
  });
2730
- import_log5.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols5.trace.end({
2768
+ import_log6.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols5.trace.end({
2731
2769
  id: traceId
2732
2770
  }), {
2733
2771
  F: __dxlog_file11,
@@ -2736,8 +2774,8 @@ var InvitationsHandler = class {
2736
2774
  C: (f, a) => f(...a)
2737
2775
  });
2738
2776
  } catch (err) {
2739
- if (err instanceof import_async8.TimeoutError) {
2740
- (0, import_log5.log)("timeout", {
2777
+ if (err instanceof import_async9.TimeoutError) {
2778
+ (0, import_log6.log)("timeout", {
2741
2779
  ...protocol.toJSON()
2742
2780
  }, {
2743
2781
  F: __dxlog_file11,
@@ -2747,7 +2785,7 @@ var InvitationsHandler = class {
2747
2785
  });
2748
2786
  guardedState.set(extension, import_services6.Invitation.State.TIMEOUT);
2749
2787
  } else {
2750
- (0, import_log5.log)("auth failed", err, {
2788
+ (0, import_log6.log)("auth failed", err, {
2751
2789
  F: __dxlog_file11,
2752
2790
  L: 314,
2753
2791
  S: this,
@@ -2756,7 +2794,7 @@ var InvitationsHandler = class {
2756
2794
  guardedState.error(extension, err);
2757
2795
  }
2758
2796
  extensionCtx.close(err);
2759
- import_log5.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols5.trace.error({
2797
+ import_log6.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols5.trace.error({
2760
2798
  id: traceId,
2761
2799
  error: err
2762
2800
  }), {
@@ -2772,8 +2810,8 @@ var InvitationsHandler = class {
2772
2810
  if (err instanceof import_protocols5.InvalidInvitationExtensionRoleError) {
2773
2811
  return;
2774
2812
  }
2775
- if (err instanceof import_async8.TimeoutError) {
2776
- (0, import_log5.log)("timeout", {
2813
+ if (err instanceof import_async9.TimeoutError) {
2814
+ (0, import_log6.log)("timeout", {
2777
2815
  ...protocol.toJSON()
2778
2816
  }, {
2779
2817
  F: __dxlog_file11,
@@ -2783,7 +2821,7 @@ var InvitationsHandler = class {
2783
2821
  });
2784
2822
  guardedState.set(extension, import_services6.Invitation.State.TIMEOUT);
2785
2823
  } else {
2786
- (0, import_log5.log)("auth failed", err, {
2824
+ (0, import_log6.log)("auth failed", err, {
2787
2825
  F: __dxlog_file11,
2788
2826
  L: 330,
2789
2827
  S: this,
@@ -2795,7 +2833,7 @@ var InvitationsHandler = class {
2795
2833
  });
2796
2834
  return extension;
2797
2835
  };
2798
- (0, import_async8.scheduleTask)(ctx, async () => {
2836
+ (0, import_async9.scheduleTask)(ctx, async () => {
2799
2837
  const error = protocol.checkInvitation(invitation);
2800
2838
  if (error) {
2801
2839
  stream.error(error);
@@ -2841,7 +2879,7 @@ var InvitationsHandler = class {
2841
2879
  * invitation flow connections.
2842
2880
  */
2843
2881
  _createGuardedState(ctx, invitation, stream) {
2844
- const mutex = new import_async8.Mutex();
2882
+ const mutex = new import_async9.Mutex();
2845
2883
  let lastActiveExtension = null;
2846
2884
  let currentInvitation = {
2847
2885
  ...invitation
@@ -2896,7 +2934,7 @@ var InvitationsHandler = class {
2896
2934
  };
2897
2935
  }
2898
2936
  _logStateUpdate(invitation, actor, newState) {
2899
- (0, import_log5.log)("invitation state update", {
2937
+ (0, import_log6.log)("invitation state update", {
2900
2938
  actor: actor?.constructor.name,
2901
2939
  newState: stateToString(newState),
2902
2940
  oldState: stateToString(invitation.state)
@@ -2918,7 +2956,7 @@ var InvitationsHandler = class {
2918
2956
  }
2919
2957
  async _handleGuestOtpAuth(extension, setState, authenticated, options) {
2920
2958
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2921
- (0, import_log5.log)("guest waiting for authentication code...", void 0, {
2959
+ (0, import_log6.log)("guest waiting for authentication code...", void 0, {
2922
2960
  F: __dxlog_file11,
2923
2961
  L: 462,
2924
2962
  S: this,
@@ -2926,7 +2964,7 @@ var InvitationsHandler = class {
2926
2964
  });
2927
2965
  setState(import_services6.Invitation.State.READY_FOR_AUTHENTICATION);
2928
2966
  const authCode = await authenticated.wait(options);
2929
- (0, import_log5.log)("sending authentication request", void 0, {
2967
+ (0, import_log6.log)("sending authentication request", void 0, {
2930
2968
  F: __dxlog_file11,
2931
2969
  L: 466,
2932
2970
  S: this,
@@ -2943,7 +2981,7 @@ var InvitationsHandler = class {
2943
2981
  if (attempt === MAX_OTP_ATTEMPTS) {
2944
2982
  throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
2945
2983
  } else {
2946
- (0, import_log5.log)("retrying invalid code", {
2984
+ (0, import_log6.log)("retrying invalid code", {
2947
2985
  attempt
2948
2986
  }, {
2949
2987
  F: __dxlog_file11,
@@ -2963,7 +3001,7 @@ var InvitationsHandler = class {
2963
3001
  if (introductionResponse.challenge == null) {
2964
3002
  throw new Error("challenge missing in the introduction");
2965
3003
  }
2966
- (0, import_log5.log)("sending authentication request", void 0, {
3004
+ (0, import_log6.log)("sending authentication request", void 0, {
2967
3005
  F: __dxlog_file11,
2968
3006
  L: 496,
2969
3007
  S: this,
@@ -3145,7 +3183,7 @@ var SpaceInvitationProtocol = class {
3145
3183
  if (space.inner.spaceState.getMemberRole(identityKey) !== import_credentials10.SpaceMember.Role.REMOVED) {
3146
3184
  throw new import_protocols8.AlreadyJoinedError();
3147
3185
  }
3148
- (0, import_log9.log)("writing guest credentials", {
3186
+ (0, import_log10.log)("writing guest credentials", {
3149
3187
  host: this._signingContext.deviceKey,
3150
3188
  guest: deviceKey
3151
3189
  }, {
@@ -3213,7 +3251,7 @@ var SpaceInvitationProtocol = class {
3213
3251
  ]
3214
3252
  });
3215
3253
  }
3216
- (0, import_log9.log)("writing delegate space invitation", {
3254
+ (0, import_log10.log)("writing delegate space invitation", {
3217
3255
  host: this._signingContext.deviceKey,
3218
3256
  id: invitation.invitationId
3219
3257
  }, {
@@ -3274,7 +3312,7 @@ var SpaceInvitationProtocol = class {
3274
3312
  ""
3275
3313
  ]
3276
3314
  });
3277
- (0, import_log9.log)("cancelling delegated space invitation", {
3315
+ (0, import_log10.log)("cancelling delegated space invitation", {
3278
3316
  host: this._signingContext.deviceKey,
3279
3317
  id: invitation.invitationId
3280
3318
  }, {
@@ -3375,12 +3413,12 @@ var InvitationsManager = class {
3375
3413
  this._metadataStore = _metadataStore;
3376
3414
  this._createInvitations = /* @__PURE__ */ new Map();
3377
3415
  this._acceptInvitations = /* @__PURE__ */ new Map();
3378
- this.invitationCreated = new import_async11.Event();
3379
- this.invitationAccepted = new import_async11.Event();
3380
- this.removedCreated = new import_async11.Event();
3381
- this.removedAccepted = new import_async11.Event();
3382
- this.saved = new import_async11.Event();
3383
- this._persistentInvitationsLoadedEvent = new import_async11.Event();
3416
+ this.invitationCreated = new import_async12.Event();
3417
+ this.invitationAccepted = new import_async12.Event();
3418
+ this.removedCreated = new import_async12.Event();
3419
+ this.removedAccepted = new import_async12.Event();
3420
+ this.saved = new import_async12.Event();
3421
+ this._persistentInvitationsLoadedEvent = new import_async12.Event();
3384
3422
  this._persistentInvitationsLoaded = false;
3385
3423
  }
3386
3424
  async createInvitation(options) {
@@ -3409,7 +3447,7 @@ var InvitationsManager = class {
3409
3447
  try {
3410
3448
  await this._persistIfRequired(handler, stream, invitation);
3411
3449
  } catch (err) {
3412
- import_log10.log.catch(err, void 0, {
3450
+ import_log11.log.catch(err, void 0, {
3413
3451
  F: __dxlog_file13,
3414
3452
  L: 82,
3415
3453
  S: this,
@@ -3451,7 +3489,7 @@ var InvitationsManager = class {
3451
3489
  invitations: cInvitations.map((invitation) => invitation.get())
3452
3490
  };
3453
3491
  } catch (err) {
3454
- import_log10.log.catch(err, void 0, {
3492
+ import_log11.log.catch(err, void 0, {
3455
3493
  F: __dxlog_file13,
3456
3494
  L: 110,
3457
3495
  S: this,
@@ -3483,7 +3521,7 @@ var InvitationsManager = class {
3483
3521
  return invitation;
3484
3522
  }
3485
3523
  async authenticate({ invitationId, authCode }) {
3486
- (0, import_log10.log)("authenticating...", void 0, {
3524
+ (0, import_log11.log)("authenticating...", void 0, {
3487
3525
  F: __dxlog_file13,
3488
3526
  L: 140,
3489
3527
  S: this,
@@ -3500,7 +3538,7 @@ var InvitationsManager = class {
3500
3538
  });
3501
3539
  const observable = this._acceptInvitations.get(invitationId);
3502
3540
  if (!observable) {
3503
- import_log10.log.warn("invalid invitation", {
3541
+ import_log11.log.warn("invalid invitation", {
3504
3542
  invitationId
3505
3543
  }, {
3506
3544
  F: __dxlog_file13,
@@ -3513,7 +3551,7 @@ var InvitationsManager = class {
3513
3551
  }
3514
3552
  }
3515
3553
  async cancelInvitation({ invitationId }) {
3516
- (0, import_log10.log)("cancelInvitation...", {
3554
+ (0, import_log11.log)("cancelInvitation...", {
3517
3555
  invitationId
3518
3556
  }, {
3519
3557
  F: __dxlog_file13,
@@ -3590,7 +3628,7 @@ var InvitationsManager = class {
3590
3628
  };
3591
3629
  }
3592
3630
  _createObservableInvitation(handler, invitation) {
3593
- const stream = new import_async11.PushStream();
3631
+ const stream = new import_async12.PushStream();
3594
3632
  const ctx = new import_context9.Context({
3595
3633
  onError: (err) => {
3596
3634
  stream.error(err);
@@ -3598,7 +3636,7 @@ var InvitationsManager = class {
3598
3636
  }
3599
3637
  });
3600
3638
  ctx.onDispose(() => {
3601
- (0, import_log10.log)("complete", {
3639
+ (0, import_log11.log)("complete", {
3602
3640
  ...handler.toJSON()
3603
3641
  }, {
3604
3642
  F: __dxlog_file13,
@@ -3626,12 +3664,12 @@ var InvitationsManager = class {
3626
3664
  };
3627
3665
  }
3628
3666
  _createObservableAcceptingInvitation(handler, initialState) {
3629
- const otpEnteredTrigger = new import_async11.Trigger();
3630
- const stream = new import_async11.PushStream();
3667
+ const otpEnteredTrigger = new import_async12.Trigger();
3668
+ const stream = new import_async12.PushStream();
3631
3669
  const ctx = new import_context9.Context({
3632
3670
  onError: (err) => {
3633
- if (err instanceof import_async11.TimeoutError) {
3634
- (0, import_log10.log)("timeout", {
3671
+ if (err instanceof import_async12.TimeoutError) {
3672
+ (0, import_log11.log)("timeout", {
3635
3673
  ...handler.toJSON()
3636
3674
  }, {
3637
3675
  F: __dxlog_file13,
@@ -3644,7 +3682,7 @@ var InvitationsManager = class {
3644
3682
  state: import_services11.Invitation.State.TIMEOUT
3645
3683
  });
3646
3684
  } else {
3647
- import_log10.log.warn("auth failed", err, {
3685
+ import_log11.log.warn("auth failed", err, {
3648
3686
  F: __dxlog_file13,
3649
3687
  L: 264,
3650
3688
  S: this,
@@ -3659,7 +3697,7 @@ var InvitationsManager = class {
3659
3697
  }
3660
3698
  });
3661
3699
  ctx.onDispose(() => {
3662
- (0, import_log10.log)("complete", {
3700
+ (0, import_log11.log)("complete", {
3663
3701
  ...handler.toJSON()
3664
3702
  }, {
3665
3703
  F: __dxlog_file13,
@@ -3706,7 +3744,7 @@ var InvitationsManager = class {
3706
3744
  try {
3707
3745
  await this._metadataStore.removeInvitation(invitation.invitationId);
3708
3746
  } catch (err) {
3709
- import_log10.log.catch(err, void 0, {
3747
+ import_log11.log.catch(err, void 0, {
3710
3748
  F: __dxlog_file13,
3711
3749
  L: 307,
3712
3750
  S: this,
@@ -3720,12 +3758,18 @@ var InvitationsManager = class {
3720
3758
  }, callback);
3721
3759
  }
3722
3760
  };
3723
- var AutomergeSpaceState = class {
3761
+ var AutomergeSpaceState = class extends import_context11.Resource {
3724
3762
  constructor(_onNewRoot) {
3763
+ super();
3725
3764
  this._onNewRoot = _onNewRoot;
3726
3765
  this.rootUrl = void 0;
3727
3766
  this.lastEpoch = void 0;
3728
- this.onNewEpoch = new import_async13.Event();
3767
+ this.onNewEpoch = new import_async14.Event();
3768
+ this._isProcessingRootDocs = false;
3769
+ }
3770
+ async _open(ctx) {
3771
+ }
3772
+ async _close(ctx) {
3729
3773
  this._isProcessingRootDocs = false;
3730
3774
  }
3731
3775
  async processCredential(credential) {
@@ -3754,18 +3798,152 @@ var AutomergeSpaceState = class {
3754
3798
  await this.onNewEpoch.waitForCondition(() => !!this.lastEpoch);
3755
3799
  }
3756
3800
  };
3757
- var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
3801
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts";
3802
+ var runEpochMigration = async (ctx, context) => {
3803
+ switch (context.migration) {
3804
+ case import_services13.CreateEpochRequest.Migration.INIT_AUTOMERGE: {
3805
+ const document = context.repo.create();
3806
+ await context.repo.flush();
3807
+ return {
3808
+ newRoot: document.url
3809
+ };
3810
+ }
3811
+ case import_services13.CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY: {
3812
+ if (!context.currentRoot) {
3813
+ throw new Error("Space does not have an automerge root");
3814
+ }
3815
+ const rootHandle = context.repo.find(context.currentRoot);
3816
+ await (0, import_context12.cancelWithContext)(ctx, (0, import_async15.asyncTimeout)(rootHandle.whenReady(), 1e4));
3817
+ const newRoot = context.repo.create(rootHandle.docSync());
3818
+ await context.repo.flush();
3819
+ return {
3820
+ newRoot: newRoot.url
3821
+ };
3822
+ }
3823
+ case import_services13.CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT: {
3824
+ import_log13.log.info("Fragmenting", void 0, {
3825
+ F: __dxlog_file14,
3826
+ L: 63,
3827
+ S: void 0,
3828
+ C: (f, a) => f(...a)
3829
+ });
3830
+ const currentRootUrl = context.currentRoot;
3831
+ const rootHandle = context.repo.find(currentRootUrl);
3832
+ await (0, import_context12.cancelWithContext)(ctx, (0, import_async15.asyncTimeout)(rootHandle.whenReady(), 1e4));
3833
+ const objects = Object.entries(rootHandle.docSync().objects);
3834
+ const properties = (0, import_echo_db.findInlineObjectOfType)(rootHandle.docSync(), import_echo_schema.TYPE_PROPERTIES);
3835
+ const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
3836
+ (0, import_invariant13.invariant)(properties, "Properties not found", {
3837
+ F: __dxlog_file14,
3838
+ L: 73,
3839
+ S: void 0,
3840
+ A: [
3841
+ "properties",
3842
+ "'Properties not found'"
3843
+ ]
3844
+ });
3845
+ const newSpaceDoc = {
3846
+ ...rootHandle.docSync(),
3847
+ objects: Object.fromEntries([
3848
+ properties
3849
+ ])
3850
+ };
3851
+ const newRoot = context.repo.create(newSpaceDoc);
3852
+ (0, import_invariant13.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3853
+ F: __dxlog_file14,
3854
+ L: 78,
3855
+ S: void 0,
3856
+ A: [
3857
+ "typeof newRoot.url === 'string' && newRoot.url.length > 0",
3858
+ ""
3859
+ ]
3860
+ });
3861
+ const docLoader = new import_echo_pipeline3.AutomergeDocumentLoaderImpl(context.spaceId, context.repo, context.spaceKey);
3862
+ await docLoader.loadSpaceRootDocHandle(ctx, {
3863
+ rootUrl: newRoot.url
3864
+ });
3865
+ otherObjects.forEach(([key, value]) => {
3866
+ const handle = docLoader.createDocumentForObject(key);
3867
+ handle.change((doc) => {
3868
+ (0, import_util8.assignDeep)(doc, [
3869
+ "objects",
3870
+ key
3871
+ ], value);
3872
+ });
3873
+ });
3874
+ await context.repo.flush();
3875
+ return {
3876
+ newRoot: newRoot.url
3877
+ };
3878
+ }
3879
+ case import_services13.CreateEpochRequest.Migration.MIGRATE_REFERENCES_TO_DXN: {
3880
+ const currentRootUrl = context.currentRoot;
3881
+ const rootHandle = context.repo.find(currentRootUrl);
3882
+ await (0, import_context12.cancelWithContext)(ctx, (0, import_async15.asyncTimeout)(rootHandle.whenReady(), 1e4));
3883
+ (0, import_invariant13.invariant)(rootHandle.docSync(), "Root doc not found", {
3884
+ F: __dxlog_file14,
3885
+ L: 100,
3886
+ S: void 0,
3887
+ A: [
3888
+ "rootHandle.docSync()",
3889
+ "'Root doc not found'"
3890
+ ]
3891
+ });
3892
+ const newRootContent = await (0, import_echo_db.convertLegacySpaceRootDoc)(structuredClone(rootHandle.docSync()));
3893
+ for (const [id, url] of Object.entries(newRootContent.links ?? {})) {
3894
+ const handle = context.repo.find(url);
3895
+ await (0, import_context12.cancelWithContext)(ctx, (0, import_async15.asyncTimeout)(handle.whenReady(), 1e4));
3896
+ (0, import_invariant13.invariant)(handle.docSync(), "Doc not found", {
3897
+ F: __dxlog_file14,
3898
+ L: 107,
3899
+ S: void 0,
3900
+ A: [
3901
+ "handle.docSync()",
3902
+ "'Doc not found'"
3903
+ ]
3904
+ });
3905
+ const newDoc = await (0, import_echo_db.convertLegacyReferences)(structuredClone(handle.docSync()));
3906
+ const migratedDoc = (0, import_echo_db.migrateDocument)(handle.docSync(), newDoc);
3907
+ const newHandle = context.repo.import(import_automerge.next.save(migratedDoc));
3908
+ newRootContent.links[id] = newHandle.url;
3909
+ }
3910
+ const migratedRoot = (0, import_echo_db.migrateDocument)(rootHandle.docSync(), newRootContent);
3911
+ const newRoot = context.repo.import(import_automerge.next.save(migratedRoot));
3912
+ await context.repo.flush();
3913
+ return {
3914
+ newRoot: newRoot.url
3915
+ };
3916
+ }
3917
+ case import_services13.CreateEpochRequest.Migration.REPLACE_AUTOMERGE_ROOT: {
3918
+ (0, import_invariant13.invariant)(context.newAutomergeRoot, void 0, {
3919
+ F: __dxlog_file14,
3920
+ L: 124,
3921
+ S: void 0,
3922
+ A: [
3923
+ "context.newAutomergeRoot",
3924
+ ""
3925
+ ]
3926
+ });
3927
+ await context.repo.flush();
3928
+ return {
3929
+ newRoot: context.newAutomergeRoot
3930
+ };
3931
+ }
3932
+ }
3933
+ return {};
3934
+ };
3935
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
3758
3936
  var DEFAULT_RETRY_TIMEOUT = 1e3;
3759
3937
  var DEFAULT_SUCCESS_DELAY = 1e3;
3760
3938
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
3761
3939
  var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
3762
3940
  var NotarizationPlugin = class {
3763
3941
  constructor() {
3764
- this._ctx = new import_context11.Context();
3765
- this._extensionOpened = new import_async14.Event();
3942
+ this._ctx = new import_context13.Context();
3943
+ this._extensionOpened = new import_async16.Event();
3766
3944
  this._extensions = /* @__PURE__ */ new Set();
3767
- this._processedCredentials = new import_util7.ComplexSet(import_keys11.PublicKey.hash);
3768
- this._processCredentialsTriggers = new import_util7.ComplexMap(import_keys11.PublicKey.hash);
3945
+ this._processedCredentials = new import_util9.ComplexSet(import_keys11.PublicKey.hash);
3946
+ this._processCredentialsTriggers = new import_util9.ComplexMap(import_keys11.PublicKey.hash);
3769
3947
  }
3770
3948
  get hasWriter() {
3771
3949
  return !!this._writer;
@@ -3779,16 +3957,16 @@ var NotarizationPlugin = class {
3779
3957
  * Request credentials to be notarized.
3780
3958
  */
3781
3959
  async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
3782
- (0, import_log12.log)("notarize", {
3960
+ (0, import_log14.log)("notarize", {
3783
3961
  credentials
3784
3962
  }, {
3785
- F: __dxlog_file14,
3963
+ F: __dxlog_file15,
3786
3964
  L: 90,
3787
3965
  S: this,
3788
3966
  C: (f, a) => f(...a)
3789
3967
  });
3790
- (0, import_invariant13.invariant)(credentials.every((credential) => credential.id), "Credentials must have an id", {
3791
- F: __dxlog_file14,
3968
+ (0, import_invariant14.invariant)(credentials.every((credential) => credential.id), "Credentials must have an id", {
3969
+ F: __dxlog_file15,
3792
3970
  L: 91,
3793
3971
  S: this,
3794
3972
  A: [
@@ -3796,13 +3974,13 @@ var NotarizationPlugin = class {
3796
3974
  "'Credentials must have an id'"
3797
3975
  ]
3798
3976
  });
3799
- const errors = new import_async14.Trigger();
3977
+ const errors = new import_async16.Trigger();
3800
3978
  const ctx = this._ctx.derive({
3801
3979
  onError: (err) => {
3802
- import_log12.log.warn("Notarization error", {
3980
+ import_log14.log.warn("Notarization error", {
3803
3981
  err
3804
3982
  }, {
3805
- F: __dxlog_file14,
3983
+ F: __dxlog_file15,
3806
3984
  L: 99,
3807
3985
  S: this,
3808
3986
  C: (f, a) => f(...a)
@@ -3813,23 +3991,23 @@ var NotarizationPlugin = class {
3813
3991
  });
3814
3992
  opCtx?.onDispose(() => ctx.dispose());
3815
3993
  if (timeout !== 0) {
3816
- (0, import_async14.scheduleTask)(ctx, () => {
3817
- import_log12.log.warn("Notarization timeout", {
3994
+ (0, import_async16.scheduleTask)(ctx, () => {
3995
+ import_log14.log.warn("Notarization timeout", {
3818
3996
  timeout,
3819
3997
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
3820
3998
  }, {
3821
- F: __dxlog_file14,
3999
+ F: __dxlog_file15,
3822
4000
  L: 111,
3823
4001
  S: this,
3824
4002
  C: (f, a) => f(...a)
3825
4003
  });
3826
4004
  void ctx.dispose();
3827
- errors.throw(new import_async14.TimeoutError(timeout, "Notarization timed out"));
4005
+ errors.throw(new import_async16.TimeoutError(timeout, "Notarization timed out"));
3828
4006
  }, timeout);
3829
4007
  }
3830
4008
  const allNotarized = Promise.all(credentials.map((credential) => this._waitUntilProcessed(credential.id)));
3831
4009
  const peersTried = /* @__PURE__ */ new Set();
3832
- const notarizeTask = new import_async14.DeferredTask(ctx, async () => {
4010
+ const notarizeTask = new import_async16.DeferredTask(ctx, async () => {
3833
4011
  try {
3834
4012
  if (this._extensions.size === 0) {
3835
4013
  return;
@@ -3838,24 +4016,24 @@ var NotarizationPlugin = class {
3838
4016
  ...this._extensions
3839
4017
  ].find((peer2) => !peersTried.has(peer2));
3840
4018
  if (!peer) {
3841
- import_log12.log.info("Exhausted all peers to notarize with", {
4019
+ import_log14.log.info("Exhausted all peers to notarize with", {
3842
4020
  retryIn: retryTimeout
3843
4021
  }, {
3844
- F: __dxlog_file14,
4022
+ F: __dxlog_file15,
3845
4023
  L: 136,
3846
4024
  S: this,
3847
4025
  C: (f, a) => f(...a)
3848
4026
  });
3849
4027
  peersTried.clear();
3850
- (0, import_async14.scheduleTask)(ctx, () => notarizeTask.schedule(), retryTimeout);
4028
+ (0, import_async16.scheduleTask)(ctx, () => notarizeTask.schedule(), retryTimeout);
3851
4029
  return;
3852
4030
  }
3853
4031
  peersTried.add(peer);
3854
- (0, import_log12.log)("try notarizing", {
4032
+ (0, import_log14.log)("try notarizing", {
3855
4033
  peer: peer.localPeerId,
3856
4034
  credentialId: credentials.map((credential) => credential.id)
3857
4035
  }, {
3858
- F: __dxlog_file14,
4036
+ F: __dxlog_file15,
3859
4037
  L: 143,
3860
4038
  S: this,
3861
4039
  C: (f, a) => f(...a)
@@ -3863,17 +4041,17 @@ var NotarizationPlugin = class {
3863
4041
  await peer.rpc.NotarizationService.notarize({
3864
4042
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
3865
4043
  });
3866
- (0, import_log12.log)("success", void 0, {
3867
- F: __dxlog_file14,
4044
+ (0, import_log14.log)("success", void 0, {
4045
+ F: __dxlog_file15,
3868
4046
  L: 147,
3869
4047
  S: this,
3870
4048
  C: (f, a) => f(...a)
3871
4049
  });
3872
- await (0, import_async14.sleep)(successDelay);
4050
+ await (0, import_async16.sleep)(successDelay);
3873
4051
  } catch (err) {
3874
4052
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
3875
- import_log12.log.info("error notarizing (recoverable)", err, {
3876
- F: __dxlog_file14,
4053
+ import_log14.log.info("error notarizing (recoverable)", err, {
4054
+ F: __dxlog_file15,
3877
4055
  L: 151,
3878
4056
  S: this,
3879
4057
  C: (f, a) => f(...a)
@@ -3886,12 +4064,12 @@ var NotarizationPlugin = class {
3886
4064
  this._extensionOpened.on(ctx, () => notarizeTask.schedule());
3887
4065
  try {
3888
4066
  await Promise.race([
3889
- (0, import_context11.rejectOnDispose)(ctx),
4067
+ (0, import_context13.rejectOnDispose)(ctx),
3890
4068
  allNotarized,
3891
4069
  errors.wait()
3892
4070
  ]);
3893
- (0, import_log12.log)("done", void 0, {
3894
- F: __dxlog_file14,
4071
+ (0, import_log14.log)("done", void 0, {
4072
+ F: __dxlog_file15,
3895
4073
  L: 162,
3896
4074
  S: this,
3897
4075
  C: (f, a) => f(...a)
@@ -3912,8 +4090,8 @@ var NotarizationPlugin = class {
3912
4090
  this._processCredentialsTriggers.delete(credential.id);
3913
4091
  }
3914
4092
  setWriter(writer) {
3915
- (0, import_invariant13.invariant)(!this._writer, "Writer already set.", {
3916
- F: __dxlog_file14,
4093
+ (0, import_invariant14.invariant)(!this._writer, "Writer already set.", {
4094
+ F: __dxlog_file15,
3917
4095
  L: 181,
3918
4096
  S: this,
3919
4097
  A: [
@@ -3927,7 +4105,7 @@ var NotarizationPlugin = class {
3927
4105
  if (this._processedCredentials.has(id)) {
3928
4106
  return;
3929
4107
  }
3930
- await (0, import_util7.entry)(this._processCredentialsTriggers, id).orInsert(new import_async14.Trigger()).value.wait();
4108
+ await (0, import_util9.entry)(this._processCredentialsTriggers, id).orInsert(new import_async16.Trigger()).value.wait();
3931
4109
  }
3932
4110
  /**
3933
4111
  * Requests from other peers to notarize credentials.
@@ -3937,8 +4115,8 @@ var NotarizationPlugin = class {
3937
4115
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
3938
4116
  }
3939
4117
  for (const credential of request.credentials ?? []) {
3940
- (0, import_invariant13.invariant)(credential.id, "Credential must have an id", {
3941
- F: __dxlog_file14,
4118
+ (0, import_invariant14.invariant)(credential.id, "Credential must have an id", {
4119
+ F: __dxlog_file15,
3942
4120
  L: 200,
3943
4121
  S: this,
3944
4122
  A: [
@@ -3955,10 +4133,10 @@ var NotarizationPlugin = class {
3955
4133
  createExtension() {
3956
4134
  const extension = new NotarizationTeleportExtension({
3957
4135
  onOpen: async () => {
3958
- (0, import_log12.log)("extension opened", {
4136
+ (0, import_log14.log)("extension opened", {
3959
4137
  peer: extension.localPeerId
3960
4138
  }, {
3961
- F: __dxlog_file14,
4139
+ F: __dxlog_file15,
3962
4140
  L: 211,
3963
4141
  S: this,
3964
4142
  C: (f, a) => f(...a)
@@ -3967,10 +4145,10 @@ var NotarizationPlugin = class {
3967
4145
  this._extensionOpened.emit();
3968
4146
  },
3969
4147
  onClose: async () => {
3970
- (0, import_log12.log)("extension closed", {
4148
+ (0, import_log14.log)("extension closed", {
3971
4149
  peer: extension.localPeerId
3972
4150
  }, {
3973
- F: __dxlog_file14,
4151
+ F: __dxlog_file15,
3974
4152
  L: 216,
3975
4153
  S: this,
3976
4154
  C: (f, a) => f(...a)
@@ -4022,16 +4200,81 @@ function _ts_decorate4(decorators, target, key, desc) {
4022
4200
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4023
4201
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4024
4202
  }
4025
- var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
4203
+ function _using_ctx() {
4204
+ var _disposeSuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed) {
4205
+ var err = new Error();
4206
+ err.name = "SuppressedError";
4207
+ err.suppressed = suppressed;
4208
+ err.error = error;
4209
+ return err;
4210
+ }, empty = {}, stack = [];
4211
+ function using(isAwait, value) {
4212
+ if (value != null) {
4213
+ if (Object(value) !== value) {
4214
+ throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
4215
+ }
4216
+ if (isAwait) {
4217
+ var dispose = value[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")];
4218
+ }
4219
+ if (dispose == null) {
4220
+ dispose = value[Symbol.dispose || Symbol.for("Symbol.dispose")];
4221
+ }
4222
+ if (typeof dispose !== "function") {
4223
+ throw new TypeError(`Property [Symbol.dispose] is not a function.`);
4224
+ }
4225
+ stack.push({
4226
+ v: value,
4227
+ d: dispose,
4228
+ a: isAwait
4229
+ });
4230
+ } else if (isAwait) {
4231
+ stack.push({
4232
+ d: value,
4233
+ a: isAwait
4234
+ });
4235
+ }
4236
+ return value;
4237
+ }
4238
+ return {
4239
+ e: empty,
4240
+ u: using.bind(null, false),
4241
+ a: using.bind(null, true),
4242
+ d: function() {
4243
+ var error = this.e;
4244
+ function next() {
4245
+ while (resource = stack.pop()) {
4246
+ try {
4247
+ var resource, disposalResult = resource.d && resource.d.call(resource.v);
4248
+ if (resource.a) {
4249
+ return Promise.resolve(disposalResult).then(next, err);
4250
+ }
4251
+ } catch (e) {
4252
+ return err(e);
4253
+ }
4254
+ }
4255
+ if (error !== empty)
4256
+ throw error;
4257
+ }
4258
+ function err(e) {
4259
+ error = error !== empty ? new _disposeSuppressedError(error, e) : e;
4260
+ return next();
4261
+ }
4262
+ return next();
4263
+ }
4264
+ };
4265
+ }
4266
+ var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
4026
4267
  var DataSpace = class {
4027
4268
  constructor(params) {
4028
4269
  this._ctx = new import_context10.Context();
4029
4270
  this._notarizationPlugin = new NotarizationPlugin();
4030
4271
  this._cache = void 0;
4031
4272
  this._automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
4273
+ this._epochProcessingMutex = new import_async13.Mutex();
4032
4274
  this._state = import_services12.SpaceState.CLOSED;
4275
+ this._databaseRoot = null;
4033
4276
  this.error = void 0;
4034
- this.stateUpdate = new import_async12.Event();
4277
+ this.stateUpdate = new import_async13.Event();
4035
4278
  this.metrics = {};
4036
4279
  this._inner = params.inner;
4037
4280
  this._inner.stateUpdate.on(this._ctx, () => this.stateUpdate.emit());
@@ -4044,17 +4287,17 @@ var DataSpace = class {
4044
4287
  this._callbacks = params.callbacks ?? {};
4045
4288
  this._echoHost = params.echoHost;
4046
4289
  this.authVerifier = new TrustedKeySetAuthVerifier({
4047
- trustedKeysProvider: () => new import_util6.ComplexSet(import_keys10.PublicKey.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => member.role !== import_credentials13.SpaceMember.Role.REMOVED).map((member) => member.key)),
4290
+ trustedKeysProvider: () => new import_util7.ComplexSet(import_keys10.PublicKey.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => member.role !== import_credentials13.SpaceMember.Role.REMOVED).map((member) => member.key)),
4048
4291
  update: this._inner.stateUpdate,
4049
4292
  authTimeout: import_client_protocol4.AUTH_TIMEOUT
4050
4293
  });
4051
4294
  this._cache = params.cache;
4052
4295
  this._state = params.initialState;
4053
- (0, import_log11.log)("new state", {
4296
+ (0, import_log12.log)("new state", {
4054
4297
  state: import_services12.SpaceState[this._state]
4055
4298
  }, {
4056
- F: __dxlog_file15,
4057
- L: 143,
4299
+ F: __dxlog_file16,
4300
+ L: 146,
4058
4301
  S: this,
4059
4302
  C: (f, a) => f(...a)
4060
4303
  });
@@ -4087,6 +4330,9 @@ var DataSpace = class {
4087
4330
  get automergeSpaceState() {
4088
4331
  return this._automergeSpaceState;
4089
4332
  }
4333
+ get databaseRoot() {
4334
+ return this._databaseRoot;
4335
+ }
4090
4336
  get _automergeInfo() {
4091
4337
  return {
4092
4338
  rootUrl: this._automergeSpaceState.rootUrl,
@@ -4103,14 +4349,15 @@ var DataSpace = class {
4103
4349
  await this._gossip.open();
4104
4350
  await this._notarizationPlugin.open();
4105
4351
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
4352
+ await this._automergeSpaceState.open();
4106
4353
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
4107
4354
  await this._inner.open(new import_context10.Context());
4108
4355
  this._state = import_services12.SpaceState.CONTROL_ONLY;
4109
- (0, import_log11.log)("new state", {
4356
+ (0, import_log12.log)("new state", {
4110
4357
  state: import_services12.SpaceState[this._state]
4111
4358
  }, {
4112
- F: __dxlog_file15,
4113
- L: 209,
4359
+ F: __dxlog_file16,
4360
+ L: 217,
4114
4361
  S: this,
4115
4362
  C: (f, a) => f(...a)
4116
4363
  });
@@ -4124,11 +4371,11 @@ var DataSpace = class {
4124
4371
  async _close() {
4125
4372
  await this._callbacks.beforeClose?.();
4126
4373
  this._state = import_services12.SpaceState.CLOSED;
4127
- (0, import_log11.log)("new state", {
4374
+ (0, import_log12.log)("new state", {
4128
4375
  state: import_services12.SpaceState[this._state]
4129
4376
  }, {
4130
- F: __dxlog_file15,
4131
- L: 223,
4377
+ F: __dxlog_file16,
4378
+ L: 231,
4132
4379
  S: this,
4133
4380
  C: (f, a) => f(...a)
4134
4381
  });
@@ -4137,6 +4384,7 @@ var DataSpace = class {
4137
4384
  await this.authVerifier.close();
4138
4385
  await this._inner.close();
4139
4386
  await this._inner.spaceState.removeCredentialProcessor(this._automergeSpaceState);
4387
+ await this._automergeSpaceState.close();
4140
4388
  await this._inner.spaceState.removeCredentialProcessor(this._notarizationPlugin);
4141
4389
  await this._notarizationPlugin.close();
4142
4390
  await this._presence.close();
@@ -4152,32 +4400,32 @@ var DataSpace = class {
4152
4400
  * Initialize the data pipeline in a separate task.
4153
4401
  */
4154
4402
  initializeDataPipelineAsync() {
4155
- (0, import_async12.scheduleTask)(this._ctx, async () => {
4403
+ (0, import_async13.scheduleTask)(this._ctx, async () => {
4156
4404
  try {
4157
4405
  this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
4158
4406
  await this.initializeDataPipeline();
4159
4407
  } catch (err) {
4160
4408
  if (err instanceof import_protocols9.CancelledError || err instanceof import_context10.ContextDisposedError) {
4161
- (0, import_log11.log)("data pipeline initialization cancelled", err, {
4162
- F: __dxlog_file15,
4163
- L: 256,
4409
+ (0, import_log12.log)("data pipeline initialization cancelled", err, {
4410
+ F: __dxlog_file16,
4411
+ L: 265,
4164
4412
  S: this,
4165
4413
  C: (f, a) => f(...a)
4166
4414
  });
4167
4415
  return;
4168
4416
  }
4169
- import_log11.log.error("Error initializing data pipeline", err, {
4170
- F: __dxlog_file15,
4171
- L: 260,
4417
+ import_log12.log.error("Error initializing data pipeline", err, {
4418
+ F: __dxlog_file16,
4419
+ L: 269,
4172
4420
  S: this,
4173
4421
  C: (f, a) => f(...a)
4174
4422
  });
4175
4423
  this._state = import_services12.SpaceState.ERROR;
4176
- (0, import_log11.log)("new state", {
4424
+ (0, import_log12.log)("new state", {
4177
4425
  state: import_services12.SpaceState[this._state]
4178
4426
  }, {
4179
- F: __dxlog_file15,
4180
- L: 262,
4427
+ F: __dxlog_file16,
4428
+ L: 271,
4181
4429
  S: this,
4182
4430
  C: (f, a) => f(...a)
4183
4431
  });
@@ -4193,31 +4441,28 @@ var DataSpace = class {
4193
4441
  throw new import_protocols9.SystemError("Invalid operation");
4194
4442
  }
4195
4443
  this._state = import_services12.SpaceState.INITIALIZING;
4196
- (0, import_log11.log)("new state", {
4444
+ (0, import_log12.log)("new state", {
4197
4445
  state: import_services12.SpaceState[this._state]
4198
4446
  }, {
4199
- F: __dxlog_file15,
4200
- L: 278,
4447
+ F: __dxlog_file16,
4448
+ L: 287,
4201
4449
  S: this,
4202
4450
  C: (f, a) => f(...a)
4203
4451
  });
4204
4452
  await this._initializeAndReadControlPipeline();
4205
- await (0, import_async12.sleep)(1);
4453
+ await (0, import_async13.sleep)(1);
4454
+ const ready = this.stateUpdate.waitForCondition(() => this._state === import_services12.SpaceState.READY);
4206
4455
  this._automergeSpaceState.startProcessingRootDocs();
4207
- await (0, import_context10.cancelWithContext)(this._ctx, this.automergeSpaceState.ensureEpochInitialized());
4208
- (0, import_log11.log)("data pipeline ready", void 0, {
4209
- F: __dxlog_file15,
4210
- L: 290,
4211
- S: this,
4212
- C: (f, a) => f(...a)
4213
- });
4456
+ await ready;
4457
+ }
4458
+ async _enterReadyState() {
4214
4459
  await this._callbacks.beforeReady?.();
4215
4460
  this._state = import_services12.SpaceState.READY;
4216
- (0, import_log11.log)("new state", {
4461
+ (0, import_log12.log)("new state", {
4217
4462
  state: import_services12.SpaceState[this._state]
4218
4463
  }, {
4219
- F: __dxlog_file15,
4220
- L: 294,
4464
+ F: __dxlog_file16,
4465
+ L: 306,
4221
4466
  S: this,
4222
4467
  C: (f, a) => f(...a)
4223
4468
  });
@@ -4231,9 +4476,9 @@ var DataSpace = class {
4231
4476
  });
4232
4477
  this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
4233
4478
  await this._createWritableFeeds();
4234
- (0, import_log11.log)("writable feeds created", void 0, {
4235
- F: __dxlog_file15,
4236
- L: 310,
4479
+ (0, import_log12.log)("writable feeds created", void 0, {
4480
+ F: __dxlog_file16,
4481
+ L: 322,
4237
4482
  S: this,
4238
4483
  C: (f, a) => f(...a)
4239
4484
  });
@@ -4291,12 +4536,12 @@ var DataSpace = class {
4291
4536
  }
4292
4537
  }
4293
4538
  _onNewAutomergeRoot(rootUrl) {
4294
- (0, import_log11.log)("loading automerge root doc for space", {
4539
+ (0, import_log12.log)("loading automerge root doc for space", {
4295
4540
  space: this.key,
4296
4541
  rootUrl
4297
4542
  }, {
4298
- F: __dxlog_file15,
4299
- L: 376,
4543
+ F: __dxlog_file16,
4544
+ L: 388,
4300
4545
  S: this,
4301
4546
  C: (f, a) => f(...a)
4302
4547
  });
@@ -4304,44 +4549,52 @@ var DataSpace = class {
4304
4549
  const handle = this._echoHost.automergeRepo.find(rootUrl);
4305
4550
  queueMicrotask(async () => {
4306
4551
  try {
4307
- await (0, import_debug3.warnAfterTimeout)(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
4308
- await (0, import_context10.cancelWithContext)(this._ctx, handle.whenReady());
4309
- });
4310
- if (this._ctx.disposed) {
4311
- return;
4312
- }
4313
- const doc = handle.docSync() ?? (0, import_invariant12.failedInvariant)();
4314
- if (!doc.access?.spaceKey) {
4315
- handle.change((doc2) => {
4316
- doc2.access = {
4317
- spaceKey: this.key.toHex()
4318
- };
4319
- });
4320
- }
4321
- if (!this._echoHost.roots.has(handle.documentId)) {
4322
- await this._echoHost.openSpaceRoot(handle.url);
4323
- } else {
4324
- import_log11.log.warn("echo database root already exists", {
4325
- space: this.key,
4326
- rootUrl
4327
- }, {
4328
- F: __dxlog_file15,
4329
- L: 403,
4330
- S: this,
4331
- C: (f, a) => f(...a)
4552
+ try {
4553
+ var _usingCtx = _using_ctx();
4554
+ await (0, import_debug3.warnAfterTimeout)(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
4555
+ await (0, import_context10.cancelWithContext)(this._ctx, handle.whenReady());
4332
4556
  });
4557
+ if (this._ctx.disposed) {
4558
+ return;
4559
+ }
4560
+ const _guard = (
4561
+ // Ensure only one root is processed at a time.
4562
+ _usingCtx.u(await this._epochProcessingMutex.acquire())
4563
+ );
4564
+ const doc = handle.docSync() ?? (0, import_invariant12.failedInvariant)();
4565
+ if (!doc.access?.spaceKey) {
4566
+ handle.change((doc2) => {
4567
+ doc2.access = {
4568
+ spaceKey: this.key.toHex()
4569
+ };
4570
+ });
4571
+ }
4572
+ const root = await this._echoHost.openSpaceRoot(handle.url);
4573
+ this._databaseRoot = root;
4574
+ if (root.getVersion() !== import_echo_protocol.SpaceDocVersion.CURRENT) {
4575
+ this._state = import_services12.SpaceState.REQUIRES_MIGRATION;
4576
+ this.stateUpdate.emit();
4577
+ } else {
4578
+ if (this._state !== import_services12.SpaceState.READY) {
4579
+ await this._enterReadyState();
4580
+ }
4581
+ }
4582
+ } catch (_) {
4583
+ _usingCtx.e = _;
4584
+ } finally {
4585
+ _usingCtx.d();
4333
4586
  }
4334
4587
  } catch (err) {
4335
4588
  if (err instanceof import_context10.ContextDisposedError) {
4336
4589
  return;
4337
4590
  }
4338
- import_log11.log.warn("error loading automerge root doc", {
4591
+ import_log12.log.warn("error loading automerge root doc", {
4339
4592
  space: this.key,
4340
4593
  rootUrl,
4341
4594
  err
4342
4595
  }, {
4343
- F: __dxlog_file15,
4344
- L: 409,
4596
+ F: __dxlog_file16,
4597
+ L: 431,
4345
4598
  S: this,
4346
4599
  C: (f, a) => f(...a)
4347
4600
  });
@@ -4364,148 +4617,34 @@ var DataSpace = class {
4364
4617
  });
4365
4618
  }
4366
4619
  async createEpoch(options) {
4367
- let epoch;
4368
- switch (options?.migration) {
4369
- case void 0:
4370
- case import_services12.CreateEpochRequest.Migration.NONE:
4371
- {
4372
- epoch = {
4373
- previousId: this._automergeSpaceState.lastEpoch?.id,
4374
- number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
4375
- timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new import_timeframe3.Timeframe(),
4376
- automergeRoot: this._automergeSpaceState.lastEpoch?.subject.assertion?.automergeRoot
4377
- };
4378
- }
4379
- break;
4380
- case import_services12.CreateEpochRequest.Migration.INIT_AUTOMERGE:
4381
- {
4382
- const document = this._echoHost.automergeRepo.create();
4383
- epoch = {
4384
- previousId: this._automergeSpaceState.lastEpoch?.id,
4385
- number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
4386
- timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new import_timeframe3.Timeframe(),
4387
- automergeRoot: document.url
4388
- };
4389
- }
4390
- break;
4391
- case import_services12.CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY:
4392
- {
4393
- const currentRootUrl = this._automergeSpaceState.rootUrl;
4394
- const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
4395
- await (0, import_context10.cancelWithContext)(this._ctx, (0, import_async12.asyncTimeout)(rootHandle.whenReady(), 1e4));
4396
- const newRoot = this._echoHost.automergeRepo.create(rootHandle.docSync());
4397
- await this._echoHost.automergeRepo.flush([
4398
- newRoot.documentId
4399
- ]);
4400
- (0, import_invariant12.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
4401
- F: __dxlog_file15,
4402
- L: 460,
4403
- S: this,
4404
- A: [
4405
- "typeof newRoot.url === 'string' && newRoot.url.length > 0",
4406
- ""
4407
- ]
4408
- });
4409
- epoch = {
4410
- previousId: this._automergeSpaceState.lastEpoch?.id,
4411
- number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
4412
- timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new import_timeframe3.Timeframe(),
4413
- automergeRoot: newRoot.url
4414
- };
4415
- }
4416
- break;
4417
- case import_services12.CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT:
4418
- {
4419
- import_log11.log.info("Fragmenting", void 0, {
4420
- F: __dxlog_file15,
4421
- L: 472,
4422
- S: this,
4423
- C: (f, a) => f(...a)
4424
- });
4425
- const currentRootUrl = this._automergeSpaceState.rootUrl;
4426
- const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
4427
- await (0, import_context10.cancelWithContext)(this._ctx, (0, import_async12.asyncTimeout)(rootHandle.whenReady(), 1e4));
4428
- const objects = Object.entries(rootHandle.docSync().objects);
4429
- const properties = findPropertiesObject(rootHandle.docSync());
4430
- const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
4431
- (0, import_invariant12.invariant)(properties, "Properties not found", {
4432
- F: __dxlog_file15,
4433
- L: 482,
4434
- S: this,
4435
- A: [
4436
- "properties",
4437
- "'Properties not found'"
4438
- ]
4439
- });
4440
- const newSpaceDoc = {
4441
- ...rootHandle.docSync(),
4442
- objects: Object.fromEntries([
4443
- properties
4444
- ])
4445
- };
4446
- const newRoot = this._echoHost.automergeRepo.create(newSpaceDoc);
4447
- (0, import_invariant12.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
4448
- F: __dxlog_file15,
4449
- L: 487,
4450
- S: this,
4451
- A: [
4452
- "typeof newRoot.url === 'string' && newRoot.url.length > 0",
4453
- ""
4454
- ]
4455
- });
4456
- const docLoader = new import_echo_pipeline2.AutomergeDocumentLoaderImpl(await (0, import_echo_pipeline2.createIdFromSpaceKey)(this.key), this._echoHost.automergeRepo, this.key);
4457
- await docLoader.loadSpaceRootDocHandle(this._ctx, {
4458
- rootUrl: newRoot.url
4459
- });
4460
- otherObjects.forEach(([key, value]) => {
4461
- const handle = docLoader.createDocumentForObject(key);
4462
- handle.change((doc) => {
4463
- (0, import_util6.assignDeep)(doc, [
4464
- "objects",
4465
- key
4466
- ], value);
4467
- });
4468
- });
4469
- epoch = {
4470
- previousId: this._automergeSpaceState.lastEpoch?.id,
4471
- number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
4472
- timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new import_timeframe3.Timeframe(),
4473
- automergeRoot: newRoot.url
4474
- };
4475
- }
4476
- break;
4477
- case import_services12.CreateEpochRequest.Migration.REPLACE_AUTOMERGE_ROOT:
4478
- {
4479
- (0, import_invariant12.invariant)(options.newAutomergeRoot, void 0, {
4480
- F: __dxlog_file15,
4481
- L: 517,
4482
- S: this,
4483
- A: [
4484
- "options.newAutomergeRoot",
4485
- ""
4486
- ]
4487
- });
4488
- epoch = {
4489
- previousId: this._automergeSpaceState.lastEpoch?.id,
4490
- number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
4491
- timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new import_timeframe3.Timeframe(),
4492
- automergeRoot: options.newAutomergeRoot
4493
- };
4494
- }
4495
- break;
4496
- }
4497
- if (!epoch) {
4498
- return;
4620
+ const ctx = this._ctx.derive();
4621
+ if (!options?.migration) {
4622
+ return null;
4499
4623
  }
4624
+ const { newRoot } = await runEpochMigration(ctx, {
4625
+ repo: this._echoHost.automergeRepo,
4626
+ spaceId: this.id,
4627
+ spaceKey: this.key,
4628
+ migration: options.migration,
4629
+ currentRoot: this._automergeSpaceState.rootUrl ?? null,
4630
+ newAutomergeRoot: options.newAutomergeRoot
4631
+ });
4632
+ const epoch = {
4633
+ previousId: this._automergeSpaceState.lastEpoch?.id,
4634
+ number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
4635
+ timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new import_timeframe3.Timeframe(),
4636
+ automergeRoot: newRoot ?? this._automergeSpaceState.rootUrl
4637
+ };
4638
+ const credential = await this._signingContext.credentialSigner.createCredential({
4639
+ subject: this.key,
4640
+ assertion: {
4641
+ "@type": "dxos.halo.credentials.Epoch",
4642
+ ...epoch
4643
+ }
4644
+ });
4500
4645
  const receipt = await this.inner.controlPipeline.writer.write({
4501
4646
  credential: {
4502
- credential: await this._signingContext.credentialSigner.createCredential({
4503
- subject: this.key,
4504
- assertion: {
4505
- "@type": "dxos.halo.credentials.Epoch",
4506
- ...epoch
4507
- }
4508
- })
4647
+ credential
4509
4648
  }
4510
4649
  });
4511
4650
  await this.inner.controlPipeline.state.waitUntilTimeframe(new import_timeframe3.Timeframe([
@@ -4515,6 +4654,7 @@ var DataSpace = class {
4515
4654
  ]
4516
4655
  ]));
4517
4656
  await this._echoHost.updateIndexes();
4657
+ return credential;
4518
4658
  }
4519
4659
  async activate() {
4520
4660
  if (![
@@ -4536,11 +4676,11 @@ var DataSpace = class {
4536
4676
  await this._close();
4537
4677
  }
4538
4678
  this._state = import_services12.SpaceState.INACTIVE;
4539
- (0, import_log11.log)("new state", {
4679
+ (0, import_log12.log)("new state", {
4540
4680
  state: import_services12.SpaceState[this._state]
4541
4681
  }, {
4542
- F: __dxlog_file15,
4543
- L: 571,
4682
+ F: __dxlog_file16,
4683
+ L: 512,
4544
4684
  S: this,
4545
4685
  C: (f, a) => f(...a)
4546
4686
  });
@@ -4567,10 +4707,10 @@ _ts_decorate4([
4567
4707
  })
4568
4708
  ], DataSpace.prototype, "_automergeInfo", null);
4569
4709
  _ts_decorate4([
4570
- import_async12.synchronized
4710
+ import_async13.synchronized
4571
4711
  ], DataSpace.prototype, "open", null);
4572
4712
  _ts_decorate4([
4573
- import_async12.synchronized
4713
+ import_async13.synchronized
4574
4714
  ], DataSpace.prototype, "close", null);
4575
4715
  _ts_decorate4([
4576
4716
  import_tracing5.trace.span({
@@ -4586,27 +4726,15 @@ _ts_decorate4([
4586
4726
  (0, import_debug3.timed)(1e4)
4587
4727
  ], DataSpace.prototype, "_createWritableFeeds", null);
4588
4728
  _ts_decorate4([
4589
- import_async12.synchronized
4729
+ import_async13.synchronized
4590
4730
  ], DataSpace.prototype, "activate", null);
4591
4731
  _ts_decorate4([
4592
- import_async12.synchronized
4732
+ import_async13.synchronized
4593
4733
  ], DataSpace.prototype, "deactivate", null);
4594
4734
  DataSpace = _ts_decorate4([
4595
- (0, import_async12.trackLeaks)("open", "close"),
4735
+ (0, import_async13.trackLeaks)("open", "close"),
4596
4736
  import_tracing5.trace.resource()
4597
4737
  ], DataSpace);
4598
- var findPropertiesObject = (spaceDoc) => {
4599
- for (const id in spaceDoc.objects ?? {}) {
4600
- const obj = spaceDoc.objects[id];
4601
- if (obj.system.type?.itemId === import_echo_schema.TYPE_PROPERTIES) {
4602
- return [
4603
- id,
4604
- obj
4605
- ];
4606
- }
4607
- }
4608
- return void 0;
4609
- };
4610
4738
  var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
4611
4739
  const credentials = [
4612
4740
  await (0, import_credentials17.createCredential)({
@@ -4681,7 +4809,7 @@ function _ts_decorate5(decorators, target, key, desc) {
4681
4809
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4682
4810
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4683
4811
  }
4684
- var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
4812
+ var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
4685
4813
  var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
4686
4814
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
4687
4815
  var DEFAULT_SPACE_KEY = "__DEFAULT__";
@@ -4695,9 +4823,9 @@ var DataSpaceManager = class {
4695
4823
  this._echoHost = _echoHost;
4696
4824
  this._invitationsManager = _invitationsManager;
4697
4825
  this._params = _params;
4698
- this._ctx = new import_context12.Context();
4699
- this.updated = new import_async15.Event();
4700
- this._spaces = new import_util8.ComplexMap(import_keys12.PublicKey.hash);
4826
+ this._ctx = new import_context14.Context();
4827
+ this.updated = new import_async17.Event();
4828
+ this._spaces = new import_util10.ComplexMap(import_keys12.PublicKey.hash);
4701
4829
  this._isOpen = false;
4702
4830
  this._instanceId = import_keys12.PublicKey.random().toHex();
4703
4831
  import_tracing6.trace.diagnostic({
@@ -4708,10 +4836,10 @@ var DataSpaceManager = class {
4708
4836
  const rootUrl = space.automergeSpaceState.rootUrl;
4709
4837
  const rootHandle = rootUrl ? this._echoHost.automergeRepo.find(rootUrl) : void 0;
4710
4838
  const rootDoc = rootHandle?.docSync();
4711
- const properties = rootDoc && findPropertiesObject(rootDoc);
4839
+ const properties = rootDoc && (0, import_echo_db2.findInlineObjectOfType)(rootDoc, import_echo_schema2.TYPE_PROPERTIES);
4712
4840
  return {
4713
4841
  key: space.key.toHex(),
4714
- state: import_services13.SpaceState[space.state],
4842
+ state: import_services14.SpaceState[space.state],
4715
4843
  name: properties?.[1].data.name ?? null,
4716
4844
  inlineObjects: rootDoc ? Object.keys(rootDoc.objects ?? {}).length : null,
4717
4845
  linkedObjects: rootDoc ? Object.keys(rootDoc.links ?? {}).length : null,
@@ -4728,46 +4856,46 @@ var DataSpaceManager = class {
4728
4856
  return this._spaces;
4729
4857
  }
4730
4858
  async open() {
4731
- (0, import_log13.log)("open", void 0, {
4732
- F: __dxlog_file16,
4733
- L: 140,
4859
+ (0, import_log15.log)("open", void 0, {
4860
+ F: __dxlog_file17,
4861
+ L: 146,
4734
4862
  S: this,
4735
4863
  C: (f, a) => f(...a)
4736
4864
  });
4737
- import_log13.log.trace("dxos.echo.data-space-manager.open", import_protocols11.trace.begin({
4865
+ import_log15.log.trace("dxos.echo.data-space-manager.open", import_protocols11.trace.begin({
4738
4866
  id: this._instanceId
4739
4867
  }), {
4740
- F: __dxlog_file16,
4741
- L: 141,
4868
+ F: __dxlog_file17,
4869
+ L: 147,
4742
4870
  S: this,
4743
4871
  C: (f, a) => f(...a)
4744
4872
  });
4745
- (0, import_log13.log)("metadata loaded", {
4873
+ (0, import_log15.log)("metadata loaded", {
4746
4874
  spaces: this._metadataStore.spaces.length
4747
4875
  }, {
4748
- F: __dxlog_file16,
4749
- L: 142,
4876
+ F: __dxlog_file17,
4877
+ L: 148,
4750
4878
  S: this,
4751
4879
  C: (f, a) => f(...a)
4752
4880
  });
4753
- await (0, import_util8.forEachAsync)(this._metadataStore.spaces, async (spaceMetadata) => {
4881
+ await (0, import_util10.forEachAsync)(this._metadataStore.spaces, async (spaceMetadata) => {
4754
4882
  try {
4755
- (0, import_log13.log)("load space", {
4883
+ (0, import_log15.log)("load space", {
4756
4884
  spaceMetadata
4757
4885
  }, {
4758
- F: __dxlog_file16,
4759
- L: 146,
4886
+ F: __dxlog_file17,
4887
+ L: 152,
4760
4888
  S: this,
4761
4889
  C: (f, a) => f(...a)
4762
4890
  });
4763
4891
  await this._constructSpace(spaceMetadata);
4764
4892
  } catch (err) {
4765
- import_log13.log.error("Error loading space", {
4893
+ import_log15.log.error("Error loading space", {
4766
4894
  spaceMetadata,
4767
4895
  err
4768
4896
  }, {
4769
- F: __dxlog_file16,
4770
- L: 149,
4897
+ F: __dxlog_file17,
4898
+ L: 155,
4771
4899
  S: this,
4772
4900
  C: (f, a) => f(...a)
4773
4901
  });
@@ -4775,19 +4903,19 @@ var DataSpaceManager = class {
4775
4903
  });
4776
4904
  this._isOpen = true;
4777
4905
  this.updated.emit();
4778
- import_log13.log.trace("dxos.echo.data-space-manager.open", import_protocols11.trace.end({
4906
+ import_log15.log.trace("dxos.echo.data-space-manager.open", import_protocols11.trace.end({
4779
4907
  id: this._instanceId
4780
4908
  }), {
4781
- F: __dxlog_file16,
4782
- L: 156,
4909
+ F: __dxlog_file17,
4910
+ L: 162,
4783
4911
  S: this,
4784
4912
  C: (f, a) => f(...a)
4785
4913
  });
4786
4914
  }
4787
4915
  async close() {
4788
- (0, import_log13.log)("close", void 0, {
4789
- F: __dxlog_file16,
4790
- L: 161,
4916
+ (0, import_log15.log)("close", void 0, {
4917
+ F: __dxlog_file17,
4918
+ L: 167,
4791
4919
  S: this,
4792
4920
  C: (f, a) => f(...a)
4793
4921
  });
@@ -4802,9 +4930,9 @@ var DataSpaceManager = class {
4802
4930
  * Creates a new space writing the genesis credentials to the control feed.
4803
4931
  */
4804
4932
  async createSpace() {
4805
- (0, import_invariant14.invariant)(this._isOpen, "Not open.", {
4806
- F: __dxlog_file16,
4807
- L: 175,
4933
+ (0, import_invariant15.invariant)(this._isOpen, "Not open.", {
4934
+ F: __dxlog_file17,
4935
+ L: 181,
4808
4936
  S: this,
4809
4937
  A: [
4810
4938
  "this._isOpen",
@@ -4819,13 +4947,13 @@ var DataSpaceManager = class {
4819
4947
  genesisFeedKey: controlFeedKey,
4820
4948
  controlFeedKey,
4821
4949
  dataFeedKey,
4822
- state: import_services13.SpaceState.ACTIVE
4950
+ state: import_services14.SpaceState.ACTIVE
4823
4951
  };
4824
- (0, import_log13.log)("creating space...", {
4952
+ (0, import_log15.log)("creating space...", {
4825
4953
  spaceKey
4826
4954
  }, {
4827
- F: __dxlog_file16,
4828
- L: 187,
4955
+ F: __dxlog_file17,
4956
+ L: 193,
4829
4957
  S: this,
4830
4958
  C: (f, a) => f(...a)
4831
4959
  });
@@ -4835,9 +4963,9 @@ var DataSpaceManager = class {
4835
4963
  const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, root.url);
4836
4964
  await this._metadataStore.addSpace(metadata);
4837
4965
  const memberCredential = credentials[1];
4838
- (0, import_invariant14.invariant)((0, import_credentials15.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4839
- F: __dxlog_file16,
4840
- L: 197,
4966
+ (0, import_invariant15.invariant)((0, import_credentials15.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4967
+ F: __dxlog_file17,
4968
+ L: 203,
4841
4969
  S: this,
4842
4970
  A: [
4843
4971
  "getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -4850,16 +4978,38 @@ var DataSpaceManager = class {
4850
4978
  return space;
4851
4979
  }
4852
4980
  async isDefaultSpace(space) {
4853
- const rootDoc = await this._getSpaceRootDocument(space);
4854
- const [_, properties] = findPropertiesObject(rootDoc.docSync()) ?? [];
4855
- return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
4981
+ if (!space.databaseRoot) {
4982
+ return false;
4983
+ }
4984
+ switch (space.databaseRoot.getVersion()) {
4985
+ case import_echo_protocol2.SpaceDocVersion.CURRENT: {
4986
+ const [_, properties] = (0, import_echo_db2.findInlineObjectOfType)(space.databaseRoot.docSync(), import_echo_schema2.TYPE_PROPERTIES) ?? [];
4987
+ return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
4988
+ }
4989
+ case import_echo_protocol2.SpaceDocVersion.LEGACY: {
4990
+ const convertedDoc = await (0, import_echo_db2.convertLegacyReferences)(space.databaseRoot.docSync());
4991
+ const [_, properties] = (0, import_echo_db2.findInlineObjectOfType)(convertedDoc, import_echo_protocol2.LEGACY_TYPE_PROPERTIES) ?? [];
4992
+ return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
4993
+ }
4994
+ default:
4995
+ import_log15.log.warn("unknown space version", {
4996
+ version: space.databaseRoot.getVersion(),
4997
+ spaceId: space.id
4998
+ }, {
4999
+ F: __dxlog_file17,
5000
+ L: 228,
5001
+ S: this,
5002
+ C: (f, a) => f(...a)
5003
+ });
5004
+ return false;
5005
+ }
4856
5006
  }
4857
5007
  async createDefaultSpace() {
4858
5008
  const space = await this.createSpace();
4859
5009
  const document = await this._getSpaceRootDocument(space);
4860
5010
  const properties = {
4861
5011
  system: {
4862
- type: (0, import_echo_protocol.encodeReference)((0, import_echo_schema2.getTypeReference)(import_client_protocol5.PropertiesType))
5012
+ type: (0, import_echo_protocol2.encodeReference)((0, import_echo_schema2.getTypeReference)(import_client_protocol5.PropertiesType))
4863
5013
  },
4864
5014
  data: {
4865
5015
  [DEFAULT_SPACE_KEY]: this._signingContext.identityKey.toHex()
@@ -4870,7 +5020,7 @@ var DataSpaceManager = class {
4870
5020
  };
4871
5021
  const propertiesId = (0, import_echo_schema2.generateEchoId)();
4872
5022
  document.change((doc) => {
4873
- (0, import_util8.assignDeep)(doc, [
5023
+ (0, import_util10.assignDeep)(doc, [
4874
5024
  "objects",
4875
5025
  propertiesId
4876
5026
  ], properties);
@@ -4880,9 +5030,9 @@ var DataSpaceManager = class {
4880
5030
  }
4881
5031
  async _getSpaceRootDocument(space) {
4882
5032
  const automergeIndex = space.automergeSpaceState.rootUrl;
4883
- (0, import_invariant14.invariant)(automergeIndex, void 0, {
4884
- F: __dxlog_file16,
4885
- L: 240,
5033
+ (0, import_invariant15.invariant)(automergeIndex, void 0, {
5034
+ F: __dxlog_file17,
5035
+ L: 261,
4886
5036
  S: this,
4887
5037
  A: [
4888
5038
  "automergeIndex",
@@ -4895,26 +5045,26 @@ var DataSpaceManager = class {
4895
5045
  }
4896
5046
  // TODO(burdon): Rename join space.
4897
5047
  async acceptSpace(opts) {
4898
- (0, import_log13.log)("accept space", {
5048
+ (0, import_log15.log)("accept space", {
4899
5049
  opts
4900
5050
  }, {
4901
- F: __dxlog_file16,
4902
- L: 249,
5051
+ F: __dxlog_file17,
5052
+ L: 270,
4903
5053
  S: this,
4904
5054
  C: (f, a) => f(...a)
4905
5055
  });
4906
- (0, import_invariant14.invariant)(this._isOpen, "Not open.", {
4907
- F: __dxlog_file16,
4908
- L: 250,
5056
+ (0, import_invariant15.invariant)(this._isOpen, "Not open.", {
5057
+ F: __dxlog_file17,
5058
+ L: 271,
4909
5059
  S: this,
4910
5060
  A: [
4911
5061
  "this._isOpen",
4912
5062
  "'Not open.'"
4913
5063
  ]
4914
5064
  });
4915
- (0, import_invariant14.invariant)(!this._spaces.has(opts.spaceKey), "Space already exists.", {
4916
- F: __dxlog_file16,
4917
- L: 251,
5065
+ (0, import_invariant15.invariant)(!this._spaces.has(opts.spaceKey), "Space already exists.", {
5066
+ F: __dxlog_file17,
5067
+ L: 272,
4918
5068
  S: this,
4919
5069
  A: [
4920
5070
  "!this._spaces.has(opts.spaceKey)",
@@ -4940,17 +5090,17 @@ var DataSpaceManager = class {
4940
5090
  * TODO(dmaretskyi): Consider removing.
4941
5091
  */
4942
5092
  async waitUntilSpaceReady(spaceKey) {
4943
- await (0, import_context12.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
5093
+ await (0, import_context14.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
4944
5094
  const space = this._spaces.get(spaceKey);
4945
- return !!space && space.state === import_services13.SpaceState.READY;
5095
+ return !!space && space.state === import_services14.SpaceState.READY;
4946
5096
  }));
4947
5097
  }
4948
5098
  async _constructSpace(metadata) {
4949
- (0, import_log13.log)("construct space", {
5099
+ (0, import_log15.log)("construct space", {
4950
5100
  metadata
4951
5101
  }, {
4952
- F: __dxlog_file16,
4953
- L: 285,
5102
+ F: __dxlog_file17,
5103
+ L: 306,
4954
5104
  S: this,
4955
5105
  C: (f, a) => f(...a)
4956
5106
  });
@@ -4975,7 +5125,7 @@ var DataSpaceManager = class {
4975
5125
  swarmIdentity: {
4976
5126
  peerKey: this._signingContext.deviceKey,
4977
5127
  credentialProvider: createAuthProvider(this._signingContext.credentialSigner),
4978
- credentialAuthenticator: (0, import_util8.deferFunction)(() => dataSpace.authVerifier.verifier)
5128
+ credentialAuthenticator: (0, import_util10.deferFunction)(() => dataSpace.authVerifier.verifier)
4979
5129
  },
4980
5130
  onAuthorizedConnection: (session) => {
4981
5131
  session.addExtension("dxos.mesh.teleport.gossip", gossip.createExtension({
@@ -4986,15 +5136,15 @@ var DataSpaceManager = class {
4986
5136
  session.addExtension("dxos.mesh.teleport.automerge", this._echoHost.createReplicationExtension());
4987
5137
  },
4988
5138
  onAuthFailure: () => {
4989
- import_log13.log.warn("auth failure", void 0, {
4990
- F: __dxlog_file16,
4991
- L: 322,
5139
+ import_log15.log.warn("auth failure", void 0, {
5140
+ F: __dxlog_file17,
5141
+ L: 343,
4992
5142
  S: this,
4993
5143
  C: (f, a) => f(...a)
4994
5144
  });
4995
5145
  },
4996
5146
  onMemberRolesChanged: async (members) => {
4997
- if (dataSpace?.state === import_services13.SpaceState.READY) {
5147
+ if (dataSpace?.state === import_services14.SpaceState.READY) {
4998
5148
  this._handleMemberRoleChanges(presence, space.protocol, members);
4999
5149
  }
5000
5150
  },
@@ -5007,7 +5157,7 @@ var DataSpaceManager = class {
5007
5157
  dataFeed && await space.setDataFeed(dataFeed);
5008
5158
  const dataSpace = new DataSpace({
5009
5159
  inner: space,
5010
- initialState: metadata.state === import_services13.SpaceState.INACTIVE ? import_services13.SpaceState.INACTIVE : import_services13.SpaceState.CLOSED,
5160
+ initialState: metadata.state === import_services14.SpaceState.INACTIVE ? import_services14.SpaceState.INACTIVE : import_services14.SpaceState.CLOSED,
5011
5161
  metadataStore: this._metadataStore,
5012
5162
  gossip,
5013
5163
  presence,
@@ -5017,22 +5167,22 @@ var DataSpaceManager = class {
5017
5167
  signingContext: this._signingContext,
5018
5168
  callbacks: {
5019
5169
  beforeReady: async () => {
5020
- (0, import_log13.log)("before space ready", {
5170
+ (0, import_log15.log)("before space ready", {
5021
5171
  space: space.key
5022
5172
  }, {
5023
- F: __dxlog_file16,
5024
- L: 349,
5173
+ F: __dxlog_file17,
5174
+ L: 370,
5025
5175
  S: this,
5026
5176
  C: (f, a) => f(...a)
5027
5177
  });
5028
5178
  },
5029
5179
  afterReady: async () => {
5030
- (0, import_log13.log)("after space ready", {
5180
+ (0, import_log15.log)("after space ready", {
5031
5181
  space: space.key,
5032
5182
  open: this._isOpen
5033
5183
  }, {
5034
- F: __dxlog_file16,
5035
- L: 352,
5184
+ F: __dxlog_file17,
5185
+ L: 373,
5036
5186
  S: this,
5037
5187
  C: (f, a) => f(...a)
5038
5188
  });
@@ -5047,11 +5197,11 @@ var DataSpaceManager = class {
5047
5197
  }
5048
5198
  },
5049
5199
  beforeClose: async () => {
5050
- (0, import_log13.log)("before space close", {
5200
+ (0, import_log15.log)("before space close", {
5051
5201
  space: space.key
5052
5202
  }, {
5053
- F: __dxlog_file16,
5054
- L: 360,
5203
+ F: __dxlog_file17,
5204
+ L: 381,
5055
5205
  S: this,
5056
5206
  C: (f, a) => f(...a)
5057
5207
  });
@@ -5060,7 +5210,7 @@ var DataSpaceManager = class {
5060
5210
  cache: metadata.cache
5061
5211
  });
5062
5212
  presence.newPeer.on((peerState) => {
5063
- if (dataSpace.state === import_services13.SpaceState.READY) {
5213
+ if (dataSpace.state === import_services14.SpaceState.READY) {
5064
5214
  this._handleNewPeerConnected(space, peerState);
5065
5215
  }
5066
5216
  });
@@ -5079,20 +5229,20 @@ var DataSpaceManager = class {
5079
5229
  const peers = presence.getPeersByIdentityKey(member.key);
5080
5230
  const sessions = peers.map((p) => p.peerId && spaceProtocol.sessions.get(p.peerId));
5081
5231
  const sessionsToClose = sessions.filter((s) => {
5082
- return (s && member.role === import_credentials16.SpaceMember.Role.REMOVED !== (s.authStatus === import_echo_pipeline3.AuthStatus.FAILURE)) ?? false;
5232
+ return (s && member.role === import_credentials16.SpaceMember.Role.REMOVED !== (s.authStatus === import_echo_pipeline4.AuthStatus.FAILURE)) ?? false;
5083
5233
  });
5084
5234
  sessionsToClose.forEach((session) => {
5085
- void session.close().catch(import_log13.log.error);
5235
+ void session.close().catch(import_log15.log.error);
5086
5236
  });
5087
5237
  closedSessions += sessionsToClose.length;
5088
5238
  }
5089
- (0, import_log13.log)("processed member role changes", {
5239
+ (0, import_log15.log)("processed member role changes", {
5090
5240
  roleChangeCount: memberInfo.length,
5091
5241
  peersOnline: presence.getPeersOnline().length,
5092
5242
  closedSessions
5093
5243
  }, {
5094
- F: __dxlog_file16,
5095
- L: 396,
5244
+ F: __dxlog_file17,
5245
+ L: 417,
5096
5246
  S: this,
5097
5247
  C: (f, a) => f(...a)
5098
5248
  });
@@ -5103,20 +5253,20 @@ var DataSpaceManager = class {
5103
5253
  if (role === import_credentials16.SpaceMember.Role.REMOVED) {
5104
5254
  const session = peerState.peerId && space.protocol.sessions.get(peerState.peerId);
5105
5255
  if (session != null) {
5106
- (0, import_log13.log)("closing a session with a removed peer", {
5256
+ (0, import_log15.log)("closing a session with a removed peer", {
5107
5257
  peerId: peerState.peerId
5108
5258
  }, {
5109
- F: __dxlog_file16,
5110
- L: 410,
5259
+ F: __dxlog_file17,
5260
+ L: 431,
5111
5261
  S: this,
5112
5262
  C: (f, a) => f(...a)
5113
5263
  });
5114
- void session.close().catch(import_log13.log.error);
5264
+ void session.close().catch(import_log15.log.error);
5115
5265
  }
5116
5266
  }
5117
5267
  }
5118
5268
  async _handleInvitationStatusChange(dataSpace, delegatedInvitation, isActive) {
5119
- if (dataSpace?.state !== import_services13.SpaceState.READY) {
5269
+ if (dataSpace?.state !== import_services14.SpaceState.READY) {
5120
5270
  return;
5121
5271
  }
5122
5272
  if (isActive) {
@@ -5133,8 +5283,8 @@ var DataSpaceManager = class {
5133
5283
  async _createDelegatedInvitations(space, invitations) {
5134
5284
  const tasks = invitations.map(([credentialId, invitation]) => {
5135
5285
  return this._invitationsManager.createInvitation({
5136
- type: import_services13.Invitation.Type.DELEGATED,
5137
- kind: import_services13.Invitation.Kind.SPACE,
5286
+ type: import_services14.Invitation.Type.DELEGATED,
5287
+ kind: import_services14.Invitation.Kind.SPACE,
5138
5288
  spaceKey: space.key,
5139
5289
  authMethod: invitation.authMethod,
5140
5290
  invitationId: invitation.invitationId,
@@ -5152,21 +5302,21 @@ var DataSpaceManager = class {
5152
5302
  }
5153
5303
  };
5154
5304
  _ts_decorate5([
5155
- import_async15.synchronized
5305
+ import_async17.synchronized
5156
5306
  ], DataSpaceManager.prototype, "open", null);
5157
5307
  _ts_decorate5([
5158
- import_async15.synchronized
5308
+ import_async17.synchronized
5159
5309
  ], DataSpaceManager.prototype, "close", null);
5160
5310
  _ts_decorate5([
5161
- import_async15.synchronized
5311
+ import_async17.synchronized
5162
5312
  ], DataSpaceManager.prototype, "createSpace", null);
5163
5313
  _ts_decorate5([
5164
- import_async15.synchronized
5314
+ import_async17.synchronized
5165
5315
  ], DataSpaceManager.prototype, "acceptSpace", null);
5166
5316
  DataSpaceManager = _ts_decorate5([
5167
- (0, import_async15.trackLeaks)("open", "close")
5317
+ (0, import_async17.trackLeaks)("open", "close")
5168
5318
  ], DataSpaceManager);
5169
- var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
5319
+ var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
5170
5320
  var SpacesServiceImpl = class {
5171
5321
  constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
5172
5322
  this._identityManager = _identityManager;
@@ -5185,10 +5335,10 @@ var SpacesServiceImpl = class {
5185
5335
  const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols12.SpaceNotFoundError(spaceKey));
5186
5336
  if (state) {
5187
5337
  switch (state) {
5188
- case import_services14.SpaceState.ACTIVE:
5338
+ case import_services15.SpaceState.ACTIVE:
5189
5339
  await space.activate();
5190
5340
  break;
5191
- case import_services14.SpaceState.INACTIVE:
5341
+ case import_services15.SpaceState.INACTIVE:
5192
5342
  await space.deactivate();
5193
5343
  break;
5194
5344
  default:
@@ -5209,9 +5359,9 @@ var SpacesServiceImpl = class {
5209
5359
  });
5210
5360
  }
5211
5361
  const credentials = await (0, import_credentials19.createAdmissionCredentials)(identity.getIdentityCredentialSigner(), request.memberKey, space.key, space.genesisFeedKey, request.newRole, space.spaceState.membershipChainHeads);
5212
- (0, import_invariant15.invariant)(credentials[0].credential, void 0, {
5213
- F: __dxlog_file17,
5214
- L: 97,
5362
+ (0, import_invariant16.invariant)(credentials[0].credential, void 0, {
5363
+ F: __dxlog_file18,
5364
+ L: 98,
5215
5365
  S: this,
5216
5366
  A: [
5217
5367
  "credentials[0].credential",
@@ -5219,9 +5369,9 @@ var SpacesServiceImpl = class {
5219
5369
  ]
5220
5370
  });
5221
5371
  const spaceMemberCredential = credentials[0].credential.credential;
5222
- (0, import_invariant15.invariant)((0, import_credentials19.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
5223
- F: __dxlog_file17,
5224
- L: 99,
5372
+ (0, import_invariant16.invariant)((0, import_credentials19.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
5373
+ F: __dxlog_file18,
5374
+ L: 100,
5225
5375
  S: this,
5226
5376
  A: [
5227
5377
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -5232,14 +5382,14 @@ var SpacesServiceImpl = class {
5232
5382
  }
5233
5383
  querySpaces() {
5234
5384
  return new import_codec_protobuf11.Stream(({ next, ctx }) => {
5235
- const scheduler = new import_async16.UpdateScheduler(ctx, async () => {
5385
+ const scheduler = new import_async18.UpdateScheduler(ctx, async () => {
5236
5386
  const dataSpaceManager = await this._getDataSpaceManager();
5237
5387
  const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
5238
- (0, import_log14.log)("update", {
5388
+ (0, import_log16.log)("update", {
5239
5389
  spaces
5240
5390
  }, {
5241
- F: __dxlog_file17,
5242
- L: 110,
5391
+ F: __dxlog_file18,
5392
+ L: 111,
5243
5393
  S: this,
5244
5394
  C: (f, a) => f(...a)
5245
5395
  });
@@ -5250,9 +5400,9 @@ var SpacesServiceImpl = class {
5250
5400
  }, {
5251
5401
  maxFrequency: process.env.NODE_ENV === "test" ? void 0 : 2
5252
5402
  });
5253
- (0, import_async16.scheduleTask)(ctx, async () => {
5403
+ (0, import_async18.scheduleTask)(ctx, async () => {
5254
5404
  const dataSpaceManager = await this._getDataSpaceManager();
5255
- const subscriptions = new import_async16.EventSubscriptions();
5405
+ const subscriptions = new import_async18.EventSubscriptions();
5256
5406
  ctx.onDispose(() => subscriptions.clear());
5257
5407
  const subscribeSpaces = () => {
5258
5408
  subscriptions.clear();
@@ -5284,7 +5434,7 @@ var SpacesServiceImpl = class {
5284
5434
  }
5285
5435
  subscribeMessages({ spaceKey, channel }) {
5286
5436
  return new import_codec_protobuf11.Stream(({ ctx, next }) => {
5287
- (0, import_async16.scheduleTask)(ctx, async () => {
5437
+ (0, import_async18.scheduleTask)(ctx, async () => {
5288
5438
  const dataSpaceManager = await this._getDataSpaceManager();
5289
5439
  const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols12.SpaceNotFoundError(spaceKey));
5290
5440
  const handle = space.listen(getChannelId(channel), (message) => {
@@ -5303,7 +5453,7 @@ var SpacesServiceImpl = class {
5303
5453
  }
5304
5454
  };
5305
5455
  ctx.onDispose(() => space.spaceState.removeCredentialProcessor(processor));
5306
- (0, import_async16.scheduleTask)(ctx, async () => {
5456
+ (0, import_async18.scheduleTask)(ctx, async () => {
5307
5457
  await space.spaceState.addCredentialProcessor(processor);
5308
5458
  if (noTail) {
5309
5459
  close();
@@ -5321,18 +5471,18 @@ var SpacesServiceImpl = class {
5321
5471
  }
5322
5472
  });
5323
5473
  } else {
5324
- (0, import_invariant15.invariant)(!credential.id, "Id on unsigned credentials is not allowed", {
5325
- F: __dxlog_file17,
5326
- L: 198,
5474
+ (0, import_invariant16.invariant)(!credential.id, "Id on unsigned credentials is not allowed", {
5475
+ F: __dxlog_file18,
5476
+ L: 199,
5327
5477
  S: this,
5328
5478
  A: [
5329
5479
  "!credential.id",
5330
5480
  "'Id on unsigned credentials is not allowed'"
5331
5481
  ]
5332
5482
  });
5333
- (0, import_invariant15.invariant)(this._identityManager.identity, "Identity is not available", {
5334
- F: __dxlog_file17,
5335
- L: 199,
5483
+ (0, import_invariant16.invariant)(this._identityManager.identity, "Identity is not available", {
5484
+ F: __dxlog_file18,
5485
+ L: 200,
5336
5486
  S: this,
5337
5487
  A: [
5338
5488
  "this._identityManager.identity",
@@ -5340,9 +5490,9 @@ var SpacesServiceImpl = class {
5340
5490
  ]
5341
5491
  });
5342
5492
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
5343
- (0, import_invariant15.invariant)(credential.issuer.equals(signer.getIssuer()), void 0, {
5344
- F: __dxlog_file17,
5345
- L: 201,
5493
+ (0, import_invariant16.invariant)(credential.issuer.equals(signer.getIssuer()), void 0, {
5494
+ F: __dxlog_file18,
5495
+ L: 202,
5346
5496
  S: this,
5347
5497
  A: [
5348
5498
  "credential.issuer.equals(signer.getIssuer())",
@@ -5364,10 +5514,13 @@ var SpacesServiceImpl = class {
5364
5514
  async createEpoch({ spaceKey, migration, automergeRootUrl }) {
5365
5515
  const dataSpaceManager = await this._getDataSpaceManager();
5366
5516
  const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols12.SpaceNotFoundError(spaceKey));
5367
- await space.createEpoch({
5517
+ const credential = await space.createEpoch({
5368
5518
  migration,
5369
5519
  newAutomergeRoot: automergeRootUrl
5370
5520
  });
5521
+ return {
5522
+ epochCredential: credential ?? void 0
5523
+ };
5371
5524
  }
5372
5525
  _serializeSpace(space) {
5373
5526
  return {
@@ -5400,7 +5553,7 @@ var SpacesServiceImpl = class {
5400
5553
  profile: member.profile ?? {}
5401
5554
  },
5402
5555
  role: member.role,
5403
- presence: peers.length > 0 ? import_services14.SpaceMember.PresenceState.ONLINE : import_services14.SpaceMember.PresenceState.OFFLINE,
5556
+ presence: peers.length > 0 ? import_services15.SpaceMember.PresenceState.ONLINE : import_services15.SpaceMember.PresenceState.OFFLINE,
5404
5557
  peerStates: peers
5405
5558
  };
5406
5559
  }),
@@ -5438,8 +5591,8 @@ function _ts_decorate6(decorators, target, key, desc) {
5438
5591
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5439
5592
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5440
5593
  }
5441
- var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
5442
- var ServiceContext = class extends import_context13.Resource {
5594
+ var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
5595
+ var ServiceContext = class extends import_context15.Resource {
5443
5596
  constructor(storage, level, networkManager, signalManager, _runtimeParams) {
5444
5597
  super();
5445
5598
  this.storage = storage;
@@ -5447,11 +5600,11 @@ var ServiceContext = class extends import_context13.Resource {
5447
5600
  this.networkManager = networkManager;
5448
5601
  this.signalManager = signalManager;
5449
5602
  this._runtimeParams = _runtimeParams;
5450
- this.initialized = new import_async17.Trigger();
5603
+ this.initialized = new import_async19.Trigger();
5451
5604
  this._handlerFactories = /* @__PURE__ */ new Map();
5452
5605
  this._instanceId = import_keys13.PublicKey.random().toHex();
5453
- this.metadataStore = new import_echo_pipeline4.MetadataStore(storage.createDirectory("metadata"));
5454
- this.snapshotStore = new import_echo_pipeline4.SnapshotStore(storage.createDirectory("snapshots"));
5606
+ this.metadataStore = new import_echo_pipeline5.MetadataStore(storage.createDirectory("metadata"));
5607
+ this.snapshotStore = new import_echo_pipeline5.SnapshotStore(storage.createDirectory("snapshots"));
5455
5608
  this.blobStore = new import_teleport_extension_object_sync.BlobStore(storage.createDirectory("blobs"));
5456
5609
  this.keyring = new import_keyring.Keyring(storage.createDirectory("keyring"));
5457
5610
  this.feedStore = new import_feed_store5.FeedStore({
@@ -5459,12 +5612,12 @@ var ServiceContext = class extends import_context13.Resource {
5459
5612
  root: storage.createDirectory("feeds"),
5460
5613
  signer: this.keyring,
5461
5614
  hypercore: {
5462
- valueEncoding: import_echo_pipeline4.valueEncoding,
5615
+ valueEncoding: import_echo_pipeline5.valueEncoding,
5463
5616
  stats: true
5464
5617
  }
5465
5618
  })
5466
5619
  });
5467
- this.spaceManager = new import_echo_pipeline4.SpaceManager({
5620
+ this.spaceManager = new import_echo_pipeline5.SpaceManager({
5468
5621
  feedStore: this.feedStore,
5469
5622
  networkManager: this.networkManager,
5470
5623
  blobStore: this.blobStore,
@@ -5472,25 +5625,25 @@ var ServiceContext = class extends import_context13.Resource {
5472
5625
  snapshotStore: this.snapshotStore
5473
5626
  });
5474
5627
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager, this._runtimeParams);
5475
- this.echoHost = new import_echo_db.EchoHost({
5628
+ this.echoHost = new import_echo_db3.EchoHost({
5476
5629
  kv: this.level
5477
5630
  });
5478
5631
  this.invitations = new InvitationsHandler(this.networkManager, _runtimeParams?.invitationConnectionDefaultParams);
5479
5632
  this.invitationsManager = new InvitationsManager(this.invitations, (invitation) => this.getInvitationHandler(invitation), this.metadataStore);
5480
- this._handlerFactories.set(import_services15.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug6.failUndefined)(), this._acceptIdentity.bind(this)));
5633
+ this._handlerFactories.set(import_services16.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug6.failUndefined)(), this._acceptIdentity.bind(this)));
5481
5634
  }
5482
5635
  async _open(ctx) {
5483
5636
  await this._checkStorageVersion();
5484
- (0, import_log15.log)("opening...", void 0, {
5485
- F: __dxlog_file18,
5637
+ (0, import_log17.log)("opening...", void 0, {
5638
+ F: __dxlog_file19,
5486
5639
  L: 149,
5487
5640
  S: this,
5488
5641
  C: (f, a) => f(...a)
5489
5642
  });
5490
- import_log15.log.trace("dxos.sdk.service-context.open", import_protocols13.trace.begin({
5643
+ import_log17.log.trace("dxos.sdk.service-context.open", import_protocols13.trace.begin({
5491
5644
  id: this._instanceId
5492
5645
  }), {
5493
- F: __dxlog_file18,
5646
+ F: __dxlog_file19,
5494
5647
  L: 150,
5495
5648
  S: this,
5496
5649
  C: (f, a) => f(...a)
@@ -5505,32 +5658,32 @@ var ServiceContext = class extends import_context13.Resource {
5505
5658
  await this._initialize(ctx);
5506
5659
  }
5507
5660
  const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
5508
- (0, import_log15.log)("loaded persistent invitations", {
5661
+ (0, import_log17.log)("loaded persistent invitations", {
5509
5662
  count: loadedInvitations.invitations?.length
5510
5663
  }, {
5511
- F: __dxlog_file18,
5664
+ F: __dxlog_file19,
5512
5665
  L: 163,
5513
5666
  S: this,
5514
5667
  C: (f, a) => f(...a)
5515
5668
  });
5516
- import_log15.log.trace("dxos.sdk.service-context.open", import_protocols13.trace.end({
5669
+ import_log17.log.trace("dxos.sdk.service-context.open", import_protocols13.trace.end({
5517
5670
  id: this._instanceId
5518
5671
  }), {
5519
- F: __dxlog_file18,
5672
+ F: __dxlog_file19,
5520
5673
  L: 165,
5521
5674
  S: this,
5522
5675
  C: (f, a) => f(...a)
5523
5676
  });
5524
- (0, import_log15.log)("opened", void 0, {
5525
- F: __dxlog_file18,
5677
+ (0, import_log17.log)("opened", void 0, {
5678
+ F: __dxlog_file19,
5526
5679
  L: 166,
5527
5680
  S: this,
5528
5681
  C: (f, a) => f(...a)
5529
5682
  });
5530
5683
  }
5531
5684
  async _close(ctx) {
5532
- (0, import_log15.log)("closing...", void 0, {
5533
- F: __dxlog_file18,
5685
+ (0, import_log17.log)("closing...", void 0, {
5686
+ F: __dxlog_file19,
5534
5687
  L: 170,
5535
5688
  S: this,
5536
5689
  C: (f, a) => f(...a)
@@ -5546,8 +5699,8 @@ var ServiceContext = class extends import_context13.Resource {
5546
5699
  await this.echoHost.close(ctx);
5547
5700
  await this.networkManager.close();
5548
5701
  await this.signalManager.close();
5549
- (0, import_log15.log)("closed", void 0, {
5550
- F: __dxlog_file18,
5702
+ (0, import_log17.log)("closed", void 0, {
5703
+ F: __dxlog_file19,
5551
5704
  L: 182,
5552
5705
  S: this,
5553
5706
  C: (f, a) => f(...a)
@@ -5555,13 +5708,13 @@ var ServiceContext = class extends import_context13.Resource {
5555
5708
  }
5556
5709
  async createIdentity(params = {}) {
5557
5710
  const identity = await this.identityManager.createIdentity(params);
5558
- await this._initialize(new import_context13.Context());
5711
+ await this._initialize(new import_context15.Context());
5559
5712
  return identity;
5560
5713
  }
5561
5714
  getInvitationHandler(invitation) {
5562
5715
  const factory = this._handlerFactories.get(invitation.kind);
5563
- (0, import_invariant16.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
5564
- F: __dxlog_file18,
5716
+ (0, import_invariant17.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
5717
+ F: __dxlog_file19,
5565
5718
  L: 193,
5566
5719
  S: this,
5567
5720
  A: [
@@ -5581,7 +5734,7 @@ var ServiceContext = class extends import_context13.Resource {
5581
5734
  }
5582
5735
  async _acceptIdentity(params) {
5583
5736
  const identity = await this.identityManager.acceptIdentity(params);
5584
- await this._initialize(new import_context13.Context());
5737
+ await this._initialize(new import_context15.Context());
5585
5738
  return identity;
5586
5739
  }
5587
5740
  async _checkStorageVersion() {
@@ -5592,8 +5745,8 @@ var ServiceContext = class extends import_context13.Resource {
5592
5745
  }
5593
5746
  // Called when identity is created.
5594
5747
  async _initialize(ctx) {
5595
- (0, import_log15.log)("initializing spaces...", void 0, {
5596
- F: __dxlog_file18,
5748
+ (0, import_log17.log)("initializing spaces...", void 0, {
5749
+ F: __dxlog_file19,
5597
5750
  L: 224,
5598
5751
  S: this,
5599
5752
  C: (f, a) => f(...a)
@@ -5614,9 +5767,9 @@ var ServiceContext = class extends import_context13.Resource {
5614
5767
  };
5615
5768
  this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.echoHost, this.invitationsManager, this._runtimeParams);
5616
5769
  await this.dataSpaceManager.open();
5617
- this._handlerFactories.set(import_services15.Invitation.Kind.SPACE, (invitation) => {
5618
- (0, import_invariant16.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
5619
- F: __dxlog_file18,
5770
+ this._handlerFactories.set(import_services16.Invitation.Kind.SPACE, (invitation) => {
5771
+ (0, import_invariant17.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
5772
+ F: __dxlog_file19,
5620
5773
  L: 249,
5621
5774
  S: this,
5622
5775
  A: [
@@ -5637,10 +5790,10 @@ var ServiceContext = class extends import_context13.Resource {
5637
5790
  return;
5638
5791
  }
5639
5792
  if (!this.dataSpaceManager) {
5640
- (0, import_log15.log)("dataSpaceManager not initialized yet, ignoring space admission", {
5793
+ (0, import_log17.log)("dataSpaceManager not initialized yet, ignoring space admission", {
5641
5794
  details: assertion
5642
5795
  }, {
5643
- F: __dxlog_file18,
5796
+ F: __dxlog_file19,
5644
5797
  L: 265,
5645
5798
  S: this,
5646
5799
  C: (f, a) => f(...a)
@@ -5648,10 +5801,10 @@ var ServiceContext = class extends import_context13.Resource {
5648
5801
  return;
5649
5802
  }
5650
5803
  if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
5651
- (0, import_log15.log)("space already exists, ignoring space admission", {
5804
+ (0, import_log17.log)("space already exists, ignoring space admission", {
5652
5805
  details: assertion
5653
5806
  }, {
5654
- F: __dxlog_file18,
5807
+ F: __dxlog_file19,
5655
5808
  L: 269,
5656
5809
  S: this,
5657
5810
  C: (f, a) => f(...a)
@@ -5659,10 +5812,10 @@ var ServiceContext = class extends import_context13.Resource {
5659
5812
  return;
5660
5813
  }
5661
5814
  try {
5662
- (0, import_log15.log)("accepting space recorded in halo", {
5815
+ (0, import_log17.log)("accepting space recorded in halo", {
5663
5816
  details: assertion
5664
5817
  }, {
5665
- F: __dxlog_file18,
5818
+ F: __dxlog_file19,
5666
5819
  L: 274,
5667
5820
  S: this,
5668
5821
  C: (f, a) => f(...a)
@@ -5672,8 +5825,8 @@ var ServiceContext = class extends import_context13.Resource {
5672
5825
  genesisFeedKey: assertion.genesisFeedKey
5673
5826
  });
5674
5827
  } catch (err) {
5675
- import_log15.log.catch(err, void 0, {
5676
- F: __dxlog_file18,
5828
+ import_log17.log.catch(err, void 0, {
5829
+ F: __dxlog_file19,
5677
5830
  L: 280,
5678
5831
  S: this,
5679
5832
  C: (f, a) => f(...a)
@@ -5691,7 +5844,7 @@ _ts_decorate6([
5691
5844
  import_tracing8.trace.span()
5692
5845
  ], ServiceContext.prototype, "_initialize", null);
5693
5846
  ServiceContext = _ts_decorate6([
5694
- (0, import_util9.safeInstanceof)("dxos.client-services.ServiceContext"),
5847
+ (0, import_util11.safeInstanceof)("dxos.client-services.ServiceContext"),
5695
5848
  import_tracing8.trace.resource()
5696
5849
  ], ServiceContext);
5697
5850
  var ServiceRegistry = class {
@@ -5726,7 +5879,7 @@ function _ts_decorate7(decorators, target, key, desc) {
5726
5879
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5727
5880
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5728
5881
  }
5729
- var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/node.ts";
5882
+ var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/node.ts";
5730
5883
  var Lock = class {
5731
5884
  constructor({ lockKey: lockPath, onAcquire, onRelease }) {
5732
5885
  this._lockPath = lockPath;
@@ -5737,16 +5890,16 @@ var Lock = class {
5737
5890
  return this._lockPath;
5738
5891
  }
5739
5892
  async acquire() {
5740
- (0, import_log16.log)("acquiring lock...", void 0, {
5741
- F: __dxlog_file19,
5893
+ (0, import_log18.log)("acquiring lock...", void 0, {
5894
+ F: __dxlog_file20,
5742
5895
  L: 32,
5743
5896
  S: this,
5744
5897
  C: (f, a) => f(...a)
5745
5898
  });
5746
5899
  this._fileHandle = await import_lock_file.LockFile.acquire(this._lockPath);
5747
5900
  await this._onAcquire?.();
5748
- (0, import_log16.log)("acquired lock", void 0, {
5749
- F: __dxlog_file19,
5901
+ (0, import_log18.log)("acquired lock", void 0, {
5902
+ F: __dxlog_file20,
5750
5903
  L: 37,
5751
5904
  S: this,
5752
5905
  C: (f, a) => f(...a)
@@ -5754,8 +5907,8 @@ var Lock = class {
5754
5907
  }
5755
5908
  async release() {
5756
5909
  await this._onRelease?.();
5757
- (0, import_invariant17.invariant)(this._fileHandle, "Lock is not acquired", {
5758
- F: __dxlog_file19,
5910
+ (0, import_invariant18.invariant)(this._fileHandle, "Lock is not acquired", {
5911
+ F: __dxlog_file20,
5759
5912
  L: 42,
5760
5913
  S: this,
5761
5914
  A: [
@@ -5767,11 +5920,11 @@ var Lock = class {
5767
5920
  }
5768
5921
  };
5769
5922
  _ts_decorate7([
5770
- import_log16.logInfo
5923
+ import_log18.logInfo
5771
5924
  ], Lock.prototype, "lockKey", null);
5772
5925
  var isLocked = (lockPath) => import_lock_file.LockFile.isLocked(lockPath);
5773
5926
  var getRootPath = (config) => {
5774
- const { dataRoot = (0, import_util10.isNode)() ? import_client_protocol6.DX_DATA : "dxos/storage" } = config ?? {};
5927
+ const { dataRoot = (0, import_util12.isNode)() ? import_client_protocol6.DX_DATA : "dxos/storage" } = config ?? {};
5775
5928
  return `${dataRoot}/`;
5776
5929
  };
5777
5930
  var isPersistent = (config) => {
@@ -5827,7 +5980,7 @@ var createLevel = async (config) => {
5827
5980
  await level.open();
5828
5981
  return level;
5829
5982
  };
5830
- var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
5983
+ var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
5831
5984
  var DevicesServiceImpl = class {
5832
5985
  constructor(_identityManager) {
5833
5986
  this._identityManager = _identityManager;
@@ -5844,8 +5997,8 @@ var DevicesServiceImpl = class {
5844
5997
  devices: []
5845
5998
  });
5846
5999
  } else {
5847
- (0, import_invariant19.invariant)(this._identityManager.identity?.presence, "presence not present", {
5848
- F: __dxlog_file20,
6000
+ (0, import_invariant20.invariant)(this._identityManager.identity?.presence, "presence not present", {
6001
+ F: __dxlog_file21,
5849
6002
  L: 32,
5850
6003
  S: this,
5851
6004
  A: [
@@ -5860,9 +6013,9 @@ var DevicesServiceImpl = class {
5860
6013
  const peerState = peers.find((peer) => peer.identityKey.equals(key));
5861
6014
  return {
5862
6015
  deviceKey: key,
5863
- kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services17.DeviceKind.CURRENT : import_services17.DeviceKind.TRUSTED,
6016
+ kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services18.DeviceKind.CURRENT : import_services18.DeviceKind.TRUSTED,
5864
6017
  profile,
5865
- presence: isMe ? import_services17.Device.PresenceState.ONLINE : peerState ? import_services17.Device.PresenceState.ONLINE : import_services17.Device.PresenceState.OFFLINE
6018
+ presence: isMe ? import_services18.Device.PresenceState.ONLINE : peerState ? import_services18.Device.PresenceState.ONLINE : import_services18.Device.PresenceState.OFFLINE
5866
6019
  };
5867
6020
  })
5868
6021
  });
@@ -5886,7 +6039,7 @@ var DevicesServiceImpl = class {
5886
6039
  presenceSubscribed = true;
5887
6040
  }
5888
6041
  };
5889
- const subscriptions = new import_async19.EventSubscriptions();
6042
+ const subscriptions = new import_async21.EventSubscriptions();
5890
6043
  if (this._identityManager.identity) {
5891
6044
  subscribeIdentity();
5892
6045
  subscribePresence();
@@ -5911,7 +6064,7 @@ var DiagnosticsCollector = class {
5911
6064
  }
5912
6065
  static async collect(config = findConfigs(), services = findSystemServiceProvider(), options = {}) {
5913
6066
  const serviceDiagnostics = await services?.services?.SystemService?.getDiagnostics({
5914
- keys: options.humanize ? import_services18.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE : options.truncate ? import_services18.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE : void 0
6067
+ keys: options.humanize ? import_services19.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE : options.truncate ? import_services19.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE : void 0
5915
6068
  }, {
5916
6069
  timeout: GET_DIAGNOSTICS_RPC_TIMEOUT
5917
6070
  });
@@ -5926,7 +6079,7 @@ var DiagnosticsCollector = class {
5926
6079
  client: clientDiagnostics,
5927
6080
  broadcast: await this.broadcastSender.broadcastDiagnosticsRequest()
5928
6081
  };
5929
- return JSON.parse(JSON.stringify(diagnostics, (0, import_util11.jsonKeyReplacer)(options)));
6082
+ return JSON.parse(JSON.stringify(diagnostics, (0, import_util13.jsonKeyReplacer)(options)));
5930
6083
  }
5931
6084
  };
5932
6085
  var findSystemServiceProvider = () => {
@@ -5936,11 +6089,11 @@ var findSystemServiceProvider = () => {
5936
6089
  };
5937
6090
  var findConfigs = () => {
5938
6091
  const configs = import_tracing10.TRACE_PROCESSOR.findResourcesByAnnotation(import_config3.ConfigResource);
5939
- return configs.map((r) => r.instance.deref()).filter(import_util11.nonNullable);
6092
+ return configs.map((r) => r.instance.deref()).filter(import_util13.nonNullable);
5940
6093
  };
5941
6094
  var LoggingServiceImpl = class {
5942
6095
  constructor() {
5943
- this._logs = new import_async20.Event();
6096
+ this._logs = new import_async22.Event();
5944
6097
  this._started = Date.now();
5945
6098
  this._sessionId = import_keys17.PublicKey.random().toHex();
5946
6099
  this._logProcessor = (_config, entry2) => {
@@ -5948,23 +6101,23 @@ var LoggingServiceImpl = class {
5948
6101
  };
5949
6102
  }
5950
6103
  async open() {
5951
- import_log18.log.runtimeConfig.processors.push(this._logProcessor);
6104
+ import_log20.log.runtimeConfig.processors.push(this._logProcessor);
5952
6105
  }
5953
6106
  async close() {
5954
- const index = import_log18.log.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
5955
- import_log18.log.runtimeConfig.processors.splice(index, 1);
6107
+ const index = import_log20.log.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
6108
+ import_log20.log.runtimeConfig.processors.splice(index, 1);
5956
6109
  }
5957
6110
  async controlMetrics({ reset, record }) {
5958
6111
  if (reset) {
5959
- import_util13.tracer.clear();
6112
+ import_util15.tracer.clear();
5960
6113
  }
5961
6114
  if (record === true) {
5962
- import_util13.tracer.start();
6115
+ import_util15.tracer.start();
5963
6116
  } else if (record === false) {
5964
- import_util13.tracer.stop();
6117
+ import_util15.tracer.stop();
5965
6118
  }
5966
6119
  return {
5967
- recording: import_util13.tracer.recording
6120
+ recording: import_util15.tracer.recording
5968
6121
  };
5969
6122
  }
5970
6123
  /**
@@ -5972,10 +6125,10 @@ var LoggingServiceImpl = class {
5972
6125
  */
5973
6126
  queryMetrics({ interval = 5e3 }) {
5974
6127
  const getNumericalValues = (key) => {
5975
- const events = import_util13.tracer.get(key) ?? [];
6128
+ const events = import_util15.tracer.get(key) ?? [];
5976
6129
  return {
5977
6130
  key,
5978
- stats: (0, import_util13.numericalValues)(events, "duration")
6131
+ stats: (0, import_util15.numericalValues)(events, "duration")
5979
6132
  };
5980
6133
  };
5981
6134
  return new import_codec_protobuf13.Stream(({ next }) => {
@@ -6013,7 +6166,7 @@ var LoggingServiceImpl = class {
6013
6166
  }
6014
6167
  const record = {
6015
6168
  ...entry2,
6016
- context: (0, import_util13.jsonify)((0, import_log18.getContextFromEntry)(entry2)),
6169
+ context: (0, import_util15.jsonify)((0, import_log20.getContextFromEntry)(entry2)),
6017
6170
  timestamp: /* @__PURE__ */ new Date(),
6018
6171
  meta: {
6019
6172
  // TODO(dmaretskyi): Fix proto.
@@ -6022,7 +6175,7 @@ var LoggingServiceImpl = class {
6022
6175
  scope: {
6023
6176
  hostSessionId: this._sessionId,
6024
6177
  uptimeSeconds: (Date.now() - this._started) / 1e3,
6025
- name: (0, import_util13.getDebugName)(entry2.meta?.S)
6178
+ name: (0, import_util15.getDebugName)(entry2.meta?.S)
6026
6179
  }
6027
6180
  }
6028
6181
  };
@@ -6039,16 +6192,16 @@ var LoggingServiceImpl = class {
6039
6192
  };
6040
6193
  var matchFilter = (filter, level, path2, options) => {
6041
6194
  switch (options) {
6042
- case import_services19.QueryLogsRequest.MatchingOptions.INCLUSIVE:
6195
+ case import_services20.QueryLogsRequest.MatchingOptions.INCLUSIVE:
6043
6196
  return level >= filter.level && (!filter.pattern || path2.includes(filter.pattern));
6044
- case import_services19.QueryLogsRequest.MatchingOptions.EXPLICIT:
6197
+ case import_services20.QueryLogsRequest.MatchingOptions.EXPLICIT:
6045
6198
  return level === filter.level && (!filter.pattern || path2.includes(filter.pattern));
6046
6199
  }
6047
6200
  };
6048
6201
  var shouldLog = (entry2, request) => {
6049
- const options = request.options ?? import_services19.QueryLogsRequest.MatchingOptions.INCLUSIVE;
6202
+ const options = request.options ?? import_services20.QueryLogsRequest.MatchingOptions.INCLUSIVE;
6050
6203
  if (request.filters === void 0) {
6051
- return options === import_services19.QueryLogsRequest.MatchingOptions.INCLUSIVE;
6204
+ return options === import_services20.QueryLogsRequest.MatchingOptions.INCLUSIVE;
6052
6205
  } else {
6053
6206
  return request.filters.some((filter) => matchFilter(filter, entry2.level, entry2.meta?.F ?? "", options));
6054
6207
  }
@@ -6103,9 +6256,9 @@ var SystemServiceImpl = class {
6103
6256
  const diagnostics = await this._getDiagnostics();
6104
6257
  return {
6105
6258
  timestamp: /* @__PURE__ */ new Date(),
6106
- diagnostics: JSON.parse(JSON.stringify(diagnostics, (0, import_util14.jsonKeyReplacer)({
6107
- truncate: keys === import_services20.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
6108
- humanize: keys === import_services20.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
6259
+ diagnostics: JSON.parse(JSON.stringify(diagnostics, (0, import_util16.jsonKeyReplacer)({
6260
+ truncate: keys === import_services21.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
6261
+ humanize: keys === import_services21.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
6109
6262
  })))
6110
6263
  };
6111
6264
  }
@@ -6146,7 +6299,7 @@ function _ts_decorate8(decorators, target, key, desc) {
6146
6299
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6147
6300
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6148
6301
  }
6149
- var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
6302
+ var __dxlog_file22 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
6150
6303
  var ClientServicesHost = class {
6151
6304
  constructor({
6152
6305
  config,
@@ -6160,7 +6313,7 @@ var ClientServicesHost = class {
6160
6313
  runtimeParams
6161
6314
  } = {}) {
6162
6315
  this._tracingService = import_tracing9.TRACE_PROCESSOR.createTraceSender();
6163
- this._statusUpdate = new import_async18.Event();
6316
+ this._statusUpdate = new import_async20.Event();
6164
6317
  this._opening = false;
6165
6318
  this._open = false;
6166
6319
  this._storage = storage;
@@ -6179,7 +6332,7 @@ var ClientServicesHost = class {
6179
6332
  lockKey,
6180
6333
  onAcquire: () => {
6181
6334
  if (!this._opening) {
6182
- void this.open(new import_context14.Context());
6335
+ void this.open(new import_context16.Context());
6183
6336
  }
6184
6337
  },
6185
6338
  onRelease: () => this.close()
@@ -6188,14 +6341,14 @@ var ClientServicesHost = class {
6188
6341
  this._systemService = new SystemServiceImpl({
6189
6342
  config: () => this._config,
6190
6343
  statusUpdate: this._statusUpdate,
6191
- getCurrentStatus: () => this.isOpen ? import_services16.SystemStatus.ACTIVE : import_services16.SystemStatus.INACTIVE,
6344
+ getCurrentStatus: () => this.isOpen ? import_services17.SystemStatus.ACTIVE : import_services17.SystemStatus.INACTIVE,
6192
6345
  getDiagnostics: () => {
6193
6346
  return createDiagnostics(this._serviceRegistry.services, this._serviceContext, this._config);
6194
6347
  },
6195
6348
  onUpdateStatus: async (status) => {
6196
- if (!this.isOpen && status === import_services16.SystemStatus.ACTIVE) {
6349
+ if (!this.isOpen && status === import_services17.SystemStatus.ACTIVE) {
6197
6350
  await this._resourceLock?.acquire();
6198
- } else if (this.isOpen && status === import_services16.SystemStatus.INACTIVE) {
6351
+ } else if (this.isOpen && status === import_services17.SystemStatus.INACTIVE) {
6199
6352
  await this._resourceLock?.release();
6200
6353
  }
6201
6354
  },
@@ -6234,8 +6387,8 @@ var ClientServicesHost = class {
6234
6387
  * Can only be called once.
6235
6388
  */
6236
6389
  initialize({ config, ...options }) {
6237
- (0, import_invariant18.invariant)(!this._open, "service host is open", {
6238
- F: __dxlog_file21,
6390
+ (0, import_invariant19.invariant)(!this._open, "service host is open", {
6391
+ F: __dxlog_file22,
6239
6392
  L: 186,
6240
6393
  S: this,
6241
6394
  A: [
@@ -6243,15 +6396,15 @@ var ClientServicesHost = class {
6243
6396
  "'service host is open'"
6244
6397
  ]
6245
6398
  });
6246
- (0, import_log17.log)("initializing...", void 0, {
6247
- F: __dxlog_file21,
6399
+ (0, import_log19.log)("initializing...", void 0, {
6400
+ F: __dxlog_file22,
6248
6401
  L: 187,
6249
6402
  S: this,
6250
6403
  C: (f, a) => f(...a)
6251
6404
  });
6252
6405
  if (config) {
6253
- (0, import_invariant18.invariant)(!this._config, "config already set", {
6254
- F: __dxlog_file21,
6406
+ (0, import_invariant19.invariant)(!this._config, "config already set", {
6407
+ F: __dxlog_file22,
6255
6408
  L: 190,
6256
6409
  S: this,
6257
6410
  A: [
@@ -6265,8 +6418,8 @@ var ClientServicesHost = class {
6265
6418
  }
6266
6419
  }
6267
6420
  if (!options.signalManager) {
6268
- import_log17.log.warn("running signaling without telemetry metadata.", void 0, {
6269
- F: __dxlog_file21,
6421
+ import_log19.log.warn("running signaling without telemetry metadata.", void 0, {
6422
+ F: __dxlog_file22,
6270
6423
  L: 198,
6271
6424
  S: this,
6272
6425
  C: (f, a) => f(...a)
@@ -6276,8 +6429,8 @@ var ClientServicesHost = class {
6276
6429
  iceServers: this._config?.get("runtime.services.ice")
6277
6430
  }), signalManager = new import_messaging.WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
6278
6431
  this._signalManager = signalManager;
6279
- (0, import_invariant18.invariant)(!this._networkManager, "network manager already set", {
6280
- F: __dxlog_file21,
6432
+ (0, import_invariant19.invariant)(!this._networkManager, "network manager already set", {
6433
+ F: __dxlog_file22,
6281
6434
  L: 209,
6282
6435
  S: this,
6283
6436
  A: [
@@ -6290,8 +6443,8 @@ var ClientServicesHost = class {
6290
6443
  transportFactory,
6291
6444
  signalManager
6292
6445
  });
6293
- (0, import_log17.log)("initialized", void 0, {
6294
- F: __dxlog_file21,
6446
+ (0, import_log19.log)("initialized", void 0, {
6447
+ F: __dxlog_file22,
6295
6448
  L: 216,
6296
6449
  S: this,
6297
6450
  C: (f, a) => f(...a)
@@ -6302,16 +6455,16 @@ var ClientServicesHost = class {
6302
6455
  return;
6303
6456
  }
6304
6457
  const traceId = import_keys15.PublicKey.random().toHex();
6305
- import_log17.log.trace("dxos.client-services.host.open", import_protocols15.trace.begin({
6458
+ import_log19.log.trace("dxos.client-services.host.open", import_protocols15.trace.begin({
6306
6459
  id: traceId
6307
6460
  }), {
6308
- F: __dxlog_file21,
6461
+ F: __dxlog_file22,
6309
6462
  L: 227,
6310
6463
  S: this,
6311
6464
  C: (f, a) => f(...a)
6312
6465
  });
6313
- (0, import_invariant18.invariant)(this._config, "config not set", {
6314
- F: __dxlog_file21,
6466
+ (0, import_invariant19.invariant)(this._config, "config not set", {
6467
+ F: __dxlog_file22,
6315
6468
  L: 229,
6316
6469
  S: this,
6317
6470
  A: [
@@ -6319,8 +6472,8 @@ var ClientServicesHost = class {
6319
6472
  "'config not set'"
6320
6473
  ]
6321
6474
  });
6322
- (0, import_invariant18.invariant)(this._storage, "storage not set", {
6323
- F: __dxlog_file21,
6475
+ (0, import_invariant19.invariant)(this._storage, "storage not set", {
6476
+ F: __dxlog_file22,
6324
6477
  L: 230,
6325
6478
  S: this,
6326
6479
  A: [
@@ -6328,8 +6481,8 @@ var ClientServicesHost = class {
6328
6481
  "'storage not set'"
6329
6482
  ]
6330
6483
  });
6331
- (0, import_invariant18.invariant)(this._signalManager, "signal manager not set", {
6332
- F: __dxlog_file21,
6484
+ (0, import_invariant19.invariant)(this._signalManager, "signal manager not set", {
6485
+ F: __dxlog_file22,
6333
6486
  L: 231,
6334
6487
  S: this,
6335
6488
  A: [
@@ -6337,8 +6490,8 @@ var ClientServicesHost = class {
6337
6490
  "'signal manager not set'"
6338
6491
  ]
6339
6492
  });
6340
- (0, import_invariant18.invariant)(this._networkManager, "network manager not set", {
6341
- F: __dxlog_file21,
6493
+ (0, import_invariant19.invariant)(this._networkManager, "network manager not set", {
6494
+ F: __dxlog_file22,
6342
6495
  L: 232,
6343
6496
  S: this,
6344
6497
  A: [
@@ -6347,10 +6500,10 @@ var ClientServicesHost = class {
6347
6500
  ]
6348
6501
  });
6349
6502
  this._opening = true;
6350
- (0, import_log17.log)("opening...", {
6503
+ (0, import_log19.log)("opening...", {
6351
6504
  lockKey: this._resourceLock?.lockKey
6352
6505
  }, {
6353
- F: __dxlog_file21,
6506
+ F: __dxlog_file22,
6354
6507
  L: 235,
6355
6508
  S: this,
6356
6509
  C: (f, a) => f(...a)
@@ -6401,18 +6554,18 @@ var ClientServicesHost = class {
6401
6554
  this._open = true;
6402
6555
  this._statusUpdate.emit();
6403
6556
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
6404
- (0, import_log17.log)("opened", {
6557
+ (0, import_log19.log)("opened", {
6405
6558
  deviceKey
6406
6559
  }, {
6407
- F: __dxlog_file21,
6560
+ F: __dxlog_file22,
6408
6561
  L: 314,
6409
6562
  S: this,
6410
6563
  C: (f, a) => f(...a)
6411
6564
  });
6412
- import_log17.log.trace("dxos.client-services.host.open", import_protocols15.trace.end({
6565
+ import_log19.log.trace("dxos.client-services.host.open", import_protocols15.trace.end({
6413
6566
  id: traceId
6414
6567
  }), {
6415
- F: __dxlog_file21,
6568
+ F: __dxlog_file22,
6416
6569
  L: 315,
6417
6570
  S: this,
6418
6571
  C: (f, a) => f(...a)
@@ -6423,10 +6576,10 @@ var ClientServicesHost = class {
6423
6576
  return;
6424
6577
  }
6425
6578
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
6426
- (0, import_log17.log)("closing...", {
6579
+ (0, import_log19.log)("closing...", {
6427
6580
  deviceKey
6428
6581
  }, {
6429
- F: __dxlog_file21,
6582
+ F: __dxlog_file22,
6430
6583
  L: 326,
6431
6584
  S: this,
6432
6585
  C: (f, a) => f(...a)
@@ -6441,10 +6594,10 @@ var ClientServicesHost = class {
6441
6594
  await this._level?.close();
6442
6595
  this._open = false;
6443
6596
  this._statusUpdate.emit();
6444
- (0, import_log17.log)("closed", {
6597
+ (0, import_log19.log)("closed", {
6445
6598
  deviceKey
6446
6599
  }, {
6447
- F: __dxlog_file21,
6600
+ F: __dxlog_file22,
6448
6601
  L: 335,
6449
6602
  S: this,
6450
6603
  C: (f, a) => f(...a)
@@ -6452,32 +6605,32 @@ var ClientServicesHost = class {
6452
6605
  }
6453
6606
  async reset() {
6454
6607
  const traceId = import_keys15.PublicKey.random().toHex();
6455
- import_log17.log.trace("dxos.sdk.client-services-host.reset", import_protocols15.trace.begin({
6608
+ import_log19.log.trace("dxos.sdk.client-services-host.reset", import_protocols15.trace.begin({
6456
6609
  id: traceId
6457
6610
  }), {
6458
- F: __dxlog_file21,
6611
+ F: __dxlog_file22,
6459
6612
  L: 340,
6460
6613
  S: this,
6461
6614
  C: (f, a) => f(...a)
6462
6615
  });
6463
- import_log17.log.info("resetting...", void 0, {
6464
- F: __dxlog_file21,
6616
+ import_log19.log.info("resetting...", void 0, {
6617
+ F: __dxlog_file22,
6465
6618
  L: 342,
6466
6619
  S: this,
6467
6620
  C: (f, a) => f(...a)
6468
6621
  });
6469
6622
  await this._serviceContext?.close();
6470
6623
  await this._storage.reset();
6471
- import_log17.log.info("reset", void 0, {
6472
- F: __dxlog_file21,
6624
+ import_log19.log.info("reset", void 0, {
6625
+ F: __dxlog_file22,
6473
6626
  L: 345,
6474
6627
  S: this,
6475
6628
  C: (f, a) => f(...a)
6476
6629
  });
6477
- import_log17.log.trace("dxos.sdk.client-services-host.reset", import_protocols15.trace.end({
6630
+ import_log19.log.trace("dxos.sdk.client-services-host.reset", import_protocols15.trace.end({
6478
6631
  id: traceId
6479
6632
  }), {
6480
- F: __dxlog_file21,
6633
+ F: __dxlog_file22,
6481
6634
  L: 346,
6482
6635
  S: this,
6483
6636
  C: (f, a) => f(...a)
@@ -6497,11 +6650,11 @@ _ts_decorate8([
6497
6650
  import_tracing9.trace.info()
6498
6651
  ], ClientServicesHost.prototype, "_open", void 0);
6499
6652
  _ts_decorate8([
6500
- import_async18.synchronized,
6653
+ import_async20.synchronized,
6501
6654
  import_tracing9.trace.span()
6502
6655
  ], ClientServicesHost.prototype, "open", null);
6503
6656
  _ts_decorate8([
6504
- import_async18.synchronized,
6657
+ import_async20.synchronized,
6505
6658
  import_tracing9.trace.span()
6506
6659
  ], ClientServicesHost.prototype, "close", null);
6507
6660
  ClientServicesHost = _ts_decorate8([
@@ -6537,7 +6690,6 @@ ClientServicesHost = _ts_decorate8([
6537
6690
  createDiagnostics,
6538
6691
  createLevel,
6539
6692
  createStorageObjects,
6540
- findPropertiesObject,
6541
6693
  getNetworkPeers,
6542
6694
  isLocked,
6543
6695
  subscribeToFeedBlocks,
@@ -6548,4 +6700,4 @@ ClientServicesHost = _ts_decorate8([
6548
6700
  subscribeToSpaces,
6549
6701
  subscribeToSwarmInfo
6550
6702
  });
6551
- //# sourceMappingURL=chunk-STUWVNPH.cjs.map
6703
+ //# sourceMappingURL=chunk-OD7BTUYY.cjs.map