@dxos/client-services 0.5.9-main.59deb28 → 0.5.9-main.5ad2d33

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 (47) hide show
  1. package/dist/lib/browser/{chunk-GCU4DHSQ.mjs → chunk-PLEBKZ2Q.mjs} +1132 -683
  2. package/dist/lib/browser/chunk-PLEBKZ2Q.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +13 -2
  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-MHRJ6WZU.cjs → chunk-E6HB26ZB.cjs} +1167 -718
  9. package/dist/lib/node/chunk-E6HB26ZB.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +53 -42
  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/data-space-manager.d.ts +10 -1
  22. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  23. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  24. package/dist/types/src/packlets/spaces/epoch-migrations.d.ts +2 -2
  25. package/dist/types/src/packlets/spaces/epoch-migrations.d.ts.map +1 -1
  26. package/dist/types/src/packlets/spaces/spaces-service.d.ts +4 -1
  27. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  28. package/dist/types/src/packlets/storage/index.d.ts +1 -0
  29. package/dist/types/src/packlets/storage/index.d.ts.map +1 -1
  30. package/dist/types/src/packlets/storage/profile-archive.d.ts +14 -0
  31. package/dist/types/src/packlets/storage/profile-archive.d.ts.map +1 -0
  32. package/dist/types/src/version.d.ts +1 -1
  33. package/package.json +36 -36
  34. package/src/packlets/identity/contacts-service.ts +85 -0
  35. package/src/packlets/identity/identity-service.ts +45 -18
  36. package/src/packlets/invitations/invitations-handler.ts +13 -5
  37. package/src/packlets/invitations/space-invitation-protocol.ts +11 -32
  38. package/src/packlets/services/service-host.ts +12 -4
  39. package/src/packlets/spaces/data-space-manager.ts +55 -2
  40. package/src/packlets/spaces/data-space.ts +8 -6
  41. package/src/packlets/spaces/epoch-migrations.ts +57 -38
  42. package/src/packlets/spaces/spaces-service.ts +52 -2
  43. package/src/packlets/storage/index.ts +1 -0
  44. package/src/packlets/storage/profile-archive.ts +111 -0
  45. package/src/version.ts +1 -1
  46. package/dist/lib/browser/chunk-GCU4DHSQ.mjs.map +0 -7
  47. package/dist/lib/node/chunk-MHRJ6WZU.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_MHRJ6WZU_exports = {};
30
- __export(chunk_MHRJ6WZU_exports, {
29
+ var chunk_E6HB26ZB_exports = {};
30
+ __export(chunk_E6HB26ZB_exports, {
31
31
  ClientRpcServer: () => ClientRpcServer,
32
32
  ClientServicesHost: () => ClientServicesHost,
33
33
  ClientServicesProviderResource: () => ClientServicesProviderResource,
@@ -56,7 +56,11 @@ __export(chunk_MHRJ6WZU_exports, {
56
56
  createDiagnostics: () => createDiagnostics,
57
57
  createLevel: () => createLevel,
58
58
  createStorageObjects: () => createStorageObjects,
59
+ decodeProfileArchive: () => decodeProfileArchive,
60
+ encodeProfileArchive: () => encodeProfileArchive,
61
+ exportProfileData: () => exportProfileData,
59
62
  getNetworkPeers: () => getNetworkPeers,
63
+ importProfileData: () => importProfileData,
60
64
  isLocked: () => isLocked,
61
65
  subscribeToFeedBlocks: () => subscribeToFeedBlocks,
62
66
  subscribeToFeeds: () => subscribeToFeeds,
@@ -66,7 +70,7 @@ __export(chunk_MHRJ6WZU_exports, {
66
70
  subscribeToSpaces: () => subscribeToSpaces,
67
71
  subscribeToSwarmInfo: () => subscribeToSwarmInfo
68
72
  });
69
- module.exports = __toCommonJS(chunk_MHRJ6WZU_exports);
73
+ module.exports = __toCommonJS(chunk_E6HB26ZB_exports);
70
74
  var import_async = require("@dxos/async");
71
75
  var import_codec_protobuf = require("@dxos/codec-protobuf");
72
76
  var import_feed_store = require("@dxos/feed-store");
@@ -126,72 +130,75 @@ var import_teleport_extension_gossip = require("@dxos/teleport-extension-gossip"
126
130
  var import_timeframe2 = require("@dxos/timeframe");
127
131
  var import_tracing4 = require("@dxos/tracing");
128
132
  var import_util3 = require("@dxos/util");
133
+ var import_async8 = require("@dxos/async");
129
134
  var import_codec_protobuf9 = require("@dxos/codec-protobuf");
130
135
  var import_context4 = require("@dxos/context");
131
136
  var import_credentials8 = require("@dxos/credentials");
132
137
  var import_debug2 = require("@dxos/debug");
133
138
  var import_invariant4 = require("@dxos/invariant");
139
+ var import_log5 = require("@dxos/log");
134
140
  var import_services4 = require("@dxos/protocols/proto/dxos/client/services");
141
+ var import_util4 = require("@dxos/util");
135
142
  var import_invariant5 = require("@dxos/invariant");
136
143
  var import_protocols4 = require("@dxos/protocols");
137
144
  var import_services5 = require("@dxos/protocols/proto/dxos/client/services");
138
- var import_async8 = require("@dxos/async");
145
+ var import_async9 = require("@dxos/async");
139
146
  var import_client_protocol2 = require("@dxos/client-protocol");
140
147
  var import_context5 = require("@dxos/context");
141
148
  var import_crypto = require("@dxos/crypto");
142
149
  var import_invariant6 = require("@dxos/invariant");
143
150
  var import_keys6 = require("@dxos/keys");
144
- var import_log5 = require("@dxos/log");
151
+ var import_log6 = require("@dxos/log");
145
152
  var import_network_manager = require("@dxos/network-manager");
146
153
  var import_protocols5 = require("@dxos/protocols");
147
154
  var import_services6 = require("@dxos/protocols/proto/dxos/client/services");
148
155
  var import_invitations = require("@dxos/protocols/proto/dxos/halo/invitations");
149
156
  var import_invitations2 = require("@dxos/protocols/proto/dxos/halo/invitations");
150
- var import_util4 = require("@dxos/util");
151
- var import_async9 = require("@dxos/async");
157
+ var import_util5 = require("@dxos/util");
158
+ var import_async10 = require("@dxos/async");
152
159
  var import_context6 = require("@dxos/context");
153
160
  var import_invariant7 = require("@dxos/invariant");
154
- var import_log6 = require("@dxos/log");
161
+ var import_log7 = require("@dxos/log");
155
162
  var import_protocols6 = require("@dxos/protocols");
156
163
  var import_invitations3 = require("@dxos/protocols/proto/dxos/halo/invitations");
157
164
  var import_teleport = require("@dxos/teleport");
158
165
  var import_context7 = require("@dxos/context");
159
166
  var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
160
- var import_async10 = require("@dxos/async");
167
+ var import_async11 = require("@dxos/async");
161
168
  var import_context8 = require("@dxos/context");
162
169
  var import_crypto2 = require("@dxos/crypto");
163
170
  var import_invariant8 = require("@dxos/invariant");
164
171
  var import_keys7 = require("@dxos/keys");
165
- var import_log7 = require("@dxos/log");
172
+ var import_log8 = require("@dxos/log");
166
173
  var import_protocols7 = require("@dxos/protocols");
167
174
  var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
168
175
  var import_invitations4 = require("@dxos/protocols/proto/dxos/halo/invitations");
169
176
  var import_teleport2 = require("@dxos/teleport");
170
177
  var import_invariant9 = require("@dxos/invariant");
171
178
  var import_keys8 = require("@dxos/keys");
172
- var import_log8 = require("@dxos/log");
179
+ var import_log9 = require("@dxos/log");
173
180
  var import_invitations5 = require("@dxos/protocols/proto/dxos/halo/invitations");
174
- var import_util5 = require("@dxos/util");
181
+ var import_util6 = require("@dxos/util");
175
182
  var import_codec_protobuf10 = require("@dxos/codec-protobuf");
176
183
  var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
177
184
  var import_credentials9 = require("@dxos/credentials");
178
185
  var import_feed_store3 = require("@dxos/feed-store");
179
186
  var import_invariant10 = require("@dxos/invariant");
180
- var import_log9 = require("@dxos/log");
187
+ var import_log10 = require("@dxos/log");
181
188
  var import_protocols8 = require("@dxos/protocols");
182
189
  var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
183
190
  var import_credentials10 = require("@dxos/protocols/proto/dxos/halo/credentials");
184
- var import_async11 = require("@dxos/async");
191
+ var import_async12 = require("@dxos/async");
185
192
  var import_client_protocol3 = require("@dxos/client-protocol");
186
193
  var import_context9 = require("@dxos/context");
187
194
  var import_credentials11 = require("@dxos/credentials");
188
195
  var import_echo_pipeline = require("@dxos/echo-pipeline");
189
196
  var import_invariant11 = require("@dxos/invariant");
190
197
  var import_keys9 = require("@dxos/keys");
191
- var import_log10 = require("@dxos/log");
198
+ var import_log11 = require("@dxos/log");
192
199
  var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
193
200
  var import_credentials12 = require("@dxos/protocols/proto/dxos/halo/credentials");
194
- var import_async12 = require("@dxos/async");
201
+ var import_async13 = require("@dxos/async");
195
202
  var import_client_protocol4 = require("@dxos/client-protocol");
196
203
  var import_context10 = require("@dxos/context");
197
204
  var import_debug3 = require("@dxos/debug");
@@ -199,45 +206,43 @@ var import_echo_pipeline2 = require("@dxos/echo-pipeline");
199
206
  var import_echo_protocol = require("@dxos/echo-protocol");
200
207
  var import_invariant12 = require("@dxos/invariant");
201
208
  var import_keys10 = require("@dxos/keys");
202
- var import_log11 = require("@dxos/log");
209
+ var import_log12 = require("@dxos/log");
203
210
  var import_protocols9 = require("@dxos/protocols");
204
211
  var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
205
212
  var import_credentials13 = require("@dxos/protocols/proto/dxos/halo/credentials");
206
213
  var import_timeframe3 = require("@dxos/timeframe");
207
214
  var import_tracing5 = require("@dxos/tracing");
208
- var import_util6 = require("@dxos/util");
209
- var import_async13 = require("@dxos/async");
215
+ var import_util7 = require("@dxos/util");
216
+ var import_async14 = require("@dxos/async");
210
217
  var import_context11 = require("@dxos/context");
211
218
  var import_credentials14 = require("@dxos/credentials");
212
- var import_async14 = require("@dxos/async");
213
- var import_automerge = require("@dxos/automerge/automerge");
214
- var import_context12 = require("@dxos/context");
215
219
  var import_echo_db = require("@dxos/echo-db");
216
- var import_echo_pipeline3 = require("@dxos/echo-pipeline");
220
+ var import_echo_protocol2 = require("@dxos/echo-protocol");
217
221
  var import_echo_schema = require("@dxos/echo-schema");
218
222
  var import_invariant13 = require("@dxos/invariant");
219
- var import_log12 = require("@dxos/log");
223
+ var import_log13 = require("@dxos/log");
220
224
  var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
221
- var import_util7 = require("@dxos/util");
222
225
  var import_async15 = require("@dxos/async");
223
- var import_context13 = require("@dxos/context");
226
+ var import_context12 = require("@dxos/context");
224
227
  var import_invariant14 = require("@dxos/invariant");
225
228
  var import_keys11 = require("@dxos/keys");
226
- var import_log13 = require("@dxos/log");
229
+ var import_log14 = require("@dxos/log");
227
230
  var import_protocols10 = require("@dxos/protocols");
228
231
  var import_teleport3 = require("@dxos/teleport");
229
232
  var import_util8 = require("@dxos/util");
230
233
  var import_async16 = require("@dxos/async");
231
234
  var import_client_protocol5 = require("@dxos/client-protocol");
232
- var import_context14 = require("@dxos/context");
235
+ var import_context13 = require("@dxos/context");
233
236
  var import_credentials15 = require("@dxos/credentials");
234
237
  var import_echo_db2 = require("@dxos/echo-db");
238
+ var import_echo_pipeline3 = require("@dxos/echo-pipeline");
235
239
  var import_echo_pipeline4 = require("@dxos/echo-pipeline");
236
- var import_echo_protocol2 = require("@dxos/echo-protocol");
240
+ var import_echo_protocol3 = require("@dxos/echo-protocol");
237
241
  var import_echo_schema2 = require("@dxos/echo-schema");
242
+ var import_feed_store4 = require("@dxos/feed-store");
238
243
  var import_invariant15 = require("@dxos/invariant");
239
244
  var import_keys12 = require("@dxos/keys");
240
- var import_log14 = require("@dxos/log");
245
+ var import_log15 = require("@dxos/log");
241
246
  var import_protocols11 = require("@dxos/protocols");
242
247
  var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
243
248
  var import_credentials16 = require("@dxos/protocols/proto/dxos/halo/credentials");
@@ -252,23 +257,23 @@ var import_async17 = require("@dxos/async");
252
257
  var import_codec_protobuf11 = require("@dxos/codec-protobuf");
253
258
  var import_credentials19 = require("@dxos/credentials");
254
259
  var import_debug5 = require("@dxos/debug");
255
- var import_feed_store4 = require("@dxos/feed-store");
260
+ var import_feed_store5 = require("@dxos/feed-store");
256
261
  var import_invariant16 = require("@dxos/invariant");
257
- var import_log15 = require("@dxos/log");
262
+ var import_log16 = require("@dxos/log");
258
263
  var import_protocols12 = require("@dxos/protocols");
259
264
  var import_services15 = require("@dxos/protocols/proto/dxos/client/services");
260
265
  var import_tracing7 = require("@dxos/tracing");
261
266
  var import_async18 = require("@dxos/async");
262
- var import_context15 = require("@dxos/context");
267
+ var import_context14 = require("@dxos/context");
263
268
  var import_credentials20 = require("@dxos/credentials");
264
269
  var import_debug6 = require("@dxos/debug");
265
270
  var import_echo_db3 = require("@dxos/echo-db");
266
271
  var import_echo_pipeline5 = require("@dxos/echo-pipeline");
267
- var import_feed_store5 = require("@dxos/feed-store");
272
+ var import_feed_store6 = require("@dxos/feed-store");
268
273
  var import_invariant17 = require("@dxos/invariant");
269
274
  var import_keyring = require("@dxos/keyring");
270
275
  var import_keys13 = require("@dxos/keys");
271
- var import_log16 = require("@dxos/log");
276
+ var import_log17 = require("@dxos/log");
272
277
  var import_protocols13 = require("@dxos/protocols");
273
278
  var import_services16 = require("@dxos/protocols/proto/dxos/client/services");
274
279
  var import_teleport_extension_object_sync = require("@dxos/teleport-extension-object-sync");
@@ -276,7 +281,7 @@ var import_tracing8 = require("@dxos/tracing");
276
281
  var import_util10 = require("@dxos/util");
277
282
  var import_invariant18 = require("@dxos/invariant");
278
283
  var import_lock_file = require("@dxos/lock-file");
279
- var import_log17 = require("@dxos/log");
284
+ var import_log18 = require("@dxos/log");
280
285
  var import_protocols14 = require("@dxos/protocols");
281
286
  var import_config = require("@dxos/protocols/proto/dxos/config");
282
287
  var import_random_access_storage = require("@dxos/random-access-storage");
@@ -286,38 +291,47 @@ var import_util11 = require("@dxos/util");
286
291
  var import_node_path = __toESM(require("node:path"));
287
292
  var import_keys14 = require("@dxos/keys");
288
293
  var import_kv_store = require("@dxos/kv-store");
294
+ var import_automerge_repo = require("@dxos/automerge/automerge-repo");
295
+ var import_invariant19 = require("@dxos/invariant");
296
+ var import_log19 = require("@dxos/log");
297
+ var import_protocols15 = require("@dxos/protocols");
298
+ var import_util12 = require("@dxos/util");
289
299
  var import_async19 = require("@dxos/async");
290
300
  var import_client_protocol7 = require("@dxos/client-protocol");
291
- var import_context16 = require("@dxos/context");
292
- var import_invariant19 = require("@dxos/invariant");
301
+ var import_context15 = require("@dxos/context");
302
+ var import_invariant20 = require("@dxos/invariant");
293
303
  var import_keys15 = require("@dxos/keys");
294
- var import_log18 = require("@dxos/log");
304
+ var import_log20 = require("@dxos/log");
295
305
  var import_messaging = require("@dxos/messaging");
296
306
  var import_network_manager2 = require("@dxos/network-manager");
297
- var import_protocols15 = require("@dxos/protocols");
307
+ var import_protocols16 = require("@dxos/protocols");
298
308
  var import_services17 = require("@dxos/protocols/proto/dxos/client/services");
299
309
  var import_tracing9 = require("@dxos/tracing");
300
310
  var import_websocket_rpc = require("@dxos/websocket-rpc");
301
311
  var import_async20 = require("@dxos/async");
302
312
  var import_codec_protobuf12 = require("@dxos/codec-protobuf");
303
- var import_invariant20 = require("@dxos/invariant");
313
+ var import_invariant21 = require("@dxos/invariant");
304
314
  var import_services18 = require("@dxos/protocols/proto/dxos/client/services");
305
315
  var import_config3 = require("@dxos/config");
306
316
  var import_services19 = require("@dxos/protocols/proto/dxos/client/services");
307
317
  var import_tracing10 = require("@dxos/tracing");
308
- var import_util12 = require("@dxos/util");
309
- var import_keys16 = require("@dxos/keys");
310
318
  var import_util13 = require("@dxos/util");
319
+ var import_keys16 = require("@dxos/keys");
320
+ var import_util14 = require("@dxos/util");
311
321
  var import_async21 = require("@dxos/async");
312
322
  var import_codec_protobuf13 = require("@dxos/codec-protobuf");
313
323
  var import_keys17 = require("@dxos/keys");
314
- var import_log19 = require("@dxos/log");
315
- var import_services20 = require("@dxos/protocols/proto/dxos/client/services");
316
- var import_util14 = require("@dxos/util");
324
+ var import_util15 = require("@dxos/util");
325
+ var import_async22 = require("@dxos/async");
317
326
  var import_codec_protobuf14 = require("@dxos/codec-protobuf");
327
+ var import_keys18 = require("@dxos/keys");
328
+ var import_log21 = require("@dxos/log");
329
+ var import_services20 = require("@dxos/protocols/proto/dxos/client/services");
330
+ var import_util16 = require("@dxos/util");
318
331
  var import_codec_protobuf15 = require("@dxos/codec-protobuf");
332
+ var import_codec_protobuf16 = require("@dxos/codec-protobuf");
319
333
  var import_services21 = require("@dxos/protocols/proto/dxos/client/services");
320
- var import_util15 = require("@dxos/util");
334
+ var import_util17 = require("@dxos/util");
321
335
  var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
322
336
  return new import_codec_protobuf.Stream(({ next }) => {
323
337
  const subscriptions = new import_async.EventSubscriptions();
@@ -385,6 +399,7 @@ var subscribeToFeedBlocks = ({ feedStore }, { feedKey, maxBlocks = 10 }) => {
385
399
  };
386
400
  });
387
401
  };
402
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devtools/network.ts";
388
403
  var subscribeToNetworkStatus = ({ signalManager }) => new import_codec_protobuf2.Stream(({ next, close }) => {
389
404
  const update = () => {
390
405
  try {
@@ -400,7 +415,10 @@ var subscribeToNetworkStatus = ({ signalManager }) => new import_codec_protobuf2
400
415
  update();
401
416
  });
402
417
  var subscribeToSignal = ({ signalManager }) => new import_codec_protobuf2.Stream(({ next }) => {
403
- const ctx = new import_context.Context();
418
+ const ctx = new import_context.Context(void 0, {
419
+ F: __dxlog_file,
420
+ L: 36
421
+ });
404
422
  signalManager.onMessage.on(ctx, (message) => {
405
423
  next({
406
424
  message: {
@@ -628,7 +646,7 @@ var DevtoolsServiceImpl = class {
628
646
  });
629
647
  }
630
648
  };
631
- var DXOS_VERSION = "0.5.9-main.59deb28";
649
+ var DXOS_VERSION = "0.5.9-main.5ad2d33";
632
650
  var getPlatform = () => {
633
651
  if (process.browser) {
634
652
  if (typeof window !== "undefined") {
@@ -656,7 +674,7 @@ var getPlatform = () => {
656
674
  };
657
675
  }
658
676
  };
659
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts";
677
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts";
660
678
  var DEFAULT_TIMEOUT = 1e3;
661
679
  var createDiagnostics = async (clientServices, serviceContext, config) => {
662
680
  const diagnostics = {
@@ -673,7 +691,7 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
673
691
  await Promise.all([
674
692
  (async () => {
675
693
  (0, import_invariant.invariant)(clientServices.LoggingService, "SystemService is not available.", {
676
- F: __dxlog_file,
694
+ F: __dxlog_file2,
677
695
  L: 110,
678
696
  S: void 0,
679
697
  A: [
@@ -862,7 +880,7 @@ _ts_decorate([
862
880
  ClientRpcServer = _ts_decorate([
863
881
  import_tracing2.trace.resource()
864
882
  ], ClientRpcServer);
865
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/authenticator.ts";
883
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/authenticator.ts";
866
884
  var Credential = import_protocols2.schema.getCodecForType("dxos.halo.credentials.Credential");
867
885
  var createAuthProvider = (signer) => async (nonce) => {
868
886
  const credential = await signer.createCredential({
@@ -877,7 +895,10 @@ var createAuthProvider = (signer) => async (nonce) => {
877
895
  var TrustedKeySetAuthVerifier = class {
878
896
  constructor(_params) {
879
897
  this._params = _params;
880
- this._ctx = new import_context2.Context();
898
+ this._ctx = new import_context2.Context(void 0, {
899
+ F: __dxlog_file3,
900
+ L: 45
901
+ });
881
902
  }
882
903
  async close() {
883
904
  await this._ctx.dispose();
@@ -888,7 +909,7 @@ var TrustedKeySetAuthVerifier = class {
888
909
  (0, import_log.log)("authenticating...", {
889
910
  credential
890
911
  }, {
891
- F: __dxlog_file2,
912
+ F: __dxlog_file3,
892
913
  L: 56,
893
914
  S: this,
894
915
  C: (f, a) => f(...a)
@@ -898,7 +919,7 @@ var TrustedKeySetAuthVerifier = class {
898
919
  (0, import_log.log)("Invalid credential", {
899
920
  result
900
921
  }, {
901
- F: __dxlog_file2,
922
+ F: __dxlog_file3,
902
923
  L: 60,
903
924
  S: this,
904
925
  C: (f, a) => f(...a)
@@ -910,7 +931,7 @@ var TrustedKeySetAuthVerifier = class {
910
931
  nonce,
911
932
  credential
912
933
  }, {
913
- F: __dxlog_file2,
934
+ F: __dxlog_file3,
914
935
  L: 65,
915
936
  S: this,
916
937
  C: (f, a) => f(...a)
@@ -921,7 +942,7 @@ var TrustedKeySetAuthVerifier = class {
921
942
  (0, import_log.log)("key is not currently in trusted set, waiting...", {
922
943
  key: credential.issuer
923
944
  }, {
924
- F: __dxlog_file2,
945
+ F: __dxlog_file3,
925
946
  L: 70,
926
947
  S: this,
927
948
  C: (f, a) => f(...a)
@@ -937,7 +958,7 @@ var TrustedKeySetAuthVerifier = class {
937
958
  (0, import_log.log)("auth success", {
938
959
  key: credential.issuer
939
960
  }, {
940
- F: __dxlog_file2,
961
+ F: __dxlog_file3,
941
962
  L: 81,
942
963
  S: this,
943
964
  C: (f, a) => f(...a)
@@ -947,7 +968,7 @@ var TrustedKeySetAuthVerifier = class {
947
968
  (0, import_log.log)("key is not currently in trusted set, waiting...", {
948
969
  key: credential.issuer
949
970
  }, {
950
- F: __dxlog_file2,
971
+ F: __dxlog_file3,
951
972
  L: 84,
952
973
  S: this,
953
974
  C: (f, a) => f(...a)
@@ -970,7 +991,7 @@ var TrustedKeySetAuthVerifier = class {
970
991
  return deviceSet.has(deviceKey);
971
992
  }
972
993
  };
973
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/default-space-state-machine.ts";
994
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/default-space-state-machine.ts";
974
995
  var DefaultSpaceStateMachine = class {
975
996
  constructor(_params) {
976
997
  this._params = _params;
@@ -987,7 +1008,7 @@ var DefaultSpaceStateMachine = class {
987
1008
  expectedIdentity: this._params.identityKey,
988
1009
  credential
989
1010
  }, {
990
- F: __dxlog_file3,
1011
+ F: __dxlog_file4,
991
1012
  L: 32,
992
1013
  S: this,
993
1014
  C: (f, a) => f(...a)
@@ -998,7 +1019,7 @@ var DefaultSpaceStateMachine = class {
998
1019
  import_log3.log.warn("Invalid default space id", {
999
1020
  id: assertion.spaceId
1000
1021
  }, {
1001
- F: __dxlog_file3,
1022
+ F: __dxlog_file4,
1002
1023
  L: 36,
1003
1024
  S: this,
1004
1025
  C: (f, a) => f(...a)
@@ -1021,7 +1042,7 @@ function _ts_decorate2(decorators, target, key, desc) {
1021
1042
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1022
1043
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1023
1044
  }
1024
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity.ts";
1045
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity.ts";
1025
1046
  var Identity = class {
1026
1047
  constructor({ space, signer, identityKey, deviceKey, presence }) {
1027
1048
  this.stateUpdate = new import_async6.Event();
@@ -1033,7 +1054,7 @@ var Identity = class {
1033
1054
  import_log2.log.trace("dxos.halo.device", {
1034
1055
  deviceKey
1035
1056
  }, {
1036
- F: __dxlog_file4,
1057
+ F: __dxlog_file5,
1037
1058
  L: 70,
1038
1059
  S: this,
1039
1060
  C: (f, a) => f(...a)
@@ -1112,7 +1133,7 @@ var Identity = class {
1112
1133
  */
1113
1134
  getIdentityCredentialSigner() {
1114
1135
  (0, import_invariant2.invariant)(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.", {
1115
- F: __dxlog_file4,
1136
+ F: __dxlog_file5,
1116
1137
  L: 159,
1117
1138
  S: this,
1118
1139
  A: [
@@ -1156,7 +1177,7 @@ var Identity = class {
1156
1177
  controlFeedKey,
1157
1178
  dataFeedKey
1158
1179
  }, {
1159
- F: __dxlog_file4,
1180
+ F: __dxlog_file5,
1160
1181
  L: 184,
1161
1182
  S: this,
1162
1183
  C: (f, a) => f(...a)
@@ -1217,7 +1238,7 @@ function _ts_decorate3(decorators, target, key, desc) {
1217
1238
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1218
1239
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1219
1240
  }
1220
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-manager.ts";
1241
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-manager.ts";
1221
1242
  var DEVICE_PRESENCE_ANNOUNCE_INTERVAL = 1e4;
1222
1243
  var DEVICE_PRESENCE_OFFLINE_TIMEOUT = 2e4;
1223
1244
  var IdentityManager = class {
@@ -1241,7 +1262,7 @@ var IdentityManager = class {
1241
1262
  import_log4.log.trace("dxos.halo.identity-manager.open", import_protocols3.trace.begin({
1242
1263
  id: traceId
1243
1264
  }), {
1244
- F: __dxlog_file5,
1265
+ F: __dxlog_file6,
1245
1266
  L: 104,
1246
1267
  S: this,
1247
1268
  C: (f, a) => f(...a)
@@ -1250,7 +1271,7 @@ var IdentityManager = class {
1250
1271
  (0, import_log4.log)("identity record", {
1251
1272
  identityRecord
1252
1273
  }, {
1253
- F: __dxlog_file5,
1274
+ F: __dxlog_file6,
1254
1275
  L: 107,
1255
1276
  S: this,
1256
1277
  C: (f, a) => f(...a)
@@ -1263,7 +1284,7 @@ var IdentityManager = class {
1263
1284
  identityKey: identityRecord.identityKey,
1264
1285
  displayName: this._identity.profileDocument?.displayName
1265
1286
  }, {
1266
- F: __dxlog_file5,
1287
+ F: __dxlog_file6,
1267
1288
  L: 112,
1268
1289
  S: this,
1269
1290
  C: (f, a) => f(...a)
@@ -1273,18 +1294,21 @@ var IdentityManager = class {
1273
1294
  import_log4.log.trace("dxos.halo.identity-manager.open", import_protocols3.trace.end({
1274
1295
  id: traceId
1275
1296
  }), {
1276
- F: __dxlog_file5,
1297
+ F: __dxlog_file6,
1277
1298
  L: 119,
1278
1299
  S: this,
1279
1300
  C: (f, a) => f(...a)
1280
1301
  });
1281
1302
  }
1282
1303
  async close() {
1283
- await this._identity?.close(new import_context3.Context());
1304
+ await this._identity?.close(new import_context3.Context(void 0, {
1305
+ F: __dxlog_file6,
1306
+ L: 123
1307
+ }));
1284
1308
  }
1285
1309
  async createIdentity({ displayName, deviceProfile } = {}) {
1286
1310
  (0, import_invariant3.invariant)(!this._identity, "Identity already exists.", {
1287
- F: __dxlog_file5,
1311
+ F: __dxlog_file6,
1288
1312
  L: 128,
1289
1313
  S: this,
1290
1314
  A: [
@@ -1293,7 +1317,7 @@ var IdentityManager = class {
1293
1317
  ]
1294
1318
  });
1295
1319
  (0, import_log4.log)("creating identity...", void 0, {
1296
- F: __dxlog_file5,
1320
+ F: __dxlog_file6,
1297
1321
  L: 129,
1298
1322
  S: this,
1299
1323
  C: (f, a) => f(...a)
@@ -1310,11 +1334,14 @@ var IdentityManager = class {
1310
1334
  }
1311
1335
  };
1312
1336
  const identity = await this._constructIdentity(identityRecord);
1313
- await identity.open(new import_context3.Context());
1337
+ await identity.open(new import_context3.Context(void 0, {
1338
+ F: __dxlog_file6,
1339
+ L: 144
1340
+ }));
1314
1341
  {
1315
1342
  const generator = new import_credentials6.CredentialGenerator(this._keyring, identityRecord.identityKey, identityRecord.deviceKey);
1316
1343
  (0, import_invariant3.invariant)(identityRecord.haloSpace.genesisFeedKey, "Genesis feed key is required.", {
1317
- F: __dxlog_file5,
1344
+ F: __dxlog_file6,
1318
1345
  L: 148,
1319
1346
  S: this,
1320
1347
  A: [
@@ -1323,7 +1350,7 @@ var IdentityManager = class {
1323
1350
  ]
1324
1351
  });
1325
1352
  (0, import_invariant3.invariant)(identityRecord.haloSpace.dataFeedKey, "Data feed key is required.", {
1326
- F: __dxlog_file5,
1353
+ F: __dxlog_file6,
1327
1354
  L: 149,
1328
1355
  S: this,
1329
1356
  A: [
@@ -1362,7 +1389,7 @@ var IdentityManager = class {
1362
1389
  identityKey: identityRecord.identityKey,
1363
1390
  displayName: this._identity.profileDocument?.displayName
1364
1391
  }, {
1365
- F: __dxlog_file5,
1392
+ F: __dxlog_file6,
1366
1393
  L: 191,
1367
1394
  S: this,
1368
1395
  C: (f, a) => f(...a)
@@ -1373,7 +1400,7 @@ var IdentityManager = class {
1373
1400
  deviceKey: identity.deviceKey,
1374
1401
  profile: identity.profileDocument
1375
1402
  }, {
1376
- F: __dxlog_file5,
1403
+ F: __dxlog_file6,
1377
1404
  L: 197,
1378
1405
  S: this,
1379
1406
  C: (f, a) => f(...a)
@@ -1410,13 +1437,13 @@ var IdentityManager = class {
1410
1437
  (0, import_log4.log)("accepting identity", {
1411
1438
  params
1412
1439
  }, {
1413
- F: __dxlog_file5,
1440
+ F: __dxlog_file6,
1414
1441
  L: 235,
1415
1442
  S: this,
1416
1443
  C: (f, a) => f(...a)
1417
1444
  });
1418
1445
  (0, import_invariant3.invariant)(!this._identity, "Identity already exists.", {
1419
- F: __dxlog_file5,
1446
+ F: __dxlog_file6,
1420
1447
  L: 236,
1421
1448
  S: this,
1422
1449
  A: [
@@ -1436,7 +1463,10 @@ var IdentityManager = class {
1436
1463
  }
1437
1464
  };
1438
1465
  const identity = await this._constructIdentity(identityRecord);
1439
- await identity.open(new import_context3.Context());
1466
+ await identity.open(new import_context3.Context(void 0, {
1467
+ F: __dxlog_file6,
1468
+ L: 251
1469
+ }));
1440
1470
  this._identity = identity;
1441
1471
  await this._metadataStore.setIdentityRecord(identityRecord);
1442
1472
  await this._identity.ready();
@@ -1444,7 +1474,7 @@ var IdentityManager = class {
1444
1474
  identityKey: identityRecord.identityKey,
1445
1475
  displayName: this._identity.profileDocument?.displayName
1446
1476
  }, {
1447
- F: __dxlog_file5,
1477
+ F: __dxlog_file6,
1448
1478
  L: 255,
1449
1479
  S: this,
1450
1480
  C: (f, a) => f(...a)
@@ -1458,7 +1488,7 @@ var IdentityManager = class {
1458
1488
  identityKey: identity.identityKey,
1459
1489
  deviceKey: identity.deviceKey
1460
1490
  }, {
1461
- F: __dxlog_file5,
1491
+ F: __dxlog_file6,
1462
1492
  L: 265,
1463
1493
  S: this,
1464
1494
  C: (f, a) => f(...a)
@@ -1470,7 +1500,7 @@ var IdentityManager = class {
1470
1500
  */
1471
1501
  async updateProfile(profile) {
1472
1502
  (0, import_invariant3.invariant)(this._identity, "Identity not initialized.", {
1473
- F: __dxlog_file5,
1503
+ F: __dxlog_file6,
1474
1504
  L: 273,
1475
1505
  S: this,
1476
1506
  A: [
@@ -1501,7 +1531,7 @@ var IdentityManager = class {
1501
1531
  }
1502
1532
  async updateDeviceProfile(profile) {
1503
1533
  (0, import_invariant3.invariant)(this._identity, "Identity not initialized.", {
1504
- F: __dxlog_file5,
1534
+ F: __dxlog_file6,
1505
1535
  L: 290,
1506
1536
  S: this,
1507
1537
  A: [
@@ -1537,7 +1567,7 @@ var IdentityManager = class {
1537
1567
  }
1538
1568
  async _constructIdentity(identityRecord) {
1539
1569
  (0, import_invariant3.invariant)(!this._identity, void 0, {
1540
- F: __dxlog_file5,
1570
+ F: __dxlog_file6,
1541
1571
  L: 316,
1542
1572
  S: this,
1543
1573
  A: [
@@ -1548,7 +1578,7 @@ var IdentityManager = class {
1548
1578
  (0, import_log4.log)("constructing identity", {
1549
1579
  identityRecord
1550
1580
  }, {
1551
- F: __dxlog_file5,
1581
+ F: __dxlog_file6,
1552
1582
  L: 317,
1553
1583
  S: this,
1554
1584
  C: (f, a) => f(...a)
@@ -1563,7 +1593,7 @@ var IdentityManager = class {
1563
1593
  gossip
1564
1594
  });
1565
1595
  (0, import_invariant3.invariant)(identityRecord.haloSpace.controlFeedKey, void 0, {
1566
- F: __dxlog_file5,
1596
+ F: __dxlog_file6,
1567
1597
  L: 330,
1568
1598
  S: this,
1569
1599
  A: [
@@ -1575,7 +1605,7 @@ var IdentityManager = class {
1575
1605
  writable: true
1576
1606
  });
1577
1607
  (0, import_invariant3.invariant)(identityRecord.haloSpace.dataFeedKey, void 0, {
1578
- F: __dxlog_file5,
1608
+ F: __dxlog_file6,
1579
1609
  L: 334,
1580
1610
  S: this,
1581
1611
  A: [
@@ -1609,7 +1639,7 @@ var IdentityManager = class {
1609
1639
  (0, import_log4.log)("done", {
1610
1640
  identityKey: identityRecord.identityKey
1611
1641
  }, {
1612
- F: __dxlog_file5,
1642
+ F: __dxlog_file6,
1613
1643
  L: 360,
1614
1644
  S: this,
1615
1645
  C: (f, a) => f(...a)
@@ -1634,7 +1664,7 @@ var IdentityManager = class {
1634
1664
  },
1635
1665
  onAuthFailure: () => {
1636
1666
  import_log4.log.warn("auth failure", void 0, {
1637
- F: __dxlog_file5,
1667
+ F: __dxlog_file6,
1638
1668
  L: 385,
1639
1669
  S: this,
1640
1670
  C: (f, a) => f(...a)
@@ -1656,7 +1686,8 @@ _ts_decorate3([
1656
1686
  IdentityManager = _ts_decorate3([
1657
1687
  import_tracing4.trace.resource()
1658
1688
  ], IdentityManager);
1659
- var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
1689
+ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
1690
+ var DEFAULT_SPACE_SEARCH_TIMEOUT = 1e4;
1660
1691
  var IdentityServiceImpl = class extends import_context4.Resource {
1661
1692
  constructor(_identityManager, _keyring, _dataSpaceManagerProvider, _createIdentity, _onProfileUpdate) {
1662
1693
  super();
@@ -1685,8 +1716,8 @@ var IdentityServiceImpl = class extends import_context4.Resource {
1685
1716
  const space = await dataSpaceManager.createDefaultSpace();
1686
1717
  const identity = this._identityManager.identity;
1687
1718
  (0, import_invariant4.invariant)(identity, void 0, {
1688
- F: __dxlog_file6,
1689
- L: 54,
1719
+ F: __dxlog_file7,
1720
+ L: 59,
1690
1721
  S: this,
1691
1722
  A: [
1692
1723
  "identity",
@@ -1719,8 +1750,8 @@ var IdentityServiceImpl = class extends import_context4.Resource {
1719
1750
  }
1720
1751
  async updateProfile(profile) {
1721
1752
  (0, import_invariant4.invariant)(this._identityManager.identity, "Identity not initialized.", {
1722
- F: __dxlog_file6,
1723
- L: 84,
1753
+ F: __dxlog_file7,
1754
+ L: 89,
1724
1755
  S: this,
1725
1756
  A: [
1726
1757
  "this._identityManager.identity",
@@ -1733,8 +1764,8 @@ var IdentityServiceImpl = class extends import_context4.Resource {
1733
1764
  }
1734
1765
  async signPresentation({ presentation, nonce }) {
1735
1766
  (0, import_invariant4.invariant)(this._identityManager.identity, "Identity not initialized.", {
1736
- F: __dxlog_file6,
1737
- L: 91,
1767
+ F: __dxlog_file7,
1768
+ L: 96,
1738
1769
  S: this,
1739
1770
  A: [
1740
1771
  "this._identityManager.identity",
@@ -1750,9 +1781,11 @@ var IdentityServiceImpl = class extends import_context4.Resource {
1750
1781
  });
1751
1782
  }
1752
1783
  async _fixIdentityWithoutDefaultSpace(identity) {
1753
- let hasDefaultSpace = false;
1784
+ let recodedDefaultSpace = false;
1785
+ let foundDefaultSpace = false;
1754
1786
  const dataSpaceManager = this._dataSpaceManagerProvider();
1755
- for (const space of dataSpaceManager.spaces.values()) {
1787
+ const recordedDefaultSpaceTrigger = new import_async8.Trigger();
1788
+ const allProcessed = (0, import_util4.safeAwaitAll)(dataSpaceManager.spaces.values(), async (space) => {
1756
1789
  if (space.state === import_services4.SpaceState.CLOSED) {
1757
1790
  await space.open();
1758
1791
  const requiresMigration = space.stateUpdate.waitForCondition(() => space.state === import_services4.SpaceState.REQUIRES_MIGRATION);
@@ -1762,17 +1795,41 @@ var IdentityServiceImpl = class extends import_context4.Resource {
1762
1795
  ]);
1763
1796
  }
1764
1797
  if (await dataSpaceManager.isDefaultSpace(space)) {
1798
+ if (foundDefaultSpace) {
1799
+ import_log5.log.warn("Multiple default spaces found. Using the first one.", {
1800
+ duplicate: space.id
1801
+ }, {
1802
+ F: __dxlog_file7,
1803
+ L: 129,
1804
+ S: this,
1805
+ C: (f, a) => f(...a)
1806
+ });
1807
+ return;
1808
+ }
1809
+ foundDefaultSpace = true;
1765
1810
  await identity.updateDefaultSpace(space.id);
1766
- hasDefaultSpace = true;
1767
- break;
1811
+ recodedDefaultSpace = true;
1812
+ recordedDefaultSpaceTrigger.wake();
1768
1813
  }
1769
- }
1770
- if (!hasDefaultSpace) {
1814
+ }, (err) => {
1815
+ import_log5.log.catch(err, void 0, {
1816
+ F: __dxlog_file7,
1817
+ L: 140,
1818
+ S: this,
1819
+ C: (f, a) => f(...a)
1820
+ });
1821
+ });
1822
+ await Promise.race([
1823
+ allProcessed,
1824
+ recordedDefaultSpaceTrigger.wait(),
1825
+ (0, import_async8.sleep)(DEFAULT_SPACE_SEARCH_TIMEOUT)
1826
+ ]);
1827
+ if (!recodedDefaultSpace) {
1771
1828
  await this._createDefaultSpace(dataSpaceManager);
1772
1829
  }
1773
1830
  }
1774
1831
  };
1775
- var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts";
1832
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts";
1776
1833
  var DeviceInvitationProtocol = class {
1777
1834
  constructor(_keyring, _getIdentity, _acceptIdentity) {
1778
1835
  this._keyring = _keyring;
@@ -1798,7 +1855,7 @@ var DeviceInvitationProtocol = class {
1798
1855
  }
1799
1856
  async admit(_, request) {
1800
1857
  (0, import_invariant5.invariant)(request.device, void 0, {
1801
- F: __dxlog_file7,
1858
+ F: __dxlog_file8,
1802
1859
  L: 50,
1803
1860
  S: this,
1804
1861
  A: [
@@ -1844,7 +1901,7 @@ var DeviceInvitationProtocol = class {
1844
1901
  }
1845
1902
  async accept(response, request) {
1846
1903
  (0, import_invariant5.invariant)(response.device, void 0, {
1847
- F: __dxlog_file7,
1904
+ F: __dxlog_file8,
1848
1905
  L: 95,
1849
1906
  S: this,
1850
1907
  A: [
@@ -1854,7 +1911,7 @@ var DeviceInvitationProtocol = class {
1854
1911
  });
1855
1912
  const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
1856
1913
  (0, import_invariant5.invariant)(request.device, void 0, {
1857
- F: __dxlog_file7,
1914
+ F: __dxlog_file8,
1858
1915
  L: 98,
1859
1916
  S: this,
1860
1917
  A: [
@@ -1893,7 +1950,7 @@ var tryAcquireBeforeContextDisposed = async (ctx, mutex) => {
1893
1950
  return guard;
1894
1951
  })());
1895
1952
  };
1896
- var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts";
1953
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts";
1897
1954
  var OPTIONS_TIMEOUT = 1e4;
1898
1955
  var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1899
1956
  constructor(_invitationFlowMutex, _callbacks) {
@@ -1907,8 +1964,11 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1907
1964
  });
1908
1965
  this._invitationFlowMutex = _invitationFlowMutex;
1909
1966
  this._callbacks = _callbacks;
1910
- this._ctx = new import_context6.Context();
1911
- this._remoteOptionsTrigger = new import_async9.Trigger();
1967
+ this._ctx = new import_context6.Context(void 0, {
1968
+ F: __dxlog_file9,
1969
+ L: 33
1970
+ });
1971
+ this._remoteOptionsTrigger = new import_async10.Trigger();
1912
1972
  this._invitationFlowLock = null;
1913
1973
  }
1914
1974
  hasFlowLock() {
@@ -1919,7 +1979,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1919
1979
  InvitationHostService: {
1920
1980
  options: async (options) => {
1921
1981
  (0, import_invariant7.invariant)(!this._remoteOptions, "Remote options already set.", {
1922
- F: __dxlog_file8,
1982
+ F: __dxlog_file9,
1923
1983
  L: 63,
1924
1984
  S: this,
1925
1985
  A: [
@@ -1945,15 +2005,15 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1945
2005
  async onOpen(context) {
1946
2006
  await super.onOpen(context);
1947
2007
  try {
1948
- (0, import_log6.log)("guest acquire lock", void 0, {
1949
- F: __dxlog_file8,
2008
+ (0, import_log7.log)("guest acquire lock", void 0, {
2009
+ F: __dxlog_file9,
1950
2010
  L: 84,
1951
2011
  S: this,
1952
2012
  C: (f, a) => f(...a)
1953
2013
  });
1954
2014
  this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
1955
- (0, import_log6.log)("guest lock acquired", void 0, {
1956
- F: __dxlog_file8,
2015
+ (0, import_log7.log)("guest lock acquired", void 0, {
2016
+ F: __dxlog_file9,
1957
2017
  L: 86,
1958
2018
  S: this,
1959
2019
  C: (f, a) => f(...a)
@@ -1961,8 +2021,8 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1961
2021
  await (0, import_context6.cancelWithContext)(this._ctx, this.rpc.InvitationHostService.options({
1962
2022
  role: import_invitations3.Options.Role.GUEST
1963
2023
  }));
1964
- (0, import_log6.log)("options sent", void 0, {
1965
- F: __dxlog_file8,
2024
+ (0, import_log7.log)("options sent", void 0, {
2025
+ F: __dxlog_file9,
1966
2026
  L: 88,
1967
2027
  S: this,
1968
2028
  C: (f, a) => f(...a)
@@ -1970,8 +2030,8 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1970
2030
  await (0, import_context6.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
1971
2031
  timeout: OPTIONS_TIMEOUT
1972
2032
  }));
1973
- (0, import_log6.log)("options received", void 0, {
1974
- F: __dxlog_file8,
2033
+ (0, import_log7.log)("options received", void 0, {
2034
+ F: __dxlog_file9,
1975
2035
  L: 90,
1976
2036
  S: this,
1977
2037
  C: (f, a) => f(...a)
@@ -2004,8 +2064,8 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
2004
2064
  if (this._invitationFlowLock != null) {
2005
2065
  this._invitationFlowLock.release();
2006
2066
  this._invitationFlowLock = null;
2007
- (0, import_log6.log)("invitation flow lock released", void 0, {
2008
- F: __dxlog_file8,
2067
+ (0, import_log7.log)("invitation flow lock released", void 0, {
2068
+ F: __dxlog_file9,
2009
2069
  L: 123,
2010
2070
  S: this,
2011
2071
  C: (f, a) => f(...a)
@@ -2013,7 +2073,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
2013
2073
  }
2014
2074
  }
2015
2075
  };
2016
- var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts";
2076
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts";
2017
2077
  var OPTIONS_TIMEOUT2 = 1e4;
2018
2078
  var MAX_OTP_ATTEMPTS = 3;
2019
2079
  var InvitationHostExtension = class extends import_teleport2.RpcExtension {
@@ -2028,13 +2088,16 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2028
2088
  });
2029
2089
  this._invitationFlowMutex = _invitationFlowMutex;
2030
2090
  this._callbacks = _callbacks;
2031
- this._ctx = new import_context8.Context();
2032
- this._remoteOptionsTrigger = new import_async10.Trigger();
2091
+ this._ctx = new import_context8.Context(void 0, {
2092
+ F: __dxlog_file10,
2093
+ L: 52
2094
+ });
2095
+ this._remoteOptionsTrigger = new import_async11.Trigger();
2033
2096
  this._challenge = void 0;
2034
2097
  this.guestProfile = void 0;
2035
2098
  this.authenticationPassed = false;
2036
2099
  this.authenticationRetry = 0;
2037
- this.completedTrigger = new import_async10.Trigger();
2100
+ this.completedTrigger = new import_async11.Trigger();
2038
2101
  this._invitationFlowLock = null;
2039
2102
  }
2040
2103
  hasFlowLock() {
@@ -2047,7 +2110,7 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2047
2110
  InvitationHostService: {
2048
2111
  options: async (options) => {
2049
2112
  (0, import_invariant8.invariant)(!this._remoteOptions, "Remote options already set.", {
2050
- F: __dxlog_file9,
2113
+ F: __dxlog_file10,
2051
2114
  L: 101,
2052
2115
  S: this,
2053
2116
  A: [
@@ -2061,10 +2124,10 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2061
2124
  introduce: async (request) => {
2062
2125
  const { profile, invitationId } = request;
2063
2126
  const traceId = import_keys7.PublicKey.random().toHex();
2064
- import_log7.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols7.trace.begin({
2127
+ import_log8.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols7.trace.begin({
2065
2128
  id: traceId
2066
2129
  }), {
2067
- F: __dxlog_file9,
2130
+ F: __dxlog_file10,
2068
2131
  L: 110,
2069
2132
  S: this,
2070
2133
  C: (f, a) => f(...a)
@@ -2072,25 +2135,25 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2072
2135
  const invitation = this._requireActiveInvitation();
2073
2136
  this._assertInvitationState(import_services8.Invitation.State.CONNECTED);
2074
2137
  if (invitationId !== invitation?.invitationId) {
2075
- import_log7.log.warn("incorrect invitationId", {
2138
+ import_log8.log.warn("incorrect invitationId", {
2076
2139
  expected: invitation.invitationId,
2077
2140
  actual: invitationId
2078
2141
  }, {
2079
- F: __dxlog_file9,
2142
+ F: __dxlog_file10,
2080
2143
  L: 116,
2081
2144
  S: this,
2082
2145
  C: (f, a) => f(...a)
2083
2146
  });
2084
2147
  this._callbacks.onError(new Error("Incorrect invitationId."));
2085
- (0, import_async10.scheduleTask)(this._ctx, () => this.close());
2148
+ (0, import_async11.scheduleTask)(this._ctx, () => this.close());
2086
2149
  return {
2087
2150
  authMethod: import_services8.Invitation.AuthMethod.NONE
2088
2151
  };
2089
2152
  }
2090
- (0, import_log7.log)("guest introduced themselves", {
2153
+ (0, import_log8.log)("guest introduced themselves", {
2091
2154
  guestProfile: profile
2092
2155
  }, {
2093
- F: __dxlog_file9,
2156
+ F: __dxlog_file10,
2094
2157
  L: 125,
2095
2158
  S: this,
2096
2159
  C: (f, a) => f(...a)
@@ -2098,10 +2161,10 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2098
2161
  this.guestProfile = profile;
2099
2162
  this._callbacks.onStateUpdate(import_services8.Invitation.State.READY_FOR_AUTHENTICATION);
2100
2163
  this._challenge = invitation.authMethod === import_services8.Invitation.AuthMethod.KNOWN_PUBLIC_KEY ? (0, import_crypto2.randomBytes)(32) : void 0;
2101
- import_log7.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols7.trace.end({
2164
+ import_log8.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols7.trace.end({
2102
2165
  id: traceId
2103
2166
  }), {
2104
- F: __dxlog_file9,
2167
+ F: __dxlog_file10,
2105
2168
  L: 132,
2106
2169
  S: this,
2107
2170
  C: (f, a) => f(...a)
@@ -2113,19 +2176,19 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2113
2176
  },
2114
2177
  authenticate: async ({ authCode: code, signedChallenge }) => {
2115
2178
  const traceId = import_keys7.PublicKey.random().toHex();
2116
- import_log7.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols7.trace.begin({
2179
+ import_log8.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols7.trace.begin({
2117
2180
  id: traceId
2118
2181
  }), {
2119
- F: __dxlog_file9,
2182
+ F: __dxlog_file10,
2120
2183
  L: 141,
2121
2184
  S: this,
2122
2185
  C: (f, a) => f(...a)
2123
2186
  });
2124
2187
  const invitation = this._requireActiveInvitation();
2125
- (0, import_log7.log)("received authentication request", {
2188
+ (0, import_log8.log)("received authentication request", {
2126
2189
  authCode: code
2127
2190
  }, {
2128
- F: __dxlog_file9,
2191
+ F: __dxlog_file10,
2129
2192
  L: 144,
2130
2193
  S: this,
2131
2194
  C: (f, a) => f(...a)
@@ -2138,8 +2201,8 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2138
2201
  this._callbacks.onStateUpdate(import_services8.Invitation.State.AUTHENTICATING);
2139
2202
  switch (invitation.authMethod) {
2140
2203
  case import_services8.Invitation.AuthMethod.NONE: {
2141
- (0, import_log7.log)("authentication not required", void 0, {
2142
- F: __dxlog_file9,
2204
+ (0, import_log8.log)("authentication not required", void 0, {
2205
+ F: __dxlog_file10,
2143
2206
  L: 152,
2144
2207
  S: this,
2145
2208
  C: (f, a) => f(...a)
@@ -2174,10 +2237,10 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2174
2237
  break;
2175
2238
  }
2176
2239
  default: {
2177
- import_log7.log.error("invalid authentication method", {
2240
+ import_log8.log.error("invalid authentication method", {
2178
2241
  authMethod: invitation.authMethod
2179
2242
  }, {
2180
- F: __dxlog_file9,
2243
+ F: __dxlog_file10,
2181
2244
  L: 190,
2182
2245
  S: this,
2183
2246
  C: (f, a) => f(...a)
@@ -2191,18 +2254,18 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2191
2254
  import_invitations4.AuthenticationResponse.Status.INVALID_OTP
2192
2255
  ].includes(status)) {
2193
2256
  this._callbacks.onError(new Error(`Authentication failed, with status=${status}`));
2194
- (0, import_async10.scheduleTask)(this._ctx, () => this.close());
2257
+ (0, import_async11.scheduleTask)(this._ctx, () => this.close());
2195
2258
  return {
2196
2259
  status
2197
2260
  };
2198
2261
  }
2199
- import_log7.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols7.trace.end({
2262
+ import_log8.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols7.trace.end({
2200
2263
  id: traceId,
2201
2264
  data: {
2202
2265
  status
2203
2266
  }
2204
2267
  }), {
2205
- F: __dxlog_file9,
2268
+ F: __dxlog_file10,
2206
2269
  L: 202,
2207
2270
  S: this,
2208
2271
  C: (f, a) => f(...a)
@@ -2213,10 +2276,10 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2213
2276
  },
2214
2277
  admit: async (request) => {
2215
2278
  const traceId = import_keys7.PublicKey.random().toHex();
2216
- import_log7.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols7.trace.begin({
2279
+ import_log8.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols7.trace.begin({
2217
2280
  id: traceId
2218
2281
  }), {
2219
- F: __dxlog_file9,
2282
+ F: __dxlog_file10,
2220
2283
  L: 208,
2221
2284
  S: this,
2222
2285
  C: (f, a) => f(...a)
@@ -2230,10 +2293,10 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2230
2293
  }
2231
2294
  }
2232
2295
  const response = await this._callbacks.admit(request);
2233
- import_log7.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols7.trace.end({
2296
+ import_log8.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols7.trace.end({
2234
2297
  id: traceId
2235
2298
  }), {
2236
- F: __dxlog_file9,
2299
+ F: __dxlog_file10,
2237
2300
  L: 222,
2238
2301
  S: this,
2239
2302
  C: (f, a) => f(...a)
@@ -2250,15 +2313,15 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2250
2313
  async onOpen(context) {
2251
2314
  await super.onOpen(context);
2252
2315
  try {
2253
- (0, import_log7.log)("host acquire lock", void 0, {
2254
- F: __dxlog_file9,
2316
+ (0, import_log8.log)("host acquire lock", void 0, {
2317
+ F: __dxlog_file10,
2255
2318
  L: 237,
2256
2319
  S: this,
2257
2320
  C: (f, a) => f(...a)
2258
2321
  });
2259
2322
  this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
2260
- (0, import_log7.log)("host lock acquired", void 0, {
2261
- F: __dxlog_file9,
2323
+ (0, import_log8.log)("host lock acquired", void 0, {
2324
+ F: __dxlog_file10,
2262
2325
  L: 239,
2263
2326
  S: this,
2264
2327
  C: (f, a) => f(...a)
@@ -2268,8 +2331,8 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2268
2331
  await this.rpc.InvitationHostService.options({
2269
2332
  role: import_invitations4.Options.Role.HOST
2270
2333
  });
2271
- (0, import_log7.log)("options sent", void 0, {
2272
- F: __dxlog_file9,
2334
+ (0, import_log8.log)("options sent", void 0, {
2335
+ F: __dxlog_file10,
2273
2336
  L: 243,
2274
2337
  S: this,
2275
2338
  C: (f, a) => f(...a)
@@ -2277,8 +2340,8 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2277
2340
  await (0, import_context8.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
2278
2341
  timeout: OPTIONS_TIMEOUT2
2279
2342
  }));
2280
- (0, import_log7.log)("options received", void 0, {
2281
- F: __dxlog_file9,
2343
+ (0, import_log8.log)("options received", void 0, {
2344
+ F: __dxlog_file10,
2282
2345
  L: 245,
2283
2346
  S: this,
2284
2347
  C: (f, a) => f(...a)
@@ -2305,7 +2368,7 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2305
2368
  _requireActiveInvitation() {
2306
2369
  const invitation = this._callbacks.activeInvitation;
2307
2370
  if (invitation == null) {
2308
- (0, import_async10.scheduleTask)(this._ctx, () => this.close());
2371
+ (0, import_async11.scheduleTask)(this._ctx, () => this.close());
2309
2372
  throw new Error("Active invitation not found");
2310
2373
  }
2311
2374
  return invitation;
@@ -2316,7 +2379,7 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2316
2379
  stateOrMany
2317
2380
  ];
2318
2381
  if (!validStates.includes(invitation.state)) {
2319
- (0, import_async10.scheduleTask)(this._ctx, () => this.close());
2382
+ (0, import_async11.scheduleTask)(this._ctx, () => this.close());
2320
2383
  throw new import_invariant8.InvariantViolation(`Expected ${stateToString(invitation.state)} to be one of [${validStates.map(stateToString).join(", ")}]`);
2321
2384
  }
2322
2385
  }
@@ -2331,8 +2394,8 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2331
2394
  if (this._invitationFlowLock != null) {
2332
2395
  this._invitationFlowLock?.release();
2333
2396
  this._invitationFlowLock = null;
2334
- (0, import_log7.log)("invitation flow lock released", void 0, {
2335
- F: __dxlog_file9,
2397
+ (0, import_log8.log)("invitation flow lock released", void 0, {
2398
+ F: __dxlog_file10,
2336
2399
  L: 300,
2337
2400
  S: this,
2338
2401
  C: (f, a) => f(...a)
@@ -2341,15 +2404,15 @@ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
2341
2404
  }
2342
2405
  };
2343
2406
  var isAuthenticationRequired = (invitation) => invitation.authMethod !== import_services8.Invitation.AuthMethod.NONE;
2344
- var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts";
2407
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts";
2345
2408
  var InvitationTopology = class {
2346
2409
  constructor(_role) {
2347
2410
  this._role = _role;
2348
- this._seenPeers = new import_util5.ComplexSet(import_keys8.PublicKey.hash);
2411
+ this._seenPeers = new import_util6.ComplexSet(import_keys8.PublicKey.hash);
2349
2412
  }
2350
2413
  init(controller) {
2351
2414
  (0, import_invariant9.invariant)(!this._controller, "Already initialized.", {
2352
- F: __dxlog_file10,
2415
+ F: __dxlog_file11,
2353
2416
  L: 42,
2354
2417
  S: this,
2355
2418
  A: [
@@ -2361,7 +2424,7 @@ var InvitationTopology = class {
2361
2424
  }
2362
2425
  update() {
2363
2426
  (0, import_invariant9.invariant)(this._controller, "Not initialized.", {
2364
- F: __dxlog_file10,
2427
+ F: __dxlog_file11,
2365
2428
  L: 47,
2366
2429
  S: this,
2367
2430
  A: [
@@ -2378,13 +2441,13 @@ var InvitationTopology = class {
2378
2441
  return;
2379
2442
  }
2380
2443
  const firstUnknownPeer = candidates.find((peerId) => !this._seenPeers.has(peerId));
2381
- this._seenPeers = new import_util5.ComplexSet(import_keys8.PublicKey.hash, allPeers.filter((peerId) => this._seenPeers.has(peerId)));
2444
+ this._seenPeers = new import_util6.ComplexSet(import_keys8.PublicKey.hash, allPeers.filter((peerId) => this._seenPeers.has(peerId)));
2382
2445
  if (firstUnknownPeer != null) {
2383
- (0, import_log8.log)("invitation connect", {
2446
+ (0, import_log9.log)("invitation connect", {
2384
2447
  ownPeerId,
2385
2448
  remotePeerId: firstUnknownPeer
2386
2449
  }, {
2387
- F: __dxlog_file10,
2450
+ F: __dxlog_file11,
2388
2451
  L: 69,
2389
2452
  S: this,
2390
2453
  C: (f, a) => f(...a)
@@ -2395,7 +2458,7 @@ var InvitationTopology = class {
2395
2458
  }
2396
2459
  async onOffer(peer) {
2397
2460
  (0, import_invariant9.invariant)(this._controller, "Not initialized.", {
2398
- F: __dxlog_file10,
2461
+ F: __dxlog_file11,
2399
2462
  L: 76,
2400
2463
  S: this,
2401
2464
  A: [
@@ -2412,7 +2475,7 @@ var InvitationTopology = class {
2412
2475
  return `InvitationTopology(${this._role === import_invitations5.Options.Role.GUEST ? "guest" : "host"})`;
2413
2476
  }
2414
2477
  };
2415
- var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts";
2478
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts";
2416
2479
  var MAX_DELEGATED_INVITATION_HOST_TRIES = 3;
2417
2480
  var InvitationsHandler = class {
2418
2481
  /**
@@ -2437,7 +2500,7 @@ var InvitationsHandler = class {
2437
2500
  try {
2438
2501
  const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
2439
2502
  (0, import_invariant6.invariant)(deviceKey, void 0, {
2440
- F: __dxlog_file11,
2503
+ F: __dxlog_file12,
2441
2504
  L: 90,
2442
2505
  S: this,
2443
2506
  A: [
@@ -2460,21 +2523,21 @@ var InvitationsHandler = class {
2460
2523
  guardedState.error(extension, new import_context5.ContextDisposedError());
2461
2524
  }
2462
2525
  });
2463
- (0, import_async8.scheduleTask)(connectionCtx, async () => {
2526
+ (0, import_async9.scheduleTask)(connectionCtx, async () => {
2464
2527
  const traceId = import_keys6.PublicKey.random().toHex();
2465
2528
  try {
2466
- import_log5.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols5.trace.begin({
2529
+ import_log6.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols5.trace.begin({
2467
2530
  id: traceId
2468
2531
  }), {
2469
- F: __dxlog_file11,
2532
+ F: __dxlog_file12,
2470
2533
  L: 115,
2471
2534
  S: this,
2472
2535
  C: (f, a) => f(...a)
2473
2536
  });
2474
- (0, import_log5.log)("connected", {
2537
+ (0, import_log6.log)("connected", {
2475
2538
  ...protocol.toJSON()
2476
2539
  }, {
2477
- F: __dxlog_file11,
2540
+ F: __dxlog_file12,
2478
2541
  L: 116,
2479
2542
  S: this,
2480
2543
  C: (f, a) => f(...a)
@@ -2482,20 +2545,20 @@ var InvitationsHandler = class {
2482
2545
  const deviceKey = await extension.completedTrigger.wait({
2483
2546
  timeout: invitation.timeout
2484
2547
  });
2485
- (0, import_log5.log)("admitted guest", {
2548
+ (0, import_log6.log)("admitted guest", {
2486
2549
  guest: deviceKey,
2487
2550
  ...protocol.toJSON()
2488
2551
  }, {
2489
- F: __dxlog_file11,
2552
+ F: __dxlog_file12,
2490
2553
  L: 118,
2491
2554
  S: this,
2492
2555
  C: (f, a) => f(...a)
2493
2556
  });
2494
2557
  guardedState.set(extension, import_services6.Invitation.State.SUCCESS);
2495
- import_log5.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols5.trace.end({
2558
+ import_log6.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols5.trace.end({
2496
2559
  id: traceId
2497
2560
  }), {
2498
- F: __dxlog_file11,
2561
+ F: __dxlog_file12,
2499
2562
  L: 120,
2500
2563
  S: this,
2501
2564
  C: (f, a) => f(...a)
@@ -2505,12 +2568,12 @@ var InvitationsHandler = class {
2505
2568
  await ctx.dispose();
2506
2569
  }
2507
2570
  } catch (err) {
2508
- if (err instanceof import_async8.TimeoutError) {
2571
+ if (err instanceof import_async9.TimeoutError) {
2509
2572
  if (guardedState.set(extension, import_services6.Invitation.State.TIMEOUT)) {
2510
- (0, import_log5.log)("timeout", {
2573
+ (0, import_log6.log)("timeout", {
2511
2574
  ...protocol.toJSON()
2512
2575
  }, {
2513
- F: __dxlog_file11,
2576
+ F: __dxlog_file12,
2514
2577
  L: 129,
2515
2578
  S: this,
2516
2579
  C: (f, a) => f(...a)
@@ -2518,19 +2581,19 @@ var InvitationsHandler = class {
2518
2581
  }
2519
2582
  } else {
2520
2583
  if (guardedState.error(extension, err)) {
2521
- import_log5.log.error("failed", err, {
2522
- F: __dxlog_file11,
2584
+ import_log6.log.error("failed", err, {
2585
+ F: __dxlog_file12,
2523
2586
  L: 133,
2524
2587
  S: this,
2525
2588
  C: (f, a) => f(...a)
2526
2589
  });
2527
2590
  }
2528
2591
  }
2529
- import_log5.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols5.trace.error({
2592
+ import_log6.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols5.trace.error({
2530
2593
  id: traceId,
2531
2594
  error: err
2532
2595
  }), {
2533
- F: __dxlog_file11,
2596
+ F: __dxlog_file12,
2534
2597
  L: 136,
2535
2598
  S: this,
2536
2599
  C: (f, a) => f(...a)
@@ -2541,22 +2604,22 @@ var InvitationsHandler = class {
2541
2604
  },
2542
2605
  onError: (err) => {
2543
2606
  if (err instanceof import_protocols5.InvalidInvitationExtensionRoleError) {
2544
- (0, import_log5.log)("invalid role", {
2607
+ (0, import_log6.log)("invalid role", {
2545
2608
  ...err.context
2546
2609
  }, {
2547
- F: __dxlog_file11,
2610
+ F: __dxlog_file12,
2548
2611
  L: 144,
2549
2612
  S: this,
2550
2613
  C: (f, a) => f(...a)
2551
2614
  });
2552
2615
  return;
2553
2616
  }
2554
- if (err instanceof import_async8.TimeoutError) {
2617
+ if (err instanceof import_async9.TimeoutError) {
2555
2618
  if (guardedState.set(extension, import_services6.Invitation.State.TIMEOUT)) {
2556
- (0, import_log5.log)("timeout", {
2619
+ (0, import_log6.log)("timeout", {
2557
2620
  err
2558
2621
  }, {
2559
- F: __dxlog_file11,
2622
+ F: __dxlog_file12,
2560
2623
  L: 149,
2561
2624
  S: this,
2562
2625
  C: (f, a) => f(...a)
@@ -2564,8 +2627,8 @@ var InvitationsHandler = class {
2564
2627
  }
2565
2628
  } else {
2566
2629
  if (guardedState.error(extension, err)) {
2567
- import_log5.log.error("failed", err, {
2568
- F: __dxlog_file11,
2630
+ import_log6.log.error("failed", err, {
2631
+ F: __dxlog_file12,
2569
2632
  L: 153,
2570
2633
  S: this,
2571
2634
  C: (f, a) => f(...a)
@@ -2578,14 +2641,14 @@ var InvitationsHandler = class {
2578
2641
  };
2579
2642
  if (invitation.lifetime && invitation.created) {
2580
2643
  if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
2581
- import_log5.log.warn("invitation has already expired", void 0, {
2582
- F: __dxlog_file11,
2644
+ import_log6.log.warn("invitation has already expired", void 0, {
2645
+ F: __dxlog_file12,
2583
2646
  L: 164,
2584
2647
  S: this,
2585
2648
  C: (f, a) => f(...a)
2586
2649
  });
2587
2650
  } else {
2588
- (0, import_async8.scheduleTask)(ctx, async () => {
2651
+ (0, import_async9.scheduleTask)(ctx, async () => {
2589
2652
  await swarmConnection.close();
2590
2653
  guardedState.set(null, import_services6.Invitation.State.EXPIRED);
2591
2654
  await ctx.dispose();
@@ -2593,7 +2656,7 @@ var InvitationsHandler = class {
2593
2656
  }
2594
2657
  }
2595
2658
  let swarmConnection;
2596
- (0, import_async8.scheduleTask)(ctx, async () => {
2659
+ (0, import_async9.scheduleTask)(ctx, async () => {
2597
2660
  swarmConnection = await this._joinSwarm(ctx, invitation, import_invitations2.Options.Role.HOST, createExtension);
2598
2661
  guardedState.set(null, import_services6.Invitation.State.CONNECTING);
2599
2662
  });
@@ -2602,7 +2665,7 @@ var InvitationsHandler = class {
2602
2665
  const { timeout = import_client_protocol2.INVITATION_TIMEOUT } = invitation;
2603
2666
  if (deviceProfile) {
2604
2667
  (0, import_invariant6.invariant)(invitation.kind === import_services6.Invitation.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
2605
- F: __dxlog_file11,
2668
+ F: __dxlog_file12,
2606
2669
  L: 197,
2607
2670
  S: this,
2608
2671
  A: [
@@ -2611,16 +2674,16 @@ var InvitationsHandler = class {
2611
2674
  ]
2612
2675
  });
2613
2676
  }
2614
- const triedPeersIds = new import_util4.ComplexSet(import_keys6.PublicKey.hash);
2677
+ const triedPeersIds = new import_util5.ComplexSet(import_keys6.PublicKey.hash);
2615
2678
  const guardedState = this._createGuardedState(ctx, invitation, stream);
2616
2679
  const shouldCancelInvitationFlow = (extension) => {
2617
2680
  const isLockedByAnotherConnection = guardedState.mutex.isLocked() && !extension.hasFlowLock();
2618
- (0, import_log5.log)("should cancel invitation flow", {
2681
+ (0, import_log6.log)("should cancel invitation flow", {
2619
2682
  isLockedByAnotherConnection,
2620
2683
  invitationType: import_services6.Invitation.Type.DELEGATED,
2621
2684
  triedPeers: triedPeersIds.size
2622
2685
  }, {
2623
- F: __dxlog_file11,
2686
+ F: __dxlog_file12,
2624
2687
  L: 205,
2625
2688
  S: this,
2626
2689
  C: (f, a) => f(...a)
@@ -2643,11 +2706,11 @@ var InvitationsHandler = class {
2643
2706
  return;
2644
2707
  }
2645
2708
  connectionCtx.onDispose(async () => {
2646
- (0, import_log5.log)("extension disposed", {
2709
+ (0, import_log6.log)("extension disposed", {
2647
2710
  admitted,
2648
2711
  currentState: guardedState.current.state
2649
2712
  }, {
2650
- F: __dxlog_file11,
2713
+ F: __dxlog_file12,
2651
2714
  L: 233,
2652
2715
  S: this,
2653
2716
  C: (f, a) => f(...a)
@@ -2659,34 +2722,34 @@ var InvitationsHandler = class {
2659
2722
  }
2660
2723
  }
2661
2724
  });
2662
- (0, import_async8.scheduleTask)(connectionCtx, async () => {
2725
+ (0, import_async9.scheduleTask)(connectionCtx, async () => {
2663
2726
  const traceId = import_keys6.PublicKey.random().toHex();
2664
2727
  try {
2665
- import_log5.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols5.trace.begin({
2728
+ import_log6.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols5.trace.begin({
2666
2729
  id: traceId
2667
2730
  }), {
2668
- F: __dxlog_file11,
2731
+ F: __dxlog_file12,
2669
2732
  L: 245,
2670
2733
  S: this,
2671
2734
  C: (f, a) => f(...a)
2672
2735
  });
2673
- (0, import_async8.scheduleTask)(connectionCtx, () => {
2736
+ (0, import_async9.scheduleTask)(connectionCtx, () => {
2674
2737
  guardedState.set(extension, import_services6.Invitation.State.TIMEOUT);
2675
2738
  extensionCtx.close();
2676
2739
  }, timeout);
2677
- (0, import_log5.log)("connected", {
2740
+ (0, import_log6.log)("connected", {
2678
2741
  ...protocol.toJSON()
2679
2742
  }, {
2680
- F: __dxlog_file11,
2743
+ F: __dxlog_file12,
2681
2744
  L: 256,
2682
2745
  S: this,
2683
2746
  C: (f, a) => f(...a)
2684
2747
  });
2685
2748
  guardedState.set(extension, import_services6.Invitation.State.CONNECTED);
2686
- (0, import_log5.log)("introduce", {
2749
+ (0, import_log6.log)("introduce", {
2687
2750
  ...protocol.toJSON()
2688
2751
  }, {
2689
- F: __dxlog_file11,
2752
+ F: __dxlog_file12,
2690
2753
  L: 260,
2691
2754
  S: this,
2692
2755
  C: (f, a) => f(...a)
@@ -2695,11 +2758,11 @@ var InvitationsHandler = class {
2695
2758
  invitationId: invitation.invitationId,
2696
2759
  ...protocol.createIntroduction()
2697
2760
  });
2698
- (0, import_log5.log)("introduce response", {
2761
+ (0, import_log6.log)("introduce response", {
2699
2762
  ...protocol.toJSON(),
2700
2763
  response: introductionResponse
2701
2764
  }, {
2702
- F: __dxlog_file11,
2765
+ F: __dxlog_file12,
2703
2766
  L: 265,
2704
2767
  S: this,
2705
2768
  C: (f, a) => f(...a)
@@ -2717,10 +2780,10 @@ var InvitationsHandler = class {
2717
2780
  break;
2718
2781
  }
2719
2782
  }
2720
- (0, import_log5.log)("request admission", {
2783
+ (0, import_log6.log)("request admission", {
2721
2784
  ...protocol.toJSON()
2722
2785
  }, {
2723
- F: __dxlog_file11,
2786
+ F: __dxlog_file12,
2724
2787
  L: 291,
2725
2788
  S: this,
2726
2789
  C: (f, a) => f(...a)
@@ -2729,10 +2792,10 @@ var InvitationsHandler = class {
2729
2792
  const admissionResponse = await extension.rpc.InvitationHostService.admit(admissionRequest);
2730
2793
  admitted = true;
2731
2794
  const result = await protocol.accept(admissionResponse, admissionRequest);
2732
- (0, import_log5.log)("admitted by host", {
2795
+ (0, import_log6.log)("admitted by host", {
2733
2796
  ...protocol.toJSON()
2734
2797
  }, {
2735
- F: __dxlog_file11,
2798
+ F: __dxlog_file12,
2736
2799
  L: 302,
2737
2800
  S: this,
2738
2801
  C: (f, a) => f(...a)
@@ -2742,28 +2805,28 @@ var InvitationsHandler = class {
2742
2805
  ...result,
2743
2806
  state: import_services6.Invitation.State.SUCCESS
2744
2807
  });
2745
- import_log5.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols5.trace.end({
2808
+ import_log6.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols5.trace.end({
2746
2809
  id: traceId
2747
2810
  }), {
2748
- F: __dxlog_file11,
2811
+ F: __dxlog_file12,
2749
2812
  L: 308,
2750
2813
  S: this,
2751
2814
  C: (f, a) => f(...a)
2752
2815
  });
2753
2816
  } catch (err) {
2754
- if (err instanceof import_async8.TimeoutError) {
2755
- (0, import_log5.log)("timeout", {
2817
+ if (err instanceof import_async9.TimeoutError) {
2818
+ (0, import_log6.log)("timeout", {
2756
2819
  ...protocol.toJSON()
2757
2820
  }, {
2758
- F: __dxlog_file11,
2821
+ F: __dxlog_file12,
2759
2822
  L: 311,
2760
2823
  S: this,
2761
2824
  C: (f, a) => f(...a)
2762
2825
  });
2763
2826
  guardedState.set(extension, import_services6.Invitation.State.TIMEOUT);
2764
2827
  } else {
2765
- (0, import_log5.log)("auth failed", err, {
2766
- F: __dxlog_file11,
2828
+ (0, import_log6.log)("auth failed", err, {
2829
+ F: __dxlog_file12,
2767
2830
  L: 314,
2768
2831
  S: this,
2769
2832
  C: (f, a) => f(...a)
@@ -2771,11 +2834,11 @@ var InvitationsHandler = class {
2771
2834
  guardedState.error(extension, err);
2772
2835
  }
2773
2836
  extensionCtx.close(err);
2774
- import_log5.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols5.trace.error({
2837
+ import_log6.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols5.trace.error({
2775
2838
  id: traceId,
2776
2839
  error: err
2777
2840
  }), {
2778
- F: __dxlog_file11,
2841
+ F: __dxlog_file12,
2779
2842
  L: 318,
2780
2843
  S: this,
2781
2844
  C: (f, a) => f(...a)
@@ -2787,19 +2850,19 @@ var InvitationsHandler = class {
2787
2850
  if (err instanceof import_protocols5.InvalidInvitationExtensionRoleError) {
2788
2851
  return;
2789
2852
  }
2790
- if (err instanceof import_async8.TimeoutError) {
2791
- (0, import_log5.log)("timeout", {
2853
+ if (err instanceof import_async9.TimeoutError) {
2854
+ (0, import_log6.log)("timeout", {
2792
2855
  ...protocol.toJSON()
2793
2856
  }, {
2794
- F: __dxlog_file11,
2857
+ F: __dxlog_file12,
2795
2858
  L: 327,
2796
2859
  S: this,
2797
2860
  C: (f, a) => f(...a)
2798
2861
  });
2799
2862
  guardedState.set(extension, import_services6.Invitation.State.TIMEOUT);
2800
2863
  } else {
2801
- (0, import_log5.log)("auth failed", err, {
2802
- F: __dxlog_file11,
2864
+ (0, import_log6.log)("auth failed", err, {
2865
+ F: __dxlog_file12,
2803
2866
  L: 330,
2804
2867
  S: this,
2805
2868
  C: (f, a) => f(...a)
@@ -2810,14 +2873,14 @@ var InvitationsHandler = class {
2810
2873
  });
2811
2874
  return extension;
2812
2875
  };
2813
- (0, import_async8.scheduleTask)(ctx, async () => {
2876
+ (0, import_async9.scheduleTask)(ctx, async () => {
2814
2877
  const error = protocol.checkInvitation(invitation);
2815
2878
  if (error) {
2816
2879
  stream.error(error);
2817
2880
  await ctx.dispose();
2818
2881
  } else {
2819
2882
  (0, import_invariant6.invariant)(invitation.swarmKey, void 0, {
2820
- F: __dxlog_file11,
2883
+ F: __dxlog_file12,
2821
2884
  L: 345,
2822
2885
  S: this,
2823
2886
  A: [
@@ -2856,7 +2919,7 @@ var InvitationsHandler = class {
2856
2919
  * invitation flow connections.
2857
2920
  */
2858
2921
  _createGuardedState(ctx, invitation, stream) {
2859
- const mutex = new import_async8.Mutex();
2922
+ const mutex = new import_async9.Mutex();
2860
2923
  let lastActiveExtension = null;
2861
2924
  let currentInvitation = {
2862
2925
  ...invitation
@@ -2911,16 +2974,29 @@ var InvitationsHandler = class {
2911
2974
  };
2912
2975
  }
2913
2976
  _logStateUpdate(invitation, actor, newState) {
2914
- (0, import_log5.log)("invitation state update", {
2915
- actor: actor?.constructor.name,
2916
- newState: stateToString(newState),
2917
- oldState: stateToString(invitation.state)
2918
- }, {
2919
- F: __dxlog_file11,
2920
- L: 438,
2921
- S: this,
2922
- C: (f, a) => f(...a)
2923
- });
2977
+ if (this._isNotTerminal(newState)) {
2978
+ (0, import_log6.log)("invitation state update", {
2979
+ actor: actor?.constructor.name,
2980
+ newState: stateToString(newState),
2981
+ oldState: stateToString(invitation.state)
2982
+ }, {
2983
+ F: __dxlog_file12,
2984
+ L: 439,
2985
+ S: this,
2986
+ C: (f, a) => f(...a)
2987
+ });
2988
+ } else {
2989
+ import_log6.log.info("invitation state update", {
2990
+ actor: actor?.constructor.name,
2991
+ newState: stateToString(newState),
2992
+ oldState: stateToString(invitation.state)
2993
+ }, {
2994
+ F: __dxlog_file12,
2995
+ L: 445,
2996
+ S: this,
2997
+ C: (f, a) => f(...a)
2998
+ });
2999
+ }
2924
3000
  }
2925
3001
  _isNotTerminal(currentState) {
2926
3002
  return ![
@@ -2933,17 +3009,17 @@ var InvitationsHandler = class {
2933
3009
  }
2934
3010
  async _handleGuestOtpAuth(extension, setState, authenticated, options) {
2935
3011
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2936
- (0, import_log5.log)("guest waiting for authentication code...", void 0, {
2937
- F: __dxlog_file11,
2938
- L: 462,
3012
+ (0, import_log6.log)("guest waiting for authentication code...", void 0, {
3013
+ F: __dxlog_file12,
3014
+ L: 470,
2939
3015
  S: this,
2940
3016
  C: (f, a) => f(...a)
2941
3017
  });
2942
3018
  setState(import_services6.Invitation.State.READY_FOR_AUTHENTICATION);
2943
3019
  const authCode = await authenticated.wait(options);
2944
- (0, import_log5.log)("sending authentication request", void 0, {
2945
- F: __dxlog_file11,
2946
- L: 466,
3020
+ (0, import_log6.log)("sending authentication request", void 0, {
3021
+ F: __dxlog_file12,
3022
+ L: 474,
2947
3023
  S: this,
2948
3024
  C: (f, a) => f(...a)
2949
3025
  });
@@ -2958,11 +3034,11 @@ var InvitationsHandler = class {
2958
3034
  if (attempt === MAX_OTP_ATTEMPTS) {
2959
3035
  throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
2960
3036
  } else {
2961
- (0, import_log5.log)("retrying invalid code", {
3037
+ (0, import_log6.log)("retrying invalid code", {
2962
3038
  attempt
2963
3039
  }, {
2964
- F: __dxlog_file11,
2965
- L: 477,
3040
+ F: __dxlog_file12,
3041
+ L: 485,
2966
3042
  S: this,
2967
3043
  C: (f, a) => f(...a)
2968
3044
  });
@@ -2978,9 +3054,9 @@ var InvitationsHandler = class {
2978
3054
  if (introductionResponse.challenge == null) {
2979
3055
  throw new Error("challenge missing in the introduction");
2980
3056
  }
2981
- (0, import_log5.log)("sending authentication request", void 0, {
2982
- F: __dxlog_file11,
2983
- L: 496,
3057
+ (0, import_log6.log)("sending authentication request", void 0, {
3058
+ F: __dxlog_file12,
3059
+ L: 504,
2984
3060
  S: this,
2985
3061
  C: (f, a) => f(...a)
2986
3062
  });
@@ -3094,7 +3170,7 @@ var InvitationsServiceImpl = class {
3094
3170
  });
3095
3171
  }
3096
3172
  };
3097
- var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
3173
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
3098
3174
  var SpaceInvitationProtocol = class {
3099
3175
  constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
3100
3176
  this._spaceManager = _spaceManager;
@@ -3128,79 +3204,43 @@ var SpaceInvitationProtocol = class {
3128
3204
  };
3129
3205
  }
3130
3206
  async admit(invitation, request, guestProfile) {
3131
- (0, import_invariant10.invariant)(this._spaceKey, void 0, {
3132
- F: __dxlog_file12,
3133
- L: 76,
3134
- S: this,
3135
- A: [
3136
- "this._spaceKey",
3137
- ""
3138
- ]
3139
- });
3140
- const space = this._spaceManager.spaces.get(this._spaceKey);
3141
- (0, import_invariant10.invariant)(space, void 0, {
3142
- F: __dxlog_file12,
3143
- L: 78,
3144
- S: this,
3145
- A: [
3146
- "space",
3147
- ""
3148
- ]
3149
- });
3150
- (0, import_invariant10.invariant)(request.space, void 0, {
3151
- F: __dxlog_file12,
3152
- L: 80,
3207
+ (0, import_invariant10.invariant)(this._spaceKey && request.space, void 0, {
3208
+ F: __dxlog_file13,
3209
+ L: 74,
3153
3210
  S: this,
3154
3211
  A: [
3155
- "request.space",
3212
+ "this._spaceKey && request.space",
3156
3213
  ""
3157
3214
  ]
3158
3215
  });
3159
- const { identityKey, deviceKey } = request.space;
3160
- if (space.inner.spaceState.getMemberRole(identityKey) !== import_credentials10.SpaceMember.Role.REMOVED) {
3161
- throw new import_protocols8.AlreadyJoinedError();
3162
- }
3163
- (0, import_log9.log)("writing guest credentials", {
3216
+ (0, import_log10.log)("writing guest credentials", {
3164
3217
  host: this._signingContext.deviceKey,
3165
- guest: deviceKey
3218
+ guest: request.space.deviceKey
3166
3219
  }, {
3167
- F: __dxlog_file12,
3168
- L: 87,
3220
+ F: __dxlog_file13,
3221
+ L: 75,
3169
3222
  S: this,
3170
3223
  C: (f, a) => f(...a)
3171
3224
  });
3172
- 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);
3173
- (0, import_invariant10.invariant)(credentials[0].credential, void 0, {
3174
- F: __dxlog_file12,
3175
- L: 101,
3176
- S: this,
3177
- A: [
3178
- "credentials[0].credential",
3179
- ""
3180
- ]
3181
- });
3182
- const spaceMemberCredential = credentials[0].credential.credential;
3183
- (0, import_invariant10.invariant)((0, import_credentials9.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3184
- F: __dxlog_file12,
3185
- L: 103,
3186
- S: this,
3187
- A: [
3188
- "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
3189
- ""
3190
- ]
3225
+ const spaceMemberCredential = await this._spaceManager.admitMember({
3226
+ spaceKey: this._spaceKey,
3227
+ identityKey: request.space.identityKey,
3228
+ role: invitation.role ?? import_credentials10.SpaceMember.Role.ADMIN,
3229
+ profile: guestProfile,
3230
+ delegationCredentialId: invitation.delegationCredentialId
3191
3231
  });
3192
- await (0, import_feed_store3.writeMessages)(space.inner.controlPipeline.writer, credentials);
3232
+ const space = this._spaceManager.spaces.get(this._spaceKey);
3193
3233
  return {
3194
3234
  space: {
3195
3235
  credential: spaceMemberCredential,
3196
- controlTimeframe: space.inner.controlPipeline.state.timeframe
3236
+ controlTimeframe: space?.inner.controlPipeline.state.timeframe
3197
3237
  }
3198
3238
  };
3199
3239
  }
3200
3240
  async delegate(invitation) {
3201
3241
  (0, import_invariant10.invariant)(this._spaceKey, void 0, {
3202
- F: __dxlog_file12,
3203
- L: 116,
3242
+ F: __dxlog_file13,
3243
+ L: 95,
3204
3244
  S: this,
3205
3245
  A: [
3206
3246
  "this._spaceKey",
@@ -3209,8 +3249,8 @@ var SpaceInvitationProtocol = class {
3209
3249
  });
3210
3250
  const space = this._spaceManager.spaces.get(this._spaceKey);
3211
3251
  (0, import_invariant10.invariant)(space, void 0, {
3212
- F: __dxlog_file12,
3213
- L: 118,
3252
+ F: __dxlog_file13,
3253
+ L: 97,
3214
3254
  S: this,
3215
3255
  A: [
3216
3256
  "space",
@@ -3219,8 +3259,8 @@ var SpaceInvitationProtocol = class {
3219
3259
  });
3220
3260
  if (invitation.authMethod === import_services10.Invitation.AuthMethod.KNOWN_PUBLIC_KEY) {
3221
3261
  (0, import_invariant10.invariant)(invitation.guestKeypair?.publicKey, void 0, {
3222
- F: __dxlog_file12,
3223
- L: 120,
3262
+ F: __dxlog_file13,
3263
+ L: 99,
3224
3264
  S: this,
3225
3265
  A: [
3226
3266
  "invitation.guestKeypair?.publicKey",
@@ -3228,12 +3268,12 @@ var SpaceInvitationProtocol = class {
3228
3268
  ]
3229
3269
  });
3230
3270
  }
3231
- (0, import_log9.log)("writing delegate space invitation", {
3271
+ (0, import_log10.log)("writing delegate space invitation", {
3232
3272
  host: this._signingContext.deviceKey,
3233
3273
  id: invitation.invitationId
3234
3274
  }, {
3235
- F: __dxlog_file12,
3236
- L: 123,
3275
+ F: __dxlog_file13,
3276
+ L: 102,
3237
3277
  S: this,
3238
3278
  C: (f, a) => f(...a)
3239
3279
  });
@@ -3247,8 +3287,8 @@ var SpaceInvitationProtocol = class {
3247
3287
  guestKey: invitation.authMethod === import_services10.Invitation.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
3248
3288
  });
3249
3289
  (0, import_invariant10.invariant)(credential.credential, void 0, {
3250
- F: __dxlog_file12,
3251
- L: 143,
3290
+ F: __dxlog_file13,
3291
+ L: 122,
3252
3292
  S: this,
3253
3293
  A: [
3254
3294
  "credential.credential",
@@ -3262,8 +3302,8 @@ var SpaceInvitationProtocol = class {
3262
3302
  }
3263
3303
  async cancelDelegation(invitation) {
3264
3304
  (0, import_invariant10.invariant)(this._spaceKey, void 0, {
3265
- F: __dxlog_file12,
3266
- L: 149,
3305
+ F: __dxlog_file13,
3306
+ L: 128,
3267
3307
  S: this,
3268
3308
  A: [
3269
3309
  "this._spaceKey",
@@ -3271,8 +3311,8 @@ var SpaceInvitationProtocol = class {
3271
3311
  ]
3272
3312
  });
3273
3313
  (0, import_invariant10.invariant)(invitation.type === import_services10.Invitation.Type.DELEGATED && invitation.delegationCredentialId, void 0, {
3274
- F: __dxlog_file12,
3275
- L: 150,
3314
+ F: __dxlog_file13,
3315
+ L: 129,
3276
3316
  S: this,
3277
3317
  A: [
3278
3318
  "invitation.type === Invitation.Type.DELEGATED && invitation.delegationCredentialId",
@@ -3281,27 +3321,27 @@ var SpaceInvitationProtocol = class {
3281
3321
  });
3282
3322
  const space = this._spaceManager.spaces.get(this._spaceKey);
3283
3323
  (0, import_invariant10.invariant)(space, void 0, {
3284
- F: __dxlog_file12,
3285
- L: 152,
3324
+ F: __dxlog_file13,
3325
+ L: 131,
3286
3326
  S: this,
3287
3327
  A: [
3288
3328
  "space",
3289
3329
  ""
3290
3330
  ]
3291
3331
  });
3292
- (0, import_log9.log)("cancelling delegated space invitation", {
3332
+ (0, import_log10.log)("cancelling delegated space invitation", {
3293
3333
  host: this._signingContext.deviceKey,
3294
3334
  id: invitation.invitationId
3295
3335
  }, {
3296
- F: __dxlog_file12,
3297
- L: 154,
3336
+ F: __dxlog_file13,
3337
+ L: 133,
3298
3338
  S: this,
3299
3339
  C: (f, a) => f(...a)
3300
3340
  });
3301
3341
  const credential = await (0, import_credentials9.createCancelDelegatedSpaceInvitationCredential)(this._signingContext.credentialSigner, space.key, invitation.delegationCredentialId);
3302
3342
  (0, import_invariant10.invariant)(credential.credential, void 0, {
3303
- F: __dxlog_file12,
3304
- L: 161,
3343
+ F: __dxlog_file13,
3344
+ L: 140,
3305
3345
  S: this,
3306
3346
  A: [
3307
3347
  "credential.credential",
@@ -3339,8 +3379,8 @@ var SpaceInvitationProtocol = class {
3339
3379
  }
3340
3380
  async accept(response) {
3341
3381
  (0, import_invariant10.invariant)(response.space, void 0, {
3342
- F: __dxlog_file12,
3343
- L: 196,
3382
+ F: __dxlog_file13,
3383
+ L: 175,
3344
3384
  S: this,
3345
3385
  A: [
3346
3386
  "response.space",
@@ -3350,8 +3390,8 @@ var SpaceInvitationProtocol = class {
3350
3390
  const { credential, controlTimeframe, dataTimeframe } = response.space;
3351
3391
  const assertion = (0, import_credentials9.getCredentialAssertion)(credential);
3352
3392
  (0, import_invariant10.invariant)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
3353
- F: __dxlog_file12,
3354
- L: 199,
3393
+ F: __dxlog_file13,
3394
+ L: 178,
3355
3395
  S: this,
3356
3396
  A: [
3357
3397
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -3359,8 +3399,8 @@ var SpaceInvitationProtocol = class {
3359
3399
  ]
3360
3400
  });
3361
3401
  (0, import_invariant10.invariant)(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
3362
- F: __dxlog_file12,
3363
- L: 200,
3402
+ F: __dxlog_file13,
3403
+ L: 179,
3364
3404
  S: this,
3365
3405
  A: [
3366
3406
  "credential.subject.id.equals(this._signingContext.identityKey)",
@@ -3382,7 +3422,7 @@ var SpaceInvitationProtocol = class {
3382
3422
  };
3383
3423
  }
3384
3424
  };
3385
- var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
3425
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
3386
3426
  var InvitationsManager = class {
3387
3427
  constructor(_invitationsHandler, _getHandler, _metadataStore) {
3388
3428
  this._invitationsHandler = _invitationsHandler;
@@ -3390,12 +3430,12 @@ var InvitationsManager = class {
3390
3430
  this._metadataStore = _metadataStore;
3391
3431
  this._createInvitations = /* @__PURE__ */ new Map();
3392
3432
  this._acceptInvitations = /* @__PURE__ */ new Map();
3393
- this.invitationCreated = new import_async11.Event();
3394
- this.invitationAccepted = new import_async11.Event();
3395
- this.removedCreated = new import_async11.Event();
3396
- this.removedAccepted = new import_async11.Event();
3397
- this.saved = new import_async11.Event();
3398
- this._persistentInvitationsLoadedEvent = new import_async11.Event();
3433
+ this.invitationCreated = new import_async12.Event();
3434
+ this.invitationAccepted = new import_async12.Event();
3435
+ this.removedCreated = new import_async12.Event();
3436
+ this.removedAccepted = new import_async12.Event();
3437
+ this.saved = new import_async12.Event();
3438
+ this._persistentInvitationsLoadedEvent = new import_async12.Event();
3399
3439
  this._persistentInvitationsLoaded = false;
3400
3440
  }
3401
3441
  async createInvitation(options) {
@@ -3424,8 +3464,8 @@ var InvitationsManager = class {
3424
3464
  try {
3425
3465
  await this._persistIfRequired(handler, stream, invitation);
3426
3466
  } catch (err) {
3427
- import_log10.log.catch(err, void 0, {
3428
- F: __dxlog_file13,
3467
+ import_log11.log.catch(err, void 0, {
3468
+ F: __dxlog_file14,
3429
3469
  L: 82,
3430
3470
  S: this,
3431
3471
  C: (f, a) => f(...a)
@@ -3448,7 +3488,7 @@ var InvitationsManager = class {
3448
3488
  const freshInvitations = persistentInvitations.filter((invitation) => !(0, import_echo_pipeline.hasInvitationExpired)(invitation));
3449
3489
  const loadTasks = freshInvitations.map((persistentInvitation) => {
3450
3490
  (0, import_invariant11.invariant)(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
3451
- F: __dxlog_file13,
3491
+ F: __dxlog_file14,
3452
3492
  L: 103,
3453
3493
  S: this,
3454
3494
  A: [
@@ -3466,8 +3506,8 @@ var InvitationsManager = class {
3466
3506
  invitations: cInvitations.map((invitation) => invitation.get())
3467
3507
  };
3468
3508
  } catch (err) {
3469
- import_log10.log.catch(err, void 0, {
3470
- F: __dxlog_file13,
3509
+ import_log11.log.catch(err, void 0, {
3510
+ F: __dxlog_file14,
3471
3511
  L: 110,
3472
3512
  S: this,
3473
3513
  C: (f, a) => f(...a)
@@ -3498,14 +3538,14 @@ var InvitationsManager = class {
3498
3538
  return invitation;
3499
3539
  }
3500
3540
  async authenticate({ invitationId, authCode }) {
3501
- (0, import_log10.log)("authenticating...", void 0, {
3502
- F: __dxlog_file13,
3541
+ (0, import_log11.log)("authenticating...", void 0, {
3542
+ F: __dxlog_file14,
3503
3543
  L: 140,
3504
3544
  S: this,
3505
3545
  C: (f, a) => f(...a)
3506
3546
  });
3507
3547
  (0, import_invariant11.invariant)(invitationId, void 0, {
3508
- F: __dxlog_file13,
3548
+ F: __dxlog_file14,
3509
3549
  L: 141,
3510
3550
  S: this,
3511
3551
  A: [
@@ -3515,10 +3555,10 @@ var InvitationsManager = class {
3515
3555
  });
3516
3556
  const observable = this._acceptInvitations.get(invitationId);
3517
3557
  if (!observable) {
3518
- import_log10.log.warn("invalid invitation", {
3558
+ import_log11.log.warn("invalid invitation", {
3519
3559
  invitationId
3520
3560
  }, {
3521
- F: __dxlog_file13,
3561
+ F: __dxlog_file14,
3522
3562
  L: 144,
3523
3563
  S: this,
3524
3564
  C: (f, a) => f(...a)
@@ -3528,16 +3568,16 @@ var InvitationsManager = class {
3528
3568
  }
3529
3569
  }
3530
3570
  async cancelInvitation({ invitationId }) {
3531
- (0, import_log10.log)("cancelInvitation...", {
3571
+ (0, import_log11.log)("cancelInvitation...", {
3532
3572
  invitationId
3533
3573
  }, {
3534
- F: __dxlog_file13,
3574
+ F: __dxlog_file14,
3535
3575
  L: 151,
3536
3576
  S: this,
3537
3577
  C: (f, a) => f(...a)
3538
3578
  });
3539
3579
  (0, import_invariant11.invariant)(invitationId, void 0, {
3540
- F: __dxlog_file13,
3580
+ F: __dxlog_file14,
3541
3581
  L: 152,
3542
3582
  S: this,
3543
3583
  A: [
@@ -3605,18 +3645,21 @@ var InvitationsManager = class {
3605
3645
  };
3606
3646
  }
3607
3647
  _createObservableInvitation(handler, invitation) {
3608
- const stream = new import_async11.PushStream();
3648
+ const stream = new import_async12.PushStream();
3609
3649
  const ctx = new import_context9.Context({
3610
3650
  onError: (err) => {
3611
3651
  stream.error(err);
3612
3652
  void ctx.dispose();
3613
3653
  }
3654
+ }, {
3655
+ F: __dxlog_file14,
3656
+ L: 234
3614
3657
  });
3615
3658
  ctx.onDispose(() => {
3616
- (0, import_log10.log)("complete", {
3659
+ (0, import_log11.log)("complete", {
3617
3660
  ...handler.toJSON()
3618
3661
  }, {
3619
- F: __dxlog_file13,
3662
+ F: __dxlog_file14,
3620
3663
  L: 241,
3621
3664
  S: this,
3622
3665
  C: (f, a) => f(...a)
@@ -3641,15 +3684,15 @@ var InvitationsManager = class {
3641
3684
  };
3642
3685
  }
3643
3686
  _createObservableAcceptingInvitation(handler, initialState) {
3644
- const otpEnteredTrigger = new import_async11.Trigger();
3645
- const stream = new import_async11.PushStream();
3687
+ const otpEnteredTrigger = new import_async12.Trigger();
3688
+ const stream = new import_async12.PushStream();
3646
3689
  const ctx = new import_context9.Context({
3647
3690
  onError: (err) => {
3648
- if (err instanceof import_async11.TimeoutError) {
3649
- (0, import_log10.log)("timeout", {
3691
+ if (err instanceof import_async12.TimeoutError) {
3692
+ (0, import_log11.log)("timeout", {
3650
3693
  ...handler.toJSON()
3651
3694
  }, {
3652
- F: __dxlog_file13,
3695
+ F: __dxlog_file14,
3653
3696
  L: 261,
3654
3697
  S: this,
3655
3698
  C: (f, a) => f(...a)
@@ -3659,8 +3702,8 @@ var InvitationsManager = class {
3659
3702
  state: import_services11.Invitation.State.TIMEOUT
3660
3703
  });
3661
3704
  } else {
3662
- import_log10.log.warn("auth failed", err, {
3663
- F: __dxlog_file13,
3705
+ import_log11.log.warn("auth failed", err, {
3706
+ F: __dxlog_file14,
3664
3707
  L: 264,
3665
3708
  S: this,
3666
3709
  C: (f, a) => f(...a)
@@ -3672,12 +3715,15 @@ var InvitationsManager = class {
3672
3715
  }
3673
3716
  void ctx.dispose();
3674
3717
  }
3718
+ }, {
3719
+ F: __dxlog_file14,
3720
+ L: 258
3675
3721
  });
3676
3722
  ctx.onDispose(() => {
3677
- (0, import_log10.log)("complete", {
3723
+ (0, import_log11.log)("complete", {
3678
3724
  ...handler.toJSON()
3679
3725
  }, {
3680
- F: __dxlog_file13,
3726
+ F: __dxlog_file14,
3681
3727
  L: 271,
3682
3728
  S: this,
3683
3729
  C: (f, a) => f(...a)
@@ -3721,8 +3767,8 @@ var InvitationsManager = class {
3721
3767
  try {
3722
3768
  await this._metadataStore.removeInvitation(invitation.invitationId);
3723
3769
  } catch (err) {
3724
- import_log10.log.catch(err, void 0, {
3725
- F: __dxlog_file13,
3770
+ import_log11.log.catch(err, void 0, {
3771
+ F: __dxlog_file14,
3726
3772
  L: 307,
3727
3773
  S: this,
3728
3774
  C: (f, a) => f(...a)
@@ -3741,7 +3787,7 @@ var AutomergeSpaceState = class extends import_context11.Resource {
3741
3787
  this._onNewRoot = _onNewRoot;
3742
3788
  this.rootUrl = void 0;
3743
3789
  this.lastEpoch = void 0;
3744
- this.onNewEpoch = new import_async13.Event();
3790
+ this.onNewEpoch = new import_async14.Event();
3745
3791
  this._isProcessingRootDocs = false;
3746
3792
  }
3747
3793
  async _open(ctx) {
@@ -3775,12 +3821,13 @@ var AutomergeSpaceState = class extends import_context11.Resource {
3775
3821
  await this.onNewEpoch.waitForCondition(() => !!this.lastEpoch);
3776
3822
  }
3777
3823
  };
3778
- var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts";
3824
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts";
3825
+ var LOAD_DOC_TIMEOUT = 1e4;
3779
3826
  var runEpochMigration = async (ctx, context) => {
3780
3827
  switch (context.migration) {
3781
3828
  case import_services13.CreateEpochRequest.Migration.INIT_AUTOMERGE: {
3782
- const document = context.repo.create();
3783
- await context.repo.flush();
3829
+ const document = context.echoHost.createDoc();
3830
+ await context.echoHost.flush();
3784
3831
  return {
3785
3832
  newRoot: document.url
3786
3833
  };
@@ -3789,77 +3836,88 @@ var runEpochMigration = async (ctx, context) => {
3789
3836
  if (!context.currentRoot) {
3790
3837
  throw new Error("Space does not have an automerge root");
3791
3838
  }
3792
- const rootHandle = context.repo.find(context.currentRoot);
3793
- await (0, import_context12.cancelWithContext)(ctx, (0, import_async14.asyncTimeout)(rootHandle.whenReady(), 1e4));
3794
- const newRoot = context.repo.create(rootHandle.docSync());
3795
- await context.repo.flush();
3839
+ const rootHandle = await context.echoHost.loadDoc(ctx, context.currentRoot, {
3840
+ timeout: LOAD_DOC_TIMEOUT
3841
+ });
3842
+ const newRoot = context.echoHost.createDoc(rootHandle.docSync());
3843
+ await context.echoHost.flush();
3796
3844
  return {
3797
3845
  newRoot: newRoot.url
3798
3846
  };
3799
3847
  }
3800
3848
  case import_services13.CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT: {
3801
- import_log12.log.info("Fragmenting", void 0, {
3802
- F: __dxlog_file14,
3803
- L: 63,
3849
+ import_log13.log.info("Fragmenting", void 0, {
3850
+ F: __dxlog_file15,
3851
+ L: 64,
3804
3852
  S: void 0,
3805
3853
  C: (f, a) => f(...a)
3806
3854
  });
3807
3855
  const currentRootUrl = context.currentRoot;
3808
- const rootHandle = context.repo.find(currentRootUrl);
3809
- await (0, import_context12.cancelWithContext)(ctx, (0, import_async14.asyncTimeout)(rootHandle.whenReady(), 1e4));
3856
+ const rootHandle = await context.echoHost.loadDoc(ctx, currentRootUrl, {
3857
+ timeout: LOAD_DOC_TIMEOUT
3858
+ });
3810
3859
  const objects = Object.entries(rootHandle.docSync().objects);
3811
3860
  const properties = (0, import_echo_db.findInlineObjectOfType)(rootHandle.docSync(), import_echo_schema.TYPE_PROPERTIES);
3812
3861
  const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
3813
3862
  (0, import_invariant13.invariant)(properties, "Properties not found", {
3814
- F: __dxlog_file14,
3815
- L: 73,
3863
+ F: __dxlog_file15,
3864
+ L: 75,
3816
3865
  S: void 0,
3817
3866
  A: [
3818
3867
  "properties",
3819
3868
  "'Properties not found'"
3820
3869
  ]
3821
3870
  });
3822
- const newSpaceDoc = {
3871
+ const newRoot = context.echoHost.createDoc({
3823
3872
  ...rootHandle.docSync(),
3824
3873
  objects: Object.fromEntries([
3825
3874
  properties
3826
3875
  ])
3827
- };
3828
- const newRoot = context.repo.create(newSpaceDoc);
3876
+ });
3829
3877
  (0, import_invariant13.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3830
- F: __dxlog_file14,
3831
- L: 78,
3878
+ F: __dxlog_file15,
3879
+ L: 82,
3832
3880
  S: void 0,
3833
3881
  A: [
3834
3882
  "typeof newRoot.url === 'string' && newRoot.url.length > 0",
3835
3883
  ""
3836
3884
  ]
3837
3885
  });
3838
- const docLoader = new import_echo_pipeline3.AutomergeDocumentLoaderImpl(context.spaceId, context.repo, context.spaceKey);
3839
- await docLoader.loadSpaceRootDocHandle(ctx, {
3840
- rootUrl: newRoot.url
3841
- });
3842
- otherObjects.forEach(([key, value]) => {
3843
- const handle = docLoader.createDocumentForObject(key);
3844
- handle.change((doc) => {
3845
- (0, import_util7.assignDeep)(doc, [
3846
- "objects",
3847
- key
3848
- ], value);
3886
+ const newLinks = [];
3887
+ for (const [id, objData] of otherObjects) {
3888
+ const handle = context.echoHost.createDoc({
3889
+ version: import_echo_protocol2.SpaceDocVersion.CURRENT,
3890
+ access: {
3891
+ spaceKey: context.spaceKey.toHex()
3892
+ },
3893
+ objects: {
3894
+ [id]: objData
3895
+ }
3849
3896
  });
3897
+ newLinks.push([
3898
+ id,
3899
+ handle.url
3900
+ ]);
3901
+ }
3902
+ newRoot.change((doc) => {
3903
+ doc.links ??= {};
3904
+ for (const [id, url] of newLinks) {
3905
+ doc.links[id] = url;
3906
+ }
3850
3907
  });
3851
- await context.repo.flush();
3908
+ await context.echoHost.flush();
3852
3909
  return {
3853
3910
  newRoot: newRoot.url
3854
3911
  };
3855
3912
  }
3856
3913
  case import_services13.CreateEpochRequest.Migration.MIGRATE_REFERENCES_TO_DXN: {
3857
3914
  const currentRootUrl = context.currentRoot;
3858
- const rootHandle = context.repo.find(currentRootUrl);
3859
- await (0, import_context12.cancelWithContext)(ctx, (0, import_async14.asyncTimeout)(rootHandle.whenReady(), 1e4));
3915
+ const rootHandle = await context.echoHost.loadDoc(ctx, currentRootUrl, {
3916
+ timeout: LOAD_DOC_TIMEOUT
3917
+ });
3860
3918
  (0, import_invariant13.invariant)(rootHandle.docSync(), "Root doc not found", {
3861
- F: __dxlog_file14,
3862
- L: 100,
3919
+ F: __dxlog_file15,
3920
+ L: 115,
3863
3921
  S: void 0,
3864
3922
  A: [
3865
3923
  "rootHandle.docSync()",
@@ -3868,40 +3926,59 @@ var runEpochMigration = async (ctx, context) => {
3868
3926
  });
3869
3927
  const newRootContent = await (0, import_echo_db.convertLegacySpaceRootDoc)(structuredClone(rootHandle.docSync()));
3870
3928
  for (const [id, url] of Object.entries(newRootContent.links ?? {})) {
3871
- const handle = context.repo.find(url);
3872
- await (0, import_context12.cancelWithContext)(ctx, (0, import_async14.asyncTimeout)(handle.whenReady(), 1e4));
3873
- (0, import_invariant13.invariant)(handle.docSync(), "Doc not found", {
3874
- F: __dxlog_file14,
3875
- L: 107,
3876
- S: void 0,
3877
- A: [
3878
- "handle.docSync()",
3879
- "'Doc not found'"
3880
- ]
3881
- });
3882
- const newDoc = await (0, import_echo_db.convertLegacyReferences)(structuredClone(handle.docSync()));
3883
- const migratedDoc = (0, import_echo_db.migrateDocument)(handle.docSync(), newDoc);
3884
- const newHandle = context.repo.import(import_automerge.next.save(migratedDoc));
3885
- newRootContent.links[id] = newHandle.url;
3929
+ try {
3930
+ const handle = await context.echoHost.loadDoc(ctx, url, {
3931
+ timeout: LOAD_DOC_TIMEOUT
3932
+ });
3933
+ (0, import_invariant13.invariant)(handle.docSync(), void 0, {
3934
+ F: __dxlog_file15,
3935
+ L: 122,
3936
+ S: void 0,
3937
+ A: [
3938
+ "handle.docSync()",
3939
+ ""
3940
+ ]
3941
+ });
3942
+ const newDoc = await (0, import_echo_db.convertLegacyReferences)(structuredClone(handle.docSync()));
3943
+ const migratedDoc = (0, import_echo_db.migrateDocument)(handle.docSync(), newDoc);
3944
+ const newHandle = context.echoHost.createDoc(migratedDoc, {
3945
+ preserveHistory: true
3946
+ });
3947
+ newRootContent.links[id] = newHandle.url;
3948
+ } catch (err) {
3949
+ import_log13.log.warn("Failed to migrate reference", {
3950
+ id,
3951
+ url,
3952
+ error: err
3953
+ }, {
3954
+ F: __dxlog_file15,
3955
+ L: 128,
3956
+ S: void 0,
3957
+ C: (f, a) => f(...a)
3958
+ });
3959
+ delete newRootContent.links[id];
3960
+ }
3886
3961
  }
3887
3962
  const migratedRoot = (0, import_echo_db.migrateDocument)(rootHandle.docSync(), newRootContent);
3888
- const newRoot = context.repo.import(import_automerge.next.save(migratedRoot));
3889
- await context.repo.flush();
3963
+ const newRoot = context.echoHost.createDoc(migratedRoot, {
3964
+ preserveHistory: true
3965
+ });
3966
+ await context.echoHost.flush();
3890
3967
  return {
3891
3968
  newRoot: newRoot.url
3892
3969
  };
3893
3970
  }
3894
3971
  case import_services13.CreateEpochRequest.Migration.REPLACE_AUTOMERGE_ROOT: {
3895
3972
  (0, import_invariant13.invariant)(context.newAutomergeRoot, void 0, {
3896
- F: __dxlog_file14,
3897
- L: 124,
3973
+ F: __dxlog_file15,
3974
+ L: 143,
3898
3975
  S: void 0,
3899
3976
  A: [
3900
3977
  "context.newAutomergeRoot",
3901
3978
  ""
3902
3979
  ]
3903
3980
  });
3904
- await context.repo.flush();
3981
+ await context.echoHost.flush();
3905
3982
  return {
3906
3983
  newRoot: context.newAutomergeRoot
3907
3984
  };
@@ -3909,14 +3986,17 @@ var runEpochMigration = async (ctx, context) => {
3909
3986
  }
3910
3987
  return {};
3911
3988
  };
3912
- var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
3989
+ var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
3913
3990
  var DEFAULT_RETRY_TIMEOUT = 1e3;
3914
3991
  var DEFAULT_SUCCESS_DELAY = 1e3;
3915
3992
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
3916
3993
  var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
3917
3994
  var NotarizationPlugin = class {
3918
3995
  constructor() {
3919
- this._ctx = new import_context13.Context();
3996
+ this._ctx = new import_context12.Context(void 0, {
3997
+ F: __dxlog_file16,
3998
+ L: 62
3999
+ });
3920
4000
  this._extensionOpened = new import_async15.Event();
3921
4001
  this._extensions = /* @__PURE__ */ new Set();
3922
4002
  this._processedCredentials = new import_util8.ComplexSet(import_keys11.PublicKey.hash);
@@ -3934,16 +4014,16 @@ var NotarizationPlugin = class {
3934
4014
  * Request credentials to be notarized.
3935
4015
  */
3936
4016
  async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
3937
- (0, import_log13.log)("notarize", {
4017
+ (0, import_log14.log)("notarize", {
3938
4018
  credentials
3939
4019
  }, {
3940
- F: __dxlog_file15,
4020
+ F: __dxlog_file16,
3941
4021
  L: 90,
3942
4022
  S: this,
3943
4023
  C: (f, a) => f(...a)
3944
4024
  });
3945
4025
  (0, import_invariant14.invariant)(credentials.every((credential) => credential.id), "Credentials must have an id", {
3946
- F: __dxlog_file15,
4026
+ F: __dxlog_file16,
3947
4027
  L: 91,
3948
4028
  S: this,
3949
4029
  A: [
@@ -3954,10 +4034,10 @@ var NotarizationPlugin = class {
3954
4034
  const errors = new import_async15.Trigger();
3955
4035
  const ctx = this._ctx.derive({
3956
4036
  onError: (err) => {
3957
- import_log13.log.warn("Notarization error", {
4037
+ import_log14.log.warn("Notarization error", {
3958
4038
  err
3959
4039
  }, {
3960
- F: __dxlog_file15,
4040
+ F: __dxlog_file16,
3961
4041
  L: 99,
3962
4042
  S: this,
3963
4043
  C: (f, a) => f(...a)
@@ -3969,11 +4049,11 @@ var NotarizationPlugin = class {
3969
4049
  opCtx?.onDispose(() => ctx.dispose());
3970
4050
  if (timeout !== 0) {
3971
4051
  (0, import_async15.scheduleTask)(ctx, () => {
3972
- import_log13.log.warn("Notarization timeout", {
4052
+ import_log14.log.warn("Notarization timeout", {
3973
4053
  timeout,
3974
4054
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
3975
4055
  }, {
3976
- F: __dxlog_file15,
4056
+ F: __dxlog_file16,
3977
4057
  L: 111,
3978
4058
  S: this,
3979
4059
  C: (f, a) => f(...a)
@@ -3993,10 +4073,10 @@ var NotarizationPlugin = class {
3993
4073
  ...this._extensions
3994
4074
  ].find((peer2) => !peersTried.has(peer2));
3995
4075
  if (!peer) {
3996
- import_log13.log.info("Exhausted all peers to notarize with", {
4076
+ import_log14.log.info("Exhausted all peers to notarize with", {
3997
4077
  retryIn: retryTimeout
3998
4078
  }, {
3999
- F: __dxlog_file15,
4079
+ F: __dxlog_file16,
4000
4080
  L: 136,
4001
4081
  S: this,
4002
4082
  C: (f, a) => f(...a)
@@ -4006,11 +4086,11 @@ var NotarizationPlugin = class {
4006
4086
  return;
4007
4087
  }
4008
4088
  peersTried.add(peer);
4009
- (0, import_log13.log)("try notarizing", {
4089
+ (0, import_log14.log)("try notarizing", {
4010
4090
  peer: peer.localPeerId,
4011
4091
  credentialId: credentials.map((credential) => credential.id)
4012
4092
  }, {
4013
- F: __dxlog_file15,
4093
+ F: __dxlog_file16,
4014
4094
  L: 143,
4015
4095
  S: this,
4016
4096
  C: (f, a) => f(...a)
@@ -4018,8 +4098,8 @@ var NotarizationPlugin = class {
4018
4098
  await peer.rpc.NotarizationService.notarize({
4019
4099
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
4020
4100
  });
4021
- (0, import_log13.log)("success", void 0, {
4022
- F: __dxlog_file15,
4101
+ (0, import_log14.log)("success", void 0, {
4102
+ F: __dxlog_file16,
4023
4103
  L: 147,
4024
4104
  S: this,
4025
4105
  C: (f, a) => f(...a)
@@ -4027,8 +4107,8 @@ var NotarizationPlugin = class {
4027
4107
  await (0, import_async15.sleep)(successDelay);
4028
4108
  } catch (err) {
4029
4109
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
4030
- import_log13.log.info("error notarizing (recoverable)", err, {
4031
- F: __dxlog_file15,
4110
+ import_log14.log.info("error notarizing (recoverable)", err, {
4111
+ F: __dxlog_file16,
4032
4112
  L: 151,
4033
4113
  S: this,
4034
4114
  C: (f, a) => f(...a)
@@ -4041,12 +4121,12 @@ var NotarizationPlugin = class {
4041
4121
  this._extensionOpened.on(ctx, () => notarizeTask.schedule());
4042
4122
  try {
4043
4123
  await Promise.race([
4044
- (0, import_context13.rejectOnDispose)(ctx),
4124
+ (0, import_context12.rejectOnDispose)(ctx),
4045
4125
  allNotarized,
4046
4126
  errors.wait()
4047
4127
  ]);
4048
- (0, import_log13.log)("done", void 0, {
4049
- F: __dxlog_file15,
4128
+ (0, import_log14.log)("done", void 0, {
4129
+ F: __dxlog_file16,
4050
4130
  L: 162,
4051
4131
  S: this,
4052
4132
  C: (f, a) => f(...a)
@@ -4068,7 +4148,7 @@ var NotarizationPlugin = class {
4068
4148
  }
4069
4149
  setWriter(writer) {
4070
4150
  (0, import_invariant14.invariant)(!this._writer, "Writer already set.", {
4071
- F: __dxlog_file15,
4151
+ F: __dxlog_file16,
4072
4152
  L: 181,
4073
4153
  S: this,
4074
4154
  A: [
@@ -4093,7 +4173,7 @@ var NotarizationPlugin = class {
4093
4173
  }
4094
4174
  for (const credential of request.credentials ?? []) {
4095
4175
  (0, import_invariant14.invariant)(credential.id, "Credential must have an id", {
4096
- F: __dxlog_file15,
4176
+ F: __dxlog_file16,
4097
4177
  L: 200,
4098
4178
  S: this,
4099
4179
  A: [
@@ -4110,10 +4190,10 @@ var NotarizationPlugin = class {
4110
4190
  createExtension() {
4111
4191
  const extension = new NotarizationTeleportExtension({
4112
4192
  onOpen: async () => {
4113
- (0, import_log13.log)("extension opened", {
4193
+ (0, import_log14.log)("extension opened", {
4114
4194
  peer: extension.localPeerId
4115
4195
  }, {
4116
- F: __dxlog_file15,
4196
+ F: __dxlog_file16,
4117
4197
  L: 211,
4118
4198
  S: this,
4119
4199
  C: (f, a) => f(...a)
@@ -4122,10 +4202,10 @@ var NotarizationPlugin = class {
4122
4202
  this._extensionOpened.emit();
4123
4203
  },
4124
4204
  onClose: async () => {
4125
- (0, import_log13.log)("extension closed", {
4205
+ (0, import_log14.log)("extension closed", {
4126
4206
  peer: extension.localPeerId
4127
4207
  }, {
4128
- F: __dxlog_file15,
4208
+ F: __dxlog_file16,
4129
4209
  L: 216,
4130
4210
  S: this,
4131
4211
  C: (f, a) => f(...a)
@@ -4240,18 +4320,21 @@ function _using_ctx() {
4240
4320
  }
4241
4321
  };
4242
4322
  }
4243
- var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
4323
+ var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
4244
4324
  var DataSpace = class {
4245
4325
  constructor(params) {
4246
- this._ctx = new import_context10.Context();
4326
+ this._ctx = new import_context10.Context(void 0, {
4327
+ F: __dxlog_file17,
4328
+ L: 84
4329
+ });
4247
4330
  this._notarizationPlugin = new NotarizationPlugin();
4248
4331
  this._cache = void 0;
4249
4332
  this._automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
4250
- this._epochProcessingMutex = new import_async12.Mutex();
4333
+ this._epochProcessingMutex = new import_async13.Mutex();
4251
4334
  this._state = import_services12.SpaceState.CLOSED;
4252
4335
  this._databaseRoot = null;
4253
4336
  this.error = void 0;
4254
- this.stateUpdate = new import_async12.Event();
4337
+ this.stateUpdate = new import_async13.Event();
4255
4338
  this.metrics = {};
4256
4339
  this._inner = params.inner;
4257
4340
  this._inner.stateUpdate.on(this._ctx, () => this.stateUpdate.emit());
@@ -4264,16 +4347,16 @@ var DataSpace = class {
4264
4347
  this._callbacks = params.callbacks ?? {};
4265
4348
  this._echoHost = params.echoHost;
4266
4349
  this.authVerifier = new TrustedKeySetAuthVerifier({
4267
- 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)),
4350
+ 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)),
4268
4351
  update: this._inner.stateUpdate,
4269
4352
  authTimeout: import_client_protocol4.AUTH_TIMEOUT
4270
4353
  });
4271
4354
  this._cache = params.cache;
4272
4355
  this._state = params.initialState;
4273
- (0, import_log11.log)("new state", {
4356
+ (0, import_log12.log)("new state", {
4274
4357
  state: import_services12.SpaceState[this._state]
4275
4358
  }, {
4276
- F: __dxlog_file16,
4359
+ F: __dxlog_file17,
4277
4360
  L: 146,
4278
4361
  S: this,
4279
4362
  C: (f, a) => f(...a)
@@ -4328,12 +4411,15 @@ var DataSpace = class {
4328
4411
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
4329
4412
  await this._automergeSpaceState.open();
4330
4413
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
4331
- await this._inner.open(new import_context10.Context());
4414
+ await this._inner.open(new import_context10.Context(void 0, {
4415
+ F: __dxlog_file17,
4416
+ L: 215
4417
+ }));
4332
4418
  this._state = import_services12.SpaceState.CONTROL_ONLY;
4333
- (0, import_log11.log)("new state", {
4419
+ (0, import_log12.log)("new state", {
4334
4420
  state: import_services12.SpaceState[this._state]
4335
4421
  }, {
4336
- F: __dxlog_file16,
4422
+ F: __dxlog_file17,
4337
4423
  L: 217,
4338
4424
  S: this,
4339
4425
  C: (f, a) => f(...a)
@@ -4348,16 +4434,19 @@ var DataSpace = class {
4348
4434
  async _close() {
4349
4435
  await this._callbacks.beforeClose?.();
4350
4436
  this._state = import_services12.SpaceState.CLOSED;
4351
- (0, import_log11.log)("new state", {
4437
+ (0, import_log12.log)("new state", {
4352
4438
  state: import_services12.SpaceState[this._state]
4353
4439
  }, {
4354
- F: __dxlog_file16,
4440
+ F: __dxlog_file17,
4355
4441
  L: 231,
4356
4442
  S: this,
4357
4443
  C: (f, a) => f(...a)
4358
4444
  });
4359
4445
  await this._ctx.dispose();
4360
- this._ctx = new import_context10.Context();
4446
+ this._ctx = new import_context10.Context(void 0, {
4447
+ F: __dxlog_file17,
4448
+ L: 233
4449
+ });
4361
4450
  await this.authVerifier.close();
4362
4451
  await this._inner.close();
4363
4452
  await this._inner.spaceState.removeCredentialProcessor(this._automergeSpaceState);
@@ -4377,31 +4466,31 @@ var DataSpace = class {
4377
4466
  * Initialize the data pipeline in a separate task.
4378
4467
  */
4379
4468
  initializeDataPipelineAsync() {
4380
- (0, import_async12.scheduleTask)(this._ctx, async () => {
4469
+ (0, import_async13.scheduleTask)(this._ctx, async () => {
4381
4470
  try {
4382
4471
  this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
4383
4472
  await this.initializeDataPipeline();
4384
4473
  } catch (err) {
4385
4474
  if (err instanceof import_protocols9.CancelledError || err instanceof import_context10.ContextDisposedError) {
4386
- (0, import_log11.log)("data pipeline initialization cancelled", err, {
4387
- F: __dxlog_file16,
4475
+ (0, import_log12.log)("data pipeline initialization cancelled", err, {
4476
+ F: __dxlog_file17,
4388
4477
  L: 265,
4389
4478
  S: this,
4390
4479
  C: (f, a) => f(...a)
4391
4480
  });
4392
4481
  return;
4393
4482
  }
4394
- import_log11.log.error("Error initializing data pipeline", err, {
4395
- F: __dxlog_file16,
4483
+ import_log12.log.error("Error initializing data pipeline", err, {
4484
+ F: __dxlog_file17,
4396
4485
  L: 269,
4397
4486
  S: this,
4398
4487
  C: (f, a) => f(...a)
4399
4488
  });
4400
4489
  this._state = import_services12.SpaceState.ERROR;
4401
- (0, import_log11.log)("new state", {
4490
+ (0, import_log12.log)("new state", {
4402
4491
  state: import_services12.SpaceState[this._state]
4403
4492
  }, {
4404
- F: __dxlog_file16,
4493
+ F: __dxlog_file17,
4405
4494
  L: 271,
4406
4495
  S: this,
4407
4496
  C: (f, a) => f(...a)
@@ -4418,16 +4507,16 @@ var DataSpace = class {
4418
4507
  throw new import_protocols9.SystemError("Invalid operation");
4419
4508
  }
4420
4509
  this._state = import_services12.SpaceState.INITIALIZING;
4421
- (0, import_log11.log)("new state", {
4510
+ (0, import_log12.log)("new state", {
4422
4511
  state: import_services12.SpaceState[this._state]
4423
4512
  }, {
4424
- F: __dxlog_file16,
4513
+ F: __dxlog_file17,
4425
4514
  L: 287,
4426
4515
  S: this,
4427
4516
  C: (f, a) => f(...a)
4428
4517
  });
4429
4518
  await this._initializeAndReadControlPipeline();
4430
- await (0, import_async12.sleep)(1);
4519
+ await (0, import_async13.sleep)(1);
4431
4520
  const ready = this.stateUpdate.waitForCondition(() => this._state === import_services12.SpaceState.READY);
4432
4521
  this._automergeSpaceState.startProcessingRootDocs();
4433
4522
  await ready;
@@ -4435,10 +4524,10 @@ var DataSpace = class {
4435
4524
  async _enterReadyState() {
4436
4525
  await this._callbacks.beforeReady?.();
4437
4526
  this._state = import_services12.SpaceState.READY;
4438
- (0, import_log11.log)("new state", {
4527
+ (0, import_log12.log)("new state", {
4439
4528
  state: import_services12.SpaceState[this._state]
4440
4529
  }, {
4441
- F: __dxlog_file16,
4530
+ F: __dxlog_file17,
4442
4531
  L: 306,
4443
4532
  S: this,
4444
4533
  C: (f, a) => f(...a)
@@ -4453,8 +4542,8 @@ var DataSpace = class {
4453
4542
  });
4454
4543
  this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
4455
4544
  await this._createWritableFeeds();
4456
- (0, import_log11.log)("writable feeds created", void 0, {
4457
- F: __dxlog_file16,
4545
+ (0, import_log12.log)("writable feeds created", void 0, {
4546
+ F: __dxlog_file17,
4458
4547
  L: 322,
4459
4548
  S: this,
4460
4549
  C: (f, a) => f(...a)
@@ -4513,16 +4602,15 @@ var DataSpace = class {
4513
4602
  }
4514
4603
  }
4515
4604
  _onNewAutomergeRoot(rootUrl) {
4516
- (0, import_log11.log)("loading automerge root doc for space", {
4605
+ (0, import_log12.log)("loading automerge root doc for space", {
4517
4606
  space: this.key,
4518
4607
  rootUrl
4519
4608
  }, {
4520
- F: __dxlog_file16,
4609
+ F: __dxlog_file17,
4521
4610
  L: 388,
4522
4611
  S: this,
4523
4612
  C: (f, a) => f(...a)
4524
4613
  });
4525
- this._echoHost.replicateDocument(rootUrl);
4526
4614
  const handle = this._echoHost.automergeRepo.find(rootUrl);
4527
4615
  queueMicrotask(async () => {
4528
4616
  try {
@@ -4549,8 +4637,10 @@ var DataSpace = class {
4549
4637
  const root = await this._echoHost.openSpaceRoot(handle.url);
4550
4638
  this._databaseRoot = root;
4551
4639
  if (root.getVersion() !== import_echo_protocol.SpaceDocVersion.CURRENT) {
4552
- this._state = import_services12.SpaceState.REQUIRES_MIGRATION;
4553
- this.stateUpdate.emit();
4640
+ if (this._state !== import_services12.SpaceState.REQUIRES_MIGRATION) {
4641
+ this._state = import_services12.SpaceState.REQUIRES_MIGRATION;
4642
+ this.stateUpdate.emit();
4643
+ }
4554
4644
  } else {
4555
4645
  if (this._state !== import_services12.SpaceState.READY) {
4556
4646
  await this._enterReadyState();
@@ -4565,13 +4655,13 @@ var DataSpace = class {
4565
4655
  if (err instanceof import_context10.ContextDisposedError) {
4566
4656
  return;
4567
4657
  }
4568
- import_log11.log.warn("error loading automerge root doc", {
4658
+ import_log12.log.warn("error loading automerge root doc", {
4569
4659
  space: this.key,
4570
4660
  rootUrl,
4571
4661
  err
4572
4662
  }, {
4573
- F: __dxlog_file16,
4574
- L: 431,
4663
+ F: __dxlog_file17,
4664
+ L: 433,
4575
4665
  S: this,
4576
4666
  C: (f, a) => f(...a)
4577
4667
  });
@@ -4599,7 +4689,7 @@ var DataSpace = class {
4599
4689
  return null;
4600
4690
  }
4601
4691
  const { newRoot } = await runEpochMigration(ctx, {
4602
- repo: this._echoHost.automergeRepo,
4692
+ echoHost: this._echoHost,
4603
4693
  spaceId: this.id,
4604
4694
  spaceKey: this.key,
4605
4695
  migration: options.migration,
@@ -4653,11 +4743,11 @@ var DataSpace = class {
4653
4743
  await this._close();
4654
4744
  }
4655
4745
  this._state = import_services12.SpaceState.INACTIVE;
4656
- (0, import_log11.log)("new state", {
4746
+ (0, import_log12.log)("new state", {
4657
4747
  state: import_services12.SpaceState[this._state]
4658
4748
  }, {
4659
- F: __dxlog_file16,
4660
- L: 512,
4749
+ F: __dxlog_file17,
4750
+ L: 514,
4661
4751
  S: this,
4662
4752
  C: (f, a) => f(...a)
4663
4753
  });
@@ -4684,10 +4774,10 @@ _ts_decorate4([
4684
4774
  })
4685
4775
  ], DataSpace.prototype, "_automergeInfo", null);
4686
4776
  _ts_decorate4([
4687
- import_async12.synchronized
4777
+ import_async13.synchronized
4688
4778
  ], DataSpace.prototype, "open", null);
4689
4779
  _ts_decorate4([
4690
- import_async12.synchronized
4780
+ import_async13.synchronized
4691
4781
  ], DataSpace.prototype, "close", null);
4692
4782
  _ts_decorate4([
4693
4783
  import_tracing5.trace.span({
@@ -4703,13 +4793,13 @@ _ts_decorate4([
4703
4793
  (0, import_debug3.timed)(1e4)
4704
4794
  ], DataSpace.prototype, "_createWritableFeeds", null);
4705
4795
  _ts_decorate4([
4706
- import_async12.synchronized
4796
+ import_async13.synchronized
4707
4797
  ], DataSpace.prototype, "activate", null);
4708
4798
  _ts_decorate4([
4709
- import_async12.synchronized
4799
+ import_async13.synchronized
4710
4800
  ], DataSpace.prototype, "deactivate", null);
4711
4801
  DataSpace = _ts_decorate4([
4712
- (0, import_async12.trackLeaks)("open", "close"),
4802
+ (0, import_async13.trackLeaks)("open", "close"),
4713
4803
  import_tracing5.trace.resource()
4714
4804
  ], DataSpace);
4715
4805
  var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
@@ -4786,7 +4876,7 @@ function _ts_decorate5(decorators, target, key, desc) {
4786
4876
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4787
4877
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4788
4878
  }
4789
- var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
4879
+ var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
4790
4880
  var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
4791
4881
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
4792
4882
  var DEFAULT_SPACE_KEY = "__DEFAULT__";
@@ -4800,7 +4890,10 @@ var DataSpaceManager = class {
4800
4890
  this._echoHost = _echoHost;
4801
4891
  this._invitationsManager = _invitationsManager;
4802
4892
  this._params = _params;
4803
- this._ctx = new import_context14.Context();
4893
+ this._ctx = new import_context13.Context(void 0, {
4894
+ F: __dxlog_file18,
4895
+ L: 104
4896
+ });
4804
4897
  this.updated = new import_async16.Event();
4805
4898
  this._spaces = new import_util9.ComplexMap(import_keys12.PublicKey.hash);
4806
4899
  this._isOpen = false;
@@ -4833,46 +4926,46 @@ var DataSpaceManager = class {
4833
4926
  return this._spaces;
4834
4927
  }
4835
4928
  async open() {
4836
- (0, import_log14.log)("open", void 0, {
4837
- F: __dxlog_file17,
4838
- L: 146,
4929
+ (0, import_log15.log)("open", void 0, {
4930
+ F: __dxlog_file18,
4931
+ L: 156,
4839
4932
  S: this,
4840
4933
  C: (f, a) => f(...a)
4841
4934
  });
4842
- import_log14.log.trace("dxos.echo.data-space-manager.open", import_protocols11.trace.begin({
4935
+ import_log15.log.trace("dxos.echo.data-space-manager.open", import_protocols11.trace.begin({
4843
4936
  id: this._instanceId
4844
4937
  }), {
4845
- F: __dxlog_file17,
4846
- L: 147,
4938
+ F: __dxlog_file18,
4939
+ L: 157,
4847
4940
  S: this,
4848
4941
  C: (f, a) => f(...a)
4849
4942
  });
4850
- (0, import_log14.log)("metadata loaded", {
4943
+ (0, import_log15.log)("metadata loaded", {
4851
4944
  spaces: this._metadataStore.spaces.length
4852
4945
  }, {
4853
- F: __dxlog_file17,
4854
- L: 148,
4946
+ F: __dxlog_file18,
4947
+ L: 158,
4855
4948
  S: this,
4856
4949
  C: (f, a) => f(...a)
4857
4950
  });
4858
4951
  await (0, import_util9.forEachAsync)(this._metadataStore.spaces, async (spaceMetadata) => {
4859
4952
  try {
4860
- (0, import_log14.log)("load space", {
4953
+ (0, import_log15.log)("load space", {
4861
4954
  spaceMetadata
4862
4955
  }, {
4863
- F: __dxlog_file17,
4864
- L: 152,
4956
+ F: __dxlog_file18,
4957
+ L: 162,
4865
4958
  S: this,
4866
4959
  C: (f, a) => f(...a)
4867
4960
  });
4868
4961
  await this._constructSpace(spaceMetadata);
4869
4962
  } catch (err) {
4870
- import_log14.log.error("Error loading space", {
4963
+ import_log15.log.error("Error loading space", {
4871
4964
  spaceMetadata,
4872
4965
  err
4873
4966
  }, {
4874
- F: __dxlog_file17,
4875
- L: 155,
4967
+ F: __dxlog_file18,
4968
+ L: 165,
4876
4969
  S: this,
4877
4970
  C: (f, a) => f(...a)
4878
4971
  });
@@ -4880,19 +4973,19 @@ var DataSpaceManager = class {
4880
4973
  });
4881
4974
  this._isOpen = true;
4882
4975
  this.updated.emit();
4883
- import_log14.log.trace("dxos.echo.data-space-manager.open", import_protocols11.trace.end({
4976
+ import_log15.log.trace("dxos.echo.data-space-manager.open", import_protocols11.trace.end({
4884
4977
  id: this._instanceId
4885
4978
  }), {
4886
- F: __dxlog_file17,
4887
- L: 162,
4979
+ F: __dxlog_file18,
4980
+ L: 172,
4888
4981
  S: this,
4889
4982
  C: (f, a) => f(...a)
4890
4983
  });
4891
4984
  }
4892
4985
  async close() {
4893
- (0, import_log14.log)("close", void 0, {
4894
- F: __dxlog_file17,
4895
- L: 167,
4986
+ (0, import_log15.log)("close", void 0, {
4987
+ F: __dxlog_file18,
4988
+ L: 177,
4896
4989
  S: this,
4897
4990
  C: (f, a) => f(...a)
4898
4991
  });
@@ -4908,8 +5001,8 @@ var DataSpaceManager = class {
4908
5001
  */
4909
5002
  async createSpace() {
4910
5003
  (0, import_invariant15.invariant)(this._isOpen, "Not open.", {
4911
- F: __dxlog_file17,
4912
- L: 181,
5004
+ F: __dxlog_file18,
5005
+ L: 191,
4913
5006
  S: this,
4914
5007
  A: [
4915
5008
  "this._isOpen",
@@ -4926,11 +5019,11 @@ var DataSpaceManager = class {
4926
5019
  dataFeedKey,
4927
5020
  state: import_services14.SpaceState.ACTIVE
4928
5021
  };
4929
- (0, import_log14.log)("creating space...", {
5022
+ (0, import_log15.log)("creating space...", {
4930
5023
  spaceKey
4931
5024
  }, {
4932
- F: __dxlog_file17,
4933
- L: 193,
5025
+ F: __dxlog_file18,
5026
+ L: 203,
4934
5027
  S: this,
4935
5028
  C: (f, a) => f(...a)
4936
5029
  });
@@ -4941,8 +5034,8 @@ var DataSpaceManager = class {
4941
5034
  await this._metadataStore.addSpace(metadata);
4942
5035
  const memberCredential = credentials[1];
4943
5036
  (0, import_invariant15.invariant)((0, import_credentials15.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4944
- F: __dxlog_file17,
4945
- L: 203,
5037
+ F: __dxlog_file18,
5038
+ L: 213,
4946
5039
  S: this,
4947
5040
  A: [
4948
5041
  "getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -4959,22 +5052,22 @@ var DataSpaceManager = class {
4959
5052
  return false;
4960
5053
  }
4961
5054
  switch (space.databaseRoot.getVersion()) {
4962
- case import_echo_protocol2.SpaceDocVersion.CURRENT: {
5055
+ case import_echo_protocol3.SpaceDocVersion.CURRENT: {
4963
5056
  const [_, properties] = (0, import_echo_db2.findInlineObjectOfType)(space.databaseRoot.docSync(), import_echo_schema2.TYPE_PROPERTIES) ?? [];
4964
5057
  return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
4965
5058
  }
4966
- case import_echo_protocol2.SpaceDocVersion.LEGACY: {
5059
+ case import_echo_protocol3.SpaceDocVersion.LEGACY: {
4967
5060
  const convertedDoc = await (0, import_echo_db2.convertLegacyReferences)(space.databaseRoot.docSync());
4968
- const [_, properties] = (0, import_echo_db2.findInlineObjectOfType)(convertedDoc, import_echo_protocol2.LEGACY_TYPE_PROPERTIES) ?? [];
5061
+ const [_, properties] = (0, import_echo_db2.findInlineObjectOfType)(convertedDoc, import_echo_protocol3.LEGACY_TYPE_PROPERTIES) ?? [];
4969
5062
  return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
4970
5063
  }
4971
5064
  default:
4972
- import_log14.log.warn("unknown space version", {
5065
+ import_log15.log.warn("unknown space version", {
4973
5066
  version: space.databaseRoot.getVersion(),
4974
5067
  spaceId: space.id
4975
5068
  }, {
4976
- F: __dxlog_file17,
4977
- L: 228,
5069
+ F: __dxlog_file18,
5070
+ L: 238,
4978
5071
  S: this,
4979
5072
  C: (f, a) => f(...a)
4980
5073
  });
@@ -4986,7 +5079,7 @@ var DataSpaceManager = class {
4986
5079
  const document = await this._getSpaceRootDocument(space);
4987
5080
  const properties = {
4988
5081
  system: {
4989
- type: (0, import_echo_protocol2.encodeReference)((0, import_echo_schema2.getTypeReference)(import_client_protocol5.PropertiesType))
5082
+ type: (0, import_echo_protocol3.encodeReference)((0, import_echo_schema2.getTypeReference)(import_client_protocol5.PropertiesType))
4990
5083
  },
4991
5084
  data: {
4992
5085
  [DEFAULT_SPACE_KEY]: this._signingContext.identityKey.toHex()
@@ -5008,8 +5101,8 @@ var DataSpaceManager = class {
5008
5101
  async _getSpaceRootDocument(space) {
5009
5102
  const automergeIndex = space.automergeSpaceState.rootUrl;
5010
5103
  (0, import_invariant15.invariant)(automergeIndex, void 0, {
5011
- F: __dxlog_file17,
5012
- L: 261,
5104
+ F: __dxlog_file18,
5105
+ L: 271,
5013
5106
  S: this,
5014
5107
  A: [
5015
5108
  "automergeIndex",
@@ -5022,17 +5115,17 @@ var DataSpaceManager = class {
5022
5115
  }
5023
5116
  // TODO(burdon): Rename join space.
5024
5117
  async acceptSpace(opts) {
5025
- (0, import_log14.log)("accept space", {
5118
+ (0, import_log15.log)("accept space", {
5026
5119
  opts
5027
5120
  }, {
5028
- F: __dxlog_file17,
5029
- L: 270,
5121
+ F: __dxlog_file18,
5122
+ L: 280,
5030
5123
  S: this,
5031
5124
  C: (f, a) => f(...a)
5032
5125
  });
5033
5126
  (0, import_invariant15.invariant)(this._isOpen, "Not open.", {
5034
- F: __dxlog_file17,
5035
- L: 271,
5127
+ F: __dxlog_file18,
5128
+ L: 281,
5036
5129
  S: this,
5037
5130
  A: [
5038
5131
  "this._isOpen",
@@ -5040,8 +5133,8 @@ var DataSpaceManager = class {
5040
5133
  ]
5041
5134
  });
5042
5135
  (0, import_invariant15.invariant)(!this._spaces.has(opts.spaceKey), "Space already exists.", {
5043
- F: __dxlog_file17,
5044
- L: 272,
5136
+ F: __dxlog_file18,
5137
+ L: 282,
5045
5138
  S: this,
5046
5139
  A: [
5047
5140
  "!this._spaces.has(opts.spaceKey)",
@@ -5061,23 +5154,72 @@ var DataSpaceManager = class {
5061
5154
  this.updated.emit();
5062
5155
  return space;
5063
5156
  }
5157
+ async admitMember(options) {
5158
+ const space = this._spaceManager.spaces.get(options.spaceKey);
5159
+ (0, import_invariant15.invariant)(space, void 0, {
5160
+ F: __dxlog_file18,
5161
+ L: 302,
5162
+ S: this,
5163
+ A: [
5164
+ "space",
5165
+ ""
5166
+ ]
5167
+ });
5168
+ if (space.spaceState.getMemberRole(options.identityKey) !== import_credentials16.SpaceMember.Role.REMOVED) {
5169
+ throw new import_protocols11.AlreadyJoinedError();
5170
+ }
5171
+ 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);
5172
+ (0, import_invariant15.invariant)(credentials[0].credential, void 0, {
5173
+ F: __dxlog_file18,
5174
+ L: 321,
5175
+ S: this,
5176
+ A: [
5177
+ "credentials[0].credential",
5178
+ ""
5179
+ ]
5180
+ });
5181
+ const spaceMemberCredential = credentials[0].credential.credential;
5182
+ (0, import_invariant15.invariant)((0, import_credentials15.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
5183
+ F: __dxlog_file18,
5184
+ L: 323,
5185
+ S: this,
5186
+ A: [
5187
+ "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
5188
+ ""
5189
+ ]
5190
+ });
5191
+ await (0, import_feed_store4.writeMessages)(space.controlPipeline.writer, credentials);
5192
+ return spaceMemberCredential;
5193
+ }
5064
5194
  /**
5065
5195
  * Wait until the space data pipeline is fully initialized.
5066
5196
  * Used by invitation handler.
5067
5197
  * TODO(dmaretskyi): Consider removing.
5068
5198
  */
5069
5199
  async waitUntilSpaceReady(spaceKey) {
5070
- await (0, import_context14.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
5200
+ await (0, import_context13.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
5071
5201
  const space = this._spaces.get(spaceKey);
5072
5202
  return !!space && space.state === import_services14.SpaceState.READY;
5073
5203
  }));
5074
5204
  }
5205
+ async requestSpaceAdmissionCredential(spaceKey) {
5206
+ return this._spaceManager.requestSpaceAdmissionCredential({
5207
+ spaceKey,
5208
+ identityKey: this._signingContext.identityKey,
5209
+ timeout: 15e3,
5210
+ swarmIdentity: {
5211
+ peerKey: this._signingContext.deviceKey,
5212
+ credentialProvider: createAuthProvider(this._signingContext.credentialSigner),
5213
+ credentialAuthenticator: async () => true
5214
+ }
5215
+ });
5216
+ }
5075
5217
  async _constructSpace(metadata) {
5076
- (0, import_log14.log)("construct space", {
5218
+ (0, import_log15.log)("construct space", {
5077
5219
  metadata
5078
5220
  }, {
5079
- F: __dxlog_file17,
5080
- L: 306,
5221
+ F: __dxlog_file18,
5222
+ L: 358,
5081
5223
  S: this,
5082
5224
  C: (f, a) => f(...a)
5083
5225
  });
@@ -5105,6 +5247,7 @@ var DataSpaceManager = class {
5105
5247
  credentialAuthenticator: (0, import_util9.deferFunction)(() => dataSpace.authVerifier.verifier)
5106
5248
  },
5107
5249
  onAuthorizedConnection: (session) => {
5250
+ session.addExtension("dxos.mesh.teleport.admission-discovery", new import_echo_pipeline4.CredentialServerExtension(space));
5108
5251
  session.addExtension("dxos.mesh.teleport.gossip", gossip.createExtension({
5109
5252
  remotePeerId: session.remotePeerId
5110
5253
  }));
@@ -5113,9 +5256,9 @@ var DataSpaceManager = class {
5113
5256
  session.addExtension("dxos.mesh.teleport.automerge", this._echoHost.createReplicationExtension());
5114
5257
  },
5115
5258
  onAuthFailure: () => {
5116
- import_log14.log.warn("auth failure", void 0, {
5117
- F: __dxlog_file17,
5118
- L: 343,
5259
+ import_log15.log.warn("auth failure", void 0, {
5260
+ F: __dxlog_file18,
5261
+ L: 396,
5119
5262
  S: this,
5120
5263
  C: (f, a) => f(...a)
5121
5264
  });
@@ -5144,22 +5287,22 @@ var DataSpaceManager = class {
5144
5287
  signingContext: this._signingContext,
5145
5288
  callbacks: {
5146
5289
  beforeReady: async () => {
5147
- (0, import_log14.log)("before space ready", {
5290
+ (0, import_log15.log)("before space ready", {
5148
5291
  space: space.key
5149
5292
  }, {
5150
- F: __dxlog_file17,
5151
- L: 370,
5293
+ F: __dxlog_file18,
5294
+ L: 423,
5152
5295
  S: this,
5153
5296
  C: (f, a) => f(...a)
5154
5297
  });
5155
5298
  },
5156
5299
  afterReady: async () => {
5157
- (0, import_log14.log)("after space ready", {
5300
+ (0, import_log15.log)("after space ready", {
5158
5301
  space: space.key,
5159
5302
  open: this._isOpen
5160
5303
  }, {
5161
- F: __dxlog_file17,
5162
- L: 373,
5304
+ F: __dxlog_file18,
5305
+ L: 426,
5163
5306
  S: this,
5164
5307
  C: (f, a) => f(...a)
5165
5308
  });
@@ -5174,11 +5317,11 @@ var DataSpaceManager = class {
5174
5317
  }
5175
5318
  },
5176
5319
  beforeClose: async () => {
5177
- (0, import_log14.log)("before space close", {
5320
+ (0, import_log15.log)("before space close", {
5178
5321
  space: space.key
5179
5322
  }, {
5180
- F: __dxlog_file17,
5181
- L: 381,
5323
+ F: __dxlog_file18,
5324
+ L: 434,
5182
5325
  S: this,
5183
5326
  C: (f, a) => f(...a)
5184
5327
  });
@@ -5206,20 +5349,20 @@ var DataSpaceManager = class {
5206
5349
  const peers = presence.getPeersByIdentityKey(member.key);
5207
5350
  const sessions = peers.map((p) => p.peerId && spaceProtocol.sessions.get(p.peerId));
5208
5351
  const sessionsToClose = sessions.filter((s) => {
5209
- return (s && member.role === import_credentials16.SpaceMember.Role.REMOVED !== (s.authStatus === import_echo_pipeline4.AuthStatus.FAILURE)) ?? false;
5352
+ return (s && member.role === import_credentials16.SpaceMember.Role.REMOVED !== (s.authStatus === import_echo_pipeline3.AuthStatus.FAILURE)) ?? false;
5210
5353
  });
5211
5354
  sessionsToClose.forEach((session) => {
5212
- void session.close().catch(import_log14.log.error);
5355
+ void session.close().catch(import_log15.log.error);
5213
5356
  });
5214
5357
  closedSessions += sessionsToClose.length;
5215
5358
  }
5216
- (0, import_log14.log)("processed member role changes", {
5359
+ (0, import_log15.log)("processed member role changes", {
5217
5360
  roleChangeCount: memberInfo.length,
5218
5361
  peersOnline: presence.getPeersOnline().length,
5219
5362
  closedSessions
5220
5363
  }, {
5221
- F: __dxlog_file17,
5222
- L: 417,
5364
+ F: __dxlog_file18,
5365
+ L: 470,
5223
5366
  S: this,
5224
5367
  C: (f, a) => f(...a)
5225
5368
  });
@@ -5230,15 +5373,15 @@ var DataSpaceManager = class {
5230
5373
  if (role === import_credentials16.SpaceMember.Role.REMOVED) {
5231
5374
  const session = peerState.peerId && space.protocol.sessions.get(peerState.peerId);
5232
5375
  if (session != null) {
5233
- (0, import_log14.log)("closing a session with a removed peer", {
5376
+ (0, import_log15.log)("closing a session with a removed peer", {
5234
5377
  peerId: peerState.peerId
5235
5378
  }, {
5236
- F: __dxlog_file17,
5237
- L: 431,
5379
+ F: __dxlog_file18,
5380
+ L: 484,
5238
5381
  S: this,
5239
5382
  C: (f, a) => f(...a)
5240
5383
  });
5241
- void session.close().catch(import_log14.log.error);
5384
+ void session.close().catch(import_log15.log.error);
5242
5385
  }
5243
5386
  }
5244
5387
  }
@@ -5293,7 +5436,7 @@ _ts_decorate5([
5293
5436
  DataSpaceManager = _ts_decorate5([
5294
5437
  (0, import_async16.trackLeaks)("open", "close")
5295
5438
  ], DataSpaceManager);
5296
- var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
5439
+ var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
5297
5440
  var SpacesServiceImpl = class {
5298
5441
  constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
5299
5442
  this._identityManager = _identityManager;
@@ -5337,8 +5480,8 @@ var SpacesServiceImpl = class {
5337
5480
  }
5338
5481
  const credentials = await (0, import_credentials19.createAdmissionCredentials)(identity.getIdentityCredentialSigner(), request.memberKey, space.key, space.genesisFeedKey, request.newRole, space.spaceState.membershipChainHeads);
5339
5482
  (0, import_invariant16.invariant)(credentials[0].credential, void 0, {
5340
- F: __dxlog_file18,
5341
- L: 98,
5483
+ F: __dxlog_file19,
5484
+ L: 102,
5342
5485
  S: this,
5343
5486
  A: [
5344
5487
  "credentials[0].credential",
@@ -5347,26 +5490,26 @@ var SpacesServiceImpl = class {
5347
5490
  });
5348
5491
  const spaceMemberCredential = credentials[0].credential.credential;
5349
5492
  (0, import_invariant16.invariant)((0, import_credentials19.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
5350
- F: __dxlog_file18,
5351
- L: 100,
5493
+ F: __dxlog_file19,
5494
+ L: 104,
5352
5495
  S: this,
5353
5496
  A: [
5354
5497
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
5355
5498
  ""
5356
5499
  ]
5357
5500
  });
5358
- await (0, import_feed_store4.writeMessages)(space.controlPipeline.writer, credentials);
5501
+ await (0, import_feed_store5.writeMessages)(space.controlPipeline.writer, credentials);
5359
5502
  }
5360
5503
  querySpaces() {
5361
5504
  return new import_codec_protobuf11.Stream(({ next, ctx }) => {
5362
5505
  const scheduler = new import_async17.UpdateScheduler(ctx, async () => {
5363
5506
  const dataSpaceManager = await this._getDataSpaceManager();
5364
5507
  const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
5365
- (0, import_log15.log)("update", {
5508
+ (0, import_log16.log)("update", {
5366
5509
  spaces
5367
5510
  }, {
5368
- F: __dxlog_file18,
5369
- L: 111,
5511
+ F: __dxlog_file19,
5512
+ L: 115,
5370
5513
  S: this,
5371
5514
  C: (f, a) => f(...a)
5372
5515
  });
@@ -5384,7 +5527,15 @@ var SpacesServiceImpl = class {
5384
5527
  const subscribeSpaces = () => {
5385
5528
  subscriptions.clear();
5386
5529
  for (const space of dataSpaceManager.spaces.values()) {
5387
- subscriptions.add(space.stateUpdate.on(ctx, () => scheduler.forceTrigger()));
5530
+ let lastState;
5531
+ subscriptions.add(space.stateUpdate.on(ctx, () => {
5532
+ if (space.state !== lastState) {
5533
+ scheduler.forceTrigger();
5534
+ } else {
5535
+ scheduler.trigger();
5536
+ }
5537
+ lastState = space.state;
5538
+ }));
5388
5539
  subscriptions.add(space.presence.updated.on(ctx, () => scheduler.trigger()));
5389
5540
  subscriptions.add(space.automergeSpaceState.onNewEpoch.on(ctx, () => scheduler.trigger()));
5390
5541
  subscriptions.add(space.inner.controlPipeline.state.timeframeUpdate.on(ctx, () => scheduler.trigger()));
@@ -5449,8 +5600,8 @@ var SpacesServiceImpl = class {
5449
5600
  });
5450
5601
  } else {
5451
5602
  (0, import_invariant16.invariant)(!credential.id, "Id on unsigned credentials is not allowed", {
5452
- F: __dxlog_file18,
5453
- L: 199,
5603
+ F: __dxlog_file19,
5604
+ L: 213,
5454
5605
  S: this,
5455
5606
  A: [
5456
5607
  "!credential.id",
@@ -5458,8 +5609,8 @@ var SpacesServiceImpl = class {
5458
5609
  ]
5459
5610
  });
5460
5611
  (0, import_invariant16.invariant)(this._identityManager.identity, "Identity is not available", {
5461
- F: __dxlog_file18,
5462
- L: 200,
5612
+ F: __dxlog_file19,
5613
+ L: 214,
5463
5614
  S: this,
5464
5615
  A: [
5465
5616
  "this._identityManager.identity",
@@ -5468,8 +5619,8 @@ var SpacesServiceImpl = class {
5468
5619
  });
5469
5620
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
5470
5621
  (0, import_invariant16.invariant)(credential.issuer.equals(signer.getIssuer()), void 0, {
5471
- F: __dxlog_file18,
5472
- L: 202,
5622
+ F: __dxlog_file19,
5623
+ L: 216,
5473
5624
  S: this,
5474
5625
  A: [
5475
5626
  "credential.issuer.equals(signer.getIssuer())",
@@ -5499,6 +5650,59 @@ var SpacesServiceImpl = class {
5499
5650
  epochCredential: credential ?? void 0
5500
5651
  };
5501
5652
  }
5653
+ async admitContact(request) {
5654
+ const dataSpaceManager = await this._getDataSpaceManager();
5655
+ await dataSpaceManager.admitMember({
5656
+ spaceKey: request.spaceKey,
5657
+ identityKey: request.contact.identityKey,
5658
+ role: request.role
5659
+ });
5660
+ }
5661
+ async joinBySpaceKey({ spaceKey }) {
5662
+ const dataSpaceManager = await this._getDataSpaceManager();
5663
+ const credential = await dataSpaceManager.requestSpaceAdmissionCredential(spaceKey);
5664
+ return this._joinByAdmission({
5665
+ credential
5666
+ });
5667
+ }
5668
+ async _joinByAdmission({ credential }) {
5669
+ const assertion = (0, import_credentials19.getCredentialAssertion)(credential);
5670
+ (0, import_invariant16.invariant)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
5671
+ F: __dxlog_file19,
5672
+ L: 250,
5673
+ S: this,
5674
+ A: [
5675
+ "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
5676
+ "'Invalid credential'"
5677
+ ]
5678
+ });
5679
+ const myIdentity = this._identityManager.identity;
5680
+ (0, import_invariant16.invariant)(myIdentity && credential.subject.id.equals(myIdentity.identityKey), void 0, {
5681
+ F: __dxlog_file19,
5682
+ L: 252,
5683
+ S: this,
5684
+ A: [
5685
+ "myIdentity && credential.subject.id.equals(myIdentity.identityKey)",
5686
+ ""
5687
+ ]
5688
+ });
5689
+ const dataSpaceManager = await this._getDataSpaceManager();
5690
+ let dataSpace = dataSpaceManager.spaces.get(assertion.spaceKey);
5691
+ if (!dataSpace) {
5692
+ dataSpace = await dataSpaceManager.acceptSpace({
5693
+ spaceKey: assertion.spaceKey,
5694
+ genesisFeedKey: assertion.genesisFeedKey
5695
+ });
5696
+ await myIdentity.controlPipeline.writer.write({
5697
+ credential: {
5698
+ credential
5699
+ }
5700
+ });
5701
+ }
5702
+ return {
5703
+ space: this._serializeSpace(dataSpace)
5704
+ };
5705
+ }
5502
5706
  _serializeSpace(space) {
5503
5707
  return {
5504
5708
  id: space.id,
@@ -5516,7 +5720,8 @@ var SpacesServiceImpl = class {
5516
5720
  startDataTimeframe: void 0,
5517
5721
  currentDataTimeframe: void 0,
5518
5722
  targetDataTimeframe: void 0,
5519
- totalDataTimeframe: void 0
5723
+ totalDataTimeframe: void 0,
5724
+ spaceRootUrl: space.databaseRoot?.url
5520
5725
  },
5521
5726
  members: Array.from(space.inner.spaceState.members.values()).map((member) => {
5522
5727
  const peers = space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key));
@@ -5568,8 +5773,8 @@ function _ts_decorate6(decorators, target, key, desc) {
5568
5773
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5569
5774
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5570
5775
  }
5571
- var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
5572
- var ServiceContext = class extends import_context15.Resource {
5776
+ var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
5777
+ var ServiceContext = class extends import_context14.Resource {
5573
5778
  constructor(storage, level, networkManager, signalManager, _runtimeParams) {
5574
5779
  super();
5575
5780
  this.storage = storage;
@@ -5584,8 +5789,8 @@ var ServiceContext = class extends import_context15.Resource {
5584
5789
  this.snapshotStore = new import_echo_pipeline5.SnapshotStore(storage.createDirectory("snapshots"));
5585
5790
  this.blobStore = new import_teleport_extension_object_sync.BlobStore(storage.createDirectory("blobs"));
5586
5791
  this.keyring = new import_keyring.Keyring(storage.createDirectory("keyring"));
5587
- this.feedStore = new import_feed_store5.FeedStore({
5588
- factory: new import_feed_store5.FeedFactory({
5792
+ this.feedStore = new import_feed_store6.FeedStore({
5793
+ factory: new import_feed_store6.FeedFactory({
5589
5794
  root: storage.createDirectory("feeds"),
5590
5795
  signer: this.keyring,
5591
5796
  hypercore: {
@@ -5611,16 +5816,16 @@ var ServiceContext = class extends import_context15.Resource {
5611
5816
  }
5612
5817
  async _open(ctx) {
5613
5818
  await this._checkStorageVersion();
5614
- (0, import_log16.log)("opening...", void 0, {
5615
- F: __dxlog_file19,
5819
+ (0, import_log17.log)("opening...", void 0, {
5820
+ F: __dxlog_file20,
5616
5821
  L: 149,
5617
5822
  S: this,
5618
5823
  C: (f, a) => f(...a)
5619
5824
  });
5620
- import_log16.log.trace("dxos.sdk.service-context.open", import_protocols13.trace.begin({
5825
+ import_log17.log.trace("dxos.sdk.service-context.open", import_protocols13.trace.begin({
5621
5826
  id: this._instanceId
5622
5827
  }), {
5623
- F: __dxlog_file19,
5828
+ F: __dxlog_file20,
5624
5829
  L: 150,
5625
5830
  S: this,
5626
5831
  C: (f, a) => f(...a)
@@ -5635,32 +5840,32 @@ var ServiceContext = class extends import_context15.Resource {
5635
5840
  await this._initialize(ctx);
5636
5841
  }
5637
5842
  const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
5638
- (0, import_log16.log)("loaded persistent invitations", {
5843
+ (0, import_log17.log)("loaded persistent invitations", {
5639
5844
  count: loadedInvitations.invitations?.length
5640
5845
  }, {
5641
- F: __dxlog_file19,
5846
+ F: __dxlog_file20,
5642
5847
  L: 163,
5643
5848
  S: this,
5644
5849
  C: (f, a) => f(...a)
5645
5850
  });
5646
- import_log16.log.trace("dxos.sdk.service-context.open", import_protocols13.trace.end({
5851
+ import_log17.log.trace("dxos.sdk.service-context.open", import_protocols13.trace.end({
5647
5852
  id: this._instanceId
5648
5853
  }), {
5649
- F: __dxlog_file19,
5854
+ F: __dxlog_file20,
5650
5855
  L: 165,
5651
5856
  S: this,
5652
5857
  C: (f, a) => f(...a)
5653
5858
  });
5654
- (0, import_log16.log)("opened", void 0, {
5655
- F: __dxlog_file19,
5859
+ (0, import_log17.log)("opened", void 0, {
5860
+ F: __dxlog_file20,
5656
5861
  L: 166,
5657
5862
  S: this,
5658
5863
  C: (f, a) => f(...a)
5659
5864
  });
5660
5865
  }
5661
5866
  async _close(ctx) {
5662
- (0, import_log16.log)("closing...", void 0, {
5663
- F: __dxlog_file19,
5867
+ (0, import_log17.log)("closing...", void 0, {
5868
+ F: __dxlog_file20,
5664
5869
  L: 170,
5665
5870
  S: this,
5666
5871
  C: (f, a) => f(...a)
@@ -5676,8 +5881,8 @@ var ServiceContext = class extends import_context15.Resource {
5676
5881
  await this.echoHost.close(ctx);
5677
5882
  await this.networkManager.close();
5678
5883
  await this.signalManager.close();
5679
- (0, import_log16.log)("closed", void 0, {
5680
- F: __dxlog_file19,
5884
+ (0, import_log17.log)("closed", void 0, {
5885
+ F: __dxlog_file20,
5681
5886
  L: 182,
5682
5887
  S: this,
5683
5888
  C: (f, a) => f(...a)
@@ -5685,13 +5890,16 @@ var ServiceContext = class extends import_context15.Resource {
5685
5890
  }
5686
5891
  async createIdentity(params = {}) {
5687
5892
  const identity = await this.identityManager.createIdentity(params);
5688
- await this._initialize(new import_context15.Context());
5893
+ await this._initialize(new import_context14.Context(void 0, {
5894
+ F: __dxlog_file20,
5895
+ L: 187
5896
+ }));
5689
5897
  return identity;
5690
5898
  }
5691
5899
  getInvitationHandler(invitation) {
5692
5900
  const factory = this._handlerFactories.get(invitation.kind);
5693
5901
  (0, import_invariant17.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
5694
- F: __dxlog_file19,
5902
+ F: __dxlog_file20,
5695
5903
  L: 193,
5696
5904
  S: this,
5697
5905
  A: [
@@ -5711,7 +5919,10 @@ var ServiceContext = class extends import_context15.Resource {
5711
5919
  }
5712
5920
  async _acceptIdentity(params) {
5713
5921
  const identity = await this.identityManager.acceptIdentity(params);
5714
- await this._initialize(new import_context15.Context());
5922
+ await this._initialize(new import_context14.Context(void 0, {
5923
+ F: __dxlog_file20,
5924
+ L: 209
5925
+ }));
5715
5926
  return identity;
5716
5927
  }
5717
5928
  async _checkStorageVersion() {
@@ -5722,8 +5933,8 @@ var ServiceContext = class extends import_context15.Resource {
5722
5933
  }
5723
5934
  // Called when identity is created.
5724
5935
  async _initialize(ctx) {
5725
- (0, import_log16.log)("initializing spaces...", void 0, {
5726
- F: __dxlog_file19,
5936
+ (0, import_log17.log)("initializing spaces...", void 0, {
5937
+ F: __dxlog_file20,
5727
5938
  L: 224,
5728
5939
  S: this,
5729
5940
  C: (f, a) => f(...a)
@@ -5746,7 +5957,7 @@ var ServiceContext = class extends import_context15.Resource {
5746
5957
  await this.dataSpaceManager.open();
5747
5958
  this._handlerFactories.set(import_services16.Invitation.Kind.SPACE, (invitation) => {
5748
5959
  (0, import_invariant17.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
5749
- F: __dxlog_file19,
5960
+ F: __dxlog_file20,
5750
5961
  L: 249,
5751
5962
  S: this,
5752
5963
  A: [
@@ -5767,10 +5978,10 @@ var ServiceContext = class extends import_context15.Resource {
5767
5978
  return;
5768
5979
  }
5769
5980
  if (!this.dataSpaceManager) {
5770
- (0, import_log16.log)("dataSpaceManager not initialized yet, ignoring space admission", {
5981
+ (0, import_log17.log)("dataSpaceManager not initialized yet, ignoring space admission", {
5771
5982
  details: assertion
5772
5983
  }, {
5773
- F: __dxlog_file19,
5984
+ F: __dxlog_file20,
5774
5985
  L: 265,
5775
5986
  S: this,
5776
5987
  C: (f, a) => f(...a)
@@ -5778,10 +5989,10 @@ var ServiceContext = class extends import_context15.Resource {
5778
5989
  return;
5779
5990
  }
5780
5991
  if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
5781
- (0, import_log16.log)("space already exists, ignoring space admission", {
5992
+ (0, import_log17.log)("space already exists, ignoring space admission", {
5782
5993
  details: assertion
5783
5994
  }, {
5784
- F: __dxlog_file19,
5995
+ F: __dxlog_file20,
5785
5996
  L: 269,
5786
5997
  S: this,
5787
5998
  C: (f, a) => f(...a)
@@ -5789,10 +6000,10 @@ var ServiceContext = class extends import_context15.Resource {
5789
6000
  return;
5790
6001
  }
5791
6002
  try {
5792
- (0, import_log16.log)("accepting space recorded in halo", {
6003
+ (0, import_log17.log)("accepting space recorded in halo", {
5793
6004
  details: assertion
5794
6005
  }, {
5795
- F: __dxlog_file19,
6006
+ F: __dxlog_file20,
5796
6007
  L: 274,
5797
6008
  S: this,
5798
6009
  C: (f, a) => f(...a)
@@ -5802,8 +6013,8 @@ var ServiceContext = class extends import_context15.Resource {
5802
6013
  genesisFeedKey: assertion.genesisFeedKey
5803
6014
  });
5804
6015
  } catch (err) {
5805
- import_log16.log.catch(err, void 0, {
5806
- F: __dxlog_file19,
6016
+ import_log17.log.catch(err, void 0, {
6017
+ F: __dxlog_file20,
5807
6018
  L: 280,
5808
6019
  S: this,
5809
6020
  C: (f, a) => f(...a)
@@ -5856,7 +6067,7 @@ function _ts_decorate7(decorators, target, key, desc) {
5856
6067
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5857
6068
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5858
6069
  }
5859
- var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/node.ts";
6070
+ var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/node.ts";
5860
6071
  var Lock = class {
5861
6072
  constructor({ lockKey: lockPath, onAcquire, onRelease }) {
5862
6073
  this._lockPath = lockPath;
@@ -5867,16 +6078,16 @@ var Lock = class {
5867
6078
  return this._lockPath;
5868
6079
  }
5869
6080
  async acquire() {
5870
- (0, import_log17.log)("acquiring lock...", void 0, {
5871
- F: __dxlog_file20,
6081
+ (0, import_log18.log)("acquiring lock...", void 0, {
6082
+ F: __dxlog_file21,
5872
6083
  L: 32,
5873
6084
  S: this,
5874
6085
  C: (f, a) => f(...a)
5875
6086
  });
5876
6087
  this._fileHandle = await import_lock_file.LockFile.acquire(this._lockPath);
5877
6088
  await this._onAcquire?.();
5878
- (0, import_log17.log)("acquired lock", void 0, {
5879
- F: __dxlog_file20,
6089
+ (0, import_log18.log)("acquired lock", void 0, {
6090
+ F: __dxlog_file21,
5880
6091
  L: 37,
5881
6092
  S: this,
5882
6093
  C: (f, a) => f(...a)
@@ -5885,7 +6096,7 @@ var Lock = class {
5885
6096
  async release() {
5886
6097
  await this._onRelease?.();
5887
6098
  (0, import_invariant18.invariant)(this._fileHandle, "Lock is not acquired", {
5888
- F: __dxlog_file20,
6099
+ F: __dxlog_file21,
5889
6100
  L: 42,
5890
6101
  S: this,
5891
6102
  A: [
@@ -5897,7 +6108,7 @@ var Lock = class {
5897
6108
  }
5898
6109
  };
5899
6110
  _ts_decorate7([
5900
- import_log17.logInfo
6111
+ import_log18.logInfo
5901
6112
  ], Lock.prototype, "lockKey", null);
5902
6113
  var isLocked = (lockPath) => import_lock_file.LockFile.isLocked(lockPath);
5903
6114
  var getRootPath = (config) => {
@@ -5957,7 +6168,159 @@ var createLevel = async (config) => {
5957
6168
  await level.open();
5958
6169
  return level;
5959
6170
  };
5960
- var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
6171
+ var __dxlog_file22 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/storage/profile-archive.ts";
6172
+ var encodeProfileArchive = (profile) => import_automerge_repo.cbor.encode(profile);
6173
+ var decodeProfileArchive = (data) => import_automerge_repo.cbor.decode(data);
6174
+ var exportProfileData = async ({ storage, level }) => {
6175
+ const archive = {
6176
+ storage: [],
6177
+ meta: {
6178
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
6179
+ }
6180
+ };
6181
+ {
6182
+ const directory = await storage.createDirectory();
6183
+ const files = await directory.list();
6184
+ import_log19.log.info("begin exporting files", {
6185
+ count: files.length
6186
+ }, {
6187
+ F: __dxlog_file22,
6188
+ L: 30,
6189
+ S: void 0,
6190
+ C: (f, a) => f(...a)
6191
+ });
6192
+ for (const filename of files) {
6193
+ const file = await directory.getOrCreateFile(filename);
6194
+ const { size } = await file.stat();
6195
+ const data = await file.read(0, size);
6196
+ archive.storage.push({
6197
+ type: import_protocols15.ProfileArchiveEntryType.FILE,
6198
+ key: filename,
6199
+ value: data
6200
+ });
6201
+ }
6202
+ import_log19.log.info("done exporting files", {
6203
+ count: files.length
6204
+ }, {
6205
+ F: __dxlog_file22,
6206
+ L: 41,
6207
+ S: void 0,
6208
+ C: (f, a) => f(...a)
6209
+ });
6210
+ }
6211
+ {
6212
+ import_log19.log.info("begin exporting kv pairs", void 0, {
6213
+ F: __dxlog_file22,
6214
+ L: 45,
6215
+ S: void 0,
6216
+ C: (f, a) => f(...a)
6217
+ });
6218
+ const iter = await level.iterator({
6219
+ keyEncoding: "binary",
6220
+ valueEncoding: "binary"
6221
+ });
6222
+ let count = 0;
6223
+ for await (const [key, value] of iter) {
6224
+ archive.storage.push({
6225
+ type: import_protocols15.ProfileArchiveEntryType.KEY_VALUE,
6226
+ key,
6227
+ value
6228
+ });
6229
+ count++;
6230
+ }
6231
+ import_log19.log.info("done exporting kv pairs", {
6232
+ count
6233
+ }, {
6234
+ F: __dxlog_file22,
6235
+ L: 56,
6236
+ S: void 0,
6237
+ C: (f, a) => f(...a)
6238
+ });
6239
+ }
6240
+ return archive;
6241
+ };
6242
+ var importProfileData = async ({ storage, level }, archive) => {
6243
+ let batch = level.batch();
6244
+ let count = 0;
6245
+ for (const entry2 of archive.storage) {
6246
+ switch (entry2.type) {
6247
+ case import_protocols15.ProfileArchiveEntryType.FILE: {
6248
+ const directory = await storage.createDirectory();
6249
+ (0, import_invariant19.invariant)(typeof entry2.key === "string", "Invalid key type", {
6250
+ F: __dxlog_file22,
6251
+ L: 79,
6252
+ S: void 0,
6253
+ A: [
6254
+ "typeof entry.key === 'string'",
6255
+ "'Invalid key type'"
6256
+ ]
6257
+ });
6258
+ const file = await directory.getOrCreateFile(entry2.key);
6259
+ (0, import_invariant19.invariant)(entry2.value instanceof Uint8Array, "Invalid value type", {
6260
+ F: __dxlog_file22,
6261
+ L: 81,
6262
+ S: void 0,
6263
+ A: [
6264
+ "entry.value instanceof Uint8Array",
6265
+ "'Invalid value type'"
6266
+ ]
6267
+ });
6268
+ await file.write(0, (0, import_util12.arrayToBuffer)(entry2.value));
6269
+ await file.close();
6270
+ break;
6271
+ }
6272
+ case import_protocols15.ProfileArchiveEntryType.KEY_VALUE: {
6273
+ (0, import_invariant19.invariant)(entry2.key instanceof Uint8Array, "Invalid key type", {
6274
+ F: __dxlog_file22,
6275
+ L: 87,
6276
+ S: void 0,
6277
+ A: [
6278
+ "entry.key instanceof Uint8Array",
6279
+ "'Invalid key type'"
6280
+ ]
6281
+ });
6282
+ (0, import_invariant19.invariant)(entry2.value instanceof Uint8Array, "Invalid value type", {
6283
+ F: __dxlog_file22,
6284
+ L: 88,
6285
+ S: void 0,
6286
+ A: [
6287
+ "entry.value instanceof Uint8Array",
6288
+ "'Invalid value type'"
6289
+ ]
6290
+ });
6291
+ batch.put(entry2.key, entry2.value, {
6292
+ keyEncoding: "binary",
6293
+ valueEncoding: "binary"
6294
+ });
6295
+ break;
6296
+ }
6297
+ default:
6298
+ throw new Error(`Invalid entry type: ${entry2.type}`);
6299
+ }
6300
+ if (++count % 1e3 === 0) {
6301
+ await batch.write();
6302
+ batch = level.batch();
6303
+ import_log19.log.info("importing", {
6304
+ count,
6305
+ total: archive.storage.length,
6306
+ progress: `${(count / archive.storage.length * 100).toFixed()}%`
6307
+ }, {
6308
+ F: __dxlog_file22,
6309
+ L: 101,
6310
+ S: void 0,
6311
+ C: (f, a) => f(...a)
6312
+ });
6313
+ }
6314
+ }
6315
+ import_log19.log.info("committing changes..", void 0, {
6316
+ F: __dxlog_file22,
6317
+ L: 109,
6318
+ S: void 0,
6319
+ C: (f, a) => f(...a)
6320
+ });
6321
+ await batch.write();
6322
+ };
6323
+ var __dxlog_file23 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
5961
6324
  var DevicesServiceImpl = class {
5962
6325
  constructor(_identityManager) {
5963
6326
  this._identityManager = _identityManager;
@@ -5974,8 +6337,8 @@ var DevicesServiceImpl = class {
5974
6337
  devices: []
5975
6338
  });
5976
6339
  } else {
5977
- (0, import_invariant20.invariant)(this._identityManager.identity?.presence, "presence not present", {
5978
- F: __dxlog_file21,
6340
+ (0, import_invariant21.invariant)(this._identityManager.identity?.presence, "presence not present", {
6341
+ F: __dxlog_file23,
5979
6342
  L: 32,
5980
6343
  S: this,
5981
6344
  A: [
@@ -6056,7 +6419,7 @@ var DiagnosticsCollector = class {
6056
6419
  client: clientDiagnostics,
6057
6420
  broadcast: await this.broadcastSender.broadcastDiagnosticsRequest()
6058
6421
  };
6059
- return JSON.parse(JSON.stringify(diagnostics, (0, import_util12.jsonKeyReplacer)(options)));
6422
+ return JSON.parse(JSON.stringify(diagnostics, (0, import_util13.jsonKeyReplacer)(options)));
6060
6423
  }
6061
6424
  };
6062
6425
  var findSystemServiceProvider = () => {
@@ -6066,35 +6429,112 @@ var findSystemServiceProvider = () => {
6066
6429
  };
6067
6430
  var findConfigs = () => {
6068
6431
  const configs = import_tracing10.TRACE_PROCESSOR.findResourcesByAnnotation(import_config3.ConfigResource);
6069
- return configs.map((r) => r.instance.deref()).filter(import_util12.nonNullable);
6432
+ return configs.map((r) => r.instance.deref()).filter(import_util13.nonNullable);
6433
+ };
6434
+ var ContactsServiceImpl = class {
6435
+ constructor(_identityManager, _spaceManager, _dataSpaceManagerProvider) {
6436
+ this._identityManager = _identityManager;
6437
+ this._spaceManager = _spaceManager;
6438
+ this._dataSpaceManagerProvider = _dataSpaceManagerProvider;
6439
+ }
6440
+ async getContacts() {
6441
+ const identity = this._identityManager.identity;
6442
+ if (identity == null) {
6443
+ return {
6444
+ contacts: []
6445
+ };
6446
+ }
6447
+ const contacts = [
6448
+ ...this._spaceManager.spaces.values()
6449
+ ].flatMap((s) => [
6450
+ ...s.spaceState.members.values()
6451
+ ].map((m) => [
6452
+ s.key,
6453
+ m
6454
+ ])).reduce((acc, v) => {
6455
+ const [spaceKey, memberInfo] = v;
6456
+ if (memberInfo.key.equals(identity.identityKey)) {
6457
+ return acc;
6458
+ }
6459
+ const existing = acc.get(memberInfo.key);
6460
+ if (existing != null) {
6461
+ existing.profile ??= memberInfo.profile;
6462
+ existing.commonSpaces?.push(spaceKey);
6463
+ } else {
6464
+ acc.set(memberInfo.key, {
6465
+ identityKey: memberInfo.key,
6466
+ profile: memberInfo.profile,
6467
+ commonSpaces: [
6468
+ spaceKey
6469
+ ]
6470
+ });
6471
+ }
6472
+ return acc;
6473
+ }, new import_util15.ComplexMap(import_keys17.PublicKey.hash));
6474
+ return {
6475
+ contacts: [
6476
+ ...contacts.values()
6477
+ ]
6478
+ };
6479
+ }
6480
+ queryContacts() {
6481
+ const subscribedSpaceKeySet = new import_util15.ComplexSet(import_keys17.PublicKey.hash);
6482
+ return new import_codec_protobuf13.Stream(({ next, ctx }) => {
6483
+ const pushUpdateTask = new import_async21.UpdateScheduler(ctx, async () => {
6484
+ const contacts = await this.getContacts();
6485
+ next(contacts);
6486
+ }, {
6487
+ maxFrequency: 2
6488
+ });
6489
+ (0, import_async21.scheduleTask)(ctx, async () => {
6490
+ const subscriptions = new import_async21.EventSubscriptions();
6491
+ ctx.onDispose(() => subscriptions.clear());
6492
+ const subscribeToSpaceAndUpdate = () => {
6493
+ const oldSetSize = subscribedSpaceKeySet.size;
6494
+ for (const space of this._spaceManager.spaces.values()) {
6495
+ if (!subscribedSpaceKeySet.has(space.key)) {
6496
+ subscriptions.add(space.stateUpdate.on(ctx, () => pushUpdateTask.trigger()));
6497
+ subscribedSpaceKeySet.add(space.key);
6498
+ }
6499
+ }
6500
+ if (oldSetSize !== subscribedSpaceKeySet.size) {
6501
+ pushUpdateTask.trigger();
6502
+ }
6503
+ };
6504
+ const unsubscribe = (await this._dataSpaceManagerProvider()).updated.on(ctx, subscribeToSpaceAndUpdate);
6505
+ ctx.onDispose(unsubscribe);
6506
+ subscribeToSpaceAndUpdate();
6507
+ });
6508
+ });
6509
+ }
6070
6510
  };
6071
6511
  var LoggingServiceImpl = class {
6072
6512
  constructor() {
6073
- this._logs = new import_async21.Event();
6513
+ this._logs = new import_async22.Event();
6074
6514
  this._started = Date.now();
6075
- this._sessionId = import_keys17.PublicKey.random().toHex();
6515
+ this._sessionId = import_keys18.PublicKey.random().toHex();
6076
6516
  this._logProcessor = (_config, entry2) => {
6077
6517
  this._logs.emit(entry2);
6078
6518
  };
6079
6519
  }
6080
6520
  async open() {
6081
- import_log19.log.runtimeConfig.processors.push(this._logProcessor);
6521
+ import_log21.log.runtimeConfig.processors.push(this._logProcessor);
6082
6522
  }
6083
6523
  async close() {
6084
- const index = import_log19.log.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
6085
- import_log19.log.runtimeConfig.processors.splice(index, 1);
6524
+ const index = import_log21.log.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
6525
+ import_log21.log.runtimeConfig.processors.splice(index, 1);
6086
6526
  }
6087
6527
  async controlMetrics({ reset, record }) {
6088
6528
  if (reset) {
6089
- import_util14.tracer.clear();
6529
+ import_util16.tracer.clear();
6090
6530
  }
6091
6531
  if (record === true) {
6092
- import_util14.tracer.start();
6532
+ import_util16.tracer.start();
6093
6533
  } else if (record === false) {
6094
- import_util14.tracer.stop();
6534
+ import_util16.tracer.stop();
6095
6535
  }
6096
6536
  return {
6097
- recording: import_util14.tracer.recording
6537
+ recording: import_util16.tracer.recording
6098
6538
  };
6099
6539
  }
6100
6540
  /**
@@ -6102,13 +6542,13 @@ var LoggingServiceImpl = class {
6102
6542
  */
6103
6543
  queryMetrics({ interval = 5e3 }) {
6104
6544
  const getNumericalValues = (key) => {
6105
- const events = import_util14.tracer.get(key) ?? [];
6545
+ const events = import_util16.tracer.get(key) ?? [];
6106
6546
  return {
6107
6547
  key,
6108
- stats: (0, import_util14.numericalValues)(events, "duration")
6548
+ stats: (0, import_util16.numericalValues)(events, "duration")
6109
6549
  };
6110
6550
  };
6111
- return new import_codec_protobuf13.Stream(({ next }) => {
6551
+ return new import_codec_protobuf14.Stream(({ next }) => {
6112
6552
  const update = () => {
6113
6553
  const metrics = {
6114
6554
  timestamp: /* @__PURE__ */ new Date(),
@@ -6130,7 +6570,7 @@ var LoggingServiceImpl = class {
6130
6570
  });
6131
6571
  }
6132
6572
  queryLogs(request) {
6133
- return new import_codec_protobuf13.Stream(({ ctx, next }) => {
6573
+ return new import_codec_protobuf14.Stream(({ ctx, next }) => {
6134
6574
  const handler = (entry2) => {
6135
6575
  if (LOG_PROCESSING > 0) {
6136
6576
  return;
@@ -6143,7 +6583,7 @@ var LoggingServiceImpl = class {
6143
6583
  }
6144
6584
  const record = {
6145
6585
  ...entry2,
6146
- context: (0, import_util14.jsonify)((0, import_log19.getContextFromEntry)(entry2)),
6586
+ context: (0, import_util16.jsonify)((0, import_log21.getContextFromEntry)(entry2)),
6147
6587
  timestamp: /* @__PURE__ */ new Date(),
6148
6588
  meta: {
6149
6589
  // TODO(dmaretskyi): Fix proto.
@@ -6152,7 +6592,7 @@ var LoggingServiceImpl = class {
6152
6592
  scope: {
6153
6593
  hostSessionId: this._sessionId,
6154
6594
  uptimeSeconds: (Date.now() - this._started) / 1e3,
6155
- name: (0, import_util14.getDebugName)(entry2.meta?.S)
6595
+ name: (0, import_util16.getDebugName)(entry2.meta?.S)
6156
6596
  }
6157
6597
  }
6158
6598
  };
@@ -6190,7 +6630,7 @@ var NetworkServiceImpl = class {
6190
6630
  this.signalManager = signalManager;
6191
6631
  }
6192
6632
  queryStatus() {
6193
- return new import_codec_protobuf14.Stream(({ next }) => {
6633
+ return new import_codec_protobuf15.Stream(({ next }) => {
6194
6634
  const update = () => {
6195
6635
  next({
6196
6636
  swarm: this.networkManager.connectionState,
@@ -6233,7 +6673,7 @@ var SystemServiceImpl = class {
6233
6673
  const diagnostics = await this._getDiagnostics();
6234
6674
  return {
6235
6675
  timestamp: /* @__PURE__ */ new Date(),
6236
- diagnostics: JSON.parse(JSON.stringify(diagnostics, (0, import_util15.jsonKeyReplacer)({
6676
+ diagnostics: JSON.parse(JSON.stringify(diagnostics, (0, import_util17.jsonKeyReplacer)({
6237
6677
  truncate: keys === import_services21.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
6238
6678
  humanize: keys === import_services21.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
6239
6679
  })))
@@ -6247,7 +6687,7 @@ var SystemServiceImpl = class {
6247
6687
  }
6248
6688
  // TODO(burdon): Standardize interval option in stream request?
6249
6689
  queryStatus({ interval = 3e3 } = {}) {
6250
- return new import_codec_protobuf15.Stream(({ next }) => {
6690
+ return new import_codec_protobuf16.Stream(({ next }) => {
6251
6691
  const update = () => {
6252
6692
  next({
6253
6693
  status: this._getCurrentStatus()
@@ -6276,7 +6716,7 @@ function _ts_decorate8(decorators, target, key, desc) {
6276
6716
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6277
6717
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6278
6718
  }
6279
- var __dxlog_file22 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
6719
+ var __dxlog_file24 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
6280
6720
  var ClientServicesHost = class {
6281
6721
  constructor({
6282
6722
  config,
@@ -6309,7 +6749,10 @@ var ClientServicesHost = class {
6309
6749
  lockKey,
6310
6750
  onAcquire: () => {
6311
6751
  if (!this._opening) {
6312
- void this.open(new import_context16.Context());
6752
+ void this.open(new import_context15.Context(void 0, {
6753
+ F: __dxlog_file24,
6754
+ L: 121
6755
+ }));
6313
6756
  }
6314
6757
  },
6315
6758
  onRelease: () => this.close()
@@ -6364,25 +6807,25 @@ var ClientServicesHost = class {
6364
6807
  * Can only be called once.
6365
6808
  */
6366
6809
  initialize({ config, ...options }) {
6367
- (0, import_invariant19.invariant)(!this._open, "service host is open", {
6368
- F: __dxlog_file22,
6369
- L: 186,
6810
+ (0, import_invariant20.invariant)(!this._open, "service host is open", {
6811
+ F: __dxlog_file24,
6812
+ L: 187,
6370
6813
  S: this,
6371
6814
  A: [
6372
6815
  "!this._open",
6373
6816
  "'service host is open'"
6374
6817
  ]
6375
6818
  });
6376
- (0, import_log18.log)("initializing...", void 0, {
6377
- F: __dxlog_file22,
6378
- L: 187,
6819
+ (0, import_log20.log)("initializing...", void 0, {
6820
+ F: __dxlog_file24,
6821
+ L: 188,
6379
6822
  S: this,
6380
6823
  C: (f, a) => f(...a)
6381
6824
  });
6382
6825
  if (config) {
6383
- (0, import_invariant19.invariant)(!this._config, "config already set", {
6384
- F: __dxlog_file22,
6385
- L: 190,
6826
+ (0, import_invariant20.invariant)(!this._config, "config already set", {
6827
+ F: __dxlog_file24,
6828
+ L: 191,
6386
6829
  S: this,
6387
6830
  A: [
6388
6831
  "!this._config",
@@ -6395,9 +6838,9 @@ var ClientServicesHost = class {
6395
6838
  }
6396
6839
  }
6397
6840
  if (!options.signalManager) {
6398
- import_log18.log.warn("running signaling without telemetry metadata.", void 0, {
6399
- F: __dxlog_file22,
6400
- L: 198,
6841
+ import_log20.log.warn("running signaling without telemetry metadata.", void 0, {
6842
+ F: __dxlog_file24,
6843
+ L: 199,
6401
6844
  S: this,
6402
6845
  C: (f, a) => f(...a)
6403
6846
  });
@@ -6406,9 +6849,9 @@ var ClientServicesHost = class {
6406
6849
  iceServers: this._config?.get("runtime.services.ice")
6407
6850
  }), signalManager = new import_messaging.WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
6408
6851
  this._signalManager = signalManager;
6409
- (0, import_invariant19.invariant)(!this._networkManager, "network manager already set", {
6410
- F: __dxlog_file22,
6411
- L: 209,
6852
+ (0, import_invariant20.invariant)(!this._networkManager, "network manager already set", {
6853
+ F: __dxlog_file24,
6854
+ L: 210,
6412
6855
  S: this,
6413
6856
  A: [
6414
6857
  "!this._networkManager",
@@ -6420,9 +6863,9 @@ var ClientServicesHost = class {
6420
6863
  transportFactory,
6421
6864
  signalManager
6422
6865
  });
6423
- (0, import_log18.log)("initialized", void 0, {
6424
- F: __dxlog_file22,
6425
- L: 216,
6866
+ (0, import_log20.log)("initialized", void 0, {
6867
+ F: __dxlog_file24,
6868
+ L: 217,
6426
6869
  S: this,
6427
6870
  C: (f, a) => f(...a)
6428
6871
  });
@@ -6432,44 +6875,44 @@ var ClientServicesHost = class {
6432
6875
  return;
6433
6876
  }
6434
6877
  const traceId = import_keys15.PublicKey.random().toHex();
6435
- import_log18.log.trace("dxos.client-services.host.open", import_protocols15.trace.begin({
6878
+ import_log20.log.trace("dxos.client-services.host.open", import_protocols16.trace.begin({
6436
6879
  id: traceId
6437
6880
  }), {
6438
- F: __dxlog_file22,
6439
- L: 227,
6881
+ F: __dxlog_file24,
6882
+ L: 228,
6440
6883
  S: this,
6441
6884
  C: (f, a) => f(...a)
6442
6885
  });
6443
- (0, import_invariant19.invariant)(this._config, "config not set", {
6444
- F: __dxlog_file22,
6445
- L: 229,
6886
+ (0, import_invariant20.invariant)(this._config, "config not set", {
6887
+ F: __dxlog_file24,
6888
+ L: 230,
6446
6889
  S: this,
6447
6890
  A: [
6448
6891
  "this._config",
6449
6892
  "'config not set'"
6450
6893
  ]
6451
6894
  });
6452
- (0, import_invariant19.invariant)(this._storage, "storage not set", {
6453
- F: __dxlog_file22,
6454
- L: 230,
6895
+ (0, import_invariant20.invariant)(this._storage, "storage not set", {
6896
+ F: __dxlog_file24,
6897
+ L: 231,
6455
6898
  S: this,
6456
6899
  A: [
6457
6900
  "this._storage",
6458
6901
  "'storage not set'"
6459
6902
  ]
6460
6903
  });
6461
- (0, import_invariant19.invariant)(this._signalManager, "signal manager not set", {
6462
- F: __dxlog_file22,
6463
- L: 231,
6904
+ (0, import_invariant20.invariant)(this._signalManager, "signal manager not set", {
6905
+ F: __dxlog_file24,
6906
+ L: 232,
6464
6907
  S: this,
6465
6908
  A: [
6466
6909
  "this._signalManager",
6467
6910
  "'signal manager not set'"
6468
6911
  ]
6469
6912
  });
6470
- (0, import_invariant19.invariant)(this._networkManager, "network manager not set", {
6471
- F: __dxlog_file22,
6472
- L: 232,
6913
+ (0, import_invariant20.invariant)(this._networkManager, "network manager not set", {
6914
+ F: __dxlog_file24,
6915
+ L: 233,
6473
6916
  S: this,
6474
6917
  A: [
6475
6918
  "this._networkManager",
@@ -6477,11 +6920,11 @@ var ClientServicesHost = class {
6477
6920
  ]
6478
6921
  });
6479
6922
  this._opening = true;
6480
- (0, import_log18.log)("opening...", {
6923
+ (0, import_log20.log)("opening...", {
6481
6924
  lockKey: this._resourceLock?.lockKey
6482
6925
  }, {
6483
- F: __dxlog_file22,
6484
- L: 235,
6926
+ F: __dxlog_file24,
6927
+ L: 236,
6485
6928
  S: this,
6486
6929
  C: (f, a) => f(...a)
6487
6930
  });
@@ -6492,16 +6935,18 @@ var ClientServicesHost = class {
6492
6935
  await this._level.open();
6493
6936
  await this._loggingService.open();
6494
6937
  this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._runtimeParams);
6938
+ const dataSpaceManagerProvider = async () => {
6939
+ await this._serviceContext.initialized.wait();
6940
+ return this._serviceContext.dataSpaceManager;
6941
+ };
6495
6942
  const identityService = new IdentityServiceImpl(this._serviceContext.identityManager, this._serviceContext.keyring, () => this._serviceContext.dataSpaceManager, (params) => this._createIdentity(params), (profile) => this._serviceContext.broadcastProfileUpdate(profile));
6496
6943
  this._serviceRegistry.setServices({
6497
6944
  SystemService: this._systemService,
6498
6945
  IdentityService: identityService,
6946
+ ContactsService: new ContactsServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, dataSpaceManagerProvider),
6499
6947
  InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitationsManager),
6500
6948
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
6501
- SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, async () => {
6502
- await this._serviceContext.initialized.wait();
6503
- return this._serviceContext.dataSpaceManager;
6504
- }),
6949
+ SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, dataSpaceManagerProvider),
6505
6950
  DataService: this._serviceContext.echoHost.dataService,
6506
6951
  QueryService: this._serviceContext.echoHost.queryService,
6507
6952
  NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager, this._serviceContext.signalManager),
@@ -6531,19 +6976,19 @@ var ClientServicesHost = class {
6531
6976
  this._open = true;
6532
6977
  this._statusUpdate.emit();
6533
6978
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
6534
- (0, import_log18.log)("opened", {
6979
+ (0, import_log20.log)("opened", {
6535
6980
  deviceKey
6536
6981
  }, {
6537
- F: __dxlog_file22,
6538
- L: 314,
6982
+ F: __dxlog_file24,
6983
+ L: 322,
6539
6984
  S: this,
6540
6985
  C: (f, a) => f(...a)
6541
6986
  });
6542
- import_log18.log.trace("dxos.client-services.host.open", import_protocols15.trace.end({
6987
+ import_log20.log.trace("dxos.client-services.host.open", import_protocols16.trace.end({
6543
6988
  id: traceId
6544
6989
  }), {
6545
- F: __dxlog_file22,
6546
- L: 315,
6990
+ F: __dxlog_file24,
6991
+ L: 323,
6547
6992
  S: this,
6548
6993
  C: (f, a) => f(...a)
6549
6994
  });
@@ -6553,11 +6998,11 @@ var ClientServicesHost = class {
6553
6998
  return;
6554
6999
  }
6555
7000
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
6556
- (0, import_log18.log)("closing...", {
7001
+ (0, import_log20.log)("closing...", {
6557
7002
  deviceKey
6558
7003
  }, {
6559
- F: __dxlog_file22,
6560
- L: 326,
7004
+ F: __dxlog_file24,
7005
+ L: 334,
6561
7006
  S: this,
6562
7007
  C: (f, a) => f(...a)
6563
7008
  });
@@ -6571,44 +7016,44 @@ var ClientServicesHost = class {
6571
7016
  await this._level?.close();
6572
7017
  this._open = false;
6573
7018
  this._statusUpdate.emit();
6574
- (0, import_log18.log)("closed", {
7019
+ (0, import_log20.log)("closed", {
6575
7020
  deviceKey
6576
7021
  }, {
6577
- F: __dxlog_file22,
6578
- L: 335,
7022
+ F: __dxlog_file24,
7023
+ L: 343,
6579
7024
  S: this,
6580
7025
  C: (f, a) => f(...a)
6581
7026
  });
6582
7027
  }
6583
7028
  async reset() {
6584
7029
  const traceId = import_keys15.PublicKey.random().toHex();
6585
- import_log18.log.trace("dxos.sdk.client-services-host.reset", import_protocols15.trace.begin({
7030
+ import_log20.log.trace("dxos.sdk.client-services-host.reset", import_protocols16.trace.begin({
6586
7031
  id: traceId
6587
7032
  }), {
6588
- F: __dxlog_file22,
6589
- L: 340,
7033
+ F: __dxlog_file24,
7034
+ L: 348,
6590
7035
  S: this,
6591
7036
  C: (f, a) => f(...a)
6592
7037
  });
6593
- import_log18.log.info("resetting...", void 0, {
6594
- F: __dxlog_file22,
6595
- L: 342,
7038
+ import_log20.log.info("resetting...", void 0, {
7039
+ F: __dxlog_file24,
7040
+ L: 350,
6596
7041
  S: this,
6597
7042
  C: (f, a) => f(...a)
6598
7043
  });
6599
7044
  await this._serviceContext?.close();
6600
7045
  await this._storage.reset();
6601
- import_log18.log.info("reset", void 0, {
6602
- F: __dxlog_file22,
6603
- L: 345,
7046
+ import_log20.log.info("reset", void 0, {
7047
+ F: __dxlog_file24,
7048
+ L: 353,
6604
7049
  S: this,
6605
7050
  C: (f, a) => f(...a)
6606
7051
  });
6607
- import_log18.log.trace("dxos.sdk.client-services-host.reset", import_protocols15.trace.end({
7052
+ import_log20.log.trace("dxos.sdk.client-services-host.reset", import_protocols16.trace.end({
6608
7053
  id: traceId
6609
7054
  }), {
6610
- F: __dxlog_file22,
6611
- L: 346,
7055
+ F: __dxlog_file24,
7056
+ L: 354,
6612
7057
  S: this,
6613
7058
  C: (f, a) => f(...a)
6614
7059
  });
@@ -6667,7 +7112,11 @@ ClientServicesHost = _ts_decorate8([
6667
7112
  createDiagnostics,
6668
7113
  createLevel,
6669
7114
  createStorageObjects,
7115
+ decodeProfileArchive,
7116
+ encodeProfileArchive,
7117
+ exportProfileData,
6670
7118
  getNetworkPeers,
7119
+ importProfileData,
6671
7120
  isLocked,
6672
7121
  subscribeToFeedBlocks,
6673
7122
  subscribeToFeeds,
@@ -6677,4 +7126,4 @@ ClientServicesHost = _ts_decorate8([
6677
7126
  subscribeToSpaces,
6678
7127
  subscribeToSwarmInfo
6679
7128
  });
6680
- //# sourceMappingURL=chunk-MHRJ6WZU.cjs.map
7129
+ //# sourceMappingURL=chunk-E6HB26ZB.cjs.map