@dxos/client-services 0.5.1-next.2ad6c47 → 0.5.1-next.39e0ee2

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 (86) hide show
  1. package/dist/lib/browser/{chunk-CMVTOS5E.mjs → chunk-YFXM4YAE.mjs} +1337 -1040
  2. package/dist/lib/browser/chunk-YFXM4YAE.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +36 -5
  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 +36 -14
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/{chunk-EAWN3LCD.cjs → chunk-DSYIRKI6.cjs} +1463 -1170
  9. package/dist/lib/node/chunk-DSYIRKI6.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +78 -47
  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 +40 -18
  14. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  15. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +2 -1
  16. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
  17. package/dist/types/src/packlets/invitations/invitation-guest-extenstion.d.ts +39 -0
  18. package/dist/types/src/packlets/invitations/invitation-guest-extenstion.d.ts.map +1 -0
  19. package/dist/types/src/packlets/invitations/{invitation-extension.d.ts → invitation-host-extension.d.ts} +17 -31
  20. package/dist/types/src/packlets/invitations/invitation-host-extension.d.ts.map +1 -0
  21. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +6 -1
  22. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
  23. package/dist/types/src/packlets/invitations/invitation-topology.d.ts +37 -0
  24. package/dist/types/src/packlets/invitations/invitation-topology.d.ts.map +1 -0
  25. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +19 -10
  26. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  27. package/dist/types/src/packlets/invitations/invitations-handler.test.d.ts +2 -0
  28. package/dist/types/src/packlets/invitations/invitations-handler.test.d.ts.map +1 -0
  29. package/dist/types/src/packlets/invitations/invitations-manager.d.ts +2 -1
  30. package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -1
  31. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +1 -0
  32. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  33. package/dist/types/src/packlets/invitations/utils.d.ts +6 -0
  34. package/dist/types/src/packlets/invitations/utils.d.ts.map +1 -0
  35. package/dist/types/src/packlets/services/service-context.d.ts +12 -11
  36. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  37. package/dist/types/src/packlets/services/service-host.d.ts +1 -2
  38. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  39. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +4 -3
  40. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  41. package/dist/types/src/packlets/spaces/data-space.d.ts +4 -3
  42. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  43. package/dist/types/src/packlets/storage/level.d.ts +1 -2
  44. package/dist/types/src/packlets/storage/level.d.ts.map +1 -1
  45. package/dist/types/src/packlets/testing/invitation-utils.d.ts +2 -1
  46. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  47. package/dist/types/src/packlets/testing/test-builder.d.ts +5 -3
  48. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  49. package/dist/types/src/packlets/vault/shell-runtime.d.ts +10 -2
  50. package/dist/types/src/packlets/vault/shell-runtime.d.ts.map +1 -1
  51. package/dist/types/src/packlets/vault/worker-runtime.d.ts.map +1 -1
  52. package/dist/types/src/version.d.ts +1 -1
  53. package/package.json +36 -35
  54. package/src/packlets/invitations/device-invitation-protocol.ts +5 -1
  55. package/src/packlets/invitations/invitation-guest-extenstion.ts +126 -0
  56. package/src/packlets/invitations/{invitation-extension.ts → invitation-host-extension.ts} +99 -105
  57. package/src/packlets/invitations/invitation-protocol.ts +7 -1
  58. package/src/packlets/invitations/invitation-topology.ts +87 -0
  59. package/src/packlets/invitations/invitations-handler.test.ts +361 -0
  60. package/src/packlets/invitations/invitations-handler.ts +246 -149
  61. package/src/packlets/invitations/invitations-manager.ts +42 -3
  62. package/src/packlets/invitations/space-invitation-protocol.ts +19 -1
  63. package/src/packlets/invitations/utils.ts +27 -0
  64. package/src/packlets/services/automerge-host.test.ts +6 -4
  65. package/src/packlets/services/service-context.test.ts +3 -3
  66. package/src/packlets/services/service-context.ts +18 -31
  67. package/src/packlets/services/service-host.test.ts +6 -0
  68. package/src/packlets/services/service-host.ts +9 -26
  69. package/src/packlets/spaces/data-space-manager.test.ts +4 -4
  70. package/src/packlets/spaces/data-space-manager.ts +8 -11
  71. package/src/packlets/spaces/data-space.ts +14 -18
  72. package/src/packlets/storage/level.ts +3 -2
  73. package/src/packlets/testing/invitation-utils.ts +23 -3
  74. package/src/packlets/testing/test-builder.ts +13 -15
  75. package/src/packlets/vault/shell-runtime.ts +40 -2
  76. package/src/packlets/vault/worker-runtime.ts +3 -1
  77. package/src/version.ts +1 -1
  78. package/dist/lib/browser/chunk-CMVTOS5E.mjs.map +0 -7
  79. package/dist/lib/node/chunk-EAWN3LCD.cjs.map +0 -7
  80. package/dist/types/src/packlets/indexing/index.d.ts +0 -2
  81. package/dist/types/src/packlets/indexing/index.d.ts.map +0 -1
  82. package/dist/types/src/packlets/indexing/util.d.ts +0 -11
  83. package/dist/types/src/packlets/indexing/util.d.ts.map +0 -1
  84. package/dist/types/src/packlets/invitations/invitation-extension.d.ts.map +0 -1
  85. package/src/packlets/indexing/index.ts +0 -5
  86. package/src/packlets/indexing/util.ts +0 -32
@@ -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_EAWN3LCD_exports = {};
30
- __export(chunk_EAWN3LCD_exports, {
29
+ var chunk_DSYIRKI6_exports = {};
30
+ __export(chunk_DSYIRKI6_exports, {
31
31
  ClientRpcServer: () => ClientRpcServer,
32
32
  ClientServicesHost: () => ClientServicesHost,
33
33
  ClientServicesProviderResource: () => ClientServicesProviderResource,
@@ -66,7 +66,7 @@ __export(chunk_EAWN3LCD_exports, {
66
66
  subscribeToSpaces: () => subscribeToSpaces,
67
67
  subscribeToSwarmInfo: () => subscribeToSwarmInfo
68
68
  });
69
- module.exports = __toCommonJS(chunk_EAWN3LCD_exports);
69
+ module.exports = __toCommonJS(chunk_DSYIRKI6_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");
@@ -128,158 +128,171 @@ var import_network_manager = require("@dxos/network-manager");
128
128
  var import_protocols4 = require("@dxos/protocols");
129
129
  var import_services3 = require("@dxos/protocols/proto/dxos/client/services");
130
130
  var import_invitations = require("@dxos/protocols/proto/dxos/halo/invitations");
131
+ var import_invitations2 = require("@dxos/protocols/proto/dxos/halo/invitations");
132
+ var import_util4 = require("@dxos/util");
131
133
  var import_async8 = require("@dxos/async");
132
134
  var import_context5 = require("@dxos/context");
133
- var import_crypto2 = require("@dxos/crypto");
134
135
  var import_invariant6 = require("@dxos/invariant");
135
- var import_keys6 = require("@dxos/keys");
136
136
  var import_log5 = require("@dxos/log");
137
137
  var import_protocols5 = require("@dxos/protocols");
138
- var import_services4 = require("@dxos/protocols/proto/dxos/client/services");
139
- var import_invitations2 = require("@dxos/protocols/proto/dxos/halo/invitations");
138
+ var import_invitations3 = require("@dxos/protocols/proto/dxos/halo/invitations");
140
139
  var import_teleport = require("@dxos/teleport");
141
- var import_codec_protobuf8 = require("@dxos/codec-protobuf");
142
- var import_services5 = require("@dxos/protocols/proto/dxos/client/services");
143
- var import_credentials7 = require("@dxos/credentials");
144
- var import_feed_store3 = require("@dxos/feed-store");
140
+ var import_context6 = require("@dxos/context");
141
+ var import_services4 = require("@dxos/protocols/proto/dxos/client/services");
142
+ var import_async9 = require("@dxos/async");
143
+ var import_context7 = require("@dxos/context");
144
+ var import_crypto2 = require("@dxos/crypto");
145
145
  var import_invariant7 = require("@dxos/invariant");
146
+ var import_keys6 = require("@dxos/keys");
146
147
  var import_log6 = require("@dxos/log");
147
148
  var import_protocols6 = require("@dxos/protocols");
149
+ var import_services5 = require("@dxos/protocols/proto/dxos/client/services");
150
+ var import_invitations4 = require("@dxos/protocols/proto/dxos/halo/invitations");
151
+ var import_teleport2 = require("@dxos/teleport");
152
+ var import_invariant8 = require("@dxos/invariant");
153
+ var import_keys7 = require("@dxos/keys");
154
+ var import_log7 = require("@dxos/log");
155
+ var import_invitations5 = require("@dxos/protocols/proto/dxos/halo/invitations");
156
+ var import_util5 = require("@dxos/util");
157
+ var import_codec_protobuf8 = require("@dxos/codec-protobuf");
148
158
  var import_services6 = require("@dxos/protocols/proto/dxos/client/services");
159
+ var import_credentials7 = require("@dxos/credentials");
160
+ var import_feed_store3 = require("@dxos/feed-store");
161
+ var import_invariant9 = require("@dxos/invariant");
162
+ var import_log8 = require("@dxos/log");
163
+ var import_protocols7 = require("@dxos/protocols");
164
+ var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
149
165
  var import_credentials8 = require("@dxos/protocols/proto/dxos/halo/credentials");
150
- var import_async9 = require("@dxos/async");
166
+ var import_async10 = require("@dxos/async");
151
167
  var import_client_protocol3 = require("@dxos/client-protocol");
152
- var import_context6 = require("@dxos/context");
168
+ var import_context8 = require("@dxos/context");
153
169
  var import_credentials9 = require("@dxos/credentials");
154
170
  var import_echo_pipeline = require("@dxos/echo-pipeline");
155
- var import_invariant8 = require("@dxos/invariant");
156
- var import_keys7 = require("@dxos/keys");
157
- var import_log7 = require("@dxos/log");
158
- var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
171
+ var import_invariant10 = require("@dxos/invariant");
172
+ var import_keys8 = require("@dxos/keys");
173
+ var import_log9 = require("@dxos/log");
174
+ var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
159
175
  var import_codec_protobuf9 = require("@dxos/codec-protobuf");
160
176
  var import_debug2 = require("@dxos/debug");
161
177
  var import_rpc = require("@dxos/rpc");
162
178
  var import_tracing3 = require("@dxos/tracing");
163
- var import_async10 = require("@dxos/async");
179
+ var import_async11 = require("@dxos/async");
164
180
  var import_client_protocol4 = require("@dxos/client-protocol");
165
- var import_context7 = require("@dxos/context");
181
+ var import_context9 = require("@dxos/context");
166
182
  var import_debug3 = require("@dxos/debug");
167
183
  var import_echo_pipeline2 = require("@dxos/echo-pipeline");
168
184
  var import_echo_pipeline3 = require("@dxos/echo-pipeline");
169
185
  var import_echo_schema = require("@dxos/echo-schema");
170
- var import_invariant9 = require("@dxos/invariant");
171
- var import_keys8 = require("@dxos/keys");
172
- var import_log8 = require("@dxos/log");
173
- var import_protocols7 = require("@dxos/protocols");
174
- var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
186
+ var import_invariant11 = require("@dxos/invariant");
187
+ var import_keys9 = require("@dxos/keys");
188
+ var import_log10 = require("@dxos/log");
189
+ var import_protocols8 = require("@dxos/protocols");
190
+ var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
175
191
  var import_credentials10 = require("@dxos/protocols/proto/dxos/halo/credentials");
176
192
  var import_timeframe2 = require("@dxos/timeframe");
177
193
  var import_tracing4 = require("@dxos/tracing");
178
- var import_util4 = require("@dxos/util");
179
- var import_async11 = require("@dxos/async");
180
- var import_credentials11 = require("@dxos/credentials");
194
+ var import_util6 = require("@dxos/util");
181
195
  var import_async12 = require("@dxos/async");
182
- var import_context8 = require("@dxos/context");
183
- var import_invariant10 = require("@dxos/invariant");
184
- var import_keys9 = require("@dxos/keys");
185
- var import_log9 = require("@dxos/log");
186
- var import_protocols8 = require("@dxos/protocols");
187
- var import_teleport2 = require("@dxos/teleport");
188
- var import_util5 = require("@dxos/util");
196
+ var import_credentials11 = require("@dxos/credentials");
189
197
  var import_async13 = require("@dxos/async");
190
- var import_context9 = require("@dxos/context");
191
- var import_credentials12 = require("@dxos/credentials");
192
- var import_invariant11 = require("@dxos/invariant");
198
+ var import_context10 = require("@dxos/context");
199
+ var import_invariant12 = require("@dxos/invariant");
193
200
  var import_keys10 = require("@dxos/keys");
194
- var import_log10 = require("@dxos/log");
201
+ var import_log11 = require("@dxos/log");
195
202
  var import_protocols9 = require("@dxos/protocols");
196
- var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
203
+ var import_teleport3 = require("@dxos/teleport");
204
+ var import_util7 = require("@dxos/util");
205
+ var import_async14 = require("@dxos/async");
206
+ var import_context11 = require("@dxos/context");
207
+ var import_credentials12 = require("@dxos/credentials");
208
+ var import_invariant13 = require("@dxos/invariant");
209
+ var import_keys11 = require("@dxos/keys");
210
+ var import_log12 = require("@dxos/log");
211
+ var import_protocols10 = require("@dxos/protocols");
212
+ var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
197
213
  var import_teleport_extension_gossip2 = require("@dxos/teleport-extension-gossip");
198
- var import_util6 = require("@dxos/util");
214
+ var import_util8 = require("@dxos/util");
199
215
  var import_credentials13 = require("@dxos/credentials");
200
216
  var import_debug4 = require("@dxos/debug");
201
217
  var import_credentials14 = require("@dxos/protocols/proto/dxos/halo/credentials");
202
218
  var import_timeframe3 = require("@dxos/timeframe");
203
- var import_async14 = require("@dxos/async");
219
+ var import_async15 = require("@dxos/async");
204
220
  var import_codec_protobuf10 = require("@dxos/codec-protobuf");
205
221
  var import_debug5 = require("@dxos/debug");
206
- var import_invariant12 = require("@dxos/invariant");
207
- var import_log11 = require("@dxos/log");
208
- var import_protocols10 = require("@dxos/protocols");
209
- var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
210
- var import_async15 = require("@dxos/async");
211
- var import_context10 = require("@dxos/context");
222
+ var import_invariant14 = require("@dxos/invariant");
223
+ var import_log13 = require("@dxos/log");
224
+ var import_protocols11 = require("@dxos/protocols");
225
+ var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
226
+ var import_async16 = require("@dxos/async");
227
+ var import_context12 = require("@dxos/context");
212
228
  var import_credentials15 = require("@dxos/credentials");
213
229
  var import_debug6 = require("@dxos/debug");
230
+ var import_echo_db = require("@dxos/echo-db");
214
231
  var import_echo_pipeline4 = require("@dxos/echo-pipeline");
215
232
  var import_feed_store4 = require("@dxos/feed-store");
216
- var import_indexing = require("@dxos/indexing");
217
- var import_invariant13 = require("@dxos/invariant");
233
+ var import_invariant15 = require("@dxos/invariant");
218
234
  var import_keyring = require("@dxos/keyring");
219
- var import_keys11 = require("@dxos/keys");
220
- var import_log12 = require("@dxos/log");
221
- var import_protocols11 = require("@dxos/protocols");
222
- var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
235
+ var import_keys12 = require("@dxos/keys");
236
+ var import_log14 = require("@dxos/log");
237
+ var import_protocols12 = require("@dxos/protocols");
238
+ var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
223
239
  var import_teleport_extension_object_sync = require("@dxos/teleport-extension-object-sync");
224
240
  var import_tracing5 = require("@dxos/tracing");
225
- var import_util7 = require("@dxos/util");
226
- var import_automerge = require("@dxos/automerge/automerge");
227
- var import_protocols12 = require("@dxos/protocols");
241
+ var import_util9 = require("@dxos/util");
228
242
  var import_codec_protobuf11 = require("@dxos/codec-protobuf");
229
243
  var import_credentials16 = require("@dxos/credentials");
230
- var import_invariant14 = require("@dxos/invariant");
244
+ var import_invariant16 = require("@dxos/invariant");
231
245
  var import_protocols13 = require("@dxos/protocols");
232
- var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
233
- var import_tracing6 = require("@dxos/tracing");
234
246
  var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
235
- var import_config = require("@dxos/config");
247
+ var import_tracing6 = require("@dxos/tracing");
236
248
  var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
249
+ var import_config = require("@dxos/config");
250
+ var import_services15 = require("@dxos/protocols/proto/dxos/client/services");
237
251
  var import_tracing7 = require("@dxos/tracing");
238
- var import_util8 = require("@dxos/util");
239
- var import_async16 = require("@dxos/async");
252
+ var import_util10 = require("@dxos/util");
253
+ var import_async17 = require("@dxos/async");
240
254
  var import_client_protocol5 = require("@dxos/client-protocol");
241
- var import_context11 = require("@dxos/context");
242
- var import_echo_pipeline5 = require("@dxos/echo-pipeline");
255
+ var import_context13 = require("@dxos/context");
256
+ var import_echo_protocol = require("@dxos/echo-protocol");
243
257
  var import_echo_schema2 = require("@dxos/echo-schema");
244
- var import_indexing2 = require("@dxos/indexing");
245
- var import_invariant15 = require("@dxos/invariant");
246
- var import_keys12 = require("@dxos/keys");
247
- var import_log13 = require("@dxos/log");
258
+ var import_invariant17 = require("@dxos/invariant");
259
+ var import_keys13 = require("@dxos/keys");
260
+ var import_log15 = require("@dxos/log");
248
261
  var import_messaging = require("@dxos/messaging");
249
262
  var import_network_manager2 = require("@dxos/network-manager");
250
263
  var import_protocols14 = require("@dxos/protocols");
251
- var import_services15 = require("@dxos/protocols/proto/dxos/client/services");
264
+ var import_services16 = require("@dxos/protocols/proto/dxos/client/services");
252
265
  var import_tracing8 = require("@dxos/tracing");
253
- var import_util9 = require("@dxos/util");
266
+ var import_util11 = require("@dxos/util");
254
267
  var import_websocket_rpc = require("@dxos/websocket-rpc");
255
- var import_async17 = require("@dxos/async");
268
+ var import_async18 = require("@dxos/async");
256
269
  var import_codec_protobuf12 = require("@dxos/codec-protobuf");
257
- var import_invariant16 = require("@dxos/invariant");
258
- var import_services16 = require("@dxos/protocols/proto/dxos/client/services");
259
- var import_invariant17 = require("@dxos/invariant");
270
+ var import_invariant18 = require("@dxos/invariant");
271
+ var import_services17 = require("@dxos/protocols/proto/dxos/client/services");
272
+ var import_invariant19 = require("@dxos/invariant");
260
273
  var import_lock_file = require("@dxos/lock-file");
261
- var import_log14 = require("@dxos/log");
262
- var import_async18 = require("@dxos/async");
274
+ var import_log16 = require("@dxos/log");
275
+ var import_async19 = require("@dxos/async");
263
276
  var import_codec_protobuf13 = require("@dxos/codec-protobuf");
264
- var import_keys13 = require("@dxos/keys");
265
- var import_log15 = require("@dxos/log");
266
- var import_services17 = require("@dxos/protocols/proto/dxos/client/services");
267
- var import_util10 = require("@dxos/util");
277
+ var import_keys14 = require("@dxos/keys");
278
+ var import_log17 = require("@dxos/log");
279
+ var import_services18 = require("@dxos/protocols/proto/dxos/client/services");
280
+ var import_util12 = require("@dxos/util");
268
281
  var import_codec_protobuf14 = require("@dxos/codec-protobuf");
269
282
  var import_protocols15 = require("@dxos/protocols");
270
283
  var import_config2 = require("@dxos/protocols/proto/dxos/config");
271
284
  var import_random_access_storage = require("@dxos/random-access-storage");
272
285
  var import_client_protocol6 = require("@dxos/client-protocol");
273
286
  var import_config3 = require("@dxos/protocols/proto/dxos/config");
274
- var import_util11 = require("@dxos/util");
275
- var import_level = require("level");
287
+ var import_util13 = require("@dxos/util");
276
288
  var import_node_path = __toESM(require("node:path"));
277
- var import_keys14 = require("@dxos/keys");
278
- var import_codec_protobuf15 = require("@dxos/codec-protobuf");
279
- var import_services18 = require("@dxos/protocols/proto/dxos/client/services");
280
- var import_util12 = require("@dxos/util");
281
289
  var import_keys15 = require("@dxos/keys");
282
- var import_util13 = require("@dxos/util");
290
+ var import_kv_store = require("@dxos/kv-store");
291
+ var import_codec_protobuf15 = require("@dxos/codec-protobuf");
292
+ var import_services19 = require("@dxos/protocols/proto/dxos/client/services");
293
+ var import_util14 = require("@dxos/util");
294
+ var import_keys16 = require("@dxos/keys");
295
+ var import_util15 = require("@dxos/util");
283
296
  var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
284
297
  return new import_codec_protobuf.Stream(({ next }) => {
285
298
  const subscriptions = new import_async.EventSubscriptions();
@@ -1396,13 +1409,16 @@ var DeviceInvitationProtocol = class {
1396
1409
  kind: import_services2.Invitation.Kind.DEVICE
1397
1410
  };
1398
1411
  }
1399
- async delegate(invitation) {
1412
+ async delegate() {
1413
+ throw new Error("delegation not supported");
1414
+ }
1415
+ async cancelDelegation() {
1400
1416
  throw new Error("delegation not supported");
1401
1417
  }
1402
1418
  async admit(_, request) {
1403
1419
  (0, import_invariant4.invariant)(request.device, void 0, {
1404
1420
  F: __dxlog_file5,
1405
- L: 42,
1421
+ L: 46,
1406
1422
  S: this,
1407
1423
  A: [
1408
1424
  "request.device",
@@ -1448,7 +1464,7 @@ var DeviceInvitationProtocol = class {
1448
1464
  async accept(response, request) {
1449
1465
  (0, import_invariant4.invariant)(response.device, void 0, {
1450
1466
  F: __dxlog_file5,
1451
- L: 87,
1467
+ L: 91,
1452
1468
  S: this,
1453
1469
  A: [
1454
1470
  "response.device",
@@ -1458,7 +1474,7 @@ var DeviceInvitationProtocol = class {
1458
1474
  const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
1459
1475
  (0, import_invariant4.invariant)(request.device, void 0, {
1460
1476
  F: __dxlog_file5,
1461
- L: 90,
1477
+ L: 94,
1462
1478
  S: this,
1463
1479
  A: [
1464
1480
  "request.device",
@@ -1481,11 +1497,25 @@ var DeviceInvitationProtocol = class {
1481
1497
  };
1482
1498
  }
1483
1499
  };
1484
- var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-extension.ts";
1500
+ var stateToString = (state) => {
1501
+ return Object.entries(import_services4.Invitation.State).find(([key, val]) => val === state)?.[0] ?? "unknown";
1502
+ };
1503
+ var tryAcquireBeforeContextDisposed = async (ctx, mutex) => {
1504
+ let guard;
1505
+ return (0, import_context6.cancelWithContext)(ctx, (async () => {
1506
+ guard = await mutex.acquire();
1507
+ if (ctx.disposed) {
1508
+ guard.release();
1509
+ guard = void 0;
1510
+ throw new import_context6.ContextDisposedError();
1511
+ }
1512
+ return guard;
1513
+ })());
1514
+ };
1515
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts";
1485
1516
  var OPTIONS_TIMEOUT = 1e4;
1486
- var MAX_OTP_ATTEMPTS = 3;
1487
- var InvitationHostExtension = class extends import_teleport.RpcExtension {
1488
- constructor(_callbacks) {
1517
+ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1518
+ constructor(_invitationFlowMutex, _callbacks) {
1489
1519
  super({
1490
1520
  requested: {
1491
1521
  InvitationHostService: import_protocols5.schema.getService("dxos.halo.invitations.InvitationHostService")
@@ -1494,15 +1524,140 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1494
1524
  InvitationHostService: import_protocols5.schema.getService("dxos.halo.invitations.InvitationHostService")
1495
1525
  }
1496
1526
  });
1527
+ this._invitationFlowMutex = _invitationFlowMutex;
1497
1528
  this._callbacks = _callbacks;
1498
1529
  this._ctx = new import_context5.Context();
1499
1530
  this._remoteOptionsTrigger = new import_async8.Trigger();
1531
+ this._invitationFlowLock = null;
1532
+ }
1533
+ hasFlowLock() {
1534
+ return this._invitationFlowLock != null;
1535
+ }
1536
+ async getHandlers() {
1537
+ return {
1538
+ InvitationHostService: {
1539
+ options: async (options) => {
1540
+ (0, import_invariant6.invariant)(!this._remoteOptions, "Remote options already set.", {
1541
+ F: __dxlog_file6,
1542
+ L: 63,
1543
+ S: this,
1544
+ A: [
1545
+ "!this._remoteOptions",
1546
+ "'Remote options already set.'"
1547
+ ]
1548
+ });
1549
+ this._remoteOptions = options;
1550
+ this._remoteOptionsTrigger.wake();
1551
+ },
1552
+ introduce: () => {
1553
+ throw new Error("Method not allowed.");
1554
+ },
1555
+ authenticate: () => {
1556
+ throw new Error("Method not allowed.");
1557
+ },
1558
+ admit: () => {
1559
+ throw new Error("Method not allowed.");
1560
+ }
1561
+ }
1562
+ };
1563
+ }
1564
+ async onOpen(context) {
1565
+ await super.onOpen(context);
1566
+ try {
1567
+ (0, import_log5.log)("guest acquire lock", void 0, {
1568
+ F: __dxlog_file6,
1569
+ L: 84,
1570
+ S: this,
1571
+ C: (f, a) => f(...a)
1572
+ });
1573
+ this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
1574
+ (0, import_log5.log)("guest lock acquired", void 0, {
1575
+ F: __dxlog_file6,
1576
+ L: 86,
1577
+ S: this,
1578
+ C: (f, a) => f(...a)
1579
+ });
1580
+ await (0, import_context5.cancelWithContext)(this._ctx, this.rpc.InvitationHostService.options({
1581
+ role: import_invitations3.Options.Role.GUEST
1582
+ }));
1583
+ (0, import_log5.log)("options sent", void 0, {
1584
+ F: __dxlog_file6,
1585
+ L: 88,
1586
+ S: this,
1587
+ C: (f, a) => f(...a)
1588
+ });
1589
+ await (0, import_context5.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
1590
+ timeout: OPTIONS_TIMEOUT
1591
+ }));
1592
+ (0, import_log5.log)("options received", void 0, {
1593
+ F: __dxlog_file6,
1594
+ L: 90,
1595
+ S: this,
1596
+ C: (f, a) => f(...a)
1597
+ });
1598
+ if (this._remoteOptions?.role !== import_invitations3.Options.Role.HOST) {
1599
+ throw new import_protocols5.InvalidInvitationExtensionRoleError(void 0, {
1600
+ expected: import_invitations3.Options.Role.HOST,
1601
+ remoteOptions: this._remoteOptions,
1602
+ remotePeerId: context.remotePeerId
1603
+ });
1604
+ }
1605
+ this._callbacks.onOpen(this._ctx, context);
1606
+ } catch (err) {
1607
+ if (this._invitationFlowLock != null) {
1608
+ this._callbacks.onError(err);
1609
+ }
1610
+ if (!this._ctx.disposed) {
1611
+ context.close(err);
1612
+ }
1613
+ }
1614
+ }
1615
+ async onClose() {
1616
+ await this._destroy();
1617
+ }
1618
+ async onAbort() {
1619
+ await this._destroy();
1620
+ }
1621
+ async _destroy() {
1622
+ await this._ctx.dispose();
1623
+ if (this._invitationFlowLock != null) {
1624
+ this._invitationFlowLock.release();
1625
+ this._invitationFlowLock = null;
1626
+ (0, import_log5.log)("invitation flow lock released", void 0, {
1627
+ F: __dxlog_file6,
1628
+ L: 123,
1629
+ S: this,
1630
+ C: (f, a) => f(...a)
1631
+ });
1632
+ }
1633
+ }
1634
+ };
1635
+ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts";
1636
+ var OPTIONS_TIMEOUT2 = 1e4;
1637
+ var MAX_OTP_ATTEMPTS = 3;
1638
+ var InvitationHostExtension = class extends import_teleport2.RpcExtension {
1639
+ constructor(_invitationFlowMutex, _callbacks) {
1640
+ super({
1641
+ requested: {
1642
+ InvitationHostService: import_protocols6.schema.getService("dxos.halo.invitations.InvitationHostService")
1643
+ },
1644
+ exposed: {
1645
+ InvitationHostService: import_protocols6.schema.getService("dxos.halo.invitations.InvitationHostService")
1646
+ }
1647
+ });
1648
+ this._invitationFlowMutex = _invitationFlowMutex;
1649
+ this._callbacks = _callbacks;
1650
+ this._ctx = new import_context7.Context();
1651
+ this._remoteOptionsTrigger = new import_async9.Trigger();
1500
1652
  this._challenge = void 0;
1501
- this.invitation = void 0;
1502
1653
  this.guestProfile = void 0;
1503
1654
  this.authenticationPassed = false;
1504
1655
  this.authenticationRetry = 0;
1505
- this.completedTrigger = new import_async8.Trigger();
1656
+ this.completedTrigger = new import_async9.Trigger();
1657
+ this._invitationFlowLock = null;
1658
+ }
1659
+ hasFlowLock() {
1660
+ return this._invitationFlowLock != null;
1506
1661
  }
1507
1662
  async getHandlers() {
1508
1663
  return {
@@ -1510,9 +1665,9 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1510
1665
  // Perhaps in the future we will have more complex logic here.
1511
1666
  InvitationHostService: {
1512
1667
  options: async (options) => {
1513
- (0, import_invariant6.invariant)(!this._remoteOptions, "Remote options already set.", {
1514
- F: __dxlog_file6,
1515
- L: 90,
1668
+ (0, import_invariant7.invariant)(!this._remoteOptions, "Remote options already set.", {
1669
+ F: __dxlog_file7,
1670
+ L: 101,
1516
1671
  S: this,
1517
1672
  A: [
1518
1673
  "!this._remoteOptions",
@@ -1525,143 +1680,149 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1525
1680
  introduce: async (request) => {
1526
1681
  const { profile, invitationId } = request;
1527
1682
  const traceId = import_keys6.PublicKey.random().toHex();
1528
- import_log5.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols5.trace.begin({
1683
+ import_log6.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols6.trace.begin({
1529
1684
  id: traceId
1530
1685
  }), {
1531
- F: __dxlog_file6,
1532
- L: 99,
1686
+ F: __dxlog_file7,
1687
+ L: 110,
1533
1688
  S: this,
1534
1689
  C: (f, a) => f(...a)
1535
1690
  });
1536
- const invitation = await this._callbacks.resolveInvitation(request);
1537
- if (!invitation) {
1538
- import_log5.log.warn("invitation not found", {
1539
- invitationId
1691
+ const invitation = this._requireActiveInvitation();
1692
+ this._assertInvitationState(import_services5.Invitation.State.CONNECTED);
1693
+ if (invitationId !== invitation?.invitationId) {
1694
+ import_log6.log.warn("incorrect invitationId", {
1695
+ expected: invitation.invitationId,
1696
+ actual: invitationId
1540
1697
  }, {
1541
- F: __dxlog_file6,
1542
- L: 103,
1698
+ F: __dxlog_file7,
1699
+ L: 116,
1543
1700
  S: this,
1544
1701
  C: (f, a) => f(...a)
1545
1702
  });
1546
- this._callbacks.onError(new Error("Invitation not found."));
1703
+ this._callbacks.onError(new Error("Incorrect invitationId."));
1704
+ (0, import_async9.scheduleTask)(this._ctx, () => this.close());
1547
1705
  return {
1548
- authMethod: import_services4.Invitation.AuthMethod.NONE
1706
+ authMethod: import_services5.Invitation.AuthMethod.NONE
1549
1707
  };
1550
1708
  }
1551
- this.invitation = invitation;
1552
- (0, import_log5.log)("guest introduced itself", {
1709
+ (0, import_log6.log)("guest introduced themselves", {
1553
1710
  guestProfile: profile
1554
1711
  }, {
1555
- F: __dxlog_file6,
1556
- L: 112,
1712
+ F: __dxlog_file7,
1713
+ L: 125,
1557
1714
  S: this,
1558
1715
  C: (f, a) => f(...a)
1559
1716
  });
1560
1717
  this.guestProfile = profile;
1561
- this._callbacks.onStateUpdate({
1562
- ...this.invitation,
1563
- state: import_services4.Invitation.State.READY_FOR_AUTHENTICATION
1564
- });
1565
- this._challenge = this.invitation.authMethod === import_services4.Invitation.AuthMethod.KNOWN_PUBLIC_KEY ? (0, import_crypto2.randomBytes)(32) : void 0;
1566
- import_log5.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols5.trace.end({
1718
+ this._callbacks.onStateUpdate(import_services5.Invitation.State.READY_FOR_AUTHENTICATION);
1719
+ this._challenge = invitation.authMethod === import_services5.Invitation.AuthMethod.KNOWN_PUBLIC_KEY ? (0, import_crypto2.randomBytes)(32) : void 0;
1720
+ import_log6.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols6.trace.end({
1567
1721
  id: traceId
1568
1722
  }), {
1569
- F: __dxlog_file6,
1570
- L: 122,
1723
+ F: __dxlog_file7,
1724
+ L: 132,
1571
1725
  S: this,
1572
1726
  C: (f, a) => f(...a)
1573
1727
  });
1574
1728
  return {
1575
- authMethod: this.invitation.authMethod,
1729
+ authMethod: invitation.authMethod,
1576
1730
  challenge: this._challenge
1577
1731
  };
1578
1732
  },
1579
1733
  authenticate: async ({ authCode: code, signedChallenge }) => {
1580
1734
  const traceId = import_keys6.PublicKey.random().toHex();
1581
- import_log5.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols5.trace.begin({
1735
+ import_log6.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols6.trace.begin({
1582
1736
  id: traceId
1583
1737
  }), {
1584
- F: __dxlog_file6,
1585
- L: 131,
1738
+ F: __dxlog_file7,
1739
+ L: 141,
1586
1740
  S: this,
1587
1741
  C: (f, a) => f(...a)
1588
1742
  });
1589
- (0, import_log5.log)("received authentication request", {
1743
+ const invitation = this._requireActiveInvitation();
1744
+ (0, import_log6.log)("received authentication request", {
1590
1745
  authCode: code
1591
1746
  }, {
1592
- F: __dxlog_file6,
1593
- L: 132,
1747
+ F: __dxlog_file7,
1748
+ L: 144,
1594
1749
  S: this,
1595
1750
  C: (f, a) => f(...a)
1596
1751
  });
1597
- let status = import_invitations2.AuthenticationResponse.Status.OK;
1598
- (0, import_invariant6.invariant)(this.invitation, "Invitation is not set.", {
1599
- F: __dxlog_file6,
1600
- L: 135,
1601
- S: this,
1602
- A: [
1603
- "this.invitation",
1604
- "'Invitation is not set.'"
1605
- ]
1606
- });
1607
- switch (this.invitation.authMethod) {
1608
- case import_services4.Invitation.AuthMethod.NONE: {
1609
- (0, import_log5.log)("authentication not required", void 0, {
1610
- F: __dxlog_file6,
1611
- L: 138,
1752
+ let status = import_invitations4.AuthenticationResponse.Status.OK;
1753
+ this._assertInvitationState([
1754
+ import_services5.Invitation.State.AUTHENTICATING,
1755
+ import_services5.Invitation.State.READY_FOR_AUTHENTICATION
1756
+ ]);
1757
+ this._callbacks.onStateUpdate(import_services5.Invitation.State.AUTHENTICATING);
1758
+ switch (invitation.authMethod) {
1759
+ case import_services5.Invitation.AuthMethod.NONE: {
1760
+ (0, import_log6.log)("authentication not required", void 0, {
1761
+ F: __dxlog_file7,
1762
+ L: 152,
1612
1763
  S: this,
1613
1764
  C: (f, a) => f(...a)
1614
1765
  });
1615
1766
  return {
1616
- status: import_invitations2.AuthenticationResponse.Status.OK
1767
+ status: import_invitations4.AuthenticationResponse.Status.OK
1617
1768
  };
1618
1769
  }
1619
- case import_services4.Invitation.AuthMethod.SHARED_SECRET: {
1620
- if (this.invitation.authCode) {
1770
+ case import_services5.Invitation.AuthMethod.SHARED_SECRET: {
1771
+ if (invitation.authCode) {
1621
1772
  if (this.authenticationRetry++ > MAX_OTP_ATTEMPTS) {
1622
- status = import_invitations2.AuthenticationResponse.Status.INVALID_OPT_ATTEMPTS;
1623
- } else if (code !== this.invitation.authCode) {
1624
- status = import_invitations2.AuthenticationResponse.Status.INVALID_OTP;
1773
+ status = import_invitations4.AuthenticationResponse.Status.INVALID_OPT_ATTEMPTS;
1774
+ } else if (code !== invitation.authCode) {
1775
+ status = import_invitations4.AuthenticationResponse.Status.INVALID_OTP;
1625
1776
  } else {
1626
1777
  this.authenticationPassed = true;
1627
1778
  }
1628
1779
  }
1629
1780
  break;
1630
1781
  }
1631
- case import_services4.Invitation.AuthMethod.KNOWN_PUBLIC_KEY: {
1632
- if (!this.invitation.guestKeypair) {
1633
- status = import_invitations2.AuthenticationResponse.Status.INTERNAL_ERROR;
1782
+ case import_services5.Invitation.AuthMethod.KNOWN_PUBLIC_KEY: {
1783
+ if (!invitation.guestKeypair) {
1784
+ status = import_invitations4.AuthenticationResponse.Status.INTERNAL_ERROR;
1634
1785
  break;
1635
1786
  }
1636
- const isSignatureValid = this._challenge && (0, import_crypto2.verify)(this._challenge, Buffer.from(signedChallenge ?? []), this.invitation.guestKeypair.publicKey.asBuffer());
1787
+ const isSignatureValid = this._challenge && (0, import_crypto2.verify)(this._challenge, Buffer.from(signedChallenge ?? []), invitation.guestKeypair.publicKey.asBuffer());
1637
1788
  if (isSignatureValid) {
1638
1789
  this.authenticationPassed = true;
1639
1790
  } else {
1640
- status = import_invitations2.AuthenticationResponse.Status.INVALID_SIGNATURE;
1791
+ status = import_invitations4.AuthenticationResponse.Status.INVALID_SIGNATURE;
1641
1792
  }
1642
1793
  break;
1643
1794
  }
1644
1795
  default: {
1645
- import_log5.log.error("invalid authentication method", {
1646
- authMethod: this.invitation.authMethod
1796
+ import_log6.log.error("invalid authentication method", {
1797
+ authMethod: invitation.authMethod
1647
1798
  }, {
1648
- F: __dxlog_file6,
1649
- L: 176,
1799
+ F: __dxlog_file7,
1800
+ L: 190,
1650
1801
  S: this,
1651
1802
  C: (f, a) => f(...a)
1652
1803
  });
1653
- status = import_invitations2.AuthenticationResponse.Status.INTERNAL_ERROR;
1804
+ status = import_invitations4.AuthenticationResponse.Status.INTERNAL_ERROR;
1654
1805
  break;
1655
1806
  }
1656
1807
  }
1657
- import_log5.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols5.trace.end({
1808
+ if (![
1809
+ import_invitations4.AuthenticationResponse.Status.OK,
1810
+ import_invitations4.AuthenticationResponse.Status.INVALID_OTP
1811
+ ].includes(status)) {
1812
+ this._callbacks.onError(new Error(`Authentication failed, with status=${status}`));
1813
+ (0, import_async9.scheduleTask)(this._ctx, () => this.close());
1814
+ return {
1815
+ status
1816
+ };
1817
+ }
1818
+ import_log6.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols6.trace.end({
1658
1819
  id: traceId,
1659
1820
  data: {
1660
1821
  status
1661
1822
  }
1662
1823
  }), {
1663
- F: __dxlog_file6,
1664
- L: 182,
1824
+ F: __dxlog_file7,
1825
+ L: 202,
1665
1826
  S: this,
1666
1827
  C: (f, a) => f(...a)
1667
1828
  });
@@ -1671,33 +1832,28 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1671
1832
  },
1672
1833
  admit: async (request) => {
1673
1834
  const traceId = import_keys6.PublicKey.random().toHex();
1674
- import_log5.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols5.trace.begin({
1835
+ import_log6.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols6.trace.begin({
1675
1836
  id: traceId
1676
1837
  }), {
1677
- F: __dxlog_file6,
1678
- L: 188,
1838
+ F: __dxlog_file7,
1839
+ L: 208,
1679
1840
  S: this,
1680
1841
  C: (f, a) => f(...a)
1681
1842
  });
1843
+ const invitation = this._requireActiveInvitation();
1682
1844
  try {
1683
- (0, import_invariant6.invariant)(this.invitation, "Invitation is not set.", {
1684
- F: __dxlog_file6,
1685
- L: 191,
1686
- S: this,
1687
- A: [
1688
- "this.invitation",
1689
- "'Invitation is not set.'"
1690
- ]
1691
- });
1692
- if (isAuthenticationRequired(this.invitation) && !this.authenticationPassed) {
1693
- throw new Error("Not authenticated");
1845
+ if (isAuthenticationRequired(invitation)) {
1846
+ this._assertInvitationState(import_services5.Invitation.State.AUTHENTICATING);
1847
+ if (!this.authenticationPassed) {
1848
+ throw new Error("Not authenticated");
1849
+ }
1694
1850
  }
1695
1851
  const response = await this._callbacks.admit(request);
1696
- import_log5.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols5.trace.end({
1852
+ import_log6.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols6.trace.end({
1697
1853
  id: traceId
1698
1854
  }), {
1699
- F: __dxlog_file6,
1700
- L: 199,
1855
+ F: __dxlog_file7,
1856
+ L: 222,
1701
1857
  S: this,
1702
1858
  C: (f, a) => f(...a)
1703
1859
  });
@@ -1713,147 +1869,195 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1713
1869
  async onOpen(context) {
1714
1870
  await super.onOpen(context);
1715
1871
  try {
1872
+ (0, import_log6.log)("host acquire lock", void 0, {
1873
+ F: __dxlog_file7,
1874
+ L: 237,
1875
+ S: this,
1876
+ C: (f, a) => f(...a)
1877
+ });
1878
+ this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
1879
+ (0, import_log6.log)("host lock acquired", void 0, {
1880
+ F: __dxlog_file7,
1881
+ L: 239,
1882
+ S: this,
1883
+ C: (f, a) => f(...a)
1884
+ });
1885
+ const lastState = this._requireActiveInvitation().state;
1886
+ this._callbacks.onStateUpdate(import_services5.Invitation.State.CONNECTING);
1716
1887
  await this.rpc.InvitationHostService.options({
1717
- role: import_invitations2.Options.Role.HOST
1888
+ role: import_invitations4.Options.Role.HOST
1718
1889
  });
1719
- await (0, import_context5.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
1720
- timeout: OPTIONS_TIMEOUT
1890
+ (0, import_log6.log)("options sent", void 0, {
1891
+ F: __dxlog_file7,
1892
+ L: 243,
1893
+ S: this,
1894
+ C: (f, a) => f(...a)
1895
+ });
1896
+ await (0, import_context7.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
1897
+ timeout: OPTIONS_TIMEOUT2
1721
1898
  }));
1722
- if (this._remoteOptions?.role !== import_invitations2.Options.Role.GUEST) {
1723
- throw new import_protocols5.InvalidInvitationExtensionRoleError(void 0, {
1724
- expected: import_invitations2.Options.Role.GUEST,
1725
- remoteOptions: this._remoteOptions
1899
+ (0, import_log6.log)("options received", void 0, {
1900
+ F: __dxlog_file7,
1901
+ L: 245,
1902
+ S: this,
1903
+ C: (f, a) => f(...a)
1904
+ });
1905
+ if (this._remoteOptions?.role !== import_invitations4.Options.Role.GUEST) {
1906
+ this._callbacks.onStateUpdate(lastState);
1907
+ throw new import_protocols6.InvalidInvitationExtensionRoleError(void 0, {
1908
+ expected: import_invitations4.Options.Role.GUEST,
1909
+ remoteOptions: this._remoteOptions,
1910
+ remotePeerId: context.remotePeerId
1726
1911
  });
1727
1912
  }
1728
- this._callbacks.onOpen();
1913
+ this._callbacks.onStateUpdate(import_services5.Invitation.State.CONNECTED);
1914
+ this._callbacks.onOpen(this._ctx, context);
1729
1915
  } catch (err) {
1730
- this._callbacks.onError(err);
1916
+ if (this._invitationFlowLock != null) {
1917
+ this._callbacks.onError(err);
1918
+ }
1919
+ if (!this._ctx.disposed) {
1920
+ context.close(err);
1921
+ }
1731
1922
  }
1732
1923
  }
1733
- async onClose() {
1734
- await this._ctx.dispose();
1924
+ _requireActiveInvitation() {
1925
+ const invitation = this._callbacks.activeInvitation;
1926
+ if (invitation == null) {
1927
+ (0, import_async9.scheduleTask)(this._ctx, () => this.close());
1928
+ throw new Error("Active invitation not found");
1929
+ }
1930
+ return invitation;
1735
1931
  }
1736
- };
1737
- var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1738
- constructor(_callbacks) {
1739
- super({
1740
- requested: {
1741
- InvitationHostService: import_protocols5.schema.getService("dxos.halo.invitations.InvitationHostService")
1742
- },
1743
- exposed: {
1744
- InvitationHostService: import_protocols5.schema.getService("dxos.halo.invitations.InvitationHostService")
1745
- }
1746
- });
1747
- this._callbacks = _callbacks;
1748
- this._ctx = new import_context5.Context();
1749
- this._remoteOptionsTrigger = new import_async8.Trigger();
1932
+ _assertInvitationState(stateOrMany) {
1933
+ const invitation = this._requireActiveInvitation();
1934
+ const validStates = Array.isArray(stateOrMany) ? stateOrMany : [
1935
+ stateOrMany
1936
+ ];
1937
+ if (!validStates.includes(invitation.state)) {
1938
+ (0, import_async9.scheduleTask)(this._ctx, () => this.close());
1939
+ throw new import_invariant7.InvariantViolation(`Expected ${stateToString(invitation.state)} to be one of [${validStates.map(stateToString).join(", ")}]`);
1940
+ }
1750
1941
  }
1751
- async getHandlers() {
1752
- return {
1753
- InvitationHostService: {
1754
- options: async (options) => {
1755
- (0, import_invariant6.invariant)(!this._remoteOptions, "Remote options already set.", {
1756
- F: __dxlog_file6,
1757
- L: 266,
1758
- S: this,
1759
- A: [
1760
- "!this._remoteOptions",
1761
- "'Remote options already set.'"
1762
- ]
1763
- });
1764
- this._remoteOptions = options;
1765
- this._remoteOptionsTrigger.wake();
1766
- },
1767
- introduce: () => {
1768
- throw new Error("Method not allowed.");
1769
- },
1770
- authenticate: () => {
1771
- throw new Error("Method not allowed.");
1772
- },
1773
- admit: () => {
1774
- throw new Error("Method not allowed.");
1775
- }
1776
- }
1777
- };
1942
+ async onClose() {
1943
+ await this._destroy();
1778
1944
  }
1779
- async onOpen(context) {
1780
- await super.onOpen(context);
1781
- try {
1782
- (0, import_log5.log)("begin options", void 0, {
1783
- F: __dxlog_file6,
1784
- L: 287,
1785
- S: this,
1786
- C: (f, a) => f(...a)
1787
- });
1788
- await (0, import_context5.cancelWithContext)(this._ctx, this.rpc.InvitationHostService.options({
1789
- role: import_invitations2.Options.Role.GUEST
1790
- }));
1791
- await (0, import_context5.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
1792
- timeout: OPTIONS_TIMEOUT
1793
- }));
1794
- (0, import_log5.log)("end options", void 0, {
1795
- F: __dxlog_file6,
1796
- L: 290,
1945
+ async onAbort() {
1946
+ await this._destroy();
1947
+ }
1948
+ async _destroy() {
1949
+ await this._ctx.dispose();
1950
+ if (this._invitationFlowLock != null) {
1951
+ this._invitationFlowLock?.release();
1952
+ this._invitationFlowLock = null;
1953
+ (0, import_log6.log)("invitation flow lock released", void 0, {
1954
+ F: __dxlog_file7,
1955
+ L: 300,
1797
1956
  S: this,
1798
1957
  C: (f, a) => f(...a)
1799
1958
  });
1800
- if (this._remoteOptions?.role !== import_invitations2.Options.Role.HOST) {
1801
- throw new import_protocols5.InvalidInvitationExtensionRoleError(void 0, {
1802
- expected: import_invitations2.Options.Role.HOST,
1803
- remoteOptions: this._remoteOptions
1804
- });
1805
- }
1806
- this._callbacks.onOpen(this._ctx);
1807
- } catch (err) {
1808
- (0, import_log5.log)("openError", err, {
1809
- F: __dxlog_file6,
1810
- L: 300,
1959
+ }
1960
+ }
1961
+ };
1962
+ var isAuthenticationRequired = (invitation) => invitation.authMethod !== import_services5.Invitation.AuthMethod.NONE;
1963
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts";
1964
+ var InvitationTopology = class {
1965
+ constructor(_role) {
1966
+ this._role = _role;
1967
+ this._seenPeers = new import_util5.ComplexSet(import_keys7.PublicKey.hash);
1968
+ }
1969
+ init(controller) {
1970
+ (0, import_invariant8.invariant)(!this._controller, "Already initialized.", {
1971
+ F: __dxlog_file8,
1972
+ L: 42,
1973
+ S: this,
1974
+ A: [
1975
+ "!this._controller",
1976
+ "'Already initialized.'"
1977
+ ]
1978
+ });
1979
+ this._controller = controller;
1980
+ }
1981
+ update() {
1982
+ (0, import_invariant8.invariant)(this._controller, "Not initialized.", {
1983
+ F: __dxlog_file8,
1984
+ L: 47,
1985
+ S: this,
1986
+ A: [
1987
+ "this._controller",
1988
+ "'Not initialized.'"
1989
+ ]
1990
+ });
1991
+ const { ownPeerId, candidates, connected, allPeers } = this._controller.getState();
1992
+ if (this._role === import_invitations5.Options.Role.GUEST) {
1993
+ return;
1994
+ }
1995
+ if (connected.length > 0) {
1996
+ connected.forEach((c) => this._seenPeers.add(c));
1997
+ return;
1998
+ }
1999
+ const firstUnknownPeer = candidates.find((peerId) => !this._seenPeers.has(peerId));
2000
+ this._seenPeers = new import_util5.ComplexSet(import_keys7.PublicKey.hash, allPeers.filter((peerId) => this._seenPeers.has(peerId)));
2001
+ if (firstUnknownPeer != null) {
2002
+ (0, import_log7.log)("invitation connect", {
2003
+ ownPeerId,
2004
+ remotePeerId: firstUnknownPeer
2005
+ }, {
2006
+ F: __dxlog_file8,
2007
+ L: 69,
1811
2008
  S: this,
1812
2009
  C: (f, a) => f(...a)
1813
2010
  });
1814
- this._callbacks.onError(err);
2011
+ this._controller.connect(firstUnknownPeer);
2012
+ this._seenPeers.add(firstUnknownPeer);
1815
2013
  }
1816
2014
  }
1817
- async onClose() {
1818
- (0, import_log5.log)("onClose", void 0, {
1819
- F: __dxlog_file6,
1820
- L: 306,
2015
+ async onOffer(peer) {
2016
+ (0, import_invariant8.invariant)(this._controller, "Not initialized.", {
2017
+ F: __dxlog_file8,
2018
+ L: 76,
1821
2019
  S: this,
1822
- C: (f, a) => f(...a)
2020
+ A: [
2021
+ "this._controller",
2022
+ "'Not initialized.'"
2023
+ ]
1823
2024
  });
1824
- await this._ctx.dispose();
2025
+ return !this._seenPeers.has(peer);
2026
+ }
2027
+ async destroy() {
2028
+ this._seenPeers.clear();
2029
+ }
2030
+ toString() {
2031
+ return `InvitationTopology(${this._role === import_invitations5.Options.Role.GUEST ? "guest" : "host"})`;
1825
2032
  }
1826
2033
  };
1827
- var isAuthenticationRequired = (invitation) => invitation.authMethod !== import_services4.Invitation.AuthMethod.NONE;
1828
- var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts";
2034
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts";
2035
+ var MAX_DELEGATED_INVITATION_HOST_TRIES = 3;
1829
2036
  var InvitationsHandler = class {
1830
2037
  /**
1831
2038
  * @internal
1832
2039
  */
1833
- constructor(_networkManager) {
2040
+ constructor(_networkManager, _defaultTeleportParams) {
1834
2041
  this._networkManager = _networkManager;
2042
+ this._defaultTeleportParams = _defaultTeleportParams;
1835
2043
  }
1836
2044
  handleInvitationFlow(ctx, stream, protocol, invitation) {
2045
+ const guardedState = this._createGuardedState(ctx, invitation, stream);
1837
2046
  const createExtension = () => {
1838
- const extension = new InvitationHostExtension({
1839
- onStateUpdate: (invitation2) => {
1840
- stream.next({
1841
- ...invitation2,
1842
- state: import_services3.Invitation.State.READY_FOR_AUTHENTICATION
1843
- });
2047
+ const extension = new InvitationHostExtension(guardedState.mutex, {
2048
+ get activeInvitation() {
2049
+ return ctx.disposed ? null : guardedState.current;
1844
2050
  },
1845
- resolveInvitation: async ({ invitationId }) => {
1846
- if (invitationId && invitationId !== invitation.invitationId) {
1847
- return void 0;
1848
- }
1849
- return invitation;
2051
+ onStateUpdate: (newState) => {
2052
+ guardedState.set(extension, newState);
2053
+ return guardedState.current;
1850
2054
  },
1851
2055
  admit: async (admissionRequest) => {
1852
2056
  try {
1853
2057
  const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
1854
2058
  (0, import_invariant5.invariant)(deviceKey, void 0, {
1855
- F: __dxlog_file7,
1856
- L: 87,
2059
+ F: __dxlog_file9,
2060
+ L: 90,
1857
2061
  S: this,
1858
2062
  A: [
1859
2063
  "deviceKey",
@@ -1864,34 +2068,36 @@ var InvitationsHandler = class {
1864
2068
  extension.completedTrigger.wake(deviceKey);
1865
2069
  return admissionResponse;
1866
2070
  } catch (err) {
1867
- stream.error(err);
2071
+ guardedState.error(extension, err);
1868
2072
  throw err;
1869
2073
  }
1870
2074
  },
1871
- onOpen: () => {
1872
- (0, import_async7.scheduleTask)(ctx, async () => {
2075
+ onOpen: (connectionCtx, extensionsCtx) => {
2076
+ let admitted = false;
2077
+ connectionCtx.onDispose(() => {
2078
+ if (!admitted) {
2079
+ guardedState.error(extension, new import_context4.ContextDisposedError());
2080
+ }
2081
+ });
2082
+ (0, import_async7.scheduleTask)(connectionCtx, async () => {
1873
2083
  const traceId = import_keys5.PublicKey.random().toHex();
1874
2084
  try {
1875
2085
  import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.begin({
1876
2086
  id: traceId
1877
2087
  }), {
1878
- F: __dxlog_file7,
1879
- L: 105,
2088
+ F: __dxlog_file9,
2089
+ L: 115,
1880
2090
  S: this,
1881
2091
  C: (f, a) => f(...a)
1882
2092
  });
1883
2093
  (0, import_log4.log)("connected", {
1884
2094
  ...protocol.toJSON()
1885
2095
  }, {
1886
- F: __dxlog_file7,
1887
- L: 106,
2096
+ F: __dxlog_file9,
2097
+ L: 116,
1888
2098
  S: this,
1889
2099
  C: (f, a) => f(...a)
1890
2100
  });
1891
- stream.next({
1892
- ...invitation,
1893
- state: import_services3.Invitation.State.CONNECTED
1894
- });
1895
2101
  const deviceKey = await extension.completedTrigger.wait({
1896
2102
  timeout: invitation.timeout
1897
2103
  });
@@ -1899,88 +2105,91 @@ var InvitationsHandler = class {
1899
2105
  guest: deviceKey,
1900
2106
  ...protocol.toJSON()
1901
2107
  }, {
1902
- F: __dxlog_file7,
1903
- L: 109,
2108
+ F: __dxlog_file9,
2109
+ L: 118,
1904
2110
  S: this,
1905
2111
  C: (f, a) => f(...a)
1906
2112
  });
1907
- stream.next({
1908
- ...invitation,
1909
- state: import_services3.Invitation.State.SUCCESS
1910
- });
2113
+ guardedState.set(extension, import_services3.Invitation.State.SUCCESS);
1911
2114
  import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.end({
1912
2115
  id: traceId
1913
2116
  }), {
1914
- F: __dxlog_file7,
1915
- L: 111,
2117
+ F: __dxlog_file9,
2118
+ L: 120,
1916
2119
  S: this,
1917
2120
  C: (f, a) => f(...a)
1918
2121
  });
2122
+ admitted = true;
2123
+ if (!invitation.multiUse) {
2124
+ await ctx.dispose();
2125
+ }
1919
2126
  } catch (err) {
1920
2127
  if (err instanceof import_async7.TimeoutError) {
1921
- (0, import_log4.log)("timeout", {
1922
- ...protocol.toJSON()
1923
- }, {
1924
- F: __dxlog_file7,
1925
- L: 114,
1926
- S: this,
1927
- C: (f, a) => f(...a)
1928
- });
1929
- stream.next({
1930
- ...invitation,
1931
- state: import_services3.Invitation.State.TIMEOUT
1932
- });
2128
+ if (guardedState.set(extension, import_services3.Invitation.State.TIMEOUT)) {
2129
+ (0, import_log4.log)("timeout", {
2130
+ ...protocol.toJSON()
2131
+ }, {
2132
+ F: __dxlog_file9,
2133
+ L: 129,
2134
+ S: this,
2135
+ C: (f, a) => f(...a)
2136
+ });
2137
+ }
1933
2138
  } else {
1934
- import_log4.log.error("failed", err, {
1935
- F: __dxlog_file7,
1936
- L: 117,
1937
- S: this,
1938
- C: (f, a) => f(...a)
1939
- });
1940
- stream.error(err);
2139
+ if (guardedState.error(extension, err)) {
2140
+ import_log4.log.error("failed", err, {
2141
+ F: __dxlog_file9,
2142
+ L: 133,
2143
+ S: this,
2144
+ C: (f, a) => f(...a)
2145
+ });
2146
+ }
1941
2147
  }
1942
2148
  import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.error({
1943
2149
  id: traceId,
1944
2150
  error: err
1945
2151
  }), {
1946
- F: __dxlog_file7,
1947
- L: 120,
2152
+ F: __dxlog_file9,
2153
+ L: 136,
1948
2154
  S: this,
1949
2155
  C: (f, a) => f(...a)
1950
2156
  });
1951
- } finally {
1952
- if (!invitation.multiUse) {
1953
- await swarmConnection.close();
1954
- await ctx.dispose();
1955
- }
2157
+ extensionsCtx.close(err);
1956
2158
  }
1957
2159
  });
1958
2160
  },
1959
2161
  onError: (err) => {
1960
2162
  if (err instanceof import_protocols4.InvalidInvitationExtensionRoleError) {
1961
- return;
1962
- }
1963
- if (err instanceof import_async7.TimeoutError) {
1964
- (0, import_log4.log)("timeout", {
1965
- ...protocol.toJSON()
2163
+ (0, import_log4.log)("invalid role", {
2164
+ ...err.context
1966
2165
  }, {
1967
- F: __dxlog_file7,
1968
- L: 135,
2166
+ F: __dxlog_file9,
2167
+ L: 144,
1969
2168
  S: this,
1970
2169
  C: (f, a) => f(...a)
1971
2170
  });
1972
- stream.next({
1973
- ...invitation,
1974
- state: import_services3.Invitation.State.TIMEOUT
1975
- });
2171
+ return;
2172
+ }
2173
+ if (err instanceof import_async7.TimeoutError) {
2174
+ if (guardedState.set(extension, import_services3.Invitation.State.TIMEOUT)) {
2175
+ (0, import_log4.log)("timeout", {
2176
+ err
2177
+ }, {
2178
+ F: __dxlog_file9,
2179
+ L: 149,
2180
+ S: this,
2181
+ C: (f, a) => f(...a)
2182
+ });
2183
+ }
1976
2184
  } else {
1977
- import_log4.log.error("failed", err, {
1978
- F: __dxlog_file7,
1979
- L: 138,
1980
- S: this,
1981
- C: (f, a) => f(...a)
1982
- });
1983
- stream.error(err);
2185
+ if (guardedState.error(extension, err)) {
2186
+ import_log4.log.error("failed", err, {
2187
+ F: __dxlog_file9,
2188
+ L: 153,
2189
+ S: this,
2190
+ C: (f, a) => f(...a)
2191
+ });
2192
+ }
1984
2193
  }
1985
2194
  }
1986
2195
  });
@@ -1989,57 +2198,31 @@ var InvitationsHandler = class {
1989
2198
  if (invitation.lifetime && invitation.created) {
1990
2199
  if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
1991
2200
  import_log4.log.warn("invitation has already expired", void 0, {
1992
- F: __dxlog_file7,
1993
- L: 149,
2201
+ F: __dxlog_file9,
2202
+ L: 164,
1994
2203
  S: this,
1995
2204
  C: (f, a) => f(...a)
1996
2205
  });
1997
2206
  } else {
1998
2207
  (0, import_async7.scheduleTask)(ctx, async () => {
1999
2208
  await swarmConnection.close();
2000
- stream.next({
2001
- ...invitation,
2002
- state: import_services3.Invitation.State.EXPIRED
2003
- });
2209
+ guardedState.set(null, import_services3.Invitation.State.EXPIRED);
2004
2210
  await ctx.dispose();
2005
2211
  }, invitation.created.getTime() + invitation.lifetime * 1e3 - Date.now());
2006
2212
  }
2007
2213
  }
2008
2214
  let swarmConnection;
2009
- const invitationLabel = "invitation host for " + (invitation.kind === import_services3.Invitation.Kind.DEVICE ? "device" : `space ${invitation.spaceKey?.truncate()}`);
2010
2215
  (0, import_async7.scheduleTask)(ctx, async () => {
2011
- const topic = invitation.swarmKey;
2012
- swarmConnection = await this._networkManager.joinSwarm({
2013
- topic,
2014
- peerId: topic,
2015
- protocolProvider: (0, import_network_manager.createTeleportProtocolFactory)(async (teleport) => {
2016
- teleport.addExtension("dxos.halo.invitations", createExtension());
2017
- }),
2018
- topology: new import_network_manager.StarTopology(topic),
2019
- label: invitationLabel
2020
- });
2021
- ctx.onDispose(() => swarmConnection.close());
2022
- stream.next({
2023
- ...invitation,
2024
- state: import_services3.Invitation.State.CONNECTING
2025
- });
2216
+ swarmConnection = await this._joinSwarm(ctx, invitation, import_invitations2.Options.Role.HOST, createExtension);
2217
+ guardedState.set(null, import_services3.Invitation.State.CONNECTING);
2026
2218
  });
2027
2219
  }
2028
- acceptInvitation(protocol, invitation, deviceProfile) {
2220
+ acceptInvitation(ctx, stream, protocol, invitation, otpEnteredTrigger, deviceProfile) {
2029
2221
  const { timeout = import_client_protocol2.INVITATION_TIMEOUT } = invitation;
2030
- (0, import_invariant5.invariant)(protocol, void 0, {
2031
- F: __dxlog_file7,
2032
- L: 191,
2033
- S: this,
2034
- A: [
2035
- "protocol",
2036
- ""
2037
- ]
2038
- });
2039
2222
  if (deviceProfile) {
2040
2223
  (0, import_invariant5.invariant)(invitation.kind === import_services3.Invitation.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
2041
- F: __dxlog_file7,
2042
- L: 194,
2224
+ F: __dxlog_file9,
2225
+ L: 197,
2043
2226
  S: this,
2044
2227
  A: [
2045
2228
  "invitation.kind === Invitation.Kind.DEVICE",
@@ -2047,121 +2230,96 @@ var InvitationsHandler = class {
2047
2230
  ]
2048
2231
  });
2049
2232
  }
2050
- const authenticated = new import_async7.Trigger();
2051
- let admitted = false;
2052
- let currentState;
2053
- const stream = new import_async7.PushStream();
2054
- const setState = (newData) => {
2055
- (0, import_invariant5.invariant)(newData.state !== void 0, void 0, {
2056
- F: __dxlog_file7,
2057
- L: 205,
2058
- S: this,
2059
- A: [
2060
- "newData.state !== undefined",
2061
- ""
2062
- ]
2063
- });
2064
- currentState = newData.state;
2065
- stream.next({
2066
- ...invitation,
2067
- ...newData
2068
- });
2069
- };
2070
- const ctx = new import_context4.Context({
2071
- onError: (err) => {
2072
- if (err instanceof import_async7.TimeoutError) {
2073
- (0, import_log4.log)("timeout", {
2074
- ...protocol.toJSON()
2075
- }, {
2076
- F: __dxlog_file7,
2077
- L: 213,
2078
- S: this,
2079
- C: (f, a) => f(...a)
2080
- });
2081
- setState({
2082
- state: import_services3.Invitation.State.TIMEOUT
2083
- });
2084
- } else {
2085
- import_log4.log.warn("auth failed", err, {
2086
- F: __dxlog_file7,
2087
- L: 216,
2088
- S: this,
2089
- C: (f, a) => f(...a)
2090
- });
2091
- stream.error(err);
2092
- }
2093
- void ctx.dispose();
2094
- }
2095
- });
2096
- ctx.onDispose(() => {
2097
- (0, import_log4.log)("complete", {
2098
- ...protocol.toJSON()
2233
+ const triedPeersIds = new import_util4.ComplexSet(import_keys5.PublicKey.hash);
2234
+ const guardedState = this._createGuardedState(ctx, invitation, stream);
2235
+ const shouldCancelInvitationFlow = (extension) => {
2236
+ const isLockedByAnotherConnection = guardedState.mutex.isLocked() && !extension.hasFlowLock();
2237
+ (0, import_log4.log)("should cancel invitation flow", {
2238
+ isLockedByAnotherConnection,
2239
+ invitationType: import_services3.Invitation.Type.DELEGATED,
2240
+ triedPeers: triedPeersIds.size
2099
2241
  }, {
2100
- F: __dxlog_file7,
2101
- L: 224,
2242
+ F: __dxlog_file9,
2243
+ L: 205,
2102
2244
  S: this,
2103
2245
  C: (f, a) => f(...a)
2104
2246
  });
2105
- stream.complete();
2106
- });
2247
+ if (isLockedByAnotherConnection) {
2248
+ return false;
2249
+ }
2250
+ return invitation.type !== import_services3.Invitation.Type.DELEGATED || triedPeersIds.size >= MAX_DELEGATED_INVITATION_HOST_TRIES;
2251
+ };
2252
+ let admitted = false;
2107
2253
  const createExtension = () => {
2108
- let connectionCount = 0;
2109
- const extension = new InvitationGuestExtension({
2110
- onOpen: (extensionCtx) => {
2111
- extensionCtx.onDispose(async () => {
2254
+ const extension = new InvitationGuestExtension(guardedState.mutex, {
2255
+ onStateUpdate: (newState) => {
2256
+ guardedState.set(extension, newState);
2257
+ },
2258
+ onOpen: (connectionCtx, extensionCtx) => {
2259
+ triedPeersIds.add(extensionCtx.remotePeerId);
2260
+ if (admitted) {
2261
+ extensionCtx.close();
2262
+ return;
2263
+ }
2264
+ connectionCtx.onDispose(async () => {
2112
2265
  (0, import_log4.log)("extension disposed", {
2113
- currentState
2266
+ admitted,
2267
+ currentState: guardedState.current.state
2114
2268
  }, {
2115
- F: __dxlog_file7,
2116
- L: 234,
2269
+ F: __dxlog_file9,
2270
+ L: 233,
2117
2271
  S: this,
2118
2272
  C: (f, a) => f(...a)
2119
2273
  });
2120
2274
  if (!admitted) {
2121
- stream.error(new Error("Remote peer disconnected."));
2275
+ guardedState.error(extension, new import_context4.ContextDisposedError());
2276
+ if (shouldCancelInvitationFlow(extension)) {
2277
+ await ctx.dispose();
2278
+ }
2122
2279
  }
2123
2280
  });
2124
- (0, import_async7.scheduleTask)(ctx, async () => {
2281
+ (0, import_async7.scheduleTask)(connectionCtx, async () => {
2125
2282
  const traceId = import_keys5.PublicKey.random().toHex();
2126
2283
  try {
2127
2284
  import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.begin({
2128
2285
  id: traceId
2129
2286
  }), {
2130
- F: __dxlog_file7,
2131
- L: 243,
2287
+ F: __dxlog_file9,
2288
+ L: 245,
2132
2289
  S: this,
2133
2290
  C: (f, a) => f(...a)
2134
2291
  });
2135
- if (++connectionCount > 1) {
2136
- throw new Error(`multiple connections detected: ${connectionCount}`);
2137
- }
2138
- (0, import_async7.scheduleTask)(ctx, () => ctx.raise(new import_async7.TimeoutError(timeout)), timeout);
2292
+ (0, import_async7.scheduleTask)(connectionCtx, () => {
2293
+ guardedState.set(extension, import_services3.Invitation.State.TIMEOUT);
2294
+ extensionCtx.close();
2295
+ }, timeout);
2139
2296
  (0, import_log4.log)("connected", {
2140
2297
  ...protocol.toJSON()
2141
2298
  }, {
2142
- F: __dxlog_file7,
2143
- L: 251,
2299
+ F: __dxlog_file9,
2300
+ L: 256,
2144
2301
  S: this,
2145
2302
  C: (f, a) => f(...a)
2146
2303
  });
2147
- setState({
2148
- state: import_services3.Invitation.State.CONNECTED
2149
- });
2304
+ guardedState.set(extension, import_services3.Invitation.State.CONNECTED);
2150
2305
  (0, import_log4.log)("introduce", {
2151
2306
  ...protocol.toJSON()
2152
2307
  }, {
2153
- F: __dxlog_file7,
2154
- L: 255,
2308
+ F: __dxlog_file9,
2309
+ L: 260,
2155
2310
  S: this,
2156
2311
  C: (f, a) => f(...a)
2157
2312
  });
2158
- const introductionResponse = await extension.rpc.InvitationHostService.introduce(protocol.createIntroduction());
2313
+ const introductionResponse = await extension.rpc.InvitationHostService.introduce({
2314
+ invitationId: invitation.invitationId,
2315
+ ...protocol.createIntroduction()
2316
+ });
2159
2317
  (0, import_log4.log)("introduce response", {
2160
2318
  ...protocol.toJSON(),
2161
2319
  response: introductionResponse
2162
2320
  }, {
2163
- F: __dxlog_file7,
2164
- L: 259,
2321
+ F: __dxlog_file9,
2322
+ L: 265,
2165
2323
  S: this,
2166
2324
  C: (f, a) => f(...a)
2167
2325
  });
@@ -2169,20 +2327,20 @@ var InvitationsHandler = class {
2169
2327
  if (isAuthenticationRequired(invitation)) {
2170
2328
  switch (invitation.authMethod) {
2171
2329
  case import_services3.Invitation.AuthMethod.SHARED_SECRET:
2172
- await this._handleGuestOtpAuth(extension, setState, authenticated, {
2330
+ await this._handleGuestOtpAuth(extension, (state) => guardedState.set(extension, state), otpEnteredTrigger, {
2173
2331
  timeout
2174
2332
  });
2175
2333
  break;
2176
2334
  case import_services3.Invitation.AuthMethod.KNOWN_PUBLIC_KEY:
2177
- await this._handleGuestKpkAuth(extension, setState, invitation, introductionResponse);
2335
+ await this._handleGuestKpkAuth(extension, (state) => guardedState.set(extension, state), invitation, introductionResponse);
2178
2336
  break;
2179
2337
  }
2180
2338
  }
2181
2339
  (0, import_log4.log)("request admission", {
2182
2340
  ...protocol.toJSON()
2183
2341
  }, {
2184
- F: __dxlog_file7,
2185
- L: 275,
2342
+ F: __dxlog_file9,
2343
+ L: 291,
2186
2344
  S: this,
2187
2345
  C: (f, a) => f(...a)
2188
2346
  });
@@ -2193,21 +2351,21 @@ var InvitationsHandler = class {
2193
2351
  (0, import_log4.log)("admitted by host", {
2194
2352
  ...protocol.toJSON()
2195
2353
  }, {
2196
- F: __dxlog_file7,
2197
- L: 286,
2354
+ F: __dxlog_file9,
2355
+ L: 302,
2198
2356
  S: this,
2199
2357
  C: (f, a) => f(...a)
2200
2358
  });
2201
- setState({
2359
+ await guardedState.complete({
2360
+ ...guardedState.current,
2202
2361
  ...result,
2203
- target: invitation.target,
2204
2362
  state: import_services3.Invitation.State.SUCCESS
2205
2363
  });
2206
2364
  import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.end({
2207
2365
  id: traceId
2208
2366
  }), {
2209
- F: __dxlog_file7,
2210
- L: 288,
2367
+ F: __dxlog_file9,
2368
+ L: 308,
2211
2369
  S: this,
2212
2370
  C: (f, a) => f(...a)
2213
2371
  });
@@ -2216,34 +2374,31 @@ var InvitationsHandler = class {
2216
2374
  (0, import_log4.log)("timeout", {
2217
2375
  ...protocol.toJSON()
2218
2376
  }, {
2219
- F: __dxlog_file7,
2220
- L: 291,
2377
+ F: __dxlog_file9,
2378
+ L: 311,
2221
2379
  S: this,
2222
2380
  C: (f, a) => f(...a)
2223
2381
  });
2224
- setState({
2225
- state: import_services3.Invitation.State.TIMEOUT
2226
- });
2382
+ guardedState.set(extension, import_services3.Invitation.State.TIMEOUT);
2227
2383
  } else {
2228
2384
  (0, import_log4.log)("auth failed", err, {
2229
- F: __dxlog_file7,
2230
- L: 294,
2385
+ F: __dxlog_file9,
2386
+ L: 314,
2231
2387
  S: this,
2232
2388
  C: (f, a) => f(...a)
2233
2389
  });
2234
- stream.error(err);
2390
+ guardedState.error(extension, err);
2235
2391
  }
2392
+ extensionCtx.close(err);
2236
2393
  import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.error({
2237
2394
  id: traceId,
2238
2395
  error: err
2239
2396
  }), {
2240
- F: __dxlog_file7,
2241
- L: 297,
2397
+ F: __dxlog_file9,
2398
+ L: 318,
2242
2399
  S: this,
2243
2400
  C: (f, a) => f(...a)
2244
2401
  });
2245
- } finally {
2246
- await ctx.dispose();
2247
2402
  }
2248
2403
  });
2249
2404
  },
@@ -2255,22 +2410,20 @@ var InvitationsHandler = class {
2255
2410
  (0, import_log4.log)("timeout", {
2256
2411
  ...protocol.toJSON()
2257
2412
  }, {
2258
- F: __dxlog_file7,
2259
- L: 308,
2413
+ F: __dxlog_file9,
2414
+ L: 327,
2260
2415
  S: this,
2261
2416
  C: (f, a) => f(...a)
2262
2417
  });
2263
- setState({
2264
- state: import_services3.Invitation.State.TIMEOUT
2265
- });
2418
+ guardedState.set(extension, import_services3.Invitation.State.TIMEOUT);
2266
2419
  } else {
2267
2420
  (0, import_log4.log)("auth failed", err, {
2268
- F: __dxlog_file7,
2269
- L: 311,
2421
+ F: __dxlog_file9,
2422
+ L: 330,
2270
2423
  S: this,
2271
2424
  C: (f, a) => f(...a)
2272
2425
  });
2273
- stream.error(err);
2426
+ guardedState.error(extension, err);
2274
2427
  }
2275
2428
  }
2276
2429
  });
@@ -2280,68 +2433,140 @@ var InvitationsHandler = class {
2280
2433
  const error = protocol.checkInvitation(invitation);
2281
2434
  if (error) {
2282
2435
  stream.error(error);
2436
+ await ctx.dispose();
2283
2437
  } else {
2284
2438
  (0, import_invariant5.invariant)(invitation.swarmKey, void 0, {
2285
- F: __dxlog_file7,
2286
- L: 325,
2439
+ F: __dxlog_file9,
2440
+ L: 345,
2287
2441
  S: this,
2288
2442
  A: [
2289
2443
  "invitation.swarmKey",
2290
2444
  ""
2291
2445
  ]
2292
2446
  });
2293
- const topic = invitation.swarmKey;
2294
- const swarmConnection = await this._networkManager.joinSwarm({
2295
- topic,
2296
- peerId: import_keys5.PublicKey.random(),
2297
- protocolProvider: (0, import_network_manager.createTeleportProtocolFactory)(async (teleport) => {
2298
- teleport.addExtension("dxos.halo.invitations", createExtension());
2299
- }),
2300
- topology: new import_network_manager.StarTopology(topic),
2301
- label: "invitation guest"
2302
- });
2303
- ctx.onDispose(() => swarmConnection.close());
2304
- setState({
2305
- state: import_services3.Invitation.State.CONNECTING
2306
- });
2447
+ await this._joinSwarm(ctx, invitation, import_invitations2.Options.Role.GUEST, createExtension);
2448
+ guardedState.set(null, import_services3.Invitation.State.CONNECTING);
2307
2449
  }
2308
2450
  });
2309
- const observable = new import_client_protocol2.AuthenticatingInvitation({
2310
- initialInvitation: invitation,
2311
- subscriber: stream.observable,
2312
- onCancel: async () => {
2313
- setState({
2314
- state: import_services3.Invitation.State.CANCELLED
2315
- });
2316
- await ctx.dispose();
2451
+ }
2452
+ async _joinSwarm(ctx, invitation, role, extensionFactory) {
2453
+ let label;
2454
+ if (role === import_invitations2.Options.Role.GUEST) {
2455
+ label = "invitation guest";
2456
+ } else if (invitation.kind === import_services3.Invitation.Kind.DEVICE) {
2457
+ label = "invitation host for device";
2458
+ } else {
2459
+ label = `invitation host for space ${invitation.spaceKey?.truncate()}`;
2460
+ }
2461
+ const swarmConnection = await this._networkManager.joinSwarm({
2462
+ topic: invitation.swarmKey,
2463
+ peerId: import_keys5.PublicKey.random(),
2464
+ protocolProvider: (0, import_network_manager.createTeleportProtocolFactory)(async (teleport) => {
2465
+ teleport.addExtension("dxos.halo.invitations", extensionFactory());
2466
+ }, this._defaultTeleportParams),
2467
+ topology: new InvitationTopology(role),
2468
+ label
2469
+ });
2470
+ ctx.onDispose(() => swarmConnection.close());
2471
+ return swarmConnection;
2472
+ }
2473
+ /**
2474
+ * A utility object for serializing invitation state changes by multiple concurrent
2475
+ * invitation flow connections.
2476
+ */
2477
+ _createGuardedState(ctx, invitation, stream) {
2478
+ const mutex = new import_async7.Mutex();
2479
+ let lastActiveExtension = null;
2480
+ let currentInvitation = {
2481
+ ...invitation
2482
+ };
2483
+ const isStateChangeAllowed = (extension) => {
2484
+ if (ctx.disposed || extension !== null && mutex.isLocked() && !extension.hasFlowLock()) {
2485
+ return false;
2486
+ }
2487
+ return extension == null || lastActiveExtension !== extension || this._isNotTerminal(currentInvitation.state);
2488
+ };
2489
+ return {
2490
+ mutex,
2491
+ get current() {
2492
+ return currentInvitation;
2317
2493
  },
2318
- onAuthenticate: async (code) => {
2319
- authenticated.wake(code);
2494
+ // disposing context prevents any further state updates
2495
+ complete: (newState) => {
2496
+ currentInvitation = {
2497
+ ...currentInvitation,
2498
+ ...newState
2499
+ };
2500
+ stream.next(currentInvitation);
2501
+ return ctx.dispose();
2502
+ },
2503
+ set: (extension, newState) => {
2504
+ if (isStateChangeAllowed(extension)) {
2505
+ this._logStateUpdate(currentInvitation, extension, newState);
2506
+ currentInvitation = {
2507
+ ...currentInvitation,
2508
+ state: newState
2509
+ };
2510
+ stream.next(currentInvitation);
2511
+ lastActiveExtension = extension;
2512
+ return true;
2513
+ }
2514
+ return false;
2515
+ },
2516
+ error: (extension, error) => {
2517
+ if (isStateChangeAllowed(extension)) {
2518
+ this._logStateUpdate(currentInvitation, extension, import_services3.Invitation.State.ERROR);
2519
+ currentInvitation = {
2520
+ ...currentInvitation,
2521
+ state: import_services3.Invitation.State.ERROR
2522
+ };
2523
+ stream.next(currentInvitation);
2524
+ stream.error(error);
2525
+ lastActiveExtension = extension;
2526
+ return true;
2527
+ }
2528
+ return false;
2320
2529
  }
2530
+ };
2531
+ }
2532
+ _logStateUpdate(invitation, actor, newState) {
2533
+ (0, import_log4.log)("invitation state update", {
2534
+ actor: actor?.constructor.name,
2535
+ newState: stateToString(newState),
2536
+ oldState: stateToString(invitation.state)
2537
+ }, {
2538
+ F: __dxlog_file9,
2539
+ L: 438,
2540
+ S: this,
2541
+ C: (f, a) => f(...a)
2321
2542
  });
2322
- return observable;
2543
+ }
2544
+ _isNotTerminal(currentState) {
2545
+ return ![
2546
+ import_services3.Invitation.State.SUCCESS,
2547
+ import_services3.Invitation.State.ERROR,
2548
+ import_services3.Invitation.State.CANCELLED,
2549
+ import_services3.Invitation.State.TIMEOUT,
2550
+ import_services3.Invitation.State.EXPIRED
2551
+ ].includes(currentState);
2323
2552
  }
2324
2553
  async _handleGuestOtpAuth(extension, setState, authenticated, options) {
2325
2554
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2326
2555
  (0, import_log4.log)("guest waiting for authentication code...", void 0, {
2327
- F: __dxlog_file7,
2328
- L: 365,
2556
+ F: __dxlog_file9,
2557
+ L: 462,
2329
2558
  S: this,
2330
2559
  C: (f, a) => f(...a)
2331
2560
  });
2332
- setState({
2333
- state: import_services3.Invitation.State.READY_FOR_AUTHENTICATION
2334
- });
2561
+ setState(import_services3.Invitation.State.READY_FOR_AUTHENTICATION);
2335
2562
  const authCode = await authenticated.wait(options);
2336
2563
  (0, import_log4.log)("sending authentication request", void 0, {
2337
- F: __dxlog_file7,
2338
- L: 369,
2564
+ F: __dxlog_file9,
2565
+ L: 466,
2339
2566
  S: this,
2340
2567
  C: (f, a) => f(...a)
2341
2568
  });
2342
- setState({
2343
- state: import_services3.Invitation.State.AUTHENTICATING
2344
- });
2569
+ setState(import_services3.Invitation.State.AUTHENTICATING);
2345
2570
  const response = await extension.rpc.InvitationHostService.authenticate({
2346
2571
  authCode
2347
2572
  });
@@ -2355,8 +2580,8 @@ var InvitationsHandler = class {
2355
2580
  (0, import_log4.log)("retrying invalid code", {
2356
2581
  attempt
2357
2582
  }, {
2358
- F: __dxlog_file7,
2359
- L: 380,
2583
+ F: __dxlog_file9,
2584
+ L: 477,
2360
2585
  S: this,
2361
2586
  C: (f, a) => f(...a)
2362
2587
  });
@@ -2373,14 +2598,12 @@ var InvitationsHandler = class {
2373
2598
  throw new Error("challenge missing in the introduction");
2374
2599
  }
2375
2600
  (0, import_log4.log)("sending authentication request", void 0, {
2376
- F: __dxlog_file7,
2377
- L: 399,
2601
+ F: __dxlog_file9,
2602
+ L: 496,
2378
2603
  S: this,
2379
2604
  C: (f, a) => f(...a)
2380
2605
  });
2381
- setState({
2382
- state: import_services3.Invitation.State.AUTHENTICATING
2383
- });
2606
+ setState(import_services3.Invitation.State.AUTHENTICATING);
2384
2607
  const signature = (0, import_crypto.sign)(Buffer.from(introductionResponse.challenge), invitation.guestKeypair.privateKey);
2385
2608
  const response = await extension.rpc.InvitationHostService.authenticate({
2386
2609
  signedChallenge: signature
@@ -2426,8 +2649,8 @@ var InvitationsServiceImpl = class {
2426
2649
  return new import_codec_protobuf8.Stream(({ next, ctx }) => {
2427
2650
  this._invitationsManager.invitationCreated.on(ctx, (invitation) => {
2428
2651
  next({
2429
- action: import_services5.QueryInvitationsResponse.Action.ADDED,
2430
- type: import_services5.QueryInvitationsResponse.Type.CREATED,
2652
+ action: import_services6.QueryInvitationsResponse.Action.ADDED,
2653
+ type: import_services6.QueryInvitationsResponse.Type.CREATED,
2431
2654
  invitations: [
2432
2655
  invitation
2433
2656
  ]
@@ -2435,8 +2658,8 @@ var InvitationsServiceImpl = class {
2435
2658
  });
2436
2659
  this._invitationsManager.invitationAccepted.on(ctx, (invitation) => {
2437
2660
  next({
2438
- action: import_services5.QueryInvitationsResponse.Action.ADDED,
2439
- type: import_services5.QueryInvitationsResponse.Type.ACCEPTED,
2661
+ action: import_services6.QueryInvitationsResponse.Action.ADDED,
2662
+ type: import_services6.QueryInvitationsResponse.Type.ACCEPTED,
2440
2663
  invitations: [
2441
2664
  invitation
2442
2665
  ]
@@ -2444,8 +2667,8 @@ var InvitationsServiceImpl = class {
2444
2667
  });
2445
2668
  this._invitationsManager.removedCreated.on(ctx, (invitation) => {
2446
2669
  next({
2447
- action: import_services5.QueryInvitationsResponse.Action.REMOVED,
2448
- type: import_services5.QueryInvitationsResponse.Type.CREATED,
2670
+ action: import_services6.QueryInvitationsResponse.Action.REMOVED,
2671
+ type: import_services6.QueryInvitationsResponse.Type.CREATED,
2449
2672
  invitations: [
2450
2673
  invitation
2451
2674
  ]
@@ -2453,8 +2676,8 @@ var InvitationsServiceImpl = class {
2453
2676
  });
2454
2677
  this._invitationsManager.removedAccepted.on(ctx, (invitation) => {
2455
2678
  next({
2456
- action: import_services5.QueryInvitationsResponse.Action.REMOVED,
2457
- type: import_services5.QueryInvitationsResponse.Type.ACCEPTED,
2679
+ action: import_services6.QueryInvitationsResponse.Action.REMOVED,
2680
+ type: import_services6.QueryInvitationsResponse.Type.ACCEPTED,
2458
2681
  invitations: [
2459
2682
  invitation
2460
2683
  ]
@@ -2462,35 +2685,35 @@ var InvitationsServiceImpl = class {
2462
2685
  });
2463
2686
  this._invitationsManager.saved.on(ctx, (invitation) => {
2464
2687
  next({
2465
- action: import_services5.QueryInvitationsResponse.Action.SAVED,
2466
- type: import_services5.QueryInvitationsResponse.Type.CREATED,
2688
+ action: import_services6.QueryInvitationsResponse.Action.SAVED,
2689
+ type: import_services6.QueryInvitationsResponse.Type.CREATED,
2467
2690
  invitations: [
2468
2691
  invitation
2469
2692
  ]
2470
2693
  });
2471
2694
  });
2472
2695
  next({
2473
- action: import_services5.QueryInvitationsResponse.Action.ADDED,
2474
- type: import_services5.QueryInvitationsResponse.Type.CREATED,
2696
+ action: import_services6.QueryInvitationsResponse.Action.ADDED,
2697
+ type: import_services6.QueryInvitationsResponse.Type.CREATED,
2475
2698
  invitations: this._invitationsManager.getCreatedInvitations(),
2476
2699
  existing: true
2477
2700
  });
2478
2701
  next({
2479
- action: import_services5.QueryInvitationsResponse.Action.ADDED,
2480
- type: import_services5.QueryInvitationsResponse.Type.ACCEPTED,
2702
+ action: import_services6.QueryInvitationsResponse.Action.ADDED,
2703
+ type: import_services6.QueryInvitationsResponse.Type.ACCEPTED,
2481
2704
  invitations: this._invitationsManager.getAcceptedInvitations(),
2482
2705
  existing: true
2483
2706
  });
2484
2707
  this._invitationsManager.onPersistentInvitationsLoaded(ctx, () => {
2485
2708
  next({
2486
- action: import_services5.QueryInvitationsResponse.Action.LOAD_COMPLETE,
2487
- type: import_services5.QueryInvitationsResponse.Type.CREATED
2709
+ action: import_services6.QueryInvitationsResponse.Action.LOAD_COMPLETE,
2710
+ type: import_services6.QueryInvitationsResponse.Type.CREATED
2488
2711
  });
2489
2712
  });
2490
2713
  });
2491
2714
  }
2492
2715
  };
2493
- var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
2716
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
2494
2717
  var SpaceInvitationProtocol = class {
2495
2718
  constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
2496
2719
  this._spaceManager = _spaceManager;
@@ -2506,14 +2729,14 @@ var SpaceInvitationProtocol = class {
2506
2729
  }
2507
2730
  getInvitationContext() {
2508
2731
  return {
2509
- kind: import_services6.Invitation.Kind.SPACE,
2732
+ kind: import_services7.Invitation.Kind.SPACE,
2510
2733
  spaceKey: this._spaceKey
2511
2734
  };
2512
2735
  }
2513
2736
  async admit(invitation, request, guestProfile) {
2514
- (0, import_invariant7.invariant)(this._spaceKey, void 0, {
2515
- F: __dxlog_file8,
2516
- L: 55,
2737
+ (0, import_invariant9.invariant)(this._spaceKey, void 0, {
2738
+ F: __dxlog_file10,
2739
+ L: 56,
2517
2740
  S: this,
2518
2741
  A: [
2519
2742
  "this._spaceKey",
@@ -2521,18 +2744,18 @@ var SpaceInvitationProtocol = class {
2521
2744
  ]
2522
2745
  });
2523
2746
  const space = await this._spaceManager.spaces.get(this._spaceKey);
2524
- (0, import_invariant7.invariant)(space, void 0, {
2525
- F: __dxlog_file8,
2526
- L: 57,
2747
+ (0, import_invariant9.invariant)(space, void 0, {
2748
+ F: __dxlog_file10,
2749
+ L: 58,
2527
2750
  S: this,
2528
2751
  A: [
2529
2752
  "space",
2530
2753
  ""
2531
2754
  ]
2532
2755
  });
2533
- (0, import_invariant7.invariant)(request.space, void 0, {
2534
- F: __dxlog_file8,
2535
- L: 59,
2756
+ (0, import_invariant9.invariant)(request.space, void 0, {
2757
+ F: __dxlog_file10,
2758
+ L: 60,
2536
2759
  S: this,
2537
2760
  A: [
2538
2761
  "request.space",
@@ -2540,19 +2763,19 @@ var SpaceInvitationProtocol = class {
2540
2763
  ]
2541
2764
  });
2542
2765
  const { identityKey, deviceKey } = request.space;
2543
- (0, import_log6.log)("writing guest credentials", {
2766
+ (0, import_log8.log)("writing guest credentials", {
2544
2767
  host: this._signingContext.deviceKey,
2545
2768
  guest: deviceKey
2546
2769
  }, {
2547
- F: __dxlog_file8,
2548
- L: 62,
2770
+ F: __dxlog_file10,
2771
+ L: 63,
2549
2772
  S: this,
2550
2773
  C: (f, a) => f(...a)
2551
2774
  });
2552
2775
  const credentials = await (0, import_credentials7.createAdmissionCredentials)(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile, invitation.delegationCredentialId);
2553
- (0, import_invariant7.invariant)(credentials[0].credential, void 0, {
2554
- F: __dxlog_file8,
2555
- L: 74,
2776
+ (0, import_invariant9.invariant)(credentials[0].credential, void 0, {
2777
+ F: __dxlog_file10,
2778
+ L: 75,
2556
2779
  S: this,
2557
2780
  A: [
2558
2781
  "credentials[0].credential",
@@ -2560,75 +2783,128 @@ var SpaceInvitationProtocol = class {
2560
2783
  ]
2561
2784
  });
2562
2785
  const spaceMemberCredential = credentials[0].credential.credential;
2563
- (0, import_invariant7.invariant)((0, import_credentials7.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2564
- F: __dxlog_file8,
2565
- L: 76,
2786
+ (0, import_invariant9.invariant)((0, import_credentials7.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2787
+ F: __dxlog_file10,
2788
+ L: 77,
2789
+ S: this,
2790
+ A: [
2791
+ "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
2792
+ ""
2793
+ ]
2794
+ });
2795
+ await (0, import_feed_store3.writeMessages)(space.inner.controlPipeline.writer, credentials);
2796
+ return {
2797
+ space: {
2798
+ credential: spaceMemberCredential,
2799
+ controlTimeframe: space.inner.controlPipeline.state.timeframe
2800
+ }
2801
+ };
2802
+ }
2803
+ async delegate(invitation) {
2804
+ (0, import_invariant9.invariant)(this._spaceKey, void 0, {
2805
+ F: __dxlog_file10,
2806
+ L: 90,
2807
+ S: this,
2808
+ A: [
2809
+ "this._spaceKey",
2810
+ ""
2811
+ ]
2812
+ });
2813
+ const space = this._spaceManager.spaces.get(this._spaceKey);
2814
+ (0, import_invariant9.invariant)(space, void 0, {
2815
+ F: __dxlog_file10,
2816
+ L: 92,
2817
+ S: this,
2818
+ A: [
2819
+ "space",
2820
+ ""
2821
+ ]
2822
+ });
2823
+ if (invitation.authMethod === import_services7.Invitation.AuthMethod.KNOWN_PUBLIC_KEY) {
2824
+ (0, import_invariant9.invariant)(invitation.guestKeypair?.publicKey, void 0, {
2825
+ F: __dxlog_file10,
2826
+ L: 94,
2827
+ S: this,
2828
+ A: [
2829
+ "invitation.guestKeypair?.publicKey",
2830
+ ""
2831
+ ]
2832
+ });
2833
+ }
2834
+ (0, import_log8.log)("writing delegate space invitation", {
2835
+ host: this._signingContext.deviceKey,
2836
+ id: invitation.invitationId
2837
+ }, {
2838
+ F: __dxlog_file10,
2839
+ L: 97,
2840
+ S: this,
2841
+ C: (f, a) => f(...a)
2842
+ });
2843
+ const credential = await (0, import_credentials7.createDelegatedSpaceInvitationCredential)(this._signingContext.credentialSigner, space.key, {
2844
+ invitationId: invitation.invitationId,
2845
+ authMethod: invitation.authMethod,
2846
+ swarmKey: invitation.swarmKey,
2847
+ role: import_credentials8.SpaceMember.Role.ADMIN,
2848
+ expiresOn: invitation.lifetime ? new Date((invitation.created?.getTime() ?? Date.now()) + invitation.lifetime) : void 0,
2849
+ multiUse: invitation.multiUse ?? false,
2850
+ guestKey: invitation.authMethod === import_services7.Invitation.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
2851
+ });
2852
+ (0, import_invariant9.invariant)(credential.credential, void 0, {
2853
+ F: __dxlog_file10,
2854
+ L: 117,
2855
+ S: this,
2856
+ A: [
2857
+ "credential.credential",
2858
+ ""
2859
+ ]
2860
+ });
2861
+ await (0, import_feed_store3.writeMessages)(space.inner.controlPipeline.writer, [
2862
+ credential
2863
+ ]);
2864
+ return credential.credential.credential.id;
2865
+ }
2866
+ async cancelDelegation(invitation) {
2867
+ (0, import_invariant9.invariant)(this._spaceKey, void 0, {
2868
+ F: __dxlog_file10,
2869
+ L: 123,
2566
2870
  S: this,
2567
2871
  A: [
2568
- "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
2872
+ "this._spaceKey",
2569
2873
  ""
2570
2874
  ]
2571
2875
  });
2572
- await (0, import_feed_store3.writeMessages)(space.inner.controlPipeline.writer, credentials);
2573
- return {
2574
- space: {
2575
- credential: spaceMemberCredential,
2576
- controlTimeframe: space.inner.controlPipeline.state.timeframe
2577
- }
2578
- };
2579
- }
2580
- async delegate(invitation) {
2581
- (0, import_invariant7.invariant)(this._spaceKey, void 0, {
2582
- F: __dxlog_file8,
2583
- L: 89,
2876
+ (0, import_invariant9.invariant)(invitation.type === import_services7.Invitation.Type.DELEGATED && invitation.delegationCredentialId, void 0, {
2877
+ F: __dxlog_file10,
2878
+ L: 124,
2584
2879
  S: this,
2585
2880
  A: [
2586
- "this._spaceKey",
2881
+ "invitation.type === Invitation.Type.DELEGATED && invitation.delegationCredentialId",
2587
2882
  ""
2588
2883
  ]
2589
2884
  });
2590
- const space = await this._spaceManager.spaces.get(this._spaceKey);
2591
- (0, import_invariant7.invariant)(space, void 0, {
2592
- F: __dxlog_file8,
2593
- L: 91,
2885
+ const space = this._spaceManager.spaces.get(this._spaceKey);
2886
+ (0, import_invariant9.invariant)(space, void 0, {
2887
+ F: __dxlog_file10,
2888
+ L: 126,
2594
2889
  S: this,
2595
2890
  A: [
2596
2891
  "space",
2597
2892
  ""
2598
2893
  ]
2599
2894
  });
2600
- if (invitation.authMethod === import_services6.Invitation.AuthMethod.KNOWN_PUBLIC_KEY) {
2601
- (0, import_invariant7.invariant)(invitation.guestKeypair?.publicKey, void 0, {
2602
- F: __dxlog_file8,
2603
- L: 93,
2604
- S: this,
2605
- A: [
2606
- "invitation.guestKeypair?.publicKey",
2607
- ""
2608
- ]
2609
- });
2610
- }
2611
- (0, import_log6.log)("writing delegate space invitation", {
2895
+ (0, import_log8.log)("cancelling delegated space invitation", {
2612
2896
  host: this._signingContext.deviceKey,
2613
2897
  id: invitation.invitationId
2614
2898
  }, {
2615
- F: __dxlog_file8,
2616
- L: 96,
2899
+ F: __dxlog_file10,
2900
+ L: 128,
2617
2901
  S: this,
2618
2902
  C: (f, a) => f(...a)
2619
2903
  });
2620
- const credential = await (0, import_credentials7.createDelegatedSpaceInvitationCredential)(this._signingContext.credentialSigner, space.key, {
2621
- invitationId: invitation.invitationId,
2622
- authMethod: invitation.authMethod,
2623
- swarmKey: invitation.swarmKey,
2624
- role: import_credentials8.SpaceMember.Role.ADMIN,
2625
- expiresOn: invitation.lifetime ? new Date((invitation.created?.getTime() ?? Date.now()) + invitation.lifetime) : void 0,
2626
- multiUse: invitation.multiUse ?? false,
2627
- guestKey: invitation.authMethod === import_services6.Invitation.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
2628
- });
2629
- (0, import_invariant7.invariant)(credential.credential, void 0, {
2630
- F: __dxlog_file8,
2631
- L: 116,
2904
+ const credential = await (0, import_credentials7.createCancelDelegatedSpaceInvitationCredential)(this._signingContext.credentialSigner, space.key, invitation.delegationCredentialId);
2905
+ (0, import_invariant9.invariant)(credential.credential, void 0, {
2906
+ F: __dxlog_file10,
2907
+ L: 135,
2632
2908
  S: this,
2633
2909
  A: [
2634
2910
  "credential.credential",
@@ -2638,11 +2914,10 @@ var SpaceInvitationProtocol = class {
2638
2914
  await (0, import_feed_store3.writeMessages)(space.inner.controlPipeline.writer, [
2639
2915
  credential
2640
2916
  ]);
2641
- return credential.credential.credential.id;
2642
2917
  }
2643
2918
  checkInvitation(invitation) {
2644
2919
  if (invitation.spaceKey && this._spaceManager.spaces.has(invitation.spaceKey)) {
2645
- return new import_protocols6.AlreadyJoinedError("Already joined space.");
2920
+ return new import_protocols7.AlreadyJoinedError("Already joined space.");
2646
2921
  }
2647
2922
  }
2648
2923
  createIntroduction() {
@@ -2663,9 +2938,9 @@ var SpaceInvitationProtocol = class {
2663
2938
  };
2664
2939
  }
2665
2940
  async accept(response) {
2666
- (0, import_invariant7.invariant)(response.space, void 0, {
2667
- F: __dxlog_file8,
2668
- L: 149,
2941
+ (0, import_invariant9.invariant)(response.space, void 0, {
2942
+ F: __dxlog_file10,
2943
+ L: 167,
2669
2944
  S: this,
2670
2945
  A: [
2671
2946
  "response.space",
@@ -2674,18 +2949,18 @@ var SpaceInvitationProtocol = class {
2674
2949
  });
2675
2950
  const { credential, controlTimeframe, dataTimeframe } = response.space;
2676
2951
  const assertion = (0, import_credentials7.getCredentialAssertion)(credential);
2677
- (0, import_invariant7.invariant)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2678
- F: __dxlog_file8,
2679
- L: 152,
2952
+ (0, import_invariant9.invariant)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2953
+ F: __dxlog_file10,
2954
+ L: 170,
2680
2955
  S: this,
2681
2956
  A: [
2682
2957
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
2683
2958
  "'Invalid credential'"
2684
2959
  ]
2685
2960
  });
2686
- (0, import_invariant7.invariant)(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
2687
- F: __dxlog_file8,
2688
- L: 153,
2961
+ (0, import_invariant9.invariant)(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
2962
+ F: __dxlog_file10,
2963
+ L: 171,
2689
2964
  S: this,
2690
2965
  A: [
2691
2966
  "credential.subject.id.equals(this._signingContext.identityKey)",
@@ -2693,7 +2968,7 @@ var SpaceInvitationProtocol = class {
2693
2968
  ]
2694
2969
  });
2695
2970
  if (this._spaceManager.spaces.has(assertion.spaceKey)) {
2696
- throw new import_protocols6.AlreadyJoinedError("Already joined space.");
2971
+ throw new import_protocols7.AlreadyJoinedError("Already joined space.");
2697
2972
  }
2698
2973
  await this._spaceManager.acceptSpace({
2699
2974
  spaceKey: assertion.spaceKey,
@@ -2707,7 +2982,7 @@ var SpaceInvitationProtocol = class {
2707
2982
  };
2708
2983
  }
2709
2984
  };
2710
- var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
2985
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
2711
2986
  var InvitationsManager = class {
2712
2987
  constructor(_invitationsHandler, _getHandler, _metadataStore) {
2713
2988
  this._invitationsHandler = _invitationsHandler;
@@ -2715,12 +2990,12 @@ var InvitationsManager = class {
2715
2990
  this._metadataStore = _metadataStore;
2716
2991
  this._createInvitations = /* @__PURE__ */ new Map();
2717
2992
  this._acceptInvitations = /* @__PURE__ */ new Map();
2718
- this.invitationCreated = new import_async9.Event();
2719
- this.invitationAccepted = new import_async9.Event();
2720
- this.removedCreated = new import_async9.Event();
2721
- this.removedAccepted = new import_async9.Event();
2722
- this.saved = new import_async9.Event();
2723
- this._persistentInvitationsLoadedEvent = new import_async9.Event();
2993
+ this.invitationCreated = new import_async10.Event();
2994
+ this.invitationAccepted = new import_async10.Event();
2995
+ this.removedCreated = new import_async10.Event();
2996
+ this.removedAccepted = new import_async10.Event();
2997
+ this.saved = new import_async10.Event();
2998
+ this._persistentInvitationsLoadedEvent = new import_async10.Event();
2724
2999
  this._persistentInvitationsLoaded = false;
2725
3000
  }
2726
3001
  async createInvitation(options) {
@@ -2745,8 +3020,8 @@ var InvitationsManager = class {
2745
3020
  try {
2746
3021
  await this._persistIfRequired(handler, stream, invitation);
2747
3022
  } catch (err) {
2748
- import_log7.log.catch(err, void 0, {
2749
- F: __dxlog_file9,
3023
+ import_log9.log.catch(err, void 0, {
3024
+ F: __dxlog_file11,
2750
3025
  L: 76,
2751
3026
  S: this,
2752
3027
  C: (f, a) => f(...a)
@@ -2768,8 +3043,8 @@ var InvitationsManager = class {
2768
3043
  const persistentInvitations = this._metadataStore.getInvitations();
2769
3044
  const freshInvitations = persistentInvitations.filter((invitation) => !(0, import_echo_pipeline.hasInvitationExpired)(invitation));
2770
3045
  const loadTasks = freshInvitations.map((persistentInvitation) => {
2771
- (0, import_invariant8.invariant)(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
2772
- F: __dxlog_file9,
3046
+ (0, import_invariant10.invariant)(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
3047
+ F: __dxlog_file11,
2773
3048
  L: 97,
2774
3049
  S: this,
2775
3050
  A: [
@@ -2787,8 +3062,8 @@ var InvitationsManager = class {
2787
3062
  invitations: cInvitations.map((invitation) => invitation.get())
2788
3063
  };
2789
3064
  } catch (err) {
2790
- import_log7.log.catch(err, void 0, {
2791
- F: __dxlog_file9,
3065
+ import_log9.log.catch(err, void 0, {
3066
+ F: __dxlog_file11,
2792
3067
  L: 104,
2793
3068
  S: this,
2794
3069
  C: (f, a) => f(...a)
@@ -2808,7 +3083,8 @@ var InvitationsManager = class {
2808
3083
  return existingInvitation;
2809
3084
  }
2810
3085
  const handler = this._getHandler(options);
2811
- const invitation = this._invitationsHandler.acceptInvitation(handler, options, request.deviceProfile);
3086
+ const { ctx, invitation, stream, otpEnteredTrigger } = this._createObservableAcceptingInvitation(handler, options);
3087
+ this._invitationsHandler.acceptInvitation(ctx, stream, handler, options, otpEnteredTrigger, request.deviceProfile);
2812
3088
  this._acceptInvitations.set(invitation.get().invitationId, invitation);
2813
3089
  this.invitationAccepted.emit(invitation.get());
2814
3090
  this._onInvitationComplete(invitation, () => {
@@ -2818,15 +3094,15 @@ var InvitationsManager = class {
2818
3094
  return invitation;
2819
3095
  }
2820
3096
  async authenticate({ invitationId, authCode }) {
2821
- (0, import_log7.log)("authenticating...", void 0, {
2822
- F: __dxlog_file9,
2823
- L: 133,
3097
+ (0, import_log9.log)("authenticating...", void 0, {
3098
+ F: __dxlog_file11,
3099
+ L: 134,
2824
3100
  S: this,
2825
3101
  C: (f, a) => f(...a)
2826
3102
  });
2827
- (0, import_invariant8.invariant)(invitationId, void 0, {
2828
- F: __dxlog_file9,
2829
- L: 134,
3103
+ (0, import_invariant10.invariant)(invitationId, void 0, {
3104
+ F: __dxlog_file11,
3105
+ L: 135,
2830
3106
  S: this,
2831
3107
  A: [
2832
3108
  "invitationId",
@@ -2835,11 +3111,11 @@ var InvitationsManager = class {
2835
3111
  });
2836
3112
  const observable = this._acceptInvitations.get(invitationId);
2837
3113
  if (!observable) {
2838
- import_log7.log.warn("invalid invitation", {
3114
+ import_log9.log.warn("invalid invitation", {
2839
3115
  invitationId
2840
3116
  }, {
2841
- F: __dxlog_file9,
2842
- L: 137,
3117
+ F: __dxlog_file11,
3118
+ L: 138,
2843
3119
  S: this,
2844
3120
  C: (f, a) => f(...a)
2845
3121
  });
@@ -2848,17 +3124,17 @@ var InvitationsManager = class {
2848
3124
  }
2849
3125
  }
2850
3126
  async cancelInvitation({ invitationId }) {
2851
- (0, import_log7.log)("cancelInvitation...", {
3127
+ (0, import_log9.log)("cancelInvitation...", {
2852
3128
  invitationId
2853
3129
  }, {
2854
- F: __dxlog_file9,
2855
- L: 144,
3130
+ F: __dxlog_file11,
3131
+ L: 145,
2856
3132
  S: this,
2857
3133
  C: (f, a) => f(...a)
2858
3134
  });
2859
- (0, import_invariant8.invariant)(invitationId, void 0, {
2860
- F: __dxlog_file9,
2861
- L: 145,
3135
+ (0, import_invariant10.invariant)(invitationId, void 0, {
3136
+ F: __dxlog_file11,
3137
+ L: 146,
2862
3138
  S: this,
2863
3139
  A: [
2864
3140
  "invitationId",
@@ -2870,6 +3146,10 @@ var InvitationsManager = class {
2870
3146
  if (created.get().persistent) {
2871
3147
  await this._metadataStore.removeInvitation(invitationId);
2872
3148
  }
3149
+ if (created.get().type === import_services8.Invitation.Type.DELEGATED) {
3150
+ const handler = this._getHandler(created.get());
3151
+ await handler.cancelDelegation(created.get());
3152
+ }
2873
3153
  await created.cancel();
2874
3154
  this._createInvitations.delete(invitationId);
2875
3155
  this.removedCreated.emit(created.get());
@@ -2900,8 +3180,8 @@ var InvitationsManager = class {
2900
3180
  }
2901
3181
  }
2902
3182
  _createInvitation(protocol, options) {
2903
- 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 ?? {};
2904
- const authCode = options?.authCode ?? (authMethod === import_services7.Invitation.AuthMethod.SHARED_SECRET ? (0, import_credentials9.generatePasscode)(import_client_protocol3.AUTHENTICATION_CODE_LENGTH) : void 0);
3183
+ const { invitationId = import_keys8.PublicKey.random().toHex(), type = import_services8.Invitation.Type.INTERACTIVE, authMethod = import_services8.Invitation.AuthMethod.SHARED_SECRET, state = import_services8.Invitation.State.INIT, timeout = import_client_protocol3.INVITATION_TIMEOUT, swarmKey = import_keys8.PublicKey.random(), persistent = options?.authMethod !== import_services8.Invitation.AuthMethod.KNOWN_PUBLIC_KEY, created = /* @__PURE__ */ new Date(), guestKeypair = void 0, lifetime = 86400, multiUse = false } = options ?? {};
3184
+ const authCode = options?.authCode ?? (authMethod === import_services8.Invitation.AuthMethod.SHARED_SECRET ? (0, import_credentials9.generatePasscode)(import_client_protocol3.AUTHENTICATION_CODE_LENGTH) : void 0);
2905
3185
  return {
2906
3186
  invitationId,
2907
3187
  type,
@@ -2910,8 +3190,8 @@ var InvitationsManager = class {
2910
3190
  swarmKey,
2911
3191
  authCode,
2912
3192
  timeout,
2913
- persistent: persistent && type !== import_services7.Invitation.Type.DELEGATED,
2914
- guestKeypair: guestKeypair ?? (authMethod === import_services7.Invitation.AuthMethod.KNOWN_PUBLIC_KEY ? createAdmissionKeypair() : void 0),
3193
+ persistent: persistent && type !== import_services8.Invitation.Type.DELEGATED,
3194
+ guestKeypair: guestKeypair ?? (authMethod === import_services8.Invitation.AuthMethod.KNOWN_PUBLIC_KEY ? createAdmissionKeypair() : void 0),
2915
3195
  created,
2916
3196
  lifetime,
2917
3197
  multiUse,
@@ -2920,19 +3200,19 @@ var InvitationsManager = class {
2920
3200
  };
2921
3201
  }
2922
3202
  _createObservableInvitation(handler, invitation) {
2923
- const stream = new import_async9.PushStream();
2924
- const ctx = new import_context6.Context({
3203
+ const stream = new import_async10.PushStream();
3204
+ const ctx = new import_context8.Context({
2925
3205
  onError: (err) => {
2926
3206
  stream.error(err);
2927
3207
  void ctx.dispose();
2928
3208
  }
2929
3209
  });
2930
3210
  ctx.onDispose(() => {
2931
- (0, import_log7.log)("complete", {
3211
+ (0, import_log9.log)("complete", {
2932
3212
  ...handler.toJSON()
2933
3213
  }, {
2934
- F: __dxlog_file9,
2935
- L: 228,
3214
+ F: __dxlog_file11,
3215
+ L: 233,
2936
3216
  S: this,
2937
3217
  C: (f, a) => f(...a)
2938
3218
  });
@@ -2944,7 +3224,7 @@ var InvitationsManager = class {
2944
3224
  onCancel: async () => {
2945
3225
  stream.next({
2946
3226
  ...invitation,
2947
- state: import_services7.Invitation.State.CANCELLED
3227
+ state: import_services8.Invitation.State.CANCELLED
2948
3228
  });
2949
3229
  await ctx.dispose();
2950
3230
  }
@@ -2955,8 +3235,73 @@ var InvitationsManager = class {
2955
3235
  observableInvitation
2956
3236
  };
2957
3237
  }
3238
+ _createObservableAcceptingInvitation(handler, initialState) {
3239
+ const otpEnteredTrigger = new import_async10.Trigger();
3240
+ const stream = new import_async10.PushStream();
3241
+ const ctx = new import_context8.Context({
3242
+ onError: (err) => {
3243
+ if (err instanceof import_async10.TimeoutError) {
3244
+ (0, import_log9.log)("timeout", {
3245
+ ...handler.toJSON()
3246
+ }, {
3247
+ F: __dxlog_file11,
3248
+ L: 253,
3249
+ S: this,
3250
+ C: (f, a) => f(...a)
3251
+ });
3252
+ stream.next({
3253
+ ...initialState,
3254
+ state: import_services8.Invitation.State.TIMEOUT
3255
+ });
3256
+ } else {
3257
+ import_log9.log.warn("auth failed", err, {
3258
+ F: __dxlog_file11,
3259
+ L: 256,
3260
+ S: this,
3261
+ C: (f, a) => f(...a)
3262
+ });
3263
+ stream.next({
3264
+ ...initialState,
3265
+ state: import_services8.Invitation.State.ERROR
3266
+ });
3267
+ }
3268
+ void ctx.dispose();
3269
+ }
3270
+ });
3271
+ ctx.onDispose(() => {
3272
+ (0, import_log9.log)("complete", {
3273
+ ...handler.toJSON()
3274
+ }, {
3275
+ F: __dxlog_file11,
3276
+ L: 263,
3277
+ S: this,
3278
+ C: (f, a) => f(...a)
3279
+ });
3280
+ stream.complete();
3281
+ });
3282
+ const invitation = new import_client_protocol3.AuthenticatingInvitation({
3283
+ initialInvitation: initialState,
3284
+ subscriber: stream.observable,
3285
+ onCancel: async () => {
3286
+ stream.next({
3287
+ ...initialState,
3288
+ state: import_services8.Invitation.State.CANCELLED
3289
+ });
3290
+ await ctx.dispose();
3291
+ },
3292
+ onAuthenticate: async (code) => {
3293
+ otpEnteredTrigger.wake(code);
3294
+ }
3295
+ });
3296
+ return {
3297
+ ctx,
3298
+ invitation,
3299
+ stream,
3300
+ otpEnteredTrigger
3301
+ };
3302
+ }
2958
3303
  async _persistIfRequired(handler, changeStream, invitation) {
2959
- if (invitation.type === import_services7.Invitation.Type.DELEGATED && invitation.delegationCredentialId == null) {
3304
+ if (invitation.type === import_services8.Invitation.Type.DELEGATED && invitation.delegationCredentialId == null) {
2960
3305
  const delegationCredentialId = await handler.delegate(invitation);
2961
3306
  changeStream.next({
2962
3307
  ...invitation,
@@ -2971,9 +3316,9 @@ var InvitationsManager = class {
2971
3316
  try {
2972
3317
  await this._metadataStore.removeInvitation(invitation.invitationId);
2973
3318
  } catch (err) {
2974
- import_log7.log.catch(err, void 0, {
2975
- F: __dxlog_file9,
2976
- L: 260,
3319
+ import_log9.log.catch(err, void 0, {
3320
+ F: __dxlog_file11,
3321
+ L: 299,
2977
3322
  S: this,
2978
3323
  C: (f, a) => f(...a)
2979
3324
  });
@@ -3065,7 +3410,7 @@ var AutomergeSpaceState = class {
3065
3410
  this._onNewRoot = _onNewRoot;
3066
3411
  this.rootUrl = void 0;
3067
3412
  this.lastEpoch = void 0;
3068
- this.onNewEpoch = new import_async11.Event();
3413
+ this.onNewEpoch = new import_async12.Event();
3069
3414
  this._isProcessingRootDocs = false;
3070
3415
  }
3071
3416
  async processCredential(credential) {
@@ -3094,18 +3439,18 @@ var AutomergeSpaceState = class {
3094
3439
  await this.onNewEpoch.waitForCondition(() => !!this.lastEpoch);
3095
3440
  }
3096
3441
  };
3097
- var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
3442
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
3098
3443
  var DEFAULT_RETRY_TIMEOUT = 1e3;
3099
3444
  var DEFAULT_SUCCESS_DELAY = 1e3;
3100
3445
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
3101
3446
  var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
3102
3447
  var NotarizationPlugin = class {
3103
3448
  constructor() {
3104
- this._ctx = new import_context8.Context();
3105
- this._extensionOpened = new import_async12.Event();
3449
+ this._ctx = new import_context10.Context();
3450
+ this._extensionOpened = new import_async13.Event();
3106
3451
  this._extensions = /* @__PURE__ */ new Set();
3107
- this._processedCredentials = new import_util5.ComplexSet(import_keys9.PublicKey.hash);
3108
- this._processCredentialsTriggers = new import_util5.ComplexMap(import_keys9.PublicKey.hash);
3452
+ this._processedCredentials = new import_util7.ComplexSet(import_keys10.PublicKey.hash);
3453
+ this._processCredentialsTriggers = new import_util7.ComplexMap(import_keys10.PublicKey.hash);
3109
3454
  }
3110
3455
  get hasWriter() {
3111
3456
  return !!this._writer;
@@ -3119,16 +3464,16 @@ var NotarizationPlugin = class {
3119
3464
  * Request credentials to be notarized.
3120
3465
  */
3121
3466
  async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
3122
- (0, import_log9.log)("notarize", {
3467
+ (0, import_log11.log)("notarize", {
3123
3468
  credentials
3124
3469
  }, {
3125
- F: __dxlog_file10,
3470
+ F: __dxlog_file12,
3126
3471
  L: 90,
3127
3472
  S: this,
3128
3473
  C: (f, a) => f(...a)
3129
3474
  });
3130
- (0, import_invariant10.invariant)(credentials.every((credential) => credential.id), "Credentials must have an id", {
3131
- F: __dxlog_file10,
3475
+ (0, import_invariant12.invariant)(credentials.every((credential) => credential.id), "Credentials must have an id", {
3476
+ F: __dxlog_file12,
3132
3477
  L: 91,
3133
3478
  S: this,
3134
3479
  A: [
@@ -3136,13 +3481,13 @@ var NotarizationPlugin = class {
3136
3481
  "'Credentials must have an id'"
3137
3482
  ]
3138
3483
  });
3139
- const errors = new import_async12.Trigger();
3484
+ const errors = new import_async13.Trigger();
3140
3485
  const ctx = this._ctx.derive({
3141
3486
  onError: (err) => {
3142
- import_log9.log.warn("Notarization error", {
3487
+ import_log11.log.warn("Notarization error", {
3143
3488
  err
3144
3489
  }, {
3145
- F: __dxlog_file10,
3490
+ F: __dxlog_file12,
3146
3491
  L: 99,
3147
3492
  S: this,
3148
3493
  C: (f, a) => f(...a)
@@ -3153,23 +3498,23 @@ var NotarizationPlugin = class {
3153
3498
  });
3154
3499
  opCtx?.onDispose(() => ctx.dispose());
3155
3500
  if (timeout !== 0) {
3156
- (0, import_async12.scheduleTask)(ctx, () => {
3157
- import_log9.log.warn("Notarization timeout", {
3501
+ (0, import_async13.scheduleTask)(ctx, () => {
3502
+ import_log11.log.warn("Notarization timeout", {
3158
3503
  timeout,
3159
3504
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
3160
3505
  }, {
3161
- F: __dxlog_file10,
3506
+ F: __dxlog_file12,
3162
3507
  L: 111,
3163
3508
  S: this,
3164
3509
  C: (f, a) => f(...a)
3165
3510
  });
3166
3511
  void ctx.dispose();
3167
- errors.throw(new import_async12.TimeoutError(timeout, "Notarization timed out"));
3512
+ errors.throw(new import_async13.TimeoutError(timeout, "Notarization timed out"));
3168
3513
  }, timeout);
3169
3514
  }
3170
3515
  const allNotarized = Promise.all(credentials.map((credential) => this._waitUntilProcessed(credential.id)));
3171
3516
  const peersTried = /* @__PURE__ */ new Set();
3172
- const notarizeTask = new import_async12.DeferredTask(ctx, async () => {
3517
+ const notarizeTask = new import_async13.DeferredTask(ctx, async () => {
3173
3518
  try {
3174
3519
  if (this._extensions.size === 0) {
3175
3520
  return;
@@ -3178,24 +3523,24 @@ var NotarizationPlugin = class {
3178
3523
  ...this._extensions
3179
3524
  ].find((peer2) => !peersTried.has(peer2));
3180
3525
  if (!peer) {
3181
- import_log9.log.info("Exhausted all peers to notarize with", {
3526
+ import_log11.log.info("Exhausted all peers to notarize with", {
3182
3527
  retryIn: retryTimeout
3183
3528
  }, {
3184
- F: __dxlog_file10,
3529
+ F: __dxlog_file12,
3185
3530
  L: 136,
3186
3531
  S: this,
3187
3532
  C: (f, a) => f(...a)
3188
3533
  });
3189
3534
  peersTried.clear();
3190
- (0, import_async12.scheduleTask)(ctx, () => notarizeTask.schedule(), retryTimeout);
3535
+ (0, import_async13.scheduleTask)(ctx, () => notarizeTask.schedule(), retryTimeout);
3191
3536
  return;
3192
3537
  }
3193
3538
  peersTried.add(peer);
3194
- (0, import_log9.log)("try notarizing", {
3539
+ (0, import_log11.log)("try notarizing", {
3195
3540
  peer: peer.localPeerId,
3196
3541
  credentialId: credentials.map((credential) => credential.id)
3197
3542
  }, {
3198
- F: __dxlog_file10,
3543
+ F: __dxlog_file12,
3199
3544
  L: 143,
3200
3545
  S: this,
3201
3546
  C: (f, a) => f(...a)
@@ -3203,17 +3548,17 @@ var NotarizationPlugin = class {
3203
3548
  await peer.rpc.NotarizationService.notarize({
3204
3549
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
3205
3550
  });
3206
- (0, import_log9.log)("success", void 0, {
3207
- F: __dxlog_file10,
3551
+ (0, import_log11.log)("success", void 0, {
3552
+ F: __dxlog_file12,
3208
3553
  L: 147,
3209
3554
  S: this,
3210
3555
  C: (f, a) => f(...a)
3211
3556
  });
3212
- await (0, import_async12.sleep)(successDelay);
3557
+ await (0, import_async13.sleep)(successDelay);
3213
3558
  } catch (err) {
3214
3559
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
3215
- import_log9.log.info("error notarizing (recoverable)", err, {
3216
- F: __dxlog_file10,
3560
+ import_log11.log.info("error notarizing (recoverable)", err, {
3561
+ F: __dxlog_file12,
3217
3562
  L: 151,
3218
3563
  S: this,
3219
3564
  C: (f, a) => f(...a)
@@ -3226,12 +3571,12 @@ var NotarizationPlugin = class {
3226
3571
  this._extensionOpened.on(ctx, () => notarizeTask.schedule());
3227
3572
  try {
3228
3573
  await Promise.race([
3229
- (0, import_context8.rejectOnDispose)(ctx),
3574
+ (0, import_context10.rejectOnDispose)(ctx),
3230
3575
  allNotarized,
3231
3576
  errors.wait()
3232
3577
  ]);
3233
- (0, import_log9.log)("done", void 0, {
3234
- F: __dxlog_file10,
3578
+ (0, import_log11.log)("done", void 0, {
3579
+ F: __dxlog_file12,
3235
3580
  L: 162,
3236
3581
  S: this,
3237
3582
  C: (f, a) => f(...a)
@@ -3252,8 +3597,8 @@ var NotarizationPlugin = class {
3252
3597
  this._processCredentialsTriggers.delete(credential.id);
3253
3598
  }
3254
3599
  setWriter(writer) {
3255
- (0, import_invariant10.invariant)(!this._writer, "Writer already set.", {
3256
- F: __dxlog_file10,
3600
+ (0, import_invariant12.invariant)(!this._writer, "Writer already set.", {
3601
+ F: __dxlog_file12,
3257
3602
  L: 181,
3258
3603
  S: this,
3259
3604
  A: [
@@ -3267,7 +3612,7 @@ var NotarizationPlugin = class {
3267
3612
  if (this._processedCredentials.has(id)) {
3268
3613
  return;
3269
3614
  }
3270
- await (0, import_util5.entry)(this._processCredentialsTriggers, id).orInsert(new import_async12.Trigger()).value.wait();
3615
+ await (0, import_util7.entry)(this._processCredentialsTriggers, id).orInsert(new import_async13.Trigger()).value.wait();
3271
3616
  }
3272
3617
  /**
3273
3618
  * Requests from other peers to notarize credentials.
@@ -3277,8 +3622,8 @@ var NotarizationPlugin = class {
3277
3622
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
3278
3623
  }
3279
3624
  for (const credential of request.credentials ?? []) {
3280
- (0, import_invariant10.invariant)(credential.id, "Credential must have an id", {
3281
- F: __dxlog_file10,
3625
+ (0, import_invariant12.invariant)(credential.id, "Credential must have an id", {
3626
+ F: __dxlog_file12,
3282
3627
  L: 200,
3283
3628
  S: this,
3284
3629
  A: [
@@ -3295,10 +3640,10 @@ var NotarizationPlugin = class {
3295
3640
  createExtension() {
3296
3641
  const extension = new NotarizationTeleportExtension({
3297
3642
  onOpen: async () => {
3298
- (0, import_log9.log)("extension opened", {
3643
+ (0, import_log11.log)("extension opened", {
3299
3644
  peer: extension.localPeerId
3300
3645
  }, {
3301
- F: __dxlog_file10,
3646
+ F: __dxlog_file12,
3302
3647
  L: 211,
3303
3648
  S: this,
3304
3649
  C: (f, a) => f(...a)
@@ -3307,10 +3652,10 @@ var NotarizationPlugin = class {
3307
3652
  this._extensionOpened.emit();
3308
3653
  },
3309
3654
  onClose: async () => {
3310
- (0, import_log9.log)("extension closed", {
3655
+ (0, import_log11.log)("extension closed", {
3311
3656
  peer: extension.localPeerId
3312
3657
  }, {
3313
- F: __dxlog_file10,
3658
+ F: __dxlog_file12,
3314
3659
  L: 216,
3315
3660
  S: this,
3316
3661
  C: (f, a) => f(...a)
@@ -3322,14 +3667,14 @@ var NotarizationPlugin = class {
3322
3667
  return extension;
3323
3668
  }
3324
3669
  };
3325
- var NotarizationTeleportExtension = class extends import_teleport2.RpcExtension {
3670
+ var NotarizationTeleportExtension = class extends import_teleport3.RpcExtension {
3326
3671
  constructor(_params) {
3327
3672
  super({
3328
3673
  requested: {
3329
- NotarizationService: import_protocols8.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3674
+ NotarizationService: import_protocols9.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3330
3675
  },
3331
3676
  exposed: {
3332
- NotarizationService: import_protocols8.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3677
+ NotarizationService: import_protocols9.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3333
3678
  }
3334
3679
  });
3335
3680
  this._params = _params;
@@ -3362,16 +3707,16 @@ function _ts_decorate4(decorators, target, key, desc) {
3362
3707
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3363
3708
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3364
3709
  }
3365
- var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
3710
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
3366
3711
  var DataSpace = class {
3367
3712
  constructor(params) {
3368
- this._ctx = new import_context7.Context();
3713
+ this._ctx = new import_context9.Context();
3369
3714
  this._notarizationPlugin = new NotarizationPlugin();
3370
3715
  this._cache = void 0;
3371
3716
  this._automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
3372
- this._state = import_services8.SpaceState.CLOSED;
3717
+ this._state = import_services9.SpaceState.CLOSED;
3373
3718
  this.error = void 0;
3374
- this.stateUpdate = new import_async10.Event();
3719
+ this.stateUpdate = new import_async11.Event();
3375
3720
  this.metrics = {};
3376
3721
  this._inner = params.inner;
3377
3722
  this._inner.stateUpdate.on(this._ctx, () => this.stateUpdate.emit());
@@ -3382,19 +3727,19 @@ var DataSpace = class {
3382
3727
  this._metadataStore = params.metadataStore;
3383
3728
  this._signingContext = params.signingContext;
3384
3729
  this._callbacks = params.callbacks ?? {};
3385
- this._automergeHost = params.automergeHost;
3730
+ this._echoHost = params.echoHost;
3386
3731
  this.authVerifier = new TrustedKeySetAuthVerifier({
3387
- trustedKeysProvider: () => new import_util4.ComplexSet(import_keys8.PublicKey.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => !member.removed).map((member) => member.key)),
3732
+ trustedKeysProvider: () => new import_util6.ComplexSet(import_keys9.PublicKey.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => !member.removed).map((member) => member.key)),
3388
3733
  update: this._inner.stateUpdate,
3389
3734
  authTimeout: import_client_protocol4.AUTH_TIMEOUT
3390
3735
  });
3391
3736
  this._cache = params.cache;
3392
3737
  this._state = params.initialState;
3393
- (0, import_log8.log)("new state", {
3394
- state: import_services8.SpaceState[this._state]
3738
+ (0, import_log10.log)("new state", {
3739
+ state: import_services9.SpaceState[this._state]
3395
3740
  }, {
3396
- F: __dxlog_file11,
3397
- L: 140,
3741
+ F: __dxlog_file13,
3742
+ L: 136,
3398
3743
  S: this,
3399
3744
  C: (f, a) => f(...a)
3400
3745
  });
@@ -3438,13 +3783,13 @@ var DataSpace = class {
3438
3783
  await this._notarizationPlugin.open();
3439
3784
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
3440
3785
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
3441
- await this._inner.open(new import_context7.Context());
3442
- this._state = import_services8.SpaceState.CONTROL_ONLY;
3443
- (0, import_log8.log)("new state", {
3444
- state: import_services8.SpaceState[this._state]
3786
+ await this._inner.open(new import_context9.Context());
3787
+ this._state = import_services9.SpaceState.CONTROL_ONLY;
3788
+ (0, import_log10.log)("new state", {
3789
+ state: import_services9.SpaceState[this._state]
3445
3790
  }, {
3446
- F: __dxlog_file11,
3447
- L: 198,
3791
+ F: __dxlog_file13,
3792
+ L: 194,
3448
3793
  S: this,
3449
3794
  C: (f, a) => f(...a)
3450
3795
  });
@@ -3457,17 +3802,17 @@ var DataSpace = class {
3457
3802
  }
3458
3803
  async _close() {
3459
3804
  await this._callbacks.beforeClose?.();
3460
- this._state = import_services8.SpaceState.CLOSED;
3461
- (0, import_log8.log)("new state", {
3462
- state: import_services8.SpaceState[this._state]
3805
+ this._state = import_services9.SpaceState.CLOSED;
3806
+ (0, import_log10.log)("new state", {
3807
+ state: import_services9.SpaceState[this._state]
3463
3808
  }, {
3464
- F: __dxlog_file11,
3465
- L: 212,
3809
+ F: __dxlog_file13,
3810
+ L: 208,
3466
3811
  S: this,
3467
3812
  C: (f, a) => f(...a)
3468
3813
  });
3469
3814
  await this._ctx.dispose();
3470
- this._ctx = new import_context7.Context();
3815
+ this._ctx = new import_context9.Context();
3471
3816
  await this.authVerifier.close();
3472
3817
  await this._inner.close();
3473
3818
  await this._inner.spaceState.removeCredentialProcessor(this._automergeSpaceState);
@@ -3486,32 +3831,32 @@ var DataSpace = class {
3486
3831
  * Initialize the data pipeline in a separate task.
3487
3832
  */
3488
3833
  initializeDataPipelineAsync() {
3489
- (0, import_async10.scheduleTask)(this._ctx, async () => {
3834
+ (0, import_async11.scheduleTask)(this._ctx, async () => {
3490
3835
  try {
3491
3836
  this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
3492
3837
  await this.initializeDataPipeline();
3493
3838
  } catch (err) {
3494
- if (err instanceof import_protocols7.CancelledError || err instanceof import_context7.ContextDisposedError) {
3495
- (0, import_log8.log)("data pipeline initialization cancelled", err, {
3496
- F: __dxlog_file11,
3497
- L: 245,
3839
+ if (err instanceof import_protocols8.CancelledError || err instanceof import_context9.ContextDisposedError) {
3840
+ (0, import_log10.log)("data pipeline initialization cancelled", err, {
3841
+ F: __dxlog_file13,
3842
+ L: 241,
3498
3843
  S: this,
3499
3844
  C: (f, a) => f(...a)
3500
3845
  });
3501
3846
  return;
3502
3847
  }
3503
- import_log8.log.error("Error initializing data pipeline", err, {
3504
- F: __dxlog_file11,
3505
- L: 249,
3848
+ import_log10.log.error("Error initializing data pipeline", err, {
3849
+ F: __dxlog_file13,
3850
+ L: 245,
3506
3851
  S: this,
3507
3852
  C: (f, a) => f(...a)
3508
3853
  });
3509
- this._state = import_services8.SpaceState.ERROR;
3510
- (0, import_log8.log)("new state", {
3511
- state: import_services8.SpaceState[this._state]
3854
+ this._state = import_services9.SpaceState.ERROR;
3855
+ (0, import_log10.log)("new state", {
3856
+ state: import_services9.SpaceState[this._state]
3512
3857
  }, {
3513
- F: __dxlog_file11,
3514
- L: 251,
3858
+ F: __dxlog_file13,
3859
+ L: 247,
3515
3860
  S: this,
3516
3861
  C: (f, a) => f(...a)
3517
3862
  });
@@ -3523,35 +3868,35 @@ var DataSpace = class {
3523
3868
  });
3524
3869
  }
3525
3870
  async initializeDataPipeline() {
3526
- if (this._state !== import_services8.SpaceState.CONTROL_ONLY) {
3527
- throw new import_protocols7.SystemError("Invalid operation");
3871
+ if (this._state !== import_services9.SpaceState.CONTROL_ONLY) {
3872
+ throw new import_protocols8.SystemError("Invalid operation");
3528
3873
  }
3529
- this._state = import_services8.SpaceState.INITIALIZING;
3530
- (0, import_log8.log)("new state", {
3531
- state: import_services8.SpaceState[this._state]
3874
+ this._state = import_services9.SpaceState.INITIALIZING;
3875
+ (0, import_log10.log)("new state", {
3876
+ state: import_services9.SpaceState[this._state]
3532
3877
  }, {
3533
- F: __dxlog_file11,
3534
- L: 267,
3878
+ F: __dxlog_file13,
3879
+ L: 263,
3535
3880
  S: this,
3536
3881
  C: (f, a) => f(...a)
3537
3882
  });
3538
3883
  await this._initializeAndReadControlPipeline();
3539
- await (0, import_async10.sleep)(1);
3884
+ await (0, import_async11.sleep)(1);
3540
3885
  this._automergeSpaceState.startProcessingRootDocs();
3541
- await (0, import_context7.cancelWithContext)(this._ctx, this.automergeSpaceState.ensureEpochInitialized());
3542
- (0, import_log8.log)("data pipeline ready", void 0, {
3543
- F: __dxlog_file11,
3544
- L: 279,
3886
+ await (0, import_context9.cancelWithContext)(this._ctx, this.automergeSpaceState.ensureEpochInitialized());
3887
+ (0, import_log10.log)("data pipeline ready", void 0, {
3888
+ F: __dxlog_file13,
3889
+ L: 275,
3545
3890
  S: this,
3546
3891
  C: (f, a) => f(...a)
3547
3892
  });
3548
3893
  await this._callbacks.beforeReady?.();
3549
- this._state = import_services8.SpaceState.READY;
3550
- (0, import_log8.log)("new state", {
3551
- state: import_services8.SpaceState[this._state]
3894
+ this._state = import_services9.SpaceState.READY;
3895
+ (0, import_log10.log)("new state", {
3896
+ state: import_services9.SpaceState[this._state]
3552
3897
  }, {
3553
- F: __dxlog_file11,
3554
- L: 283,
3898
+ F: __dxlog_file13,
3899
+ L: 279,
3555
3900
  S: this,
3556
3901
  C: (f, a) => f(...a)
3557
3902
  });
@@ -3565,9 +3910,9 @@ var DataSpace = class {
3565
3910
  });
3566
3911
  this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
3567
3912
  await this._createWritableFeeds();
3568
- (0, import_log8.log)("writable feeds created", void 0, {
3569
- F: __dxlog_file11,
3570
- L: 299,
3913
+ (0, import_log10.log)("writable feeds created", void 0, {
3914
+ F: __dxlog_file13,
3915
+ L: 295,
3571
3916
  S: this,
3572
3917
  C: (f, a) => f(...a)
3573
3918
  });
@@ -3625,26 +3970,26 @@ var DataSpace = class {
3625
3970
  }
3626
3971
  }
3627
3972
  _onNewAutomergeRoot(rootUrl) {
3628
- (0, import_log8.log)("loading automerge root doc for space", {
3973
+ (0, import_log10.log)("loading automerge root doc for space", {
3629
3974
  space: this.key,
3630
3975
  rootUrl
3631
3976
  }, {
3632
- F: __dxlog_file11,
3633
- L: 365,
3977
+ F: __dxlog_file13,
3978
+ L: 361,
3634
3979
  S: this,
3635
3980
  C: (f, a) => f(...a)
3636
3981
  });
3637
- this._automergeHost._requestedDocs.add(rootUrl);
3638
- const handle = this._automergeHost.repo.find(rootUrl);
3982
+ this._echoHost.replicateDocument(rootUrl);
3983
+ const handle = this._echoHost.automergeRepo.find(rootUrl);
3639
3984
  queueMicrotask(async () => {
3640
3985
  try {
3641
3986
  await (0, import_debug3.warnAfterTimeout)(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
3642
- await (0, import_context7.cancelWithContext)(this._ctx, handle.whenReady());
3987
+ await (0, import_context9.cancelWithContext)(this._ctx, handle.whenReady());
3643
3988
  });
3644
3989
  if (this._ctx.disposed) {
3645
3990
  return;
3646
3991
  }
3647
- const doc = handle.docSync() ?? (0, import_invariant9.failedInvariant)();
3992
+ const doc = handle.docSync() ?? (0, import_invariant11.failedInvariant)();
3648
3993
  if (!doc.access?.spaceKey) {
3649
3994
  handle.change((doc2) => {
3650
3995
  doc2.access = {
@@ -3653,16 +3998,16 @@ var DataSpace = class {
3653
3998
  });
3654
3999
  }
3655
4000
  } catch (err) {
3656
- if (err instanceof import_context7.ContextDisposedError) {
4001
+ if (err instanceof import_context9.ContextDisposedError) {
3657
4002
  return;
3658
4003
  }
3659
- import_log8.log.warn("error loading automerge root doc", {
4004
+ import_log10.log.warn("error loading automerge root doc", {
3660
4005
  space: this.key,
3661
4006
  rootUrl,
3662
4007
  err
3663
4008
  }, {
3664
- F: __dxlog_file11,
3665
- L: 388,
4009
+ F: __dxlog_file13,
4010
+ L: 384,
3666
4011
  S: this,
3667
4012
  C: (f, a) => f(...a)
3668
4013
  });
@@ -3688,7 +4033,7 @@ var DataSpace = class {
3688
4033
  let epoch;
3689
4034
  switch (options?.migration) {
3690
4035
  case void 0:
3691
- case import_services8.CreateEpochRequest.Migration.NONE:
4036
+ case import_services9.CreateEpochRequest.Migration.NONE:
3692
4037
  {
3693
4038
  epoch = {
3694
4039
  previousId: this._automergeSpaceState.lastEpoch?.id,
@@ -3698,9 +4043,9 @@ var DataSpace = class {
3698
4043
  };
3699
4044
  }
3700
4045
  break;
3701
- case import_services8.CreateEpochRequest.Migration.INIT_AUTOMERGE:
4046
+ case import_services9.CreateEpochRequest.Migration.INIT_AUTOMERGE:
3702
4047
  {
3703
- const document = this._automergeHost.repo.create();
4048
+ const document = this._echoHost.automergeRepo.create();
3704
4049
  epoch = {
3705
4050
  previousId: this._automergeSpaceState.lastEpoch?.id,
3706
4051
  number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
@@ -3709,15 +4054,15 @@ var DataSpace = class {
3709
4054
  };
3710
4055
  }
3711
4056
  break;
3712
- case import_services8.CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY:
4057
+ case import_services9.CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY:
3713
4058
  {
3714
4059
  const currentRootUrl = this._automergeSpaceState.rootUrl;
3715
- const rootHandle = this._automergeHost.repo.find(currentRootUrl);
3716
- await (0, import_context7.cancelWithContext)(this._ctx, (0, import_async10.asyncTimeout)(rootHandle.whenReady(), 1e4));
3717
- const newRoot = this._automergeHost.repo.create(rootHandle.docSync());
3718
- (0, import_invariant9.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3719
- F: __dxlog_file11,
3720
- L: 438,
4060
+ const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
4061
+ await (0, import_context9.cancelWithContext)(this._ctx, (0, import_async11.asyncTimeout)(rootHandle.whenReady(), 1e4));
4062
+ const newRoot = this._echoHost.automergeRepo.create(rootHandle.docSync());
4063
+ (0, import_invariant11.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
4064
+ F: __dxlog_file13,
4065
+ L: 434,
3721
4066
  S: this,
3722
4067
  A: [
3723
4068
  "typeof newRoot.url === 'string' && newRoot.url.length > 0",
@@ -3732,23 +4077,23 @@ var DataSpace = class {
3732
4077
  };
3733
4078
  }
3734
4079
  break;
3735
- case import_services8.CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT:
4080
+ case import_services9.CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT:
3736
4081
  {
3737
- import_log8.log.info("Fragmenting", void 0, {
3738
- F: __dxlog_file11,
3739
- L: 450,
4082
+ import_log10.log.info("Fragmenting", void 0, {
4083
+ F: __dxlog_file13,
4084
+ L: 446,
3740
4085
  S: this,
3741
4086
  C: (f, a) => f(...a)
3742
4087
  });
3743
4088
  const currentRootUrl = this._automergeSpaceState.rootUrl;
3744
- const rootHandle = this._automergeHost.repo.find(currentRootUrl);
3745
- await (0, import_context7.cancelWithContext)(this._ctx, (0, import_async10.asyncTimeout)(rootHandle.whenReady(), 1e4));
4089
+ const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
4090
+ await (0, import_context9.cancelWithContext)(this._ctx, (0, import_async11.asyncTimeout)(rootHandle.whenReady(), 1e4));
3746
4091
  const objects = Object.entries(rootHandle.docSync().objects);
3747
4092
  const properties = objects.find(([_, value]) => value.system.type?.itemId === import_echo_schema.TYPE_PROPERTIES);
3748
4093
  const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
3749
- (0, import_invariant9.invariant)(properties, "Properties not found", {
3750
- F: __dxlog_file11,
3751
- L: 460,
4094
+ (0, import_invariant11.invariant)(properties, "Properties not found", {
4095
+ F: __dxlog_file13,
4096
+ L: 456,
3752
4097
  S: this,
3753
4098
  A: [
3754
4099
  "properties",
@@ -3761,24 +4106,24 @@ var DataSpace = class {
3761
4106
  properties
3762
4107
  ])
3763
4108
  };
3764
- const newRoot = this._automergeHost.repo.create(newSpaceDoc);
3765
- (0, import_invariant9.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3766
- F: __dxlog_file11,
3767
- L: 465,
4109
+ const newRoot = this._echoHost.automergeRepo.create(newSpaceDoc);
4110
+ (0, import_invariant11.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
4111
+ F: __dxlog_file13,
4112
+ L: 461,
3768
4113
  S: this,
3769
4114
  A: [
3770
4115
  "typeof newRoot.url === 'string' && newRoot.url.length > 0",
3771
4116
  ""
3772
4117
  ]
3773
4118
  });
3774
- const docLoader = new import_echo_pipeline3.AutomergeDocumentLoaderImpl(this.key, this._automergeHost.repo);
4119
+ const docLoader = new import_echo_pipeline3.AutomergeDocumentLoaderImpl(this.key, this._echoHost.automergeRepo);
3775
4120
  await docLoader.loadSpaceRootDocHandle(this._ctx, {
3776
4121
  rootUrl: newRoot.url
3777
4122
  });
3778
4123
  otherObjects.forEach(([key, value]) => {
3779
4124
  const handle = docLoader.createDocumentForObject(key);
3780
4125
  handle.change((doc) => {
3781
- (0, import_util4.assignDeep)(doc, [
4126
+ (0, import_util6.assignDeep)(doc, [
3782
4127
  "objects",
3783
4128
  key
3784
4129
  ], value);
@@ -3815,25 +4160,25 @@ var DataSpace = class {
3815
4160
  ]));
3816
4161
  }
3817
4162
  async activate() {
3818
- if (this._state !== import_services8.SpaceState.INACTIVE) {
4163
+ if (this._state !== import_services9.SpaceState.INACTIVE) {
3819
4164
  return;
3820
4165
  }
3821
- await this._metadataStore.setSpaceState(this.key, import_services8.SpaceState.ACTIVE);
4166
+ await this._metadataStore.setSpaceState(this.key, import_services9.SpaceState.ACTIVE);
3822
4167
  await this._open();
3823
4168
  this.initializeDataPipelineAsync();
3824
4169
  }
3825
4170
  async deactivate() {
3826
- if (this._state === import_services8.SpaceState.INACTIVE) {
4171
+ if (this._state === import_services9.SpaceState.INACTIVE) {
3827
4172
  return;
3828
4173
  }
3829
- await this._metadataStore.setSpaceState(this.key, import_services8.SpaceState.INACTIVE);
4174
+ await this._metadataStore.setSpaceState(this.key, import_services9.SpaceState.INACTIVE);
3830
4175
  await this._close();
3831
- this._state = import_services8.SpaceState.INACTIVE;
3832
- (0, import_log8.log)("new state", {
3833
- state: import_services8.SpaceState[this._state]
4176
+ this._state = import_services9.SpaceState.INACTIVE;
4177
+ (0, import_log10.log)("new state", {
4178
+ state: import_services9.SpaceState[this._state]
3834
4179
  }, {
3835
- F: __dxlog_file11,
3836
- L: 531,
4180
+ F: __dxlog_file13,
4181
+ L: 527,
3837
4182
  S: this,
3838
4183
  C: (f, a) => f(...a)
3839
4184
  });
@@ -3848,7 +4193,7 @@ _ts_decorate4([
3848
4193
  ], DataSpace.prototype, "key", null);
3849
4194
  _ts_decorate4([
3850
4195
  import_tracing4.trace.info({
3851
- enum: import_services8.SpaceState
4196
+ enum: import_services9.SpaceState
3852
4197
  })
3853
4198
  ], DataSpace.prototype, "state", null);
3854
4199
  _ts_decorate4([
@@ -3857,10 +4202,10 @@ _ts_decorate4([
3857
4202
  })
3858
4203
  ], DataSpace.prototype, "_automergeInfo", null);
3859
4204
  _ts_decorate4([
3860
- import_async10.synchronized
4205
+ import_async11.synchronized
3861
4206
  ], DataSpace.prototype, "open", null);
3862
4207
  _ts_decorate4([
3863
- import_async10.synchronized
4208
+ import_async11.synchronized
3864
4209
  ], DataSpace.prototype, "close", null);
3865
4210
  _ts_decorate4([
3866
4211
  import_tracing4.trace.span({
@@ -3876,13 +4221,13 @@ _ts_decorate4([
3876
4221
  (0, import_debug3.timed)(1e4)
3877
4222
  ], DataSpace.prototype, "_createWritableFeeds", null);
3878
4223
  _ts_decorate4([
3879
- import_async10.synchronized
4224
+ import_async11.synchronized
3880
4225
  ], DataSpace.prototype, "activate", null);
3881
4226
  _ts_decorate4([
3882
- import_async10.synchronized
4227
+ import_async11.synchronized
3883
4228
  ], DataSpace.prototype, "deactivate", null);
3884
4229
  DataSpace = _ts_decorate4([
3885
- (0, import_async10.trackLeaks)("open", "close"),
4230
+ (0, import_async11.trackLeaks)("open", "close"),
3886
4231
  import_tracing4.trace.resource()
3887
4232
  ], DataSpace);
3888
4233
  var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
@@ -3959,23 +4304,23 @@ function _ts_decorate5(decorators, target, key, desc) {
3959
4304
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3960
4305
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3961
4306
  }
3962
- var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
4307
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
3963
4308
  var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
3964
4309
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
3965
4310
  var DataSpaceManager = class {
3966
- constructor(_spaceManager, _metadataStore, _keyring, _signingContext, _feedStore, _automergeHost, _invitationsManager, params) {
4311
+ constructor(_spaceManager, _metadataStore, _keyring, _signingContext, _feedStore, _echoHost, _invitationsManager, params) {
3967
4312
  this._spaceManager = _spaceManager;
3968
4313
  this._metadataStore = _metadataStore;
3969
4314
  this._keyring = _keyring;
3970
4315
  this._signingContext = _signingContext;
3971
4316
  this._feedStore = _feedStore;
3972
- this._automergeHost = _automergeHost;
4317
+ this._echoHost = _echoHost;
3973
4318
  this._invitationsManager = _invitationsManager;
3974
- this._ctx = new import_context9.Context();
3975
- this.updated = new import_async13.Event();
3976
- this._spaces = new import_util6.ComplexMap(import_keys10.PublicKey.hash);
4319
+ this._ctx = new import_context11.Context();
4320
+ this.updated = new import_async14.Event();
4321
+ this._spaces = new import_util8.ComplexMap(import_keys11.PublicKey.hash);
3977
4322
  this._isOpen = false;
3978
- this._instanceId = import_keys10.PublicKey.random().toHex();
4323
+ this._instanceId = import_keys11.PublicKey.random().toHex();
3979
4324
  const { spaceMemberPresenceAnnounceInterval = PRESENCE_ANNOUNCE_INTERVAL, spaceMemberPresenceOfflineTimeout = PRESENCE_OFFLINE_TIMEOUT } = params ?? {};
3980
4325
  this._spaceMemberPresenceAnnounceInterval = spaceMemberPresenceAnnounceInterval;
3981
4326
  this._spaceMemberPresenceOfflineTimeout = spaceMemberPresenceOfflineTimeout;
@@ -3985,46 +4330,46 @@ var DataSpaceManager = class {
3985
4330
  return this._spaces;
3986
4331
  }
3987
4332
  async open() {
3988
- (0, import_log10.log)("open", void 0, {
3989
- F: __dxlog_file12,
3990
- L: 101,
4333
+ (0, import_log12.log)("open", void 0, {
4334
+ F: __dxlog_file14,
4335
+ L: 102,
3991
4336
  S: this,
3992
4337
  C: (f, a) => f(...a)
3993
4338
  });
3994
- import_log10.log.trace("dxos.echo.data-space-manager.open", import_protocols9.trace.begin({
4339
+ import_log12.log.trace("dxos.echo.data-space-manager.open", import_protocols10.trace.begin({
3995
4340
  id: this._instanceId
3996
4341
  }), {
3997
- F: __dxlog_file12,
3998
- L: 102,
4342
+ F: __dxlog_file14,
4343
+ L: 103,
3999
4344
  S: this,
4000
4345
  C: (f, a) => f(...a)
4001
4346
  });
4002
- (0, import_log10.log)("metadata loaded", {
4347
+ (0, import_log12.log)("metadata loaded", {
4003
4348
  spaces: this._metadataStore.spaces.length
4004
4349
  }, {
4005
- F: __dxlog_file12,
4006
- L: 103,
4350
+ F: __dxlog_file14,
4351
+ L: 104,
4007
4352
  S: this,
4008
4353
  C: (f, a) => f(...a)
4009
4354
  });
4010
- await (0, import_util6.forEachAsync)(this._metadataStore.spaces, async (spaceMetadata) => {
4355
+ await (0, import_util8.forEachAsync)(this._metadataStore.spaces, async (spaceMetadata) => {
4011
4356
  try {
4012
- (0, import_log10.log)("load space", {
4357
+ (0, import_log12.log)("load space", {
4013
4358
  spaceMetadata
4014
4359
  }, {
4015
- F: __dxlog_file12,
4016
- L: 107,
4360
+ F: __dxlog_file14,
4361
+ L: 108,
4017
4362
  S: this,
4018
4363
  C: (f, a) => f(...a)
4019
4364
  });
4020
4365
  await this._constructSpace(spaceMetadata);
4021
4366
  } catch (err) {
4022
- import_log10.log.error("Error loading space", {
4367
+ import_log12.log.error("Error loading space", {
4023
4368
  spaceMetadata,
4024
4369
  err
4025
4370
  }, {
4026
- F: __dxlog_file12,
4027
- L: 110,
4371
+ F: __dxlog_file14,
4372
+ L: 111,
4028
4373
  S: this,
4029
4374
  C: (f, a) => f(...a)
4030
4375
  });
@@ -4033,23 +4378,23 @@ var DataSpaceManager = class {
4033
4378
  this._isOpen = true;
4034
4379
  this.updated.emit();
4035
4380
  for (const space of this._spaces.values()) {
4036
- if (space.state !== import_services9.SpaceState.INACTIVE) {
4381
+ if (space.state !== import_services10.SpaceState.INACTIVE) {
4037
4382
  space.initializeDataPipelineAsync();
4038
4383
  }
4039
4384
  }
4040
- import_log10.log.trace("dxos.echo.data-space-manager.open", import_protocols9.trace.end({
4385
+ import_log12.log.trace("dxos.echo.data-space-manager.open", import_protocols10.trace.end({
4041
4386
  id: this._instanceId
4042
4387
  }), {
4043
- F: __dxlog_file12,
4044
- L: 123,
4388
+ F: __dxlog_file14,
4389
+ L: 124,
4045
4390
  S: this,
4046
4391
  C: (f, a) => f(...a)
4047
4392
  });
4048
4393
  }
4049
4394
  async close() {
4050
- (0, import_log10.log)("close", void 0, {
4051
- F: __dxlog_file12,
4052
- L: 128,
4395
+ (0, import_log12.log)("close", void 0, {
4396
+ F: __dxlog_file14,
4397
+ L: 129,
4053
4398
  S: this,
4054
4399
  C: (f, a) => f(...a)
4055
4400
  });
@@ -4063,9 +4408,9 @@ var DataSpaceManager = class {
4063
4408
  * Creates a new space writing the genesis credentials to the control feed.
4064
4409
  */
4065
4410
  async createSpace() {
4066
- (0, import_invariant11.invariant)(this._isOpen, "Not open.", {
4067
- F: __dxlog_file12,
4068
- L: 141,
4411
+ (0, import_invariant13.invariant)(this._isOpen, "Not open.", {
4412
+ F: __dxlog_file14,
4413
+ L: 142,
4069
4414
  S: this,
4070
4415
  A: [
4071
4416
  "this._isOpen",
@@ -4080,29 +4425,24 @@ var DataSpaceManager = class {
4080
4425
  genesisFeedKey: controlFeedKey,
4081
4426
  controlFeedKey,
4082
4427
  dataFeedKey,
4083
- state: import_services9.SpaceState.ACTIVE
4428
+ state: import_services10.SpaceState.ACTIVE
4084
4429
  };
4085
- (0, import_log10.log)("creating space...", {
4430
+ (0, import_log12.log)("creating space...", {
4086
4431
  spaceKey
4087
4432
  }, {
4088
- F: __dxlog_file12,
4089
- L: 153,
4433
+ F: __dxlog_file14,
4434
+ L: 154,
4090
4435
  S: this,
4091
4436
  C: (f, a) => f(...a)
4092
4437
  });
4093
- const automergeRoot = this._automergeHost.repo.create();
4094
- automergeRoot.change((doc) => {
4095
- doc.access = {
4096
- spaceKey: spaceKey.toHex()
4097
- };
4098
- });
4438
+ const automergeRootUrl = await this._echoHost.createSpaceRoot(spaceKey);
4099
4439
  const space = await this._constructSpace(metadata);
4100
- const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRoot.url);
4440
+ const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRootUrl);
4101
4441
  await this._metadataStore.addSpace(metadata);
4102
4442
  const memberCredential = credentials[1];
4103
- (0, import_invariant11.invariant)((0, import_credentials12.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4104
- F: __dxlog_file12,
4105
- L: 166,
4443
+ (0, import_invariant13.invariant)((0, import_credentials12.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4444
+ F: __dxlog_file14,
4445
+ L: 163,
4106
4446
  S: this,
4107
4447
  A: [
4108
4448
  "getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -4116,26 +4456,26 @@ var DataSpaceManager = class {
4116
4456
  }
4117
4457
  // TODO(burdon): Rename join space.
4118
4458
  async acceptSpace(opts) {
4119
- (0, import_log10.log)("accept space", {
4459
+ (0, import_log12.log)("accept space", {
4120
4460
  opts
4121
4461
  }, {
4122
- F: __dxlog_file12,
4123
- L: 178,
4462
+ F: __dxlog_file14,
4463
+ L: 175,
4124
4464
  S: this,
4125
4465
  C: (f, a) => f(...a)
4126
4466
  });
4127
- (0, import_invariant11.invariant)(this._isOpen, "Not open.", {
4128
- F: __dxlog_file12,
4129
- L: 179,
4467
+ (0, import_invariant13.invariant)(this._isOpen, "Not open.", {
4468
+ F: __dxlog_file14,
4469
+ L: 176,
4130
4470
  S: this,
4131
4471
  A: [
4132
4472
  "this._isOpen",
4133
4473
  "'Not open.'"
4134
4474
  ]
4135
4475
  });
4136
- (0, import_invariant11.invariant)(!this._spaces.has(opts.spaceKey), "Space already exists.", {
4137
- F: __dxlog_file12,
4138
- L: 180,
4476
+ (0, import_invariant13.invariant)(!this._spaces.has(opts.spaceKey), "Space already exists.", {
4477
+ F: __dxlog_file14,
4478
+ L: 177,
4139
4479
  S: this,
4140
4480
  A: [
4141
4481
  "!this._spaces.has(opts.spaceKey)",
@@ -4160,17 +4500,17 @@ var DataSpaceManager = class {
4160
4500
  * TODO(dmaretskyi): Consider removing.
4161
4501
  */
4162
4502
  async waitUntilSpaceReady(spaceKey) {
4163
- await (0, import_context9.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
4503
+ await (0, import_context11.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
4164
4504
  const space = this._spaces.get(spaceKey);
4165
- return !!space && space.state === import_services9.SpaceState.READY;
4505
+ return !!space && space.state === import_services10.SpaceState.READY;
4166
4506
  }));
4167
4507
  }
4168
4508
  async _constructSpace(metadata) {
4169
- (0, import_log10.log)("construct space", {
4509
+ (0, import_log12.log)("construct space", {
4170
4510
  metadata
4171
4511
  }, {
4172
- F: __dxlog_file12,
4173
- L: 213,
4512
+ F: __dxlog_file14,
4513
+ L: 210,
4174
4514
  S: this,
4175
4515
  C: (f, a) => f(...a)
4176
4516
  });
@@ -4195,20 +4535,20 @@ var DataSpaceManager = class {
4195
4535
  swarmIdentity: {
4196
4536
  peerKey: this._signingContext.deviceKey,
4197
4537
  credentialProvider: createAuthProvider(this._signingContext.credentialSigner),
4198
- credentialAuthenticator: (0, import_util6.deferFunction)(() => dataSpace.authVerifier.verifier)
4538
+ credentialAuthenticator: (0, import_util8.deferFunction)(() => dataSpace.authVerifier.verifier)
4199
4539
  },
4200
4540
  onAuthorizedConnection: (session) => {
4201
4541
  session.addExtension("dxos.mesh.teleport.gossip", gossip.createExtension({
4202
4542
  remotePeerId: session.remotePeerId
4203
4543
  }));
4204
4544
  session.addExtension("dxos.mesh.teleport.notarization", dataSpace.notarizationPlugin.createExtension());
4205
- this._automergeHost.authorizeDevice(space.key, session.remotePeerId);
4206
- session.addExtension("dxos.mesh.teleport.automerge", this._automergeHost.createExtension());
4545
+ this._echoHost.authorizeDevice(space.key, session.remotePeerId);
4546
+ session.addExtension("dxos.mesh.teleport.automerge", this._echoHost.createReplicationExtension());
4207
4547
  },
4208
4548
  onAuthFailure: () => {
4209
- import_log10.log.warn("auth failure", void 0, {
4210
- F: __dxlog_file12,
4211
- L: 250,
4549
+ import_log12.log.warn("auth failure", void 0, {
4550
+ F: __dxlog_file14,
4551
+ L: 247,
4212
4552
  S: this,
4213
4553
  C: (f, a) => f(...a)
4214
4554
  });
@@ -4222,31 +4562,32 @@ var DataSpaceManager = class {
4222
4562
  dataFeed && await space.setDataFeed(dataFeed);
4223
4563
  const dataSpace = new DataSpace({
4224
4564
  inner: space,
4225
- initialState: metadata.state === import_services9.SpaceState.INACTIVE ? import_services9.SpaceState.INACTIVE : import_services9.SpaceState.CLOSED,
4565
+ initialState: metadata.state === import_services10.SpaceState.INACTIVE ? import_services10.SpaceState.INACTIVE : import_services10.SpaceState.CLOSED,
4226
4566
  metadataStore: this._metadataStore,
4227
4567
  gossip,
4228
4568
  presence,
4229
4569
  keyring: this._keyring,
4230
4570
  feedStore: this._feedStore,
4571
+ echoHost: this._echoHost,
4231
4572
  signingContext: this._signingContext,
4232
4573
  callbacks: {
4233
4574
  beforeReady: async () => {
4234
- (0, import_log10.log)("before space ready", {
4575
+ (0, import_log12.log)("before space ready", {
4235
4576
  space: space.key
4236
4577
  }, {
4237
- F: __dxlog_file12,
4238
- L: 271,
4578
+ F: __dxlog_file14,
4579
+ L: 269,
4239
4580
  S: this,
4240
4581
  C: (f, a) => f(...a)
4241
4582
  });
4242
4583
  },
4243
4584
  afterReady: async () => {
4244
- (0, import_log10.log)("after space ready", {
4585
+ (0, import_log12.log)("after space ready", {
4245
4586
  space: space.key,
4246
4587
  open: this._isOpen
4247
4588
  }, {
4248
- F: __dxlog_file12,
4249
- L: 274,
4589
+ F: __dxlog_file14,
4590
+ L: 272,
4250
4591
  S: this,
4251
4592
  C: (f, a) => f(...a)
4252
4593
  });
@@ -4258,20 +4599,19 @@ var DataSpaceManager = class {
4258
4599
  }
4259
4600
  },
4260
4601
  beforeClose: async () => {
4261
- (0, import_log10.log)("before space close", {
4602
+ (0, import_log12.log)("before space close", {
4262
4603
  space: space.key
4263
4604
  }, {
4264
- F: __dxlog_file12,
4265
- L: 281,
4605
+ F: __dxlog_file14,
4606
+ L: 279,
4266
4607
  S: this,
4267
4608
  C: (f, a) => f(...a)
4268
4609
  });
4269
4610
  }
4270
4611
  },
4271
- cache: metadata.cache,
4272
- automergeHost: this._automergeHost
4612
+ cache: metadata.cache
4273
4613
  });
4274
- if (metadata.state !== import_services9.SpaceState.INACTIVE) {
4614
+ if (metadata.state !== import_services10.SpaceState.INACTIVE) {
4275
4615
  await dataSpace.open();
4276
4616
  }
4277
4617
  if (metadata.controlTimeframe) {
@@ -4281,7 +4621,7 @@ var DataSpaceManager = class {
4281
4621
  return dataSpace;
4282
4622
  }
4283
4623
  async _handleInvitationStatusChange(dataSpace, delegatedInvitation, isActive) {
4284
- if (dataSpace?.state !== import_services9.SpaceState.READY) {
4624
+ if (dataSpace?.state !== import_services10.SpaceState.READY) {
4285
4625
  return;
4286
4626
  }
4287
4627
  if (isActive) {
@@ -4298,8 +4638,8 @@ var DataSpaceManager = class {
4298
4638
  async _createDelegatedInvitations(space, invitations) {
4299
4639
  const tasks = invitations.map(([credentialId, invitation]) => {
4300
4640
  return this._invitationsManager.createInvitation({
4301
- type: import_services9.Invitation.Type.DELEGATED,
4302
- kind: import_services9.Invitation.Kind.SPACE,
4641
+ type: import_services10.Invitation.Type.DELEGATED,
4642
+ kind: import_services10.Invitation.Kind.SPACE,
4303
4643
  spaceKey: space.key,
4304
4644
  authMethod: invitation.authMethod,
4305
4645
  invitationId: invitation.invitationId,
@@ -4317,21 +4657,21 @@ var DataSpaceManager = class {
4317
4657
  }
4318
4658
  };
4319
4659
  _ts_decorate5([
4320
- import_async13.synchronized
4660
+ import_async14.synchronized
4321
4661
  ], DataSpaceManager.prototype, "open", null);
4322
4662
  _ts_decorate5([
4323
- import_async13.synchronized
4663
+ import_async14.synchronized
4324
4664
  ], DataSpaceManager.prototype, "close", null);
4325
4665
  _ts_decorate5([
4326
- import_async13.synchronized
4666
+ import_async14.synchronized
4327
4667
  ], DataSpaceManager.prototype, "createSpace", null);
4328
4668
  _ts_decorate5([
4329
- import_async13.synchronized
4669
+ import_async14.synchronized
4330
4670
  ], DataSpaceManager.prototype, "acceptSpace", null);
4331
4671
  DataSpaceManager = _ts_decorate5([
4332
- (0, import_async13.trackLeaks)("open", "close")
4672
+ (0, import_async14.trackLeaks)("open", "close")
4333
4673
  ], DataSpaceManager);
4334
- var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
4674
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
4335
4675
  var SpacesServiceImpl = class {
4336
4676
  constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
4337
4677
  this._identityManager = _identityManager;
@@ -4348,29 +4688,29 @@ var SpacesServiceImpl = class {
4348
4688
  }
4349
4689
  async updateSpace({ spaceKey, state }) {
4350
4690
  const dataSpaceManager = await this._getDataSpaceManager();
4351
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols10.SpaceNotFoundError(spaceKey));
4691
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4352
4692
  if (state) {
4353
4693
  switch (state) {
4354
- case import_services10.SpaceState.ACTIVE:
4694
+ case import_services11.SpaceState.ACTIVE:
4355
4695
  await space.activate();
4356
4696
  break;
4357
- case import_services10.SpaceState.INACTIVE:
4697
+ case import_services11.SpaceState.INACTIVE:
4358
4698
  await space.deactivate();
4359
4699
  break;
4360
4700
  default:
4361
- throw new import_protocols10.ApiError("Invalid space state");
4701
+ throw new import_protocols11.ApiError("Invalid space state");
4362
4702
  }
4363
4703
  }
4364
4704
  }
4365
4705
  querySpaces() {
4366
4706
  return new import_codec_protobuf10.Stream(({ next, ctx }) => {
4367
- const scheduler = new import_async14.UpdateScheduler(ctx, async () => {
4707
+ const scheduler = new import_async15.UpdateScheduler(ctx, async () => {
4368
4708
  const dataSpaceManager = await this._getDataSpaceManager();
4369
4709
  const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
4370
- (0, import_log11.log)("update", {
4710
+ (0, import_log13.log)("update", {
4371
4711
  spaces
4372
4712
  }, {
4373
- F: __dxlog_file13,
4713
+ F: __dxlog_file15,
4374
4714
  L: 77,
4375
4715
  S: this,
4376
4716
  C: (f, a) => f(...a)
@@ -4381,9 +4721,9 @@ var SpacesServiceImpl = class {
4381
4721
  }, {
4382
4722
  maxFrequency: process.env.NODE_ENV === "test" ? void 0 : 2
4383
4723
  });
4384
- (0, import_async14.scheduleTask)(ctx, async () => {
4724
+ (0, import_async15.scheduleTask)(ctx, async () => {
4385
4725
  const dataSpaceManager = await this._getDataSpaceManager();
4386
- const subscriptions = new import_async14.EventSubscriptions();
4726
+ const subscriptions = new import_async15.EventSubscriptions();
4387
4727
  ctx.onDispose(() => subscriptions.clear());
4388
4728
  const subscribeSpaces = () => {
4389
4729
  subscriptions.clear();
@@ -4410,14 +4750,14 @@ var SpacesServiceImpl = class {
4410
4750
  }
4411
4751
  async postMessage({ spaceKey, channel, message }) {
4412
4752
  const dataSpaceManager = await this._getDataSpaceManager();
4413
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols10.SpaceNotFoundError(spaceKey));
4753
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4414
4754
  await space.postMessage(getChannelId(channel), message);
4415
4755
  }
4416
4756
  subscribeMessages({ spaceKey, channel }) {
4417
4757
  return new import_codec_protobuf10.Stream(({ ctx, next }) => {
4418
- (0, import_async14.scheduleTask)(ctx, async () => {
4758
+ (0, import_async15.scheduleTask)(ctx, async () => {
4419
4759
  const dataSpaceManager = await this._getDataSpaceManager();
4420
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols10.SpaceNotFoundError(spaceKey));
4760
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4421
4761
  const handle = space.listen(getChannelId(channel), (message) => {
4422
4762
  next(message);
4423
4763
  });
@@ -4427,14 +4767,14 @@ var SpacesServiceImpl = class {
4427
4767
  }
4428
4768
  queryCredentials({ spaceKey, noTail }) {
4429
4769
  return new import_codec_protobuf10.Stream(({ ctx, next, close }) => {
4430
- const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols10.SpaceNotFoundError(spaceKey));
4770
+ const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4431
4771
  const processor = {
4432
4772
  processCredential: async (credential) => {
4433
4773
  next(credential);
4434
4774
  }
4435
4775
  };
4436
4776
  ctx.onDispose(() => space.spaceState.removeCredentialProcessor(processor));
4437
- (0, import_async14.scheduleTask)(ctx, async () => {
4777
+ (0, import_async15.scheduleTask)(ctx, async () => {
4438
4778
  await space.spaceState.addCredentialProcessor(processor);
4439
4779
  if (noTail) {
4440
4780
  close();
@@ -4443,7 +4783,7 @@ var SpacesServiceImpl = class {
4443
4783
  });
4444
4784
  }
4445
4785
  async writeCredentials({ spaceKey, credentials }) {
4446
- const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols10.SpaceNotFoundError(spaceKey));
4786
+ const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4447
4787
  for (const credential of credentials ?? []) {
4448
4788
  if (credential.proof) {
4449
4789
  await space.controlPipeline.writer.write({
@@ -4452,8 +4792,8 @@ var SpacesServiceImpl = class {
4452
4792
  }
4453
4793
  });
4454
4794
  } else {
4455
- (0, import_invariant12.invariant)(!credential.id, "Id on unsigned credentials is not allowed", {
4456
- F: __dxlog_file13,
4795
+ (0, import_invariant14.invariant)(!credential.id, "Id on unsigned credentials is not allowed", {
4796
+ F: __dxlog_file15,
4457
4797
  L: 164,
4458
4798
  S: this,
4459
4799
  A: [
@@ -4461,8 +4801,8 @@ var SpacesServiceImpl = class {
4461
4801
  "'Id on unsigned credentials is not allowed'"
4462
4802
  ]
4463
4803
  });
4464
- (0, import_invariant12.invariant)(this._identityManager.identity, "Identity is not available", {
4465
- F: __dxlog_file13,
4804
+ (0, import_invariant14.invariant)(this._identityManager.identity, "Identity is not available", {
4805
+ F: __dxlog_file15,
4466
4806
  L: 165,
4467
4807
  S: this,
4468
4808
  A: [
@@ -4471,8 +4811,8 @@ var SpacesServiceImpl = class {
4471
4811
  ]
4472
4812
  });
4473
4813
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
4474
- (0, import_invariant12.invariant)(credential.issuer.equals(signer.getIssuer()), void 0, {
4475
- F: __dxlog_file13,
4814
+ (0, import_invariant14.invariant)(credential.issuer.equals(signer.getIssuer()), void 0, {
4815
+ F: __dxlog_file15,
4476
4816
  L: 167,
4477
4817
  S: this,
4478
4818
  A: [
@@ -4494,7 +4834,7 @@ var SpacesServiceImpl = class {
4494
4834
  }
4495
4835
  async createEpoch({ spaceKey, migration }) {
4496
4836
  const dataSpaceManager = await this._getDataSpaceManager();
4497
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols10.SpaceNotFoundError(spaceKey));
4837
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4498
4838
  await space.createEpoch({
4499
4839
  migration
4500
4840
  });
@@ -4503,7 +4843,7 @@ var SpacesServiceImpl = class {
4503
4843
  return {
4504
4844
  spaceKey: space.key,
4505
4845
  state: space.state,
4506
- error: space.error ? (0, import_protocols10.encodeError)(space.error) : void 0,
4846
+ error: space.error ? (0, import_protocols11.encodeError)(space.error) : void 0,
4507
4847
  pipeline: {
4508
4848
  currentEpoch: space.automergeSpaceState.lastEpoch,
4509
4849
  appliedEpoch: space.automergeSpaceState.lastEpoch,
@@ -4528,7 +4868,7 @@ var SpacesServiceImpl = class {
4528
4868
  identityKey: member.key,
4529
4869
  profile: member.profile ?? {}
4530
4870
  },
4531
- presence: member.removed ? import_services10.SpaceMember.PresenceState.REMOVED : isMe || peers.length > 0 ? import_services10.SpaceMember.PresenceState.ONLINE : import_services10.SpaceMember.PresenceState.OFFLINE,
4871
+ presence: member.removed ? import_services11.SpaceMember.PresenceState.REMOVED : isMe || peers.length > 0 ? import_services11.SpaceMember.PresenceState.ONLINE : import_services11.SpaceMember.PresenceState.OFFLINE,
4532
4872
  peerStates: peers
4533
4873
  };
4534
4874
  }),
@@ -4539,31 +4879,6 @@ var SpacesServiceImpl = class {
4539
4879
  }
4540
4880
  };
4541
4881
  var getChannelId = (channel) => `user-channel/${channel}`;
4542
- var createSelectedDocumentsIterator = (automergeHost) => (
4543
- /**
4544
- * Get object data blobs from Automerge Repo by ids.
4545
- * @param ids
4546
- */
4547
- // TODO(mykola): Unload automerge handles after usage.
4548
- async function* loadDocuments(ids) {
4549
- for (const id of ids) {
4550
- const { documentId, objectId } = import_protocols12.idCodec.decode(id);
4551
- const handle = automergeHost.repo.handles[documentId] ?? automergeHost.repo.find(documentId);
4552
- if (!handle.isReady()) {
4553
- await handle.whenReady();
4554
- }
4555
- const doc = handle.docSync();
4556
- const hash = (0, import_automerge.getHeads)(doc).join("");
4557
- yield doc.objects?.[objectId] ? [
4558
- {
4559
- id,
4560
- object: doc.objects[objectId],
4561
- currentHash: hash
4562
- }
4563
- ] : [];
4564
- }
4565
- }
4566
- );
4567
4882
  function _ts_decorate6(decorators, target, key, desc) {
4568
4883
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4569
4884
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -4574,8 +4889,8 @@ function _ts_decorate6(decorators, target, key, desc) {
4574
4889
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4575
4890
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4576
4891
  }
4577
- var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
4578
- var ServiceContext = class extends import_context10.Resource {
4892
+ var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
4893
+ var ServiceContext = class extends import_context12.Resource {
4579
4894
  constructor(storage, level, networkManager, signalManager, _runtimeParams) {
4580
4895
  super();
4581
4896
  this.storage = storage;
@@ -4583,9 +4898,9 @@ var ServiceContext = class extends import_context10.Resource {
4583
4898
  this.networkManager = networkManager;
4584
4899
  this.signalManager = signalManager;
4585
4900
  this._runtimeParams = _runtimeParams;
4586
- this.initialized = new import_async15.Trigger();
4901
+ this.initialized = new import_async16.Trigger();
4587
4902
  this._handlerFactories = /* @__PURE__ */ new Map();
4588
- this._instanceId = import_keys11.PublicKey.random().toHex();
4903
+ this._instanceId = import_keys12.PublicKey.random().toHex();
4589
4904
  this.metadataStore = new import_echo_pipeline4.MetadataStore(storage.createDirectory("metadata"));
4590
4905
  this.snapshotStore = new import_echo_pipeline4.SnapshotStore(storage.createDirectory("snapshots"));
4591
4906
  this.blobStore = new import_teleport_extension_object_sync.BlobStore(storage.createDirectory("blobs"));
@@ -4608,48 +4923,33 @@ var ServiceContext = class extends import_context10.Resource {
4608
4923
  snapshotStore: this.snapshotStore
4609
4924
  });
4610
4925
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager, this._runtimeParams);
4611
- this.indexMetadata = new import_indexing.IndexMetadataStore({
4612
- db: level.sublevel("index-metadata")
4613
- });
4614
- this.automergeHost = new import_echo_pipeline4.AutomergeHost({
4615
- directory: storage.createDirectory("automerge"),
4616
- db: level.sublevel("automerge"),
4617
- storageCallbacks: (0, import_indexing.createStorageCallbacks)({
4618
- host: () => this.automergeHost,
4619
- metadata: this.indexMetadata
4620
- })
4621
- });
4622
- this.indexer = new import_indexing.Indexer({
4623
- db: this.level,
4624
- indexStore: new import_indexing.IndexStore({
4625
- db: level.sublevel("index-storage")
4626
- }),
4627
- metadataStore: this.indexMetadata,
4628
- loadDocuments: createSelectedDocumentsIterator(this.automergeHost)
4926
+ this.echoHost = new import_echo_db.EchoHost({
4927
+ kv: this.level,
4928
+ storage: this.storage
4629
4929
  });
4630
- this.invitations = new InvitationsHandler(this.networkManager);
4930
+ this.invitations = new InvitationsHandler(this.networkManager, _runtimeParams?.invitationConnectionDefaultParams);
4631
4931
  this.invitationsManager = new InvitationsManager(this.invitations, (invitation) => this.getInvitationHandler(invitation), this.metadataStore);
4632
- this._handlerFactories.set(import_services11.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug6.failUndefined)(), this._acceptIdentity.bind(this)));
4932
+ this._handlerFactories.set(import_services12.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug6.failUndefined)(), this._acceptIdentity.bind(this)));
4633
4933
  }
4634
4934
  async _open(ctx) {
4635
4935
  await this._checkStorageVersion();
4636
- (0, import_log12.log)("opening...", void 0, {
4637
- F: __dxlog_file14,
4638
- L: 164,
4936
+ (0, import_log14.log)("opening...", void 0, {
4937
+ F: __dxlog_file16,
4938
+ L: 152,
4639
4939
  S: this,
4640
4940
  C: (f, a) => f(...a)
4641
4941
  });
4642
- import_log12.log.trace("dxos.sdk.service-context.open", import_protocols11.trace.begin({
4942
+ import_log14.log.trace("dxos.sdk.service-context.open", import_protocols12.trace.begin({
4643
4943
  id: this._instanceId
4644
4944
  }), {
4645
- F: __dxlog_file14,
4646
- L: 165,
4945
+ F: __dxlog_file16,
4946
+ L: 153,
4647
4947
  S: this,
4648
4948
  C: (f, a) => f(...a)
4649
4949
  });
4650
4950
  await this.signalManager.open();
4651
4951
  await this.networkManager.open();
4652
- await this.automergeHost.open();
4952
+ await this.echoHost.open(ctx);
4653
4953
  await this.metadataStore.load();
4654
4954
  await this.spaceManager.open();
4655
4955
  await this.identityManager.open(ctx);
@@ -4657,65 +4957,64 @@ var ServiceContext = class extends import_context10.Resource {
4657
4957
  await this._initialize(ctx);
4658
4958
  }
4659
4959
  const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
4660
- (0, import_log12.log)("loaded persistent invitations", {
4960
+ (0, import_log14.log)("loaded persistent invitations", {
4661
4961
  count: loadedInvitations.invitations?.length
4662
4962
  }, {
4663
- F: __dxlog_file14,
4664
- L: 178,
4963
+ F: __dxlog_file16,
4964
+ L: 166,
4665
4965
  S: this,
4666
4966
  C: (f, a) => f(...a)
4667
4967
  });
4668
- import_log12.log.trace("dxos.sdk.service-context.open", import_protocols11.trace.end({
4968
+ import_log14.log.trace("dxos.sdk.service-context.open", import_protocols12.trace.end({
4669
4969
  id: this._instanceId
4670
4970
  }), {
4671
- F: __dxlog_file14,
4672
- L: 180,
4971
+ F: __dxlog_file16,
4972
+ L: 168,
4673
4973
  S: this,
4674
4974
  C: (f, a) => f(...a)
4675
4975
  });
4676
- (0, import_log12.log)("opened", void 0, {
4677
- F: __dxlog_file14,
4678
- L: 181,
4976
+ (0, import_log14.log)("opened", void 0, {
4977
+ F: __dxlog_file16,
4978
+ L: 169,
4679
4979
  S: this,
4680
4980
  C: (f, a) => f(...a)
4681
4981
  });
4682
4982
  }
4683
- async _close() {
4684
- (0, import_log12.log)("closing...", void 0, {
4685
- F: __dxlog_file14,
4686
- L: 185,
4983
+ async _close(ctx) {
4984
+ (0, import_log14.log)("closing...", void 0, {
4985
+ F: __dxlog_file16,
4986
+ L: 173,
4687
4987
  S: this,
4688
4988
  C: (f, a) => f(...a)
4689
4989
  });
4690
4990
  if (this._deviceSpaceSync && this.identityManager.identity) {
4691
4991
  await this.identityManager.identity.space.spaceState.removeCredentialProcessor(this._deviceSpaceSync);
4692
4992
  }
4693
- await this.automergeHost.close();
4694
4993
  await this.dataSpaceManager?.close();
4695
4994
  await this.identityManager.close();
4696
4995
  await this.spaceManager.close();
4697
4996
  await this.feedStore.close();
4997
+ await this.metadataStore.close();
4998
+ await this.echoHost.close(ctx);
4698
4999
  await this.networkManager.close();
4699
5000
  await this.signalManager.close();
4700
- await this.metadataStore.close();
4701
- await this.indexer.destroy();
4702
- (0, import_log12.log)("closed", void 0, {
4703
- F: __dxlog_file14,
4704
- L: 198,
5001
+ (0, import_log14.log)("closed", void 0, {
5002
+ F: __dxlog_file16,
5003
+ L: 185,
4705
5004
  S: this,
4706
5005
  C: (f, a) => f(...a)
4707
5006
  });
4708
5007
  }
4709
5008
  async createIdentity(params = {}) {
4710
5009
  const identity = await this.identityManager.createIdentity(params);
4711
- await this._initialize(new import_context10.Context());
5010
+ await this._initialize(new import_context12.Context());
4712
5011
  return identity;
4713
5012
  }
4714
5013
  getInvitationHandler(invitation) {
4715
5014
  const factory = this._handlerFactories.get(invitation.kind);
4716
- (0, import_invariant13.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
4717
- F: __dxlog_file14,
4718
- L: 209,
5015
+ (0, import_invariant15.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
5016
+ F: __dxlog_file16,
5017
+ L: 196,
4719
5018
  S: this,
4720
5019
  A: [
4721
5020
  "factory",
@@ -4734,20 +5033,20 @@ var ServiceContext = class extends import_context10.Resource {
4734
5033
  }
4735
5034
  async _acceptIdentity(params) {
4736
5035
  const identity = await this.identityManager.acceptIdentity(params);
4737
- await this._initialize(new import_context10.Context());
5036
+ await this._initialize(new import_context12.Context());
4738
5037
  return identity;
4739
5038
  }
4740
5039
  async _checkStorageVersion() {
4741
5040
  await this.metadataStore.load();
4742
- if (this.metadataStore.version !== import_protocols11.STORAGE_VERSION) {
4743
- throw new import_protocols11.InvalidStorageVersionError(import_protocols11.STORAGE_VERSION, this.metadataStore.version);
5041
+ if (this.metadataStore.version !== import_protocols12.STORAGE_VERSION) {
5042
+ throw new import_protocols12.InvalidStorageVersionError(import_protocols12.STORAGE_VERSION, this.metadataStore.version);
4744
5043
  }
4745
5044
  }
4746
5045
  // Called when identity is created.
4747
5046
  async _initialize(ctx) {
4748
- (0, import_log12.log)("initializing spaces...", void 0, {
4749
- F: __dxlog_file14,
4750
- L: 240,
5047
+ (0, import_log14.log)("initializing spaces...", void 0, {
5048
+ F: __dxlog_file16,
5049
+ L: 227,
4751
5050
  S: this,
4752
5051
  C: (f, a) => f(...a)
4753
5052
  });
@@ -4765,12 +5064,12 @@ var ServiceContext = class extends import_context10.Resource {
4765
5064
  });
4766
5065
  }
4767
5066
  };
4768
- this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.automergeHost, this.invitationsManager, this._runtimeParams);
5067
+ this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.echoHost, this.invitationsManager, this._runtimeParams);
4769
5068
  await this.dataSpaceManager.open();
4770
- this._handlerFactories.set(import_services11.Invitation.Kind.SPACE, (invitation) => {
4771
- (0, import_invariant13.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4772
- F: __dxlog_file14,
4773
- L: 265,
5069
+ this._handlerFactories.set(import_services12.Invitation.Kind.SPACE, (invitation) => {
5070
+ (0, import_invariant15.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
5071
+ F: __dxlog_file16,
5072
+ L: 252,
4774
5073
  S: this,
4775
5074
  A: [
4776
5075
  "this.dataSpaceManager",
@@ -4790,33 +5089,33 @@ var ServiceContext = class extends import_context10.Resource {
4790
5089
  return;
4791
5090
  }
4792
5091
  if (!this.dataSpaceManager) {
4793
- (0, import_log12.log)("dataSpaceManager not initialized yet, ignoring space admission", {
5092
+ (0, import_log14.log)("dataSpaceManager not initialized yet, ignoring space admission", {
4794
5093
  details: assertion
4795
5094
  }, {
4796
- F: __dxlog_file14,
4797
- L: 281,
5095
+ F: __dxlog_file16,
5096
+ L: 268,
4798
5097
  S: this,
4799
5098
  C: (f, a) => f(...a)
4800
5099
  });
4801
5100
  return;
4802
5101
  }
4803
5102
  if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
4804
- (0, import_log12.log)("space already exists, ignoring space admission", {
5103
+ (0, import_log14.log)("space already exists, ignoring space admission", {
4805
5104
  details: assertion
4806
5105
  }, {
4807
- F: __dxlog_file14,
4808
- L: 285,
5106
+ F: __dxlog_file16,
5107
+ L: 272,
4809
5108
  S: this,
4810
5109
  C: (f, a) => f(...a)
4811
5110
  });
4812
5111
  return;
4813
5112
  }
4814
5113
  try {
4815
- (0, import_log12.log)("accepting space recorded in halo", {
5114
+ (0, import_log14.log)("accepting space recorded in halo", {
4816
5115
  details: assertion
4817
5116
  }, {
4818
- F: __dxlog_file14,
4819
- L: 290,
5117
+ F: __dxlog_file16,
5118
+ L: 277,
4820
5119
  S: this,
4821
5120
  C: (f, a) => f(...a)
4822
5121
  });
@@ -4825,9 +5124,9 @@ var ServiceContext = class extends import_context10.Resource {
4825
5124
  genesisFeedKey: assertion.genesisFeedKey
4826
5125
  });
4827
5126
  } catch (err) {
4828
- import_log12.log.catch(err, void 0, {
4829
- F: __dxlog_file14,
4830
- L: 296,
5127
+ import_log14.log.catch(err, void 0, {
5128
+ F: __dxlog_file16,
5129
+ L: 283,
4831
5130
  S: this,
4832
5131
  C: (f, a) => f(...a)
4833
5132
  });
@@ -4844,7 +5143,7 @@ _ts_decorate6([
4844
5143
  import_tracing5.trace.span()
4845
5144
  ], ServiceContext.prototype, "_initialize", null);
4846
5145
  ServiceContext = _ts_decorate6([
4847
- (0, import_util7.safeInstanceof)("dxos.client-services.ServiceContext"),
5146
+ (0, import_util9.safeInstanceof)("dxos.client-services.ServiceContext"),
4848
5147
  import_tracing5.trace.resource()
4849
5148
  ], ServiceContext);
4850
5149
  var ServiceRegistry = class {
@@ -4869,26 +5168,26 @@ var ServiceRegistry = class {
4869
5168
  delete this._handlers[name];
4870
5169
  }
4871
5170
  };
4872
- var DXOS_VERSION = "0.5.1-next.2ad6c47";
5171
+ var DXOS_VERSION = "0.5.1-next.39e0ee2";
4873
5172
  var getPlatform = () => {
4874
5173
  if (process.browser) {
4875
5174
  if (typeof window !== "undefined") {
4876
5175
  const { userAgent } = window.navigator;
4877
5176
  return {
4878
- type: import_services13.Platform.PLATFORM_TYPE.BROWSER,
5177
+ type: import_services14.Platform.PLATFORM_TYPE.BROWSER,
4879
5178
  userAgent,
4880
5179
  uptime: Math.floor((Date.now() - window.performance.timeOrigin) / 1e3)
4881
5180
  };
4882
5181
  } else {
4883
5182
  return {
4884
- type: import_services13.Platform.PLATFORM_TYPE.SHARED_WORKER,
5183
+ type: import_services14.Platform.PLATFORM_TYPE.SHARED_WORKER,
4885
5184
  uptime: Math.floor((Date.now() - performance.timeOrigin) / 1e3)
4886
5185
  };
4887
5186
  }
4888
5187
  } else {
4889
5188
  const { platform: platform2, version, arch } = process;
4890
5189
  return {
4891
- type: import_services13.Platform.PLATFORM_TYPE.NODE,
5190
+ type: import_services14.Platform.PLATFORM_TYPE.NODE,
4892
5191
  platform: platform2,
4893
5192
  arch,
4894
5193
  runtime: version,
@@ -4897,7 +5196,7 @@ var getPlatform = () => {
4897
5196
  };
4898
5197
  }
4899
5198
  };
4900
- var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts";
5199
+ var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts";
4901
5200
  var DEFAULT_TIMEOUT = 1e3;
4902
5201
  var createDiagnostics = async (clientServices, serviceContext, config) => {
4903
5202
  const diagnostics = {
@@ -4912,8 +5211,8 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
4912
5211
  trace: import_tracing6.TRACE_PROCESSOR.getDiagnostics()
4913
5212
  };
4914
5213
  {
4915
- (0, import_invariant14.invariant)(clientServices.LoggingService, "SystemService is not available.", {
4916
- F: __dxlog_file15,
5214
+ (0, import_invariant16.invariant)(clientServices.LoggingService, "SystemService is not available.", {
5215
+ F: __dxlog_file17,
4917
5216
  L: 108,
4918
5217
  S: void 0,
4919
5218
  A: [
@@ -4986,7 +5285,7 @@ var getSpaceStats = async (space) => {
4986
5285
  displayName: member.assertion.profile?.displayName
4987
5286
  }
4988
5287
  },
4989
- presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? import_services12.SpaceMember.PresenceState.ONLINE : import_services12.SpaceMember.PresenceState.OFFLINE
5288
+ presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? import_services13.SpaceMember.PresenceState.ONLINE : import_services13.SpaceMember.PresenceState.OFFLINE
4990
5289
  })),
4991
5290
  pipeline: {
4992
5291
  // TODO(burdon): Pick properties from credentials if needed.
@@ -5017,7 +5316,7 @@ var createCollectDiagnosticsBroadcastHandler = (_) => {
5017
5316
  }
5018
5317
  };
5019
5318
  };
5020
- var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
5319
+ var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
5021
5320
  var DevicesServiceImpl = class {
5022
5321
  constructor(_identityManager) {
5023
5322
  this._identityManager = _identityManager;
@@ -5034,8 +5333,8 @@ var DevicesServiceImpl = class {
5034
5333
  devices: []
5035
5334
  });
5036
5335
  } else {
5037
- (0, import_invariant16.invariant)(this._identityManager.identity?.presence, "presence not present", {
5038
- F: __dxlog_file16,
5336
+ (0, import_invariant18.invariant)(this._identityManager.identity?.presence, "presence not present", {
5337
+ F: __dxlog_file18,
5039
5338
  L: 32,
5040
5339
  S: this,
5041
5340
  A: [
@@ -5050,9 +5349,9 @@ var DevicesServiceImpl = class {
5050
5349
  const peerState = peers.find((peer) => peer.identityKey.equals(key));
5051
5350
  return {
5052
5351
  deviceKey: key,
5053
- kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services16.DeviceKind.CURRENT : import_services16.DeviceKind.TRUSTED,
5352
+ kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services17.DeviceKind.CURRENT : import_services17.DeviceKind.TRUSTED,
5054
5353
  profile,
5055
- presence: isMe ? import_services16.Device.PresenceState.ONLINE : peerState ? import_services16.Device.PresenceState.ONLINE : import_services16.Device.PresenceState.OFFLINE
5354
+ presence: isMe ? import_services17.Device.PresenceState.ONLINE : peerState ? import_services17.Device.PresenceState.ONLINE : import_services17.Device.PresenceState.OFFLINE
5056
5355
  };
5057
5356
  })
5058
5357
  });
@@ -5076,7 +5375,7 @@ var DevicesServiceImpl = class {
5076
5375
  presenceSubscribed = true;
5077
5376
  }
5078
5377
  };
5079
- const subscriptions = new import_async17.EventSubscriptions();
5378
+ const subscriptions = new import_async18.EventSubscriptions();
5080
5379
  if (this._identityManager.identity) {
5081
5380
  subscribeIdentity();
5082
5381
  subscribePresence();
@@ -5103,7 +5402,7 @@ function _ts_decorate7(decorators, target, key, desc) {
5103
5402
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5104
5403
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5105
5404
  }
5106
- var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/node.ts";
5405
+ var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/node.ts";
5107
5406
  var Lock = class {
5108
5407
  constructor({ lockKey: lockPath, onAcquire, onRelease }) {
5109
5408
  this._lockPath = lockPath;
@@ -5114,16 +5413,16 @@ var Lock = class {
5114
5413
  return this._lockPath;
5115
5414
  }
5116
5415
  async acquire() {
5117
- (0, import_log14.log)("acquiring lock...", void 0, {
5118
- F: __dxlog_file17,
5416
+ (0, import_log16.log)("acquiring lock...", void 0, {
5417
+ F: __dxlog_file19,
5119
5418
  L: 32,
5120
5419
  S: this,
5121
5420
  C: (f, a) => f(...a)
5122
5421
  });
5123
5422
  this._fileHandle = await import_lock_file.LockFile.acquire(this._lockPath);
5124
5423
  await this._onAcquire?.();
5125
- (0, import_log14.log)("acquired lock", void 0, {
5126
- F: __dxlog_file17,
5424
+ (0, import_log16.log)("acquired lock", void 0, {
5425
+ F: __dxlog_file19,
5127
5426
  L: 37,
5128
5427
  S: this,
5129
5428
  C: (f, a) => f(...a)
@@ -5131,8 +5430,8 @@ var Lock = class {
5131
5430
  }
5132
5431
  async release() {
5133
5432
  await this._onRelease?.();
5134
- (0, import_invariant17.invariant)(this._fileHandle, "Lock is not acquired", {
5135
- F: __dxlog_file17,
5433
+ (0, import_invariant19.invariant)(this._fileHandle, "Lock is not acquired", {
5434
+ F: __dxlog_file19,
5136
5435
  L: 42,
5137
5436
  S: this,
5138
5437
  A: [
@@ -5144,36 +5443,36 @@ var Lock = class {
5144
5443
  }
5145
5444
  };
5146
5445
  _ts_decorate7([
5147
- import_log14.logInfo
5446
+ import_log16.logInfo
5148
5447
  ], Lock.prototype, "lockKey", null);
5149
5448
  var isLocked = (lockPath) => import_lock_file.LockFile.isLocked(lockPath);
5150
5449
  var LoggingServiceImpl = class {
5151
5450
  constructor() {
5152
- this._logs = new import_async18.Event();
5451
+ this._logs = new import_async19.Event();
5153
5452
  this._started = Date.now();
5154
- this._sessionId = import_keys13.PublicKey.random().toHex();
5453
+ this._sessionId = import_keys14.PublicKey.random().toHex();
5155
5454
  this._logProcessor = (_config, entry2) => {
5156
5455
  this._logs.emit(entry2);
5157
5456
  };
5158
5457
  }
5159
5458
  async open() {
5160
- import_log15.log.runtimeConfig.processors.push(this._logProcessor);
5459
+ import_log17.log.runtimeConfig.processors.push(this._logProcessor);
5161
5460
  }
5162
5461
  async close() {
5163
- const index = import_log15.log.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
5164
- import_log15.log.runtimeConfig.processors.splice(index, 1);
5462
+ const index = import_log17.log.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
5463
+ import_log17.log.runtimeConfig.processors.splice(index, 1);
5165
5464
  }
5166
5465
  async controlMetrics({ reset, record }) {
5167
5466
  if (reset) {
5168
- import_util10.tracer.clear();
5467
+ import_util12.tracer.clear();
5169
5468
  }
5170
5469
  if (record === true) {
5171
- import_util10.tracer.start();
5470
+ import_util12.tracer.start();
5172
5471
  } else if (record === false) {
5173
- import_util10.tracer.stop();
5472
+ import_util12.tracer.stop();
5174
5473
  }
5175
5474
  return {
5176
- recording: import_util10.tracer.recording
5475
+ recording: import_util12.tracer.recording
5177
5476
  };
5178
5477
  }
5179
5478
  /**
@@ -5181,10 +5480,10 @@ var LoggingServiceImpl = class {
5181
5480
  */
5182
5481
  queryMetrics({ interval = 5e3 }) {
5183
5482
  const getNumericalValues = (key) => {
5184
- const events = import_util10.tracer.get(key) ?? [];
5483
+ const events = import_util12.tracer.get(key) ?? [];
5185
5484
  return {
5186
5485
  key,
5187
- stats: (0, import_util10.numericalValues)(events, "duration")
5486
+ stats: (0, import_util12.numericalValues)(events, "duration")
5188
5487
  };
5189
5488
  };
5190
5489
  return new import_codec_protobuf13.Stream(({ next }) => {
@@ -5222,7 +5521,7 @@ var LoggingServiceImpl = class {
5222
5521
  }
5223
5522
  const record = {
5224
5523
  ...entry2,
5225
- context: (0, import_util10.jsonify)((0, import_log15.getContextFromEntry)(entry2)),
5524
+ context: (0, import_util12.jsonify)((0, import_log17.getContextFromEntry)(entry2)),
5226
5525
  timestamp: /* @__PURE__ */ new Date(),
5227
5526
  meta: {
5228
5527
  // TODO(dmaretskyi): Fix proto.
@@ -5231,7 +5530,7 @@ var LoggingServiceImpl = class {
5231
5530
  scope: {
5232
5531
  hostSessionId: this._sessionId,
5233
5532
  uptimeSeconds: (Date.now() - this._started) / 1e3,
5234
- name: (0, import_util10.getDebugName)(entry2.meta?.S)
5533
+ name: (0, import_util12.getDebugName)(entry2.meta?.S)
5235
5534
  }
5236
5535
  }
5237
5536
  };
@@ -5248,16 +5547,16 @@ var LoggingServiceImpl = class {
5248
5547
  };
5249
5548
  var matchFilter = (filter, level, path2, options) => {
5250
5549
  switch (options) {
5251
- case import_services17.QueryLogsRequest.MatchingOptions.INCLUSIVE:
5550
+ case import_services18.QueryLogsRequest.MatchingOptions.INCLUSIVE:
5252
5551
  return level >= filter.level && (!filter.pattern || path2.includes(filter.pattern));
5253
- case import_services17.QueryLogsRequest.MatchingOptions.EXPLICIT:
5552
+ case import_services18.QueryLogsRequest.MatchingOptions.EXPLICIT:
5254
5553
  return level === filter.level && (!filter.pattern || path2.includes(filter.pattern));
5255
5554
  }
5256
5555
  };
5257
5556
  var shouldLog = (entry2, request) => {
5258
- const options = request.options ?? import_services17.QueryLogsRequest.MatchingOptions.INCLUSIVE;
5557
+ const options = request.options ?? import_services18.QueryLogsRequest.MatchingOptions.INCLUSIVE;
5259
5558
  if (request.filters === void 0) {
5260
- return options === import_services17.QueryLogsRequest.MatchingOptions.INCLUSIVE;
5559
+ return options === import_services18.QueryLogsRequest.MatchingOptions.INCLUSIVE;
5261
5560
  } else {
5262
5561
  return request.filters.some((filter) => matchFilter(filter, entry2.level, entry2.meta?.F ?? "", options));
5263
5562
  }
@@ -5294,7 +5593,7 @@ var NetworkServiceImpl = class {
5294
5593
  }
5295
5594
  };
5296
5595
  var getRootPath = (config) => {
5297
- const { dataRoot = (0, import_util11.isNode)() ? import_client_protocol6.DX_DATA : "dxos/storage" } = config ?? {};
5596
+ const { dataRoot = (0, import_util13.isNode)() ? import_client_protocol6.DX_DATA : "dxos/storage" } = config ?? {};
5298
5597
  return `${dataRoot}/`;
5299
5598
  };
5300
5599
  var isPersistent = (config) => {
@@ -5345,8 +5644,8 @@ var toStorageType = (type) => {
5345
5644
  };
5346
5645
  var createLevel = async (config) => {
5347
5646
  const persistent = isPersistent(config);
5348
- const storagePath = persistent ? import_node_path.default.join(getRootPath(config), "level") : `/tmp/dxos-${import_keys14.PublicKey.random().toHex()}`;
5349
- const level = new import_level.Level(storagePath);
5647
+ const storagePath = persistent ? import_node_path.default.join(getRootPath(config), "level") : `/tmp/dxos-${import_keys15.PublicKey.random().toHex()}`;
5648
+ const level = (0, import_kv_store.createLevel)(storagePath);
5350
5649
  await level.open();
5351
5650
  return level;
5352
5651
  };
@@ -5369,9 +5668,9 @@ var SystemServiceImpl = class {
5369
5668
  const diagnostics = await this._getDiagnostics();
5370
5669
  return {
5371
5670
  timestamp: /* @__PURE__ */ new Date(),
5372
- diagnostics: JSON.parse(JSON.stringify(diagnostics, (0, import_util12.jsonKeyReplacer)({
5373
- truncate: keys === import_services18.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
5374
- humanize: keys === import_services18.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
5671
+ diagnostics: JSON.parse(JSON.stringify(diagnostics, (0, import_util14.jsonKeyReplacer)({
5672
+ truncate: keys === import_services19.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
5673
+ humanize: keys === import_services19.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
5375
5674
  })))
5376
5675
  };
5377
5676
  }
@@ -5412,7 +5711,7 @@ function _ts_decorate8(decorators, target, key, desc) {
5412
5711
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5413
5712
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5414
5713
  }
5415
- var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
5714
+ var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
5416
5715
  var ClientServicesHost = class {
5417
5716
  constructor({
5418
5717
  config,
@@ -5426,7 +5725,7 @@ var ClientServicesHost = class {
5426
5725
  runtimeParams
5427
5726
  } = {}) {
5428
5727
  this._tracingService = import_tracing8.TRACE_PROCESSOR.createTraceSender();
5429
- this._statusUpdate = new import_async16.Event();
5728
+ this._statusUpdate = new import_async17.Event();
5430
5729
  this._opening = false;
5431
5730
  this._open = false;
5432
5731
  this._storage = storage;
@@ -5445,7 +5744,7 @@ var ClientServicesHost = class {
5445
5744
  lockKey,
5446
5745
  onAcquire: () => {
5447
5746
  if (!this._opening) {
5448
- void this.open(new import_context11.Context());
5747
+ void this.open(new import_context13.Context());
5449
5748
  }
5450
5749
  },
5451
5750
  onRelease: () => this.close()
@@ -5454,14 +5753,14 @@ var ClientServicesHost = class {
5454
5753
  this._systemService = new SystemServiceImpl({
5455
5754
  config: () => this._config,
5456
5755
  statusUpdate: this._statusUpdate,
5457
- getCurrentStatus: () => this.isOpen ? import_services15.SystemStatus.ACTIVE : import_services15.SystemStatus.INACTIVE,
5756
+ getCurrentStatus: () => this.isOpen ? import_services16.SystemStatus.ACTIVE : import_services16.SystemStatus.INACTIVE,
5458
5757
  getDiagnostics: () => {
5459
5758
  return createDiagnostics(this._serviceRegistry.services, this._serviceContext, this._config);
5460
5759
  },
5461
5760
  onUpdateStatus: async (status) => {
5462
- if (!this.isOpen && status === import_services15.SystemStatus.ACTIVE) {
5761
+ if (!this.isOpen && status === import_services16.SystemStatus.ACTIVE) {
5463
5762
  await this._resourceLock?.acquire();
5464
- } else if (this.isOpen && status === import_services15.SystemStatus.INACTIVE) {
5763
+ } else if (this.isOpen && status === import_services16.SystemStatus.INACTIVE) {
5465
5764
  await this._resourceLock?.release();
5466
5765
  }
5467
5766
  },
@@ -5500,25 +5799,25 @@ var ClientServicesHost = class {
5500
5799
  * Can only be called once.
5501
5800
  */
5502
5801
  initialize({ config, ...options }) {
5503
- (0, import_invariant15.invariant)(!this._open, "service host is open", {
5504
- F: __dxlog_file18,
5505
- L: 198,
5802
+ (0, import_invariant17.invariant)(!this._open, "service host is open", {
5803
+ F: __dxlog_file20,
5804
+ L: 189,
5506
5805
  S: this,
5507
5806
  A: [
5508
5807
  "!this._open",
5509
5808
  "'service host is open'"
5510
5809
  ]
5511
5810
  });
5512
- (0, import_log13.log)("initializing...", void 0, {
5513
- F: __dxlog_file18,
5514
- L: 199,
5811
+ (0, import_log15.log)("initializing...", void 0, {
5812
+ F: __dxlog_file20,
5813
+ L: 190,
5515
5814
  S: this,
5516
5815
  C: (f, a) => f(...a)
5517
5816
  });
5518
5817
  if (config) {
5519
- (0, import_invariant15.invariant)(!this._config, "config already set", {
5520
- F: __dxlog_file18,
5521
- L: 202,
5818
+ (0, import_invariant17.invariant)(!this._config, "config already set", {
5819
+ F: __dxlog_file20,
5820
+ L: 193,
5522
5821
  S: this,
5523
5822
  A: [
5524
5823
  "!this._config",
@@ -5531,9 +5830,9 @@ var ClientServicesHost = class {
5531
5830
  }
5532
5831
  }
5533
5832
  if (!options.signalManager) {
5534
- import_log13.log.warn("running signaling without telemetry metadata.", void 0, {
5535
- F: __dxlog_file18,
5536
- L: 210,
5833
+ import_log15.log.warn("running signaling without telemetry metadata.", void 0, {
5834
+ F: __dxlog_file20,
5835
+ L: 201,
5537
5836
  S: this,
5538
5837
  C: (f, a) => f(...a)
5539
5838
  });
@@ -5542,9 +5841,9 @@ var ClientServicesHost = class {
5542
5841
  iceServers: this._config?.get("runtime.services.ice")
5543
5842
  }), signalManager = new import_messaging.WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
5544
5843
  this._signalManager = signalManager;
5545
- (0, import_invariant15.invariant)(!this._networkManager, "network manager already set", {
5546
- F: __dxlog_file18,
5547
- L: 221,
5844
+ (0, import_invariant17.invariant)(!this._networkManager, "network manager already set", {
5845
+ F: __dxlog_file20,
5846
+ L: 212,
5548
5847
  S: this,
5549
5848
  A: [
5550
5849
  "!this._networkManager",
@@ -5556,9 +5855,9 @@ var ClientServicesHost = class {
5556
5855
  transportFactory,
5557
5856
  signalManager
5558
5857
  });
5559
- (0, import_log13.log)("initialized", void 0, {
5560
- F: __dxlog_file18,
5561
- L: 228,
5858
+ (0, import_log15.log)("initialized", void 0, {
5859
+ F: __dxlog_file20,
5860
+ L: 219,
5562
5861
  S: this,
5563
5862
  C: (f, a) => f(...a)
5564
5863
  });
@@ -5567,45 +5866,45 @@ var ClientServicesHost = class {
5567
5866
  if (this._open) {
5568
5867
  return;
5569
5868
  }
5570
- const traceId = import_keys12.PublicKey.random().toHex();
5571
- import_log13.log.trace("dxos.client-services.host.open", import_protocols14.trace.begin({
5869
+ const traceId = import_keys13.PublicKey.random().toHex();
5870
+ import_log15.log.trace("dxos.client-services.host.open", import_protocols14.trace.begin({
5572
5871
  id: traceId
5573
5872
  }), {
5574
- F: __dxlog_file18,
5575
- L: 239,
5873
+ F: __dxlog_file20,
5874
+ L: 230,
5576
5875
  S: this,
5577
5876
  C: (f, a) => f(...a)
5578
5877
  });
5579
- (0, import_invariant15.invariant)(this._config, "config not set", {
5580
- F: __dxlog_file18,
5581
- L: 241,
5878
+ (0, import_invariant17.invariant)(this._config, "config not set", {
5879
+ F: __dxlog_file20,
5880
+ L: 232,
5582
5881
  S: this,
5583
5882
  A: [
5584
5883
  "this._config",
5585
5884
  "'config not set'"
5586
5885
  ]
5587
5886
  });
5588
- (0, import_invariant15.invariant)(this._storage, "storage not set", {
5589
- F: __dxlog_file18,
5590
- L: 242,
5887
+ (0, import_invariant17.invariant)(this._storage, "storage not set", {
5888
+ F: __dxlog_file20,
5889
+ L: 233,
5591
5890
  S: this,
5592
5891
  A: [
5593
5892
  "this._storage",
5594
5893
  "'storage not set'"
5595
5894
  ]
5596
5895
  });
5597
- (0, import_invariant15.invariant)(this._signalManager, "signal manager not set", {
5598
- F: __dxlog_file18,
5599
- L: 243,
5896
+ (0, import_invariant17.invariant)(this._signalManager, "signal manager not set", {
5897
+ F: __dxlog_file20,
5898
+ L: 234,
5600
5899
  S: this,
5601
5900
  A: [
5602
5901
  "this._signalManager",
5603
5902
  "'signal manager not set'"
5604
5903
  ]
5605
5904
  });
5606
- (0, import_invariant15.invariant)(this._networkManager, "network manager not set", {
5607
- F: __dxlog_file18,
5608
- L: 244,
5905
+ (0, import_invariant17.invariant)(this._networkManager, "network manager not set", {
5906
+ F: __dxlog_file20,
5907
+ L: 235,
5609
5908
  S: this,
5610
5909
  A: [
5611
5910
  "this._networkManager",
@@ -5613,26 +5912,21 @@ var ClientServicesHost = class {
5613
5912
  ]
5614
5913
  });
5615
5914
  this._opening = true;
5616
- (0, import_log13.log)("opening...", {
5915
+ (0, import_log15.log)("opening...", {
5617
5916
  lockKey: this._resourceLock?.lockKey
5618
5917
  }, {
5619
- F: __dxlog_file18,
5620
- L: 247,
5918
+ F: __dxlog_file20,
5919
+ L: 238,
5621
5920
  S: this,
5622
5921
  C: (f, a) => f(...a)
5623
5922
  });
5923
+ await this._resourceLock?.acquire();
5624
5924
  if (!this._level) {
5625
5925
  this._level = await createLevel(this._config.get("runtime.client.storage", {}));
5626
5926
  }
5627
5927
  await this._level.open();
5628
- await this._resourceLock?.acquire();
5629
5928
  await this._loggingService.open();
5630
5929
  this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._runtimeParams);
5631
- this._queryService = new import_indexing2.QueryServiceImpl({
5632
- indexer: this._serviceContext.indexer,
5633
- automergeHost: this._serviceContext.automergeHost
5634
- });
5635
- await this._queryService.open(ctx);
5636
5930
  this._serviceRegistry.setServices({
5637
5931
  SystemService: this._systemService,
5638
5932
  IdentityService: new IdentityServiceImpl((params) => this._createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring, (profile) => this._serviceContext.broadcastProfileUpdate(profile)),
@@ -5642,8 +5936,8 @@ var ClientServicesHost = class {
5642
5936
  await this._serviceContext.initialized.wait();
5643
5937
  return this._serviceContext.dataSpaceManager;
5644
5938
  }),
5645
- DataService: new import_echo_pipeline5.DataServiceImpl(this._serviceContext.automergeHost),
5646
- QueryService: this._queryService,
5939
+ DataService: this._serviceContext.echoHost.dataService,
5940
+ QueryService: this._serviceContext.echoHost.queryService,
5647
5941
  NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager, this._serviceContext.signalManager),
5648
5942
  LoggingService: this._loggingService,
5649
5943
  TracingService: this._tracingService,
@@ -5670,19 +5964,19 @@ var ClientServicesHost = class {
5670
5964
  this._open = true;
5671
5965
  this._statusUpdate.emit();
5672
5966
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
5673
- (0, import_log13.log)("opened", {
5967
+ (0, import_log15.log)("opened", {
5674
5968
  deviceKey
5675
5969
  }, {
5676
- F: __dxlog_file18,
5677
- L: 330,
5970
+ F: __dxlog_file20,
5971
+ L: 314,
5678
5972
  S: this,
5679
5973
  C: (f, a) => f(...a)
5680
5974
  });
5681
- import_log13.log.trace("dxos.client-services.host.open", import_protocols14.trace.end({
5975
+ import_log15.log.trace("dxos.client-services.host.open", import_protocols14.trace.end({
5682
5976
  id: traceId
5683
5977
  }), {
5684
- F: __dxlog_file18,
5685
- L: 331,
5978
+ F: __dxlog_file20,
5979
+ L: 315,
5686
5980
  S: this,
5687
5981
  C: (f, a) => f(...a)
5688
5982
  });
@@ -5692,11 +5986,11 @@ var ClientServicesHost = class {
5692
5986
  return;
5693
5987
  }
5694
5988
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
5695
- (0, import_log13.log)("closing...", {
5989
+ (0, import_log15.log)("closing...", {
5696
5990
  deviceKey
5697
5991
  }, {
5698
- F: __dxlog_file18,
5699
- L: 342,
5992
+ F: __dxlog_file20,
5993
+ L: 326,
5700
5994
  S: this,
5701
5995
  C: (f, a) => f(...a)
5702
5996
  });
@@ -5706,49 +6000,48 @@ var ClientServicesHost = class {
5706
6000
  SystemService: this._systemService
5707
6001
  });
5708
6002
  await this._loggingService.close();
5709
- await this._queryService.close();
5710
6003
  await this._serviceContext.close();
5711
6004
  await this._level?.close();
5712
6005
  this._open = false;
5713
6006
  this._statusUpdate.emit();
5714
- (0, import_log13.log)("closed", {
6007
+ (0, import_log15.log)("closed", {
5715
6008
  deviceKey
5716
6009
  }, {
5717
- F: __dxlog_file18,
5718
- L: 352,
6010
+ F: __dxlog_file20,
6011
+ L: 335,
5719
6012
  S: this,
5720
6013
  C: (f, a) => f(...a)
5721
6014
  });
5722
6015
  }
5723
6016
  async reset() {
5724
- const traceId = import_keys12.PublicKey.random().toHex();
5725
- import_log13.log.trace("dxos.sdk.client-services-host.reset", import_protocols14.trace.begin({
6017
+ const traceId = import_keys13.PublicKey.random().toHex();
6018
+ import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols14.trace.begin({
5726
6019
  id: traceId
5727
6020
  }), {
5728
- F: __dxlog_file18,
5729
- L: 357,
6021
+ F: __dxlog_file20,
6022
+ L: 340,
5730
6023
  S: this,
5731
6024
  C: (f, a) => f(...a)
5732
6025
  });
5733
- (0, import_log13.log)("resetting...", void 0, {
5734
- F: __dxlog_file18,
5735
- L: 359,
6026
+ (0, import_log15.log)("resetting...", void 0, {
6027
+ F: __dxlog_file20,
6028
+ L: 342,
5736
6029
  S: this,
5737
6030
  C: (f, a) => f(...a)
5738
6031
  });
5739
6032
  await this._serviceContext?.close();
5740
6033
  await this._storage.reset();
5741
- (0, import_log13.log)("reset", void 0, {
5742
- F: __dxlog_file18,
5743
- L: 362,
6034
+ (0, import_log15.log)("reset", void 0, {
6035
+ F: __dxlog_file20,
6036
+ L: 345,
5744
6037
  S: this,
5745
6038
  C: (f, a) => f(...a)
5746
6039
  });
5747
- import_log13.log.trace("dxos.sdk.client-services-host.reset", import_protocols14.trace.end({
6040
+ import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols14.trace.end({
5748
6041
  id: traceId
5749
6042
  }), {
5750
- F: __dxlog_file18,
5751
- L: 363,
6043
+ F: __dxlog_file20,
6044
+ L: 346,
5752
6045
  S: this,
5753
6046
  C: (f, a) => f(...a)
5754
6047
  });
@@ -5759,20 +6052,20 @@ var ClientServicesHost = class {
5759
6052
  await this._serviceContext.initialized.wait();
5760
6053
  const space = await this._serviceContext.dataSpaceManager.createSpace();
5761
6054
  const automergeIndex = space.automergeSpaceState.rootUrl;
5762
- (0, import_invariant15.invariant)(automergeIndex, void 0, {
5763
- F: __dxlog_file18,
5764
- L: 375,
6055
+ (0, import_invariant17.invariant)(automergeIndex, void 0, {
6056
+ F: __dxlog_file20,
6057
+ L: 358,
5765
6058
  S: this,
5766
6059
  A: [
5767
6060
  "automergeIndex",
5768
6061
  ""
5769
6062
  ]
5770
6063
  });
5771
- const document = await this._serviceContext.automergeHost.repo.find(automergeIndex);
6064
+ const document = await this._serviceContext.echoHost.automergeRepo.find(automergeIndex);
5772
6065
  await document.whenReady();
5773
6066
  const properties = {
5774
6067
  system: {
5775
- type: (0, import_echo_pipeline5.encodeReference)((0, import_echo_schema2.getTypeReference)(import_client_protocol5.Properties))
6068
+ type: (0, import_echo_protocol.encodeReference)((0, import_echo_schema2.getTypeReference)(import_client_protocol5.Properties))
5776
6069
  },
5777
6070
  data: {
5778
6071
  [import_client_protocol5.defaultKey]: identity.identityKey.toHex()
@@ -5781,14 +6074,14 @@ var ClientServicesHost = class {
5781
6074
  keys: []
5782
6075
  }
5783
6076
  };
5784
- const propertiesId = import_keys12.PublicKey.random().toHex();
6077
+ const propertiesId = import_keys13.PublicKey.random().toHex();
5785
6078
  document.change((doc) => {
5786
- (0, import_util9.assignDeep)(doc, [
6079
+ (0, import_util11.assignDeep)(doc, [
5787
6080
  "objects",
5788
6081
  propertiesId
5789
6082
  ], properties);
5790
6083
  });
5791
- await this._serviceContext.automergeHost.repo.flush();
6084
+ await this._serviceContext.echoHost.flush();
5792
6085
  return identity;
5793
6086
  }
5794
6087
  };
@@ -5799,11 +6092,11 @@ _ts_decorate8([
5799
6092
  import_tracing8.trace.info()
5800
6093
  ], ClientServicesHost.prototype, "_open", void 0);
5801
6094
  _ts_decorate8([
5802
- import_async16.synchronized,
6095
+ import_async17.synchronized,
5803
6096
  import_tracing8.trace.span()
5804
6097
  ], ClientServicesHost.prototype, "open", null);
5805
6098
  _ts_decorate8([
5806
- import_async16.synchronized,
6099
+ import_async17.synchronized,
5807
6100
  import_tracing8.trace.span()
5808
6101
  ], ClientServicesHost.prototype, "close", null);
5809
6102
  ClientServicesHost = _ts_decorate8([
@@ -5816,7 +6109,7 @@ var DiagnosticsCollector = class {
5816
6109
  }
5817
6110
  static async collect(config = findConfigs(), services = findSystemServiceProvider(), options = {}) {
5818
6111
  const serviceDiagnostics = await services?.services?.SystemService?.getDiagnostics({
5819
- keys: options.humanize ? import_services14.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE : options.truncate ? import_services14.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE : void 0
6112
+ keys: options.humanize ? import_services15.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE : options.truncate ? import_services15.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE : void 0
5820
6113
  });
5821
6114
  const clientDiagnostics = {
5822
6115
  config,
@@ -5829,7 +6122,7 @@ var DiagnosticsCollector = class {
5829
6122
  client: clientDiagnostics,
5830
6123
  broadcast: await this.broadcastSender.broadcastDiagnosticsRequest()
5831
6124
  };
5832
- return JSON.parse(JSON.stringify(diagnostics, (0, import_util8.jsonKeyReplacer)(options)));
6125
+ return JSON.parse(JSON.stringify(diagnostics, (0, import_util10.jsonKeyReplacer)(options)));
5833
6126
  }
5834
6127
  };
5835
6128
  var findSystemServiceProvider = () => {
@@ -5839,7 +6132,7 @@ var findSystemServiceProvider = () => {
5839
6132
  };
5840
6133
  var findConfigs = () => {
5841
6134
  const configs = import_tracing7.TRACE_PROCESSOR.findByAnnotation(import_config.ConfigResource);
5842
- return configs.map((r) => r.instance.deref()).filter(import_util8.nonNullable);
6135
+ return configs.map((r) => r.instance.deref()).filter(import_util10.nonNullable);
5843
6136
  };
5844
6137
  // Annotate the CommonJS export names for ESM import in node:
5845
6138
  0 && (module.exports = {
@@ -5881,4 +6174,4 @@ var findConfigs = () => {
5881
6174
  subscribeToSpaces,
5882
6175
  subscribeToSwarmInfo
5883
6176
  });
5884
- //# sourceMappingURL=chunk-EAWN3LCD.cjs.map
6177
+ //# sourceMappingURL=chunk-DSYIRKI6.cjs.map