@dxos/client-services 0.4.10-main.4c8c73c → 0.4.10-main.4d26ea7

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 (68) hide show
  1. package/dist/lib/browser/{chunk-F4LOSBRJ.mjs → chunk-X462P3GQ.mjs} +425 -416
  2. package/dist/lib/browser/chunk-X462P3GQ.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +6 -4
  4. package/dist/lib/browser/index.mjs.map +3 -3
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +131 -116
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/{chunk-IPO3WM44.cjs → chunk-LE3INNLG.cjs} +527 -514
  9. package/dist/lib/node/chunk-LE3INNLG.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +48 -46
  11. package/dist/lib/node/index.cjs.map +3 -3
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/packlets/testing/index.cjs +130 -118
  14. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  15. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  16. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +3 -1
  17. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
  18. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +6 -1
  19. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
  20. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +4 -2
  21. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  22. package/dist/types/src/packlets/invitations/invitations-manager.d.ts +9 -7
  23. package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -1
  24. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  25. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +2 -1
  26. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  27. package/dist/types/src/packlets/services/service-context.d.ts +4 -6
  28. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  29. package/dist/types/src/packlets/services/service-host.d.ts +0 -1
  30. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  31. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +8 -3
  32. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  33. package/dist/types/src/packlets/spaces/data-space.d.ts +4 -3
  34. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  35. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  36. package/dist/types/src/packlets/testing/test-builder.d.ts +7 -3
  37. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  38. package/dist/types/src/packlets/vault/worker-runtime.d.ts.map +1 -1
  39. package/dist/types/src/version.d.ts +1 -1
  40. package/package.json +34 -34
  41. package/src/packlets/identity/identity-manager.ts +1 -0
  42. package/src/packlets/identity/identity.test.ts +3 -0
  43. package/src/packlets/invitations/device-invitation-protocol.ts +6 -1
  44. package/src/packlets/invitations/invitation-protocol.ts +7 -1
  45. package/src/packlets/invitations/invitations-handler.ts +10 -71
  46. package/src/packlets/invitations/invitations-manager.ts +114 -40
  47. package/src/packlets/invitations/invitations-service.ts +4 -2
  48. package/src/packlets/invitations/space-invitation-protocol.ts +45 -3
  49. package/src/packlets/services/automerge-host.test.ts +1 -1
  50. package/src/packlets/services/service-context.test.ts +3 -3
  51. package/src/packlets/services/service-context.ts +12 -25
  52. package/src/packlets/services/service-host.test.ts +6 -0
  53. package/src/packlets/services/service-host.ts +5 -21
  54. package/src/packlets/spaces/data-space-manager.test.ts +4 -4
  55. package/src/packlets/spaces/data-space-manager.ts +56 -13
  56. package/src/packlets/spaces/data-space.ts +14 -19
  57. package/src/packlets/testing/invitation-utils.ts +100 -97
  58. package/src/packlets/testing/test-builder.ts +27 -14
  59. package/src/packlets/vault/worker-runtime.ts +3 -1
  60. package/src/version.ts +1 -1
  61. package/dist/lib/browser/chunk-F4LOSBRJ.mjs.map +0 -7
  62. package/dist/lib/node/chunk-IPO3WM44.cjs.map +0 -7
  63. package/dist/types/src/packlets/indexing/index.d.ts +0 -2
  64. package/dist/types/src/packlets/indexing/index.d.ts.map +0 -1
  65. package/dist/types/src/packlets/indexing/util.d.ts +0 -16
  66. package/dist/types/src/packlets/indexing/util.d.ts.map +0 -1
  67. package/src/packlets/indexing/index.ts +0 -5
  68. package/src/packlets/indexing/util.ts +0 -96
@@ -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_IPO3WM44_exports = {};
30
- __export(chunk_IPO3WM44_exports, {
29
+ var chunk_LE3INNLG_exports = {};
30
+ __export(chunk_LE3INNLG_exports, {
31
31
  ClientRpcServer: () => ClientRpcServer,
32
32
  ClientServicesHost: () => ClientServicesHost,
33
33
  ClientServicesProviderResource: () => ClientServicesProviderResource,
@@ -66,7 +66,7 @@ __export(chunk_IPO3WM44_exports, {
66
66
  subscribeToSpaces: () => subscribeToSpaces,
67
67
  subscribeToSwarmInfo: () => subscribeToSwarmInfo
68
68
  });
69
- module.exports = __toCommonJS(chunk_IPO3WM44_exports);
69
+ module.exports = __toCommonJS(chunk_LE3INNLG_exports);
70
70
  var import_async = require("@dxos/async");
71
71
  var import_codec_protobuf = require("@dxos/codec-protobuf");
72
72
  var import_feed_store = require("@dxos/feed-store");
@@ -120,7 +120,6 @@ var import_services2 = require("@dxos/protocols/proto/dxos/client/services");
120
120
  var import_async7 = require("@dxos/async");
121
121
  var import_client_protocol2 = require("@dxos/client-protocol");
122
122
  var import_context4 = require("@dxos/context");
123
- var import_credentials7 = require("@dxos/credentials");
124
123
  var import_crypto = require("@dxos/crypto");
125
124
  var import_invariant5 = require("@dxos/invariant");
126
125
  var import_keys5 = require("@dxos/keys");
@@ -141,59 +140,65 @@ var import_invitations2 = require("@dxos/protocols/proto/dxos/halo/invitations")
141
140
  var import_teleport = require("@dxos/teleport");
142
141
  var import_codec_protobuf8 = require("@dxos/codec-protobuf");
143
142
  var import_services5 = require("@dxos/protocols/proto/dxos/client/services");
144
- var import_credentials8 = require("@dxos/credentials");
143
+ var import_credentials7 = require("@dxos/credentials");
145
144
  var import_feed_store3 = require("@dxos/feed-store");
146
145
  var import_invariant7 = require("@dxos/invariant");
147
146
  var import_log6 = require("@dxos/log");
148
147
  var import_protocols6 = require("@dxos/protocols");
149
148
  var import_services6 = require("@dxos/protocols/proto/dxos/client/services");
149
+ var import_credentials8 = require("@dxos/protocols/proto/dxos/halo/credentials");
150
150
  var import_async9 = require("@dxos/async");
151
+ var import_client_protocol3 = require("@dxos/client-protocol");
152
+ var import_context6 = require("@dxos/context");
153
+ var import_credentials9 = require("@dxos/credentials");
151
154
  var import_echo_pipeline = require("@dxos/echo-pipeline");
152
155
  var import_invariant8 = require("@dxos/invariant");
156
+ var import_keys7 = require("@dxos/keys");
153
157
  var import_log7 = require("@dxos/log");
158
+ var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
154
159
  var import_codec_protobuf9 = require("@dxos/codec-protobuf");
155
160
  var import_debug2 = require("@dxos/debug");
156
161
  var import_rpc = require("@dxos/rpc");
157
162
  var import_tracing3 = require("@dxos/tracing");
158
163
  var import_async10 = require("@dxos/async");
159
- var import_client_protocol3 = require("@dxos/client-protocol");
160
- var import_context6 = require("@dxos/context");
164
+ var import_client_protocol4 = require("@dxos/client-protocol");
165
+ var import_context7 = require("@dxos/context");
161
166
  var import_debug3 = require("@dxos/debug");
162
- var import_echo_db = require("@dxos/echo-db");
163
167
  var import_echo_pipeline2 = require("@dxos/echo-pipeline");
164
168
  var import_echo_pipeline3 = require("@dxos/echo-pipeline");
169
+ var import_echo_schema = require("@dxos/echo-schema");
165
170
  var import_invariant9 = require("@dxos/invariant");
166
- var import_keys7 = require("@dxos/keys");
171
+ var import_keys8 = require("@dxos/keys");
167
172
  var import_log8 = require("@dxos/log");
168
173
  var import_protocols7 = require("@dxos/protocols");
169
- var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
170
- var import_credentials9 = require("@dxos/protocols/proto/dxos/halo/credentials");
174
+ var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
175
+ var import_credentials10 = require("@dxos/protocols/proto/dxos/halo/credentials");
171
176
  var import_timeframe2 = require("@dxos/timeframe");
172
177
  var import_tracing4 = require("@dxos/tracing");
173
178
  var import_util4 = require("@dxos/util");
174
179
  var import_async11 = require("@dxos/async");
175
- var import_credentials10 = require("@dxos/credentials");
180
+ var import_credentials11 = require("@dxos/credentials");
176
181
  var import_async12 = require("@dxos/async");
177
- var import_context7 = require("@dxos/context");
182
+ var import_context8 = require("@dxos/context");
178
183
  var import_invariant10 = require("@dxos/invariant");
179
- var import_keys8 = require("@dxos/keys");
184
+ var import_keys9 = require("@dxos/keys");
180
185
  var import_log9 = require("@dxos/log");
181
186
  var import_protocols8 = require("@dxos/protocols");
182
187
  var import_teleport2 = require("@dxos/teleport");
183
188
  var import_util5 = require("@dxos/util");
184
189
  var import_async13 = require("@dxos/async");
185
- var import_context8 = require("@dxos/context");
186
- var import_credentials11 = require("@dxos/credentials");
190
+ var import_context9 = require("@dxos/context");
191
+ var import_credentials12 = require("@dxos/credentials");
187
192
  var import_invariant11 = require("@dxos/invariant");
188
- var import_keys9 = require("@dxos/keys");
193
+ var import_keys10 = require("@dxos/keys");
189
194
  var import_log10 = require("@dxos/log");
190
195
  var import_protocols9 = require("@dxos/protocols");
191
- var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
196
+ var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
192
197
  var import_teleport_extension_gossip2 = require("@dxos/teleport-extension-gossip");
193
198
  var import_util6 = require("@dxos/util");
194
- var import_credentials12 = require("@dxos/credentials");
199
+ var import_credentials13 = require("@dxos/credentials");
195
200
  var import_debug4 = require("@dxos/debug");
196
- var import_credentials13 = require("@dxos/protocols/proto/dxos/halo/credentials");
201
+ var import_credentials14 = require("@dxos/protocols/proto/dxos/halo/credentials");
197
202
  var import_timeframe3 = require("@dxos/timeframe");
198
203
  var import_async14 = require("@dxos/async");
199
204
  var import_codec_protobuf10 = require("@dxos/codec-protobuf");
@@ -201,79 +206,76 @@ var import_debug5 = require("@dxos/debug");
201
206
  var import_invariant12 = require("@dxos/invariant");
202
207
  var import_log11 = require("@dxos/log");
203
208
  var import_protocols10 = require("@dxos/protocols");
204
- var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
209
+ var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
205
210
  var import_async15 = require("@dxos/async");
206
- var import_context9 = require("@dxos/context");
207
- var import_credentials14 = require("@dxos/credentials");
211
+ var import_context10 = require("@dxos/context");
212
+ var import_credentials15 = require("@dxos/credentials");
208
213
  var import_debug6 = require("@dxos/debug");
214
+ var import_echo_db = require("@dxos/echo-db");
209
215
  var import_echo_pipeline4 = require("@dxos/echo-pipeline");
210
216
  var import_feed_store4 = require("@dxos/feed-store");
211
- var import_indexing = require("@dxos/indexing");
212
217
  var import_invariant13 = require("@dxos/invariant");
213
218
  var import_keyring = require("@dxos/keyring");
214
- var import_keys10 = require("@dxos/keys");
219
+ var import_keys11 = require("@dxos/keys");
215
220
  var import_log12 = require("@dxos/log");
216
221
  var import_protocols11 = require("@dxos/protocols");
217
- var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
222
+ var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
218
223
  var import_teleport_extension_object_sync = require("@dxos/teleport-extension-object-sync");
219
224
  var import_tracing5 = require("@dxos/tracing");
220
225
  var import_util7 = require("@dxos/util");
221
- var import_automerge = require("@dxos/automerge/automerge");
222
- var import_protocols12 = require("@dxos/protocols");
223
226
  var import_codec_protobuf11 = require("@dxos/codec-protobuf");
224
- var import_credentials15 = require("@dxos/credentials");
227
+ var import_credentials16 = require("@dxos/credentials");
225
228
  var import_invariant14 = require("@dxos/invariant");
226
- var import_protocols13 = require("@dxos/protocols");
227
- var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
228
- var import_tracing6 = require("@dxos/tracing");
229
+ var import_protocols12 = require("@dxos/protocols");
229
230
  var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
230
- var import_config = require("@dxos/config");
231
+ var import_tracing6 = require("@dxos/tracing");
231
232
  var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
233
+ var import_config = require("@dxos/config");
234
+ var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
232
235
  var import_tracing7 = require("@dxos/tracing");
233
236
  var import_util8 = require("@dxos/util");
234
237
  var import_async16 = require("@dxos/async");
235
- var import_client_protocol4 = require("@dxos/client-protocol");
236
- var import_context10 = require("@dxos/context");
238
+ var import_client_protocol5 = require("@dxos/client-protocol");
239
+ var import_context11 = require("@dxos/context");
237
240
  var import_echo_pipeline5 = require("@dxos/echo-pipeline");
238
- var import_echo_schema = require("@dxos/echo-schema");
239
- var import_indexing2 = require("@dxos/indexing");
241
+ var import_echo_schema2 = require("@dxos/echo-schema");
240
242
  var import_invariant15 = require("@dxos/invariant");
241
- var import_keys11 = require("@dxos/keys");
243
+ var import_keys12 = require("@dxos/keys");
242
244
  var import_log13 = require("@dxos/log");
243
245
  var import_messaging = require("@dxos/messaging");
244
246
  var import_network_manager2 = require("@dxos/network-manager");
245
- var import_protocols14 = require("@dxos/protocols");
246
- var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
247
+ var import_protocols13 = require("@dxos/protocols");
248
+ var import_services15 = require("@dxos/protocols/proto/dxos/client/services");
247
249
  var import_tracing8 = require("@dxos/tracing");
248
250
  var import_util9 = require("@dxos/util");
249
251
  var import_websocket_rpc = require("@dxos/websocket-rpc");
250
252
  var import_async17 = require("@dxos/async");
251
253
  var import_codec_protobuf12 = require("@dxos/codec-protobuf");
252
254
  var import_invariant16 = require("@dxos/invariant");
253
- var import_services15 = require("@dxos/protocols/proto/dxos/client/services");
255
+ var import_services16 = require("@dxos/protocols/proto/dxos/client/services");
254
256
  var import_invariant17 = require("@dxos/invariant");
255
257
  var import_lock_file = require("@dxos/lock-file");
256
258
  var import_log14 = require("@dxos/log");
257
259
  var import_async18 = require("@dxos/async");
258
260
  var import_codec_protobuf13 = require("@dxos/codec-protobuf");
259
- var import_keys12 = require("@dxos/keys");
261
+ var import_keys13 = require("@dxos/keys");
260
262
  var import_log15 = require("@dxos/log");
261
- var import_services16 = require("@dxos/protocols/proto/dxos/client/services");
263
+ var import_services17 = require("@dxos/protocols/proto/dxos/client/services");
262
264
  var import_util10 = require("@dxos/util");
263
265
  var import_codec_protobuf14 = require("@dxos/codec-protobuf");
264
- var import_protocols15 = require("@dxos/protocols");
266
+ var import_protocols14 = require("@dxos/protocols");
265
267
  var import_config2 = require("@dxos/protocols/proto/dxos/config");
266
268
  var import_random_access_storage = require("@dxos/random-access-storage");
267
- var import_client_protocol5 = require("@dxos/client-protocol");
269
+ var import_client_protocol6 = require("@dxos/client-protocol");
268
270
  var import_config3 = require("@dxos/protocols/proto/dxos/config");
269
271
  var import_util11 = require("@dxos/util");
270
272
  var import_level = require("level");
271
273
  var import_node_path = __toESM(require("node:path"));
272
- var import_keys13 = require("@dxos/keys");
274
+ var import_keys14 = require("@dxos/keys");
273
275
  var import_codec_protobuf15 = require("@dxos/codec-protobuf");
274
- var import_services17 = require("@dxos/protocols/proto/dxos/client/services");
276
+ var import_services18 = require("@dxos/protocols/proto/dxos/client/services");
275
277
  var import_util12 = require("@dxos/util");
276
- var import_keys14 = require("@dxos/keys");
278
+ var import_keys15 = require("@dxos/keys");
277
279
  var import_util13 = require("@dxos/util");
278
280
  var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
279
281
  return new import_codec_protobuf.Stream(({ next }) => {
@@ -1292,7 +1294,9 @@ var IdentityManager = class {
1292
1294
  C: (f, a) => f(...a)
1293
1295
  });
1294
1296
  },
1295
- memberKey: identityKey
1297
+ memberKey: identityKey,
1298
+ onDelegatedInvitationStatusChange: async () => {
1299
+ }
1296
1300
  });
1297
1301
  }
1298
1302
  };
@@ -1389,10 +1393,13 @@ var DeviceInvitationProtocol = class {
1389
1393
  kind: import_services2.Invitation.Kind.DEVICE
1390
1394
  };
1391
1395
  }
1392
- async admit(request) {
1396
+ async delegate(invitation) {
1397
+ throw new Error("delegation not supported");
1398
+ }
1399
+ async admit(_, request) {
1393
1400
  (0, import_invariant4.invariant)(request.device, void 0, {
1394
1401
  F: __dxlog_file5,
1395
- L: 37,
1402
+ L: 42,
1396
1403
  S: this,
1397
1404
  A: [
1398
1405
  "request.device",
@@ -1438,7 +1445,7 @@ var DeviceInvitationProtocol = class {
1438
1445
  async accept(response, request) {
1439
1446
  (0, import_invariant4.invariant)(response.device, void 0, {
1440
1447
  F: __dxlog_file5,
1441
- L: 82,
1448
+ L: 87,
1442
1449
  S: this,
1443
1450
  A: [
1444
1451
  "response.device",
@@ -1448,7 +1455,7 @@ var DeviceInvitationProtocol = class {
1448
1455
  const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
1449
1456
  (0, import_invariant4.invariant)(request.device, void 0, {
1450
1457
  F: __dxlog_file5,
1451
- L: 85,
1458
+ L: 90,
1452
1459
  S: this,
1453
1460
  A: [
1454
1461
  "request.device",
@@ -1823,51 +1830,7 @@ var InvitationsHandler = class {
1823
1830
  constructor(_networkManager) {
1824
1831
  this._networkManager = _networkManager;
1825
1832
  }
1826
- createInvitation(protocol, options) {
1827
- const { invitationId = import_keys5.PublicKey.random().toHex(), type = import_services3.Invitation.Type.INTERACTIVE, authMethod = import_services3.Invitation.AuthMethod.SHARED_SECRET, state = import_services3.Invitation.State.INIT, timeout = import_client_protocol2.INVITATION_TIMEOUT, swarmKey = import_keys5.PublicKey.random(), persistent = options?.authMethod !== import_services3.Invitation.AuthMethod.KNOWN_PUBLIC_KEY, created = /* @__PURE__ */ new Date(), guestKeypair = void 0, lifetime = 86400, multiUse = false } = options ?? {};
1828
- const authCode = options?.authCode ?? (authMethod === import_services3.Invitation.AuthMethod.SHARED_SECRET ? (0, import_credentials7.generatePasscode)(import_client_protocol2.AUTHENTICATION_CODE_LENGTH) : void 0);
1829
- (0, import_invariant5.invariant)(protocol, void 0, {
1830
- F: __dxlog_file7,
1831
- L: 87,
1832
- S: this,
1833
- A: [
1834
- "protocol",
1835
- ""
1836
- ]
1837
- });
1838
- const invitation = {
1839
- invitationId,
1840
- type,
1841
- authMethod,
1842
- state,
1843
- swarmKey,
1844
- authCode,
1845
- timeout,
1846
- persistent: persistent && type !== import_services3.Invitation.Type.DELEGATED,
1847
- guestKeypair: guestKeypair ?? (authMethod === import_services3.Invitation.AuthMethod.KNOWN_PUBLIC_KEY ? createAdmissionKeypair() : void 0),
1848
- created,
1849
- lifetime,
1850
- multiUse,
1851
- ...protocol.getInvitationContext()
1852
- };
1853
- const stream = new import_async7.PushStream();
1854
- const ctx = new import_context4.Context({
1855
- onError: (err) => {
1856
- stream.error(err);
1857
- void ctx.dispose();
1858
- }
1859
- });
1860
- ctx.onDispose(() => {
1861
- (0, import_log4.log)("complete", {
1862
- ...protocol.toJSON()
1863
- }, {
1864
- F: __dxlog_file7,
1865
- L: 115,
1866
- S: this,
1867
- C: (f, a) => f(...a)
1868
- });
1869
- stream.complete();
1870
- });
1833
+ handleInvitationFlow(ctx, stream, protocol, invitation) {
1871
1834
  const createExtension = () => {
1872
1835
  const extension = new InvitationHostExtension({
1873
1836
  onStateUpdate: (invitation2) => {
@@ -1876,8 +1839,8 @@ var InvitationsHandler = class {
1876
1839
  state: import_services3.Invitation.State.READY_FOR_AUTHENTICATION
1877
1840
  });
1878
1841
  },
1879
- resolveInvitation: async ({ invitationId: invitationId2 }) => {
1880
- if (invitationId2 && invitationId2 !== invitation.invitationId) {
1842
+ resolveInvitation: async ({ invitationId }) => {
1843
+ if (invitationId && invitationId !== invitation.invitationId) {
1881
1844
  return void 0;
1882
1845
  }
1883
1846
  return invitation;
@@ -1887,14 +1850,14 @@ var InvitationsHandler = class {
1887
1850
  const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
1888
1851
  (0, import_invariant5.invariant)(deviceKey, void 0, {
1889
1852
  F: __dxlog_file7,
1890
- L: 136,
1853
+ L: 87,
1891
1854
  S: this,
1892
1855
  A: [
1893
1856
  "deviceKey",
1894
1857
  ""
1895
1858
  ]
1896
1859
  });
1897
- const admissionResponse = await protocol.admit(admissionRequest, extension.guestProfile);
1860
+ const admissionResponse = await protocol.admit(invitation, admissionRequest, extension.guestProfile);
1898
1861
  extension.completedTrigger.wake(deviceKey);
1899
1862
  return admissionResponse;
1900
1863
  } catch (err) {
@@ -1910,7 +1873,7 @@ var InvitationsHandler = class {
1910
1873
  id: traceId
1911
1874
  }), {
1912
1875
  F: __dxlog_file7,
1913
- L: 154,
1876
+ L: 105,
1914
1877
  S: this,
1915
1878
  C: (f, a) => f(...a)
1916
1879
  });
@@ -1918,7 +1881,7 @@ var InvitationsHandler = class {
1918
1881
  ...protocol.toJSON()
1919
1882
  }, {
1920
1883
  F: __dxlog_file7,
1921
- L: 155,
1884
+ L: 106,
1922
1885
  S: this,
1923
1886
  C: (f, a) => f(...a)
1924
1887
  });
@@ -1927,14 +1890,14 @@ var InvitationsHandler = class {
1927
1890
  state: import_services3.Invitation.State.CONNECTED
1928
1891
  });
1929
1892
  const deviceKey = await extension.completedTrigger.wait({
1930
- timeout
1893
+ timeout: invitation.timeout
1931
1894
  });
1932
1895
  (0, import_log4.log)("admitted guest", {
1933
1896
  guest: deviceKey,
1934
1897
  ...protocol.toJSON()
1935
1898
  }, {
1936
1899
  F: __dxlog_file7,
1937
- L: 158,
1900
+ L: 109,
1938
1901
  S: this,
1939
1902
  C: (f, a) => f(...a)
1940
1903
  });
@@ -1946,7 +1909,7 @@ var InvitationsHandler = class {
1946
1909
  id: traceId
1947
1910
  }), {
1948
1911
  F: __dxlog_file7,
1949
- L: 160,
1912
+ L: 111,
1950
1913
  S: this,
1951
1914
  C: (f, a) => f(...a)
1952
1915
  });
@@ -1956,7 +1919,7 @@ var InvitationsHandler = class {
1956
1919
  ...protocol.toJSON()
1957
1920
  }, {
1958
1921
  F: __dxlog_file7,
1959
- L: 163,
1922
+ L: 114,
1960
1923
  S: this,
1961
1924
  C: (f, a) => f(...a)
1962
1925
  });
@@ -1967,7 +1930,7 @@ var InvitationsHandler = class {
1967
1930
  } else {
1968
1931
  import_log4.log.error("failed", err, {
1969
1932
  F: __dxlog_file7,
1970
- L: 166,
1933
+ L: 117,
1971
1934
  S: this,
1972
1935
  C: (f, a) => f(...a)
1973
1936
  });
@@ -1978,12 +1941,12 @@ var InvitationsHandler = class {
1978
1941
  error: err
1979
1942
  }), {
1980
1943
  F: __dxlog_file7,
1981
- L: 169,
1944
+ L: 120,
1982
1945
  S: this,
1983
1946
  C: (f, a) => f(...a)
1984
1947
  });
1985
1948
  } finally {
1986
- if (!multiUse) {
1949
+ if (!invitation.multiUse) {
1987
1950
  await swarmConnection.close();
1988
1951
  await ctx.dispose();
1989
1952
  }
@@ -1999,7 +1962,7 @@ var InvitationsHandler = class {
1999
1962
  ...protocol.toJSON()
2000
1963
  }, {
2001
1964
  F: __dxlog_file7,
2002
- L: 184,
1965
+ L: 135,
2003
1966
  S: this,
2004
1967
  C: (f, a) => f(...a)
2005
1968
  });
@@ -2010,7 +1973,7 @@ var InvitationsHandler = class {
2010
1973
  } else {
2011
1974
  import_log4.log.error("failed", err, {
2012
1975
  F: __dxlog_file7,
2013
- L: 187,
1976
+ L: 138,
2014
1977
  S: this,
2015
1978
  C: (f, a) => f(...a)
2016
1979
  });
@@ -2024,7 +1987,7 @@ var InvitationsHandler = class {
2024
1987
  if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
2025
1988
  import_log4.log.warn("invitation has already expired", void 0, {
2026
1989
  F: __dxlog_file7,
2027
- L: 198,
1990
+ L: 149,
2028
1991
  S: this,
2029
1992
  C: (f, a) => f(...a)
2030
1993
  });
@@ -2058,24 +2021,12 @@ var InvitationsHandler = class {
2058
2021
  state: import_services3.Invitation.State.CONNECTING
2059
2022
  });
2060
2023
  });
2061
- const observable = new import_client_protocol2.CancellableInvitation({
2062
- initialInvitation: invitation,
2063
- subscriber: stream.observable,
2064
- onCancel: async () => {
2065
- stream.next({
2066
- ...invitation,
2067
- state: import_services3.Invitation.State.CANCELLED
2068
- });
2069
- await ctx.dispose();
2070
- }
2071
- });
2072
- return observable;
2073
2024
  }
2074
2025
  acceptInvitation(protocol, invitation, deviceProfile) {
2075
2026
  const { timeout = import_client_protocol2.INVITATION_TIMEOUT } = invitation;
2076
2027
  (0, import_invariant5.invariant)(protocol, void 0, {
2077
2028
  F: __dxlog_file7,
2078
- L: 252,
2029
+ L: 191,
2079
2030
  S: this,
2080
2031
  A: [
2081
2032
  "protocol",
@@ -2085,7 +2036,7 @@ var InvitationsHandler = class {
2085
2036
  if (deviceProfile) {
2086
2037
  (0, import_invariant5.invariant)(invitation.kind === import_services3.Invitation.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
2087
2038
  F: __dxlog_file7,
2088
- L: 255,
2039
+ L: 194,
2089
2040
  S: this,
2090
2041
  A: [
2091
2042
  "invitation.kind === Invitation.Kind.DEVICE",
@@ -2100,7 +2051,7 @@ var InvitationsHandler = class {
2100
2051
  const setState = (newData) => {
2101
2052
  (0, import_invariant5.invariant)(newData.state !== void 0, void 0, {
2102
2053
  F: __dxlog_file7,
2103
- L: 266,
2054
+ L: 205,
2104
2055
  S: this,
2105
2056
  A: [
2106
2057
  "newData.state !== undefined",
@@ -2120,7 +2071,7 @@ var InvitationsHandler = class {
2120
2071
  ...protocol.toJSON()
2121
2072
  }, {
2122
2073
  F: __dxlog_file7,
2123
- L: 274,
2074
+ L: 213,
2124
2075
  S: this,
2125
2076
  C: (f, a) => f(...a)
2126
2077
  });
@@ -2130,7 +2081,7 @@ var InvitationsHandler = class {
2130
2081
  } else {
2131
2082
  import_log4.log.warn("auth failed", err, {
2132
2083
  F: __dxlog_file7,
2133
- L: 277,
2084
+ L: 216,
2134
2085
  S: this,
2135
2086
  C: (f, a) => f(...a)
2136
2087
  });
@@ -2144,7 +2095,7 @@ var InvitationsHandler = class {
2144
2095
  ...protocol.toJSON()
2145
2096
  }, {
2146
2097
  F: __dxlog_file7,
2147
- L: 285,
2098
+ L: 224,
2148
2099
  S: this,
2149
2100
  C: (f, a) => f(...a)
2150
2101
  });
@@ -2159,7 +2110,7 @@ var InvitationsHandler = class {
2159
2110
  currentState
2160
2111
  }, {
2161
2112
  F: __dxlog_file7,
2162
- L: 295,
2113
+ L: 234,
2163
2114
  S: this,
2164
2115
  C: (f, a) => f(...a)
2165
2116
  });
@@ -2174,7 +2125,7 @@ var InvitationsHandler = class {
2174
2125
  id: traceId
2175
2126
  }), {
2176
2127
  F: __dxlog_file7,
2177
- L: 304,
2128
+ L: 243,
2178
2129
  S: this,
2179
2130
  C: (f, a) => f(...a)
2180
2131
  });
@@ -2186,7 +2137,7 @@ var InvitationsHandler = class {
2186
2137
  ...protocol.toJSON()
2187
2138
  }, {
2188
2139
  F: __dxlog_file7,
2189
- L: 312,
2140
+ L: 251,
2190
2141
  S: this,
2191
2142
  C: (f, a) => f(...a)
2192
2143
  });
@@ -2197,7 +2148,7 @@ var InvitationsHandler = class {
2197
2148
  ...protocol.toJSON()
2198
2149
  }, {
2199
2150
  F: __dxlog_file7,
2200
- L: 316,
2151
+ L: 255,
2201
2152
  S: this,
2202
2153
  C: (f, a) => f(...a)
2203
2154
  });
@@ -2207,7 +2158,7 @@ var InvitationsHandler = class {
2207
2158
  response: introductionResponse
2208
2159
  }, {
2209
2160
  F: __dxlog_file7,
2210
- L: 320,
2161
+ L: 259,
2211
2162
  S: this,
2212
2163
  C: (f, a) => f(...a)
2213
2164
  });
@@ -2228,7 +2179,7 @@ var InvitationsHandler = class {
2228
2179
  ...protocol.toJSON()
2229
2180
  }, {
2230
2181
  F: __dxlog_file7,
2231
- L: 336,
2182
+ L: 275,
2232
2183
  S: this,
2233
2184
  C: (f, a) => f(...a)
2234
2185
  });
@@ -2240,7 +2191,7 @@ var InvitationsHandler = class {
2240
2191
  ...protocol.toJSON()
2241
2192
  }, {
2242
2193
  F: __dxlog_file7,
2243
- L: 347,
2194
+ L: 286,
2244
2195
  S: this,
2245
2196
  C: (f, a) => f(...a)
2246
2197
  });
@@ -2253,7 +2204,7 @@ var InvitationsHandler = class {
2253
2204
  id: traceId
2254
2205
  }), {
2255
2206
  F: __dxlog_file7,
2256
- L: 349,
2207
+ L: 288,
2257
2208
  S: this,
2258
2209
  C: (f, a) => f(...a)
2259
2210
  });
@@ -2263,7 +2214,7 @@ var InvitationsHandler = class {
2263
2214
  ...protocol.toJSON()
2264
2215
  }, {
2265
2216
  F: __dxlog_file7,
2266
- L: 352,
2217
+ L: 291,
2267
2218
  S: this,
2268
2219
  C: (f, a) => f(...a)
2269
2220
  });
@@ -2273,7 +2224,7 @@ var InvitationsHandler = class {
2273
2224
  } else {
2274
2225
  (0, import_log4.log)("auth failed", err, {
2275
2226
  F: __dxlog_file7,
2276
- L: 355,
2227
+ L: 294,
2277
2228
  S: this,
2278
2229
  C: (f, a) => f(...a)
2279
2230
  });
@@ -2284,7 +2235,7 @@ var InvitationsHandler = class {
2284
2235
  error: err
2285
2236
  }), {
2286
2237
  F: __dxlog_file7,
2287
- L: 358,
2238
+ L: 297,
2288
2239
  S: this,
2289
2240
  C: (f, a) => f(...a)
2290
2241
  });
@@ -2302,7 +2253,7 @@ var InvitationsHandler = class {
2302
2253
  ...protocol.toJSON()
2303
2254
  }, {
2304
2255
  F: __dxlog_file7,
2305
- L: 369,
2256
+ L: 308,
2306
2257
  S: this,
2307
2258
  C: (f, a) => f(...a)
2308
2259
  });
@@ -2312,7 +2263,7 @@ var InvitationsHandler = class {
2312
2263
  } else {
2313
2264
  (0, import_log4.log)("auth failed", err, {
2314
2265
  F: __dxlog_file7,
2315
- L: 372,
2266
+ L: 311,
2316
2267
  S: this,
2317
2268
  C: (f, a) => f(...a)
2318
2269
  });
@@ -2329,7 +2280,7 @@ var InvitationsHandler = class {
2329
2280
  } else {
2330
2281
  (0, import_invariant5.invariant)(invitation.swarmKey, void 0, {
2331
2282
  F: __dxlog_file7,
2332
- L: 386,
2283
+ L: 325,
2333
2284
  S: this,
2334
2285
  A: [
2335
2286
  "invitation.swarmKey",
@@ -2371,7 +2322,7 @@ var InvitationsHandler = class {
2371
2322
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2372
2323
  (0, import_log4.log)("guest waiting for authentication code...", void 0, {
2373
2324
  F: __dxlog_file7,
2374
- L: 426,
2325
+ L: 365,
2375
2326
  S: this,
2376
2327
  C: (f, a) => f(...a)
2377
2328
  });
@@ -2381,7 +2332,7 @@ var InvitationsHandler = class {
2381
2332
  const authCode = await authenticated.wait(options);
2382
2333
  (0, import_log4.log)("sending authentication request", void 0, {
2383
2334
  F: __dxlog_file7,
2384
- L: 430,
2335
+ L: 369,
2385
2336
  S: this,
2386
2337
  C: (f, a) => f(...a)
2387
2338
  });
@@ -2402,7 +2353,7 @@ var InvitationsHandler = class {
2402
2353
  attempt
2403
2354
  }, {
2404
2355
  F: __dxlog_file7,
2405
- L: 441,
2356
+ L: 380,
2406
2357
  S: this,
2407
2358
  C: (f, a) => f(...a)
2408
2359
  });
@@ -2420,7 +2371,7 @@ var InvitationsHandler = class {
2420
2371
  }
2421
2372
  (0, import_log4.log)("sending authentication request", void 0, {
2422
2373
  F: __dxlog_file7,
2423
- L: 460,
2374
+ L: 399,
2424
2375
  S: this,
2425
2376
  C: (f, a) => f(...a)
2426
2377
  });
@@ -2452,9 +2403,8 @@ var InvitationsServiceImpl = class {
2452
2403
  return {};
2453
2404
  }
2454
2405
  createInvitation(options) {
2455
- const invitation = this._invitationsManager.createInvitation(options);
2456
2406
  return new import_codec_protobuf8.Stream(({ next, close }) => {
2457
- invitation.subscribe(next, close, close);
2407
+ void this._invitationsManager.createInvitation(options).then((invitation) => invitation.subscribe(next, close, close)).catch(close);
2458
2408
  });
2459
2409
  }
2460
2410
  acceptInvitation(request) {
@@ -2557,10 +2507,10 @@ var SpaceInvitationProtocol = class {
2557
2507
  spaceKey: this._spaceKey
2558
2508
  };
2559
2509
  }
2560
- async admit(request, guestProfile) {
2510
+ async admit(invitation, request, guestProfile) {
2561
2511
  (0, import_invariant7.invariant)(this._spaceKey, void 0, {
2562
2512
  F: __dxlog_file8,
2563
- L: 47,
2513
+ L: 55,
2564
2514
  S: this,
2565
2515
  A: [
2566
2516
  "this._spaceKey",
@@ -2570,7 +2520,7 @@ var SpaceInvitationProtocol = class {
2570
2520
  const space = await this._spaceManager.spaces.get(this._spaceKey);
2571
2521
  (0, import_invariant7.invariant)(space, void 0, {
2572
2522
  F: __dxlog_file8,
2573
- L: 49,
2523
+ L: 57,
2574
2524
  S: this,
2575
2525
  A: [
2576
2526
  "space",
@@ -2579,7 +2529,7 @@ var SpaceInvitationProtocol = class {
2579
2529
  });
2580
2530
  (0, import_invariant7.invariant)(request.space, void 0, {
2581
2531
  F: __dxlog_file8,
2582
- L: 51,
2532
+ L: 59,
2583
2533
  S: this,
2584
2534
  A: [
2585
2535
  "request.space",
@@ -2592,14 +2542,14 @@ var SpaceInvitationProtocol = class {
2592
2542
  guest: deviceKey
2593
2543
  }, {
2594
2544
  F: __dxlog_file8,
2595
- L: 54,
2545
+ L: 62,
2596
2546
  S: this,
2597
2547
  C: (f, a) => f(...a)
2598
2548
  });
2599
- const credentials = await (0, import_credentials8.createAdmissionCredentials)(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile);
2549
+ const credentials = await (0, import_credentials7.createAdmissionCredentials)(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile, invitation.delegationCredentialId);
2600
2550
  (0, import_invariant7.invariant)(credentials[0].credential, void 0, {
2601
2551
  F: __dxlog_file8,
2602
- L: 65,
2552
+ L: 74,
2603
2553
  S: this,
2604
2554
  A: [
2605
2555
  "credentials[0].credential",
@@ -2607,9 +2557,9 @@ var SpaceInvitationProtocol = class {
2607
2557
  ]
2608
2558
  });
2609
2559
  const spaceMemberCredential = credentials[0].credential.credential;
2610
- (0, import_invariant7.invariant)((0, import_credentials8.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2560
+ (0, import_invariant7.invariant)((0, import_credentials7.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2611
2561
  F: __dxlog_file8,
2612
- L: 67,
2562
+ L: 76,
2613
2563
  S: this,
2614
2564
  A: [
2615
2565
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2624,6 +2574,69 @@ var SpaceInvitationProtocol = class {
2624
2574
  }
2625
2575
  };
2626
2576
  }
2577
+ async delegate(invitation) {
2578
+ (0, import_invariant7.invariant)(this._spaceKey, void 0, {
2579
+ F: __dxlog_file8,
2580
+ L: 89,
2581
+ S: this,
2582
+ A: [
2583
+ "this._spaceKey",
2584
+ ""
2585
+ ]
2586
+ });
2587
+ const space = await this._spaceManager.spaces.get(this._spaceKey);
2588
+ (0, import_invariant7.invariant)(space, void 0, {
2589
+ F: __dxlog_file8,
2590
+ L: 91,
2591
+ S: this,
2592
+ A: [
2593
+ "space",
2594
+ ""
2595
+ ]
2596
+ });
2597
+ if (invitation.authMethod === import_services6.Invitation.AuthMethod.KNOWN_PUBLIC_KEY) {
2598
+ (0, import_invariant7.invariant)(invitation.guestKeypair?.publicKey, void 0, {
2599
+ F: __dxlog_file8,
2600
+ L: 93,
2601
+ S: this,
2602
+ A: [
2603
+ "invitation.guestKeypair?.publicKey",
2604
+ ""
2605
+ ]
2606
+ });
2607
+ }
2608
+ (0, import_log6.log)("writing delegate space invitation", {
2609
+ host: this._signingContext.deviceKey,
2610
+ id: invitation.invitationId
2611
+ }, {
2612
+ F: __dxlog_file8,
2613
+ L: 96,
2614
+ S: this,
2615
+ C: (f, a) => f(...a)
2616
+ });
2617
+ const credential = await (0, import_credentials7.createDelegatedSpaceInvitationCredential)(this._signingContext.credentialSigner, space.key, {
2618
+ invitationId: invitation.invitationId,
2619
+ authMethod: invitation.authMethod,
2620
+ swarmKey: invitation.swarmKey,
2621
+ role: import_credentials8.SpaceMember.Role.ADMIN,
2622
+ expiresOn: invitation.lifetime ? new Date((invitation.created?.getTime() ?? Date.now()) + invitation.lifetime) : void 0,
2623
+ multiUse: invitation.multiUse ?? false,
2624
+ guestKey: invitation.authMethod === import_services6.Invitation.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
2625
+ });
2626
+ (0, import_invariant7.invariant)(credential.credential, void 0, {
2627
+ F: __dxlog_file8,
2628
+ L: 116,
2629
+ S: this,
2630
+ A: [
2631
+ "credential.credential",
2632
+ ""
2633
+ ]
2634
+ });
2635
+ await (0, import_feed_store3.writeMessages)(space.inner.controlPipeline.writer, [
2636
+ credential
2637
+ ]);
2638
+ return credential.credential.credential.id;
2639
+ }
2627
2640
  checkInvitation(invitation) {
2628
2641
  if (invitation.spaceKey && this._spaceManager.spaces.has(invitation.spaceKey)) {
2629
2642
  return new import_protocols6.AlreadyJoinedError("Already joined space.");
@@ -2649,7 +2662,7 @@ var SpaceInvitationProtocol = class {
2649
2662
  async accept(response) {
2650
2663
  (0, import_invariant7.invariant)(response.space, void 0, {
2651
2664
  F: __dxlog_file8,
2652
- L: 107,
2665
+ L: 149,
2653
2666
  S: this,
2654
2667
  A: [
2655
2668
  "response.space",
@@ -2657,10 +2670,10 @@ var SpaceInvitationProtocol = class {
2657
2670
  ]
2658
2671
  });
2659
2672
  const { credential, controlTimeframe, dataTimeframe } = response.space;
2660
- const assertion = (0, import_credentials8.getCredentialAssertion)(credential);
2673
+ const assertion = (0, import_credentials7.getCredentialAssertion)(credential);
2661
2674
  (0, import_invariant7.invariant)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2662
2675
  F: __dxlog_file8,
2663
- L: 110,
2676
+ L: 152,
2664
2677
  S: this,
2665
2678
  A: [
2666
2679
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2669,7 +2682,7 @@ var SpaceInvitationProtocol = class {
2669
2682
  });
2670
2683
  (0, import_invariant7.invariant)(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
2671
2684
  F: __dxlog_file8,
2672
- L: 111,
2685
+ L: 153,
2673
2686
  S: this,
2674
2687
  A: [
2675
2688
  "credential.subject.id.equals(this._signingContext.identityKey)",
@@ -2707,25 +2720,39 @@ var InvitationsManager = class {
2707
2720
  this._persistentInvitationsLoadedEvent = new import_async9.Event();
2708
2721
  this._persistentInvitationsLoaded = false;
2709
2722
  }
2710
- createInvitation(options) {
2711
- const existingInvitation = this._createInvitations.get(options.invitationId);
2712
- if (existingInvitation) {
2713
- return existingInvitation;
2723
+ async createInvitation(options) {
2724
+ if (options.invitationId) {
2725
+ const existingInvitation = this._createInvitations.get(options.invitationId);
2726
+ if (existingInvitation) {
2727
+ return existingInvitation;
2728
+ }
2714
2729
  }
2715
2730
  const handler = this._getHandler(options);
2716
- const invitation = this._invitationsHandler.createInvitation(handler, options);
2717
- this._createInvitations.set(invitation.get().invitationId, invitation);
2718
- this.invitationCreated.emit(invitation.get());
2719
- const saveInvitationTask = invitation.get().persistent ? this._safePersistInBackground(invitation) : Promise.resolve();
2720
- this._onInvitationComplete(invitation, async () => {
2721
- this._createInvitations.delete(invitation.get().invitationId);
2722
- this.removedCreated.emit(invitation.get());
2723
- if (invitation.get().persistent) {
2724
- await saveInvitationTask;
2725
- await this._safeDeleteInvitation(invitation.get());
2731
+ const invitation = this._createInvitation(handler, options);
2732
+ const { ctx, stream, observableInvitation } = this._createObservableInvitation(handler, invitation);
2733
+ this._createInvitations.set(invitation.invitationId, observableInvitation);
2734
+ this.invitationCreated.emit(invitation);
2735
+ this._onInvitationComplete(observableInvitation, async () => {
2736
+ this._createInvitations.delete(observableInvitation.get().invitationId);
2737
+ this.removedCreated.emit(observableInvitation.get());
2738
+ if (observableInvitation.get().persistent) {
2739
+ await this._safeDeleteInvitation(observableInvitation.get());
2726
2740
  }
2727
2741
  });
2728
- return invitation;
2742
+ try {
2743
+ await this._persistIfRequired(handler, stream, invitation);
2744
+ } catch (err) {
2745
+ import_log7.log.catch(err, void 0, {
2746
+ F: __dxlog_file9,
2747
+ L: 76,
2748
+ S: this,
2749
+ C: (f, a) => f(...a)
2750
+ });
2751
+ await observableInvitation.cancel();
2752
+ return observableInvitation;
2753
+ }
2754
+ this._invitationsHandler.handleInvitationFlow(ctx, stream, handler, observableInvitation.get());
2755
+ return observableInvitation;
2729
2756
  }
2730
2757
  async loadPersistentInvitations() {
2731
2758
  if (this._persistentInvitationsLoaded) {
@@ -2737,10 +2764,10 @@ var InvitationsManager = class {
2737
2764
  try {
2738
2765
  const persistentInvitations = this._metadataStore.getInvitations();
2739
2766
  const freshInvitations = persistentInvitations.filter((invitation) => !(0, import_echo_pipeline.hasInvitationExpired)(invitation));
2740
- const cInvitations = freshInvitations.map((persistentInvitation) => {
2767
+ const loadTasks = freshInvitations.map((persistentInvitation) => {
2741
2768
  (0, import_invariant8.invariant)(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
2742
2769
  F: __dxlog_file9,
2743
- L: 82,
2770
+ L: 97,
2744
2771
  S: this,
2745
2772
  A: [
2746
2773
  "!this._createInvitations.get(persistentInvitation.invitationId)",
@@ -2750,15 +2777,16 @@ var InvitationsManager = class {
2750
2777
  return this.createInvitation({
2751
2778
  ...persistentInvitation,
2752
2779
  persistent: false
2753
- }).get();
2780
+ });
2754
2781
  });
2782
+ const cInvitations = await Promise.all(loadTasks);
2755
2783
  return {
2756
- invitations: cInvitations
2784
+ invitations: cInvitations.map((invitation) => invitation.get())
2757
2785
  };
2758
2786
  } catch (err) {
2759
2787
  import_log7.log.catch(err, void 0, {
2760
2788
  F: __dxlog_file9,
2761
- L: 88,
2789
+ L: 104,
2762
2790
  S: this,
2763
2791
  C: (f, a) => f(...a)
2764
2792
  });
@@ -2789,13 +2817,13 @@ var InvitationsManager = class {
2789
2817
  async authenticate({ invitationId, authCode }) {
2790
2818
  (0, import_log7.log)("authenticating...", void 0, {
2791
2819
  F: __dxlog_file9,
2792
- L: 117,
2820
+ L: 133,
2793
2821
  S: this,
2794
2822
  C: (f, a) => f(...a)
2795
2823
  });
2796
2824
  (0, import_invariant8.invariant)(invitationId, void 0, {
2797
2825
  F: __dxlog_file9,
2798
- L: 118,
2826
+ L: 134,
2799
2827
  S: this,
2800
2828
  A: [
2801
2829
  "invitationId",
@@ -2808,7 +2836,7 @@ var InvitationsManager = class {
2808
2836
  invitationId
2809
2837
  }, {
2810
2838
  F: __dxlog_file9,
2811
- L: 121,
2839
+ L: 137,
2812
2840
  S: this,
2813
2841
  C: (f, a) => f(...a)
2814
2842
  });
@@ -2821,13 +2849,13 @@ var InvitationsManager = class {
2821
2849
  invitationId
2822
2850
  }, {
2823
2851
  F: __dxlog_file9,
2824
- L: 128,
2852
+ L: 144,
2825
2853
  S: this,
2826
2854
  C: (f, a) => f(...a)
2827
2855
  });
2828
2856
  (0, import_invariant8.invariant)(invitationId, void 0, {
2829
2857
  F: __dxlog_file9,
2830
- L: 129,
2858
+ L: 145,
2831
2859
  S: this,
2832
2860
  A: [
2833
2861
  "invitationId",
@@ -2868,25 +2896,73 @@ var InvitationsManager = class {
2868
2896
  this._persistentInvitationsLoadedEvent.once(ctx, () => callback());
2869
2897
  }
2870
2898
  }
2871
- _safePersistInBackground(invitation) {
2872
- return new Promise((resolve) => {
2873
- setTimeout(async () => {
2874
- try {
2875
- await this._metadataStore.addInvitation(invitation.get());
2876
- this.saved.emit(invitation.get());
2877
- } catch (err) {
2878
- import_log7.log.catch(err, void 0, {
2879
- F: __dxlog_file9,
2880
- L: 173,
2881
- S: this,
2882
- C: (f, a) => f(...a)
2883
- });
2884
- await invitation.cancel();
2885
- } finally {
2886
- resolve();
2887
- }
2899
+ _createInvitation(protocol, options) {
2900
+ const { invitationId = import_keys7.PublicKey.random().toHex(), type = import_services7.Invitation.Type.INTERACTIVE, authMethod = import_services7.Invitation.AuthMethod.SHARED_SECRET, state = import_services7.Invitation.State.INIT, timeout = import_client_protocol3.INVITATION_TIMEOUT, swarmKey = import_keys7.PublicKey.random(), persistent = options?.authMethod !== import_services7.Invitation.AuthMethod.KNOWN_PUBLIC_KEY, created = /* @__PURE__ */ new Date(), guestKeypair = void 0, lifetime = 86400, multiUse = false } = options ?? {};
2901
+ const authCode = options?.authCode ?? (authMethod === import_services7.Invitation.AuthMethod.SHARED_SECRET ? (0, import_credentials9.generatePasscode)(import_client_protocol3.AUTHENTICATION_CODE_LENGTH) : void 0);
2902
+ return {
2903
+ invitationId,
2904
+ type,
2905
+ authMethod,
2906
+ state,
2907
+ swarmKey,
2908
+ authCode,
2909
+ timeout,
2910
+ persistent: persistent && type !== import_services7.Invitation.Type.DELEGATED,
2911
+ guestKeypair: guestKeypair ?? (authMethod === import_services7.Invitation.AuthMethod.KNOWN_PUBLIC_KEY ? createAdmissionKeypair() : void 0),
2912
+ created,
2913
+ lifetime,
2914
+ multiUse,
2915
+ delegationCredentialId: options?.delegationCredentialId,
2916
+ ...protocol.getInvitationContext()
2917
+ };
2918
+ }
2919
+ _createObservableInvitation(handler, invitation) {
2920
+ const stream = new import_async9.PushStream();
2921
+ const ctx = new import_context6.Context({
2922
+ onError: (err) => {
2923
+ stream.error(err);
2924
+ void ctx.dispose();
2925
+ }
2926
+ });
2927
+ ctx.onDispose(() => {
2928
+ (0, import_log7.log)("complete", {
2929
+ ...handler.toJSON()
2930
+ }, {
2931
+ F: __dxlog_file9,
2932
+ L: 228,
2933
+ S: this,
2934
+ C: (f, a) => f(...a)
2888
2935
  });
2936
+ stream.complete();
2889
2937
  });
2938
+ const observableInvitation = new import_client_protocol3.CancellableInvitation({
2939
+ initialInvitation: invitation,
2940
+ subscriber: stream.observable,
2941
+ onCancel: async () => {
2942
+ stream.next({
2943
+ ...invitation,
2944
+ state: import_services7.Invitation.State.CANCELLED
2945
+ });
2946
+ await ctx.dispose();
2947
+ }
2948
+ });
2949
+ return {
2950
+ ctx,
2951
+ stream,
2952
+ observableInvitation
2953
+ };
2954
+ }
2955
+ async _persistIfRequired(handler, changeStream, invitation) {
2956
+ if (invitation.type === import_services7.Invitation.Type.DELEGATED && invitation.delegationCredentialId == null) {
2957
+ const delegationCredentialId = await handler.delegate(invitation);
2958
+ changeStream.next({
2959
+ ...invitation,
2960
+ delegationCredentialId
2961
+ });
2962
+ } else if (invitation.persistent) {
2963
+ await this._metadataStore.addInvitation(invitation);
2964
+ this.saved.emit(invitation);
2965
+ }
2890
2966
  }
2891
2967
  async _safeDeleteInvitation(invitation) {
2892
2968
  try {
@@ -2894,7 +2970,7 @@ var InvitationsManager = class {
2894
2970
  } catch (err) {
2895
2971
  import_log7.log.catch(err, void 0, {
2896
2972
  F: __dxlog_file9,
2897
- L: 186,
2973
+ L: 260,
2898
2974
  S: this,
2899
2975
  C: (f, a) => f(...a)
2900
2976
  });
@@ -2990,7 +3066,7 @@ var AutomergeSpaceState = class {
2990
3066
  this._isProcessingRootDocs = false;
2991
3067
  }
2992
3068
  async processCredential(credential) {
2993
- if (!(0, import_credentials10.checkCredentialType)(credential, "dxos.halo.credentials.Epoch")) {
3069
+ if (!(0, import_credentials11.checkCredentialType)(credential, "dxos.halo.credentials.Epoch")) {
2994
3070
  return;
2995
3071
  }
2996
3072
  this.lastEpoch = credential;
@@ -3022,11 +3098,11 @@ var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
3022
3098
  var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
3023
3099
  var NotarizationPlugin = class {
3024
3100
  constructor() {
3025
- this._ctx = new import_context7.Context();
3101
+ this._ctx = new import_context8.Context();
3026
3102
  this._extensionOpened = new import_async12.Event();
3027
3103
  this._extensions = /* @__PURE__ */ new Set();
3028
- this._processedCredentials = new import_util5.ComplexSet(import_keys8.PublicKey.hash);
3029
- this._processCredentialsTriggers = new import_util5.ComplexMap(import_keys8.PublicKey.hash);
3104
+ this._processedCredentials = new import_util5.ComplexSet(import_keys9.PublicKey.hash);
3105
+ this._processCredentialsTriggers = new import_util5.ComplexMap(import_keys9.PublicKey.hash);
3030
3106
  }
3031
3107
  get hasWriter() {
3032
3108
  return !!this._writer;
@@ -3147,7 +3223,7 @@ var NotarizationPlugin = class {
3147
3223
  this._extensionOpened.on(ctx, () => notarizeTask.schedule());
3148
3224
  try {
3149
3225
  await Promise.race([
3150
- (0, import_context7.rejectOnDispose)(ctx),
3226
+ (0, import_context8.rejectOnDispose)(ctx),
3151
3227
  allNotarized,
3152
3228
  errors.wait()
3153
3229
  ]);
@@ -3286,11 +3362,11 @@ function _ts_decorate4(decorators, target, key, desc) {
3286
3362
  var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
3287
3363
  var DataSpace = class {
3288
3364
  constructor(params) {
3289
- this._ctx = new import_context6.Context();
3365
+ this._ctx = new import_context7.Context();
3290
3366
  this._notarizationPlugin = new NotarizationPlugin();
3291
3367
  this._cache = void 0;
3292
3368
  this._automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
3293
- this._state = import_services7.SpaceState.CLOSED;
3369
+ this._state = import_services8.SpaceState.CLOSED;
3294
3370
  this.error = void 0;
3295
3371
  this.stateUpdate = new import_async10.Event();
3296
3372
  this.metrics = {};
@@ -3303,19 +3379,19 @@ var DataSpace = class {
3303
3379
  this._metadataStore = params.metadataStore;
3304
3380
  this._signingContext = params.signingContext;
3305
3381
  this._callbacks = params.callbacks ?? {};
3306
- this._automergeHost = params.automergeHost;
3382
+ this._echoHost = params.echoHost;
3307
3383
  this.authVerifier = new TrustedKeySetAuthVerifier({
3308
- trustedKeysProvider: () => new import_util4.ComplexSet(import_keys7.PublicKey.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => !member.removed).map((member) => member.key)),
3384
+ trustedKeysProvider: () => new import_util4.ComplexSet(import_keys8.PublicKey.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => !member.removed).map((member) => member.key)),
3309
3385
  update: this._inner.stateUpdate,
3310
- authTimeout: import_client_protocol3.AUTH_TIMEOUT
3386
+ authTimeout: import_client_protocol4.AUTH_TIMEOUT
3311
3387
  });
3312
3388
  this._cache = params.cache;
3313
3389
  this._state = params.initialState;
3314
3390
  (0, import_log8.log)("new state", {
3315
- state: import_services7.SpaceState[this._state]
3391
+ state: import_services8.SpaceState[this._state]
3316
3392
  }, {
3317
3393
  F: __dxlog_file11,
3318
- L: 140,
3394
+ L: 135,
3319
3395
  S: this,
3320
3396
  C: (f, a) => f(...a)
3321
3397
  });
@@ -3359,13 +3435,13 @@ var DataSpace = class {
3359
3435
  await this._notarizationPlugin.open();
3360
3436
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
3361
3437
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
3362
- await this._inner.open(new import_context6.Context());
3363
- this._state = import_services7.SpaceState.CONTROL_ONLY;
3438
+ await this._inner.open(new import_context7.Context());
3439
+ this._state = import_services8.SpaceState.CONTROL_ONLY;
3364
3440
  (0, import_log8.log)("new state", {
3365
- state: import_services7.SpaceState[this._state]
3441
+ state: import_services8.SpaceState[this._state]
3366
3442
  }, {
3367
3443
  F: __dxlog_file11,
3368
- L: 198,
3444
+ L: 193,
3369
3445
  S: this,
3370
3446
  C: (f, a) => f(...a)
3371
3447
  });
@@ -3378,17 +3454,17 @@ var DataSpace = class {
3378
3454
  }
3379
3455
  async _close() {
3380
3456
  await this._callbacks.beforeClose?.();
3381
- this._state = import_services7.SpaceState.CLOSED;
3457
+ this._state = import_services8.SpaceState.CLOSED;
3382
3458
  (0, import_log8.log)("new state", {
3383
- state: import_services7.SpaceState[this._state]
3459
+ state: import_services8.SpaceState[this._state]
3384
3460
  }, {
3385
3461
  F: __dxlog_file11,
3386
- L: 212,
3462
+ L: 207,
3387
3463
  S: this,
3388
3464
  C: (f, a) => f(...a)
3389
3465
  });
3390
3466
  await this._ctx.dispose();
3391
- this._ctx = new import_context6.Context();
3467
+ this._ctx = new import_context7.Context();
3392
3468
  await this.authVerifier.close();
3393
3469
  await this._inner.close();
3394
3470
  await this._inner.spaceState.removeCredentialProcessor(this._automergeSpaceState);
@@ -3412,10 +3488,10 @@ var DataSpace = class {
3412
3488
  this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
3413
3489
  await this.initializeDataPipeline();
3414
3490
  } catch (err) {
3415
- if (err instanceof import_protocols7.CancelledError || err instanceof import_context6.ContextDisposedError) {
3491
+ if (err instanceof import_protocols7.CancelledError || err instanceof import_context7.ContextDisposedError) {
3416
3492
  (0, import_log8.log)("data pipeline initialization cancelled", err, {
3417
3493
  F: __dxlog_file11,
3418
- L: 245,
3494
+ L: 240,
3419
3495
  S: this,
3420
3496
  C: (f, a) => f(...a)
3421
3497
  });
@@ -3423,16 +3499,16 @@ var DataSpace = class {
3423
3499
  }
3424
3500
  import_log8.log.error("Error initializing data pipeline", err, {
3425
3501
  F: __dxlog_file11,
3426
- L: 249,
3502
+ L: 244,
3427
3503
  S: this,
3428
3504
  C: (f, a) => f(...a)
3429
3505
  });
3430
- this._state = import_services7.SpaceState.ERROR;
3506
+ this._state = import_services8.SpaceState.ERROR;
3431
3507
  (0, import_log8.log)("new state", {
3432
- state: import_services7.SpaceState[this._state]
3508
+ state: import_services8.SpaceState[this._state]
3433
3509
  }, {
3434
3510
  F: __dxlog_file11,
3435
- L: 251,
3511
+ L: 246,
3436
3512
  S: this,
3437
3513
  C: (f, a) => f(...a)
3438
3514
  });
@@ -3444,35 +3520,35 @@ var DataSpace = class {
3444
3520
  });
3445
3521
  }
3446
3522
  async initializeDataPipeline() {
3447
- if (this._state !== import_services7.SpaceState.CONTROL_ONLY) {
3523
+ if (this._state !== import_services8.SpaceState.CONTROL_ONLY) {
3448
3524
  throw new import_protocols7.SystemError("Invalid operation");
3449
3525
  }
3450
- this._state = import_services7.SpaceState.INITIALIZING;
3526
+ this._state = import_services8.SpaceState.INITIALIZING;
3451
3527
  (0, import_log8.log)("new state", {
3452
- state: import_services7.SpaceState[this._state]
3528
+ state: import_services8.SpaceState[this._state]
3453
3529
  }, {
3454
3530
  F: __dxlog_file11,
3455
- L: 267,
3531
+ L: 262,
3456
3532
  S: this,
3457
3533
  C: (f, a) => f(...a)
3458
3534
  });
3459
3535
  await this._initializeAndReadControlPipeline();
3460
3536
  await (0, import_async10.sleep)(1);
3461
3537
  this._automergeSpaceState.startProcessingRootDocs();
3462
- await (0, import_context6.cancelWithContext)(this._ctx, this.automergeSpaceState.ensureEpochInitialized());
3538
+ await (0, import_context7.cancelWithContext)(this._ctx, this.automergeSpaceState.ensureEpochInitialized());
3463
3539
  (0, import_log8.log)("data pipeline ready", void 0, {
3464
3540
  F: __dxlog_file11,
3465
- L: 279,
3541
+ L: 274,
3466
3542
  S: this,
3467
3543
  C: (f, a) => f(...a)
3468
3544
  });
3469
3545
  await this._callbacks.beforeReady?.();
3470
- this._state = import_services7.SpaceState.READY;
3546
+ this._state = import_services8.SpaceState.READY;
3471
3547
  (0, import_log8.log)("new state", {
3472
- state: import_services7.SpaceState[this._state]
3548
+ state: import_services8.SpaceState[this._state]
3473
3549
  }, {
3474
3550
  F: __dxlog_file11,
3475
- L: 283,
3551
+ L: 278,
3476
3552
  S: this,
3477
3553
  C: (f, a) => f(...a)
3478
3554
  });
@@ -3488,7 +3564,7 @@ var DataSpace = class {
3488
3564
  await this._createWritableFeeds();
3489
3565
  (0, import_log8.log)("writable feeds created", void 0, {
3490
3566
  F: __dxlog_file11,
3491
- L: 299,
3567
+ L: 294,
3492
3568
  S: this,
3493
3569
  C: (f, a) => f(...a)
3494
3570
  });
@@ -3515,7 +3591,7 @@ var DataSpace = class {
3515
3591
  spaceKey: this.key,
3516
3592
  deviceKey: this._signingContext.deviceKey,
3517
3593
  identityKey: this._signingContext.identityKey,
3518
- designation: import_credentials9.AdmittedFeed.Designation.CONTROL
3594
+ designation: import_credentials10.AdmittedFeed.Designation.CONTROL
3519
3595
  }
3520
3596
  }));
3521
3597
  }
@@ -3532,7 +3608,7 @@ var DataSpace = class {
3532
3608
  spaceKey: this.key,
3533
3609
  deviceKey: this._signingContext.deviceKey,
3534
3610
  identityKey: this._signingContext.identityKey,
3535
- designation: import_credentials9.AdmittedFeed.Designation.DATA
3611
+ designation: import_credentials10.AdmittedFeed.Designation.DATA
3536
3612
  }
3537
3613
  }));
3538
3614
  }
@@ -3551,16 +3627,16 @@ var DataSpace = class {
3551
3627
  rootUrl
3552
3628
  }, {
3553
3629
  F: __dxlog_file11,
3554
- L: 365,
3630
+ L: 360,
3555
3631
  S: this,
3556
3632
  C: (f, a) => f(...a)
3557
3633
  });
3558
- this._automergeHost._requestedDocs.add(rootUrl);
3559
- const handle = this._automergeHost.repo.find(rootUrl);
3634
+ this._echoHost.replicateDocument(rootUrl);
3635
+ const handle = this._echoHost.automergeRepo.find(rootUrl);
3560
3636
  queueMicrotask(async () => {
3561
3637
  try {
3562
3638
  await (0, import_debug3.warnAfterTimeout)(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
3563
- await (0, import_context6.cancelWithContext)(this._ctx, handle.whenReady());
3639
+ await (0, import_context7.cancelWithContext)(this._ctx, handle.whenReady());
3564
3640
  });
3565
3641
  if (this._ctx.disposed) {
3566
3642
  return;
@@ -3574,7 +3650,7 @@ var DataSpace = class {
3574
3650
  });
3575
3651
  }
3576
3652
  } catch (err) {
3577
- if (err instanceof import_context6.ContextDisposedError) {
3653
+ if (err instanceof import_context7.ContextDisposedError) {
3578
3654
  return;
3579
3655
  }
3580
3656
  import_log8.log.warn("error loading automerge root doc", {
@@ -3583,7 +3659,7 @@ var DataSpace = class {
3583
3659
  err
3584
3660
  }, {
3585
3661
  F: __dxlog_file11,
3586
- L: 388,
3662
+ L: 383,
3587
3663
  S: this,
3588
3664
  C: (f, a) => f(...a)
3589
3665
  });
@@ -3609,7 +3685,7 @@ var DataSpace = class {
3609
3685
  let epoch;
3610
3686
  switch (options?.migration) {
3611
3687
  case void 0:
3612
- case import_services7.CreateEpochRequest.Migration.NONE:
3688
+ case import_services8.CreateEpochRequest.Migration.NONE:
3613
3689
  {
3614
3690
  epoch = {
3615
3691
  previousId: this._automergeSpaceState.lastEpoch?.id,
@@ -3619,9 +3695,9 @@ var DataSpace = class {
3619
3695
  };
3620
3696
  }
3621
3697
  break;
3622
- case import_services7.CreateEpochRequest.Migration.INIT_AUTOMERGE:
3698
+ case import_services8.CreateEpochRequest.Migration.INIT_AUTOMERGE:
3623
3699
  {
3624
- const document = this._automergeHost.repo.create();
3700
+ const document = this._echoHost.automergeRepo.create();
3625
3701
  epoch = {
3626
3702
  previousId: this._automergeSpaceState.lastEpoch?.id,
3627
3703
  number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
@@ -3630,15 +3706,15 @@ var DataSpace = class {
3630
3706
  };
3631
3707
  }
3632
3708
  break;
3633
- case import_services7.CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY:
3709
+ case import_services8.CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY:
3634
3710
  {
3635
3711
  const currentRootUrl = this._automergeSpaceState.rootUrl;
3636
- const rootHandle = this._automergeHost.repo.find(currentRootUrl);
3637
- await (0, import_context6.cancelWithContext)(this._ctx, (0, import_async10.asyncTimeout)(rootHandle.whenReady(), 1e4));
3638
- const newRoot = this._automergeHost.repo.create(rootHandle.docSync());
3712
+ const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
3713
+ await (0, import_context7.cancelWithContext)(this._ctx, (0, import_async10.asyncTimeout)(rootHandle.whenReady(), 1e4));
3714
+ const newRoot = this._echoHost.automergeRepo.create(rootHandle.docSync());
3639
3715
  (0, import_invariant9.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3640
3716
  F: __dxlog_file11,
3641
- L: 438,
3717
+ L: 433,
3642
3718
  S: this,
3643
3719
  A: [
3644
3720
  "typeof newRoot.url === 'string' && newRoot.url.length > 0",
@@ -3653,23 +3729,23 @@ var DataSpace = class {
3653
3729
  };
3654
3730
  }
3655
3731
  break;
3656
- case import_services7.CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT:
3732
+ case import_services8.CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT:
3657
3733
  {
3658
3734
  import_log8.log.info("Fragmenting", void 0, {
3659
3735
  F: __dxlog_file11,
3660
- L: 450,
3736
+ L: 445,
3661
3737
  S: this,
3662
3738
  C: (f, a) => f(...a)
3663
3739
  });
3664
3740
  const currentRootUrl = this._automergeSpaceState.rootUrl;
3665
- const rootHandle = this._automergeHost.repo.find(currentRootUrl);
3666
- await (0, import_context6.cancelWithContext)(this._ctx, (0, import_async10.asyncTimeout)(rootHandle.whenReady(), 1e4));
3741
+ const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
3742
+ await (0, import_context7.cancelWithContext)(this._ctx, (0, import_async10.asyncTimeout)(rootHandle.whenReady(), 1e4));
3667
3743
  const objects = Object.entries(rootHandle.docSync().objects);
3668
- const properties = objects.find(([_, value]) => value.system.type?.itemId === import_echo_db.TYPE_PROPERTIES);
3744
+ const properties = objects.find(([_, value]) => value.system.type?.itemId === import_echo_schema.TYPE_PROPERTIES);
3669
3745
  const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
3670
3746
  (0, import_invariant9.invariant)(properties, "Properties not found", {
3671
3747
  F: __dxlog_file11,
3672
- L: 460,
3748
+ L: 455,
3673
3749
  S: this,
3674
3750
  A: [
3675
3751
  "properties",
@@ -3682,17 +3758,17 @@ var DataSpace = class {
3682
3758
  properties
3683
3759
  ])
3684
3760
  };
3685
- const newRoot = this._automergeHost.repo.create(newSpaceDoc);
3761
+ const newRoot = this._echoHost.automergeRepo.create(newSpaceDoc);
3686
3762
  (0, import_invariant9.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3687
3763
  F: __dxlog_file11,
3688
- L: 465,
3764
+ L: 460,
3689
3765
  S: this,
3690
3766
  A: [
3691
3767
  "typeof newRoot.url === 'string' && newRoot.url.length > 0",
3692
3768
  ""
3693
3769
  ]
3694
3770
  });
3695
- const docLoader = new import_echo_pipeline3.AutomergeDocumentLoaderImpl(this.key, this._automergeHost.repo);
3771
+ const docLoader = new import_echo_pipeline3.AutomergeDocumentLoaderImpl(this.key, this._echoHost.automergeRepo);
3696
3772
  await docLoader.loadSpaceRootDocHandle(this._ctx, {
3697
3773
  rootUrl: newRoot.url
3698
3774
  });
@@ -3736,25 +3812,25 @@ var DataSpace = class {
3736
3812
  ]));
3737
3813
  }
3738
3814
  async activate() {
3739
- if (this._state !== import_services7.SpaceState.INACTIVE) {
3815
+ if (this._state !== import_services8.SpaceState.INACTIVE) {
3740
3816
  return;
3741
3817
  }
3742
- await this._metadataStore.setSpaceState(this.key, import_services7.SpaceState.ACTIVE);
3818
+ await this._metadataStore.setSpaceState(this.key, import_services8.SpaceState.ACTIVE);
3743
3819
  await this._open();
3744
3820
  this.initializeDataPipelineAsync();
3745
3821
  }
3746
3822
  async deactivate() {
3747
- if (this._state === import_services7.SpaceState.INACTIVE) {
3823
+ if (this._state === import_services8.SpaceState.INACTIVE) {
3748
3824
  return;
3749
3825
  }
3750
- await this._metadataStore.setSpaceState(this.key, import_services7.SpaceState.INACTIVE);
3826
+ await this._metadataStore.setSpaceState(this.key, import_services8.SpaceState.INACTIVE);
3751
3827
  await this._close();
3752
- this._state = import_services7.SpaceState.INACTIVE;
3828
+ this._state = import_services8.SpaceState.INACTIVE;
3753
3829
  (0, import_log8.log)("new state", {
3754
- state: import_services7.SpaceState[this._state]
3830
+ state: import_services8.SpaceState[this._state]
3755
3831
  }, {
3756
3832
  F: __dxlog_file11,
3757
- L: 531,
3833
+ L: 526,
3758
3834
  S: this,
3759
3835
  C: (f, a) => f(...a)
3760
3836
  });
@@ -3769,7 +3845,7 @@ _ts_decorate4([
3769
3845
  ], DataSpace.prototype, "key", null);
3770
3846
  _ts_decorate4([
3771
3847
  import_tracing4.trace.info({
3772
- enum: import_services7.SpaceState
3848
+ enum: import_services8.SpaceState
3773
3849
  })
3774
3850
  ], DataSpace.prototype, "state", null);
3775
3851
  _ts_decorate4([
@@ -3808,7 +3884,7 @@ DataSpace = _ts_decorate4([
3808
3884
  ], DataSpace);
3809
3885
  var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3810
3886
  const credentials = [
3811
- await (0, import_credentials12.createCredential)({
3887
+ await (0, import_credentials13.createCredential)({
3812
3888
  signer: keyring,
3813
3889
  issuer: space.key,
3814
3890
  subject: space.key,
@@ -3817,14 +3893,14 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3817
3893
  spaceKey: space.key
3818
3894
  }
3819
3895
  }),
3820
- await (0, import_credentials12.createCredential)({
3896
+ await (0, import_credentials13.createCredential)({
3821
3897
  signer: keyring,
3822
3898
  issuer: space.key,
3823
3899
  subject: signingContext.identityKey,
3824
3900
  assertion: {
3825
3901
  "@type": "dxos.halo.credentials.SpaceMember",
3826
3902
  spaceKey: space.key,
3827
- role: import_credentials13.SpaceMember.Role.ADMIN,
3903
+ role: import_credentials14.SpaceMember.Role.ADMIN,
3828
3904
  profile: signingContext.getProfile(),
3829
3905
  genesisFeedKey: space.controlFeedKey ?? (0, import_debug4.failUndefined)()
3830
3906
  }
@@ -3836,7 +3912,7 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3836
3912
  spaceKey: space.key,
3837
3913
  identityKey: signingContext.identityKey,
3838
3914
  deviceKey: signingContext.deviceKey,
3839
- designation: import_credentials13.AdmittedFeed.Designation.CONTROL
3915
+ designation: import_credentials14.AdmittedFeed.Designation.CONTROL
3840
3916
  }
3841
3917
  }),
3842
3918
  await signingContext.credentialSigner.createCredential({
@@ -3846,7 +3922,7 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3846
3922
  spaceKey: space.key,
3847
3923
  identityKey: signingContext.identityKey,
3848
3924
  deviceKey: signingContext.deviceKey,
3849
- designation: import_credentials13.AdmittedFeed.Designation.DATA
3925
+ designation: import_credentials14.AdmittedFeed.Designation.DATA
3850
3926
  }
3851
3927
  }),
3852
3928
  await signingContext.credentialSigner.createCredential({
@@ -3884,18 +3960,19 @@ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/s
3884
3960
  var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
3885
3961
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
3886
3962
  var DataSpaceManager = class {
3887
- constructor(_spaceManager, _metadataStore, _keyring, _signingContext, _feedStore, _automergeHost, params) {
3963
+ constructor(_spaceManager, _metadataStore, _keyring, _signingContext, _feedStore, _echoHost, _invitationsManager, params) {
3888
3964
  this._spaceManager = _spaceManager;
3889
3965
  this._metadataStore = _metadataStore;
3890
3966
  this._keyring = _keyring;
3891
3967
  this._signingContext = _signingContext;
3892
3968
  this._feedStore = _feedStore;
3893
- this._automergeHost = _automergeHost;
3894
- this._ctx = new import_context8.Context();
3969
+ this._echoHost = _echoHost;
3970
+ this._invitationsManager = _invitationsManager;
3971
+ this._ctx = new import_context9.Context();
3895
3972
  this.updated = new import_async13.Event();
3896
- this._spaces = new import_util6.ComplexMap(import_keys9.PublicKey.hash);
3973
+ this._spaces = new import_util6.ComplexMap(import_keys10.PublicKey.hash);
3897
3974
  this._isOpen = false;
3898
- this._instanceId = import_keys9.PublicKey.random().toHex();
3975
+ this._instanceId = import_keys10.PublicKey.random().toHex();
3899
3976
  const { spaceMemberPresenceAnnounceInterval = PRESENCE_ANNOUNCE_INTERVAL, spaceMemberPresenceOfflineTimeout = PRESENCE_OFFLINE_TIMEOUT } = params ?? {};
3900
3977
  this._spaceMemberPresenceAnnounceInterval = spaceMemberPresenceAnnounceInterval;
3901
3978
  this._spaceMemberPresenceOfflineTimeout = spaceMemberPresenceOfflineTimeout;
@@ -3907,7 +3984,7 @@ var DataSpaceManager = class {
3907
3984
  async open() {
3908
3985
  (0, import_log10.log)("open", void 0, {
3909
3986
  F: __dxlog_file12,
3910
- L: 98,
3987
+ L: 102,
3911
3988
  S: this,
3912
3989
  C: (f, a) => f(...a)
3913
3990
  });
@@ -3915,7 +3992,7 @@ var DataSpaceManager = class {
3915
3992
  id: this._instanceId
3916
3993
  }), {
3917
3994
  F: __dxlog_file12,
3918
- L: 99,
3995
+ L: 103,
3919
3996
  S: this,
3920
3997
  C: (f, a) => f(...a)
3921
3998
  });
@@ -3923,7 +4000,7 @@ var DataSpaceManager = class {
3923
4000
  spaces: this._metadataStore.spaces.length
3924
4001
  }, {
3925
4002
  F: __dxlog_file12,
3926
- L: 100,
4003
+ L: 104,
3927
4004
  S: this,
3928
4005
  C: (f, a) => f(...a)
3929
4006
  });
@@ -3933,7 +4010,7 @@ var DataSpaceManager = class {
3933
4010
  spaceMetadata
3934
4011
  }, {
3935
4012
  F: __dxlog_file12,
3936
- L: 104,
4013
+ L: 108,
3937
4014
  S: this,
3938
4015
  C: (f, a) => f(...a)
3939
4016
  });
@@ -3944,7 +4021,7 @@ var DataSpaceManager = class {
3944
4021
  err
3945
4022
  }, {
3946
4023
  F: __dxlog_file12,
3947
- L: 107,
4024
+ L: 111,
3948
4025
  S: this,
3949
4026
  C: (f, a) => f(...a)
3950
4027
  });
@@ -3953,7 +4030,7 @@ var DataSpaceManager = class {
3953
4030
  this._isOpen = true;
3954
4031
  this.updated.emit();
3955
4032
  for (const space of this._spaces.values()) {
3956
- if (space.state !== import_services8.SpaceState.INACTIVE) {
4033
+ if (space.state !== import_services9.SpaceState.INACTIVE) {
3957
4034
  space.initializeDataPipelineAsync();
3958
4035
  }
3959
4036
  }
@@ -3961,7 +4038,7 @@ var DataSpaceManager = class {
3961
4038
  id: this._instanceId
3962
4039
  }), {
3963
4040
  F: __dxlog_file12,
3964
- L: 120,
4041
+ L: 124,
3965
4042
  S: this,
3966
4043
  C: (f, a) => f(...a)
3967
4044
  });
@@ -3969,7 +4046,7 @@ var DataSpaceManager = class {
3969
4046
  async close() {
3970
4047
  (0, import_log10.log)("close", void 0, {
3971
4048
  F: __dxlog_file12,
3972
- L: 125,
4049
+ L: 129,
3973
4050
  S: this,
3974
4051
  C: (f, a) => f(...a)
3975
4052
  });
@@ -3985,7 +4062,7 @@ var DataSpaceManager = class {
3985
4062
  async createSpace() {
3986
4063
  (0, import_invariant11.invariant)(this._isOpen, "Not open.", {
3987
4064
  F: __dxlog_file12,
3988
- L: 138,
4065
+ L: 142,
3989
4066
  S: this,
3990
4067
  A: [
3991
4068
  "this._isOpen",
@@ -4000,27 +4077,22 @@ var DataSpaceManager = class {
4000
4077
  genesisFeedKey: controlFeedKey,
4001
4078
  controlFeedKey,
4002
4079
  dataFeedKey,
4003
- state: import_services8.SpaceState.ACTIVE
4080
+ state: import_services9.SpaceState.ACTIVE
4004
4081
  };
4005
4082
  (0, import_log10.log)("creating space...", {
4006
4083
  spaceKey
4007
4084
  }, {
4008
4085
  F: __dxlog_file12,
4009
- L: 150,
4086
+ L: 154,
4010
4087
  S: this,
4011
4088
  C: (f, a) => f(...a)
4012
4089
  });
4013
- const automergeRoot = this._automergeHost.repo.create();
4014
- automergeRoot.change((doc) => {
4015
- doc.access = {
4016
- spaceKey: spaceKey.toHex()
4017
- };
4018
- });
4090
+ const automergeRootUrl = await this._echoHost.createSpaceRoot(spaceKey);
4019
4091
  const space = await this._constructSpace(metadata);
4020
- const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRoot.url);
4092
+ const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRootUrl);
4021
4093
  await this._metadataStore.addSpace(metadata);
4022
4094
  const memberCredential = credentials[1];
4023
- (0, import_invariant11.invariant)((0, import_credentials11.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4095
+ (0, import_invariant11.invariant)((0, import_credentials12.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4024
4096
  F: __dxlog_file12,
4025
4097
  L: 163,
4026
4098
  S: this,
@@ -4080,9 +4152,9 @@ var DataSpaceManager = class {
4080
4152
  * TODO(dmaretskyi): Consider removing.
4081
4153
  */
4082
4154
  async waitUntilSpaceReady(spaceKey) {
4083
- await (0, import_context8.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
4155
+ await (0, import_context9.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
4084
4156
  const space = this._spaces.get(spaceKey);
4085
- return !!space && space.state === import_services8.SpaceState.READY;
4157
+ return !!space && space.state === import_services9.SpaceState.READY;
4086
4158
  }));
4087
4159
  }
4088
4160
  async _constructSpace(metadata) {
@@ -4122,8 +4194,8 @@ var DataSpaceManager = class {
4122
4194
  remotePeerId: session.remotePeerId
4123
4195
  }));
4124
4196
  session.addExtension("dxos.mesh.teleport.notarization", dataSpace.notarizationPlugin.createExtension());
4125
- this._automergeHost.authorizeDevice(space.key, session.remotePeerId);
4126
- session.addExtension("dxos.mesh.teleport.automerge", this._automergeHost.createExtension());
4197
+ this._echoHost.authorizeDevice(space.key, session.remotePeerId);
4198
+ session.addExtension("dxos.mesh.teleport.automerge", this._echoHost.createReplicationExtension());
4127
4199
  },
4128
4200
  onAuthFailure: () => {
4129
4201
  import_log10.log.warn("auth failure", void 0, {
@@ -4133,18 +4205,22 @@ var DataSpaceManager = class {
4133
4205
  C: (f, a) => f(...a)
4134
4206
  });
4135
4207
  },
4136
- memberKey: this._signingContext.identityKey
4208
+ memberKey: this._signingContext.identityKey,
4209
+ onDelegatedInvitationStatusChange: (invitation, isActive) => {
4210
+ return this._handleInvitationStatusChange(dataSpace, invitation, isActive);
4211
+ }
4137
4212
  });
4138
4213
  controlFeed && await space.setControlFeed(controlFeed);
4139
4214
  dataFeed && await space.setDataFeed(dataFeed);
4140
4215
  const dataSpace = new DataSpace({
4141
4216
  inner: space,
4142
- initialState: metadata.state === import_services8.SpaceState.INACTIVE ? import_services8.SpaceState.INACTIVE : import_services8.SpaceState.CLOSED,
4217
+ initialState: metadata.state === import_services9.SpaceState.INACTIVE ? import_services9.SpaceState.INACTIVE : import_services9.SpaceState.CLOSED,
4143
4218
  metadataStore: this._metadataStore,
4144
4219
  gossip,
4145
4220
  presence,
4146
4221
  keyring: this._keyring,
4147
4222
  feedStore: this._feedStore,
4223
+ echoHost: this._echoHost,
4148
4224
  signingContext: this._signingContext,
4149
4225
  callbacks: {
4150
4226
  beforeReady: async () => {
@@ -4152,7 +4228,7 @@ var DataSpaceManager = class {
4152
4228
  space: space.key
4153
4229
  }, {
4154
4230
  F: __dxlog_file12,
4155
- L: 265,
4231
+ L: 269,
4156
4232
  S: this,
4157
4233
  C: (f, a) => f(...a)
4158
4234
  });
@@ -4163,11 +4239,14 @@ var DataSpaceManager = class {
4163
4239
  open: this._isOpen
4164
4240
  }, {
4165
4241
  F: __dxlog_file12,
4166
- L: 268,
4242
+ L: 272,
4167
4243
  S: this,
4168
4244
  C: (f, a) => f(...a)
4169
4245
  });
4170
4246
  if (this._isOpen) {
4247
+ await this._createDelegatedInvitations(dataSpace, [
4248
+ ...space.spaceState.invitations.entries()
4249
+ ]);
4171
4250
  this.updated.emit();
4172
4251
  }
4173
4252
  },
@@ -4176,16 +4255,15 @@ var DataSpaceManager = class {
4176
4255
  space: space.key
4177
4256
  }, {
4178
4257
  F: __dxlog_file12,
4179
- L: 274,
4258
+ L: 279,
4180
4259
  S: this,
4181
4260
  C: (f, a) => f(...a)
4182
4261
  });
4183
4262
  }
4184
4263
  },
4185
- cache: metadata.cache,
4186
- automergeHost: this._automergeHost
4264
+ cache: metadata.cache
4187
4265
  });
4188
- if (metadata.state !== import_services8.SpaceState.INACTIVE) {
4266
+ if (metadata.state !== import_services9.SpaceState.INACTIVE) {
4189
4267
  await dataSpace.open();
4190
4268
  }
4191
4269
  if (metadata.controlTimeframe) {
@@ -4194,6 +4272,41 @@ var DataSpaceManager = class {
4194
4272
  this._spaces.set(metadata.key, dataSpace);
4195
4273
  return dataSpace;
4196
4274
  }
4275
+ async _handleInvitationStatusChange(dataSpace, delegatedInvitation, isActive) {
4276
+ if (dataSpace?.state !== import_services9.SpaceState.READY) {
4277
+ return;
4278
+ }
4279
+ if (isActive) {
4280
+ await this._createDelegatedInvitations(dataSpace, [
4281
+ [
4282
+ delegatedInvitation.credentialId,
4283
+ delegatedInvitation.invitation
4284
+ ]
4285
+ ]);
4286
+ } else {
4287
+ await this._invitationsManager.cancelInvitation(delegatedInvitation.invitation);
4288
+ }
4289
+ }
4290
+ async _createDelegatedInvitations(space, invitations) {
4291
+ const tasks = invitations.map(([credentialId, invitation]) => {
4292
+ return this._invitationsManager.createInvitation({
4293
+ type: import_services9.Invitation.Type.DELEGATED,
4294
+ kind: import_services9.Invitation.Kind.SPACE,
4295
+ spaceKey: space.key,
4296
+ authMethod: invitation.authMethod,
4297
+ invitationId: invitation.invitationId,
4298
+ swarmKey: invitation.swarmKey,
4299
+ guestKeypair: invitation.guestKey ? {
4300
+ publicKey: invitation.guestKey
4301
+ } : void 0,
4302
+ lifetime: invitation.expiresOn ? invitation.expiresOn.getTime() - Date.now() : void 0,
4303
+ multiUse: invitation.multiUse,
4304
+ delegationCredentialId: credentialId,
4305
+ persistent: false
4306
+ });
4307
+ });
4308
+ await Promise.all(tasks);
4309
+ }
4197
4310
  };
4198
4311
  _ts_decorate5([
4199
4312
  import_async13.synchronized
@@ -4230,10 +4343,10 @@ var SpacesServiceImpl = class {
4230
4343
  const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols10.SpaceNotFoundError(spaceKey));
4231
4344
  if (state) {
4232
4345
  switch (state) {
4233
- case import_services9.SpaceState.ACTIVE:
4346
+ case import_services10.SpaceState.ACTIVE:
4234
4347
  await space.activate();
4235
4348
  break;
4236
- case import_services9.SpaceState.INACTIVE:
4349
+ case import_services10.SpaceState.INACTIVE:
4237
4350
  await space.deactivate();
4238
4351
  break;
4239
4352
  default:
@@ -4407,7 +4520,7 @@ var SpacesServiceImpl = class {
4407
4520
  identityKey: member.key,
4408
4521
  profile: member.profile ?? {}
4409
4522
  },
4410
- presence: member.removed ? import_services9.SpaceMember.PresenceState.REMOVED : isMe || peers.length > 0 ? import_services9.SpaceMember.PresenceState.ONLINE : import_services9.SpaceMember.PresenceState.OFFLINE,
4523
+ presence: member.removed ? import_services10.SpaceMember.PresenceState.REMOVED : isMe || peers.length > 0 ? import_services10.SpaceMember.PresenceState.ONLINE : import_services10.SpaceMember.PresenceState.OFFLINE,
4411
4524
  peerStates: peers
4412
4525
  };
4413
4526
  }),
@@ -4418,84 +4531,6 @@ var SpacesServiceImpl = class {
4418
4531
  }
4419
4532
  };
4420
4533
  var getChannelId = (channel) => `user-channel/${channel}`;
4421
- var createSelectedDocumentsIterator = (automergeHost) => (
4422
- /**
4423
- * Get object data blobs from Automerge Repo by ids.
4424
- * @param ids
4425
- */
4426
- // TODO(mykola): Unload automerge handles after usage.
4427
- async function* loadDocuments(ids) {
4428
- for (const id of ids) {
4429
- const { documentId, objectId } = import_protocols12.idCodec.decode(id);
4430
- const handle = automergeHost.repo.handles[documentId] ?? automergeHost.repo.find(documentId);
4431
- if (!handle.isReady()) {
4432
- await handle.whenReady();
4433
- }
4434
- const doc = handle.docSync();
4435
- const hash = (0, import_automerge.getHeads)(doc).join("");
4436
- yield doc.objects?.[objectId] ? [
4437
- {
4438
- id,
4439
- object: doc.objects[objectId],
4440
- currentHash: hash
4441
- }
4442
- ] : [];
4443
- }
4444
- }
4445
- );
4446
- var createDocumentsIterator = (automergeHost) => (
4447
- /**
4448
- * Recursively get all object data blobs from Automerge Repo.
4449
- * @param ids
4450
- */
4451
- // TODO(mykola): Unload automerge handles after usage.
4452
- async function* getAllDocuments() {
4453
- const visited = /* @__PURE__ */ new Set();
4454
- async function* getObjectsFromHandle(handle) {
4455
- if (visited.has(handle.documentId)) {
4456
- return;
4457
- }
4458
- if (!handle.isReady()) {
4459
- await handle.whenReady();
4460
- }
4461
- const doc = handle.docSync();
4462
- const heads = (0, import_automerge.getHeads)(doc);
4463
- if (doc.objects) {
4464
- yield Object.entries(doc.objects).map(([objectId, object]) => {
4465
- return {
4466
- id: import_protocols12.idCodec.encode({
4467
- documentId: handle.documentId,
4468
- objectId
4469
- }),
4470
- object,
4471
- currentHash: heads.join("")
4472
- };
4473
- });
4474
- }
4475
- if (doc.links) {
4476
- for (const id of Object.values(doc.links)) {
4477
- if (visited.has(id)) {
4478
- continue;
4479
- }
4480
- const linkHandle = automergeHost.repo.handles[id] ?? automergeHost.repo.find(id);
4481
- for await (const result of getObjectsFromHandle(linkHandle)) {
4482
- yield result;
4483
- }
4484
- }
4485
- }
4486
- visited.add(handle.documentId);
4487
- }
4488
- for (const handle of Object.values(automergeHost.repo.handles)) {
4489
- if (visited.has(handle.documentId)) {
4490
- continue;
4491
- }
4492
- for await (const result of getObjectsFromHandle(handle)) {
4493
- yield result;
4494
- }
4495
- visited.add(handle.documentId);
4496
- }
4497
- }
4498
- );
4499
4534
  function _ts_decorate6(decorators, target, key, desc) {
4500
4535
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4501
4536
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -4507,7 +4542,7 @@ function _ts_decorate6(decorators, target, key, desc) {
4507
4542
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4508
4543
  }
4509
4544
  var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
4510
- var ServiceContext = class extends import_context9.Resource {
4545
+ var ServiceContext = class extends import_context10.Resource {
4511
4546
  constructor(storage, level, networkManager, signalManager, _runtimeParams) {
4512
4547
  super();
4513
4548
  this.storage = storage;
@@ -4517,7 +4552,7 @@ var ServiceContext = class extends import_context9.Resource {
4517
4552
  this._runtimeParams = _runtimeParams;
4518
4553
  this.initialized = new import_async15.Trigger();
4519
4554
  this._handlerFactories = /* @__PURE__ */ new Map();
4520
- this._instanceId = import_keys10.PublicKey.random().toHex();
4555
+ this._instanceId = import_keys11.PublicKey.random().toHex();
4521
4556
  this.metadataStore = new import_echo_pipeline4.MetadataStore(storage.createDirectory("metadata"));
4522
4557
  this.snapshotStore = new import_echo_pipeline4.SnapshotStore(storage.createDirectory("snapshots"));
4523
4558
  this.blobStore = new import_teleport_extension_object_sync.BlobStore(storage.createDirectory("blobs"));
@@ -4540,34 +4575,19 @@ var ServiceContext = class extends import_context9.Resource {
4540
4575
  snapshotStore: this.snapshotStore
4541
4576
  });
4542
4577
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager, this._runtimeParams);
4543
- this.indexMetadata = new import_indexing.IndexMetadataStore({
4544
- db: level.sublevel("index-metadata")
4545
- });
4546
- this.automergeHost = new import_echo_pipeline4.AutomergeHost({
4547
- directory: storage.createDirectory("automerge"),
4548
- db: level.sublevel("automerge"),
4549
- storageCallbacks: (0, import_indexing.createStorageCallbacks)({
4550
- host: () => this.automergeHost,
4551
- metadata: this.indexMetadata
4552
- })
4553
- });
4554
- this.indexer = new import_indexing.Indexer({
4555
- indexStore: new import_indexing.IndexStore({
4556
- db: level.sublevel("index-storage")
4557
- }),
4558
- metadataStore: this.indexMetadata,
4559
- loadDocuments: createSelectedDocumentsIterator(this.automergeHost),
4560
- getAllDocuments: createDocumentsIterator(this.automergeHost)
4578
+ this.echoHost = new import_echo_db.EchoHost({
4579
+ kv: this.level,
4580
+ storage: this.storage
4561
4581
  });
4562
4582
  this.invitations = new InvitationsHandler(this.networkManager);
4563
4583
  this.invitationsManager = new InvitationsManager(this.invitations, (invitation) => this.getInvitationHandler(invitation), this.metadataStore);
4564
- this._handlerFactories.set(import_services10.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug6.failUndefined)(), this._acceptIdentity.bind(this)));
4584
+ this._handlerFactories.set(import_services11.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug6.failUndefined)(), this._acceptIdentity.bind(this)));
4565
4585
  }
4566
4586
  async _open(ctx) {
4567
4587
  await this._checkStorageVersion();
4568
4588
  (0, import_log12.log)("opening...", void 0, {
4569
4589
  F: __dxlog_file14,
4570
- L: 164,
4590
+ L: 151,
4571
4591
  S: this,
4572
4592
  C: (f, a) => f(...a)
4573
4593
  });
@@ -4575,13 +4595,13 @@ var ServiceContext = class extends import_context9.Resource {
4575
4595
  id: this._instanceId
4576
4596
  }), {
4577
4597
  F: __dxlog_file14,
4578
- L: 165,
4598
+ L: 152,
4579
4599
  S: this,
4580
4600
  C: (f, a) => f(...a)
4581
4601
  });
4582
4602
  await this.signalManager.open();
4583
4603
  await this.networkManager.open();
4584
- await this.automergeHost.open();
4604
+ await this.echoHost.open(ctx);
4585
4605
  await this.metadataStore.load();
4586
4606
  await this.spaceManager.open();
4587
4607
  await this.identityManager.open(ctx);
@@ -4593,7 +4613,7 @@ var ServiceContext = class extends import_context9.Resource {
4593
4613
  count: loadedInvitations.invitations?.length
4594
4614
  }, {
4595
4615
  F: __dxlog_file14,
4596
- L: 178,
4616
+ L: 165,
4597
4617
  S: this,
4598
4618
  C: (f, a) => f(...a)
4599
4619
  });
@@ -4601,53 +4621,52 @@ var ServiceContext = class extends import_context9.Resource {
4601
4621
  id: this._instanceId
4602
4622
  }), {
4603
4623
  F: __dxlog_file14,
4604
- L: 180,
4624
+ L: 167,
4605
4625
  S: this,
4606
4626
  C: (f, a) => f(...a)
4607
4627
  });
4608
4628
  (0, import_log12.log)("opened", void 0, {
4609
4629
  F: __dxlog_file14,
4610
- L: 181,
4630
+ L: 168,
4611
4631
  S: this,
4612
4632
  C: (f, a) => f(...a)
4613
4633
  });
4614
4634
  }
4615
- async _close() {
4635
+ async _close(ctx) {
4616
4636
  (0, import_log12.log)("closing...", void 0, {
4617
4637
  F: __dxlog_file14,
4618
- L: 185,
4638
+ L: 172,
4619
4639
  S: this,
4620
4640
  C: (f, a) => f(...a)
4621
4641
  });
4622
4642
  if (this._deviceSpaceSync && this.identityManager.identity) {
4623
4643
  await this.identityManager.identity.space.spaceState.removeCredentialProcessor(this._deviceSpaceSync);
4624
4644
  }
4625
- await this.automergeHost.close();
4626
4645
  await this.dataSpaceManager?.close();
4627
4646
  await this.identityManager.close();
4628
4647
  await this.spaceManager.close();
4629
4648
  await this.feedStore.close();
4649
+ await this.metadataStore.close();
4650
+ await this.echoHost.close(ctx);
4630
4651
  await this.networkManager.close();
4631
4652
  await this.signalManager.close();
4632
- await this.metadataStore.close();
4633
- await this.indexer.destroy();
4634
4653
  (0, import_log12.log)("closed", void 0, {
4635
4654
  F: __dxlog_file14,
4636
- L: 198,
4655
+ L: 184,
4637
4656
  S: this,
4638
4657
  C: (f, a) => f(...a)
4639
4658
  });
4640
4659
  }
4641
4660
  async createIdentity(params = {}) {
4642
4661
  const identity = await this.identityManager.createIdentity(params);
4643
- await this._initialize(new import_context9.Context());
4662
+ await this._initialize(new import_context10.Context());
4644
4663
  return identity;
4645
4664
  }
4646
4665
  getInvitationHandler(invitation) {
4647
4666
  const factory = this._handlerFactories.get(invitation.kind);
4648
4667
  (0, import_invariant13.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
4649
4668
  F: __dxlog_file14,
4650
- L: 209,
4669
+ L: 195,
4651
4670
  S: this,
4652
4671
  A: [
4653
4672
  "factory",
@@ -4666,7 +4685,7 @@ var ServiceContext = class extends import_context9.Resource {
4666
4685
  }
4667
4686
  async _acceptIdentity(params) {
4668
4687
  const identity = await this.identityManager.acceptIdentity(params);
4669
- await this._initialize(new import_context9.Context());
4688
+ await this._initialize(new import_context10.Context());
4670
4689
  return identity;
4671
4690
  }
4672
4691
  async _checkStorageVersion() {
@@ -4679,7 +4698,7 @@ var ServiceContext = class extends import_context9.Resource {
4679
4698
  async _initialize(ctx) {
4680
4699
  (0, import_log12.log)("initializing spaces...", void 0, {
4681
4700
  F: __dxlog_file14,
4682
- L: 240,
4701
+ L: 226,
4683
4702
  S: this,
4684
4703
  C: (f, a) => f(...a)
4685
4704
  });
@@ -4697,12 +4716,12 @@ var ServiceContext = class extends import_context9.Resource {
4697
4716
  });
4698
4717
  }
4699
4718
  };
4700
- this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.automergeHost, this._runtimeParams);
4719
+ this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.echoHost, this.invitationsManager, this._runtimeParams);
4701
4720
  await this.dataSpaceManager.open();
4702
- this._handlerFactories.set(import_services10.Invitation.Kind.SPACE, (invitation) => {
4721
+ this._handlerFactories.set(import_services11.Invitation.Kind.SPACE, (invitation) => {
4703
4722
  (0, import_invariant13.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4704
4723
  F: __dxlog_file14,
4705
- L: 264,
4724
+ L: 251,
4706
4725
  S: this,
4707
4726
  A: [
4708
4727
  "this.dataSpaceManager",
@@ -4714,7 +4733,7 @@ var ServiceContext = class extends import_context9.Resource {
4714
4733
  this.initialized.wake();
4715
4734
  this._deviceSpaceSync = {
4716
4735
  processCredential: async (credential) => {
4717
- const assertion = (0, import_credentials14.getCredentialAssertion)(credential);
4736
+ const assertion = (0, import_credentials15.getCredentialAssertion)(credential);
4718
4737
  if (assertion["@type"] !== "dxos.halo.credentials.SpaceMember") {
4719
4738
  return;
4720
4739
  }
@@ -4726,7 +4745,7 @@ var ServiceContext = class extends import_context9.Resource {
4726
4745
  details: assertion
4727
4746
  }, {
4728
4747
  F: __dxlog_file14,
4729
- L: 280,
4748
+ L: 267,
4730
4749
  S: this,
4731
4750
  C: (f, a) => f(...a)
4732
4751
  });
@@ -4737,7 +4756,7 @@ var ServiceContext = class extends import_context9.Resource {
4737
4756
  details: assertion
4738
4757
  }, {
4739
4758
  F: __dxlog_file14,
4740
- L: 284,
4759
+ L: 271,
4741
4760
  S: this,
4742
4761
  C: (f, a) => f(...a)
4743
4762
  });
@@ -4748,7 +4767,7 @@ var ServiceContext = class extends import_context9.Resource {
4748
4767
  details: assertion
4749
4768
  }, {
4750
4769
  F: __dxlog_file14,
4751
- L: 289,
4770
+ L: 276,
4752
4771
  S: this,
4753
4772
  C: (f, a) => f(...a)
4754
4773
  });
@@ -4759,7 +4778,7 @@ var ServiceContext = class extends import_context9.Resource {
4759
4778
  } catch (err) {
4760
4779
  import_log12.log.catch(err, void 0, {
4761
4780
  F: __dxlog_file14,
4762
- L: 295,
4781
+ L: 282,
4763
4782
  S: this,
4764
4783
  C: (f, a) => f(...a)
4765
4784
  });
@@ -4801,26 +4820,26 @@ var ServiceRegistry = class {
4801
4820
  delete this._handlers[name];
4802
4821
  }
4803
4822
  };
4804
- var DXOS_VERSION = "0.4.10-main.4c8c73c";
4823
+ var DXOS_VERSION = "0.4.10-main.4d26ea7";
4805
4824
  var getPlatform = () => {
4806
4825
  if (process.browser) {
4807
4826
  if (typeof window !== "undefined") {
4808
4827
  const { userAgent } = window.navigator;
4809
4828
  return {
4810
- type: import_services12.Platform.PLATFORM_TYPE.BROWSER,
4829
+ type: import_services13.Platform.PLATFORM_TYPE.BROWSER,
4811
4830
  userAgent,
4812
4831
  uptime: Math.floor((Date.now() - window.performance.timeOrigin) / 1e3)
4813
4832
  };
4814
4833
  } else {
4815
4834
  return {
4816
- type: import_services12.Platform.PLATFORM_TYPE.SHARED_WORKER,
4835
+ type: import_services13.Platform.PLATFORM_TYPE.SHARED_WORKER,
4817
4836
  uptime: Math.floor((Date.now() - performance.timeOrigin) / 1e3)
4818
4837
  };
4819
4838
  }
4820
4839
  } else {
4821
4840
  const { platform: platform2, version, arch } = process;
4822
4841
  return {
4823
- type: import_services12.Platform.PLATFORM_TYPE.NODE,
4842
+ type: import_services13.Platform.PLATFORM_TYPE.NODE,
4824
4843
  platform: platform2,
4825
4844
  arch,
4826
4845
  runtime: version,
@@ -4838,7 +4857,7 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
4838
4857
  client: {
4839
4858
  version: DXOS_VERSION,
4840
4859
  storage: {
4841
- version: import_protocols13.STORAGE_VERSION
4860
+ version: import_protocols12.STORAGE_VERSION
4842
4861
  }
4843
4862
  },
4844
4863
  trace: import_tracing6.TRACE_PROCESSOR.getDiagnostics()
@@ -4907,7 +4926,7 @@ var getSpaceStats = async (space) => {
4907
4926
  const stats = {
4908
4927
  key: space.key,
4909
4928
  metrics: space.metrics,
4910
- epochs: space.inner.spaceState.credentials.filter((0, import_credentials15.credentialTypeFilter)("dxos.halo.credentials.Epoch")).map((credential) => ({
4929
+ epochs: space.inner.spaceState.credentials.filter((0, import_credentials16.credentialTypeFilter)("dxos.halo.credentials.Epoch")).map((credential) => ({
4911
4930
  ...credential.subject.assertion,
4912
4931
  id: credential.id
4913
4932
  })),
@@ -4918,7 +4937,7 @@ var getSpaceStats = async (space) => {
4918
4937
  displayName: member.assertion.profile?.displayName
4919
4938
  }
4920
4939
  },
4921
- presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? import_services11.SpaceMember.PresenceState.ONLINE : import_services11.SpaceMember.PresenceState.OFFLINE
4940
+ presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? import_services12.SpaceMember.PresenceState.ONLINE : import_services12.SpaceMember.PresenceState.OFFLINE
4922
4941
  })),
4923
4942
  pipeline: {
4924
4943
  // TODO(burdon): Pick properties from credentials if needed.
@@ -4982,9 +5001,9 @@ var DevicesServiceImpl = class {
4982
5001
  const peerState = peers.find((peer) => peer.identityKey.equals(key));
4983
5002
  return {
4984
5003
  deviceKey: key,
4985
- kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services15.DeviceKind.CURRENT : import_services15.DeviceKind.TRUSTED,
5004
+ kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services16.DeviceKind.CURRENT : import_services16.DeviceKind.TRUSTED,
4986
5005
  profile,
4987
- presence: isMe ? import_services15.Device.PresenceState.ONLINE : peerState ? import_services15.Device.PresenceState.ONLINE : import_services15.Device.PresenceState.OFFLINE
5006
+ presence: isMe ? import_services16.Device.PresenceState.ONLINE : peerState ? import_services16.Device.PresenceState.ONLINE : import_services16.Device.PresenceState.OFFLINE
4988
5007
  };
4989
5008
  })
4990
5009
  });
@@ -5083,7 +5102,7 @@ var LoggingServiceImpl = class {
5083
5102
  constructor() {
5084
5103
  this._logs = new import_async18.Event();
5085
5104
  this._started = Date.now();
5086
- this._sessionId = import_keys12.PublicKey.random().toHex();
5105
+ this._sessionId = import_keys13.PublicKey.random().toHex();
5087
5106
  this._logProcessor = (_config, entry2) => {
5088
5107
  this._logs.emit(entry2);
5089
5108
  };
@@ -5180,16 +5199,16 @@ var LoggingServiceImpl = class {
5180
5199
  };
5181
5200
  var matchFilter = (filter, level, path2, options) => {
5182
5201
  switch (options) {
5183
- case import_services16.QueryLogsRequest.MatchingOptions.INCLUSIVE:
5202
+ case import_services17.QueryLogsRequest.MatchingOptions.INCLUSIVE:
5184
5203
  return level >= filter.level && (!filter.pattern || path2.includes(filter.pattern));
5185
- case import_services16.QueryLogsRequest.MatchingOptions.EXPLICIT:
5204
+ case import_services17.QueryLogsRequest.MatchingOptions.EXPLICIT:
5186
5205
  return level === filter.level && (!filter.pattern || path2.includes(filter.pattern));
5187
5206
  }
5188
5207
  };
5189
5208
  var shouldLog = (entry2, request) => {
5190
- const options = request.options ?? import_services16.QueryLogsRequest.MatchingOptions.INCLUSIVE;
5209
+ const options = request.options ?? import_services17.QueryLogsRequest.MatchingOptions.INCLUSIVE;
5191
5210
  if (request.filters === void 0) {
5192
- return options === import_services16.QueryLogsRequest.MatchingOptions.INCLUSIVE;
5211
+ return options === import_services17.QueryLogsRequest.MatchingOptions.INCLUSIVE;
5193
5212
  } else {
5194
5213
  return request.filters.some((filter) => matchFilter(filter, entry2.level, entry2.meta?.F ?? "", options));
5195
5214
  }
@@ -5226,7 +5245,7 @@ var NetworkServiceImpl = class {
5226
5245
  }
5227
5246
  };
5228
5247
  var getRootPath = (config) => {
5229
- const { dataRoot = (0, import_util11.isNode)() ? import_client_protocol5.DX_DATA : "dxos/storage" } = config ?? {};
5248
+ const { dataRoot = (0, import_util11.isNode)() ? import_client_protocol6.DX_DATA : "dxos/storage" } = config ?? {};
5230
5249
  return `${dataRoot}/`;
5231
5250
  };
5232
5251
  var isPersistent = (config) => {
@@ -5237,16 +5256,16 @@ var StorageDriver = import_config2.Runtime.Client.Storage.StorageDriver;
5237
5256
  var createStorageObjects = (config) => {
5238
5257
  const { persistent = false, keyStore, dataStore } = config ?? {};
5239
5258
  if (persistent && dataStore === StorageDriver.RAM) {
5240
- throw new import_protocols15.InvalidConfigError("RAM storage cannot be used in persistent mode.");
5259
+ throw new import_protocols14.InvalidConfigError("RAM storage cannot be used in persistent mode.");
5241
5260
  }
5242
5261
  if (!persistent && dataStore !== void 0 && dataStore !== StorageDriver.RAM) {
5243
- throw new import_protocols15.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
5262
+ throw new import_protocols14.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
5244
5263
  }
5245
5264
  if (persistent && keyStore === StorageDriver.RAM) {
5246
- throw new import_protocols15.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
5265
+ throw new import_protocols14.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
5247
5266
  }
5248
5267
  if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== void 0) {
5249
- throw new import_protocols15.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
5268
+ throw new import_protocols14.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
5250
5269
  }
5251
5270
  return {
5252
5271
  storage: (0, import_random_access_storage.createStorage)({
@@ -5277,7 +5296,7 @@ var toStorageType = (type) => {
5277
5296
  };
5278
5297
  var createLevel = async (config) => {
5279
5298
  const persistent = isPersistent(config);
5280
- const storagePath = persistent ? import_node_path.default.join(getRootPath(config), "level") : `/tmp/dxos-${import_keys13.PublicKey.random().toHex()}`;
5299
+ const storagePath = persistent ? import_node_path.default.join(getRootPath(config), "level") : `/tmp/dxos-${import_keys14.PublicKey.random().toHex()}`;
5281
5300
  const level = new import_level.Level(storagePath);
5282
5301
  await level.open();
5283
5302
  return level;
@@ -5302,8 +5321,8 @@ var SystemServiceImpl = class {
5302
5321
  return {
5303
5322
  timestamp: /* @__PURE__ */ new Date(),
5304
5323
  diagnostics: JSON.parse(JSON.stringify(diagnostics, (0, import_util12.jsonKeyReplacer)({
5305
- truncate: keys === import_services17.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
5306
- humanize: keys === import_services17.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
5324
+ truncate: keys === import_services18.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
5325
+ humanize: keys === import_services18.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
5307
5326
  })))
5308
5327
  };
5309
5328
  }
@@ -5377,7 +5396,7 @@ var ClientServicesHost = class {
5377
5396
  lockKey,
5378
5397
  onAcquire: () => {
5379
5398
  if (!this._opening) {
5380
- void this.open(new import_context10.Context());
5399
+ void this.open(new import_context11.Context());
5381
5400
  }
5382
5401
  },
5383
5402
  onRelease: () => this.close()
@@ -5386,14 +5405,14 @@ var ClientServicesHost = class {
5386
5405
  this._systemService = new SystemServiceImpl({
5387
5406
  config: () => this._config,
5388
5407
  statusUpdate: this._statusUpdate,
5389
- getCurrentStatus: () => this.isOpen ? import_services14.SystemStatus.ACTIVE : import_services14.SystemStatus.INACTIVE,
5408
+ getCurrentStatus: () => this.isOpen ? import_services15.SystemStatus.ACTIVE : import_services15.SystemStatus.INACTIVE,
5390
5409
  getDiagnostics: () => {
5391
5410
  return createDiagnostics(this._serviceRegistry.services, this._serviceContext, this._config);
5392
5411
  },
5393
5412
  onUpdateStatus: async (status) => {
5394
- if (!this.isOpen && status === import_services14.SystemStatus.ACTIVE) {
5413
+ if (!this.isOpen && status === import_services15.SystemStatus.ACTIVE) {
5395
5414
  await this._resourceLock?.acquire();
5396
- } else if (this.isOpen && status === import_services14.SystemStatus.INACTIVE) {
5415
+ } else if (this.isOpen && status === import_services15.SystemStatus.INACTIVE) {
5397
5416
  await this._resourceLock?.release();
5398
5417
  }
5399
5418
  },
@@ -5403,7 +5422,7 @@ var ClientServicesHost = class {
5403
5422
  });
5404
5423
  this.diagnosticsBroadcastHandler = createCollectDiagnosticsBroadcastHandler(this._systemService);
5405
5424
  this._loggingService = new LoggingServiceImpl();
5406
- this._serviceRegistry = new ServiceRegistry(import_client_protocol4.clientServiceBundle, {
5425
+ this._serviceRegistry = new ServiceRegistry(import_client_protocol5.clientServiceBundle, {
5407
5426
  SystemService: this._systemService,
5408
5427
  TracingService: this._tracingService
5409
5428
  });
@@ -5434,7 +5453,7 @@ var ClientServicesHost = class {
5434
5453
  initialize({ config, ...options }) {
5435
5454
  (0, import_invariant15.invariant)(!this._open, "service host is open", {
5436
5455
  F: __dxlog_file18,
5437
- L: 198,
5456
+ L: 190,
5438
5457
  S: this,
5439
5458
  A: [
5440
5459
  "!this._open",
@@ -5443,14 +5462,14 @@ var ClientServicesHost = class {
5443
5462
  });
5444
5463
  (0, import_log13.log)("initializing...", void 0, {
5445
5464
  F: __dxlog_file18,
5446
- L: 199,
5465
+ L: 191,
5447
5466
  S: this,
5448
5467
  C: (f, a) => f(...a)
5449
5468
  });
5450
5469
  if (config) {
5451
5470
  (0, import_invariant15.invariant)(!this._config, "config already set", {
5452
5471
  F: __dxlog_file18,
5453
- L: 202,
5472
+ L: 194,
5454
5473
  S: this,
5455
5474
  A: [
5456
5475
  "!this._config",
@@ -5465,7 +5484,7 @@ var ClientServicesHost = class {
5465
5484
  if (!options.signalManager) {
5466
5485
  import_log13.log.warn("running signaling without telemetry metadata.", void 0, {
5467
5486
  F: __dxlog_file18,
5468
- L: 210,
5487
+ L: 202,
5469
5488
  S: this,
5470
5489
  C: (f, a) => f(...a)
5471
5490
  });
@@ -5476,7 +5495,7 @@ var ClientServicesHost = class {
5476
5495
  this._signalManager = signalManager;
5477
5496
  (0, import_invariant15.invariant)(!this._networkManager, "network manager already set", {
5478
5497
  F: __dxlog_file18,
5479
- L: 221,
5498
+ L: 213,
5480
5499
  S: this,
5481
5500
  A: [
5482
5501
  "!this._networkManager",
@@ -5490,7 +5509,7 @@ var ClientServicesHost = class {
5490
5509
  });
5491
5510
  (0, import_log13.log)("initialized", void 0, {
5492
5511
  F: __dxlog_file18,
5493
- L: 228,
5512
+ L: 220,
5494
5513
  S: this,
5495
5514
  C: (f, a) => f(...a)
5496
5515
  });
@@ -5499,18 +5518,18 @@ var ClientServicesHost = class {
5499
5518
  if (this._open) {
5500
5519
  return;
5501
5520
  }
5502
- const traceId = import_keys11.PublicKey.random().toHex();
5503
- import_log13.log.trace("dxos.client-services.host.open", import_protocols14.trace.begin({
5521
+ const traceId = import_keys12.PublicKey.random().toHex();
5522
+ import_log13.log.trace("dxos.client-services.host.open", import_protocols13.trace.begin({
5504
5523
  id: traceId
5505
5524
  }), {
5506
5525
  F: __dxlog_file18,
5507
- L: 239,
5526
+ L: 231,
5508
5527
  S: this,
5509
5528
  C: (f, a) => f(...a)
5510
5529
  });
5511
5530
  (0, import_invariant15.invariant)(this._config, "config not set", {
5512
5531
  F: __dxlog_file18,
5513
- L: 241,
5532
+ L: 233,
5514
5533
  S: this,
5515
5534
  A: [
5516
5535
  "this._config",
@@ -5519,7 +5538,7 @@ var ClientServicesHost = class {
5519
5538
  });
5520
5539
  (0, import_invariant15.invariant)(this._storage, "storage not set", {
5521
5540
  F: __dxlog_file18,
5522
- L: 242,
5541
+ L: 234,
5523
5542
  S: this,
5524
5543
  A: [
5525
5544
  "this._storage",
@@ -5528,7 +5547,7 @@ var ClientServicesHost = class {
5528
5547
  });
5529
5548
  (0, import_invariant15.invariant)(this._signalManager, "signal manager not set", {
5530
5549
  F: __dxlog_file18,
5531
- L: 243,
5550
+ L: 235,
5532
5551
  S: this,
5533
5552
  A: [
5534
5553
  "this._signalManager",
@@ -5537,7 +5556,7 @@ var ClientServicesHost = class {
5537
5556
  });
5538
5557
  (0, import_invariant15.invariant)(this._networkManager, "network manager not set", {
5539
5558
  F: __dxlog_file18,
5540
- L: 244,
5559
+ L: 236,
5541
5560
  S: this,
5542
5561
  A: [
5543
5562
  "this._networkManager",
@@ -5549,7 +5568,7 @@ var ClientServicesHost = class {
5549
5568
  lockKey: this._resourceLock?.lockKey
5550
5569
  }, {
5551
5570
  F: __dxlog_file18,
5552
- L: 247,
5571
+ L: 239,
5553
5572
  S: this,
5554
5573
  C: (f, a) => f(...a)
5555
5574
  });
@@ -5560,11 +5579,6 @@ var ClientServicesHost = class {
5560
5579
  await this._resourceLock?.acquire();
5561
5580
  await this._loggingService.open();
5562
5581
  this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._runtimeParams);
5563
- this._queryService = new import_indexing2.QueryServiceImpl({
5564
- indexer: this._serviceContext.indexer,
5565
- automergeHost: this._serviceContext.automergeHost
5566
- });
5567
- await this._queryService.open(ctx);
5568
5582
  this._serviceRegistry.setServices({
5569
5583
  SystemService: this._systemService,
5570
5584
  IdentityService: new IdentityServiceImpl((params) => this._createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring, (profile) => this._serviceContext.broadcastProfileUpdate(profile)),
@@ -5574,8 +5588,8 @@ var ClientServicesHost = class {
5574
5588
  await this._serviceContext.initialized.wait();
5575
5589
  return this._serviceContext.dataSpaceManager;
5576
5590
  }),
5577
- DataService: new import_echo_pipeline5.DataServiceImpl(this._serviceContext.automergeHost),
5578
- QueryService: this._queryService,
5591
+ DataService: this._serviceContext.echoHost.dataService,
5592
+ QueryService: this._serviceContext.echoHost.queryService,
5579
5593
  NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager, this._serviceContext.signalManager),
5580
5594
  LoggingService: this._loggingService,
5581
5595
  TracingService: this._tracingService,
@@ -5592,7 +5606,7 @@ var ClientServicesHost = class {
5592
5606
  this._devtoolsProxy = new import_websocket_rpc.WebsocketRpcClient({
5593
5607
  url: devtoolsProxy,
5594
5608
  requested: {},
5595
- exposed: import_client_protocol4.clientServiceBundle,
5609
+ exposed: import_client_protocol5.clientServiceBundle,
5596
5610
  handlers: this.services
5597
5611
  });
5598
5612
  void this._devtoolsProxy.open();
@@ -5606,15 +5620,15 @@ var ClientServicesHost = class {
5606
5620
  deviceKey
5607
5621
  }, {
5608
5622
  F: __dxlog_file18,
5609
- L: 330,
5623
+ L: 315,
5610
5624
  S: this,
5611
5625
  C: (f, a) => f(...a)
5612
5626
  });
5613
- import_log13.log.trace("dxos.client-services.host.open", import_protocols14.trace.end({
5627
+ import_log13.log.trace("dxos.client-services.host.open", import_protocols13.trace.end({
5614
5628
  id: traceId
5615
5629
  }), {
5616
5630
  F: __dxlog_file18,
5617
- L: 331,
5631
+ L: 316,
5618
5632
  S: this,
5619
5633
  C: (f, a) => f(...a)
5620
5634
  });
@@ -5628,7 +5642,7 @@ var ClientServicesHost = class {
5628
5642
  deviceKey
5629
5643
  }, {
5630
5644
  F: __dxlog_file18,
5631
- L: 342,
5645
+ L: 327,
5632
5646
  S: this,
5633
5647
  C: (f, a) => f(...a)
5634
5648
  });
@@ -5638,7 +5652,6 @@ var ClientServicesHost = class {
5638
5652
  SystemService: this._systemService
5639
5653
  });
5640
5654
  await this._loggingService.close();
5641
- await this._queryService.close();
5642
5655
  await this._serviceContext.close();
5643
5656
  await this._level?.close();
5644
5657
  this._open = false;
@@ -5647,24 +5660,24 @@ var ClientServicesHost = class {
5647
5660
  deviceKey
5648
5661
  }, {
5649
5662
  F: __dxlog_file18,
5650
- L: 352,
5663
+ L: 336,
5651
5664
  S: this,
5652
5665
  C: (f, a) => f(...a)
5653
5666
  });
5654
5667
  }
5655
5668
  async reset() {
5656
- const traceId = import_keys11.PublicKey.random().toHex();
5657
- import_log13.log.trace("dxos.sdk.client-services-host.reset", import_protocols14.trace.begin({
5669
+ const traceId = import_keys12.PublicKey.random().toHex();
5670
+ import_log13.log.trace("dxos.sdk.client-services-host.reset", import_protocols13.trace.begin({
5658
5671
  id: traceId
5659
5672
  }), {
5660
5673
  F: __dxlog_file18,
5661
- L: 357,
5674
+ L: 341,
5662
5675
  S: this,
5663
5676
  C: (f, a) => f(...a)
5664
5677
  });
5665
5678
  (0, import_log13.log)("resetting...", void 0, {
5666
5679
  F: __dxlog_file18,
5667
- L: 359,
5680
+ L: 343,
5668
5681
  S: this,
5669
5682
  C: (f, a) => f(...a)
5670
5683
  });
@@ -5672,15 +5685,15 @@ var ClientServicesHost = class {
5672
5685
  await this._storage.reset();
5673
5686
  (0, import_log13.log)("reset", void 0, {
5674
5687
  F: __dxlog_file18,
5675
- L: 362,
5688
+ L: 346,
5676
5689
  S: this,
5677
5690
  C: (f, a) => f(...a)
5678
5691
  });
5679
- import_log13.log.trace("dxos.sdk.client-services-host.reset", import_protocols14.trace.end({
5692
+ import_log13.log.trace("dxos.sdk.client-services-host.reset", import_protocols13.trace.end({
5680
5693
  id: traceId
5681
5694
  }), {
5682
5695
  F: __dxlog_file18,
5683
- L: 363,
5696
+ L: 347,
5684
5697
  S: this,
5685
5698
  C: (f, a) => f(...a)
5686
5699
  });
@@ -5693,34 +5706,34 @@ var ClientServicesHost = class {
5693
5706
  const automergeIndex = space.automergeSpaceState.rootUrl;
5694
5707
  (0, import_invariant15.invariant)(automergeIndex, void 0, {
5695
5708
  F: __dxlog_file18,
5696
- L: 375,
5709
+ L: 359,
5697
5710
  S: this,
5698
5711
  A: [
5699
5712
  "automergeIndex",
5700
5713
  ""
5701
5714
  ]
5702
5715
  });
5703
- const document = await this._serviceContext.automergeHost.repo.find(automergeIndex);
5716
+ const document = await this._serviceContext.echoHost.automergeRepo.find(automergeIndex);
5704
5717
  await document.whenReady();
5705
5718
  const properties = {
5706
5719
  system: {
5707
- type: (0, import_echo_pipeline5.encodeReference)((0, import_echo_schema.getTypeReference)(import_client_protocol4.Properties))
5720
+ type: (0, import_echo_pipeline5.encodeReference)((0, import_echo_schema2.getTypeReference)(import_client_protocol5.Properties))
5708
5721
  },
5709
5722
  data: {
5710
- [import_client_protocol4.defaultKey]: identity.identityKey.toHex()
5723
+ [import_client_protocol5.defaultKey]: identity.identityKey.toHex()
5711
5724
  },
5712
5725
  meta: {
5713
5726
  keys: []
5714
5727
  }
5715
5728
  };
5716
- const propertiesId = import_keys11.PublicKey.random().toHex();
5729
+ const propertiesId = import_keys12.PublicKey.random().toHex();
5717
5730
  document.change((doc) => {
5718
5731
  (0, import_util9.assignDeep)(doc, [
5719
5732
  "objects",
5720
5733
  propertiesId
5721
5734
  ], properties);
5722
5735
  });
5723
- await this._serviceContext.automergeHost.repo.flush();
5736
+ await this._serviceContext.echoHost.flush();
5724
5737
  return identity;
5725
5738
  }
5726
5739
  };
@@ -5748,7 +5761,7 @@ var DiagnosticsCollector = class {
5748
5761
  }
5749
5762
  static async collect(config = findConfigs(), services = findSystemServiceProvider(), options = {}) {
5750
5763
  const serviceDiagnostics = await services?.services?.SystemService?.getDiagnostics({
5751
- keys: options.humanize ? import_services13.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE : options.truncate ? import_services13.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE : void 0
5764
+ keys: options.humanize ? import_services14.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE : options.truncate ? import_services14.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE : void 0
5752
5765
  });
5753
5766
  const clientDiagnostics = {
5754
5767
  config,
@@ -5813,4 +5826,4 @@ var findConfigs = () => {
5813
5826
  subscribeToSpaces,
5814
5827
  subscribeToSwarmInfo
5815
5828
  });
5816
- //# sourceMappingURL=chunk-IPO3WM44.cjs.map
5829
+ //# sourceMappingURL=chunk-LE3INNLG.cjs.map