@dxos/client-services 0.4.10-main.4c8c73c → 0.4.10-main.4d26ea7

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 (68) hide show
  1. package/dist/lib/browser/{chunk-F4LOSBRJ.mjs → chunk-X462P3GQ.mjs} +425 -416
  2. package/dist/lib/browser/chunk-X462P3GQ.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +6 -4
  4. package/dist/lib/browser/index.mjs.map +3 -3
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +131 -116
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/{chunk-IPO3WM44.cjs → chunk-LE3INNLG.cjs} +527 -514
  9. package/dist/lib/node/chunk-LE3INNLG.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +48 -46
  11. package/dist/lib/node/index.cjs.map +3 -3
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/packlets/testing/index.cjs +130 -118
  14. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  15. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  16. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +3 -1
  17. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
  18. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +6 -1
  19. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
  20. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +4 -2
  21. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  22. package/dist/types/src/packlets/invitations/invitations-manager.d.ts +9 -7
  23. package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -1
  24. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  25. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +2 -1
  26. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  27. package/dist/types/src/packlets/services/service-context.d.ts +4 -6
  28. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  29. package/dist/types/src/packlets/services/service-host.d.ts +0 -1
  30. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  31. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +8 -3
  32. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  33. package/dist/types/src/packlets/spaces/data-space.d.ts +4 -3
  34. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  35. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  36. package/dist/types/src/packlets/testing/test-builder.d.ts +7 -3
  37. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  38. package/dist/types/src/packlets/vault/worker-runtime.d.ts.map +1 -1
  39. package/dist/types/src/version.d.ts +1 -1
  40. package/package.json +34 -34
  41. package/src/packlets/identity/identity-manager.ts +1 -0
  42. package/src/packlets/identity/identity.test.ts +3 -0
  43. package/src/packlets/invitations/device-invitation-protocol.ts +6 -1
  44. package/src/packlets/invitations/invitation-protocol.ts +7 -1
  45. package/src/packlets/invitations/invitations-handler.ts +10 -71
  46. package/src/packlets/invitations/invitations-manager.ts +114 -40
  47. package/src/packlets/invitations/invitations-service.ts +4 -2
  48. package/src/packlets/invitations/space-invitation-protocol.ts +45 -3
  49. package/src/packlets/services/automerge-host.test.ts +1 -1
  50. package/src/packlets/services/service-context.test.ts +3 -3
  51. package/src/packlets/services/service-context.ts +12 -25
  52. package/src/packlets/services/service-host.test.ts +6 -0
  53. package/src/packlets/services/service-host.ts +5 -21
  54. package/src/packlets/spaces/data-space-manager.test.ts +4 -4
  55. package/src/packlets/spaces/data-space-manager.ts +56 -13
  56. package/src/packlets/spaces/data-space.ts +14 -19
  57. package/src/packlets/testing/invitation-utils.ts +100 -97
  58. package/src/packlets/testing/test-builder.ts +27 -14
  59. package/src/packlets/vault/worker-runtime.ts +3 -1
  60. package/src/version.ts +1 -1
  61. package/dist/lib/browser/chunk-F4LOSBRJ.mjs.map +0 -7
  62. package/dist/lib/node/chunk-IPO3WM44.cjs.map +0 -7
  63. package/dist/types/src/packlets/indexing/index.d.ts +0 -2
  64. package/dist/types/src/packlets/indexing/index.d.ts.map +0 -1
  65. package/dist/types/src/packlets/indexing/util.d.ts +0 -16
  66. package/dist/types/src/packlets/indexing/util.d.ts.map +0 -1
  67. package/src/packlets/indexing/index.ts +0 -5
  68. package/src/packlets/indexing/util.ts +0 -96
@@ -1086,7 +1086,9 @@ var IdentityManager = class {
1086
1086
  C: (f, a) => f(...a)
1087
1087
  });
1088
1088
  },
1089
- memberKey: identityKey
1089
+ memberKey: identityKey,
1090
+ onDelegatedInvitationStatusChange: async () => {
1091
+ }
1090
1092
  });
1091
1093
  }
1092
1094
  };
@@ -1194,10 +1196,13 @@ var DeviceInvitationProtocol = class {
1194
1196
  kind: Invitation.Kind.DEVICE
1195
1197
  };
1196
1198
  }
1197
- async admit(request) {
1199
+ async delegate(invitation) {
1200
+ throw new Error("delegation not supported");
1201
+ }
1202
+ async admit(_, request) {
1198
1203
  invariant4(request.device, void 0, {
1199
1204
  F: __dxlog_file5,
1200
- L: 37,
1205
+ L: 42,
1201
1206
  S: this,
1202
1207
  A: [
1203
1208
  "request.device",
@@ -1243,7 +1248,7 @@ var DeviceInvitationProtocol = class {
1243
1248
  async accept(response, request) {
1244
1249
  invariant4(response.device, void 0, {
1245
1250
  F: __dxlog_file5,
1246
- L: 82,
1251
+ L: 87,
1247
1252
  S: this,
1248
1253
  A: [
1249
1254
  "response.device",
@@ -1253,7 +1258,7 @@ var DeviceInvitationProtocol = class {
1253
1258
  const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
1254
1259
  invariant4(request.device, void 0, {
1255
1260
  F: __dxlog_file5,
1256
- L: 85,
1261
+ L: 90,
1257
1262
  S: this,
1258
1263
  A: [
1259
1264
  "request.device",
@@ -1279,9 +1284,8 @@ var DeviceInvitationProtocol = class {
1279
1284
 
1280
1285
  // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
1281
1286
  import { PushStream, scheduleTask as scheduleTask2, TimeoutError, Trigger as Trigger3 } from "@dxos/async";
1282
- import { AuthenticatingInvitation, AUTHENTICATION_CODE_LENGTH, CancellableInvitation, INVITATION_TIMEOUT } from "@dxos/client-protocol";
1287
+ import { AuthenticatingInvitation, INVITATION_TIMEOUT } from "@dxos/client-protocol";
1283
1288
  import { Context as Context5 } from "@dxos/context";
1284
- import { generatePasscode } from "@dxos/credentials";
1285
1289
  import { createKeyPair, sign } from "@dxos/crypto";
1286
1290
  import { invariant as invariant6 } from "@dxos/invariant";
1287
1291
  import { PublicKey as PublicKey6 } from "@dxos/keys";
@@ -1656,51 +1660,7 @@ var InvitationsHandler = class {
1656
1660
  constructor(_networkManager) {
1657
1661
  this._networkManager = _networkManager;
1658
1662
  }
1659
- createInvitation(protocol, options) {
1660
- 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 = options?.authMethod !== Invitation3.AuthMethod.KNOWN_PUBLIC_KEY, created = /* @__PURE__ */ new Date(), guestKeypair = void 0, lifetime = 86400, multiUse = false } = options ?? {};
1661
- const authCode = options?.authCode ?? (authMethod === Invitation3.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0);
1662
- invariant6(protocol, void 0, {
1663
- F: __dxlog_file7,
1664
- L: 87,
1665
- S: this,
1666
- A: [
1667
- "protocol",
1668
- ""
1669
- ]
1670
- });
1671
- const invitation = {
1672
- invitationId,
1673
- type,
1674
- authMethod,
1675
- state,
1676
- swarmKey,
1677
- authCode,
1678
- timeout,
1679
- persistent: persistent && type !== Invitation3.Type.DELEGATED,
1680
- guestKeypair: guestKeypair ?? (authMethod === Invitation3.AuthMethod.KNOWN_PUBLIC_KEY ? createAdmissionKeypair() : void 0),
1681
- created,
1682
- lifetime,
1683
- multiUse,
1684
- ...protocol.getInvitationContext()
1685
- };
1686
- const stream = new PushStream();
1687
- const ctx = new Context5({
1688
- onError: (err) => {
1689
- stream.error(err);
1690
- void ctx.dispose();
1691
- }
1692
- });
1693
- ctx.onDispose(() => {
1694
- log5("complete", {
1695
- ...protocol.toJSON()
1696
- }, {
1697
- F: __dxlog_file7,
1698
- L: 115,
1699
- S: this,
1700
- C: (f, a) => f(...a)
1701
- });
1702
- stream.complete();
1703
- });
1663
+ handleInvitationFlow(ctx, stream, protocol, invitation) {
1704
1664
  const createExtension = () => {
1705
1665
  const extension = new InvitationHostExtension({
1706
1666
  onStateUpdate: (invitation2) => {
@@ -1709,8 +1669,8 @@ var InvitationsHandler = class {
1709
1669
  state: Invitation3.State.READY_FOR_AUTHENTICATION
1710
1670
  });
1711
1671
  },
1712
- resolveInvitation: async ({ invitationId: invitationId2 }) => {
1713
- if (invitationId2 && invitationId2 !== invitation.invitationId) {
1672
+ resolveInvitation: async ({ invitationId }) => {
1673
+ if (invitationId && invitationId !== invitation.invitationId) {
1714
1674
  return void 0;
1715
1675
  }
1716
1676
  return invitation;
@@ -1720,14 +1680,14 @@ var InvitationsHandler = class {
1720
1680
  const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
1721
1681
  invariant6(deviceKey, void 0, {
1722
1682
  F: __dxlog_file7,
1723
- L: 136,
1683
+ L: 87,
1724
1684
  S: this,
1725
1685
  A: [
1726
1686
  "deviceKey",
1727
1687
  ""
1728
1688
  ]
1729
1689
  });
1730
- const admissionResponse = await protocol.admit(admissionRequest, extension.guestProfile);
1690
+ const admissionResponse = await protocol.admit(invitation, admissionRequest, extension.guestProfile);
1731
1691
  extension.completedTrigger.wake(deviceKey);
1732
1692
  return admissionResponse;
1733
1693
  } catch (err) {
@@ -1743,7 +1703,7 @@ var InvitationsHandler = class {
1743
1703
  id: traceId
1744
1704
  }), {
1745
1705
  F: __dxlog_file7,
1746
- L: 154,
1706
+ L: 105,
1747
1707
  S: this,
1748
1708
  C: (f, a) => f(...a)
1749
1709
  });
@@ -1751,7 +1711,7 @@ var InvitationsHandler = class {
1751
1711
  ...protocol.toJSON()
1752
1712
  }, {
1753
1713
  F: __dxlog_file7,
1754
- L: 155,
1714
+ L: 106,
1755
1715
  S: this,
1756
1716
  C: (f, a) => f(...a)
1757
1717
  });
@@ -1760,14 +1720,14 @@ var InvitationsHandler = class {
1760
1720
  state: Invitation3.State.CONNECTED
1761
1721
  });
1762
1722
  const deviceKey = await extension.completedTrigger.wait({
1763
- timeout
1723
+ timeout: invitation.timeout
1764
1724
  });
1765
1725
  log5("admitted guest", {
1766
1726
  guest: deviceKey,
1767
1727
  ...protocol.toJSON()
1768
1728
  }, {
1769
1729
  F: __dxlog_file7,
1770
- L: 158,
1730
+ L: 109,
1771
1731
  S: this,
1772
1732
  C: (f, a) => f(...a)
1773
1733
  });
@@ -1779,7 +1739,7 @@ var InvitationsHandler = class {
1779
1739
  id: traceId
1780
1740
  }), {
1781
1741
  F: __dxlog_file7,
1782
- L: 160,
1742
+ L: 111,
1783
1743
  S: this,
1784
1744
  C: (f, a) => f(...a)
1785
1745
  });
@@ -1789,7 +1749,7 @@ var InvitationsHandler = class {
1789
1749
  ...protocol.toJSON()
1790
1750
  }, {
1791
1751
  F: __dxlog_file7,
1792
- L: 163,
1752
+ L: 114,
1793
1753
  S: this,
1794
1754
  C: (f, a) => f(...a)
1795
1755
  });
@@ -1800,7 +1760,7 @@ var InvitationsHandler = class {
1800
1760
  } else {
1801
1761
  log5.error("failed", err, {
1802
1762
  F: __dxlog_file7,
1803
- L: 166,
1763
+ L: 117,
1804
1764
  S: this,
1805
1765
  C: (f, a) => f(...a)
1806
1766
  });
@@ -1811,12 +1771,12 @@ var InvitationsHandler = class {
1811
1771
  error: err
1812
1772
  }), {
1813
1773
  F: __dxlog_file7,
1814
- L: 169,
1774
+ L: 120,
1815
1775
  S: this,
1816
1776
  C: (f, a) => f(...a)
1817
1777
  });
1818
1778
  } finally {
1819
- if (!multiUse) {
1779
+ if (!invitation.multiUse) {
1820
1780
  await swarmConnection.close();
1821
1781
  await ctx.dispose();
1822
1782
  }
@@ -1832,7 +1792,7 @@ var InvitationsHandler = class {
1832
1792
  ...protocol.toJSON()
1833
1793
  }, {
1834
1794
  F: __dxlog_file7,
1835
- L: 184,
1795
+ L: 135,
1836
1796
  S: this,
1837
1797
  C: (f, a) => f(...a)
1838
1798
  });
@@ -1843,7 +1803,7 @@ var InvitationsHandler = class {
1843
1803
  } else {
1844
1804
  log5.error("failed", err, {
1845
1805
  F: __dxlog_file7,
1846
- L: 187,
1806
+ L: 138,
1847
1807
  S: this,
1848
1808
  C: (f, a) => f(...a)
1849
1809
  });
@@ -1857,7 +1817,7 @@ var InvitationsHandler = class {
1857
1817
  if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
1858
1818
  log5.warn("invitation has already expired", void 0, {
1859
1819
  F: __dxlog_file7,
1860
- L: 198,
1820
+ L: 149,
1861
1821
  S: this,
1862
1822
  C: (f, a) => f(...a)
1863
1823
  });
@@ -1891,24 +1851,12 @@ var InvitationsHandler = class {
1891
1851
  state: Invitation3.State.CONNECTING
1892
1852
  });
1893
1853
  });
1894
- const observable = new CancellableInvitation({
1895
- initialInvitation: invitation,
1896
- subscriber: stream.observable,
1897
- onCancel: async () => {
1898
- stream.next({
1899
- ...invitation,
1900
- state: Invitation3.State.CANCELLED
1901
- });
1902
- await ctx.dispose();
1903
- }
1904
- });
1905
- return observable;
1906
1854
  }
1907
1855
  acceptInvitation(protocol, invitation, deviceProfile) {
1908
1856
  const { timeout = INVITATION_TIMEOUT } = invitation;
1909
1857
  invariant6(protocol, void 0, {
1910
1858
  F: __dxlog_file7,
1911
- L: 252,
1859
+ L: 191,
1912
1860
  S: this,
1913
1861
  A: [
1914
1862
  "protocol",
@@ -1918,7 +1866,7 @@ var InvitationsHandler = class {
1918
1866
  if (deviceProfile) {
1919
1867
  invariant6(invitation.kind === Invitation3.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
1920
1868
  F: __dxlog_file7,
1921
- L: 255,
1869
+ L: 194,
1922
1870
  S: this,
1923
1871
  A: [
1924
1872
  "invitation.kind === Invitation.Kind.DEVICE",
@@ -1933,7 +1881,7 @@ var InvitationsHandler = class {
1933
1881
  const setState = (newData) => {
1934
1882
  invariant6(newData.state !== void 0, void 0, {
1935
1883
  F: __dxlog_file7,
1936
- L: 266,
1884
+ L: 205,
1937
1885
  S: this,
1938
1886
  A: [
1939
1887
  "newData.state !== undefined",
@@ -1953,7 +1901,7 @@ var InvitationsHandler = class {
1953
1901
  ...protocol.toJSON()
1954
1902
  }, {
1955
1903
  F: __dxlog_file7,
1956
- L: 274,
1904
+ L: 213,
1957
1905
  S: this,
1958
1906
  C: (f, a) => f(...a)
1959
1907
  });
@@ -1963,7 +1911,7 @@ var InvitationsHandler = class {
1963
1911
  } else {
1964
1912
  log5.warn("auth failed", err, {
1965
1913
  F: __dxlog_file7,
1966
- L: 277,
1914
+ L: 216,
1967
1915
  S: this,
1968
1916
  C: (f, a) => f(...a)
1969
1917
  });
@@ -1977,7 +1925,7 @@ var InvitationsHandler = class {
1977
1925
  ...protocol.toJSON()
1978
1926
  }, {
1979
1927
  F: __dxlog_file7,
1980
- L: 285,
1928
+ L: 224,
1981
1929
  S: this,
1982
1930
  C: (f, a) => f(...a)
1983
1931
  });
@@ -1992,7 +1940,7 @@ var InvitationsHandler = class {
1992
1940
  currentState
1993
1941
  }, {
1994
1942
  F: __dxlog_file7,
1995
- L: 295,
1943
+ L: 234,
1996
1944
  S: this,
1997
1945
  C: (f, a) => f(...a)
1998
1946
  });
@@ -2007,7 +1955,7 @@ var InvitationsHandler = class {
2007
1955
  id: traceId
2008
1956
  }), {
2009
1957
  F: __dxlog_file7,
2010
- L: 304,
1958
+ L: 243,
2011
1959
  S: this,
2012
1960
  C: (f, a) => f(...a)
2013
1961
  });
@@ -2019,7 +1967,7 @@ var InvitationsHandler = class {
2019
1967
  ...protocol.toJSON()
2020
1968
  }, {
2021
1969
  F: __dxlog_file7,
2022
- L: 312,
1970
+ L: 251,
2023
1971
  S: this,
2024
1972
  C: (f, a) => f(...a)
2025
1973
  });
@@ -2030,7 +1978,7 @@ var InvitationsHandler = class {
2030
1978
  ...protocol.toJSON()
2031
1979
  }, {
2032
1980
  F: __dxlog_file7,
2033
- L: 316,
1981
+ L: 255,
2034
1982
  S: this,
2035
1983
  C: (f, a) => f(...a)
2036
1984
  });
@@ -2040,7 +1988,7 @@ var InvitationsHandler = class {
2040
1988
  response: introductionResponse
2041
1989
  }, {
2042
1990
  F: __dxlog_file7,
2043
- L: 320,
1991
+ L: 259,
2044
1992
  S: this,
2045
1993
  C: (f, a) => f(...a)
2046
1994
  });
@@ -2061,7 +2009,7 @@ var InvitationsHandler = class {
2061
2009
  ...protocol.toJSON()
2062
2010
  }, {
2063
2011
  F: __dxlog_file7,
2064
- L: 336,
2012
+ L: 275,
2065
2013
  S: this,
2066
2014
  C: (f, a) => f(...a)
2067
2015
  });
@@ -2073,7 +2021,7 @@ var InvitationsHandler = class {
2073
2021
  ...protocol.toJSON()
2074
2022
  }, {
2075
2023
  F: __dxlog_file7,
2076
- L: 347,
2024
+ L: 286,
2077
2025
  S: this,
2078
2026
  C: (f, a) => f(...a)
2079
2027
  });
@@ -2086,7 +2034,7 @@ var InvitationsHandler = class {
2086
2034
  id: traceId
2087
2035
  }), {
2088
2036
  F: __dxlog_file7,
2089
- L: 349,
2037
+ L: 288,
2090
2038
  S: this,
2091
2039
  C: (f, a) => f(...a)
2092
2040
  });
@@ -2096,7 +2044,7 @@ var InvitationsHandler = class {
2096
2044
  ...protocol.toJSON()
2097
2045
  }, {
2098
2046
  F: __dxlog_file7,
2099
- L: 352,
2047
+ L: 291,
2100
2048
  S: this,
2101
2049
  C: (f, a) => f(...a)
2102
2050
  });
@@ -2106,7 +2054,7 @@ var InvitationsHandler = class {
2106
2054
  } else {
2107
2055
  log5("auth failed", err, {
2108
2056
  F: __dxlog_file7,
2109
- L: 355,
2057
+ L: 294,
2110
2058
  S: this,
2111
2059
  C: (f, a) => f(...a)
2112
2060
  });
@@ -2117,7 +2065,7 @@ var InvitationsHandler = class {
2117
2065
  error: err
2118
2066
  }), {
2119
2067
  F: __dxlog_file7,
2120
- L: 358,
2068
+ L: 297,
2121
2069
  S: this,
2122
2070
  C: (f, a) => f(...a)
2123
2071
  });
@@ -2135,7 +2083,7 @@ var InvitationsHandler = class {
2135
2083
  ...protocol.toJSON()
2136
2084
  }, {
2137
2085
  F: __dxlog_file7,
2138
- L: 369,
2086
+ L: 308,
2139
2087
  S: this,
2140
2088
  C: (f, a) => f(...a)
2141
2089
  });
@@ -2145,7 +2093,7 @@ var InvitationsHandler = class {
2145
2093
  } else {
2146
2094
  log5("auth failed", err, {
2147
2095
  F: __dxlog_file7,
2148
- L: 372,
2096
+ L: 311,
2149
2097
  S: this,
2150
2098
  C: (f, a) => f(...a)
2151
2099
  });
@@ -2162,7 +2110,7 @@ var InvitationsHandler = class {
2162
2110
  } else {
2163
2111
  invariant6(invitation.swarmKey, void 0, {
2164
2112
  F: __dxlog_file7,
2165
- L: 386,
2113
+ L: 325,
2166
2114
  S: this,
2167
2115
  A: [
2168
2116
  "invitation.swarmKey",
@@ -2204,7 +2152,7 @@ var InvitationsHandler = class {
2204
2152
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2205
2153
  log5("guest waiting for authentication code...", void 0, {
2206
2154
  F: __dxlog_file7,
2207
- L: 426,
2155
+ L: 365,
2208
2156
  S: this,
2209
2157
  C: (f, a) => f(...a)
2210
2158
  });
@@ -2214,7 +2162,7 @@ var InvitationsHandler = class {
2214
2162
  const authCode = await authenticated.wait(options);
2215
2163
  log5("sending authentication request", void 0, {
2216
2164
  F: __dxlog_file7,
2217
- L: 430,
2165
+ L: 369,
2218
2166
  S: this,
2219
2167
  C: (f, a) => f(...a)
2220
2168
  });
@@ -2235,7 +2183,7 @@ var InvitationsHandler = class {
2235
2183
  attempt
2236
2184
  }, {
2237
2185
  F: __dxlog_file7,
2238
- L: 441,
2186
+ L: 380,
2239
2187
  S: this,
2240
2188
  C: (f, a) => f(...a)
2241
2189
  });
@@ -2253,7 +2201,7 @@ var InvitationsHandler = class {
2253
2201
  }
2254
2202
  log5("sending authentication request", void 0, {
2255
2203
  F: __dxlog_file7,
2256
- L: 460,
2204
+ L: 399,
2257
2205
  S: this,
2258
2206
  C: (f, a) => f(...a)
2259
2207
  });
@@ -2289,9 +2237,8 @@ var InvitationsServiceImpl = class {
2289
2237
  return {};
2290
2238
  }
2291
2239
  createInvitation(options) {
2292
- const invitation = this._invitationsManager.createInvitation(options);
2293
2240
  return new Stream8(({ next, close }) => {
2294
- invitation.subscribe(next, close, close);
2241
+ void this._invitationsManager.createInvitation(options).then((invitation) => invitation.subscribe(next, close, close)).catch(close);
2295
2242
  });
2296
2243
  }
2297
2244
  acceptInvitation(request) {
@@ -2376,12 +2323,13 @@ var InvitationsServiceImpl = class {
2376
2323
  };
2377
2324
 
2378
2325
  // packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts
2379
- import { createAdmissionCredentials, getCredentialAssertion } from "@dxos/credentials";
2326
+ import { createAdmissionCredentials, createDelegatedSpaceInvitationCredential, getCredentialAssertion } from "@dxos/credentials";
2380
2327
  import { writeMessages as writeMessages2 } from "@dxos/feed-store";
2381
2328
  import { invariant as invariant7 } from "@dxos/invariant";
2382
2329
  import { log as log6 } from "@dxos/log";
2383
2330
  import { AlreadyJoinedError as AlreadyJoinedError2 } from "@dxos/protocols";
2384
2331
  import { Invitation as Invitation4 } from "@dxos/protocols/proto/dxos/client/services";
2332
+ import { SpaceMember } from "@dxos/protocols/proto/dxos/halo/credentials";
2385
2333
  var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
2386
2334
  var SpaceInvitationProtocol = class {
2387
2335
  constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
@@ -2402,10 +2350,10 @@ var SpaceInvitationProtocol = class {
2402
2350
  spaceKey: this._spaceKey
2403
2351
  };
2404
2352
  }
2405
- async admit(request, guestProfile) {
2353
+ async admit(invitation, request, guestProfile) {
2406
2354
  invariant7(this._spaceKey, void 0, {
2407
2355
  F: __dxlog_file8,
2408
- L: 47,
2356
+ L: 55,
2409
2357
  S: this,
2410
2358
  A: [
2411
2359
  "this._spaceKey",
@@ -2415,7 +2363,7 @@ var SpaceInvitationProtocol = class {
2415
2363
  const space = await this._spaceManager.spaces.get(this._spaceKey);
2416
2364
  invariant7(space, void 0, {
2417
2365
  F: __dxlog_file8,
2418
- L: 49,
2366
+ L: 57,
2419
2367
  S: this,
2420
2368
  A: [
2421
2369
  "space",
@@ -2424,7 +2372,7 @@ var SpaceInvitationProtocol = class {
2424
2372
  });
2425
2373
  invariant7(request.space, void 0, {
2426
2374
  F: __dxlog_file8,
2427
- L: 51,
2375
+ L: 59,
2428
2376
  S: this,
2429
2377
  A: [
2430
2378
  "request.space",
@@ -2437,14 +2385,14 @@ var SpaceInvitationProtocol = class {
2437
2385
  guest: deviceKey
2438
2386
  }, {
2439
2387
  F: __dxlog_file8,
2440
- L: 54,
2388
+ L: 62,
2441
2389
  S: this,
2442
2390
  C: (f, a) => f(...a)
2443
2391
  });
2444
- const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile);
2392
+ const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile, invitation.delegationCredentialId);
2445
2393
  invariant7(credentials[0].credential, void 0, {
2446
2394
  F: __dxlog_file8,
2447
- L: 65,
2395
+ L: 74,
2448
2396
  S: this,
2449
2397
  A: [
2450
2398
  "credentials[0].credential",
@@ -2454,7 +2402,7 @@ var SpaceInvitationProtocol = class {
2454
2402
  const spaceMemberCredential = credentials[0].credential.credential;
2455
2403
  invariant7(getCredentialAssertion(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2456
2404
  F: __dxlog_file8,
2457
- L: 67,
2405
+ L: 76,
2458
2406
  S: this,
2459
2407
  A: [
2460
2408
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2469,6 +2417,69 @@ var SpaceInvitationProtocol = class {
2469
2417
  }
2470
2418
  };
2471
2419
  }
2420
+ async delegate(invitation) {
2421
+ invariant7(this._spaceKey, void 0, {
2422
+ F: __dxlog_file8,
2423
+ L: 89,
2424
+ S: this,
2425
+ A: [
2426
+ "this._spaceKey",
2427
+ ""
2428
+ ]
2429
+ });
2430
+ const space = await this._spaceManager.spaces.get(this._spaceKey);
2431
+ invariant7(space, void 0, {
2432
+ F: __dxlog_file8,
2433
+ L: 91,
2434
+ S: this,
2435
+ A: [
2436
+ "space",
2437
+ ""
2438
+ ]
2439
+ });
2440
+ if (invitation.authMethod === Invitation4.AuthMethod.KNOWN_PUBLIC_KEY) {
2441
+ invariant7(invitation.guestKeypair?.publicKey, void 0, {
2442
+ F: __dxlog_file8,
2443
+ L: 93,
2444
+ S: this,
2445
+ A: [
2446
+ "invitation.guestKeypair?.publicKey",
2447
+ ""
2448
+ ]
2449
+ });
2450
+ }
2451
+ log6("writing delegate space invitation", {
2452
+ host: this._signingContext.deviceKey,
2453
+ id: invitation.invitationId
2454
+ }, {
2455
+ F: __dxlog_file8,
2456
+ L: 96,
2457
+ S: this,
2458
+ C: (f, a) => f(...a)
2459
+ });
2460
+ const credential = await createDelegatedSpaceInvitationCredential(this._signingContext.credentialSigner, space.key, {
2461
+ invitationId: invitation.invitationId,
2462
+ authMethod: invitation.authMethod,
2463
+ swarmKey: invitation.swarmKey,
2464
+ role: SpaceMember.Role.ADMIN,
2465
+ expiresOn: invitation.lifetime ? new Date((invitation.created?.getTime() ?? Date.now()) + invitation.lifetime) : void 0,
2466
+ multiUse: invitation.multiUse ?? false,
2467
+ guestKey: invitation.authMethod === Invitation4.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
2468
+ });
2469
+ invariant7(credential.credential, void 0, {
2470
+ F: __dxlog_file8,
2471
+ L: 116,
2472
+ S: this,
2473
+ A: [
2474
+ "credential.credential",
2475
+ ""
2476
+ ]
2477
+ });
2478
+ await writeMessages2(space.inner.controlPipeline.writer, [
2479
+ credential
2480
+ ]);
2481
+ return credential.credential.credential.id;
2482
+ }
2472
2483
  checkInvitation(invitation) {
2473
2484
  if (invitation.spaceKey && this._spaceManager.spaces.has(invitation.spaceKey)) {
2474
2485
  return new AlreadyJoinedError2("Already joined space.");
@@ -2494,7 +2505,7 @@ var SpaceInvitationProtocol = class {
2494
2505
  async accept(response) {
2495
2506
  invariant7(response.space, void 0, {
2496
2507
  F: __dxlog_file8,
2497
- L: 107,
2508
+ L: 149,
2498
2509
  S: this,
2499
2510
  A: [
2500
2511
  "response.space",
@@ -2505,7 +2516,7 @@ var SpaceInvitationProtocol = class {
2505
2516
  const assertion = getCredentialAssertion(credential);
2506
2517
  invariant7(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2507
2518
  F: __dxlog_file8,
2508
- L: 110,
2519
+ L: 152,
2509
2520
  S: this,
2510
2521
  A: [
2511
2522
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2514,7 +2525,7 @@ var SpaceInvitationProtocol = class {
2514
2525
  });
2515
2526
  invariant7(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
2516
2527
  F: __dxlog_file8,
2517
- L: 111,
2528
+ L: 153,
2518
2529
  S: this,
2519
2530
  A: [
2520
2531
  "credential.subject.id.equals(this._signingContext.identityKey)",
@@ -2538,10 +2549,15 @@ var SpaceInvitationProtocol = class {
2538
2549
  };
2539
2550
 
2540
2551
  // packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts
2541
- import { Event as Event3 } from "@dxos/async";
2552
+ import { Event as Event3, PushStream as PushStream2 } from "@dxos/async";
2553
+ import { AUTHENTICATION_CODE_LENGTH, CancellableInvitation, INVITATION_TIMEOUT as INVITATION_TIMEOUT2 } from "@dxos/client-protocol";
2554
+ import { Context as Context6 } from "@dxos/context";
2555
+ import { generatePasscode } from "@dxos/credentials";
2542
2556
  import { hasInvitationExpired } from "@dxos/echo-pipeline";
2543
2557
  import { invariant as invariant8 } from "@dxos/invariant";
2558
+ import { PublicKey as PublicKey7 } from "@dxos/keys";
2544
2559
  import { log as log7 } from "@dxos/log";
2560
+ import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
2545
2561
  var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
2546
2562
  var InvitationsManager = class {
2547
2563
  constructor(_invitationsHandler, _getHandler, _metadataStore) {
@@ -2558,25 +2574,39 @@ var InvitationsManager = class {
2558
2574
  this._persistentInvitationsLoadedEvent = new Event3();
2559
2575
  this._persistentInvitationsLoaded = false;
2560
2576
  }
2561
- createInvitation(options) {
2562
- const existingInvitation = this._createInvitations.get(options.invitationId);
2563
- if (existingInvitation) {
2564
- return existingInvitation;
2577
+ async createInvitation(options) {
2578
+ if (options.invitationId) {
2579
+ const existingInvitation = this._createInvitations.get(options.invitationId);
2580
+ if (existingInvitation) {
2581
+ return existingInvitation;
2582
+ }
2565
2583
  }
2566
2584
  const handler = this._getHandler(options);
2567
- const invitation = this._invitationsHandler.createInvitation(handler, options);
2568
- this._createInvitations.set(invitation.get().invitationId, invitation);
2569
- this.invitationCreated.emit(invitation.get());
2570
- const saveInvitationTask = invitation.get().persistent ? this._safePersistInBackground(invitation) : Promise.resolve();
2571
- this._onInvitationComplete(invitation, async () => {
2572
- this._createInvitations.delete(invitation.get().invitationId);
2573
- this.removedCreated.emit(invitation.get());
2574
- if (invitation.get().persistent) {
2575
- await saveInvitationTask;
2576
- await this._safeDeleteInvitation(invitation.get());
2585
+ const invitation = this._createInvitation(handler, options);
2586
+ const { ctx, stream, observableInvitation } = this._createObservableInvitation(handler, invitation);
2587
+ this._createInvitations.set(invitation.invitationId, observableInvitation);
2588
+ this.invitationCreated.emit(invitation);
2589
+ this._onInvitationComplete(observableInvitation, async () => {
2590
+ this._createInvitations.delete(observableInvitation.get().invitationId);
2591
+ this.removedCreated.emit(observableInvitation.get());
2592
+ if (observableInvitation.get().persistent) {
2593
+ await this._safeDeleteInvitation(observableInvitation.get());
2577
2594
  }
2578
2595
  });
2579
- return invitation;
2596
+ try {
2597
+ await this._persistIfRequired(handler, stream, invitation);
2598
+ } catch (err) {
2599
+ log7.catch(err, void 0, {
2600
+ F: __dxlog_file9,
2601
+ L: 76,
2602
+ S: this,
2603
+ C: (f, a) => f(...a)
2604
+ });
2605
+ await observableInvitation.cancel();
2606
+ return observableInvitation;
2607
+ }
2608
+ this._invitationsHandler.handleInvitationFlow(ctx, stream, handler, observableInvitation.get());
2609
+ return observableInvitation;
2580
2610
  }
2581
2611
  async loadPersistentInvitations() {
2582
2612
  if (this._persistentInvitationsLoaded) {
@@ -2588,10 +2618,10 @@ var InvitationsManager = class {
2588
2618
  try {
2589
2619
  const persistentInvitations = this._metadataStore.getInvitations();
2590
2620
  const freshInvitations = persistentInvitations.filter((invitation) => !hasInvitationExpired(invitation));
2591
- const cInvitations = freshInvitations.map((persistentInvitation) => {
2621
+ const loadTasks = freshInvitations.map((persistentInvitation) => {
2592
2622
  invariant8(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
2593
2623
  F: __dxlog_file9,
2594
- L: 82,
2624
+ L: 97,
2595
2625
  S: this,
2596
2626
  A: [
2597
2627
  "!this._createInvitations.get(persistentInvitation.invitationId)",
@@ -2601,15 +2631,16 @@ var InvitationsManager = class {
2601
2631
  return this.createInvitation({
2602
2632
  ...persistentInvitation,
2603
2633
  persistent: false
2604
- }).get();
2634
+ });
2605
2635
  });
2636
+ const cInvitations = await Promise.all(loadTasks);
2606
2637
  return {
2607
- invitations: cInvitations
2638
+ invitations: cInvitations.map((invitation) => invitation.get())
2608
2639
  };
2609
2640
  } catch (err) {
2610
2641
  log7.catch(err, void 0, {
2611
2642
  F: __dxlog_file9,
2612
- L: 88,
2643
+ L: 104,
2613
2644
  S: this,
2614
2645
  C: (f, a) => f(...a)
2615
2646
  });
@@ -2640,13 +2671,13 @@ var InvitationsManager = class {
2640
2671
  async authenticate({ invitationId, authCode }) {
2641
2672
  log7("authenticating...", void 0, {
2642
2673
  F: __dxlog_file9,
2643
- L: 117,
2674
+ L: 133,
2644
2675
  S: this,
2645
2676
  C: (f, a) => f(...a)
2646
2677
  });
2647
2678
  invariant8(invitationId, void 0, {
2648
2679
  F: __dxlog_file9,
2649
- L: 118,
2680
+ L: 134,
2650
2681
  S: this,
2651
2682
  A: [
2652
2683
  "invitationId",
@@ -2659,7 +2690,7 @@ var InvitationsManager = class {
2659
2690
  invitationId
2660
2691
  }, {
2661
2692
  F: __dxlog_file9,
2662
- L: 121,
2693
+ L: 137,
2663
2694
  S: this,
2664
2695
  C: (f, a) => f(...a)
2665
2696
  });
@@ -2672,13 +2703,13 @@ var InvitationsManager = class {
2672
2703
  invitationId
2673
2704
  }, {
2674
2705
  F: __dxlog_file9,
2675
- L: 128,
2706
+ L: 144,
2676
2707
  S: this,
2677
2708
  C: (f, a) => f(...a)
2678
2709
  });
2679
2710
  invariant8(invitationId, void 0, {
2680
2711
  F: __dxlog_file9,
2681
- L: 129,
2712
+ L: 145,
2682
2713
  S: this,
2683
2714
  A: [
2684
2715
  "invitationId",
@@ -2719,25 +2750,73 @@ var InvitationsManager = class {
2719
2750
  this._persistentInvitationsLoadedEvent.once(ctx, () => callback());
2720
2751
  }
2721
2752
  }
2722
- _safePersistInBackground(invitation) {
2723
- return new Promise((resolve) => {
2724
- setTimeout(async () => {
2725
- try {
2726
- await this._metadataStore.addInvitation(invitation.get());
2727
- this.saved.emit(invitation.get());
2728
- } catch (err) {
2729
- log7.catch(err, void 0, {
2730
- F: __dxlog_file9,
2731
- L: 173,
2732
- S: this,
2733
- C: (f, a) => f(...a)
2734
- });
2735
- await invitation.cancel();
2736
- } finally {
2737
- resolve();
2738
- }
2753
+ _createInvitation(protocol, options) {
2754
+ const { invitationId = PublicKey7.random().toHex(), type = Invitation5.Type.INTERACTIVE, authMethod = Invitation5.AuthMethod.SHARED_SECRET, state = Invitation5.State.INIT, timeout = INVITATION_TIMEOUT2, swarmKey = PublicKey7.random(), persistent = options?.authMethod !== Invitation5.AuthMethod.KNOWN_PUBLIC_KEY, created = /* @__PURE__ */ new Date(), guestKeypair = void 0, lifetime = 86400, multiUse = false } = options ?? {};
2755
+ const authCode = options?.authCode ?? (authMethod === Invitation5.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0);
2756
+ return {
2757
+ invitationId,
2758
+ type,
2759
+ authMethod,
2760
+ state,
2761
+ swarmKey,
2762
+ authCode,
2763
+ timeout,
2764
+ persistent: persistent && type !== Invitation5.Type.DELEGATED,
2765
+ guestKeypair: guestKeypair ?? (authMethod === Invitation5.AuthMethod.KNOWN_PUBLIC_KEY ? createAdmissionKeypair() : void 0),
2766
+ created,
2767
+ lifetime,
2768
+ multiUse,
2769
+ delegationCredentialId: options?.delegationCredentialId,
2770
+ ...protocol.getInvitationContext()
2771
+ };
2772
+ }
2773
+ _createObservableInvitation(handler, invitation) {
2774
+ const stream = new PushStream2();
2775
+ const ctx = new Context6({
2776
+ onError: (err) => {
2777
+ stream.error(err);
2778
+ void ctx.dispose();
2779
+ }
2780
+ });
2781
+ ctx.onDispose(() => {
2782
+ log7("complete", {
2783
+ ...handler.toJSON()
2784
+ }, {
2785
+ F: __dxlog_file9,
2786
+ L: 228,
2787
+ S: this,
2788
+ C: (f, a) => f(...a)
2739
2789
  });
2790
+ stream.complete();
2791
+ });
2792
+ const observableInvitation = new CancellableInvitation({
2793
+ initialInvitation: invitation,
2794
+ subscriber: stream.observable,
2795
+ onCancel: async () => {
2796
+ stream.next({
2797
+ ...invitation,
2798
+ state: Invitation5.State.CANCELLED
2799
+ });
2800
+ await ctx.dispose();
2801
+ }
2740
2802
  });
2803
+ return {
2804
+ ctx,
2805
+ stream,
2806
+ observableInvitation
2807
+ };
2808
+ }
2809
+ async _persistIfRequired(handler, changeStream, invitation) {
2810
+ if (invitation.type === Invitation5.Type.DELEGATED && invitation.delegationCredentialId == null) {
2811
+ const delegationCredentialId = await handler.delegate(invitation);
2812
+ changeStream.next({
2813
+ ...invitation,
2814
+ delegationCredentialId
2815
+ });
2816
+ } else if (invitation.persistent) {
2817
+ await this._metadataStore.addInvitation(invitation);
2818
+ this.saved.emit(invitation);
2819
+ }
2741
2820
  }
2742
2821
  async _safeDeleteInvitation(invitation) {
2743
2822
  try {
@@ -2745,7 +2824,7 @@ var InvitationsManager = class {
2745
2824
  } catch (err) {
2746
2825
  log7.catch(err, void 0, {
2747
2826
  F: __dxlog_file9,
2748
- L: 186,
2827
+ L: 260,
2749
2828
  S: this,
2750
2829
  C: (f, a) => f(...a)
2751
2830
  });
@@ -2842,13 +2921,13 @@ ClientRpcServer = _ts_decorate3([
2842
2921
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2843
2922
  import { Event as Event6, asyncTimeout, scheduleTask as scheduleTask4, sleep as sleep2, synchronized, trackLeaks } from "@dxos/async";
2844
2923
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
2845
- import { cancelWithContext as cancelWithContext2, Context as Context7, ContextDisposedError } from "@dxos/context";
2924
+ import { cancelWithContext as cancelWithContext2, Context as Context8, ContextDisposedError } from "@dxos/context";
2846
2925
  import { timed, warnAfterTimeout } from "@dxos/debug";
2847
- import { TYPE_PROPERTIES } from "@dxos/echo-db";
2848
2926
  import { createMappedFeedWriter } from "@dxos/echo-pipeline";
2849
2927
  import { AutomergeDocumentLoaderImpl } from "@dxos/echo-pipeline";
2928
+ import { TYPE_PROPERTIES } from "@dxos/echo-schema";
2850
2929
  import { failedInvariant, invariant as invariant10 } from "@dxos/invariant";
2851
- import { PublicKey as PublicKey8 } from "@dxos/keys";
2930
+ import { PublicKey as PublicKey9 } from "@dxos/keys";
2852
2931
  import { log as log9 } from "@dxos/log";
2853
2932
  import { CancelledError, SystemError } from "@dxos/protocols";
2854
2933
  import { SpaceState, CreateEpochRequest } from "@dxos/protocols/proto/dxos/client/services";
@@ -2897,9 +2976,9 @@ var AutomergeSpaceState = class {
2897
2976
 
2898
2977
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
2899
2978
  import { DeferredTask, Event as Event5, scheduleTask as scheduleTask3, sleep, TimeoutError as TimeoutError2, Trigger as Trigger4 } from "@dxos/async";
2900
- import { Context as Context6, rejectOnDispose } from "@dxos/context";
2979
+ import { Context as Context7, rejectOnDispose } from "@dxos/context";
2901
2980
  import { invariant as invariant9 } from "@dxos/invariant";
2902
- import { PublicKey as PublicKey7 } from "@dxos/keys";
2981
+ import { PublicKey as PublicKey8 } from "@dxos/keys";
2903
2982
  import { log as log8 } from "@dxos/log";
2904
2983
  import { schema as schema3 } from "@dxos/protocols";
2905
2984
  import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
@@ -2911,11 +2990,11 @@ var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
2911
2990
  var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
2912
2991
  var NotarizationPlugin = class {
2913
2992
  constructor() {
2914
- this._ctx = new Context6();
2993
+ this._ctx = new Context7();
2915
2994
  this._extensionOpened = new Event5();
2916
2995
  this._extensions = /* @__PURE__ */ new Set();
2917
- this._processedCredentials = new ComplexSet2(PublicKey7.hash);
2918
- this._processCredentialsTriggers = new ComplexMap2(PublicKey7.hash);
2996
+ this._processedCredentials = new ComplexSet2(PublicKey8.hash);
2997
+ this._processCredentialsTriggers = new ComplexMap2(PublicKey8.hash);
2919
2998
  }
2920
2999
  get hasWriter() {
2921
3000
  return !!this._writer;
@@ -3177,7 +3256,7 @@ function _ts_decorate4(decorators, target, key, desc) {
3177
3256
  var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
3178
3257
  var DataSpace = class {
3179
3258
  constructor(params) {
3180
- this._ctx = new Context7();
3259
+ this._ctx = new Context8();
3181
3260
  this._notarizationPlugin = new NotarizationPlugin();
3182
3261
  this._cache = void 0;
3183
3262
  // TODO(dmaretskyi): Move into Space?
@@ -3198,9 +3277,9 @@ var DataSpace = class {
3198
3277
  this._metadataStore = params.metadataStore;
3199
3278
  this._signingContext = params.signingContext;
3200
3279
  this._callbacks = params.callbacks ?? {};
3201
- this._automergeHost = params.automergeHost;
3280
+ this._echoHost = params.echoHost;
3202
3281
  this.authVerifier = new TrustedKeySetAuthVerifier({
3203
- trustedKeysProvider: () => new ComplexSet3(PublicKey8.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => !member.removed).map((member) => member.key)),
3282
+ trustedKeysProvider: () => new ComplexSet3(PublicKey9.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => !member.removed).map((member) => member.key)),
3204
3283
  update: this._inner.stateUpdate,
3205
3284
  authTimeout: AUTH_TIMEOUT2
3206
3285
  });
@@ -3210,7 +3289,7 @@ var DataSpace = class {
3210
3289
  state: SpaceState[this._state]
3211
3290
  }, {
3212
3291
  F: __dxlog_file11,
3213
- L: 140,
3292
+ L: 135,
3214
3293
  S: this,
3215
3294
  C: (f, a) => f(...a)
3216
3295
  });
@@ -3254,13 +3333,13 @@ var DataSpace = class {
3254
3333
  await this._notarizationPlugin.open();
3255
3334
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
3256
3335
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
3257
- await this._inner.open(new Context7());
3336
+ await this._inner.open(new Context8());
3258
3337
  this._state = SpaceState.CONTROL_ONLY;
3259
3338
  log9("new state", {
3260
3339
  state: SpaceState[this._state]
3261
3340
  }, {
3262
3341
  F: __dxlog_file11,
3263
- L: 198,
3342
+ L: 193,
3264
3343
  S: this,
3265
3344
  C: (f, a) => f(...a)
3266
3345
  });
@@ -3278,12 +3357,12 @@ var DataSpace = class {
3278
3357
  state: SpaceState[this._state]
3279
3358
  }, {
3280
3359
  F: __dxlog_file11,
3281
- L: 212,
3360
+ L: 207,
3282
3361
  S: this,
3283
3362
  C: (f, a) => f(...a)
3284
3363
  });
3285
3364
  await this._ctx.dispose();
3286
- this._ctx = new Context7();
3365
+ this._ctx = new Context8();
3287
3366
  await this.authVerifier.close();
3288
3367
  await this._inner.close();
3289
3368
  await this._inner.spaceState.removeCredentialProcessor(this._automergeSpaceState);
@@ -3310,7 +3389,7 @@ var DataSpace = class {
3310
3389
  if (err instanceof CancelledError || err instanceof ContextDisposedError) {
3311
3390
  log9("data pipeline initialization cancelled", err, {
3312
3391
  F: __dxlog_file11,
3313
- L: 245,
3392
+ L: 240,
3314
3393
  S: this,
3315
3394
  C: (f, a) => f(...a)
3316
3395
  });
@@ -3318,7 +3397,7 @@ var DataSpace = class {
3318
3397
  }
3319
3398
  log9.error("Error initializing data pipeline", err, {
3320
3399
  F: __dxlog_file11,
3321
- L: 249,
3400
+ L: 244,
3322
3401
  S: this,
3323
3402
  C: (f, a) => f(...a)
3324
3403
  });
@@ -3327,7 +3406,7 @@ var DataSpace = class {
3327
3406
  state: SpaceState[this._state]
3328
3407
  }, {
3329
3408
  F: __dxlog_file11,
3330
- L: 251,
3409
+ L: 246,
3331
3410
  S: this,
3332
3411
  C: (f, a) => f(...a)
3333
3412
  });
@@ -3347,7 +3426,7 @@ var DataSpace = class {
3347
3426
  state: SpaceState[this._state]
3348
3427
  }, {
3349
3428
  F: __dxlog_file11,
3350
- L: 267,
3429
+ L: 262,
3351
3430
  S: this,
3352
3431
  C: (f, a) => f(...a)
3353
3432
  });
@@ -3357,7 +3436,7 @@ var DataSpace = class {
3357
3436
  await cancelWithContext2(this._ctx, this.automergeSpaceState.ensureEpochInitialized());
3358
3437
  log9("data pipeline ready", void 0, {
3359
3438
  F: __dxlog_file11,
3360
- L: 279,
3439
+ L: 274,
3361
3440
  S: this,
3362
3441
  C: (f, a) => f(...a)
3363
3442
  });
@@ -3367,7 +3446,7 @@ var DataSpace = class {
3367
3446
  state: SpaceState[this._state]
3368
3447
  }, {
3369
3448
  F: __dxlog_file11,
3370
- L: 283,
3449
+ L: 278,
3371
3450
  S: this,
3372
3451
  C: (f, a) => f(...a)
3373
3452
  });
@@ -3383,7 +3462,7 @@ var DataSpace = class {
3383
3462
  await this._createWritableFeeds();
3384
3463
  log9("writable feeds created", void 0, {
3385
3464
  F: __dxlog_file11,
3386
- L: 299,
3465
+ L: 294,
3387
3466
  S: this,
3388
3467
  C: (f, a) => f(...a)
3389
3468
  });
@@ -3446,12 +3525,12 @@ var DataSpace = class {
3446
3525
  rootUrl
3447
3526
  }, {
3448
3527
  F: __dxlog_file11,
3449
- L: 365,
3528
+ L: 360,
3450
3529
  S: this,
3451
3530
  C: (f, a) => f(...a)
3452
3531
  });
3453
- this._automergeHost._requestedDocs.add(rootUrl);
3454
- const handle = this._automergeHost.repo.find(rootUrl);
3532
+ this._echoHost.replicateDocument(rootUrl);
3533
+ const handle = this._echoHost.automergeRepo.find(rootUrl);
3455
3534
  queueMicrotask(async () => {
3456
3535
  try {
3457
3536
  await warnAfterTimeout(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
@@ -3478,7 +3557,7 @@ var DataSpace = class {
3478
3557
  err
3479
3558
  }, {
3480
3559
  F: __dxlog_file11,
3481
- L: 388,
3560
+ L: 383,
3482
3561
  S: this,
3483
3562
  C: (f, a) => f(...a)
3484
3563
  });
@@ -3516,7 +3595,7 @@ var DataSpace = class {
3516
3595
  break;
3517
3596
  case CreateEpochRequest.Migration.INIT_AUTOMERGE:
3518
3597
  {
3519
- const document = this._automergeHost.repo.create();
3598
+ const document = this._echoHost.automergeRepo.create();
3520
3599
  epoch = {
3521
3600
  previousId: this._automergeSpaceState.lastEpoch?.id,
3522
3601
  number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
@@ -3528,12 +3607,12 @@ var DataSpace = class {
3528
3607
  case CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY:
3529
3608
  {
3530
3609
  const currentRootUrl = this._automergeSpaceState.rootUrl;
3531
- const rootHandle = this._automergeHost.repo.find(currentRootUrl);
3610
+ const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
3532
3611
  await cancelWithContext2(this._ctx, asyncTimeout(rootHandle.whenReady(), 1e4));
3533
- const newRoot = this._automergeHost.repo.create(rootHandle.docSync());
3612
+ const newRoot = this._echoHost.automergeRepo.create(rootHandle.docSync());
3534
3613
  invariant10(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3535
3614
  F: __dxlog_file11,
3536
- L: 438,
3615
+ L: 433,
3537
3616
  S: this,
3538
3617
  A: [
3539
3618
  "typeof newRoot.url === 'string' && newRoot.url.length > 0",
@@ -3552,19 +3631,19 @@ var DataSpace = class {
3552
3631
  {
3553
3632
  log9.info("Fragmenting", void 0, {
3554
3633
  F: __dxlog_file11,
3555
- L: 450,
3634
+ L: 445,
3556
3635
  S: this,
3557
3636
  C: (f, a) => f(...a)
3558
3637
  });
3559
3638
  const currentRootUrl = this._automergeSpaceState.rootUrl;
3560
- const rootHandle = this._automergeHost.repo.find(currentRootUrl);
3639
+ const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
3561
3640
  await cancelWithContext2(this._ctx, asyncTimeout(rootHandle.whenReady(), 1e4));
3562
3641
  const objects = Object.entries(rootHandle.docSync().objects);
3563
3642
  const properties = objects.find(([_, value]) => value.system.type?.itemId === TYPE_PROPERTIES);
3564
3643
  const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
3565
3644
  invariant10(properties, "Properties not found", {
3566
3645
  F: __dxlog_file11,
3567
- L: 460,
3646
+ L: 455,
3568
3647
  S: this,
3569
3648
  A: [
3570
3649
  "properties",
@@ -3577,17 +3656,17 @@ var DataSpace = class {
3577
3656
  properties
3578
3657
  ])
3579
3658
  };
3580
- const newRoot = this._automergeHost.repo.create(newSpaceDoc);
3659
+ const newRoot = this._echoHost.automergeRepo.create(newSpaceDoc);
3581
3660
  invariant10(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3582
3661
  F: __dxlog_file11,
3583
- L: 465,
3662
+ L: 460,
3584
3663
  S: this,
3585
3664
  A: [
3586
3665
  "typeof newRoot.url === 'string' && newRoot.url.length > 0",
3587
3666
  ""
3588
3667
  ]
3589
3668
  });
3590
- const docLoader = new AutomergeDocumentLoaderImpl(this.key, this._automergeHost.repo);
3669
+ const docLoader = new AutomergeDocumentLoaderImpl(this.key, this._echoHost.automergeRepo);
3591
3670
  await docLoader.loadSpaceRootDocHandle(this._ctx, {
3592
3671
  rootUrl: newRoot.url
3593
3672
  });
@@ -3649,7 +3728,7 @@ var DataSpace = class {
3649
3728
  state: SpaceState[this._state]
3650
3729
  }, {
3651
3730
  F: __dxlog_file11,
3652
- L: 531,
3731
+ L: 526,
3653
3732
  S: this,
3654
3733
  C: (f, a) => f(...a)
3655
3734
  });
@@ -3704,20 +3783,20 @@ DataSpace = _ts_decorate4([
3704
3783
 
3705
3784
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
3706
3785
  import { Event as Event7, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
3707
- import { Context as Context8, cancelWithContext as cancelWithContext3 } from "@dxos/context";
3786
+ import { Context as Context9, cancelWithContext as cancelWithContext3 } from "@dxos/context";
3708
3787
  import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
3709
3788
  import { invariant as invariant11 } from "@dxos/invariant";
3710
- import { PublicKey as PublicKey9 } from "@dxos/keys";
3789
+ import { PublicKey as PublicKey10 } from "@dxos/keys";
3711
3790
  import { log as log10 } from "@dxos/log";
3712
3791
  import { trace as trace7 } from "@dxos/protocols";
3713
- import { SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
3792
+ import { Invitation as Invitation6, SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
3714
3793
  import { Gossip as Gossip2, Presence as Presence2 } from "@dxos/teleport-extension-gossip";
3715
3794
  import { ComplexMap as ComplexMap3, deferFunction as deferFunction2, forEachAsync } from "@dxos/util";
3716
3795
 
3717
3796
  // packages/sdk/client-services/src/packlets/spaces/genesis.ts
3718
3797
  import { createCredential } from "@dxos/credentials";
3719
3798
  import { failUndefined } from "@dxos/debug";
3720
- import { AdmittedFeed as AdmittedFeed4, SpaceMember } from "@dxos/protocols/proto/dxos/halo/credentials";
3799
+ import { AdmittedFeed as AdmittedFeed4, SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/halo/credentials";
3721
3800
  import { Timeframe as Timeframe3 } from "@dxos/timeframe";
3722
3801
  var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3723
3802
  const credentials = [
@@ -3737,7 +3816,7 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3737
3816
  assertion: {
3738
3817
  "@type": "dxos.halo.credentials.SpaceMember",
3739
3818
  spaceKey: space.key,
3740
- role: SpaceMember.Role.ADMIN,
3819
+ role: SpaceMember2.Role.ADMIN,
3741
3820
  profile: signingContext.getProfile(),
3742
3821
  genesisFeedKey: space.controlFeedKey ?? failUndefined()
3743
3822
  }
@@ -3799,18 +3878,19 @@ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/s
3799
3878
  var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
3800
3879
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
3801
3880
  var DataSpaceManager = class {
3802
- constructor(_spaceManager, _metadataStore, _keyring, _signingContext, _feedStore, _automergeHost, params) {
3881
+ constructor(_spaceManager, _metadataStore, _keyring, _signingContext, _feedStore, _echoHost, _invitationsManager, params) {
3803
3882
  this._spaceManager = _spaceManager;
3804
3883
  this._metadataStore = _metadataStore;
3805
3884
  this._keyring = _keyring;
3806
3885
  this._signingContext = _signingContext;
3807
3886
  this._feedStore = _feedStore;
3808
- this._automergeHost = _automergeHost;
3809
- this._ctx = new Context8();
3887
+ this._echoHost = _echoHost;
3888
+ this._invitationsManager = _invitationsManager;
3889
+ this._ctx = new Context9();
3810
3890
  this.updated = new Event7();
3811
- this._spaces = new ComplexMap3(PublicKey9.hash);
3891
+ this._spaces = new ComplexMap3(PublicKey10.hash);
3812
3892
  this._isOpen = false;
3813
- this._instanceId = PublicKey9.random().toHex();
3893
+ this._instanceId = PublicKey10.random().toHex();
3814
3894
  const { spaceMemberPresenceAnnounceInterval = PRESENCE_ANNOUNCE_INTERVAL, spaceMemberPresenceOfflineTimeout = PRESENCE_OFFLINE_TIMEOUT } = params ?? {};
3815
3895
  this._spaceMemberPresenceAnnounceInterval = spaceMemberPresenceAnnounceInterval;
3816
3896
  this._spaceMemberPresenceOfflineTimeout = spaceMemberPresenceOfflineTimeout;
@@ -3822,7 +3902,7 @@ var DataSpaceManager = class {
3822
3902
  async open() {
3823
3903
  log10("open", void 0, {
3824
3904
  F: __dxlog_file12,
3825
- L: 98,
3905
+ L: 102,
3826
3906
  S: this,
3827
3907
  C: (f, a) => f(...a)
3828
3908
  });
@@ -3830,7 +3910,7 @@ var DataSpaceManager = class {
3830
3910
  id: this._instanceId
3831
3911
  }), {
3832
3912
  F: __dxlog_file12,
3833
- L: 99,
3913
+ L: 103,
3834
3914
  S: this,
3835
3915
  C: (f, a) => f(...a)
3836
3916
  });
@@ -3838,7 +3918,7 @@ var DataSpaceManager = class {
3838
3918
  spaces: this._metadataStore.spaces.length
3839
3919
  }, {
3840
3920
  F: __dxlog_file12,
3841
- L: 100,
3921
+ L: 104,
3842
3922
  S: this,
3843
3923
  C: (f, a) => f(...a)
3844
3924
  });
@@ -3848,7 +3928,7 @@ var DataSpaceManager = class {
3848
3928
  spaceMetadata
3849
3929
  }, {
3850
3930
  F: __dxlog_file12,
3851
- L: 104,
3931
+ L: 108,
3852
3932
  S: this,
3853
3933
  C: (f, a) => f(...a)
3854
3934
  });
@@ -3859,7 +3939,7 @@ var DataSpaceManager = class {
3859
3939
  err
3860
3940
  }, {
3861
3941
  F: __dxlog_file12,
3862
- L: 107,
3942
+ L: 111,
3863
3943
  S: this,
3864
3944
  C: (f, a) => f(...a)
3865
3945
  });
@@ -3876,7 +3956,7 @@ var DataSpaceManager = class {
3876
3956
  id: this._instanceId
3877
3957
  }), {
3878
3958
  F: __dxlog_file12,
3879
- L: 120,
3959
+ L: 124,
3880
3960
  S: this,
3881
3961
  C: (f, a) => f(...a)
3882
3962
  });
@@ -3884,7 +3964,7 @@ var DataSpaceManager = class {
3884
3964
  async close() {
3885
3965
  log10("close", void 0, {
3886
3966
  F: __dxlog_file12,
3887
- L: 125,
3967
+ L: 129,
3888
3968
  S: this,
3889
3969
  C: (f, a) => f(...a)
3890
3970
  });
@@ -3900,7 +3980,7 @@ var DataSpaceManager = class {
3900
3980
  async createSpace() {
3901
3981
  invariant11(this._isOpen, "Not open.", {
3902
3982
  F: __dxlog_file12,
3903
- L: 138,
3983
+ L: 142,
3904
3984
  S: this,
3905
3985
  A: [
3906
3986
  "this._isOpen",
@@ -3921,18 +4001,13 @@ var DataSpaceManager = class {
3921
4001
  spaceKey
3922
4002
  }, {
3923
4003
  F: __dxlog_file12,
3924
- L: 150,
4004
+ L: 154,
3925
4005
  S: this,
3926
4006
  C: (f, a) => f(...a)
3927
4007
  });
3928
- const automergeRoot = this._automergeHost.repo.create();
3929
- automergeRoot.change((doc) => {
3930
- doc.access = {
3931
- spaceKey: spaceKey.toHex()
3932
- };
3933
- });
4008
+ const automergeRootUrl = await this._echoHost.createSpaceRoot(spaceKey);
3934
4009
  const space = await this._constructSpace(metadata);
3935
- const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRoot.url);
4010
+ const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRootUrl);
3936
4011
  await this._metadataStore.addSpace(metadata);
3937
4012
  const memberCredential = credentials[1];
3938
4013
  invariant11(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
@@ -4037,8 +4112,8 @@ var DataSpaceManager = class {
4037
4112
  remotePeerId: session.remotePeerId
4038
4113
  }));
4039
4114
  session.addExtension("dxos.mesh.teleport.notarization", dataSpace.notarizationPlugin.createExtension());
4040
- this._automergeHost.authorizeDevice(space.key, session.remotePeerId);
4041
- session.addExtension("dxos.mesh.teleport.automerge", this._automergeHost.createExtension());
4115
+ this._echoHost.authorizeDevice(space.key, session.remotePeerId);
4116
+ session.addExtension("dxos.mesh.teleport.automerge", this._echoHost.createReplicationExtension());
4042
4117
  },
4043
4118
  onAuthFailure: () => {
4044
4119
  log10.warn("auth failure", void 0, {
@@ -4048,7 +4123,10 @@ var DataSpaceManager = class {
4048
4123
  C: (f, a) => f(...a)
4049
4124
  });
4050
4125
  },
4051
- memberKey: this._signingContext.identityKey
4126
+ memberKey: this._signingContext.identityKey,
4127
+ onDelegatedInvitationStatusChange: (invitation, isActive) => {
4128
+ return this._handleInvitationStatusChange(dataSpace, invitation, isActive);
4129
+ }
4052
4130
  });
4053
4131
  controlFeed && await space.setControlFeed(controlFeed);
4054
4132
  dataFeed && await space.setDataFeed(dataFeed);
@@ -4060,6 +4138,7 @@ var DataSpaceManager = class {
4060
4138
  presence,
4061
4139
  keyring: this._keyring,
4062
4140
  feedStore: this._feedStore,
4141
+ echoHost: this._echoHost,
4063
4142
  signingContext: this._signingContext,
4064
4143
  callbacks: {
4065
4144
  beforeReady: async () => {
@@ -4067,7 +4146,7 @@ var DataSpaceManager = class {
4067
4146
  space: space.key
4068
4147
  }, {
4069
4148
  F: __dxlog_file12,
4070
- L: 265,
4149
+ L: 269,
4071
4150
  S: this,
4072
4151
  C: (f, a) => f(...a)
4073
4152
  });
@@ -4078,11 +4157,14 @@ var DataSpaceManager = class {
4078
4157
  open: this._isOpen
4079
4158
  }, {
4080
4159
  F: __dxlog_file12,
4081
- L: 268,
4160
+ L: 272,
4082
4161
  S: this,
4083
4162
  C: (f, a) => f(...a)
4084
4163
  });
4085
4164
  if (this._isOpen) {
4165
+ await this._createDelegatedInvitations(dataSpace, [
4166
+ ...space.spaceState.invitations.entries()
4167
+ ]);
4086
4168
  this.updated.emit();
4087
4169
  }
4088
4170
  },
@@ -4091,14 +4173,13 @@ var DataSpaceManager = class {
4091
4173
  space: space.key
4092
4174
  }, {
4093
4175
  F: __dxlog_file12,
4094
- L: 274,
4176
+ L: 279,
4095
4177
  S: this,
4096
4178
  C: (f, a) => f(...a)
4097
4179
  });
4098
4180
  }
4099
4181
  },
4100
- cache: metadata.cache,
4101
- automergeHost: this._automergeHost
4182
+ cache: metadata.cache
4102
4183
  });
4103
4184
  if (metadata.state !== SpaceState2.INACTIVE) {
4104
4185
  await dataSpace.open();
@@ -4109,6 +4190,41 @@ var DataSpaceManager = class {
4109
4190
  this._spaces.set(metadata.key, dataSpace);
4110
4191
  return dataSpace;
4111
4192
  }
4193
+ async _handleInvitationStatusChange(dataSpace, delegatedInvitation, isActive) {
4194
+ if (dataSpace?.state !== SpaceState2.READY) {
4195
+ return;
4196
+ }
4197
+ if (isActive) {
4198
+ await this._createDelegatedInvitations(dataSpace, [
4199
+ [
4200
+ delegatedInvitation.credentialId,
4201
+ delegatedInvitation.invitation
4202
+ ]
4203
+ ]);
4204
+ } else {
4205
+ await this._invitationsManager.cancelInvitation(delegatedInvitation.invitation);
4206
+ }
4207
+ }
4208
+ async _createDelegatedInvitations(space, invitations) {
4209
+ const tasks = invitations.map(([credentialId, invitation]) => {
4210
+ return this._invitationsManager.createInvitation({
4211
+ type: Invitation6.Type.DELEGATED,
4212
+ kind: Invitation6.Kind.SPACE,
4213
+ spaceKey: space.key,
4214
+ authMethod: invitation.authMethod,
4215
+ invitationId: invitation.invitationId,
4216
+ swarmKey: invitation.swarmKey,
4217
+ guestKeypair: invitation.guestKey ? {
4218
+ publicKey: invitation.guestKey
4219
+ } : void 0,
4220
+ lifetime: invitation.expiresOn ? invitation.expiresOn.getTime() - Date.now() : void 0,
4221
+ multiUse: invitation.multiUse,
4222
+ delegationCredentialId: credentialId,
4223
+ persistent: false
4224
+ });
4225
+ });
4226
+ await Promise.all(tasks);
4227
+ }
4112
4228
  };
4113
4229
  _ts_decorate5([
4114
4230
  synchronized2
@@ -4133,7 +4249,7 @@ import { raise as raise2 } from "@dxos/debug";
4133
4249
  import { invariant as invariant12 } from "@dxos/invariant";
4134
4250
  import { log as log11 } from "@dxos/log";
4135
4251
  import { ApiError, SpaceNotFoundError, encodeError } from "@dxos/protocols";
4136
- import { SpaceMember as SpaceMember2, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
4252
+ import { SpaceMember as SpaceMember3, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
4137
4253
  var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
4138
4254
  var SpacesServiceImpl = class {
4139
4255
  constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
@@ -4331,7 +4447,7 @@ var SpacesServiceImpl = class {
4331
4447
  identityKey: member.key,
4332
4448
  profile: member.profile ?? {}
4333
4449
  },
4334
- presence: member.removed ? SpaceMember2.PresenceState.REMOVED : isMe || peers.length > 0 ? SpaceMember2.PresenceState.ONLINE : SpaceMember2.PresenceState.OFFLINE,
4450
+ presence: member.removed ? SpaceMember3.PresenceState.REMOVED : isMe || peers.length > 0 ? SpaceMember3.PresenceState.ONLINE : SpaceMember3.PresenceState.OFFLINE,
4335
4451
  peerStates: peers
4336
4452
  };
4337
4453
  }),
@@ -4345,105 +4461,21 @@ var getChannelId = (channel) => `user-channel/${channel}`;
4345
4461
 
4346
4462
  // packages/sdk/client-services/src/packlets/services/service-context.ts
4347
4463
  import { Trigger as Trigger5 } from "@dxos/async";
4348
- import { Context as Context9, Resource } from "@dxos/context";
4464
+ import { Context as Context10, Resource } from "@dxos/context";
4349
4465
  import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
4350
4466
  import { failUndefined as failUndefined2 } from "@dxos/debug";
4351
- import { AutomergeHost, MetadataStore, SnapshotStore, SpaceManager, valueEncoding } from "@dxos/echo-pipeline";
4467
+ import { EchoHost } from "@dxos/echo-db";
4468
+ import { MetadataStore, SnapshotStore, SpaceManager, valueEncoding } from "@dxos/echo-pipeline";
4352
4469
  import { FeedFactory, FeedStore } from "@dxos/feed-store";
4353
- import { IndexMetadataStore, IndexStore, Indexer, createStorageCallbacks } from "@dxos/indexing";
4354
4470
  import { invariant as invariant13 } from "@dxos/invariant";
4355
4471
  import { Keyring } from "@dxos/keyring";
4356
- import { PublicKey as PublicKey10 } from "@dxos/keys";
4472
+ import { PublicKey as PublicKey11 } from "@dxos/keys";
4357
4473
  import { log as log12 } from "@dxos/log";
4358
4474
  import { InvalidStorageVersionError, STORAGE_VERSION, trace as trace8 } from "@dxos/protocols";
4359
- import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
4475
+ import { Invitation as Invitation7 } from "@dxos/protocols/proto/dxos/client/services";
4360
4476
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
4361
4477
  import { trace as Trace2 } from "@dxos/tracing";
4362
4478
  import { safeInstanceof } from "@dxos/util";
4363
-
4364
- // packages/sdk/client-services/src/packlets/indexing/util.ts
4365
- import { getHeads } from "@dxos/automerge/automerge";
4366
- import { idCodec } from "@dxos/protocols";
4367
- var createSelectedDocumentsIterator = (automergeHost) => (
4368
- /**
4369
- * Get object data blobs from Automerge Repo by ids.
4370
- * @param ids
4371
- */
4372
- // TODO(mykola): Unload automerge handles after usage.
4373
- async function* loadDocuments(ids) {
4374
- for (const id of ids) {
4375
- const { documentId, objectId } = idCodec.decode(id);
4376
- const handle = automergeHost.repo.handles[documentId] ?? automergeHost.repo.find(documentId);
4377
- if (!handle.isReady()) {
4378
- await handle.whenReady();
4379
- }
4380
- const doc = handle.docSync();
4381
- const hash = getHeads(doc).join("");
4382
- yield doc.objects?.[objectId] ? [
4383
- {
4384
- id,
4385
- object: doc.objects[objectId],
4386
- currentHash: hash
4387
- }
4388
- ] : [];
4389
- }
4390
- }
4391
- );
4392
- var createDocumentsIterator = (automergeHost) => (
4393
- /**
4394
- * Recursively get all object data blobs from Automerge Repo.
4395
- * @param ids
4396
- */
4397
- // TODO(mykola): Unload automerge handles after usage.
4398
- async function* getAllDocuments() {
4399
- const visited = /* @__PURE__ */ new Set();
4400
- async function* getObjectsFromHandle(handle) {
4401
- if (visited.has(handle.documentId)) {
4402
- return;
4403
- }
4404
- if (!handle.isReady()) {
4405
- await handle.whenReady();
4406
- }
4407
- const doc = handle.docSync();
4408
- const heads = getHeads(doc);
4409
- if (doc.objects) {
4410
- yield Object.entries(doc.objects).map(([objectId, object]) => {
4411
- return {
4412
- id: idCodec.encode({
4413
- documentId: handle.documentId,
4414
- objectId
4415
- }),
4416
- object,
4417
- currentHash: heads.join("")
4418
- };
4419
- });
4420
- }
4421
- if (doc.links) {
4422
- for (const id of Object.values(doc.links)) {
4423
- if (visited.has(id)) {
4424
- continue;
4425
- }
4426
- const linkHandle = automergeHost.repo.handles[id] ?? automergeHost.repo.find(id);
4427
- for await (const result of getObjectsFromHandle(linkHandle)) {
4428
- yield result;
4429
- }
4430
- }
4431
- }
4432
- visited.add(handle.documentId);
4433
- }
4434
- for (const handle of Object.values(automergeHost.repo.handles)) {
4435
- if (visited.has(handle.documentId)) {
4436
- continue;
4437
- }
4438
- for await (const result of getObjectsFromHandle(handle)) {
4439
- yield result;
4440
- }
4441
- visited.add(handle.documentId);
4442
- }
4443
- }
4444
- );
4445
-
4446
- // packages/sdk/client-services/src/packlets/services/service-context.ts
4447
4479
  function _ts_decorate6(decorators, target, key, desc) {
4448
4480
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4449
4481
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -4465,7 +4497,7 @@ var ServiceContext = class extends Resource {
4465
4497
  this._runtimeParams = _runtimeParams;
4466
4498
  this.initialized = new Trigger5();
4467
4499
  this._handlerFactories = /* @__PURE__ */ new Map();
4468
- this._instanceId = PublicKey10.random().toHex();
4500
+ this._instanceId = PublicKey11.random().toHex();
4469
4501
  this.metadataStore = new MetadataStore(storage.createDirectory("metadata"));
4470
4502
  this.snapshotStore = new SnapshotStore(storage.createDirectory("snapshots"));
4471
4503
  this.blobStore = new BlobStore(storage.createDirectory("blobs"));
@@ -4488,34 +4520,19 @@ var ServiceContext = class extends Resource {
4488
4520
  snapshotStore: this.snapshotStore
4489
4521
  });
4490
4522
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager, this._runtimeParams);
4491
- this.indexMetadata = new IndexMetadataStore({
4492
- db: level.sublevel("index-metadata")
4493
- });
4494
- this.automergeHost = new AutomergeHost({
4495
- directory: storage.createDirectory("automerge"),
4496
- db: level.sublevel("automerge"),
4497
- storageCallbacks: createStorageCallbacks({
4498
- host: () => this.automergeHost,
4499
- metadata: this.indexMetadata
4500
- })
4501
- });
4502
- this.indexer = new Indexer({
4503
- indexStore: new IndexStore({
4504
- db: level.sublevel("index-storage")
4505
- }),
4506
- metadataStore: this.indexMetadata,
4507
- loadDocuments: createSelectedDocumentsIterator(this.automergeHost),
4508
- getAllDocuments: createDocumentsIterator(this.automergeHost)
4523
+ this.echoHost = new EchoHost({
4524
+ kv: this.level,
4525
+ storage: this.storage
4509
4526
  });
4510
4527
  this.invitations = new InvitationsHandler(this.networkManager);
4511
4528
  this.invitationsManager = new InvitationsManager(this.invitations, (invitation) => this.getInvitationHandler(invitation), this.metadataStore);
4512
- this._handlerFactories.set(Invitation5.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined2(), this._acceptIdentity.bind(this)));
4529
+ this._handlerFactories.set(Invitation7.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined2(), this._acceptIdentity.bind(this)));
4513
4530
  }
4514
4531
  async _open(ctx) {
4515
4532
  await this._checkStorageVersion();
4516
4533
  log12("opening...", void 0, {
4517
4534
  F: __dxlog_file14,
4518
- L: 164,
4535
+ L: 151,
4519
4536
  S: this,
4520
4537
  C: (f, a) => f(...a)
4521
4538
  });
@@ -4523,13 +4540,13 @@ var ServiceContext = class extends Resource {
4523
4540
  id: this._instanceId
4524
4541
  }), {
4525
4542
  F: __dxlog_file14,
4526
- L: 165,
4543
+ L: 152,
4527
4544
  S: this,
4528
4545
  C: (f, a) => f(...a)
4529
4546
  });
4530
4547
  await this.signalManager.open();
4531
4548
  await this.networkManager.open();
4532
- await this.automergeHost.open();
4549
+ await this.echoHost.open(ctx);
4533
4550
  await this.metadataStore.load();
4534
4551
  await this.spaceManager.open();
4535
4552
  await this.identityManager.open(ctx);
@@ -4541,7 +4558,7 @@ var ServiceContext = class extends Resource {
4541
4558
  count: loadedInvitations.invitations?.length
4542
4559
  }, {
4543
4560
  F: __dxlog_file14,
4544
- L: 178,
4561
+ L: 165,
4545
4562
  S: this,
4546
4563
  C: (f, a) => f(...a)
4547
4564
  });
@@ -4549,53 +4566,52 @@ var ServiceContext = class extends Resource {
4549
4566
  id: this._instanceId
4550
4567
  }), {
4551
4568
  F: __dxlog_file14,
4552
- L: 180,
4569
+ L: 167,
4553
4570
  S: this,
4554
4571
  C: (f, a) => f(...a)
4555
4572
  });
4556
4573
  log12("opened", void 0, {
4557
4574
  F: __dxlog_file14,
4558
- L: 181,
4575
+ L: 168,
4559
4576
  S: this,
4560
4577
  C: (f, a) => f(...a)
4561
4578
  });
4562
4579
  }
4563
- async _close() {
4580
+ async _close(ctx) {
4564
4581
  log12("closing...", void 0, {
4565
4582
  F: __dxlog_file14,
4566
- L: 185,
4583
+ L: 172,
4567
4584
  S: this,
4568
4585
  C: (f, a) => f(...a)
4569
4586
  });
4570
4587
  if (this._deviceSpaceSync && this.identityManager.identity) {
4571
4588
  await this.identityManager.identity.space.spaceState.removeCredentialProcessor(this._deviceSpaceSync);
4572
4589
  }
4573
- await this.automergeHost.close();
4574
4590
  await this.dataSpaceManager?.close();
4575
4591
  await this.identityManager.close();
4576
4592
  await this.spaceManager.close();
4577
4593
  await this.feedStore.close();
4594
+ await this.metadataStore.close();
4595
+ await this.echoHost.close(ctx);
4578
4596
  await this.networkManager.close();
4579
4597
  await this.signalManager.close();
4580
- await this.metadataStore.close();
4581
- await this.indexer.destroy();
4582
4598
  log12("closed", void 0, {
4583
4599
  F: __dxlog_file14,
4584
- L: 198,
4600
+ L: 184,
4585
4601
  S: this,
4586
4602
  C: (f, a) => f(...a)
4587
4603
  });
4588
4604
  }
4589
4605
  async createIdentity(params = {}) {
4590
4606
  const identity = await this.identityManager.createIdentity(params);
4591
- await this._initialize(new Context9());
4607
+ await this._initialize(new Context10());
4592
4608
  return identity;
4593
4609
  }
4594
4610
  getInvitationHandler(invitation) {
4595
4611
  const factory = this._handlerFactories.get(invitation.kind);
4596
4612
  invariant13(factory, `Unknown invitation kind: ${invitation.kind}`, {
4597
4613
  F: __dxlog_file14,
4598
- L: 209,
4614
+ L: 195,
4599
4615
  S: this,
4600
4616
  A: [
4601
4617
  "factory",
@@ -4614,7 +4630,7 @@ var ServiceContext = class extends Resource {
4614
4630
  }
4615
4631
  async _acceptIdentity(params) {
4616
4632
  const identity = await this.identityManager.acceptIdentity(params);
4617
- await this._initialize(new Context9());
4633
+ await this._initialize(new Context10());
4618
4634
  return identity;
4619
4635
  }
4620
4636
  async _checkStorageVersion() {
@@ -4627,7 +4643,7 @@ var ServiceContext = class extends Resource {
4627
4643
  async _initialize(ctx) {
4628
4644
  log12("initializing spaces...", void 0, {
4629
4645
  F: __dxlog_file14,
4630
- L: 240,
4646
+ L: 226,
4631
4647
  S: this,
4632
4648
  C: (f, a) => f(...a)
4633
4649
  });
@@ -4645,12 +4661,12 @@ var ServiceContext = class extends Resource {
4645
4661
  });
4646
4662
  }
4647
4663
  };
4648
- this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.automergeHost, this._runtimeParams);
4664
+ this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.echoHost, this.invitationsManager, this._runtimeParams);
4649
4665
  await this.dataSpaceManager.open();
4650
- this._handlerFactories.set(Invitation5.Kind.SPACE, (invitation) => {
4666
+ this._handlerFactories.set(Invitation7.Kind.SPACE, (invitation) => {
4651
4667
  invariant13(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4652
4668
  F: __dxlog_file14,
4653
- L: 264,
4669
+ L: 251,
4654
4670
  S: this,
4655
4671
  A: [
4656
4672
  "this.dataSpaceManager",
@@ -4674,7 +4690,7 @@ var ServiceContext = class extends Resource {
4674
4690
  details: assertion
4675
4691
  }, {
4676
4692
  F: __dxlog_file14,
4677
- L: 280,
4693
+ L: 267,
4678
4694
  S: this,
4679
4695
  C: (f, a) => f(...a)
4680
4696
  });
@@ -4685,7 +4701,7 @@ var ServiceContext = class extends Resource {
4685
4701
  details: assertion
4686
4702
  }, {
4687
4703
  F: __dxlog_file14,
4688
- L: 284,
4704
+ L: 271,
4689
4705
  S: this,
4690
4706
  C: (f, a) => f(...a)
4691
4707
  });
@@ -4696,7 +4712,7 @@ var ServiceContext = class extends Resource {
4696
4712
  details: assertion
4697
4713
  }, {
4698
4714
  F: __dxlog_file14,
4699
- L: 289,
4715
+ L: 276,
4700
4716
  S: this,
4701
4717
  C: (f, a) => f(...a)
4702
4718
  });
@@ -4707,7 +4723,7 @@ var ServiceContext = class extends Resource {
4707
4723
  } catch (err) {
4708
4724
  log12.catch(err, void 0, {
4709
4725
  F: __dxlog_file14,
4710
- L: 295,
4726
+ L: 282,
4711
4727
  S: this,
4712
4728
  C: (f, a) => f(...a)
4713
4729
  });
@@ -4757,11 +4773,11 @@ import { getFirstStreamValue } from "@dxos/codec-protobuf";
4757
4773
  import { credentialTypeFilter } from "@dxos/credentials";
4758
4774
  import { invariant as invariant14 } from "@dxos/invariant";
4759
4775
  import { STORAGE_VERSION as STORAGE_VERSION2 } from "@dxos/protocols";
4760
- import { SpaceMember as SpaceMember3 } from "@dxos/protocols/proto/dxos/client/services";
4776
+ import { SpaceMember as SpaceMember4 } from "@dxos/protocols/proto/dxos/client/services";
4761
4777
  import { TRACE_PROCESSOR } from "@dxos/tracing";
4762
4778
 
4763
4779
  // packages/sdk/client-services/src/version.ts
4764
- var DXOS_VERSION = "0.4.10-main.4c8c73c";
4780
+ var DXOS_VERSION = "0.4.10-main.4d26ea7";
4765
4781
 
4766
4782
  // packages/sdk/client-services/src/packlets/services/platform.ts
4767
4783
  import { Platform } from "@dxos/protocols/proto/dxos/client/services";
@@ -4883,7 +4899,7 @@ var getSpaceStats = async (space) => {
4883
4899
  displayName: member.assertion.profile?.displayName
4884
4900
  }
4885
4901
  },
4886
- presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember3.PresenceState.ONLINE : SpaceMember3.PresenceState.OFFLINE
4902
+ presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember4.PresenceState.ONLINE : SpaceMember4.PresenceState.OFFLINE
4887
4903
  })),
4888
4904
  pipeline: {
4889
4905
  // TODO(burdon): Pick properties from credentials if needed.
@@ -5004,12 +5020,11 @@ import { jsonKeyReplacer as jsonKeyReplacer2, nonNullable } from "@dxos/util";
5004
5020
  // packages/sdk/client-services/src/packlets/services/service-host.ts
5005
5021
  import { Event as Event9, synchronized as synchronized3 } from "@dxos/async";
5006
5022
  import { clientServiceBundle, defaultKey, Properties } from "@dxos/client-protocol";
5007
- import { Context as Context10 } from "@dxos/context";
5008
- import { DataServiceImpl, encodeReference } from "@dxos/echo-pipeline";
5023
+ import { Context as Context11 } from "@dxos/context";
5024
+ import { encodeReference } from "@dxos/echo-pipeline";
5009
5025
  import { getTypeReference } from "@dxos/echo-schema";
5010
- import { QueryServiceImpl } from "@dxos/indexing";
5011
5026
  import { invariant as invariant16 } from "@dxos/invariant";
5012
- import { PublicKey as PublicKey13 } from "@dxos/keys";
5027
+ import { PublicKey as PublicKey14 } from "@dxos/keys";
5013
5028
  import { log as log16 } from "@dxos/log";
5014
5029
  import { WebsocketSignalManager } from "@dxos/messaging";
5015
5030
  import { NetworkManager, createSimplePeerTransportFactory } from "@dxos/network-manager";
@@ -5228,7 +5243,7 @@ var isLocked = (lockPath) => {
5228
5243
  // packages/sdk/client-services/src/packlets/logging/logging-service.ts
5229
5244
  import { Event as Event8 } from "@dxos/async";
5230
5245
  import { Stream as Stream12 } from "@dxos/codec-protobuf";
5231
- import { PublicKey as PublicKey11 } from "@dxos/keys";
5246
+ import { PublicKey as PublicKey12 } from "@dxos/keys";
5232
5247
  import { getContextFromEntry, log as log15 } from "@dxos/log";
5233
5248
  import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
5234
5249
  import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
@@ -5236,7 +5251,7 @@ var LoggingServiceImpl = class {
5236
5251
  constructor() {
5237
5252
  this._logs = new Event8();
5238
5253
  this._started = Date.now();
5239
- this._sessionId = PublicKey11.random().toHex();
5254
+ this._sessionId = PublicKey12.random().toHex();
5240
5255
  this._logProcessor = (_config, entry2) => {
5241
5256
  this._logs.emit(entry2);
5242
5257
  };
@@ -5447,10 +5462,10 @@ var toStorageType = (type) => {
5447
5462
  // packages/sdk/client-services/src/packlets/storage/level.ts
5448
5463
  import { Level } from "level";
5449
5464
  import path from "@dxos/node-std/path";
5450
- import { PublicKey as PublicKey12 } from "@dxos/keys";
5465
+ import { PublicKey as PublicKey13 } from "@dxos/keys";
5451
5466
  var createLevel = async (config) => {
5452
5467
  const persistent = isPersistent(config);
5453
- const storagePath = persistent ? path.join(getRootPath(config), "level") : `/tmp/dxos-${PublicKey12.random().toHex()}`;
5468
+ const storagePath = persistent ? path.join(getRootPath(config), "level") : `/tmp/dxos-${PublicKey13.random().toHex()}`;
5454
5469
  const level = new Level(storagePath);
5455
5470
  await level.open();
5456
5471
  return level;
@@ -5557,7 +5572,7 @@ var ClientServicesHost = class {
5557
5572
  lockKey,
5558
5573
  onAcquire: () => {
5559
5574
  if (!this._opening) {
5560
- void this.open(new Context10());
5575
+ void this.open(new Context11());
5561
5576
  }
5562
5577
  },
5563
5578
  onRelease: () => this.close()
@@ -5614,7 +5629,7 @@ var ClientServicesHost = class {
5614
5629
  initialize({ config, ...options }) {
5615
5630
  invariant16(!this._open, "service host is open", {
5616
5631
  F: __dxlog_file19,
5617
- L: 198,
5632
+ L: 190,
5618
5633
  S: this,
5619
5634
  A: [
5620
5635
  "!this._open",
@@ -5623,14 +5638,14 @@ var ClientServicesHost = class {
5623
5638
  });
5624
5639
  log16("initializing...", void 0, {
5625
5640
  F: __dxlog_file19,
5626
- L: 199,
5641
+ L: 191,
5627
5642
  S: this,
5628
5643
  C: (f, a) => f(...a)
5629
5644
  });
5630
5645
  if (config) {
5631
5646
  invariant16(!this._config, "config already set", {
5632
5647
  F: __dxlog_file19,
5633
- L: 202,
5648
+ L: 194,
5634
5649
  S: this,
5635
5650
  A: [
5636
5651
  "!this._config",
@@ -5645,7 +5660,7 @@ var ClientServicesHost = class {
5645
5660
  if (!options.signalManager) {
5646
5661
  log16.warn("running signaling without telemetry metadata.", void 0, {
5647
5662
  F: __dxlog_file19,
5648
- L: 210,
5663
+ L: 202,
5649
5664
  S: this,
5650
5665
  C: (f, a) => f(...a)
5651
5666
  });
@@ -5656,7 +5671,7 @@ var ClientServicesHost = class {
5656
5671
  this._signalManager = signalManager;
5657
5672
  invariant16(!this._networkManager, "network manager already set", {
5658
5673
  F: __dxlog_file19,
5659
- L: 221,
5674
+ L: 213,
5660
5675
  S: this,
5661
5676
  A: [
5662
5677
  "!this._networkManager",
@@ -5670,7 +5685,7 @@ var ClientServicesHost = class {
5670
5685
  });
5671
5686
  log16("initialized", void 0, {
5672
5687
  F: __dxlog_file19,
5673
- L: 228,
5688
+ L: 220,
5674
5689
  S: this,
5675
5690
  C: (f, a) => f(...a)
5676
5691
  });
@@ -5679,18 +5694,18 @@ var ClientServicesHost = class {
5679
5694
  if (this._open) {
5680
5695
  return;
5681
5696
  }
5682
- const traceId = PublicKey13.random().toHex();
5697
+ const traceId = PublicKey14.random().toHex();
5683
5698
  log16.trace("dxos.client-services.host.open", trace9.begin({
5684
5699
  id: traceId
5685
5700
  }), {
5686
5701
  F: __dxlog_file19,
5687
- L: 239,
5702
+ L: 231,
5688
5703
  S: this,
5689
5704
  C: (f, a) => f(...a)
5690
5705
  });
5691
5706
  invariant16(this._config, "config not set", {
5692
5707
  F: __dxlog_file19,
5693
- L: 241,
5708
+ L: 233,
5694
5709
  S: this,
5695
5710
  A: [
5696
5711
  "this._config",
@@ -5699,7 +5714,7 @@ var ClientServicesHost = class {
5699
5714
  });
5700
5715
  invariant16(this._storage, "storage not set", {
5701
5716
  F: __dxlog_file19,
5702
- L: 242,
5717
+ L: 234,
5703
5718
  S: this,
5704
5719
  A: [
5705
5720
  "this._storage",
@@ -5708,7 +5723,7 @@ var ClientServicesHost = class {
5708
5723
  });
5709
5724
  invariant16(this._signalManager, "signal manager not set", {
5710
5725
  F: __dxlog_file19,
5711
- L: 243,
5726
+ L: 235,
5712
5727
  S: this,
5713
5728
  A: [
5714
5729
  "this._signalManager",
@@ -5717,7 +5732,7 @@ var ClientServicesHost = class {
5717
5732
  });
5718
5733
  invariant16(this._networkManager, "network manager not set", {
5719
5734
  F: __dxlog_file19,
5720
- L: 244,
5735
+ L: 236,
5721
5736
  S: this,
5722
5737
  A: [
5723
5738
  "this._networkManager",
@@ -5729,7 +5744,7 @@ var ClientServicesHost = class {
5729
5744
  lockKey: this._resourceLock?.lockKey
5730
5745
  }, {
5731
5746
  F: __dxlog_file19,
5732
- L: 247,
5747
+ L: 239,
5733
5748
  S: this,
5734
5749
  C: (f, a) => f(...a)
5735
5750
  });
@@ -5740,11 +5755,6 @@ var ClientServicesHost = class {
5740
5755
  await this._resourceLock?.acquire();
5741
5756
  await this._loggingService.open();
5742
5757
  this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._runtimeParams);
5743
- this._queryService = new QueryServiceImpl({
5744
- indexer: this._serviceContext.indexer,
5745
- automergeHost: this._serviceContext.automergeHost
5746
- });
5747
- await this._queryService.open(ctx);
5748
5758
  this._serviceRegistry.setServices({
5749
5759
  SystemService: this._systemService,
5750
5760
  IdentityService: new IdentityServiceImpl((params) => this._createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring, (profile) => this._serviceContext.broadcastProfileUpdate(profile)),
@@ -5754,8 +5764,8 @@ var ClientServicesHost = class {
5754
5764
  await this._serviceContext.initialized.wait();
5755
5765
  return this._serviceContext.dataSpaceManager;
5756
5766
  }),
5757
- DataService: new DataServiceImpl(this._serviceContext.automergeHost),
5758
- QueryService: this._queryService,
5767
+ DataService: this._serviceContext.echoHost.dataService,
5768
+ QueryService: this._serviceContext.echoHost.queryService,
5759
5769
  NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager, this._serviceContext.signalManager),
5760
5770
  LoggingService: this._loggingService,
5761
5771
  TracingService: this._tracingService,
@@ -5786,7 +5796,7 @@ var ClientServicesHost = class {
5786
5796
  deviceKey
5787
5797
  }, {
5788
5798
  F: __dxlog_file19,
5789
- L: 330,
5799
+ L: 315,
5790
5800
  S: this,
5791
5801
  C: (f, a) => f(...a)
5792
5802
  });
@@ -5794,7 +5804,7 @@ var ClientServicesHost = class {
5794
5804
  id: traceId
5795
5805
  }), {
5796
5806
  F: __dxlog_file19,
5797
- L: 331,
5807
+ L: 316,
5798
5808
  S: this,
5799
5809
  C: (f, a) => f(...a)
5800
5810
  });
@@ -5808,7 +5818,7 @@ var ClientServicesHost = class {
5808
5818
  deviceKey
5809
5819
  }, {
5810
5820
  F: __dxlog_file19,
5811
- L: 342,
5821
+ L: 327,
5812
5822
  S: this,
5813
5823
  C: (f, a) => f(...a)
5814
5824
  });
@@ -5818,7 +5828,6 @@ var ClientServicesHost = class {
5818
5828
  SystemService: this._systemService
5819
5829
  });
5820
5830
  await this._loggingService.close();
5821
- await this._queryService.close();
5822
5831
  await this._serviceContext.close();
5823
5832
  await this._level?.close();
5824
5833
  this._open = false;
@@ -5827,24 +5836,24 @@ var ClientServicesHost = class {
5827
5836
  deviceKey
5828
5837
  }, {
5829
5838
  F: __dxlog_file19,
5830
- L: 352,
5839
+ L: 336,
5831
5840
  S: this,
5832
5841
  C: (f, a) => f(...a)
5833
5842
  });
5834
5843
  }
5835
5844
  async reset() {
5836
- const traceId = PublicKey13.random().toHex();
5845
+ const traceId = PublicKey14.random().toHex();
5837
5846
  log16.trace("dxos.sdk.client-services-host.reset", trace9.begin({
5838
5847
  id: traceId
5839
5848
  }), {
5840
5849
  F: __dxlog_file19,
5841
- L: 357,
5850
+ L: 341,
5842
5851
  S: this,
5843
5852
  C: (f, a) => f(...a)
5844
5853
  });
5845
5854
  log16("resetting...", void 0, {
5846
5855
  F: __dxlog_file19,
5847
- L: 359,
5856
+ L: 343,
5848
5857
  S: this,
5849
5858
  C: (f, a) => f(...a)
5850
5859
  });
@@ -5852,7 +5861,7 @@ var ClientServicesHost = class {
5852
5861
  await this._storage.reset();
5853
5862
  log16("reset", void 0, {
5854
5863
  F: __dxlog_file19,
5855
- L: 362,
5864
+ L: 346,
5856
5865
  S: this,
5857
5866
  C: (f, a) => f(...a)
5858
5867
  });
@@ -5860,7 +5869,7 @@ var ClientServicesHost = class {
5860
5869
  id: traceId
5861
5870
  }), {
5862
5871
  F: __dxlog_file19,
5863
- L: 363,
5872
+ L: 347,
5864
5873
  S: this,
5865
5874
  C: (f, a) => f(...a)
5866
5875
  });
@@ -5873,14 +5882,14 @@ var ClientServicesHost = class {
5873
5882
  const automergeIndex = space.automergeSpaceState.rootUrl;
5874
5883
  invariant16(automergeIndex, void 0, {
5875
5884
  F: __dxlog_file19,
5876
- L: 375,
5885
+ L: 359,
5877
5886
  S: this,
5878
5887
  A: [
5879
5888
  "automergeIndex",
5880
5889
  ""
5881
5890
  ]
5882
5891
  });
5883
- const document = await this._serviceContext.automergeHost.repo.find(automergeIndex);
5892
+ const document = await this._serviceContext.echoHost.automergeRepo.find(automergeIndex);
5884
5893
  await document.whenReady();
5885
5894
  const properties = {
5886
5895
  system: {
@@ -5893,14 +5902,14 @@ var ClientServicesHost = class {
5893
5902
  keys: []
5894
5903
  }
5895
5904
  };
5896
- const propertiesId = PublicKey13.random().toHex();
5905
+ const propertiesId = PublicKey14.random().toHex();
5897
5906
  document.change((doc) => {
5898
5907
  assignDeep2(doc, [
5899
5908
  "objects",
5900
5909
  propertiesId
5901
5910
  ], properties);
5902
5911
  });
5903
- await this._serviceContext.automergeHost.repo.flush();
5912
+ await this._serviceContext.echoHost.flush();
5904
5913
  return identity;
5905
5914
  }
5906
5915
  };
@@ -5923,7 +5932,7 @@ ClientServicesHost = _ts_decorate8([
5923
5932
  ], ClientServicesHost);
5924
5933
 
5925
5934
  // packages/sdk/client-services/src/packlets/services/util.ts
5926
- import { PublicKey as PublicKey14 } from "@dxos/keys";
5935
+ import { PublicKey as PublicKey15 } from "@dxos/keys";
5927
5936
  import { humanize } from "@dxos/util";
5928
5937
  var ClientServicesProviderResource = Symbol.for("dxos.resource.ClientServices");
5929
5938
 
@@ -6000,4 +6009,4 @@ export {
6000
6009
  ClientServicesHost,
6001
6010
  ClientServicesProviderResource
6002
6011
  };
6003
- //# sourceMappingURL=chunk-F4LOSBRJ.mjs.map
6012
+ //# sourceMappingURL=chunk-X462P3GQ.mjs.map