@dxos/client-services 0.5.9-main.bf0ae3e → 0.5.9-main.c2c4258

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 (51) hide show
  1. package/dist/lib/browser/{chunk-4IR3JP4U.mjs → chunk-YUU4EUWY.mjs} +1347 -822
  2. package/dist/lib/browser/chunk-YUU4EUWY.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +13 -4
  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 +10 -3
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +1 -1
  8. package/dist/lib/node/{chunk-ZBIDLLZ4.cjs → chunk-6FKYSRZO.cjs} +1481 -959
  9. package/dist/lib/node/chunk-6FKYSRZO.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +53 -44
  11. package/dist/lib/node/index.cjs.map +1 -1
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/packlets/testing/index.cjs +17 -10
  14. package/dist/lib/node/packlets/testing/index.cjs.map +1 -1
  15. package/dist/types/src/packlets/identity/contacts-service.d.ts +14 -0
  16. package/dist/types/src/packlets/identity/contacts-service.d.ts.map +1 -0
  17. package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
  18. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  19. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  20. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  21. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts +4 -1
  22. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts.map +1 -1
  23. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +10 -1
  24. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  25. package/dist/types/src/packlets/spaces/data-space.d.ts +9 -9
  26. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  27. package/dist/types/src/packlets/spaces/epoch-migrations.d.ts +23 -0
  28. package/dist/types/src/packlets/spaces/epoch-migrations.d.ts.map +1 -0
  29. package/dist/types/src/packlets/spaces/spaces-service.d.ts +5 -2
  30. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  31. package/dist/types/src/packlets/storage/index.d.ts +1 -0
  32. package/dist/types/src/packlets/storage/index.d.ts.map +1 -1
  33. package/dist/types/src/packlets/storage/profile-archive.d.ts +14 -0
  34. package/dist/types/src/packlets/storage/profile-archive.d.ts.map +1 -0
  35. package/dist/types/src/version.d.ts +1 -1
  36. package/package.json +36 -36
  37. package/src/packlets/identity/contacts-service.ts +85 -0
  38. package/src/packlets/identity/identity-service.ts +33 -7
  39. package/src/packlets/invitations/invitations-handler.ts +13 -5
  40. package/src/packlets/invitations/space-invitation-protocol.ts +11 -32
  41. package/src/packlets/services/service-host.ts +12 -4
  42. package/src/packlets/spaces/automerge-space-state.ts +11 -2
  43. package/src/packlets/spaces/data-space-manager.ts +90 -16
  44. package/src/packlets/spaces/data-space.ts +76 -148
  45. package/src/packlets/spaces/epoch-migrations.ts +135 -0
  46. package/src/packlets/spaces/spaces-service.ts +54 -4
  47. package/src/packlets/storage/index.ts +1 -0
  48. package/src/packlets/storage/profile-archive.ts +97 -0
  49. package/src/version.ts +1 -1
  50. package/dist/lib/browser/chunk-4IR3JP4U.mjs.map +0 -7
  51. package/dist/lib/node/chunk-ZBIDLLZ4.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_ZBIDLLZ4_exports = {};
30
- __export(chunk_ZBIDLLZ4_exports, {
29
+ var chunk_6FKYSRZO_exports = {};
30
+ __export(chunk_6FKYSRZO_exports, {
31
31
  ClientRpcServer: () => ClientRpcServer,
32
32
  ClientServicesHost: () => ClientServicesHost,
33
33
  ClientServicesProviderResource: () => ClientServicesProviderResource,
@@ -56,8 +56,11 @@ __export(chunk_ZBIDLLZ4_exports, {
56
56
  createDiagnostics: () => createDiagnostics,
57
57
  createLevel: () => createLevel,
58
58
  createStorageObjects: () => createStorageObjects,
59
- findPropertiesObject: () => findPropertiesObject,
59
+ decodeProfileArchive: () => decodeProfileArchive,
60
+ encodeProfileArchive: () => encodeProfileArchive,
61
+ exportProfileData: () => exportProfileData,
60
62
  getNetworkPeers: () => getNetworkPeers,
63
+ importProfileData: () => importProfileData,
61
64
  isLocked: () => isLocked,
62
65
  subscribeToFeedBlocks: () => subscribeToFeedBlocks,
63
66
  subscribeToFeeds: () => subscribeToFeeds,
@@ -67,7 +70,7 @@ __export(chunk_ZBIDLLZ4_exports, {
67
70
  subscribeToSpaces: () => subscribeToSpaces,
68
71
  subscribeToSwarmInfo: () => subscribeToSwarmInfo
69
72
  });
70
- module.exports = __toCommonJS(chunk_ZBIDLLZ4_exports);
73
+ module.exports = __toCommonJS(chunk_6FKYSRZO_exports);
71
74
  var import_async = require("@dxos/async");
72
75
  var import_codec_protobuf = require("@dxos/codec-protobuf");
73
76
  var import_feed_store = require("@dxos/feed-store");
@@ -127,186 +130,212 @@ var import_teleport_extension_gossip = require("@dxos/teleport-extension-gossip"
127
130
  var import_timeframe2 = require("@dxos/timeframe");
128
131
  var import_tracing4 = require("@dxos/tracing");
129
132
  var import_util3 = require("@dxos/util");
133
+ var import_async8 = require("@dxos/async");
130
134
  var import_codec_protobuf9 = require("@dxos/codec-protobuf");
131
135
  var import_context4 = require("@dxos/context");
132
136
  var import_credentials8 = require("@dxos/credentials");
133
137
  var import_debug2 = require("@dxos/debug");
134
138
  var import_invariant4 = require("@dxos/invariant");
139
+ var import_log5 = require("@dxos/log");
135
140
  var import_services4 = require("@dxos/protocols/proto/dxos/client/services");
141
+ var import_util4 = require("@dxos/util");
136
142
  var import_invariant5 = require("@dxos/invariant");
137
143
  var import_protocols4 = require("@dxos/protocols");
138
144
  var import_services5 = require("@dxos/protocols/proto/dxos/client/services");
139
- var import_async8 = require("@dxos/async");
145
+ var import_async9 = require("@dxos/async");
140
146
  var import_client_protocol2 = require("@dxos/client-protocol");
141
147
  var import_context5 = require("@dxos/context");
142
148
  var import_crypto = require("@dxos/crypto");
143
149
  var import_invariant6 = require("@dxos/invariant");
144
150
  var import_keys6 = require("@dxos/keys");
145
- var import_log5 = require("@dxos/log");
151
+ var import_log6 = require("@dxos/log");
146
152
  var import_network_manager = require("@dxos/network-manager");
147
153
  var import_protocols5 = require("@dxos/protocols");
148
154
  var import_services6 = require("@dxos/protocols/proto/dxos/client/services");
149
155
  var import_invitations = require("@dxos/protocols/proto/dxos/halo/invitations");
150
156
  var import_invitations2 = require("@dxos/protocols/proto/dxos/halo/invitations");
151
- var import_util4 = require("@dxos/util");
152
- var import_async9 = require("@dxos/async");
157
+ var import_util5 = require("@dxos/util");
158
+ var import_async10 = require("@dxos/async");
153
159
  var import_context6 = require("@dxos/context");
154
160
  var import_invariant7 = require("@dxos/invariant");
155
- var import_log6 = require("@dxos/log");
161
+ var import_log7 = require("@dxos/log");
156
162
  var import_protocols6 = require("@dxos/protocols");
157
163
  var import_invitations3 = require("@dxos/protocols/proto/dxos/halo/invitations");
158
164
  var import_teleport = require("@dxos/teleport");
159
165
  var import_context7 = require("@dxos/context");
160
166
  var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
161
- var import_async10 = require("@dxos/async");
167
+ var import_async11 = require("@dxos/async");
162
168
  var import_context8 = require("@dxos/context");
163
169
  var import_crypto2 = require("@dxos/crypto");
164
170
  var import_invariant8 = require("@dxos/invariant");
165
171
  var import_keys7 = require("@dxos/keys");
166
- var import_log7 = require("@dxos/log");
172
+ var import_log8 = require("@dxos/log");
167
173
  var import_protocols7 = require("@dxos/protocols");
168
174
  var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
169
175
  var import_invitations4 = require("@dxos/protocols/proto/dxos/halo/invitations");
170
176
  var import_teleport2 = require("@dxos/teleport");
171
177
  var import_invariant9 = require("@dxos/invariant");
172
178
  var import_keys8 = require("@dxos/keys");
173
- var import_log8 = require("@dxos/log");
179
+ var import_log9 = require("@dxos/log");
174
180
  var import_invitations5 = require("@dxos/protocols/proto/dxos/halo/invitations");
175
- var import_util5 = require("@dxos/util");
181
+ var import_util6 = require("@dxos/util");
176
182
  var import_codec_protobuf10 = require("@dxos/codec-protobuf");
177
183
  var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
178
184
  var import_credentials9 = require("@dxos/credentials");
179
185
  var import_feed_store3 = require("@dxos/feed-store");
180
186
  var import_invariant10 = require("@dxos/invariant");
181
- var import_log9 = require("@dxos/log");
187
+ var import_log10 = require("@dxos/log");
182
188
  var import_protocols8 = require("@dxos/protocols");
183
189
  var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
184
190
  var import_credentials10 = require("@dxos/protocols/proto/dxos/halo/credentials");
185
- var import_async11 = require("@dxos/async");
191
+ var import_async12 = require("@dxos/async");
186
192
  var import_client_protocol3 = require("@dxos/client-protocol");
187
193
  var import_context9 = require("@dxos/context");
188
194
  var import_credentials11 = require("@dxos/credentials");
189
195
  var import_echo_pipeline = require("@dxos/echo-pipeline");
190
196
  var import_invariant11 = require("@dxos/invariant");
191
197
  var import_keys9 = require("@dxos/keys");
192
- var import_log10 = require("@dxos/log");
198
+ var import_log11 = require("@dxos/log");
193
199
  var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
194
200
  var import_credentials12 = require("@dxos/protocols/proto/dxos/halo/credentials");
195
- var import_async12 = require("@dxos/async");
201
+ var import_async13 = require("@dxos/async");
196
202
  var import_client_protocol4 = require("@dxos/client-protocol");
197
203
  var import_context10 = require("@dxos/context");
198
204
  var import_debug3 = require("@dxos/debug");
199
205
  var import_echo_pipeline2 = require("@dxos/echo-pipeline");
200
- var import_echo_schema = require("@dxos/echo-schema");
206
+ var import_echo_protocol = require("@dxos/echo-protocol");
201
207
  var import_invariant12 = require("@dxos/invariant");
202
208
  var import_keys10 = require("@dxos/keys");
203
- var import_log11 = require("@dxos/log");
209
+ var import_log12 = require("@dxos/log");
204
210
  var import_protocols9 = require("@dxos/protocols");
205
211
  var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
206
212
  var import_credentials13 = require("@dxos/protocols/proto/dxos/halo/credentials");
207
213
  var import_timeframe3 = require("@dxos/timeframe");
208
214
  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");
215
+ var import_util7 = require("@dxos/util");
212
216
  var import_async14 = require("@dxos/async");
213
217
  var import_context11 = require("@dxos/context");
218
+ var import_credentials14 = require("@dxos/credentials");
219
+ var import_async15 = require("@dxos/async");
220
+ var import_automerge = require("@dxos/automerge/automerge");
221
+ var import_context12 = require("@dxos/context");
222
+ var import_echo_db = require("@dxos/echo-db");
223
+ var import_echo_pipeline3 = require("@dxos/echo-pipeline");
224
+ var import_echo_schema = require("@dxos/echo-schema");
214
225
  var import_invariant13 = require("@dxos/invariant");
226
+ var import_log13 = require("@dxos/log");
227
+ var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
228
+ var import_util8 = require("@dxos/util");
229
+ var import_async16 = require("@dxos/async");
230
+ var import_context13 = require("@dxos/context");
231
+ var import_invariant14 = require("@dxos/invariant");
215
232
  var import_keys11 = require("@dxos/keys");
216
- var import_log12 = require("@dxos/log");
233
+ var import_log14 = require("@dxos/log");
217
234
  var import_protocols10 = require("@dxos/protocols");
218
235
  var import_teleport3 = require("@dxos/teleport");
219
- var import_util7 = require("@dxos/util");
220
- var import_async15 = require("@dxos/async");
236
+ var import_util9 = require("@dxos/util");
237
+ var import_async17 = require("@dxos/async");
221
238
  var import_client_protocol5 = require("@dxos/client-protocol");
222
- var import_context12 = require("@dxos/context");
239
+ var import_context14 = require("@dxos/context");
223
240
  var import_credentials15 = require("@dxos/credentials");
224
- var import_echo_pipeline3 = require("@dxos/echo-pipeline");
225
- var import_echo_protocol = require("@dxos/echo-protocol");
241
+ var import_echo_db2 = require("@dxos/echo-db");
242
+ var import_echo_pipeline4 = require("@dxos/echo-pipeline");
243
+ var import_echo_pipeline5 = require("@dxos/echo-pipeline");
244
+ var import_echo_protocol2 = require("@dxos/echo-protocol");
226
245
  var import_echo_schema2 = require("@dxos/echo-schema");
227
- var import_invariant14 = require("@dxos/invariant");
246
+ var import_feed_store4 = require("@dxos/feed-store");
247
+ var import_invariant15 = require("@dxos/invariant");
228
248
  var import_keys12 = require("@dxos/keys");
229
- var import_log13 = require("@dxos/log");
249
+ var import_log15 = require("@dxos/log");
230
250
  var import_protocols11 = require("@dxos/protocols");
231
- var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
251
+ var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
232
252
  var import_credentials16 = require("@dxos/protocols/proto/dxos/halo/credentials");
233
253
  var import_teleport_extension_gossip2 = require("@dxos/teleport-extension-gossip");
234
254
  var import_tracing6 = require("@dxos/tracing");
235
- var import_util8 = require("@dxos/util");
255
+ var import_util10 = require("@dxos/util");
236
256
  var import_credentials17 = require("@dxos/credentials");
237
257
  var import_debug4 = require("@dxos/debug");
238
258
  var import_credentials18 = require("@dxos/protocols/proto/dxos/halo/credentials");
239
259
  var import_timeframe4 = require("@dxos/timeframe");
240
- var import_async16 = require("@dxos/async");
260
+ var import_async18 = require("@dxos/async");
241
261
  var import_codec_protobuf11 = require("@dxos/codec-protobuf");
242
262
  var import_credentials19 = require("@dxos/credentials");
243
263
  var import_debug5 = require("@dxos/debug");
244
- var import_feed_store4 = require("@dxos/feed-store");
245
- var import_invariant15 = require("@dxos/invariant");
246
- var import_log14 = require("@dxos/log");
264
+ var import_feed_store5 = require("@dxos/feed-store");
265
+ var import_invariant16 = require("@dxos/invariant");
266
+ var import_log16 = require("@dxos/log");
247
267
  var import_protocols12 = require("@dxos/protocols");
248
- var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
268
+ var import_services15 = require("@dxos/protocols/proto/dxos/client/services");
249
269
  var import_tracing7 = require("@dxos/tracing");
250
- var import_async17 = require("@dxos/async");
251
- var import_context13 = require("@dxos/context");
270
+ var import_async19 = require("@dxos/async");
271
+ var import_context15 = require("@dxos/context");
252
272
  var import_credentials20 = require("@dxos/credentials");
253
273
  var import_debug6 = require("@dxos/debug");
254
- var import_echo_db = require("@dxos/echo-db");
255
- var import_echo_pipeline4 = require("@dxos/echo-pipeline");
256
- var import_feed_store5 = require("@dxos/feed-store");
257
- var import_invariant16 = require("@dxos/invariant");
274
+ var import_echo_db3 = require("@dxos/echo-db");
275
+ var import_echo_pipeline6 = require("@dxos/echo-pipeline");
276
+ var import_feed_store6 = require("@dxos/feed-store");
277
+ var import_invariant17 = require("@dxos/invariant");
258
278
  var import_keyring = require("@dxos/keyring");
259
279
  var import_keys13 = require("@dxos/keys");
260
- var import_log15 = require("@dxos/log");
280
+ var import_log17 = require("@dxos/log");
261
281
  var import_protocols13 = require("@dxos/protocols");
262
- var import_services15 = require("@dxos/protocols/proto/dxos/client/services");
282
+ var import_services16 = require("@dxos/protocols/proto/dxos/client/services");
263
283
  var import_teleport_extension_object_sync = require("@dxos/teleport-extension-object-sync");
264
284
  var import_tracing8 = require("@dxos/tracing");
265
- var import_util9 = require("@dxos/util");
266
- var import_invariant17 = require("@dxos/invariant");
285
+ var import_util11 = require("@dxos/util");
286
+ var import_invariant18 = require("@dxos/invariant");
267
287
  var import_lock_file = require("@dxos/lock-file");
268
- var import_log16 = require("@dxos/log");
288
+ var import_log18 = require("@dxos/log");
269
289
  var import_protocols14 = require("@dxos/protocols");
270
290
  var import_config = require("@dxos/protocols/proto/dxos/config");
271
291
  var import_random_access_storage = require("@dxos/random-access-storage");
272
292
  var import_client_protocol6 = require("@dxos/client-protocol");
273
293
  var import_config2 = require("@dxos/protocols/proto/dxos/config");
274
- var import_util10 = require("@dxos/util");
294
+ var import_util12 = require("@dxos/util");
275
295
  var import_node_path = __toESM(require("node:path"));
276
296
  var import_keys14 = require("@dxos/keys");
277
297
  var import_kv_store = require("@dxos/kv-store");
278
- var import_async18 = require("@dxos/async");
298
+ var import_automerge_repo = require("@dxos/automerge/automerge-repo");
299
+ var import_invariant19 = require("@dxos/invariant");
300
+ var import_log19 = require("@dxos/log");
301
+ var import_protocols15 = require("@dxos/protocols");
302
+ var import_util13 = require("@dxos/util");
303
+ var import_async20 = require("@dxos/async");
279
304
  var import_client_protocol7 = require("@dxos/client-protocol");
280
- var import_context14 = require("@dxos/context");
281
- var import_invariant18 = require("@dxos/invariant");
305
+ var import_context16 = require("@dxos/context");
306
+ var import_invariant20 = require("@dxos/invariant");
282
307
  var import_keys15 = require("@dxos/keys");
283
- var import_log17 = require("@dxos/log");
308
+ var import_log20 = require("@dxos/log");
284
309
  var import_messaging = require("@dxos/messaging");
285
310
  var import_network_manager2 = require("@dxos/network-manager");
286
- var import_protocols15 = require("@dxos/protocols");
287
- var import_services16 = require("@dxos/protocols/proto/dxos/client/services");
311
+ var import_protocols16 = require("@dxos/protocols");
312
+ var import_services17 = require("@dxos/protocols/proto/dxos/client/services");
288
313
  var import_tracing9 = require("@dxos/tracing");
289
314
  var import_websocket_rpc = require("@dxos/websocket-rpc");
290
- var import_async19 = require("@dxos/async");
315
+ var import_async21 = require("@dxos/async");
291
316
  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");
317
+ var import_invariant21 = require("@dxos/invariant");
295
318
  var import_services18 = require("@dxos/protocols/proto/dxos/client/services");
319
+ var import_config3 = require("@dxos/config");
320
+ var import_services19 = require("@dxos/protocols/proto/dxos/client/services");
296
321
  var import_tracing10 = require("@dxos/tracing");
297
- var import_util11 = require("@dxos/util");
322
+ var import_util14 = require("@dxos/util");
298
323
  var import_keys16 = require("@dxos/keys");
299
- var import_util12 = require("@dxos/util");
300
- var import_async20 = require("@dxos/async");
324
+ var import_util15 = require("@dxos/util");
325
+ var import_async22 = require("@dxos/async");
301
326
  var import_codec_protobuf13 = require("@dxos/codec-protobuf");
302
327
  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");
328
+ var import_util16 = require("@dxos/util");
329
+ var import_async23 = require("@dxos/async");
306
330
  var import_codec_protobuf14 = require("@dxos/codec-protobuf");
307
- var import_codec_protobuf15 = require("@dxos/codec-protobuf");
331
+ var import_keys18 = require("@dxos/keys");
332
+ var import_log21 = require("@dxos/log");
308
333
  var import_services20 = require("@dxos/protocols/proto/dxos/client/services");
309
- var import_util14 = require("@dxos/util");
334
+ var import_util17 = require("@dxos/util");
335
+ var import_codec_protobuf15 = require("@dxos/codec-protobuf");
336
+ var import_codec_protobuf16 = require("@dxos/codec-protobuf");
337
+ var import_services21 = require("@dxos/protocols/proto/dxos/client/services");
338
+ var import_util18 = require("@dxos/util");
310
339
  var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
311
340
  return new import_codec_protobuf.Stream(({ next }) => {
312
341
  const subscriptions = new import_async.EventSubscriptions();
@@ -374,6 +403,7 @@ var subscribeToFeedBlocks = ({ feedStore }, { feedKey, maxBlocks = 10 }) => {
374
403
  };
375
404
  });
376
405
  };
406
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devtools/network.ts";
377
407
  var subscribeToNetworkStatus = ({ signalManager }) => new import_codec_protobuf2.Stream(({ next, close }) => {
378
408
  const update = () => {
379
409
  try {
@@ -389,7 +419,10 @@ var subscribeToNetworkStatus = ({ signalManager }) => new import_codec_protobuf2
389
419
  update();
390
420
  });
391
421
  var subscribeToSignal = ({ signalManager }) => new import_codec_protobuf2.Stream(({ next }) => {
392
- const ctx = new import_context.Context();
422
+ const ctx = new import_context.Context(void 0, {
423
+ F: __dxlog_file,
424
+ L: 36
425
+ });
393
426
  signalManager.onMessage.on(ctx, (message) => {
394
427
  next({
395
428
  message: {
@@ -617,7 +650,7 @@ var DevtoolsServiceImpl = class {
617
650
  });
618
651
  }
619
652
  };
620
- var DXOS_VERSION = "0.5.9-main.bf0ae3e";
653
+ var DXOS_VERSION = "0.5.9-main.c2c4258";
621
654
  var getPlatform = () => {
622
655
  if (process.browser) {
623
656
  if (typeof window !== "undefined") {
@@ -645,7 +678,7 @@ var getPlatform = () => {
645
678
  };
646
679
  }
647
680
  };
648
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts";
681
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts";
649
682
  var DEFAULT_TIMEOUT = 1e3;
650
683
  var createDiagnostics = async (clientServices, serviceContext, config) => {
651
684
  const diagnostics = {
@@ -662,7 +695,7 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
662
695
  await Promise.all([
663
696
  (async () => {
664
697
  (0, import_invariant.invariant)(clientServices.LoggingService, "SystemService is not available.", {
665
- F: __dxlog_file,
698
+ F: __dxlog_file2,
666
699
  L: 110,
667
700
  S: void 0,
668
701
  A: [
@@ -851,7 +884,7 @@ _ts_decorate([
851
884
  ClientRpcServer = _ts_decorate([
852
885
  import_tracing2.trace.resource()
853
886
  ], ClientRpcServer);
854
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/authenticator.ts";
887
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/authenticator.ts";
855
888
  var Credential = import_protocols2.schema.getCodecForType("dxos.halo.credentials.Credential");
856
889
  var createAuthProvider = (signer) => async (nonce) => {
857
890
  const credential = await signer.createCredential({
@@ -866,7 +899,10 @@ var createAuthProvider = (signer) => async (nonce) => {
866
899
  var TrustedKeySetAuthVerifier = class {
867
900
  constructor(_params) {
868
901
  this._params = _params;
869
- this._ctx = new import_context2.Context();
902
+ this._ctx = new import_context2.Context(void 0, {
903
+ F: __dxlog_file3,
904
+ L: 45
905
+ });
870
906
  }
871
907
  async close() {
872
908
  await this._ctx.dispose();
@@ -877,7 +913,7 @@ var TrustedKeySetAuthVerifier = class {
877
913
  (0, import_log.log)("authenticating...", {
878
914
  credential
879
915
  }, {
880
- F: __dxlog_file2,
916
+ F: __dxlog_file3,
881
917
  L: 56,
882
918
  S: this,
883
919
  C: (f, a) => f(...a)
@@ -887,7 +923,7 @@ var TrustedKeySetAuthVerifier = class {
887
923
  (0, import_log.log)("Invalid credential", {
888
924
  result
889
925
  }, {
890
- F: __dxlog_file2,
926
+ F: __dxlog_file3,
891
927
  L: 60,
892
928
  S: this,
893
929
  C: (f, a) => f(...a)
@@ -899,7 +935,7 @@ var TrustedKeySetAuthVerifier = class {
899
935
  nonce,
900
936
  credential
901
937
  }, {
902
- F: __dxlog_file2,
938
+ F: __dxlog_file3,
903
939
  L: 65,
904
940
  S: this,
905
941
  C: (f, a) => f(...a)
@@ -910,7 +946,7 @@ var TrustedKeySetAuthVerifier = class {
910
946
  (0, import_log.log)("key is not currently in trusted set, waiting...", {
911
947
  key: credential.issuer
912
948
  }, {
913
- F: __dxlog_file2,
949
+ F: __dxlog_file3,
914
950
  L: 70,
915
951
  S: this,
916
952
  C: (f, a) => f(...a)
@@ -926,7 +962,7 @@ var TrustedKeySetAuthVerifier = class {
926
962
  (0, import_log.log)("auth success", {
927
963
  key: credential.issuer
928
964
  }, {
929
- F: __dxlog_file2,
965
+ F: __dxlog_file3,
930
966
  L: 81,
931
967
  S: this,
932
968
  C: (f, a) => f(...a)
@@ -936,7 +972,7 @@ var TrustedKeySetAuthVerifier = class {
936
972
  (0, import_log.log)("key is not currently in trusted set, waiting...", {
937
973
  key: credential.issuer
938
974
  }, {
939
- F: __dxlog_file2,
975
+ F: __dxlog_file3,
940
976
  L: 84,
941
977
  S: this,
942
978
  C: (f, a) => f(...a)
@@ -959,7 +995,7 @@ var TrustedKeySetAuthVerifier = class {
959
995
  return deviceSet.has(deviceKey);
960
996
  }
961
997
  };
962
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/default-space-state-machine.ts";
998
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/default-space-state-machine.ts";
963
999
  var DefaultSpaceStateMachine = class {
964
1000
  constructor(_params) {
965
1001
  this._params = _params;
@@ -976,7 +1012,7 @@ var DefaultSpaceStateMachine = class {
976
1012
  expectedIdentity: this._params.identityKey,
977
1013
  credential
978
1014
  }, {
979
- F: __dxlog_file3,
1015
+ F: __dxlog_file4,
980
1016
  L: 32,
981
1017
  S: this,
982
1018
  C: (f, a) => f(...a)
@@ -987,7 +1023,7 @@ var DefaultSpaceStateMachine = class {
987
1023
  import_log3.log.warn("Invalid default space id", {
988
1024
  id: assertion.spaceId
989
1025
  }, {
990
- F: __dxlog_file3,
1026
+ F: __dxlog_file4,
991
1027
  L: 36,
992
1028
  S: this,
993
1029
  C: (f, a) => f(...a)
@@ -1010,7 +1046,7 @@ function _ts_decorate2(decorators, target, key, desc) {
1010
1046
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1011
1047
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1012
1048
  }
1013
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity.ts";
1049
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity.ts";
1014
1050
  var Identity = class {
1015
1051
  constructor({ space, signer, identityKey, deviceKey, presence }) {
1016
1052
  this.stateUpdate = new import_async6.Event();
@@ -1022,7 +1058,7 @@ var Identity = class {
1022
1058
  import_log2.log.trace("dxos.halo.device", {
1023
1059
  deviceKey
1024
1060
  }, {
1025
- F: __dxlog_file4,
1061
+ F: __dxlog_file5,
1026
1062
  L: 70,
1027
1063
  S: this,
1028
1064
  C: (f, a) => f(...a)
@@ -1101,7 +1137,7 @@ var Identity = class {
1101
1137
  */
1102
1138
  getIdentityCredentialSigner() {
1103
1139
  (0, import_invariant2.invariant)(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.", {
1104
- F: __dxlog_file4,
1140
+ F: __dxlog_file5,
1105
1141
  L: 159,
1106
1142
  S: this,
1107
1143
  A: [
@@ -1145,7 +1181,7 @@ var Identity = class {
1145
1181
  controlFeedKey,
1146
1182
  dataFeedKey
1147
1183
  }, {
1148
- F: __dxlog_file4,
1184
+ F: __dxlog_file5,
1149
1185
  L: 184,
1150
1186
  S: this,
1151
1187
  C: (f, a) => f(...a)
@@ -1206,7 +1242,7 @@ function _ts_decorate3(decorators, target, key, desc) {
1206
1242
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1207
1243
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1208
1244
  }
1209
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-manager.ts";
1245
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-manager.ts";
1210
1246
  var DEVICE_PRESENCE_ANNOUNCE_INTERVAL = 1e4;
1211
1247
  var DEVICE_PRESENCE_OFFLINE_TIMEOUT = 2e4;
1212
1248
  var IdentityManager = class {
@@ -1230,7 +1266,7 @@ var IdentityManager = class {
1230
1266
  import_log4.log.trace("dxos.halo.identity-manager.open", import_protocols3.trace.begin({
1231
1267
  id: traceId
1232
1268
  }), {
1233
- F: __dxlog_file5,
1269
+ F: __dxlog_file6,
1234
1270
  L: 104,
1235
1271
  S: this,
1236
1272
  C: (f, a) => f(...a)
@@ -1239,7 +1275,7 @@ var IdentityManager = class {
1239
1275
  (0, import_log4.log)("identity record", {
1240
1276
  identityRecord
1241
1277
  }, {
1242
- F: __dxlog_file5,
1278
+ F: __dxlog_file6,
1243
1279
  L: 107,
1244
1280
  S: this,
1245
1281
  C: (f, a) => f(...a)
@@ -1252,7 +1288,7 @@ var IdentityManager = class {
1252
1288
  identityKey: identityRecord.identityKey,
1253
1289
  displayName: this._identity.profileDocument?.displayName
1254
1290
  }, {
1255
- F: __dxlog_file5,
1291
+ F: __dxlog_file6,
1256
1292
  L: 112,
1257
1293
  S: this,
1258
1294
  C: (f, a) => f(...a)
@@ -1262,18 +1298,21 @@ var IdentityManager = class {
1262
1298
  import_log4.log.trace("dxos.halo.identity-manager.open", import_protocols3.trace.end({
1263
1299
  id: traceId
1264
1300
  }), {
1265
- F: __dxlog_file5,
1301
+ F: __dxlog_file6,
1266
1302
  L: 119,
1267
1303
  S: this,
1268
1304
  C: (f, a) => f(...a)
1269
1305
  });
1270
1306
  }
1271
1307
  async close() {
1272
- await this._identity?.close(new import_context3.Context());
1308
+ await this._identity?.close(new import_context3.Context(void 0, {
1309
+ F: __dxlog_file6,
1310
+ L: 123
1311
+ }));
1273
1312
  }
1274
1313
  async createIdentity({ displayName, deviceProfile } = {}) {
1275
1314
  (0, import_invariant3.invariant)(!this._identity, "Identity already exists.", {
1276
- F: __dxlog_file5,
1315
+ F: __dxlog_file6,
1277
1316
  L: 128,
1278
1317
  S: this,
1279
1318
  A: [
@@ -1282,7 +1321,7 @@ var IdentityManager = class {
1282
1321
  ]
1283
1322
  });
1284
1323
  (0, import_log4.log)("creating identity...", void 0, {
1285
- F: __dxlog_file5,
1324
+ F: __dxlog_file6,
1286
1325
  L: 129,
1287
1326
  S: this,
1288
1327
  C: (f, a) => f(...a)
@@ -1299,11 +1338,14 @@ var IdentityManager = class {
1299
1338
  }
1300
1339
  };
1301
1340
  const identity = await this._constructIdentity(identityRecord);
1302
- await identity.open(new import_context3.Context());
1341
+ await identity.open(new import_context3.Context(void 0, {
1342
+ F: __dxlog_file6,
1343
+ L: 144
1344
+ }));
1303
1345
  {
1304
1346
  const generator = new import_credentials6.CredentialGenerator(this._keyring, identityRecord.identityKey, identityRecord.deviceKey);
1305
1347
  (0, import_invariant3.invariant)(identityRecord.haloSpace.genesisFeedKey, "Genesis feed key is required.", {
1306
- F: __dxlog_file5,
1348
+ F: __dxlog_file6,
1307
1349
  L: 148,
1308
1350
  S: this,
1309
1351
  A: [
@@ -1312,7 +1354,7 @@ var IdentityManager = class {
1312
1354
  ]
1313
1355
  });
1314
1356
  (0, import_invariant3.invariant)(identityRecord.haloSpace.dataFeedKey, "Data feed key is required.", {
1315
- F: __dxlog_file5,
1357
+ F: __dxlog_file6,
1316
1358
  L: 149,
1317
1359
  S: this,
1318
1360
  A: [
@@ -1351,7 +1393,7 @@ var IdentityManager = class {
1351
1393
  identityKey: identityRecord.identityKey,
1352
1394
  displayName: this._identity.profileDocument?.displayName
1353
1395
  }, {
1354
- F: __dxlog_file5,
1396
+ F: __dxlog_file6,
1355
1397
  L: 191,
1356
1398
  S: this,
1357
1399
  C: (f, a) => f(...a)
@@ -1362,7 +1404,7 @@ var IdentityManager = class {
1362
1404
  deviceKey: identity.deviceKey,
1363
1405
  profile: identity.profileDocument
1364
1406
  }, {
1365
- F: __dxlog_file5,
1407
+ F: __dxlog_file6,
1366
1408
  L: 197,
1367
1409
  S: this,
1368
1410
  C: (f, a) => f(...a)
@@ -1399,13 +1441,13 @@ var IdentityManager = class {
1399
1441
  (0, import_log4.log)("accepting identity", {
1400
1442
  params
1401
1443
  }, {
1402
- F: __dxlog_file5,
1444
+ F: __dxlog_file6,
1403
1445
  L: 235,
1404
1446
  S: this,
1405
1447
  C: (f, a) => f(...a)
1406
1448
  });
1407
1449
  (0, import_invariant3.invariant)(!this._identity, "Identity already exists.", {
1408
- F: __dxlog_file5,
1450
+ F: __dxlog_file6,
1409
1451
  L: 236,
1410
1452
  S: this,
1411
1453
  A: [
@@ -1425,7 +1467,10 @@ var IdentityManager = class {
1425
1467
  }
1426
1468
  };
1427
1469
  const identity = await this._constructIdentity(identityRecord);
1428
- await identity.open(new import_context3.Context());
1470
+ await identity.open(new import_context3.Context(void 0, {
1471
+ F: __dxlog_file6,
1472
+ L: 251
1473
+ }));
1429
1474
  this._identity = identity;
1430
1475
  await this._metadataStore.setIdentityRecord(identityRecord);
1431
1476
  await this._identity.ready();
@@ -1433,7 +1478,7 @@ var IdentityManager = class {
1433
1478
  identityKey: identityRecord.identityKey,
1434
1479
  displayName: this._identity.profileDocument?.displayName
1435
1480
  }, {
1436
- F: __dxlog_file5,
1481
+ F: __dxlog_file6,
1437
1482
  L: 255,
1438
1483
  S: this,
1439
1484
  C: (f, a) => f(...a)
@@ -1447,7 +1492,7 @@ var IdentityManager = class {
1447
1492
  identityKey: identity.identityKey,
1448
1493
  deviceKey: identity.deviceKey
1449
1494
  }, {
1450
- F: __dxlog_file5,
1495
+ F: __dxlog_file6,
1451
1496
  L: 265,
1452
1497
  S: this,
1453
1498
  C: (f, a) => f(...a)
@@ -1459,7 +1504,7 @@ var IdentityManager = class {
1459
1504
  */
1460
1505
  async updateProfile(profile) {
1461
1506
  (0, import_invariant3.invariant)(this._identity, "Identity not initialized.", {
1462
- F: __dxlog_file5,
1507
+ F: __dxlog_file6,
1463
1508
  L: 273,
1464
1509
  S: this,
1465
1510
  A: [
@@ -1490,7 +1535,7 @@ var IdentityManager = class {
1490
1535
  }
1491
1536
  async updateDeviceProfile(profile) {
1492
1537
  (0, import_invariant3.invariant)(this._identity, "Identity not initialized.", {
1493
- F: __dxlog_file5,
1538
+ F: __dxlog_file6,
1494
1539
  L: 290,
1495
1540
  S: this,
1496
1541
  A: [
@@ -1526,7 +1571,7 @@ var IdentityManager = class {
1526
1571
  }
1527
1572
  async _constructIdentity(identityRecord) {
1528
1573
  (0, import_invariant3.invariant)(!this._identity, void 0, {
1529
- F: __dxlog_file5,
1574
+ F: __dxlog_file6,
1530
1575
  L: 316,
1531
1576
  S: this,
1532
1577
  A: [
@@ -1537,7 +1582,7 @@ var IdentityManager = class {
1537
1582
  (0, import_log4.log)("constructing identity", {
1538
1583
  identityRecord
1539
1584
  }, {
1540
- F: __dxlog_file5,
1585
+ F: __dxlog_file6,
1541
1586
  L: 317,
1542
1587
  S: this,
1543
1588
  C: (f, a) => f(...a)
@@ -1552,7 +1597,7 @@ var IdentityManager = class {
1552
1597
  gossip
1553
1598
  });
1554
1599
  (0, import_invariant3.invariant)(identityRecord.haloSpace.controlFeedKey, void 0, {
1555
- F: __dxlog_file5,
1600
+ F: __dxlog_file6,
1556
1601
  L: 330,
1557
1602
  S: this,
1558
1603
  A: [
@@ -1564,7 +1609,7 @@ var IdentityManager = class {
1564
1609
  writable: true
1565
1610
  });
1566
1611
  (0, import_invariant3.invariant)(identityRecord.haloSpace.dataFeedKey, void 0, {
1567
- F: __dxlog_file5,
1612
+ F: __dxlog_file6,
1568
1613
  L: 334,
1569
1614
  S: this,
1570
1615
  A: [
@@ -1598,7 +1643,7 @@ var IdentityManager = class {
1598
1643
  (0, import_log4.log)("done", {
1599
1644
  identityKey: identityRecord.identityKey
1600
1645
  }, {
1601
- F: __dxlog_file5,
1646
+ F: __dxlog_file6,
1602
1647
  L: 360,
1603
1648
  S: this,
1604
1649
  C: (f, a) => f(...a)
@@ -1623,7 +1668,7 @@ var IdentityManager = class {
1623
1668
  },
1624
1669
  onAuthFailure: () => {
1625
1670
  import_log4.log.warn("auth failure", void 0, {
1626
- F: __dxlog_file5,
1671
+ F: __dxlog_file6,
1627
1672
  L: 385,
1628
1673
  S: this,
1629
1674
  C: (f, a) => f(...a)
@@ -1645,7 +1690,8 @@ _ts_decorate3([
1645
1690
  IdentityManager = _ts_decorate3([
1646
1691
  import_tracing4.trace.resource()
1647
1692
  ], IdentityManager);
1648
- var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
1693
+ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
1694
+ var DEFAULT_SPACE_SEARCH_TIMEOUT = 1e4;
1649
1695
  var IdentityServiceImpl = class extends import_context4.Resource {
1650
1696
  constructor(_identityManager, _keyring, _dataSpaceManagerProvider, _createIdentity, _onProfileUpdate) {
1651
1697
  super();
@@ -1674,8 +1720,8 @@ var IdentityServiceImpl = class extends import_context4.Resource {
1674
1720
  const space = await dataSpaceManager.createDefaultSpace();
1675
1721
  const identity = this._identityManager.identity;
1676
1722
  (0, import_invariant4.invariant)(identity, void 0, {
1677
- F: __dxlog_file6,
1678
- L: 54,
1723
+ F: __dxlog_file7,
1724
+ L: 59,
1679
1725
  S: this,
1680
1726
  A: [
1681
1727
  "identity",
@@ -1708,8 +1754,8 @@ var IdentityServiceImpl = class extends import_context4.Resource {
1708
1754
  }
1709
1755
  async updateProfile(profile) {
1710
1756
  (0, import_invariant4.invariant)(this._identityManager.identity, "Identity not initialized.", {
1711
- F: __dxlog_file6,
1712
- L: 84,
1757
+ F: __dxlog_file7,
1758
+ L: 89,
1713
1759
  S: this,
1714
1760
  A: [
1715
1761
  "this._identityManager.identity",
@@ -1722,8 +1768,8 @@ var IdentityServiceImpl = class extends import_context4.Resource {
1722
1768
  }
1723
1769
  async signPresentation({ presentation, nonce }) {
1724
1770
  (0, import_invariant4.invariant)(this._identityManager.identity, "Identity not initialized.", {
1725
- F: __dxlog_file6,
1726
- L: 91,
1771
+ F: __dxlog_file7,
1772
+ L: 96,
1727
1773
  S: this,
1728
1774
  A: [
1729
1775
  "this._identityManager.identity",
@@ -1739,25 +1785,48 @@ var IdentityServiceImpl = class extends import_context4.Resource {
1739
1785
  });
1740
1786
  }
1741
1787
  async _fixIdentityWithoutDefaultSpace(identity) {
1742
- let hasDefaultSpace = false;
1788
+ let recodedDefaultSpace = false;
1789
+ let foundDefaultSpace = false;
1743
1790
  const dataSpaceManager = this._dataSpaceManagerProvider();
1744
- for (const space of dataSpaceManager.spaces.values()) {
1791
+ const recordedDefaultSpaceTrigger = new import_async8.Trigger();
1792
+ const allProcessed = (0, import_util4.safeAwaitAll)(dataSpaceManager.spaces.values(), async (space) => {
1745
1793
  if (space.state === import_services4.SpaceState.CLOSED) {
1746
1794
  await space.open();
1747
- await space.initializeDataPipeline();
1795
+ const requiresMigration = space.stateUpdate.waitForCondition(() => space.state === import_services4.SpaceState.REQUIRES_MIGRATION);
1796
+ await Promise.race([
1797
+ space.initializeDataPipeline(),
1798
+ requiresMigration
1799
+ ]);
1748
1800
  }
1749
1801
  if (await dataSpaceManager.isDefaultSpace(space)) {
1802
+ if (foundDefaultSpace) {
1803
+ import_log5.log.warn("Multiple default spaces found. Using the first one.", {
1804
+ duplicate: space.id
1805
+ }, {
1806
+ F: __dxlog_file7,
1807
+ L: 127,
1808
+ S: this,
1809
+ C: (f, a) => f(...a)
1810
+ });
1811
+ return;
1812
+ }
1813
+ foundDefaultSpace = true;
1750
1814
  await identity.updateDefaultSpace(space.id);
1751
- hasDefaultSpace = true;
1752
- break;
1815
+ recodedDefaultSpace = true;
1816
+ recordedDefaultSpaceTrigger.wake();
1753
1817
  }
1754
- }
1755
- if (!hasDefaultSpace) {
1818
+ });
1819
+ await Promise.race([
1820
+ allProcessed,
1821
+ recordedDefaultSpaceTrigger.wait(),
1822
+ (0, import_async8.sleep)(DEFAULT_SPACE_SEARCH_TIMEOUT)
1823
+ ]);
1824
+ if (!recodedDefaultSpace) {
1756
1825
  await this._createDefaultSpace(dataSpaceManager);
1757
1826
  }
1758
1827
  }
1759
1828
  };
1760
- var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts";
1829
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts";
1761
1830
  var DeviceInvitationProtocol = class {
1762
1831
  constructor(_keyring, _getIdentity, _acceptIdentity) {
1763
1832
  this._keyring = _keyring;
@@ -1783,7 +1852,7 @@ var DeviceInvitationProtocol = class {
1783
1852
  }
1784
1853
  async admit(_, request) {
1785
1854
  (0, import_invariant5.invariant)(request.device, void 0, {
1786
- F: __dxlog_file7,
1855
+ F: __dxlog_file8,
1787
1856
  L: 50,
1788
1857
  S: this,
1789
1858
  A: [
@@ -1829,7 +1898,7 @@ var DeviceInvitationProtocol = class {
1829
1898
  }
1830
1899
  async accept(response, request) {
1831
1900
  (0, import_invariant5.invariant)(response.device, void 0, {
1832
- F: __dxlog_file7,
1901
+ F: __dxlog_file8,
1833
1902
  L: 95,
1834
1903
  S: this,
1835
1904
  A: [
@@ -1839,7 +1908,7 @@ var DeviceInvitationProtocol = class {
1839
1908
  });
1840
1909
  const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
1841
1910
  (0, import_invariant5.invariant)(request.device, void 0, {
1842
- F: __dxlog_file7,
1911
+ F: __dxlog_file8,
1843
1912
  L: 98,
1844
1913
  S: this,
1845
1914
  A: [
@@ -1878,7 +1947,7 @@ var tryAcquireBeforeContextDisposed = async (ctx, mutex) => {
1878
1947
  return guard;
1879
1948
  })());
1880
1949
  };
1881
- var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts";
1950
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts";
1882
1951
  var OPTIONS_TIMEOUT = 1e4;
1883
1952
  var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1884
1953
  constructor(_invitationFlowMutex, _callbacks) {
@@ -1892,8 +1961,11 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1892
1961
  });
1893
1962
  this._invitationFlowMutex = _invitationFlowMutex;
1894
1963
  this._callbacks = _callbacks;
1895
- this._ctx = new import_context6.Context();
1896
- this._remoteOptionsTrigger = new import_async9.Trigger();
1964
+ this._ctx = new import_context6.Context(void 0, {
1965
+ F: __dxlog_file9,
1966
+ L: 33
1967
+ });
1968
+ this._remoteOptionsTrigger = new import_async10.Trigger();
1897
1969
  this._invitationFlowLock = null;
1898
1970
  }
1899
1971
  hasFlowLock() {
@@ -1904,7 +1976,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1904
1976
  InvitationHostService: {
1905
1977
  options: async (options) => {
1906
1978
  (0, import_invariant7.invariant)(!this._remoteOptions, "Remote options already set.", {
1907
- F: __dxlog_file8,
1979
+ F: __dxlog_file9,
1908
1980
  L: 63,
1909
1981
  S: this,
1910
1982
  A: [
@@ -1930,15 +2002,15 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1930
2002
  async onOpen(context) {
1931
2003
  await super.onOpen(context);
1932
2004
  try {
1933
- (0, import_log6.log)("guest acquire lock", void 0, {
1934
- F: __dxlog_file8,
2005
+ (0, import_log7.log)("guest acquire lock", void 0, {
2006
+ F: __dxlog_file9,
1935
2007
  L: 84,
1936
2008
  S: this,
1937
2009
  C: (f, a) => f(...a)
1938
2010
  });
1939
2011
  this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
1940
- (0, import_log6.log)("guest lock acquired", void 0, {
1941
- F: __dxlog_file8,
2012
+ (0, import_log7.log)("guest lock acquired", void 0, {
2013
+ F: __dxlog_file9,
1942
2014
  L: 86,
1943
2015
  S: this,
1944
2016
  C: (f, a) => f(...a)
@@ -1946,8 +2018,8 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1946
2018
  await (0, import_context6.cancelWithContext)(this._ctx, this.rpc.InvitationHostService.options({
1947
2019
  role: import_invitations3.Options.Role.GUEST
1948
2020
  }));
1949
- (0, import_log6.log)("options sent", void 0, {
1950
- F: __dxlog_file8,
2021
+ (0, import_log7.log)("options sent", void 0, {
2022
+ F: __dxlog_file9,
1951
2023
  L: 88,
1952
2024
  S: this,
1953
2025
  C: (f, a) => f(...a)
@@ -1955,8 +2027,8 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1955
2027
  await (0, import_context6.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
1956
2028
  timeout: OPTIONS_TIMEOUT
1957
2029
  }));
1958
- (0, import_log6.log)("options received", void 0, {
1959
- F: __dxlog_file8,
2030
+ (0, import_log7.log)("options received", void 0, {
2031
+ F: __dxlog_file9,
1960
2032
  L: 90,
1961
2033
  S: this,
1962
2034
  C: (f, a) => f(...a)
@@ -1989,8 +2061,8 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1989
2061
  if (this._invitationFlowLock != null) {
1990
2062
  this._invitationFlowLock.release();
1991
2063
  this._invitationFlowLock = null;
1992
- (0, import_log6.log)("invitation flow lock released", void 0, {
1993
- F: __dxlog_file8,
2064
+ (0, import_log7.log)("invitation flow lock released", void 0, {
2065
+ F: __dxlog_file9,
1994
2066
  L: 123,
1995
2067
  S: this,
1996
2068
  C: (f, a) => f(...a)
@@ -1998,7 +2070,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1998
2070
  }
1999
2071
  }
2000
2072
  };
2001
- var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts";
2073
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts";
2002
2074
  var OPTIONS_TIMEOUT2 = 1e4;
2003
2075
  var MAX_OTP_ATTEMPTS = 3;
2004
2076
  var InvitationHostExtension = class extends import_teleport2.RpcExtension {
@@ -2013,13 +2085,16 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2013
2085
  });
2014
2086
  this._invitationFlowMutex = _invitationFlowMutex;
2015
2087
  this._callbacks = _callbacks;
2016
- this._ctx = new import_context8.Context();
2017
- this._remoteOptionsTrigger = new import_async10.Trigger();
2088
+ this._ctx = new import_context8.Context(void 0, {
2089
+ F: __dxlog_file10,
2090
+ L: 52
2091
+ });
2092
+ this._remoteOptionsTrigger = new import_async11.Trigger();
2018
2093
  this._challenge = void 0;
2019
2094
  this.guestProfile = void 0;
2020
2095
  this.authenticationPassed = false;
2021
2096
  this.authenticationRetry = 0;
2022
- this.completedTrigger = new import_async10.Trigger();
2097
+ this.completedTrigger = new import_async11.Trigger();
2023
2098
  this._invitationFlowLock = null;
2024
2099
  }
2025
2100
  hasFlowLock() {
@@ -2032,7 +2107,7 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2032
2107
  InvitationHostService: {
2033
2108
  options: async (options) => {
2034
2109
  (0, import_invariant8.invariant)(!this._remoteOptions, "Remote options already set.", {
2035
- F: __dxlog_file9,
2110
+ F: __dxlog_file10,
2036
2111
  L: 101,
2037
2112
  S: this,
2038
2113
  A: [
@@ -2046,10 +2121,10 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2046
2121
  introduce: async (request) => {
2047
2122
  const { profile, invitationId } = request;
2048
2123
  const traceId = import_keys7.PublicKey.random().toHex();
2049
- import_log7.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols7.trace.begin({
2124
+ import_log8.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols7.trace.begin({
2050
2125
  id: traceId
2051
2126
  }), {
2052
- F: __dxlog_file9,
2127
+ F: __dxlog_file10,
2053
2128
  L: 110,
2054
2129
  S: this,
2055
2130
  C: (f, a) => f(...a)
@@ -2057,25 +2132,25 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2057
2132
  const invitation = this._requireActiveInvitation();
2058
2133
  this._assertInvitationState(import_services8.Invitation.State.CONNECTED);
2059
2134
  if (invitationId !== invitation?.invitationId) {
2060
- import_log7.log.warn("incorrect invitationId", {
2135
+ import_log8.log.warn("incorrect invitationId", {
2061
2136
  expected: invitation.invitationId,
2062
2137
  actual: invitationId
2063
2138
  }, {
2064
- F: __dxlog_file9,
2139
+ F: __dxlog_file10,
2065
2140
  L: 116,
2066
2141
  S: this,
2067
2142
  C: (f, a) => f(...a)
2068
2143
  });
2069
2144
  this._callbacks.onError(new Error("Incorrect invitationId."));
2070
- (0, import_async10.scheduleTask)(this._ctx, () => this.close());
2145
+ (0, import_async11.scheduleTask)(this._ctx, () => this.close());
2071
2146
  return {
2072
2147
  authMethod: import_services8.Invitation.AuthMethod.NONE
2073
2148
  };
2074
2149
  }
2075
- (0, import_log7.log)("guest introduced themselves", {
2150
+ (0, import_log8.log)("guest introduced themselves", {
2076
2151
  guestProfile: profile
2077
2152
  }, {
2078
- F: __dxlog_file9,
2153
+ F: __dxlog_file10,
2079
2154
  L: 125,
2080
2155
  S: this,
2081
2156
  C: (f, a) => f(...a)
@@ -2083,10 +2158,10 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2083
2158
  this.guestProfile = profile;
2084
2159
  this._callbacks.onStateUpdate(import_services8.Invitation.State.READY_FOR_AUTHENTICATION);
2085
2160
  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({
2161
+ import_log8.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols7.trace.end({
2087
2162
  id: traceId
2088
2163
  }), {
2089
- F: __dxlog_file9,
2164
+ F: __dxlog_file10,
2090
2165
  L: 132,
2091
2166
  S: this,
2092
2167
  C: (f, a) => f(...a)
@@ -2098,19 +2173,19 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2098
2173
  },
2099
2174
  authenticate: async ({ authCode: code, signedChallenge }) => {
2100
2175
  const traceId = import_keys7.PublicKey.random().toHex();
2101
- import_log7.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols7.trace.begin({
2176
+ import_log8.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols7.trace.begin({
2102
2177
  id: traceId
2103
2178
  }), {
2104
- F: __dxlog_file9,
2179
+ F: __dxlog_file10,
2105
2180
  L: 141,
2106
2181
  S: this,
2107
2182
  C: (f, a) => f(...a)
2108
2183
  });
2109
2184
  const invitation = this._requireActiveInvitation();
2110
- (0, import_log7.log)("received authentication request", {
2185
+ (0, import_log8.log)("received authentication request", {
2111
2186
  authCode: code
2112
2187
  }, {
2113
- F: __dxlog_file9,
2188
+ F: __dxlog_file10,
2114
2189
  L: 144,
2115
2190
  S: this,
2116
2191
  C: (f, a) => f(...a)
@@ -2123,8 +2198,8 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2123
2198
  this._callbacks.onStateUpdate(import_services8.Invitation.State.AUTHENTICATING);
2124
2199
  switch (invitation.authMethod) {
2125
2200
  case import_services8.Invitation.AuthMethod.NONE: {
2126
- (0, import_log7.log)("authentication not required", void 0, {
2127
- F: __dxlog_file9,
2201
+ (0, import_log8.log)("authentication not required", void 0, {
2202
+ F: __dxlog_file10,
2128
2203
  L: 152,
2129
2204
  S: this,
2130
2205
  C: (f, a) => f(...a)
@@ -2159,10 +2234,10 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2159
2234
  break;
2160
2235
  }
2161
2236
  default: {
2162
- import_log7.log.error("invalid authentication method", {
2237
+ import_log8.log.error("invalid authentication method", {
2163
2238
  authMethod: invitation.authMethod
2164
2239
  }, {
2165
- F: __dxlog_file9,
2240
+ F: __dxlog_file10,
2166
2241
  L: 190,
2167
2242
  S: this,
2168
2243
  C: (f, a) => f(...a)
@@ -2176,18 +2251,18 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2176
2251
  import_invitations4.AuthenticationResponse.Status.INVALID_OTP
2177
2252
  ].includes(status)) {
2178
2253
  this._callbacks.onError(new Error(`Authentication failed, with status=${status}`));
2179
- (0, import_async10.scheduleTask)(this._ctx, () => this.close());
2254
+ (0, import_async11.scheduleTask)(this._ctx, () => this.close());
2180
2255
  return {
2181
2256
  status
2182
2257
  };
2183
2258
  }
2184
- import_log7.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols7.trace.end({
2259
+ import_log8.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols7.trace.end({
2185
2260
  id: traceId,
2186
2261
  data: {
2187
2262
  status
2188
2263
  }
2189
2264
  }), {
2190
- F: __dxlog_file9,
2265
+ F: __dxlog_file10,
2191
2266
  L: 202,
2192
2267
  S: this,
2193
2268
  C: (f, a) => f(...a)
@@ -2198,10 +2273,10 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2198
2273
  },
2199
2274
  admit: async (request) => {
2200
2275
  const traceId = import_keys7.PublicKey.random().toHex();
2201
- import_log7.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols7.trace.begin({
2276
+ import_log8.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols7.trace.begin({
2202
2277
  id: traceId
2203
2278
  }), {
2204
- F: __dxlog_file9,
2279
+ F: __dxlog_file10,
2205
2280
  L: 208,
2206
2281
  S: this,
2207
2282
  C: (f, a) => f(...a)
@@ -2215,10 +2290,10 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2215
2290
  }
2216
2291
  }
2217
2292
  const response = await this._callbacks.admit(request);
2218
- import_log7.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols7.trace.end({
2293
+ import_log8.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols7.trace.end({
2219
2294
  id: traceId
2220
2295
  }), {
2221
- F: __dxlog_file9,
2296
+ F: __dxlog_file10,
2222
2297
  L: 222,
2223
2298
  S: this,
2224
2299
  C: (f, a) => f(...a)
@@ -2235,15 +2310,15 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2235
2310
  async onOpen(context) {
2236
2311
  await super.onOpen(context);
2237
2312
  try {
2238
- (0, import_log7.log)("host acquire lock", void 0, {
2239
- F: __dxlog_file9,
2313
+ (0, import_log8.log)("host acquire lock", void 0, {
2314
+ F: __dxlog_file10,
2240
2315
  L: 237,
2241
2316
  S: this,
2242
2317
  C: (f, a) => f(...a)
2243
2318
  });
2244
2319
  this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
2245
- (0, import_log7.log)("host lock acquired", void 0, {
2246
- F: __dxlog_file9,
2320
+ (0, import_log8.log)("host lock acquired", void 0, {
2321
+ F: __dxlog_file10,
2247
2322
  L: 239,
2248
2323
  S: this,
2249
2324
  C: (f, a) => f(...a)
@@ -2253,8 +2328,8 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2253
2328
  await this.rpc.InvitationHostService.options({
2254
2329
  role: import_invitations4.Options.Role.HOST
2255
2330
  });
2256
- (0, import_log7.log)("options sent", void 0, {
2257
- F: __dxlog_file9,
2331
+ (0, import_log8.log)("options sent", void 0, {
2332
+ F: __dxlog_file10,
2258
2333
  L: 243,
2259
2334
  S: this,
2260
2335
  C: (f, a) => f(...a)
@@ -2262,8 +2337,8 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2262
2337
  await (0, import_context8.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
2263
2338
  timeout: OPTIONS_TIMEOUT2
2264
2339
  }));
2265
- (0, import_log7.log)("options received", void 0, {
2266
- F: __dxlog_file9,
2340
+ (0, import_log8.log)("options received", void 0, {
2341
+ F: __dxlog_file10,
2267
2342
  L: 245,
2268
2343
  S: this,
2269
2344
  C: (f, a) => f(...a)
@@ -2290,7 +2365,7 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2290
2365
  _requireActiveInvitation() {
2291
2366
  const invitation = this._callbacks.activeInvitation;
2292
2367
  if (invitation == null) {
2293
- (0, import_async10.scheduleTask)(this._ctx, () => this.close());
2368
+ (0, import_async11.scheduleTask)(this._ctx, () => this.close());
2294
2369
  throw new Error("Active invitation not found");
2295
2370
  }
2296
2371
  return invitation;
@@ -2301,7 +2376,7 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2301
2376
  stateOrMany
2302
2377
  ];
2303
2378
  if (!validStates.includes(invitation.state)) {
2304
- (0, import_async10.scheduleTask)(this._ctx, () => this.close());
2379
+ (0, import_async11.scheduleTask)(this._ctx, () => this.close());
2305
2380
  throw new import_invariant8.InvariantViolation(`Expected ${stateToString(invitation.state)} to be one of [${validStates.map(stateToString).join(", ")}]`);
2306
2381
  }
2307
2382
  }
@@ -2316,8 +2391,8 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2316
2391
  if (this._invitationFlowLock != null) {
2317
2392
  this._invitationFlowLock?.release();
2318
2393
  this._invitationFlowLock = null;
2319
- (0, import_log7.log)("invitation flow lock released", void 0, {
2320
- F: __dxlog_file9,
2394
+ (0, import_log8.log)("invitation flow lock released", void 0, {
2395
+ F: __dxlog_file10,
2321
2396
  L: 300,
2322
2397
  S: this,
2323
2398
  C: (f, a) => f(...a)
@@ -2326,15 +2401,15 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2326
2401
  }
2327
2402
  };
2328
2403
  var isAuthenticationRequired = (invitation) => invitation.authMethod !== import_services8.Invitation.AuthMethod.NONE;
2329
- var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts";
2404
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts";
2330
2405
  var InvitationTopology = class {
2331
2406
  constructor(_role) {
2332
2407
  this._role = _role;
2333
- this._seenPeers = new import_util5.ComplexSet(import_keys8.PublicKey.hash);
2408
+ this._seenPeers = new import_util6.ComplexSet(import_keys8.PublicKey.hash);
2334
2409
  }
2335
2410
  init(controller) {
2336
2411
  (0, import_invariant9.invariant)(!this._controller, "Already initialized.", {
2337
- F: __dxlog_file10,
2412
+ F: __dxlog_file11,
2338
2413
  L: 42,
2339
2414
  S: this,
2340
2415
  A: [
@@ -2346,7 +2421,7 @@ var InvitationTopology = class {
2346
2421
  }
2347
2422
  update() {
2348
2423
  (0, import_invariant9.invariant)(this._controller, "Not initialized.", {
2349
- F: __dxlog_file10,
2424
+ F: __dxlog_file11,
2350
2425
  L: 47,
2351
2426
  S: this,
2352
2427
  A: [
@@ -2363,13 +2438,13 @@ var InvitationTopology = class {
2363
2438
  return;
2364
2439
  }
2365
2440
  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)));
2441
+ this._seenPeers = new import_util6.ComplexSet(import_keys8.PublicKey.hash, allPeers.filter((peerId) => this._seenPeers.has(peerId)));
2367
2442
  if (firstUnknownPeer != null) {
2368
- (0, import_log8.log)("invitation connect", {
2443
+ (0, import_log9.log)("invitation connect", {
2369
2444
  ownPeerId,
2370
2445
  remotePeerId: firstUnknownPeer
2371
2446
  }, {
2372
- F: __dxlog_file10,
2447
+ F: __dxlog_file11,
2373
2448
  L: 69,
2374
2449
  S: this,
2375
2450
  C: (f, a) => f(...a)
@@ -2380,7 +2455,7 @@ var InvitationTopology = class {
2380
2455
  }
2381
2456
  async onOffer(peer) {
2382
2457
  (0, import_invariant9.invariant)(this._controller, "Not initialized.", {
2383
- F: __dxlog_file10,
2458
+ F: __dxlog_file11,
2384
2459
  L: 76,
2385
2460
  S: this,
2386
2461
  A: [
@@ -2397,7 +2472,7 @@ var InvitationTopology = class {
2397
2472
  return `InvitationTopology(${this._role === import_invitations5.Options.Role.GUEST ? "guest" : "host"})`;
2398
2473
  }
2399
2474
  };
2400
- var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts";
2475
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts";
2401
2476
  var MAX_DELEGATED_INVITATION_HOST_TRIES = 3;
2402
2477
  var InvitationsHandler = class {
2403
2478
  /**
@@ -2422,7 +2497,7 @@ var InvitationsHandler = class {
2422
2497
  try {
2423
2498
  const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
2424
2499
  (0, import_invariant6.invariant)(deviceKey, void 0, {
2425
- F: __dxlog_file11,
2500
+ F: __dxlog_file12,
2426
2501
  L: 90,
2427
2502
  S: this,
2428
2503
  A: [
@@ -2445,21 +2520,21 @@ var InvitationsHandler = class {
2445
2520
  guardedState.error(extension, new import_context5.ContextDisposedError());
2446
2521
  }
2447
2522
  });
2448
- (0, import_async8.scheduleTask)(connectionCtx, async () => {
2523
+ (0, import_async9.scheduleTask)(connectionCtx, async () => {
2449
2524
  const traceId = import_keys6.PublicKey.random().toHex();
2450
2525
  try {
2451
- import_log5.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols5.trace.begin({
2526
+ import_log6.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols5.trace.begin({
2452
2527
  id: traceId
2453
2528
  }), {
2454
- F: __dxlog_file11,
2529
+ F: __dxlog_file12,
2455
2530
  L: 115,
2456
2531
  S: this,
2457
2532
  C: (f, a) => f(...a)
2458
2533
  });
2459
- (0, import_log5.log)("connected", {
2534
+ (0, import_log6.log)("connected", {
2460
2535
  ...protocol.toJSON()
2461
2536
  }, {
2462
- F: __dxlog_file11,
2537
+ F: __dxlog_file12,
2463
2538
  L: 116,
2464
2539
  S: this,
2465
2540
  C: (f, a) => f(...a)
@@ -2467,20 +2542,20 @@ var InvitationsHandler = class {
2467
2542
  const deviceKey = await extension.completedTrigger.wait({
2468
2543
  timeout: invitation.timeout
2469
2544
  });
2470
- (0, import_log5.log)("admitted guest", {
2545
+ (0, import_log6.log)("admitted guest", {
2471
2546
  guest: deviceKey,
2472
2547
  ...protocol.toJSON()
2473
2548
  }, {
2474
- F: __dxlog_file11,
2549
+ F: __dxlog_file12,
2475
2550
  L: 118,
2476
2551
  S: this,
2477
2552
  C: (f, a) => f(...a)
2478
2553
  });
2479
2554
  guardedState.set(extension, import_services6.Invitation.State.SUCCESS);
2480
- import_log5.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols5.trace.end({
2555
+ import_log6.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols5.trace.end({
2481
2556
  id: traceId
2482
2557
  }), {
2483
- F: __dxlog_file11,
2558
+ F: __dxlog_file12,
2484
2559
  L: 120,
2485
2560
  S: this,
2486
2561
  C: (f, a) => f(...a)
@@ -2490,12 +2565,12 @@ var InvitationsHandler = class {
2490
2565
  await ctx.dispose();
2491
2566
  }
2492
2567
  } catch (err) {
2493
- if (err instanceof import_async8.TimeoutError) {
2568
+ if (err instanceof import_async9.TimeoutError) {
2494
2569
  if (guardedState.set(extension, import_services6.Invitation.State.TIMEOUT)) {
2495
- (0, import_log5.log)("timeout", {
2570
+ (0, import_log6.log)("timeout", {
2496
2571
  ...protocol.toJSON()
2497
2572
  }, {
2498
- F: __dxlog_file11,
2573
+ F: __dxlog_file12,
2499
2574
  L: 129,
2500
2575
  S: this,
2501
2576
  C: (f, a) => f(...a)
@@ -2503,19 +2578,19 @@ var InvitationsHandler = class {
2503
2578
  }
2504
2579
  } else {
2505
2580
  if (guardedState.error(extension, err)) {
2506
- import_log5.log.error("failed", err, {
2507
- F: __dxlog_file11,
2581
+ import_log6.log.error("failed", err, {
2582
+ F: __dxlog_file12,
2508
2583
  L: 133,
2509
2584
  S: this,
2510
2585
  C: (f, a) => f(...a)
2511
2586
  });
2512
2587
  }
2513
2588
  }
2514
- import_log5.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols5.trace.error({
2589
+ import_log6.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols5.trace.error({
2515
2590
  id: traceId,
2516
2591
  error: err
2517
2592
  }), {
2518
- F: __dxlog_file11,
2593
+ F: __dxlog_file12,
2519
2594
  L: 136,
2520
2595
  S: this,
2521
2596
  C: (f, a) => f(...a)
@@ -2526,22 +2601,22 @@ var InvitationsHandler = class {
2526
2601
  },
2527
2602
  onError: (err) => {
2528
2603
  if (err instanceof import_protocols5.InvalidInvitationExtensionRoleError) {
2529
- (0, import_log5.log)("invalid role", {
2604
+ (0, import_log6.log)("invalid role", {
2530
2605
  ...err.context
2531
2606
  }, {
2532
- F: __dxlog_file11,
2607
+ F: __dxlog_file12,
2533
2608
  L: 144,
2534
2609
  S: this,
2535
2610
  C: (f, a) => f(...a)
2536
2611
  });
2537
2612
  return;
2538
2613
  }
2539
- if (err instanceof import_async8.TimeoutError) {
2614
+ if (err instanceof import_async9.TimeoutError) {
2540
2615
  if (guardedState.set(extension, import_services6.Invitation.State.TIMEOUT)) {
2541
- (0, import_log5.log)("timeout", {
2616
+ (0, import_log6.log)("timeout", {
2542
2617
  err
2543
2618
  }, {
2544
- F: __dxlog_file11,
2619
+ F: __dxlog_file12,
2545
2620
  L: 149,
2546
2621
  S: this,
2547
2622
  C: (f, a) => f(...a)
@@ -2549,8 +2624,8 @@ var InvitationsHandler = class {
2549
2624
  }
2550
2625
  } else {
2551
2626
  if (guardedState.error(extension, err)) {
2552
- import_log5.log.error("failed", err, {
2553
- F: __dxlog_file11,
2627
+ import_log6.log.error("failed", err, {
2628
+ F: __dxlog_file12,
2554
2629
  L: 153,
2555
2630
  S: this,
2556
2631
  C: (f, a) => f(...a)
@@ -2563,14 +2638,14 @@ var InvitationsHandler = class {
2563
2638
  };
2564
2639
  if (invitation.lifetime && invitation.created) {
2565
2640
  if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
2566
- import_log5.log.warn("invitation has already expired", void 0, {
2567
- F: __dxlog_file11,
2641
+ import_log6.log.warn("invitation has already expired", void 0, {
2642
+ F: __dxlog_file12,
2568
2643
  L: 164,
2569
2644
  S: this,
2570
2645
  C: (f, a) => f(...a)
2571
2646
  });
2572
2647
  } else {
2573
- (0, import_async8.scheduleTask)(ctx, async () => {
2648
+ (0, import_async9.scheduleTask)(ctx, async () => {
2574
2649
  await swarmConnection.close();
2575
2650
  guardedState.set(null, import_services6.Invitation.State.EXPIRED);
2576
2651
  await ctx.dispose();
@@ -2578,7 +2653,7 @@ var InvitationsHandler = class {
2578
2653
  }
2579
2654
  }
2580
2655
  let swarmConnection;
2581
- (0, import_async8.scheduleTask)(ctx, async () => {
2656
+ (0, import_async9.scheduleTask)(ctx, async () => {
2582
2657
  swarmConnection = await this._joinSwarm(ctx, invitation, import_invitations2.Options.Role.HOST, createExtension);
2583
2658
  guardedState.set(null, import_services6.Invitation.State.CONNECTING);
2584
2659
  });
@@ -2587,7 +2662,7 @@ var InvitationsHandler = class {
2587
2662
  const { timeout = import_client_protocol2.INVITATION_TIMEOUT } = invitation;
2588
2663
  if (deviceProfile) {
2589
2664
  (0, import_invariant6.invariant)(invitation.kind === import_services6.Invitation.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
2590
- F: __dxlog_file11,
2665
+ F: __dxlog_file12,
2591
2666
  L: 197,
2592
2667
  S: this,
2593
2668
  A: [
@@ -2596,16 +2671,16 @@ var InvitationsHandler = class {
2596
2671
  ]
2597
2672
  });
2598
2673
  }
2599
- const triedPeersIds = new import_util4.ComplexSet(import_keys6.PublicKey.hash);
2674
+ const triedPeersIds = new import_util5.ComplexSet(import_keys6.PublicKey.hash);
2600
2675
  const guardedState = this._createGuardedState(ctx, invitation, stream);
2601
2676
  const shouldCancelInvitationFlow = (extension) => {
2602
2677
  const isLockedByAnotherConnection = guardedState.mutex.isLocked() && !extension.hasFlowLock();
2603
- (0, import_log5.log)("should cancel invitation flow", {
2678
+ (0, import_log6.log)("should cancel invitation flow", {
2604
2679
  isLockedByAnotherConnection,
2605
2680
  invitationType: import_services6.Invitation.Type.DELEGATED,
2606
2681
  triedPeers: triedPeersIds.size
2607
2682
  }, {
2608
- F: __dxlog_file11,
2683
+ F: __dxlog_file12,
2609
2684
  L: 205,
2610
2685
  S: this,
2611
2686
  C: (f, a) => f(...a)
@@ -2628,11 +2703,11 @@ var InvitationsHandler = class {
2628
2703
  return;
2629
2704
  }
2630
2705
  connectionCtx.onDispose(async () => {
2631
- (0, import_log5.log)("extension disposed", {
2706
+ (0, import_log6.log)("extension disposed", {
2632
2707
  admitted,
2633
2708
  currentState: guardedState.current.state
2634
2709
  }, {
2635
- F: __dxlog_file11,
2710
+ F: __dxlog_file12,
2636
2711
  L: 233,
2637
2712
  S: this,
2638
2713
  C: (f, a) => f(...a)
@@ -2644,34 +2719,34 @@ var InvitationsHandler = class {
2644
2719
  }
2645
2720
  }
2646
2721
  });
2647
- (0, import_async8.scheduleTask)(connectionCtx, async () => {
2722
+ (0, import_async9.scheduleTask)(connectionCtx, async () => {
2648
2723
  const traceId = import_keys6.PublicKey.random().toHex();
2649
2724
  try {
2650
- import_log5.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols5.trace.begin({
2725
+ import_log6.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols5.trace.begin({
2651
2726
  id: traceId
2652
2727
  }), {
2653
- F: __dxlog_file11,
2728
+ F: __dxlog_file12,
2654
2729
  L: 245,
2655
2730
  S: this,
2656
2731
  C: (f, a) => f(...a)
2657
2732
  });
2658
- (0, import_async8.scheduleTask)(connectionCtx, () => {
2733
+ (0, import_async9.scheduleTask)(connectionCtx, () => {
2659
2734
  guardedState.set(extension, import_services6.Invitation.State.TIMEOUT);
2660
2735
  extensionCtx.close();
2661
2736
  }, timeout);
2662
- (0, import_log5.log)("connected", {
2737
+ (0, import_log6.log)("connected", {
2663
2738
  ...protocol.toJSON()
2664
2739
  }, {
2665
- F: __dxlog_file11,
2740
+ F: __dxlog_file12,
2666
2741
  L: 256,
2667
2742
  S: this,
2668
2743
  C: (f, a) => f(...a)
2669
2744
  });
2670
2745
  guardedState.set(extension, import_services6.Invitation.State.CONNECTED);
2671
- (0, import_log5.log)("introduce", {
2746
+ (0, import_log6.log)("introduce", {
2672
2747
  ...protocol.toJSON()
2673
2748
  }, {
2674
- F: __dxlog_file11,
2749
+ F: __dxlog_file12,
2675
2750
  L: 260,
2676
2751
  S: this,
2677
2752
  C: (f, a) => f(...a)
@@ -2680,11 +2755,11 @@ var InvitationsHandler = class {
2680
2755
  invitationId: invitation.invitationId,
2681
2756
  ...protocol.createIntroduction()
2682
2757
  });
2683
- (0, import_log5.log)("introduce response", {
2758
+ (0, import_log6.log)("introduce response", {
2684
2759
  ...protocol.toJSON(),
2685
2760
  response: introductionResponse
2686
2761
  }, {
2687
- F: __dxlog_file11,
2762
+ F: __dxlog_file12,
2688
2763
  L: 265,
2689
2764
  S: this,
2690
2765
  C: (f, a) => f(...a)
@@ -2702,10 +2777,10 @@ var InvitationsHandler = class {
2702
2777
  break;
2703
2778
  }
2704
2779
  }
2705
- (0, import_log5.log)("request admission", {
2780
+ (0, import_log6.log)("request admission", {
2706
2781
  ...protocol.toJSON()
2707
2782
  }, {
2708
- F: __dxlog_file11,
2783
+ F: __dxlog_file12,
2709
2784
  L: 291,
2710
2785
  S: this,
2711
2786
  C: (f, a) => f(...a)
@@ -2714,10 +2789,10 @@ var InvitationsHandler = class {
2714
2789
  const admissionResponse = await extension.rpc.InvitationHostService.admit(admissionRequest);
2715
2790
  admitted = true;
2716
2791
  const result = await protocol.accept(admissionResponse, admissionRequest);
2717
- (0, import_log5.log)("admitted by host", {
2792
+ (0, import_log6.log)("admitted by host", {
2718
2793
  ...protocol.toJSON()
2719
2794
  }, {
2720
- F: __dxlog_file11,
2795
+ F: __dxlog_file12,
2721
2796
  L: 302,
2722
2797
  S: this,
2723
2798
  C: (f, a) => f(...a)
@@ -2727,28 +2802,28 @@ var InvitationsHandler = class {
2727
2802
  ...result,
2728
2803
  state: import_services6.Invitation.State.SUCCESS
2729
2804
  });
2730
- import_log5.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols5.trace.end({
2805
+ import_log6.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols5.trace.end({
2731
2806
  id: traceId
2732
2807
  }), {
2733
- F: __dxlog_file11,
2808
+ F: __dxlog_file12,
2734
2809
  L: 308,
2735
2810
  S: this,
2736
2811
  C: (f, a) => f(...a)
2737
2812
  });
2738
2813
  } catch (err) {
2739
- if (err instanceof import_async8.TimeoutError) {
2740
- (0, import_log5.log)("timeout", {
2814
+ if (err instanceof import_async9.TimeoutError) {
2815
+ (0, import_log6.log)("timeout", {
2741
2816
  ...protocol.toJSON()
2742
2817
  }, {
2743
- F: __dxlog_file11,
2818
+ F: __dxlog_file12,
2744
2819
  L: 311,
2745
2820
  S: this,
2746
2821
  C: (f, a) => f(...a)
2747
2822
  });
2748
2823
  guardedState.set(extension, import_services6.Invitation.State.TIMEOUT);
2749
2824
  } else {
2750
- (0, import_log5.log)("auth failed", err, {
2751
- F: __dxlog_file11,
2825
+ (0, import_log6.log)("auth failed", err, {
2826
+ F: __dxlog_file12,
2752
2827
  L: 314,
2753
2828
  S: this,
2754
2829
  C: (f, a) => f(...a)
@@ -2756,11 +2831,11 @@ var InvitationsHandler = class {
2756
2831
  guardedState.error(extension, err);
2757
2832
  }
2758
2833
  extensionCtx.close(err);
2759
- import_log5.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols5.trace.error({
2834
+ import_log6.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols5.trace.error({
2760
2835
  id: traceId,
2761
2836
  error: err
2762
2837
  }), {
2763
- F: __dxlog_file11,
2838
+ F: __dxlog_file12,
2764
2839
  L: 318,
2765
2840
  S: this,
2766
2841
  C: (f, a) => f(...a)
@@ -2772,19 +2847,19 @@ var InvitationsHandler = class {
2772
2847
  if (err instanceof import_protocols5.InvalidInvitationExtensionRoleError) {
2773
2848
  return;
2774
2849
  }
2775
- if (err instanceof import_async8.TimeoutError) {
2776
- (0, import_log5.log)("timeout", {
2850
+ if (err instanceof import_async9.TimeoutError) {
2851
+ (0, import_log6.log)("timeout", {
2777
2852
  ...protocol.toJSON()
2778
2853
  }, {
2779
- F: __dxlog_file11,
2854
+ F: __dxlog_file12,
2780
2855
  L: 327,
2781
2856
  S: this,
2782
2857
  C: (f, a) => f(...a)
2783
2858
  });
2784
2859
  guardedState.set(extension, import_services6.Invitation.State.TIMEOUT);
2785
2860
  } else {
2786
- (0, import_log5.log)("auth failed", err, {
2787
- F: __dxlog_file11,
2861
+ (0, import_log6.log)("auth failed", err, {
2862
+ F: __dxlog_file12,
2788
2863
  L: 330,
2789
2864
  S: this,
2790
2865
  C: (f, a) => f(...a)
@@ -2795,14 +2870,14 @@ var InvitationsHandler = class {
2795
2870
  });
2796
2871
  return extension;
2797
2872
  };
2798
- (0, import_async8.scheduleTask)(ctx, async () => {
2873
+ (0, import_async9.scheduleTask)(ctx, async () => {
2799
2874
  const error = protocol.checkInvitation(invitation);
2800
2875
  if (error) {
2801
2876
  stream.error(error);
2802
2877
  await ctx.dispose();
2803
2878
  } else {
2804
2879
  (0, import_invariant6.invariant)(invitation.swarmKey, void 0, {
2805
- F: __dxlog_file11,
2880
+ F: __dxlog_file12,
2806
2881
  L: 345,
2807
2882
  S: this,
2808
2883
  A: [
@@ -2841,7 +2916,7 @@ var InvitationsHandler = class {
2841
2916
  * invitation flow connections.
2842
2917
  */
2843
2918
  _createGuardedState(ctx, invitation, stream) {
2844
- const mutex = new import_async8.Mutex();
2919
+ const mutex = new import_async9.Mutex();
2845
2920
  let lastActiveExtension = null;
2846
2921
  let currentInvitation = {
2847
2922
  ...invitation
@@ -2896,21 +2971,34 @@ var InvitationsHandler = class {
2896
2971
  };
2897
2972
  }
2898
2973
  _logStateUpdate(invitation, actor, newState) {
2899
- (0, import_log5.log)("invitation state update", {
2900
- actor: actor?.constructor.name,
2901
- newState: stateToString(newState),
2902
- oldState: stateToString(invitation.state)
2903
- }, {
2904
- F: __dxlog_file11,
2905
- L: 438,
2906
- S: this,
2907
- C: (f, a) => f(...a)
2908
- });
2909
- }
2910
- _isNotTerminal(currentState) {
2911
- return ![
2912
- import_services6.Invitation.State.SUCCESS,
2913
- import_services6.Invitation.State.ERROR,
2974
+ if (this._isNotTerminal(newState)) {
2975
+ (0, import_log6.log)("invitation state update", {
2976
+ actor: actor?.constructor.name,
2977
+ newState: stateToString(newState),
2978
+ oldState: stateToString(invitation.state)
2979
+ }, {
2980
+ F: __dxlog_file12,
2981
+ L: 439,
2982
+ S: this,
2983
+ C: (f, a) => f(...a)
2984
+ });
2985
+ } else {
2986
+ import_log6.log.info("invitation state update", {
2987
+ actor: actor?.constructor.name,
2988
+ newState: stateToString(newState),
2989
+ oldState: stateToString(invitation.state)
2990
+ }, {
2991
+ F: __dxlog_file12,
2992
+ L: 445,
2993
+ S: this,
2994
+ C: (f, a) => f(...a)
2995
+ });
2996
+ }
2997
+ }
2998
+ _isNotTerminal(currentState) {
2999
+ return ![
3000
+ import_services6.Invitation.State.SUCCESS,
3001
+ import_services6.Invitation.State.ERROR,
2914
3002
  import_services6.Invitation.State.CANCELLED,
2915
3003
  import_services6.Invitation.State.TIMEOUT,
2916
3004
  import_services6.Invitation.State.EXPIRED
@@ -2918,17 +3006,17 @@ var InvitationsHandler = class {
2918
3006
  }
2919
3007
  async _handleGuestOtpAuth(extension, setState, authenticated, options) {
2920
3008
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2921
- (0, import_log5.log)("guest waiting for authentication code...", void 0, {
2922
- F: __dxlog_file11,
2923
- L: 462,
3009
+ (0, import_log6.log)("guest waiting for authentication code...", void 0, {
3010
+ F: __dxlog_file12,
3011
+ L: 470,
2924
3012
  S: this,
2925
3013
  C: (f, a) => f(...a)
2926
3014
  });
2927
3015
  setState(import_services6.Invitation.State.READY_FOR_AUTHENTICATION);
2928
3016
  const authCode = await authenticated.wait(options);
2929
- (0, import_log5.log)("sending authentication request", void 0, {
2930
- F: __dxlog_file11,
2931
- L: 466,
3017
+ (0, import_log6.log)("sending authentication request", void 0, {
3018
+ F: __dxlog_file12,
3019
+ L: 474,
2932
3020
  S: this,
2933
3021
  C: (f, a) => f(...a)
2934
3022
  });
@@ -2943,11 +3031,11 @@ var InvitationsHandler = class {
2943
3031
  if (attempt === MAX_OTP_ATTEMPTS) {
2944
3032
  throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
2945
3033
  } else {
2946
- (0, import_log5.log)("retrying invalid code", {
3034
+ (0, import_log6.log)("retrying invalid code", {
2947
3035
  attempt
2948
3036
  }, {
2949
- F: __dxlog_file11,
2950
- L: 477,
3037
+ F: __dxlog_file12,
3038
+ L: 485,
2951
3039
  S: this,
2952
3040
  C: (f, a) => f(...a)
2953
3041
  });
@@ -2963,9 +3051,9 @@ var InvitationsHandler = class {
2963
3051
  if (introductionResponse.challenge == null) {
2964
3052
  throw new Error("challenge missing in the introduction");
2965
3053
  }
2966
- (0, import_log5.log)("sending authentication request", void 0, {
2967
- F: __dxlog_file11,
2968
- L: 496,
3054
+ (0, import_log6.log)("sending authentication request", void 0, {
3055
+ F: __dxlog_file12,
3056
+ L: 504,
2969
3057
  S: this,
2970
3058
  C: (f, a) => f(...a)
2971
3059
  });
@@ -3079,7 +3167,7 @@ var InvitationsServiceImpl = class {
3079
3167
  });
3080
3168
  }
3081
3169
  };
3082
- var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
3170
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
3083
3171
  var SpaceInvitationProtocol = class {
3084
3172
  constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
3085
3173
  this._spaceManager = _spaceManager;
@@ -3113,79 +3201,43 @@ var SpaceInvitationProtocol = class {
3113
3201
  };
3114
3202
  }
3115
3203
  async admit(invitation, request, guestProfile) {
3116
- (0, import_invariant10.invariant)(this._spaceKey, void 0, {
3117
- F: __dxlog_file12,
3118
- L: 76,
3119
- S: this,
3120
- A: [
3121
- "this._spaceKey",
3122
- ""
3123
- ]
3124
- });
3125
- const space = this._spaceManager.spaces.get(this._spaceKey);
3126
- (0, import_invariant10.invariant)(space, void 0, {
3127
- F: __dxlog_file12,
3128
- L: 78,
3129
- S: this,
3130
- A: [
3131
- "space",
3132
- ""
3133
- ]
3134
- });
3135
- (0, import_invariant10.invariant)(request.space, void 0, {
3136
- F: __dxlog_file12,
3137
- L: 80,
3204
+ (0, import_invariant10.invariant)(this._spaceKey && request.space, void 0, {
3205
+ F: __dxlog_file13,
3206
+ L: 74,
3138
3207
  S: this,
3139
3208
  A: [
3140
- "request.space",
3209
+ "this._spaceKey && request.space",
3141
3210
  ""
3142
3211
  ]
3143
3212
  });
3144
- const { identityKey, deviceKey } = request.space;
3145
- if (space.inner.spaceState.getMemberRole(identityKey) !== import_credentials10.SpaceMember.Role.REMOVED) {
3146
- throw new import_protocols8.AlreadyJoinedError();
3147
- }
3148
- (0, import_log9.log)("writing guest credentials", {
3213
+ (0, import_log10.log)("writing guest credentials", {
3149
3214
  host: this._signingContext.deviceKey,
3150
- guest: deviceKey
3215
+ guest: request.space.deviceKey
3151
3216
  }, {
3152
- F: __dxlog_file12,
3153
- L: 87,
3217
+ F: __dxlog_file13,
3218
+ L: 75,
3154
3219
  S: this,
3155
3220
  C: (f, a) => f(...a)
3156
3221
  });
3157
- const credentials = await (0, import_credentials9.createAdmissionCredentials)(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, invitation.role ?? import_credentials10.SpaceMember.Role.ADMIN, space.inner.spaceState.membershipChainHeads, guestProfile, invitation.delegationCredentialId);
3158
- (0, import_invariant10.invariant)(credentials[0].credential, void 0, {
3159
- F: __dxlog_file12,
3160
- L: 101,
3161
- S: this,
3162
- A: [
3163
- "credentials[0].credential",
3164
- ""
3165
- ]
3166
- });
3167
- const spaceMemberCredential = credentials[0].credential.credential;
3168
- (0, import_invariant10.invariant)((0, import_credentials9.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3169
- F: __dxlog_file12,
3170
- L: 103,
3171
- S: this,
3172
- A: [
3173
- "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
3174
- ""
3175
- ]
3222
+ const spaceMemberCredential = await this._spaceManager.admitMember({
3223
+ spaceKey: this._spaceKey,
3224
+ identityKey: request.space.identityKey,
3225
+ role: invitation.role ?? import_credentials10.SpaceMember.Role.ADMIN,
3226
+ profile: guestProfile,
3227
+ delegationCredentialId: invitation.delegationCredentialId
3176
3228
  });
3177
- await (0, import_feed_store3.writeMessages)(space.inner.controlPipeline.writer, credentials);
3229
+ const space = this._spaceManager.spaces.get(this._spaceKey);
3178
3230
  return {
3179
3231
  space: {
3180
3232
  credential: spaceMemberCredential,
3181
- controlTimeframe: space.inner.controlPipeline.state.timeframe
3233
+ controlTimeframe: space?.inner.controlPipeline.state.timeframe
3182
3234
  }
3183
3235
  };
3184
3236
  }
3185
3237
  async delegate(invitation) {
3186
3238
  (0, import_invariant10.invariant)(this._spaceKey, void 0, {
3187
- F: __dxlog_file12,
3188
- L: 116,
3239
+ F: __dxlog_file13,
3240
+ L: 95,
3189
3241
  S: this,
3190
3242
  A: [
3191
3243
  "this._spaceKey",
@@ -3194,8 +3246,8 @@ var SpaceInvitationProtocol = class {
3194
3246
  });
3195
3247
  const space = this._spaceManager.spaces.get(this._spaceKey);
3196
3248
  (0, import_invariant10.invariant)(space, void 0, {
3197
- F: __dxlog_file12,
3198
- L: 118,
3249
+ F: __dxlog_file13,
3250
+ L: 97,
3199
3251
  S: this,
3200
3252
  A: [
3201
3253
  "space",
@@ -3204,8 +3256,8 @@ var SpaceInvitationProtocol = class {
3204
3256
  });
3205
3257
  if (invitation.authMethod === import_services10.Invitation.AuthMethod.KNOWN_PUBLIC_KEY) {
3206
3258
  (0, import_invariant10.invariant)(invitation.guestKeypair?.publicKey, void 0, {
3207
- F: __dxlog_file12,
3208
- L: 120,
3259
+ F: __dxlog_file13,
3260
+ L: 99,
3209
3261
  S: this,
3210
3262
  A: [
3211
3263
  "invitation.guestKeypair?.publicKey",
@@ -3213,12 +3265,12 @@ var SpaceInvitationProtocol = class {
3213
3265
  ]
3214
3266
  });
3215
3267
  }
3216
- (0, import_log9.log)("writing delegate space invitation", {
3268
+ (0, import_log10.log)("writing delegate space invitation", {
3217
3269
  host: this._signingContext.deviceKey,
3218
3270
  id: invitation.invitationId
3219
3271
  }, {
3220
- F: __dxlog_file12,
3221
- L: 123,
3272
+ F: __dxlog_file13,
3273
+ L: 102,
3222
3274
  S: this,
3223
3275
  C: (f, a) => f(...a)
3224
3276
  });
@@ -3232,8 +3284,8 @@ var SpaceInvitationProtocol = class {
3232
3284
  guestKey: invitation.authMethod === import_services10.Invitation.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
3233
3285
  });
3234
3286
  (0, import_invariant10.invariant)(credential.credential, void 0, {
3235
- F: __dxlog_file12,
3236
- L: 143,
3287
+ F: __dxlog_file13,
3288
+ L: 122,
3237
3289
  S: this,
3238
3290
  A: [
3239
3291
  "credential.credential",
@@ -3247,8 +3299,8 @@ var SpaceInvitationProtocol = class {
3247
3299
  }
3248
3300
  async cancelDelegation(invitation) {
3249
3301
  (0, import_invariant10.invariant)(this._spaceKey, void 0, {
3250
- F: __dxlog_file12,
3251
- L: 149,
3302
+ F: __dxlog_file13,
3303
+ L: 128,
3252
3304
  S: this,
3253
3305
  A: [
3254
3306
  "this._spaceKey",
@@ -3256,8 +3308,8 @@ var SpaceInvitationProtocol = class {
3256
3308
  ]
3257
3309
  });
3258
3310
  (0, import_invariant10.invariant)(invitation.type === import_services10.Invitation.Type.DELEGATED && invitation.delegationCredentialId, void 0, {
3259
- F: __dxlog_file12,
3260
- L: 150,
3311
+ F: __dxlog_file13,
3312
+ L: 129,
3261
3313
  S: this,
3262
3314
  A: [
3263
3315
  "invitation.type === Invitation.Type.DELEGATED && invitation.delegationCredentialId",
@@ -3266,27 +3318,27 @@ var SpaceInvitationProtocol = class {
3266
3318
  });
3267
3319
  const space = this._spaceManager.spaces.get(this._spaceKey);
3268
3320
  (0, import_invariant10.invariant)(space, void 0, {
3269
- F: __dxlog_file12,
3270
- L: 152,
3321
+ F: __dxlog_file13,
3322
+ L: 131,
3271
3323
  S: this,
3272
3324
  A: [
3273
3325
  "space",
3274
3326
  ""
3275
3327
  ]
3276
3328
  });
3277
- (0, import_log9.log)("cancelling delegated space invitation", {
3329
+ (0, import_log10.log)("cancelling delegated space invitation", {
3278
3330
  host: this._signingContext.deviceKey,
3279
3331
  id: invitation.invitationId
3280
3332
  }, {
3281
- F: __dxlog_file12,
3282
- L: 154,
3333
+ F: __dxlog_file13,
3334
+ L: 133,
3283
3335
  S: this,
3284
3336
  C: (f, a) => f(...a)
3285
3337
  });
3286
3338
  const credential = await (0, import_credentials9.createCancelDelegatedSpaceInvitationCredential)(this._signingContext.credentialSigner, space.key, invitation.delegationCredentialId);
3287
3339
  (0, import_invariant10.invariant)(credential.credential, void 0, {
3288
- F: __dxlog_file12,
3289
- L: 161,
3340
+ F: __dxlog_file13,
3341
+ L: 140,
3290
3342
  S: this,
3291
3343
  A: [
3292
3344
  "credential.credential",
@@ -3324,8 +3376,8 @@ var SpaceInvitationProtocol = class {
3324
3376
  }
3325
3377
  async accept(response) {
3326
3378
  (0, import_invariant10.invariant)(response.space, void 0, {
3327
- F: __dxlog_file12,
3328
- L: 196,
3379
+ F: __dxlog_file13,
3380
+ L: 175,
3329
3381
  S: this,
3330
3382
  A: [
3331
3383
  "response.space",
@@ -3335,8 +3387,8 @@ var SpaceInvitationProtocol = class {
3335
3387
  const { credential, controlTimeframe, dataTimeframe } = response.space;
3336
3388
  const assertion = (0, import_credentials9.getCredentialAssertion)(credential);
3337
3389
  (0, import_invariant10.invariant)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
3338
- F: __dxlog_file12,
3339
- L: 199,
3390
+ F: __dxlog_file13,
3391
+ L: 178,
3340
3392
  S: this,
3341
3393
  A: [
3342
3394
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -3344,8 +3396,8 @@ var SpaceInvitationProtocol = class {
3344
3396
  ]
3345
3397
  });
3346
3398
  (0, import_invariant10.invariant)(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
3347
- F: __dxlog_file12,
3348
- L: 200,
3399
+ F: __dxlog_file13,
3400
+ L: 179,
3349
3401
  S: this,
3350
3402
  A: [
3351
3403
  "credential.subject.id.equals(this._signingContext.identityKey)",
@@ -3367,7 +3419,7 @@ var SpaceInvitationProtocol = class {
3367
3419
  };
3368
3420
  }
3369
3421
  };
3370
- var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
3422
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
3371
3423
  var InvitationsManager = class {
3372
3424
  constructor(_invitationsHandler, _getHandler, _metadataStore) {
3373
3425
  this._invitationsHandler = _invitationsHandler;
@@ -3375,12 +3427,12 @@ var InvitationsManager = class {
3375
3427
  this._metadataStore = _metadataStore;
3376
3428
  this._createInvitations = /* @__PURE__ */ new Map();
3377
3429
  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();
3430
+ this.invitationCreated = new import_async12.Event();
3431
+ this.invitationAccepted = new import_async12.Event();
3432
+ this.removedCreated = new import_async12.Event();
3433
+ this.removedAccepted = new import_async12.Event();
3434
+ this.saved = new import_async12.Event();
3435
+ this._persistentInvitationsLoadedEvent = new import_async12.Event();
3384
3436
  this._persistentInvitationsLoaded = false;
3385
3437
  }
3386
3438
  async createInvitation(options) {
@@ -3409,8 +3461,8 @@ var InvitationsManager = class {
3409
3461
  try {
3410
3462
  await this._persistIfRequired(handler, stream, invitation);
3411
3463
  } catch (err) {
3412
- import_log10.log.catch(err, void 0, {
3413
- F: __dxlog_file13,
3464
+ import_log11.log.catch(err, void 0, {
3465
+ F: __dxlog_file14,
3414
3466
  L: 82,
3415
3467
  S: this,
3416
3468
  C: (f, a) => f(...a)
@@ -3433,7 +3485,7 @@ var InvitationsManager = class {
3433
3485
  const freshInvitations = persistentInvitations.filter((invitation) => !(0, import_echo_pipeline.hasInvitationExpired)(invitation));
3434
3486
  const loadTasks = freshInvitations.map((persistentInvitation) => {
3435
3487
  (0, import_invariant11.invariant)(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
3436
- F: __dxlog_file13,
3488
+ F: __dxlog_file14,
3437
3489
  L: 103,
3438
3490
  S: this,
3439
3491
  A: [
@@ -3451,8 +3503,8 @@ var InvitationsManager = class {
3451
3503
  invitations: cInvitations.map((invitation) => invitation.get())
3452
3504
  };
3453
3505
  } catch (err) {
3454
- import_log10.log.catch(err, void 0, {
3455
- F: __dxlog_file13,
3506
+ import_log11.log.catch(err, void 0, {
3507
+ F: __dxlog_file14,
3456
3508
  L: 110,
3457
3509
  S: this,
3458
3510
  C: (f, a) => f(...a)
@@ -3483,14 +3535,14 @@ var InvitationsManager = class {
3483
3535
  return invitation;
3484
3536
  }
3485
3537
  async authenticate({ invitationId, authCode }) {
3486
- (0, import_log10.log)("authenticating...", void 0, {
3487
- F: __dxlog_file13,
3538
+ (0, import_log11.log)("authenticating...", void 0, {
3539
+ F: __dxlog_file14,
3488
3540
  L: 140,
3489
3541
  S: this,
3490
3542
  C: (f, a) => f(...a)
3491
3543
  });
3492
3544
  (0, import_invariant11.invariant)(invitationId, void 0, {
3493
- F: __dxlog_file13,
3545
+ F: __dxlog_file14,
3494
3546
  L: 141,
3495
3547
  S: this,
3496
3548
  A: [
@@ -3500,10 +3552,10 @@ var InvitationsManager = class {
3500
3552
  });
3501
3553
  const observable = this._acceptInvitations.get(invitationId);
3502
3554
  if (!observable) {
3503
- import_log10.log.warn("invalid invitation", {
3555
+ import_log11.log.warn("invalid invitation", {
3504
3556
  invitationId
3505
3557
  }, {
3506
- F: __dxlog_file13,
3558
+ F: __dxlog_file14,
3507
3559
  L: 144,
3508
3560
  S: this,
3509
3561
  C: (f, a) => f(...a)
@@ -3513,16 +3565,16 @@ var InvitationsManager = class {
3513
3565
  }
3514
3566
  }
3515
3567
  async cancelInvitation({ invitationId }) {
3516
- (0, import_log10.log)("cancelInvitation...", {
3568
+ (0, import_log11.log)("cancelInvitation...", {
3517
3569
  invitationId
3518
3570
  }, {
3519
- F: __dxlog_file13,
3571
+ F: __dxlog_file14,
3520
3572
  L: 151,
3521
3573
  S: this,
3522
3574
  C: (f, a) => f(...a)
3523
3575
  });
3524
3576
  (0, import_invariant11.invariant)(invitationId, void 0, {
3525
- F: __dxlog_file13,
3577
+ F: __dxlog_file14,
3526
3578
  L: 152,
3527
3579
  S: this,
3528
3580
  A: [
@@ -3590,18 +3642,21 @@ var InvitationsManager = class {
3590
3642
  };
3591
3643
  }
3592
3644
  _createObservableInvitation(handler, invitation) {
3593
- const stream = new import_async11.PushStream();
3645
+ const stream = new import_async12.PushStream();
3594
3646
  const ctx = new import_context9.Context({
3595
3647
  onError: (err) => {
3596
3648
  stream.error(err);
3597
3649
  void ctx.dispose();
3598
3650
  }
3651
+ }, {
3652
+ F: __dxlog_file14,
3653
+ L: 234
3599
3654
  });
3600
3655
  ctx.onDispose(() => {
3601
- (0, import_log10.log)("complete", {
3656
+ (0, import_log11.log)("complete", {
3602
3657
  ...handler.toJSON()
3603
3658
  }, {
3604
- F: __dxlog_file13,
3659
+ F: __dxlog_file14,
3605
3660
  L: 241,
3606
3661
  S: this,
3607
3662
  C: (f, a) => f(...a)
@@ -3626,15 +3681,15 @@ var InvitationsManager = class {
3626
3681
  };
3627
3682
  }
3628
3683
  _createObservableAcceptingInvitation(handler, initialState) {
3629
- const otpEnteredTrigger = new import_async11.Trigger();
3630
- const stream = new import_async11.PushStream();
3684
+ const otpEnteredTrigger = new import_async12.Trigger();
3685
+ const stream = new import_async12.PushStream();
3631
3686
  const ctx = new import_context9.Context({
3632
3687
  onError: (err) => {
3633
- if (err instanceof import_async11.TimeoutError) {
3634
- (0, import_log10.log)("timeout", {
3688
+ if (err instanceof import_async12.TimeoutError) {
3689
+ (0, import_log11.log)("timeout", {
3635
3690
  ...handler.toJSON()
3636
3691
  }, {
3637
- F: __dxlog_file13,
3692
+ F: __dxlog_file14,
3638
3693
  L: 261,
3639
3694
  S: this,
3640
3695
  C: (f, a) => f(...a)
@@ -3644,8 +3699,8 @@ var InvitationsManager = class {
3644
3699
  state: import_services11.Invitation.State.TIMEOUT
3645
3700
  });
3646
3701
  } else {
3647
- import_log10.log.warn("auth failed", err, {
3648
- F: __dxlog_file13,
3702
+ import_log11.log.warn("auth failed", err, {
3703
+ F: __dxlog_file14,
3649
3704
  L: 264,
3650
3705
  S: this,
3651
3706
  C: (f, a) => f(...a)
@@ -3657,12 +3712,15 @@ var InvitationsManager = class {
3657
3712
  }
3658
3713
  void ctx.dispose();
3659
3714
  }
3715
+ }, {
3716
+ F: __dxlog_file14,
3717
+ L: 258
3660
3718
  });
3661
3719
  ctx.onDispose(() => {
3662
- (0, import_log10.log)("complete", {
3720
+ (0, import_log11.log)("complete", {
3663
3721
  ...handler.toJSON()
3664
3722
  }, {
3665
- F: __dxlog_file13,
3723
+ F: __dxlog_file14,
3666
3724
  L: 271,
3667
3725
  S: this,
3668
3726
  C: (f, a) => f(...a)
@@ -3706,8 +3764,8 @@ var InvitationsManager = class {
3706
3764
  try {
3707
3765
  await this._metadataStore.removeInvitation(invitation.invitationId);
3708
3766
  } catch (err) {
3709
- import_log10.log.catch(err, void 0, {
3710
- F: __dxlog_file13,
3767
+ import_log11.log.catch(err, void 0, {
3768
+ F: __dxlog_file14,
3711
3769
  L: 307,
3712
3770
  S: this,
3713
3771
  C: (f, a) => f(...a)
@@ -3720,12 +3778,18 @@ var InvitationsManager = class {
3720
3778
  }, callback);
3721
3779
  }
3722
3780
  };
3723
- var AutomergeSpaceState = class {
3781
+ var AutomergeSpaceState = class extends import_context11.Resource {
3724
3782
  constructor(_onNewRoot) {
3783
+ super();
3725
3784
  this._onNewRoot = _onNewRoot;
3726
3785
  this.rootUrl = void 0;
3727
3786
  this.lastEpoch = void 0;
3728
- this.onNewEpoch = new import_async13.Event();
3787
+ this.onNewEpoch = new import_async14.Event();
3788
+ this._isProcessingRootDocs = false;
3789
+ }
3790
+ async _open(ctx) {
3791
+ }
3792
+ async _close(ctx) {
3729
3793
  this._isProcessingRootDocs = false;
3730
3794
  }
3731
3795
  async processCredential(credential) {
@@ -3754,18 +3818,155 @@ var AutomergeSpaceState = class {
3754
3818
  await this.onNewEpoch.waitForCondition(() => !!this.lastEpoch);
3755
3819
  }
3756
3820
  };
3757
- var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
3821
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts";
3822
+ var runEpochMigration = async (ctx, context) => {
3823
+ switch (context.migration) {
3824
+ case import_services13.CreateEpochRequest.Migration.INIT_AUTOMERGE: {
3825
+ const document = context.repo.create();
3826
+ await context.repo.flush();
3827
+ return {
3828
+ newRoot: document.url
3829
+ };
3830
+ }
3831
+ case import_services13.CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY: {
3832
+ if (!context.currentRoot) {
3833
+ throw new Error("Space does not have an automerge root");
3834
+ }
3835
+ const rootHandle = context.repo.find(context.currentRoot);
3836
+ await (0, import_context12.cancelWithContext)(ctx, (0, import_async15.asyncTimeout)(rootHandle.whenReady(), 1e4));
3837
+ const newRoot = context.repo.create(rootHandle.docSync());
3838
+ await context.repo.flush();
3839
+ return {
3840
+ newRoot: newRoot.url
3841
+ };
3842
+ }
3843
+ case import_services13.CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT: {
3844
+ import_log13.log.info("Fragmenting", void 0, {
3845
+ F: __dxlog_file15,
3846
+ L: 63,
3847
+ S: void 0,
3848
+ C: (f, a) => f(...a)
3849
+ });
3850
+ const currentRootUrl = context.currentRoot;
3851
+ const rootHandle = context.repo.find(currentRootUrl);
3852
+ await (0, import_context12.cancelWithContext)(ctx, (0, import_async15.asyncTimeout)(rootHandle.whenReady(), 1e4));
3853
+ const objects = Object.entries(rootHandle.docSync().objects);
3854
+ const properties = (0, import_echo_db.findInlineObjectOfType)(rootHandle.docSync(), import_echo_schema.TYPE_PROPERTIES);
3855
+ const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
3856
+ (0, import_invariant13.invariant)(properties, "Properties not found", {
3857
+ F: __dxlog_file15,
3858
+ L: 73,
3859
+ S: void 0,
3860
+ A: [
3861
+ "properties",
3862
+ "'Properties not found'"
3863
+ ]
3864
+ });
3865
+ const newSpaceDoc = {
3866
+ ...rootHandle.docSync(),
3867
+ objects: Object.fromEntries([
3868
+ properties
3869
+ ])
3870
+ };
3871
+ const newRoot = context.repo.create(newSpaceDoc);
3872
+ (0, import_invariant13.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3873
+ F: __dxlog_file15,
3874
+ L: 78,
3875
+ S: void 0,
3876
+ A: [
3877
+ "typeof newRoot.url === 'string' && newRoot.url.length > 0",
3878
+ ""
3879
+ ]
3880
+ });
3881
+ const docLoader = new import_echo_pipeline3.AutomergeDocumentLoaderImpl(context.spaceId, context.repo, context.spaceKey);
3882
+ await docLoader.loadSpaceRootDocHandle(ctx, {
3883
+ rootUrl: newRoot.url
3884
+ });
3885
+ otherObjects.forEach(([key, value]) => {
3886
+ const handle = docLoader.createDocumentForObject(key);
3887
+ handle.change((doc) => {
3888
+ (0, import_util8.assignDeep)(doc, [
3889
+ "objects",
3890
+ key
3891
+ ], value);
3892
+ });
3893
+ });
3894
+ await context.repo.flush();
3895
+ return {
3896
+ newRoot: newRoot.url
3897
+ };
3898
+ }
3899
+ case import_services13.CreateEpochRequest.Migration.MIGRATE_REFERENCES_TO_DXN: {
3900
+ const currentRootUrl = context.currentRoot;
3901
+ const rootHandle = context.repo.find(currentRootUrl);
3902
+ await (0, import_context12.cancelWithContext)(ctx, (0, import_async15.asyncTimeout)(rootHandle.whenReady(), 1e4));
3903
+ (0, import_invariant13.invariant)(rootHandle.docSync(), "Root doc not found", {
3904
+ F: __dxlog_file15,
3905
+ L: 100,
3906
+ S: void 0,
3907
+ A: [
3908
+ "rootHandle.docSync()",
3909
+ "'Root doc not found'"
3910
+ ]
3911
+ });
3912
+ const newRootContent = await (0, import_echo_db.convertLegacySpaceRootDoc)(structuredClone(rootHandle.docSync()));
3913
+ for (const [id, url] of Object.entries(newRootContent.links ?? {})) {
3914
+ const handle = context.repo.find(url);
3915
+ await (0, import_context12.cancelWithContext)(ctx, (0, import_async15.asyncTimeout)(handle.whenReady(), 1e4));
3916
+ (0, import_invariant13.invariant)(handle.docSync(), "Doc not found", {
3917
+ F: __dxlog_file15,
3918
+ L: 107,
3919
+ S: void 0,
3920
+ A: [
3921
+ "handle.docSync()",
3922
+ "'Doc not found'"
3923
+ ]
3924
+ });
3925
+ const newDoc = await (0, import_echo_db.convertLegacyReferences)(structuredClone(handle.docSync()));
3926
+ const migratedDoc = (0, import_echo_db.migrateDocument)(handle.docSync(), newDoc);
3927
+ const newHandle = context.repo.import(import_automerge.next.save(migratedDoc));
3928
+ newRootContent.links[id] = newHandle.url;
3929
+ }
3930
+ const migratedRoot = (0, import_echo_db.migrateDocument)(rootHandle.docSync(), newRootContent);
3931
+ const newRoot = context.repo.import(import_automerge.next.save(migratedRoot));
3932
+ await context.repo.flush();
3933
+ return {
3934
+ newRoot: newRoot.url
3935
+ };
3936
+ }
3937
+ case import_services13.CreateEpochRequest.Migration.REPLACE_AUTOMERGE_ROOT: {
3938
+ (0, import_invariant13.invariant)(context.newAutomergeRoot, void 0, {
3939
+ F: __dxlog_file15,
3940
+ L: 124,
3941
+ S: void 0,
3942
+ A: [
3943
+ "context.newAutomergeRoot",
3944
+ ""
3945
+ ]
3946
+ });
3947
+ await context.repo.flush();
3948
+ return {
3949
+ newRoot: context.newAutomergeRoot
3950
+ };
3951
+ }
3952
+ }
3953
+ return {};
3954
+ };
3955
+ var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
3758
3956
  var DEFAULT_RETRY_TIMEOUT = 1e3;
3759
3957
  var DEFAULT_SUCCESS_DELAY = 1e3;
3760
3958
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
3761
3959
  var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
3762
3960
  var NotarizationPlugin = class {
3763
3961
  constructor() {
3764
- this._ctx = new import_context11.Context();
3765
- this._extensionOpened = new import_async14.Event();
3962
+ this._ctx = new import_context13.Context(void 0, {
3963
+ F: __dxlog_file16,
3964
+ L: 62
3965
+ });
3966
+ this._extensionOpened = new import_async16.Event();
3766
3967
  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);
3968
+ this._processedCredentials = new import_util9.ComplexSet(import_keys11.PublicKey.hash);
3969
+ this._processCredentialsTriggers = new import_util9.ComplexMap(import_keys11.PublicKey.hash);
3769
3970
  }
3770
3971
  get hasWriter() {
3771
3972
  return !!this._writer;
@@ -3779,16 +3980,16 @@ var NotarizationPlugin = class {
3779
3980
  * Request credentials to be notarized.
3780
3981
  */
3781
3982
  async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
3782
- (0, import_log12.log)("notarize", {
3983
+ (0, import_log14.log)("notarize", {
3783
3984
  credentials
3784
3985
  }, {
3785
- F: __dxlog_file14,
3986
+ F: __dxlog_file16,
3786
3987
  L: 90,
3787
3988
  S: this,
3788
3989
  C: (f, a) => f(...a)
3789
3990
  });
3790
- (0, import_invariant13.invariant)(credentials.every((credential) => credential.id), "Credentials must have an id", {
3791
- F: __dxlog_file14,
3991
+ (0, import_invariant14.invariant)(credentials.every((credential) => credential.id), "Credentials must have an id", {
3992
+ F: __dxlog_file16,
3792
3993
  L: 91,
3793
3994
  S: this,
3794
3995
  A: [
@@ -3796,13 +3997,13 @@ var NotarizationPlugin = class {
3796
3997
  "'Credentials must have an id'"
3797
3998
  ]
3798
3999
  });
3799
- const errors = new import_async14.Trigger();
4000
+ const errors = new import_async16.Trigger();
3800
4001
  const ctx = this._ctx.derive({
3801
4002
  onError: (err) => {
3802
- import_log12.log.warn("Notarization error", {
4003
+ import_log14.log.warn("Notarization error", {
3803
4004
  err
3804
4005
  }, {
3805
- F: __dxlog_file14,
4006
+ F: __dxlog_file16,
3806
4007
  L: 99,
3807
4008
  S: this,
3808
4009
  C: (f, a) => f(...a)
@@ -3813,23 +4014,23 @@ var NotarizationPlugin = class {
3813
4014
  });
3814
4015
  opCtx?.onDispose(() => ctx.dispose());
3815
4016
  if (timeout !== 0) {
3816
- (0, import_async14.scheduleTask)(ctx, () => {
3817
- import_log12.log.warn("Notarization timeout", {
4017
+ (0, import_async16.scheduleTask)(ctx, () => {
4018
+ import_log14.log.warn("Notarization timeout", {
3818
4019
  timeout,
3819
4020
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
3820
4021
  }, {
3821
- F: __dxlog_file14,
4022
+ F: __dxlog_file16,
3822
4023
  L: 111,
3823
4024
  S: this,
3824
4025
  C: (f, a) => f(...a)
3825
4026
  });
3826
4027
  void ctx.dispose();
3827
- errors.throw(new import_async14.TimeoutError(timeout, "Notarization timed out"));
4028
+ errors.throw(new import_async16.TimeoutError(timeout, "Notarization timed out"));
3828
4029
  }, timeout);
3829
4030
  }
3830
4031
  const allNotarized = Promise.all(credentials.map((credential) => this._waitUntilProcessed(credential.id)));
3831
4032
  const peersTried = /* @__PURE__ */ new Set();
3832
- const notarizeTask = new import_async14.DeferredTask(ctx, async () => {
4033
+ const notarizeTask = new import_async16.DeferredTask(ctx, async () => {
3833
4034
  try {
3834
4035
  if (this._extensions.size === 0) {
3835
4036
  return;
@@ -3838,24 +4039,24 @@ var NotarizationPlugin = class {
3838
4039
  ...this._extensions
3839
4040
  ].find((peer2) => !peersTried.has(peer2));
3840
4041
  if (!peer) {
3841
- import_log12.log.info("Exhausted all peers to notarize with", {
4042
+ import_log14.log.info("Exhausted all peers to notarize with", {
3842
4043
  retryIn: retryTimeout
3843
4044
  }, {
3844
- F: __dxlog_file14,
4045
+ F: __dxlog_file16,
3845
4046
  L: 136,
3846
4047
  S: this,
3847
4048
  C: (f, a) => f(...a)
3848
4049
  });
3849
4050
  peersTried.clear();
3850
- (0, import_async14.scheduleTask)(ctx, () => notarizeTask.schedule(), retryTimeout);
4051
+ (0, import_async16.scheduleTask)(ctx, () => notarizeTask.schedule(), retryTimeout);
3851
4052
  return;
3852
4053
  }
3853
4054
  peersTried.add(peer);
3854
- (0, import_log12.log)("try notarizing", {
4055
+ (0, import_log14.log)("try notarizing", {
3855
4056
  peer: peer.localPeerId,
3856
4057
  credentialId: credentials.map((credential) => credential.id)
3857
4058
  }, {
3858
- F: __dxlog_file14,
4059
+ F: __dxlog_file16,
3859
4060
  L: 143,
3860
4061
  S: this,
3861
4062
  C: (f, a) => f(...a)
@@ -3863,17 +4064,17 @@ var NotarizationPlugin = class {
3863
4064
  await peer.rpc.NotarizationService.notarize({
3864
4065
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
3865
4066
  });
3866
- (0, import_log12.log)("success", void 0, {
3867
- F: __dxlog_file14,
4067
+ (0, import_log14.log)("success", void 0, {
4068
+ F: __dxlog_file16,
3868
4069
  L: 147,
3869
4070
  S: this,
3870
4071
  C: (f, a) => f(...a)
3871
4072
  });
3872
- await (0, import_async14.sleep)(successDelay);
4073
+ await (0, import_async16.sleep)(successDelay);
3873
4074
  } catch (err) {
3874
4075
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
3875
- import_log12.log.info("error notarizing (recoverable)", err, {
3876
- F: __dxlog_file14,
4076
+ import_log14.log.info("error notarizing (recoverable)", err, {
4077
+ F: __dxlog_file16,
3877
4078
  L: 151,
3878
4079
  S: this,
3879
4080
  C: (f, a) => f(...a)
@@ -3886,12 +4087,12 @@ var NotarizationPlugin = class {
3886
4087
  this._extensionOpened.on(ctx, () => notarizeTask.schedule());
3887
4088
  try {
3888
4089
  await Promise.race([
3889
- (0, import_context11.rejectOnDispose)(ctx),
4090
+ (0, import_context13.rejectOnDispose)(ctx),
3890
4091
  allNotarized,
3891
4092
  errors.wait()
3892
4093
  ]);
3893
- (0, import_log12.log)("done", void 0, {
3894
- F: __dxlog_file14,
4094
+ (0, import_log14.log)("done", void 0, {
4095
+ F: __dxlog_file16,
3895
4096
  L: 162,
3896
4097
  S: this,
3897
4098
  C: (f, a) => f(...a)
@@ -3912,8 +4113,8 @@ var NotarizationPlugin = class {
3912
4113
  this._processCredentialsTriggers.delete(credential.id);
3913
4114
  }
3914
4115
  setWriter(writer) {
3915
- (0, import_invariant13.invariant)(!this._writer, "Writer already set.", {
3916
- F: __dxlog_file14,
4116
+ (0, import_invariant14.invariant)(!this._writer, "Writer already set.", {
4117
+ F: __dxlog_file16,
3917
4118
  L: 181,
3918
4119
  S: this,
3919
4120
  A: [
@@ -3927,7 +4128,7 @@ var NotarizationPlugin = class {
3927
4128
  if (this._processedCredentials.has(id)) {
3928
4129
  return;
3929
4130
  }
3930
- await (0, import_util7.entry)(this._processCredentialsTriggers, id).orInsert(new import_async14.Trigger()).value.wait();
4131
+ await (0, import_util9.entry)(this._processCredentialsTriggers, id).orInsert(new import_async16.Trigger()).value.wait();
3931
4132
  }
3932
4133
  /**
3933
4134
  * Requests from other peers to notarize credentials.
@@ -3937,8 +4138,8 @@ var NotarizationPlugin = class {
3937
4138
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
3938
4139
  }
3939
4140
  for (const credential of request.credentials ?? []) {
3940
- (0, import_invariant13.invariant)(credential.id, "Credential must have an id", {
3941
- F: __dxlog_file14,
4141
+ (0, import_invariant14.invariant)(credential.id, "Credential must have an id", {
4142
+ F: __dxlog_file16,
3942
4143
  L: 200,
3943
4144
  S: this,
3944
4145
  A: [
@@ -3955,10 +4156,10 @@ var NotarizationPlugin = class {
3955
4156
  createExtension() {
3956
4157
  const extension = new NotarizationTeleportExtension({
3957
4158
  onOpen: async () => {
3958
- (0, import_log12.log)("extension opened", {
4159
+ (0, import_log14.log)("extension opened", {
3959
4160
  peer: extension.localPeerId
3960
4161
  }, {
3961
- F: __dxlog_file14,
4162
+ F: __dxlog_file16,
3962
4163
  L: 211,
3963
4164
  S: this,
3964
4165
  C: (f, a) => f(...a)
@@ -3967,10 +4168,10 @@ var NotarizationPlugin = class {
3967
4168
  this._extensionOpened.emit();
3968
4169
  },
3969
4170
  onClose: async () => {
3970
- (0, import_log12.log)("extension closed", {
4171
+ (0, import_log14.log)("extension closed", {
3971
4172
  peer: extension.localPeerId
3972
4173
  }, {
3973
- F: __dxlog_file14,
4174
+ F: __dxlog_file16,
3974
4175
  L: 216,
3975
4176
  S: this,
3976
4177
  C: (f, a) => f(...a)
@@ -4022,16 +4223,84 @@ function _ts_decorate4(decorators, target, key, desc) {
4022
4223
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4023
4224
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4024
4225
  }
4025
- var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
4226
+ function _using_ctx() {
4227
+ var _disposeSuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed) {
4228
+ var err = new Error();
4229
+ err.name = "SuppressedError";
4230
+ err.suppressed = suppressed;
4231
+ err.error = error;
4232
+ return err;
4233
+ }, empty = {}, stack = [];
4234
+ function using(isAwait, value) {
4235
+ if (value != null) {
4236
+ if (Object(value) !== value) {
4237
+ throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
4238
+ }
4239
+ if (isAwait) {
4240
+ var dispose = value[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")];
4241
+ }
4242
+ if (dispose == null) {
4243
+ dispose = value[Symbol.dispose || Symbol.for("Symbol.dispose")];
4244
+ }
4245
+ if (typeof dispose !== "function") {
4246
+ throw new TypeError(`Property [Symbol.dispose] is not a function.`);
4247
+ }
4248
+ stack.push({
4249
+ v: value,
4250
+ d: dispose,
4251
+ a: isAwait
4252
+ });
4253
+ } else if (isAwait) {
4254
+ stack.push({
4255
+ d: value,
4256
+ a: isAwait
4257
+ });
4258
+ }
4259
+ return value;
4260
+ }
4261
+ return {
4262
+ e: empty,
4263
+ u: using.bind(null, false),
4264
+ a: using.bind(null, true),
4265
+ d: function() {
4266
+ var error = this.e;
4267
+ function next() {
4268
+ while (resource = stack.pop()) {
4269
+ try {
4270
+ var resource, disposalResult = resource.d && resource.d.call(resource.v);
4271
+ if (resource.a) {
4272
+ return Promise.resolve(disposalResult).then(next, err);
4273
+ }
4274
+ } catch (e) {
4275
+ return err(e);
4276
+ }
4277
+ }
4278
+ if (error !== empty)
4279
+ throw error;
4280
+ }
4281
+ function err(e) {
4282
+ error = error !== empty ? new _disposeSuppressedError(error, e) : e;
4283
+ return next();
4284
+ }
4285
+ return next();
4286
+ }
4287
+ };
4288
+ }
4289
+ var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
4026
4290
  var DataSpace = class {
4027
4291
  constructor(params) {
4028
- this._ctx = new import_context10.Context();
4292
+ this._ctx = new import_context10.Context(void 0, {
4293
+ F: __dxlog_file17,
4294
+ L: 84
4295
+ });
4029
4296
  this._notarizationPlugin = new NotarizationPlugin();
4030
4297
  this._cache = void 0;
4031
4298
  this._automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
4299
+ this._epochProcessingMutex = new import_async13.Mutex();
4032
4300
  this._state = import_services12.SpaceState.CLOSED;
4301
+ this._databaseRoot = null;
4033
4302
  this.error = void 0;
4034
- this.stateUpdate = new import_async12.Event();
4303
+ this.stateUpdate = new import_async13.Event();
4035
4304
  this.metrics = {};
4036
4305
  this._inner = params.inner;
4037
4306
  this._inner.stateUpdate.on(this._ctx, () => this.stateUpdate.emit());
@@ -4044,17 +4313,17 @@ var DataSpace = class {
4044
4313
  this._callbacks = params.callbacks ?? {};
4045
4314
  this._echoHost = params.echoHost;
4046
4315
  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)),
4316
+ 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
4317
  update: this._inner.stateUpdate,
4049
4318
  authTimeout: import_client_protocol4.AUTH_TIMEOUT
4050
4319
  });
4051
4320
  this._cache = params.cache;
4052
4321
  this._state = params.initialState;
4053
- (0, import_log11.log)("new state", {
4322
+ (0, import_log12.log)("new state", {
4054
4323
  state: import_services12.SpaceState[this._state]
4055
4324
  }, {
4056
- F: __dxlog_file15,
4057
- L: 143,
4325
+ F: __dxlog_file17,
4326
+ L: 146,
4058
4327
  S: this,
4059
4328
  C: (f, a) => f(...a)
4060
4329
  });
@@ -4087,6 +4356,9 @@ var DataSpace = class {
4087
4356
  get automergeSpaceState() {
4088
4357
  return this._automergeSpaceState;
4089
4358
  }
4359
+ get databaseRoot() {
4360
+ return this._databaseRoot;
4361
+ }
4090
4362
  get _automergeInfo() {
4091
4363
  return {
4092
4364
  rootUrl: this._automergeSpaceState.rootUrl,
@@ -4103,14 +4375,18 @@ var DataSpace = class {
4103
4375
  await this._gossip.open();
4104
4376
  await this._notarizationPlugin.open();
4105
4377
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
4378
+ await this._automergeSpaceState.open();
4106
4379
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
4107
- await this._inner.open(new import_context10.Context());
4380
+ await this._inner.open(new import_context10.Context(void 0, {
4381
+ F: __dxlog_file17,
4382
+ L: 215
4383
+ }));
4108
4384
  this._state = import_services12.SpaceState.CONTROL_ONLY;
4109
- (0, import_log11.log)("new state", {
4385
+ (0, import_log12.log)("new state", {
4110
4386
  state: import_services12.SpaceState[this._state]
4111
4387
  }, {
4112
- F: __dxlog_file15,
4113
- L: 209,
4388
+ F: __dxlog_file17,
4389
+ L: 217,
4114
4390
  S: this,
4115
4391
  C: (f, a) => f(...a)
4116
4392
  });
@@ -4124,19 +4400,23 @@ var DataSpace = class {
4124
4400
  async _close() {
4125
4401
  await this._callbacks.beforeClose?.();
4126
4402
  this._state = import_services12.SpaceState.CLOSED;
4127
- (0, import_log11.log)("new state", {
4403
+ (0, import_log12.log)("new state", {
4128
4404
  state: import_services12.SpaceState[this._state]
4129
4405
  }, {
4130
- F: __dxlog_file15,
4131
- L: 223,
4406
+ F: __dxlog_file17,
4407
+ L: 231,
4132
4408
  S: this,
4133
4409
  C: (f, a) => f(...a)
4134
4410
  });
4135
4411
  await this._ctx.dispose();
4136
- this._ctx = new import_context10.Context();
4412
+ this._ctx = new import_context10.Context(void 0, {
4413
+ F: __dxlog_file17,
4414
+ L: 233
4415
+ });
4137
4416
  await this.authVerifier.close();
4138
4417
  await this._inner.close();
4139
4418
  await this._inner.spaceState.removeCredentialProcessor(this._automergeSpaceState);
4419
+ await this._automergeSpaceState.close();
4140
4420
  await this._inner.spaceState.removeCredentialProcessor(this._notarizationPlugin);
4141
4421
  await this._notarizationPlugin.close();
4142
4422
  await this._presence.close();
@@ -4152,32 +4432,32 @@ var DataSpace = class {
4152
4432
  * Initialize the data pipeline in a separate task.
4153
4433
  */
4154
4434
  initializeDataPipelineAsync() {
4155
- (0, import_async12.scheduleTask)(this._ctx, async () => {
4435
+ (0, import_async13.scheduleTask)(this._ctx, async () => {
4156
4436
  try {
4157
4437
  this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
4158
4438
  await this.initializeDataPipeline();
4159
4439
  } catch (err) {
4160
4440
  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,
4441
+ (0, import_log12.log)("data pipeline initialization cancelled", err, {
4442
+ F: __dxlog_file17,
4443
+ L: 265,
4164
4444
  S: this,
4165
4445
  C: (f, a) => f(...a)
4166
4446
  });
4167
4447
  return;
4168
4448
  }
4169
- import_log11.log.error("Error initializing data pipeline", err, {
4170
- F: __dxlog_file15,
4171
- L: 260,
4449
+ import_log12.log.error("Error initializing data pipeline", err, {
4450
+ F: __dxlog_file17,
4451
+ L: 269,
4172
4452
  S: this,
4173
4453
  C: (f, a) => f(...a)
4174
4454
  });
4175
4455
  this._state = import_services12.SpaceState.ERROR;
4176
- (0, import_log11.log)("new state", {
4456
+ (0, import_log12.log)("new state", {
4177
4457
  state: import_services12.SpaceState[this._state]
4178
4458
  }, {
4179
- F: __dxlog_file15,
4180
- L: 262,
4459
+ F: __dxlog_file17,
4460
+ L: 271,
4181
4461
  S: this,
4182
4462
  C: (f, a) => f(...a)
4183
4463
  });
@@ -4193,31 +4473,28 @@ var DataSpace = class {
4193
4473
  throw new import_protocols9.SystemError("Invalid operation");
4194
4474
  }
4195
4475
  this._state = import_services12.SpaceState.INITIALIZING;
4196
- (0, import_log11.log)("new state", {
4476
+ (0, import_log12.log)("new state", {
4197
4477
  state: import_services12.SpaceState[this._state]
4198
4478
  }, {
4199
- F: __dxlog_file15,
4200
- L: 278,
4479
+ F: __dxlog_file17,
4480
+ L: 287,
4201
4481
  S: this,
4202
4482
  C: (f, a) => f(...a)
4203
4483
  });
4204
4484
  await this._initializeAndReadControlPipeline();
4205
- await (0, import_async12.sleep)(1);
4485
+ await (0, import_async13.sleep)(1);
4486
+ const ready = this.stateUpdate.waitForCondition(() => this._state === import_services12.SpaceState.READY);
4206
4487
  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
- });
4488
+ await ready;
4489
+ }
4490
+ async _enterReadyState() {
4214
4491
  await this._callbacks.beforeReady?.();
4215
4492
  this._state = import_services12.SpaceState.READY;
4216
- (0, import_log11.log)("new state", {
4493
+ (0, import_log12.log)("new state", {
4217
4494
  state: import_services12.SpaceState[this._state]
4218
4495
  }, {
4219
- F: __dxlog_file15,
4220
- L: 294,
4496
+ F: __dxlog_file17,
4497
+ L: 306,
4221
4498
  S: this,
4222
4499
  C: (f, a) => f(...a)
4223
4500
  });
@@ -4231,9 +4508,9 @@ var DataSpace = class {
4231
4508
  });
4232
4509
  this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
4233
4510
  await this._createWritableFeeds();
4234
- (0, import_log11.log)("writable feeds created", void 0, {
4235
- F: __dxlog_file15,
4236
- L: 310,
4511
+ (0, import_log12.log)("writable feeds created", void 0, {
4512
+ F: __dxlog_file17,
4513
+ L: 322,
4237
4514
  S: this,
4238
4515
  C: (f, a) => f(...a)
4239
4516
  });
@@ -4291,57 +4568,66 @@ var DataSpace = class {
4291
4568
  }
4292
4569
  }
4293
4570
  _onNewAutomergeRoot(rootUrl) {
4294
- (0, import_log11.log)("loading automerge root doc for space", {
4571
+ (0, import_log12.log)("loading automerge root doc for space", {
4295
4572
  space: this.key,
4296
4573
  rootUrl
4297
4574
  }, {
4298
- F: __dxlog_file15,
4299
- L: 376,
4575
+ F: __dxlog_file17,
4576
+ L: 388,
4300
4577
  S: this,
4301
4578
  C: (f, a) => f(...a)
4302
4579
  });
4303
- this._echoHost.replicateDocument(rootUrl);
4304
4580
  const handle = this._echoHost.automergeRepo.find(rootUrl);
4305
4581
  queueMicrotask(async () => {
4306
4582
  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)
4583
+ try {
4584
+ var _usingCtx = _using_ctx();
4585
+ await (0, import_debug3.warnAfterTimeout)(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
4586
+ await (0, import_context10.cancelWithContext)(this._ctx, handle.whenReady());
4332
4587
  });
4588
+ if (this._ctx.disposed) {
4589
+ return;
4590
+ }
4591
+ const _guard = (
4592
+ // Ensure only one root is processed at a time.
4593
+ _usingCtx.u(await this._epochProcessingMutex.acquire())
4594
+ );
4595
+ const doc = handle.docSync() ?? (0, import_invariant12.failedInvariant)();
4596
+ if (!doc.access?.spaceKey) {
4597
+ handle.change((doc2) => {
4598
+ doc2.access = {
4599
+ spaceKey: this.key.toHex()
4600
+ };
4601
+ });
4602
+ }
4603
+ const root = await this._echoHost.openSpaceRoot(handle.url);
4604
+ this._databaseRoot = root;
4605
+ if (root.getVersion() !== import_echo_protocol.SpaceDocVersion.CURRENT) {
4606
+ if (this._state !== import_services12.SpaceState.REQUIRES_MIGRATION) {
4607
+ this._state = import_services12.SpaceState.REQUIRES_MIGRATION;
4608
+ this.stateUpdate.emit();
4609
+ }
4610
+ } else {
4611
+ if (this._state !== import_services12.SpaceState.READY) {
4612
+ await this._enterReadyState();
4613
+ }
4614
+ }
4615
+ } catch (_) {
4616
+ _usingCtx.e = _;
4617
+ } finally {
4618
+ _usingCtx.d();
4333
4619
  }
4334
4620
  } catch (err) {
4335
4621
  if (err instanceof import_context10.ContextDisposedError) {
4336
4622
  return;
4337
4623
  }
4338
- import_log11.log.warn("error loading automerge root doc", {
4624
+ import_log12.log.warn("error loading automerge root doc", {
4339
4625
  space: this.key,
4340
4626
  rootUrl,
4341
4627
  err
4342
4628
  }, {
4343
- F: __dxlog_file15,
4344
- L: 409,
4629
+ F: __dxlog_file17,
4630
+ L: 431,
4345
4631
  S: this,
4346
4632
  C: (f, a) => f(...a)
4347
4633
  });
@@ -4364,148 +4650,34 @@ var DataSpace = class {
4364
4650
  });
4365
4651
  }
4366
4652
  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;
4653
+ const ctx = this._ctx.derive();
4654
+ if (!options?.migration) {
4655
+ return null;
4499
4656
  }
4657
+ const { newRoot } = await runEpochMigration(ctx, {
4658
+ repo: this._echoHost.automergeRepo,
4659
+ spaceId: this.id,
4660
+ spaceKey: this.key,
4661
+ migration: options.migration,
4662
+ currentRoot: this._automergeSpaceState.rootUrl ?? null,
4663
+ newAutomergeRoot: options.newAutomergeRoot
4664
+ });
4665
+ const epoch = {
4666
+ previousId: this._automergeSpaceState.lastEpoch?.id,
4667
+ number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
4668
+ timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new import_timeframe3.Timeframe(),
4669
+ automergeRoot: newRoot ?? this._automergeSpaceState.rootUrl
4670
+ };
4671
+ const credential = await this._signingContext.credentialSigner.createCredential({
4672
+ subject: this.key,
4673
+ assertion: {
4674
+ "@type": "dxos.halo.credentials.Epoch",
4675
+ ...epoch
4676
+ }
4677
+ });
4500
4678
  const receipt = await this.inner.controlPipeline.writer.write({
4501
4679
  credential: {
4502
- credential: await this._signingContext.credentialSigner.createCredential({
4503
- subject: this.key,
4504
- assertion: {
4505
- "@type": "dxos.halo.credentials.Epoch",
4506
- ...epoch
4507
- }
4508
- })
4680
+ credential
4509
4681
  }
4510
4682
  });
4511
4683
  await this.inner.controlPipeline.state.waitUntilTimeframe(new import_timeframe3.Timeframe([
@@ -4515,6 +4687,7 @@ var DataSpace = class {
4515
4687
  ]
4516
4688
  ]));
4517
4689
  await this._echoHost.updateIndexes();
4690
+ return credential;
4518
4691
  }
4519
4692
  async activate() {
4520
4693
  if (![
@@ -4536,11 +4709,11 @@ var DataSpace = class {
4536
4709
  await this._close();
4537
4710
  }
4538
4711
  this._state = import_services12.SpaceState.INACTIVE;
4539
- (0, import_log11.log)("new state", {
4712
+ (0, import_log12.log)("new state", {
4540
4713
  state: import_services12.SpaceState[this._state]
4541
4714
  }, {
4542
- F: __dxlog_file15,
4543
- L: 571,
4715
+ F: __dxlog_file17,
4716
+ L: 512,
4544
4717
  S: this,
4545
4718
  C: (f, a) => f(...a)
4546
4719
  });
@@ -4567,10 +4740,10 @@ _ts_decorate4([
4567
4740
  })
4568
4741
  ], DataSpace.prototype, "_automergeInfo", null);
4569
4742
  _ts_decorate4([
4570
- import_async12.synchronized
4743
+ import_async13.synchronized
4571
4744
  ], DataSpace.prototype, "open", null);
4572
4745
  _ts_decorate4([
4573
- import_async12.synchronized
4746
+ import_async13.synchronized
4574
4747
  ], DataSpace.prototype, "close", null);
4575
4748
  _ts_decorate4([
4576
4749
  import_tracing5.trace.span({
@@ -4586,27 +4759,15 @@ _ts_decorate4([
4586
4759
  (0, import_debug3.timed)(1e4)
4587
4760
  ], DataSpace.prototype, "_createWritableFeeds", null);
4588
4761
  _ts_decorate4([
4589
- import_async12.synchronized
4762
+ import_async13.synchronized
4590
4763
  ], DataSpace.prototype, "activate", null);
4591
4764
  _ts_decorate4([
4592
- import_async12.synchronized
4765
+ import_async13.synchronized
4593
4766
  ], DataSpace.prototype, "deactivate", null);
4594
4767
  DataSpace = _ts_decorate4([
4595
- (0, import_async12.trackLeaks)("open", "close"),
4768
+ (0, import_async13.trackLeaks)("open", "close"),
4596
4769
  import_tracing5.trace.resource()
4597
4770
  ], 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
4771
  var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
4611
4772
  const credentials = [
4612
4773
  await (0, import_credentials17.createCredential)({
@@ -4681,7 +4842,7 @@ function _ts_decorate5(decorators, target, key, desc) {
4681
4842
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4682
4843
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4683
4844
  }
4684
- var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
4845
+ var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
4685
4846
  var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
4686
4847
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
4687
4848
  var DEFAULT_SPACE_KEY = "__DEFAULT__";
@@ -4695,9 +4856,12 @@ var DataSpaceManager = class {
4695
4856
  this._echoHost = _echoHost;
4696
4857
  this._invitationsManager = _invitationsManager;
4697
4858
  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);
4859
+ this._ctx = new import_context14.Context(void 0, {
4860
+ F: __dxlog_file18,
4861
+ L: 104
4862
+ });
4863
+ this.updated = new import_async17.Event();
4864
+ this._spaces = new import_util10.ComplexMap(import_keys12.PublicKey.hash);
4701
4865
  this._isOpen = false;
4702
4866
  this._instanceId = import_keys12.PublicKey.random().toHex();
4703
4867
  import_tracing6.trace.diagnostic({
@@ -4708,10 +4872,10 @@ var DataSpaceManager = class {
4708
4872
  const rootUrl = space.automergeSpaceState.rootUrl;
4709
4873
  const rootHandle = rootUrl ? this._echoHost.automergeRepo.find(rootUrl) : void 0;
4710
4874
  const rootDoc = rootHandle?.docSync();
4711
- const properties = rootDoc && findPropertiesObject(rootDoc);
4875
+ const properties = rootDoc && (0, import_echo_db2.findInlineObjectOfType)(rootDoc, import_echo_schema2.TYPE_PROPERTIES);
4712
4876
  return {
4713
4877
  key: space.key.toHex(),
4714
- state: import_services13.SpaceState[space.state],
4878
+ state: import_services14.SpaceState[space.state],
4715
4879
  name: properties?.[1].data.name ?? null,
4716
4880
  inlineObjects: rootDoc ? Object.keys(rootDoc.objects ?? {}).length : null,
4717
4881
  linkedObjects: rootDoc ? Object.keys(rootDoc.links ?? {}).length : null,
@@ -4728,46 +4892,46 @@ var DataSpaceManager = class {
4728
4892
  return this._spaces;
4729
4893
  }
4730
4894
  async open() {
4731
- (0, import_log13.log)("open", void 0, {
4732
- F: __dxlog_file16,
4733
- L: 140,
4895
+ (0, import_log15.log)("open", void 0, {
4896
+ F: __dxlog_file18,
4897
+ L: 156,
4734
4898
  S: this,
4735
4899
  C: (f, a) => f(...a)
4736
4900
  });
4737
- import_log13.log.trace("dxos.echo.data-space-manager.open", import_protocols11.trace.begin({
4901
+ import_log15.log.trace("dxos.echo.data-space-manager.open", import_protocols11.trace.begin({
4738
4902
  id: this._instanceId
4739
4903
  }), {
4740
- F: __dxlog_file16,
4741
- L: 141,
4904
+ F: __dxlog_file18,
4905
+ L: 157,
4742
4906
  S: this,
4743
4907
  C: (f, a) => f(...a)
4744
4908
  });
4745
- (0, import_log13.log)("metadata loaded", {
4909
+ (0, import_log15.log)("metadata loaded", {
4746
4910
  spaces: this._metadataStore.spaces.length
4747
4911
  }, {
4748
- F: __dxlog_file16,
4749
- L: 142,
4912
+ F: __dxlog_file18,
4913
+ L: 158,
4750
4914
  S: this,
4751
4915
  C: (f, a) => f(...a)
4752
4916
  });
4753
- await (0, import_util8.forEachAsync)(this._metadataStore.spaces, async (spaceMetadata) => {
4917
+ await (0, import_util10.forEachAsync)(this._metadataStore.spaces, async (spaceMetadata) => {
4754
4918
  try {
4755
- (0, import_log13.log)("load space", {
4919
+ (0, import_log15.log)("load space", {
4756
4920
  spaceMetadata
4757
4921
  }, {
4758
- F: __dxlog_file16,
4759
- L: 146,
4922
+ F: __dxlog_file18,
4923
+ L: 162,
4760
4924
  S: this,
4761
4925
  C: (f, a) => f(...a)
4762
4926
  });
4763
4927
  await this._constructSpace(spaceMetadata);
4764
4928
  } catch (err) {
4765
- import_log13.log.error("Error loading space", {
4929
+ import_log15.log.error("Error loading space", {
4766
4930
  spaceMetadata,
4767
4931
  err
4768
4932
  }, {
4769
- F: __dxlog_file16,
4770
- L: 149,
4933
+ F: __dxlog_file18,
4934
+ L: 165,
4771
4935
  S: this,
4772
4936
  C: (f, a) => f(...a)
4773
4937
  });
@@ -4775,19 +4939,19 @@ var DataSpaceManager = class {
4775
4939
  });
4776
4940
  this._isOpen = true;
4777
4941
  this.updated.emit();
4778
- import_log13.log.trace("dxos.echo.data-space-manager.open", import_protocols11.trace.end({
4942
+ import_log15.log.trace("dxos.echo.data-space-manager.open", import_protocols11.trace.end({
4779
4943
  id: this._instanceId
4780
- }), {
4781
- F: __dxlog_file16,
4782
- L: 156,
4944
+ }), {
4945
+ F: __dxlog_file18,
4946
+ L: 172,
4783
4947
  S: this,
4784
4948
  C: (f, a) => f(...a)
4785
4949
  });
4786
4950
  }
4787
4951
  async close() {
4788
- (0, import_log13.log)("close", void 0, {
4789
- F: __dxlog_file16,
4790
- L: 161,
4952
+ (0, import_log15.log)("close", void 0, {
4953
+ F: __dxlog_file18,
4954
+ L: 177,
4791
4955
  S: this,
4792
4956
  C: (f, a) => f(...a)
4793
4957
  });
@@ -4802,9 +4966,9 @@ var DataSpaceManager = class {
4802
4966
  * Creates a new space writing the genesis credentials to the control feed.
4803
4967
  */
4804
4968
  async createSpace() {
4805
- (0, import_invariant14.invariant)(this._isOpen, "Not open.", {
4806
- F: __dxlog_file16,
4807
- L: 175,
4969
+ (0, import_invariant15.invariant)(this._isOpen, "Not open.", {
4970
+ F: __dxlog_file18,
4971
+ L: 191,
4808
4972
  S: this,
4809
4973
  A: [
4810
4974
  "this._isOpen",
@@ -4819,13 +4983,13 @@ var DataSpaceManager = class {
4819
4983
  genesisFeedKey: controlFeedKey,
4820
4984
  controlFeedKey,
4821
4985
  dataFeedKey,
4822
- state: import_services13.SpaceState.ACTIVE
4986
+ state: import_services14.SpaceState.ACTIVE
4823
4987
  };
4824
- (0, import_log13.log)("creating space...", {
4988
+ (0, import_log15.log)("creating space...", {
4825
4989
  spaceKey
4826
4990
  }, {
4827
- F: __dxlog_file16,
4828
- L: 187,
4991
+ F: __dxlog_file18,
4992
+ L: 203,
4829
4993
  S: this,
4830
4994
  C: (f, a) => f(...a)
4831
4995
  });
@@ -4835,9 +4999,9 @@ var DataSpaceManager = class {
4835
4999
  const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, root.url);
4836
5000
  await this._metadataStore.addSpace(metadata);
4837
5001
  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,
5002
+ (0, import_invariant15.invariant)((0, import_credentials15.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
5003
+ F: __dxlog_file18,
5004
+ L: 213,
4841
5005
  S: this,
4842
5006
  A: [
4843
5007
  "getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -4850,16 +5014,38 @@ var DataSpaceManager = class {
4850
5014
  return space;
4851
5015
  }
4852
5016
  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();
5017
+ if (!space.databaseRoot) {
5018
+ return false;
5019
+ }
5020
+ switch (space.databaseRoot.getVersion()) {
5021
+ case import_echo_protocol2.SpaceDocVersion.CURRENT: {
5022
+ const [_, properties] = (0, import_echo_db2.findInlineObjectOfType)(space.databaseRoot.docSync(), import_echo_schema2.TYPE_PROPERTIES) ?? [];
5023
+ return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
5024
+ }
5025
+ case import_echo_protocol2.SpaceDocVersion.LEGACY: {
5026
+ const convertedDoc = await (0, import_echo_db2.convertLegacyReferences)(space.databaseRoot.docSync());
5027
+ const [_, properties] = (0, import_echo_db2.findInlineObjectOfType)(convertedDoc, import_echo_protocol2.LEGACY_TYPE_PROPERTIES) ?? [];
5028
+ return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
5029
+ }
5030
+ default:
5031
+ import_log15.log.warn("unknown space version", {
5032
+ version: space.databaseRoot.getVersion(),
5033
+ spaceId: space.id
5034
+ }, {
5035
+ F: __dxlog_file18,
5036
+ L: 238,
5037
+ S: this,
5038
+ C: (f, a) => f(...a)
5039
+ });
5040
+ return false;
5041
+ }
4856
5042
  }
4857
5043
  async createDefaultSpace() {
4858
5044
  const space = await this.createSpace();
4859
5045
  const document = await this._getSpaceRootDocument(space);
4860
5046
  const properties = {
4861
5047
  system: {
4862
- type: (0, import_echo_protocol.encodeReference)((0, import_echo_schema2.getTypeReference)(import_client_protocol5.PropertiesType))
5048
+ type: (0, import_echo_protocol2.encodeReference)((0, import_echo_schema2.getTypeReference)(import_client_protocol5.PropertiesType))
4863
5049
  },
4864
5050
  data: {
4865
5051
  [DEFAULT_SPACE_KEY]: this._signingContext.identityKey.toHex()
@@ -4868,9 +5054,9 @@ var DataSpaceManager = class {
4868
5054
  keys: []
4869
5055
  }
4870
5056
  };
4871
- const propertiesId = import_keys12.PublicKey.random().toHex();
5057
+ const propertiesId = (0, import_echo_schema2.generateEchoId)();
4872
5058
  document.change((doc) => {
4873
- (0, import_util8.assignDeep)(doc, [
5059
+ (0, import_util10.assignDeep)(doc, [
4874
5060
  "objects",
4875
5061
  propertiesId
4876
5062
  ], properties);
@@ -4880,9 +5066,9 @@ var DataSpaceManager = class {
4880
5066
  }
4881
5067
  async _getSpaceRootDocument(space) {
4882
5068
  const automergeIndex = space.automergeSpaceState.rootUrl;
4883
- (0, import_invariant14.invariant)(automergeIndex, void 0, {
4884
- F: __dxlog_file16,
4885
- L: 240,
5069
+ (0, import_invariant15.invariant)(automergeIndex, void 0, {
5070
+ F: __dxlog_file18,
5071
+ L: 271,
4886
5072
  S: this,
4887
5073
  A: [
4888
5074
  "automergeIndex",
@@ -4895,26 +5081,26 @@ var DataSpaceManager = class {
4895
5081
  }
4896
5082
  // TODO(burdon): Rename join space.
4897
5083
  async acceptSpace(opts) {
4898
- (0, import_log13.log)("accept space", {
5084
+ (0, import_log15.log)("accept space", {
4899
5085
  opts
4900
5086
  }, {
4901
- F: __dxlog_file16,
4902
- L: 249,
5087
+ F: __dxlog_file18,
5088
+ L: 280,
4903
5089
  S: this,
4904
5090
  C: (f, a) => f(...a)
4905
5091
  });
4906
- (0, import_invariant14.invariant)(this._isOpen, "Not open.", {
4907
- F: __dxlog_file16,
4908
- L: 250,
5092
+ (0, import_invariant15.invariant)(this._isOpen, "Not open.", {
5093
+ F: __dxlog_file18,
5094
+ L: 281,
4909
5095
  S: this,
4910
5096
  A: [
4911
5097
  "this._isOpen",
4912
5098
  "'Not open.'"
4913
5099
  ]
4914
5100
  });
4915
- (0, import_invariant14.invariant)(!this._spaces.has(opts.spaceKey), "Space already exists.", {
4916
- F: __dxlog_file16,
4917
- L: 251,
5101
+ (0, import_invariant15.invariant)(!this._spaces.has(opts.spaceKey), "Space already exists.", {
5102
+ F: __dxlog_file18,
5103
+ L: 282,
4918
5104
  S: this,
4919
5105
  A: [
4920
5106
  "!this._spaces.has(opts.spaceKey)",
@@ -4934,23 +5120,72 @@ var DataSpaceManager = class {
4934
5120
  this.updated.emit();
4935
5121
  return space;
4936
5122
  }
5123
+ async admitMember(options) {
5124
+ const space = this._spaceManager.spaces.get(options.spaceKey);
5125
+ (0, import_invariant15.invariant)(space, void 0, {
5126
+ F: __dxlog_file18,
5127
+ L: 302,
5128
+ S: this,
5129
+ A: [
5130
+ "space",
5131
+ ""
5132
+ ]
5133
+ });
5134
+ if (space.spaceState.getMemberRole(options.identityKey) !== import_credentials16.SpaceMember.Role.REMOVED) {
5135
+ throw new import_protocols11.AlreadyJoinedError();
5136
+ }
5137
+ const credentials = await (0, import_credentials15.createAdmissionCredentials)(this._signingContext.credentialSigner, options.identityKey, space.key, space.genesisFeedKey, options.role, space.spaceState.membershipChainHeads, options.profile, options.delegationCredentialId);
5138
+ (0, import_invariant15.invariant)(credentials[0].credential, void 0, {
5139
+ F: __dxlog_file18,
5140
+ L: 321,
5141
+ S: this,
5142
+ A: [
5143
+ "credentials[0].credential",
5144
+ ""
5145
+ ]
5146
+ });
5147
+ const spaceMemberCredential = credentials[0].credential.credential;
5148
+ (0, import_invariant15.invariant)((0, import_credentials15.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
5149
+ F: __dxlog_file18,
5150
+ L: 323,
5151
+ S: this,
5152
+ A: [
5153
+ "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
5154
+ ""
5155
+ ]
5156
+ });
5157
+ await (0, import_feed_store4.writeMessages)(space.controlPipeline.writer, credentials);
5158
+ return spaceMemberCredential;
5159
+ }
4937
5160
  /**
4938
5161
  * Wait until the space data pipeline is fully initialized.
4939
5162
  * Used by invitation handler.
4940
5163
  * TODO(dmaretskyi): Consider removing.
4941
5164
  */
4942
5165
  async waitUntilSpaceReady(spaceKey) {
4943
- await (0, import_context12.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
5166
+ await (0, import_context14.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
4944
5167
  const space = this._spaces.get(spaceKey);
4945
- return !!space && space.state === import_services13.SpaceState.READY;
5168
+ return !!space && space.state === import_services14.SpaceState.READY;
4946
5169
  }));
4947
5170
  }
5171
+ async requestSpaceAdmissionCredential(spaceKey) {
5172
+ return this._spaceManager.requestSpaceAdmissionCredential({
5173
+ spaceKey,
5174
+ identityKey: this._signingContext.identityKey,
5175
+ timeout: 15e3,
5176
+ swarmIdentity: {
5177
+ peerKey: this._signingContext.deviceKey,
5178
+ credentialProvider: createAuthProvider(this._signingContext.credentialSigner),
5179
+ credentialAuthenticator: async () => true
5180
+ }
5181
+ });
5182
+ }
4948
5183
  async _constructSpace(metadata) {
4949
- (0, import_log13.log)("construct space", {
5184
+ (0, import_log15.log)("construct space", {
4950
5185
  metadata
4951
5186
  }, {
4952
- F: __dxlog_file16,
4953
- L: 285,
5187
+ F: __dxlog_file18,
5188
+ L: 358,
4954
5189
  S: this,
4955
5190
  C: (f, a) => f(...a)
4956
5191
  });
@@ -4975,9 +5210,10 @@ var DataSpaceManager = class {
4975
5210
  swarmIdentity: {
4976
5211
  peerKey: this._signingContext.deviceKey,
4977
5212
  credentialProvider: createAuthProvider(this._signingContext.credentialSigner),
4978
- credentialAuthenticator: (0, import_util8.deferFunction)(() => dataSpace.authVerifier.verifier)
5213
+ credentialAuthenticator: (0, import_util10.deferFunction)(() => dataSpace.authVerifier.verifier)
4979
5214
  },
4980
5215
  onAuthorizedConnection: (session) => {
5216
+ session.addExtension("dxos.mesh.teleport.admission-discovery", new import_echo_pipeline5.CredentialServerExtension(space));
4981
5217
  session.addExtension("dxos.mesh.teleport.gossip", gossip.createExtension({
4982
5218
  remotePeerId: session.remotePeerId
4983
5219
  }));
@@ -4986,15 +5222,15 @@ var DataSpaceManager = class {
4986
5222
  session.addExtension("dxos.mesh.teleport.automerge", this._echoHost.createReplicationExtension());
4987
5223
  },
4988
5224
  onAuthFailure: () => {
4989
- import_log13.log.warn("auth failure", void 0, {
4990
- F: __dxlog_file16,
4991
- L: 322,
5225
+ import_log15.log.warn("auth failure", void 0, {
5226
+ F: __dxlog_file18,
5227
+ L: 396,
4992
5228
  S: this,
4993
5229
  C: (f, a) => f(...a)
4994
5230
  });
4995
5231
  },
4996
5232
  onMemberRolesChanged: async (members) => {
4997
- if (dataSpace?.state === import_services13.SpaceState.READY) {
5233
+ if (dataSpace?.state === import_services14.SpaceState.READY) {
4998
5234
  this._handleMemberRoleChanges(presence, space.protocol, members);
4999
5235
  }
5000
5236
  },
@@ -5007,7 +5243,7 @@ var DataSpaceManager = class {
5007
5243
  dataFeed && await space.setDataFeed(dataFeed);
5008
5244
  const dataSpace = new DataSpace({
5009
5245
  inner: space,
5010
- initialState: metadata.state === import_services13.SpaceState.INACTIVE ? import_services13.SpaceState.INACTIVE : import_services13.SpaceState.CLOSED,
5246
+ initialState: metadata.state === import_services14.SpaceState.INACTIVE ? import_services14.SpaceState.INACTIVE : import_services14.SpaceState.CLOSED,
5011
5247
  metadataStore: this._metadataStore,
5012
5248
  gossip,
5013
5249
  presence,
@@ -5017,22 +5253,22 @@ var DataSpaceManager = class {
5017
5253
  signingContext: this._signingContext,
5018
5254
  callbacks: {
5019
5255
  beforeReady: async () => {
5020
- (0, import_log13.log)("before space ready", {
5256
+ (0, import_log15.log)("before space ready", {
5021
5257
  space: space.key
5022
5258
  }, {
5023
- F: __dxlog_file16,
5024
- L: 349,
5259
+ F: __dxlog_file18,
5260
+ L: 423,
5025
5261
  S: this,
5026
5262
  C: (f, a) => f(...a)
5027
5263
  });
5028
5264
  },
5029
5265
  afterReady: async () => {
5030
- (0, import_log13.log)("after space ready", {
5266
+ (0, import_log15.log)("after space ready", {
5031
5267
  space: space.key,
5032
5268
  open: this._isOpen
5033
5269
  }, {
5034
- F: __dxlog_file16,
5035
- L: 352,
5270
+ F: __dxlog_file18,
5271
+ L: 426,
5036
5272
  S: this,
5037
5273
  C: (f, a) => f(...a)
5038
5274
  });
@@ -5047,11 +5283,11 @@ var DataSpaceManager = class {
5047
5283
  }
5048
5284
  },
5049
5285
  beforeClose: async () => {
5050
- (0, import_log13.log)("before space close", {
5286
+ (0, import_log15.log)("before space close", {
5051
5287
  space: space.key
5052
5288
  }, {
5053
- F: __dxlog_file16,
5054
- L: 360,
5289
+ F: __dxlog_file18,
5290
+ L: 434,
5055
5291
  S: this,
5056
5292
  C: (f, a) => f(...a)
5057
5293
  });
@@ -5060,7 +5296,7 @@ var DataSpaceManager = class {
5060
5296
  cache: metadata.cache
5061
5297
  });
5062
5298
  presence.newPeer.on((peerState) => {
5063
- if (dataSpace.state === import_services13.SpaceState.READY) {
5299
+ if (dataSpace.state === import_services14.SpaceState.READY) {
5064
5300
  this._handleNewPeerConnected(space, peerState);
5065
5301
  }
5066
5302
  });
@@ -5079,20 +5315,20 @@ var DataSpaceManager = class {
5079
5315
  const peers = presence.getPeersByIdentityKey(member.key);
5080
5316
  const sessions = peers.map((p) => p.peerId && spaceProtocol.sessions.get(p.peerId));
5081
5317
  const sessionsToClose = sessions.filter((s) => {
5082
- return (s && member.role === import_credentials16.SpaceMember.Role.REMOVED !== (s.authStatus === import_echo_pipeline3.AuthStatus.FAILURE)) ?? false;
5318
+ return (s && member.role === import_credentials16.SpaceMember.Role.REMOVED !== (s.authStatus === import_echo_pipeline4.AuthStatus.FAILURE)) ?? false;
5083
5319
  });
5084
5320
  sessionsToClose.forEach((session) => {
5085
- void session.close().catch(import_log13.log.error);
5321
+ void session.close().catch(import_log15.log.error);
5086
5322
  });
5087
5323
  closedSessions += sessionsToClose.length;
5088
5324
  }
5089
- (0, import_log13.log)("processed member role changes", {
5325
+ (0, import_log15.log)("processed member role changes", {
5090
5326
  roleChangeCount: memberInfo.length,
5091
5327
  peersOnline: presence.getPeersOnline().length,
5092
5328
  closedSessions
5093
5329
  }, {
5094
- F: __dxlog_file16,
5095
- L: 396,
5330
+ F: __dxlog_file18,
5331
+ L: 470,
5096
5332
  S: this,
5097
5333
  C: (f, a) => f(...a)
5098
5334
  });
@@ -5103,20 +5339,20 @@ var DataSpaceManager = class {
5103
5339
  if (role === import_credentials16.SpaceMember.Role.REMOVED) {
5104
5340
  const session = peerState.peerId && space.protocol.sessions.get(peerState.peerId);
5105
5341
  if (session != null) {
5106
- (0, import_log13.log)("closing a session with a removed peer", {
5342
+ (0, import_log15.log)("closing a session with a removed peer", {
5107
5343
  peerId: peerState.peerId
5108
5344
  }, {
5109
- F: __dxlog_file16,
5110
- L: 410,
5345
+ F: __dxlog_file18,
5346
+ L: 484,
5111
5347
  S: this,
5112
5348
  C: (f, a) => f(...a)
5113
5349
  });
5114
- void session.close().catch(import_log13.log.error);
5350
+ void session.close().catch(import_log15.log.error);
5115
5351
  }
5116
5352
  }
5117
5353
  }
5118
5354
  async _handleInvitationStatusChange(dataSpace, delegatedInvitation, isActive) {
5119
- if (dataSpace?.state !== import_services13.SpaceState.READY) {
5355
+ if (dataSpace?.state !== import_services14.SpaceState.READY) {
5120
5356
  return;
5121
5357
  }
5122
5358
  if (isActive) {
@@ -5133,8 +5369,8 @@ var DataSpaceManager = class {
5133
5369
  async _createDelegatedInvitations(space, invitations) {
5134
5370
  const tasks = invitations.map(([credentialId, invitation]) => {
5135
5371
  return this._invitationsManager.createInvitation({
5136
- type: import_services13.Invitation.Type.DELEGATED,
5137
- kind: import_services13.Invitation.Kind.SPACE,
5372
+ type: import_services14.Invitation.Type.DELEGATED,
5373
+ kind: import_services14.Invitation.Kind.SPACE,
5138
5374
  spaceKey: space.key,
5139
5375
  authMethod: invitation.authMethod,
5140
5376
  invitationId: invitation.invitationId,
@@ -5152,21 +5388,21 @@ var DataSpaceManager = class {
5152
5388
  }
5153
5389
  };
5154
5390
  _ts_decorate5([
5155
- import_async15.synchronized
5391
+ import_async17.synchronized
5156
5392
  ], DataSpaceManager.prototype, "open", null);
5157
5393
  _ts_decorate5([
5158
- import_async15.synchronized
5394
+ import_async17.synchronized
5159
5395
  ], DataSpaceManager.prototype, "close", null);
5160
5396
  _ts_decorate5([
5161
- import_async15.synchronized
5397
+ import_async17.synchronized
5162
5398
  ], DataSpaceManager.prototype, "createSpace", null);
5163
5399
  _ts_decorate5([
5164
- import_async15.synchronized
5400
+ import_async17.synchronized
5165
5401
  ], DataSpaceManager.prototype, "acceptSpace", null);
5166
5402
  DataSpaceManager = _ts_decorate5([
5167
- (0, import_async15.trackLeaks)("open", "close")
5403
+ (0, import_async17.trackLeaks)("open", "close")
5168
5404
  ], DataSpaceManager);
5169
- var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
5405
+ var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
5170
5406
  var SpacesServiceImpl = class {
5171
5407
  constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
5172
5408
  this._identityManager = _identityManager;
@@ -5185,10 +5421,10 @@ var SpacesServiceImpl = class {
5185
5421
  const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols12.SpaceNotFoundError(spaceKey));
5186
5422
  if (state) {
5187
5423
  switch (state) {
5188
- case import_services14.SpaceState.ACTIVE:
5424
+ case import_services15.SpaceState.ACTIVE:
5189
5425
  await space.activate();
5190
5426
  break;
5191
- case import_services14.SpaceState.INACTIVE:
5427
+ case import_services15.SpaceState.INACTIVE:
5192
5428
  await space.deactivate();
5193
5429
  break;
5194
5430
  default:
@@ -5209,9 +5445,9 @@ var SpacesServiceImpl = class {
5209
5445
  });
5210
5446
  }
5211
5447
  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,
5448
+ (0, import_invariant16.invariant)(credentials[0].credential, void 0, {
5449
+ F: __dxlog_file19,
5450
+ L: 102,
5215
5451
  S: this,
5216
5452
  A: [
5217
5453
  "credentials[0].credential",
@@ -5219,27 +5455,27 @@ var SpacesServiceImpl = class {
5219
5455
  ]
5220
5456
  });
5221
5457
  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,
5458
+ (0, import_invariant16.invariant)((0, import_credentials19.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
5459
+ F: __dxlog_file19,
5460
+ L: 104,
5225
5461
  S: this,
5226
5462
  A: [
5227
5463
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
5228
5464
  ""
5229
5465
  ]
5230
5466
  });
5231
- await (0, import_feed_store4.writeMessages)(space.controlPipeline.writer, credentials);
5467
+ await (0, import_feed_store5.writeMessages)(space.controlPipeline.writer, credentials);
5232
5468
  }
5233
5469
  querySpaces() {
5234
5470
  return new import_codec_protobuf11.Stream(({ next, ctx }) => {
5235
- const scheduler = new import_async16.UpdateScheduler(ctx, async () => {
5471
+ const scheduler = new import_async18.UpdateScheduler(ctx, async () => {
5236
5472
  const dataSpaceManager = await this._getDataSpaceManager();
5237
5473
  const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
5238
- (0, import_log14.log)("update", {
5474
+ (0, import_log16.log)("update", {
5239
5475
  spaces
5240
5476
  }, {
5241
- F: __dxlog_file17,
5242
- L: 110,
5477
+ F: __dxlog_file19,
5478
+ L: 115,
5243
5479
  S: this,
5244
5480
  C: (f, a) => f(...a)
5245
5481
  });
@@ -5250,14 +5486,22 @@ var SpacesServiceImpl = class {
5250
5486
  }, {
5251
5487
  maxFrequency: process.env.NODE_ENV === "test" ? void 0 : 2
5252
5488
  });
5253
- (0, import_async16.scheduleTask)(ctx, async () => {
5489
+ (0, import_async18.scheduleTask)(ctx, async () => {
5254
5490
  const dataSpaceManager = await this._getDataSpaceManager();
5255
- const subscriptions = new import_async16.EventSubscriptions();
5491
+ const subscriptions = new import_async18.EventSubscriptions();
5256
5492
  ctx.onDispose(() => subscriptions.clear());
5257
5493
  const subscribeSpaces = () => {
5258
5494
  subscriptions.clear();
5259
5495
  for (const space of dataSpaceManager.spaces.values()) {
5260
- subscriptions.add(space.stateUpdate.on(ctx, () => scheduler.forceTrigger()));
5496
+ let lastState;
5497
+ subscriptions.add(space.stateUpdate.on(ctx, () => {
5498
+ if (space.state !== lastState) {
5499
+ scheduler.forceTrigger();
5500
+ } else {
5501
+ scheduler.trigger();
5502
+ }
5503
+ lastState = space.state;
5504
+ }));
5261
5505
  subscriptions.add(space.presence.updated.on(ctx, () => scheduler.trigger()));
5262
5506
  subscriptions.add(space.automergeSpaceState.onNewEpoch.on(ctx, () => scheduler.trigger()));
5263
5507
  subscriptions.add(space.inner.controlPipeline.state.timeframeUpdate.on(ctx, () => scheduler.trigger()));
@@ -5284,7 +5528,7 @@ var SpacesServiceImpl = class {
5284
5528
  }
5285
5529
  subscribeMessages({ spaceKey, channel }) {
5286
5530
  return new import_codec_protobuf11.Stream(({ ctx, next }) => {
5287
- (0, import_async16.scheduleTask)(ctx, async () => {
5531
+ (0, import_async18.scheduleTask)(ctx, async () => {
5288
5532
  const dataSpaceManager = await this._getDataSpaceManager();
5289
5533
  const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols12.SpaceNotFoundError(spaceKey));
5290
5534
  const handle = space.listen(getChannelId(channel), (message) => {
@@ -5303,7 +5547,7 @@ var SpacesServiceImpl = class {
5303
5547
  }
5304
5548
  };
5305
5549
  ctx.onDispose(() => space.spaceState.removeCredentialProcessor(processor));
5306
- (0, import_async16.scheduleTask)(ctx, async () => {
5550
+ (0, import_async18.scheduleTask)(ctx, async () => {
5307
5551
  await space.spaceState.addCredentialProcessor(processor);
5308
5552
  if (noTail) {
5309
5553
  close();
@@ -5321,18 +5565,18 @@ var SpacesServiceImpl = class {
5321
5565
  }
5322
5566
  });
5323
5567
  } else {
5324
- (0, import_invariant15.invariant)(!credential.id, "Id on unsigned credentials is not allowed", {
5325
- F: __dxlog_file17,
5326
- L: 198,
5568
+ (0, import_invariant16.invariant)(!credential.id, "Id on unsigned credentials is not allowed", {
5569
+ F: __dxlog_file19,
5570
+ L: 213,
5327
5571
  S: this,
5328
5572
  A: [
5329
5573
  "!credential.id",
5330
5574
  "'Id on unsigned credentials is not allowed'"
5331
5575
  ]
5332
5576
  });
5333
- (0, import_invariant15.invariant)(this._identityManager.identity, "Identity is not available", {
5334
- F: __dxlog_file17,
5335
- L: 199,
5577
+ (0, import_invariant16.invariant)(this._identityManager.identity, "Identity is not available", {
5578
+ F: __dxlog_file19,
5579
+ L: 214,
5336
5580
  S: this,
5337
5581
  A: [
5338
5582
  "this._identityManager.identity",
@@ -5340,9 +5584,9 @@ var SpacesServiceImpl = class {
5340
5584
  ]
5341
5585
  });
5342
5586
  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,
5587
+ (0, import_invariant16.invariant)(credential.issuer.equals(signer.getIssuer()), void 0, {
5588
+ F: __dxlog_file19,
5589
+ L: 216,
5346
5590
  S: this,
5347
5591
  A: [
5348
5592
  "credential.issuer.equals(signer.getIssuer())",
@@ -5364,10 +5608,66 @@ var SpacesServiceImpl = class {
5364
5608
  async createEpoch({ spaceKey, migration, automergeRootUrl }) {
5365
5609
  const dataSpaceManager = await this._getDataSpaceManager();
5366
5610
  const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols12.SpaceNotFoundError(spaceKey));
5367
- await space.createEpoch({
5611
+ const credential = await space.createEpoch({
5368
5612
  migration,
5369
5613
  newAutomergeRoot: automergeRootUrl
5370
5614
  });
5615
+ return {
5616
+ epochCredential: credential ?? void 0
5617
+ };
5618
+ }
5619
+ async admitContact(request) {
5620
+ const dataSpaceManager = await this._getDataSpaceManager();
5621
+ await dataSpaceManager.admitMember({
5622
+ spaceKey: request.spaceKey,
5623
+ identityKey: request.contact.identityKey,
5624
+ role: request.role
5625
+ });
5626
+ }
5627
+ async joinBySpaceKey({ spaceKey }) {
5628
+ const dataSpaceManager = await this._getDataSpaceManager();
5629
+ const credential = await dataSpaceManager.requestSpaceAdmissionCredential(spaceKey);
5630
+ return this._joinByAdmission({
5631
+ credential
5632
+ });
5633
+ }
5634
+ async _joinByAdmission({ credential }) {
5635
+ const assertion = (0, import_credentials19.getCredentialAssertion)(credential);
5636
+ (0, import_invariant16.invariant)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
5637
+ F: __dxlog_file19,
5638
+ L: 250,
5639
+ S: this,
5640
+ A: [
5641
+ "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
5642
+ "'Invalid credential'"
5643
+ ]
5644
+ });
5645
+ const myIdentity = this._identityManager.identity;
5646
+ (0, import_invariant16.invariant)(myIdentity && credential.subject.id.equals(myIdentity.identityKey), void 0, {
5647
+ F: __dxlog_file19,
5648
+ L: 252,
5649
+ S: this,
5650
+ A: [
5651
+ "myIdentity && credential.subject.id.equals(myIdentity.identityKey)",
5652
+ ""
5653
+ ]
5654
+ });
5655
+ const dataSpaceManager = await this._getDataSpaceManager();
5656
+ let dataSpace = dataSpaceManager.spaces.get(assertion.spaceKey);
5657
+ if (!dataSpace) {
5658
+ dataSpace = await dataSpaceManager.acceptSpace({
5659
+ spaceKey: assertion.spaceKey,
5660
+ genesisFeedKey: assertion.genesisFeedKey
5661
+ });
5662
+ await myIdentity.controlPipeline.writer.write({
5663
+ credential: {
5664
+ credential
5665
+ }
5666
+ });
5667
+ }
5668
+ return {
5669
+ space: this._serializeSpace(dataSpace)
5670
+ };
5371
5671
  }
5372
5672
  _serializeSpace(space) {
5373
5673
  return {
@@ -5400,7 +5700,7 @@ var SpacesServiceImpl = class {
5400
5700
  profile: member.profile ?? {}
5401
5701
  },
5402
5702
  role: member.role,
5403
- presence: peers.length > 0 ? import_services14.SpaceMember.PresenceState.ONLINE : import_services14.SpaceMember.PresenceState.OFFLINE,
5703
+ presence: peers.length > 0 ? import_services15.SpaceMember.PresenceState.ONLINE : import_services15.SpaceMember.PresenceState.OFFLINE,
5404
5704
  peerStates: peers
5405
5705
  };
5406
5706
  }),
@@ -5438,8 +5738,8 @@ function _ts_decorate6(decorators, target, key, desc) {
5438
5738
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5439
5739
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5440
5740
  }
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 {
5741
+ var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
5742
+ var ServiceContext = class extends import_context15.Resource {
5443
5743
  constructor(storage, level, networkManager, signalManager, _runtimeParams) {
5444
5744
  super();
5445
5745
  this.storage = storage;
@@ -5447,24 +5747,24 @@ var ServiceContext = class extends import_context13.Resource {
5447
5747
  this.networkManager = networkManager;
5448
5748
  this.signalManager = signalManager;
5449
5749
  this._runtimeParams = _runtimeParams;
5450
- this.initialized = new import_async17.Trigger();
5750
+ this.initialized = new import_async19.Trigger();
5451
5751
  this._handlerFactories = /* @__PURE__ */ new Map();
5452
5752
  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"));
5753
+ this.metadataStore = new import_echo_pipeline6.MetadataStore(storage.createDirectory("metadata"));
5754
+ this.snapshotStore = new import_echo_pipeline6.SnapshotStore(storage.createDirectory("snapshots"));
5455
5755
  this.blobStore = new import_teleport_extension_object_sync.BlobStore(storage.createDirectory("blobs"));
5456
5756
  this.keyring = new import_keyring.Keyring(storage.createDirectory("keyring"));
5457
- this.feedStore = new import_feed_store5.FeedStore({
5458
- factory: new import_feed_store5.FeedFactory({
5757
+ this.feedStore = new import_feed_store6.FeedStore({
5758
+ factory: new import_feed_store6.FeedFactory({
5459
5759
  root: storage.createDirectory("feeds"),
5460
5760
  signer: this.keyring,
5461
5761
  hypercore: {
5462
- valueEncoding: import_echo_pipeline4.valueEncoding,
5762
+ valueEncoding: import_echo_pipeline6.valueEncoding,
5463
5763
  stats: true
5464
5764
  }
5465
5765
  })
5466
5766
  });
5467
- this.spaceManager = new import_echo_pipeline4.SpaceManager({
5767
+ this.spaceManager = new import_echo_pipeline6.SpaceManager({
5468
5768
  feedStore: this.feedStore,
5469
5769
  networkManager: this.networkManager,
5470
5770
  blobStore: this.blobStore,
@@ -5472,25 +5772,25 @@ var ServiceContext = class extends import_context13.Resource {
5472
5772
  snapshotStore: this.snapshotStore
5473
5773
  });
5474
5774
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager, this._runtimeParams);
5475
- this.echoHost = new import_echo_db.EchoHost({
5775
+ this.echoHost = new import_echo_db3.EchoHost({
5476
5776
  kv: this.level
5477
5777
  });
5478
5778
  this.invitations = new InvitationsHandler(this.networkManager, _runtimeParams?.invitationConnectionDefaultParams);
5479
5779
  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)));
5780
+ this._handlerFactories.set(import_services16.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug6.failUndefined)(), this._acceptIdentity.bind(this)));
5481
5781
  }
5482
5782
  async _open(ctx) {
5483
5783
  await this._checkStorageVersion();
5484
- (0, import_log15.log)("opening...", void 0, {
5485
- F: __dxlog_file18,
5784
+ (0, import_log17.log)("opening...", void 0, {
5785
+ F: __dxlog_file20,
5486
5786
  L: 149,
5487
5787
  S: this,
5488
5788
  C: (f, a) => f(...a)
5489
5789
  });
5490
- import_log15.log.trace("dxos.sdk.service-context.open", import_protocols13.trace.begin({
5790
+ import_log17.log.trace("dxos.sdk.service-context.open", import_protocols13.trace.begin({
5491
5791
  id: this._instanceId
5492
5792
  }), {
5493
- F: __dxlog_file18,
5793
+ F: __dxlog_file20,
5494
5794
  L: 150,
5495
5795
  S: this,
5496
5796
  C: (f, a) => f(...a)
@@ -5505,32 +5805,32 @@ var ServiceContext = class extends import_context13.Resource {
5505
5805
  await this._initialize(ctx);
5506
5806
  }
5507
5807
  const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
5508
- (0, import_log15.log)("loaded persistent invitations", {
5808
+ (0, import_log17.log)("loaded persistent invitations", {
5509
5809
  count: loadedInvitations.invitations?.length
5510
5810
  }, {
5511
- F: __dxlog_file18,
5811
+ F: __dxlog_file20,
5512
5812
  L: 163,
5513
5813
  S: this,
5514
5814
  C: (f, a) => f(...a)
5515
5815
  });
5516
- import_log15.log.trace("dxos.sdk.service-context.open", import_protocols13.trace.end({
5816
+ import_log17.log.trace("dxos.sdk.service-context.open", import_protocols13.trace.end({
5517
5817
  id: this._instanceId
5518
5818
  }), {
5519
- F: __dxlog_file18,
5819
+ F: __dxlog_file20,
5520
5820
  L: 165,
5521
5821
  S: this,
5522
5822
  C: (f, a) => f(...a)
5523
5823
  });
5524
- (0, import_log15.log)("opened", void 0, {
5525
- F: __dxlog_file18,
5824
+ (0, import_log17.log)("opened", void 0, {
5825
+ F: __dxlog_file20,
5526
5826
  L: 166,
5527
5827
  S: this,
5528
5828
  C: (f, a) => f(...a)
5529
5829
  });
5530
5830
  }
5531
5831
  async _close(ctx) {
5532
- (0, import_log15.log)("closing...", void 0, {
5533
- F: __dxlog_file18,
5832
+ (0, import_log17.log)("closing...", void 0, {
5833
+ F: __dxlog_file20,
5534
5834
  L: 170,
5535
5835
  S: this,
5536
5836
  C: (f, a) => f(...a)
@@ -5546,8 +5846,8 @@ var ServiceContext = class extends import_context13.Resource {
5546
5846
  await this.echoHost.close(ctx);
5547
5847
  await this.networkManager.close();
5548
5848
  await this.signalManager.close();
5549
- (0, import_log15.log)("closed", void 0, {
5550
- F: __dxlog_file18,
5849
+ (0, import_log17.log)("closed", void 0, {
5850
+ F: __dxlog_file20,
5551
5851
  L: 182,
5552
5852
  S: this,
5553
5853
  C: (f, a) => f(...a)
@@ -5555,13 +5855,16 @@ var ServiceContext = class extends import_context13.Resource {
5555
5855
  }
5556
5856
  async createIdentity(params = {}) {
5557
5857
  const identity = await this.identityManager.createIdentity(params);
5558
- await this._initialize(new import_context13.Context());
5858
+ await this._initialize(new import_context15.Context(void 0, {
5859
+ F: __dxlog_file20,
5860
+ L: 187
5861
+ }));
5559
5862
  return identity;
5560
5863
  }
5561
5864
  getInvitationHandler(invitation) {
5562
5865
  const factory = this._handlerFactories.get(invitation.kind);
5563
- (0, import_invariant16.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
5564
- F: __dxlog_file18,
5866
+ (0, import_invariant17.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
5867
+ F: __dxlog_file20,
5565
5868
  L: 193,
5566
5869
  S: this,
5567
5870
  A: [
@@ -5581,7 +5884,10 @@ var ServiceContext = class extends import_context13.Resource {
5581
5884
  }
5582
5885
  async _acceptIdentity(params) {
5583
5886
  const identity = await this.identityManager.acceptIdentity(params);
5584
- await this._initialize(new import_context13.Context());
5887
+ await this._initialize(new import_context15.Context(void 0, {
5888
+ F: __dxlog_file20,
5889
+ L: 209
5890
+ }));
5585
5891
  return identity;
5586
5892
  }
5587
5893
  async _checkStorageVersion() {
@@ -5592,8 +5898,8 @@ var ServiceContext = class extends import_context13.Resource {
5592
5898
  }
5593
5899
  // Called when identity is created.
5594
5900
  async _initialize(ctx) {
5595
- (0, import_log15.log)("initializing spaces...", void 0, {
5596
- F: __dxlog_file18,
5901
+ (0, import_log17.log)("initializing spaces...", void 0, {
5902
+ F: __dxlog_file20,
5597
5903
  L: 224,
5598
5904
  S: this,
5599
5905
  C: (f, a) => f(...a)
@@ -5614,9 +5920,9 @@ var ServiceContext = class extends import_context13.Resource {
5614
5920
  };
5615
5921
  this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.echoHost, this.invitationsManager, this._runtimeParams);
5616
5922
  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,
5923
+ this._handlerFactories.set(import_services16.Invitation.Kind.SPACE, (invitation) => {
5924
+ (0, import_invariant17.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
5925
+ F: __dxlog_file20,
5620
5926
  L: 249,
5621
5927
  S: this,
5622
5928
  A: [
@@ -5637,10 +5943,10 @@ var ServiceContext = class extends import_context13.Resource {
5637
5943
  return;
5638
5944
  }
5639
5945
  if (!this.dataSpaceManager) {
5640
- (0, import_log15.log)("dataSpaceManager not initialized yet, ignoring space admission", {
5946
+ (0, import_log17.log)("dataSpaceManager not initialized yet, ignoring space admission", {
5641
5947
  details: assertion
5642
5948
  }, {
5643
- F: __dxlog_file18,
5949
+ F: __dxlog_file20,
5644
5950
  L: 265,
5645
5951
  S: this,
5646
5952
  C: (f, a) => f(...a)
@@ -5648,10 +5954,10 @@ var ServiceContext = class extends import_context13.Resource {
5648
5954
  return;
5649
5955
  }
5650
5956
  if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
5651
- (0, import_log15.log)("space already exists, ignoring space admission", {
5957
+ (0, import_log17.log)("space already exists, ignoring space admission", {
5652
5958
  details: assertion
5653
5959
  }, {
5654
- F: __dxlog_file18,
5960
+ F: __dxlog_file20,
5655
5961
  L: 269,
5656
5962
  S: this,
5657
5963
  C: (f, a) => f(...a)
@@ -5659,10 +5965,10 @@ var ServiceContext = class extends import_context13.Resource {
5659
5965
  return;
5660
5966
  }
5661
5967
  try {
5662
- (0, import_log15.log)("accepting space recorded in halo", {
5968
+ (0, import_log17.log)("accepting space recorded in halo", {
5663
5969
  details: assertion
5664
5970
  }, {
5665
- F: __dxlog_file18,
5971
+ F: __dxlog_file20,
5666
5972
  L: 274,
5667
5973
  S: this,
5668
5974
  C: (f, a) => f(...a)
@@ -5672,8 +5978,8 @@ var ServiceContext = class extends import_context13.Resource {
5672
5978
  genesisFeedKey: assertion.genesisFeedKey
5673
5979
  });
5674
5980
  } catch (err) {
5675
- import_log15.log.catch(err, void 0, {
5676
- F: __dxlog_file18,
5981
+ import_log17.log.catch(err, void 0, {
5982
+ F: __dxlog_file20,
5677
5983
  L: 280,
5678
5984
  S: this,
5679
5985
  C: (f, a) => f(...a)
@@ -5691,7 +5997,7 @@ _ts_decorate6([
5691
5997
  import_tracing8.trace.span()
5692
5998
  ], ServiceContext.prototype, "_initialize", null);
5693
5999
  ServiceContext = _ts_decorate6([
5694
- (0, import_util9.safeInstanceof)("dxos.client-services.ServiceContext"),
6000
+ (0, import_util11.safeInstanceof)("dxos.client-services.ServiceContext"),
5695
6001
  import_tracing8.trace.resource()
5696
6002
  ], ServiceContext);
5697
6003
  var ServiceRegistry = class {
@@ -5726,7 +6032,7 @@ function _ts_decorate7(decorators, target, key, desc) {
5726
6032
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5727
6033
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5728
6034
  }
5729
- var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/node.ts";
6035
+ var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/node.ts";
5730
6036
  var Lock = class {
5731
6037
  constructor({ lockKey: lockPath, onAcquire, onRelease }) {
5732
6038
  this._lockPath = lockPath;
@@ -5737,16 +6043,16 @@ var Lock = class {
5737
6043
  return this._lockPath;
5738
6044
  }
5739
6045
  async acquire() {
5740
- (0, import_log16.log)("acquiring lock...", void 0, {
5741
- F: __dxlog_file19,
6046
+ (0, import_log18.log)("acquiring lock...", void 0, {
6047
+ F: __dxlog_file21,
5742
6048
  L: 32,
5743
6049
  S: this,
5744
6050
  C: (f, a) => f(...a)
5745
6051
  });
5746
6052
  this._fileHandle = await import_lock_file.LockFile.acquire(this._lockPath);
5747
6053
  await this._onAcquire?.();
5748
- (0, import_log16.log)("acquired lock", void 0, {
5749
- F: __dxlog_file19,
6054
+ (0, import_log18.log)("acquired lock", void 0, {
6055
+ F: __dxlog_file21,
5750
6056
  L: 37,
5751
6057
  S: this,
5752
6058
  C: (f, a) => f(...a)
@@ -5754,8 +6060,8 @@ var Lock = class {
5754
6060
  }
5755
6061
  async release() {
5756
6062
  await this._onRelease?.();
5757
- (0, import_invariant17.invariant)(this._fileHandle, "Lock is not acquired", {
5758
- F: __dxlog_file19,
6063
+ (0, import_invariant18.invariant)(this._fileHandle, "Lock is not acquired", {
6064
+ F: __dxlog_file21,
5759
6065
  L: 42,
5760
6066
  S: this,
5761
6067
  A: [
@@ -5767,11 +6073,11 @@ var Lock = class {
5767
6073
  }
5768
6074
  };
5769
6075
  _ts_decorate7([
5770
- import_log16.logInfo
6076
+ import_log18.logInfo
5771
6077
  ], Lock.prototype, "lockKey", null);
5772
6078
  var isLocked = (lockPath) => import_lock_file.LockFile.isLocked(lockPath);
5773
6079
  var getRootPath = (config) => {
5774
- const { dataRoot = (0, import_util10.isNode)() ? import_client_protocol6.DX_DATA : "dxos/storage" } = config ?? {};
6080
+ const { dataRoot = (0, import_util12.isNode)() ? import_client_protocol6.DX_DATA : "dxos/storage" } = config ?? {};
5775
6081
  return `${dataRoot}/`;
5776
6082
  };
5777
6083
  var isPersistent = (config) => {
@@ -5827,7 +6133,138 @@ var createLevel = async (config) => {
5827
6133
  await level.open();
5828
6134
  return level;
5829
6135
  };
5830
- var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
6136
+ var __dxlog_file22 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/storage/profile-archive.ts";
6137
+ var encodeProfileArchive = (profile) => import_automerge_repo.cbor.encode(profile);
6138
+ var decodeProfileArchive = (data) => import_automerge_repo.cbor.decode(data);
6139
+ var exportProfileData = async ({ storage, level }) => {
6140
+ const archive = {
6141
+ storage: [],
6142
+ meta: {
6143
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
6144
+ }
6145
+ };
6146
+ {
6147
+ const directory = await storage.createDirectory();
6148
+ const files = await directory.list();
6149
+ import_log19.log.info("begin exporting files", {
6150
+ count: files.length
6151
+ }, {
6152
+ F: __dxlog_file22,
6153
+ L: 30,
6154
+ S: void 0,
6155
+ C: (f, a) => f(...a)
6156
+ });
6157
+ for (const filename of files) {
6158
+ const file = await directory.getOrCreateFile(filename);
6159
+ const { size } = await file.stat();
6160
+ const data = await file.read(0, size);
6161
+ archive.storage.push({
6162
+ type: import_protocols15.ProfileArchiveEntryType.FILE,
6163
+ key: filename,
6164
+ value: data
6165
+ });
6166
+ }
6167
+ import_log19.log.info("done exporting files", {
6168
+ count: files.length
6169
+ }, {
6170
+ F: __dxlog_file22,
6171
+ L: 41,
6172
+ S: void 0,
6173
+ C: (f, a) => f(...a)
6174
+ });
6175
+ }
6176
+ {
6177
+ import_log19.log.info("begin exporting kv pairs", void 0, {
6178
+ F: __dxlog_file22,
6179
+ L: 45,
6180
+ S: void 0,
6181
+ C: (f, a) => f(...a)
6182
+ });
6183
+ const iter = await level.iterator({
6184
+ keyEncoding: "binary",
6185
+ valueEncoding: "binary"
6186
+ });
6187
+ let count = 0;
6188
+ for await (const [key, value] of iter) {
6189
+ archive.storage.push({
6190
+ type: import_protocols15.ProfileArchiveEntryType.KEY_VALUE,
6191
+ key,
6192
+ value
6193
+ });
6194
+ count++;
6195
+ }
6196
+ import_log19.log.info("done exporting kv pairs", {
6197
+ count
6198
+ }, {
6199
+ F: __dxlog_file22,
6200
+ L: 56,
6201
+ S: void 0,
6202
+ C: (f, a) => f(...a)
6203
+ });
6204
+ }
6205
+ return archive;
6206
+ };
6207
+ var importProfileData = async ({ storage, level }, archive) => {
6208
+ const batch = level.batch();
6209
+ for (const entry2 of archive.storage) {
6210
+ switch (entry2.type) {
6211
+ case import_protocols15.ProfileArchiveEntryType.FILE: {
6212
+ const directory = await storage.createDirectory();
6213
+ (0, import_invariant19.invariant)(typeof entry2.key === "string", "Invalid key type", {
6214
+ F: __dxlog_file22,
6215
+ L: 78,
6216
+ S: void 0,
6217
+ A: [
6218
+ "typeof entry.key === 'string'",
6219
+ "'Invalid key type'"
6220
+ ]
6221
+ });
6222
+ const file = await directory.getOrCreateFile(entry2.key);
6223
+ (0, import_invariant19.invariant)(entry2.value instanceof Uint8Array, "Invalid value type", {
6224
+ F: __dxlog_file22,
6225
+ L: 80,
6226
+ S: void 0,
6227
+ A: [
6228
+ "entry.value instanceof Uint8Array",
6229
+ "'Invalid value type'"
6230
+ ]
6231
+ });
6232
+ await file.write(0, (0, import_util13.arrayToBuffer)(entry2.value));
6233
+ await file.close();
6234
+ break;
6235
+ }
6236
+ case import_protocols15.ProfileArchiveEntryType.KEY_VALUE: {
6237
+ (0, import_invariant19.invariant)(entry2.key instanceof Uint8Array, "Invalid key type", {
6238
+ F: __dxlog_file22,
6239
+ L: 86,
6240
+ S: void 0,
6241
+ A: [
6242
+ "entry.key instanceof Uint8Array",
6243
+ "'Invalid key type'"
6244
+ ]
6245
+ });
6246
+ (0, import_invariant19.invariant)(entry2.value instanceof Uint8Array, "Invalid value type", {
6247
+ F: __dxlog_file22,
6248
+ L: 87,
6249
+ S: void 0,
6250
+ A: [
6251
+ "entry.value instanceof Uint8Array",
6252
+ "'Invalid value type'"
6253
+ ]
6254
+ });
6255
+ batch.put(entry2.key, entry2.value, {
6256
+ keyEncoding: "binary",
6257
+ valueEncoding: "binary"
6258
+ });
6259
+ break;
6260
+ }
6261
+ default:
6262
+ throw new Error(`Invalid entry type: ${entry2.type}`);
6263
+ }
6264
+ }
6265
+ await batch.write();
6266
+ };
6267
+ var __dxlog_file23 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
5831
6268
  var DevicesServiceImpl = class {
5832
6269
  constructor(_identityManager) {
5833
6270
  this._identityManager = _identityManager;
@@ -5844,8 +6281,8 @@ var DevicesServiceImpl = class {
5844
6281
  devices: []
5845
6282
  });
5846
6283
  } else {
5847
- (0, import_invariant19.invariant)(this._identityManager.identity?.presence, "presence not present", {
5848
- F: __dxlog_file20,
6284
+ (0, import_invariant21.invariant)(this._identityManager.identity?.presence, "presence not present", {
6285
+ F: __dxlog_file23,
5849
6286
  L: 32,
5850
6287
  S: this,
5851
6288
  A: [
@@ -5860,9 +6297,9 @@ var DevicesServiceImpl = class {
5860
6297
  const peerState = peers.find((peer) => peer.identityKey.equals(key));
5861
6298
  return {
5862
6299
  deviceKey: key,
5863
- kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services17.DeviceKind.CURRENT : import_services17.DeviceKind.TRUSTED,
6300
+ kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services18.DeviceKind.CURRENT : import_services18.DeviceKind.TRUSTED,
5864
6301
  profile,
5865
- presence: isMe ? import_services17.Device.PresenceState.ONLINE : peerState ? import_services17.Device.PresenceState.ONLINE : import_services17.Device.PresenceState.OFFLINE
6302
+ presence: isMe ? import_services18.Device.PresenceState.ONLINE : peerState ? import_services18.Device.PresenceState.ONLINE : import_services18.Device.PresenceState.OFFLINE
5866
6303
  };
5867
6304
  })
5868
6305
  });
@@ -5886,7 +6323,7 @@ var DevicesServiceImpl = class {
5886
6323
  presenceSubscribed = true;
5887
6324
  }
5888
6325
  };
5889
- const subscriptions = new import_async19.EventSubscriptions();
6326
+ const subscriptions = new import_async21.EventSubscriptions();
5890
6327
  if (this._identityManager.identity) {
5891
6328
  subscribeIdentity();
5892
6329
  subscribePresence();
@@ -5911,7 +6348,7 @@ var DiagnosticsCollector = class {
5911
6348
  }
5912
6349
  static async collect(config = findConfigs(), services = findSystemServiceProvider(), options = {}) {
5913
6350
  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
6351
+ keys: options.humanize ? import_services19.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE : options.truncate ? import_services19.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE : void 0
5915
6352
  }, {
5916
6353
  timeout: GET_DIAGNOSTICS_RPC_TIMEOUT
5917
6354
  });
@@ -5926,7 +6363,7 @@ var DiagnosticsCollector = class {
5926
6363
  client: clientDiagnostics,
5927
6364
  broadcast: await this.broadcastSender.broadcastDiagnosticsRequest()
5928
6365
  };
5929
- return JSON.parse(JSON.stringify(diagnostics, (0, import_util11.jsonKeyReplacer)(options)));
6366
+ return JSON.parse(JSON.stringify(diagnostics, (0, import_util14.jsonKeyReplacer)(options)));
5930
6367
  }
5931
6368
  };
5932
6369
  var findSystemServiceProvider = () => {
@@ -5936,35 +6373,112 @@ var findSystemServiceProvider = () => {
5936
6373
  };
5937
6374
  var findConfigs = () => {
5938
6375
  const configs = import_tracing10.TRACE_PROCESSOR.findResourcesByAnnotation(import_config3.ConfigResource);
5939
- return configs.map((r) => r.instance.deref()).filter(import_util11.nonNullable);
6376
+ return configs.map((r) => r.instance.deref()).filter(import_util14.nonNullable);
6377
+ };
6378
+ var ContactsServiceImpl = class {
6379
+ constructor(_identityManager, _spaceManager, _dataSpaceManagerProvider) {
6380
+ this._identityManager = _identityManager;
6381
+ this._spaceManager = _spaceManager;
6382
+ this._dataSpaceManagerProvider = _dataSpaceManagerProvider;
6383
+ }
6384
+ async getContacts() {
6385
+ const identity = this._identityManager.identity;
6386
+ if (identity == null) {
6387
+ return {
6388
+ contacts: []
6389
+ };
6390
+ }
6391
+ const contacts = [
6392
+ ...this._spaceManager.spaces.values()
6393
+ ].flatMap((s) => [
6394
+ ...s.spaceState.members.values()
6395
+ ].map((m) => [
6396
+ s.key,
6397
+ m
6398
+ ])).reduce((acc, v) => {
6399
+ const [spaceKey, memberInfo] = v;
6400
+ if (memberInfo.key.equals(identity.identityKey)) {
6401
+ return acc;
6402
+ }
6403
+ const existing = acc.get(memberInfo.key);
6404
+ if (existing != null) {
6405
+ existing.profile ??= memberInfo.profile;
6406
+ existing.commonSpaces?.push(spaceKey);
6407
+ } else {
6408
+ acc.set(memberInfo.key, {
6409
+ identityKey: memberInfo.key,
6410
+ profile: memberInfo.profile,
6411
+ commonSpaces: [
6412
+ spaceKey
6413
+ ]
6414
+ });
6415
+ }
6416
+ return acc;
6417
+ }, new import_util16.ComplexMap(import_keys17.PublicKey.hash));
6418
+ return {
6419
+ contacts: [
6420
+ ...contacts.values()
6421
+ ]
6422
+ };
6423
+ }
6424
+ queryContacts() {
6425
+ const subscribedSpaceKeySet = new import_util16.ComplexSet(import_keys17.PublicKey.hash);
6426
+ return new import_codec_protobuf13.Stream(({ next, ctx }) => {
6427
+ const pushUpdateTask = new import_async22.UpdateScheduler(ctx, async () => {
6428
+ const contacts = await this.getContacts();
6429
+ next(contacts);
6430
+ }, {
6431
+ maxFrequency: 2
6432
+ });
6433
+ (0, import_async22.scheduleTask)(ctx, async () => {
6434
+ const subscriptions = new import_async22.EventSubscriptions();
6435
+ ctx.onDispose(() => subscriptions.clear());
6436
+ const subscribeToSpaceAndUpdate = () => {
6437
+ const oldSetSize = subscribedSpaceKeySet.size;
6438
+ for (const space of this._spaceManager.spaces.values()) {
6439
+ if (!subscribedSpaceKeySet.has(space.key)) {
6440
+ subscriptions.add(space.stateUpdate.on(ctx, () => pushUpdateTask.trigger()));
6441
+ subscribedSpaceKeySet.add(space.key);
6442
+ }
6443
+ }
6444
+ if (oldSetSize !== subscribedSpaceKeySet.size) {
6445
+ pushUpdateTask.trigger();
6446
+ }
6447
+ };
6448
+ const unsubscribe = (await this._dataSpaceManagerProvider()).updated.on(ctx, subscribeToSpaceAndUpdate);
6449
+ ctx.onDispose(unsubscribe);
6450
+ subscribeToSpaceAndUpdate();
6451
+ });
6452
+ });
6453
+ }
5940
6454
  };
5941
6455
  var LoggingServiceImpl = class {
5942
6456
  constructor() {
5943
- this._logs = new import_async20.Event();
6457
+ this._logs = new import_async23.Event();
5944
6458
  this._started = Date.now();
5945
- this._sessionId = import_keys17.PublicKey.random().toHex();
6459
+ this._sessionId = import_keys18.PublicKey.random().toHex();
5946
6460
  this._logProcessor = (_config, entry2) => {
5947
6461
  this._logs.emit(entry2);
5948
6462
  };
5949
6463
  }
5950
6464
  async open() {
5951
- import_log18.log.runtimeConfig.processors.push(this._logProcessor);
6465
+ import_log21.log.runtimeConfig.processors.push(this._logProcessor);
5952
6466
  }
5953
6467
  async close() {
5954
- const index = import_log18.log.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
5955
- import_log18.log.runtimeConfig.processors.splice(index, 1);
6468
+ const index = import_log21.log.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
6469
+ import_log21.log.runtimeConfig.processors.splice(index, 1);
5956
6470
  }
5957
6471
  async controlMetrics({ reset, record }) {
5958
6472
  if (reset) {
5959
- import_util13.tracer.clear();
6473
+ import_util17.tracer.clear();
5960
6474
  }
5961
6475
  if (record === true) {
5962
- import_util13.tracer.start();
6476
+ import_util17.tracer.start();
5963
6477
  } else if (record === false) {
5964
- import_util13.tracer.stop();
6478
+ import_util17.tracer.stop();
5965
6479
  }
5966
6480
  return {
5967
- recording: import_util13.tracer.recording
6481
+ recording: import_util17.tracer.recording
5968
6482
  };
5969
6483
  }
5970
6484
  /**
@@ -5972,13 +6486,13 @@ var LoggingServiceImpl = class {
5972
6486
  */
5973
6487
  queryMetrics({ interval = 5e3 }) {
5974
6488
  const getNumericalValues = (key) => {
5975
- const events = import_util13.tracer.get(key) ?? [];
6489
+ const events = import_util17.tracer.get(key) ?? [];
5976
6490
  return {
5977
6491
  key,
5978
- stats: (0, import_util13.numericalValues)(events, "duration")
6492
+ stats: (0, import_util17.numericalValues)(events, "duration")
5979
6493
  };
5980
6494
  };
5981
- return new import_codec_protobuf13.Stream(({ next }) => {
6495
+ return new import_codec_protobuf14.Stream(({ next }) => {
5982
6496
  const update = () => {
5983
6497
  const metrics = {
5984
6498
  timestamp: /* @__PURE__ */ new Date(),
@@ -6000,7 +6514,7 @@ var LoggingServiceImpl = class {
6000
6514
  });
6001
6515
  }
6002
6516
  queryLogs(request) {
6003
- return new import_codec_protobuf13.Stream(({ ctx, next }) => {
6517
+ return new import_codec_protobuf14.Stream(({ ctx, next }) => {
6004
6518
  const handler = (entry2) => {
6005
6519
  if (LOG_PROCESSING > 0) {
6006
6520
  return;
@@ -6013,7 +6527,7 @@ var LoggingServiceImpl = class {
6013
6527
  }
6014
6528
  const record = {
6015
6529
  ...entry2,
6016
- context: (0, import_util13.jsonify)((0, import_log18.getContextFromEntry)(entry2)),
6530
+ context: (0, import_util17.jsonify)((0, import_log21.getContextFromEntry)(entry2)),
6017
6531
  timestamp: /* @__PURE__ */ new Date(),
6018
6532
  meta: {
6019
6533
  // TODO(dmaretskyi): Fix proto.
@@ -6022,7 +6536,7 @@ var LoggingServiceImpl = class {
6022
6536
  scope: {
6023
6537
  hostSessionId: this._sessionId,
6024
6538
  uptimeSeconds: (Date.now() - this._started) / 1e3,
6025
- name: (0, import_util13.getDebugName)(entry2.meta?.S)
6539
+ name: (0, import_util17.getDebugName)(entry2.meta?.S)
6026
6540
  }
6027
6541
  }
6028
6542
  };
@@ -6039,16 +6553,16 @@ var LoggingServiceImpl = class {
6039
6553
  };
6040
6554
  var matchFilter = (filter, level, path2, options) => {
6041
6555
  switch (options) {
6042
- case import_services19.QueryLogsRequest.MatchingOptions.INCLUSIVE:
6556
+ case import_services20.QueryLogsRequest.MatchingOptions.INCLUSIVE:
6043
6557
  return level >= filter.level && (!filter.pattern || path2.includes(filter.pattern));
6044
- case import_services19.QueryLogsRequest.MatchingOptions.EXPLICIT:
6558
+ case import_services20.QueryLogsRequest.MatchingOptions.EXPLICIT:
6045
6559
  return level === filter.level && (!filter.pattern || path2.includes(filter.pattern));
6046
6560
  }
6047
6561
  };
6048
6562
  var shouldLog = (entry2, request) => {
6049
- const options = request.options ?? import_services19.QueryLogsRequest.MatchingOptions.INCLUSIVE;
6563
+ const options = request.options ?? import_services20.QueryLogsRequest.MatchingOptions.INCLUSIVE;
6050
6564
  if (request.filters === void 0) {
6051
- return options === import_services19.QueryLogsRequest.MatchingOptions.INCLUSIVE;
6565
+ return options === import_services20.QueryLogsRequest.MatchingOptions.INCLUSIVE;
6052
6566
  } else {
6053
6567
  return request.filters.some((filter) => matchFilter(filter, entry2.level, entry2.meta?.F ?? "", options));
6054
6568
  }
@@ -6060,7 +6574,7 @@ var NetworkServiceImpl = class {
6060
6574
  this.signalManager = signalManager;
6061
6575
  }
6062
6576
  queryStatus() {
6063
- return new import_codec_protobuf14.Stream(({ next }) => {
6577
+ return new import_codec_protobuf15.Stream(({ next }) => {
6064
6578
  const update = () => {
6065
6579
  next({
6066
6580
  swarm: this.networkManager.connectionState,
@@ -6103,9 +6617,9 @@ var SystemServiceImpl = class {
6103
6617
  const diagnostics = await this._getDiagnostics();
6104
6618
  return {
6105
6619
  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
6620
+ diagnostics: JSON.parse(JSON.stringify(diagnostics, (0, import_util18.jsonKeyReplacer)({
6621
+ truncate: keys === import_services21.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
6622
+ humanize: keys === import_services21.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
6109
6623
  })))
6110
6624
  };
6111
6625
  }
@@ -6117,7 +6631,7 @@ var SystemServiceImpl = class {
6117
6631
  }
6118
6632
  // TODO(burdon): Standardize interval option in stream request?
6119
6633
  queryStatus({ interval = 3e3 } = {}) {
6120
- return new import_codec_protobuf15.Stream(({ next }) => {
6634
+ return new import_codec_protobuf16.Stream(({ next }) => {
6121
6635
  const update = () => {
6122
6636
  next({
6123
6637
  status: this._getCurrentStatus()
@@ -6146,7 +6660,7 @@ function _ts_decorate8(decorators, target, key, desc) {
6146
6660
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6147
6661
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6148
6662
  }
6149
- var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
6663
+ var __dxlog_file24 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
6150
6664
  var ClientServicesHost = class {
6151
6665
  constructor({
6152
6666
  config,
@@ -6160,7 +6674,7 @@ var ClientServicesHost = class {
6160
6674
  runtimeParams
6161
6675
  } = {}) {
6162
6676
  this._tracingService = import_tracing9.TRACE_PROCESSOR.createTraceSender();
6163
- this._statusUpdate = new import_async18.Event();
6677
+ this._statusUpdate = new import_async20.Event();
6164
6678
  this._opening = false;
6165
6679
  this._open = false;
6166
6680
  this._storage = storage;
@@ -6179,7 +6693,10 @@ var ClientServicesHost = class {
6179
6693
  lockKey,
6180
6694
  onAcquire: () => {
6181
6695
  if (!this._opening) {
6182
- void this.open(new import_context14.Context());
6696
+ void this.open(new import_context16.Context(void 0, {
6697
+ F: __dxlog_file24,
6698
+ L: 121
6699
+ }));
6183
6700
  }
6184
6701
  },
6185
6702
  onRelease: () => this.close()
@@ -6188,14 +6705,14 @@ var ClientServicesHost = class {
6188
6705
  this._systemService = new SystemServiceImpl({
6189
6706
  config: () => this._config,
6190
6707
  statusUpdate: this._statusUpdate,
6191
- getCurrentStatus: () => this.isOpen ? import_services16.SystemStatus.ACTIVE : import_services16.SystemStatus.INACTIVE,
6708
+ getCurrentStatus: () => this.isOpen ? import_services17.SystemStatus.ACTIVE : import_services17.SystemStatus.INACTIVE,
6192
6709
  getDiagnostics: () => {
6193
6710
  return createDiagnostics(this._serviceRegistry.services, this._serviceContext, this._config);
6194
6711
  },
6195
6712
  onUpdateStatus: async (status) => {
6196
- if (!this.isOpen && status === import_services16.SystemStatus.ACTIVE) {
6713
+ if (!this.isOpen && status === import_services17.SystemStatus.ACTIVE) {
6197
6714
  await this._resourceLock?.acquire();
6198
- } else if (this.isOpen && status === import_services16.SystemStatus.INACTIVE) {
6715
+ } else if (this.isOpen && status === import_services17.SystemStatus.INACTIVE) {
6199
6716
  await this._resourceLock?.release();
6200
6717
  }
6201
6718
  },
@@ -6234,25 +6751,25 @@ var ClientServicesHost = class {
6234
6751
  * Can only be called once.
6235
6752
  */
6236
6753
  initialize({ config, ...options }) {
6237
- (0, import_invariant18.invariant)(!this._open, "service host is open", {
6238
- F: __dxlog_file21,
6239
- L: 186,
6754
+ (0, import_invariant20.invariant)(!this._open, "service host is open", {
6755
+ F: __dxlog_file24,
6756
+ L: 187,
6240
6757
  S: this,
6241
6758
  A: [
6242
6759
  "!this._open",
6243
6760
  "'service host is open'"
6244
6761
  ]
6245
6762
  });
6246
- (0, import_log17.log)("initializing...", void 0, {
6247
- F: __dxlog_file21,
6248
- L: 187,
6763
+ (0, import_log20.log)("initializing...", void 0, {
6764
+ F: __dxlog_file24,
6765
+ L: 188,
6249
6766
  S: this,
6250
6767
  C: (f, a) => f(...a)
6251
6768
  });
6252
6769
  if (config) {
6253
- (0, import_invariant18.invariant)(!this._config, "config already set", {
6254
- F: __dxlog_file21,
6255
- L: 190,
6770
+ (0, import_invariant20.invariant)(!this._config, "config already set", {
6771
+ F: __dxlog_file24,
6772
+ L: 191,
6256
6773
  S: this,
6257
6774
  A: [
6258
6775
  "!this._config",
@@ -6265,9 +6782,9 @@ var ClientServicesHost = class {
6265
6782
  }
6266
6783
  }
6267
6784
  if (!options.signalManager) {
6268
- import_log17.log.warn("running signaling without telemetry metadata.", void 0, {
6269
- F: __dxlog_file21,
6270
- L: 198,
6785
+ import_log20.log.warn("running signaling without telemetry metadata.", void 0, {
6786
+ F: __dxlog_file24,
6787
+ L: 199,
6271
6788
  S: this,
6272
6789
  C: (f, a) => f(...a)
6273
6790
  });
@@ -6276,9 +6793,9 @@ var ClientServicesHost = class {
6276
6793
  iceServers: this._config?.get("runtime.services.ice")
6277
6794
  }), signalManager = new import_messaging.WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
6278
6795
  this._signalManager = signalManager;
6279
- (0, import_invariant18.invariant)(!this._networkManager, "network manager already set", {
6280
- F: __dxlog_file21,
6281
- L: 209,
6796
+ (0, import_invariant20.invariant)(!this._networkManager, "network manager already set", {
6797
+ F: __dxlog_file24,
6798
+ L: 210,
6282
6799
  S: this,
6283
6800
  A: [
6284
6801
  "!this._networkManager",
@@ -6290,9 +6807,9 @@ var ClientServicesHost = class {
6290
6807
  transportFactory,
6291
6808
  signalManager
6292
6809
  });
6293
- (0, import_log17.log)("initialized", void 0, {
6294
- F: __dxlog_file21,
6295
- L: 216,
6810
+ (0, import_log20.log)("initialized", void 0, {
6811
+ F: __dxlog_file24,
6812
+ L: 217,
6296
6813
  S: this,
6297
6814
  C: (f, a) => f(...a)
6298
6815
  });
@@ -6302,44 +6819,44 @@ var ClientServicesHost = class {
6302
6819
  return;
6303
6820
  }
6304
6821
  const traceId = import_keys15.PublicKey.random().toHex();
6305
- import_log17.log.trace("dxos.client-services.host.open", import_protocols15.trace.begin({
6822
+ import_log20.log.trace("dxos.client-services.host.open", import_protocols16.trace.begin({
6306
6823
  id: traceId
6307
6824
  }), {
6308
- F: __dxlog_file21,
6309
- L: 227,
6825
+ F: __dxlog_file24,
6826
+ L: 228,
6310
6827
  S: this,
6311
6828
  C: (f, a) => f(...a)
6312
6829
  });
6313
- (0, import_invariant18.invariant)(this._config, "config not set", {
6314
- F: __dxlog_file21,
6315
- L: 229,
6830
+ (0, import_invariant20.invariant)(this._config, "config not set", {
6831
+ F: __dxlog_file24,
6832
+ L: 230,
6316
6833
  S: this,
6317
6834
  A: [
6318
6835
  "this._config",
6319
6836
  "'config not set'"
6320
6837
  ]
6321
6838
  });
6322
- (0, import_invariant18.invariant)(this._storage, "storage not set", {
6323
- F: __dxlog_file21,
6324
- L: 230,
6839
+ (0, import_invariant20.invariant)(this._storage, "storage not set", {
6840
+ F: __dxlog_file24,
6841
+ L: 231,
6325
6842
  S: this,
6326
6843
  A: [
6327
6844
  "this._storage",
6328
6845
  "'storage not set'"
6329
6846
  ]
6330
6847
  });
6331
- (0, import_invariant18.invariant)(this._signalManager, "signal manager not set", {
6332
- F: __dxlog_file21,
6333
- L: 231,
6848
+ (0, import_invariant20.invariant)(this._signalManager, "signal manager not set", {
6849
+ F: __dxlog_file24,
6850
+ L: 232,
6334
6851
  S: this,
6335
6852
  A: [
6336
6853
  "this._signalManager",
6337
6854
  "'signal manager not set'"
6338
6855
  ]
6339
6856
  });
6340
- (0, import_invariant18.invariant)(this._networkManager, "network manager not set", {
6341
- F: __dxlog_file21,
6342
- L: 232,
6857
+ (0, import_invariant20.invariant)(this._networkManager, "network manager not set", {
6858
+ F: __dxlog_file24,
6859
+ L: 233,
6343
6860
  S: this,
6344
6861
  A: [
6345
6862
  "this._networkManager",
@@ -6347,11 +6864,11 @@ var ClientServicesHost = class {
6347
6864
  ]
6348
6865
  });
6349
6866
  this._opening = true;
6350
- (0, import_log17.log)("opening...", {
6867
+ (0, import_log20.log)("opening...", {
6351
6868
  lockKey: this._resourceLock?.lockKey
6352
6869
  }, {
6353
- F: __dxlog_file21,
6354
- L: 235,
6870
+ F: __dxlog_file24,
6871
+ L: 236,
6355
6872
  S: this,
6356
6873
  C: (f, a) => f(...a)
6357
6874
  });
@@ -6362,16 +6879,18 @@ var ClientServicesHost = class {
6362
6879
  await this._level.open();
6363
6880
  await this._loggingService.open();
6364
6881
  this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._runtimeParams);
6882
+ const dataSpaceManagerProvider = async () => {
6883
+ await this._serviceContext.initialized.wait();
6884
+ return this._serviceContext.dataSpaceManager;
6885
+ };
6365
6886
  const identityService = new IdentityServiceImpl(this._serviceContext.identityManager, this._serviceContext.keyring, () => this._serviceContext.dataSpaceManager, (params) => this._createIdentity(params), (profile) => this._serviceContext.broadcastProfileUpdate(profile));
6366
6887
  this._serviceRegistry.setServices({
6367
6888
  SystemService: this._systemService,
6368
6889
  IdentityService: identityService,
6890
+ ContactsService: new ContactsServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, dataSpaceManagerProvider),
6369
6891
  InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitationsManager),
6370
6892
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
6371
- SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, async () => {
6372
- await this._serviceContext.initialized.wait();
6373
- return this._serviceContext.dataSpaceManager;
6374
- }),
6893
+ SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, dataSpaceManagerProvider),
6375
6894
  DataService: this._serviceContext.echoHost.dataService,
6376
6895
  QueryService: this._serviceContext.echoHost.queryService,
6377
6896
  NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager, this._serviceContext.signalManager),
@@ -6401,19 +6920,19 @@ var ClientServicesHost = class {
6401
6920
  this._open = true;
6402
6921
  this._statusUpdate.emit();
6403
6922
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
6404
- (0, import_log17.log)("opened", {
6923
+ (0, import_log20.log)("opened", {
6405
6924
  deviceKey
6406
6925
  }, {
6407
- F: __dxlog_file21,
6408
- L: 314,
6926
+ F: __dxlog_file24,
6927
+ L: 322,
6409
6928
  S: this,
6410
6929
  C: (f, a) => f(...a)
6411
6930
  });
6412
- import_log17.log.trace("dxos.client-services.host.open", import_protocols15.trace.end({
6931
+ import_log20.log.trace("dxos.client-services.host.open", import_protocols16.trace.end({
6413
6932
  id: traceId
6414
6933
  }), {
6415
- F: __dxlog_file21,
6416
- L: 315,
6934
+ F: __dxlog_file24,
6935
+ L: 323,
6417
6936
  S: this,
6418
6937
  C: (f, a) => f(...a)
6419
6938
  });
@@ -6423,11 +6942,11 @@ var ClientServicesHost = class {
6423
6942
  return;
6424
6943
  }
6425
6944
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
6426
- (0, import_log17.log)("closing...", {
6945
+ (0, import_log20.log)("closing...", {
6427
6946
  deviceKey
6428
6947
  }, {
6429
- F: __dxlog_file21,
6430
- L: 326,
6948
+ F: __dxlog_file24,
6949
+ L: 334,
6431
6950
  S: this,
6432
6951
  C: (f, a) => f(...a)
6433
6952
  });
@@ -6441,44 +6960,44 @@ var ClientServicesHost = class {
6441
6960
  await this._level?.close();
6442
6961
  this._open = false;
6443
6962
  this._statusUpdate.emit();
6444
- (0, import_log17.log)("closed", {
6963
+ (0, import_log20.log)("closed", {
6445
6964
  deviceKey
6446
6965
  }, {
6447
- F: __dxlog_file21,
6448
- L: 335,
6966
+ F: __dxlog_file24,
6967
+ L: 343,
6449
6968
  S: this,
6450
6969
  C: (f, a) => f(...a)
6451
6970
  });
6452
6971
  }
6453
6972
  async reset() {
6454
6973
  const traceId = import_keys15.PublicKey.random().toHex();
6455
- import_log17.log.trace("dxos.sdk.client-services-host.reset", import_protocols15.trace.begin({
6974
+ import_log20.log.trace("dxos.sdk.client-services-host.reset", import_protocols16.trace.begin({
6456
6975
  id: traceId
6457
6976
  }), {
6458
- F: __dxlog_file21,
6459
- L: 340,
6977
+ F: __dxlog_file24,
6978
+ L: 348,
6460
6979
  S: this,
6461
6980
  C: (f, a) => f(...a)
6462
6981
  });
6463
- import_log17.log.info("resetting...", void 0, {
6464
- F: __dxlog_file21,
6465
- L: 342,
6982
+ import_log20.log.info("resetting...", void 0, {
6983
+ F: __dxlog_file24,
6984
+ L: 350,
6466
6985
  S: this,
6467
6986
  C: (f, a) => f(...a)
6468
6987
  });
6469
6988
  await this._serviceContext?.close();
6470
6989
  await this._storage.reset();
6471
- import_log17.log.info("reset", void 0, {
6472
- F: __dxlog_file21,
6473
- L: 345,
6990
+ import_log20.log.info("reset", void 0, {
6991
+ F: __dxlog_file24,
6992
+ L: 353,
6474
6993
  S: this,
6475
6994
  C: (f, a) => f(...a)
6476
6995
  });
6477
- import_log17.log.trace("dxos.sdk.client-services-host.reset", import_protocols15.trace.end({
6996
+ import_log20.log.trace("dxos.sdk.client-services-host.reset", import_protocols16.trace.end({
6478
6997
  id: traceId
6479
6998
  }), {
6480
- F: __dxlog_file21,
6481
- L: 346,
6999
+ F: __dxlog_file24,
7000
+ L: 354,
6482
7001
  S: this,
6483
7002
  C: (f, a) => f(...a)
6484
7003
  });
@@ -6497,11 +7016,11 @@ _ts_decorate8([
6497
7016
  import_tracing9.trace.info()
6498
7017
  ], ClientServicesHost.prototype, "_open", void 0);
6499
7018
  _ts_decorate8([
6500
- import_async18.synchronized,
7019
+ import_async20.synchronized,
6501
7020
  import_tracing9.trace.span()
6502
7021
  ], ClientServicesHost.prototype, "open", null);
6503
7022
  _ts_decorate8([
6504
- import_async18.synchronized,
7023
+ import_async20.synchronized,
6505
7024
  import_tracing9.trace.span()
6506
7025
  ], ClientServicesHost.prototype, "close", null);
6507
7026
  ClientServicesHost = _ts_decorate8([
@@ -6537,8 +7056,11 @@ ClientServicesHost = _ts_decorate8([
6537
7056
  createDiagnostics,
6538
7057
  createLevel,
6539
7058
  createStorageObjects,
6540
- findPropertiesObject,
7059
+ decodeProfileArchive,
7060
+ encodeProfileArchive,
7061
+ exportProfileData,
6541
7062
  getNetworkPeers,
7063
+ importProfileData,
6542
7064
  isLocked,
6543
7065
  subscribeToFeedBlocks,
6544
7066
  subscribeToFeeds,
@@ -6548,4 +7070,4 @@ ClientServicesHost = _ts_decorate8([
6548
7070
  subscribeToSpaces,
6549
7071
  subscribeToSwarmInfo
6550
7072
  });
6551
- //# sourceMappingURL=chunk-ZBIDLLZ4.cjs.map
7073
+ //# sourceMappingURL=chunk-6FKYSRZO.cjs.map