@dxos/client-services 0.5.0 → 0.5.1-main.0ec204c

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