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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/dist/lib/browser/{chunk-5YFNO6CM.mjs → chunk-DXJJOAJI.mjs} +695 -513
  2. package/dist/lib/browser/chunk-DXJJOAJI.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +11 -1
  4. package/dist/lib/browser/index.mjs.map +1 -1
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +6 -4
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/{chunk-3CGMNOA3.cjs → chunk-54K33CLU.cjs} +628 -533
  9. package/dist/lib/node/chunk-54K33CLU.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +47 -37
  11. package/dist/lib/node/index.cjs.map +1 -1
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/packlets/testing/index.cjs +10 -8
  14. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  15. package/dist/types/src/index.d.ts +1 -0
  16. package/dist/types/src/index.d.ts.map +1 -1
  17. package/dist/types/src/packlets/diagnostics/browser-diagnostics-broadcast.d.ts +5 -0
  18. package/dist/types/src/packlets/diagnostics/browser-diagnostics-broadcast.d.ts.map +1 -0
  19. package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts +5 -0
  20. package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts.map +1 -0
  21. package/dist/types/src/packlets/diagnostics/diagnostics-collector.d.ts +15 -0
  22. package/dist/types/src/packlets/diagnostics/diagnostics-collector.d.ts.map +1 -0
  23. package/dist/types/src/packlets/{services → diagnostics}/diagnostics.d.ts +1 -1
  24. package/dist/types/src/packlets/diagnostics/diagnostics.d.ts.map +1 -0
  25. package/dist/types/src/packlets/diagnostics/index.d.ts +4 -0
  26. package/dist/types/src/packlets/diagnostics/index.d.ts.map +1 -0
  27. package/dist/types/src/packlets/services/index.d.ts +1 -1
  28. package/dist/types/src/packlets/services/index.d.ts.map +1 -1
  29. package/dist/types/src/packlets/services/service-context.d.ts +7 -5
  30. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  31. package/dist/types/src/packlets/services/service-host.d.ts +2 -0
  32. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  33. package/dist/types/src/packlets/services/util.d.ts +1 -0
  34. package/dist/types/src/packlets/services/util.d.ts.map +1 -1
  35. package/dist/types/src/packlets/storage/index.d.ts +1 -0
  36. package/dist/types/src/packlets/storage/index.d.ts.map +1 -1
  37. package/dist/types/src/packlets/storage/level.d.ts +4 -0
  38. package/dist/types/src/packlets/storage/level.d.ts.map +1 -0
  39. package/dist/types/src/packlets/storage/storage.d.ts.map +1 -1
  40. package/dist/types/src/packlets/storage/util.d.ts +4 -0
  41. package/dist/types/src/packlets/storage/util.d.ts.map +1 -0
  42. package/dist/types/src/packlets/system/system-service.d.ts +1 -1
  43. package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
  44. package/dist/types/src/packlets/testing/test-builder.d.ts +1 -1
  45. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  46. package/dist/types/src/version.d.ts +1 -1
  47. package/package.json +36 -34
  48. package/src/index.ts +1 -0
  49. package/src/packlets/devices/devices-service.test.ts +1 -1
  50. package/src/packlets/diagnostics/browser-diagnostics-broadcast.ts +94 -0
  51. package/src/packlets/diagnostics/diagnostics-broadcast.ts +20 -0
  52. package/src/packlets/diagnostics/diagnostics-collector.ts +65 -0
  53. package/src/packlets/{services → diagnostics}/diagnostics.ts +2 -2
  54. package/src/packlets/diagnostics/index.ts +7 -0
  55. package/src/packlets/identity/identity-service.test.ts +1 -1
  56. package/src/packlets/invitations/device-invitation-protocol.test.ts +1 -1
  57. package/src/packlets/network/network-service.test.ts +1 -1
  58. package/src/packlets/services/index.ts +1 -1
  59. package/src/packlets/services/service-context.test.ts +5 -5
  60. package/src/packlets/services/service-context.ts +10 -5
  61. package/src/packlets/services/service-host.ts +38 -13
  62. package/src/packlets/services/service-registry.test.ts +1 -1
  63. package/src/packlets/services/util.ts +2 -0
  64. package/src/packlets/spaces/spaces-service.test.ts +1 -1
  65. package/src/packlets/storage/index.ts +1 -0
  66. package/src/packlets/storage/level.ts +19 -0
  67. package/src/packlets/storage/storage.ts +3 -9
  68. package/src/packlets/storage/util.ts +19 -0
  69. package/src/packlets/system/system-service.ts +1 -1
  70. package/src/packlets/testing/test-builder.ts +5 -3
  71. package/src/version.ts +1 -1
  72. package/dist/lib/browser/chunk-5YFNO6CM.mjs.map +0 -7
  73. package/dist/lib/node/chunk-3CGMNOA3.cjs.map +0 -7
  74. package/dist/types/src/packlets/services/diagnostics.d.ts.map +0 -1
@@ -2730,156 +2730,6 @@ ClientRpcServer = _ts_decorate3([
2730
2730
  trace5.resource()
2731
2731
  ], ClientRpcServer);
2732
2732
 
2733
- // packages/sdk/client-services/src/packlets/services/diagnostics.ts
2734
- import { getFirstStreamValue } from "@dxos/codec-protobuf";
2735
- import { credentialTypeFilter } from "@dxos/credentials";
2736
- import { invariant as invariant9 } from "@dxos/invariant";
2737
- import { STORAGE_VERSION } from "@dxos/protocols";
2738
- import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
2739
- import { TRACE_PROCESSOR } from "@dxos/tracing";
2740
-
2741
- // packages/sdk/client-services/src/packlets/services/platform.ts
2742
- import { Platform } from "@dxos/protocols/proto/dxos/client/services";
2743
- var getPlatform = () => {
2744
- if (process.browser) {
2745
- if (typeof window !== "undefined") {
2746
- const { userAgent } = window.navigator;
2747
- return {
2748
- type: Platform.PLATFORM_TYPE.BROWSER,
2749
- userAgent,
2750
- uptime: Math.floor((Date.now() - window.performance.timeOrigin) / 1e3)
2751
- };
2752
- } else {
2753
- return {
2754
- type: Platform.PLATFORM_TYPE.SHARED_WORKER,
2755
- uptime: Math.floor((Date.now() - performance.timeOrigin) / 1e3)
2756
- };
2757
- }
2758
- } else {
2759
- const { platform: platform2, version, arch } = process;
2760
- return {
2761
- type: Platform.PLATFORM_TYPE.NODE,
2762
- platform: platform2,
2763
- arch,
2764
- runtime: version,
2765
- uptime: Math.floor(process.uptime()),
2766
- memory: process.memoryUsage()
2767
- };
2768
- }
2769
- };
2770
-
2771
- // packages/sdk/client-services/src/version.ts
2772
- var DXOS_VERSION = "0.4.10-main.d2a7fe7";
2773
-
2774
- // packages/sdk/client-services/src/packlets/services/diagnostics.ts
2775
- var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
2776
- var DEFAULT_TIMEOUT = 1e3;
2777
- var createDiagnostics = async (clientServices, serviceContext, config) => {
2778
- const diagnostics = {
2779
- created: (/* @__PURE__ */ new Date()).toISOString(),
2780
- platform: getPlatform(),
2781
- client: {
2782
- version: DXOS_VERSION,
2783
- storage: {
2784
- version: STORAGE_VERSION
2785
- }
2786
- },
2787
- trace: TRACE_PROCESSOR.getDiagnostics()
2788
- };
2789
- {
2790
- invariant9(clientServices.LoggingService, "SystemService is not available.", {
2791
- F: __dxlog_file10,
2792
- L: 108,
2793
- S: void 0,
2794
- A: [
2795
- "clientServices.LoggingService",
2796
- "'SystemService is not available.'"
2797
- ]
2798
- });
2799
- diagnostics.metrics = await getFirstStreamValue(clientServices.LoggingService.queryMetrics({}), {
2800
- timeout: DEFAULT_TIMEOUT
2801
- }).catch(() => void 0);
2802
- }
2803
- if (typeof navigator !== "undefined" && navigator.storage) {
2804
- const map = /* @__PURE__ */ new Map();
2805
- const dir = await navigator.storage.getDirectory();
2806
- for await (const filename of dir?.keys()) {
2807
- const idx = filename.indexOf("-", filename.indexOf("-") + 1);
2808
- if (idx === -1) {
2809
- continue;
2810
- }
2811
- map.set(filename.slice(0, idx), (map.get(filename.slice(0, idx)) ?? 0) + 1);
2812
- }
2813
- diagnostics.storage = Array.from(map.entries()).sort((a, b) => b[1] - a[1]).map(([file, count]) => ({
2814
- file,
2815
- count
2816
- }));
2817
- }
2818
- const identity = serviceContext.identityManager.identity;
2819
- if (identity) {
2820
- diagnostics.identity = {
2821
- identityKey: identity.identityKey,
2822
- spaceKey: identity.space.key,
2823
- profile: identity.profileDocument
2824
- };
2825
- const { devices } = await getFirstStreamValue(clientServices.DevicesService.queryDevices(), {
2826
- timeout: DEFAULT_TIMEOUT
2827
- }).catch(() => void 0) ?? {};
2828
- diagnostics.devices = devices;
2829
- if (serviceContext.dataSpaceManager) {
2830
- diagnostics.spaces = await Promise.all(Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space)) ?? []);
2831
- }
2832
- const { feeds = [] } = await getFirstStreamValue(clientServices.DevtoolsHost.subscribeToFeeds({}), {
2833
- timeout: DEFAULT_TIMEOUT
2834
- }).catch(() => void 0) ?? {};
2835
- diagnostics.feeds = feeds.map(({ feedKey, bytes, length }) => ({
2836
- feedKey,
2837
- bytes,
2838
- length
2839
- }));
2840
- const status = await getFirstStreamValue(clientServices.NetworkService.queryStatus(), {
2841
- timeout: DEFAULT_TIMEOUT
2842
- }).catch(() => void 0);
2843
- diagnostics.networkStatus = status;
2844
- diagnostics.swarms = serviceContext.networkManager.connectionLog?.swarms;
2845
- }
2846
- diagnostics.config = config.values;
2847
- return diagnostics;
2848
- };
2849
- var getSpaceStats = async (space) => {
2850
- const stats = {
2851
- key: space.key,
2852
- metrics: space.metrics,
2853
- epochs: space.inner.spaceState.credentials.filter(credentialTypeFilter("dxos.halo.credentials.Epoch")).map((credential) => ({
2854
- ...credential.subject.assertion,
2855
- id: credential.id
2856
- })),
2857
- members: Array.from(space.inner.spaceState.members.values()).map((member) => ({
2858
- identity: {
2859
- identityKey: member.key,
2860
- profile: {
2861
- displayName: member.assertion.profile?.displayName
2862
- }
2863
- },
2864
- presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember.PresenceState.ONLINE : SpaceMember.PresenceState.OFFLINE
2865
- })),
2866
- pipeline: {
2867
- // TODO(burdon): Pick properties from credentials if needed.
2868
- currentEpoch: space.automergeSpaceState.lastEpoch,
2869
- appliedEpoch: space.automergeSpaceState.lastEpoch,
2870
- controlFeeds: space.inner.controlPipeline.state.feeds.map((feed) => feed.key),
2871
- currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
2872
- targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
2873
- totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe
2874
- }
2875
- };
2876
- if (stats.metrics) {
2877
- const { open, ready } = stats.metrics;
2878
- stats.metrics.startupTime = open && ready && ready.getTime() - open.getTime();
2879
- }
2880
- return stats;
2881
- };
2882
-
2883
2733
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2884
2734
  import { Event as Event6, asyncTimeout, scheduleTask as scheduleTask5, sleep as sleep2, synchronized, trackLeaks } from "@dxos/async";
2885
2735
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
@@ -2888,7 +2738,7 @@ import { timed, warnAfterTimeout } from "@dxos/debug";
2888
2738
  import { TYPE_PROPERTIES } from "@dxos/echo-db";
2889
2739
  import { createMappedFeedWriter } from "@dxos/echo-pipeline";
2890
2740
  import { AutomergeDocumentLoaderImpl } from "@dxos/echo-pipeline";
2891
- import { failedInvariant, invariant as invariant11 } from "@dxos/invariant";
2741
+ import { failedInvariant, invariant as invariant10 } from "@dxos/invariant";
2892
2742
  import { PublicKey as PublicKey8 } from "@dxos/keys";
2893
2743
  import { log as log9 } from "@dxos/log";
2894
2744
  import { CancelledError, SystemError } from "@dxos/protocols";
@@ -2939,13 +2789,13 @@ var AutomergeSpaceState = class {
2939
2789
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
2940
2790
  import { DeferredTask, Event as Event5, scheduleTask as scheduleTask4, sleep, TimeoutError as TimeoutError2, Trigger as Trigger4 } from "@dxos/async";
2941
2791
  import { Context as Context7, rejectOnDispose } from "@dxos/context";
2942
- import { invariant as invariant10 } from "@dxos/invariant";
2792
+ import { invariant as invariant9 } from "@dxos/invariant";
2943
2793
  import { PublicKey as PublicKey7 } from "@dxos/keys";
2944
2794
  import { log as log8 } from "@dxos/log";
2945
2795
  import { schema as schema3 } from "@dxos/protocols";
2946
2796
  import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
2947
2797
  import { ComplexMap as ComplexMap2, ComplexSet as ComplexSet2, entry } from "@dxos/util";
2948
- var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
2798
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
2949
2799
  var DEFAULT_RETRY_TIMEOUT = 1e3;
2950
2800
  var DEFAULT_SUCCESS_DELAY = 1e3;
2951
2801
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
@@ -2973,13 +2823,13 @@ var NotarizationPlugin = class {
2973
2823
  log8("notarize", {
2974
2824
  credentials
2975
2825
  }, {
2976
- F: __dxlog_file11,
2826
+ F: __dxlog_file10,
2977
2827
  L: 90,
2978
2828
  S: this,
2979
2829
  C: (f, a) => f(...a)
2980
2830
  });
2981
- invariant10(credentials.every((credential) => credential.id), "Credentials must have an id", {
2982
- F: __dxlog_file11,
2831
+ invariant9(credentials.every((credential) => credential.id), "Credentials must have an id", {
2832
+ F: __dxlog_file10,
2983
2833
  L: 91,
2984
2834
  S: this,
2985
2835
  A: [
@@ -2993,7 +2843,7 @@ var NotarizationPlugin = class {
2993
2843
  log8.warn("Notarization error", {
2994
2844
  err
2995
2845
  }, {
2996
- F: __dxlog_file11,
2846
+ F: __dxlog_file10,
2997
2847
  L: 99,
2998
2848
  S: this,
2999
2849
  C: (f, a) => f(...a)
@@ -3009,7 +2859,7 @@ var NotarizationPlugin = class {
3009
2859
  timeout,
3010
2860
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
3011
2861
  }, {
3012
- F: __dxlog_file11,
2862
+ F: __dxlog_file10,
3013
2863
  L: 111,
3014
2864
  S: this,
3015
2865
  C: (f, a) => f(...a)
@@ -3032,7 +2882,7 @@ var NotarizationPlugin = class {
3032
2882
  log8.info("Exhausted all peers to notarize with", {
3033
2883
  retryIn: retryTimeout
3034
2884
  }, {
3035
- F: __dxlog_file11,
2885
+ F: __dxlog_file10,
3036
2886
  L: 136,
3037
2887
  S: this,
3038
2888
  C: (f, a) => f(...a)
@@ -3046,7 +2896,7 @@ var NotarizationPlugin = class {
3046
2896
  peer: peer.localPeerId,
3047
2897
  credentialId: credentials.map((credential) => credential.id)
3048
2898
  }, {
3049
- F: __dxlog_file11,
2899
+ F: __dxlog_file10,
3050
2900
  L: 143,
3051
2901
  S: this,
3052
2902
  C: (f, a) => f(...a)
@@ -3055,7 +2905,7 @@ var NotarizationPlugin = class {
3055
2905
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
3056
2906
  });
3057
2907
  log8("success", void 0, {
3058
- F: __dxlog_file11,
2908
+ F: __dxlog_file10,
3059
2909
  L: 147,
3060
2910
  S: this,
3061
2911
  C: (f, a) => f(...a)
@@ -3064,7 +2914,7 @@ var NotarizationPlugin = class {
3064
2914
  } catch (err) {
3065
2915
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
3066
2916
  log8.info("error notarizing (recoverable)", err, {
3067
- F: __dxlog_file11,
2917
+ F: __dxlog_file10,
3068
2918
  L: 151,
3069
2919
  S: this,
3070
2920
  C: (f, a) => f(...a)
@@ -3082,7 +2932,7 @@ var NotarizationPlugin = class {
3082
2932
  errors.wait()
3083
2933
  ]);
3084
2934
  log8("done", void 0, {
3085
- F: __dxlog_file11,
2935
+ F: __dxlog_file10,
3086
2936
  L: 162,
3087
2937
  S: this,
3088
2938
  C: (f, a) => f(...a)
@@ -3103,8 +2953,8 @@ var NotarizationPlugin = class {
3103
2953
  this._processCredentialsTriggers.delete(credential.id);
3104
2954
  }
3105
2955
  setWriter(writer) {
3106
- invariant10(!this._writer, "Writer already set.", {
3107
- F: __dxlog_file11,
2956
+ invariant9(!this._writer, "Writer already set.", {
2957
+ F: __dxlog_file10,
3108
2958
  L: 181,
3109
2959
  S: this,
3110
2960
  A: [
@@ -3128,8 +2978,8 @@ var NotarizationPlugin = class {
3128
2978
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
3129
2979
  }
3130
2980
  for (const credential of request.credentials ?? []) {
3131
- invariant10(credential.id, "Credential must have an id", {
3132
- F: __dxlog_file11,
2981
+ invariant9(credential.id, "Credential must have an id", {
2982
+ F: __dxlog_file10,
3133
2983
  L: 200,
3134
2984
  S: this,
3135
2985
  A: [
@@ -3149,7 +2999,7 @@ var NotarizationPlugin = class {
3149
2999
  log8("extension opened", {
3150
3000
  peer: extension.localPeerId
3151
3001
  }, {
3152
- F: __dxlog_file11,
3002
+ F: __dxlog_file10,
3153
3003
  L: 211,
3154
3004
  S: this,
3155
3005
  C: (f, a) => f(...a)
@@ -3161,7 +3011,7 @@ var NotarizationPlugin = class {
3161
3011
  log8("extension closed", {
3162
3012
  peer: extension.localPeerId
3163
3013
  }, {
3164
- F: __dxlog_file11,
3014
+ F: __dxlog_file10,
3165
3015
  L: 216,
3166
3016
  S: this,
3167
3017
  C: (f, a) => f(...a)
@@ -3215,7 +3065,7 @@ function _ts_decorate4(decorators, target, key, desc) {
3215
3065
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3216
3066
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3217
3067
  }
3218
- var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
3068
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
3219
3069
  var DataSpace = class {
3220
3070
  constructor(params) {
3221
3071
  this._ctx = new Context8();
@@ -3250,7 +3100,7 @@ var DataSpace = class {
3250
3100
  log9("new state", {
3251
3101
  state: SpaceState[this._state]
3252
3102
  }, {
3253
- F: __dxlog_file12,
3103
+ F: __dxlog_file11,
3254
3104
  L: 140,
3255
3105
  S: this,
3256
3106
  C: (f, a) => f(...a)
@@ -3300,7 +3150,7 @@ var DataSpace = class {
3300
3150
  log9("new state", {
3301
3151
  state: SpaceState[this._state]
3302
3152
  }, {
3303
- F: __dxlog_file12,
3153
+ F: __dxlog_file11,
3304
3154
  L: 198,
3305
3155
  S: this,
3306
3156
  C: (f, a) => f(...a)
@@ -3318,7 +3168,7 @@ var DataSpace = class {
3318
3168
  log9("new state", {
3319
3169
  state: SpaceState[this._state]
3320
3170
  }, {
3321
- F: __dxlog_file12,
3171
+ F: __dxlog_file11,
3322
3172
  L: 212,
3323
3173
  S: this,
3324
3174
  C: (f, a) => f(...a)
@@ -3350,7 +3200,7 @@ var DataSpace = class {
3350
3200
  } catch (err) {
3351
3201
  if (err instanceof CancelledError || err instanceof ContextDisposedError) {
3352
3202
  log9("data pipeline initialization cancelled", err, {
3353
- F: __dxlog_file12,
3203
+ F: __dxlog_file11,
3354
3204
  L: 245,
3355
3205
  S: this,
3356
3206
  C: (f, a) => f(...a)
@@ -3358,7 +3208,7 @@ var DataSpace = class {
3358
3208
  return;
3359
3209
  }
3360
3210
  log9.error("Error initializing data pipeline", err, {
3361
- F: __dxlog_file12,
3211
+ F: __dxlog_file11,
3362
3212
  L: 249,
3363
3213
  S: this,
3364
3214
  C: (f, a) => f(...a)
@@ -3367,7 +3217,7 @@ var DataSpace = class {
3367
3217
  log9("new state", {
3368
3218
  state: SpaceState[this._state]
3369
3219
  }, {
3370
- F: __dxlog_file12,
3220
+ F: __dxlog_file11,
3371
3221
  L: 251,
3372
3222
  S: this,
3373
3223
  C: (f, a) => f(...a)
@@ -3387,7 +3237,7 @@ var DataSpace = class {
3387
3237
  log9("new state", {
3388
3238
  state: SpaceState[this._state]
3389
3239
  }, {
3390
- F: __dxlog_file12,
3240
+ F: __dxlog_file11,
3391
3241
  L: 267,
3392
3242
  S: this,
3393
3243
  C: (f, a) => f(...a)
@@ -3397,7 +3247,7 @@ var DataSpace = class {
3397
3247
  this._automergeSpaceState.startProcessingRootDocs();
3398
3248
  await cancelWithContext2(this._ctx, this.automergeSpaceState.ensureEpochInitialized());
3399
3249
  log9("data pipeline ready", void 0, {
3400
- F: __dxlog_file12,
3250
+ F: __dxlog_file11,
3401
3251
  L: 279,
3402
3252
  S: this,
3403
3253
  C: (f, a) => f(...a)
@@ -3407,7 +3257,7 @@ var DataSpace = class {
3407
3257
  log9("new state", {
3408
3258
  state: SpaceState[this._state]
3409
3259
  }, {
3410
- F: __dxlog_file12,
3260
+ F: __dxlog_file11,
3411
3261
  L: 283,
3412
3262
  S: this,
3413
3263
  C: (f, a) => f(...a)
@@ -3423,7 +3273,7 @@ var DataSpace = class {
3423
3273
  this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
3424
3274
  await this._createWritableFeeds();
3425
3275
  log9("writable feeds created", void 0, {
3426
- F: __dxlog_file12,
3276
+ F: __dxlog_file11,
3427
3277
  L: 299,
3428
3278
  S: this,
3429
3279
  C: (f, a) => f(...a)
@@ -3486,7 +3336,7 @@ var DataSpace = class {
3486
3336
  space: this.key,
3487
3337
  rootUrl
3488
3338
  }, {
3489
- F: __dxlog_file12,
3339
+ F: __dxlog_file11,
3490
3340
  L: 365,
3491
3341
  S: this,
3492
3342
  C: (f, a) => f(...a)
@@ -3518,7 +3368,7 @@ var DataSpace = class {
3518
3368
  rootUrl,
3519
3369
  err
3520
3370
  }, {
3521
- F: __dxlog_file12,
3371
+ F: __dxlog_file11,
3522
3372
  L: 388,
3523
3373
  S: this,
3524
3374
  C: (f, a) => f(...a)
@@ -3572,8 +3422,8 @@ var DataSpace = class {
3572
3422
  const rootHandle = this._automergeHost.repo.find(currentRootUrl);
3573
3423
  await cancelWithContext2(this._ctx, asyncTimeout(rootHandle.whenReady(), 1e4));
3574
3424
  const newRoot = this._automergeHost.repo.create(rootHandle.docSync());
3575
- invariant11(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3576
- F: __dxlog_file12,
3425
+ invariant10(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3426
+ F: __dxlog_file11,
3577
3427
  L: 438,
3578
3428
  S: this,
3579
3429
  A: [
@@ -3592,7 +3442,7 @@ var DataSpace = class {
3592
3442
  case CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT:
3593
3443
  {
3594
3444
  log9.info("Fragmenting", void 0, {
3595
- F: __dxlog_file12,
3445
+ F: __dxlog_file11,
3596
3446
  L: 450,
3597
3447
  S: this,
3598
3448
  C: (f, a) => f(...a)
@@ -3603,8 +3453,8 @@ var DataSpace = class {
3603
3453
  const objects = Object.entries(rootHandle.docSync().objects);
3604
3454
  const properties = objects.find(([_, value]) => value.system.type?.itemId === TYPE_PROPERTIES);
3605
3455
  const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
3606
- invariant11(properties, "Properties not found", {
3607
- F: __dxlog_file12,
3456
+ invariant10(properties, "Properties not found", {
3457
+ F: __dxlog_file11,
3608
3458
  L: 460,
3609
3459
  S: this,
3610
3460
  A: [
@@ -3619,8 +3469,8 @@ var DataSpace = class {
3619
3469
  ])
3620
3470
  };
3621
3471
  const newRoot = this._automergeHost.repo.create(newSpaceDoc);
3622
- invariant11(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3623
- F: __dxlog_file12,
3472
+ invariant10(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3473
+ F: __dxlog_file11,
3624
3474
  L: 465,
3625
3475
  S: this,
3626
3476
  A: [
@@ -3689,7 +3539,7 @@ var DataSpace = class {
3689
3539
  log9("new state", {
3690
3540
  state: SpaceState[this._state]
3691
3541
  }, {
3692
- F: __dxlog_file12,
3542
+ F: __dxlog_file11,
3693
3543
  L: 531,
3694
3544
  S: this,
3695
3545
  C: (f, a) => f(...a)
@@ -3747,7 +3597,7 @@ DataSpace = _ts_decorate4([
3747
3597
  import { Event as Event7, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
3748
3598
  import { Context as Context9, cancelWithContext as cancelWithContext3 } from "@dxos/context";
3749
3599
  import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
3750
- import { invariant as invariant12 } from "@dxos/invariant";
3600
+ import { invariant as invariant11 } from "@dxos/invariant";
3751
3601
  import { PublicKey as PublicKey9 } from "@dxos/keys";
3752
3602
  import { log as log10 } from "@dxos/log";
3753
3603
  import { trace as trace7 } from "@dxos/protocols";
@@ -3758,7 +3608,7 @@ import { ComplexMap as ComplexMap3, deferFunction as deferFunction2, forEachAsyn
3758
3608
  // packages/sdk/client-services/src/packlets/spaces/genesis.ts
3759
3609
  import { createCredential } from "@dxos/credentials";
3760
3610
  import { failUndefined } from "@dxos/debug";
3761
- import { AdmittedFeed as AdmittedFeed4, SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/halo/credentials";
3611
+ import { AdmittedFeed as AdmittedFeed4, SpaceMember } from "@dxos/protocols/proto/dxos/halo/credentials";
3762
3612
  import { Timeframe as Timeframe3 } from "@dxos/timeframe";
3763
3613
  var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3764
3614
  const credentials = [
@@ -3778,7 +3628,7 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3778
3628
  assertion: {
3779
3629
  "@type": "dxos.halo.credentials.SpaceMember",
3780
3630
  spaceKey: space.key,
3781
- role: SpaceMember2.Role.ADMIN,
3631
+ role: SpaceMember.Role.ADMIN,
3782
3632
  profile: signingContext.getProfile(),
3783
3633
  genesisFeedKey: space.controlFeedKey ?? failUndefined()
3784
3634
  }
@@ -3836,7 +3686,7 @@ function _ts_decorate5(decorators, target, key, desc) {
3836
3686
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3837
3687
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3838
3688
  }
3839
- var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
3689
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
3840
3690
  var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
3841
3691
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
3842
3692
  var DataSpaceManager = class {
@@ -3862,7 +3712,7 @@ var DataSpaceManager = class {
3862
3712
  }
3863
3713
  async open() {
3864
3714
  log10("open", void 0, {
3865
- F: __dxlog_file13,
3715
+ F: __dxlog_file12,
3866
3716
  L: 98,
3867
3717
  S: this,
3868
3718
  C: (f, a) => f(...a)
@@ -3870,7 +3720,7 @@ var DataSpaceManager = class {
3870
3720
  log10.trace("dxos.echo.data-space-manager.open", trace7.begin({
3871
3721
  id: this._instanceId
3872
3722
  }), {
3873
- F: __dxlog_file13,
3723
+ F: __dxlog_file12,
3874
3724
  L: 99,
3875
3725
  S: this,
3876
3726
  C: (f, a) => f(...a)
@@ -3878,7 +3728,7 @@ var DataSpaceManager = class {
3878
3728
  log10("metadata loaded", {
3879
3729
  spaces: this._metadataStore.spaces.length
3880
3730
  }, {
3881
- F: __dxlog_file13,
3731
+ F: __dxlog_file12,
3882
3732
  L: 100,
3883
3733
  S: this,
3884
3734
  C: (f, a) => f(...a)
@@ -3888,7 +3738,7 @@ var DataSpaceManager = class {
3888
3738
  log10("load space", {
3889
3739
  spaceMetadata
3890
3740
  }, {
3891
- F: __dxlog_file13,
3741
+ F: __dxlog_file12,
3892
3742
  L: 104,
3893
3743
  S: this,
3894
3744
  C: (f, a) => f(...a)
@@ -3899,7 +3749,7 @@ var DataSpaceManager = class {
3899
3749
  spaceMetadata,
3900
3750
  err
3901
3751
  }, {
3902
- F: __dxlog_file13,
3752
+ F: __dxlog_file12,
3903
3753
  L: 107,
3904
3754
  S: this,
3905
3755
  C: (f, a) => f(...a)
@@ -3916,7 +3766,7 @@ var DataSpaceManager = class {
3916
3766
  log10.trace("dxos.echo.data-space-manager.open", trace7.end({
3917
3767
  id: this._instanceId
3918
3768
  }), {
3919
- F: __dxlog_file13,
3769
+ F: __dxlog_file12,
3920
3770
  L: 120,
3921
3771
  S: this,
3922
3772
  C: (f, a) => f(...a)
@@ -3924,7 +3774,7 @@ var DataSpaceManager = class {
3924
3774
  }
3925
3775
  async close() {
3926
3776
  log10("close", void 0, {
3927
- F: __dxlog_file13,
3777
+ F: __dxlog_file12,
3928
3778
  L: 125,
3929
3779
  S: this,
3930
3780
  C: (f, a) => f(...a)
@@ -3939,8 +3789,8 @@ var DataSpaceManager = class {
3939
3789
  * Creates a new space writing the genesis credentials to the control feed.
3940
3790
  */
3941
3791
  async createSpace() {
3942
- invariant12(this._isOpen, "Not open.", {
3943
- F: __dxlog_file13,
3792
+ invariant11(this._isOpen, "Not open.", {
3793
+ F: __dxlog_file12,
3944
3794
  L: 138,
3945
3795
  S: this,
3946
3796
  A: [
@@ -3961,7 +3811,7 @@ var DataSpaceManager = class {
3961
3811
  log10("creating space...", {
3962
3812
  spaceKey
3963
3813
  }, {
3964
- F: __dxlog_file13,
3814
+ F: __dxlog_file12,
3965
3815
  L: 150,
3966
3816
  S: this,
3967
3817
  C: (f, a) => f(...a)
@@ -3976,8 +3826,8 @@ var DataSpaceManager = class {
3976
3826
  const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRoot.url);
3977
3827
  await this._metadataStore.addSpace(metadata);
3978
3828
  const memberCredential = credentials[1];
3979
- invariant12(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3980
- F: __dxlog_file13,
3829
+ invariant11(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3830
+ F: __dxlog_file12,
3981
3831
  L: 163,
3982
3832
  S: this,
3983
3833
  A: [
@@ -3995,13 +3845,13 @@ var DataSpaceManager = class {
3995
3845
  log10("accept space", {
3996
3846
  opts
3997
3847
  }, {
3998
- F: __dxlog_file13,
3848
+ F: __dxlog_file12,
3999
3849
  L: 175,
4000
3850
  S: this,
4001
3851
  C: (f, a) => f(...a)
4002
3852
  });
4003
- invariant12(this._isOpen, "Not open.", {
4004
- F: __dxlog_file13,
3853
+ invariant11(this._isOpen, "Not open.", {
3854
+ F: __dxlog_file12,
4005
3855
  L: 176,
4006
3856
  S: this,
4007
3857
  A: [
@@ -4009,8 +3859,8 @@ var DataSpaceManager = class {
4009
3859
  "'Not open.'"
4010
3860
  ]
4011
3861
  });
4012
- invariant12(!this._spaces.has(opts.spaceKey), "Space already exists.", {
4013
- F: __dxlog_file13,
3862
+ invariant11(!this._spaces.has(opts.spaceKey), "Space already exists.", {
3863
+ F: __dxlog_file12,
4014
3864
  L: 177,
4015
3865
  S: this,
4016
3866
  A: [
@@ -4045,7 +3895,7 @@ var DataSpaceManager = class {
4045
3895
  log10("construct space", {
4046
3896
  metadata
4047
3897
  }, {
4048
- F: __dxlog_file13,
3898
+ F: __dxlog_file12,
4049
3899
  L: 210,
4050
3900
  S: this,
4051
3901
  C: (f, a) => f(...a)
@@ -4083,7 +3933,7 @@ var DataSpaceManager = class {
4083
3933
  },
4084
3934
  onAuthFailure: () => {
4085
3935
  log10.warn("auth failure", void 0, {
4086
- F: __dxlog_file13,
3936
+ F: __dxlog_file12,
4087
3937
  L: 247,
4088
3938
  S: this,
4089
3939
  C: (f, a) => f(...a)
@@ -4107,7 +3957,7 @@ var DataSpaceManager = class {
4107
3957
  log10("before space ready", {
4108
3958
  space: space.key
4109
3959
  }, {
4110
- F: __dxlog_file13,
3960
+ F: __dxlog_file12,
4111
3961
  L: 265,
4112
3962
  S: this,
4113
3963
  C: (f, a) => f(...a)
@@ -4118,7 +3968,7 @@ var DataSpaceManager = class {
4118
3968
  space: space.key,
4119
3969
  open: this._isOpen
4120
3970
  }, {
4121
- F: __dxlog_file13,
3971
+ F: __dxlog_file12,
4122
3972
  L: 268,
4123
3973
  S: this,
4124
3974
  C: (f, a) => f(...a)
@@ -4131,7 +3981,7 @@ var DataSpaceManager = class {
4131
3981
  log10("before space close", {
4132
3982
  space: space.key
4133
3983
  }, {
4134
- F: __dxlog_file13,
3984
+ F: __dxlog_file12,
4135
3985
  L: 274,
4136
3986
  S: this,
4137
3987
  C: (f, a) => f(...a)
@@ -4171,11 +4021,11 @@ DataSpaceManager = _ts_decorate5([
4171
4021
  import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTask as scheduleTask6 } from "@dxos/async";
4172
4022
  import { Stream as Stream10 } from "@dxos/codec-protobuf";
4173
4023
  import { raise as raise2 } from "@dxos/debug";
4174
- import { invariant as invariant13 } from "@dxos/invariant";
4024
+ import { invariant as invariant12 } from "@dxos/invariant";
4175
4025
  import { log as log11 } from "@dxos/log";
4176
4026
  import { ApiError, SpaceNotFoundError, encodeError } from "@dxos/protocols";
4177
- import { SpaceMember as SpaceMember3, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
4178
- var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
4027
+ import { SpaceMember as SpaceMember2, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
4028
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
4179
4029
  var SpacesServiceImpl = class {
4180
4030
  constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
4181
4031
  this._identityManager = _identityManager;
@@ -4214,7 +4064,7 @@ var SpacesServiceImpl = class {
4214
4064
  log11("update", {
4215
4065
  spaces
4216
4066
  }, {
4217
- F: __dxlog_file14,
4067
+ F: __dxlog_file13,
4218
4068
  L: 77,
4219
4069
  S: this,
4220
4070
  C: (f, a) => f(...a)
@@ -4296,8 +4146,8 @@ var SpacesServiceImpl = class {
4296
4146
  }
4297
4147
  });
4298
4148
  } else {
4299
- invariant13(!credential.id, "Id on unsigned credentials is not allowed", {
4300
- F: __dxlog_file14,
4149
+ invariant12(!credential.id, "Id on unsigned credentials is not allowed", {
4150
+ F: __dxlog_file13,
4301
4151
  L: 164,
4302
4152
  S: this,
4303
4153
  A: [
@@ -4305,8 +4155,8 @@ var SpacesServiceImpl = class {
4305
4155
  "'Id on unsigned credentials is not allowed'"
4306
4156
  ]
4307
4157
  });
4308
- invariant13(this._identityManager.identity, "Identity is not available", {
4309
- F: __dxlog_file14,
4158
+ invariant12(this._identityManager.identity, "Identity is not available", {
4159
+ F: __dxlog_file13,
4310
4160
  L: 165,
4311
4161
  S: this,
4312
4162
  A: [
@@ -4315,8 +4165,8 @@ var SpacesServiceImpl = class {
4315
4165
  ]
4316
4166
  });
4317
4167
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
4318
- invariant13(credential.issuer.equals(signer.getIssuer()), void 0, {
4319
- F: __dxlog_file14,
4168
+ invariant12(credential.issuer.equals(signer.getIssuer()), void 0, {
4169
+ F: __dxlog_file13,
4320
4170
  L: 167,
4321
4171
  S: this,
4322
4172
  A: [
@@ -4372,7 +4222,7 @@ var SpacesServiceImpl = class {
4372
4222
  identityKey: member.key,
4373
4223
  profile: member.profile ?? {}
4374
4224
  },
4375
- presence: member.removed ? SpaceMember3.PresenceState.REMOVED : isMe || peers.length > 0 ? SpaceMember3.PresenceState.ONLINE : SpaceMember3.PresenceState.OFFLINE,
4225
+ presence: member.removed ? SpaceMember2.PresenceState.REMOVED : isMe || peers.length > 0 ? SpaceMember2.PresenceState.ONLINE : SpaceMember2.PresenceState.OFFLINE,
4376
4226
  peerStates: peers
4377
4227
  };
4378
4228
  }),
@@ -4386,17 +4236,17 @@ var getChannelId = (channel) => `user-channel/${channel}`;
4386
4236
 
4387
4237
  // packages/sdk/client-services/src/packlets/services/service-context.ts
4388
4238
  import { Trigger as Trigger5 } from "@dxos/async";
4389
- import { Context as Context10 } from "@dxos/context";
4239
+ import { Context as Context10, Resource } from "@dxos/context";
4390
4240
  import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
4391
4241
  import { failUndefined as failUndefined2 } from "@dxos/debug";
4392
4242
  import { AutomergeHost, MetadataStore, SnapshotStore, SpaceManager, valueEncoding } from "@dxos/echo-pipeline";
4393
4243
  import { FeedFactory, FeedStore } from "@dxos/feed-store";
4394
4244
  import { IndexMetadataStore, IndexStore, Indexer } from "@dxos/indexing";
4395
- import { invariant as invariant14 } from "@dxos/invariant";
4245
+ import { invariant as invariant13 } from "@dxos/invariant";
4396
4246
  import { Keyring } from "@dxos/keyring";
4397
4247
  import { PublicKey as PublicKey10 } from "@dxos/keys";
4398
4248
  import { log as log12 } from "@dxos/log";
4399
- import { InvalidStorageVersionError, STORAGE_VERSION as STORAGE_VERSION2, trace as trace8 } from "@dxos/protocols";
4249
+ import { InvalidStorageVersionError, STORAGE_VERSION, trace as trace8 } from "@dxos/protocols";
4400
4250
  import { Invitation as Invitation6 } from "@dxos/protocols/proto/dxos/client/services";
4401
4251
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
4402
4252
  import { trace as Trace2 } from "@dxos/tracing";
@@ -4492,10 +4342,12 @@ function _ts_decorate6(decorators, target, key, desc) {
4492
4342
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4493
4343
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4494
4344
  }
4495
- var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
4496
- var ServiceContext = class {
4497
- constructor(storage, networkManager, signalManager, _runtimeParams) {
4345
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
4346
+ var ServiceContext = class extends Resource {
4347
+ constructor(storage, level, networkManager, signalManager, _runtimeParams) {
4348
+ super();
4498
4349
  this.storage = storage;
4350
+ this.level = level;
4499
4351
  this.networkManager = networkManager;
4500
4352
  this.signalManager = signalManager;
4501
4353
  this._runtimeParams = _runtimeParams;
@@ -4525,7 +4377,7 @@ var ServiceContext = class {
4525
4377
  });
4526
4378
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager, this._runtimeParams);
4527
4379
  this.indexMetadata = new IndexMetadataStore({
4528
- directory: storage.createDirectory("index-metadata")
4380
+ db: level.sublevel("index-metadata")
4529
4381
  });
4530
4382
  this.automergeHost = new AutomergeHost({
4531
4383
  directory: storage.createDirectory("automerge"),
@@ -4542,19 +4394,19 @@ var ServiceContext = class {
4542
4394
  this.invitations = new InvitationsHandler(this.networkManager);
4543
4395
  this._handlerFactories.set(Invitation6.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined2(), this._acceptIdentity.bind(this)));
4544
4396
  }
4545
- async open(ctx) {
4397
+ async _open(ctx) {
4546
4398
  await this._checkStorageVersion();
4547
4399
  log12("opening...", void 0, {
4548
- F: __dxlog_file15,
4549
- L: 151,
4400
+ F: __dxlog_file14,
4401
+ L: 156,
4550
4402
  S: this,
4551
4403
  C: (f, a) => f(...a)
4552
4404
  });
4553
4405
  log12.trace("dxos.sdk.service-context.open", trace8.begin({
4554
4406
  id: this._instanceId
4555
4407
  }), {
4556
- F: __dxlog_file15,
4557
- L: 152,
4408
+ F: __dxlog_file14,
4409
+ L: 157,
4558
4410
  S: this,
4559
4411
  C: (f, a) => f(...a)
4560
4412
  });
@@ -4569,22 +4421,22 @@ var ServiceContext = class {
4569
4421
  log12.trace("dxos.sdk.service-context.open", trace8.end({
4570
4422
  id: this._instanceId
4571
4423
  }), {
4572
- F: __dxlog_file15,
4573
- L: 162,
4424
+ F: __dxlog_file14,
4425
+ L: 167,
4574
4426
  S: this,
4575
4427
  C: (f, a) => f(...a)
4576
4428
  });
4577
4429
  log12("opened", void 0, {
4578
- F: __dxlog_file15,
4579
- L: 163,
4430
+ F: __dxlog_file14,
4431
+ L: 168,
4580
4432
  S: this,
4581
4433
  C: (f, a) => f(...a)
4582
4434
  });
4583
4435
  }
4584
- async close() {
4436
+ async _close() {
4585
4437
  log12("closing...", void 0, {
4586
- F: __dxlog_file15,
4587
- L: 167,
4438
+ F: __dxlog_file14,
4439
+ L: 172,
4588
4440
  S: this,
4589
4441
  C: (f, a) => f(...a)
4590
4442
  });
@@ -4601,8 +4453,8 @@ var ServiceContext = class {
4601
4453
  await this.metadataStore.close();
4602
4454
  await this.indexer.destroy();
4603
4455
  log12("closed", void 0, {
4604
- F: __dxlog_file15,
4605
- L: 180,
4456
+ F: __dxlog_file14,
4457
+ L: 185,
4606
4458
  S: this,
4607
4459
  C: (f, a) => f(...a)
4608
4460
  });
@@ -4614,9 +4466,9 @@ var ServiceContext = class {
4614
4466
  }
4615
4467
  getInvitationHandler(invitation) {
4616
4468
  const factory = this._handlerFactories.get(invitation.kind);
4617
- invariant14(factory, `Unknown invitation kind: ${invitation.kind}`, {
4618
- F: __dxlog_file15,
4619
- L: 191,
4469
+ invariant13(factory, `Unknown invitation kind: ${invitation.kind}`, {
4470
+ F: __dxlog_file14,
4471
+ L: 196,
4620
4472
  S: this,
4621
4473
  A: [
4622
4474
  "factory",
@@ -4640,15 +4492,15 @@ var ServiceContext = class {
4640
4492
  }
4641
4493
  async _checkStorageVersion() {
4642
4494
  await this.metadataStore.load();
4643
- if (this.metadataStore.version !== STORAGE_VERSION2) {
4644
- throw new InvalidStorageVersionError(STORAGE_VERSION2, this.metadataStore.version);
4495
+ if (this.metadataStore.version !== STORAGE_VERSION) {
4496
+ throw new InvalidStorageVersionError(STORAGE_VERSION, this.metadataStore.version);
4645
4497
  }
4646
4498
  }
4647
4499
  // Called when identity is created.
4648
4500
  async _initialize(ctx) {
4649
4501
  log12("initializing spaces...", void 0, {
4650
- F: __dxlog_file15,
4651
- L: 222,
4502
+ F: __dxlog_file14,
4503
+ L: 227,
4652
4504
  S: this,
4653
4505
  C: (f, a) => f(...a)
4654
4506
  });
@@ -4669,9 +4521,9 @@ var ServiceContext = class {
4669
4521
  this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.automergeHost, this._runtimeParams);
4670
4522
  await this.dataSpaceManager.open();
4671
4523
  this._handlerFactories.set(Invitation6.Kind.SPACE, (invitation) => {
4672
- invariant14(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4673
- F: __dxlog_file15,
4674
- L: 246,
4524
+ invariant13(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4525
+ F: __dxlog_file14,
4526
+ L: 251,
4675
4527
  S: this,
4676
4528
  A: [
4677
4529
  "this.dataSpaceManager",
@@ -4694,8 +4546,8 @@ var ServiceContext = class {
4694
4546
  log12("dataSpaceManager not initialized yet, ignoring space admission", {
4695
4547
  details: assertion
4696
4548
  }, {
4697
- F: __dxlog_file15,
4698
- L: 262,
4549
+ F: __dxlog_file14,
4550
+ L: 267,
4699
4551
  S: this,
4700
4552
  C: (f, a) => f(...a)
4701
4553
  });
@@ -4705,8 +4557,8 @@ var ServiceContext = class {
4705
4557
  log12("space already exists, ignoring space admission", {
4706
4558
  details: assertion
4707
4559
  }, {
4708
- F: __dxlog_file15,
4709
- L: 266,
4560
+ F: __dxlog_file14,
4561
+ L: 271,
4710
4562
  S: this,
4711
4563
  C: (f, a) => f(...a)
4712
4564
  });
@@ -4716,8 +4568,8 @@ var ServiceContext = class {
4716
4568
  log12("accepting space recorded in halo", {
4717
4569
  details: assertion
4718
4570
  }, {
4719
- F: __dxlog_file15,
4720
- L: 271,
4571
+ F: __dxlog_file14,
4572
+ L: 276,
4721
4573
  S: this,
4722
4574
  C: (f, a) => f(...a)
4723
4575
  });
@@ -4727,8 +4579,8 @@ var ServiceContext = class {
4727
4579
  });
4728
4580
  } catch (err) {
4729
4581
  log12.catch(err, void 0, {
4730
- F: __dxlog_file15,
4731
- L: 277,
4582
+ F: __dxlog_file14,
4583
+ L: 282,
4732
4584
  S: this,
4733
4585
  C: (f, a) => f(...a)
4734
4586
  });
@@ -4740,7 +4592,7 @@ var ServiceContext = class {
4740
4592
  };
4741
4593
  _ts_decorate6([
4742
4594
  Trace2.span()
4743
- ], ServiceContext.prototype, "open", null);
4595
+ ], ServiceContext.prototype, "_open", null);
4744
4596
  _ts_decorate6([
4745
4597
  Trace2.span()
4746
4598
  ], ServiceContext.prototype, "_initialize", null);
@@ -4773,190 +4625,265 @@ var ServiceRegistry = class {
4773
4625
  }
4774
4626
  };
4775
4627
 
4776
- // packages/sdk/client-services/src/packlets/locks/browser.ts
4777
- import { asyncTimeout as asyncTimeout2, Trigger as Trigger6 } from "@dxos/async";
4778
- import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
4779
- import { log as log13, logInfo } from "@dxos/log";
4780
- function _ts_decorate7(decorators, target, key, desc) {
4781
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4782
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
4783
- r = Reflect.decorate(decorators, target, key, desc);
4784
- else
4785
- for (var i = decorators.length - 1; i >= 0; i--)
4786
- if (d = decorators[i])
4787
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4788
- return c > 3 && r && Object.defineProperty(target, key, r), r;
4789
- }
4790
- var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
4791
- var Message;
4792
- (function(Message2) {
4793
- Message2["ACQUIRING"] = "acquiring";
4794
- })(Message || (Message = {}));
4795
- var Lock = class {
4796
- constructor({ lockKey, onAcquire, onRelease }) {
4797
- this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
4798
- this._releaseTrigger = new Trigger6();
4799
- this._lockKey = lockKey;
4800
- this._onAcquire = onAcquire;
4801
- this._onRelease = onRelease;
4802
- this._broadcastChannel.onmessage = this._onMessage.bind(this);
4803
- }
4804
- get lockKey() {
4805
- return this._lockKey;
4806
- }
4807
- async acquire() {
4808
- this._broadcastChannel.postMessage({
4809
- message: "acquiring"
4810
- });
4811
- try {
4812
- log13("aquiring lock...", void 0, {
4813
- F: __dxlog_file16,
4814
- L: 42,
4815
- S: this,
4816
- C: (f, a) => f(...a)
4817
- });
4818
- await asyncTimeout2(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
4819
- log13("acquired lock", void 0, {
4820
- F: __dxlog_file16,
4821
- L: 44,
4822
- S: this,
4823
- C: (f, a) => f(...a)
4824
- });
4825
- } catch {
4826
- log13("stealing lock...", void 0, {
4827
- F: __dxlog_file16,
4828
- L: 46,
4829
- S: this,
4830
- C: (f, a) => f(...a)
4831
- });
4832
- await this._requestLock(true);
4833
- log13("stolen lock", void 0, {
4834
- F: __dxlog_file16,
4835
- L: 48,
4836
- S: this,
4837
- C: (f, a) => f(...a)
4838
- });
4628
+ // packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts
4629
+ import { getFirstStreamValue } from "@dxos/codec-protobuf";
4630
+ import { credentialTypeFilter } from "@dxos/credentials";
4631
+ import { invariant as invariant14 } from "@dxos/invariant";
4632
+ import { STORAGE_VERSION as STORAGE_VERSION2 } from "@dxos/protocols";
4633
+ import { SpaceMember as SpaceMember3 } from "@dxos/protocols/proto/dxos/client/services";
4634
+ import { TRACE_PROCESSOR } from "@dxos/tracing";
4635
+
4636
+ // packages/sdk/client-services/src/version.ts
4637
+ var DXOS_VERSION = "0.4.10-main.d4766e5";
4638
+
4639
+ // packages/sdk/client-services/src/packlets/services/platform.ts
4640
+ import { Platform } from "@dxos/protocols/proto/dxos/client/services";
4641
+ var getPlatform = () => {
4642
+ if (process.browser) {
4643
+ if (typeof window !== "undefined") {
4644
+ const { userAgent } = window.navigator;
4645
+ return {
4646
+ type: Platform.PLATFORM_TYPE.BROWSER,
4647
+ userAgent,
4648
+ uptime: Math.floor((Date.now() - window.performance.timeOrigin) / 1e3)
4649
+ };
4650
+ } else {
4651
+ return {
4652
+ type: Platform.PLATFORM_TYPE.SHARED_WORKER,
4653
+ uptime: Math.floor((Date.now() - performance.timeOrigin) / 1e3)
4654
+ };
4839
4655
  }
4656
+ } else {
4657
+ const { platform: platform2, version, arch } = process;
4658
+ return {
4659
+ type: Platform.PLATFORM_TYPE.NODE,
4660
+ platform: platform2,
4661
+ arch,
4662
+ runtime: version,
4663
+ uptime: Math.floor(process.uptime()),
4664
+ memory: process.memoryUsage()
4665
+ };
4840
4666
  }
4841
- async release() {
4842
- this._releaseTrigger.wake();
4667
+ };
4668
+
4669
+ // packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts
4670
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts";
4671
+ var DEFAULT_TIMEOUT = 1e3;
4672
+ var createDiagnostics = async (clientServices, serviceContext, config) => {
4673
+ const diagnostics = {
4674
+ created: (/* @__PURE__ */ new Date()).toISOString(),
4675
+ platform: getPlatform(),
4676
+ client: {
4677
+ version: DXOS_VERSION,
4678
+ storage: {
4679
+ version: STORAGE_VERSION2
4680
+ }
4681
+ },
4682
+ trace: TRACE_PROCESSOR.getDiagnostics()
4683
+ };
4684
+ {
4685
+ invariant14(clientServices.LoggingService, "SystemService is not available.", {
4686
+ F: __dxlog_file15,
4687
+ L: 108,
4688
+ S: void 0,
4689
+ A: [
4690
+ "clientServices.LoggingService",
4691
+ "'SystemService is not available.'"
4692
+ ]
4693
+ });
4694
+ diagnostics.metrics = await getFirstStreamValue(clientServices.LoggingService.queryMetrics({}), {
4695
+ timeout: DEFAULT_TIMEOUT
4696
+ }).catch(() => void 0);
4843
4697
  }
4844
- _onMessage(event) {
4845
- if (event.data.message === "acquiring") {
4846
- this._releaseTrigger.wake();
4698
+ if (typeof navigator !== "undefined" && navigator.storage) {
4699
+ const map = /* @__PURE__ */ new Map();
4700
+ const dir = await navigator.storage.getDirectory();
4701
+ for await (const filename of dir?.keys()) {
4702
+ const idx = filename.indexOf("-", filename.indexOf("-") + 1);
4703
+ if (idx === -1) {
4704
+ continue;
4705
+ }
4706
+ map.set(filename.slice(0, idx), (map.get(filename.slice(0, idx)) ?? 0) + 1);
4847
4707
  }
4708
+ diagnostics.storage = Array.from(map.entries()).sort((a, b) => b[1] - a[1]).map(([file, count]) => ({
4709
+ file,
4710
+ count
4711
+ }));
4848
4712
  }
4849
- async _requestLock(steal = false) {
4850
- log13("requesting lock...", {
4851
- steal
4852
- }, {
4853
- F: __dxlog_file16,
4854
- L: 63,
4855
- S: this,
4856
- C: (f, a) => f(...a)
4857
- });
4858
- const acquired = new Trigger6();
4859
- void navigator.locks.request(this._lockKey, {
4860
- steal
4861
- }, async () => {
4862
- await this._onAcquire?.();
4863
- acquired.wake();
4864
- this._releaseTrigger = new Trigger6();
4865
- await this._releaseTrigger.wait();
4866
- log13("releasing lock...", void 0, {
4867
- F: __dxlog_file16,
4868
- L: 72,
4869
- S: this,
4870
- C: (f, a) => f(...a)
4871
- });
4872
- await this._onRelease?.();
4873
- log13("released lock", void 0, {
4874
- F: __dxlog_file16,
4875
- L: 74,
4876
- S: this,
4877
- C: (f, a) => f(...a)
4878
- });
4879
- }).catch(async () => {
4880
- await this._onRelease?.();
4881
- });
4882
- await acquired.wait();
4883
- log13("recieved lock", {
4884
- steal
4885
- }, {
4886
- F: __dxlog_file16,
4887
- L: 81,
4888
- S: this,
4889
- C: (f, a) => f(...a)
4890
- });
4713
+ const identity = serviceContext.identityManager.identity;
4714
+ if (identity) {
4715
+ diagnostics.identity = {
4716
+ identityKey: identity.identityKey,
4717
+ spaceKey: identity.space.key,
4718
+ profile: identity.profileDocument
4719
+ };
4720
+ const { devices } = await getFirstStreamValue(clientServices.DevicesService.queryDevices(), {
4721
+ timeout: DEFAULT_TIMEOUT
4722
+ }).catch(() => void 0) ?? {};
4723
+ diagnostics.devices = devices;
4724
+ if (serviceContext.dataSpaceManager) {
4725
+ diagnostics.spaces = await Promise.all(Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space)) ?? []);
4726
+ }
4727
+ const { feeds = [] } = await getFirstStreamValue(clientServices.DevtoolsHost.subscribeToFeeds({}), {
4728
+ timeout: DEFAULT_TIMEOUT
4729
+ }).catch(() => void 0) ?? {};
4730
+ diagnostics.feeds = feeds.map(({ feedKey, bytes, length }) => ({
4731
+ feedKey,
4732
+ bytes,
4733
+ length
4734
+ }));
4735
+ const status = await getFirstStreamValue(clientServices.NetworkService.queryStatus(), {
4736
+ timeout: DEFAULT_TIMEOUT
4737
+ }).catch(() => void 0);
4738
+ diagnostics.networkStatus = status;
4739
+ diagnostics.swarms = serviceContext.networkManager.connectionLog?.swarms;
4891
4740
  }
4741
+ diagnostics.config = config.values;
4742
+ return diagnostics;
4892
4743
  };
4893
- _ts_decorate7([
4894
- logInfo
4895
- ], Lock.prototype, "lockKey", null);
4896
- var isLocked = (lockPath) => {
4897
- throw new Error("Not implemented");
4744
+ var getSpaceStats = async (space) => {
4745
+ const stats = {
4746
+ key: space.key,
4747
+ metrics: space.metrics,
4748
+ epochs: space.inner.spaceState.credentials.filter(credentialTypeFilter("dxos.halo.credentials.Epoch")).map((credential) => ({
4749
+ ...credential.subject.assertion,
4750
+ id: credential.id
4751
+ })),
4752
+ members: Array.from(space.inner.spaceState.members.values()).map((member) => ({
4753
+ identity: {
4754
+ identityKey: member.key,
4755
+ profile: {
4756
+ displayName: member.assertion.profile?.displayName
4757
+ }
4758
+ },
4759
+ presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember3.PresenceState.ONLINE : SpaceMember3.PresenceState.OFFLINE
4760
+ })),
4761
+ pipeline: {
4762
+ // TODO(burdon): Pick properties from credentials if needed.
4763
+ currentEpoch: space.automergeSpaceState.lastEpoch,
4764
+ appliedEpoch: space.automergeSpaceState.lastEpoch,
4765
+ controlFeeds: space.inner.controlPipeline.state.feeds.map((feed) => feed.key),
4766
+ currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
4767
+ targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
4768
+ totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe
4769
+ }
4770
+ };
4771
+ if (stats.metrics) {
4772
+ const { open, ready } = stats.metrics;
4773
+ stats.metrics.startupTime = open && ready && ready.getTime() - open.getTime();
4774
+ }
4775
+ return stats;
4898
4776
  };
4899
4777
 
4900
- // packages/sdk/client-services/src/packlets/storage/storage.ts
4901
- import { DX_DATA } from "@dxos/client-protocol";
4902
- import { InvalidConfigError } from "@dxos/protocols";
4903
- import { Runtime } from "@dxos/protocols/proto/dxos/config";
4904
- import { createStorage, StorageType } from "@dxos/random-access-storage";
4905
- import { isNode as isNode2 } from "@dxos/util";
4906
- var StorageDriver = Runtime.Client.Storage.StorageDriver;
4907
- var createStorageObjects = (config) => {
4908
- const { persistent = false, keyStore, dataStore, dataRoot = isNode2() ? DX_DATA : "dxos/storage" } = config ?? {};
4909
- if (persistent && dataStore === StorageDriver.RAM) {
4910
- throw new InvalidConfigError("RAM storage cannot be used in persistent mode.");
4911
- }
4912
- if (!persistent && dataStore !== void 0 && dataStore !== StorageDriver.RAM) {
4913
- throw new InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
4914
- }
4915
- if (persistent && keyStore === StorageDriver.RAM) {
4916
- throw new InvalidConfigError("RAM key storage cannot be used in persistent mode.");
4917
- }
4918
- if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== void 0) {
4919
- throw new InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
4920
- }
4778
+ // packages/sdk/client-services/src/packlets/diagnostics/browser-diagnostics-broadcast.ts
4779
+ import { Trigger as Trigger6 } from "@dxos/async";
4780
+ import { log as log13 } from "@dxos/log";
4781
+ var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/browser-diagnostics-broadcast.ts";
4782
+ var CHANNEL_NAME = "dxos.diagnostics.broadcast";
4783
+ var MessageType;
4784
+ (function(MessageType2) {
4785
+ MessageType2["PROBE"] = "probe";
4786
+ MessageType2["PROBE_ACK"] = "probe-ack";
4787
+ MessageType2["REQUEST_DIAGNOSTICS"] = "request-diagnostics";
4788
+ MessageType2["RECEIVE_DIAGNOSTICS"] = "receive-diagnostics";
4789
+ })(MessageType || (MessageType = {}));
4790
+ var createCollectDiagnosticsBroadcastSender = () => {
4921
4791
  return {
4922
- storage: createStorage({
4923
- type: persistent ? toStorageType(dataStore) : StorageType.RAM,
4924
- root: `${dataRoot}/`
4925
- })
4792
+ broadcastDiagnosticsRequest: async () => {
4793
+ let expectedResponse = "probe-ack";
4794
+ let channel;
4795
+ try {
4796
+ const trigger = new Trigger6();
4797
+ channel = new BroadcastChannel(CHANNEL_NAME);
4798
+ channel.onmessage = (msg) => {
4799
+ if (expectedResponse === msg.data.type) {
4800
+ trigger.wake(msg.data);
4801
+ }
4802
+ };
4803
+ channel.postMessage({
4804
+ type: "probe"
4805
+ });
4806
+ await trigger.wait({
4807
+ timeout: 200
4808
+ });
4809
+ expectedResponse = "receive-diagnostics";
4810
+ trigger.reset();
4811
+ channel.postMessage({
4812
+ type: "request-diagnostics"
4813
+ });
4814
+ const diagnostics = await trigger.wait({
4815
+ timeout: 5e3
4816
+ });
4817
+ return diagnostics.payload;
4818
+ } catch (e) {
4819
+ const errorDescription = e instanceof Error ? e.message : JSON.stringify(e);
4820
+ return {
4821
+ expectedResponse,
4822
+ errorDescription
4823
+ };
4824
+ } finally {
4825
+ safeClose(channel);
4826
+ }
4827
+ }
4926
4828
  };
4927
4829
  };
4928
- var toStorageType = (type) => {
4929
- switch (type) {
4930
- case void 0:
4931
- return void 0;
4932
- case StorageDriver.RAM:
4933
- return StorageType.RAM;
4934
- case StorageDriver.CHROME:
4935
- return StorageType.CHROME;
4936
- case StorageDriver.FIREFOX:
4937
- return StorageType.FIREFOX;
4938
- case StorageDriver.IDB:
4939
- return StorageType.IDB;
4940
- case StorageDriver.NODE:
4941
- return StorageType.NODE;
4942
- case StorageDriver.WEBFS:
4943
- return StorageType.WEBFS;
4944
- default:
4945
- throw new Error(`Invalid storage type: ${StorageDriver[type]}`);
4830
+ var createCollectDiagnosticsBroadcastHandler = (systemService) => {
4831
+ let channel;
4832
+ return {
4833
+ start: () => {
4834
+ channel = new BroadcastChannel(CHANNEL_NAME);
4835
+ channel.onmessage = async (message) => {
4836
+ try {
4837
+ if (message.data.type === "probe") {
4838
+ channel?.postMessage({
4839
+ type: "probe-ack"
4840
+ });
4841
+ } else if (message.data.type === "request-diagnostics") {
4842
+ const diagnostics = await systemService.getDiagnostics({});
4843
+ channel?.postMessage({
4844
+ type: "receive-diagnostics",
4845
+ payload: diagnostics
4846
+ });
4847
+ }
4848
+ } catch (error) {
4849
+ log13.catch(error, void 0, {
4850
+ F: __dxlog_file16,
4851
+ L: 77,
4852
+ S: void 0,
4853
+ C: (f, a) => f(...a)
4854
+ });
4855
+ }
4856
+ };
4857
+ },
4858
+ stop: () => {
4859
+ safeClose(channel);
4860
+ channel = void 0;
4861
+ }
4862
+ };
4863
+ };
4864
+ var safeClose = (channel) => {
4865
+ try {
4866
+ channel?.close();
4867
+ } catch (e) {
4946
4868
  }
4947
4869
  };
4948
4870
 
4871
+ // packages/sdk/client-services/src/packlets/diagnostics/diagnostics-collector.ts
4872
+ import { ConfigResource } from "@dxos/config";
4873
+ import { GetDiagnosticsRequest as GetDiagnosticsRequest2 } from "@dxos/protocols/proto/dxos/client/services";
4874
+ import { TRACE_PROCESSOR as TRACE_PROCESSOR3 } from "@dxos/tracing";
4875
+ import { jsonKeyReplacer as jsonKeyReplacer2, nonNullable } from "@dxos/util";
4876
+
4949
4877
  // packages/sdk/client-services/src/packlets/services/service-host.ts
4950
- import { Event as Event9, sleep as sleep3, synchronized as synchronized3 } from "@dxos/async";
4951
- import { clientServiceBundle, defaultKey, PropertiesSchema } from "@dxos/client-protocol";
4878
+ import { Event as Event9, synchronized as synchronized3 } from "@dxos/async";
4879
+ import { clientServiceBundle, defaultKey, Properties } from "@dxos/client-protocol";
4952
4880
  import { Context as Context11 } from "@dxos/context";
4953
- import { DataServiceImpl } from "@dxos/echo-pipeline";
4881
+ import { DataServiceImpl, encodeReference } from "@dxos/echo-pipeline";
4954
4882
  import * as E from "@dxos/echo-schema";
4955
- import { createRawObjectDoc } from "@dxos/echo-schema";
4956
4883
  import { IndexServiceImpl } from "@dxos/indexing";
4957
4884
  import { invariant as invariant16 } from "@dxos/invariant";
4958
- import { PublicKey as PublicKey12 } from "@dxos/keys";
4959
- import { log as log15 } from "@dxos/log";
4885
+ import { PublicKey as PublicKey13 } from "@dxos/keys";
4886
+ import { log as log16 } from "@dxos/log";
4960
4887
  import { WebsocketSignalManager } from "@dxos/messaging";
4961
4888
  import { NetworkManager, createSimplePeerTransportFactory } from "@dxos/network-manager";
4962
4889
  import { trace as trace9 } from "@dxos/protocols";
@@ -5047,11 +4974,135 @@ var DevicesServiceImpl = class {
5047
4974
  }
5048
4975
  };
5049
4976
 
4977
+ // packages/sdk/client-services/src/packlets/locks/browser.ts
4978
+ import { asyncTimeout as asyncTimeout2, Trigger as Trigger7 } from "@dxos/async";
4979
+ import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
4980
+ import { log as log14, logInfo } from "@dxos/log";
4981
+ function _ts_decorate7(decorators, target, key, desc) {
4982
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4983
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
4984
+ r = Reflect.decorate(decorators, target, key, desc);
4985
+ else
4986
+ for (var i = decorators.length - 1; i >= 0; i--)
4987
+ if (d = decorators[i])
4988
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4989
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
4990
+ }
4991
+ var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
4992
+ var Message;
4993
+ (function(Message2) {
4994
+ Message2["ACQUIRING"] = "acquiring";
4995
+ })(Message || (Message = {}));
4996
+ var Lock = class {
4997
+ constructor({ lockKey, onAcquire, onRelease }) {
4998
+ this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
4999
+ this._releaseTrigger = new Trigger7();
5000
+ this._lockKey = lockKey;
5001
+ this._onAcquire = onAcquire;
5002
+ this._onRelease = onRelease;
5003
+ this._broadcastChannel.onmessage = this._onMessage.bind(this);
5004
+ }
5005
+ get lockKey() {
5006
+ return this._lockKey;
5007
+ }
5008
+ async acquire() {
5009
+ this._broadcastChannel.postMessage({
5010
+ message: "acquiring"
5011
+ });
5012
+ try {
5013
+ log14("aquiring lock...", void 0, {
5014
+ F: __dxlog_file18,
5015
+ L: 42,
5016
+ S: this,
5017
+ C: (f, a) => f(...a)
5018
+ });
5019
+ await asyncTimeout2(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
5020
+ log14("acquired lock", void 0, {
5021
+ F: __dxlog_file18,
5022
+ L: 44,
5023
+ S: this,
5024
+ C: (f, a) => f(...a)
5025
+ });
5026
+ } catch {
5027
+ log14("stealing lock...", void 0, {
5028
+ F: __dxlog_file18,
5029
+ L: 46,
5030
+ S: this,
5031
+ C: (f, a) => f(...a)
5032
+ });
5033
+ await this._requestLock(true);
5034
+ log14("stolen lock", void 0, {
5035
+ F: __dxlog_file18,
5036
+ L: 48,
5037
+ S: this,
5038
+ C: (f, a) => f(...a)
5039
+ });
5040
+ }
5041
+ }
5042
+ async release() {
5043
+ this._releaseTrigger.wake();
5044
+ }
5045
+ _onMessage(event) {
5046
+ if (event.data.message === "acquiring") {
5047
+ this._releaseTrigger.wake();
5048
+ }
5049
+ }
5050
+ async _requestLock(steal = false) {
5051
+ log14("requesting lock...", {
5052
+ steal
5053
+ }, {
5054
+ F: __dxlog_file18,
5055
+ L: 63,
5056
+ S: this,
5057
+ C: (f, a) => f(...a)
5058
+ });
5059
+ const acquired = new Trigger7();
5060
+ void navigator.locks.request(this._lockKey, {
5061
+ steal
5062
+ }, async () => {
5063
+ await this._onAcquire?.();
5064
+ acquired.wake();
5065
+ this._releaseTrigger = new Trigger7();
5066
+ await this._releaseTrigger.wait();
5067
+ log14("releasing lock...", void 0, {
5068
+ F: __dxlog_file18,
5069
+ L: 72,
5070
+ S: this,
5071
+ C: (f, a) => f(...a)
5072
+ });
5073
+ await this._onRelease?.();
5074
+ log14("released lock", void 0, {
5075
+ F: __dxlog_file18,
5076
+ L: 74,
5077
+ S: this,
5078
+ C: (f, a) => f(...a)
5079
+ });
5080
+ }).catch(async () => {
5081
+ await this._onRelease?.();
5082
+ });
5083
+ await acquired.wait();
5084
+ log14("recieved lock", {
5085
+ steal
5086
+ }, {
5087
+ F: __dxlog_file18,
5088
+ L: 81,
5089
+ S: this,
5090
+ C: (f, a) => f(...a)
5091
+ });
5092
+ }
5093
+ };
5094
+ _ts_decorate7([
5095
+ logInfo
5096
+ ], Lock.prototype, "lockKey", null);
5097
+ var isLocked = (lockPath) => {
5098
+ throw new Error("Not implemented");
5099
+ };
5100
+
5050
5101
  // packages/sdk/client-services/src/packlets/logging/logging-service.ts
5051
5102
  import { Event as Event8 } from "@dxos/async";
5052
5103
  import { Stream as Stream12 } from "@dxos/codec-protobuf";
5053
5104
  import { PublicKey as PublicKey11 } from "@dxos/keys";
5054
- import { getContextFromEntry, log as log14 } from "@dxos/log";
5105
+ import { getContextFromEntry, log as log15 } from "@dxos/log";
5055
5106
  import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
5056
5107
  import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
5057
5108
  var LoggingServiceImpl = class {
@@ -5064,11 +5115,11 @@ var LoggingServiceImpl = class {
5064
5115
  };
5065
5116
  }
5066
5117
  async open() {
5067
- log14.runtimeConfig.processors.push(this._logProcessor);
5118
+ log15.runtimeConfig.processors.push(this._logProcessor);
5068
5119
  }
5069
5120
  async close() {
5070
- const index = log14.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
5071
- log14.runtimeConfig.processors.splice(index, 1);
5121
+ const index = log15.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
5122
+ log15.runtimeConfig.processors.splice(index, 1);
5072
5123
  }
5073
5124
  async controlMetrics({ reset, record }) {
5074
5125
  if (reset) {
@@ -5153,12 +5204,12 @@ var LoggingServiceImpl = class {
5153
5204
  });
5154
5205
  }
5155
5206
  };
5156
- var matchFilter = (filter, level, path, options) => {
5207
+ var matchFilter = (filter, level, path2, options) => {
5157
5208
  switch (options) {
5158
5209
  case QueryLogsRequest.MatchingOptions.INCLUSIVE:
5159
- return level >= filter.level && (!filter.pattern || path.includes(filter.pattern));
5210
+ return level >= filter.level && (!filter.pattern || path2.includes(filter.pattern));
5160
5211
  case QueryLogsRequest.MatchingOptions.EXPLICIT:
5161
- return level === filter.level && (!filter.pattern || path.includes(filter.pattern));
5212
+ return level === filter.level && (!filter.pattern || path2.includes(filter.pattern));
5162
5213
  }
5163
5214
  };
5164
5215
  var shouldLog = (entry2, request) => {
@@ -5204,6 +5255,80 @@ var NetworkServiceImpl = class {
5204
5255
  }
5205
5256
  };
5206
5257
 
5258
+ // packages/sdk/client-services/src/packlets/storage/storage.ts
5259
+ import { InvalidConfigError } from "@dxos/protocols";
5260
+ import { Runtime as Runtime2 } from "@dxos/protocols/proto/dxos/config";
5261
+ import { createStorage, StorageType } from "@dxos/random-access-storage";
5262
+
5263
+ // packages/sdk/client-services/src/packlets/storage/util.ts
5264
+ import { DX_DATA } from "@dxos/client-protocol";
5265
+ import { Runtime } from "@dxos/protocols/proto/dxos/config";
5266
+ import { isNode as isNode2 } from "@dxos/util";
5267
+ var getRootPath = (config) => {
5268
+ const { dataRoot = isNode2() ? DX_DATA : "dxos/storage" } = config ?? {};
5269
+ return `${dataRoot}/`;
5270
+ };
5271
+ var isPersistent = (config) => {
5272
+ const { persistent = false } = config ?? {};
5273
+ return config.dataStore !== void 0 && config.dataStore !== Runtime.Client.Storage.StorageDriver.RAM || persistent;
5274
+ };
5275
+
5276
+ // packages/sdk/client-services/src/packlets/storage/storage.ts
5277
+ var StorageDriver = Runtime2.Client.Storage.StorageDriver;
5278
+ var createStorageObjects = (config) => {
5279
+ const { persistent = false, keyStore, dataStore } = config ?? {};
5280
+ if (persistent && dataStore === StorageDriver.RAM) {
5281
+ throw new InvalidConfigError("RAM storage cannot be used in persistent mode.");
5282
+ }
5283
+ if (!persistent && dataStore !== void 0 && dataStore !== StorageDriver.RAM) {
5284
+ throw new InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
5285
+ }
5286
+ if (persistent && keyStore === StorageDriver.RAM) {
5287
+ throw new InvalidConfigError("RAM key storage cannot be used in persistent mode.");
5288
+ }
5289
+ if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== void 0) {
5290
+ throw new InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
5291
+ }
5292
+ return {
5293
+ storage: createStorage({
5294
+ type: persistent ? toStorageType(dataStore) : StorageType.RAM,
5295
+ root: getRootPath(config)
5296
+ })
5297
+ };
5298
+ };
5299
+ var toStorageType = (type) => {
5300
+ switch (type) {
5301
+ case void 0:
5302
+ return void 0;
5303
+ case StorageDriver.RAM:
5304
+ return StorageType.RAM;
5305
+ case StorageDriver.CHROME:
5306
+ return StorageType.CHROME;
5307
+ case StorageDriver.FIREFOX:
5308
+ return StorageType.FIREFOX;
5309
+ case StorageDriver.IDB:
5310
+ return StorageType.IDB;
5311
+ case StorageDriver.NODE:
5312
+ return StorageType.NODE;
5313
+ case StorageDriver.WEBFS:
5314
+ return StorageType.WEBFS;
5315
+ default:
5316
+ throw new Error(`Invalid storage type: ${StorageDriver[type]}`);
5317
+ }
5318
+ };
5319
+
5320
+ // packages/sdk/client-services/src/packlets/storage/level.ts
5321
+ import { Level } from "level";
5322
+ import path from "@dxos/node-std/path";
5323
+ import { PublicKey as PublicKey12 } from "@dxos/keys";
5324
+ var createLevel = async (config) => {
5325
+ const persistent = isPersistent(config);
5326
+ const storagePath = persistent ? getRootPath(config) : path.join("tmp", "level", PublicKey12.random().toHex());
5327
+ const level = new Level(storagePath);
5328
+ await level.open();
5329
+ return level;
5330
+ };
5331
+
5207
5332
  // packages/sdk/client-services/src/packlets/system/system-service.ts
5208
5333
  import { Stream as Stream14 } from "@dxos/codec-protobuf";
5209
5334
  import { GetDiagnosticsRequest } from "@dxos/protocols/proto/dxos/client/services";
@@ -5272,7 +5397,7 @@ function _ts_decorate8(decorators, target, key, desc) {
5272
5397
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5273
5398
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5274
5399
  }
5275
- var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
5400
+ var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
5276
5401
  var ClientServicesHost = class {
5277
5402
  constructor({
5278
5403
  config,
@@ -5327,6 +5452,7 @@ var ClientServicesHost = class {
5327
5452
  await this.reset();
5328
5453
  }
5329
5454
  });
5455
+ this.diagnosticsBroadcastHandler = createCollectDiagnosticsBroadcastHandler(this._systemService);
5330
5456
  this._loggingService = new LoggingServiceImpl();
5331
5457
  this._serviceRegistry = new ServiceRegistry(clientServiceBundle, {
5332
5458
  SystemService: this._systemService,
@@ -5358,24 +5484,24 @@ var ClientServicesHost = class {
5358
5484
  */
5359
5485
  initialize({ config, ...options }) {
5360
5486
  invariant16(!this._open, "service host is open", {
5361
- F: __dxlog_file18,
5362
- L: 180,
5487
+ F: __dxlog_file19,
5488
+ L: 188,
5363
5489
  S: this,
5364
5490
  A: [
5365
5491
  "!this._open",
5366
5492
  "'service host is open'"
5367
5493
  ]
5368
5494
  });
5369
- log15("initializing...", void 0, {
5370
- F: __dxlog_file18,
5371
- L: 181,
5495
+ log16("initializing...", void 0, {
5496
+ F: __dxlog_file19,
5497
+ L: 189,
5372
5498
  S: this,
5373
5499
  C: (f, a) => f(...a)
5374
5500
  });
5375
5501
  if (config) {
5376
5502
  invariant16(!this._config, "config already set", {
5377
- F: __dxlog_file18,
5378
- L: 184,
5503
+ F: __dxlog_file19,
5504
+ L: 192,
5379
5505
  S: this,
5380
5506
  A: [
5381
5507
  "!this._config",
@@ -5388,9 +5514,9 @@ var ClientServicesHost = class {
5388
5514
  }
5389
5515
  }
5390
5516
  if (!options.signalManager) {
5391
- log15.warn("running signaling without telemetry metadata.", void 0, {
5392
- F: __dxlog_file18,
5393
- L: 192,
5517
+ log16.warn("running signaling without telemetry metadata.", void 0, {
5518
+ F: __dxlog_file19,
5519
+ L: 200,
5394
5520
  S: this,
5395
5521
  C: (f, a) => f(...a)
5396
5522
  });
@@ -5400,8 +5526,8 @@ var ClientServicesHost = class {
5400
5526
  }), signalManager = new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
5401
5527
  this._signalManager = signalManager;
5402
5528
  invariant16(!this._networkManager, "network manager already set", {
5403
- F: __dxlog_file18,
5404
- L: 203,
5529
+ F: __dxlog_file19,
5530
+ L: 211,
5405
5531
  S: this,
5406
5532
  A: [
5407
5533
  "!this._networkManager",
@@ -5413,9 +5539,9 @@ var ClientServicesHost = class {
5413
5539
  transportFactory,
5414
5540
  signalManager
5415
5541
  });
5416
- log15("initialized", void 0, {
5417
- F: __dxlog_file18,
5418
- L: 210,
5542
+ log16("initialized", void 0, {
5543
+ F: __dxlog_file19,
5544
+ L: 218,
5419
5545
  S: this,
5420
5546
  C: (f, a) => f(...a)
5421
5547
  });
@@ -5424,18 +5550,18 @@ var ClientServicesHost = class {
5424
5550
  if (this._open) {
5425
5551
  return;
5426
5552
  }
5427
- const traceId = PublicKey12.random().toHex();
5428
- log15.trace("dxos.client-services.host.open", trace9.begin({
5553
+ const traceId = PublicKey13.random().toHex();
5554
+ log16.trace("dxos.client-services.host.open", trace9.begin({
5429
5555
  id: traceId
5430
5556
  }), {
5431
- F: __dxlog_file18,
5432
- L: 221,
5557
+ F: __dxlog_file19,
5558
+ L: 229,
5433
5559
  S: this,
5434
5560
  C: (f, a) => f(...a)
5435
5561
  });
5436
5562
  invariant16(this._config, "config not set", {
5437
- F: __dxlog_file18,
5438
- L: 223,
5563
+ F: __dxlog_file19,
5564
+ L: 231,
5439
5565
  S: this,
5440
5566
  A: [
5441
5567
  "this._config",
@@ -5443,8 +5569,8 @@ var ClientServicesHost = class {
5443
5569
  ]
5444
5570
  });
5445
5571
  invariant16(this._storage, "storage not set", {
5446
- F: __dxlog_file18,
5447
- L: 224,
5572
+ F: __dxlog_file19,
5573
+ L: 232,
5448
5574
  S: this,
5449
5575
  A: [
5450
5576
  "this._storage",
@@ -5452,8 +5578,8 @@ var ClientServicesHost = class {
5452
5578
  ]
5453
5579
  });
5454
5580
  invariant16(this._signalManager, "signal manager not set", {
5455
- F: __dxlog_file18,
5456
- L: 225,
5581
+ F: __dxlog_file19,
5582
+ L: 233,
5457
5583
  S: this,
5458
5584
  A: [
5459
5585
  "this._signalManager",
@@ -5461,8 +5587,8 @@ var ClientServicesHost = class {
5461
5587
  ]
5462
5588
  });
5463
5589
  invariant16(this._networkManager, "network manager not set", {
5464
- F: __dxlog_file18,
5465
- L: 226,
5590
+ F: __dxlog_file19,
5591
+ L: 234,
5466
5592
  S: this,
5467
5593
  A: [
5468
5594
  "this._networkManager",
@@ -5470,17 +5596,20 @@ var ClientServicesHost = class {
5470
5596
  ]
5471
5597
  });
5472
5598
  this._opening = true;
5473
- log15("opening...", {
5599
+ log16("opening...", {
5474
5600
  lockKey: this._resourceLock?.lockKey
5475
5601
  }, {
5476
- F: __dxlog_file18,
5477
- L: 229,
5602
+ F: __dxlog_file19,
5603
+ L: 237,
5478
5604
  S: this,
5479
5605
  C: (f, a) => f(...a)
5480
5606
  });
5607
+ if (!this._level) {
5608
+ this._level = await createLevel(this._config.get("runtime.client.storage", {}));
5609
+ }
5481
5610
  await this._resourceLock?.acquire();
5482
5611
  await this._loggingService.open();
5483
- this._serviceContext = new ServiceContext(this._storage, this._networkManager, this._signalManager, this._runtimeParams);
5612
+ this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._runtimeParams);
5484
5613
  this._serviceRegistry.setServices({
5485
5614
  SystemService: this._systemService,
5486
5615
  IdentityService: new IdentityServiceImpl((params) => this._createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring, (profile) => this._serviceContext.broadcastProfileUpdate(profile)),
@@ -5507,8 +5636,8 @@ var ClientServicesHost = class {
5507
5636
  });
5508
5637
  await this._serviceContext.open(ctx);
5509
5638
  invariant16(this.serviceRegistry.services.InvitationsService, void 0, {
5510
- F: __dxlog_file18,
5511
- L: 290,
5639
+ F: __dxlog_file19,
5640
+ L: 303,
5512
5641
  S: this,
5513
5642
  A: [
5514
5643
  "this.serviceRegistry.services.InvitationsService",
@@ -5516,11 +5645,11 @@ var ClientServicesHost = class {
5516
5645
  ]
5517
5646
  });
5518
5647
  const loadedInvitations = await this.serviceRegistry.services.InvitationsService.loadPersistentInvitations();
5519
- log15("loaded persistent invitations", {
5648
+ log16("loaded persistent invitations", {
5520
5649
  count: loadedInvitations.invitations?.length
5521
5650
  }, {
5522
- F: __dxlog_file18,
5523
- L: 293,
5651
+ F: __dxlog_file19,
5652
+ L: 306,
5524
5653
  S: this,
5525
5654
  C: (f, a) => f(...a)
5526
5655
  });
@@ -5534,23 +5663,24 @@ var ClientServicesHost = class {
5534
5663
  });
5535
5664
  void this._devtoolsProxy.open();
5536
5665
  }
5666
+ this.diagnosticsBroadcastHandler.start();
5537
5667
  this._opening = false;
5538
5668
  this._open = true;
5539
5669
  this._statusUpdate.emit();
5540
5670
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
5541
- log15("opened", {
5671
+ log16("opened", {
5542
5672
  deviceKey
5543
5673
  }, {
5544
- F: __dxlog_file18,
5545
- L: 310,
5674
+ F: __dxlog_file19,
5675
+ L: 324,
5546
5676
  S: this,
5547
5677
  C: (f, a) => f(...a)
5548
5678
  });
5549
- log15.trace("dxos.client-services.host.open", trace9.end({
5679
+ log16.trace("dxos.client-services.host.open", trace9.end({
5550
5680
  id: traceId
5551
5681
  }), {
5552
- F: __dxlog_file18,
5553
- L: 311,
5682
+ F: __dxlog_file19,
5683
+ L: 325,
5554
5684
  S: this,
5555
5685
  C: (f, a) => f(...a)
5556
5686
  });
@@ -5560,60 +5690,62 @@ var ClientServicesHost = class {
5560
5690
  return;
5561
5691
  }
5562
5692
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
5563
- log15("closing...", {
5693
+ log16("closing...", {
5564
5694
  deviceKey
5565
5695
  }, {
5566
- F: __dxlog_file18,
5567
- L: 322,
5696
+ F: __dxlog_file19,
5697
+ L: 336,
5568
5698
  S: this,
5569
5699
  C: (f, a) => f(...a)
5570
5700
  });
5701
+ this.diagnosticsBroadcastHandler.stop();
5571
5702
  await this._devtoolsProxy?.close();
5572
5703
  this._serviceRegistry.setServices({
5573
5704
  SystemService: this._systemService
5574
5705
  });
5575
5706
  await this._loggingService.close();
5576
5707
  await this._serviceContext.close();
5708
+ await this._level?.close();
5577
5709
  this._open = false;
5578
5710
  this._statusUpdate.emit();
5579
- log15("closed", {
5711
+ log16("closed", {
5580
5712
  deviceKey
5581
5713
  }, {
5582
- F: __dxlog_file18,
5583
- L: 329,
5714
+ F: __dxlog_file19,
5715
+ L: 345,
5584
5716
  S: this,
5585
5717
  C: (f, a) => f(...a)
5586
5718
  });
5587
5719
  }
5588
5720
  async reset() {
5589
- const traceId = PublicKey12.random().toHex();
5590
- log15.trace("dxos.sdk.client-services-host.reset", trace9.begin({
5721
+ const traceId = PublicKey13.random().toHex();
5722
+ log16.trace("dxos.sdk.client-services-host.reset", trace9.begin({
5591
5723
  id: traceId
5592
5724
  }), {
5593
- F: __dxlog_file18,
5594
- L: 334,
5725
+ F: __dxlog_file19,
5726
+ L: 350,
5595
5727
  S: this,
5596
5728
  C: (f, a) => f(...a)
5597
5729
  });
5598
- log15("resetting...", void 0, {
5599
- F: __dxlog_file18,
5600
- L: 336,
5730
+ log16("resetting...", void 0, {
5731
+ F: __dxlog_file19,
5732
+ L: 352,
5601
5733
  S: this,
5602
5734
  C: (f, a) => f(...a)
5603
5735
  });
5604
5736
  await this._serviceContext?.close();
5605
5737
  await this._storage.reset();
5606
- log15("reset", void 0, {
5607
- F: __dxlog_file18,
5608
- L: 339,
5738
+ log16("reset", void 0, {
5739
+ F: __dxlog_file19,
5740
+ L: 355,
5609
5741
  S: this,
5610
5742
  C: (f, a) => f(...a)
5611
5743
  });
5612
- log15.trace("dxos.sdk.client-services-host.reset", trace9.end({
5744
+ log16.trace("dxos.sdk.client-services-host.reset", trace9.end({
5613
5745
  id: traceId
5614
5746
  }), {
5615
- F: __dxlog_file18,
5616
- L: 340,
5747
+ F: __dxlog_file19,
5748
+ L: 356,
5617
5749
  S: this,
5618
5750
  C: (f, a) => f(...a)
5619
5751
  });
@@ -5625,8 +5757,8 @@ var ClientServicesHost = class {
5625
5757
  const space = await this._serviceContext.dataSpaceManager.createSpace();
5626
5758
  const automergeIndex = space.automergeSpaceState.rootUrl;
5627
5759
  invariant16(automergeIndex, void 0, {
5628
- F: __dxlog_file18,
5629
- L: 352,
5760
+ F: __dxlog_file19,
5761
+ L: 368,
5630
5762
  S: this,
5631
5763
  A: [
5632
5764
  "automergeIndex",
@@ -5635,18 +5767,25 @@ var ClientServicesHost = class {
5635
5767
  });
5636
5768
  const document = await this._serviceContext.automergeHost.repo.find(automergeIndex);
5637
5769
  await document.whenReady();
5638
- const objectDocument = createRawObjectDoc({
5639
- [defaultKey]: identity.identityKey.toHex()
5640
- }, {
5641
- type: E.getTypeReference(PropertiesSchema)
5642
- });
5770
+ const properties = {
5771
+ system: {
5772
+ type: encodeReference(E.getTypeReference(Properties))
5773
+ },
5774
+ data: {
5775
+ [defaultKey]: identity.identityKey.toHex()
5776
+ },
5777
+ meta: {
5778
+ keys: []
5779
+ }
5780
+ };
5781
+ const propertiesId = PublicKey13.random().toHex();
5643
5782
  document.change((doc) => {
5644
5783
  assignDeep2(doc, [
5645
5784
  "objects",
5646
- objectDocument.id
5647
- ], objectDocument.handle.docSync());
5785
+ propertiesId
5786
+ ], properties);
5648
5787
  });
5649
- await sleep3(200);
5788
+ await this._serviceContext.automergeHost.repo.flush();
5650
5789
  return identity;
5651
5790
  }
5652
5791
  };
@@ -5668,6 +5807,44 @@ ClientServicesHost = _ts_decorate8([
5668
5807
  Trace3.resource()
5669
5808
  ], ClientServicesHost);
5670
5809
 
5810
+ // packages/sdk/client-services/src/packlets/services/util.ts
5811
+ import { PublicKey as PublicKey14 } from "@dxos/keys";
5812
+ import { humanize } from "@dxos/util";
5813
+ var ClientServicesProviderResource = Symbol.for("dxos.resource.ClientServices");
5814
+
5815
+ // packages/sdk/client-services/src/packlets/diagnostics/diagnostics-collector.ts
5816
+ var DiagnosticsCollector = class {
5817
+ static {
5818
+ this.broadcastSender = createCollectDiagnosticsBroadcastSender();
5819
+ }
5820
+ static async collect(config = findConfigs(), services = findSystemServiceProvider(), options = {}) {
5821
+ const serviceDiagnostics = await services?.services?.SystemService?.getDiagnostics({
5822
+ keys: options.humanize ? GetDiagnosticsRequest2.KEY_OPTION.HUMANIZE : options.truncate ? GetDiagnosticsRequest2.KEY_OPTION.TRUNCATE : void 0
5823
+ });
5824
+ const clientDiagnostics = {
5825
+ config,
5826
+ trace: TRACE_PROCESSOR3.getDiagnostics()
5827
+ };
5828
+ const diagnostics = serviceDiagnostics != null ? {
5829
+ client: clientDiagnostics,
5830
+ services: serviceDiagnostics
5831
+ } : {
5832
+ client: clientDiagnostics,
5833
+ broadcast: await this.broadcastSender.broadcastDiagnosticsRequest()
5834
+ };
5835
+ return JSON.parse(JSON.stringify(diagnostics, jsonKeyReplacer2(options)));
5836
+ }
5837
+ };
5838
+ var findSystemServiceProvider = () => {
5839
+ const serviceProviders = TRACE_PROCESSOR3.findByAnnotation(ClientServicesProviderResource);
5840
+ const providerResource = serviceProviders.find((r) => r.instance.deref()?.services?.SystemService != null);
5841
+ return providerResource?.instance?.deref() ?? null;
5842
+ };
5843
+ var findConfigs = () => {
5844
+ const configs = TRACE_PROCESSOR3.findByAnnotation(ConfigResource);
5845
+ return configs.map((r) => r.instance.deref()).filter(nonNullable);
5846
+ };
5847
+
5671
5848
  export {
5672
5849
  Buffer,
5673
5850
  subscribeToFeeds,
@@ -5691,15 +5868,20 @@ export {
5691
5868
  InvitationsServiceImpl,
5692
5869
  SpaceInvitationProtocol,
5693
5870
  ClientRpcServer,
5694
- createDiagnostics,
5695
5871
  DataSpace,
5696
5872
  DataSpaceManager,
5697
5873
  SpacesServiceImpl,
5698
5874
  ServiceContext,
5699
5875
  ServiceRegistry,
5876
+ createDiagnostics,
5877
+ createCollectDiagnosticsBroadcastSender,
5878
+ createCollectDiagnosticsBroadcastHandler,
5879
+ DiagnosticsCollector,
5700
5880
  Lock,
5701
5881
  isLocked,
5702
5882
  createStorageObjects,
5703
- ClientServicesHost
5883
+ createLevel,
5884
+ ClientServicesHost,
5885
+ ClientServicesProviderResource
5704
5886
  };
5705
- //# sourceMappingURL=chunk-5YFNO6CM.mjs.map
5887
+ //# sourceMappingURL=chunk-DXJJOAJI.mjs.map