@dxos/client-services 0.4.10-main.f68a1ca → 0.4.10-main.f937af6

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 (94) hide show
  1. package/dist/lib/browser/{chunk-B4JZEXRB.mjs → chunk-N2WDHCKA.mjs} +1280 -985
  2. package/dist/lib/browser/chunk-N2WDHCKA.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +15 -3
  4. package/dist/lib/browser/index.mjs.map +1 -1
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +12 -5
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/{chunk-EC2QGJ2V.cjs → chunk-KIKQMYZ7.cjs} +1108 -901
  9. package/dist/lib/node/chunk-KIKQMYZ7.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +50 -38
  11. package/dist/lib/node/index.cjs.map +1 -1
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/packlets/testing/index.cjs +16 -9
  14. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  15. package/dist/types/src/index.d.ts +1 -0
  16. package/dist/types/src/index.d.ts.map +1 -1
  17. package/dist/types/src/packlets/diagnostics/browser-diagnostics-broadcast.d.ts +5 -0
  18. package/dist/types/src/packlets/diagnostics/browser-diagnostics-broadcast.d.ts.map +1 -0
  19. package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts +5 -0
  20. package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts.map +1 -0
  21. package/dist/types/src/packlets/diagnostics/diagnostics-collector.d.ts +15 -0
  22. package/dist/types/src/packlets/diagnostics/diagnostics-collector.d.ts.map +1 -0
  23. package/dist/types/src/packlets/{services → diagnostics}/diagnostics.d.ts +1 -1
  24. package/dist/types/src/packlets/diagnostics/diagnostics.d.ts.map +1 -0
  25. package/dist/types/src/packlets/diagnostics/index.d.ts +4 -0
  26. package/dist/types/src/packlets/diagnostics/index.d.ts.map +1 -0
  27. package/dist/types/src/packlets/indexing/util.d.ts +2 -1
  28. package/dist/types/src/packlets/indexing/util.d.ts.map +1 -1
  29. package/dist/types/src/packlets/invitations/index.d.ts +1 -0
  30. package/dist/types/src/packlets/invitations/index.d.ts.map +1 -1
  31. package/dist/types/src/packlets/invitations/invitation-extension.d.ts +1 -0
  32. package/dist/types/src/packlets/invitations/invitation-extension.d.ts.map +1 -1
  33. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +4 -2
  34. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  35. package/dist/types/src/packlets/invitations/invitations-manager.d.ts +42 -0
  36. package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -0
  37. package/dist/types/src/packlets/invitations/invitations-service.d.ts +7 -23
  38. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  39. package/dist/types/src/packlets/services/index.d.ts +1 -1
  40. package/dist/types/src/packlets/services/index.d.ts.map +1 -1
  41. package/dist/types/src/packlets/services/service-context.d.ts +9 -5
  42. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  43. package/dist/types/src/packlets/services/service-host.d.ts +5 -1
  44. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  45. package/dist/types/src/packlets/services/util.d.ts +1 -0
  46. package/dist/types/src/packlets/services/util.d.ts.map +1 -1
  47. package/dist/types/src/packlets/storage/index.d.ts +1 -0
  48. package/dist/types/src/packlets/storage/index.d.ts.map +1 -1
  49. package/dist/types/src/packlets/storage/level.d.ts +4 -0
  50. package/dist/types/src/packlets/storage/level.d.ts.map +1 -0
  51. package/dist/types/src/packlets/storage/storage.d.ts.map +1 -1
  52. package/dist/types/src/packlets/storage/util.d.ts +4 -0
  53. package/dist/types/src/packlets/storage/util.d.ts.map +1 -0
  54. package/dist/types/src/packlets/system/system-service.d.ts +1 -1
  55. package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
  56. package/dist/types/src/packlets/testing/test-builder.d.ts +4 -2
  57. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  58. package/dist/types/src/version.d.ts +1 -1
  59. package/package.json +36 -34
  60. package/src/index.ts +1 -0
  61. package/src/packlets/devices/devices-service.test.ts +1 -1
  62. package/src/packlets/diagnostics/browser-diagnostics-broadcast.ts +94 -0
  63. package/src/packlets/diagnostics/diagnostics-broadcast.ts +20 -0
  64. package/src/packlets/diagnostics/diagnostics-collector.ts +65 -0
  65. package/src/packlets/{services → diagnostics}/diagnostics.ts +2 -2
  66. package/src/packlets/diagnostics/index.ts +7 -0
  67. package/src/packlets/identity/identity-service.test.ts +1 -1
  68. package/src/packlets/indexing/util.ts +11 -6
  69. package/src/packlets/invitations/device-invitation-protocol.test.ts +1 -1
  70. package/src/packlets/invitations/index.ts +1 -0
  71. package/src/packlets/invitations/invitation-extension.ts +28 -1
  72. package/src/packlets/invitations/invitations-handler.ts +74 -34
  73. package/src/packlets/invitations/invitations-manager.ts +197 -0
  74. package/src/packlets/invitations/invitations-service.ts +21 -168
  75. package/src/packlets/network/network-service.test.ts +1 -1
  76. package/src/packlets/services/automerge-host.test.ts +9 -3
  77. package/src/packlets/services/index.ts +1 -1
  78. package/src/packlets/services/service-context.test.ts +9 -6
  79. package/src/packlets/services/service-context.ts +26 -8
  80. package/src/packlets/services/service-host.ts +51 -24
  81. package/src/packlets/services/service-registry.test.ts +1 -1
  82. package/src/packlets/services/util.ts +2 -0
  83. package/src/packlets/spaces/data-space-manager.test.ts +4 -4
  84. package/src/packlets/spaces/spaces-service.test.ts +1 -1
  85. package/src/packlets/storage/index.ts +1 -0
  86. package/src/packlets/storage/level.ts +19 -0
  87. package/src/packlets/storage/storage.ts +3 -9
  88. package/src/packlets/storage/util.ts +19 -0
  89. package/src/packlets/system/system-service.ts +1 -1
  90. package/src/packlets/testing/test-builder.ts +23 -5
  91. package/src/version.ts +1 -1
  92. package/dist/lib/browser/chunk-B4JZEXRB.mjs.map +0 -7
  93. package/dist/lib/node/chunk-EC2QGJ2V.cjs.map +0 -7
  94. package/dist/types/src/packlets/services/diagnostics.d.ts.map +0 -1
@@ -26,19 +26,22 @@ 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_EC2QGJ2V_exports = {};
30
- __export(chunk_EC2QGJ2V_exports, {
29
+ var chunk_KIKQMYZ7_exports = {};
30
+ __export(chunk_KIKQMYZ7_exports, {
31
31
  ClientRpcServer: () => ClientRpcServer,
32
32
  ClientServicesHost: () => ClientServicesHost,
33
+ ClientServicesProviderResource: () => ClientServicesProviderResource,
33
34
  DataSpace: () => DataSpace,
34
35
  DataSpaceManager: () => DataSpaceManager,
35
36
  DeviceInvitationProtocol: () => DeviceInvitationProtocol,
36
37
  DevtoolsHostEvents: () => DevtoolsHostEvents,
37
38
  DevtoolsServiceImpl: () => DevtoolsServiceImpl,
39
+ DiagnosticsCollector: () => DiagnosticsCollector,
38
40
  Identity: () => Identity,
39
41
  IdentityManager: () => IdentityManager,
40
42
  IdentityServiceImpl: () => IdentityServiceImpl,
41
43
  InvitationsHandler: () => InvitationsHandler,
44
+ InvitationsManager: () => InvitationsManager,
42
45
  InvitationsServiceImpl: () => InvitationsServiceImpl,
43
46
  Lock: () => Lock,
44
47
  ServiceContext: () => ServiceContext,
@@ -46,11 +49,14 @@ __export(chunk_EC2QGJ2V_exports, {
46
49
  SpaceInvitationProtocol: () => SpaceInvitationProtocol,
47
50
  SpacesServiceImpl: () => SpacesServiceImpl,
48
51
  TrustedKeySetAuthVerifier: () => TrustedKeySetAuthVerifier,
52
+ createAdmissionKeypair: () => createAdmissionKeypair,
49
53
  createAuthProvider: () => createAuthProvider,
54
+ createCollectDiagnosticsBroadcastHandler: () => createCollectDiagnosticsBroadcastHandler,
55
+ createCollectDiagnosticsBroadcastSender: () => createCollectDiagnosticsBroadcastSender,
50
56
  createDiagnostics: () => createDiagnostics,
57
+ createLevel: () => createLevel,
51
58
  createStorageObjects: () => createStorageObjects,
52
59
  getNetworkPeers: () => getNetworkPeers,
53
- invitationExpired: () => invitationExpired,
54
60
  isLocked: () => isLocked,
55
61
  subscribeToFeedBlocks: () => subscribeToFeedBlocks,
56
62
  subscribeToFeeds: () => subscribeToFeeds,
@@ -60,7 +66,7 @@ __export(chunk_EC2QGJ2V_exports, {
60
66
  subscribeToSpaces: () => subscribeToSpaces,
61
67
  subscribeToSwarmInfo: () => subscribeToSwarmInfo
62
68
  });
63
- module.exports = __toCommonJS(chunk_EC2QGJ2V_exports);
69
+ module.exports = __toCommonJS(chunk_KIKQMYZ7_exports);
64
70
  var import_async = require("@dxos/async");
65
71
  var import_codec_protobuf = require("@dxos/codec-protobuf");
66
72
  var import_feed_store = require("@dxos/feed-store");
@@ -115,6 +121,7 @@ var import_async7 = require("@dxos/async");
115
121
  var import_client_protocol2 = require("@dxos/client-protocol");
116
122
  var import_context4 = require("@dxos/context");
117
123
  var import_credentials7 = require("@dxos/credentials");
124
+ var import_crypto = require("@dxos/crypto");
118
125
  var import_invariant5 = require("@dxos/invariant");
119
126
  var import_keys5 = require("@dxos/keys");
120
127
  var import_log4 = require("@dxos/log");
@@ -124,6 +131,7 @@ var import_services3 = require("@dxos/protocols/proto/dxos/client/services");
124
131
  var import_invitations = require("@dxos/protocols/proto/dxos/halo/invitations");
125
132
  var import_async8 = require("@dxos/async");
126
133
  var import_context5 = require("@dxos/context");
134
+ var import_crypto2 = require("@dxos/crypto");
127
135
  var import_invariant6 = require("@dxos/invariant");
128
136
  var import_keys6 = require("@dxos/keys");
129
137
  var import_log5 = require("@dxos/log");
@@ -131,134 +139,142 @@ var import_protocols5 = require("@dxos/protocols");
131
139
  var import_services4 = require("@dxos/protocols/proto/dxos/client/services");
132
140
  var import_invitations2 = require("@dxos/protocols/proto/dxos/halo/invitations");
133
141
  var import_teleport = require("@dxos/teleport");
134
- var import_async9 = require("@dxos/async");
135
142
  var import_codec_protobuf8 = require("@dxos/codec-protobuf");
136
- var import_context6 = require("@dxos/context");
137
- var import_invariant7 = require("@dxos/invariant");
138
- var import_log6 = require("@dxos/log");
139
143
  var import_services5 = require("@dxos/protocols/proto/dxos/client/services");
140
144
  var import_credentials8 = require("@dxos/credentials");
141
145
  var import_feed_store3 = require("@dxos/feed-store");
142
- var import_invariant8 = require("@dxos/invariant");
143
- var import_log7 = require("@dxos/log");
146
+ var import_invariant7 = require("@dxos/invariant");
147
+ var import_log6 = require("@dxos/log");
144
148
  var import_protocols6 = require("@dxos/protocols");
145
149
  var import_services6 = require("@dxos/protocols/proto/dxos/client/services");
150
+ var import_async9 = require("@dxos/async");
151
+ var import_echo_pipeline = require("@dxos/echo-pipeline");
152
+ var import_invariant8 = require("@dxos/invariant");
153
+ var import_log7 = require("@dxos/log");
146
154
  var import_codec_protobuf9 = require("@dxos/codec-protobuf");
147
155
  var import_debug2 = require("@dxos/debug");
148
156
  var import_rpc = require("@dxos/rpc");
149
157
  var import_tracing3 = require("@dxos/tracing");
150
- var import_codec_protobuf10 = require("@dxos/codec-protobuf");
151
- var import_credentials9 = require("@dxos/credentials");
152
- var import_invariant9 = require("@dxos/invariant");
153
- var import_protocols7 = require("@dxos/protocols");
154
- var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
155
- var import_tracing4 = require("@dxos/tracing");
156
- var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
157
158
  var import_async10 = require("@dxos/async");
158
159
  var import_client_protocol3 = require("@dxos/client-protocol");
159
- var import_context7 = require("@dxos/context");
160
+ var import_context6 = require("@dxos/context");
160
161
  var import_debug3 = require("@dxos/debug");
161
162
  var import_echo_db = require("@dxos/echo-db");
162
- var import_echo_pipeline = require("@dxos/echo-pipeline");
163
163
  var import_echo_pipeline2 = require("@dxos/echo-pipeline");
164
- var import_invariant10 = require("@dxos/invariant");
164
+ var import_echo_pipeline3 = require("@dxos/echo-pipeline");
165
+ var import_invariant9 = require("@dxos/invariant");
165
166
  var import_keys7 = require("@dxos/keys");
166
167
  var import_log8 = require("@dxos/log");
167
- var import_protocols8 = require("@dxos/protocols");
168
- var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
169
- var import_credentials10 = require("@dxos/protocols/proto/dxos/halo/credentials");
168
+ var import_protocols7 = require("@dxos/protocols");
169
+ var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
170
+ var import_credentials9 = require("@dxos/protocols/proto/dxos/halo/credentials");
170
171
  var import_timeframe2 = require("@dxos/timeframe");
171
- var import_tracing5 = require("@dxos/tracing");
172
+ var import_tracing4 = require("@dxos/tracing");
172
173
  var import_util4 = require("@dxos/util");
173
174
  var import_async11 = require("@dxos/async");
174
- var import_credentials11 = require("@dxos/credentials");
175
+ var import_credentials10 = require("@dxos/credentials");
175
176
  var import_async12 = require("@dxos/async");
176
- var import_context8 = require("@dxos/context");
177
- var import_invariant11 = require("@dxos/invariant");
177
+ var import_context7 = require("@dxos/context");
178
+ var import_invariant10 = require("@dxos/invariant");
178
179
  var import_keys8 = require("@dxos/keys");
179
180
  var import_log9 = require("@dxos/log");
180
- var import_protocols9 = require("@dxos/protocols");
181
+ var import_protocols8 = require("@dxos/protocols");
181
182
  var import_teleport2 = require("@dxos/teleport");
182
183
  var import_util5 = require("@dxos/util");
183
184
  var import_async13 = require("@dxos/async");
184
- var import_context9 = require("@dxos/context");
185
- var import_credentials12 = require("@dxos/credentials");
186
- var import_invariant12 = require("@dxos/invariant");
185
+ var import_context8 = require("@dxos/context");
186
+ var import_credentials11 = require("@dxos/credentials");
187
+ var import_invariant11 = require("@dxos/invariant");
187
188
  var import_keys9 = require("@dxos/keys");
188
189
  var import_log10 = require("@dxos/log");
189
- var import_protocols10 = require("@dxos/protocols");
190
- var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
190
+ var import_protocols9 = require("@dxos/protocols");
191
+ var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
191
192
  var import_teleport_extension_gossip2 = require("@dxos/teleport-extension-gossip");
192
193
  var import_util6 = require("@dxos/util");
193
- var import_credentials13 = require("@dxos/credentials");
194
+ var import_credentials12 = require("@dxos/credentials");
194
195
  var import_debug4 = require("@dxos/debug");
195
- var import_credentials14 = require("@dxos/protocols/proto/dxos/halo/credentials");
196
+ var import_credentials13 = require("@dxos/protocols/proto/dxos/halo/credentials");
196
197
  var import_timeframe3 = require("@dxos/timeframe");
197
198
  var import_async14 = require("@dxos/async");
198
- var import_codec_protobuf11 = require("@dxos/codec-protobuf");
199
+ var import_codec_protobuf10 = require("@dxos/codec-protobuf");
199
200
  var import_debug5 = require("@dxos/debug");
200
- var import_invariant13 = require("@dxos/invariant");
201
+ var import_invariant12 = require("@dxos/invariant");
201
202
  var import_log11 = require("@dxos/log");
202
- var import_protocols11 = require("@dxos/protocols");
203
- var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
203
+ var import_protocols10 = require("@dxos/protocols");
204
+ var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
204
205
  var import_async15 = require("@dxos/async");
205
- var import_context10 = require("@dxos/context");
206
- var import_credentials15 = require("@dxos/credentials");
206
+ var import_context9 = require("@dxos/context");
207
+ var import_credentials14 = require("@dxos/credentials");
207
208
  var import_debug6 = require("@dxos/debug");
208
- var import_echo_pipeline3 = require("@dxos/echo-pipeline");
209
+ var import_echo_pipeline4 = require("@dxos/echo-pipeline");
209
210
  var import_feed_store4 = require("@dxos/feed-store");
210
211
  var import_indexing = require("@dxos/indexing");
211
- var import_invariant14 = require("@dxos/invariant");
212
+ var import_invariant13 = require("@dxos/invariant");
212
213
  var import_keyring = require("@dxos/keyring");
213
214
  var import_keys10 = require("@dxos/keys");
214
215
  var import_log12 = require("@dxos/log");
215
- var import_protocols12 = require("@dxos/protocols");
216
- var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
216
+ var import_protocols11 = require("@dxos/protocols");
217
+ var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
217
218
  var import_teleport_extension_object_sync = require("@dxos/teleport-extension-object-sync");
218
- var import_tracing6 = require("@dxos/tracing");
219
+ var import_tracing5 = require("@dxos/tracing");
219
220
  var import_util7 = require("@dxos/util");
220
221
  var import_automerge = require("@dxos/automerge/automerge");
221
- var import_debug7 = require("@dxos/debug");
222
+ var import_protocols12 = require("@dxos/protocols");
223
+ var import_codec_protobuf11 = require("@dxos/codec-protobuf");
224
+ var import_credentials15 = require("@dxos/credentials");
225
+ var import_invariant14 = require("@dxos/invariant");
222
226
  var import_protocols13 = require("@dxos/protocols");
223
- var import_invariant15 = require("@dxos/invariant");
224
- var import_lock_file = require("@dxos/lock-file");
225
- var import_log13 = require("@dxos/log");
226
- var import_client_protocol4 = require("@dxos/client-protocol");
227
- var import_protocols14 = require("@dxos/protocols");
228
- var import_config = require("@dxos/protocols/proto/dxos/config");
229
- var import_random_access_storage = require("@dxos/random-access-storage");
227
+ var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
228
+ var import_tracing6 = require("@dxos/tracing");
229
+ var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
230
+ var import_config = require("@dxos/config");
231
+ var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
232
+ var import_tracing7 = require("@dxos/tracing");
230
233
  var import_util8 = require("@dxos/util");
231
234
  var import_async16 = require("@dxos/async");
232
- var import_client_protocol5 = require("@dxos/client-protocol");
233
- var import_context11 = require("@dxos/context");
234
- var import_echo_pipeline4 = require("@dxos/echo-pipeline");
235
- var E = __toESM(require("@dxos/echo-schema"));
235
+ var import_client_protocol4 = require("@dxos/client-protocol");
236
+ var import_context10 = require("@dxos/context");
237
+ var import_echo_pipeline5 = require("@dxos/echo-pipeline");
236
238
  var import_echo_schema = require("@dxos/echo-schema");
237
239
  var import_indexing2 = require("@dxos/indexing");
238
- var import_invariant16 = require("@dxos/invariant");
240
+ var import_invariant15 = require("@dxos/invariant");
239
241
  var import_keys11 = require("@dxos/keys");
240
- var import_log14 = require("@dxos/log");
242
+ var import_log13 = require("@dxos/log");
241
243
  var import_messaging = require("@dxos/messaging");
242
244
  var import_network_manager2 = require("@dxos/network-manager");
243
- var import_protocols15 = require("@dxos/protocols");
244
- var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
245
- var import_tracing7 = require("@dxos/tracing");
245
+ var import_protocols14 = require("@dxos/protocols");
246
+ var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
247
+ var import_tracing8 = require("@dxos/tracing");
246
248
  var import_util9 = require("@dxos/util");
247
249
  var import_websocket_rpc = require("@dxos/websocket-rpc");
248
250
  var import_async17 = require("@dxos/async");
249
251
  var import_codec_protobuf12 = require("@dxos/codec-protobuf");
252
+ var import_invariant16 = require("@dxos/invariant");
253
+ var import_services15 = require("@dxos/protocols/proto/dxos/client/services");
250
254
  var import_invariant17 = require("@dxos/invariant");
251
- var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
255
+ var import_lock_file = require("@dxos/lock-file");
256
+ var import_log14 = require("@dxos/log");
252
257
  var import_async18 = require("@dxos/async");
253
258
  var import_codec_protobuf13 = require("@dxos/codec-protobuf");
254
259
  var import_keys12 = require("@dxos/keys");
255
260
  var import_log15 = require("@dxos/log");
256
- var import_services15 = require("@dxos/protocols/proto/dxos/client/services");
261
+ var import_services16 = require("@dxos/protocols/proto/dxos/client/services");
257
262
  var import_util10 = require("@dxos/util");
258
263
  var import_codec_protobuf14 = require("@dxos/codec-protobuf");
259
- var import_codec_protobuf15 = require("@dxos/codec-protobuf");
260
- var import_services16 = require("@dxos/protocols/proto/dxos/client/services");
264
+ var import_protocols15 = require("@dxos/protocols");
265
+ var import_config2 = require("@dxos/protocols/proto/dxos/config");
266
+ var import_random_access_storage = require("@dxos/random-access-storage");
267
+ var import_client_protocol5 = require("@dxos/client-protocol");
268
+ var import_config3 = require("@dxos/protocols/proto/dxos/config");
261
269
  var import_util11 = require("@dxos/util");
270
+ var import_level = require("level");
271
+ var import_node_path = __toESM(require("node:path"));
272
+ var import_keys13 = require("@dxos/keys");
273
+ var import_codec_protobuf15 = require("@dxos/codec-protobuf");
274
+ var import_services17 = require("@dxos/protocols/proto/dxos/client/services");
275
+ var import_util12 = require("@dxos/util");
276
+ var import_keys14 = require("@dxos/keys");
277
+ var import_util13 = require("@dxos/util");
262
278
  var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
263
279
  return new import_codec_protobuf.Stream(({ next }) => {
264
280
  const subscriptions = new import_async.EventSubscriptions();
@@ -1471,6 +1487,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1471
1487
  this._callbacks = _callbacks;
1472
1488
  this._ctx = new import_context5.Context();
1473
1489
  this._remoteOptionsTrigger = new import_async8.Trigger();
1490
+ this._challenge = void 0;
1474
1491
  this.invitation = void 0;
1475
1492
  this.guestProfile = void 0;
1476
1493
  this.authenticationPassed = false;
@@ -1485,7 +1502,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1485
1502
  options: async (options) => {
1486
1503
  (0, import_invariant6.invariant)(!this._remoteOptions, "Remote options already set.", {
1487
1504
  F: __dxlog_file6,
1488
- L: 87,
1505
+ L: 90,
1489
1506
  S: this,
1490
1507
  A: [
1491
1508
  "!this._remoteOptions",
@@ -1502,7 +1519,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1502
1519
  id: traceId
1503
1520
  }), {
1504
1521
  F: __dxlog_file6,
1505
- L: 96,
1522
+ L: 99,
1506
1523
  S: this,
1507
1524
  C: (f, a) => f(...a)
1508
1525
  });
@@ -1512,7 +1529,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1512
1529
  invitationId
1513
1530
  }, {
1514
1531
  F: __dxlog_file6,
1515
- L: 100,
1532
+ L: 103,
1516
1533
  S: this,
1517
1534
  C: (f, a) => f(...a)
1518
1535
  });
@@ -1526,7 +1543,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1526
1543
  guestProfile: profile
1527
1544
  }, {
1528
1545
  F: __dxlog_file6,
1529
- L: 109,
1546
+ L: 112,
1530
1547
  S: this,
1531
1548
  C: (f, a) => f(...a)
1532
1549
  });
@@ -1535,25 +1552,27 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1535
1552
  ...this.invitation,
1536
1553
  state: import_services4.Invitation.State.READY_FOR_AUTHENTICATION
1537
1554
  });
1555
+ this._challenge = this.invitation.authMethod === import_services4.Invitation.AuthMethod.KNOWN_PUBLIC_KEY ? (0, import_crypto2.randomBytes)(32) : void 0;
1538
1556
  import_log5.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols5.trace.end({
1539
1557
  id: traceId
1540
1558
  }), {
1541
1559
  F: __dxlog_file6,
1542
- L: 116,
1560
+ L: 122,
1543
1561
  S: this,
1544
1562
  C: (f, a) => f(...a)
1545
1563
  });
1546
1564
  return {
1547
- authMethod: this.invitation.authMethod
1565
+ authMethod: this.invitation.authMethod,
1566
+ challenge: this._challenge
1548
1567
  };
1549
1568
  },
1550
- authenticate: async ({ authCode: code }) => {
1569
+ authenticate: async ({ authCode: code, signedChallenge }) => {
1551
1570
  const traceId = import_keys6.PublicKey.random().toHex();
1552
1571
  import_log5.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols5.trace.begin({
1553
1572
  id: traceId
1554
1573
  }), {
1555
1574
  F: __dxlog_file6,
1556
- L: 124,
1575
+ L: 131,
1557
1576
  S: this,
1558
1577
  C: (f, a) => f(...a)
1559
1578
  });
@@ -1561,14 +1580,14 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1561
1580
  authCode: code
1562
1581
  }, {
1563
1582
  F: __dxlog_file6,
1564
- L: 125,
1583
+ L: 132,
1565
1584
  S: this,
1566
1585
  C: (f, a) => f(...a)
1567
1586
  });
1568
1587
  let status = import_invitations2.AuthenticationResponse.Status.OK;
1569
1588
  (0, import_invariant6.invariant)(this.invitation, "Invitation is not set.", {
1570
1589
  F: __dxlog_file6,
1571
- L: 128,
1590
+ L: 135,
1572
1591
  S: this,
1573
1592
  A: [
1574
1593
  "this.invitation",
@@ -1579,7 +1598,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1579
1598
  case import_services4.Invitation.AuthMethod.NONE: {
1580
1599
  (0, import_log5.log)("authentication not required", void 0, {
1581
1600
  F: __dxlog_file6,
1582
- L: 131,
1601
+ L: 138,
1583
1602
  S: this,
1584
1603
  C: (f, a) => f(...a)
1585
1604
  });
@@ -1599,12 +1618,25 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1599
1618
  }
1600
1619
  break;
1601
1620
  }
1621
+ case import_services4.Invitation.AuthMethod.KNOWN_PUBLIC_KEY: {
1622
+ if (!this.invitation.guestKeypair) {
1623
+ status = import_invitations2.AuthenticationResponse.Status.INTERNAL_ERROR;
1624
+ break;
1625
+ }
1626
+ const isSignatureValid = this._challenge && (0, import_crypto2.verify)(this._challenge, Buffer.from(signedChallenge ?? []), this.invitation.guestKeypair.publicKey.asBuffer());
1627
+ if (isSignatureValid) {
1628
+ this.authenticationPassed = true;
1629
+ } else {
1630
+ status = import_invitations2.AuthenticationResponse.Status.INVALID_SIGNATURE;
1631
+ }
1632
+ break;
1633
+ }
1602
1634
  default: {
1603
1635
  import_log5.log.error("invalid authentication method", {
1604
1636
  authMethod: this.invitation.authMethod
1605
1637
  }, {
1606
1638
  F: __dxlog_file6,
1607
- L: 149,
1639
+ L: 176,
1608
1640
  S: this,
1609
1641
  C: (f, a) => f(...a)
1610
1642
  });
@@ -1619,7 +1651,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1619
1651
  }
1620
1652
  }), {
1621
1653
  F: __dxlog_file6,
1622
- L: 155,
1654
+ L: 182,
1623
1655
  S: this,
1624
1656
  C: (f, a) => f(...a)
1625
1657
  });
@@ -1633,14 +1665,14 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1633
1665
  id: traceId
1634
1666
  }), {
1635
1667
  F: __dxlog_file6,
1636
- L: 161,
1668
+ L: 188,
1637
1669
  S: this,
1638
1670
  C: (f, a) => f(...a)
1639
1671
  });
1640
1672
  try {
1641
1673
  (0, import_invariant6.invariant)(this.invitation, "Invitation is not set.", {
1642
1674
  F: __dxlog_file6,
1643
- L: 164,
1675
+ L: 191,
1644
1676
  S: this,
1645
1677
  A: [
1646
1678
  "this.invitation",
@@ -1655,7 +1687,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1655
1687
  id: traceId
1656
1688
  }), {
1657
1689
  F: __dxlog_file6,
1658
- L: 172,
1690
+ L: 199,
1659
1691
  S: this,
1660
1692
  C: (f, a) => f(...a)
1661
1693
  });
@@ -1712,7 +1744,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1712
1744
  options: async (options) => {
1713
1745
  (0, import_invariant6.invariant)(!this._remoteOptions, "Remote options already set.", {
1714
1746
  F: __dxlog_file6,
1715
- L: 239,
1747
+ L: 266,
1716
1748
  S: this,
1717
1749
  A: [
1718
1750
  "!this._remoteOptions",
@@ -1739,7 +1771,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1739
1771
  try {
1740
1772
  (0, import_log5.log)("begin options", void 0, {
1741
1773
  F: __dxlog_file6,
1742
- L: 260,
1774
+ L: 287,
1743
1775
  S: this,
1744
1776
  C: (f, a) => f(...a)
1745
1777
  });
@@ -1751,7 +1783,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1751
1783
  }));
1752
1784
  (0, import_log5.log)("end options", void 0, {
1753
1785
  F: __dxlog_file6,
1754
- L: 263,
1786
+ L: 290,
1755
1787
  S: this,
1756
1788
  C: (f, a) => f(...a)
1757
1789
  });
@@ -1765,7 +1797,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1765
1797
  } catch (err) {
1766
1798
  (0, import_log5.log)("openError", err, {
1767
1799
  F: __dxlog_file6,
1768
- L: 273,
1800
+ L: 300,
1769
1801
  S: this,
1770
1802
  C: (f, a) => f(...a)
1771
1803
  });
@@ -1775,7 +1807,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1775
1807
  async onClose() {
1776
1808
  (0, import_log5.log)("onClose", void 0, {
1777
1809
  F: __dxlog_file6,
1778
- L: 279,
1810
+ L: 306,
1779
1811
  S: this,
1780
1812
  C: (f, a) => f(...a)
1781
1813
  });
@@ -1792,11 +1824,11 @@ var InvitationsHandler = class {
1792
1824
  this._networkManager = _networkManager;
1793
1825
  }
1794
1826
  createInvitation(protocol, options) {
1795
- const { invitationId = import_keys5.PublicKey.random().toHex(), type = import_services3.Invitation.Type.INTERACTIVE, authMethod = import_services3.Invitation.AuthMethod.SHARED_SECRET, state = import_services3.Invitation.State.INIT, timeout = import_client_protocol2.INVITATION_TIMEOUT, swarmKey = import_keys5.PublicKey.random(), persistent = true, created = /* @__PURE__ */ new Date(), lifetime = 86400 } = options ?? {};
1827
+ const { invitationId = import_keys5.PublicKey.random().toHex(), type = import_services3.Invitation.Type.INTERACTIVE, authMethod = import_services3.Invitation.AuthMethod.SHARED_SECRET, state = import_services3.Invitation.State.INIT, timeout = import_client_protocol2.INVITATION_TIMEOUT, swarmKey = import_keys5.PublicKey.random(), persistent = options?.authMethod !== import_services3.Invitation.AuthMethod.KNOWN_PUBLIC_KEY, created = /* @__PURE__ */ new Date(), guestKeypair = void 0, lifetime = 86400, multiUse = false } = options ?? {};
1796
1828
  const authCode = options?.authCode ?? (authMethod === import_services3.Invitation.AuthMethod.SHARED_SECRET ? (0, import_credentials7.generatePasscode)(import_client_protocol2.AUTHENTICATION_CODE_LENGTH) : void 0);
1797
1829
  (0, import_invariant5.invariant)(protocol, void 0, {
1798
1830
  F: __dxlog_file7,
1799
- L: 84,
1831
+ L: 87,
1800
1832
  S: this,
1801
1833
  A: [
1802
1834
  "protocol",
@@ -1811,9 +1843,11 @@ var InvitationsHandler = class {
1811
1843
  swarmKey,
1812
1844
  authCode,
1813
1845
  timeout,
1814
- persistent,
1846
+ persistent: persistent && type !== import_services3.Invitation.Type.DELEGATED,
1847
+ guestKeypair: guestKeypair ?? (authMethod === import_services3.Invitation.AuthMethod.KNOWN_PUBLIC_KEY ? createAdmissionKeypair() : void 0),
1815
1848
  created,
1816
1849
  lifetime,
1850
+ multiUse,
1817
1851
  ...protocol.getInvitationContext()
1818
1852
  };
1819
1853
  const stream = new import_async7.PushStream();
@@ -1828,7 +1862,7 @@ var InvitationsHandler = class {
1828
1862
  ...protocol.toJSON()
1829
1863
  }, {
1830
1864
  F: __dxlog_file7,
1831
- L: 109,
1865
+ L: 115,
1832
1866
  S: this,
1833
1867
  C: (f, a) => f(...a)
1834
1868
  });
@@ -1853,7 +1887,7 @@ var InvitationsHandler = class {
1853
1887
  const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
1854
1888
  (0, import_invariant5.invariant)(deviceKey, void 0, {
1855
1889
  F: __dxlog_file7,
1856
- L: 130,
1890
+ L: 136,
1857
1891
  S: this,
1858
1892
  A: [
1859
1893
  "deviceKey",
@@ -1876,7 +1910,7 @@ var InvitationsHandler = class {
1876
1910
  id: traceId
1877
1911
  }), {
1878
1912
  F: __dxlog_file7,
1879
- L: 148,
1913
+ L: 154,
1880
1914
  S: this,
1881
1915
  C: (f, a) => f(...a)
1882
1916
  });
@@ -1884,7 +1918,7 @@ var InvitationsHandler = class {
1884
1918
  ...protocol.toJSON()
1885
1919
  }, {
1886
1920
  F: __dxlog_file7,
1887
- L: 149,
1921
+ L: 155,
1888
1922
  S: this,
1889
1923
  C: (f, a) => f(...a)
1890
1924
  });
@@ -1900,7 +1934,7 @@ var InvitationsHandler = class {
1900
1934
  ...protocol.toJSON()
1901
1935
  }, {
1902
1936
  F: __dxlog_file7,
1903
- L: 152,
1937
+ L: 158,
1904
1938
  S: this,
1905
1939
  C: (f, a) => f(...a)
1906
1940
  });
@@ -1912,7 +1946,7 @@ var InvitationsHandler = class {
1912
1946
  id: traceId
1913
1947
  }), {
1914
1948
  F: __dxlog_file7,
1915
- L: 154,
1949
+ L: 160,
1916
1950
  S: this,
1917
1951
  C: (f, a) => f(...a)
1918
1952
  });
@@ -1922,7 +1956,7 @@ var InvitationsHandler = class {
1922
1956
  ...protocol.toJSON()
1923
1957
  }, {
1924
1958
  F: __dxlog_file7,
1925
- L: 157,
1959
+ L: 163,
1926
1960
  S: this,
1927
1961
  C: (f, a) => f(...a)
1928
1962
  });
@@ -1933,7 +1967,7 @@ var InvitationsHandler = class {
1933
1967
  } else {
1934
1968
  import_log4.log.error("failed", err, {
1935
1969
  F: __dxlog_file7,
1936
- L: 160,
1970
+ L: 166,
1937
1971
  S: this,
1938
1972
  C: (f, a) => f(...a)
1939
1973
  });
@@ -1944,12 +1978,12 @@ var InvitationsHandler = class {
1944
1978
  error: err
1945
1979
  }), {
1946
1980
  F: __dxlog_file7,
1947
- L: 163,
1981
+ L: 169,
1948
1982
  S: this,
1949
1983
  C: (f, a) => f(...a)
1950
1984
  });
1951
1985
  } finally {
1952
- if (type !== import_services3.Invitation.Type.MULTIUSE) {
1986
+ if (!multiUse) {
1953
1987
  await swarmConnection.close();
1954
1988
  await ctx.dispose();
1955
1989
  }
@@ -1965,7 +1999,7 @@ var InvitationsHandler = class {
1965
1999
  ...protocol.toJSON()
1966
2000
  }, {
1967
2001
  F: __dxlog_file7,
1968
- L: 178,
2002
+ L: 184,
1969
2003
  S: this,
1970
2004
  C: (f, a) => f(...a)
1971
2005
  });
@@ -1976,7 +2010,7 @@ var InvitationsHandler = class {
1976
2010
  } else {
1977
2011
  import_log4.log.error("failed", err, {
1978
2012
  F: __dxlog_file7,
1979
- L: 181,
2013
+ L: 187,
1980
2014
  S: this,
1981
2015
  C: (f, a) => f(...a)
1982
2016
  });
@@ -1986,11 +2020,11 @@ var InvitationsHandler = class {
1986
2020
  });
1987
2021
  return extension;
1988
2022
  };
1989
- if (invitation.lifetime && invitation.created && invitation.lifetime !== 0) {
2023
+ if (invitation.lifetime && invitation.created) {
1990
2024
  if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
1991
2025
  import_log4.log.warn("invitation has already expired", void 0, {
1992
2026
  F: __dxlog_file7,
1993
- L: 192,
2027
+ L: 198,
1994
2028
  S: this,
1995
2029
  C: (f, a) => f(...a)
1996
2030
  });
@@ -2041,7 +2075,7 @@ var InvitationsHandler = class {
2041
2075
  const { timeout = import_client_protocol2.INVITATION_TIMEOUT } = invitation;
2042
2076
  (0, import_invariant5.invariant)(protocol, void 0, {
2043
2077
  F: __dxlog_file7,
2044
- L: 246,
2078
+ L: 252,
2045
2079
  S: this,
2046
2080
  A: [
2047
2081
  "protocol",
@@ -2051,7 +2085,7 @@ var InvitationsHandler = class {
2051
2085
  if (deviceProfile) {
2052
2086
  (0, import_invariant5.invariant)(invitation.kind === import_services3.Invitation.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
2053
2087
  F: __dxlog_file7,
2054
- L: 250,
2088
+ L: 255,
2055
2089
  S: this,
2056
2090
  A: [
2057
2091
  "invitation.kind === Invitation.Kind.DEVICE",
@@ -2066,7 +2100,7 @@ var InvitationsHandler = class {
2066
2100
  const setState = (newData) => {
2067
2101
  (0, import_invariant5.invariant)(newData.state !== void 0, void 0, {
2068
2102
  F: __dxlog_file7,
2069
- L: 261,
2103
+ L: 266,
2070
2104
  S: this,
2071
2105
  A: [
2072
2106
  "newData.state !== undefined",
@@ -2086,7 +2120,7 @@ var InvitationsHandler = class {
2086
2120
  ...protocol.toJSON()
2087
2121
  }, {
2088
2122
  F: __dxlog_file7,
2089
- L: 269,
2123
+ L: 274,
2090
2124
  S: this,
2091
2125
  C: (f, a) => f(...a)
2092
2126
  });
@@ -2096,7 +2130,7 @@ var InvitationsHandler = class {
2096
2130
  } else {
2097
2131
  import_log4.log.warn("auth failed", err, {
2098
2132
  F: __dxlog_file7,
2099
- L: 272,
2133
+ L: 277,
2100
2134
  S: this,
2101
2135
  C: (f, a) => f(...a)
2102
2136
  });
@@ -2110,7 +2144,7 @@ var InvitationsHandler = class {
2110
2144
  ...protocol.toJSON()
2111
2145
  }, {
2112
2146
  F: __dxlog_file7,
2113
- L: 280,
2147
+ L: 285,
2114
2148
  S: this,
2115
2149
  C: (f, a) => f(...a)
2116
2150
  });
@@ -2125,7 +2159,7 @@ var InvitationsHandler = class {
2125
2159
  currentState
2126
2160
  }, {
2127
2161
  F: __dxlog_file7,
2128
- L: 290,
2162
+ L: 295,
2129
2163
  S: this,
2130
2164
  C: (f, a) => f(...a)
2131
2165
  });
@@ -2140,7 +2174,7 @@ var InvitationsHandler = class {
2140
2174
  id: traceId
2141
2175
  }), {
2142
2176
  F: __dxlog_file7,
2143
- L: 299,
2177
+ L: 304,
2144
2178
  S: this,
2145
2179
  C: (f, a) => f(...a)
2146
2180
  });
@@ -2152,7 +2186,7 @@ var InvitationsHandler = class {
2152
2186
  ...protocol.toJSON()
2153
2187
  }, {
2154
2188
  F: __dxlog_file7,
2155
- L: 307,
2189
+ L: 312,
2156
2190
  S: this,
2157
2191
  C: (f, a) => f(...a)
2158
2192
  });
@@ -2163,7 +2197,7 @@ var InvitationsHandler = class {
2163
2197
  ...protocol.toJSON()
2164
2198
  }, {
2165
2199
  F: __dxlog_file7,
2166
- L: 311,
2200
+ L: 316,
2167
2201
  S: this,
2168
2202
  C: (f, a) => f(...a)
2169
2203
  });
@@ -2173,62 +2207,28 @@ var InvitationsHandler = class {
2173
2207
  response: introductionResponse
2174
2208
  }, {
2175
2209
  F: __dxlog_file7,
2176
- L: 315,
2210
+ L: 320,
2177
2211
  S: this,
2178
2212
  C: (f, a) => f(...a)
2179
2213
  });
2180
2214
  invitation.authMethod = introductionResponse.authMethod;
2181
2215
  if (isAuthenticationRequired(invitation)) {
2182
- for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2183
- (0, import_log4.log)("guest waiting for authentication code...", void 0, {
2184
- F: __dxlog_file7,
2185
- L: 321,
2186
- S: this,
2187
- C: (f, a) => f(...a)
2188
- });
2189
- setState({
2190
- state: import_services3.Invitation.State.READY_FOR_AUTHENTICATION
2191
- });
2192
- const authCode = await authenticated.wait({
2193
- timeout
2194
- });
2195
- (0, import_log4.log)("sending authentication request", void 0, {
2196
- F: __dxlog_file7,
2197
- L: 325,
2198
- S: this,
2199
- C: (f, a) => f(...a)
2200
- });
2201
- setState({
2202
- state: import_services3.Invitation.State.AUTHENTICATING
2203
- });
2204
- const response = await extension.rpc.InvitationHostService.authenticate({
2205
- authCode
2206
- });
2207
- if (response.status === void 0 || response.status === import_invitations.AuthenticationResponse.Status.OK) {
2216
+ switch (invitation.authMethod) {
2217
+ case import_services3.Invitation.AuthMethod.SHARED_SECRET:
2218
+ await this._handleGuestOtpAuth(extension, setState, authenticated, {
2219
+ timeout
2220
+ });
2221
+ break;
2222
+ case import_services3.Invitation.AuthMethod.KNOWN_PUBLIC_KEY:
2223
+ await this._handleGuestKpkAuth(extension, setState, invitation, introductionResponse);
2208
2224
  break;
2209
- }
2210
- if (response.status === import_invitations.AuthenticationResponse.Status.INVALID_OTP) {
2211
- if (attempt === MAX_OTP_ATTEMPTS) {
2212
- throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
2213
- } else {
2214
- (0, import_log4.log)("retrying invalid code", {
2215
- attempt
2216
- }, {
2217
- F: __dxlog_file7,
2218
- L: 336,
2219
- S: this,
2220
- C: (f, a) => f(...a)
2221
- });
2222
- authenticated.reset();
2223
- }
2224
- }
2225
2225
  }
2226
2226
  }
2227
2227
  (0, import_log4.log)("request admission", {
2228
2228
  ...protocol.toJSON()
2229
2229
  }, {
2230
2230
  F: __dxlog_file7,
2231
- L: 344,
2231
+ L: 336,
2232
2232
  S: this,
2233
2233
  C: (f, a) => f(...a)
2234
2234
  });
@@ -2240,7 +2240,7 @@ var InvitationsHandler = class {
2240
2240
  ...protocol.toJSON()
2241
2241
  }, {
2242
2242
  F: __dxlog_file7,
2243
- L: 355,
2243
+ L: 347,
2244
2244
  S: this,
2245
2245
  C: (f, a) => f(...a)
2246
2246
  });
@@ -2253,7 +2253,7 @@ var InvitationsHandler = class {
2253
2253
  id: traceId
2254
2254
  }), {
2255
2255
  F: __dxlog_file7,
2256
- L: 357,
2256
+ L: 349,
2257
2257
  S: this,
2258
2258
  C: (f, a) => f(...a)
2259
2259
  });
@@ -2263,7 +2263,7 @@ var InvitationsHandler = class {
2263
2263
  ...protocol.toJSON()
2264
2264
  }, {
2265
2265
  F: __dxlog_file7,
2266
- L: 360,
2266
+ L: 352,
2267
2267
  S: this,
2268
2268
  C: (f, a) => f(...a)
2269
2269
  });
@@ -2273,7 +2273,7 @@ var InvitationsHandler = class {
2273
2273
  } else {
2274
2274
  (0, import_log4.log)("auth failed", err, {
2275
2275
  F: __dxlog_file7,
2276
- L: 363,
2276
+ L: 355,
2277
2277
  S: this,
2278
2278
  C: (f, a) => f(...a)
2279
2279
  });
@@ -2284,7 +2284,7 @@ var InvitationsHandler = class {
2284
2284
  error: err
2285
2285
  }), {
2286
2286
  F: __dxlog_file7,
2287
- L: 366,
2287
+ L: 358,
2288
2288
  S: this,
2289
2289
  C: (f, a) => f(...a)
2290
2290
  });
@@ -2302,7 +2302,7 @@ var InvitationsHandler = class {
2302
2302
  ...protocol.toJSON()
2303
2303
  }, {
2304
2304
  F: __dxlog_file7,
2305
- L: 377,
2305
+ L: 369,
2306
2306
  S: this,
2307
2307
  C: (f, a) => f(...a)
2308
2308
  });
@@ -2312,7 +2312,7 @@ var InvitationsHandler = class {
2312
2312
  } else {
2313
2313
  (0, import_log4.log)("auth failed", err, {
2314
2314
  F: __dxlog_file7,
2315
- L: 380,
2315
+ L: 372,
2316
2316
  S: this,
2317
2317
  C: (f, a) => f(...a)
2318
2318
  });
@@ -2329,7 +2329,7 @@ var InvitationsHandler = class {
2329
2329
  } else {
2330
2330
  (0, import_invariant5.invariant)(invitation.swarmKey, void 0, {
2331
2331
  F: __dxlog_file7,
2332
- L: 394,
2332
+ L: 386,
2333
2333
  S: this,
2334
2334
  A: [
2335
2335
  "invitation.swarmKey",
@@ -2367,198 +2367,111 @@ var InvitationsHandler = class {
2367
2367
  });
2368
2368
  return observable;
2369
2369
  }
2370
+ async _handleGuestOtpAuth(extension, setState, authenticated, options) {
2371
+ for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2372
+ (0, import_log4.log)("guest waiting for authentication code...", void 0, {
2373
+ F: __dxlog_file7,
2374
+ L: 426,
2375
+ S: this,
2376
+ C: (f, a) => f(...a)
2377
+ });
2378
+ setState({
2379
+ state: import_services3.Invitation.State.READY_FOR_AUTHENTICATION
2380
+ });
2381
+ const authCode = await authenticated.wait(options);
2382
+ (0, import_log4.log)("sending authentication request", void 0, {
2383
+ F: __dxlog_file7,
2384
+ L: 430,
2385
+ S: this,
2386
+ C: (f, a) => f(...a)
2387
+ });
2388
+ setState({
2389
+ state: import_services3.Invitation.State.AUTHENTICATING
2390
+ });
2391
+ const response = await extension.rpc.InvitationHostService.authenticate({
2392
+ authCode
2393
+ });
2394
+ if (response.status === void 0 || response.status === import_invitations.AuthenticationResponse.Status.OK) {
2395
+ break;
2396
+ }
2397
+ if (response.status === import_invitations.AuthenticationResponse.Status.INVALID_OTP) {
2398
+ if (attempt === MAX_OTP_ATTEMPTS) {
2399
+ throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
2400
+ } else {
2401
+ (0, import_log4.log)("retrying invalid code", {
2402
+ attempt
2403
+ }, {
2404
+ F: __dxlog_file7,
2405
+ L: 441,
2406
+ S: this,
2407
+ C: (f, a) => f(...a)
2408
+ });
2409
+ authenticated.reset();
2410
+ }
2411
+ }
2412
+ }
2413
+ }
2414
+ async _handleGuestKpkAuth(extension, setState, invitation, introductionResponse) {
2415
+ if (invitation.guestKeypair?.privateKey == null) {
2416
+ throw new Error("keypair missing in the invitation");
2417
+ }
2418
+ if (introductionResponse.challenge == null) {
2419
+ throw new Error("challenge missing in the introduction");
2420
+ }
2421
+ (0, import_log4.log)("sending authentication request", void 0, {
2422
+ F: __dxlog_file7,
2423
+ L: 460,
2424
+ S: this,
2425
+ C: (f, a) => f(...a)
2426
+ });
2427
+ setState({
2428
+ state: import_services3.Invitation.State.AUTHENTICATING
2429
+ });
2430
+ const signature = (0, import_crypto.sign)(Buffer.from(introductionResponse.challenge), invitation.guestKeypair.privateKey);
2431
+ const response = await extension.rpc.InvitationHostService.authenticate({
2432
+ signedChallenge: signature
2433
+ });
2434
+ if (response.status !== import_invitations.AuthenticationResponse.Status.OK) {
2435
+ throw new Error(`Authentication failed with code: ${response.status}`);
2436
+ }
2437
+ }
2370
2438
  };
2371
- var invitationExpired = (invitation) => {
2372
- return invitation.created && invitation.lifetime && invitation.lifetime !== 0 && invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now();
2439
+ var createAdmissionKeypair = () => {
2440
+ const keypair = (0, import_crypto.createKeyPair)();
2441
+ return {
2442
+ publicKey: import_keys5.PublicKey.from(keypair.publicKey),
2443
+ privateKey: keypair.secretKey
2444
+ };
2373
2445
  };
2374
- var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-service.ts";
2375
2446
  var InvitationsServiceImpl = class {
2376
- constructor(_invitationsHandler, _getHandler, _metadataStore) {
2377
- this._invitationsHandler = _invitationsHandler;
2378
- this._getHandler = _getHandler;
2379
- this._metadataStore = _metadataStore;
2380
- this._createInvitations = /* @__PURE__ */ new Map();
2381
- this._acceptInvitations = /* @__PURE__ */ new Map();
2382
- this._invitationCreated = new import_async9.Event();
2383
- this._invitationAccepted = new import_async9.Event();
2384
- this._removedCreated = new import_async9.Event();
2385
- this._removedAccepted = new import_async9.Event();
2386
- this._saved = new import_async9.Event();
2387
- this._persistentInvitationsLoadedEvent = new import_async9.Event();
2388
- this._persistentInvitationsLoaded = false;
2447
+ constructor(_invitationsManager) {
2448
+ this._invitationsManager = _invitationsManager;
2389
2449
  }
2390
2450
  // TODO(burdon): Guest/host label.
2391
2451
  getLoggingContext() {
2392
2452
  return {};
2393
2453
  }
2394
2454
  createInvitation(options) {
2395
- let invitation;
2396
- const savePersistentInvitationCtx = new import_context6.Context();
2397
- const existingInvitation = this._createInvitations.get(options.invitationId);
2398
- if (existingInvitation) {
2399
- invitation = existingInvitation;
2400
- } else {
2401
- const handler = this._getHandler(options);
2402
- invitation = this._invitationsHandler.createInvitation(handler, options);
2403
- this._createInvitations.set(invitation.get().invitationId, invitation);
2404
- this._invitationCreated.emit(invitation.get());
2405
- }
2455
+ const invitation = this._invitationsManager.createInvitation(options);
2406
2456
  return new import_codec_protobuf8.Stream(({ next, close }) => {
2407
- if (invitation.get().persistent) {
2408
- (0, import_async9.scheduleTask)(savePersistentInvitationCtx, async () => {
2409
- try {
2410
- await this._metadataStore.addInvitation(invitation.get());
2411
- this._saved.emit(invitation.get());
2412
- } catch (err) {
2413
- close(err);
2414
- }
2415
- });
2416
- }
2417
- invitation.subscribe((invitation2) => {
2418
- next(invitation2);
2419
- }, async (err) => {
2420
- await savePersistentInvitationCtx.dispose();
2421
- close(err);
2422
- }, async () => {
2423
- close();
2424
- if (invitation.get().persistent) {
2425
- await savePersistentInvitationCtx.dispose();
2426
- await this._metadataStore.removeInvitation(invitation.get().invitationId);
2427
- }
2428
- this._createInvitations.delete(invitation.get().invitationId);
2429
- if (invitation.get().type !== import_services5.Invitation.Type.MULTIUSE) {
2430
- this._removedCreated.emit(invitation.get());
2431
- }
2432
- });
2457
+ invitation.subscribe(next, close, close);
2433
2458
  });
2434
2459
  }
2435
- async loadPersistentInvitations() {
2436
- const persistentInvitations = this._metadataStore.getInvitations();
2437
- const freshInvitations = persistentInvitations.filter(async (invitation) => !invitationExpired(invitation));
2438
- const cInvitations = freshInvitations.map((persistentInvitation) => {
2439
- (0, import_invariant7.invariant)(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
2440
- F: __dxlog_file8,
2441
- L: 109,
2442
- S: this,
2443
- A: [
2444
- "!this._createInvitations.get(persistentInvitation.invitationId)",
2445
- "'invitation already exists'"
2446
- ]
2447
- });
2448
- const handler = this._getHandler(persistentInvitation);
2449
- const invitation = this._invitationsHandler.createInvitation(handler, persistentInvitation);
2450
- this._createInvitations.set(invitation.get().invitationId, invitation);
2451
- this._invitationCreated.emit(invitation.get());
2452
- return persistentInvitation;
2453
- });
2454
- this._persistentInvitationsLoadedEvent.emit();
2455
- this._persistentInvitationsLoaded = true;
2456
- return {
2457
- invitations: cInvitations
2458
- };
2459
- }
2460
- acceptInvitation({ invitation: options, deviceProfile }) {
2461
- let invitation;
2462
- if (deviceProfile) {
2463
- (0, import_invariant7.invariant)(options.kind === import_services5.Invitation.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
2464
- F: __dxlog_file8,
2465
- L: 127,
2466
- S: this,
2467
- A: [
2468
- "options.kind === Invitation.Kind.DEVICE",
2469
- "'deviceProfile provided for non-device invitation'"
2470
- ]
2471
- });
2472
- }
2473
- const existingInvitation = this._acceptInvitations.get(options.invitationId);
2474
- if (existingInvitation) {
2475
- invitation = existingInvitation;
2476
- } else {
2477
- const handler = this._getHandler(options);
2478
- invitation = this._invitationsHandler.acceptInvitation(handler, options, deviceProfile);
2479
- this._acceptInvitations.set(invitation.get().invitationId, invitation);
2480
- this._invitationAccepted.emit(invitation.get());
2481
- }
2460
+ acceptInvitation(request) {
2461
+ const invitation = this._invitationsManager.acceptInvitation(request);
2482
2462
  return new import_codec_protobuf8.Stream(({ next, close }) => {
2483
- invitation.subscribe((invitation2) => {
2484
- next(invitation2);
2485
- }, (err) => {
2486
- close(err);
2487
- }, () => {
2488
- close();
2489
- this._acceptInvitations.delete(invitation.get().invitationId);
2490
- if (invitation.get().type !== import_services5.Invitation.Type.MULTIUSE) {
2491
- this._removedAccepted.emit(invitation.get());
2492
- }
2493
- });
2463
+ invitation.subscribe(next, close, close);
2494
2464
  });
2495
2465
  }
2496
- async authenticate({ invitationId, authCode }) {
2497
- (0, import_log6.log)("authenticating...", void 0, {
2498
- F: __dxlog_file8,
2499
- L: 160,
2500
- S: this,
2501
- C: (f, a) => f(...a)
2502
- });
2503
- (0, import_invariant7.invariant)(invitationId, void 0, {
2504
- F: __dxlog_file8,
2505
- L: 161,
2506
- S: this,
2507
- A: [
2508
- "invitationId",
2509
- ""
2510
- ]
2511
- });
2512
- const observable = this._acceptInvitations.get(invitationId);
2513
- if (!observable) {
2514
- import_log6.log.warn("invalid invitation", {
2515
- invitationId
2516
- }, {
2517
- F: __dxlog_file8,
2518
- L: 164,
2519
- S: this,
2520
- C: (f, a) => f(...a)
2521
- });
2522
- } else {
2523
- await observable.authenticate(authCode);
2524
- }
2466
+ async authenticate(request) {
2467
+ return this._invitationsManager.authenticate(request);
2525
2468
  }
2526
- async cancelInvitation({ invitationId }) {
2527
- (0, import_log6.log)("cancelInvitation...", {
2528
- invitationId
2529
- }, {
2530
- F: __dxlog_file8,
2531
- L: 171,
2532
- S: this,
2533
- C: (f, a) => f(...a)
2534
- });
2535
- (0, import_invariant7.invariant)(invitationId, void 0, {
2536
- F: __dxlog_file8,
2537
- L: 172,
2538
- S: this,
2539
- A: [
2540
- "invitationId",
2541
- ""
2542
- ]
2543
- });
2544
- const created = this._createInvitations.get(invitationId);
2545
- const accepted = this._acceptInvitations.get(invitationId);
2546
- if (created) {
2547
- await created.cancel();
2548
- this._createInvitations.delete(invitationId);
2549
- this._removedCreated.emit(created.get());
2550
- if (created.get().persistent) {
2551
- await this._metadataStore.removeInvitation(created.get().invitationId);
2552
- }
2553
- } else if (accepted) {
2554
- await accepted.cancel();
2555
- this._acceptInvitations.delete(invitationId);
2556
- this._removedAccepted.emit(accepted.get());
2557
- }
2469
+ async cancelInvitation(request) {
2470
+ return this._invitationsManager.cancelInvitation(request);
2558
2471
  }
2559
2472
  queryInvitations() {
2560
2473
  return new import_codec_protobuf8.Stream(({ next, ctx }) => {
2561
- this._invitationCreated.on(ctx, (invitation) => {
2474
+ this._invitationsManager.invitationCreated.on(ctx, (invitation) => {
2562
2475
  next({
2563
2476
  action: import_services5.QueryInvitationsResponse.Action.ADDED,
2564
2477
  type: import_services5.QueryInvitationsResponse.Type.CREATED,
@@ -2567,7 +2480,7 @@ var InvitationsServiceImpl = class {
2567
2480
  ]
2568
2481
  });
2569
2482
  });
2570
- this._invitationAccepted.on(ctx, (invitation) => {
2483
+ this._invitationsManager.invitationAccepted.on(ctx, (invitation) => {
2571
2484
  next({
2572
2485
  action: import_services5.QueryInvitationsResponse.Action.ADDED,
2573
2486
  type: import_services5.QueryInvitationsResponse.Type.ACCEPTED,
@@ -2576,7 +2489,7 @@ var InvitationsServiceImpl = class {
2576
2489
  ]
2577
2490
  });
2578
2491
  });
2579
- this._removedCreated.on(ctx, (invitation) => {
2492
+ this._invitationsManager.removedCreated.on(ctx, (invitation) => {
2580
2493
  next({
2581
2494
  action: import_services5.QueryInvitationsResponse.Action.REMOVED,
2582
2495
  type: import_services5.QueryInvitationsResponse.Type.CREATED,
@@ -2585,7 +2498,7 @@ var InvitationsServiceImpl = class {
2585
2498
  ]
2586
2499
  });
2587
2500
  });
2588
- this._removedAccepted.on(ctx, (invitation) => {
2501
+ this._invitationsManager.removedAccepted.on(ctx, (invitation) => {
2589
2502
  next({
2590
2503
  action: import_services5.QueryInvitationsResponse.Action.REMOVED,
2591
2504
  type: import_services5.QueryInvitationsResponse.Type.ACCEPTED,
@@ -2594,7 +2507,7 @@ var InvitationsServiceImpl = class {
2594
2507
  ]
2595
2508
  });
2596
2509
  });
2597
- this._saved.on(ctx, (invitation) => {
2510
+ this._invitationsManager.saved.on(ctx, (invitation) => {
2598
2511
  next({
2599
2512
  action: import_services5.QueryInvitationsResponse.Action.SAVED,
2600
2513
  type: import_services5.QueryInvitationsResponse.Type.CREATED,
@@ -2606,32 +2519,25 @@ var InvitationsServiceImpl = class {
2606
2519
  next({
2607
2520
  action: import_services5.QueryInvitationsResponse.Action.ADDED,
2608
2521
  type: import_services5.QueryInvitationsResponse.Type.CREATED,
2609
- invitations: Array.from(this._createInvitations.values()).map((invitation) => invitation.get()),
2522
+ invitations: this._invitationsManager.getCreatedInvitations(),
2610
2523
  existing: true
2611
2524
  });
2612
2525
  next({
2613
2526
  action: import_services5.QueryInvitationsResponse.Action.ADDED,
2614
2527
  type: import_services5.QueryInvitationsResponse.Type.ACCEPTED,
2615
- invitations: Array.from(this._acceptInvitations.values()).map((invitation) => invitation.get()),
2528
+ invitations: this._invitationsManager.getAcceptedInvitations(),
2616
2529
  existing: true
2617
2530
  });
2618
- if (this._persistentInvitationsLoaded) {
2531
+ this._invitationsManager.onPersistentInvitationsLoaded(ctx, () => {
2619
2532
  next({
2620
2533
  action: import_services5.QueryInvitationsResponse.Action.LOAD_COMPLETE,
2621
2534
  type: import_services5.QueryInvitationsResponse.Type.CREATED
2622
2535
  });
2623
- } else {
2624
- this._persistentInvitationsLoadedEvent.on(ctx, () => {
2625
- next({
2626
- action: import_services5.QueryInvitationsResponse.Action.LOAD_COMPLETE,
2627
- type: import_services5.QueryInvitationsResponse.Type.CREATED
2628
- });
2629
- });
2630
- }
2536
+ });
2631
2537
  });
2632
2538
  }
2633
2539
  };
2634
- var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
2540
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
2635
2541
  var SpaceInvitationProtocol = class {
2636
2542
  constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
2637
2543
  this._spaceManager = _spaceManager;
@@ -2652,8 +2558,8 @@ var SpaceInvitationProtocol = class {
2652
2558
  };
2653
2559
  }
2654
2560
  async admit(request, guestProfile) {
2655
- (0, import_invariant8.invariant)(this._spaceKey, void 0, {
2656
- F: __dxlog_file9,
2561
+ (0, import_invariant7.invariant)(this._spaceKey, void 0, {
2562
+ F: __dxlog_file8,
2657
2563
  L: 47,
2658
2564
  S: this,
2659
2565
  A: [
@@ -2662,8 +2568,8 @@ var SpaceInvitationProtocol = class {
2662
2568
  ]
2663
2569
  });
2664
2570
  const space = await this._spaceManager.spaces.get(this._spaceKey);
2665
- (0, import_invariant8.invariant)(space, void 0, {
2666
- F: __dxlog_file9,
2571
+ (0, import_invariant7.invariant)(space, void 0, {
2572
+ F: __dxlog_file8,
2667
2573
  L: 49,
2668
2574
  S: this,
2669
2575
  A: [
@@ -2671,8 +2577,8 @@ var SpaceInvitationProtocol = class {
2671
2577
  ""
2672
2578
  ]
2673
2579
  });
2674
- (0, import_invariant8.invariant)(request.space, void 0, {
2675
- F: __dxlog_file9,
2580
+ (0, import_invariant7.invariant)(request.space, void 0, {
2581
+ F: __dxlog_file8,
2676
2582
  L: 51,
2677
2583
  S: this,
2678
2584
  A: [
@@ -2681,18 +2587,18 @@ var SpaceInvitationProtocol = class {
2681
2587
  ]
2682
2588
  });
2683
2589
  const { identityKey, deviceKey } = request.space;
2684
- (0, import_log7.log)("writing guest credentials", {
2590
+ (0, import_log6.log)("writing guest credentials", {
2685
2591
  host: this._signingContext.deviceKey,
2686
2592
  guest: deviceKey
2687
2593
  }, {
2688
- F: __dxlog_file9,
2594
+ F: __dxlog_file8,
2689
2595
  L: 54,
2690
2596
  S: this,
2691
2597
  C: (f, a) => f(...a)
2692
2598
  });
2693
2599
  const credentials = await (0, import_credentials8.createAdmissionCredentials)(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile);
2694
- (0, import_invariant8.invariant)(credentials[0].credential, void 0, {
2695
- F: __dxlog_file9,
2600
+ (0, import_invariant7.invariant)(credentials[0].credential, void 0, {
2601
+ F: __dxlog_file8,
2696
2602
  L: 65,
2697
2603
  S: this,
2698
2604
  A: [
@@ -2701,8 +2607,8 @@ var SpaceInvitationProtocol = class {
2701
2607
  ]
2702
2608
  });
2703
2609
  const spaceMemberCredential = credentials[0].credential.credential;
2704
- (0, import_invariant8.invariant)((0, import_credentials8.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2705
- F: __dxlog_file9,
2610
+ (0, import_invariant7.invariant)((0, import_credentials8.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2611
+ F: __dxlog_file8,
2706
2612
  L: 67,
2707
2613
  S: this,
2708
2614
  A: [
@@ -2741,8 +2647,8 @@ var SpaceInvitationProtocol = class {
2741
2647
  };
2742
2648
  }
2743
2649
  async accept(response) {
2744
- (0, import_invariant8.invariant)(response.space, void 0, {
2745
- F: __dxlog_file9,
2650
+ (0, import_invariant7.invariant)(response.space, void 0, {
2651
+ F: __dxlog_file8,
2746
2652
  L: 107,
2747
2653
  S: this,
2748
2654
  A: [
@@ -2752,8 +2658,8 @@ var SpaceInvitationProtocol = class {
2752
2658
  });
2753
2659
  const { credential, controlTimeframe, dataTimeframe } = response.space;
2754
2660
  const assertion = (0, import_credentials8.getCredentialAssertion)(credential);
2755
- (0, import_invariant8.invariant)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2756
- F: __dxlog_file9,
2661
+ (0, import_invariant7.invariant)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2662
+ F: __dxlog_file8,
2757
2663
  L: 110,
2758
2664
  S: this,
2759
2665
  A: [
@@ -2761,8 +2667,8 @@ var SpaceInvitationProtocol = class {
2761
2667
  "'Invalid credential'"
2762
2668
  ]
2763
2669
  });
2764
- (0, import_invariant8.invariant)(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
2765
- F: __dxlog_file9,
2670
+ (0, import_invariant7.invariant)(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
2671
+ F: __dxlog_file8,
2766
2672
  L: 111,
2767
2673
  S: this,
2768
2674
  A: [
@@ -2785,6 +2691,221 @@ var SpaceInvitationProtocol = class {
2785
2691
  };
2786
2692
  }
2787
2693
  };
2694
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
2695
+ var InvitationsManager = class {
2696
+ constructor(_invitationsHandler, _getHandler, _metadataStore) {
2697
+ this._invitationsHandler = _invitationsHandler;
2698
+ this._getHandler = _getHandler;
2699
+ this._metadataStore = _metadataStore;
2700
+ this._createInvitations = /* @__PURE__ */ new Map();
2701
+ this._acceptInvitations = /* @__PURE__ */ new Map();
2702
+ this.invitationCreated = new import_async9.Event();
2703
+ this.invitationAccepted = new import_async9.Event();
2704
+ this.removedCreated = new import_async9.Event();
2705
+ this.removedAccepted = new import_async9.Event();
2706
+ this.saved = new import_async9.Event();
2707
+ this._persistentInvitationsLoadedEvent = new import_async9.Event();
2708
+ this._persistentInvitationsLoaded = false;
2709
+ }
2710
+ createInvitation(options) {
2711
+ const existingInvitation = this._createInvitations.get(options.invitationId);
2712
+ if (existingInvitation) {
2713
+ return existingInvitation;
2714
+ }
2715
+ const handler = this._getHandler(options);
2716
+ const invitation = this._invitationsHandler.createInvitation(handler, options);
2717
+ this._createInvitations.set(invitation.get().invitationId, invitation);
2718
+ this.invitationCreated.emit(invitation.get());
2719
+ const saveInvitationTask = invitation.get().persistent ? this._safePersistInBackground(invitation) : Promise.resolve();
2720
+ this._onInvitationComplete(invitation, async () => {
2721
+ this._createInvitations.delete(invitation.get().invitationId);
2722
+ this.removedCreated.emit(invitation.get());
2723
+ if (invitation.get().persistent) {
2724
+ await saveInvitationTask;
2725
+ await this._safeDeleteInvitation(invitation.get());
2726
+ }
2727
+ });
2728
+ return invitation;
2729
+ }
2730
+ async loadPersistentInvitations() {
2731
+ if (this._persistentInvitationsLoaded) {
2732
+ const invitations = this.getCreatedInvitations().filter((i) => i.persistent);
2733
+ return {
2734
+ invitations
2735
+ };
2736
+ }
2737
+ try {
2738
+ const persistentInvitations = this._metadataStore.getInvitations();
2739
+ const freshInvitations = persistentInvitations.filter((invitation) => !(0, import_echo_pipeline.hasInvitationExpired)(invitation));
2740
+ const cInvitations = freshInvitations.map((persistentInvitation) => {
2741
+ (0, import_invariant8.invariant)(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
2742
+ F: __dxlog_file9,
2743
+ L: 82,
2744
+ S: this,
2745
+ A: [
2746
+ "!this._createInvitations.get(persistentInvitation.invitationId)",
2747
+ "'invitation already exists'"
2748
+ ]
2749
+ });
2750
+ return this.createInvitation({
2751
+ ...persistentInvitation,
2752
+ persistent: false
2753
+ }).get();
2754
+ });
2755
+ return {
2756
+ invitations: cInvitations
2757
+ };
2758
+ } catch (err) {
2759
+ import_log7.log.catch(err, void 0, {
2760
+ F: __dxlog_file9,
2761
+ L: 88,
2762
+ S: this,
2763
+ C: (f, a) => f(...a)
2764
+ });
2765
+ return {
2766
+ invitations: []
2767
+ };
2768
+ } finally {
2769
+ this._persistentInvitationsLoadedEvent.emit();
2770
+ this._persistentInvitationsLoaded = true;
2771
+ }
2772
+ }
2773
+ acceptInvitation(request) {
2774
+ const options = request.invitation;
2775
+ const existingInvitation = this._acceptInvitations.get(options.invitationId);
2776
+ if (existingInvitation) {
2777
+ return existingInvitation;
2778
+ }
2779
+ const handler = this._getHandler(options);
2780
+ const invitation = this._invitationsHandler.acceptInvitation(handler, options, request.deviceProfile);
2781
+ this._acceptInvitations.set(invitation.get().invitationId, invitation);
2782
+ this.invitationAccepted.emit(invitation.get());
2783
+ this._onInvitationComplete(invitation, () => {
2784
+ this._acceptInvitations.delete(invitation.get().invitationId);
2785
+ this.removedAccepted.emit(invitation.get());
2786
+ });
2787
+ return invitation;
2788
+ }
2789
+ async authenticate({ invitationId, authCode }) {
2790
+ (0, import_log7.log)("authenticating...", void 0, {
2791
+ F: __dxlog_file9,
2792
+ L: 117,
2793
+ S: this,
2794
+ C: (f, a) => f(...a)
2795
+ });
2796
+ (0, import_invariant8.invariant)(invitationId, void 0, {
2797
+ F: __dxlog_file9,
2798
+ L: 118,
2799
+ S: this,
2800
+ A: [
2801
+ "invitationId",
2802
+ ""
2803
+ ]
2804
+ });
2805
+ const observable = this._acceptInvitations.get(invitationId);
2806
+ if (!observable) {
2807
+ import_log7.log.warn("invalid invitation", {
2808
+ invitationId
2809
+ }, {
2810
+ F: __dxlog_file9,
2811
+ L: 121,
2812
+ S: this,
2813
+ C: (f, a) => f(...a)
2814
+ });
2815
+ } else {
2816
+ await observable.authenticate(authCode);
2817
+ }
2818
+ }
2819
+ async cancelInvitation({ invitationId }) {
2820
+ (0, import_log7.log)("cancelInvitation...", {
2821
+ invitationId
2822
+ }, {
2823
+ F: __dxlog_file9,
2824
+ L: 128,
2825
+ S: this,
2826
+ C: (f, a) => f(...a)
2827
+ });
2828
+ (0, import_invariant8.invariant)(invitationId, void 0, {
2829
+ F: __dxlog_file9,
2830
+ L: 129,
2831
+ S: this,
2832
+ A: [
2833
+ "invitationId",
2834
+ ""
2835
+ ]
2836
+ });
2837
+ const created = this._createInvitations.get(invitationId);
2838
+ if (created) {
2839
+ if (created.get().persistent) {
2840
+ await this._metadataStore.removeInvitation(invitationId);
2841
+ }
2842
+ await created.cancel();
2843
+ this._createInvitations.delete(invitationId);
2844
+ this.removedCreated.emit(created.get());
2845
+ return;
2846
+ }
2847
+ const accepted = this._acceptInvitations.get(invitationId);
2848
+ if (accepted) {
2849
+ await accepted.cancel();
2850
+ this._acceptInvitations.delete(invitationId);
2851
+ this.removedAccepted.emit(accepted.get());
2852
+ }
2853
+ }
2854
+ getCreatedInvitations() {
2855
+ return [
2856
+ ...this._createInvitations.values()
2857
+ ].map((i) => i.get());
2858
+ }
2859
+ getAcceptedInvitations() {
2860
+ return [
2861
+ ...this._acceptInvitations.values()
2862
+ ].map((i) => i.get());
2863
+ }
2864
+ onPersistentInvitationsLoaded(ctx, callback) {
2865
+ if (this._persistentInvitationsLoaded) {
2866
+ callback();
2867
+ } else {
2868
+ this._persistentInvitationsLoadedEvent.once(ctx, () => callback());
2869
+ }
2870
+ }
2871
+ _safePersistInBackground(invitation) {
2872
+ return new Promise((resolve) => {
2873
+ setTimeout(async () => {
2874
+ try {
2875
+ await this._metadataStore.addInvitation(invitation.get());
2876
+ this.saved.emit(invitation.get());
2877
+ } catch (err) {
2878
+ import_log7.log.catch(err, void 0, {
2879
+ F: __dxlog_file9,
2880
+ L: 173,
2881
+ S: this,
2882
+ C: (f, a) => f(...a)
2883
+ });
2884
+ await invitation.cancel();
2885
+ } finally {
2886
+ resolve();
2887
+ }
2888
+ });
2889
+ });
2890
+ }
2891
+ async _safeDeleteInvitation(invitation) {
2892
+ try {
2893
+ await this._metadataStore.removeInvitation(invitation.invitationId);
2894
+ } catch (err) {
2895
+ import_log7.log.catch(err, void 0, {
2896
+ F: __dxlog_file9,
2897
+ L: 186,
2898
+ S: this,
2899
+ C: (f, a) => f(...a)
2900
+ });
2901
+ }
2902
+ }
2903
+ _onInvitationComplete(invitation, callback) {
2904
+ invitation.subscribe(() => {
2905
+ }, () => {
2906
+ }, callback);
2907
+ }
2908
+ };
2788
2909
  function _ts_decorate3(decorators, target, key, desc) {
2789
2910
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2790
2911
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -2860,141 +2981,6 @@ _ts_decorate3([
2860
2981
  ClientRpcServer = _ts_decorate3([
2861
2982
  import_tracing3.trace.resource()
2862
2983
  ], ClientRpcServer);
2863
- var getPlatform = () => {
2864
- if (process.browser) {
2865
- if (typeof window !== "undefined") {
2866
- const { userAgent } = window.navigator;
2867
- return {
2868
- type: import_services8.Platform.PLATFORM_TYPE.BROWSER,
2869
- userAgent,
2870
- uptime: Math.floor((Date.now() - window.performance.timeOrigin) / 1e3)
2871
- };
2872
- } else {
2873
- return {
2874
- type: import_services8.Platform.PLATFORM_TYPE.SHARED_WORKER,
2875
- uptime: Math.floor((Date.now() - performance.timeOrigin) / 1e3)
2876
- };
2877
- }
2878
- } else {
2879
- const { platform: platform2, version, arch } = process;
2880
- return {
2881
- type: import_services8.Platform.PLATFORM_TYPE.NODE,
2882
- platform: platform2,
2883
- arch,
2884
- runtime: version,
2885
- uptime: Math.floor(process.uptime()),
2886
- memory: process.memoryUsage()
2887
- };
2888
- }
2889
- };
2890
- var DXOS_VERSION = "0.4.10-main.f68a1ca";
2891
- var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
2892
- var DEFAULT_TIMEOUT = 1e3;
2893
- var createDiagnostics = async (clientServices, serviceContext, config) => {
2894
- const diagnostics = {
2895
- created: (/* @__PURE__ */ new Date()).toISOString(),
2896
- platform: getPlatform(),
2897
- client: {
2898
- version: DXOS_VERSION,
2899
- storage: {
2900
- version: import_protocols7.STORAGE_VERSION
2901
- }
2902
- },
2903
- trace: import_tracing4.TRACE_PROCESSOR.getDiagnostics()
2904
- };
2905
- {
2906
- (0, import_invariant9.invariant)(clientServices.LoggingService, "SystemService is not available.", {
2907
- F: __dxlog_file10,
2908
- L: 108,
2909
- S: void 0,
2910
- A: [
2911
- "clientServices.LoggingService",
2912
- "'SystemService is not available.'"
2913
- ]
2914
- });
2915
- diagnostics.metrics = await (0, import_codec_protobuf10.getFirstStreamValue)(clientServices.LoggingService.queryMetrics({}), {
2916
- timeout: DEFAULT_TIMEOUT
2917
- }).catch(() => void 0);
2918
- }
2919
- if (typeof navigator !== "undefined" && navigator.storage) {
2920
- const map = /* @__PURE__ */ new Map();
2921
- const dir = await navigator.storage.getDirectory();
2922
- for await (const filename of dir?.keys()) {
2923
- const idx = filename.indexOf("-", filename.indexOf("-") + 1);
2924
- if (idx === -1) {
2925
- continue;
2926
- }
2927
- map.set(filename.slice(0, idx), (map.get(filename.slice(0, idx)) ?? 0) + 1);
2928
- }
2929
- diagnostics.storage = Array.from(map.entries()).sort((a, b) => b[1] - a[1]).map(([file, count]) => ({
2930
- file,
2931
- count
2932
- }));
2933
- }
2934
- const identity = serviceContext.identityManager.identity;
2935
- if (identity) {
2936
- diagnostics.identity = {
2937
- identityKey: identity.identityKey,
2938
- spaceKey: identity.space.key,
2939
- profile: identity.profileDocument
2940
- };
2941
- const { devices } = await (0, import_codec_protobuf10.getFirstStreamValue)(clientServices.DevicesService.queryDevices(), {
2942
- timeout: DEFAULT_TIMEOUT
2943
- }).catch(() => void 0) ?? {};
2944
- diagnostics.devices = devices;
2945
- if (serviceContext.dataSpaceManager) {
2946
- diagnostics.spaces = await Promise.all(Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space)) ?? []);
2947
- }
2948
- const { feeds = [] } = await (0, import_codec_protobuf10.getFirstStreamValue)(clientServices.DevtoolsHost.subscribeToFeeds({}), {
2949
- timeout: DEFAULT_TIMEOUT
2950
- }).catch(() => void 0) ?? {};
2951
- diagnostics.feeds = feeds.map(({ feedKey, bytes, length }) => ({
2952
- feedKey,
2953
- bytes,
2954
- length
2955
- }));
2956
- const status = await (0, import_codec_protobuf10.getFirstStreamValue)(clientServices.NetworkService.queryStatus(), {
2957
- timeout: DEFAULT_TIMEOUT
2958
- }).catch(() => void 0);
2959
- diagnostics.networkStatus = status;
2960
- diagnostics.swarms = serviceContext.networkManager.connectionLog?.swarms;
2961
- }
2962
- diagnostics.config = config.values;
2963
- return diagnostics;
2964
- };
2965
- var getSpaceStats = async (space) => {
2966
- const stats = {
2967
- key: space.key,
2968
- metrics: space.metrics,
2969
- epochs: space.inner.spaceState.credentials.filter((0, import_credentials9.credentialTypeFilter)("dxos.halo.credentials.Epoch")).map((credential) => ({
2970
- ...credential.subject.assertion,
2971
- id: credential.id
2972
- })),
2973
- members: Array.from(space.inner.spaceState.members.values()).map((member) => ({
2974
- identity: {
2975
- identityKey: member.key,
2976
- profile: {
2977
- displayName: member.assertion.profile?.displayName
2978
- }
2979
- },
2980
- presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? import_services7.SpaceMember.PresenceState.ONLINE : import_services7.SpaceMember.PresenceState.OFFLINE
2981
- })),
2982
- pipeline: {
2983
- // TODO(burdon): Pick properties from credentials if needed.
2984
- currentEpoch: space.automergeSpaceState.lastEpoch,
2985
- appliedEpoch: space.automergeSpaceState.lastEpoch,
2986
- controlFeeds: space.inner.controlPipeline.state.feeds.map((feed) => feed.key),
2987
- currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
2988
- targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
2989
- totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe
2990
- }
2991
- };
2992
- if (stats.metrics) {
2993
- const { open, ready } = stats.metrics;
2994
- stats.metrics.startupTime = open && ready && ready.getTime() - open.getTime();
2995
- }
2996
- return stats;
2997
- };
2998
2984
  var AutomergeSpaceState = class {
2999
2985
  constructor(_onNewRoot) {
3000
2986
  this._onNewRoot = _onNewRoot;
@@ -3004,7 +2990,7 @@ var AutomergeSpaceState = class {
3004
2990
  this._isProcessingRootDocs = false;
3005
2991
  }
3006
2992
  async processCredential(credential) {
3007
- if (!(0, import_credentials11.checkCredentialType)(credential, "dxos.halo.credentials.Epoch")) {
2993
+ if (!(0, import_credentials10.checkCredentialType)(credential, "dxos.halo.credentials.Epoch")) {
3008
2994
  return;
3009
2995
  }
3010
2996
  this.lastEpoch = credential;
@@ -3029,14 +3015,14 @@ var AutomergeSpaceState = class {
3029
3015
  await this.onNewEpoch.waitForCondition(() => !!this.lastEpoch);
3030
3016
  }
3031
3017
  };
3032
- var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
3018
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
3033
3019
  var DEFAULT_RETRY_TIMEOUT = 1e3;
3034
3020
  var DEFAULT_SUCCESS_DELAY = 1e3;
3035
3021
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
3036
3022
  var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
3037
3023
  var NotarizationPlugin = class {
3038
3024
  constructor() {
3039
- this._ctx = new import_context8.Context();
3025
+ this._ctx = new import_context7.Context();
3040
3026
  this._extensionOpened = new import_async12.Event();
3041
3027
  this._extensions = /* @__PURE__ */ new Set();
3042
3028
  this._processedCredentials = new import_util5.ComplexSet(import_keys8.PublicKey.hash);
@@ -3057,13 +3043,13 @@ var NotarizationPlugin = class {
3057
3043
  (0, import_log9.log)("notarize", {
3058
3044
  credentials
3059
3045
  }, {
3060
- F: __dxlog_file11,
3046
+ F: __dxlog_file10,
3061
3047
  L: 90,
3062
3048
  S: this,
3063
3049
  C: (f, a) => f(...a)
3064
3050
  });
3065
- (0, import_invariant11.invariant)(credentials.every((credential) => credential.id), "Credentials must have an id", {
3066
- F: __dxlog_file11,
3051
+ (0, import_invariant10.invariant)(credentials.every((credential) => credential.id), "Credentials must have an id", {
3052
+ F: __dxlog_file10,
3067
3053
  L: 91,
3068
3054
  S: this,
3069
3055
  A: [
@@ -3077,7 +3063,7 @@ var NotarizationPlugin = class {
3077
3063
  import_log9.log.warn("Notarization error", {
3078
3064
  err
3079
3065
  }, {
3080
- F: __dxlog_file11,
3066
+ F: __dxlog_file10,
3081
3067
  L: 99,
3082
3068
  S: this,
3083
3069
  C: (f, a) => f(...a)
@@ -3093,7 +3079,7 @@ var NotarizationPlugin = class {
3093
3079
  timeout,
3094
3080
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
3095
3081
  }, {
3096
- F: __dxlog_file11,
3082
+ F: __dxlog_file10,
3097
3083
  L: 111,
3098
3084
  S: this,
3099
3085
  C: (f, a) => f(...a)
@@ -3116,7 +3102,7 @@ var NotarizationPlugin = class {
3116
3102
  import_log9.log.info("Exhausted all peers to notarize with", {
3117
3103
  retryIn: retryTimeout
3118
3104
  }, {
3119
- F: __dxlog_file11,
3105
+ F: __dxlog_file10,
3120
3106
  L: 136,
3121
3107
  S: this,
3122
3108
  C: (f, a) => f(...a)
@@ -3130,7 +3116,7 @@ var NotarizationPlugin = class {
3130
3116
  peer: peer.localPeerId,
3131
3117
  credentialId: credentials.map((credential) => credential.id)
3132
3118
  }, {
3133
- F: __dxlog_file11,
3119
+ F: __dxlog_file10,
3134
3120
  L: 143,
3135
3121
  S: this,
3136
3122
  C: (f, a) => f(...a)
@@ -3139,7 +3125,7 @@ var NotarizationPlugin = class {
3139
3125
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
3140
3126
  });
3141
3127
  (0, import_log9.log)("success", void 0, {
3142
- F: __dxlog_file11,
3128
+ F: __dxlog_file10,
3143
3129
  L: 147,
3144
3130
  S: this,
3145
3131
  C: (f, a) => f(...a)
@@ -3148,7 +3134,7 @@ var NotarizationPlugin = class {
3148
3134
  } catch (err) {
3149
3135
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
3150
3136
  import_log9.log.info("error notarizing (recoverable)", err, {
3151
- F: __dxlog_file11,
3137
+ F: __dxlog_file10,
3152
3138
  L: 151,
3153
3139
  S: this,
3154
3140
  C: (f, a) => f(...a)
@@ -3161,12 +3147,12 @@ var NotarizationPlugin = class {
3161
3147
  this._extensionOpened.on(ctx, () => notarizeTask.schedule());
3162
3148
  try {
3163
3149
  await Promise.race([
3164
- (0, import_context8.rejectOnDispose)(ctx),
3150
+ (0, import_context7.rejectOnDispose)(ctx),
3165
3151
  allNotarized,
3166
3152
  errors.wait()
3167
3153
  ]);
3168
3154
  (0, import_log9.log)("done", void 0, {
3169
- F: __dxlog_file11,
3155
+ F: __dxlog_file10,
3170
3156
  L: 162,
3171
3157
  S: this,
3172
3158
  C: (f, a) => f(...a)
@@ -3187,8 +3173,8 @@ var NotarizationPlugin = class {
3187
3173
  this._processCredentialsTriggers.delete(credential.id);
3188
3174
  }
3189
3175
  setWriter(writer) {
3190
- (0, import_invariant11.invariant)(!this._writer, "Writer already set.", {
3191
- F: __dxlog_file11,
3176
+ (0, import_invariant10.invariant)(!this._writer, "Writer already set.", {
3177
+ F: __dxlog_file10,
3192
3178
  L: 181,
3193
3179
  S: this,
3194
3180
  A: [
@@ -3212,8 +3198,8 @@ var NotarizationPlugin = class {
3212
3198
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
3213
3199
  }
3214
3200
  for (const credential of request.credentials ?? []) {
3215
- (0, import_invariant11.invariant)(credential.id, "Credential must have an id", {
3216
- F: __dxlog_file11,
3201
+ (0, import_invariant10.invariant)(credential.id, "Credential must have an id", {
3202
+ F: __dxlog_file10,
3217
3203
  L: 200,
3218
3204
  S: this,
3219
3205
  A: [
@@ -3233,7 +3219,7 @@ var NotarizationPlugin = class {
3233
3219
  (0, import_log9.log)("extension opened", {
3234
3220
  peer: extension.localPeerId
3235
3221
  }, {
3236
- F: __dxlog_file11,
3222
+ F: __dxlog_file10,
3237
3223
  L: 211,
3238
3224
  S: this,
3239
3225
  C: (f, a) => f(...a)
@@ -3245,7 +3231,7 @@ var NotarizationPlugin = class {
3245
3231
  (0, import_log9.log)("extension closed", {
3246
3232
  peer: extension.localPeerId
3247
3233
  }, {
3248
- F: __dxlog_file11,
3234
+ F: __dxlog_file10,
3249
3235
  L: 216,
3250
3236
  S: this,
3251
3237
  C: (f, a) => f(...a)
@@ -3261,10 +3247,10 @@ var NotarizationTeleportExtension = class extends import_teleport2.RpcExtension
3261
3247
  constructor(_params) {
3262
3248
  super({
3263
3249
  requested: {
3264
- NotarizationService: import_protocols9.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3250
+ NotarizationService: import_protocols8.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3265
3251
  },
3266
3252
  exposed: {
3267
- NotarizationService: import_protocols9.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3253
+ NotarizationService: import_protocols8.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3268
3254
  }
3269
3255
  });
3270
3256
  this._params = _params;
@@ -3297,14 +3283,14 @@ function _ts_decorate4(decorators, target, key, desc) {
3297
3283
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3298
3284
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3299
3285
  }
3300
- var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
3286
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
3301
3287
  var DataSpace = class {
3302
3288
  constructor(params) {
3303
- this._ctx = new import_context7.Context();
3289
+ this._ctx = new import_context6.Context();
3304
3290
  this._notarizationPlugin = new NotarizationPlugin();
3305
3291
  this._cache = void 0;
3306
3292
  this._automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
3307
- this._state = import_services9.SpaceState.CLOSED;
3293
+ this._state = import_services7.SpaceState.CLOSED;
3308
3294
  this.error = void 0;
3309
3295
  this.stateUpdate = new import_async10.Event();
3310
3296
  this.metrics = {};
@@ -3326,9 +3312,9 @@ var DataSpace = class {
3326
3312
  this._cache = params.cache;
3327
3313
  this._state = params.initialState;
3328
3314
  (0, import_log8.log)("new state", {
3329
- state: import_services9.SpaceState[this._state]
3315
+ state: import_services7.SpaceState[this._state]
3330
3316
  }, {
3331
- F: __dxlog_file12,
3317
+ F: __dxlog_file11,
3332
3318
  L: 140,
3333
3319
  S: this,
3334
3320
  C: (f, a) => f(...a)
@@ -3373,12 +3359,12 @@ var DataSpace = class {
3373
3359
  await this._notarizationPlugin.open();
3374
3360
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
3375
3361
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
3376
- await this._inner.open(new import_context7.Context());
3377
- this._state = import_services9.SpaceState.CONTROL_ONLY;
3362
+ await this._inner.open(new import_context6.Context());
3363
+ this._state = import_services7.SpaceState.CONTROL_ONLY;
3378
3364
  (0, import_log8.log)("new state", {
3379
- state: import_services9.SpaceState[this._state]
3365
+ state: import_services7.SpaceState[this._state]
3380
3366
  }, {
3381
- F: __dxlog_file12,
3367
+ F: __dxlog_file11,
3382
3368
  L: 198,
3383
3369
  S: this,
3384
3370
  C: (f, a) => f(...a)
@@ -3392,17 +3378,17 @@ var DataSpace = class {
3392
3378
  }
3393
3379
  async _close() {
3394
3380
  await this._callbacks.beforeClose?.();
3395
- this._state = import_services9.SpaceState.CLOSED;
3381
+ this._state = import_services7.SpaceState.CLOSED;
3396
3382
  (0, import_log8.log)("new state", {
3397
- state: import_services9.SpaceState[this._state]
3383
+ state: import_services7.SpaceState[this._state]
3398
3384
  }, {
3399
- F: __dxlog_file12,
3385
+ F: __dxlog_file11,
3400
3386
  L: 212,
3401
3387
  S: this,
3402
3388
  C: (f, a) => f(...a)
3403
3389
  });
3404
3390
  await this._ctx.dispose();
3405
- this._ctx = new import_context7.Context();
3391
+ this._ctx = new import_context6.Context();
3406
3392
  await this.authVerifier.close();
3407
3393
  await this._inner.close();
3408
3394
  await this._inner.spaceState.removeCredentialProcessor(this._automergeSpaceState);
@@ -3426,9 +3412,9 @@ var DataSpace = class {
3426
3412
  this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
3427
3413
  await this.initializeDataPipeline();
3428
3414
  } catch (err) {
3429
- if (err instanceof import_protocols8.CancelledError || err instanceof import_context7.ContextDisposedError) {
3415
+ if (err instanceof import_protocols7.CancelledError || err instanceof import_context6.ContextDisposedError) {
3430
3416
  (0, import_log8.log)("data pipeline initialization cancelled", err, {
3431
- F: __dxlog_file12,
3417
+ F: __dxlog_file11,
3432
3418
  L: 245,
3433
3419
  S: this,
3434
3420
  C: (f, a) => f(...a)
@@ -3436,16 +3422,16 @@ var DataSpace = class {
3436
3422
  return;
3437
3423
  }
3438
3424
  import_log8.log.error("Error initializing data pipeline", err, {
3439
- F: __dxlog_file12,
3425
+ F: __dxlog_file11,
3440
3426
  L: 249,
3441
3427
  S: this,
3442
3428
  C: (f, a) => f(...a)
3443
3429
  });
3444
- this._state = import_services9.SpaceState.ERROR;
3430
+ this._state = import_services7.SpaceState.ERROR;
3445
3431
  (0, import_log8.log)("new state", {
3446
- state: import_services9.SpaceState[this._state]
3432
+ state: import_services7.SpaceState[this._state]
3447
3433
  }, {
3448
- F: __dxlog_file12,
3434
+ F: __dxlog_file11,
3449
3435
  L: 251,
3450
3436
  S: this,
3451
3437
  C: (f, a) => f(...a)
@@ -3458,14 +3444,14 @@ var DataSpace = class {
3458
3444
  });
3459
3445
  }
3460
3446
  async initializeDataPipeline() {
3461
- if (this._state !== import_services9.SpaceState.CONTROL_ONLY) {
3462
- throw new import_protocols8.SystemError("Invalid operation");
3447
+ if (this._state !== import_services7.SpaceState.CONTROL_ONLY) {
3448
+ throw new import_protocols7.SystemError("Invalid operation");
3463
3449
  }
3464
- this._state = import_services9.SpaceState.INITIALIZING;
3450
+ this._state = import_services7.SpaceState.INITIALIZING;
3465
3451
  (0, import_log8.log)("new state", {
3466
- state: import_services9.SpaceState[this._state]
3452
+ state: import_services7.SpaceState[this._state]
3467
3453
  }, {
3468
- F: __dxlog_file12,
3454
+ F: __dxlog_file11,
3469
3455
  L: 267,
3470
3456
  S: this,
3471
3457
  C: (f, a) => f(...a)
@@ -3473,19 +3459,19 @@ var DataSpace = class {
3473
3459
  await this._initializeAndReadControlPipeline();
3474
3460
  await (0, import_async10.sleep)(1);
3475
3461
  this._automergeSpaceState.startProcessingRootDocs();
3476
- await (0, import_context7.cancelWithContext)(this._ctx, this.automergeSpaceState.ensureEpochInitialized());
3462
+ await (0, import_context6.cancelWithContext)(this._ctx, this.automergeSpaceState.ensureEpochInitialized());
3477
3463
  (0, import_log8.log)("data pipeline ready", void 0, {
3478
- F: __dxlog_file12,
3464
+ F: __dxlog_file11,
3479
3465
  L: 279,
3480
3466
  S: this,
3481
3467
  C: (f, a) => f(...a)
3482
3468
  });
3483
3469
  await this._callbacks.beforeReady?.();
3484
- this._state = import_services9.SpaceState.READY;
3470
+ this._state = import_services7.SpaceState.READY;
3485
3471
  (0, import_log8.log)("new state", {
3486
- state: import_services9.SpaceState[this._state]
3472
+ state: import_services7.SpaceState[this._state]
3487
3473
  }, {
3488
- F: __dxlog_file12,
3474
+ F: __dxlog_file11,
3489
3475
  L: 283,
3490
3476
  S: this,
3491
3477
  C: (f, a) => f(...a)
@@ -3501,14 +3487,14 @@ var DataSpace = class {
3501
3487
  this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
3502
3488
  await this._createWritableFeeds();
3503
3489
  (0, import_log8.log)("writable feeds created", void 0, {
3504
- F: __dxlog_file12,
3490
+ F: __dxlog_file11,
3505
3491
  L: 299,
3506
3492
  S: this,
3507
3493
  C: (f, a) => f(...a)
3508
3494
  });
3509
3495
  this.stateUpdate.emit();
3510
3496
  if (!this.notarizationPlugin.hasWriter) {
3511
- this.notarizationPlugin.setWriter((0, import_echo_pipeline.createMappedFeedWriter)((credential) => ({
3497
+ this.notarizationPlugin.setWriter((0, import_echo_pipeline2.createMappedFeedWriter)((credential) => ({
3512
3498
  credential: {
3513
3499
  credential
3514
3500
  }
@@ -3529,7 +3515,7 @@ var DataSpace = class {
3529
3515
  spaceKey: this.key,
3530
3516
  deviceKey: this._signingContext.deviceKey,
3531
3517
  identityKey: this._signingContext.identityKey,
3532
- designation: import_credentials10.AdmittedFeed.Designation.CONTROL
3518
+ designation: import_credentials9.AdmittedFeed.Designation.CONTROL
3533
3519
  }
3534
3520
  }));
3535
3521
  }
@@ -3546,7 +3532,7 @@ var DataSpace = class {
3546
3532
  spaceKey: this.key,
3547
3533
  deviceKey: this._signingContext.deviceKey,
3548
3534
  identityKey: this._signingContext.identityKey,
3549
- designation: import_credentials10.AdmittedFeed.Designation.DATA
3535
+ designation: import_credentials9.AdmittedFeed.Designation.DATA
3550
3536
  }
3551
3537
  }));
3552
3538
  }
@@ -3564,7 +3550,7 @@ var DataSpace = class {
3564
3550
  space: this.key,
3565
3551
  rootUrl
3566
3552
  }, {
3567
- F: __dxlog_file12,
3553
+ F: __dxlog_file11,
3568
3554
  L: 365,
3569
3555
  S: this,
3570
3556
  C: (f, a) => f(...a)
@@ -3574,12 +3560,12 @@ var DataSpace = class {
3574
3560
  queueMicrotask(async () => {
3575
3561
  try {
3576
3562
  await (0, import_debug3.warnAfterTimeout)(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
3577
- await (0, import_context7.cancelWithContext)(this._ctx, handle.whenReady());
3563
+ await (0, import_context6.cancelWithContext)(this._ctx, handle.whenReady());
3578
3564
  });
3579
3565
  if (this._ctx.disposed) {
3580
3566
  return;
3581
3567
  }
3582
- const doc = handle.docSync() ?? (0, import_invariant10.failedInvariant)();
3568
+ const doc = handle.docSync() ?? (0, import_invariant9.failedInvariant)();
3583
3569
  if (!doc.access?.spaceKey) {
3584
3570
  handle.change((doc2) => {
3585
3571
  doc2.access = {
@@ -3588,7 +3574,7 @@ var DataSpace = class {
3588
3574
  });
3589
3575
  }
3590
3576
  } catch (err) {
3591
- if (err instanceof import_context7.ContextDisposedError) {
3577
+ if (err instanceof import_context6.ContextDisposedError) {
3592
3578
  return;
3593
3579
  }
3594
3580
  import_log8.log.warn("error loading automerge root doc", {
@@ -3596,7 +3582,7 @@ var DataSpace = class {
3596
3582
  rootUrl,
3597
3583
  err
3598
3584
  }, {
3599
- F: __dxlog_file12,
3585
+ F: __dxlog_file11,
3600
3586
  L: 388,
3601
3587
  S: this,
3602
3588
  C: (f, a) => f(...a)
@@ -3623,7 +3609,7 @@ var DataSpace = class {
3623
3609
  let epoch;
3624
3610
  switch (options?.migration) {
3625
3611
  case void 0:
3626
- case import_services9.CreateEpochRequest.Migration.NONE:
3612
+ case import_services7.CreateEpochRequest.Migration.NONE:
3627
3613
  {
3628
3614
  epoch = {
3629
3615
  previousId: this._automergeSpaceState.lastEpoch?.id,
@@ -3633,7 +3619,7 @@ var DataSpace = class {
3633
3619
  };
3634
3620
  }
3635
3621
  break;
3636
- case import_services9.CreateEpochRequest.Migration.INIT_AUTOMERGE:
3622
+ case import_services7.CreateEpochRequest.Migration.INIT_AUTOMERGE:
3637
3623
  {
3638
3624
  const document = this._automergeHost.repo.create();
3639
3625
  epoch = {
@@ -3644,14 +3630,14 @@ var DataSpace = class {
3644
3630
  };
3645
3631
  }
3646
3632
  break;
3647
- case import_services9.CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY:
3633
+ case import_services7.CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY:
3648
3634
  {
3649
3635
  const currentRootUrl = this._automergeSpaceState.rootUrl;
3650
3636
  const rootHandle = this._automergeHost.repo.find(currentRootUrl);
3651
- await (0, import_context7.cancelWithContext)(this._ctx, (0, import_async10.asyncTimeout)(rootHandle.whenReady(), 1e4));
3637
+ await (0, import_context6.cancelWithContext)(this._ctx, (0, import_async10.asyncTimeout)(rootHandle.whenReady(), 1e4));
3652
3638
  const newRoot = this._automergeHost.repo.create(rootHandle.docSync());
3653
- (0, import_invariant10.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3654
- F: __dxlog_file12,
3639
+ (0, import_invariant9.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3640
+ F: __dxlog_file11,
3655
3641
  L: 438,
3656
3642
  S: this,
3657
3643
  A: [
@@ -3667,22 +3653,22 @@ var DataSpace = class {
3667
3653
  };
3668
3654
  }
3669
3655
  break;
3670
- case import_services9.CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT:
3656
+ case import_services7.CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT:
3671
3657
  {
3672
3658
  import_log8.log.info("Fragmenting", void 0, {
3673
- F: __dxlog_file12,
3659
+ F: __dxlog_file11,
3674
3660
  L: 450,
3675
3661
  S: this,
3676
3662
  C: (f, a) => f(...a)
3677
3663
  });
3678
3664
  const currentRootUrl = this._automergeSpaceState.rootUrl;
3679
3665
  const rootHandle = this._automergeHost.repo.find(currentRootUrl);
3680
- await (0, import_context7.cancelWithContext)(this._ctx, (0, import_async10.asyncTimeout)(rootHandle.whenReady(), 1e4));
3666
+ await (0, import_context6.cancelWithContext)(this._ctx, (0, import_async10.asyncTimeout)(rootHandle.whenReady(), 1e4));
3681
3667
  const objects = Object.entries(rootHandle.docSync().objects);
3682
3668
  const properties = objects.find(([_, value]) => value.system.type?.itemId === import_echo_db.TYPE_PROPERTIES);
3683
3669
  const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
3684
- (0, import_invariant10.invariant)(properties, "Properties not found", {
3685
- F: __dxlog_file12,
3670
+ (0, import_invariant9.invariant)(properties, "Properties not found", {
3671
+ F: __dxlog_file11,
3686
3672
  L: 460,
3687
3673
  S: this,
3688
3674
  A: [
@@ -3697,8 +3683,8 @@ var DataSpace = class {
3697
3683
  ])
3698
3684
  };
3699
3685
  const newRoot = this._automergeHost.repo.create(newSpaceDoc);
3700
- (0, import_invariant10.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3701
- F: __dxlog_file12,
3686
+ (0, import_invariant9.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3687
+ F: __dxlog_file11,
3702
3688
  L: 465,
3703
3689
  S: this,
3704
3690
  A: [
@@ -3706,7 +3692,7 @@ var DataSpace = class {
3706
3692
  ""
3707
3693
  ]
3708
3694
  });
3709
- const docLoader = new import_echo_pipeline2.AutomergeDocumentLoaderImpl(this.key, this._automergeHost.repo);
3695
+ const docLoader = new import_echo_pipeline3.AutomergeDocumentLoaderImpl(this.key, this._automergeHost.repo);
3710
3696
  await docLoader.loadSpaceRootDocHandle(this._ctx, {
3711
3697
  rootUrl: newRoot.url
3712
3698
  });
@@ -3750,24 +3736,24 @@ var DataSpace = class {
3750
3736
  ]));
3751
3737
  }
3752
3738
  async activate() {
3753
- if (this._state !== import_services9.SpaceState.INACTIVE) {
3739
+ if (this._state !== import_services7.SpaceState.INACTIVE) {
3754
3740
  return;
3755
3741
  }
3756
- await this._metadataStore.setSpaceState(this.key, import_services9.SpaceState.ACTIVE);
3742
+ await this._metadataStore.setSpaceState(this.key, import_services7.SpaceState.ACTIVE);
3757
3743
  await this._open();
3758
3744
  this.initializeDataPipelineAsync();
3759
3745
  }
3760
3746
  async deactivate() {
3761
- if (this._state === import_services9.SpaceState.INACTIVE) {
3747
+ if (this._state === import_services7.SpaceState.INACTIVE) {
3762
3748
  return;
3763
3749
  }
3764
- await this._metadataStore.setSpaceState(this.key, import_services9.SpaceState.INACTIVE);
3750
+ await this._metadataStore.setSpaceState(this.key, import_services7.SpaceState.INACTIVE);
3765
3751
  await this._close();
3766
- this._state = import_services9.SpaceState.INACTIVE;
3752
+ this._state = import_services7.SpaceState.INACTIVE;
3767
3753
  (0, import_log8.log)("new state", {
3768
- state: import_services9.SpaceState[this._state]
3754
+ state: import_services7.SpaceState[this._state]
3769
3755
  }, {
3770
- F: __dxlog_file12,
3756
+ F: __dxlog_file11,
3771
3757
  L: 531,
3772
3758
  S: this,
3773
3759
  C: (f, a) => f(...a)
@@ -3776,18 +3762,18 @@ var DataSpace = class {
3776
3762
  }
3777
3763
  };
3778
3764
  _ts_decorate4([
3779
- import_tracing5.trace.info()
3765
+ import_tracing4.trace.info()
3780
3766
  ], DataSpace.prototype, "_inner", void 0);
3781
3767
  _ts_decorate4([
3782
- import_tracing5.trace.info()
3768
+ import_tracing4.trace.info()
3783
3769
  ], DataSpace.prototype, "key", null);
3784
3770
  _ts_decorate4([
3785
- import_tracing5.trace.info({
3786
- enum: import_services9.SpaceState
3771
+ import_tracing4.trace.info({
3772
+ enum: import_services7.SpaceState
3787
3773
  })
3788
3774
  ], DataSpace.prototype, "state", null);
3789
3775
  _ts_decorate4([
3790
- import_tracing5.trace.info({
3776
+ import_tracing4.trace.info({
3791
3777
  depth: null
3792
3778
  })
3793
3779
  ], DataSpace.prototype, "_automergeInfo", null);
@@ -3798,12 +3784,12 @@ _ts_decorate4([
3798
3784
  import_async10.synchronized
3799
3785
  ], DataSpace.prototype, "close", null);
3800
3786
  _ts_decorate4([
3801
- import_tracing5.trace.span({
3787
+ import_tracing4.trace.span({
3802
3788
  showInBrowserTimeline: true
3803
3789
  })
3804
3790
  ], DataSpace.prototype, "initializeDataPipeline", null);
3805
3791
  _ts_decorate4([
3806
- import_tracing5.trace.span({
3792
+ import_tracing4.trace.span({
3807
3793
  showInBrowserTimeline: true
3808
3794
  })
3809
3795
  ], DataSpace.prototype, "_initializeAndReadControlPipeline", null);
@@ -3818,11 +3804,11 @@ _ts_decorate4([
3818
3804
  ], DataSpace.prototype, "deactivate", null);
3819
3805
  DataSpace = _ts_decorate4([
3820
3806
  (0, import_async10.trackLeaks)("open", "close"),
3821
- import_tracing5.trace.resource()
3807
+ import_tracing4.trace.resource()
3822
3808
  ], DataSpace);
3823
3809
  var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3824
3810
  const credentials = [
3825
- await (0, import_credentials13.createCredential)({
3811
+ await (0, import_credentials12.createCredential)({
3826
3812
  signer: keyring,
3827
3813
  issuer: space.key,
3828
3814
  subject: space.key,
@@ -3831,14 +3817,14 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3831
3817
  spaceKey: space.key
3832
3818
  }
3833
3819
  }),
3834
- await (0, import_credentials13.createCredential)({
3820
+ await (0, import_credentials12.createCredential)({
3835
3821
  signer: keyring,
3836
3822
  issuer: space.key,
3837
3823
  subject: signingContext.identityKey,
3838
3824
  assertion: {
3839
3825
  "@type": "dxos.halo.credentials.SpaceMember",
3840
3826
  spaceKey: space.key,
3841
- role: import_credentials14.SpaceMember.Role.ADMIN,
3827
+ role: import_credentials13.SpaceMember.Role.ADMIN,
3842
3828
  profile: signingContext.getProfile(),
3843
3829
  genesisFeedKey: space.controlFeedKey ?? (0, import_debug4.failUndefined)()
3844
3830
  }
@@ -3850,7 +3836,7 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3850
3836
  spaceKey: space.key,
3851
3837
  identityKey: signingContext.identityKey,
3852
3838
  deviceKey: signingContext.deviceKey,
3853
- designation: import_credentials14.AdmittedFeed.Designation.CONTROL
3839
+ designation: import_credentials13.AdmittedFeed.Designation.CONTROL
3854
3840
  }
3855
3841
  }),
3856
3842
  await signingContext.credentialSigner.createCredential({
@@ -3860,7 +3846,7 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3860
3846
  spaceKey: space.key,
3861
3847
  identityKey: signingContext.identityKey,
3862
3848
  deviceKey: signingContext.deviceKey,
3863
- designation: import_credentials14.AdmittedFeed.Designation.DATA
3849
+ designation: import_credentials13.AdmittedFeed.Designation.DATA
3864
3850
  }
3865
3851
  }),
3866
3852
  await signingContext.credentialSigner.createCredential({
@@ -3894,7 +3880,7 @@ function _ts_decorate5(decorators, target, key, desc) {
3894
3880
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3895
3881
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3896
3882
  }
3897
- var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
3883
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
3898
3884
  var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
3899
3885
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
3900
3886
  var DataSpaceManager = class {
@@ -3905,7 +3891,7 @@ var DataSpaceManager = class {
3905
3891
  this._signingContext = _signingContext;
3906
3892
  this._feedStore = _feedStore;
3907
3893
  this._automergeHost = _automergeHost;
3908
- this._ctx = new import_context9.Context();
3894
+ this._ctx = new import_context8.Context();
3909
3895
  this.updated = new import_async13.Event();
3910
3896
  this._spaces = new import_util6.ComplexMap(import_keys9.PublicKey.hash);
3911
3897
  this._isOpen = false;
@@ -3920,15 +3906,15 @@ var DataSpaceManager = class {
3920
3906
  }
3921
3907
  async open() {
3922
3908
  (0, import_log10.log)("open", void 0, {
3923
- F: __dxlog_file13,
3909
+ F: __dxlog_file12,
3924
3910
  L: 98,
3925
3911
  S: this,
3926
3912
  C: (f, a) => f(...a)
3927
3913
  });
3928
- import_log10.log.trace("dxos.echo.data-space-manager.open", import_protocols10.trace.begin({
3914
+ import_log10.log.trace("dxos.echo.data-space-manager.open", import_protocols9.trace.begin({
3929
3915
  id: this._instanceId
3930
3916
  }), {
3931
- F: __dxlog_file13,
3917
+ F: __dxlog_file12,
3932
3918
  L: 99,
3933
3919
  S: this,
3934
3920
  C: (f, a) => f(...a)
@@ -3936,7 +3922,7 @@ var DataSpaceManager = class {
3936
3922
  (0, import_log10.log)("metadata loaded", {
3937
3923
  spaces: this._metadataStore.spaces.length
3938
3924
  }, {
3939
- F: __dxlog_file13,
3925
+ F: __dxlog_file12,
3940
3926
  L: 100,
3941
3927
  S: this,
3942
3928
  C: (f, a) => f(...a)
@@ -3946,7 +3932,7 @@ var DataSpaceManager = class {
3946
3932
  (0, import_log10.log)("load space", {
3947
3933
  spaceMetadata
3948
3934
  }, {
3949
- F: __dxlog_file13,
3935
+ F: __dxlog_file12,
3950
3936
  L: 104,
3951
3937
  S: this,
3952
3938
  C: (f, a) => f(...a)
@@ -3957,7 +3943,7 @@ var DataSpaceManager = class {
3957
3943
  spaceMetadata,
3958
3944
  err
3959
3945
  }, {
3960
- F: __dxlog_file13,
3946
+ F: __dxlog_file12,
3961
3947
  L: 107,
3962
3948
  S: this,
3963
3949
  C: (f, a) => f(...a)
@@ -3967,14 +3953,14 @@ var DataSpaceManager = class {
3967
3953
  this._isOpen = true;
3968
3954
  this.updated.emit();
3969
3955
  for (const space of this._spaces.values()) {
3970
- if (space.state !== import_services10.SpaceState.INACTIVE) {
3956
+ if (space.state !== import_services8.SpaceState.INACTIVE) {
3971
3957
  space.initializeDataPipelineAsync();
3972
3958
  }
3973
3959
  }
3974
- import_log10.log.trace("dxos.echo.data-space-manager.open", import_protocols10.trace.end({
3960
+ import_log10.log.trace("dxos.echo.data-space-manager.open", import_protocols9.trace.end({
3975
3961
  id: this._instanceId
3976
3962
  }), {
3977
- F: __dxlog_file13,
3963
+ F: __dxlog_file12,
3978
3964
  L: 120,
3979
3965
  S: this,
3980
3966
  C: (f, a) => f(...a)
@@ -3982,7 +3968,7 @@ var DataSpaceManager = class {
3982
3968
  }
3983
3969
  async close() {
3984
3970
  (0, import_log10.log)("close", void 0, {
3985
- F: __dxlog_file13,
3971
+ F: __dxlog_file12,
3986
3972
  L: 125,
3987
3973
  S: this,
3988
3974
  C: (f, a) => f(...a)
@@ -3997,8 +3983,8 @@ var DataSpaceManager = class {
3997
3983
  * Creates a new space writing the genesis credentials to the control feed.
3998
3984
  */
3999
3985
  async createSpace() {
4000
- (0, import_invariant12.invariant)(this._isOpen, "Not open.", {
4001
- F: __dxlog_file13,
3986
+ (0, import_invariant11.invariant)(this._isOpen, "Not open.", {
3987
+ F: __dxlog_file12,
4002
3988
  L: 138,
4003
3989
  S: this,
4004
3990
  A: [
@@ -4014,12 +4000,12 @@ var DataSpaceManager = class {
4014
4000
  genesisFeedKey: controlFeedKey,
4015
4001
  controlFeedKey,
4016
4002
  dataFeedKey,
4017
- state: import_services10.SpaceState.ACTIVE
4003
+ state: import_services8.SpaceState.ACTIVE
4018
4004
  };
4019
4005
  (0, import_log10.log)("creating space...", {
4020
4006
  spaceKey
4021
4007
  }, {
4022
- F: __dxlog_file13,
4008
+ F: __dxlog_file12,
4023
4009
  L: 150,
4024
4010
  S: this,
4025
4011
  C: (f, a) => f(...a)
@@ -4034,8 +4020,8 @@ var DataSpaceManager = class {
4034
4020
  const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRoot.url);
4035
4021
  await this._metadataStore.addSpace(metadata);
4036
4022
  const memberCredential = credentials[1];
4037
- (0, import_invariant12.invariant)((0, import_credentials12.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4038
- F: __dxlog_file13,
4023
+ (0, import_invariant11.invariant)((0, import_credentials11.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4024
+ F: __dxlog_file12,
4039
4025
  L: 163,
4040
4026
  S: this,
4041
4027
  A: [
@@ -4053,13 +4039,13 @@ var DataSpaceManager = class {
4053
4039
  (0, import_log10.log)("accept space", {
4054
4040
  opts
4055
4041
  }, {
4056
- F: __dxlog_file13,
4042
+ F: __dxlog_file12,
4057
4043
  L: 175,
4058
4044
  S: this,
4059
4045
  C: (f, a) => f(...a)
4060
4046
  });
4061
- (0, import_invariant12.invariant)(this._isOpen, "Not open.", {
4062
- F: __dxlog_file13,
4047
+ (0, import_invariant11.invariant)(this._isOpen, "Not open.", {
4048
+ F: __dxlog_file12,
4063
4049
  L: 176,
4064
4050
  S: this,
4065
4051
  A: [
@@ -4067,8 +4053,8 @@ var DataSpaceManager = class {
4067
4053
  "'Not open.'"
4068
4054
  ]
4069
4055
  });
4070
- (0, import_invariant12.invariant)(!this._spaces.has(opts.spaceKey), "Space already exists.", {
4071
- F: __dxlog_file13,
4056
+ (0, import_invariant11.invariant)(!this._spaces.has(opts.spaceKey), "Space already exists.", {
4057
+ F: __dxlog_file12,
4072
4058
  L: 177,
4073
4059
  S: this,
4074
4060
  A: [
@@ -4094,16 +4080,16 @@ var DataSpaceManager = class {
4094
4080
  * TODO(dmaretskyi): Consider removing.
4095
4081
  */
4096
4082
  async waitUntilSpaceReady(spaceKey) {
4097
- await (0, import_context9.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
4083
+ await (0, import_context8.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
4098
4084
  const space = this._spaces.get(spaceKey);
4099
- return !!space && space.state === import_services10.SpaceState.READY;
4085
+ return !!space && space.state === import_services8.SpaceState.READY;
4100
4086
  }));
4101
4087
  }
4102
4088
  async _constructSpace(metadata) {
4103
4089
  (0, import_log10.log)("construct space", {
4104
4090
  metadata
4105
4091
  }, {
4106
- F: __dxlog_file13,
4092
+ F: __dxlog_file12,
4107
4093
  L: 210,
4108
4094
  S: this,
4109
4095
  C: (f, a) => f(...a)
@@ -4141,7 +4127,7 @@ var DataSpaceManager = class {
4141
4127
  },
4142
4128
  onAuthFailure: () => {
4143
4129
  import_log10.log.warn("auth failure", void 0, {
4144
- F: __dxlog_file13,
4130
+ F: __dxlog_file12,
4145
4131
  L: 247,
4146
4132
  S: this,
4147
4133
  C: (f, a) => f(...a)
@@ -4153,7 +4139,7 @@ var DataSpaceManager = class {
4153
4139
  dataFeed && await space.setDataFeed(dataFeed);
4154
4140
  const dataSpace = new DataSpace({
4155
4141
  inner: space,
4156
- initialState: metadata.state === import_services10.SpaceState.INACTIVE ? import_services10.SpaceState.INACTIVE : import_services10.SpaceState.CLOSED,
4142
+ initialState: metadata.state === import_services8.SpaceState.INACTIVE ? import_services8.SpaceState.INACTIVE : import_services8.SpaceState.CLOSED,
4157
4143
  metadataStore: this._metadataStore,
4158
4144
  gossip,
4159
4145
  presence,
@@ -4165,7 +4151,7 @@ var DataSpaceManager = class {
4165
4151
  (0, import_log10.log)("before space ready", {
4166
4152
  space: space.key
4167
4153
  }, {
4168
- F: __dxlog_file13,
4154
+ F: __dxlog_file12,
4169
4155
  L: 265,
4170
4156
  S: this,
4171
4157
  C: (f, a) => f(...a)
@@ -4176,7 +4162,7 @@ var DataSpaceManager = class {
4176
4162
  space: space.key,
4177
4163
  open: this._isOpen
4178
4164
  }, {
4179
- F: __dxlog_file13,
4165
+ F: __dxlog_file12,
4180
4166
  L: 268,
4181
4167
  S: this,
4182
4168
  C: (f, a) => f(...a)
@@ -4189,7 +4175,7 @@ var DataSpaceManager = class {
4189
4175
  (0, import_log10.log)("before space close", {
4190
4176
  space: space.key
4191
4177
  }, {
4192
- F: __dxlog_file13,
4178
+ F: __dxlog_file12,
4193
4179
  L: 274,
4194
4180
  S: this,
4195
4181
  C: (f, a) => f(...a)
@@ -4199,7 +4185,7 @@ var DataSpaceManager = class {
4199
4185
  cache: metadata.cache,
4200
4186
  automergeHost: this._automergeHost
4201
4187
  });
4202
- if (metadata.state !== import_services10.SpaceState.INACTIVE) {
4188
+ if (metadata.state !== import_services8.SpaceState.INACTIVE) {
4203
4189
  await dataSpace.open();
4204
4190
  }
4205
4191
  if (metadata.controlTimeframe) {
@@ -4224,7 +4210,7 @@ _ts_decorate5([
4224
4210
  DataSpaceManager = _ts_decorate5([
4225
4211
  (0, import_async13.trackLeaks)("open", "close")
4226
4212
  ], DataSpaceManager);
4227
- var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
4213
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
4228
4214
  var SpacesServiceImpl = class {
4229
4215
  constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
4230
4216
  this._identityManager = _identityManager;
@@ -4241,29 +4227,29 @@ var SpacesServiceImpl = class {
4241
4227
  }
4242
4228
  async updateSpace({ spaceKey, state }) {
4243
4229
  const dataSpaceManager = await this._getDataSpaceManager();
4244
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4230
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols10.SpaceNotFoundError(spaceKey));
4245
4231
  if (state) {
4246
4232
  switch (state) {
4247
- case import_services11.SpaceState.ACTIVE:
4233
+ case import_services9.SpaceState.ACTIVE:
4248
4234
  await space.activate();
4249
4235
  break;
4250
- case import_services11.SpaceState.INACTIVE:
4236
+ case import_services9.SpaceState.INACTIVE:
4251
4237
  await space.deactivate();
4252
4238
  break;
4253
4239
  default:
4254
- throw new import_protocols11.ApiError("Invalid space state");
4240
+ throw new import_protocols10.ApiError("Invalid space state");
4255
4241
  }
4256
4242
  }
4257
4243
  }
4258
4244
  querySpaces() {
4259
- return new import_codec_protobuf11.Stream(({ next, ctx }) => {
4245
+ return new import_codec_protobuf10.Stream(({ next, ctx }) => {
4260
4246
  const scheduler = new import_async14.UpdateScheduler(ctx, async () => {
4261
4247
  const dataSpaceManager = await this._getDataSpaceManager();
4262
4248
  const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
4263
4249
  (0, import_log11.log)("update", {
4264
4250
  spaces
4265
4251
  }, {
4266
- F: __dxlog_file14,
4252
+ F: __dxlog_file13,
4267
4253
  L: 77,
4268
4254
  S: this,
4269
4255
  C: (f, a) => f(...a)
@@ -4303,14 +4289,14 @@ var SpacesServiceImpl = class {
4303
4289
  }
4304
4290
  async postMessage({ spaceKey, channel, message }) {
4305
4291
  const dataSpaceManager = await this._getDataSpaceManager();
4306
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4292
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols10.SpaceNotFoundError(spaceKey));
4307
4293
  await space.postMessage(getChannelId(channel), message);
4308
4294
  }
4309
4295
  subscribeMessages({ spaceKey, channel }) {
4310
- return new import_codec_protobuf11.Stream(({ ctx, next }) => {
4296
+ return new import_codec_protobuf10.Stream(({ ctx, next }) => {
4311
4297
  (0, import_async14.scheduleTask)(ctx, async () => {
4312
4298
  const dataSpaceManager = await this._getDataSpaceManager();
4313
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4299
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols10.SpaceNotFoundError(spaceKey));
4314
4300
  const handle = space.listen(getChannelId(channel), (message) => {
4315
4301
  next(message);
4316
4302
  });
@@ -4319,8 +4305,8 @@ var SpacesServiceImpl = class {
4319
4305
  });
4320
4306
  }
4321
4307
  queryCredentials({ spaceKey, noTail }) {
4322
- return new import_codec_protobuf11.Stream(({ ctx, next, close }) => {
4323
- const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4308
+ return new import_codec_protobuf10.Stream(({ ctx, next, close }) => {
4309
+ const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols10.SpaceNotFoundError(spaceKey));
4324
4310
  const processor = {
4325
4311
  processCredential: async (credential) => {
4326
4312
  next(credential);
@@ -4336,7 +4322,7 @@ var SpacesServiceImpl = class {
4336
4322
  });
4337
4323
  }
4338
4324
  async writeCredentials({ spaceKey, credentials }) {
4339
- const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4325
+ const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols10.SpaceNotFoundError(spaceKey));
4340
4326
  for (const credential of credentials ?? []) {
4341
4327
  if (credential.proof) {
4342
4328
  await space.controlPipeline.writer.write({
@@ -4345,8 +4331,8 @@ var SpacesServiceImpl = class {
4345
4331
  }
4346
4332
  });
4347
4333
  } else {
4348
- (0, import_invariant13.invariant)(!credential.id, "Id on unsigned credentials is not allowed", {
4349
- F: __dxlog_file14,
4334
+ (0, import_invariant12.invariant)(!credential.id, "Id on unsigned credentials is not allowed", {
4335
+ F: __dxlog_file13,
4350
4336
  L: 164,
4351
4337
  S: this,
4352
4338
  A: [
@@ -4354,8 +4340,8 @@ var SpacesServiceImpl = class {
4354
4340
  "'Id on unsigned credentials is not allowed'"
4355
4341
  ]
4356
4342
  });
4357
- (0, import_invariant13.invariant)(this._identityManager.identity, "Identity is not available", {
4358
- F: __dxlog_file14,
4343
+ (0, import_invariant12.invariant)(this._identityManager.identity, "Identity is not available", {
4344
+ F: __dxlog_file13,
4359
4345
  L: 165,
4360
4346
  S: this,
4361
4347
  A: [
@@ -4364,8 +4350,8 @@ var SpacesServiceImpl = class {
4364
4350
  ]
4365
4351
  });
4366
4352
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
4367
- (0, import_invariant13.invariant)(credential.issuer.equals(signer.getIssuer()), void 0, {
4368
- F: __dxlog_file14,
4353
+ (0, import_invariant12.invariant)(credential.issuer.equals(signer.getIssuer()), void 0, {
4354
+ F: __dxlog_file13,
4369
4355
  L: 167,
4370
4356
  S: this,
4371
4357
  A: [
@@ -4387,7 +4373,7 @@ var SpacesServiceImpl = class {
4387
4373
  }
4388
4374
  async createEpoch({ spaceKey, migration }) {
4389
4375
  const dataSpaceManager = await this._getDataSpaceManager();
4390
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4376
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols10.SpaceNotFoundError(spaceKey));
4391
4377
  await space.createEpoch({
4392
4378
  migration
4393
4379
  });
@@ -4396,7 +4382,7 @@ var SpacesServiceImpl = class {
4396
4382
  return {
4397
4383
  spaceKey: space.key,
4398
4384
  state: space.state,
4399
- error: space.error ? (0, import_protocols11.encodeError)(space.error) : void 0,
4385
+ error: space.error ? (0, import_protocols10.encodeError)(space.error) : void 0,
4400
4386
  pipeline: {
4401
4387
  currentEpoch: space.automergeSpaceState.lastEpoch,
4402
4388
  appliedEpoch: space.automergeSpaceState.lastEpoch,
@@ -4421,7 +4407,7 @@ var SpacesServiceImpl = class {
4421
4407
  identityKey: member.key,
4422
4408
  profile: member.profile ?? {}
4423
4409
  },
4424
- presence: member.removed ? import_services11.SpaceMember.PresenceState.REMOVED : isMe || peers.length > 0 ? import_services11.SpaceMember.PresenceState.ONLINE : import_services11.SpaceMember.PresenceState.OFFLINE,
4410
+ presence: member.removed ? import_services9.SpaceMember.PresenceState.REMOVED : isMe || peers.length > 0 ? import_services9.SpaceMember.PresenceState.ONLINE : import_services9.SpaceMember.PresenceState.OFFLINE,
4425
4411
  peerStates: peers
4426
4412
  };
4427
4413
  }),
@@ -4440,18 +4426,20 @@ var createSelectedDocumentsIterator = (automergeHost) => (
4440
4426
  // TODO(mykola): Unload automerge handles after usage.
4441
4427
  async function* loadDocuments(ids) {
4442
4428
  for (const id of ids) {
4443
- const { documentId, objectId } = import_protocols13.idCodec.decode(id);
4429
+ const { documentId, objectId } = import_protocols12.idCodec.decode(id);
4444
4430
  const handle = automergeHost.repo.find(documentId);
4445
- await (0, import_debug7.warnAfterTimeout)(5e3, "to long to load doc", () => handle.whenReady());
4431
+ if (!handle.isReady()) {
4432
+ await handle.whenReady();
4433
+ }
4446
4434
  const doc = handle.docSync();
4447
4435
  const hash = (0, import_automerge.getHeads)(doc).join("");
4448
- yield [
4436
+ yield doc.objects?.[objectId] ? [
4449
4437
  {
4450
4438
  id,
4451
4439
  object: doc.objects[objectId],
4452
4440
  currentHash: hash
4453
4441
  }
4454
- ];
4442
+ ] : [];
4455
4443
  }
4456
4444
  }
4457
4445
  );
@@ -4467,13 +4455,15 @@ var createDocumentsIterator = (automergeHost) => (
4467
4455
  if (visited.has(handle.documentId)) {
4468
4456
  return;
4469
4457
  }
4470
- await (0, import_debug7.warnAfterTimeout)(5e3, "to long to load doc", () => handle.whenReady());
4458
+ if (!handle.isReady()) {
4459
+ await handle.whenReady();
4460
+ }
4471
4461
  const doc = handle.docSync();
4472
4462
  const heads = (0, import_automerge.getHeads)(doc);
4473
4463
  if (doc.objects) {
4474
4464
  yield Object.entries(doc.objects).map(([objectId, object]) => {
4475
4465
  return {
4476
- id: import_protocols13.idCodec.encode({
4466
+ id: import_protocols12.idCodec.encode({
4477
4467
  documentId: handle.documentId,
4478
4468
  objectId
4479
4469
  }),
@@ -4516,18 +4506,20 @@ function _ts_decorate6(decorators, target, key, desc) {
4516
4506
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4517
4507
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4518
4508
  }
4519
- var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
4520
- var ServiceContext = class {
4521
- constructor(storage, networkManager, signalManager, _runtimeParams) {
4509
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
4510
+ var ServiceContext = class extends import_context9.Resource {
4511
+ constructor(storage, level, networkManager, signalManager, _runtimeParams) {
4512
+ super();
4522
4513
  this.storage = storage;
4514
+ this.level = level;
4523
4515
  this.networkManager = networkManager;
4524
4516
  this.signalManager = signalManager;
4525
4517
  this._runtimeParams = _runtimeParams;
4526
4518
  this.initialized = new import_async15.Trigger();
4527
4519
  this._handlerFactories = /* @__PURE__ */ new Map();
4528
4520
  this._instanceId = import_keys10.PublicKey.random().toHex();
4529
- this.metadataStore = new import_echo_pipeline3.MetadataStore(storage.createDirectory("metadata"));
4530
- this.snapshotStore = new import_echo_pipeline3.SnapshotStore(storage.createDirectory("snapshots"));
4521
+ this.metadataStore = new import_echo_pipeline4.MetadataStore(storage.createDirectory("metadata"));
4522
+ this.snapshotStore = new import_echo_pipeline4.SnapshotStore(storage.createDirectory("snapshots"));
4531
4523
  this.blobStore = new import_teleport_extension_object_sync.BlobStore(storage.createDirectory("blobs"));
4532
4524
  this.keyring = new import_keyring.Keyring(storage.createDirectory("keyring"));
4533
4525
  this.feedStore = new import_feed_store4.FeedStore({
@@ -4535,12 +4527,12 @@ var ServiceContext = class {
4535
4527
  root: storage.createDirectory("feeds"),
4536
4528
  signer: this.keyring,
4537
4529
  hypercore: {
4538
- valueEncoding: import_echo_pipeline3.valueEncoding,
4530
+ valueEncoding: import_echo_pipeline4.valueEncoding,
4539
4531
  stats: true
4540
4532
  }
4541
4533
  })
4542
4534
  });
4543
- this.spaceManager = new import_echo_pipeline3.SpaceManager({
4535
+ this.spaceManager = new import_echo_pipeline4.SpaceManager({
4544
4536
  feedStore: this.feedStore,
4545
4537
  networkManager: this.networkManager,
4546
4538
  blobStore: this.blobStore,
@@ -4549,66 +4541,81 @@ var ServiceContext = class {
4549
4541
  });
4550
4542
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager, this._runtimeParams);
4551
4543
  this.indexMetadata = new import_indexing.IndexMetadataStore({
4552
- directory: storage.createDirectory("index-metadata")
4544
+ db: level.sublevel("index-metadata")
4553
4545
  });
4554
- this.automergeHost = new import_echo_pipeline3.AutomergeHost({
4546
+ this.automergeHost = new import_echo_pipeline4.AutomergeHost({
4555
4547
  directory: storage.createDirectory("automerge"),
4556
- metadata: this.indexMetadata
4548
+ db: level.sublevel("automerge"),
4549
+ storageCallbacks: (0, import_indexing.createStorageCallbacks)({
4550
+ host: () => this.automergeHost,
4551
+ metadata: this.indexMetadata
4552
+ })
4557
4553
  });
4558
4554
  this.indexer = new import_indexing.Indexer({
4559
4555
  indexStore: new import_indexing.IndexStore({
4560
- directory: storage.createDirectory("index-store")
4556
+ db: level.sublevel("index-storage")
4561
4557
  }),
4562
4558
  metadataStore: this.indexMetadata,
4563
4559
  loadDocuments: createSelectedDocumentsIterator(this.automergeHost),
4564
4560
  getAllDocuments: createDocumentsIterator(this.automergeHost)
4565
4561
  });
4566
4562
  this.invitations = new InvitationsHandler(this.networkManager);
4567
- this._handlerFactories.set(import_services12.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug6.failUndefined)(), this._acceptIdentity.bind(this)));
4563
+ this.invitationsManager = new InvitationsManager(this.invitations, (invitation) => this.getInvitationHandler(invitation), this.metadataStore);
4564
+ this._handlerFactories.set(import_services10.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug6.failUndefined)(), this._acceptIdentity.bind(this)));
4568
4565
  }
4569
- async open(ctx) {
4566
+ async _open(ctx) {
4570
4567
  await this._checkStorageVersion();
4571
4568
  (0, import_log12.log)("opening...", void 0, {
4572
- F: __dxlog_file15,
4573
- L: 151,
4569
+ F: __dxlog_file14,
4570
+ L: 164,
4574
4571
  S: this,
4575
4572
  C: (f, a) => f(...a)
4576
4573
  });
4577
- import_log12.log.trace("dxos.sdk.service-context.open", import_protocols12.trace.begin({
4574
+ import_log12.log.trace("dxos.sdk.service-context.open", import_protocols11.trace.begin({
4578
4575
  id: this._instanceId
4579
4576
  }), {
4580
- F: __dxlog_file15,
4581
- L: 152,
4577
+ F: __dxlog_file14,
4578
+ L: 165,
4582
4579
  S: this,
4583
4580
  C: (f, a) => f(...a)
4584
4581
  });
4585
4582
  await this.signalManager.open();
4586
4583
  await this.networkManager.open();
4584
+ await this.automergeHost.open();
4587
4585
  await this.metadataStore.load();
4588
4586
  await this.spaceManager.open();
4589
4587
  await this.identityManager.open(ctx);
4590
4588
  if (this.identityManager.identity) {
4591
4589
  await this._initialize(ctx);
4592
4590
  }
4593
- import_log12.log.trace("dxos.sdk.service-context.open", import_protocols12.trace.end({
4591
+ const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
4592
+ (0, import_log12.log)("loaded persistent invitations", {
4593
+ count: loadedInvitations.invitations?.length
4594
+ }, {
4595
+ F: __dxlog_file14,
4596
+ L: 178,
4597
+ S: this,
4598
+ C: (f, a) => f(...a)
4599
+ });
4600
+ import_log12.log.trace("dxos.sdk.service-context.open", import_protocols11.trace.end({
4594
4601
  id: this._instanceId
4595
4602
  }), {
4596
- F: __dxlog_file15,
4597
- L: 162,
4603
+ F: __dxlog_file14,
4604
+ L: 180,
4598
4605
  S: this,
4599
4606
  C: (f, a) => f(...a)
4600
4607
  });
4601
4608
  (0, import_log12.log)("opened", void 0, {
4602
- F: __dxlog_file15,
4603
- L: 163,
4609
+ F: __dxlog_file14,
4610
+ L: 181,
4604
4611
  S: this,
4605
4612
  C: (f, a) => f(...a)
4606
4613
  });
4607
4614
  }
4608
- async close() {
4615
+ async _close() {
4609
4616
  (0, import_log12.log)("closing...", void 0, {
4610
- F: __dxlog_file15,
4611
- L: 167,
4617
+ F: __dxlog_file14,
4618
+ L: 185,
4612
4619
  S: this,
4613
4620
  C: (f, a) => f(...a)
4614
4621
  });
@@ -4625,22 +4632,22 @@ var ServiceContext = class {
4625
4632
  await this.metadataStore.close();
4626
4633
  await this.indexer.destroy();
4627
4634
  (0, import_log12.log)("closed", void 0, {
4628
- F: __dxlog_file15,
4629
- L: 180,
4635
+ F: __dxlog_file14,
4636
+ L: 198,
4630
4637
  S: this,
4631
4638
  C: (f, a) => f(...a)
4632
4639
  });
4633
4640
  }
4634
4641
  async createIdentity(params = {}) {
4635
4642
  const identity = await this.identityManager.createIdentity(params);
4636
- await this._initialize(new import_context10.Context());
4643
+ await this._initialize(new import_context9.Context());
4637
4644
  return identity;
4638
4645
  }
4639
4646
  getInvitationHandler(invitation) {
4640
4647
  const factory = this._handlerFactories.get(invitation.kind);
4641
- (0, import_invariant14.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
4642
- F: __dxlog_file15,
4643
- L: 191,
4648
+ (0, import_invariant13.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
4649
+ F: __dxlog_file14,
4650
+ L: 209,
4644
4651
  S: this,
4645
4652
  A: [
4646
4653
  "factory",
@@ -4659,20 +4666,20 @@ var ServiceContext = class {
4659
4666
  }
4660
4667
  async _acceptIdentity(params) {
4661
4668
  const identity = await this.identityManager.acceptIdentity(params);
4662
- await this._initialize(new import_context10.Context());
4669
+ await this._initialize(new import_context9.Context());
4663
4670
  return identity;
4664
4671
  }
4665
4672
  async _checkStorageVersion() {
4666
4673
  await this.metadataStore.load();
4667
- if (this.metadataStore.version !== import_protocols12.STORAGE_VERSION) {
4668
- throw new import_protocols12.InvalidStorageVersionError(import_protocols12.STORAGE_VERSION, this.metadataStore.version);
4674
+ if (this.metadataStore.version !== import_protocols11.STORAGE_VERSION) {
4675
+ throw new import_protocols11.InvalidStorageVersionError(import_protocols11.STORAGE_VERSION, this.metadataStore.version);
4669
4676
  }
4670
4677
  }
4671
4678
  // Called when identity is created.
4672
4679
  async _initialize(ctx) {
4673
4680
  (0, import_log12.log)("initializing spaces...", void 0, {
4674
- F: __dxlog_file15,
4675
- L: 222,
4681
+ F: __dxlog_file14,
4682
+ L: 240,
4676
4683
  S: this,
4677
4684
  C: (f, a) => f(...a)
4678
4685
  });
@@ -4692,10 +4699,10 @@ var ServiceContext = class {
4692
4699
  };
4693
4700
  this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.automergeHost, this._runtimeParams);
4694
4701
  await this.dataSpaceManager.open();
4695
- this._handlerFactories.set(import_services12.Invitation.Kind.SPACE, (invitation) => {
4696
- (0, import_invariant14.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4697
- F: __dxlog_file15,
4698
- L: 246,
4702
+ this._handlerFactories.set(import_services10.Invitation.Kind.SPACE, (invitation) => {
4703
+ (0, import_invariant13.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4704
+ F: __dxlog_file14,
4705
+ L: 264,
4699
4706
  S: this,
4700
4707
  A: [
4701
4708
  "this.dataSpaceManager",
@@ -4707,7 +4714,7 @@ var ServiceContext = class {
4707
4714
  this.initialized.wake();
4708
4715
  this._deviceSpaceSync = {
4709
4716
  processCredential: async (credential) => {
4710
- const assertion = (0, import_credentials15.getCredentialAssertion)(credential);
4717
+ const assertion = (0, import_credentials14.getCredentialAssertion)(credential);
4711
4718
  if (assertion["@type"] !== "dxos.halo.credentials.SpaceMember") {
4712
4719
  return;
4713
4720
  }
@@ -4718,8 +4725,8 @@ var ServiceContext = class {
4718
4725
  (0, import_log12.log)("dataSpaceManager not initialized yet, ignoring space admission", {
4719
4726
  details: assertion
4720
4727
  }, {
4721
- F: __dxlog_file15,
4722
- L: 262,
4728
+ F: __dxlog_file14,
4729
+ L: 280,
4723
4730
  S: this,
4724
4731
  C: (f, a) => f(...a)
4725
4732
  });
@@ -4729,8 +4736,8 @@ var ServiceContext = class {
4729
4736
  (0, import_log12.log)("space already exists, ignoring space admission", {
4730
4737
  details: assertion
4731
4738
  }, {
4732
- F: __dxlog_file15,
4733
- L: 266,
4739
+ F: __dxlog_file14,
4740
+ L: 284,
4734
4741
  S: this,
4735
4742
  C: (f, a) => f(...a)
4736
4743
  });
@@ -4740,8 +4747,8 @@ var ServiceContext = class {
4740
4747
  (0, import_log12.log)("accepting space recorded in halo", {
4741
4748
  details: assertion
4742
4749
  }, {
4743
- F: __dxlog_file15,
4744
- L: 271,
4750
+ F: __dxlog_file14,
4751
+ L: 289,
4745
4752
  S: this,
4746
4753
  C: (f, a) => f(...a)
4747
4754
  });
@@ -4751,8 +4758,8 @@ var ServiceContext = class {
4751
4758
  });
4752
4759
  } catch (err) {
4753
4760
  import_log12.log.catch(err, void 0, {
4754
- F: __dxlog_file15,
4755
- L: 277,
4761
+ F: __dxlog_file14,
4762
+ L: 295,
4756
4763
  S: this,
4757
4764
  C: (f, a) => f(...a)
4758
4765
  });
@@ -4763,14 +4770,14 @@ var ServiceContext = class {
4763
4770
  }
4764
4771
  };
4765
4772
  _ts_decorate6([
4766
- import_tracing6.trace.span()
4767
- ], ServiceContext.prototype, "open", null);
4773
+ import_tracing5.trace.span()
4774
+ ], ServiceContext.prototype, "_open", null);
4768
4775
  _ts_decorate6([
4769
- import_tracing6.trace.span()
4776
+ import_tracing5.trace.span()
4770
4777
  ], ServiceContext.prototype, "_initialize", null);
4771
4778
  ServiceContext = _ts_decorate6([
4772
4779
  (0, import_util7.safeInstanceof)("dxos.client-services.ServiceContext"),
4773
- import_tracing6.trace.resource()
4780
+ import_tracing5.trace.resource()
4774
4781
  ], ServiceContext);
4775
4782
  var ServiceRegistry = class {
4776
4783
  // prettier-ignore
@@ -4794,103 +4801,155 @@ var ServiceRegistry = class {
4794
4801
  delete this._handlers[name];
4795
4802
  }
4796
4803
  };
4797
- function _ts_decorate7(decorators, target, key, desc) {
4798
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4799
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
4800
- r = Reflect.decorate(decorators, target, key, desc);
4801
- else
4802
- for (var i = decorators.length - 1; i >= 0; i--)
4803
- if (d = decorators[i])
4804
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4805
- return c > 3 && r && Object.defineProperty(target, key, r), r;
4806
- }
4807
- var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/node.ts";
4808
- var Lock = class {
4809
- constructor({ lockKey: lockPath, onAcquire, onRelease }) {
4810
- this._lockPath = lockPath;
4811
- this._onAcquire = onAcquire;
4812
- this._onRelease = onRelease;
4813
- }
4814
- get lockKey() {
4815
- return this._lockPath;
4816
- }
4817
- async acquire() {
4818
- (0, import_log13.log)("acquiring lock...", void 0, {
4819
- F: __dxlog_file16,
4820
- L: 32,
4821
- S: this,
4822
- C: (f, a) => f(...a)
4823
- });
4824
- this._fileHandle = await import_lock_file.LockFile.acquire(this._lockPath);
4825
- await this._onAcquire?.();
4826
- (0, import_log13.log)("acquired lock", void 0, {
4827
- F: __dxlog_file16,
4828
- L: 37,
4829
- S: this,
4830
- C: (f, a) => f(...a)
4831
- });
4804
+ var DXOS_VERSION = "0.4.10-main.f937af6";
4805
+ var getPlatform = () => {
4806
+ if (process.browser) {
4807
+ if (typeof window !== "undefined") {
4808
+ const { userAgent } = window.navigator;
4809
+ return {
4810
+ type: import_services12.Platform.PLATFORM_TYPE.BROWSER,
4811
+ userAgent,
4812
+ uptime: Math.floor((Date.now() - window.performance.timeOrigin) / 1e3)
4813
+ };
4814
+ } else {
4815
+ return {
4816
+ type: import_services12.Platform.PLATFORM_TYPE.SHARED_WORKER,
4817
+ uptime: Math.floor((Date.now() - performance.timeOrigin) / 1e3)
4818
+ };
4819
+ }
4820
+ } else {
4821
+ const { platform: platform2, version, arch } = process;
4822
+ return {
4823
+ type: import_services12.Platform.PLATFORM_TYPE.NODE,
4824
+ platform: platform2,
4825
+ arch,
4826
+ runtime: version,
4827
+ uptime: Math.floor(process.uptime()),
4828
+ memory: process.memoryUsage()
4829
+ };
4832
4830
  }
4833
- async release() {
4834
- await this._onRelease?.();
4835
- (0, import_invariant15.invariant)(this._fileHandle, "Lock is not acquired", {
4836
- F: __dxlog_file16,
4837
- L: 42,
4838
- S: this,
4831
+ };
4832
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts";
4833
+ var DEFAULT_TIMEOUT = 1e3;
4834
+ var createDiagnostics = async (clientServices, serviceContext, config) => {
4835
+ const diagnostics = {
4836
+ created: (/* @__PURE__ */ new Date()).toISOString(),
4837
+ platform: getPlatform(),
4838
+ client: {
4839
+ version: DXOS_VERSION,
4840
+ storage: {
4841
+ version: import_protocols13.STORAGE_VERSION
4842
+ }
4843
+ },
4844
+ trace: import_tracing6.TRACE_PROCESSOR.getDiagnostics()
4845
+ };
4846
+ {
4847
+ (0, import_invariant14.invariant)(clientServices.LoggingService, "SystemService is not available.", {
4848
+ F: __dxlog_file15,
4849
+ L: 108,
4850
+ S: void 0,
4839
4851
  A: [
4840
- "this._fileHandle",
4841
- "'Lock is not acquired'"
4852
+ "clientServices.LoggingService",
4853
+ "'SystemService is not available.'"
4842
4854
  ]
4843
4855
  });
4844
- await import_lock_file.LockFile.release(this._fileHandle);
4845
- }
4846
- };
4847
- _ts_decorate7([
4848
- import_log13.logInfo
4849
- ], Lock.prototype, "lockKey", null);
4850
- var isLocked = (lockPath) => import_lock_file.LockFile.isLocked(lockPath);
4851
- var StorageDriver = import_config.Runtime.Client.Storage.StorageDriver;
4852
- var createStorageObjects = (config) => {
4853
- const { persistent = false, keyStore, dataStore, dataRoot = (0, import_util8.isNode)() ? import_client_protocol4.DX_DATA : "dxos/storage" } = config ?? {};
4854
- if (persistent && dataStore === StorageDriver.RAM) {
4855
- throw new import_protocols14.InvalidConfigError("RAM storage cannot be used in persistent mode.");
4856
+ diagnostics.metrics = await (0, import_codec_protobuf11.getFirstStreamValue)(clientServices.LoggingService.queryMetrics({}), {
4857
+ timeout: DEFAULT_TIMEOUT
4858
+ }).catch(() => void 0);
4856
4859
  }
4857
- if (!persistent && dataStore !== void 0 && dataStore !== StorageDriver.RAM) {
4858
- throw new import_protocols14.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
4860
+ if (typeof navigator !== "undefined" && navigator.storage) {
4861
+ const map = /* @__PURE__ */ new Map();
4862
+ const dir = await navigator.storage.getDirectory();
4863
+ for await (const filename of dir?.keys()) {
4864
+ const idx = filename.indexOf("-", filename.indexOf("-") + 1);
4865
+ if (idx === -1) {
4866
+ continue;
4867
+ }
4868
+ map.set(filename.slice(0, idx), (map.get(filename.slice(0, idx)) ?? 0) + 1);
4869
+ }
4870
+ diagnostics.storage = Array.from(map.entries()).sort((a, b) => b[1] - a[1]).map(([file, count]) => ({
4871
+ file,
4872
+ count
4873
+ }));
4859
4874
  }
4860
- if (persistent && keyStore === StorageDriver.RAM) {
4861
- throw new import_protocols14.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
4875
+ const identity = serviceContext.identityManager.identity;
4876
+ if (identity) {
4877
+ diagnostics.identity = {
4878
+ identityKey: identity.identityKey,
4879
+ spaceKey: identity.space.key,
4880
+ profile: identity.profileDocument
4881
+ };
4882
+ const { devices } = await (0, import_codec_protobuf11.getFirstStreamValue)(clientServices.DevicesService.queryDevices(), {
4883
+ timeout: DEFAULT_TIMEOUT
4884
+ }).catch(() => void 0) ?? {};
4885
+ diagnostics.devices = devices;
4886
+ if (serviceContext.dataSpaceManager) {
4887
+ diagnostics.spaces = await Promise.all(Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space)) ?? []);
4888
+ }
4889
+ const { feeds = [] } = await (0, import_codec_protobuf11.getFirstStreamValue)(clientServices.DevtoolsHost.subscribeToFeeds({}), {
4890
+ timeout: DEFAULT_TIMEOUT
4891
+ }).catch(() => void 0) ?? {};
4892
+ diagnostics.feeds = feeds.map(({ feedKey, bytes, length }) => ({
4893
+ feedKey,
4894
+ bytes,
4895
+ length
4896
+ }));
4897
+ const status = await (0, import_codec_protobuf11.getFirstStreamValue)(clientServices.NetworkService.queryStatus(), {
4898
+ timeout: DEFAULT_TIMEOUT
4899
+ }).catch(() => void 0);
4900
+ diagnostics.networkStatus = status;
4901
+ diagnostics.swarms = serviceContext.networkManager.connectionLog?.swarms;
4862
4902
  }
4863
- if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== void 0) {
4864
- throw new import_protocols14.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
4903
+ diagnostics.config = config.values;
4904
+ return diagnostics;
4905
+ };
4906
+ var getSpaceStats = async (space) => {
4907
+ const stats = {
4908
+ key: space.key,
4909
+ metrics: space.metrics,
4910
+ epochs: space.inner.spaceState.credentials.filter((0, import_credentials15.credentialTypeFilter)("dxos.halo.credentials.Epoch")).map((credential) => ({
4911
+ ...credential.subject.assertion,
4912
+ id: credential.id
4913
+ })),
4914
+ members: Array.from(space.inner.spaceState.members.values()).map((member) => ({
4915
+ identity: {
4916
+ identityKey: member.key,
4917
+ profile: {
4918
+ displayName: member.assertion.profile?.displayName
4919
+ }
4920
+ },
4921
+ presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? import_services11.SpaceMember.PresenceState.ONLINE : import_services11.SpaceMember.PresenceState.OFFLINE
4922
+ })),
4923
+ pipeline: {
4924
+ // TODO(burdon): Pick properties from credentials if needed.
4925
+ currentEpoch: space.automergeSpaceState.lastEpoch,
4926
+ appliedEpoch: space.automergeSpaceState.lastEpoch,
4927
+ controlFeeds: space.inner.controlPipeline.state.feeds.map((feed) => feed.key),
4928
+ currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
4929
+ targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
4930
+ totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe
4931
+ }
4932
+ };
4933
+ if (stats.metrics) {
4934
+ const { open, ready } = stats.metrics;
4935
+ stats.metrics.startupTime = open && ready && ready.getTime() - open.getTime();
4865
4936
  }
4937
+ return stats;
4938
+ };
4939
+ var createCollectDiagnosticsBroadcastSender = () => {
4866
4940
  return {
4867
- storage: (0, import_random_access_storage.createStorage)({
4868
- type: persistent ? toStorageType(dataStore) : import_random_access_storage.StorageType.RAM,
4869
- root: `${dataRoot}/`
4870
- })
4941
+ broadcastDiagnosticsRequest: async () => void 0
4871
4942
  };
4872
4943
  };
4873
- var toStorageType = (type) => {
4874
- switch (type) {
4875
- case void 0:
4876
- return void 0;
4877
- case StorageDriver.RAM:
4878
- return import_random_access_storage.StorageType.RAM;
4879
- case StorageDriver.CHROME:
4880
- return import_random_access_storage.StorageType.CHROME;
4881
- case StorageDriver.FIREFOX:
4882
- return import_random_access_storage.StorageType.FIREFOX;
4883
- case StorageDriver.IDB:
4884
- return import_random_access_storage.StorageType.IDB;
4885
- case StorageDriver.NODE:
4886
- return import_random_access_storage.StorageType.NODE;
4887
- case StorageDriver.WEBFS:
4888
- return import_random_access_storage.StorageType.WEBFS;
4889
- default:
4890
- throw new Error(`Invalid storage type: ${StorageDriver[type]}`);
4891
- }
4944
+ var createCollectDiagnosticsBroadcastHandler = (_) => {
4945
+ return {
4946
+ start: () => {
4947
+ },
4948
+ stop: () => {
4949
+ }
4950
+ };
4892
4951
  };
4893
- var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
4952
+ var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
4894
4953
  var DevicesServiceImpl = class {
4895
4954
  constructor(_identityManager) {
4896
4955
  this._identityManager = _identityManager;
@@ -4907,8 +4966,8 @@ var DevicesServiceImpl = class {
4907
4966
  devices: []
4908
4967
  });
4909
4968
  } else {
4910
- (0, import_invariant17.invariant)(this._identityManager.identity?.presence, "presence not present", {
4911
- F: __dxlog_file17,
4969
+ (0, import_invariant16.invariant)(this._identityManager.identity?.presence, "presence not present", {
4970
+ F: __dxlog_file16,
4912
4971
  L: 32,
4913
4972
  S: this,
4914
4973
  A: [
@@ -4923,9 +4982,9 @@ var DevicesServiceImpl = class {
4923
4982
  const peerState = peers.find((peer) => peer.identityKey.equals(key));
4924
4983
  return {
4925
4984
  deviceKey: key,
4926
- kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services14.DeviceKind.CURRENT : import_services14.DeviceKind.TRUSTED,
4985
+ kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services15.DeviceKind.CURRENT : import_services15.DeviceKind.TRUSTED,
4927
4986
  profile,
4928
- presence: isMe ? import_services14.Device.PresenceState.ONLINE : peerState ? import_services14.Device.PresenceState.ONLINE : import_services14.Device.PresenceState.OFFLINE
4987
+ presence: isMe ? import_services15.Device.PresenceState.ONLINE : peerState ? import_services15.Device.PresenceState.ONLINE : import_services15.Device.PresenceState.OFFLINE
4929
4988
  };
4930
4989
  })
4931
4990
  });
@@ -4966,6 +5025,60 @@ var DevicesServiceImpl = class {
4966
5025
  });
4967
5026
  }
4968
5027
  };
5028
+ function _ts_decorate7(decorators, target, key, desc) {
5029
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5030
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
5031
+ r = Reflect.decorate(decorators, target, key, desc);
5032
+ else
5033
+ for (var i = decorators.length - 1; i >= 0; i--)
5034
+ if (d = decorators[i])
5035
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5036
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
5037
+ }
5038
+ var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/node.ts";
5039
+ var Lock = class {
5040
+ constructor({ lockKey: lockPath, onAcquire, onRelease }) {
5041
+ this._lockPath = lockPath;
5042
+ this._onAcquire = onAcquire;
5043
+ this._onRelease = onRelease;
5044
+ }
5045
+ get lockKey() {
5046
+ return this._lockPath;
5047
+ }
5048
+ async acquire() {
5049
+ (0, import_log14.log)("acquiring lock...", void 0, {
5050
+ F: __dxlog_file17,
5051
+ L: 32,
5052
+ S: this,
5053
+ C: (f, a) => f(...a)
5054
+ });
5055
+ this._fileHandle = await import_lock_file.LockFile.acquire(this._lockPath);
5056
+ await this._onAcquire?.();
5057
+ (0, import_log14.log)("acquired lock", void 0, {
5058
+ F: __dxlog_file17,
5059
+ L: 37,
5060
+ S: this,
5061
+ C: (f, a) => f(...a)
5062
+ });
5063
+ }
5064
+ async release() {
5065
+ await this._onRelease?.();
5066
+ (0, import_invariant17.invariant)(this._fileHandle, "Lock is not acquired", {
5067
+ F: __dxlog_file17,
5068
+ L: 42,
5069
+ S: this,
5070
+ A: [
5071
+ "this._fileHandle",
5072
+ "'Lock is not acquired'"
5073
+ ]
5074
+ });
5075
+ await import_lock_file.LockFile.release(this._fileHandle);
5076
+ }
5077
+ };
5078
+ _ts_decorate7([
5079
+ import_log14.logInfo
5080
+ ], Lock.prototype, "lockKey", null);
5081
+ var isLocked = (lockPath) => import_lock_file.LockFile.isLocked(lockPath);
4969
5082
  var LoggingServiceImpl = class {
4970
5083
  constructor() {
4971
5084
  this._logs = new import_async18.Event();
@@ -5065,18 +5178,18 @@ var LoggingServiceImpl = class {
5065
5178
  });
5066
5179
  }
5067
5180
  };
5068
- var matchFilter = (filter, level, path, options) => {
5181
+ var matchFilter = (filter, level, path2, options) => {
5069
5182
  switch (options) {
5070
- case import_services15.QueryLogsRequest.MatchingOptions.INCLUSIVE:
5071
- return level >= filter.level && (!filter.pattern || path.includes(filter.pattern));
5072
- case import_services15.QueryLogsRequest.MatchingOptions.EXPLICIT:
5073
- return level === filter.level && (!filter.pattern || path.includes(filter.pattern));
5183
+ case import_services16.QueryLogsRequest.MatchingOptions.INCLUSIVE:
5184
+ return level >= filter.level && (!filter.pattern || path2.includes(filter.pattern));
5185
+ case import_services16.QueryLogsRequest.MatchingOptions.EXPLICIT:
5186
+ return level === filter.level && (!filter.pattern || path2.includes(filter.pattern));
5074
5187
  }
5075
5188
  };
5076
5189
  var shouldLog = (entry2, request) => {
5077
- const options = request.options ?? import_services15.QueryLogsRequest.MatchingOptions.INCLUSIVE;
5190
+ const options = request.options ?? import_services16.QueryLogsRequest.MatchingOptions.INCLUSIVE;
5078
5191
  if (request.filters === void 0) {
5079
- return options === import_services15.QueryLogsRequest.MatchingOptions.INCLUSIVE;
5192
+ return options === import_services16.QueryLogsRequest.MatchingOptions.INCLUSIVE;
5080
5193
  } else {
5081
5194
  return request.filters.some((filter) => matchFilter(filter, entry2.level, entry2.meta?.F ?? "", options));
5082
5195
  }
@@ -5112,6 +5225,63 @@ var NetworkServiceImpl = class {
5112
5225
  await this.networkManager.setConnectionState(request.swarm);
5113
5226
  }
5114
5227
  };
5228
+ var getRootPath = (config) => {
5229
+ const { dataRoot = (0, import_util11.isNode)() ? import_client_protocol5.DX_DATA : "dxos/storage" } = config ?? {};
5230
+ return `${dataRoot}/`;
5231
+ };
5232
+ var isPersistent = (config) => {
5233
+ const { persistent = false } = config ?? {};
5234
+ return config.dataStore !== void 0 && config.dataStore !== import_config3.Runtime.Client.Storage.StorageDriver.RAM || persistent;
5235
+ };
5236
+ var StorageDriver = import_config2.Runtime.Client.Storage.StorageDriver;
5237
+ var createStorageObjects = (config) => {
5238
+ const { persistent = false, keyStore, dataStore } = config ?? {};
5239
+ if (persistent && dataStore === StorageDriver.RAM) {
5240
+ throw new import_protocols15.InvalidConfigError("RAM storage cannot be used in persistent mode.");
5241
+ }
5242
+ if (!persistent && dataStore !== void 0 && dataStore !== StorageDriver.RAM) {
5243
+ throw new import_protocols15.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
5244
+ }
5245
+ if (persistent && keyStore === StorageDriver.RAM) {
5246
+ throw new import_protocols15.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
5247
+ }
5248
+ if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== void 0) {
5249
+ throw new import_protocols15.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
5250
+ }
5251
+ return {
5252
+ storage: (0, import_random_access_storage.createStorage)({
5253
+ type: persistent ? toStorageType(dataStore) : import_random_access_storage.StorageType.RAM,
5254
+ root: getRootPath(config)
5255
+ })
5256
+ };
5257
+ };
5258
+ var toStorageType = (type) => {
5259
+ switch (type) {
5260
+ case void 0:
5261
+ return void 0;
5262
+ case StorageDriver.RAM:
5263
+ return import_random_access_storage.StorageType.RAM;
5264
+ case StorageDriver.CHROME:
5265
+ return import_random_access_storage.StorageType.CHROME;
5266
+ case StorageDriver.FIREFOX:
5267
+ return import_random_access_storage.StorageType.FIREFOX;
5268
+ case StorageDriver.IDB:
5269
+ return import_random_access_storage.StorageType.IDB;
5270
+ case StorageDriver.NODE:
5271
+ return import_random_access_storage.StorageType.NODE;
5272
+ case StorageDriver.WEBFS:
5273
+ return import_random_access_storage.StorageType.WEBFS;
5274
+ default:
5275
+ throw new Error(`Invalid storage type: ${StorageDriver[type]}`);
5276
+ }
5277
+ };
5278
+ var createLevel = async (config) => {
5279
+ const persistent = isPersistent(config);
5280
+ const storagePath = persistent ? import_node_path.default.join(getRootPath(config), "level") : `/tmp/dxos-${import_keys13.PublicKey.random().toHex()}`;
5281
+ const level = new import_level.Level(storagePath);
5282
+ await level.open();
5283
+ return level;
5284
+ };
5115
5285
  var SystemServiceImpl = class {
5116
5286
  constructor({ config, statusUpdate, getDiagnostics, onUpdateStatus, getCurrentStatus, onReset }) {
5117
5287
  this._config = config;
@@ -5131,9 +5301,9 @@ var SystemServiceImpl = class {
5131
5301
  const diagnostics = await this._getDiagnostics();
5132
5302
  return {
5133
5303
  timestamp: /* @__PURE__ */ new Date(),
5134
- diagnostics: JSON.parse(JSON.stringify(diagnostics, (0, import_util11.jsonKeyReplacer)({
5135
- truncate: keys === import_services16.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
5136
- humanize: keys === import_services16.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
5304
+ diagnostics: JSON.parse(JSON.stringify(diagnostics, (0, import_util12.jsonKeyReplacer)({
5305
+ truncate: keys === import_services17.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
5306
+ humanize: keys === import_services17.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
5137
5307
  })))
5138
5308
  };
5139
5309
  }
@@ -5181,16 +5351,18 @@ var ClientServicesHost = class {
5181
5351
  transportFactory,
5182
5352
  signalManager,
5183
5353
  storage,
5354
+ level,
5184
5355
  // TODO(wittjosiah): Turn this on by default.
5185
5356
  lockKey,
5186
5357
  callbacks,
5187
5358
  runtimeParams
5188
5359
  } = {}) {
5189
- this._tracingService = import_tracing7.TRACE_PROCESSOR.createTraceSender();
5360
+ this._tracingService = import_tracing8.TRACE_PROCESSOR.createTraceSender();
5190
5361
  this._statusUpdate = new import_async16.Event();
5191
5362
  this._opening = false;
5192
5363
  this._open = false;
5193
5364
  this._storage = storage;
5365
+ this._level = level;
5194
5366
  this._callbacks = callbacks;
5195
5367
  this._runtimeParams = runtimeParams;
5196
5368
  if (config) {
@@ -5205,7 +5377,7 @@ var ClientServicesHost = class {
5205
5377
  lockKey,
5206
5378
  onAcquire: () => {
5207
5379
  if (!this._opening) {
5208
- void this.open(new import_context11.Context());
5380
+ void this.open(new import_context10.Context());
5209
5381
  }
5210
5382
  },
5211
5383
  onRelease: () => this.close()
@@ -5214,14 +5386,14 @@ var ClientServicesHost = class {
5214
5386
  this._systemService = new SystemServiceImpl({
5215
5387
  config: () => this._config,
5216
5388
  statusUpdate: this._statusUpdate,
5217
- getCurrentStatus: () => this.isOpen ? import_services13.SystemStatus.ACTIVE : import_services13.SystemStatus.INACTIVE,
5389
+ getCurrentStatus: () => this.isOpen ? import_services14.SystemStatus.ACTIVE : import_services14.SystemStatus.INACTIVE,
5218
5390
  getDiagnostics: () => {
5219
5391
  return createDiagnostics(this._serviceRegistry.services, this._serviceContext, this._config);
5220
5392
  },
5221
5393
  onUpdateStatus: async (status) => {
5222
- if (!this.isOpen && status === import_services13.SystemStatus.ACTIVE) {
5394
+ if (!this.isOpen && status === import_services14.SystemStatus.ACTIVE) {
5223
5395
  await this._resourceLock?.acquire();
5224
- } else if (this.isOpen && status === import_services13.SystemStatus.INACTIVE) {
5396
+ } else if (this.isOpen && status === import_services14.SystemStatus.INACTIVE) {
5225
5397
  await this._resourceLock?.release();
5226
5398
  }
5227
5399
  },
@@ -5229,8 +5401,9 @@ var ClientServicesHost = class {
5229
5401
  await this.reset();
5230
5402
  }
5231
5403
  });
5404
+ this.diagnosticsBroadcastHandler = createCollectDiagnosticsBroadcastHandler(this._systemService);
5232
5405
  this._loggingService = new LoggingServiceImpl();
5233
- this._serviceRegistry = new ServiceRegistry(import_client_protocol5.clientServiceBundle, {
5406
+ this._serviceRegistry = new ServiceRegistry(import_client_protocol4.clientServiceBundle, {
5234
5407
  SystemService: this._systemService,
5235
5408
  TracingService: this._tracingService
5236
5409
  });
@@ -5259,25 +5432,25 @@ var ClientServicesHost = class {
5259
5432
  * Can only be called once.
5260
5433
  */
5261
5434
  initialize({ config, ...options }) {
5262
- (0, import_invariant16.invariant)(!this._open, "service host is open", {
5435
+ (0, import_invariant15.invariant)(!this._open, "service host is open", {
5263
5436
  F: __dxlog_file18,
5264
- L: 180,
5437
+ L: 197,
5265
5438
  S: this,
5266
5439
  A: [
5267
5440
  "!this._open",
5268
5441
  "'service host is open'"
5269
5442
  ]
5270
5443
  });
5271
- (0, import_log14.log)("initializing...", void 0, {
5444
+ (0, import_log13.log)("initializing...", void 0, {
5272
5445
  F: __dxlog_file18,
5273
- L: 181,
5446
+ L: 198,
5274
5447
  S: this,
5275
5448
  C: (f, a) => f(...a)
5276
5449
  });
5277
5450
  if (config) {
5278
- (0, import_invariant16.invariant)(!this._config, "config already set", {
5451
+ (0, import_invariant15.invariant)(!this._config, "config already set", {
5279
5452
  F: __dxlog_file18,
5280
- L: 184,
5453
+ L: 201,
5281
5454
  S: this,
5282
5455
  A: [
5283
5456
  "!this._config",
@@ -5290,9 +5463,9 @@ var ClientServicesHost = class {
5290
5463
  }
5291
5464
  }
5292
5465
  if (!options.signalManager) {
5293
- import_log14.log.warn("running signaling without telemetry metadata.", void 0, {
5466
+ import_log13.log.warn("running signaling without telemetry metadata.", void 0, {
5294
5467
  F: __dxlog_file18,
5295
- L: 192,
5468
+ L: 209,
5296
5469
  S: this,
5297
5470
  C: (f, a) => f(...a)
5298
5471
  });
@@ -5301,9 +5474,9 @@ var ClientServicesHost = class {
5301
5474
  iceServers: this._config?.get("runtime.services.ice")
5302
5475
  }), signalManager = new import_messaging.WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
5303
5476
  this._signalManager = signalManager;
5304
- (0, import_invariant16.invariant)(!this._networkManager, "network manager already set", {
5477
+ (0, import_invariant15.invariant)(!this._networkManager, "network manager already set", {
5305
5478
  F: __dxlog_file18,
5306
- L: 203,
5479
+ L: 220,
5307
5480
  S: this,
5308
5481
  A: [
5309
5482
  "!this._networkManager",
@@ -5315,9 +5488,9 @@ var ClientServicesHost = class {
5315
5488
  transportFactory,
5316
5489
  signalManager
5317
5490
  });
5318
- (0, import_log14.log)("initialized", void 0, {
5491
+ (0, import_log13.log)("initialized", void 0, {
5319
5492
  F: __dxlog_file18,
5320
- L: 210,
5493
+ L: 227,
5321
5494
  S: this,
5322
5495
  C: (f, a) => f(...a)
5323
5496
  });
@@ -5327,44 +5500,44 @@ var ClientServicesHost = class {
5327
5500
  return;
5328
5501
  }
5329
5502
  const traceId = import_keys11.PublicKey.random().toHex();
5330
- import_log14.log.trace("dxos.client-services.host.open", import_protocols15.trace.begin({
5503
+ import_log13.log.trace("dxos.client-services.host.open", import_protocols14.trace.begin({
5331
5504
  id: traceId
5332
5505
  }), {
5333
5506
  F: __dxlog_file18,
5334
- L: 221,
5507
+ L: 238,
5335
5508
  S: this,
5336
5509
  C: (f, a) => f(...a)
5337
5510
  });
5338
- (0, import_invariant16.invariant)(this._config, "config not set", {
5511
+ (0, import_invariant15.invariant)(this._config, "config not set", {
5339
5512
  F: __dxlog_file18,
5340
- L: 223,
5513
+ L: 240,
5341
5514
  S: this,
5342
5515
  A: [
5343
5516
  "this._config",
5344
5517
  "'config not set'"
5345
5518
  ]
5346
5519
  });
5347
- (0, import_invariant16.invariant)(this._storage, "storage not set", {
5520
+ (0, import_invariant15.invariant)(this._storage, "storage not set", {
5348
5521
  F: __dxlog_file18,
5349
- L: 224,
5522
+ L: 241,
5350
5523
  S: this,
5351
5524
  A: [
5352
5525
  "this._storage",
5353
5526
  "'storage not set'"
5354
5527
  ]
5355
5528
  });
5356
- (0, import_invariant16.invariant)(this._signalManager, "signal manager not set", {
5529
+ (0, import_invariant15.invariant)(this._signalManager, "signal manager not set", {
5357
5530
  F: __dxlog_file18,
5358
- L: 225,
5531
+ L: 242,
5359
5532
  S: this,
5360
5533
  A: [
5361
5534
  "this._signalManager",
5362
5535
  "'signal manager not set'"
5363
5536
  ]
5364
5537
  });
5365
- (0, import_invariant16.invariant)(this._networkManager, "network manager not set", {
5538
+ (0, import_invariant15.invariant)(this._networkManager, "network manager not set", {
5366
5539
  F: __dxlog_file18,
5367
- L: 226,
5540
+ L: 243,
5368
5541
  S: this,
5369
5542
  A: [
5370
5543
  "this._networkManager",
@@ -5372,27 +5545,31 @@ var ClientServicesHost = class {
5372
5545
  ]
5373
5546
  });
5374
5547
  this._opening = true;
5375
- (0, import_log14.log)("opening...", {
5548
+ (0, import_log13.log)("opening...", {
5376
5549
  lockKey: this._resourceLock?.lockKey
5377
5550
  }, {
5378
5551
  F: __dxlog_file18,
5379
- L: 229,
5552
+ L: 246,
5380
5553
  S: this,
5381
5554
  C: (f, a) => f(...a)
5382
5555
  });
5556
+ if (!this._level) {
5557
+ this._level = await createLevel(this._config.get("runtime.client.storage", {}));
5558
+ }
5559
+ await this._level.open();
5383
5560
  await this._resourceLock?.acquire();
5384
5561
  await this._loggingService.open();
5385
- this._serviceContext = new ServiceContext(this._storage, this._networkManager, this._signalManager, this._runtimeParams);
5562
+ this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._runtimeParams);
5386
5563
  this._serviceRegistry.setServices({
5387
5564
  SystemService: this._systemService,
5388
5565
  IdentityService: new IdentityServiceImpl((params) => this._createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring, (profile) => this._serviceContext.broadcastProfileUpdate(profile)),
5389
- InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitations, (invitation) => this._serviceContext.getInvitationHandler(invitation), this._serviceContext.metadataStore),
5566
+ InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitationsManager),
5390
5567
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
5391
5568
  SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, async () => {
5392
5569
  await this._serviceContext.initialized.wait();
5393
5570
  return this._serviceContext.dataSpaceManager;
5394
5571
  }),
5395
- DataService: new import_echo_pipeline4.DataServiceImpl(this._serviceContext.automergeHost),
5572
+ DataService: new import_echo_pipeline5.DataServiceImpl(this._serviceContext.automergeHost),
5396
5573
  IndexService: new import_indexing2.IndexServiceImpl({
5397
5574
  indexer: this._serviceContext.indexer,
5398
5575
  automergeHost: this._serviceContext.automergeHost
@@ -5408,51 +5585,34 @@ var ClientServicesHost = class {
5408
5585
  })
5409
5586
  });
5410
5587
  await this._serviceContext.open(ctx);
5411
- (0, import_invariant16.invariant)(this.serviceRegistry.services.InvitationsService, void 0, {
5412
- F: __dxlog_file18,
5413
- L: 290,
5414
- S: this,
5415
- A: [
5416
- "this.serviceRegistry.services.InvitationsService",
5417
- ""
5418
- ]
5419
- });
5420
- const loadedInvitations = await this.serviceRegistry.services.InvitationsService.loadPersistentInvitations();
5421
- (0, import_log14.log)("loaded persistent invitations", {
5422
- count: loadedInvitations.invitations?.length
5423
- }, {
5424
- F: __dxlog_file18,
5425
- L: 293,
5426
- S: this,
5427
- C: (f, a) => f(...a)
5428
- });
5429
5588
  const devtoolsProxy = this._config?.get("runtime.client.devtoolsProxy");
5430
5589
  if (devtoolsProxy) {
5431
5590
  this._devtoolsProxy = new import_websocket_rpc.WebsocketRpcClient({
5432
5591
  url: devtoolsProxy,
5433
5592
  requested: {},
5434
- exposed: import_client_protocol5.clientServiceBundle,
5593
+ exposed: import_client_protocol4.clientServiceBundle,
5435
5594
  handlers: this.services
5436
5595
  });
5437
5596
  void this._devtoolsProxy.open();
5438
5597
  }
5598
+ this.diagnosticsBroadcastHandler.start();
5439
5599
  this._opening = false;
5440
5600
  this._open = true;
5441
5601
  this._statusUpdate.emit();
5442
5602
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
5443
- (0, import_log14.log)("opened", {
5603
+ (0, import_log13.log)("opened", {
5444
5604
  deviceKey
5445
5605
  }, {
5446
5606
  F: __dxlog_file18,
5447
- L: 310,
5607
+ L: 326,
5448
5608
  S: this,
5449
5609
  C: (f, a) => f(...a)
5450
5610
  });
5451
- import_log14.log.trace("dxos.client-services.host.open", import_protocols15.trace.end({
5611
+ import_log13.log.trace("dxos.client-services.host.open", import_protocols14.trace.end({
5452
5612
  id: traceId
5453
5613
  }), {
5454
5614
  F: __dxlog_file18,
5455
- L: 311,
5615
+ L: 327,
5456
5616
  S: this,
5457
5617
  C: (f, a) => f(...a)
5458
5618
  });
@@ -5462,60 +5622,62 @@ var ClientServicesHost = class {
5462
5622
  return;
5463
5623
  }
5464
5624
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
5465
- (0, import_log14.log)("closing...", {
5625
+ (0, import_log13.log)("closing...", {
5466
5626
  deviceKey
5467
5627
  }, {
5468
5628
  F: __dxlog_file18,
5469
- L: 322,
5629
+ L: 338,
5470
5630
  S: this,
5471
5631
  C: (f, a) => f(...a)
5472
5632
  });
5633
+ this.diagnosticsBroadcastHandler.stop();
5473
5634
  await this._devtoolsProxy?.close();
5474
5635
  this._serviceRegistry.setServices({
5475
5636
  SystemService: this._systemService
5476
5637
  });
5477
5638
  await this._loggingService.close();
5478
5639
  await this._serviceContext.close();
5640
+ await this._level?.close();
5479
5641
  this._open = false;
5480
5642
  this._statusUpdate.emit();
5481
- (0, import_log14.log)("closed", {
5643
+ (0, import_log13.log)("closed", {
5482
5644
  deviceKey
5483
5645
  }, {
5484
5646
  F: __dxlog_file18,
5485
- L: 329,
5647
+ L: 347,
5486
5648
  S: this,
5487
5649
  C: (f, a) => f(...a)
5488
5650
  });
5489
5651
  }
5490
5652
  async reset() {
5491
5653
  const traceId = import_keys11.PublicKey.random().toHex();
5492
- import_log14.log.trace("dxos.sdk.client-services-host.reset", import_protocols15.trace.begin({
5654
+ import_log13.log.trace("dxos.sdk.client-services-host.reset", import_protocols14.trace.begin({
5493
5655
  id: traceId
5494
5656
  }), {
5495
5657
  F: __dxlog_file18,
5496
- L: 334,
5658
+ L: 352,
5497
5659
  S: this,
5498
5660
  C: (f, a) => f(...a)
5499
5661
  });
5500
- (0, import_log14.log)("resetting...", void 0, {
5662
+ (0, import_log13.log)("resetting...", void 0, {
5501
5663
  F: __dxlog_file18,
5502
- L: 336,
5664
+ L: 354,
5503
5665
  S: this,
5504
5666
  C: (f, a) => f(...a)
5505
5667
  });
5506
5668
  await this._serviceContext?.close();
5507
5669
  await this._storage.reset();
5508
- (0, import_log14.log)("reset", void 0, {
5670
+ (0, import_log13.log)("reset", void 0, {
5509
5671
  F: __dxlog_file18,
5510
- L: 339,
5672
+ L: 357,
5511
5673
  S: this,
5512
5674
  C: (f, a) => f(...a)
5513
5675
  });
5514
- import_log14.log.trace("dxos.sdk.client-services-host.reset", import_protocols15.trace.end({
5676
+ import_log13.log.trace("dxos.sdk.client-services-host.reset", import_protocols14.trace.end({
5515
5677
  id: traceId
5516
5678
  }), {
5517
5679
  F: __dxlog_file18,
5518
- L: 340,
5680
+ L: 358,
5519
5681
  S: this,
5520
5682
  C: (f, a) => f(...a)
5521
5683
  });
@@ -5526,9 +5688,9 @@ var ClientServicesHost = class {
5526
5688
  await this._serviceContext.initialized.wait();
5527
5689
  const space = await this._serviceContext.dataSpaceManager.createSpace();
5528
5690
  const automergeIndex = space.automergeSpaceState.rootUrl;
5529
- (0, import_invariant16.invariant)(automergeIndex, void 0, {
5691
+ (0, import_invariant15.invariant)(automergeIndex, void 0, {
5530
5692
  F: __dxlog_file18,
5531
- L: 352,
5693
+ L: 370,
5532
5694
  S: this,
5533
5695
  A: [
5534
5696
  "automergeIndex",
@@ -5537,51 +5699,93 @@ var ClientServicesHost = class {
5537
5699
  });
5538
5700
  const document = await this._serviceContext.automergeHost.repo.find(automergeIndex);
5539
5701
  await document.whenReady();
5540
- const objectDocument = (0, import_echo_schema.createRawObjectDoc)({
5541
- [import_client_protocol5.defaultKey]: identity.identityKey.toHex()
5542
- }, {
5543
- type: E.getTypeReference(import_client_protocol5.PropertiesSchema)
5544
- });
5702
+ const properties = {
5703
+ system: {
5704
+ type: (0, import_echo_pipeline5.encodeReference)((0, import_echo_schema.getTypeReference)(import_client_protocol4.Properties))
5705
+ },
5706
+ data: {
5707
+ [import_client_protocol4.defaultKey]: identity.identityKey.toHex()
5708
+ },
5709
+ meta: {
5710
+ keys: []
5711
+ }
5712
+ };
5713
+ const propertiesId = import_keys11.PublicKey.random().toHex();
5545
5714
  document.change((doc) => {
5546
5715
  (0, import_util9.assignDeep)(doc, [
5547
5716
  "objects",
5548
- objectDocument.id
5549
- ], objectDocument.handle.docSync());
5717
+ propertiesId
5718
+ ], properties);
5550
5719
  });
5551
- await (0, import_async16.sleep)(200);
5720
+ await this._serviceContext.automergeHost.repo.flush();
5552
5721
  return identity;
5553
5722
  }
5554
5723
  };
5555
5724
  _ts_decorate8([
5556
- import_tracing7.trace.info()
5725
+ import_tracing8.trace.info()
5557
5726
  ], ClientServicesHost.prototype, "_opening", void 0);
5558
5727
  _ts_decorate8([
5559
- import_tracing7.trace.info()
5728
+ import_tracing8.trace.info()
5560
5729
  ], ClientServicesHost.prototype, "_open", void 0);
5561
5730
  _ts_decorate8([
5562
5731
  import_async16.synchronized,
5563
- import_tracing7.trace.span()
5732
+ import_tracing8.trace.span()
5564
5733
  ], ClientServicesHost.prototype, "open", null);
5565
5734
  _ts_decorate8([
5566
5735
  import_async16.synchronized,
5567
- import_tracing7.trace.span()
5736
+ import_tracing8.trace.span()
5568
5737
  ], ClientServicesHost.prototype, "close", null);
5569
5738
  ClientServicesHost = _ts_decorate8([
5570
- import_tracing7.trace.resource()
5739
+ import_tracing8.trace.resource()
5571
5740
  ], ClientServicesHost);
5741
+ var ClientServicesProviderResource = Symbol.for("dxos.resource.ClientServices");
5742
+ var DiagnosticsCollector = class {
5743
+ static {
5744
+ this.broadcastSender = createCollectDiagnosticsBroadcastSender();
5745
+ }
5746
+ static async collect(config = findConfigs(), services = findSystemServiceProvider(), options = {}) {
5747
+ const serviceDiagnostics = await services?.services?.SystemService?.getDiagnostics({
5748
+ keys: options.humanize ? import_services13.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE : options.truncate ? import_services13.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE : void 0
5749
+ });
5750
+ const clientDiagnostics = {
5751
+ config,
5752
+ trace: import_tracing7.TRACE_PROCESSOR.getDiagnostics()
5753
+ };
5754
+ const diagnostics = serviceDiagnostics != null ? {
5755
+ client: clientDiagnostics,
5756
+ services: serviceDiagnostics
5757
+ } : {
5758
+ client: clientDiagnostics,
5759
+ broadcast: await this.broadcastSender.broadcastDiagnosticsRequest()
5760
+ };
5761
+ return JSON.parse(JSON.stringify(diagnostics, (0, import_util8.jsonKeyReplacer)(options)));
5762
+ }
5763
+ };
5764
+ var findSystemServiceProvider = () => {
5765
+ const serviceProviders = import_tracing7.TRACE_PROCESSOR.findByAnnotation(ClientServicesProviderResource);
5766
+ const providerResource = serviceProviders.find((r) => r.instance.deref()?.services?.SystemService != null);
5767
+ return providerResource?.instance?.deref() ?? null;
5768
+ };
5769
+ var findConfigs = () => {
5770
+ const configs = import_tracing7.TRACE_PROCESSOR.findByAnnotation(import_config.ConfigResource);
5771
+ return configs.map((r) => r.instance.deref()).filter(import_util8.nonNullable);
5772
+ };
5572
5773
  // Annotate the CommonJS export names for ESM import in node:
5573
5774
  0 && (module.exports = {
5574
5775
  ClientRpcServer,
5575
5776
  ClientServicesHost,
5777
+ ClientServicesProviderResource,
5576
5778
  DataSpace,
5577
5779
  DataSpaceManager,
5578
5780
  DeviceInvitationProtocol,
5579
5781
  DevtoolsHostEvents,
5580
5782
  DevtoolsServiceImpl,
5783
+ DiagnosticsCollector,
5581
5784
  Identity,
5582
5785
  IdentityManager,
5583
5786
  IdentityServiceImpl,
5584
5787
  InvitationsHandler,
5788
+ InvitationsManager,
5585
5789
  InvitationsServiceImpl,
5586
5790
  Lock,
5587
5791
  ServiceContext,
@@ -5589,11 +5793,14 @@ ClientServicesHost = _ts_decorate8([
5589
5793
  SpaceInvitationProtocol,
5590
5794
  SpacesServiceImpl,
5591
5795
  TrustedKeySetAuthVerifier,
5796
+ createAdmissionKeypair,
5592
5797
  createAuthProvider,
5798
+ createCollectDiagnosticsBroadcastHandler,
5799
+ createCollectDiagnosticsBroadcastSender,
5593
5800
  createDiagnostics,
5801
+ createLevel,
5594
5802
  createStorageObjects,
5595
5803
  getNetworkPeers,
5596
- invitationExpired,
5597
5804
  isLocked,
5598
5805
  subscribeToFeedBlocks,
5599
5806
  subscribeToFeeds,
@@ -5603,4 +5810,4 @@ ClientServicesHost = _ts_decorate8([
5603
5810
  subscribeToSpaces,
5604
5811
  subscribeToSwarmInfo
5605
5812
  });
5606
- //# sourceMappingURL=chunk-EC2QGJ2V.cjs.map
5813
+ //# sourceMappingURL=chunk-KIKQMYZ7.cjs.map