@dxos/client-services 0.4.7-next.f4b92be → 0.4.8-main.00e6f19

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 (46) hide show
  1. package/dist/lib/browser/{chunk-NTKD4OQC.mjs → chunk-EQPR3Z5Y.mjs} +426 -164
  2. package/dist/lib/browser/chunk-EQPR3Z5Y.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +3 -1
  4. package/dist/lib/browser/index.mjs.map +1 -1
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +1 -1
  7. package/dist/lib/node/{chunk-GCIW4VHF.cjs → chunk-VDSDEN45.cjs} +405 -146
  8. package/dist/lib/node/chunk-VDSDEN45.cjs.map +7 -0
  9. package/dist/lib/node/index.cjs +39 -37
  10. package/dist/lib/node/index.cjs.map +1 -1
  11. package/dist/lib/node/meta.json +1 -1
  12. package/dist/lib/node/packlets/testing/index.cjs +8 -8
  13. package/dist/types/src/packlets/indexing/index.d.ts +2 -0
  14. package/dist/types/src/packlets/indexing/index.d.ts.map +1 -0
  15. package/dist/types/src/packlets/indexing/util.d.ts +15 -0
  16. package/dist/types/src/packlets/indexing/util.d.ts.map +1 -0
  17. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +1 -0
  18. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  19. package/dist/types/src/packlets/invitations/invitations-service.d.ts +9 -1
  20. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  21. package/dist/types/src/packlets/logging/logging-service.d.ts +1 -0
  22. package/dist/types/src/packlets/logging/logging-service.d.ts.map +1 -1
  23. package/dist/types/src/packlets/services/service-context.d.ts +2 -1
  24. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  25. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  26. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts +2 -0
  27. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts.map +1 -1
  28. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  29. package/dist/types/src/packlets/spaces/spaces-service.d.ts +1 -1
  30. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  31. package/dist/types/src/version.d.ts +1 -1
  32. package/package.json +37 -35
  33. package/src/packlets/identity/identity-manager.ts +1 -1
  34. package/src/packlets/indexing/index.ts +5 -0
  35. package/src/packlets/indexing/util.ts +89 -0
  36. package/src/packlets/invitations/invitations-handler.ts +37 -2
  37. package/src/packlets/invitations/invitations-service.ts +83 -5
  38. package/src/packlets/logging/logging-service.ts +9 -2
  39. package/src/packlets/services/service-context.ts +13 -2
  40. package/src/packlets/services/service-host.ts +15 -2
  41. package/src/packlets/spaces/automerge-space-state.ts +15 -0
  42. package/src/packlets/spaces/data-space.ts +33 -11
  43. package/src/packlets/spaces/spaces-service.ts +2 -2
  44. package/src/version.ts +1 -1
  45. package/dist/lib/browser/chunk-NTKD4OQC.mjs.map +0 -7
  46. package/dist/lib/node/chunk-GCIW4VHF.cjs.map +0 -7
@@ -1043,7 +1043,7 @@ var IdentityManager = class {
1043
1043
  identityKey: identityRecord.identityKey
1044
1044
  });
1045
1045
  await space.setControlFeed(controlFeed);
1046
- void space.setDataFeed(dataFeed);
1046
+ await space.setDataFeed(dataFeed);
1047
1047
  const identity = new Identity({
1048
1048
  space,
1049
1049
  presence,
@@ -1638,11 +1638,11 @@ var InvitationsHandler = class {
1638
1638
  this._networkManager = _networkManager;
1639
1639
  }
1640
1640
  createInvitation(protocol, options) {
1641
- const { invitationId = PublicKey6.random().toHex(), type = Invitation3.Type.INTERACTIVE, authMethod = Invitation3.AuthMethod.SHARED_SECRET, state = Invitation3.State.INIT, timeout = INVITATION_TIMEOUT, swarmKey = PublicKey6.random() } = options ?? {};
1641
+ 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
1642
  const authCode = options?.authCode ?? (authMethod === Invitation3.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0);
1643
1643
  invariant6(protocol, void 0, {
1644
1644
  F: __dxlog_file7,
1645
- L: 81,
1645
+ L: 84,
1646
1646
  S: this,
1647
1647
  A: [
1648
1648
  "protocol",
@@ -1657,13 +1657,16 @@ var InvitationsHandler = class {
1657
1657
  swarmKey,
1658
1658
  authCode,
1659
1659
  timeout,
1660
+ persistent,
1661
+ created,
1662
+ lifetime,
1660
1663
  ...protocol.getInvitationContext()
1661
1664
  };
1662
1665
  const stream = new PushStream();
1663
1666
  const ctx = new Context5({
1664
1667
  onError: (err) => {
1665
- void ctx.dispose();
1666
1668
  stream.error(err);
1669
+ void ctx.dispose();
1667
1670
  }
1668
1671
  });
1669
1672
  ctx.onDispose(() => {
@@ -1671,7 +1674,7 @@ var InvitationsHandler = class {
1671
1674
  ...protocol.toJSON()
1672
1675
  }, {
1673
1676
  F: __dxlog_file7,
1674
- L: 103,
1677
+ L: 109,
1675
1678
  S: this,
1676
1679
  C: (f, a) => f(...a)
1677
1680
  });
@@ -1696,7 +1699,7 @@ var InvitationsHandler = class {
1696
1699
  const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
1697
1700
  invariant6(deviceKey, void 0, {
1698
1701
  F: __dxlog_file7,
1699
- L: 124,
1702
+ L: 130,
1700
1703
  S: this,
1701
1704
  A: [
1702
1705
  "deviceKey",
@@ -1719,7 +1722,7 @@ var InvitationsHandler = class {
1719
1722
  id: traceId
1720
1723
  }), {
1721
1724
  F: __dxlog_file7,
1722
- L: 142,
1725
+ L: 148,
1723
1726
  S: this,
1724
1727
  C: (f, a) => f(...a)
1725
1728
  });
@@ -1727,7 +1730,7 @@ var InvitationsHandler = class {
1727
1730
  ...protocol.toJSON()
1728
1731
  }, {
1729
1732
  F: __dxlog_file7,
1730
- L: 143,
1733
+ L: 149,
1731
1734
  S: this,
1732
1735
  C: (f, a) => f(...a)
1733
1736
  });
@@ -1743,7 +1746,7 @@ var InvitationsHandler = class {
1743
1746
  ...protocol.toJSON()
1744
1747
  }, {
1745
1748
  F: __dxlog_file7,
1746
- L: 146,
1749
+ L: 152,
1747
1750
  S: this,
1748
1751
  C: (f, a) => f(...a)
1749
1752
  });
@@ -1755,7 +1758,7 @@ var InvitationsHandler = class {
1755
1758
  id: traceId
1756
1759
  }), {
1757
1760
  F: __dxlog_file7,
1758
- L: 148,
1761
+ L: 154,
1759
1762
  S: this,
1760
1763
  C: (f, a) => f(...a)
1761
1764
  });
@@ -1765,7 +1768,7 @@ var InvitationsHandler = class {
1765
1768
  ...protocol.toJSON()
1766
1769
  }, {
1767
1770
  F: __dxlog_file7,
1768
- L: 151,
1771
+ L: 157,
1769
1772
  S: this,
1770
1773
  C: (f, a) => f(...a)
1771
1774
  });
@@ -1776,7 +1779,7 @@ var InvitationsHandler = class {
1776
1779
  } else {
1777
1780
  log5.error("failed", err, {
1778
1781
  F: __dxlog_file7,
1779
- L: 154,
1782
+ L: 160,
1780
1783
  S: this,
1781
1784
  C: (f, a) => f(...a)
1782
1785
  });
@@ -1787,7 +1790,7 @@ var InvitationsHandler = class {
1787
1790
  error: err
1788
1791
  }), {
1789
1792
  F: __dxlog_file7,
1790
- L: 157,
1793
+ L: 163,
1791
1794
  S: this,
1792
1795
  C: (f, a) => f(...a)
1793
1796
  });
@@ -1808,7 +1811,7 @@ var InvitationsHandler = class {
1808
1811
  ...protocol.toJSON()
1809
1812
  }, {
1810
1813
  F: __dxlog_file7,
1811
- L: 172,
1814
+ L: 178,
1812
1815
  S: this,
1813
1816
  C: (f, a) => f(...a)
1814
1817
  });
@@ -1819,7 +1822,7 @@ var InvitationsHandler = class {
1819
1822
  } else {
1820
1823
  log5.error("failed", err, {
1821
1824
  F: __dxlog_file7,
1822
- L: 175,
1825
+ L: 181,
1823
1826
  S: this,
1824
1827
  C: (f, a) => f(...a)
1825
1828
  });
@@ -1829,7 +1832,27 @@ var InvitationsHandler = class {
1829
1832
  });
1830
1833
  return extension;
1831
1834
  };
1835
+ if (invitation.lifetime && invitation.created && invitation.lifetime !== 0) {
1836
+ if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
1837
+ log5.warn("invitation has already expired", void 0, {
1838
+ F: __dxlog_file7,
1839
+ L: 192,
1840
+ S: this,
1841
+ C: (f, a) => f(...a)
1842
+ });
1843
+ } else {
1844
+ scheduleTask2(ctx, async () => {
1845
+ await swarmConnection.close();
1846
+ stream.next({
1847
+ ...invitation,
1848
+ state: Invitation3.State.EXPIRED
1849
+ });
1850
+ await ctx.dispose();
1851
+ }, invitation.created.getTime() + invitation.lifetime * 1e3 - Date.now());
1852
+ }
1853
+ }
1832
1854
  let swarmConnection;
1855
+ const invitationLabel = "invitation host for " + (invitation.kind === Invitation3.Kind.DEVICE ? "device" : `space ${invitation.spaceKey?.truncate()}`);
1833
1856
  scheduleTask2(ctx, async () => {
1834
1857
  const topic = invitation.swarmKey;
1835
1858
  swarmConnection = await this._networkManager.joinSwarm({
@@ -1839,7 +1862,7 @@ var InvitationsHandler = class {
1839
1862
  teleport.addExtension("dxos.halo.invitations", createExtension());
1840
1863
  }),
1841
1864
  topology: new StarTopology(topic),
1842
- label: "invitation host"
1865
+ label: invitationLabel
1843
1866
  });
1844
1867
  ctx.onDispose(() => swarmConnection.close());
1845
1868
  stream.next({
@@ -1864,7 +1887,7 @@ var InvitationsHandler = class {
1864
1887
  const { timeout = INVITATION_TIMEOUT } = invitation;
1865
1888
  invariant6(protocol, void 0, {
1866
1889
  F: __dxlog_file7,
1867
- L: 220,
1890
+ L: 246,
1868
1891
  S: this,
1869
1892
  A: [
1870
1893
  "protocol",
@@ -1874,7 +1897,7 @@ var InvitationsHandler = class {
1874
1897
  if (deviceProfile) {
1875
1898
  invariant6(invitation.kind === Invitation3.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
1876
1899
  F: __dxlog_file7,
1877
- L: 224,
1900
+ L: 250,
1878
1901
  S: this,
1879
1902
  A: [
1880
1903
  "invitation.kind === Invitation.Kind.DEVICE",
@@ -1889,7 +1912,7 @@ var InvitationsHandler = class {
1889
1912
  const setState = (newData) => {
1890
1913
  invariant6(newData.state !== void 0, void 0, {
1891
1914
  F: __dxlog_file7,
1892
- L: 235,
1915
+ L: 261,
1893
1916
  S: this,
1894
1917
  A: [
1895
1918
  "newData.state !== undefined",
@@ -1909,7 +1932,7 @@ var InvitationsHandler = class {
1909
1932
  ...protocol.toJSON()
1910
1933
  }, {
1911
1934
  F: __dxlog_file7,
1912
- L: 243,
1935
+ L: 269,
1913
1936
  S: this,
1914
1937
  C: (f, a) => f(...a)
1915
1938
  });
@@ -1919,7 +1942,7 @@ var InvitationsHandler = class {
1919
1942
  } else {
1920
1943
  log5.warn("auth failed", err, {
1921
1944
  F: __dxlog_file7,
1922
- L: 246,
1945
+ L: 272,
1923
1946
  S: this,
1924
1947
  C: (f, a) => f(...a)
1925
1948
  });
@@ -1933,7 +1956,7 @@ var InvitationsHandler = class {
1933
1956
  ...protocol.toJSON()
1934
1957
  }, {
1935
1958
  F: __dxlog_file7,
1936
- L: 254,
1959
+ L: 280,
1937
1960
  S: this,
1938
1961
  C: (f, a) => f(...a)
1939
1962
  });
@@ -1948,7 +1971,7 @@ var InvitationsHandler = class {
1948
1971
  currentState
1949
1972
  }, {
1950
1973
  F: __dxlog_file7,
1951
- L: 264,
1974
+ L: 290,
1952
1975
  S: this,
1953
1976
  C: (f, a) => f(...a)
1954
1977
  });
@@ -1963,7 +1986,7 @@ var InvitationsHandler = class {
1963
1986
  id: traceId
1964
1987
  }), {
1965
1988
  F: __dxlog_file7,
1966
- L: 273,
1989
+ L: 299,
1967
1990
  S: this,
1968
1991
  C: (f, a) => f(...a)
1969
1992
  });
@@ -1975,7 +1998,7 @@ var InvitationsHandler = class {
1975
1998
  ...protocol.toJSON()
1976
1999
  }, {
1977
2000
  F: __dxlog_file7,
1978
- L: 281,
2001
+ L: 307,
1979
2002
  S: this,
1980
2003
  C: (f, a) => f(...a)
1981
2004
  });
@@ -1986,7 +2009,7 @@ var InvitationsHandler = class {
1986
2009
  ...protocol.toJSON()
1987
2010
  }, {
1988
2011
  F: __dxlog_file7,
1989
- L: 285,
2012
+ L: 311,
1990
2013
  S: this,
1991
2014
  C: (f, a) => f(...a)
1992
2015
  });
@@ -1996,7 +2019,7 @@ var InvitationsHandler = class {
1996
2019
  response: introductionResponse
1997
2020
  }, {
1998
2021
  F: __dxlog_file7,
1999
- L: 289,
2022
+ L: 315,
2000
2023
  S: this,
2001
2024
  C: (f, a) => f(...a)
2002
2025
  });
@@ -2005,7 +2028,7 @@ var InvitationsHandler = class {
2005
2028
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2006
2029
  log5("guest waiting for authentication code...", void 0, {
2007
2030
  F: __dxlog_file7,
2008
- L: 295,
2031
+ L: 321,
2009
2032
  S: this,
2010
2033
  C: (f, a) => f(...a)
2011
2034
  });
@@ -2017,7 +2040,7 @@ var InvitationsHandler = class {
2017
2040
  });
2018
2041
  log5("sending authentication request", void 0, {
2019
2042
  F: __dxlog_file7,
2020
- L: 299,
2043
+ L: 325,
2021
2044
  S: this,
2022
2045
  C: (f, a) => f(...a)
2023
2046
  });
@@ -2038,7 +2061,7 @@ var InvitationsHandler = class {
2038
2061
  attempt
2039
2062
  }, {
2040
2063
  F: __dxlog_file7,
2041
- L: 310,
2064
+ L: 336,
2042
2065
  S: this,
2043
2066
  C: (f, a) => f(...a)
2044
2067
  });
@@ -2051,7 +2074,7 @@ var InvitationsHandler = class {
2051
2074
  ...protocol.toJSON()
2052
2075
  }, {
2053
2076
  F: __dxlog_file7,
2054
- L: 318,
2077
+ L: 344,
2055
2078
  S: this,
2056
2079
  C: (f, a) => f(...a)
2057
2080
  });
@@ -2063,7 +2086,7 @@ var InvitationsHandler = class {
2063
2086
  ...protocol.toJSON()
2064
2087
  }, {
2065
2088
  F: __dxlog_file7,
2066
- L: 329,
2089
+ L: 355,
2067
2090
  S: this,
2068
2091
  C: (f, a) => f(...a)
2069
2092
  });
@@ -2076,7 +2099,7 @@ var InvitationsHandler = class {
2076
2099
  id: traceId
2077
2100
  }), {
2078
2101
  F: __dxlog_file7,
2079
- L: 331,
2102
+ L: 357,
2080
2103
  S: this,
2081
2104
  C: (f, a) => f(...a)
2082
2105
  });
@@ -2086,7 +2109,7 @@ var InvitationsHandler = class {
2086
2109
  ...protocol.toJSON()
2087
2110
  }, {
2088
2111
  F: __dxlog_file7,
2089
- L: 334,
2112
+ L: 360,
2090
2113
  S: this,
2091
2114
  C: (f, a) => f(...a)
2092
2115
  });
@@ -2096,7 +2119,7 @@ var InvitationsHandler = class {
2096
2119
  } else {
2097
2120
  log5("auth failed", err, {
2098
2121
  F: __dxlog_file7,
2099
- L: 337,
2122
+ L: 363,
2100
2123
  S: this,
2101
2124
  C: (f, a) => f(...a)
2102
2125
  });
@@ -2107,7 +2130,7 @@ var InvitationsHandler = class {
2107
2130
  error: err
2108
2131
  }), {
2109
2132
  F: __dxlog_file7,
2110
- L: 340,
2133
+ L: 366,
2111
2134
  S: this,
2112
2135
  C: (f, a) => f(...a)
2113
2136
  });
@@ -2125,7 +2148,7 @@ var InvitationsHandler = class {
2125
2148
  ...protocol.toJSON()
2126
2149
  }, {
2127
2150
  F: __dxlog_file7,
2128
- L: 351,
2151
+ L: 377,
2129
2152
  S: this,
2130
2153
  C: (f, a) => f(...a)
2131
2154
  });
@@ -2135,7 +2158,7 @@ var InvitationsHandler = class {
2135
2158
  } else {
2136
2159
  log5("auth failed", err, {
2137
2160
  F: __dxlog_file7,
2138
- L: 354,
2161
+ L: 380,
2139
2162
  S: this,
2140
2163
  C: (f, a) => f(...a)
2141
2164
  });
@@ -2152,7 +2175,7 @@ var InvitationsHandler = class {
2152
2175
  } else {
2153
2176
  invariant6(invitation.swarmKey, void 0, {
2154
2177
  F: __dxlog_file7,
2155
- L: 368,
2178
+ L: 394,
2156
2179
  S: this,
2157
2180
  A: [
2158
2181
  "invitation.swarmKey",
@@ -2191,24 +2214,32 @@ var InvitationsHandler = class {
2191
2214
  return observable;
2192
2215
  }
2193
2216
  };
2217
+ var invitationExpired = (invitation) => {
2218
+ return invitation.created && invitation.lifetime && invitation.lifetime !== 0 && invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now();
2219
+ };
2194
2220
 
2195
2221
  // packages/sdk/client-services/src/packlets/invitations/invitations-service.ts
2196
- import { Event as Event3 } from "@dxos/async";
2222
+ import { Event as Event3, scheduleTask as scheduleTask3 } from "@dxos/async";
2197
2223
  import { Stream as Stream8 } from "@dxos/codec-protobuf";
2224
+ import { Context as Context6 } from "@dxos/context";
2198
2225
  import { invariant as invariant7 } from "@dxos/invariant";
2199
2226
  import { log as log6 } from "@dxos/log";
2200
2227
  import { Invitation as Invitation4, QueryInvitationsResponse } from "@dxos/protocols/proto/dxos/client/services";
2201
2228
  var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-service.ts";
2202
2229
  var InvitationsServiceImpl = class {
2203
- constructor(_invitationsHandler, _getHandler) {
2230
+ constructor(_invitationsHandler, _getHandler, _metadataStore) {
2204
2231
  this._invitationsHandler = _invitationsHandler;
2205
2232
  this._getHandler = _getHandler;
2233
+ this._metadataStore = _metadataStore;
2206
2234
  this._createInvitations = /* @__PURE__ */ new Map();
2207
2235
  this._acceptInvitations = /* @__PURE__ */ new Map();
2208
2236
  this._invitationCreated = new Event3();
2209
2237
  this._invitationAccepted = new Event3();
2210
2238
  this._removedCreated = new Event3();
2211
2239
  this._removedAccepted = new Event3();
2240
+ this._saved = new Event3();
2241
+ this._persistentInvitationsLoadedEvent = new Event3();
2242
+ this._persistentInvitationsLoaded = false;
2212
2243
  }
2213
2244
  // TODO(burdon): Guest/host label.
2214
2245
  getLoggingContext() {
@@ -2216,6 +2247,7 @@ var InvitationsServiceImpl = class {
2216
2247
  }
2217
2248
  createInvitation(options) {
2218
2249
  let invitation;
2250
+ const savePersistentInvitationCtx = new Context6();
2219
2251
  const existingInvitation = this._createInvitations.get(options.invitationId);
2220
2252
  if (existingInvitation) {
2221
2253
  invitation = existingInvitation;
@@ -2226,12 +2258,27 @@ var InvitationsServiceImpl = class {
2226
2258
  this._invitationCreated.emit(invitation.get());
2227
2259
  }
2228
2260
  return new Stream8(({ next, close }) => {
2261
+ if (invitation.get().persistent) {
2262
+ scheduleTask3(savePersistentInvitationCtx, async () => {
2263
+ try {
2264
+ await this._metadataStore.addInvitation(invitation.get());
2265
+ this._saved.emit(invitation.get());
2266
+ } catch (err) {
2267
+ close(err);
2268
+ }
2269
+ });
2270
+ }
2229
2271
  invitation.subscribe((invitation2) => {
2230
2272
  next(invitation2);
2231
- }, (err) => {
2273
+ }, async (err) => {
2274
+ await savePersistentInvitationCtx.dispose();
2232
2275
  close(err);
2233
- }, () => {
2276
+ }, async () => {
2234
2277
  close();
2278
+ if (invitation.get().persistent) {
2279
+ await savePersistentInvitationCtx.dispose();
2280
+ await this._metadataStore.removeInvitation(invitation.get().invitationId);
2281
+ }
2235
2282
  this._createInvitations.delete(invitation.get().invitationId);
2236
2283
  if (invitation.get().type !== Invitation4.Type.MULTIUSE) {
2237
2284
  this._removedCreated.emit(invitation.get());
@@ -2239,12 +2286,37 @@ var InvitationsServiceImpl = class {
2239
2286
  });
2240
2287
  });
2241
2288
  }
2289
+ async loadPersistentInvitations() {
2290
+ const persistentInvitations = this._metadataStore.getInvitations();
2291
+ const freshInvitations = persistentInvitations.filter(async (invitation) => !invitationExpired(invitation));
2292
+ const cInvitations = freshInvitations.map((persistentInvitation) => {
2293
+ invariant7(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
2294
+ F: __dxlog_file8,
2295
+ L: 109,
2296
+ S: this,
2297
+ A: [
2298
+ "!this._createInvitations.get(persistentInvitation.invitationId)",
2299
+ "'invitation already exists'"
2300
+ ]
2301
+ });
2302
+ const handler = this._getHandler(persistentInvitation);
2303
+ const invitation = this._invitationsHandler.createInvitation(handler, persistentInvitation);
2304
+ this._createInvitations.set(invitation.get().invitationId, invitation);
2305
+ this._invitationCreated.emit(invitation.get());
2306
+ return persistentInvitation;
2307
+ });
2308
+ this._persistentInvitationsLoadedEvent.emit();
2309
+ this._persistentInvitationsLoaded = true;
2310
+ return {
2311
+ invitations: cInvitations
2312
+ };
2313
+ }
2242
2314
  acceptInvitation({ invitation: options, deviceProfile }) {
2243
2315
  let invitation;
2244
2316
  if (deviceProfile) {
2245
2317
  invariant7(options.kind === Invitation4.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
2246
2318
  F: __dxlog_file8,
2247
- L: 81,
2319
+ L: 127,
2248
2320
  S: this,
2249
2321
  A: [
2250
2322
  "options.kind === Invitation.Kind.DEVICE",
@@ -2278,13 +2350,13 @@ var InvitationsServiceImpl = class {
2278
2350
  async authenticate({ invitationId, authCode }) {
2279
2351
  log6("authenticating...", void 0, {
2280
2352
  F: __dxlog_file8,
2281
- L: 114,
2353
+ L: 160,
2282
2354
  S: this,
2283
2355
  C: (f, a) => f(...a)
2284
2356
  });
2285
2357
  invariant7(invitationId, void 0, {
2286
2358
  F: __dxlog_file8,
2287
- L: 115,
2359
+ L: 161,
2288
2360
  S: this,
2289
2361
  A: [
2290
2362
  "invitationId",
@@ -2297,7 +2369,7 @@ var InvitationsServiceImpl = class {
2297
2369
  invitationId
2298
2370
  }, {
2299
2371
  F: __dxlog_file8,
2300
- L: 118,
2372
+ L: 164,
2301
2373
  S: this,
2302
2374
  C: (f, a) => f(...a)
2303
2375
  });
@@ -2306,15 +2378,17 @@ var InvitationsServiceImpl = class {
2306
2378
  }
2307
2379
  }
2308
2380
  async cancelInvitation({ invitationId }) {
2309
- log6("deleting...", void 0, {
2381
+ log6("cancelInvitation...", {
2382
+ invitationId
2383
+ }, {
2310
2384
  F: __dxlog_file8,
2311
- L: 125,
2385
+ L: 171,
2312
2386
  S: this,
2313
2387
  C: (f, a) => f(...a)
2314
2388
  });
2315
2389
  invariant7(invitationId, void 0, {
2316
2390
  F: __dxlog_file8,
2317
- L: 126,
2391
+ L: 172,
2318
2392
  S: this,
2319
2393
  A: [
2320
2394
  "invitationId",
@@ -2327,6 +2401,9 @@ var InvitationsServiceImpl = class {
2327
2401
  await created.cancel();
2328
2402
  this._createInvitations.delete(invitationId);
2329
2403
  this._removedCreated.emit(created.get());
2404
+ if (created.get().persistent) {
2405
+ await this._metadataStore.removeInvitation(created.get().invitationId);
2406
+ }
2330
2407
  } else if (accepted) {
2331
2408
  await accepted.cancel();
2332
2409
  this._acceptInvitations.delete(invitationId);
@@ -2371,16 +2448,40 @@ var InvitationsServiceImpl = class {
2371
2448
  ]
2372
2449
  });
2373
2450
  });
2451
+ this._saved.on(ctx, (invitation) => {
2452
+ next({
2453
+ action: QueryInvitationsResponse.Action.SAVED,
2454
+ type: QueryInvitationsResponse.Type.CREATED,
2455
+ invitations: [
2456
+ invitation
2457
+ ]
2458
+ });
2459
+ });
2374
2460
  next({
2375
2461
  action: QueryInvitationsResponse.Action.ADDED,
2376
2462
  type: QueryInvitationsResponse.Type.CREATED,
2377
- invitations: Array.from(this._createInvitations.values()).map((invitation) => invitation.get())
2463
+ invitations: Array.from(this._createInvitations.values()).map((invitation) => invitation.get()),
2464
+ existing: true
2378
2465
  });
2379
2466
  next({
2380
2467
  action: QueryInvitationsResponse.Action.ADDED,
2381
2468
  type: QueryInvitationsResponse.Type.ACCEPTED,
2382
- invitations: Array.from(this._acceptInvitations.values()).map((invitation) => invitation.get())
2469
+ invitations: Array.from(this._acceptInvitations.values()).map((invitation) => invitation.get()),
2470
+ existing: true
2383
2471
  });
2472
+ if (this._persistentInvitationsLoaded) {
2473
+ next({
2474
+ action: QueryInvitationsResponse.Action.LOAD_COMPLETE,
2475
+ type: QueryInvitationsResponse.Type.CREATED
2476
+ });
2477
+ } else {
2478
+ this._persistentInvitationsLoadedEvent.on(ctx, () => {
2479
+ next({
2480
+ action: QueryInvitationsResponse.Action.LOAD_COMPLETE,
2481
+ type: QueryInvitationsResponse.Type.CREATED
2482
+ });
2483
+ });
2484
+ }
2384
2485
  });
2385
2486
  }
2386
2487
  };
@@ -2671,7 +2772,7 @@ var getPlatform = () => {
2671
2772
  };
2672
2773
 
2673
2774
  // packages/sdk/client-services/src/version.ts
2674
- var DXOS_VERSION = "0.4.7-next.f4b92be";
2775
+ var DXOS_VERSION = "0.4.8-main.00e6f19";
2675
2776
 
2676
2777
  // packages/sdk/client-services/src/packlets/services/diagnostics.ts
2677
2778
  var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
@@ -2813,12 +2914,12 @@ var getSpaceStats = async (space) => {
2813
2914
  };
2814
2915
 
2815
2916
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2816
- import { Event as Event5, scheduleTask as scheduleTask4, sleep as sleep2, synchronized, trackLeaks } from "@dxos/async";
2917
+ import { Event as Event5, asyncTimeout, scheduleTask as scheduleTask5, sleep as sleep2, synchronized, trackLeaks } from "@dxos/async";
2817
2918
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
2818
- import { cancelWithContext as cancelWithContext2, Context as Context7, ContextDisposedError } from "@dxos/context";
2919
+ import { cancelWithContext as cancelWithContext2, Context as Context8, ContextDisposedError } from "@dxos/context";
2819
2920
  import { timed, warnAfterTimeout } from "@dxos/debug";
2820
2921
  import { createMappedFeedWriter } from "@dxos/echo-pipeline";
2821
- import { failedInvariant } from "@dxos/invariant";
2922
+ import { failedInvariant, invariant as invariant11 } from "@dxos/invariant";
2822
2923
  import { PublicKey as PublicKey8 } from "@dxos/keys";
2823
2924
  import { log as log10 } from "@dxos/log";
2824
2925
  import { CancelledError, SystemError } from "@dxos/protocols";
@@ -2835,6 +2936,7 @@ var AutomergeSpaceState = class {
2835
2936
  this._onNewRoot = _onNewRoot;
2836
2937
  this.rootUrl = void 0;
2837
2938
  this.lastEpoch = void 0;
2939
+ this._isProcessingRootDocs = false;
2838
2940
  }
2839
2941
  async processCredential(credential) {
2840
2942
  if (!checkCredentialType(credential, "dxos.halo.credentials.Epoch")) {
@@ -2843,14 +2945,25 @@ var AutomergeSpaceState = class {
2843
2945
  this.lastEpoch = credential;
2844
2946
  if (credential.subject.assertion.automergeRoot) {
2845
2947
  this.rootUrl = credential.subject.assertion.automergeRoot;
2948
+ if (this._isProcessingRootDocs) {
2949
+ this._onNewRoot(this.rootUrl);
2950
+ }
2951
+ }
2952
+ }
2953
+ startProcessingRootDocs() {
2954
+ if (this._isProcessingRootDocs) {
2955
+ return;
2956
+ }
2957
+ if (this.rootUrl) {
2846
2958
  this._onNewRoot(this.rootUrl);
2847
2959
  }
2960
+ this._isProcessingRootDocs = true;
2848
2961
  }
2849
2962
  };
2850
2963
 
2851
2964
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
2852
- import { DeferredTask, Event as Event4, scheduleTask as scheduleTask3, sleep, TimeoutError as TimeoutError2, Trigger as Trigger4 } from "@dxos/async";
2853
- import { Context as Context6, rejectOnDispose } from "@dxos/context";
2965
+ import { DeferredTask, Event as Event4, scheduleTask as scheduleTask4, sleep, TimeoutError as TimeoutError2, Trigger as Trigger4 } from "@dxos/async";
2966
+ import { Context as Context7, rejectOnDispose } from "@dxos/context";
2854
2967
  import { invariant as invariant10 } from "@dxos/invariant";
2855
2968
  import { PublicKey as PublicKey7 } from "@dxos/keys";
2856
2969
  import { log as log9 } from "@dxos/log";
@@ -2864,7 +2977,7 @@ var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
2864
2977
  var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
2865
2978
  var NotarizationPlugin = class {
2866
2979
  constructor() {
2867
- this._ctx = new Context6();
2980
+ this._ctx = new Context7();
2868
2981
  this._extensionOpened = new Event4();
2869
2982
  this._extensions = /* @__PURE__ */ new Set();
2870
2983
  this._processedCredentials = new ComplexSet2(PublicKey7.hash);
@@ -2916,7 +3029,7 @@ var NotarizationPlugin = class {
2916
3029
  });
2917
3030
  opCtx?.onDispose(() => ctx.dispose());
2918
3031
  if (timeout !== 0) {
2919
- scheduleTask3(ctx, () => {
3032
+ scheduleTask4(ctx, () => {
2920
3033
  log9.warn("Notarization timeout", {
2921
3034
  timeout,
2922
3035
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
@@ -2950,7 +3063,7 @@ var NotarizationPlugin = class {
2950
3063
  C: (f, a) => f(...a)
2951
3064
  });
2952
3065
  peersTried.clear();
2953
- scheduleTask3(ctx, () => notarizeTask.schedule(), retryTimeout);
3066
+ scheduleTask4(ctx, () => notarizeTask.schedule(), retryTimeout);
2954
3067
  return;
2955
3068
  }
2956
3069
  peersTried.add(peer);
@@ -3131,7 +3244,7 @@ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/s
3131
3244
  var ENABLE_FEED_PURGE = false;
3132
3245
  var DataSpace = class {
3133
3246
  constructor(params) {
3134
- this._ctx = new Context7();
3247
+ this._ctx = new Context8();
3135
3248
  this._notarizationPlugin = new NotarizationPlugin();
3136
3249
  this._cache = void 0;
3137
3250
  // TODO(dmaretskyi): Move into Space?
@@ -3211,7 +3324,7 @@ var DataSpace = class {
3211
3324
  await this._notarizationPlugin.open();
3212
3325
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
3213
3326
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
3214
- await this._inner.open(new Context7());
3327
+ await this._inner.open(new Context8());
3215
3328
  this._state = SpaceState.CONTROL_ONLY;
3216
3329
  log10("new state", {
3217
3330
  state: SpaceState[this._state]
@@ -3240,7 +3353,7 @@ var DataSpace = class {
3240
3353
  C: (f, a) => f(...a)
3241
3354
  });
3242
3355
  await this._ctx.dispose();
3243
- this._ctx = new Context7();
3356
+ this._ctx = new Context8();
3244
3357
  await this.authVerifier.close();
3245
3358
  await this._inner.close();
3246
3359
  await this._inner.spaceState.removeCredentialProcessor(this._automergeSpaceState);
@@ -3259,7 +3372,7 @@ var DataSpace = class {
3259
3372
  * Initialize the data pipeline in a separate task.
3260
3373
  */
3261
3374
  initializeDataPipelineAsync() {
3262
- scheduleTask4(this._ctx, async () => {
3375
+ scheduleTask5(this._ctx, async () => {
3263
3376
  try {
3264
3377
  this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
3265
3378
  await this.initializeDataPipeline();
@@ -3310,12 +3423,13 @@ var DataSpace = class {
3310
3423
  });
3311
3424
  await this._initializeAndReadControlPipeline();
3312
3425
  await sleep2(1);
3426
+ this._automergeSpaceState.startProcessingRootDocs();
3313
3427
  await this._inner.initializeDataPipeline();
3314
3428
  this.metrics.dataPipelineOpen = /* @__PURE__ */ new Date();
3315
3429
  await cancelWithContext2(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
3316
3430
  log10("waiting for data pipeline to reach target timeframe", void 0, {
3317
3431
  F: __dxlog_file12,
3318
- L: 286,
3432
+ L: 288,
3319
3433
  S: this,
3320
3434
  C: (f, a) => f(...a)
3321
3435
  });
@@ -3326,7 +3440,7 @@ var DataSpace = class {
3326
3440
  this.metrics.dataPipelineReady = /* @__PURE__ */ new Date();
3327
3441
  log10("data pipeline ready", void 0, {
3328
3442
  F: __dxlog_file12,
3329
- L: 294,
3443
+ L: 296,
3330
3444
  S: this,
3331
3445
  C: (f, a) => f(...a)
3332
3446
  });
@@ -3336,7 +3450,7 @@ var DataSpace = class {
3336
3450
  state: SpaceState[this._state]
3337
3451
  }, {
3338
3452
  F: __dxlog_file12,
3339
- L: 298,
3453
+ L: 300,
3340
3454
  S: this,
3341
3455
  C: (f, a) => f(...a)
3342
3456
  });
@@ -3352,7 +3466,7 @@ var DataSpace = class {
3352
3466
  await this._createWritableFeeds();
3353
3467
  log10("writable feeds created", void 0, {
3354
3468
  F: __dxlog_file12,
3355
- L: 314,
3469
+ L: 316,
3356
3470
  S: this,
3357
3471
  C: (f, a) => f(...a)
3358
3472
  });
@@ -3415,7 +3529,7 @@ var DataSpace = class {
3415
3529
  rootUrl
3416
3530
  }, {
3417
3531
  F: __dxlog_file12,
3418
- L: 380,
3532
+ L: 382,
3419
3533
  S: this,
3420
3534
  C: (f, a) => f(...a)
3421
3535
  });
@@ -3447,7 +3561,7 @@ var DataSpace = class {
3447
3561
  err
3448
3562
  }, {
3449
3563
  F: __dxlog_file12,
3450
- L: 403,
3564
+ L: 405,
3451
3565
  S: this,
3452
3566
  C: (f, a) => f(...a)
3453
3567
  });
@@ -3478,15 +3592,40 @@ var DataSpace = class {
3478
3592
  epoch = await this.dataPipeline.createEpoch();
3479
3593
  }
3480
3594
  break;
3481
- case CreateEpochRequest.Migration.INIT_AUTOMERGE: {
3482
- const document = this._automergeHost.repo.create();
3483
- epoch = {
3484
- previousId: this._automergeSpaceState.lastEpoch?.id,
3485
- number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
3486
- timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe2(),
3487
- automergeRoot: document.url
3488
- };
3489
- }
3595
+ case CreateEpochRequest.Migration.INIT_AUTOMERGE:
3596
+ {
3597
+ const document = this._automergeHost.repo.create();
3598
+ epoch = {
3599
+ previousId: this._automergeSpaceState.lastEpoch?.id,
3600
+ number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
3601
+ timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe2(),
3602
+ automergeRoot: document.url
3603
+ };
3604
+ }
3605
+ break;
3606
+ case CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY:
3607
+ {
3608
+ const currentRootUrl = this._automergeSpaceState.rootUrl;
3609
+ const rootHandle = this._automergeHost.repo.find(currentRootUrl);
3610
+ await cancelWithContext2(this._ctx, asyncTimeout(rootHandle.whenReady(), 1e4));
3611
+ const newRoot = this._automergeHost.repo.create(rootHandle.docSync());
3612
+ invariant11(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3613
+ F: __dxlog_file12,
3614
+ L: 450,
3615
+ S: this,
3616
+ A: [
3617
+ "typeof newRoot.url === 'string' && newRoot.url.length > 0",
3618
+ ""
3619
+ ]
3620
+ });
3621
+ epoch = {
3622
+ previousId: this._automergeSpaceState.lastEpoch?.id,
3623
+ number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
3624
+ timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe2(),
3625
+ automergeRoot: newRoot.url
3626
+ };
3627
+ }
3628
+ break;
3490
3629
  }
3491
3630
  if (!epoch) {
3492
3631
  return;
@@ -3537,7 +3676,7 @@ var DataSpace = class {
3537
3676
  state: SpaceState[this._state]
3538
3677
  }, {
3539
3678
  F: __dxlog_file12,
3540
- L: 492,
3679
+ L: 514,
3541
3680
  S: this,
3542
3681
  C: (f, a) => f(...a)
3543
3682
  });
@@ -3592,9 +3731,9 @@ DataSpace = _ts_decorate4([
3592
3731
 
3593
3732
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
3594
3733
  import { Event as Event6, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
3595
- import { cancelWithContext as cancelWithContext3, Context as Context8 } from "@dxos/context";
3734
+ import { cancelWithContext as cancelWithContext3, Context as Context9 } from "@dxos/context";
3596
3735
  import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
3597
- import { invariant as invariant11 } from "@dxos/invariant";
3736
+ import { invariant as invariant12 } from "@dxos/invariant";
3598
3737
  import { PublicKey as PublicKey9 } from "@dxos/keys";
3599
3738
  import { log as log11 } from "@dxos/log";
3600
3739
  import { trace as trace7 } from "@dxos/protocols";
@@ -3695,7 +3834,7 @@ var DataSpaceManager = class {
3695
3834
  this._signingContext = _signingContext;
3696
3835
  this._feedStore = _feedStore;
3697
3836
  this._automergeHost = _automergeHost;
3698
- this._ctx = new Context8();
3837
+ this._ctx = new Context9();
3699
3838
  this.updated = new Event6();
3700
3839
  this._spaces = new ComplexMap3(PublicKey9.hash);
3701
3840
  this._isOpen = false;
@@ -3787,7 +3926,7 @@ var DataSpaceManager = class {
3787
3926
  * Creates a new space writing the genesis credentials to the control feed.
3788
3927
  */
3789
3928
  async createSpace() {
3790
- invariant11(this._isOpen, "Not open.", {
3929
+ invariant12(this._isOpen, "Not open.", {
3791
3930
  F: __dxlog_file13,
3792
3931
  L: 145,
3793
3932
  S: this,
@@ -3824,7 +3963,7 @@ var DataSpaceManager = class {
3824
3963
  const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRoot.url);
3825
3964
  await this._metadataStore.addSpace(metadata);
3826
3965
  const memberCredential = credentials[1];
3827
- invariant11(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3966
+ invariant12(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3828
3967
  F: __dxlog_file13,
3829
3968
  L: 170,
3830
3969
  S: this,
@@ -3848,7 +3987,7 @@ var DataSpaceManager = class {
3848
3987
  S: this,
3849
3988
  C: (f, a) => f(...a)
3850
3989
  });
3851
- invariant11(this._isOpen, "Not open.", {
3990
+ invariant12(this._isOpen, "Not open.", {
3852
3991
  F: __dxlog_file13,
3853
3992
  L: 183,
3854
3993
  S: this,
@@ -3857,7 +3996,7 @@ var DataSpaceManager = class {
3857
3996
  "'Not open.'"
3858
3997
  ]
3859
3998
  });
3860
- invariant11(!this._spaces.has(opts.spaceKey), "Space already exists.", {
3999
+ invariant12(!this._spaces.has(opts.spaceKey), "Space already exists.", {
3861
4000
  F: __dxlog_file13,
3862
4001
  L: 184,
3863
4002
  S: this,
@@ -4021,10 +4160,10 @@ DataSpaceManager = _ts_decorate5([
4021
4160
  ], DataSpaceManager);
4022
4161
 
4023
4162
  // packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
4024
- import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTask as scheduleTask5 } from "@dxos/async";
4163
+ import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTask as scheduleTask6 } from "@dxos/async";
4025
4164
  import { Stream as Stream10 } from "@dxos/codec-protobuf";
4026
4165
  import { raise as raise2 } from "@dxos/debug";
4027
- import { invariant as invariant12 } from "@dxos/invariant";
4166
+ import { invariant as invariant13 } from "@dxos/invariant";
4028
4167
  import { log as log12 } from "@dxos/log";
4029
4168
  import { ApiError, SpaceNotFoundError, encodeError } from "@dxos/protocols";
4030
4169
  import { SpaceMember as SpaceMember3, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
@@ -4079,7 +4218,7 @@ var SpacesServiceImpl = class {
4079
4218
  }, {
4080
4219
  maxFrequency: false ? void 0 : 2
4081
4220
  });
4082
- scheduleTask5(ctx, async () => {
4221
+ scheduleTask6(ctx, async () => {
4083
4222
  const dataSpaceManager = await this._getDataSpaceManager();
4084
4223
  const subscriptions = new EventSubscriptions2();
4085
4224
  ctx.onDispose(() => subscriptions.clear());
@@ -4116,7 +4255,7 @@ var SpacesServiceImpl = class {
4116
4255
  }
4117
4256
  subscribeMessages({ spaceKey, channel }) {
4118
4257
  return new Stream10(({ ctx, next }) => {
4119
- scheduleTask5(ctx, async () => {
4258
+ scheduleTask6(ctx, async () => {
4120
4259
  const dataSpaceManager = await this._getDataSpaceManager();
4121
4260
  const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
4122
4261
  const handle = space.listen(getChannelId(channel), (message) => {
@@ -4135,7 +4274,7 @@ var SpacesServiceImpl = class {
4135
4274
  }
4136
4275
  };
4137
4276
  ctx.onDispose(() => space.spaceState.removeCredentialProcessor(processor));
4138
- scheduleTask5(ctx, async () => {
4277
+ scheduleTask6(ctx, async () => {
4139
4278
  await space.spaceState.addCredentialProcessor(processor);
4140
4279
  if (noTail) {
4141
4280
  close();
@@ -4153,7 +4292,7 @@ var SpacesServiceImpl = class {
4153
4292
  }
4154
4293
  });
4155
4294
  } else {
4156
- invariant12(!credential.id, "Id on unsigned credentials is not allowed", {
4295
+ invariant13(!credential.id, "Id on unsigned credentials is not allowed", {
4157
4296
  F: __dxlog_file14,
4158
4297
  L: 168,
4159
4298
  S: this,
@@ -4162,7 +4301,7 @@ var SpacesServiceImpl = class {
4162
4301
  "'Id on unsigned credentials is not allowed'"
4163
4302
  ]
4164
4303
  });
4165
- invariant12(this._identityManager.identity, "Identity is not available", {
4304
+ invariant13(this._identityManager.identity, "Identity is not available", {
4166
4305
  F: __dxlog_file14,
4167
4306
  L: 169,
4168
4307
  S: this,
@@ -4172,7 +4311,7 @@ var SpacesServiceImpl = class {
4172
4311
  ]
4173
4312
  });
4174
4313
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
4175
- invariant12(credential.issuer.equals(signer.getIssuer()), void 0, {
4314
+ invariant13(credential.issuer.equals(signer.getIssuer()), void 0, {
4176
4315
  F: __dxlog_file14,
4177
4316
  L: 171,
4178
4317
  S: this,
@@ -4193,10 +4332,12 @@ var SpacesServiceImpl = class {
4193
4332
  }
4194
4333
  }
4195
4334
  }
4196
- async createEpoch({ spaceKey }) {
4335
+ async createEpoch({ spaceKey, migration }) {
4197
4336
  const dataSpaceManager = await this._getDataSpaceManager();
4198
4337
  const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
4199
- await space.createEpoch();
4338
+ await space.createEpoch({
4339
+ migration
4340
+ });
4200
4341
  }
4201
4342
  _serializeSpace(space) {
4202
4343
  return {
@@ -4241,13 +4382,13 @@ var getChannelId = (channel) => `user-channel/${channel}`;
4241
4382
 
4242
4383
  // packages/sdk/client-services/src/packlets/services/service-context.ts
4243
4384
  import { Trigger as Trigger5 } from "@dxos/async";
4244
- import { Context as Context9 } from "@dxos/context";
4385
+ import { Context as Context10 } from "@dxos/context";
4245
4386
  import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
4246
4387
  import { failUndefined as failUndefined2 } from "@dxos/debug";
4247
4388
  import { valueEncoding, MetadataStore, SpaceManager, DataServiceSubscriptions, SnapshotStore, AutomergeHost } from "@dxos/echo-pipeline";
4248
- import { IndexMetadataStore } from "@dxos/echo-schema";
4249
4389
  import { FeedFactory, FeedStore } from "@dxos/feed-store";
4250
- import { invariant as invariant13 } from "@dxos/invariant";
4390
+ import { IndexMetadataStore, IndexStore, Indexer } from "@dxos/indexing";
4391
+ import { invariant as invariant14 } from "@dxos/invariant";
4251
4392
  import { Keyring } from "@dxos/keyring";
4252
4393
  import { PublicKey as PublicKey10 } from "@dxos/keys";
4253
4394
  import { log as log13 } from "@dxos/log";
@@ -4256,6 +4397,87 @@ import { Invitation as Invitation6 } from "@dxos/protocols/proto/dxos/client/ser
4256
4397
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
4257
4398
  import { trace as Trace2 } from "@dxos/tracing";
4258
4399
  import { safeInstanceof } from "@dxos/util";
4400
+
4401
+ // packages/sdk/client-services/src/packlets/indexing/util.ts
4402
+ import { getHeads } from "@dxos/automerge/automerge";
4403
+ import { warnAfterTimeout as warnAfterTimeout2 } from "@dxos/debug";
4404
+ import { idCodec } from "@dxos/protocols";
4405
+ var createLoadDocuments = (automergeHost) => (
4406
+ /**
4407
+ * Get object data blobs from Automerge Repo by ids.
4408
+ * @param ids
4409
+ */
4410
+ // TODO(mykola): Unload automerge handles after usage.
4411
+ async function* loadDocuments(ids) {
4412
+ for (const id of ids) {
4413
+ const { documentId, objectId } = idCodec.decode(id);
4414
+ const handle = automergeHost.repo.find(documentId);
4415
+ await warnAfterTimeout2(5e3, "to long to load doc", () => handle.whenReady());
4416
+ const doc = handle.docSync();
4417
+ const heads = getHeads(doc);
4418
+ yield [
4419
+ {
4420
+ id,
4421
+ object: doc.objects[objectId],
4422
+ currentHash: heads.at(-1)
4423
+ }
4424
+ ];
4425
+ }
4426
+ }
4427
+ );
4428
+ var createGetAllDocuments = (automergeHost) => (
4429
+ /**
4430
+ * Recursively get all object data blobs from Automerge Repo.
4431
+ * @param ids
4432
+ */
4433
+ // TODO(mykola): Unload automerge handles after usage.
4434
+ async function* getAllDocuments() {
4435
+ const visited = /* @__PURE__ */ new Set();
4436
+ async function* getObjectsFromHandle(handle) {
4437
+ if (visited.has(handle.documentId)) {
4438
+ return;
4439
+ }
4440
+ await warnAfterTimeout2(5e3, "to long to load doc", () => handle.whenReady());
4441
+ const doc = handle.docSync();
4442
+ const heads = getHeads(doc);
4443
+ if (doc.objects) {
4444
+ yield Object.entries(doc.objects).map(([objectId, object]) => {
4445
+ return {
4446
+ id: idCodec.encode({
4447
+ documentId: handle.documentId,
4448
+ objectId
4449
+ }),
4450
+ object,
4451
+ currentHash: heads.at(-1)
4452
+ };
4453
+ });
4454
+ }
4455
+ if (doc.links) {
4456
+ for (const id of Object.values(doc.links)) {
4457
+ if (visited.has(id)) {
4458
+ continue;
4459
+ }
4460
+ const linkHandle = automergeHost.repo.find(id);
4461
+ for await (const result of getObjectsFromHandle(linkHandle)) {
4462
+ yield result;
4463
+ }
4464
+ }
4465
+ }
4466
+ visited.add(handle.documentId);
4467
+ }
4468
+ for (const handle of Object.values(automergeHost.repo.handles)) {
4469
+ if (visited.has(handle.documentId)) {
4470
+ continue;
4471
+ }
4472
+ for await (const result of getObjectsFromHandle(handle)) {
4473
+ yield result;
4474
+ }
4475
+ visited.add(handle.documentId);
4476
+ }
4477
+ }
4478
+ );
4479
+
4480
+ // packages/sdk/client-services/src/packlets/services/service-context.ts
4259
4481
  function _ts_decorate6(decorators, target, key, desc) {
4260
4482
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4261
4483
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -4279,9 +4501,6 @@ var ServiceContext = class {
4279
4501
  this._handlerFactories = /* @__PURE__ */ new Map();
4280
4502
  this._instanceId = PublicKey10.random().toHex();
4281
4503
  this.metadataStore = new MetadataStore(storage.createDirectory("metadata"));
4282
- this.indexMetadata = new IndexMetadataStore({
4283
- directory: storage.createDirectory("index-metadata")
4284
- });
4285
4504
  this.snapshotStore = new SnapshotStore(storage.createDirectory("snapshots"));
4286
4505
  this.blobStore = new BlobStore(storage.createDirectory("blobs"));
4287
4506
  this.keyring = new Keyring(storage.createDirectory("keyring"));
@@ -4304,10 +4523,21 @@ var ServiceContext = class {
4304
4523
  snapshotStore: this.snapshotStore
4305
4524
  });
4306
4525
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager, this._runtimeParams);
4526
+ this.indexMetadata = new IndexMetadataStore({
4527
+ directory: storage.createDirectory("index-metadata")
4528
+ });
4307
4529
  this.automergeHost = new AutomergeHost({
4308
4530
  directory: storage.createDirectory("automerge"),
4309
4531
  metadata: this.indexMetadata
4310
4532
  });
4533
+ this.indexer = new Indexer({
4534
+ indexStore: new IndexStore({
4535
+ directory: storage.createDirectory("index-store")
4536
+ }),
4537
+ metadataStore: this.indexMetadata,
4538
+ loadDocuments: createLoadDocuments(this.automergeHost),
4539
+ getAllDocuments: createGetAllDocuments(this.automergeHost)
4540
+ });
4311
4541
  this.invitations = new InvitationsHandler(this.networkManager);
4312
4542
  this._handlerFactories.set(Invitation6.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined2(), this._acceptIdentity.bind(this)));
4313
4543
  }
@@ -4315,7 +4545,7 @@ var ServiceContext = class {
4315
4545
  await this._checkStorageVersion();
4316
4546
  log13("opening...", void 0, {
4317
4547
  F: __dxlog_file15,
4318
- L: 152,
4548
+ L: 162,
4319
4549
  S: this,
4320
4550
  C: (f, a) => f(...a)
4321
4551
  });
@@ -4323,7 +4553,7 @@ var ServiceContext = class {
4323
4553
  id: this._instanceId
4324
4554
  }), {
4325
4555
  F: __dxlog_file15,
4326
- L: 153,
4556
+ L: 163,
4327
4557
  S: this,
4328
4558
  C: (f, a) => f(...a)
4329
4559
  });
@@ -4339,13 +4569,13 @@ var ServiceContext = class {
4339
4569
  id: this._instanceId
4340
4570
  }), {
4341
4571
  F: __dxlog_file15,
4342
- L: 163,
4572
+ L: 173,
4343
4573
  S: this,
4344
4574
  C: (f, a) => f(...a)
4345
4575
  });
4346
4576
  log13("opened", void 0, {
4347
4577
  F: __dxlog_file15,
4348
- L: 164,
4578
+ L: 174,
4349
4579
  S: this,
4350
4580
  C: (f, a) => f(...a)
4351
4581
  });
@@ -4353,7 +4583,7 @@ var ServiceContext = class {
4353
4583
  async close() {
4354
4584
  log13("closing...", void 0, {
4355
4585
  F: __dxlog_file15,
4356
- L: 168,
4586
+ L: 178,
4357
4587
  S: this,
4358
4588
  C: (f, a) => f(...a)
4359
4589
  });
@@ -4369,23 +4599,24 @@ var ServiceContext = class {
4369
4599
  await this.signalManager.close();
4370
4600
  this.dataServiceSubscriptions.clear();
4371
4601
  await this.metadataStore.close();
4602
+ await this.indexer.destroy();
4372
4603
  log13("closed", void 0, {
4373
4604
  F: __dxlog_file15,
4374
- L: 181,
4605
+ L: 192,
4375
4606
  S: this,
4376
4607
  C: (f, a) => f(...a)
4377
4608
  });
4378
4609
  }
4379
4610
  async createIdentity(params = {}) {
4380
4611
  const identity = await this.identityManager.createIdentity(params);
4381
- await this._initialize(new Context9());
4612
+ await this._initialize(new Context10());
4382
4613
  return identity;
4383
4614
  }
4384
4615
  getInvitationHandler(invitation) {
4385
4616
  const factory = this._handlerFactories.get(invitation.kind);
4386
- invariant13(factory, `Unknown invitation kind: ${invitation.kind}`, {
4617
+ invariant14(factory, `Unknown invitation kind: ${invitation.kind}`, {
4387
4618
  F: __dxlog_file15,
4388
- L: 192,
4619
+ L: 203,
4389
4620
  S: this,
4390
4621
  A: [
4391
4622
  "factory",
@@ -4404,7 +4635,7 @@ var ServiceContext = class {
4404
4635
  }
4405
4636
  async _acceptIdentity(params) {
4406
4637
  const identity = await this.identityManager.acceptIdentity(params);
4407
- await this._initialize(new Context9());
4638
+ await this._initialize(new Context10());
4408
4639
  return identity;
4409
4640
  }
4410
4641
  async _checkStorageVersion() {
@@ -4417,7 +4648,7 @@ var ServiceContext = class {
4417
4648
  async _initialize(ctx) {
4418
4649
  log13("initializing spaces...", void 0, {
4419
4650
  F: __dxlog_file15,
4420
- L: 223,
4651
+ L: 234,
4421
4652
  S: this,
4422
4653
  C: (f, a) => f(...a)
4423
4654
  });
@@ -4438,9 +4669,9 @@ var ServiceContext = class {
4438
4669
  this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.dataServiceSubscriptions, this.keyring, signingContext, this.feedStore, this.automergeHost, this._runtimeParams);
4439
4670
  await this.dataSpaceManager.open();
4440
4671
  this._handlerFactories.set(Invitation6.Kind.SPACE, (invitation) => {
4441
- invariant13(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4672
+ invariant14(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4442
4673
  F: __dxlog_file15,
4443
- L: 248,
4674
+ L: 259,
4444
4675
  S: this,
4445
4676
  A: [
4446
4677
  "this.dataSpaceManager",
@@ -4464,7 +4695,7 @@ var ServiceContext = class {
4464
4695
  details: assertion
4465
4696
  }, {
4466
4697
  F: __dxlog_file15,
4467
- L: 264,
4698
+ L: 275,
4468
4699
  S: this,
4469
4700
  C: (f, a) => f(...a)
4470
4701
  });
@@ -4475,7 +4706,7 @@ var ServiceContext = class {
4475
4706
  details: assertion
4476
4707
  }, {
4477
4708
  F: __dxlog_file15,
4478
- L: 268,
4709
+ L: 279,
4479
4710
  S: this,
4480
4711
  C: (f, a) => f(...a)
4481
4712
  });
@@ -4486,7 +4717,7 @@ var ServiceContext = class {
4486
4717
  details: assertion
4487
4718
  }, {
4488
4719
  F: __dxlog_file15,
4489
- L: 273,
4720
+ L: 284,
4490
4721
  S: this,
4491
4722
  C: (f, a) => f(...a)
4492
4723
  });
@@ -4497,7 +4728,7 @@ var ServiceContext = class {
4497
4728
  } catch (err) {
4498
4729
  log13.catch(err, void 0, {
4499
4730
  F: __dxlog_file15,
4500
- L: 279,
4731
+ L: 290,
4501
4732
  S: this,
4502
4733
  C: (f, a) => f(...a)
4503
4734
  });
@@ -4543,7 +4774,7 @@ var ServiceRegistry = class {
4543
4774
  };
4544
4775
 
4545
4776
  // packages/sdk/client-services/src/packlets/locks/browser.ts
4546
- import { asyncTimeout, Trigger as Trigger6 } from "@dxos/async";
4777
+ import { asyncTimeout as asyncTimeout2, Trigger as Trigger6 } from "@dxos/async";
4547
4778
  import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
4548
4779
  import { log as log14, logInfo } from "@dxos/log";
4549
4780
  function _ts_decorate7(decorators, target, key, desc) {
@@ -4584,7 +4815,7 @@ var Lock = class {
4584
4815
  S: this,
4585
4816
  C: (f, a) => f(...a)
4586
4817
  });
4587
- await asyncTimeout(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
4818
+ await asyncTimeout2(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
4588
4819
  log14("acquired lock", void 0, {
4589
4820
  F: __dxlog_file16,
4590
4821
  L: 44,
@@ -4718,12 +4949,13 @@ var toStorageType = (type) => {
4718
4949
  // packages/sdk/client-services/src/packlets/services/service-host.ts
4719
4950
  import { Event as Event8, synchronized as synchronized3 } from "@dxos/async";
4720
4951
  import { clientServiceBundle, defaultKey, Properties } from "@dxos/client-protocol";
4721
- import { Context as Context10 } from "@dxos/context";
4952
+ import { Context as Context11 } from "@dxos/context";
4722
4953
  import { DocumentModel as DocumentModel2 } from "@dxos/document-model";
4723
4954
  import { DataServiceImpl } from "@dxos/echo-pipeline";
4724
4955
  import { getRawDoc, getAutomergeObjectCore } from "@dxos/echo-schema";
4725
- import { invariant as invariant15 } from "@dxos/invariant";
4726
- import { PublicKey as PublicKey11 } from "@dxos/keys";
4956
+ import { IndexServiceImpl } from "@dxos/indexing";
4957
+ import { invariant as invariant16 } from "@dxos/invariant";
4958
+ import { PublicKey as PublicKey12 } from "@dxos/keys";
4727
4959
  import { log as log16 } from "@dxos/log";
4728
4960
  import { WebsocketSignalManager } from "@dxos/messaging";
4729
4961
  import { ModelFactory } from "@dxos/model-factory";
@@ -4738,7 +4970,7 @@ import { WebsocketRpcClient } from "@dxos/websocket-rpc";
4738
4970
  // packages/sdk/client-services/src/packlets/devices/devices-service.ts
4739
4971
  import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
4740
4972
  import { Stream as Stream11 } from "@dxos/codec-protobuf";
4741
- import { invariant as invariant14 } from "@dxos/invariant";
4973
+ import { invariant as invariant15 } from "@dxos/invariant";
4742
4974
  import { Device as Device2, DeviceKind as DeviceKind2 } from "@dxos/protocols/proto/dxos/client/services";
4743
4975
  var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
4744
4976
  var DevicesServiceImpl = class {
@@ -4757,7 +4989,7 @@ var DevicesServiceImpl = class {
4757
4989
  devices: []
4758
4990
  });
4759
4991
  } else {
4760
- invariant14(this._identityManager.identity?.presence, "presence not present", {
4992
+ invariant15(this._identityManager.identity?.presence, "presence not present", {
4761
4993
  F: __dxlog_file17,
4762
4994
  L: 32,
4763
4995
  S: this,
@@ -4820,13 +5052,15 @@ var DevicesServiceImpl = class {
4820
5052
  // packages/sdk/client-services/src/packlets/logging/logging-service.ts
4821
5053
  import { Event as Event7 } from "@dxos/async";
4822
5054
  import { Stream as Stream12 } from "@dxos/codec-protobuf";
5055
+ import { PublicKey as PublicKey11 } from "@dxos/keys";
4823
5056
  import { getContextFromEntry, log as log15 } from "@dxos/log";
4824
5057
  import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
4825
- import { jsonify, numericalValues, tracer } from "@dxos/util";
5058
+ import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
4826
5059
  var LoggingServiceImpl = class {
4827
5060
  constructor() {
4828
5061
  this._logs = new Event7();
4829
- this._started = /* @__PURE__ */ new Date();
5062
+ this._started = Date.now();
5063
+ this._sessionId = PublicKey11.random().toHex();
4830
5064
  this._logProcessor = (_config, entry2) => {
4831
5065
  this._logs.emit(entry2);
4832
5066
  };
@@ -4902,7 +5136,12 @@ var LoggingServiceImpl = class {
4902
5136
  meta: {
4903
5137
  // TODO(dmaretskyi): Fix proto.
4904
5138
  file: entry2.meta?.F ?? "",
4905
- line: entry2.meta?.L ?? 0
5139
+ line: entry2.meta?.L ?? 0,
5140
+ scope: {
5141
+ hostSessionId: this._sessionId,
5142
+ uptimeSeconds: (Date.now() - this._started) / 1e3,
5143
+ name: getDebugName(entry2.meta?.S)
5144
+ }
4906
5145
  }
4907
5146
  };
4908
5147
  try {
@@ -5071,7 +5310,7 @@ var ClientServicesHost = class {
5071
5310
  lockKey,
5072
5311
  onAcquire: () => {
5073
5312
  if (!this._opening) {
5074
- void this.open(new Context10());
5313
+ void this.open(new Context11());
5075
5314
  }
5076
5315
  },
5077
5316
  onRelease: () => this.close()
@@ -5125,9 +5364,9 @@ var ClientServicesHost = class {
5125
5364
  * Can only be called once.
5126
5365
  */
5127
5366
  initialize({ config, ...options }) {
5128
- invariant15(!this._open, "service host is open", {
5367
+ invariant16(!this._open, "service host is open", {
5129
5368
  F: __dxlog_file18,
5130
- L: 190,
5369
+ L: 191,
5131
5370
  S: this,
5132
5371
  A: [
5133
5372
  "!this._open",
@@ -5136,14 +5375,14 @@ var ClientServicesHost = class {
5136
5375
  });
5137
5376
  log16("initializing...", void 0, {
5138
5377
  F: __dxlog_file18,
5139
- L: 191,
5378
+ L: 192,
5140
5379
  S: this,
5141
5380
  C: (f, a) => f(...a)
5142
5381
  });
5143
5382
  if (config) {
5144
- invariant15(!this._config, "config already set", {
5383
+ invariant16(!this._config, "config already set", {
5145
5384
  F: __dxlog_file18,
5146
- L: 194,
5385
+ L: 195,
5147
5386
  S: this,
5148
5387
  A: [
5149
5388
  "!this._config",
@@ -5159,9 +5398,9 @@ var ClientServicesHost = class {
5159
5398
  iceServers: this._config?.get("runtime.services.ice")
5160
5399
  }), signalManager = new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
5161
5400
  this._signalManager = signalManager;
5162
- invariant15(!this._networkManager, "network manager already set", {
5401
+ invariant16(!this._networkManager, "network manager already set", {
5163
5402
  F: __dxlog_file18,
5164
- L: 210,
5403
+ L: 211,
5165
5404
  S: this,
5166
5405
  A: [
5167
5406
  "!this._networkManager",
@@ -5175,7 +5414,7 @@ var ClientServicesHost = class {
5175
5414
  });
5176
5415
  log16("initialized", void 0, {
5177
5416
  F: __dxlog_file18,
5178
- L: 217,
5417
+ L: 218,
5179
5418
  S: this,
5180
5419
  C: (f, a) => f(...a)
5181
5420
  });
@@ -5184,45 +5423,45 @@ var ClientServicesHost = class {
5184
5423
  if (this._open) {
5185
5424
  return;
5186
5425
  }
5187
- const traceId = PublicKey11.random().toHex();
5426
+ const traceId = PublicKey12.random().toHex();
5188
5427
  log16.trace("dxos.client-services.host.open", trace9.begin({
5189
5428
  id: traceId
5190
5429
  }), {
5191
5430
  F: __dxlog_file18,
5192
- L: 228,
5431
+ L: 229,
5193
5432
  S: this,
5194
5433
  C: (f, a) => f(...a)
5195
5434
  });
5196
- invariant15(this._config, "config not set", {
5435
+ invariant16(this._config, "config not set", {
5197
5436
  F: __dxlog_file18,
5198
- L: 230,
5437
+ L: 231,
5199
5438
  S: this,
5200
5439
  A: [
5201
5440
  "this._config",
5202
5441
  "'config not set'"
5203
5442
  ]
5204
5443
  });
5205
- invariant15(this._storage, "storage not set", {
5444
+ invariant16(this._storage, "storage not set", {
5206
5445
  F: __dxlog_file18,
5207
- L: 231,
5446
+ L: 232,
5208
5447
  S: this,
5209
5448
  A: [
5210
5449
  "this._storage",
5211
5450
  "'storage not set'"
5212
5451
  ]
5213
5452
  });
5214
- invariant15(this._signalManager, "signal manager not set", {
5453
+ invariant16(this._signalManager, "signal manager not set", {
5215
5454
  F: __dxlog_file18,
5216
- L: 232,
5455
+ L: 233,
5217
5456
  S: this,
5218
5457
  A: [
5219
5458
  "this._signalManager",
5220
5459
  "'signal manager not set'"
5221
5460
  ]
5222
5461
  });
5223
- invariant15(this._networkManager, "network manager not set", {
5462
+ invariant16(this._networkManager, "network manager not set", {
5224
5463
  F: __dxlog_file18,
5225
- L: 233,
5464
+ L: 234,
5226
5465
  S: this,
5227
5466
  A: [
5228
5467
  "this._networkManager",
@@ -5234,7 +5473,7 @@ var ClientServicesHost = class {
5234
5473
  lockKey: this._resourceLock?.lockKey
5235
5474
  }, {
5236
5475
  F: __dxlog_file18,
5237
- L: 236,
5476
+ L: 237,
5238
5477
  S: this,
5239
5478
  C: (f, a) => f(...a)
5240
5479
  });
@@ -5244,13 +5483,17 @@ var ClientServicesHost = class {
5244
5483
  this._serviceRegistry.setServices({
5245
5484
  SystemService: this._systemService,
5246
5485
  IdentityService: new IdentityServiceImpl((params) => this._createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring, (profile) => this._serviceContext.broadcastProfileUpdate(profile)),
5247
- InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitations, (invitation) => this._serviceContext.getInvitationHandler(invitation)),
5486
+ InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitations, (invitation) => this._serviceContext.getInvitationHandler(invitation), this._serviceContext.metadataStore),
5248
5487
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
5249
5488
  SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, this._serviceContext.dataServiceSubscriptions, async () => {
5250
5489
  await this._serviceContext.initialized.wait();
5251
5490
  return this._serviceContext.dataSpaceManager;
5252
5491
  }),
5253
5492
  DataService: new DataServiceImpl(this._serviceContext.dataServiceSubscriptions, this._serviceContext.automergeHost),
5493
+ IndexService: new IndexServiceImpl({
5494
+ indexer: this._serviceContext.indexer,
5495
+ automergeHost: this._serviceContext.automergeHost
5496
+ }),
5254
5497
  NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager, this._serviceContext.signalManager),
5255
5498
  LoggingService: this._loggingService,
5256
5499
  TracingService: this._tracingService,
@@ -5262,6 +5505,24 @@ var ClientServicesHost = class {
5262
5505
  })
5263
5506
  });
5264
5507
  await this._serviceContext.open(ctx);
5508
+ invariant16(this.serviceRegistry.services.InvitationsService, void 0, {
5509
+ F: __dxlog_file18,
5510
+ L: 303,
5511
+ S: this,
5512
+ A: [
5513
+ "this.serviceRegistry.services.InvitationsService",
5514
+ ""
5515
+ ]
5516
+ });
5517
+ const loadedInvitations = await this.serviceRegistry.services.InvitationsService.loadPersistentInvitations();
5518
+ log16("loaded persistent invitations", {
5519
+ count: loadedInvitations.invitations?.length
5520
+ }, {
5521
+ F: __dxlog_file18,
5522
+ L: 306,
5523
+ S: this,
5524
+ C: (f, a) => f(...a)
5525
+ });
5265
5526
  const devtoolsProxy = this._config?.get("runtime.client.devtoolsProxy");
5266
5527
  if (devtoolsProxy) {
5267
5528
  this._devtoolsProxy = new WebsocketRpcClient({
@@ -5280,7 +5541,7 @@ var ClientServicesHost = class {
5280
5541
  deviceKey
5281
5542
  }, {
5282
5543
  F: __dxlog_file18,
5283
- L: 310,
5544
+ L: 323,
5284
5545
  S: this,
5285
5546
  C: (f, a) => f(...a)
5286
5547
  });
@@ -5288,7 +5549,7 @@ var ClientServicesHost = class {
5288
5549
  id: traceId
5289
5550
  }), {
5290
5551
  F: __dxlog_file18,
5291
- L: 311,
5552
+ L: 324,
5292
5553
  S: this,
5293
5554
  C: (f, a) => f(...a)
5294
5555
  });
@@ -5302,7 +5563,7 @@ var ClientServicesHost = class {
5302
5563
  deviceKey
5303
5564
  }, {
5304
5565
  F: __dxlog_file18,
5305
- L: 322,
5566
+ L: 335,
5306
5567
  S: this,
5307
5568
  C: (f, a) => f(...a)
5308
5569
  });
@@ -5318,24 +5579,24 @@ var ClientServicesHost = class {
5318
5579
  deviceKey
5319
5580
  }, {
5320
5581
  F: __dxlog_file18,
5321
- L: 329,
5582
+ L: 342,
5322
5583
  S: this,
5323
5584
  C: (f, a) => f(...a)
5324
5585
  });
5325
5586
  }
5326
5587
  async reset() {
5327
- const traceId = PublicKey11.random().toHex();
5588
+ const traceId = PublicKey12.random().toHex();
5328
5589
  log16.trace("dxos.sdk.client-services-host.reset", trace9.begin({
5329
5590
  id: traceId
5330
5591
  }), {
5331
5592
  F: __dxlog_file18,
5332
- L: 334,
5593
+ L: 347,
5333
5594
  S: this,
5334
5595
  C: (f, a) => f(...a)
5335
5596
  });
5336
5597
  log16("resetting...", void 0, {
5337
5598
  F: __dxlog_file18,
5338
- L: 336,
5599
+ L: 349,
5339
5600
  S: this,
5340
5601
  C: (f, a) => f(...a)
5341
5602
  });
@@ -5343,7 +5604,7 @@ var ClientServicesHost = class {
5343
5604
  await this._storage.reset();
5344
5605
  log16("reset", void 0, {
5345
5606
  F: __dxlog_file18,
5346
- L: 339,
5607
+ L: 352,
5347
5608
  S: this,
5348
5609
  C: (f, a) => f(...a)
5349
5610
  });
@@ -5351,7 +5612,7 @@ var ClientServicesHost = class {
5351
5612
  id: traceId
5352
5613
  }), {
5353
5614
  F: __dxlog_file18,
5354
- L: 340,
5615
+ L: 353,
5355
5616
  S: this,
5356
5617
  C: (f, a) => f(...a)
5357
5618
  });
@@ -5364,9 +5625,9 @@ var ClientServicesHost = class {
5364
5625
  const obj = new Properties(void 0);
5365
5626
  obj[defaultKey] = identity.identityKey.toHex();
5366
5627
  const automergeIndex = space.automergeSpaceState.rootUrl;
5367
- invariant15(automergeIndex, void 0, {
5628
+ invariant16(automergeIndex, void 0, {
5368
5629
  F: __dxlog_file18,
5369
- L: 355,
5630
+ L: 368,
5370
5631
  S: this,
5371
5632
  A: [
5372
5633
  "automergeIndex",
@@ -5421,6 +5682,7 @@ export {
5421
5682
  IdentityServiceImpl,
5422
5683
  DeviceInvitationProtocol,
5423
5684
  InvitationsHandler,
5685
+ invitationExpired,
5424
5686
  InvitationsServiceImpl,
5425
5687
  SpaceInvitationProtocol,
5426
5688
  ClientRpcServer,
@@ -5436,4 +5698,4 @@ export {
5436
5698
  createDefaultModelFactory,
5437
5699
  ClientServicesHost
5438
5700
  };
5439
- //# sourceMappingURL=chunk-NTKD4OQC.mjs.map
5701
+ //# sourceMappingURL=chunk-EQPR3Z5Y.mjs.map