@dxos/client-services 0.4.10-main.c32f430 → 0.4.10-main.c42bfdb

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