@dxos/client-services 0.4.10-main.d9dc7ae → 0.4.10-main.e9f9c10

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 (64) hide show
  1. package/dist/lib/browser/{chunk-WYFJLESV.mjs → chunk-4GN43XQ4.mjs} +708 -561
  2. package/dist/lib/browser/chunk-4GN43XQ4.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +9 -3
  4. package/dist/lib/browser/index.mjs.map +1 -1
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +8 -4
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/{chunk-SF4YXR7W.cjs → chunk-V7W7YK6W.cjs} +663 -599
  9. package/dist/lib/node/chunk-V7W7YK6W.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +45 -39
  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 +13 -9
  14. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  15. package/dist/types/src/index.d.ts +1 -0
  16. package/dist/types/src/index.d.ts.map +1 -1
  17. package/dist/types/src/packlets/diagnostics/browser-diagnostics-broadcast.d.ts +5 -0
  18. package/dist/types/src/packlets/diagnostics/browser-diagnostics-broadcast.d.ts.map +1 -0
  19. package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts +5 -0
  20. package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts.map +1 -0
  21. package/dist/types/src/packlets/diagnostics/diagnostics-collector.d.ts +15 -0
  22. package/dist/types/src/packlets/diagnostics/diagnostics-collector.d.ts.map +1 -0
  23. package/dist/types/src/packlets/{services → diagnostics}/diagnostics.d.ts +1 -1
  24. package/dist/types/src/packlets/diagnostics/diagnostics.d.ts.map +1 -0
  25. package/dist/types/src/packlets/diagnostics/index.d.ts +4 -0
  26. package/dist/types/src/packlets/diagnostics/index.d.ts.map +1 -0
  27. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +0 -1
  28. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  29. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  30. package/dist/types/src/packlets/services/index.d.ts +1 -1
  31. package/dist/types/src/packlets/services/index.d.ts.map +1 -1
  32. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  33. package/dist/types/src/packlets/services/service-host.d.ts +4 -1
  34. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  35. package/dist/types/src/packlets/services/util.d.ts +1 -0
  36. package/dist/types/src/packlets/services/util.d.ts.map +1 -1
  37. package/dist/types/src/packlets/system/system-service.d.ts +1 -1
  38. package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
  39. package/dist/types/src/packlets/testing/test-builder.d.ts +4 -1
  40. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  41. package/dist/types/src/version.d.ts +1 -1
  42. package/package.json +35 -34
  43. package/src/index.ts +1 -0
  44. package/src/packlets/diagnostics/browser-diagnostics-broadcast.ts +94 -0
  45. package/src/packlets/diagnostics/diagnostics-broadcast.ts +20 -0
  46. package/src/packlets/diagnostics/diagnostics-collector.ts +65 -0
  47. package/src/packlets/{services → diagnostics}/diagnostics.ts +2 -2
  48. package/src/packlets/diagnostics/index.ts +7 -0
  49. package/src/packlets/invitations/invitations-handler.ts +5 -12
  50. package/src/packlets/invitations/invitations-service.ts +5 -5
  51. package/src/packlets/services/automerge-host.test.ts +9 -3
  52. package/src/packlets/services/index.ts +1 -1
  53. package/src/packlets/services/service-context.test.ts +4 -1
  54. package/src/packlets/services/service-context.ts +2 -0
  55. package/src/packlets/services/service-host.ts +21 -2
  56. package/src/packlets/services/util.ts +2 -0
  57. package/src/packlets/spaces/data-space-manager.test.ts +4 -4
  58. package/src/packlets/storage/level.ts +1 -1
  59. package/src/packlets/system/system-service.ts +1 -1
  60. package/src/packlets/testing/test-builder.ts +20 -4
  61. package/src/version.ts +1 -1
  62. package/dist/lib/browser/chunk-WYFJLESV.mjs.map +0 -7
  63. package/dist/lib/node/chunk-SF4YXR7W.cjs.map +0 -7
  64. package/dist/types/src/packlets/services/diagnostics.d.ts.map +0 -1
@@ -1639,11 +1639,11 @@ var InvitationsHandler = class {
1639
1639
  this._networkManager = _networkManager;
1640
1640
  }
1641
1641
  createInvitation(protocol, options) {
1642
- const { invitationId = PublicKey6.random().toHex(), type = Invitation3.Type.INTERACTIVE, authMethod = Invitation3.AuthMethod.SHARED_SECRET, state = Invitation3.State.INIT, timeout = INVITATION_TIMEOUT, swarmKey = PublicKey6.random(), persistent = true, created = /* @__PURE__ */ new Date(), lifetime = 86400 } = options ?? {};
1642
+ const { invitationId = PublicKey6.random().toHex(), type = Invitation3.Type.INTERACTIVE, authMethod = Invitation3.AuthMethod.SHARED_SECRET, state = Invitation3.State.INIT, timeout = INVITATION_TIMEOUT, swarmKey = PublicKey6.random(), persistent = true, created = /* @__PURE__ */ new Date(), lifetime = 86400, multiUse = false } = options ?? {};
1643
1643
  const authCode = options?.authCode ?? (authMethod === Invitation3.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0);
1644
1644
  invariant6(protocol, void 0, {
1645
1645
  F: __dxlog_file7,
1646
- L: 84,
1646
+ L: 85,
1647
1647
  S: this,
1648
1648
  A: [
1649
1649
  "protocol",
@@ -1658,9 +1658,10 @@ var InvitationsHandler = class {
1658
1658
  swarmKey,
1659
1659
  authCode,
1660
1660
  timeout,
1661
- persistent,
1661
+ persistent: persistent && type !== Invitation3.Type.OFFLINE,
1662
1662
  created,
1663
1663
  lifetime,
1664
+ multiUse,
1664
1665
  ...protocol.getInvitationContext()
1665
1666
  };
1666
1667
  const stream = new PushStream();
@@ -1675,7 +1676,7 @@ var InvitationsHandler = class {
1675
1676
  ...protocol.toJSON()
1676
1677
  }, {
1677
1678
  F: __dxlog_file7,
1678
- L: 109,
1679
+ L: 111,
1679
1680
  S: this,
1680
1681
  C: (f, a) => f(...a)
1681
1682
  });
@@ -1700,7 +1701,7 @@ var InvitationsHandler = class {
1700
1701
  const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
1701
1702
  invariant6(deviceKey, void 0, {
1702
1703
  F: __dxlog_file7,
1703
- L: 130,
1704
+ L: 132,
1704
1705
  S: this,
1705
1706
  A: [
1706
1707
  "deviceKey",
@@ -1723,7 +1724,7 @@ var InvitationsHandler = class {
1723
1724
  id: traceId
1724
1725
  }), {
1725
1726
  F: __dxlog_file7,
1726
- L: 148,
1727
+ L: 150,
1727
1728
  S: this,
1728
1729
  C: (f, a) => f(...a)
1729
1730
  });
@@ -1731,7 +1732,7 @@ var InvitationsHandler = class {
1731
1732
  ...protocol.toJSON()
1732
1733
  }, {
1733
1734
  F: __dxlog_file7,
1734
- L: 149,
1735
+ L: 151,
1735
1736
  S: this,
1736
1737
  C: (f, a) => f(...a)
1737
1738
  });
@@ -1747,7 +1748,7 @@ var InvitationsHandler = class {
1747
1748
  ...protocol.toJSON()
1748
1749
  }, {
1749
1750
  F: __dxlog_file7,
1750
- L: 152,
1751
+ L: 154,
1751
1752
  S: this,
1752
1753
  C: (f, a) => f(...a)
1753
1754
  });
@@ -1759,7 +1760,7 @@ var InvitationsHandler = class {
1759
1760
  id: traceId
1760
1761
  }), {
1761
1762
  F: __dxlog_file7,
1762
- L: 154,
1763
+ L: 156,
1763
1764
  S: this,
1764
1765
  C: (f, a) => f(...a)
1765
1766
  });
@@ -1769,7 +1770,7 @@ var InvitationsHandler = class {
1769
1770
  ...protocol.toJSON()
1770
1771
  }, {
1771
1772
  F: __dxlog_file7,
1772
- L: 157,
1773
+ L: 159,
1773
1774
  S: this,
1774
1775
  C: (f, a) => f(...a)
1775
1776
  });
@@ -1780,7 +1781,7 @@ var InvitationsHandler = class {
1780
1781
  } else {
1781
1782
  log5.error("failed", err, {
1782
1783
  F: __dxlog_file7,
1783
- L: 160,
1784
+ L: 162,
1784
1785
  S: this,
1785
1786
  C: (f, a) => f(...a)
1786
1787
  });
@@ -1791,12 +1792,12 @@ var InvitationsHandler = class {
1791
1792
  error: err
1792
1793
  }), {
1793
1794
  F: __dxlog_file7,
1794
- L: 163,
1795
+ L: 165,
1795
1796
  S: this,
1796
1797
  C: (f, a) => f(...a)
1797
1798
  });
1798
1799
  } finally {
1799
- if (type !== Invitation3.Type.MULTIUSE) {
1800
+ if (!multiUse) {
1800
1801
  await swarmConnection.close();
1801
1802
  await ctx.dispose();
1802
1803
  }
@@ -1812,7 +1813,7 @@ var InvitationsHandler = class {
1812
1813
  ...protocol.toJSON()
1813
1814
  }, {
1814
1815
  F: __dxlog_file7,
1815
- L: 178,
1816
+ L: 180,
1816
1817
  S: this,
1817
1818
  C: (f, a) => f(...a)
1818
1819
  });
@@ -1823,7 +1824,7 @@ var InvitationsHandler = class {
1823
1824
  } else {
1824
1825
  log5.error("failed", err, {
1825
1826
  F: __dxlog_file7,
1826
- L: 181,
1827
+ L: 183,
1827
1828
  S: this,
1828
1829
  C: (f, a) => f(...a)
1829
1830
  });
@@ -1837,7 +1838,7 @@ var InvitationsHandler = class {
1837
1838
  if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
1838
1839
  log5.warn("invitation has already expired", void 0, {
1839
1840
  F: __dxlog_file7,
1840
- L: 192,
1841
+ L: 194,
1841
1842
  S: this,
1842
1843
  C: (f, a) => f(...a)
1843
1844
  });
@@ -1888,7 +1889,7 @@ var InvitationsHandler = class {
1888
1889
  const { timeout = INVITATION_TIMEOUT } = invitation;
1889
1890
  invariant6(protocol, void 0, {
1890
1891
  F: __dxlog_file7,
1891
- L: 246,
1892
+ L: 248,
1892
1893
  S: this,
1893
1894
  A: [
1894
1895
  "protocol",
@@ -1898,7 +1899,7 @@ var InvitationsHandler = class {
1898
1899
  if (deviceProfile) {
1899
1900
  invariant6(invitation.kind === Invitation3.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
1900
1901
  F: __dxlog_file7,
1901
- L: 250,
1902
+ L: 252,
1902
1903
  S: this,
1903
1904
  A: [
1904
1905
  "invitation.kind === Invitation.Kind.DEVICE",
@@ -1913,7 +1914,7 @@ var InvitationsHandler = class {
1913
1914
  const setState = (newData) => {
1914
1915
  invariant6(newData.state !== void 0, void 0, {
1915
1916
  F: __dxlog_file7,
1916
- L: 261,
1917
+ L: 263,
1917
1918
  S: this,
1918
1919
  A: [
1919
1920
  "newData.state !== undefined",
@@ -1933,7 +1934,7 @@ var InvitationsHandler = class {
1933
1934
  ...protocol.toJSON()
1934
1935
  }, {
1935
1936
  F: __dxlog_file7,
1936
- L: 269,
1937
+ L: 271,
1937
1938
  S: this,
1938
1939
  C: (f, a) => f(...a)
1939
1940
  });
@@ -1943,7 +1944,7 @@ var InvitationsHandler = class {
1943
1944
  } else {
1944
1945
  log5.warn("auth failed", err, {
1945
1946
  F: __dxlog_file7,
1946
- L: 272,
1947
+ L: 274,
1947
1948
  S: this,
1948
1949
  C: (f, a) => f(...a)
1949
1950
  });
@@ -1957,7 +1958,7 @@ var InvitationsHandler = class {
1957
1958
  ...protocol.toJSON()
1958
1959
  }, {
1959
1960
  F: __dxlog_file7,
1960
- L: 280,
1961
+ L: 282,
1961
1962
  S: this,
1962
1963
  C: (f, a) => f(...a)
1963
1964
  });
@@ -1972,7 +1973,7 @@ var InvitationsHandler = class {
1972
1973
  currentState
1973
1974
  }, {
1974
1975
  F: __dxlog_file7,
1975
- L: 290,
1976
+ L: 292,
1976
1977
  S: this,
1977
1978
  C: (f, a) => f(...a)
1978
1979
  });
@@ -1987,7 +1988,7 @@ var InvitationsHandler = class {
1987
1988
  id: traceId
1988
1989
  }), {
1989
1990
  F: __dxlog_file7,
1990
- L: 299,
1991
+ L: 301,
1991
1992
  S: this,
1992
1993
  C: (f, a) => f(...a)
1993
1994
  });
@@ -1999,7 +2000,7 @@ var InvitationsHandler = class {
1999
2000
  ...protocol.toJSON()
2000
2001
  }, {
2001
2002
  F: __dxlog_file7,
2002
- L: 307,
2003
+ L: 309,
2003
2004
  S: this,
2004
2005
  C: (f, a) => f(...a)
2005
2006
  });
@@ -2010,7 +2011,7 @@ var InvitationsHandler = class {
2010
2011
  ...protocol.toJSON()
2011
2012
  }, {
2012
2013
  F: __dxlog_file7,
2013
- L: 311,
2014
+ L: 313,
2014
2015
  S: this,
2015
2016
  C: (f, a) => f(...a)
2016
2017
  });
@@ -2020,7 +2021,7 @@ var InvitationsHandler = class {
2020
2021
  response: introductionResponse
2021
2022
  }, {
2022
2023
  F: __dxlog_file7,
2023
- L: 315,
2024
+ L: 317,
2024
2025
  S: this,
2025
2026
  C: (f, a) => f(...a)
2026
2027
  });
@@ -2029,7 +2030,7 @@ var InvitationsHandler = class {
2029
2030
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2030
2031
  log5("guest waiting for authentication code...", void 0, {
2031
2032
  F: __dxlog_file7,
2032
- L: 321,
2033
+ L: 323,
2033
2034
  S: this,
2034
2035
  C: (f, a) => f(...a)
2035
2036
  });
@@ -2041,7 +2042,7 @@ var InvitationsHandler = class {
2041
2042
  });
2042
2043
  log5("sending authentication request", void 0, {
2043
2044
  F: __dxlog_file7,
2044
- L: 325,
2045
+ L: 327,
2045
2046
  S: this,
2046
2047
  C: (f, a) => f(...a)
2047
2048
  });
@@ -2062,7 +2063,7 @@ var InvitationsHandler = class {
2062
2063
  attempt
2063
2064
  }, {
2064
2065
  F: __dxlog_file7,
2065
- L: 336,
2066
+ L: 338,
2066
2067
  S: this,
2067
2068
  C: (f, a) => f(...a)
2068
2069
  });
@@ -2075,7 +2076,7 @@ var InvitationsHandler = class {
2075
2076
  ...protocol.toJSON()
2076
2077
  }, {
2077
2078
  F: __dxlog_file7,
2078
- L: 344,
2079
+ L: 346,
2079
2080
  S: this,
2080
2081
  C: (f, a) => f(...a)
2081
2082
  });
@@ -2087,7 +2088,7 @@ var InvitationsHandler = class {
2087
2088
  ...protocol.toJSON()
2088
2089
  }, {
2089
2090
  F: __dxlog_file7,
2090
- L: 355,
2091
+ L: 357,
2091
2092
  S: this,
2092
2093
  C: (f, a) => f(...a)
2093
2094
  });
@@ -2100,7 +2101,7 @@ var InvitationsHandler = class {
2100
2101
  id: traceId
2101
2102
  }), {
2102
2103
  F: __dxlog_file7,
2103
- L: 357,
2104
+ L: 359,
2104
2105
  S: this,
2105
2106
  C: (f, a) => f(...a)
2106
2107
  });
@@ -2110,7 +2111,7 @@ var InvitationsHandler = class {
2110
2111
  ...protocol.toJSON()
2111
2112
  }, {
2112
2113
  F: __dxlog_file7,
2113
- L: 360,
2114
+ L: 362,
2114
2115
  S: this,
2115
2116
  C: (f, a) => f(...a)
2116
2117
  });
@@ -2120,7 +2121,7 @@ var InvitationsHandler = class {
2120
2121
  } else {
2121
2122
  log5("auth failed", err, {
2122
2123
  F: __dxlog_file7,
2123
- L: 363,
2124
+ L: 365,
2124
2125
  S: this,
2125
2126
  C: (f, a) => f(...a)
2126
2127
  });
@@ -2131,7 +2132,7 @@ var InvitationsHandler = class {
2131
2132
  error: err
2132
2133
  }), {
2133
2134
  F: __dxlog_file7,
2134
- L: 366,
2135
+ L: 368,
2135
2136
  S: this,
2136
2137
  C: (f, a) => f(...a)
2137
2138
  });
@@ -2149,7 +2150,7 @@ var InvitationsHandler = class {
2149
2150
  ...protocol.toJSON()
2150
2151
  }, {
2151
2152
  F: __dxlog_file7,
2152
- L: 377,
2153
+ L: 379,
2153
2154
  S: this,
2154
2155
  C: (f, a) => f(...a)
2155
2156
  });
@@ -2159,7 +2160,7 @@ var InvitationsHandler = class {
2159
2160
  } else {
2160
2161
  log5("auth failed", err, {
2161
2162
  F: __dxlog_file7,
2162
- L: 380,
2163
+ L: 382,
2163
2164
  S: this,
2164
2165
  C: (f, a) => f(...a)
2165
2166
  });
@@ -2176,7 +2177,7 @@ var InvitationsHandler = class {
2176
2177
  } else {
2177
2178
  invariant6(invitation.swarmKey, void 0, {
2178
2179
  F: __dxlog_file7,
2179
- L: 394,
2180
+ L: 396,
2180
2181
  S: this,
2181
2182
  A: [
2182
2183
  "invitation.swarmKey",
@@ -2215,14 +2216,12 @@ var InvitationsHandler = class {
2215
2216
  return observable;
2216
2217
  }
2217
2218
  };
2218
- var invitationExpired = (invitation) => {
2219
- return invitation.created && invitation.lifetime && invitation.lifetime !== 0 && invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now();
2220
- };
2221
2219
 
2222
2220
  // packages/sdk/client-services/src/packlets/invitations/invitations-service.ts
2223
2221
  import { Event as Event3, scheduleTask as scheduleTask3 } from "@dxos/async";
2224
2222
  import { Stream as Stream8 } from "@dxos/codec-protobuf";
2225
2223
  import { Context as Context6 } from "@dxos/context";
2224
+ import { hasInvitationExpired } from "@dxos/echo-pipeline";
2226
2225
  import { invariant as invariant7 } from "@dxos/invariant";
2227
2226
  import { log as log6 } from "@dxos/log";
2228
2227
  import { Invitation as Invitation4, QueryInvitationsResponse } from "@dxos/protocols/proto/dxos/client/services";
@@ -2281,7 +2280,7 @@ var InvitationsServiceImpl = class {
2281
2280
  await this._metadataStore.removeInvitation(invitation.get().invitationId);
2282
2281
  }
2283
2282
  this._createInvitations.delete(invitation.get().invitationId);
2284
- if (invitation.get().type !== Invitation4.Type.MULTIUSE) {
2283
+ if (!invitation.get().multiUse) {
2285
2284
  this._removedCreated.emit(invitation.get());
2286
2285
  }
2287
2286
  });
@@ -2289,7 +2288,7 @@ var InvitationsServiceImpl = class {
2289
2288
  }
2290
2289
  async loadPersistentInvitations() {
2291
2290
  const persistentInvitations = this._metadataStore.getInvitations();
2292
- const freshInvitations = persistentInvitations.filter(async (invitation) => !invitationExpired(invitation));
2291
+ const freshInvitations = persistentInvitations.filter(async (invitation) => !hasInvitationExpired(invitation));
2293
2292
  const cInvitations = freshInvitations.map((persistentInvitation) => {
2294
2293
  invariant7(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
2295
2294
  F: __dxlog_file8,
@@ -2342,7 +2341,7 @@ var InvitationsServiceImpl = class {
2342
2341
  }, () => {
2343
2342
  close();
2344
2343
  this._acceptInvitations.delete(invitation.get().invitationId);
2345
- if (invitation.get().type !== Invitation4.Type.MULTIUSE) {
2344
+ if (!invitation.get().multiUse) {
2346
2345
  this._removedAccepted.emit(invitation.get());
2347
2346
  }
2348
2347
  });
@@ -2730,156 +2729,6 @@ ClientRpcServer = _ts_decorate3([
2730
2729
  trace5.resource()
2731
2730
  ], ClientRpcServer);
2732
2731
 
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.d9dc7ae";
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
2732
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2884
2733
  import { Event as Event6, asyncTimeout, scheduleTask as scheduleTask5, sleep as sleep2, synchronized, trackLeaks } from "@dxos/async";
2885
2734
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
@@ -2888,7 +2737,7 @@ import { timed, warnAfterTimeout } from "@dxos/debug";
2888
2737
  import { TYPE_PROPERTIES } from "@dxos/echo-db";
2889
2738
  import { createMappedFeedWriter } from "@dxos/echo-pipeline";
2890
2739
  import { AutomergeDocumentLoaderImpl } from "@dxos/echo-pipeline";
2891
- import { failedInvariant, invariant as invariant11 } from "@dxos/invariant";
2740
+ import { failedInvariant, invariant as invariant10 } from "@dxos/invariant";
2892
2741
  import { PublicKey as PublicKey8 } from "@dxos/keys";
2893
2742
  import { log as log9 } from "@dxos/log";
2894
2743
  import { CancelledError, SystemError } from "@dxos/protocols";
@@ -2939,13 +2788,13 @@ var AutomergeSpaceState = class {
2939
2788
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
2940
2789
  import { DeferredTask, Event as Event5, scheduleTask as scheduleTask4, sleep, TimeoutError as TimeoutError2, Trigger as Trigger4 } from "@dxos/async";
2941
2790
  import { Context as Context7, rejectOnDispose } from "@dxos/context";
2942
- import { invariant as invariant10 } from "@dxos/invariant";
2791
+ import { invariant as invariant9 } from "@dxos/invariant";
2943
2792
  import { PublicKey as PublicKey7 } from "@dxos/keys";
2944
2793
  import { log as log8 } from "@dxos/log";
2945
2794
  import { schema as schema3 } from "@dxos/protocols";
2946
2795
  import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
2947
2796
  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";
2797
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
2949
2798
  var DEFAULT_RETRY_TIMEOUT = 1e3;
2950
2799
  var DEFAULT_SUCCESS_DELAY = 1e3;
2951
2800
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
@@ -2973,13 +2822,13 @@ var NotarizationPlugin = class {
2973
2822
  log8("notarize", {
2974
2823
  credentials
2975
2824
  }, {
2976
- F: __dxlog_file11,
2825
+ F: __dxlog_file10,
2977
2826
  L: 90,
2978
2827
  S: this,
2979
2828
  C: (f, a) => f(...a)
2980
2829
  });
2981
- invariant10(credentials.every((credential) => credential.id), "Credentials must have an id", {
2982
- F: __dxlog_file11,
2830
+ invariant9(credentials.every((credential) => credential.id), "Credentials must have an id", {
2831
+ F: __dxlog_file10,
2983
2832
  L: 91,
2984
2833
  S: this,
2985
2834
  A: [
@@ -2993,7 +2842,7 @@ var NotarizationPlugin = class {
2993
2842
  log8.warn("Notarization error", {
2994
2843
  err
2995
2844
  }, {
2996
- F: __dxlog_file11,
2845
+ F: __dxlog_file10,
2997
2846
  L: 99,
2998
2847
  S: this,
2999
2848
  C: (f, a) => f(...a)
@@ -3009,7 +2858,7 @@ var NotarizationPlugin = class {
3009
2858
  timeout,
3010
2859
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
3011
2860
  }, {
3012
- F: __dxlog_file11,
2861
+ F: __dxlog_file10,
3013
2862
  L: 111,
3014
2863
  S: this,
3015
2864
  C: (f, a) => f(...a)
@@ -3032,7 +2881,7 @@ var NotarizationPlugin = class {
3032
2881
  log8.info("Exhausted all peers to notarize with", {
3033
2882
  retryIn: retryTimeout
3034
2883
  }, {
3035
- F: __dxlog_file11,
2884
+ F: __dxlog_file10,
3036
2885
  L: 136,
3037
2886
  S: this,
3038
2887
  C: (f, a) => f(...a)
@@ -3046,7 +2895,7 @@ var NotarizationPlugin = class {
3046
2895
  peer: peer.localPeerId,
3047
2896
  credentialId: credentials.map((credential) => credential.id)
3048
2897
  }, {
3049
- F: __dxlog_file11,
2898
+ F: __dxlog_file10,
3050
2899
  L: 143,
3051
2900
  S: this,
3052
2901
  C: (f, a) => f(...a)
@@ -3055,7 +2904,7 @@ var NotarizationPlugin = class {
3055
2904
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
3056
2905
  });
3057
2906
  log8("success", void 0, {
3058
- F: __dxlog_file11,
2907
+ F: __dxlog_file10,
3059
2908
  L: 147,
3060
2909
  S: this,
3061
2910
  C: (f, a) => f(...a)
@@ -3064,7 +2913,7 @@ var NotarizationPlugin = class {
3064
2913
  } catch (err) {
3065
2914
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
3066
2915
  log8.info("error notarizing (recoverable)", err, {
3067
- F: __dxlog_file11,
2916
+ F: __dxlog_file10,
3068
2917
  L: 151,
3069
2918
  S: this,
3070
2919
  C: (f, a) => f(...a)
@@ -3082,7 +2931,7 @@ var NotarizationPlugin = class {
3082
2931
  errors.wait()
3083
2932
  ]);
3084
2933
  log8("done", void 0, {
3085
- F: __dxlog_file11,
2934
+ F: __dxlog_file10,
3086
2935
  L: 162,
3087
2936
  S: this,
3088
2937
  C: (f, a) => f(...a)
@@ -3103,8 +2952,8 @@ var NotarizationPlugin = class {
3103
2952
  this._processCredentialsTriggers.delete(credential.id);
3104
2953
  }
3105
2954
  setWriter(writer) {
3106
- invariant10(!this._writer, "Writer already set.", {
3107
- F: __dxlog_file11,
2955
+ invariant9(!this._writer, "Writer already set.", {
2956
+ F: __dxlog_file10,
3108
2957
  L: 181,
3109
2958
  S: this,
3110
2959
  A: [
@@ -3128,8 +2977,8 @@ var NotarizationPlugin = class {
3128
2977
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
3129
2978
  }
3130
2979
  for (const credential of request.credentials ?? []) {
3131
- invariant10(credential.id, "Credential must have an id", {
3132
- F: __dxlog_file11,
2980
+ invariant9(credential.id, "Credential must have an id", {
2981
+ F: __dxlog_file10,
3133
2982
  L: 200,
3134
2983
  S: this,
3135
2984
  A: [
@@ -3149,7 +2998,7 @@ var NotarizationPlugin = class {
3149
2998
  log8("extension opened", {
3150
2999
  peer: extension.localPeerId
3151
3000
  }, {
3152
- F: __dxlog_file11,
3001
+ F: __dxlog_file10,
3153
3002
  L: 211,
3154
3003
  S: this,
3155
3004
  C: (f, a) => f(...a)
@@ -3161,7 +3010,7 @@ var NotarizationPlugin = class {
3161
3010
  log8("extension closed", {
3162
3011
  peer: extension.localPeerId
3163
3012
  }, {
3164
- F: __dxlog_file11,
3013
+ F: __dxlog_file10,
3165
3014
  L: 216,
3166
3015
  S: this,
3167
3016
  C: (f, a) => f(...a)
@@ -3215,7 +3064,7 @@ function _ts_decorate4(decorators, target, key, desc) {
3215
3064
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3216
3065
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3217
3066
  }
3218
- var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
3067
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
3219
3068
  var DataSpace = class {
3220
3069
  constructor(params) {
3221
3070
  this._ctx = new Context8();
@@ -3250,7 +3099,7 @@ var DataSpace = class {
3250
3099
  log9("new state", {
3251
3100
  state: SpaceState[this._state]
3252
3101
  }, {
3253
- F: __dxlog_file12,
3102
+ F: __dxlog_file11,
3254
3103
  L: 140,
3255
3104
  S: this,
3256
3105
  C: (f, a) => f(...a)
@@ -3300,7 +3149,7 @@ var DataSpace = class {
3300
3149
  log9("new state", {
3301
3150
  state: SpaceState[this._state]
3302
3151
  }, {
3303
- F: __dxlog_file12,
3152
+ F: __dxlog_file11,
3304
3153
  L: 198,
3305
3154
  S: this,
3306
3155
  C: (f, a) => f(...a)
@@ -3318,7 +3167,7 @@ var DataSpace = class {
3318
3167
  log9("new state", {
3319
3168
  state: SpaceState[this._state]
3320
3169
  }, {
3321
- F: __dxlog_file12,
3170
+ F: __dxlog_file11,
3322
3171
  L: 212,
3323
3172
  S: this,
3324
3173
  C: (f, a) => f(...a)
@@ -3350,7 +3199,7 @@ var DataSpace = class {
3350
3199
  } catch (err) {
3351
3200
  if (err instanceof CancelledError || err instanceof ContextDisposedError) {
3352
3201
  log9("data pipeline initialization cancelled", err, {
3353
- F: __dxlog_file12,
3202
+ F: __dxlog_file11,
3354
3203
  L: 245,
3355
3204
  S: this,
3356
3205
  C: (f, a) => f(...a)
@@ -3358,7 +3207,7 @@ var DataSpace = class {
3358
3207
  return;
3359
3208
  }
3360
3209
  log9.error("Error initializing data pipeline", err, {
3361
- F: __dxlog_file12,
3210
+ F: __dxlog_file11,
3362
3211
  L: 249,
3363
3212
  S: this,
3364
3213
  C: (f, a) => f(...a)
@@ -3367,7 +3216,7 @@ var DataSpace = class {
3367
3216
  log9("new state", {
3368
3217
  state: SpaceState[this._state]
3369
3218
  }, {
3370
- F: __dxlog_file12,
3219
+ F: __dxlog_file11,
3371
3220
  L: 251,
3372
3221
  S: this,
3373
3222
  C: (f, a) => f(...a)
@@ -3387,7 +3236,7 @@ var DataSpace = class {
3387
3236
  log9("new state", {
3388
3237
  state: SpaceState[this._state]
3389
3238
  }, {
3390
- F: __dxlog_file12,
3239
+ F: __dxlog_file11,
3391
3240
  L: 267,
3392
3241
  S: this,
3393
3242
  C: (f, a) => f(...a)
@@ -3397,7 +3246,7 @@ var DataSpace = class {
3397
3246
  this._automergeSpaceState.startProcessingRootDocs();
3398
3247
  await cancelWithContext2(this._ctx, this.automergeSpaceState.ensureEpochInitialized());
3399
3248
  log9("data pipeline ready", void 0, {
3400
- F: __dxlog_file12,
3249
+ F: __dxlog_file11,
3401
3250
  L: 279,
3402
3251
  S: this,
3403
3252
  C: (f, a) => f(...a)
@@ -3407,7 +3256,7 @@ var DataSpace = class {
3407
3256
  log9("new state", {
3408
3257
  state: SpaceState[this._state]
3409
3258
  }, {
3410
- F: __dxlog_file12,
3259
+ F: __dxlog_file11,
3411
3260
  L: 283,
3412
3261
  S: this,
3413
3262
  C: (f, a) => f(...a)
@@ -3423,7 +3272,7 @@ var DataSpace = class {
3423
3272
  this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
3424
3273
  await this._createWritableFeeds();
3425
3274
  log9("writable feeds created", void 0, {
3426
- F: __dxlog_file12,
3275
+ F: __dxlog_file11,
3427
3276
  L: 299,
3428
3277
  S: this,
3429
3278
  C: (f, a) => f(...a)
@@ -3486,7 +3335,7 @@ var DataSpace = class {
3486
3335
  space: this.key,
3487
3336
  rootUrl
3488
3337
  }, {
3489
- F: __dxlog_file12,
3338
+ F: __dxlog_file11,
3490
3339
  L: 365,
3491
3340
  S: this,
3492
3341
  C: (f, a) => f(...a)
@@ -3518,7 +3367,7 @@ var DataSpace = class {
3518
3367
  rootUrl,
3519
3368
  err
3520
3369
  }, {
3521
- F: __dxlog_file12,
3370
+ F: __dxlog_file11,
3522
3371
  L: 388,
3523
3372
  S: this,
3524
3373
  C: (f, a) => f(...a)
@@ -3572,8 +3421,8 @@ var DataSpace = class {
3572
3421
  const rootHandle = this._automergeHost.repo.find(currentRootUrl);
3573
3422
  await cancelWithContext2(this._ctx, asyncTimeout(rootHandle.whenReady(), 1e4));
3574
3423
  const newRoot = this._automergeHost.repo.create(rootHandle.docSync());
3575
- invariant11(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3576
- F: __dxlog_file12,
3424
+ invariant10(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3425
+ F: __dxlog_file11,
3577
3426
  L: 438,
3578
3427
  S: this,
3579
3428
  A: [
@@ -3592,7 +3441,7 @@ var DataSpace = class {
3592
3441
  case CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT:
3593
3442
  {
3594
3443
  log9.info("Fragmenting", void 0, {
3595
- F: __dxlog_file12,
3444
+ F: __dxlog_file11,
3596
3445
  L: 450,
3597
3446
  S: this,
3598
3447
  C: (f, a) => f(...a)
@@ -3603,8 +3452,8 @@ var DataSpace = class {
3603
3452
  const objects = Object.entries(rootHandle.docSync().objects);
3604
3453
  const properties = objects.find(([_, value]) => value.system.type?.itemId === TYPE_PROPERTIES);
3605
3454
  const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
3606
- invariant11(properties, "Properties not found", {
3607
- F: __dxlog_file12,
3455
+ invariant10(properties, "Properties not found", {
3456
+ F: __dxlog_file11,
3608
3457
  L: 460,
3609
3458
  S: this,
3610
3459
  A: [
@@ -3619,8 +3468,8 @@ var DataSpace = class {
3619
3468
  ])
3620
3469
  };
3621
3470
  const newRoot = this._automergeHost.repo.create(newSpaceDoc);
3622
- invariant11(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3623
- F: __dxlog_file12,
3471
+ invariant10(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3472
+ F: __dxlog_file11,
3624
3473
  L: 465,
3625
3474
  S: this,
3626
3475
  A: [
@@ -3689,7 +3538,7 @@ var DataSpace = class {
3689
3538
  log9("new state", {
3690
3539
  state: SpaceState[this._state]
3691
3540
  }, {
3692
- F: __dxlog_file12,
3541
+ F: __dxlog_file11,
3693
3542
  L: 531,
3694
3543
  S: this,
3695
3544
  C: (f, a) => f(...a)
@@ -3747,7 +3596,7 @@ DataSpace = _ts_decorate4([
3747
3596
  import { Event as Event7, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
3748
3597
  import { Context as Context9, cancelWithContext as cancelWithContext3 } from "@dxos/context";
3749
3598
  import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
3750
- import { invariant as invariant12 } from "@dxos/invariant";
3599
+ import { invariant as invariant11 } from "@dxos/invariant";
3751
3600
  import { PublicKey as PublicKey9 } from "@dxos/keys";
3752
3601
  import { log as log10 } from "@dxos/log";
3753
3602
  import { trace as trace7 } from "@dxos/protocols";
@@ -3758,7 +3607,7 @@ import { ComplexMap as ComplexMap3, deferFunction as deferFunction2, forEachAsyn
3758
3607
  // packages/sdk/client-services/src/packlets/spaces/genesis.ts
3759
3608
  import { createCredential } from "@dxos/credentials";
3760
3609
  import { failUndefined } from "@dxos/debug";
3761
- import { AdmittedFeed as AdmittedFeed4, SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/halo/credentials";
3610
+ import { AdmittedFeed as AdmittedFeed4, SpaceMember } from "@dxos/protocols/proto/dxos/halo/credentials";
3762
3611
  import { Timeframe as Timeframe3 } from "@dxos/timeframe";
3763
3612
  var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3764
3613
  const credentials = [
@@ -3778,7 +3627,7 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3778
3627
  assertion: {
3779
3628
  "@type": "dxos.halo.credentials.SpaceMember",
3780
3629
  spaceKey: space.key,
3781
- role: SpaceMember2.Role.ADMIN,
3630
+ role: SpaceMember.Role.ADMIN,
3782
3631
  profile: signingContext.getProfile(),
3783
3632
  genesisFeedKey: space.controlFeedKey ?? failUndefined()
3784
3633
  }
@@ -3836,7 +3685,7 @@ function _ts_decorate5(decorators, target, key, desc) {
3836
3685
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3837
3686
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3838
3687
  }
3839
- var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
3688
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
3840
3689
  var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
3841
3690
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
3842
3691
  var DataSpaceManager = class {
@@ -3862,7 +3711,7 @@ var DataSpaceManager = class {
3862
3711
  }
3863
3712
  async open() {
3864
3713
  log10("open", void 0, {
3865
- F: __dxlog_file13,
3714
+ F: __dxlog_file12,
3866
3715
  L: 98,
3867
3716
  S: this,
3868
3717
  C: (f, a) => f(...a)
@@ -3870,7 +3719,7 @@ var DataSpaceManager = class {
3870
3719
  log10.trace("dxos.echo.data-space-manager.open", trace7.begin({
3871
3720
  id: this._instanceId
3872
3721
  }), {
3873
- F: __dxlog_file13,
3722
+ F: __dxlog_file12,
3874
3723
  L: 99,
3875
3724
  S: this,
3876
3725
  C: (f, a) => f(...a)
@@ -3878,7 +3727,7 @@ var DataSpaceManager = class {
3878
3727
  log10("metadata loaded", {
3879
3728
  spaces: this._metadataStore.spaces.length
3880
3729
  }, {
3881
- F: __dxlog_file13,
3730
+ F: __dxlog_file12,
3882
3731
  L: 100,
3883
3732
  S: this,
3884
3733
  C: (f, a) => f(...a)
@@ -3888,7 +3737,7 @@ var DataSpaceManager = class {
3888
3737
  log10("load space", {
3889
3738
  spaceMetadata
3890
3739
  }, {
3891
- F: __dxlog_file13,
3740
+ F: __dxlog_file12,
3892
3741
  L: 104,
3893
3742
  S: this,
3894
3743
  C: (f, a) => f(...a)
@@ -3899,7 +3748,7 @@ var DataSpaceManager = class {
3899
3748
  spaceMetadata,
3900
3749
  err
3901
3750
  }, {
3902
- F: __dxlog_file13,
3751
+ F: __dxlog_file12,
3903
3752
  L: 107,
3904
3753
  S: this,
3905
3754
  C: (f, a) => f(...a)
@@ -3916,7 +3765,7 @@ var DataSpaceManager = class {
3916
3765
  log10.trace("dxos.echo.data-space-manager.open", trace7.end({
3917
3766
  id: this._instanceId
3918
3767
  }), {
3919
- F: __dxlog_file13,
3768
+ F: __dxlog_file12,
3920
3769
  L: 120,
3921
3770
  S: this,
3922
3771
  C: (f, a) => f(...a)
@@ -3924,7 +3773,7 @@ var DataSpaceManager = class {
3924
3773
  }
3925
3774
  async close() {
3926
3775
  log10("close", void 0, {
3927
- F: __dxlog_file13,
3776
+ F: __dxlog_file12,
3928
3777
  L: 125,
3929
3778
  S: this,
3930
3779
  C: (f, a) => f(...a)
@@ -3939,8 +3788,8 @@ var DataSpaceManager = class {
3939
3788
  * Creates a new space writing the genesis credentials to the control feed.
3940
3789
  */
3941
3790
  async createSpace() {
3942
- invariant12(this._isOpen, "Not open.", {
3943
- F: __dxlog_file13,
3791
+ invariant11(this._isOpen, "Not open.", {
3792
+ F: __dxlog_file12,
3944
3793
  L: 138,
3945
3794
  S: this,
3946
3795
  A: [
@@ -3961,7 +3810,7 @@ var DataSpaceManager = class {
3961
3810
  log10("creating space...", {
3962
3811
  spaceKey
3963
3812
  }, {
3964
- F: __dxlog_file13,
3813
+ F: __dxlog_file12,
3965
3814
  L: 150,
3966
3815
  S: this,
3967
3816
  C: (f, a) => f(...a)
@@ -3976,8 +3825,8 @@ var DataSpaceManager = class {
3976
3825
  const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRoot.url);
3977
3826
  await this._metadataStore.addSpace(metadata);
3978
3827
  const memberCredential = credentials[1];
3979
- invariant12(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3980
- F: __dxlog_file13,
3828
+ invariant11(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3829
+ F: __dxlog_file12,
3981
3830
  L: 163,
3982
3831
  S: this,
3983
3832
  A: [
@@ -3995,13 +3844,13 @@ var DataSpaceManager = class {
3995
3844
  log10("accept space", {
3996
3845
  opts
3997
3846
  }, {
3998
- F: __dxlog_file13,
3847
+ F: __dxlog_file12,
3999
3848
  L: 175,
4000
3849
  S: this,
4001
3850
  C: (f, a) => f(...a)
4002
3851
  });
4003
- invariant12(this._isOpen, "Not open.", {
4004
- F: __dxlog_file13,
3852
+ invariant11(this._isOpen, "Not open.", {
3853
+ F: __dxlog_file12,
4005
3854
  L: 176,
4006
3855
  S: this,
4007
3856
  A: [
@@ -4009,8 +3858,8 @@ var DataSpaceManager = class {
4009
3858
  "'Not open.'"
4010
3859
  ]
4011
3860
  });
4012
- invariant12(!this._spaces.has(opts.spaceKey), "Space already exists.", {
4013
- F: __dxlog_file13,
3861
+ invariant11(!this._spaces.has(opts.spaceKey), "Space already exists.", {
3862
+ F: __dxlog_file12,
4014
3863
  L: 177,
4015
3864
  S: this,
4016
3865
  A: [
@@ -4045,7 +3894,7 @@ var DataSpaceManager = class {
4045
3894
  log10("construct space", {
4046
3895
  metadata
4047
3896
  }, {
4048
- F: __dxlog_file13,
3897
+ F: __dxlog_file12,
4049
3898
  L: 210,
4050
3899
  S: this,
4051
3900
  C: (f, a) => f(...a)
@@ -4083,7 +3932,7 @@ var DataSpaceManager = class {
4083
3932
  },
4084
3933
  onAuthFailure: () => {
4085
3934
  log10.warn("auth failure", void 0, {
4086
- F: __dxlog_file13,
3935
+ F: __dxlog_file12,
4087
3936
  L: 247,
4088
3937
  S: this,
4089
3938
  C: (f, a) => f(...a)
@@ -4107,7 +3956,7 @@ var DataSpaceManager = class {
4107
3956
  log10("before space ready", {
4108
3957
  space: space.key
4109
3958
  }, {
4110
- F: __dxlog_file13,
3959
+ F: __dxlog_file12,
4111
3960
  L: 265,
4112
3961
  S: this,
4113
3962
  C: (f, a) => f(...a)
@@ -4118,7 +3967,7 @@ var DataSpaceManager = class {
4118
3967
  space: space.key,
4119
3968
  open: this._isOpen
4120
3969
  }, {
4121
- F: __dxlog_file13,
3970
+ F: __dxlog_file12,
4122
3971
  L: 268,
4123
3972
  S: this,
4124
3973
  C: (f, a) => f(...a)
@@ -4131,7 +3980,7 @@ var DataSpaceManager = class {
4131
3980
  log10("before space close", {
4132
3981
  space: space.key
4133
3982
  }, {
4134
- F: __dxlog_file13,
3983
+ F: __dxlog_file12,
4135
3984
  L: 274,
4136
3985
  S: this,
4137
3986
  C: (f, a) => f(...a)
@@ -4171,11 +4020,11 @@ DataSpaceManager = _ts_decorate5([
4171
4020
  import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTask as scheduleTask6 } from "@dxos/async";
4172
4021
  import { Stream as Stream10 } from "@dxos/codec-protobuf";
4173
4022
  import { raise as raise2 } from "@dxos/debug";
4174
- import { invariant as invariant13 } from "@dxos/invariant";
4023
+ import { invariant as invariant12 } from "@dxos/invariant";
4175
4024
  import { log as log11 } from "@dxos/log";
4176
4025
  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";
4026
+ import { SpaceMember as SpaceMember2, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
4027
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
4179
4028
  var SpacesServiceImpl = class {
4180
4029
  constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
4181
4030
  this._identityManager = _identityManager;
@@ -4214,7 +4063,7 @@ var SpacesServiceImpl = class {
4214
4063
  log11("update", {
4215
4064
  spaces
4216
4065
  }, {
4217
- F: __dxlog_file14,
4066
+ F: __dxlog_file13,
4218
4067
  L: 77,
4219
4068
  S: this,
4220
4069
  C: (f, a) => f(...a)
@@ -4296,8 +4145,8 @@ var SpacesServiceImpl = class {
4296
4145
  }
4297
4146
  });
4298
4147
  } else {
4299
- invariant13(!credential.id, "Id on unsigned credentials is not allowed", {
4300
- F: __dxlog_file14,
4148
+ invariant12(!credential.id, "Id on unsigned credentials is not allowed", {
4149
+ F: __dxlog_file13,
4301
4150
  L: 164,
4302
4151
  S: this,
4303
4152
  A: [
@@ -4305,8 +4154,8 @@ var SpacesServiceImpl = class {
4305
4154
  "'Id on unsigned credentials is not allowed'"
4306
4155
  ]
4307
4156
  });
4308
- invariant13(this._identityManager.identity, "Identity is not available", {
4309
- F: __dxlog_file14,
4157
+ invariant12(this._identityManager.identity, "Identity is not available", {
4158
+ F: __dxlog_file13,
4310
4159
  L: 165,
4311
4160
  S: this,
4312
4161
  A: [
@@ -4315,8 +4164,8 @@ var SpacesServiceImpl = class {
4315
4164
  ]
4316
4165
  });
4317
4166
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
4318
- invariant13(credential.issuer.equals(signer.getIssuer()), void 0, {
4319
- F: __dxlog_file14,
4167
+ invariant12(credential.issuer.equals(signer.getIssuer()), void 0, {
4168
+ F: __dxlog_file13,
4320
4169
  L: 167,
4321
4170
  S: this,
4322
4171
  A: [
@@ -4372,7 +4221,7 @@ var SpacesServiceImpl = class {
4372
4221
  identityKey: member.key,
4373
4222
  profile: member.profile ?? {}
4374
4223
  },
4375
- presence: member.removed ? SpaceMember3.PresenceState.REMOVED : isMe || peers.length > 0 ? SpaceMember3.PresenceState.ONLINE : SpaceMember3.PresenceState.OFFLINE,
4224
+ presence: member.removed ? SpaceMember2.PresenceState.REMOVED : isMe || peers.length > 0 ? SpaceMember2.PresenceState.ONLINE : SpaceMember2.PresenceState.OFFLINE,
4376
4225
  peerStates: peers
4377
4226
  };
4378
4227
  }),
@@ -4392,11 +4241,11 @@ import { failUndefined as failUndefined2 } from "@dxos/debug";
4392
4241
  import { AutomergeHost, MetadataStore, SnapshotStore, SpaceManager, valueEncoding } from "@dxos/echo-pipeline";
4393
4242
  import { FeedFactory, FeedStore } from "@dxos/feed-store";
4394
4243
  import { IndexMetadataStore, IndexStore, Indexer } from "@dxos/indexing";
4395
- import { invariant as invariant14 } from "@dxos/invariant";
4244
+ import { invariant as invariant13 } from "@dxos/invariant";
4396
4245
  import { Keyring } from "@dxos/keyring";
4397
4246
  import { PublicKey as PublicKey10 } from "@dxos/keys";
4398
4247
  import { log as log12 } from "@dxos/log";
4399
- import { InvalidStorageVersionError, STORAGE_VERSION as STORAGE_VERSION2, trace as trace8 } from "@dxos/protocols";
4248
+ import { InvalidStorageVersionError, STORAGE_VERSION, trace as trace8 } from "@dxos/protocols";
4400
4249
  import { Invitation as Invitation6 } from "@dxos/protocols/proto/dxos/client/services";
4401
4250
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
4402
4251
  import { trace as Trace2 } from "@dxos/tracing";
@@ -4492,7 +4341,7 @@ function _ts_decorate6(decorators, target, key, desc) {
4492
4341
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4493
4342
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4494
4343
  }
4495
- var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
4344
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
4496
4345
  var ServiceContext = class extends Resource {
4497
4346
  constructor(storage, level, networkManager, signalManager, _runtimeParams) {
4498
4347
  super();
@@ -4531,6 +4380,7 @@ var ServiceContext = class extends Resource {
4531
4380
  });
4532
4381
  this.automergeHost = new AutomergeHost({
4533
4382
  directory: storage.createDirectory("automerge"),
4383
+ db: level.sublevel("automerge"),
4534
4384
  metadata: this.indexMetadata
4535
4385
  });
4536
4386
  this.indexer = new Indexer({
@@ -4547,21 +4397,22 @@ var ServiceContext = class extends Resource {
4547
4397
  async _open(ctx) {
4548
4398
  await this._checkStorageVersion();
4549
4399
  log12("opening...", void 0, {
4550
- F: __dxlog_file15,
4551
- L: 156,
4400
+ F: __dxlog_file14,
4401
+ L: 157,
4552
4402
  S: this,
4553
4403
  C: (f, a) => f(...a)
4554
4404
  });
4555
4405
  log12.trace("dxos.sdk.service-context.open", trace8.begin({
4556
4406
  id: this._instanceId
4557
4407
  }), {
4558
- F: __dxlog_file15,
4559
- L: 157,
4408
+ F: __dxlog_file14,
4409
+ L: 158,
4560
4410
  S: this,
4561
4411
  C: (f, a) => f(...a)
4562
4412
  });
4563
4413
  await this.signalManager.open();
4564
4414
  await this.networkManager.open();
4415
+ await this.automergeHost.open();
4565
4416
  await this.metadataStore.load();
4566
4417
  await this.spaceManager.open();
4567
4418
  await this.identityManager.open(ctx);
@@ -4571,22 +4422,22 @@ var ServiceContext = class extends Resource {
4571
4422
  log12.trace("dxos.sdk.service-context.open", trace8.end({
4572
4423
  id: this._instanceId
4573
4424
  }), {
4574
- F: __dxlog_file15,
4575
- L: 167,
4425
+ F: __dxlog_file14,
4426
+ L: 169,
4576
4427
  S: this,
4577
4428
  C: (f, a) => f(...a)
4578
4429
  });
4579
4430
  log12("opened", void 0, {
4580
- F: __dxlog_file15,
4581
- L: 168,
4431
+ F: __dxlog_file14,
4432
+ L: 170,
4582
4433
  S: this,
4583
4434
  C: (f, a) => f(...a)
4584
4435
  });
4585
4436
  }
4586
4437
  async _close() {
4587
4438
  log12("closing...", void 0, {
4588
- F: __dxlog_file15,
4589
- L: 172,
4439
+ F: __dxlog_file14,
4440
+ L: 174,
4590
4441
  S: this,
4591
4442
  C: (f, a) => f(...a)
4592
4443
  });
@@ -4603,8 +4454,8 @@ var ServiceContext = class extends Resource {
4603
4454
  await this.metadataStore.close();
4604
4455
  await this.indexer.destroy();
4605
4456
  log12("closed", void 0, {
4606
- F: __dxlog_file15,
4607
- L: 185,
4457
+ F: __dxlog_file14,
4458
+ L: 187,
4608
4459
  S: this,
4609
4460
  C: (f, a) => f(...a)
4610
4461
  });
@@ -4616,9 +4467,9 @@ var ServiceContext = class extends Resource {
4616
4467
  }
4617
4468
  getInvitationHandler(invitation) {
4618
4469
  const factory = this._handlerFactories.get(invitation.kind);
4619
- invariant14(factory, `Unknown invitation kind: ${invitation.kind}`, {
4620
- F: __dxlog_file15,
4621
- L: 196,
4470
+ invariant13(factory, `Unknown invitation kind: ${invitation.kind}`, {
4471
+ F: __dxlog_file14,
4472
+ L: 198,
4622
4473
  S: this,
4623
4474
  A: [
4624
4475
  "factory",
@@ -4642,15 +4493,15 @@ var ServiceContext = class extends Resource {
4642
4493
  }
4643
4494
  async _checkStorageVersion() {
4644
4495
  await this.metadataStore.load();
4645
- if (this.metadataStore.version !== STORAGE_VERSION2) {
4646
- throw new InvalidStorageVersionError(STORAGE_VERSION2, this.metadataStore.version);
4496
+ if (this.metadataStore.version !== STORAGE_VERSION) {
4497
+ throw new InvalidStorageVersionError(STORAGE_VERSION, this.metadataStore.version);
4647
4498
  }
4648
4499
  }
4649
4500
  // Called when identity is created.
4650
4501
  async _initialize(ctx) {
4651
4502
  log12("initializing spaces...", void 0, {
4652
- F: __dxlog_file15,
4653
- L: 227,
4503
+ F: __dxlog_file14,
4504
+ L: 229,
4654
4505
  S: this,
4655
4506
  C: (f, a) => f(...a)
4656
4507
  });
@@ -4671,9 +4522,9 @@ var ServiceContext = class extends Resource {
4671
4522
  this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.automergeHost, this._runtimeParams);
4672
4523
  await this.dataSpaceManager.open();
4673
4524
  this._handlerFactories.set(Invitation6.Kind.SPACE, (invitation) => {
4674
- invariant14(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4675
- F: __dxlog_file15,
4676
- L: 251,
4525
+ invariant13(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4526
+ F: __dxlog_file14,
4527
+ L: 253,
4677
4528
  S: this,
4678
4529
  A: [
4679
4530
  "this.dataSpaceManager",
@@ -4696,8 +4547,8 @@ var ServiceContext = class extends Resource {
4696
4547
  log12("dataSpaceManager not initialized yet, ignoring space admission", {
4697
4548
  details: assertion
4698
4549
  }, {
4699
- F: __dxlog_file15,
4700
- L: 267,
4550
+ F: __dxlog_file14,
4551
+ L: 269,
4701
4552
  S: this,
4702
4553
  C: (f, a) => f(...a)
4703
4554
  });
@@ -4707,8 +4558,8 @@ var ServiceContext = class extends Resource {
4707
4558
  log12("space already exists, ignoring space admission", {
4708
4559
  details: assertion
4709
4560
  }, {
4710
- F: __dxlog_file15,
4711
- L: 271,
4561
+ F: __dxlog_file14,
4562
+ L: 273,
4712
4563
  S: this,
4713
4564
  C: (f, a) => f(...a)
4714
4565
  });
@@ -4718,8 +4569,8 @@ var ServiceContext = class extends Resource {
4718
4569
  log12("accepting space recorded in halo", {
4719
4570
  details: assertion
4720
4571
  }, {
4721
- F: __dxlog_file15,
4722
- L: 276,
4572
+ F: __dxlog_file14,
4573
+ L: 278,
4723
4574
  S: this,
4724
4575
  C: (f, a) => f(...a)
4725
4576
  });
@@ -4729,8 +4580,8 @@ var ServiceContext = class extends Resource {
4729
4580
  });
4730
4581
  } catch (err) {
4731
4582
  log12.catch(err, void 0, {
4732
- F: __dxlog_file15,
4733
- L: 282,
4583
+ F: __dxlog_file14,
4584
+ L: 284,
4734
4585
  S: this,
4735
4586
  C: (f, a) => f(...a)
4736
4587
  });
@@ -4775,203 +4626,254 @@ var ServiceRegistry = class {
4775
4626
  }
4776
4627
  };
4777
4628
 
4778
- // packages/sdk/client-services/src/packlets/locks/browser.ts
4779
- import { asyncTimeout as asyncTimeout2, Trigger as Trigger6 } from "@dxos/async";
4780
- import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
4781
- import { log as log13, logInfo } from "@dxos/log";
4782
- function _ts_decorate7(decorators, target, key, desc) {
4783
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4784
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
4785
- r = Reflect.decorate(decorators, target, key, desc);
4786
- else
4787
- for (var i = decorators.length - 1; i >= 0; i--)
4788
- if (d = decorators[i])
4789
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4790
- return c > 3 && r && Object.defineProperty(target, key, r), r;
4791
- }
4792
- var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
4793
- var Message;
4794
- (function(Message2) {
4795
- Message2["ACQUIRING"] = "acquiring";
4796
- })(Message || (Message = {}));
4797
- var Lock = class {
4798
- constructor({ lockKey, onAcquire, onRelease }) {
4799
- this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
4800
- this._releaseTrigger = new Trigger6();
4801
- this._lockKey = lockKey;
4802
- this._onAcquire = onAcquire;
4803
- this._onRelease = onRelease;
4804
- this._broadcastChannel.onmessage = this._onMessage.bind(this);
4805
- }
4806
- get lockKey() {
4807
- return this._lockKey;
4808
- }
4809
- async acquire() {
4810
- this._broadcastChannel.postMessage({
4811
- message: "acquiring"
4812
- });
4813
- try {
4814
- log13("aquiring lock...", void 0, {
4815
- F: __dxlog_file16,
4816
- L: 42,
4817
- S: this,
4818
- C: (f, a) => f(...a)
4819
- });
4820
- await asyncTimeout2(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
4821
- log13("acquired lock", void 0, {
4822
- F: __dxlog_file16,
4823
- L: 44,
4824
- S: this,
4825
- C: (f, a) => f(...a)
4826
- });
4827
- } catch {
4828
- log13("stealing lock...", void 0, {
4829
- F: __dxlog_file16,
4830
- L: 46,
4831
- S: this,
4832
- C: (f, a) => f(...a)
4833
- });
4834
- await this._requestLock(true);
4835
- log13("stolen lock", void 0, {
4836
- F: __dxlog_file16,
4837
- L: 48,
4838
- S: this,
4839
- C: (f, a) => f(...a)
4840
- });
4629
+ // packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts
4630
+ import { getFirstStreamValue } from "@dxos/codec-protobuf";
4631
+ import { credentialTypeFilter } from "@dxos/credentials";
4632
+ import { invariant as invariant14 } from "@dxos/invariant";
4633
+ import { STORAGE_VERSION as STORAGE_VERSION2 } from "@dxos/protocols";
4634
+ import { SpaceMember as SpaceMember3 } from "@dxos/protocols/proto/dxos/client/services";
4635
+ import { TRACE_PROCESSOR } from "@dxos/tracing";
4636
+
4637
+ // packages/sdk/client-services/src/version.ts
4638
+ var DXOS_VERSION = "0.4.10-main.e9f9c10";
4639
+
4640
+ // packages/sdk/client-services/src/packlets/services/platform.ts
4641
+ import { Platform } from "@dxos/protocols/proto/dxos/client/services";
4642
+ var getPlatform = () => {
4643
+ if (process.browser) {
4644
+ if (typeof window !== "undefined") {
4645
+ const { userAgent } = window.navigator;
4646
+ return {
4647
+ type: Platform.PLATFORM_TYPE.BROWSER,
4648
+ userAgent,
4649
+ uptime: Math.floor((Date.now() - window.performance.timeOrigin) / 1e3)
4650
+ };
4651
+ } else {
4652
+ return {
4653
+ type: Platform.PLATFORM_TYPE.SHARED_WORKER,
4654
+ uptime: Math.floor((Date.now() - performance.timeOrigin) / 1e3)
4655
+ };
4841
4656
  }
4657
+ } else {
4658
+ const { platform: platform2, version, arch } = process;
4659
+ return {
4660
+ type: Platform.PLATFORM_TYPE.NODE,
4661
+ platform: platform2,
4662
+ arch,
4663
+ runtime: version,
4664
+ uptime: Math.floor(process.uptime()),
4665
+ memory: process.memoryUsage()
4666
+ };
4842
4667
  }
4843
- async release() {
4844
- this._releaseTrigger.wake();
4668
+ };
4669
+
4670
+ // packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts
4671
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts";
4672
+ var DEFAULT_TIMEOUT = 1e3;
4673
+ var createDiagnostics = async (clientServices, serviceContext, config) => {
4674
+ const diagnostics = {
4675
+ created: (/* @__PURE__ */ new Date()).toISOString(),
4676
+ platform: getPlatform(),
4677
+ client: {
4678
+ version: DXOS_VERSION,
4679
+ storage: {
4680
+ version: STORAGE_VERSION2
4681
+ }
4682
+ },
4683
+ trace: TRACE_PROCESSOR.getDiagnostics()
4684
+ };
4685
+ {
4686
+ invariant14(clientServices.LoggingService, "SystemService is not available.", {
4687
+ F: __dxlog_file15,
4688
+ L: 108,
4689
+ S: void 0,
4690
+ A: [
4691
+ "clientServices.LoggingService",
4692
+ "'SystemService is not available.'"
4693
+ ]
4694
+ });
4695
+ diagnostics.metrics = await getFirstStreamValue(clientServices.LoggingService.queryMetrics({}), {
4696
+ timeout: DEFAULT_TIMEOUT
4697
+ }).catch(() => void 0);
4845
4698
  }
4846
- _onMessage(event) {
4847
- if (event.data.message === "acquiring") {
4848
- this._releaseTrigger.wake();
4699
+ if (typeof navigator !== "undefined" && navigator.storage) {
4700
+ const map = /* @__PURE__ */ new Map();
4701
+ const dir = await navigator.storage.getDirectory();
4702
+ for await (const filename of dir?.keys()) {
4703
+ const idx = filename.indexOf("-", filename.indexOf("-") + 1);
4704
+ if (idx === -1) {
4705
+ continue;
4706
+ }
4707
+ map.set(filename.slice(0, idx), (map.get(filename.slice(0, idx)) ?? 0) + 1);
4849
4708
  }
4709
+ diagnostics.storage = Array.from(map.entries()).sort((a, b) => b[1] - a[1]).map(([file, count]) => ({
4710
+ file,
4711
+ count
4712
+ }));
4850
4713
  }
4851
- async _requestLock(steal = false) {
4852
- log13("requesting lock...", {
4853
- steal
4854
- }, {
4855
- F: __dxlog_file16,
4856
- L: 63,
4857
- S: this,
4858
- C: (f, a) => f(...a)
4859
- });
4860
- const acquired = new Trigger6();
4861
- void navigator.locks.request(this._lockKey, {
4862
- steal
4863
- }, async () => {
4864
- await this._onAcquire?.();
4865
- acquired.wake();
4866
- this._releaseTrigger = new Trigger6();
4867
- await this._releaseTrigger.wait();
4868
- log13("releasing lock...", void 0, {
4869
- F: __dxlog_file16,
4870
- L: 72,
4871
- S: this,
4872
- C: (f, a) => f(...a)
4873
- });
4874
- await this._onRelease?.();
4875
- log13("released lock", void 0, {
4876
- F: __dxlog_file16,
4877
- L: 74,
4878
- S: this,
4879
- C: (f, a) => f(...a)
4880
- });
4881
- }).catch(async () => {
4882
- await this._onRelease?.();
4883
- });
4884
- await acquired.wait();
4885
- log13("recieved lock", {
4886
- steal
4887
- }, {
4888
- F: __dxlog_file16,
4889
- L: 81,
4890
- S: this,
4891
- C: (f, a) => f(...a)
4892
- });
4714
+ const identity = serviceContext.identityManager.identity;
4715
+ if (identity) {
4716
+ diagnostics.identity = {
4717
+ identityKey: identity.identityKey,
4718
+ spaceKey: identity.space.key,
4719
+ profile: identity.profileDocument
4720
+ };
4721
+ const { devices } = await getFirstStreamValue(clientServices.DevicesService.queryDevices(), {
4722
+ timeout: DEFAULT_TIMEOUT
4723
+ }).catch(() => void 0) ?? {};
4724
+ diagnostics.devices = devices;
4725
+ if (serviceContext.dataSpaceManager) {
4726
+ diagnostics.spaces = await Promise.all(Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space)) ?? []);
4727
+ }
4728
+ const { feeds = [] } = await getFirstStreamValue(clientServices.DevtoolsHost.subscribeToFeeds({}), {
4729
+ timeout: DEFAULT_TIMEOUT
4730
+ }).catch(() => void 0) ?? {};
4731
+ diagnostics.feeds = feeds.map(({ feedKey, bytes, length }) => ({
4732
+ feedKey,
4733
+ bytes,
4734
+ length
4735
+ }));
4736
+ const status = await getFirstStreamValue(clientServices.NetworkService.queryStatus(), {
4737
+ timeout: DEFAULT_TIMEOUT
4738
+ }).catch(() => void 0);
4739
+ diagnostics.networkStatus = status;
4740
+ diagnostics.swarms = serviceContext.networkManager.connectionLog?.swarms;
4893
4741
  }
4742
+ diagnostics.config = config.values;
4743
+ return diagnostics;
4894
4744
  };
4895
- _ts_decorate7([
4896
- logInfo
4897
- ], Lock.prototype, "lockKey", null);
4898
- var isLocked = (lockPath) => {
4899
- throw new Error("Not implemented");
4900
- };
4901
-
4902
- // packages/sdk/client-services/src/packlets/storage/storage.ts
4903
- import { InvalidConfigError } from "@dxos/protocols";
4904
- import { Runtime as Runtime2 } from "@dxos/protocols/proto/dxos/config";
4905
- import { createStorage, StorageType } from "@dxos/random-access-storage";
4906
-
4907
- // packages/sdk/client-services/src/packlets/storage/util.ts
4908
- import { DX_DATA } from "@dxos/client-protocol";
4909
- import { Runtime } from "@dxos/protocols/proto/dxos/config";
4910
- import { isNode as isNode2 } from "@dxos/util";
4911
- var getRootPath = (config) => {
4912
- const { dataRoot = isNode2() ? DX_DATA : "dxos/storage" } = config ?? {};
4913
- return `${dataRoot}/`;
4914
- };
4915
- var isPersistent = (config) => {
4916
- const { persistent = false } = config ?? {};
4917
- return config.dataStore !== void 0 && config.dataStore !== Runtime.Client.Storage.StorageDriver.RAM || persistent;
4745
+ var getSpaceStats = async (space) => {
4746
+ const stats = {
4747
+ key: space.key,
4748
+ metrics: space.metrics,
4749
+ epochs: space.inner.spaceState.credentials.filter(credentialTypeFilter("dxos.halo.credentials.Epoch")).map((credential) => ({
4750
+ ...credential.subject.assertion,
4751
+ id: credential.id
4752
+ })),
4753
+ members: Array.from(space.inner.spaceState.members.values()).map((member) => ({
4754
+ identity: {
4755
+ identityKey: member.key,
4756
+ profile: {
4757
+ displayName: member.assertion.profile?.displayName
4758
+ }
4759
+ },
4760
+ presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember3.PresenceState.ONLINE : SpaceMember3.PresenceState.OFFLINE
4761
+ })),
4762
+ pipeline: {
4763
+ // TODO(burdon): Pick properties from credentials if needed.
4764
+ currentEpoch: space.automergeSpaceState.lastEpoch,
4765
+ appliedEpoch: space.automergeSpaceState.lastEpoch,
4766
+ controlFeeds: space.inner.controlPipeline.state.feeds.map((feed) => feed.key),
4767
+ currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
4768
+ targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
4769
+ totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe
4770
+ }
4771
+ };
4772
+ if (stats.metrics) {
4773
+ const { open, ready } = stats.metrics;
4774
+ stats.metrics.startupTime = open && ready && ready.getTime() - open.getTime();
4775
+ }
4776
+ return stats;
4918
4777
  };
4919
4778
 
4920
- // packages/sdk/client-services/src/packlets/storage/storage.ts
4921
- var StorageDriver = Runtime2.Client.Storage.StorageDriver;
4922
- var createStorageObjects = (config) => {
4923
- const { persistent = false, keyStore, dataStore } = config ?? {};
4924
- if (persistent && dataStore === StorageDriver.RAM) {
4925
- throw new InvalidConfigError("RAM storage cannot be used in persistent mode.");
4926
- }
4927
- if (!persistent && dataStore !== void 0 && dataStore !== StorageDriver.RAM) {
4928
- throw new InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
4929
- }
4930
- if (persistent && keyStore === StorageDriver.RAM) {
4931
- throw new InvalidConfigError("RAM key storage cannot be used in persistent mode.");
4932
- }
4933
- if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== void 0) {
4934
- throw new InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
4935
- }
4779
+ // packages/sdk/client-services/src/packlets/diagnostics/browser-diagnostics-broadcast.ts
4780
+ import { Trigger as Trigger6 } from "@dxos/async";
4781
+ import { log as log13 } from "@dxos/log";
4782
+ var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/browser-diagnostics-broadcast.ts";
4783
+ var CHANNEL_NAME = "dxos.diagnostics.broadcast";
4784
+ var MessageType;
4785
+ (function(MessageType2) {
4786
+ MessageType2["PROBE"] = "probe";
4787
+ MessageType2["PROBE_ACK"] = "probe-ack";
4788
+ MessageType2["REQUEST_DIAGNOSTICS"] = "request-diagnostics";
4789
+ MessageType2["RECEIVE_DIAGNOSTICS"] = "receive-diagnostics";
4790
+ })(MessageType || (MessageType = {}));
4791
+ var createCollectDiagnosticsBroadcastSender = () => {
4936
4792
  return {
4937
- storage: createStorage({
4938
- type: persistent ? toStorageType(dataStore) : StorageType.RAM,
4939
- root: getRootPath(config)
4940
- })
4941
- };
4942
- };
4943
- var toStorageType = (type) => {
4944
- switch (type) {
4945
- case void 0:
4946
- return void 0;
4947
- case StorageDriver.RAM:
4948
- return StorageType.RAM;
4949
- case StorageDriver.CHROME:
4950
- return StorageType.CHROME;
4951
- case StorageDriver.FIREFOX:
4952
- return StorageType.FIREFOX;
4953
- case StorageDriver.IDB:
4954
- return StorageType.IDB;
4955
- case StorageDriver.NODE:
4956
- return StorageType.NODE;
4957
- case StorageDriver.WEBFS:
4958
- return StorageType.WEBFS;
4959
- default:
4960
- throw new Error(`Invalid storage type: ${StorageDriver[type]}`);
4793
+ broadcastDiagnosticsRequest: async () => {
4794
+ let expectedResponse = "probe-ack";
4795
+ let channel;
4796
+ try {
4797
+ const trigger = new Trigger6();
4798
+ channel = new BroadcastChannel(CHANNEL_NAME);
4799
+ channel.onmessage = (msg) => {
4800
+ if (expectedResponse === msg.data.type) {
4801
+ trigger.wake(msg.data);
4802
+ }
4803
+ };
4804
+ channel.postMessage({
4805
+ type: "probe"
4806
+ });
4807
+ await trigger.wait({
4808
+ timeout: 200
4809
+ });
4810
+ expectedResponse = "receive-diagnostics";
4811
+ trigger.reset();
4812
+ channel.postMessage({
4813
+ type: "request-diagnostics"
4814
+ });
4815
+ const diagnostics = await trigger.wait({
4816
+ timeout: 5e3
4817
+ });
4818
+ return diagnostics.payload;
4819
+ } catch (e) {
4820
+ const errorDescription = e instanceof Error ? e.message : JSON.stringify(e);
4821
+ return {
4822
+ expectedResponse,
4823
+ errorDescription
4824
+ };
4825
+ } finally {
4826
+ safeClose(channel);
4827
+ }
4828
+ }
4829
+ };
4830
+ };
4831
+ var createCollectDiagnosticsBroadcastHandler = (systemService) => {
4832
+ let channel;
4833
+ return {
4834
+ start: () => {
4835
+ channel = new BroadcastChannel(CHANNEL_NAME);
4836
+ channel.onmessage = async (message) => {
4837
+ try {
4838
+ if (message.data.type === "probe") {
4839
+ channel?.postMessage({
4840
+ type: "probe-ack"
4841
+ });
4842
+ } else if (message.data.type === "request-diagnostics") {
4843
+ const diagnostics = await systemService.getDiagnostics({});
4844
+ channel?.postMessage({
4845
+ type: "receive-diagnostics",
4846
+ payload: diagnostics
4847
+ });
4848
+ }
4849
+ } catch (error) {
4850
+ log13.catch(error, void 0, {
4851
+ F: __dxlog_file16,
4852
+ L: 77,
4853
+ S: void 0,
4854
+ C: (f, a) => f(...a)
4855
+ });
4856
+ }
4857
+ };
4858
+ },
4859
+ stop: () => {
4860
+ safeClose(channel);
4861
+ channel = void 0;
4862
+ }
4863
+ };
4864
+ };
4865
+ var safeClose = (channel) => {
4866
+ try {
4867
+ channel?.close();
4868
+ } catch (e) {
4961
4869
  }
4962
4870
  };
4963
4871
 
4964
- // packages/sdk/client-services/src/packlets/storage/level.ts
4965
- import { Level } from "level";
4966
- import path from "@dxos/node-std/path";
4967
- import { PublicKey as PublicKey11 } from "@dxos/keys";
4968
- var createLevel = async (config) => {
4969
- const persistent = isPersistent(config);
4970
- const storagePath = persistent ? getRootPath(config) : path.join("tmp", "level", PublicKey11.random().toHex());
4971
- const level = new Level(storagePath);
4972
- await level.open();
4973
- return level;
4974
- };
4872
+ // packages/sdk/client-services/src/packlets/diagnostics/diagnostics-collector.ts
4873
+ import { ConfigResource } from "@dxos/config";
4874
+ import { GetDiagnosticsRequest as GetDiagnosticsRequest2 } from "@dxos/protocols/proto/dxos/client/services";
4875
+ import { TRACE_PROCESSOR as TRACE_PROCESSOR3 } from "@dxos/tracing";
4876
+ import { jsonKeyReplacer as jsonKeyReplacer2, nonNullable } from "@dxos/util";
4975
4877
 
4976
4878
  // packages/sdk/client-services/src/packlets/services/service-host.ts
4977
4879
  import { Event as Event9, synchronized as synchronized3 } from "@dxos/async";
@@ -4982,7 +4884,7 @@ import * as E from "@dxos/echo-schema";
4982
4884
  import { IndexServiceImpl } from "@dxos/indexing";
4983
4885
  import { invariant as invariant16 } from "@dxos/invariant";
4984
4886
  import { PublicKey as PublicKey13 } from "@dxos/keys";
4985
- import { log as log15 } from "@dxos/log";
4887
+ import { log as log16 } from "@dxos/log";
4986
4888
  import { WebsocketSignalManager } from "@dxos/messaging";
4987
4889
  import { NetworkManager, createSimplePeerTransportFactory } from "@dxos/network-manager";
4988
4890
  import { trace as trace9 } from "@dxos/protocols";
@@ -5073,28 +4975,152 @@ var DevicesServiceImpl = class {
5073
4975
  }
5074
4976
  };
5075
4977
 
4978
+ // packages/sdk/client-services/src/packlets/locks/browser.ts
4979
+ import { asyncTimeout as asyncTimeout2, Trigger as Trigger7 } from "@dxos/async";
4980
+ import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
4981
+ import { log as log14, logInfo } from "@dxos/log";
4982
+ function _ts_decorate7(decorators, target, key, desc) {
4983
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4984
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
4985
+ r = Reflect.decorate(decorators, target, key, desc);
4986
+ else
4987
+ for (var i = decorators.length - 1; i >= 0; i--)
4988
+ if (d = decorators[i])
4989
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4990
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
4991
+ }
4992
+ var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
4993
+ var Message;
4994
+ (function(Message2) {
4995
+ Message2["ACQUIRING"] = "acquiring";
4996
+ })(Message || (Message = {}));
4997
+ var Lock = class {
4998
+ constructor({ lockKey, onAcquire, onRelease }) {
4999
+ this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
5000
+ this._releaseTrigger = new Trigger7();
5001
+ this._lockKey = lockKey;
5002
+ this._onAcquire = onAcquire;
5003
+ this._onRelease = onRelease;
5004
+ this._broadcastChannel.onmessage = this._onMessage.bind(this);
5005
+ }
5006
+ get lockKey() {
5007
+ return this._lockKey;
5008
+ }
5009
+ async acquire() {
5010
+ this._broadcastChannel.postMessage({
5011
+ message: "acquiring"
5012
+ });
5013
+ try {
5014
+ log14("aquiring lock...", void 0, {
5015
+ F: __dxlog_file18,
5016
+ L: 42,
5017
+ S: this,
5018
+ C: (f, a) => f(...a)
5019
+ });
5020
+ await asyncTimeout2(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
5021
+ log14("acquired lock", void 0, {
5022
+ F: __dxlog_file18,
5023
+ L: 44,
5024
+ S: this,
5025
+ C: (f, a) => f(...a)
5026
+ });
5027
+ } catch {
5028
+ log14("stealing lock...", void 0, {
5029
+ F: __dxlog_file18,
5030
+ L: 46,
5031
+ S: this,
5032
+ C: (f, a) => f(...a)
5033
+ });
5034
+ await this._requestLock(true);
5035
+ log14("stolen lock", void 0, {
5036
+ F: __dxlog_file18,
5037
+ L: 48,
5038
+ S: this,
5039
+ C: (f, a) => f(...a)
5040
+ });
5041
+ }
5042
+ }
5043
+ async release() {
5044
+ this._releaseTrigger.wake();
5045
+ }
5046
+ _onMessage(event) {
5047
+ if (event.data.message === "acquiring") {
5048
+ this._releaseTrigger.wake();
5049
+ }
5050
+ }
5051
+ async _requestLock(steal = false) {
5052
+ log14("requesting lock...", {
5053
+ steal
5054
+ }, {
5055
+ F: __dxlog_file18,
5056
+ L: 63,
5057
+ S: this,
5058
+ C: (f, a) => f(...a)
5059
+ });
5060
+ const acquired = new Trigger7();
5061
+ void navigator.locks.request(this._lockKey, {
5062
+ steal
5063
+ }, async () => {
5064
+ await this._onAcquire?.();
5065
+ acquired.wake();
5066
+ this._releaseTrigger = new Trigger7();
5067
+ await this._releaseTrigger.wait();
5068
+ log14("releasing lock...", void 0, {
5069
+ F: __dxlog_file18,
5070
+ L: 72,
5071
+ S: this,
5072
+ C: (f, a) => f(...a)
5073
+ });
5074
+ await this._onRelease?.();
5075
+ log14("released lock", void 0, {
5076
+ F: __dxlog_file18,
5077
+ L: 74,
5078
+ S: this,
5079
+ C: (f, a) => f(...a)
5080
+ });
5081
+ }).catch(async () => {
5082
+ await this._onRelease?.();
5083
+ });
5084
+ await acquired.wait();
5085
+ log14("recieved lock", {
5086
+ steal
5087
+ }, {
5088
+ F: __dxlog_file18,
5089
+ L: 81,
5090
+ S: this,
5091
+ C: (f, a) => f(...a)
5092
+ });
5093
+ }
5094
+ };
5095
+ _ts_decorate7([
5096
+ logInfo
5097
+ ], Lock.prototype, "lockKey", null);
5098
+ var isLocked = (lockPath) => {
5099
+ throw new Error("Not implemented");
5100
+ };
5101
+
5076
5102
  // packages/sdk/client-services/src/packlets/logging/logging-service.ts
5077
5103
  import { Event as Event8 } from "@dxos/async";
5078
5104
  import { Stream as Stream12 } from "@dxos/codec-protobuf";
5079
- import { PublicKey as PublicKey12 } from "@dxos/keys";
5080
- import { getContextFromEntry, log as log14 } from "@dxos/log";
5105
+ import { PublicKey as PublicKey11 } from "@dxos/keys";
5106
+ import { getContextFromEntry, log as log15 } from "@dxos/log";
5081
5107
  import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
5082
5108
  import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
5083
5109
  var LoggingServiceImpl = class {
5084
5110
  constructor() {
5085
5111
  this._logs = new Event8();
5086
5112
  this._started = Date.now();
5087
- this._sessionId = PublicKey12.random().toHex();
5113
+ this._sessionId = PublicKey11.random().toHex();
5088
5114
  this._logProcessor = (_config, entry2) => {
5089
5115
  this._logs.emit(entry2);
5090
5116
  };
5091
5117
  }
5092
5118
  async open() {
5093
- log14.runtimeConfig.processors.push(this._logProcessor);
5119
+ log15.runtimeConfig.processors.push(this._logProcessor);
5094
5120
  }
5095
5121
  async close() {
5096
- const index = log14.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
5097
- log14.runtimeConfig.processors.splice(index, 1);
5122
+ const index = log15.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
5123
+ log15.runtimeConfig.processors.splice(index, 1);
5098
5124
  }
5099
5125
  async controlMetrics({ reset, record }) {
5100
5126
  if (reset) {
@@ -5230,6 +5256,80 @@ var NetworkServiceImpl = class {
5230
5256
  }
5231
5257
  };
5232
5258
 
5259
+ // packages/sdk/client-services/src/packlets/storage/storage.ts
5260
+ import { InvalidConfigError } from "@dxos/protocols";
5261
+ import { Runtime as Runtime2 } from "@dxos/protocols/proto/dxos/config";
5262
+ import { createStorage, StorageType } from "@dxos/random-access-storage";
5263
+
5264
+ // packages/sdk/client-services/src/packlets/storage/util.ts
5265
+ import { DX_DATA } from "@dxos/client-protocol";
5266
+ import { Runtime } from "@dxos/protocols/proto/dxos/config";
5267
+ import { isNode as isNode2 } from "@dxos/util";
5268
+ var getRootPath = (config) => {
5269
+ const { dataRoot = isNode2() ? DX_DATA : "dxos/storage" } = config ?? {};
5270
+ return `${dataRoot}/`;
5271
+ };
5272
+ var isPersistent = (config) => {
5273
+ const { persistent = false } = config ?? {};
5274
+ return config.dataStore !== void 0 && config.dataStore !== Runtime.Client.Storage.StorageDriver.RAM || persistent;
5275
+ };
5276
+
5277
+ // packages/sdk/client-services/src/packlets/storage/storage.ts
5278
+ var StorageDriver = Runtime2.Client.Storage.StorageDriver;
5279
+ var createStorageObjects = (config) => {
5280
+ const { persistent = false, keyStore, dataStore } = config ?? {};
5281
+ if (persistent && dataStore === StorageDriver.RAM) {
5282
+ throw new InvalidConfigError("RAM storage cannot be used in persistent mode.");
5283
+ }
5284
+ if (!persistent && dataStore !== void 0 && dataStore !== StorageDriver.RAM) {
5285
+ throw new InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
5286
+ }
5287
+ if (persistent && keyStore === StorageDriver.RAM) {
5288
+ throw new InvalidConfigError("RAM key storage cannot be used in persistent mode.");
5289
+ }
5290
+ if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== void 0) {
5291
+ throw new InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
5292
+ }
5293
+ return {
5294
+ storage: createStorage({
5295
+ type: persistent ? toStorageType(dataStore) : StorageType.RAM,
5296
+ root: getRootPath(config)
5297
+ })
5298
+ };
5299
+ };
5300
+ var toStorageType = (type) => {
5301
+ switch (type) {
5302
+ case void 0:
5303
+ return void 0;
5304
+ case StorageDriver.RAM:
5305
+ return StorageType.RAM;
5306
+ case StorageDriver.CHROME:
5307
+ return StorageType.CHROME;
5308
+ case StorageDriver.FIREFOX:
5309
+ return StorageType.FIREFOX;
5310
+ case StorageDriver.IDB:
5311
+ return StorageType.IDB;
5312
+ case StorageDriver.NODE:
5313
+ return StorageType.NODE;
5314
+ case StorageDriver.WEBFS:
5315
+ return StorageType.WEBFS;
5316
+ default:
5317
+ throw new Error(`Invalid storage type: ${StorageDriver[type]}`);
5318
+ }
5319
+ };
5320
+
5321
+ // packages/sdk/client-services/src/packlets/storage/level.ts
5322
+ import { Level } from "level";
5323
+ import path from "@dxos/node-std/path";
5324
+ import { PublicKey as PublicKey12 } from "@dxos/keys";
5325
+ var createLevel = async (config) => {
5326
+ const persistent = isPersistent(config);
5327
+ const storagePath = persistent ? path.join(getRootPath(config), "level") : `/tmp/dxos-${PublicKey12.random().toHex()}`;
5328
+ const level = new Level(storagePath);
5329
+ await level.open();
5330
+ return level;
5331
+ };
5332
+
5233
5333
  // packages/sdk/client-services/src/packlets/system/system-service.ts
5234
5334
  import { Stream as Stream14 } from "@dxos/codec-protobuf";
5235
5335
  import { GetDiagnosticsRequest } from "@dxos/protocols/proto/dxos/client/services";
@@ -5298,13 +5398,14 @@ function _ts_decorate8(decorators, target, key, desc) {
5298
5398
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5299
5399
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5300
5400
  }
5301
- var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
5401
+ var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
5302
5402
  var ClientServicesHost = class {
5303
5403
  constructor({
5304
5404
  config,
5305
5405
  transportFactory,
5306
5406
  signalManager,
5307
5407
  storage,
5408
+ level,
5308
5409
  // TODO(wittjosiah): Turn this on by default.
5309
5410
  lockKey,
5310
5411
  callbacks,
@@ -5315,6 +5416,7 @@ var ClientServicesHost = class {
5315
5416
  this._opening = false;
5316
5417
  this._open = false;
5317
5418
  this._storage = storage;
5419
+ this._level = level;
5318
5420
  this._callbacks = callbacks;
5319
5421
  this._runtimeParams = runtimeParams;
5320
5422
  if (config) {
@@ -5353,6 +5455,7 @@ var ClientServicesHost = class {
5353
5455
  await this.reset();
5354
5456
  }
5355
5457
  });
5458
+ this.diagnosticsBroadcastHandler = createCollectDiagnosticsBroadcastHandler(this._systemService);
5356
5459
  this._loggingService = new LoggingServiceImpl();
5357
5460
  this._serviceRegistry = new ServiceRegistry(clientServiceBundle, {
5358
5461
  SystemService: this._systemService,
@@ -5384,24 +5487,24 @@ var ClientServicesHost = class {
5384
5487
  */
5385
5488
  initialize({ config, ...options }) {
5386
5489
  invariant16(!this._open, "service host is open", {
5387
- F: __dxlog_file18,
5388
- L: 182,
5490
+ F: __dxlog_file19,
5491
+ L: 197,
5389
5492
  S: this,
5390
5493
  A: [
5391
5494
  "!this._open",
5392
5495
  "'service host is open'"
5393
5496
  ]
5394
5497
  });
5395
- log15("initializing...", void 0, {
5396
- F: __dxlog_file18,
5397
- L: 183,
5498
+ log16("initializing...", void 0, {
5499
+ F: __dxlog_file19,
5500
+ L: 198,
5398
5501
  S: this,
5399
5502
  C: (f, a) => f(...a)
5400
5503
  });
5401
5504
  if (config) {
5402
5505
  invariant16(!this._config, "config already set", {
5403
- F: __dxlog_file18,
5404
- L: 186,
5506
+ F: __dxlog_file19,
5507
+ L: 201,
5405
5508
  S: this,
5406
5509
  A: [
5407
5510
  "!this._config",
@@ -5414,9 +5517,9 @@ var ClientServicesHost = class {
5414
5517
  }
5415
5518
  }
5416
5519
  if (!options.signalManager) {
5417
- log15.warn("running signaling without telemetry metadata.", void 0, {
5418
- F: __dxlog_file18,
5419
- L: 194,
5520
+ log16.warn("running signaling without telemetry metadata.", void 0, {
5521
+ F: __dxlog_file19,
5522
+ L: 209,
5420
5523
  S: this,
5421
5524
  C: (f, a) => f(...a)
5422
5525
  });
@@ -5426,8 +5529,8 @@ var ClientServicesHost = class {
5426
5529
  }), signalManager = new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
5427
5530
  this._signalManager = signalManager;
5428
5531
  invariant16(!this._networkManager, "network manager already set", {
5429
- F: __dxlog_file18,
5430
- L: 205,
5532
+ F: __dxlog_file19,
5533
+ L: 220,
5431
5534
  S: this,
5432
5535
  A: [
5433
5536
  "!this._networkManager",
@@ -5439,9 +5542,9 @@ var ClientServicesHost = class {
5439
5542
  transportFactory,
5440
5543
  signalManager
5441
5544
  });
5442
- log15("initialized", void 0, {
5443
- F: __dxlog_file18,
5444
- L: 212,
5545
+ log16("initialized", void 0, {
5546
+ F: __dxlog_file19,
5547
+ L: 227,
5445
5548
  S: this,
5446
5549
  C: (f, a) => f(...a)
5447
5550
  });
@@ -5451,17 +5554,17 @@ var ClientServicesHost = class {
5451
5554
  return;
5452
5555
  }
5453
5556
  const traceId = PublicKey13.random().toHex();
5454
- log15.trace("dxos.client-services.host.open", trace9.begin({
5557
+ log16.trace("dxos.client-services.host.open", trace9.begin({
5455
5558
  id: traceId
5456
5559
  }), {
5457
- F: __dxlog_file18,
5458
- L: 223,
5560
+ F: __dxlog_file19,
5561
+ L: 238,
5459
5562
  S: this,
5460
5563
  C: (f, a) => f(...a)
5461
5564
  });
5462
5565
  invariant16(this._config, "config not set", {
5463
- F: __dxlog_file18,
5464
- L: 225,
5566
+ F: __dxlog_file19,
5567
+ L: 240,
5465
5568
  S: this,
5466
5569
  A: [
5467
5570
  "this._config",
@@ -5469,8 +5572,8 @@ var ClientServicesHost = class {
5469
5572
  ]
5470
5573
  });
5471
5574
  invariant16(this._storage, "storage not set", {
5472
- F: __dxlog_file18,
5473
- L: 226,
5575
+ F: __dxlog_file19,
5576
+ L: 241,
5474
5577
  S: this,
5475
5578
  A: [
5476
5579
  "this._storage",
@@ -5478,8 +5581,8 @@ var ClientServicesHost = class {
5478
5581
  ]
5479
5582
  });
5480
5583
  invariant16(this._signalManager, "signal manager not set", {
5481
- F: __dxlog_file18,
5482
- L: 227,
5584
+ F: __dxlog_file19,
5585
+ L: 242,
5483
5586
  S: this,
5484
5587
  A: [
5485
5588
  "this._signalManager",
@@ -5487,8 +5590,8 @@ var ClientServicesHost = class {
5487
5590
  ]
5488
5591
  });
5489
5592
  invariant16(this._networkManager, "network manager not set", {
5490
- F: __dxlog_file18,
5491
- L: 228,
5593
+ F: __dxlog_file19,
5594
+ L: 243,
5492
5595
  S: this,
5493
5596
  A: [
5494
5597
  "this._networkManager",
@@ -5496,17 +5599,18 @@ var ClientServicesHost = class {
5496
5599
  ]
5497
5600
  });
5498
5601
  this._opening = true;
5499
- log15("opening...", {
5602
+ log16("opening...", {
5500
5603
  lockKey: this._resourceLock?.lockKey
5501
5604
  }, {
5502
- F: __dxlog_file18,
5503
- L: 231,
5605
+ F: __dxlog_file19,
5606
+ L: 246,
5504
5607
  S: this,
5505
5608
  C: (f, a) => f(...a)
5506
5609
  });
5507
5610
  if (!this._level) {
5508
5611
  this._level = await createLevel(this._config.get("runtime.client.storage", {}));
5509
5612
  }
5613
+ await this._level.open();
5510
5614
  await this._resourceLock?.acquire();
5511
5615
  await this._loggingService.open();
5512
5616
  this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._runtimeParams);
@@ -5536,8 +5640,8 @@ var ClientServicesHost = class {
5536
5640
  });
5537
5641
  await this._serviceContext.open(ctx);
5538
5642
  invariant16(this.serviceRegistry.services.InvitationsService, void 0, {
5539
- F: __dxlog_file18,
5540
- L: 297,
5643
+ F: __dxlog_file19,
5644
+ L: 314,
5541
5645
  S: this,
5542
5646
  A: [
5543
5647
  "this.serviceRegistry.services.InvitationsService",
@@ -5545,11 +5649,11 @@ var ClientServicesHost = class {
5545
5649
  ]
5546
5650
  });
5547
5651
  const loadedInvitations = await this.serviceRegistry.services.InvitationsService.loadPersistentInvitations();
5548
- log15("loaded persistent invitations", {
5652
+ log16("loaded persistent invitations", {
5549
5653
  count: loadedInvitations.invitations?.length
5550
5654
  }, {
5551
- F: __dxlog_file18,
5552
- L: 300,
5655
+ F: __dxlog_file19,
5656
+ L: 317,
5553
5657
  S: this,
5554
5658
  C: (f, a) => f(...a)
5555
5659
  });
@@ -5563,23 +5667,24 @@ var ClientServicesHost = class {
5563
5667
  });
5564
5668
  void this._devtoolsProxy.open();
5565
5669
  }
5670
+ this.diagnosticsBroadcastHandler.start();
5566
5671
  this._opening = false;
5567
5672
  this._open = true;
5568
5673
  this._statusUpdate.emit();
5569
5674
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
5570
- log15("opened", {
5675
+ log16("opened", {
5571
5676
  deviceKey
5572
5677
  }, {
5573
- F: __dxlog_file18,
5574
- L: 317,
5678
+ F: __dxlog_file19,
5679
+ L: 335,
5575
5680
  S: this,
5576
5681
  C: (f, a) => f(...a)
5577
5682
  });
5578
- log15.trace("dxos.client-services.host.open", trace9.end({
5683
+ log16.trace("dxos.client-services.host.open", trace9.end({
5579
5684
  id: traceId
5580
5685
  }), {
5581
- F: __dxlog_file18,
5582
- L: 318,
5686
+ F: __dxlog_file19,
5687
+ L: 336,
5583
5688
  S: this,
5584
5689
  C: (f, a) => f(...a)
5585
5690
  });
@@ -5589,14 +5694,15 @@ var ClientServicesHost = class {
5589
5694
  return;
5590
5695
  }
5591
5696
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
5592
- log15("closing...", {
5697
+ log16("closing...", {
5593
5698
  deviceKey
5594
5699
  }, {
5595
- F: __dxlog_file18,
5596
- L: 329,
5700
+ F: __dxlog_file19,
5701
+ L: 347,
5597
5702
  S: this,
5598
5703
  C: (f, a) => f(...a)
5599
5704
  });
5705
+ this.diagnosticsBroadcastHandler.stop();
5600
5706
  await this._devtoolsProxy?.close();
5601
5707
  this._serviceRegistry.setServices({
5602
5708
  SystemService: this._systemService
@@ -5606,44 +5712,44 @@ var ClientServicesHost = class {
5606
5712
  await this._level?.close();
5607
5713
  this._open = false;
5608
5714
  this._statusUpdate.emit();
5609
- log15("closed", {
5715
+ log16("closed", {
5610
5716
  deviceKey
5611
5717
  }, {
5612
- F: __dxlog_file18,
5613
- L: 337,
5718
+ F: __dxlog_file19,
5719
+ L: 356,
5614
5720
  S: this,
5615
5721
  C: (f, a) => f(...a)
5616
5722
  });
5617
5723
  }
5618
5724
  async reset() {
5619
5725
  const traceId = PublicKey13.random().toHex();
5620
- log15.trace("dxos.sdk.client-services-host.reset", trace9.begin({
5726
+ log16.trace("dxos.sdk.client-services-host.reset", trace9.begin({
5621
5727
  id: traceId
5622
5728
  }), {
5623
- F: __dxlog_file18,
5624
- L: 342,
5729
+ F: __dxlog_file19,
5730
+ L: 361,
5625
5731
  S: this,
5626
5732
  C: (f, a) => f(...a)
5627
5733
  });
5628
- log15("resetting...", void 0, {
5629
- F: __dxlog_file18,
5630
- L: 344,
5734
+ log16("resetting...", void 0, {
5735
+ F: __dxlog_file19,
5736
+ L: 363,
5631
5737
  S: this,
5632
5738
  C: (f, a) => f(...a)
5633
5739
  });
5634
5740
  await this._serviceContext?.close();
5635
5741
  await this._storage.reset();
5636
- log15("reset", void 0, {
5637
- F: __dxlog_file18,
5638
- L: 347,
5742
+ log16("reset", void 0, {
5743
+ F: __dxlog_file19,
5744
+ L: 366,
5639
5745
  S: this,
5640
5746
  C: (f, a) => f(...a)
5641
5747
  });
5642
- log15.trace("dxos.sdk.client-services-host.reset", trace9.end({
5748
+ log16.trace("dxos.sdk.client-services-host.reset", trace9.end({
5643
5749
  id: traceId
5644
5750
  }), {
5645
- F: __dxlog_file18,
5646
- L: 348,
5751
+ F: __dxlog_file19,
5752
+ L: 367,
5647
5753
  S: this,
5648
5754
  C: (f, a) => f(...a)
5649
5755
  });
@@ -5655,8 +5761,8 @@ var ClientServicesHost = class {
5655
5761
  const space = await this._serviceContext.dataSpaceManager.createSpace();
5656
5762
  const automergeIndex = space.automergeSpaceState.rootUrl;
5657
5763
  invariant16(automergeIndex, void 0, {
5658
- F: __dxlog_file18,
5659
- L: 360,
5764
+ F: __dxlog_file19,
5765
+ L: 379,
5660
5766
  S: this,
5661
5767
  A: [
5662
5768
  "automergeIndex",
@@ -5705,6 +5811,44 @@ ClientServicesHost = _ts_decorate8([
5705
5811
  Trace3.resource()
5706
5812
  ], ClientServicesHost);
5707
5813
 
5814
+ // packages/sdk/client-services/src/packlets/services/util.ts
5815
+ import { PublicKey as PublicKey14 } from "@dxos/keys";
5816
+ import { humanize } from "@dxos/util";
5817
+ var ClientServicesProviderResource = Symbol.for("dxos.resource.ClientServices");
5818
+
5819
+ // packages/sdk/client-services/src/packlets/diagnostics/diagnostics-collector.ts
5820
+ var DiagnosticsCollector = class {
5821
+ static {
5822
+ this.broadcastSender = createCollectDiagnosticsBroadcastSender();
5823
+ }
5824
+ static async collect(config = findConfigs(), services = findSystemServiceProvider(), options = {}) {
5825
+ const serviceDiagnostics = await services?.services?.SystemService?.getDiagnostics({
5826
+ keys: options.humanize ? GetDiagnosticsRequest2.KEY_OPTION.HUMANIZE : options.truncate ? GetDiagnosticsRequest2.KEY_OPTION.TRUNCATE : void 0
5827
+ });
5828
+ const clientDiagnostics = {
5829
+ config,
5830
+ trace: TRACE_PROCESSOR3.getDiagnostics()
5831
+ };
5832
+ const diagnostics = serviceDiagnostics != null ? {
5833
+ client: clientDiagnostics,
5834
+ services: serviceDiagnostics
5835
+ } : {
5836
+ client: clientDiagnostics,
5837
+ broadcast: await this.broadcastSender.broadcastDiagnosticsRequest()
5838
+ };
5839
+ return JSON.parse(JSON.stringify(diagnostics, jsonKeyReplacer2(options)));
5840
+ }
5841
+ };
5842
+ var findSystemServiceProvider = () => {
5843
+ const serviceProviders = TRACE_PROCESSOR3.findByAnnotation(ClientServicesProviderResource);
5844
+ const providerResource = serviceProviders.find((r) => r.instance.deref()?.services?.SystemService != null);
5845
+ return providerResource?.instance?.deref() ?? null;
5846
+ };
5847
+ var findConfigs = () => {
5848
+ const configs = TRACE_PROCESSOR3.findByAnnotation(ConfigResource);
5849
+ return configs.map((r) => r.instance.deref()).filter(nonNullable);
5850
+ };
5851
+
5708
5852
  export {
5709
5853
  Buffer,
5710
5854
  subscribeToFeeds,
@@ -5724,20 +5868,23 @@ export {
5724
5868
  IdentityServiceImpl,
5725
5869
  DeviceInvitationProtocol,
5726
5870
  InvitationsHandler,
5727
- invitationExpired,
5728
5871
  InvitationsServiceImpl,
5729
5872
  SpaceInvitationProtocol,
5730
5873
  ClientRpcServer,
5731
- createDiagnostics,
5732
5874
  DataSpace,
5733
5875
  DataSpaceManager,
5734
5876
  SpacesServiceImpl,
5735
5877
  ServiceContext,
5736
5878
  ServiceRegistry,
5879
+ createDiagnostics,
5880
+ createCollectDiagnosticsBroadcastSender,
5881
+ createCollectDiagnosticsBroadcastHandler,
5882
+ DiagnosticsCollector,
5737
5883
  Lock,
5738
5884
  isLocked,
5739
5885
  createStorageObjects,
5740
5886
  createLevel,
5741
- ClientServicesHost
5887
+ ClientServicesHost,
5888
+ ClientServicesProviderResource
5742
5889
  };
5743
- //# sourceMappingURL=chunk-WYFJLESV.mjs.map
5890
+ //# sourceMappingURL=chunk-4GN43XQ4.mjs.map