@dxos/client-services 0.4.9 → 0.4.10-main.068c3d8

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