@dxos/client-services 0.4.10-main.d2a7fe7 → 0.4.10-main.d4766e5

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 (74) hide show
  1. package/dist/lib/browser/{chunk-5YFNO6CM.mjs → chunk-DXJJOAJI.mjs} +695 -513
  2. package/dist/lib/browser/chunk-DXJJOAJI.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +11 -1
  4. package/dist/lib/browser/index.mjs.map +1 -1
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +6 -4
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/{chunk-3CGMNOA3.cjs → chunk-54K33CLU.cjs} +628 -533
  9. package/dist/lib/node/chunk-54K33CLU.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +47 -37
  11. package/dist/lib/node/index.cjs.map +1 -1
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/packlets/testing/index.cjs +10 -8
  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/services/index.d.ts +1 -1
  28. package/dist/types/src/packlets/services/index.d.ts.map +1 -1
  29. package/dist/types/src/packlets/services/service-context.d.ts +7 -5
  30. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  31. package/dist/types/src/packlets/services/service-host.d.ts +2 -0
  32. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  33. package/dist/types/src/packlets/services/util.d.ts +1 -0
  34. package/dist/types/src/packlets/services/util.d.ts.map +1 -1
  35. package/dist/types/src/packlets/storage/index.d.ts +1 -0
  36. package/dist/types/src/packlets/storage/index.d.ts.map +1 -1
  37. package/dist/types/src/packlets/storage/level.d.ts +4 -0
  38. package/dist/types/src/packlets/storage/level.d.ts.map +1 -0
  39. package/dist/types/src/packlets/storage/storage.d.ts.map +1 -1
  40. package/dist/types/src/packlets/storage/util.d.ts +4 -0
  41. package/dist/types/src/packlets/storage/util.d.ts.map +1 -0
  42. package/dist/types/src/packlets/system/system-service.d.ts +1 -1
  43. package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
  44. package/dist/types/src/packlets/testing/test-builder.d.ts +1 -1
  45. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  46. package/dist/types/src/version.d.ts +1 -1
  47. package/package.json +36 -34
  48. package/src/index.ts +1 -0
  49. package/src/packlets/devices/devices-service.test.ts +1 -1
  50. package/src/packlets/diagnostics/browser-diagnostics-broadcast.ts +94 -0
  51. package/src/packlets/diagnostics/diagnostics-broadcast.ts +20 -0
  52. package/src/packlets/diagnostics/diagnostics-collector.ts +65 -0
  53. package/src/packlets/{services → diagnostics}/diagnostics.ts +2 -2
  54. package/src/packlets/diagnostics/index.ts +7 -0
  55. package/src/packlets/identity/identity-service.test.ts +1 -1
  56. package/src/packlets/invitations/device-invitation-protocol.test.ts +1 -1
  57. package/src/packlets/network/network-service.test.ts +1 -1
  58. package/src/packlets/services/index.ts +1 -1
  59. package/src/packlets/services/service-context.test.ts +5 -5
  60. package/src/packlets/services/service-context.ts +10 -5
  61. package/src/packlets/services/service-host.ts +38 -13
  62. package/src/packlets/services/service-registry.test.ts +1 -1
  63. package/src/packlets/services/util.ts +2 -0
  64. package/src/packlets/spaces/spaces-service.test.ts +1 -1
  65. package/src/packlets/storage/index.ts +1 -0
  66. package/src/packlets/storage/level.ts +19 -0
  67. package/src/packlets/storage/storage.ts +3 -9
  68. package/src/packlets/storage/util.ts +19 -0
  69. package/src/packlets/system/system-service.ts +1 -1
  70. package/src/packlets/testing/test-builder.ts +5 -3
  71. package/src/version.ts +1 -1
  72. package/dist/lib/browser/chunk-5YFNO6CM.mjs.map +0 -7
  73. package/dist/lib/node/chunk-3CGMNOA3.cjs.map +0 -7
  74. package/dist/types/src/packlets/services/diagnostics.d.ts.map +0 -1
@@ -26,15 +26,17 @@ 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_3CGMNOA3_exports = {};
30
- __export(chunk_3CGMNOA3_exports, {
29
+ var chunk_54K33CLU_exports = {};
30
+ __export(chunk_54K33CLU_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,
@@ -47,7 +49,10 @@ __export(chunk_3CGMNOA3_exports, {
47
49
  SpacesServiceImpl: () => SpacesServiceImpl,
48
50
  TrustedKeySetAuthVerifier: () => TrustedKeySetAuthVerifier,
49
51
  createAuthProvider: () => createAuthProvider,
52
+ createCollectDiagnosticsBroadcastHandler: () => createCollectDiagnosticsBroadcastHandler,
53
+ createCollectDiagnosticsBroadcastSender: () => createCollectDiagnosticsBroadcastSender,
50
54
  createDiagnostics: () => createDiagnostics,
55
+ createLevel: () => createLevel,
51
56
  createStorageObjects: () => createStorageObjects,
52
57
  getNetworkPeers: () => getNetworkPeers,
53
58
  invitationExpired: () => invitationExpired,
@@ -60,7 +65,7 @@ __export(chunk_3CGMNOA3_exports, {
60
65
  subscribeToSpaces: () => subscribeToSpaces,
61
66
  subscribeToSwarmInfo: () => subscribeToSwarmInfo
62
67
  });
63
- module.exports = __toCommonJS(chunk_3CGMNOA3_exports);
68
+ module.exports = __toCommonJS(chunk_54K33CLU_exports);
64
69
  var import_async = require("@dxos/async");
65
70
  var import_codec_protobuf = require("@dxos/codec-protobuf");
66
71
  var import_feed_store = require("@dxos/feed-store");
@@ -147,13 +152,6 @@ var import_codec_protobuf9 = require("@dxos/codec-protobuf");
147
152
  var import_debug2 = require("@dxos/debug");
148
153
  var import_rpc = require("@dxos/rpc");
149
154
  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
155
  var import_async10 = require("@dxos/async");
158
156
  var import_client_protocol3 = require("@dxos/client-protocol");
159
157
  var import_context7 = require("@dxos/context");
@@ -161,104 +159,120 @@ var import_debug3 = require("@dxos/debug");
161
159
  var import_echo_db = require("@dxos/echo-db");
162
160
  var import_echo_pipeline = require("@dxos/echo-pipeline");
163
161
  var import_echo_pipeline2 = require("@dxos/echo-pipeline");
164
- var import_invariant10 = require("@dxos/invariant");
162
+ var import_invariant9 = require("@dxos/invariant");
165
163
  var import_keys7 = require("@dxos/keys");
166
164
  var import_log8 = require("@dxos/log");
167
- var import_protocols8 = require("@dxos/protocols");
168
- var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
169
- var import_credentials10 = require("@dxos/protocols/proto/dxos/halo/credentials");
165
+ var import_protocols7 = require("@dxos/protocols");
166
+ var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
167
+ var import_credentials9 = require("@dxos/protocols/proto/dxos/halo/credentials");
170
168
  var import_timeframe2 = require("@dxos/timeframe");
171
- var import_tracing5 = require("@dxos/tracing");
169
+ var import_tracing4 = require("@dxos/tracing");
172
170
  var import_util4 = require("@dxos/util");
173
171
  var import_async11 = require("@dxos/async");
174
- var import_credentials11 = require("@dxos/credentials");
172
+ var import_credentials10 = require("@dxos/credentials");
175
173
  var import_async12 = require("@dxos/async");
176
174
  var import_context8 = require("@dxos/context");
177
- var import_invariant11 = require("@dxos/invariant");
175
+ var import_invariant10 = require("@dxos/invariant");
178
176
  var import_keys8 = require("@dxos/keys");
179
177
  var import_log9 = require("@dxos/log");
180
- var import_protocols9 = require("@dxos/protocols");
178
+ var import_protocols8 = require("@dxos/protocols");
181
179
  var import_teleport2 = require("@dxos/teleport");
182
180
  var import_util5 = require("@dxos/util");
183
181
  var import_async13 = require("@dxos/async");
184
182
  var import_context9 = require("@dxos/context");
185
- var import_credentials12 = require("@dxos/credentials");
186
- var import_invariant12 = require("@dxos/invariant");
183
+ var import_credentials11 = require("@dxos/credentials");
184
+ var import_invariant11 = require("@dxos/invariant");
187
185
  var import_keys9 = require("@dxos/keys");
188
186
  var import_log10 = require("@dxos/log");
189
- var import_protocols10 = require("@dxos/protocols");
190
- var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
187
+ var import_protocols9 = require("@dxos/protocols");
188
+ var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
191
189
  var import_teleport_extension_gossip2 = require("@dxos/teleport-extension-gossip");
192
190
  var import_util6 = require("@dxos/util");
193
- var import_credentials13 = require("@dxos/credentials");
191
+ var import_credentials12 = require("@dxos/credentials");
194
192
  var import_debug4 = require("@dxos/debug");
195
- var import_credentials14 = require("@dxos/protocols/proto/dxos/halo/credentials");
193
+ var import_credentials13 = require("@dxos/protocols/proto/dxos/halo/credentials");
196
194
  var import_timeframe3 = require("@dxos/timeframe");
197
195
  var import_async14 = require("@dxos/async");
198
- var import_codec_protobuf11 = require("@dxos/codec-protobuf");
196
+ var import_codec_protobuf10 = require("@dxos/codec-protobuf");
199
197
  var import_debug5 = require("@dxos/debug");
200
- var import_invariant13 = require("@dxos/invariant");
198
+ var import_invariant12 = require("@dxos/invariant");
201
199
  var import_log11 = require("@dxos/log");
202
- var import_protocols11 = require("@dxos/protocols");
203
- var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
200
+ var import_protocols10 = require("@dxos/protocols");
201
+ var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
204
202
  var import_async15 = require("@dxos/async");
205
203
  var import_context10 = require("@dxos/context");
206
- var import_credentials15 = require("@dxos/credentials");
204
+ var import_credentials14 = require("@dxos/credentials");
207
205
  var import_debug6 = require("@dxos/debug");
208
206
  var import_echo_pipeline3 = require("@dxos/echo-pipeline");
209
207
  var import_feed_store4 = require("@dxos/feed-store");
210
208
  var import_indexing = require("@dxos/indexing");
211
- var import_invariant14 = require("@dxos/invariant");
209
+ var import_invariant13 = require("@dxos/invariant");
212
210
  var import_keyring = require("@dxos/keyring");
213
211
  var import_keys10 = require("@dxos/keys");
214
212
  var import_log12 = require("@dxos/log");
215
- var import_protocols12 = require("@dxos/protocols");
216
- var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
213
+ var import_protocols11 = require("@dxos/protocols");
214
+ var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
217
215
  var import_teleport_extension_object_sync = require("@dxos/teleport-extension-object-sync");
218
- var import_tracing6 = require("@dxos/tracing");
216
+ var import_tracing5 = require("@dxos/tracing");
219
217
  var import_util7 = require("@dxos/util");
220
218
  var import_automerge = require("@dxos/automerge/automerge");
221
219
  var import_debug7 = require("@dxos/debug");
220
+ var import_protocols12 = require("@dxos/protocols");
221
+ var import_codec_protobuf11 = require("@dxos/codec-protobuf");
222
+ var import_credentials15 = require("@dxos/credentials");
223
+ var import_invariant14 = require("@dxos/invariant");
222
224
  var import_protocols13 = require("@dxos/protocols");
223
- var import_invariant15 = require("@dxos/invariant");
224
- var import_lock_file = require("@dxos/lock-file");
225
- var import_log13 = require("@dxos/log");
226
- var import_client_protocol4 = require("@dxos/client-protocol");
227
- var import_protocols14 = require("@dxos/protocols");
228
- var import_config = require("@dxos/protocols/proto/dxos/config");
229
- var import_random_access_storage = require("@dxos/random-access-storage");
225
+ var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
226
+ var import_tracing6 = require("@dxos/tracing");
227
+ var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
228
+ var import_config = require("@dxos/config");
229
+ var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
230
+ var import_tracing7 = require("@dxos/tracing");
230
231
  var import_util8 = require("@dxos/util");
231
232
  var import_async16 = require("@dxos/async");
232
- var import_client_protocol5 = require("@dxos/client-protocol");
233
+ var import_client_protocol4 = require("@dxos/client-protocol");
233
234
  var import_context11 = require("@dxos/context");
234
235
  var import_echo_pipeline4 = require("@dxos/echo-pipeline");
235
236
  var E = __toESM(require("@dxos/echo-schema"));
236
- var import_echo_schema = require("@dxos/echo-schema");
237
237
  var import_indexing2 = require("@dxos/indexing");
238
- var import_invariant16 = require("@dxos/invariant");
238
+ var import_invariant15 = require("@dxos/invariant");
239
239
  var import_keys11 = require("@dxos/keys");
240
- var import_log14 = require("@dxos/log");
240
+ var import_log13 = require("@dxos/log");
241
241
  var import_messaging = require("@dxos/messaging");
242
242
  var import_network_manager2 = require("@dxos/network-manager");
243
- var import_protocols15 = require("@dxos/protocols");
244
- var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
245
- var import_tracing7 = require("@dxos/tracing");
243
+ var import_protocols14 = require("@dxos/protocols");
244
+ var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
245
+ var import_tracing8 = require("@dxos/tracing");
246
246
  var import_util9 = require("@dxos/util");
247
247
  var import_websocket_rpc = require("@dxos/websocket-rpc");
248
248
  var import_async17 = require("@dxos/async");
249
249
  var import_codec_protobuf12 = require("@dxos/codec-protobuf");
250
+ var import_invariant16 = require("@dxos/invariant");
251
+ var import_services15 = require("@dxos/protocols/proto/dxos/client/services");
250
252
  var import_invariant17 = require("@dxos/invariant");
251
- var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
253
+ var import_lock_file = require("@dxos/lock-file");
254
+ var import_log14 = require("@dxos/log");
252
255
  var import_async18 = require("@dxos/async");
253
256
  var import_codec_protobuf13 = require("@dxos/codec-protobuf");
254
257
  var import_keys12 = require("@dxos/keys");
255
258
  var import_log15 = require("@dxos/log");
256
- var import_services15 = require("@dxos/protocols/proto/dxos/client/services");
259
+ var import_services16 = require("@dxos/protocols/proto/dxos/client/services");
257
260
  var import_util10 = require("@dxos/util");
258
261
  var import_codec_protobuf14 = require("@dxos/codec-protobuf");
259
- var import_codec_protobuf15 = require("@dxos/codec-protobuf");
260
- var import_services16 = require("@dxos/protocols/proto/dxos/client/services");
262
+ var import_protocols15 = require("@dxos/protocols");
263
+ var import_config2 = require("@dxos/protocols/proto/dxos/config");
264
+ var import_random_access_storage = require("@dxos/random-access-storage");
265
+ var import_client_protocol5 = require("@dxos/client-protocol");
266
+ var import_config3 = require("@dxos/protocols/proto/dxos/config");
261
267
  var import_util11 = require("@dxos/util");
268
+ var import_level = require("level");
269
+ var import_node_path = __toESM(require("node:path"));
270
+ var import_keys13 = require("@dxos/keys");
271
+ var import_codec_protobuf15 = require("@dxos/codec-protobuf");
272
+ var import_services17 = require("@dxos/protocols/proto/dxos/client/services");
273
+ var import_util12 = require("@dxos/util");
274
+ var import_keys14 = require("@dxos/keys");
275
+ var import_util13 = require("@dxos/util");
262
276
  var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
263
277
  return new import_codec_protobuf.Stream(({ next }) => {
264
278
  const subscriptions = new import_async.EventSubscriptions();
@@ -2860,141 +2874,6 @@ _ts_decorate3([
2860
2874
  ClientRpcServer = _ts_decorate3([
2861
2875
  import_tracing3.trace.resource()
2862
2876
  ], ClientRpcServer);
2863
- var getPlatform = () => {
2864
- if (process.browser) {
2865
- if (typeof window !== "undefined") {
2866
- const { userAgent } = window.navigator;
2867
- return {
2868
- type: import_services8.Platform.PLATFORM_TYPE.BROWSER,
2869
- userAgent,
2870
- uptime: Math.floor((Date.now() - window.performance.timeOrigin) / 1e3)
2871
- };
2872
- } else {
2873
- return {
2874
- type: import_services8.Platform.PLATFORM_TYPE.SHARED_WORKER,
2875
- uptime: Math.floor((Date.now() - performance.timeOrigin) / 1e3)
2876
- };
2877
- }
2878
- } else {
2879
- const { platform: platform2, version, arch } = process;
2880
- return {
2881
- type: import_services8.Platform.PLATFORM_TYPE.NODE,
2882
- platform: platform2,
2883
- arch,
2884
- runtime: version,
2885
- uptime: Math.floor(process.uptime()),
2886
- memory: process.memoryUsage()
2887
- };
2888
- }
2889
- };
2890
- var DXOS_VERSION = "0.4.10-main.d2a7fe7";
2891
- var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
2892
- var DEFAULT_TIMEOUT = 1e3;
2893
- var createDiagnostics = async (clientServices, serviceContext, config) => {
2894
- const diagnostics = {
2895
- created: (/* @__PURE__ */ new Date()).toISOString(),
2896
- platform: getPlatform(),
2897
- client: {
2898
- version: DXOS_VERSION,
2899
- storage: {
2900
- version: import_protocols7.STORAGE_VERSION
2901
- }
2902
- },
2903
- trace: import_tracing4.TRACE_PROCESSOR.getDiagnostics()
2904
- };
2905
- {
2906
- (0, import_invariant9.invariant)(clientServices.LoggingService, "SystemService is not available.", {
2907
- F: __dxlog_file10,
2908
- L: 108,
2909
- S: void 0,
2910
- A: [
2911
- "clientServices.LoggingService",
2912
- "'SystemService is not available.'"
2913
- ]
2914
- });
2915
- diagnostics.metrics = await (0, import_codec_protobuf10.getFirstStreamValue)(clientServices.LoggingService.queryMetrics({}), {
2916
- timeout: DEFAULT_TIMEOUT
2917
- }).catch(() => void 0);
2918
- }
2919
- if (typeof navigator !== "undefined" && navigator.storage) {
2920
- const map = /* @__PURE__ */ new Map();
2921
- const dir = await navigator.storage.getDirectory();
2922
- for await (const filename of dir?.keys()) {
2923
- const idx = filename.indexOf("-", filename.indexOf("-") + 1);
2924
- if (idx === -1) {
2925
- continue;
2926
- }
2927
- map.set(filename.slice(0, idx), (map.get(filename.slice(0, idx)) ?? 0) + 1);
2928
- }
2929
- diagnostics.storage = Array.from(map.entries()).sort((a, b) => b[1] - a[1]).map(([file, count]) => ({
2930
- file,
2931
- count
2932
- }));
2933
- }
2934
- const identity = serviceContext.identityManager.identity;
2935
- if (identity) {
2936
- diagnostics.identity = {
2937
- identityKey: identity.identityKey,
2938
- spaceKey: identity.space.key,
2939
- profile: identity.profileDocument
2940
- };
2941
- const { devices } = await (0, import_codec_protobuf10.getFirstStreamValue)(clientServices.DevicesService.queryDevices(), {
2942
- timeout: DEFAULT_TIMEOUT
2943
- }).catch(() => void 0) ?? {};
2944
- diagnostics.devices = devices;
2945
- if (serviceContext.dataSpaceManager) {
2946
- diagnostics.spaces = await Promise.all(Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space)) ?? []);
2947
- }
2948
- const { feeds = [] } = await (0, import_codec_protobuf10.getFirstStreamValue)(clientServices.DevtoolsHost.subscribeToFeeds({}), {
2949
- timeout: DEFAULT_TIMEOUT
2950
- }).catch(() => void 0) ?? {};
2951
- diagnostics.feeds = feeds.map(({ feedKey, bytes, length }) => ({
2952
- feedKey,
2953
- bytes,
2954
- length
2955
- }));
2956
- const status = await (0, import_codec_protobuf10.getFirstStreamValue)(clientServices.NetworkService.queryStatus(), {
2957
- timeout: DEFAULT_TIMEOUT
2958
- }).catch(() => void 0);
2959
- diagnostics.networkStatus = status;
2960
- diagnostics.swarms = serviceContext.networkManager.connectionLog?.swarms;
2961
- }
2962
- diagnostics.config = config.values;
2963
- return diagnostics;
2964
- };
2965
- var getSpaceStats = async (space) => {
2966
- const stats = {
2967
- key: space.key,
2968
- metrics: space.metrics,
2969
- epochs: space.inner.spaceState.credentials.filter((0, import_credentials9.credentialTypeFilter)("dxos.halo.credentials.Epoch")).map((credential) => ({
2970
- ...credential.subject.assertion,
2971
- id: credential.id
2972
- })),
2973
- members: Array.from(space.inner.spaceState.members.values()).map((member) => ({
2974
- identity: {
2975
- identityKey: member.key,
2976
- profile: {
2977
- displayName: member.assertion.profile?.displayName
2978
- }
2979
- },
2980
- presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? import_services7.SpaceMember.PresenceState.ONLINE : import_services7.SpaceMember.PresenceState.OFFLINE
2981
- })),
2982
- pipeline: {
2983
- // TODO(burdon): Pick properties from credentials if needed.
2984
- currentEpoch: space.automergeSpaceState.lastEpoch,
2985
- appliedEpoch: space.automergeSpaceState.lastEpoch,
2986
- controlFeeds: space.inner.controlPipeline.state.feeds.map((feed) => feed.key),
2987
- currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
2988
- targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
2989
- totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe
2990
- }
2991
- };
2992
- if (stats.metrics) {
2993
- const { open, ready } = stats.metrics;
2994
- stats.metrics.startupTime = open && ready && ready.getTime() - open.getTime();
2995
- }
2996
- return stats;
2997
- };
2998
2877
  var AutomergeSpaceState = class {
2999
2878
  constructor(_onNewRoot) {
3000
2879
  this._onNewRoot = _onNewRoot;
@@ -3004,7 +2883,7 @@ var AutomergeSpaceState = class {
3004
2883
  this._isProcessingRootDocs = false;
3005
2884
  }
3006
2885
  async processCredential(credential) {
3007
- if (!(0, import_credentials11.checkCredentialType)(credential, "dxos.halo.credentials.Epoch")) {
2886
+ if (!(0, import_credentials10.checkCredentialType)(credential, "dxos.halo.credentials.Epoch")) {
3008
2887
  return;
3009
2888
  }
3010
2889
  this.lastEpoch = credential;
@@ -3029,7 +2908,7 @@ var AutomergeSpaceState = class {
3029
2908
  await this.onNewEpoch.waitForCondition(() => !!this.lastEpoch);
3030
2909
  }
3031
2910
  };
3032
- var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
2911
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
3033
2912
  var DEFAULT_RETRY_TIMEOUT = 1e3;
3034
2913
  var DEFAULT_SUCCESS_DELAY = 1e3;
3035
2914
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
@@ -3057,13 +2936,13 @@ var NotarizationPlugin = class {
3057
2936
  (0, import_log9.log)("notarize", {
3058
2937
  credentials
3059
2938
  }, {
3060
- F: __dxlog_file11,
2939
+ F: __dxlog_file10,
3061
2940
  L: 90,
3062
2941
  S: this,
3063
2942
  C: (f, a) => f(...a)
3064
2943
  });
3065
- (0, import_invariant11.invariant)(credentials.every((credential) => credential.id), "Credentials must have an id", {
3066
- F: __dxlog_file11,
2944
+ (0, import_invariant10.invariant)(credentials.every((credential) => credential.id), "Credentials must have an id", {
2945
+ F: __dxlog_file10,
3067
2946
  L: 91,
3068
2947
  S: this,
3069
2948
  A: [
@@ -3077,7 +2956,7 @@ var NotarizationPlugin = class {
3077
2956
  import_log9.log.warn("Notarization error", {
3078
2957
  err
3079
2958
  }, {
3080
- F: __dxlog_file11,
2959
+ F: __dxlog_file10,
3081
2960
  L: 99,
3082
2961
  S: this,
3083
2962
  C: (f, a) => f(...a)
@@ -3093,7 +2972,7 @@ var NotarizationPlugin = class {
3093
2972
  timeout,
3094
2973
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
3095
2974
  }, {
3096
- F: __dxlog_file11,
2975
+ F: __dxlog_file10,
3097
2976
  L: 111,
3098
2977
  S: this,
3099
2978
  C: (f, a) => f(...a)
@@ -3116,7 +2995,7 @@ var NotarizationPlugin = class {
3116
2995
  import_log9.log.info("Exhausted all peers to notarize with", {
3117
2996
  retryIn: retryTimeout
3118
2997
  }, {
3119
- F: __dxlog_file11,
2998
+ F: __dxlog_file10,
3120
2999
  L: 136,
3121
3000
  S: this,
3122
3001
  C: (f, a) => f(...a)
@@ -3130,7 +3009,7 @@ var NotarizationPlugin = class {
3130
3009
  peer: peer.localPeerId,
3131
3010
  credentialId: credentials.map((credential) => credential.id)
3132
3011
  }, {
3133
- F: __dxlog_file11,
3012
+ F: __dxlog_file10,
3134
3013
  L: 143,
3135
3014
  S: this,
3136
3015
  C: (f, a) => f(...a)
@@ -3139,7 +3018,7 @@ var NotarizationPlugin = class {
3139
3018
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
3140
3019
  });
3141
3020
  (0, import_log9.log)("success", void 0, {
3142
- F: __dxlog_file11,
3021
+ F: __dxlog_file10,
3143
3022
  L: 147,
3144
3023
  S: this,
3145
3024
  C: (f, a) => f(...a)
@@ -3148,7 +3027,7 @@ var NotarizationPlugin = class {
3148
3027
  } catch (err) {
3149
3028
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
3150
3029
  import_log9.log.info("error notarizing (recoverable)", err, {
3151
- F: __dxlog_file11,
3030
+ F: __dxlog_file10,
3152
3031
  L: 151,
3153
3032
  S: this,
3154
3033
  C: (f, a) => f(...a)
@@ -3166,7 +3045,7 @@ var NotarizationPlugin = class {
3166
3045
  errors.wait()
3167
3046
  ]);
3168
3047
  (0, import_log9.log)("done", void 0, {
3169
- F: __dxlog_file11,
3048
+ F: __dxlog_file10,
3170
3049
  L: 162,
3171
3050
  S: this,
3172
3051
  C: (f, a) => f(...a)
@@ -3187,8 +3066,8 @@ var NotarizationPlugin = class {
3187
3066
  this._processCredentialsTriggers.delete(credential.id);
3188
3067
  }
3189
3068
  setWriter(writer) {
3190
- (0, import_invariant11.invariant)(!this._writer, "Writer already set.", {
3191
- F: __dxlog_file11,
3069
+ (0, import_invariant10.invariant)(!this._writer, "Writer already set.", {
3070
+ F: __dxlog_file10,
3192
3071
  L: 181,
3193
3072
  S: this,
3194
3073
  A: [
@@ -3212,8 +3091,8 @@ var NotarizationPlugin = class {
3212
3091
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
3213
3092
  }
3214
3093
  for (const credential of request.credentials ?? []) {
3215
- (0, import_invariant11.invariant)(credential.id, "Credential must have an id", {
3216
- F: __dxlog_file11,
3094
+ (0, import_invariant10.invariant)(credential.id, "Credential must have an id", {
3095
+ F: __dxlog_file10,
3217
3096
  L: 200,
3218
3097
  S: this,
3219
3098
  A: [
@@ -3233,7 +3112,7 @@ var NotarizationPlugin = class {
3233
3112
  (0, import_log9.log)("extension opened", {
3234
3113
  peer: extension.localPeerId
3235
3114
  }, {
3236
- F: __dxlog_file11,
3115
+ F: __dxlog_file10,
3237
3116
  L: 211,
3238
3117
  S: this,
3239
3118
  C: (f, a) => f(...a)
@@ -3245,7 +3124,7 @@ var NotarizationPlugin = class {
3245
3124
  (0, import_log9.log)("extension closed", {
3246
3125
  peer: extension.localPeerId
3247
3126
  }, {
3248
- F: __dxlog_file11,
3127
+ F: __dxlog_file10,
3249
3128
  L: 216,
3250
3129
  S: this,
3251
3130
  C: (f, a) => f(...a)
@@ -3261,10 +3140,10 @@ var NotarizationTeleportExtension = class extends import_teleport2.RpcExtension
3261
3140
  constructor(_params) {
3262
3141
  super({
3263
3142
  requested: {
3264
- NotarizationService: import_protocols9.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3143
+ NotarizationService: import_protocols8.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3265
3144
  },
3266
3145
  exposed: {
3267
- NotarizationService: import_protocols9.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3146
+ NotarizationService: import_protocols8.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3268
3147
  }
3269
3148
  });
3270
3149
  this._params = _params;
@@ -3297,14 +3176,14 @@ function _ts_decorate4(decorators, target, key, desc) {
3297
3176
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3298
3177
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3299
3178
  }
3300
- var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
3179
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
3301
3180
  var DataSpace = class {
3302
3181
  constructor(params) {
3303
3182
  this._ctx = new import_context7.Context();
3304
3183
  this._notarizationPlugin = new NotarizationPlugin();
3305
3184
  this._cache = void 0;
3306
3185
  this._automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
3307
- this._state = import_services9.SpaceState.CLOSED;
3186
+ this._state = import_services7.SpaceState.CLOSED;
3308
3187
  this.error = void 0;
3309
3188
  this.stateUpdate = new import_async10.Event();
3310
3189
  this.metrics = {};
@@ -3326,9 +3205,9 @@ var DataSpace = class {
3326
3205
  this._cache = params.cache;
3327
3206
  this._state = params.initialState;
3328
3207
  (0, import_log8.log)("new state", {
3329
- state: import_services9.SpaceState[this._state]
3208
+ state: import_services7.SpaceState[this._state]
3330
3209
  }, {
3331
- F: __dxlog_file12,
3210
+ F: __dxlog_file11,
3332
3211
  L: 140,
3333
3212
  S: this,
3334
3213
  C: (f, a) => f(...a)
@@ -3374,11 +3253,11 @@ var DataSpace = class {
3374
3253
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
3375
3254
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
3376
3255
  await this._inner.open(new import_context7.Context());
3377
- this._state = import_services9.SpaceState.CONTROL_ONLY;
3256
+ this._state = import_services7.SpaceState.CONTROL_ONLY;
3378
3257
  (0, import_log8.log)("new state", {
3379
- state: import_services9.SpaceState[this._state]
3258
+ state: import_services7.SpaceState[this._state]
3380
3259
  }, {
3381
- F: __dxlog_file12,
3260
+ F: __dxlog_file11,
3382
3261
  L: 198,
3383
3262
  S: this,
3384
3263
  C: (f, a) => f(...a)
@@ -3392,11 +3271,11 @@ var DataSpace = class {
3392
3271
  }
3393
3272
  async _close() {
3394
3273
  await this._callbacks.beforeClose?.();
3395
- this._state = import_services9.SpaceState.CLOSED;
3274
+ this._state = import_services7.SpaceState.CLOSED;
3396
3275
  (0, import_log8.log)("new state", {
3397
- state: import_services9.SpaceState[this._state]
3276
+ state: import_services7.SpaceState[this._state]
3398
3277
  }, {
3399
- F: __dxlog_file12,
3278
+ F: __dxlog_file11,
3400
3279
  L: 212,
3401
3280
  S: this,
3402
3281
  C: (f, a) => f(...a)
@@ -3426,9 +3305,9 @@ var DataSpace = class {
3426
3305
  this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
3427
3306
  await this.initializeDataPipeline();
3428
3307
  } catch (err) {
3429
- if (err instanceof import_protocols8.CancelledError || err instanceof import_context7.ContextDisposedError) {
3308
+ if (err instanceof import_protocols7.CancelledError || err instanceof import_context7.ContextDisposedError) {
3430
3309
  (0, import_log8.log)("data pipeline initialization cancelled", err, {
3431
- F: __dxlog_file12,
3310
+ F: __dxlog_file11,
3432
3311
  L: 245,
3433
3312
  S: this,
3434
3313
  C: (f, a) => f(...a)
@@ -3436,16 +3315,16 @@ var DataSpace = class {
3436
3315
  return;
3437
3316
  }
3438
3317
  import_log8.log.error("Error initializing data pipeline", err, {
3439
- F: __dxlog_file12,
3318
+ F: __dxlog_file11,
3440
3319
  L: 249,
3441
3320
  S: this,
3442
3321
  C: (f, a) => f(...a)
3443
3322
  });
3444
- this._state = import_services9.SpaceState.ERROR;
3323
+ this._state = import_services7.SpaceState.ERROR;
3445
3324
  (0, import_log8.log)("new state", {
3446
- state: import_services9.SpaceState[this._state]
3325
+ state: import_services7.SpaceState[this._state]
3447
3326
  }, {
3448
- F: __dxlog_file12,
3327
+ F: __dxlog_file11,
3449
3328
  L: 251,
3450
3329
  S: this,
3451
3330
  C: (f, a) => f(...a)
@@ -3458,14 +3337,14 @@ var DataSpace = class {
3458
3337
  });
3459
3338
  }
3460
3339
  async initializeDataPipeline() {
3461
- if (this._state !== import_services9.SpaceState.CONTROL_ONLY) {
3462
- throw new import_protocols8.SystemError("Invalid operation");
3340
+ if (this._state !== import_services7.SpaceState.CONTROL_ONLY) {
3341
+ throw new import_protocols7.SystemError("Invalid operation");
3463
3342
  }
3464
- this._state = import_services9.SpaceState.INITIALIZING;
3343
+ this._state = import_services7.SpaceState.INITIALIZING;
3465
3344
  (0, import_log8.log)("new state", {
3466
- state: import_services9.SpaceState[this._state]
3345
+ state: import_services7.SpaceState[this._state]
3467
3346
  }, {
3468
- F: __dxlog_file12,
3347
+ F: __dxlog_file11,
3469
3348
  L: 267,
3470
3349
  S: this,
3471
3350
  C: (f, a) => f(...a)
@@ -3475,17 +3354,17 @@ var DataSpace = class {
3475
3354
  this._automergeSpaceState.startProcessingRootDocs();
3476
3355
  await (0, import_context7.cancelWithContext)(this._ctx, this.automergeSpaceState.ensureEpochInitialized());
3477
3356
  (0, import_log8.log)("data pipeline ready", void 0, {
3478
- F: __dxlog_file12,
3357
+ F: __dxlog_file11,
3479
3358
  L: 279,
3480
3359
  S: this,
3481
3360
  C: (f, a) => f(...a)
3482
3361
  });
3483
3362
  await this._callbacks.beforeReady?.();
3484
- this._state = import_services9.SpaceState.READY;
3363
+ this._state = import_services7.SpaceState.READY;
3485
3364
  (0, import_log8.log)("new state", {
3486
- state: import_services9.SpaceState[this._state]
3365
+ state: import_services7.SpaceState[this._state]
3487
3366
  }, {
3488
- F: __dxlog_file12,
3367
+ F: __dxlog_file11,
3489
3368
  L: 283,
3490
3369
  S: this,
3491
3370
  C: (f, a) => f(...a)
@@ -3501,7 +3380,7 @@ var DataSpace = class {
3501
3380
  this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
3502
3381
  await this._createWritableFeeds();
3503
3382
  (0, import_log8.log)("writable feeds created", void 0, {
3504
- F: __dxlog_file12,
3383
+ F: __dxlog_file11,
3505
3384
  L: 299,
3506
3385
  S: this,
3507
3386
  C: (f, a) => f(...a)
@@ -3529,7 +3408,7 @@ var DataSpace = class {
3529
3408
  spaceKey: this.key,
3530
3409
  deviceKey: this._signingContext.deviceKey,
3531
3410
  identityKey: this._signingContext.identityKey,
3532
- designation: import_credentials10.AdmittedFeed.Designation.CONTROL
3411
+ designation: import_credentials9.AdmittedFeed.Designation.CONTROL
3533
3412
  }
3534
3413
  }));
3535
3414
  }
@@ -3546,7 +3425,7 @@ var DataSpace = class {
3546
3425
  spaceKey: this.key,
3547
3426
  deviceKey: this._signingContext.deviceKey,
3548
3427
  identityKey: this._signingContext.identityKey,
3549
- designation: import_credentials10.AdmittedFeed.Designation.DATA
3428
+ designation: import_credentials9.AdmittedFeed.Designation.DATA
3550
3429
  }
3551
3430
  }));
3552
3431
  }
@@ -3564,7 +3443,7 @@ var DataSpace = class {
3564
3443
  space: this.key,
3565
3444
  rootUrl
3566
3445
  }, {
3567
- F: __dxlog_file12,
3446
+ F: __dxlog_file11,
3568
3447
  L: 365,
3569
3448
  S: this,
3570
3449
  C: (f, a) => f(...a)
@@ -3579,7 +3458,7 @@ var DataSpace = class {
3579
3458
  if (this._ctx.disposed) {
3580
3459
  return;
3581
3460
  }
3582
- const doc = handle.docSync() ?? (0, import_invariant10.failedInvariant)();
3461
+ const doc = handle.docSync() ?? (0, import_invariant9.failedInvariant)();
3583
3462
  if (!doc.access?.spaceKey) {
3584
3463
  handle.change((doc2) => {
3585
3464
  doc2.access = {
@@ -3596,7 +3475,7 @@ var DataSpace = class {
3596
3475
  rootUrl,
3597
3476
  err
3598
3477
  }, {
3599
- F: __dxlog_file12,
3478
+ F: __dxlog_file11,
3600
3479
  L: 388,
3601
3480
  S: this,
3602
3481
  C: (f, a) => f(...a)
@@ -3623,7 +3502,7 @@ var DataSpace = class {
3623
3502
  let epoch;
3624
3503
  switch (options?.migration) {
3625
3504
  case void 0:
3626
- case import_services9.CreateEpochRequest.Migration.NONE:
3505
+ case import_services7.CreateEpochRequest.Migration.NONE:
3627
3506
  {
3628
3507
  epoch = {
3629
3508
  previousId: this._automergeSpaceState.lastEpoch?.id,
@@ -3633,7 +3512,7 @@ var DataSpace = class {
3633
3512
  };
3634
3513
  }
3635
3514
  break;
3636
- case import_services9.CreateEpochRequest.Migration.INIT_AUTOMERGE:
3515
+ case import_services7.CreateEpochRequest.Migration.INIT_AUTOMERGE:
3637
3516
  {
3638
3517
  const document = this._automergeHost.repo.create();
3639
3518
  epoch = {
@@ -3644,14 +3523,14 @@ var DataSpace = class {
3644
3523
  };
3645
3524
  }
3646
3525
  break;
3647
- case import_services9.CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY:
3526
+ case import_services7.CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY:
3648
3527
  {
3649
3528
  const currentRootUrl = this._automergeSpaceState.rootUrl;
3650
3529
  const rootHandle = this._automergeHost.repo.find(currentRootUrl);
3651
3530
  await (0, import_context7.cancelWithContext)(this._ctx, (0, import_async10.asyncTimeout)(rootHandle.whenReady(), 1e4));
3652
3531
  const newRoot = this._automergeHost.repo.create(rootHandle.docSync());
3653
- (0, import_invariant10.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3654
- F: __dxlog_file12,
3532
+ (0, import_invariant9.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3533
+ F: __dxlog_file11,
3655
3534
  L: 438,
3656
3535
  S: this,
3657
3536
  A: [
@@ -3667,10 +3546,10 @@ var DataSpace = class {
3667
3546
  };
3668
3547
  }
3669
3548
  break;
3670
- case import_services9.CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT:
3549
+ case import_services7.CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT:
3671
3550
  {
3672
3551
  import_log8.log.info("Fragmenting", void 0, {
3673
- F: __dxlog_file12,
3552
+ F: __dxlog_file11,
3674
3553
  L: 450,
3675
3554
  S: this,
3676
3555
  C: (f, a) => f(...a)
@@ -3681,8 +3560,8 @@ var DataSpace = class {
3681
3560
  const objects = Object.entries(rootHandle.docSync().objects);
3682
3561
  const properties = objects.find(([_, value]) => value.system.type?.itemId === import_echo_db.TYPE_PROPERTIES);
3683
3562
  const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
3684
- (0, import_invariant10.invariant)(properties, "Properties not found", {
3685
- F: __dxlog_file12,
3563
+ (0, import_invariant9.invariant)(properties, "Properties not found", {
3564
+ F: __dxlog_file11,
3686
3565
  L: 460,
3687
3566
  S: this,
3688
3567
  A: [
@@ -3697,8 +3576,8 @@ var DataSpace = class {
3697
3576
  ])
3698
3577
  };
3699
3578
  const newRoot = this._automergeHost.repo.create(newSpaceDoc);
3700
- (0, import_invariant10.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3701
- F: __dxlog_file12,
3579
+ (0, import_invariant9.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3580
+ F: __dxlog_file11,
3702
3581
  L: 465,
3703
3582
  S: this,
3704
3583
  A: [
@@ -3750,24 +3629,24 @@ var DataSpace = class {
3750
3629
  ]));
3751
3630
  }
3752
3631
  async activate() {
3753
- if (this._state !== import_services9.SpaceState.INACTIVE) {
3632
+ if (this._state !== import_services7.SpaceState.INACTIVE) {
3754
3633
  return;
3755
3634
  }
3756
- await this._metadataStore.setSpaceState(this.key, import_services9.SpaceState.ACTIVE);
3635
+ await this._metadataStore.setSpaceState(this.key, import_services7.SpaceState.ACTIVE);
3757
3636
  await this._open();
3758
3637
  this.initializeDataPipelineAsync();
3759
3638
  }
3760
3639
  async deactivate() {
3761
- if (this._state === import_services9.SpaceState.INACTIVE) {
3640
+ if (this._state === import_services7.SpaceState.INACTIVE) {
3762
3641
  return;
3763
3642
  }
3764
- await this._metadataStore.setSpaceState(this.key, import_services9.SpaceState.INACTIVE);
3643
+ await this._metadataStore.setSpaceState(this.key, import_services7.SpaceState.INACTIVE);
3765
3644
  await this._close();
3766
- this._state = import_services9.SpaceState.INACTIVE;
3645
+ this._state = import_services7.SpaceState.INACTIVE;
3767
3646
  (0, import_log8.log)("new state", {
3768
- state: import_services9.SpaceState[this._state]
3647
+ state: import_services7.SpaceState[this._state]
3769
3648
  }, {
3770
- F: __dxlog_file12,
3649
+ F: __dxlog_file11,
3771
3650
  L: 531,
3772
3651
  S: this,
3773
3652
  C: (f, a) => f(...a)
@@ -3776,18 +3655,18 @@ var DataSpace = class {
3776
3655
  }
3777
3656
  };
3778
3657
  _ts_decorate4([
3779
- import_tracing5.trace.info()
3658
+ import_tracing4.trace.info()
3780
3659
  ], DataSpace.prototype, "_inner", void 0);
3781
3660
  _ts_decorate4([
3782
- import_tracing5.trace.info()
3661
+ import_tracing4.trace.info()
3783
3662
  ], DataSpace.prototype, "key", null);
3784
3663
  _ts_decorate4([
3785
- import_tracing5.trace.info({
3786
- enum: import_services9.SpaceState
3664
+ import_tracing4.trace.info({
3665
+ enum: import_services7.SpaceState
3787
3666
  })
3788
3667
  ], DataSpace.prototype, "state", null);
3789
3668
  _ts_decorate4([
3790
- import_tracing5.trace.info({
3669
+ import_tracing4.trace.info({
3791
3670
  depth: null
3792
3671
  })
3793
3672
  ], DataSpace.prototype, "_automergeInfo", null);
@@ -3798,12 +3677,12 @@ _ts_decorate4([
3798
3677
  import_async10.synchronized
3799
3678
  ], DataSpace.prototype, "close", null);
3800
3679
  _ts_decorate4([
3801
- import_tracing5.trace.span({
3680
+ import_tracing4.trace.span({
3802
3681
  showInBrowserTimeline: true
3803
3682
  })
3804
3683
  ], DataSpace.prototype, "initializeDataPipeline", null);
3805
3684
  _ts_decorate4([
3806
- import_tracing5.trace.span({
3685
+ import_tracing4.trace.span({
3807
3686
  showInBrowserTimeline: true
3808
3687
  })
3809
3688
  ], DataSpace.prototype, "_initializeAndReadControlPipeline", null);
@@ -3818,11 +3697,11 @@ _ts_decorate4([
3818
3697
  ], DataSpace.prototype, "deactivate", null);
3819
3698
  DataSpace = _ts_decorate4([
3820
3699
  (0, import_async10.trackLeaks)("open", "close"),
3821
- import_tracing5.trace.resource()
3700
+ import_tracing4.trace.resource()
3822
3701
  ], DataSpace);
3823
3702
  var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3824
3703
  const credentials = [
3825
- await (0, import_credentials13.createCredential)({
3704
+ await (0, import_credentials12.createCredential)({
3826
3705
  signer: keyring,
3827
3706
  issuer: space.key,
3828
3707
  subject: space.key,
@@ -3831,14 +3710,14 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3831
3710
  spaceKey: space.key
3832
3711
  }
3833
3712
  }),
3834
- await (0, import_credentials13.createCredential)({
3713
+ await (0, import_credentials12.createCredential)({
3835
3714
  signer: keyring,
3836
3715
  issuer: space.key,
3837
3716
  subject: signingContext.identityKey,
3838
3717
  assertion: {
3839
3718
  "@type": "dxos.halo.credentials.SpaceMember",
3840
3719
  spaceKey: space.key,
3841
- role: import_credentials14.SpaceMember.Role.ADMIN,
3720
+ role: import_credentials13.SpaceMember.Role.ADMIN,
3842
3721
  profile: signingContext.getProfile(),
3843
3722
  genesisFeedKey: space.controlFeedKey ?? (0, import_debug4.failUndefined)()
3844
3723
  }
@@ -3850,7 +3729,7 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3850
3729
  spaceKey: space.key,
3851
3730
  identityKey: signingContext.identityKey,
3852
3731
  deviceKey: signingContext.deviceKey,
3853
- designation: import_credentials14.AdmittedFeed.Designation.CONTROL
3732
+ designation: import_credentials13.AdmittedFeed.Designation.CONTROL
3854
3733
  }
3855
3734
  }),
3856
3735
  await signingContext.credentialSigner.createCredential({
@@ -3860,7 +3739,7 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3860
3739
  spaceKey: space.key,
3861
3740
  identityKey: signingContext.identityKey,
3862
3741
  deviceKey: signingContext.deviceKey,
3863
- designation: import_credentials14.AdmittedFeed.Designation.DATA
3742
+ designation: import_credentials13.AdmittedFeed.Designation.DATA
3864
3743
  }
3865
3744
  }),
3866
3745
  await signingContext.credentialSigner.createCredential({
@@ -3894,7 +3773,7 @@ function _ts_decorate5(decorators, target, key, desc) {
3894
3773
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3895
3774
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3896
3775
  }
3897
- var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
3776
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
3898
3777
  var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
3899
3778
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
3900
3779
  var DataSpaceManager = class {
@@ -3920,15 +3799,15 @@ var DataSpaceManager = class {
3920
3799
  }
3921
3800
  async open() {
3922
3801
  (0, import_log10.log)("open", void 0, {
3923
- F: __dxlog_file13,
3802
+ F: __dxlog_file12,
3924
3803
  L: 98,
3925
3804
  S: this,
3926
3805
  C: (f, a) => f(...a)
3927
3806
  });
3928
- import_log10.log.trace("dxos.echo.data-space-manager.open", import_protocols10.trace.begin({
3807
+ import_log10.log.trace("dxos.echo.data-space-manager.open", import_protocols9.trace.begin({
3929
3808
  id: this._instanceId
3930
3809
  }), {
3931
- F: __dxlog_file13,
3810
+ F: __dxlog_file12,
3932
3811
  L: 99,
3933
3812
  S: this,
3934
3813
  C: (f, a) => f(...a)
@@ -3936,7 +3815,7 @@ var DataSpaceManager = class {
3936
3815
  (0, import_log10.log)("metadata loaded", {
3937
3816
  spaces: this._metadataStore.spaces.length
3938
3817
  }, {
3939
- F: __dxlog_file13,
3818
+ F: __dxlog_file12,
3940
3819
  L: 100,
3941
3820
  S: this,
3942
3821
  C: (f, a) => f(...a)
@@ -3946,7 +3825,7 @@ var DataSpaceManager = class {
3946
3825
  (0, import_log10.log)("load space", {
3947
3826
  spaceMetadata
3948
3827
  }, {
3949
- F: __dxlog_file13,
3828
+ F: __dxlog_file12,
3950
3829
  L: 104,
3951
3830
  S: this,
3952
3831
  C: (f, a) => f(...a)
@@ -3957,7 +3836,7 @@ var DataSpaceManager = class {
3957
3836
  spaceMetadata,
3958
3837
  err
3959
3838
  }, {
3960
- F: __dxlog_file13,
3839
+ F: __dxlog_file12,
3961
3840
  L: 107,
3962
3841
  S: this,
3963
3842
  C: (f, a) => f(...a)
@@ -3967,14 +3846,14 @@ var DataSpaceManager = class {
3967
3846
  this._isOpen = true;
3968
3847
  this.updated.emit();
3969
3848
  for (const space of this._spaces.values()) {
3970
- if (space.state !== import_services10.SpaceState.INACTIVE) {
3849
+ if (space.state !== import_services8.SpaceState.INACTIVE) {
3971
3850
  space.initializeDataPipelineAsync();
3972
3851
  }
3973
3852
  }
3974
- import_log10.log.trace("dxos.echo.data-space-manager.open", import_protocols10.trace.end({
3853
+ import_log10.log.trace("dxos.echo.data-space-manager.open", import_protocols9.trace.end({
3975
3854
  id: this._instanceId
3976
3855
  }), {
3977
- F: __dxlog_file13,
3856
+ F: __dxlog_file12,
3978
3857
  L: 120,
3979
3858
  S: this,
3980
3859
  C: (f, a) => f(...a)
@@ -3982,7 +3861,7 @@ var DataSpaceManager = class {
3982
3861
  }
3983
3862
  async close() {
3984
3863
  (0, import_log10.log)("close", void 0, {
3985
- F: __dxlog_file13,
3864
+ F: __dxlog_file12,
3986
3865
  L: 125,
3987
3866
  S: this,
3988
3867
  C: (f, a) => f(...a)
@@ -3997,8 +3876,8 @@ var DataSpaceManager = class {
3997
3876
  * Creates a new space writing the genesis credentials to the control feed.
3998
3877
  */
3999
3878
  async createSpace() {
4000
- (0, import_invariant12.invariant)(this._isOpen, "Not open.", {
4001
- F: __dxlog_file13,
3879
+ (0, import_invariant11.invariant)(this._isOpen, "Not open.", {
3880
+ F: __dxlog_file12,
4002
3881
  L: 138,
4003
3882
  S: this,
4004
3883
  A: [
@@ -4014,12 +3893,12 @@ var DataSpaceManager = class {
4014
3893
  genesisFeedKey: controlFeedKey,
4015
3894
  controlFeedKey,
4016
3895
  dataFeedKey,
4017
- state: import_services10.SpaceState.ACTIVE
3896
+ state: import_services8.SpaceState.ACTIVE
4018
3897
  };
4019
3898
  (0, import_log10.log)("creating space...", {
4020
3899
  spaceKey
4021
3900
  }, {
4022
- F: __dxlog_file13,
3901
+ F: __dxlog_file12,
4023
3902
  L: 150,
4024
3903
  S: this,
4025
3904
  C: (f, a) => f(...a)
@@ -4034,8 +3913,8 @@ var DataSpaceManager = class {
4034
3913
  const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRoot.url);
4035
3914
  await this._metadataStore.addSpace(metadata);
4036
3915
  const memberCredential = credentials[1];
4037
- (0, import_invariant12.invariant)((0, import_credentials12.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4038
- F: __dxlog_file13,
3916
+ (0, import_invariant11.invariant)((0, import_credentials11.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3917
+ F: __dxlog_file12,
4039
3918
  L: 163,
4040
3919
  S: this,
4041
3920
  A: [
@@ -4053,13 +3932,13 @@ var DataSpaceManager = class {
4053
3932
  (0, import_log10.log)("accept space", {
4054
3933
  opts
4055
3934
  }, {
4056
- F: __dxlog_file13,
3935
+ F: __dxlog_file12,
4057
3936
  L: 175,
4058
3937
  S: this,
4059
3938
  C: (f, a) => f(...a)
4060
3939
  });
4061
- (0, import_invariant12.invariant)(this._isOpen, "Not open.", {
4062
- F: __dxlog_file13,
3940
+ (0, import_invariant11.invariant)(this._isOpen, "Not open.", {
3941
+ F: __dxlog_file12,
4063
3942
  L: 176,
4064
3943
  S: this,
4065
3944
  A: [
@@ -4067,8 +3946,8 @@ var DataSpaceManager = class {
4067
3946
  "'Not open.'"
4068
3947
  ]
4069
3948
  });
4070
- (0, import_invariant12.invariant)(!this._spaces.has(opts.spaceKey), "Space already exists.", {
4071
- F: __dxlog_file13,
3949
+ (0, import_invariant11.invariant)(!this._spaces.has(opts.spaceKey), "Space already exists.", {
3950
+ F: __dxlog_file12,
4072
3951
  L: 177,
4073
3952
  S: this,
4074
3953
  A: [
@@ -4096,14 +3975,14 @@ var DataSpaceManager = class {
4096
3975
  async waitUntilSpaceReady(spaceKey) {
4097
3976
  await (0, import_context9.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
4098
3977
  const space = this._spaces.get(spaceKey);
4099
- return !!space && space.state === import_services10.SpaceState.READY;
3978
+ return !!space && space.state === import_services8.SpaceState.READY;
4100
3979
  }));
4101
3980
  }
4102
3981
  async _constructSpace(metadata) {
4103
3982
  (0, import_log10.log)("construct space", {
4104
3983
  metadata
4105
3984
  }, {
4106
- F: __dxlog_file13,
3985
+ F: __dxlog_file12,
4107
3986
  L: 210,
4108
3987
  S: this,
4109
3988
  C: (f, a) => f(...a)
@@ -4141,7 +4020,7 @@ var DataSpaceManager = class {
4141
4020
  },
4142
4021
  onAuthFailure: () => {
4143
4022
  import_log10.log.warn("auth failure", void 0, {
4144
- F: __dxlog_file13,
4023
+ F: __dxlog_file12,
4145
4024
  L: 247,
4146
4025
  S: this,
4147
4026
  C: (f, a) => f(...a)
@@ -4153,7 +4032,7 @@ var DataSpaceManager = class {
4153
4032
  dataFeed && await space.setDataFeed(dataFeed);
4154
4033
  const dataSpace = new DataSpace({
4155
4034
  inner: space,
4156
- initialState: metadata.state === import_services10.SpaceState.INACTIVE ? import_services10.SpaceState.INACTIVE : import_services10.SpaceState.CLOSED,
4035
+ initialState: metadata.state === import_services8.SpaceState.INACTIVE ? import_services8.SpaceState.INACTIVE : import_services8.SpaceState.CLOSED,
4157
4036
  metadataStore: this._metadataStore,
4158
4037
  gossip,
4159
4038
  presence,
@@ -4165,7 +4044,7 @@ var DataSpaceManager = class {
4165
4044
  (0, import_log10.log)("before space ready", {
4166
4045
  space: space.key
4167
4046
  }, {
4168
- F: __dxlog_file13,
4047
+ F: __dxlog_file12,
4169
4048
  L: 265,
4170
4049
  S: this,
4171
4050
  C: (f, a) => f(...a)
@@ -4176,7 +4055,7 @@ var DataSpaceManager = class {
4176
4055
  space: space.key,
4177
4056
  open: this._isOpen
4178
4057
  }, {
4179
- F: __dxlog_file13,
4058
+ F: __dxlog_file12,
4180
4059
  L: 268,
4181
4060
  S: this,
4182
4061
  C: (f, a) => f(...a)
@@ -4189,7 +4068,7 @@ var DataSpaceManager = class {
4189
4068
  (0, import_log10.log)("before space close", {
4190
4069
  space: space.key
4191
4070
  }, {
4192
- F: __dxlog_file13,
4071
+ F: __dxlog_file12,
4193
4072
  L: 274,
4194
4073
  S: this,
4195
4074
  C: (f, a) => f(...a)
@@ -4199,7 +4078,7 @@ var DataSpaceManager = class {
4199
4078
  cache: metadata.cache,
4200
4079
  automergeHost: this._automergeHost
4201
4080
  });
4202
- if (metadata.state !== import_services10.SpaceState.INACTIVE) {
4081
+ if (metadata.state !== import_services8.SpaceState.INACTIVE) {
4203
4082
  await dataSpace.open();
4204
4083
  }
4205
4084
  if (metadata.controlTimeframe) {
@@ -4224,7 +4103,7 @@ _ts_decorate5([
4224
4103
  DataSpaceManager = _ts_decorate5([
4225
4104
  (0, import_async13.trackLeaks)("open", "close")
4226
4105
  ], DataSpaceManager);
4227
- var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
4106
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
4228
4107
  var SpacesServiceImpl = class {
4229
4108
  constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
4230
4109
  this._identityManager = _identityManager;
@@ -4241,29 +4120,29 @@ var SpacesServiceImpl = class {
4241
4120
  }
4242
4121
  async updateSpace({ spaceKey, state }) {
4243
4122
  const dataSpaceManager = await this._getDataSpaceManager();
4244
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4123
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols10.SpaceNotFoundError(spaceKey));
4245
4124
  if (state) {
4246
4125
  switch (state) {
4247
- case import_services11.SpaceState.ACTIVE:
4126
+ case import_services9.SpaceState.ACTIVE:
4248
4127
  await space.activate();
4249
4128
  break;
4250
- case import_services11.SpaceState.INACTIVE:
4129
+ case import_services9.SpaceState.INACTIVE:
4251
4130
  await space.deactivate();
4252
4131
  break;
4253
4132
  default:
4254
- throw new import_protocols11.ApiError("Invalid space state");
4133
+ throw new import_protocols10.ApiError("Invalid space state");
4255
4134
  }
4256
4135
  }
4257
4136
  }
4258
4137
  querySpaces() {
4259
- return new import_codec_protobuf11.Stream(({ next, ctx }) => {
4138
+ return new import_codec_protobuf10.Stream(({ next, ctx }) => {
4260
4139
  const scheduler = new import_async14.UpdateScheduler(ctx, async () => {
4261
4140
  const dataSpaceManager = await this._getDataSpaceManager();
4262
4141
  const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
4263
4142
  (0, import_log11.log)("update", {
4264
4143
  spaces
4265
4144
  }, {
4266
- F: __dxlog_file14,
4145
+ F: __dxlog_file13,
4267
4146
  L: 77,
4268
4147
  S: this,
4269
4148
  C: (f, a) => f(...a)
@@ -4303,14 +4182,14 @@ var SpacesServiceImpl = class {
4303
4182
  }
4304
4183
  async postMessage({ spaceKey, channel, message }) {
4305
4184
  const dataSpaceManager = await this._getDataSpaceManager();
4306
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4185
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols10.SpaceNotFoundError(spaceKey));
4307
4186
  await space.postMessage(getChannelId(channel), message);
4308
4187
  }
4309
4188
  subscribeMessages({ spaceKey, channel }) {
4310
- return new import_codec_protobuf11.Stream(({ ctx, next }) => {
4189
+ return new import_codec_protobuf10.Stream(({ ctx, next }) => {
4311
4190
  (0, import_async14.scheduleTask)(ctx, async () => {
4312
4191
  const dataSpaceManager = await this._getDataSpaceManager();
4313
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4192
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols10.SpaceNotFoundError(spaceKey));
4314
4193
  const handle = space.listen(getChannelId(channel), (message) => {
4315
4194
  next(message);
4316
4195
  });
@@ -4319,8 +4198,8 @@ var SpacesServiceImpl = class {
4319
4198
  });
4320
4199
  }
4321
4200
  queryCredentials({ spaceKey, noTail }) {
4322
- return new import_codec_protobuf11.Stream(({ ctx, next, close }) => {
4323
- const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4201
+ return new import_codec_protobuf10.Stream(({ ctx, next, close }) => {
4202
+ const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols10.SpaceNotFoundError(spaceKey));
4324
4203
  const processor = {
4325
4204
  processCredential: async (credential) => {
4326
4205
  next(credential);
@@ -4336,7 +4215,7 @@ var SpacesServiceImpl = class {
4336
4215
  });
4337
4216
  }
4338
4217
  async writeCredentials({ spaceKey, credentials }) {
4339
- const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4218
+ const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols10.SpaceNotFoundError(spaceKey));
4340
4219
  for (const credential of credentials ?? []) {
4341
4220
  if (credential.proof) {
4342
4221
  await space.controlPipeline.writer.write({
@@ -4345,8 +4224,8 @@ var SpacesServiceImpl = class {
4345
4224
  }
4346
4225
  });
4347
4226
  } else {
4348
- (0, import_invariant13.invariant)(!credential.id, "Id on unsigned credentials is not allowed", {
4349
- F: __dxlog_file14,
4227
+ (0, import_invariant12.invariant)(!credential.id, "Id on unsigned credentials is not allowed", {
4228
+ F: __dxlog_file13,
4350
4229
  L: 164,
4351
4230
  S: this,
4352
4231
  A: [
@@ -4354,8 +4233,8 @@ var SpacesServiceImpl = class {
4354
4233
  "'Id on unsigned credentials is not allowed'"
4355
4234
  ]
4356
4235
  });
4357
- (0, import_invariant13.invariant)(this._identityManager.identity, "Identity is not available", {
4358
- F: __dxlog_file14,
4236
+ (0, import_invariant12.invariant)(this._identityManager.identity, "Identity is not available", {
4237
+ F: __dxlog_file13,
4359
4238
  L: 165,
4360
4239
  S: this,
4361
4240
  A: [
@@ -4364,8 +4243,8 @@ var SpacesServiceImpl = class {
4364
4243
  ]
4365
4244
  });
4366
4245
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
4367
- (0, import_invariant13.invariant)(credential.issuer.equals(signer.getIssuer()), void 0, {
4368
- F: __dxlog_file14,
4246
+ (0, import_invariant12.invariant)(credential.issuer.equals(signer.getIssuer()), void 0, {
4247
+ F: __dxlog_file13,
4369
4248
  L: 167,
4370
4249
  S: this,
4371
4250
  A: [
@@ -4387,7 +4266,7 @@ var SpacesServiceImpl = class {
4387
4266
  }
4388
4267
  async createEpoch({ spaceKey, migration }) {
4389
4268
  const dataSpaceManager = await this._getDataSpaceManager();
4390
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4269
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols10.SpaceNotFoundError(spaceKey));
4391
4270
  await space.createEpoch({
4392
4271
  migration
4393
4272
  });
@@ -4396,7 +4275,7 @@ var SpacesServiceImpl = class {
4396
4275
  return {
4397
4276
  spaceKey: space.key,
4398
4277
  state: space.state,
4399
- error: space.error ? (0, import_protocols11.encodeError)(space.error) : void 0,
4278
+ error: space.error ? (0, import_protocols10.encodeError)(space.error) : void 0,
4400
4279
  pipeline: {
4401
4280
  currentEpoch: space.automergeSpaceState.lastEpoch,
4402
4281
  appliedEpoch: space.automergeSpaceState.lastEpoch,
@@ -4421,7 +4300,7 @@ var SpacesServiceImpl = class {
4421
4300
  identityKey: member.key,
4422
4301
  profile: member.profile ?? {}
4423
4302
  },
4424
- presence: member.removed ? import_services11.SpaceMember.PresenceState.REMOVED : isMe || peers.length > 0 ? import_services11.SpaceMember.PresenceState.ONLINE : import_services11.SpaceMember.PresenceState.OFFLINE,
4303
+ presence: member.removed ? import_services9.SpaceMember.PresenceState.REMOVED : isMe || peers.length > 0 ? import_services9.SpaceMember.PresenceState.ONLINE : import_services9.SpaceMember.PresenceState.OFFLINE,
4425
4304
  peerStates: peers
4426
4305
  };
4427
4306
  }),
@@ -4440,7 +4319,7 @@ var createSelectedDocumentsIterator = (automergeHost) => (
4440
4319
  // TODO(mykola): Unload automerge handles after usage.
4441
4320
  async function* loadDocuments(ids) {
4442
4321
  for (const id of ids) {
4443
- const { documentId, objectId } = import_protocols13.idCodec.decode(id);
4322
+ const { documentId, objectId } = import_protocols12.idCodec.decode(id);
4444
4323
  const handle = automergeHost.repo.find(documentId);
4445
4324
  await (0, import_debug7.warnAfterTimeout)(5e3, "to long to load doc", () => handle.whenReady());
4446
4325
  const doc = handle.docSync();
@@ -4473,7 +4352,7 @@ var createDocumentsIterator = (automergeHost) => (
4473
4352
  if (doc.objects) {
4474
4353
  yield Object.entries(doc.objects).map(([objectId, object]) => {
4475
4354
  return {
4476
- id: import_protocols13.idCodec.encode({
4355
+ id: import_protocols12.idCodec.encode({
4477
4356
  documentId: handle.documentId,
4478
4357
  objectId
4479
4358
  }),
@@ -4516,10 +4395,12 @@ function _ts_decorate6(decorators, target, key, desc) {
4516
4395
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4517
4396
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4518
4397
  }
4519
- var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
4520
- var ServiceContext = class {
4521
- constructor(storage, networkManager, signalManager, _runtimeParams) {
4398
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
4399
+ var ServiceContext = class extends import_context10.Resource {
4400
+ constructor(storage, level, networkManager, signalManager, _runtimeParams) {
4401
+ super();
4522
4402
  this.storage = storage;
4403
+ this.level = level;
4523
4404
  this.networkManager = networkManager;
4524
4405
  this.signalManager = signalManager;
4525
4406
  this._runtimeParams = _runtimeParams;
@@ -4549,7 +4430,7 @@ var ServiceContext = class {
4549
4430
  });
4550
4431
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager, this._runtimeParams);
4551
4432
  this.indexMetadata = new import_indexing.IndexMetadataStore({
4552
- directory: storage.createDirectory("index-metadata")
4433
+ db: level.sublevel("index-metadata")
4553
4434
  });
4554
4435
  this.automergeHost = new import_echo_pipeline3.AutomergeHost({
4555
4436
  directory: storage.createDirectory("automerge"),
@@ -4564,21 +4445,21 @@ var ServiceContext = class {
4564
4445
  getAllDocuments: createDocumentsIterator(this.automergeHost)
4565
4446
  });
4566
4447
  this.invitations = new InvitationsHandler(this.networkManager);
4567
- this._handlerFactories.set(import_services12.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug6.failUndefined)(), this._acceptIdentity.bind(this)));
4448
+ this._handlerFactories.set(import_services10.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug6.failUndefined)(), this._acceptIdentity.bind(this)));
4568
4449
  }
4569
- async open(ctx) {
4450
+ async _open(ctx) {
4570
4451
  await this._checkStorageVersion();
4571
4452
  (0, import_log12.log)("opening...", void 0, {
4572
- F: __dxlog_file15,
4573
- L: 151,
4453
+ F: __dxlog_file14,
4454
+ L: 156,
4574
4455
  S: this,
4575
4456
  C: (f, a) => f(...a)
4576
4457
  });
4577
- import_log12.log.trace("dxos.sdk.service-context.open", import_protocols12.trace.begin({
4458
+ import_log12.log.trace("dxos.sdk.service-context.open", import_protocols11.trace.begin({
4578
4459
  id: this._instanceId
4579
4460
  }), {
4580
- F: __dxlog_file15,
4581
- L: 152,
4461
+ F: __dxlog_file14,
4462
+ L: 157,
4582
4463
  S: this,
4583
4464
  C: (f, a) => f(...a)
4584
4465
  });
@@ -4590,25 +4471,25 @@ var ServiceContext = class {
4590
4471
  if (this.identityManager.identity) {
4591
4472
  await this._initialize(ctx);
4592
4473
  }
4593
- import_log12.log.trace("dxos.sdk.service-context.open", import_protocols12.trace.end({
4474
+ import_log12.log.trace("dxos.sdk.service-context.open", import_protocols11.trace.end({
4594
4475
  id: this._instanceId
4595
4476
  }), {
4596
- F: __dxlog_file15,
4597
- L: 162,
4477
+ F: __dxlog_file14,
4478
+ L: 167,
4598
4479
  S: this,
4599
4480
  C: (f, a) => f(...a)
4600
4481
  });
4601
4482
  (0, import_log12.log)("opened", void 0, {
4602
- F: __dxlog_file15,
4603
- L: 163,
4483
+ F: __dxlog_file14,
4484
+ L: 168,
4604
4485
  S: this,
4605
4486
  C: (f, a) => f(...a)
4606
4487
  });
4607
4488
  }
4608
- async close() {
4489
+ async _close() {
4609
4490
  (0, import_log12.log)("closing...", void 0, {
4610
- F: __dxlog_file15,
4611
- L: 167,
4491
+ F: __dxlog_file14,
4492
+ L: 172,
4612
4493
  S: this,
4613
4494
  C: (f, a) => f(...a)
4614
4495
  });
@@ -4625,8 +4506,8 @@ var ServiceContext = class {
4625
4506
  await this.metadataStore.close();
4626
4507
  await this.indexer.destroy();
4627
4508
  (0, import_log12.log)("closed", void 0, {
4628
- F: __dxlog_file15,
4629
- L: 180,
4509
+ F: __dxlog_file14,
4510
+ L: 185,
4630
4511
  S: this,
4631
4512
  C: (f, a) => f(...a)
4632
4513
  });
@@ -4638,9 +4519,9 @@ var ServiceContext = class {
4638
4519
  }
4639
4520
  getInvitationHandler(invitation) {
4640
4521
  const factory = this._handlerFactories.get(invitation.kind);
4641
- (0, import_invariant14.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
4642
- F: __dxlog_file15,
4643
- L: 191,
4522
+ (0, import_invariant13.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
4523
+ F: __dxlog_file14,
4524
+ L: 196,
4644
4525
  S: this,
4645
4526
  A: [
4646
4527
  "factory",
@@ -4664,15 +4545,15 @@ var ServiceContext = class {
4664
4545
  }
4665
4546
  async _checkStorageVersion() {
4666
4547
  await this.metadataStore.load();
4667
- if (this.metadataStore.version !== import_protocols12.STORAGE_VERSION) {
4668
- throw new import_protocols12.InvalidStorageVersionError(import_protocols12.STORAGE_VERSION, this.metadataStore.version);
4548
+ if (this.metadataStore.version !== import_protocols11.STORAGE_VERSION) {
4549
+ throw new import_protocols11.InvalidStorageVersionError(import_protocols11.STORAGE_VERSION, this.metadataStore.version);
4669
4550
  }
4670
4551
  }
4671
4552
  // Called when identity is created.
4672
4553
  async _initialize(ctx) {
4673
4554
  (0, import_log12.log)("initializing spaces...", void 0, {
4674
- F: __dxlog_file15,
4675
- L: 222,
4555
+ F: __dxlog_file14,
4556
+ L: 227,
4676
4557
  S: this,
4677
4558
  C: (f, a) => f(...a)
4678
4559
  });
@@ -4692,10 +4573,10 @@ var ServiceContext = class {
4692
4573
  };
4693
4574
  this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.automergeHost, this._runtimeParams);
4694
4575
  await this.dataSpaceManager.open();
4695
- this._handlerFactories.set(import_services12.Invitation.Kind.SPACE, (invitation) => {
4696
- (0, import_invariant14.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4697
- F: __dxlog_file15,
4698
- L: 246,
4576
+ this._handlerFactories.set(import_services10.Invitation.Kind.SPACE, (invitation) => {
4577
+ (0, import_invariant13.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4578
+ F: __dxlog_file14,
4579
+ L: 251,
4699
4580
  S: this,
4700
4581
  A: [
4701
4582
  "this.dataSpaceManager",
@@ -4707,7 +4588,7 @@ var ServiceContext = class {
4707
4588
  this.initialized.wake();
4708
4589
  this._deviceSpaceSync = {
4709
4590
  processCredential: async (credential) => {
4710
- const assertion = (0, import_credentials15.getCredentialAssertion)(credential);
4591
+ const assertion = (0, import_credentials14.getCredentialAssertion)(credential);
4711
4592
  if (assertion["@type"] !== "dxos.halo.credentials.SpaceMember") {
4712
4593
  return;
4713
4594
  }
@@ -4718,8 +4599,8 @@ var ServiceContext = class {
4718
4599
  (0, import_log12.log)("dataSpaceManager not initialized yet, ignoring space admission", {
4719
4600
  details: assertion
4720
4601
  }, {
4721
- F: __dxlog_file15,
4722
- L: 262,
4602
+ F: __dxlog_file14,
4603
+ L: 267,
4723
4604
  S: this,
4724
4605
  C: (f, a) => f(...a)
4725
4606
  });
@@ -4729,8 +4610,8 @@ var ServiceContext = class {
4729
4610
  (0, import_log12.log)("space already exists, ignoring space admission", {
4730
4611
  details: assertion
4731
4612
  }, {
4732
- F: __dxlog_file15,
4733
- L: 266,
4613
+ F: __dxlog_file14,
4614
+ L: 271,
4734
4615
  S: this,
4735
4616
  C: (f, a) => f(...a)
4736
4617
  });
@@ -4740,8 +4621,8 @@ var ServiceContext = class {
4740
4621
  (0, import_log12.log)("accepting space recorded in halo", {
4741
4622
  details: assertion
4742
4623
  }, {
4743
- F: __dxlog_file15,
4744
- L: 271,
4624
+ F: __dxlog_file14,
4625
+ L: 276,
4745
4626
  S: this,
4746
4627
  C: (f, a) => f(...a)
4747
4628
  });
@@ -4751,8 +4632,8 @@ var ServiceContext = class {
4751
4632
  });
4752
4633
  } catch (err) {
4753
4634
  import_log12.log.catch(err, void 0, {
4754
- F: __dxlog_file15,
4755
- L: 277,
4635
+ F: __dxlog_file14,
4636
+ L: 282,
4756
4637
  S: this,
4757
4638
  C: (f, a) => f(...a)
4758
4639
  });
@@ -4763,14 +4644,14 @@ var ServiceContext = class {
4763
4644
  }
4764
4645
  };
4765
4646
  _ts_decorate6([
4766
- import_tracing6.trace.span()
4767
- ], ServiceContext.prototype, "open", null);
4647
+ import_tracing5.trace.span()
4648
+ ], ServiceContext.prototype, "_open", null);
4768
4649
  _ts_decorate6([
4769
- import_tracing6.trace.span()
4650
+ import_tracing5.trace.span()
4770
4651
  ], ServiceContext.prototype, "_initialize", null);
4771
4652
  ServiceContext = _ts_decorate6([
4772
4653
  (0, import_util7.safeInstanceof)("dxos.client-services.ServiceContext"),
4773
- import_tracing6.trace.resource()
4654
+ import_tracing5.trace.resource()
4774
4655
  ], ServiceContext);
4775
4656
  var ServiceRegistry = class {
4776
4657
  // prettier-ignore
@@ -4794,103 +4675,155 @@ var ServiceRegistry = class {
4794
4675
  delete this._handlers[name];
4795
4676
  }
4796
4677
  };
4797
- function _ts_decorate7(decorators, target, key, desc) {
4798
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4799
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
4800
- r = Reflect.decorate(decorators, target, key, desc);
4801
- else
4802
- for (var i = decorators.length - 1; i >= 0; i--)
4803
- if (d = decorators[i])
4804
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4805
- return c > 3 && r && Object.defineProperty(target, key, r), r;
4806
- }
4807
- var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/node.ts";
4808
- var Lock = class {
4809
- constructor({ lockKey: lockPath, onAcquire, onRelease }) {
4810
- this._lockPath = lockPath;
4811
- this._onAcquire = onAcquire;
4812
- this._onRelease = onRelease;
4813
- }
4814
- get lockKey() {
4815
- return this._lockPath;
4816
- }
4817
- async acquire() {
4818
- (0, import_log13.log)("acquiring lock...", void 0, {
4819
- F: __dxlog_file16,
4820
- L: 32,
4821
- S: this,
4822
- C: (f, a) => f(...a)
4823
- });
4824
- this._fileHandle = await import_lock_file.LockFile.acquire(this._lockPath);
4825
- await this._onAcquire?.();
4826
- (0, import_log13.log)("acquired lock", void 0, {
4827
- F: __dxlog_file16,
4828
- L: 37,
4829
- S: this,
4830
- C: (f, a) => f(...a)
4831
- });
4678
+ var DXOS_VERSION = "0.4.10-main.d4766e5";
4679
+ var getPlatform = () => {
4680
+ if (process.browser) {
4681
+ if (typeof window !== "undefined") {
4682
+ const { userAgent } = window.navigator;
4683
+ return {
4684
+ type: import_services12.Platform.PLATFORM_TYPE.BROWSER,
4685
+ userAgent,
4686
+ uptime: Math.floor((Date.now() - window.performance.timeOrigin) / 1e3)
4687
+ };
4688
+ } else {
4689
+ return {
4690
+ type: import_services12.Platform.PLATFORM_TYPE.SHARED_WORKER,
4691
+ uptime: Math.floor((Date.now() - performance.timeOrigin) / 1e3)
4692
+ };
4693
+ }
4694
+ } else {
4695
+ const { platform: platform2, version, arch } = process;
4696
+ return {
4697
+ type: import_services12.Platform.PLATFORM_TYPE.NODE,
4698
+ platform: platform2,
4699
+ arch,
4700
+ runtime: version,
4701
+ uptime: Math.floor(process.uptime()),
4702
+ memory: process.memoryUsage()
4703
+ };
4832
4704
  }
4833
- async release() {
4834
- await this._onRelease?.();
4835
- (0, import_invariant15.invariant)(this._fileHandle, "Lock is not acquired", {
4836
- F: __dxlog_file16,
4837
- L: 42,
4838
- S: this,
4705
+ };
4706
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts";
4707
+ var DEFAULT_TIMEOUT = 1e3;
4708
+ var createDiagnostics = async (clientServices, serviceContext, config) => {
4709
+ const diagnostics = {
4710
+ created: (/* @__PURE__ */ new Date()).toISOString(),
4711
+ platform: getPlatform(),
4712
+ client: {
4713
+ version: DXOS_VERSION,
4714
+ storage: {
4715
+ version: import_protocols13.STORAGE_VERSION
4716
+ }
4717
+ },
4718
+ trace: import_tracing6.TRACE_PROCESSOR.getDiagnostics()
4719
+ };
4720
+ {
4721
+ (0, import_invariant14.invariant)(clientServices.LoggingService, "SystemService is not available.", {
4722
+ F: __dxlog_file15,
4723
+ L: 108,
4724
+ S: void 0,
4839
4725
  A: [
4840
- "this._fileHandle",
4841
- "'Lock is not acquired'"
4726
+ "clientServices.LoggingService",
4727
+ "'SystemService is not available.'"
4842
4728
  ]
4843
4729
  });
4844
- await import_lock_file.LockFile.release(this._fileHandle);
4845
- }
4846
- };
4847
- _ts_decorate7([
4848
- import_log13.logInfo
4849
- ], Lock.prototype, "lockKey", null);
4850
- var isLocked = (lockPath) => import_lock_file.LockFile.isLocked(lockPath);
4851
- var StorageDriver = import_config.Runtime.Client.Storage.StorageDriver;
4852
- var createStorageObjects = (config) => {
4853
- const { persistent = false, keyStore, dataStore, dataRoot = (0, import_util8.isNode)() ? import_client_protocol4.DX_DATA : "dxos/storage" } = config ?? {};
4854
- if (persistent && dataStore === StorageDriver.RAM) {
4855
- throw new import_protocols14.InvalidConfigError("RAM storage cannot be used in persistent mode.");
4730
+ diagnostics.metrics = await (0, import_codec_protobuf11.getFirstStreamValue)(clientServices.LoggingService.queryMetrics({}), {
4731
+ timeout: DEFAULT_TIMEOUT
4732
+ }).catch(() => void 0);
4856
4733
  }
4857
- if (!persistent && dataStore !== void 0 && dataStore !== StorageDriver.RAM) {
4858
- throw new import_protocols14.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
4734
+ if (typeof navigator !== "undefined" && navigator.storage) {
4735
+ const map = /* @__PURE__ */ new Map();
4736
+ const dir = await navigator.storage.getDirectory();
4737
+ for await (const filename of dir?.keys()) {
4738
+ const idx = filename.indexOf("-", filename.indexOf("-") + 1);
4739
+ if (idx === -1) {
4740
+ continue;
4741
+ }
4742
+ map.set(filename.slice(0, idx), (map.get(filename.slice(0, idx)) ?? 0) + 1);
4743
+ }
4744
+ diagnostics.storage = Array.from(map.entries()).sort((a, b) => b[1] - a[1]).map(([file, count]) => ({
4745
+ file,
4746
+ count
4747
+ }));
4859
4748
  }
4860
- if (persistent && keyStore === StorageDriver.RAM) {
4861
- throw new import_protocols14.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
4749
+ const identity = serviceContext.identityManager.identity;
4750
+ if (identity) {
4751
+ diagnostics.identity = {
4752
+ identityKey: identity.identityKey,
4753
+ spaceKey: identity.space.key,
4754
+ profile: identity.profileDocument
4755
+ };
4756
+ const { devices } = await (0, import_codec_protobuf11.getFirstStreamValue)(clientServices.DevicesService.queryDevices(), {
4757
+ timeout: DEFAULT_TIMEOUT
4758
+ }).catch(() => void 0) ?? {};
4759
+ diagnostics.devices = devices;
4760
+ if (serviceContext.dataSpaceManager) {
4761
+ diagnostics.spaces = await Promise.all(Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space)) ?? []);
4762
+ }
4763
+ const { feeds = [] } = await (0, import_codec_protobuf11.getFirstStreamValue)(clientServices.DevtoolsHost.subscribeToFeeds({}), {
4764
+ timeout: DEFAULT_TIMEOUT
4765
+ }).catch(() => void 0) ?? {};
4766
+ diagnostics.feeds = feeds.map(({ feedKey, bytes, length }) => ({
4767
+ feedKey,
4768
+ bytes,
4769
+ length
4770
+ }));
4771
+ const status = await (0, import_codec_protobuf11.getFirstStreamValue)(clientServices.NetworkService.queryStatus(), {
4772
+ timeout: DEFAULT_TIMEOUT
4773
+ }).catch(() => void 0);
4774
+ diagnostics.networkStatus = status;
4775
+ diagnostics.swarms = serviceContext.networkManager.connectionLog?.swarms;
4862
4776
  }
4863
- if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== void 0) {
4864
- throw new import_protocols14.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
4777
+ diagnostics.config = config.values;
4778
+ return diagnostics;
4779
+ };
4780
+ var getSpaceStats = async (space) => {
4781
+ const stats = {
4782
+ key: space.key,
4783
+ metrics: space.metrics,
4784
+ epochs: space.inner.spaceState.credentials.filter((0, import_credentials15.credentialTypeFilter)("dxos.halo.credentials.Epoch")).map((credential) => ({
4785
+ ...credential.subject.assertion,
4786
+ id: credential.id
4787
+ })),
4788
+ members: Array.from(space.inner.spaceState.members.values()).map((member) => ({
4789
+ identity: {
4790
+ identityKey: member.key,
4791
+ profile: {
4792
+ displayName: member.assertion.profile?.displayName
4793
+ }
4794
+ },
4795
+ presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? import_services11.SpaceMember.PresenceState.ONLINE : import_services11.SpaceMember.PresenceState.OFFLINE
4796
+ })),
4797
+ pipeline: {
4798
+ // TODO(burdon): Pick properties from credentials if needed.
4799
+ currentEpoch: space.automergeSpaceState.lastEpoch,
4800
+ appliedEpoch: space.automergeSpaceState.lastEpoch,
4801
+ controlFeeds: space.inner.controlPipeline.state.feeds.map((feed) => feed.key),
4802
+ currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
4803
+ targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
4804
+ totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe
4805
+ }
4806
+ };
4807
+ if (stats.metrics) {
4808
+ const { open, ready } = stats.metrics;
4809
+ stats.metrics.startupTime = open && ready && ready.getTime() - open.getTime();
4865
4810
  }
4811
+ return stats;
4812
+ };
4813
+ var createCollectDiagnosticsBroadcastSender = () => {
4866
4814
  return {
4867
- storage: (0, import_random_access_storage.createStorage)({
4868
- type: persistent ? toStorageType(dataStore) : import_random_access_storage.StorageType.RAM,
4869
- root: `${dataRoot}/`
4870
- })
4815
+ broadcastDiagnosticsRequest: async () => void 0
4871
4816
  };
4872
4817
  };
4873
- var toStorageType = (type) => {
4874
- switch (type) {
4875
- case void 0:
4876
- return void 0;
4877
- case StorageDriver.RAM:
4878
- return import_random_access_storage.StorageType.RAM;
4879
- case StorageDriver.CHROME:
4880
- return import_random_access_storage.StorageType.CHROME;
4881
- case StorageDriver.FIREFOX:
4882
- return import_random_access_storage.StorageType.FIREFOX;
4883
- case StorageDriver.IDB:
4884
- return import_random_access_storage.StorageType.IDB;
4885
- case StorageDriver.NODE:
4886
- return import_random_access_storage.StorageType.NODE;
4887
- case StorageDriver.WEBFS:
4888
- return import_random_access_storage.StorageType.WEBFS;
4889
- default:
4890
- throw new Error(`Invalid storage type: ${StorageDriver[type]}`);
4891
- }
4818
+ var createCollectDiagnosticsBroadcastHandler = (_) => {
4819
+ return {
4820
+ start: () => {
4821
+ },
4822
+ stop: () => {
4823
+ }
4824
+ };
4892
4825
  };
4893
- var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
4826
+ var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
4894
4827
  var DevicesServiceImpl = class {
4895
4828
  constructor(_identityManager) {
4896
4829
  this._identityManager = _identityManager;
@@ -4907,8 +4840,8 @@ var DevicesServiceImpl = class {
4907
4840
  devices: []
4908
4841
  });
4909
4842
  } else {
4910
- (0, import_invariant17.invariant)(this._identityManager.identity?.presence, "presence not present", {
4911
- F: __dxlog_file17,
4843
+ (0, import_invariant16.invariant)(this._identityManager.identity?.presence, "presence not present", {
4844
+ F: __dxlog_file16,
4912
4845
  L: 32,
4913
4846
  S: this,
4914
4847
  A: [
@@ -4923,9 +4856,9 @@ var DevicesServiceImpl = class {
4923
4856
  const peerState = peers.find((peer) => peer.identityKey.equals(key));
4924
4857
  return {
4925
4858
  deviceKey: key,
4926
- kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services14.DeviceKind.CURRENT : import_services14.DeviceKind.TRUSTED,
4859
+ kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services15.DeviceKind.CURRENT : import_services15.DeviceKind.TRUSTED,
4927
4860
  profile,
4928
- presence: isMe ? import_services14.Device.PresenceState.ONLINE : peerState ? import_services14.Device.PresenceState.ONLINE : import_services14.Device.PresenceState.OFFLINE
4861
+ presence: isMe ? import_services15.Device.PresenceState.ONLINE : peerState ? import_services15.Device.PresenceState.ONLINE : import_services15.Device.PresenceState.OFFLINE
4929
4862
  };
4930
4863
  })
4931
4864
  });
@@ -4966,6 +4899,60 @@ var DevicesServiceImpl = class {
4966
4899
  });
4967
4900
  }
4968
4901
  };
4902
+ function _ts_decorate7(decorators, target, key, desc) {
4903
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4904
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
4905
+ r = Reflect.decorate(decorators, target, key, desc);
4906
+ else
4907
+ for (var i = decorators.length - 1; i >= 0; i--)
4908
+ if (d = decorators[i])
4909
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4910
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
4911
+ }
4912
+ var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/node.ts";
4913
+ var Lock = class {
4914
+ constructor({ lockKey: lockPath, onAcquire, onRelease }) {
4915
+ this._lockPath = lockPath;
4916
+ this._onAcquire = onAcquire;
4917
+ this._onRelease = onRelease;
4918
+ }
4919
+ get lockKey() {
4920
+ return this._lockPath;
4921
+ }
4922
+ async acquire() {
4923
+ (0, import_log14.log)("acquiring lock...", void 0, {
4924
+ F: __dxlog_file17,
4925
+ L: 32,
4926
+ S: this,
4927
+ C: (f, a) => f(...a)
4928
+ });
4929
+ this._fileHandle = await import_lock_file.LockFile.acquire(this._lockPath);
4930
+ await this._onAcquire?.();
4931
+ (0, import_log14.log)("acquired lock", void 0, {
4932
+ F: __dxlog_file17,
4933
+ L: 37,
4934
+ S: this,
4935
+ C: (f, a) => f(...a)
4936
+ });
4937
+ }
4938
+ async release() {
4939
+ await this._onRelease?.();
4940
+ (0, import_invariant17.invariant)(this._fileHandle, "Lock is not acquired", {
4941
+ F: __dxlog_file17,
4942
+ L: 42,
4943
+ S: this,
4944
+ A: [
4945
+ "this._fileHandle",
4946
+ "'Lock is not acquired'"
4947
+ ]
4948
+ });
4949
+ await import_lock_file.LockFile.release(this._fileHandle);
4950
+ }
4951
+ };
4952
+ _ts_decorate7([
4953
+ import_log14.logInfo
4954
+ ], Lock.prototype, "lockKey", null);
4955
+ var isLocked = (lockPath) => import_lock_file.LockFile.isLocked(lockPath);
4969
4956
  var LoggingServiceImpl = class {
4970
4957
  constructor() {
4971
4958
  this._logs = new import_async18.Event();
@@ -5065,18 +5052,18 @@ var LoggingServiceImpl = class {
5065
5052
  });
5066
5053
  }
5067
5054
  };
5068
- var matchFilter = (filter, level, path, options) => {
5055
+ var matchFilter = (filter, level, path2, options) => {
5069
5056
  switch (options) {
5070
- case import_services15.QueryLogsRequest.MatchingOptions.INCLUSIVE:
5071
- return level >= filter.level && (!filter.pattern || path.includes(filter.pattern));
5072
- case import_services15.QueryLogsRequest.MatchingOptions.EXPLICIT:
5073
- return level === filter.level && (!filter.pattern || path.includes(filter.pattern));
5057
+ case import_services16.QueryLogsRequest.MatchingOptions.INCLUSIVE:
5058
+ return level >= filter.level && (!filter.pattern || path2.includes(filter.pattern));
5059
+ case import_services16.QueryLogsRequest.MatchingOptions.EXPLICIT:
5060
+ return level === filter.level && (!filter.pattern || path2.includes(filter.pattern));
5074
5061
  }
5075
5062
  };
5076
5063
  var shouldLog = (entry2, request) => {
5077
- const options = request.options ?? import_services15.QueryLogsRequest.MatchingOptions.INCLUSIVE;
5064
+ const options = request.options ?? import_services16.QueryLogsRequest.MatchingOptions.INCLUSIVE;
5078
5065
  if (request.filters === void 0) {
5079
- return options === import_services15.QueryLogsRequest.MatchingOptions.INCLUSIVE;
5066
+ return options === import_services16.QueryLogsRequest.MatchingOptions.INCLUSIVE;
5080
5067
  } else {
5081
5068
  return request.filters.some((filter) => matchFilter(filter, entry2.level, entry2.meta?.F ?? "", options));
5082
5069
  }
@@ -5112,6 +5099,63 @@ var NetworkServiceImpl = class {
5112
5099
  await this.networkManager.setConnectionState(request.swarm);
5113
5100
  }
5114
5101
  };
5102
+ var getRootPath = (config) => {
5103
+ const { dataRoot = (0, import_util11.isNode)() ? import_client_protocol5.DX_DATA : "dxos/storage" } = config ?? {};
5104
+ return `${dataRoot}/`;
5105
+ };
5106
+ var isPersistent = (config) => {
5107
+ const { persistent = false } = config ?? {};
5108
+ return config.dataStore !== void 0 && config.dataStore !== import_config3.Runtime.Client.Storage.StorageDriver.RAM || persistent;
5109
+ };
5110
+ var StorageDriver = import_config2.Runtime.Client.Storage.StorageDriver;
5111
+ var createStorageObjects = (config) => {
5112
+ const { persistent = false, keyStore, dataStore } = config ?? {};
5113
+ if (persistent && dataStore === StorageDriver.RAM) {
5114
+ throw new import_protocols15.InvalidConfigError("RAM storage cannot be used in persistent mode.");
5115
+ }
5116
+ if (!persistent && dataStore !== void 0 && dataStore !== StorageDriver.RAM) {
5117
+ throw new import_protocols15.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
5118
+ }
5119
+ if (persistent && keyStore === StorageDriver.RAM) {
5120
+ throw new import_protocols15.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
5121
+ }
5122
+ if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== void 0) {
5123
+ throw new import_protocols15.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
5124
+ }
5125
+ return {
5126
+ storage: (0, import_random_access_storage.createStorage)({
5127
+ type: persistent ? toStorageType(dataStore) : import_random_access_storage.StorageType.RAM,
5128
+ root: getRootPath(config)
5129
+ })
5130
+ };
5131
+ };
5132
+ var toStorageType = (type) => {
5133
+ switch (type) {
5134
+ case void 0:
5135
+ return void 0;
5136
+ case StorageDriver.RAM:
5137
+ return import_random_access_storage.StorageType.RAM;
5138
+ case StorageDriver.CHROME:
5139
+ return import_random_access_storage.StorageType.CHROME;
5140
+ case StorageDriver.FIREFOX:
5141
+ return import_random_access_storage.StorageType.FIREFOX;
5142
+ case StorageDriver.IDB:
5143
+ return import_random_access_storage.StorageType.IDB;
5144
+ case StorageDriver.NODE:
5145
+ return import_random_access_storage.StorageType.NODE;
5146
+ case StorageDriver.WEBFS:
5147
+ return import_random_access_storage.StorageType.WEBFS;
5148
+ default:
5149
+ throw new Error(`Invalid storage type: ${StorageDriver[type]}`);
5150
+ }
5151
+ };
5152
+ var createLevel = async (config) => {
5153
+ const persistent = isPersistent(config);
5154
+ const storagePath = persistent ? getRootPath(config) : import_node_path.default.join("tmp", "level", import_keys13.PublicKey.random().toHex());
5155
+ const level = new import_level.Level(storagePath);
5156
+ await level.open();
5157
+ return level;
5158
+ };
5115
5159
  var SystemServiceImpl = class {
5116
5160
  constructor({ config, statusUpdate, getDiagnostics, onUpdateStatus, getCurrentStatus, onReset }) {
5117
5161
  this._config = config;
@@ -5131,9 +5175,9 @@ var SystemServiceImpl = class {
5131
5175
  const diagnostics = await this._getDiagnostics();
5132
5176
  return {
5133
5177
  timestamp: /* @__PURE__ */ new Date(),
5134
- diagnostics: JSON.parse(JSON.stringify(diagnostics, (0, import_util11.jsonKeyReplacer)({
5135
- truncate: keys === import_services16.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
5136
- humanize: keys === import_services16.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
5178
+ diagnostics: JSON.parse(JSON.stringify(diagnostics, (0, import_util12.jsonKeyReplacer)({
5179
+ truncate: keys === import_services17.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
5180
+ humanize: keys === import_services17.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
5137
5181
  })))
5138
5182
  };
5139
5183
  }
@@ -5186,7 +5230,7 @@ var ClientServicesHost = class {
5186
5230
  callbacks,
5187
5231
  runtimeParams
5188
5232
  } = {}) {
5189
- this._tracingService = import_tracing7.TRACE_PROCESSOR.createTraceSender();
5233
+ this._tracingService = import_tracing8.TRACE_PROCESSOR.createTraceSender();
5190
5234
  this._statusUpdate = new import_async16.Event();
5191
5235
  this._opening = false;
5192
5236
  this._open = false;
@@ -5214,14 +5258,14 @@ var ClientServicesHost = class {
5214
5258
  this._systemService = new SystemServiceImpl({
5215
5259
  config: () => this._config,
5216
5260
  statusUpdate: this._statusUpdate,
5217
- getCurrentStatus: () => this.isOpen ? import_services13.SystemStatus.ACTIVE : import_services13.SystemStatus.INACTIVE,
5261
+ getCurrentStatus: () => this.isOpen ? import_services14.SystemStatus.ACTIVE : import_services14.SystemStatus.INACTIVE,
5218
5262
  getDiagnostics: () => {
5219
5263
  return createDiagnostics(this._serviceRegistry.services, this._serviceContext, this._config);
5220
5264
  },
5221
5265
  onUpdateStatus: async (status) => {
5222
- if (!this.isOpen && status === import_services13.SystemStatus.ACTIVE) {
5266
+ if (!this.isOpen && status === import_services14.SystemStatus.ACTIVE) {
5223
5267
  await this._resourceLock?.acquire();
5224
- } else if (this.isOpen && status === import_services13.SystemStatus.INACTIVE) {
5268
+ } else if (this.isOpen && status === import_services14.SystemStatus.INACTIVE) {
5225
5269
  await this._resourceLock?.release();
5226
5270
  }
5227
5271
  },
@@ -5229,8 +5273,9 @@ var ClientServicesHost = class {
5229
5273
  await this.reset();
5230
5274
  }
5231
5275
  });
5276
+ this.diagnosticsBroadcastHandler = createCollectDiagnosticsBroadcastHandler(this._systemService);
5232
5277
  this._loggingService = new LoggingServiceImpl();
5233
- this._serviceRegistry = new ServiceRegistry(import_client_protocol5.clientServiceBundle, {
5278
+ this._serviceRegistry = new ServiceRegistry(import_client_protocol4.clientServiceBundle, {
5234
5279
  SystemService: this._systemService,
5235
5280
  TracingService: this._tracingService
5236
5281
  });
@@ -5259,25 +5304,25 @@ var ClientServicesHost = class {
5259
5304
  * Can only be called once.
5260
5305
  */
5261
5306
  initialize({ config, ...options }) {
5262
- (0, import_invariant16.invariant)(!this._open, "service host is open", {
5307
+ (0, import_invariant15.invariant)(!this._open, "service host is open", {
5263
5308
  F: __dxlog_file18,
5264
- L: 180,
5309
+ L: 188,
5265
5310
  S: this,
5266
5311
  A: [
5267
5312
  "!this._open",
5268
5313
  "'service host is open'"
5269
5314
  ]
5270
5315
  });
5271
- (0, import_log14.log)("initializing...", void 0, {
5316
+ (0, import_log13.log)("initializing...", void 0, {
5272
5317
  F: __dxlog_file18,
5273
- L: 181,
5318
+ L: 189,
5274
5319
  S: this,
5275
5320
  C: (f, a) => f(...a)
5276
5321
  });
5277
5322
  if (config) {
5278
- (0, import_invariant16.invariant)(!this._config, "config already set", {
5323
+ (0, import_invariant15.invariant)(!this._config, "config already set", {
5279
5324
  F: __dxlog_file18,
5280
- L: 184,
5325
+ L: 192,
5281
5326
  S: this,
5282
5327
  A: [
5283
5328
  "!this._config",
@@ -5290,9 +5335,9 @@ var ClientServicesHost = class {
5290
5335
  }
5291
5336
  }
5292
5337
  if (!options.signalManager) {
5293
- import_log14.log.warn("running signaling without telemetry metadata.", void 0, {
5338
+ import_log13.log.warn("running signaling without telemetry metadata.", void 0, {
5294
5339
  F: __dxlog_file18,
5295
- L: 192,
5340
+ L: 200,
5296
5341
  S: this,
5297
5342
  C: (f, a) => f(...a)
5298
5343
  });
@@ -5301,9 +5346,9 @@ var ClientServicesHost = class {
5301
5346
  iceServers: this._config?.get("runtime.services.ice")
5302
5347
  }), signalManager = new import_messaging.WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
5303
5348
  this._signalManager = signalManager;
5304
- (0, import_invariant16.invariant)(!this._networkManager, "network manager already set", {
5349
+ (0, import_invariant15.invariant)(!this._networkManager, "network manager already set", {
5305
5350
  F: __dxlog_file18,
5306
- L: 203,
5351
+ L: 211,
5307
5352
  S: this,
5308
5353
  A: [
5309
5354
  "!this._networkManager",
@@ -5315,9 +5360,9 @@ var ClientServicesHost = class {
5315
5360
  transportFactory,
5316
5361
  signalManager
5317
5362
  });
5318
- (0, import_log14.log)("initialized", void 0, {
5363
+ (0, import_log13.log)("initialized", void 0, {
5319
5364
  F: __dxlog_file18,
5320
- L: 210,
5365
+ L: 218,
5321
5366
  S: this,
5322
5367
  C: (f, a) => f(...a)
5323
5368
  });
@@ -5327,44 +5372,44 @@ var ClientServicesHost = class {
5327
5372
  return;
5328
5373
  }
5329
5374
  const traceId = import_keys11.PublicKey.random().toHex();
5330
- import_log14.log.trace("dxos.client-services.host.open", import_protocols15.trace.begin({
5375
+ import_log13.log.trace("dxos.client-services.host.open", import_protocols14.trace.begin({
5331
5376
  id: traceId
5332
5377
  }), {
5333
5378
  F: __dxlog_file18,
5334
- L: 221,
5379
+ L: 229,
5335
5380
  S: this,
5336
5381
  C: (f, a) => f(...a)
5337
5382
  });
5338
- (0, import_invariant16.invariant)(this._config, "config not set", {
5383
+ (0, import_invariant15.invariant)(this._config, "config not set", {
5339
5384
  F: __dxlog_file18,
5340
- L: 223,
5385
+ L: 231,
5341
5386
  S: this,
5342
5387
  A: [
5343
5388
  "this._config",
5344
5389
  "'config not set'"
5345
5390
  ]
5346
5391
  });
5347
- (0, import_invariant16.invariant)(this._storage, "storage not set", {
5392
+ (0, import_invariant15.invariant)(this._storage, "storage not set", {
5348
5393
  F: __dxlog_file18,
5349
- L: 224,
5394
+ L: 232,
5350
5395
  S: this,
5351
5396
  A: [
5352
5397
  "this._storage",
5353
5398
  "'storage not set'"
5354
5399
  ]
5355
5400
  });
5356
- (0, import_invariant16.invariant)(this._signalManager, "signal manager not set", {
5401
+ (0, import_invariant15.invariant)(this._signalManager, "signal manager not set", {
5357
5402
  F: __dxlog_file18,
5358
- L: 225,
5403
+ L: 233,
5359
5404
  S: this,
5360
5405
  A: [
5361
5406
  "this._signalManager",
5362
5407
  "'signal manager not set'"
5363
5408
  ]
5364
5409
  });
5365
- (0, import_invariant16.invariant)(this._networkManager, "network manager not set", {
5410
+ (0, import_invariant15.invariant)(this._networkManager, "network manager not set", {
5366
5411
  F: __dxlog_file18,
5367
- L: 226,
5412
+ L: 234,
5368
5413
  S: this,
5369
5414
  A: [
5370
5415
  "this._networkManager",
@@ -5372,17 +5417,20 @@ var ClientServicesHost = class {
5372
5417
  ]
5373
5418
  });
5374
5419
  this._opening = true;
5375
- (0, import_log14.log)("opening...", {
5420
+ (0, import_log13.log)("opening...", {
5376
5421
  lockKey: this._resourceLock?.lockKey
5377
5422
  }, {
5378
5423
  F: __dxlog_file18,
5379
- L: 229,
5424
+ L: 237,
5380
5425
  S: this,
5381
5426
  C: (f, a) => f(...a)
5382
5427
  });
5428
+ if (!this._level) {
5429
+ this._level = await createLevel(this._config.get("runtime.client.storage", {}));
5430
+ }
5383
5431
  await this._resourceLock?.acquire();
5384
5432
  await this._loggingService.open();
5385
- this._serviceContext = new ServiceContext(this._storage, this._networkManager, this._signalManager, this._runtimeParams);
5433
+ this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._runtimeParams);
5386
5434
  this._serviceRegistry.setServices({
5387
5435
  SystemService: this._systemService,
5388
5436
  IdentityService: new IdentityServiceImpl((params) => this._createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring, (profile) => this._serviceContext.broadcastProfileUpdate(profile)),
@@ -5408,9 +5456,9 @@ var ClientServicesHost = class {
5408
5456
  })
5409
5457
  });
5410
5458
  await this._serviceContext.open(ctx);
5411
- (0, import_invariant16.invariant)(this.serviceRegistry.services.InvitationsService, void 0, {
5459
+ (0, import_invariant15.invariant)(this.serviceRegistry.services.InvitationsService, void 0, {
5412
5460
  F: __dxlog_file18,
5413
- L: 290,
5461
+ L: 303,
5414
5462
  S: this,
5415
5463
  A: [
5416
5464
  "this.serviceRegistry.services.InvitationsService",
@@ -5418,11 +5466,11 @@ var ClientServicesHost = class {
5418
5466
  ]
5419
5467
  });
5420
5468
  const loadedInvitations = await this.serviceRegistry.services.InvitationsService.loadPersistentInvitations();
5421
- (0, import_log14.log)("loaded persistent invitations", {
5469
+ (0, import_log13.log)("loaded persistent invitations", {
5422
5470
  count: loadedInvitations.invitations?.length
5423
5471
  }, {
5424
5472
  F: __dxlog_file18,
5425
- L: 293,
5473
+ L: 306,
5426
5474
  S: this,
5427
5475
  C: (f, a) => f(...a)
5428
5476
  });
@@ -5431,28 +5479,29 @@ var ClientServicesHost = class {
5431
5479
  this._devtoolsProxy = new import_websocket_rpc.WebsocketRpcClient({
5432
5480
  url: devtoolsProxy,
5433
5481
  requested: {},
5434
- exposed: import_client_protocol5.clientServiceBundle,
5482
+ exposed: import_client_protocol4.clientServiceBundle,
5435
5483
  handlers: this.services
5436
5484
  });
5437
5485
  void this._devtoolsProxy.open();
5438
5486
  }
5487
+ this.diagnosticsBroadcastHandler.start();
5439
5488
  this._opening = false;
5440
5489
  this._open = true;
5441
5490
  this._statusUpdate.emit();
5442
5491
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
5443
- (0, import_log14.log)("opened", {
5492
+ (0, import_log13.log)("opened", {
5444
5493
  deviceKey
5445
5494
  }, {
5446
5495
  F: __dxlog_file18,
5447
- L: 310,
5496
+ L: 324,
5448
5497
  S: this,
5449
5498
  C: (f, a) => f(...a)
5450
5499
  });
5451
- import_log14.log.trace("dxos.client-services.host.open", import_protocols15.trace.end({
5500
+ import_log13.log.trace("dxos.client-services.host.open", import_protocols14.trace.end({
5452
5501
  id: traceId
5453
5502
  }), {
5454
5503
  F: __dxlog_file18,
5455
- L: 311,
5504
+ L: 325,
5456
5505
  S: this,
5457
5506
  C: (f, a) => f(...a)
5458
5507
  });
@@ -5462,60 +5511,62 @@ var ClientServicesHost = class {
5462
5511
  return;
5463
5512
  }
5464
5513
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
5465
- (0, import_log14.log)("closing...", {
5514
+ (0, import_log13.log)("closing...", {
5466
5515
  deviceKey
5467
5516
  }, {
5468
5517
  F: __dxlog_file18,
5469
- L: 322,
5518
+ L: 336,
5470
5519
  S: this,
5471
5520
  C: (f, a) => f(...a)
5472
5521
  });
5522
+ this.diagnosticsBroadcastHandler.stop();
5473
5523
  await this._devtoolsProxy?.close();
5474
5524
  this._serviceRegistry.setServices({
5475
5525
  SystemService: this._systemService
5476
5526
  });
5477
5527
  await this._loggingService.close();
5478
5528
  await this._serviceContext.close();
5529
+ await this._level?.close();
5479
5530
  this._open = false;
5480
5531
  this._statusUpdate.emit();
5481
- (0, import_log14.log)("closed", {
5532
+ (0, import_log13.log)("closed", {
5482
5533
  deviceKey
5483
5534
  }, {
5484
5535
  F: __dxlog_file18,
5485
- L: 329,
5536
+ L: 345,
5486
5537
  S: this,
5487
5538
  C: (f, a) => f(...a)
5488
5539
  });
5489
5540
  }
5490
5541
  async reset() {
5491
5542
  const traceId = import_keys11.PublicKey.random().toHex();
5492
- import_log14.log.trace("dxos.sdk.client-services-host.reset", import_protocols15.trace.begin({
5543
+ import_log13.log.trace("dxos.sdk.client-services-host.reset", import_protocols14.trace.begin({
5493
5544
  id: traceId
5494
5545
  }), {
5495
5546
  F: __dxlog_file18,
5496
- L: 334,
5547
+ L: 350,
5497
5548
  S: this,
5498
5549
  C: (f, a) => f(...a)
5499
5550
  });
5500
- (0, import_log14.log)("resetting...", void 0, {
5551
+ (0, import_log13.log)("resetting...", void 0, {
5501
5552
  F: __dxlog_file18,
5502
- L: 336,
5553
+ L: 352,
5503
5554
  S: this,
5504
5555
  C: (f, a) => f(...a)
5505
5556
  });
5506
5557
  await this._serviceContext?.close();
5507
5558
  await this._storage.reset();
5508
- (0, import_log14.log)("reset", void 0, {
5559
+ (0, import_log13.log)("reset", void 0, {
5509
5560
  F: __dxlog_file18,
5510
- L: 339,
5561
+ L: 355,
5511
5562
  S: this,
5512
5563
  C: (f, a) => f(...a)
5513
5564
  });
5514
- import_log14.log.trace("dxos.sdk.client-services-host.reset", import_protocols15.trace.end({
5565
+ import_log13.log.trace("dxos.sdk.client-services-host.reset", import_protocols14.trace.end({
5515
5566
  id: traceId
5516
5567
  }), {
5517
5568
  F: __dxlog_file18,
5518
- L: 340,
5569
+ L: 356,
5519
5570
  S: this,
5520
5571
  C: (f, a) => f(...a)
5521
5572
  });
@@ -5526,9 +5577,9 @@ var ClientServicesHost = class {
5526
5577
  await this._serviceContext.initialized.wait();
5527
5578
  const space = await this._serviceContext.dataSpaceManager.createSpace();
5528
5579
  const automergeIndex = space.automergeSpaceState.rootUrl;
5529
- (0, import_invariant16.invariant)(automergeIndex, void 0, {
5580
+ (0, import_invariant15.invariant)(automergeIndex, void 0, {
5530
5581
  F: __dxlog_file18,
5531
- L: 352,
5582
+ L: 368,
5532
5583
  S: this,
5533
5584
  A: [
5534
5585
  "automergeIndex",
@@ -5537,47 +5588,88 @@ var ClientServicesHost = class {
5537
5588
  });
5538
5589
  const document = await this._serviceContext.automergeHost.repo.find(automergeIndex);
5539
5590
  await document.whenReady();
5540
- const objectDocument = (0, import_echo_schema.createRawObjectDoc)({
5541
- [import_client_protocol5.defaultKey]: identity.identityKey.toHex()
5542
- }, {
5543
- type: E.getTypeReference(import_client_protocol5.PropertiesSchema)
5544
- });
5591
+ const properties = {
5592
+ system: {
5593
+ type: (0, import_echo_pipeline4.encodeReference)(E.getTypeReference(import_client_protocol4.Properties))
5594
+ },
5595
+ data: {
5596
+ [import_client_protocol4.defaultKey]: identity.identityKey.toHex()
5597
+ },
5598
+ meta: {
5599
+ keys: []
5600
+ }
5601
+ };
5602
+ const propertiesId = import_keys11.PublicKey.random().toHex();
5545
5603
  document.change((doc) => {
5546
5604
  (0, import_util9.assignDeep)(doc, [
5547
5605
  "objects",
5548
- objectDocument.id
5549
- ], objectDocument.handle.docSync());
5606
+ propertiesId
5607
+ ], properties);
5550
5608
  });
5551
- await (0, import_async16.sleep)(200);
5609
+ await this._serviceContext.automergeHost.repo.flush();
5552
5610
  return identity;
5553
5611
  }
5554
5612
  };
5555
5613
  _ts_decorate8([
5556
- import_tracing7.trace.info()
5614
+ import_tracing8.trace.info()
5557
5615
  ], ClientServicesHost.prototype, "_opening", void 0);
5558
5616
  _ts_decorate8([
5559
- import_tracing7.trace.info()
5617
+ import_tracing8.trace.info()
5560
5618
  ], ClientServicesHost.prototype, "_open", void 0);
5561
5619
  _ts_decorate8([
5562
5620
  import_async16.synchronized,
5563
- import_tracing7.trace.span()
5621
+ import_tracing8.trace.span()
5564
5622
  ], ClientServicesHost.prototype, "open", null);
5565
5623
  _ts_decorate8([
5566
5624
  import_async16.synchronized,
5567
- import_tracing7.trace.span()
5625
+ import_tracing8.trace.span()
5568
5626
  ], ClientServicesHost.prototype, "close", null);
5569
5627
  ClientServicesHost = _ts_decorate8([
5570
- import_tracing7.trace.resource()
5628
+ import_tracing8.trace.resource()
5571
5629
  ], ClientServicesHost);
5630
+ var ClientServicesProviderResource = Symbol.for("dxos.resource.ClientServices");
5631
+ var DiagnosticsCollector = class {
5632
+ static {
5633
+ this.broadcastSender = createCollectDiagnosticsBroadcastSender();
5634
+ }
5635
+ static async collect(config = findConfigs(), services = findSystemServiceProvider(), options = {}) {
5636
+ const serviceDiagnostics = await services?.services?.SystemService?.getDiagnostics({
5637
+ keys: options.humanize ? import_services13.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE : options.truncate ? import_services13.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE : void 0
5638
+ });
5639
+ const clientDiagnostics = {
5640
+ config,
5641
+ trace: import_tracing7.TRACE_PROCESSOR.getDiagnostics()
5642
+ };
5643
+ const diagnostics = serviceDiagnostics != null ? {
5644
+ client: clientDiagnostics,
5645
+ services: serviceDiagnostics
5646
+ } : {
5647
+ client: clientDiagnostics,
5648
+ broadcast: await this.broadcastSender.broadcastDiagnosticsRequest()
5649
+ };
5650
+ return JSON.parse(JSON.stringify(diagnostics, (0, import_util8.jsonKeyReplacer)(options)));
5651
+ }
5652
+ };
5653
+ var findSystemServiceProvider = () => {
5654
+ const serviceProviders = import_tracing7.TRACE_PROCESSOR.findByAnnotation(ClientServicesProviderResource);
5655
+ const providerResource = serviceProviders.find((r) => r.instance.deref()?.services?.SystemService != null);
5656
+ return providerResource?.instance?.deref() ?? null;
5657
+ };
5658
+ var findConfigs = () => {
5659
+ const configs = import_tracing7.TRACE_PROCESSOR.findByAnnotation(import_config.ConfigResource);
5660
+ return configs.map((r) => r.instance.deref()).filter(import_util8.nonNullable);
5661
+ };
5572
5662
  // Annotate the CommonJS export names for ESM import in node:
5573
5663
  0 && (module.exports = {
5574
5664
  ClientRpcServer,
5575
5665
  ClientServicesHost,
5666
+ ClientServicesProviderResource,
5576
5667
  DataSpace,
5577
5668
  DataSpaceManager,
5578
5669
  DeviceInvitationProtocol,
5579
5670
  DevtoolsHostEvents,
5580
5671
  DevtoolsServiceImpl,
5672
+ DiagnosticsCollector,
5581
5673
  Identity,
5582
5674
  IdentityManager,
5583
5675
  IdentityServiceImpl,
@@ -5590,7 +5682,10 @@ ClientServicesHost = _ts_decorate8([
5590
5682
  SpacesServiceImpl,
5591
5683
  TrustedKeySetAuthVerifier,
5592
5684
  createAuthProvider,
5685
+ createCollectDiagnosticsBroadcastHandler,
5686
+ createCollectDiagnosticsBroadcastSender,
5593
5687
  createDiagnostics,
5688
+ createLevel,
5594
5689
  createStorageObjects,
5595
5690
  getNetworkPeers,
5596
5691
  invitationExpired,
@@ -5603,4 +5698,4 @@ ClientServicesHost = _ts_decorate8([
5603
5698
  subscribeToSpaces,
5604
5699
  subscribeToSwarmInfo
5605
5700
  });
5606
- //# sourceMappingURL=chunk-3CGMNOA3.cjs.map
5701
+ //# sourceMappingURL=chunk-54K33CLU.cjs.map