@dxos/client-services 0.4.10-main.fd4f2a3 → 0.4.10-main.fe71b4c

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 (70) hide show
  1. package/dist/lib/browser/{chunk-V2ALN47T.mjs → chunk-7S34JE6M.mjs} +836 -625
  2. package/dist/lib/browser/chunk-7S34JE6M.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +11 -3
  4. package/dist/lib/browser/index.mjs.map +1 -1
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +9 -4
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/{chunk-7WXQVUAE.cjs → chunk-DQMGKBOV.cjs} +854 -725
  9. package/dist/lib/node/chunk-DQMGKBOV.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +47 -39
  11. package/dist/lib/node/index.cjs.map +1 -1
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/packlets/testing/index.cjs +14 -9
  14. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  15. package/dist/types/src/index.d.ts +1 -0
  16. package/dist/types/src/index.d.ts.map +1 -1
  17. package/dist/types/src/packlets/diagnostics/browser-diagnostics-broadcast.d.ts +5 -0
  18. package/dist/types/src/packlets/diagnostics/browser-diagnostics-broadcast.d.ts.map +1 -0
  19. package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts +5 -0
  20. package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts.map +1 -0
  21. package/dist/types/src/packlets/diagnostics/diagnostics-collector.d.ts +15 -0
  22. package/dist/types/src/packlets/diagnostics/diagnostics-collector.d.ts.map +1 -0
  23. package/dist/types/src/packlets/{services → diagnostics}/diagnostics.d.ts +1 -1
  24. package/dist/types/src/packlets/diagnostics/diagnostics.d.ts.map +1 -0
  25. package/dist/types/src/packlets/diagnostics/index.d.ts +4 -0
  26. package/dist/types/src/packlets/diagnostics/index.d.ts.map +1 -0
  27. package/dist/types/src/packlets/indexing/util.d.ts +2 -1
  28. package/dist/types/src/packlets/indexing/util.d.ts.map +1 -1
  29. package/dist/types/src/packlets/invitations/invitation-extension.d.ts +1 -0
  30. package/dist/types/src/packlets/invitations/invitation-extension.d.ts.map +1 -1
  31. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +4 -2
  32. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  33. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  34. package/dist/types/src/packlets/services/index.d.ts +1 -1
  35. package/dist/types/src/packlets/services/index.d.ts.map +1 -1
  36. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  37. package/dist/types/src/packlets/services/service-host.d.ts +4 -1
  38. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  39. package/dist/types/src/packlets/services/util.d.ts +1 -0
  40. package/dist/types/src/packlets/services/util.d.ts.map +1 -1
  41. package/dist/types/src/packlets/system/system-service.d.ts +1 -1
  42. package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
  43. package/dist/types/src/packlets/testing/test-builder.d.ts +3 -1
  44. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  45. package/dist/types/src/version.d.ts +1 -1
  46. package/package.json +35 -34
  47. package/src/index.ts +1 -0
  48. package/src/packlets/diagnostics/browser-diagnostics-broadcast.ts +94 -0
  49. package/src/packlets/diagnostics/diagnostics-broadcast.ts +20 -0
  50. package/src/packlets/diagnostics/diagnostics-collector.ts +65 -0
  51. package/src/packlets/{services → diagnostics}/diagnostics.ts +2 -2
  52. package/src/packlets/diagnostics/index.ts +7 -0
  53. package/src/packlets/indexing/util.ts +2 -2
  54. package/src/packlets/invitations/invitation-extension.ts +28 -1
  55. package/src/packlets/invitations/invitations-handler.ts +73 -32
  56. package/src/packlets/invitations/invitations-service.ts +5 -5
  57. package/src/packlets/services/automerge-host.test.ts +9 -3
  58. package/src/packlets/services/index.ts +1 -1
  59. package/src/packlets/services/service-context.test.ts +4 -1
  60. package/src/packlets/services/service-context.ts +5 -3
  61. package/src/packlets/services/service-host.ts +23 -4
  62. package/src/packlets/services/util.ts +2 -0
  63. package/src/packlets/spaces/data-space-manager.test.ts +4 -4
  64. package/src/packlets/storage/level.ts +1 -1
  65. package/src/packlets/system/system-service.ts +1 -1
  66. package/src/packlets/testing/test-builder.ts +20 -4
  67. package/src/version.ts +1 -1
  68. package/dist/lib/browser/chunk-V2ALN47T.mjs.map +0 -7
  69. package/dist/lib/node/chunk-7WXQVUAE.cjs.map +0 -7
  70. package/dist/types/src/packlets/services/diagnostics.d.ts.map +0 -1
@@ -1282,6 +1282,7 @@ import { PushStream, scheduleTask as scheduleTask2, TimeoutError, Trigger as Tri
1282
1282
  import { AuthenticatingInvitation, AUTHENTICATION_CODE_LENGTH, CancellableInvitation, INVITATION_TIMEOUT } from "@dxos/client-protocol";
1283
1283
  import { Context as Context5 } from "@dxos/context";
1284
1284
  import { generatePasscode } from "@dxos/credentials";
1285
+ import { createKeyPair, sign } from "@dxos/crypto";
1285
1286
  import { invariant as invariant6 } from "@dxos/invariant";
1286
1287
  import { PublicKey as PublicKey6 } from "@dxos/keys";
1287
1288
  import { log as log5 } from "@dxos/log";
@@ -1293,6 +1294,7 @@ import { AuthenticationResponse as AuthenticationResponse2 } from "@dxos/protoco
1293
1294
  // packages/sdk/client-services/src/packlets/invitations/invitation-extension.ts
1294
1295
  import { Trigger as Trigger2 } from "@dxos/async";
1295
1296
  import { cancelWithContext, Context as Context4 } from "@dxos/context";
1297
+ import { randomBytes, verify } from "@dxos/crypto";
1296
1298
  import { invariant as invariant5 } from "@dxos/invariant";
1297
1299
  import { PublicKey as PublicKey5 } from "@dxos/keys";
1298
1300
  import { log as log4 } from "@dxos/log";
@@ -1316,6 +1318,7 @@ var InvitationHostExtension = class extends RpcExtension {
1316
1318
  this._callbacks = _callbacks;
1317
1319
  this._ctx = new Context4();
1318
1320
  this._remoteOptionsTrigger = new Trigger2();
1321
+ this._challenge = void 0;
1319
1322
  this.invitation = void 0;
1320
1323
  this.guestProfile = void 0;
1321
1324
  this.authenticationPassed = false;
@@ -1330,7 +1333,7 @@ var InvitationHostExtension = class extends RpcExtension {
1330
1333
  options: async (options) => {
1331
1334
  invariant5(!this._remoteOptions, "Remote options already set.", {
1332
1335
  F: __dxlog_file6,
1333
- L: 87,
1336
+ L: 90,
1334
1337
  S: this,
1335
1338
  A: [
1336
1339
  "!this._remoteOptions",
@@ -1347,7 +1350,7 @@ var InvitationHostExtension = class extends RpcExtension {
1347
1350
  id: traceId
1348
1351
  }), {
1349
1352
  F: __dxlog_file6,
1350
- L: 96,
1353
+ L: 99,
1351
1354
  S: this,
1352
1355
  C: (f, a) => f(...a)
1353
1356
  });
@@ -1357,7 +1360,7 @@ var InvitationHostExtension = class extends RpcExtension {
1357
1360
  invitationId
1358
1361
  }, {
1359
1362
  F: __dxlog_file6,
1360
- L: 100,
1363
+ L: 103,
1361
1364
  S: this,
1362
1365
  C: (f, a) => f(...a)
1363
1366
  });
@@ -1371,7 +1374,7 @@ var InvitationHostExtension = class extends RpcExtension {
1371
1374
  guestProfile: profile
1372
1375
  }, {
1373
1376
  F: __dxlog_file6,
1374
- L: 109,
1377
+ L: 112,
1375
1378
  S: this,
1376
1379
  C: (f, a) => f(...a)
1377
1380
  });
@@ -1380,25 +1383,27 @@ var InvitationHostExtension = class extends RpcExtension {
1380
1383
  ...this.invitation,
1381
1384
  state: Invitation2.State.READY_FOR_AUTHENTICATION
1382
1385
  });
1386
+ this._challenge = this.invitation.authMethod === Invitation2.AuthMethod.KNOWN_PUBLIC_KEY ? randomBytes(32) : void 0;
1383
1387
  log4.trace("dxos.sdk.invitation-handler.host.introduce", trace3.end({
1384
1388
  id: traceId
1385
1389
  }), {
1386
1390
  F: __dxlog_file6,
1387
- L: 116,
1391
+ L: 122,
1388
1392
  S: this,
1389
1393
  C: (f, a) => f(...a)
1390
1394
  });
1391
1395
  return {
1392
- authMethod: this.invitation.authMethod
1396
+ authMethod: this.invitation.authMethod,
1397
+ challenge: this._challenge
1393
1398
  };
1394
1399
  },
1395
- authenticate: async ({ authCode: code }) => {
1400
+ authenticate: async ({ authCode: code, signedChallenge }) => {
1396
1401
  const traceId = PublicKey5.random().toHex();
1397
1402
  log4.trace("dxos.sdk.invitation-handler.host.authenticate", trace3.begin({
1398
1403
  id: traceId
1399
1404
  }), {
1400
1405
  F: __dxlog_file6,
1401
- L: 124,
1406
+ L: 131,
1402
1407
  S: this,
1403
1408
  C: (f, a) => f(...a)
1404
1409
  });
@@ -1406,14 +1411,14 @@ var InvitationHostExtension = class extends RpcExtension {
1406
1411
  authCode: code
1407
1412
  }, {
1408
1413
  F: __dxlog_file6,
1409
- L: 125,
1414
+ L: 132,
1410
1415
  S: this,
1411
1416
  C: (f, a) => f(...a)
1412
1417
  });
1413
1418
  let status = AuthenticationResponse.Status.OK;
1414
1419
  invariant5(this.invitation, "Invitation is not set.", {
1415
1420
  F: __dxlog_file6,
1416
- L: 128,
1421
+ L: 135,
1417
1422
  S: this,
1418
1423
  A: [
1419
1424
  "this.invitation",
@@ -1424,7 +1429,7 @@ var InvitationHostExtension = class extends RpcExtension {
1424
1429
  case Invitation2.AuthMethod.NONE: {
1425
1430
  log4("authentication not required", void 0, {
1426
1431
  F: __dxlog_file6,
1427
- L: 131,
1432
+ L: 138,
1428
1433
  S: this,
1429
1434
  C: (f, a) => f(...a)
1430
1435
  });
@@ -1444,12 +1449,25 @@ var InvitationHostExtension = class extends RpcExtension {
1444
1449
  }
1445
1450
  break;
1446
1451
  }
1452
+ case Invitation2.AuthMethod.KNOWN_PUBLIC_KEY: {
1453
+ if (!this.invitation.guestKeypair) {
1454
+ status = AuthenticationResponse.Status.INTERNAL_ERROR;
1455
+ break;
1456
+ }
1457
+ const isSignatureValid = this._challenge && verify(this._challenge, Buffer.from(signedChallenge ?? []), this.invitation.guestKeypair.publicKey.asBuffer());
1458
+ if (isSignatureValid) {
1459
+ this.authenticationPassed = true;
1460
+ } else {
1461
+ status = AuthenticationResponse.Status.INVALID_SIGNATURE;
1462
+ }
1463
+ break;
1464
+ }
1447
1465
  default: {
1448
1466
  log4.error("invalid authentication method", {
1449
1467
  authMethod: this.invitation.authMethod
1450
1468
  }, {
1451
1469
  F: __dxlog_file6,
1452
- L: 149,
1470
+ L: 176,
1453
1471
  S: this,
1454
1472
  C: (f, a) => f(...a)
1455
1473
  });
@@ -1464,7 +1482,7 @@ var InvitationHostExtension = class extends RpcExtension {
1464
1482
  }
1465
1483
  }), {
1466
1484
  F: __dxlog_file6,
1467
- L: 155,
1485
+ L: 182,
1468
1486
  S: this,
1469
1487
  C: (f, a) => f(...a)
1470
1488
  });
@@ -1478,14 +1496,14 @@ var InvitationHostExtension = class extends RpcExtension {
1478
1496
  id: traceId
1479
1497
  }), {
1480
1498
  F: __dxlog_file6,
1481
- L: 161,
1499
+ L: 188,
1482
1500
  S: this,
1483
1501
  C: (f, a) => f(...a)
1484
1502
  });
1485
1503
  try {
1486
1504
  invariant5(this.invitation, "Invitation is not set.", {
1487
1505
  F: __dxlog_file6,
1488
- L: 164,
1506
+ L: 191,
1489
1507
  S: this,
1490
1508
  A: [
1491
1509
  "this.invitation",
@@ -1500,7 +1518,7 @@ var InvitationHostExtension = class extends RpcExtension {
1500
1518
  id: traceId
1501
1519
  }), {
1502
1520
  F: __dxlog_file6,
1503
- L: 172,
1521
+ L: 199,
1504
1522
  S: this,
1505
1523
  C: (f, a) => f(...a)
1506
1524
  });
@@ -1557,7 +1575,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1557
1575
  options: async (options) => {
1558
1576
  invariant5(!this._remoteOptions, "Remote options already set.", {
1559
1577
  F: __dxlog_file6,
1560
- L: 239,
1578
+ L: 266,
1561
1579
  S: this,
1562
1580
  A: [
1563
1581
  "!this._remoteOptions",
@@ -1584,7 +1602,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1584
1602
  try {
1585
1603
  log4("begin options", void 0, {
1586
1604
  F: __dxlog_file6,
1587
- L: 260,
1605
+ L: 287,
1588
1606
  S: this,
1589
1607
  C: (f, a) => f(...a)
1590
1608
  });
@@ -1596,7 +1614,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1596
1614
  }));
1597
1615
  log4("end options", void 0, {
1598
1616
  F: __dxlog_file6,
1599
- L: 263,
1617
+ L: 290,
1600
1618
  S: this,
1601
1619
  C: (f, a) => f(...a)
1602
1620
  });
@@ -1610,7 +1628,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1610
1628
  } catch (err) {
1611
1629
  log4("openError", err, {
1612
1630
  F: __dxlog_file6,
1613
- L: 273,
1631
+ L: 300,
1614
1632
  S: this,
1615
1633
  C: (f, a) => f(...a)
1616
1634
  });
@@ -1620,7 +1638,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1620
1638
  async onClose() {
1621
1639
  log4("onClose", void 0, {
1622
1640
  F: __dxlog_file6,
1623
- L: 279,
1641
+ L: 306,
1624
1642
  S: this,
1625
1643
  C: (f, a) => f(...a)
1626
1644
  });
@@ -1639,11 +1657,11 @@ var InvitationsHandler = class {
1639
1657
  this._networkManager = _networkManager;
1640
1658
  }
1641
1659
  createInvitation(protocol, options) {
1642
- const { invitationId = PublicKey6.random().toHex(), type = Invitation3.Type.INTERACTIVE, authMethod = Invitation3.AuthMethod.SHARED_SECRET, state = Invitation3.State.INIT, timeout = INVITATION_TIMEOUT, swarmKey = PublicKey6.random(), persistent = true, created = /* @__PURE__ */ new Date(), lifetime = 86400 } = options ?? {};
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 ?? {};
1643
1661
  const authCode = options?.authCode ?? (authMethod === Invitation3.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0);
1644
1662
  invariant6(protocol, void 0, {
1645
1663
  F: __dxlog_file7,
1646
- L: 84,
1664
+ L: 87,
1647
1665
  S: this,
1648
1666
  A: [
1649
1667
  "protocol",
@@ -1658,9 +1676,11 @@ var InvitationsHandler = class {
1658
1676
  swarmKey,
1659
1677
  authCode,
1660
1678
  timeout,
1661
- persistent,
1679
+ persistent: persistent && type !== Invitation3.Type.DELEGATED,
1680
+ guestKeypair: guestKeypair ?? (authMethod === Invitation3.AuthMethod.KNOWN_PUBLIC_KEY ? createAdmissionKeypair() : void 0),
1662
1681
  created,
1663
1682
  lifetime,
1683
+ multiUse,
1664
1684
  ...protocol.getInvitationContext()
1665
1685
  };
1666
1686
  const stream = new PushStream();
@@ -1675,7 +1695,7 @@ var InvitationsHandler = class {
1675
1695
  ...protocol.toJSON()
1676
1696
  }, {
1677
1697
  F: __dxlog_file7,
1678
- L: 109,
1698
+ L: 115,
1679
1699
  S: this,
1680
1700
  C: (f, a) => f(...a)
1681
1701
  });
@@ -1700,7 +1720,7 @@ var InvitationsHandler = class {
1700
1720
  const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
1701
1721
  invariant6(deviceKey, void 0, {
1702
1722
  F: __dxlog_file7,
1703
- L: 130,
1723
+ L: 136,
1704
1724
  S: this,
1705
1725
  A: [
1706
1726
  "deviceKey",
@@ -1723,7 +1743,7 @@ var InvitationsHandler = class {
1723
1743
  id: traceId
1724
1744
  }), {
1725
1745
  F: __dxlog_file7,
1726
- L: 148,
1746
+ L: 154,
1727
1747
  S: this,
1728
1748
  C: (f, a) => f(...a)
1729
1749
  });
@@ -1731,7 +1751,7 @@ var InvitationsHandler = class {
1731
1751
  ...protocol.toJSON()
1732
1752
  }, {
1733
1753
  F: __dxlog_file7,
1734
- L: 149,
1754
+ L: 155,
1735
1755
  S: this,
1736
1756
  C: (f, a) => f(...a)
1737
1757
  });
@@ -1747,7 +1767,7 @@ var InvitationsHandler = class {
1747
1767
  ...protocol.toJSON()
1748
1768
  }, {
1749
1769
  F: __dxlog_file7,
1750
- L: 152,
1770
+ L: 158,
1751
1771
  S: this,
1752
1772
  C: (f, a) => f(...a)
1753
1773
  });
@@ -1759,7 +1779,7 @@ var InvitationsHandler = class {
1759
1779
  id: traceId
1760
1780
  }), {
1761
1781
  F: __dxlog_file7,
1762
- L: 154,
1782
+ L: 160,
1763
1783
  S: this,
1764
1784
  C: (f, a) => f(...a)
1765
1785
  });
@@ -1769,7 +1789,7 @@ var InvitationsHandler = class {
1769
1789
  ...protocol.toJSON()
1770
1790
  }, {
1771
1791
  F: __dxlog_file7,
1772
- L: 157,
1792
+ L: 163,
1773
1793
  S: this,
1774
1794
  C: (f, a) => f(...a)
1775
1795
  });
@@ -1780,7 +1800,7 @@ var InvitationsHandler = class {
1780
1800
  } else {
1781
1801
  log5.error("failed", err, {
1782
1802
  F: __dxlog_file7,
1783
- L: 160,
1803
+ L: 166,
1784
1804
  S: this,
1785
1805
  C: (f, a) => f(...a)
1786
1806
  });
@@ -1791,12 +1811,12 @@ var InvitationsHandler = class {
1791
1811
  error: err
1792
1812
  }), {
1793
1813
  F: __dxlog_file7,
1794
- L: 163,
1814
+ L: 169,
1795
1815
  S: this,
1796
1816
  C: (f, a) => f(...a)
1797
1817
  });
1798
1818
  } finally {
1799
- if (type !== Invitation3.Type.MULTIUSE) {
1819
+ if (!multiUse) {
1800
1820
  await swarmConnection.close();
1801
1821
  await ctx.dispose();
1802
1822
  }
@@ -1812,7 +1832,7 @@ var InvitationsHandler = class {
1812
1832
  ...protocol.toJSON()
1813
1833
  }, {
1814
1834
  F: __dxlog_file7,
1815
- L: 178,
1835
+ L: 184,
1816
1836
  S: this,
1817
1837
  C: (f, a) => f(...a)
1818
1838
  });
@@ -1823,7 +1843,7 @@ var InvitationsHandler = class {
1823
1843
  } else {
1824
1844
  log5.error("failed", err, {
1825
1845
  F: __dxlog_file7,
1826
- L: 181,
1846
+ L: 187,
1827
1847
  S: this,
1828
1848
  C: (f, a) => f(...a)
1829
1849
  });
@@ -1837,7 +1857,7 @@ var InvitationsHandler = class {
1837
1857
  if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
1838
1858
  log5.warn("invitation has already expired", void 0, {
1839
1859
  F: __dxlog_file7,
1840
- L: 192,
1860
+ L: 198,
1841
1861
  S: this,
1842
1862
  C: (f, a) => f(...a)
1843
1863
  });
@@ -1888,7 +1908,7 @@ var InvitationsHandler = class {
1888
1908
  const { timeout = INVITATION_TIMEOUT } = invitation;
1889
1909
  invariant6(protocol, void 0, {
1890
1910
  F: __dxlog_file7,
1891
- L: 246,
1911
+ L: 252,
1892
1912
  S: this,
1893
1913
  A: [
1894
1914
  "protocol",
@@ -1898,7 +1918,7 @@ var InvitationsHandler = class {
1898
1918
  if (deviceProfile) {
1899
1919
  invariant6(invitation.kind === Invitation3.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
1900
1920
  F: __dxlog_file7,
1901
- L: 250,
1921
+ L: 256,
1902
1922
  S: this,
1903
1923
  A: [
1904
1924
  "invitation.kind === Invitation.Kind.DEVICE",
@@ -1913,7 +1933,7 @@ var InvitationsHandler = class {
1913
1933
  const setState = (newData) => {
1914
1934
  invariant6(newData.state !== void 0, void 0, {
1915
1935
  F: __dxlog_file7,
1916
- L: 261,
1936
+ L: 267,
1917
1937
  S: this,
1918
1938
  A: [
1919
1939
  "newData.state !== undefined",
@@ -1933,7 +1953,7 @@ var InvitationsHandler = class {
1933
1953
  ...protocol.toJSON()
1934
1954
  }, {
1935
1955
  F: __dxlog_file7,
1936
- L: 269,
1956
+ L: 275,
1937
1957
  S: this,
1938
1958
  C: (f, a) => f(...a)
1939
1959
  });
@@ -1943,7 +1963,7 @@ var InvitationsHandler = class {
1943
1963
  } else {
1944
1964
  log5.warn("auth failed", err, {
1945
1965
  F: __dxlog_file7,
1946
- L: 272,
1966
+ L: 278,
1947
1967
  S: this,
1948
1968
  C: (f, a) => f(...a)
1949
1969
  });
@@ -1957,7 +1977,7 @@ var InvitationsHandler = class {
1957
1977
  ...protocol.toJSON()
1958
1978
  }, {
1959
1979
  F: __dxlog_file7,
1960
- L: 280,
1980
+ L: 286,
1961
1981
  S: this,
1962
1982
  C: (f, a) => f(...a)
1963
1983
  });
@@ -1972,7 +1992,7 @@ var InvitationsHandler = class {
1972
1992
  currentState
1973
1993
  }, {
1974
1994
  F: __dxlog_file7,
1975
- L: 290,
1995
+ L: 296,
1976
1996
  S: this,
1977
1997
  C: (f, a) => f(...a)
1978
1998
  });
@@ -1987,7 +2007,7 @@ var InvitationsHandler = class {
1987
2007
  id: traceId
1988
2008
  }), {
1989
2009
  F: __dxlog_file7,
1990
- L: 299,
2010
+ L: 305,
1991
2011
  S: this,
1992
2012
  C: (f, a) => f(...a)
1993
2013
  });
@@ -1999,7 +2019,7 @@ var InvitationsHandler = class {
1999
2019
  ...protocol.toJSON()
2000
2020
  }, {
2001
2021
  F: __dxlog_file7,
2002
- L: 307,
2022
+ L: 313,
2003
2023
  S: this,
2004
2024
  C: (f, a) => f(...a)
2005
2025
  });
@@ -2010,7 +2030,7 @@ var InvitationsHandler = class {
2010
2030
  ...protocol.toJSON()
2011
2031
  }, {
2012
2032
  F: __dxlog_file7,
2013
- L: 311,
2033
+ L: 317,
2014
2034
  S: this,
2015
2035
  C: (f, a) => f(...a)
2016
2036
  });
@@ -2020,62 +2040,28 @@ var InvitationsHandler = class {
2020
2040
  response: introductionResponse
2021
2041
  }, {
2022
2042
  F: __dxlog_file7,
2023
- L: 315,
2043
+ L: 321,
2024
2044
  S: this,
2025
2045
  C: (f, a) => f(...a)
2026
2046
  });
2027
2047
  invitation.authMethod = introductionResponse.authMethod;
2028
2048
  if (isAuthenticationRequired(invitation)) {
2029
- for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2030
- log5("guest waiting for authentication code...", void 0, {
2031
- F: __dxlog_file7,
2032
- L: 321,
2033
- S: this,
2034
- C: (f, a) => f(...a)
2035
- });
2036
- setState({
2037
- state: Invitation3.State.READY_FOR_AUTHENTICATION
2038
- });
2039
- const authCode = await authenticated.wait({
2040
- timeout
2041
- });
2042
- log5("sending authentication request", void 0, {
2043
- F: __dxlog_file7,
2044
- L: 325,
2045
- S: this,
2046
- C: (f, a) => f(...a)
2047
- });
2048
- setState({
2049
- state: Invitation3.State.AUTHENTICATING
2050
- });
2051
- const response = await extension.rpc.InvitationHostService.authenticate({
2052
- authCode
2053
- });
2054
- if (response.status === void 0 || response.status === AuthenticationResponse2.Status.OK) {
2049
+ switch (invitation.authMethod) {
2050
+ case Invitation3.AuthMethod.SHARED_SECRET:
2051
+ await this._handleGuestOtpAuth(extension, setState, authenticated, {
2052
+ timeout
2053
+ });
2054
+ break;
2055
+ case Invitation3.AuthMethod.KNOWN_PUBLIC_KEY:
2056
+ await this._handleGuestKpkAuth(extension, setState, invitation, introductionResponse);
2055
2057
  break;
2056
- }
2057
- if (response.status === AuthenticationResponse2.Status.INVALID_OTP) {
2058
- if (attempt === MAX_OTP_ATTEMPTS) {
2059
- throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
2060
- } else {
2061
- log5("retrying invalid code", {
2062
- attempt
2063
- }, {
2064
- F: __dxlog_file7,
2065
- L: 336,
2066
- S: this,
2067
- C: (f, a) => f(...a)
2068
- });
2069
- authenticated.reset();
2070
- }
2071
- }
2072
2058
  }
2073
2059
  }
2074
2060
  log5("request admission", {
2075
2061
  ...protocol.toJSON()
2076
2062
  }, {
2077
2063
  F: __dxlog_file7,
2078
- L: 344,
2064
+ L: 337,
2079
2065
  S: this,
2080
2066
  C: (f, a) => f(...a)
2081
2067
  });
@@ -2087,7 +2073,7 @@ var InvitationsHandler = class {
2087
2073
  ...protocol.toJSON()
2088
2074
  }, {
2089
2075
  F: __dxlog_file7,
2090
- L: 355,
2076
+ L: 348,
2091
2077
  S: this,
2092
2078
  C: (f, a) => f(...a)
2093
2079
  });
@@ -2100,7 +2086,7 @@ var InvitationsHandler = class {
2100
2086
  id: traceId
2101
2087
  }), {
2102
2088
  F: __dxlog_file7,
2103
- L: 357,
2089
+ L: 350,
2104
2090
  S: this,
2105
2091
  C: (f, a) => f(...a)
2106
2092
  });
@@ -2110,7 +2096,7 @@ var InvitationsHandler = class {
2110
2096
  ...protocol.toJSON()
2111
2097
  }, {
2112
2098
  F: __dxlog_file7,
2113
- L: 360,
2099
+ L: 353,
2114
2100
  S: this,
2115
2101
  C: (f, a) => f(...a)
2116
2102
  });
@@ -2120,7 +2106,7 @@ var InvitationsHandler = class {
2120
2106
  } else {
2121
2107
  log5("auth failed", err, {
2122
2108
  F: __dxlog_file7,
2123
- L: 363,
2109
+ L: 356,
2124
2110
  S: this,
2125
2111
  C: (f, a) => f(...a)
2126
2112
  });
@@ -2131,7 +2117,7 @@ var InvitationsHandler = class {
2131
2117
  error: err
2132
2118
  }), {
2133
2119
  F: __dxlog_file7,
2134
- L: 366,
2120
+ L: 359,
2135
2121
  S: this,
2136
2122
  C: (f, a) => f(...a)
2137
2123
  });
@@ -2149,7 +2135,7 @@ var InvitationsHandler = class {
2149
2135
  ...protocol.toJSON()
2150
2136
  }, {
2151
2137
  F: __dxlog_file7,
2152
- L: 377,
2138
+ L: 370,
2153
2139
  S: this,
2154
2140
  C: (f, a) => f(...a)
2155
2141
  });
@@ -2159,7 +2145,7 @@ var InvitationsHandler = class {
2159
2145
  } else {
2160
2146
  log5("auth failed", err, {
2161
2147
  F: __dxlog_file7,
2162
- L: 380,
2148
+ L: 373,
2163
2149
  S: this,
2164
2150
  C: (f, a) => f(...a)
2165
2151
  });
@@ -2176,7 +2162,7 @@ var InvitationsHandler = class {
2176
2162
  } else {
2177
2163
  invariant6(invitation.swarmKey, void 0, {
2178
2164
  F: __dxlog_file7,
2179
- L: 394,
2165
+ L: 387,
2180
2166
  S: this,
2181
2167
  A: [
2182
2168
  "invitation.swarmKey",
@@ -2214,15 +2200,88 @@ var InvitationsHandler = class {
2214
2200
  });
2215
2201
  return observable;
2216
2202
  }
2203
+ async _handleGuestOtpAuth(extension, setState, authenticated, options) {
2204
+ for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2205
+ log5("guest waiting for authentication code...", void 0, {
2206
+ F: __dxlog_file7,
2207
+ L: 427,
2208
+ S: this,
2209
+ C: (f, a) => f(...a)
2210
+ });
2211
+ setState({
2212
+ state: Invitation3.State.READY_FOR_AUTHENTICATION
2213
+ });
2214
+ const authCode = await authenticated.wait(options);
2215
+ log5("sending authentication request", void 0, {
2216
+ F: __dxlog_file7,
2217
+ L: 431,
2218
+ S: this,
2219
+ C: (f, a) => f(...a)
2220
+ });
2221
+ setState({
2222
+ state: Invitation3.State.AUTHENTICATING
2223
+ });
2224
+ const response = await extension.rpc.InvitationHostService.authenticate({
2225
+ authCode
2226
+ });
2227
+ if (response.status === void 0 || response.status === AuthenticationResponse2.Status.OK) {
2228
+ break;
2229
+ }
2230
+ if (response.status === AuthenticationResponse2.Status.INVALID_OTP) {
2231
+ if (attempt === MAX_OTP_ATTEMPTS) {
2232
+ throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
2233
+ } else {
2234
+ log5("retrying invalid code", {
2235
+ attempt
2236
+ }, {
2237
+ F: __dxlog_file7,
2238
+ L: 442,
2239
+ S: this,
2240
+ C: (f, a) => f(...a)
2241
+ });
2242
+ authenticated.reset();
2243
+ }
2244
+ }
2245
+ }
2246
+ }
2247
+ async _handleGuestKpkAuth(extension, setState, invitation, introductionResponse) {
2248
+ if (invitation.guestKeypair?.privateKey == null) {
2249
+ throw new Error("keypair missing in the invitation");
2250
+ }
2251
+ if (introductionResponse.challenge == null) {
2252
+ throw new Error("challenge missing in the introduction");
2253
+ }
2254
+ log5("sending authentication request", void 0, {
2255
+ F: __dxlog_file7,
2256
+ L: 461,
2257
+ S: this,
2258
+ C: (f, a) => f(...a)
2259
+ });
2260
+ setState({
2261
+ state: Invitation3.State.AUTHENTICATING
2262
+ });
2263
+ const signature = sign(Buffer.from(introductionResponse.challenge), invitation.guestKeypair.privateKey);
2264
+ const response = await extension.rpc.InvitationHostService.authenticate({
2265
+ signedChallenge: signature
2266
+ });
2267
+ if (response.status !== AuthenticationResponse2.Status.OK) {
2268
+ throw new Error(`Authentication failed with code: ${response.status}`);
2269
+ }
2270
+ }
2217
2271
  };
2218
- var invitationExpired = (invitation) => {
2219
- return invitation.created && invitation.lifetime && invitation.lifetime !== 0 && invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now();
2272
+ var createAdmissionKeypair = () => {
2273
+ const keypair = createKeyPair();
2274
+ return {
2275
+ publicKey: PublicKey6.from(keypair.publicKey),
2276
+ privateKey: keypair.secretKey
2277
+ };
2220
2278
  };
2221
2279
 
2222
2280
  // packages/sdk/client-services/src/packlets/invitations/invitations-service.ts
2223
2281
  import { Event as Event3, scheduleTask as scheduleTask3 } from "@dxos/async";
2224
2282
  import { Stream as Stream8 } from "@dxos/codec-protobuf";
2225
2283
  import { Context as Context6 } from "@dxos/context";
2284
+ import { hasInvitationExpired } from "@dxos/echo-pipeline";
2226
2285
  import { invariant as invariant7 } from "@dxos/invariant";
2227
2286
  import { log as log6 } from "@dxos/log";
2228
2287
  import { Invitation as Invitation4, QueryInvitationsResponse } from "@dxos/protocols/proto/dxos/client/services";
@@ -2281,7 +2340,7 @@ var InvitationsServiceImpl = class {
2281
2340
  await this._metadataStore.removeInvitation(invitation.get().invitationId);
2282
2341
  }
2283
2342
  this._createInvitations.delete(invitation.get().invitationId);
2284
- if (invitation.get().type !== Invitation4.Type.MULTIUSE) {
2343
+ if (!invitation.get().multiUse) {
2285
2344
  this._removedCreated.emit(invitation.get());
2286
2345
  }
2287
2346
  });
@@ -2289,7 +2348,7 @@ var InvitationsServiceImpl = class {
2289
2348
  }
2290
2349
  async loadPersistentInvitations() {
2291
2350
  const persistentInvitations = this._metadataStore.getInvitations();
2292
- const freshInvitations = persistentInvitations.filter(async (invitation) => !invitationExpired(invitation));
2351
+ const freshInvitations = persistentInvitations.filter(async (invitation) => !hasInvitationExpired(invitation));
2293
2352
  const cInvitations = freshInvitations.map((persistentInvitation) => {
2294
2353
  invariant7(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
2295
2354
  F: __dxlog_file8,
@@ -2342,7 +2401,7 @@ var InvitationsServiceImpl = class {
2342
2401
  }, () => {
2343
2402
  close();
2344
2403
  this._acceptInvitations.delete(invitation.get().invitationId);
2345
- if (invitation.get().type !== Invitation4.Type.MULTIUSE) {
2404
+ if (!invitation.get().multiUse) {
2346
2405
  this._removedAccepted.emit(invitation.get());
2347
2406
  }
2348
2407
  });
@@ -2730,156 +2789,6 @@ ClientRpcServer = _ts_decorate3([
2730
2789
  trace5.resource()
2731
2790
  ], ClientRpcServer);
2732
2791
 
2733
- // packages/sdk/client-services/src/packlets/services/diagnostics.ts
2734
- import { getFirstStreamValue } from "@dxos/codec-protobuf";
2735
- import { credentialTypeFilter } from "@dxos/credentials";
2736
- import { invariant as invariant9 } from "@dxos/invariant";
2737
- import { STORAGE_VERSION } from "@dxos/protocols";
2738
- import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
2739
- import { TRACE_PROCESSOR } from "@dxos/tracing";
2740
-
2741
- // packages/sdk/client-services/src/packlets/services/platform.ts
2742
- import { Platform } from "@dxos/protocols/proto/dxos/client/services";
2743
- var getPlatform = () => {
2744
- if (process.browser) {
2745
- if (typeof window !== "undefined") {
2746
- const { userAgent } = window.navigator;
2747
- return {
2748
- type: Platform.PLATFORM_TYPE.BROWSER,
2749
- userAgent,
2750
- uptime: Math.floor((Date.now() - window.performance.timeOrigin) / 1e3)
2751
- };
2752
- } else {
2753
- return {
2754
- type: Platform.PLATFORM_TYPE.SHARED_WORKER,
2755
- uptime: Math.floor((Date.now() - performance.timeOrigin) / 1e3)
2756
- };
2757
- }
2758
- } else {
2759
- const { platform: platform2, version, arch } = process;
2760
- return {
2761
- type: Platform.PLATFORM_TYPE.NODE,
2762
- platform: platform2,
2763
- arch,
2764
- runtime: version,
2765
- uptime: Math.floor(process.uptime()),
2766
- memory: process.memoryUsage()
2767
- };
2768
- }
2769
- };
2770
-
2771
- // packages/sdk/client-services/src/version.ts
2772
- var DXOS_VERSION = "0.4.10-main.fd4f2a3";
2773
-
2774
- // packages/sdk/client-services/src/packlets/services/diagnostics.ts
2775
- var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
2776
- var DEFAULT_TIMEOUT = 1e3;
2777
- var createDiagnostics = async (clientServices, serviceContext, config) => {
2778
- const diagnostics = {
2779
- created: (/* @__PURE__ */ new Date()).toISOString(),
2780
- platform: getPlatform(),
2781
- client: {
2782
- version: DXOS_VERSION,
2783
- storage: {
2784
- version: STORAGE_VERSION
2785
- }
2786
- },
2787
- trace: TRACE_PROCESSOR.getDiagnostics()
2788
- };
2789
- {
2790
- invariant9(clientServices.LoggingService, "SystemService is not available.", {
2791
- F: __dxlog_file10,
2792
- L: 108,
2793
- S: void 0,
2794
- A: [
2795
- "clientServices.LoggingService",
2796
- "'SystemService is not available.'"
2797
- ]
2798
- });
2799
- diagnostics.metrics = await getFirstStreamValue(clientServices.LoggingService.queryMetrics({}), {
2800
- timeout: DEFAULT_TIMEOUT
2801
- }).catch(() => void 0);
2802
- }
2803
- if (typeof navigator !== "undefined" && navigator.storage) {
2804
- const map = /* @__PURE__ */ new Map();
2805
- const dir = await navigator.storage.getDirectory();
2806
- for await (const filename of dir?.keys()) {
2807
- const idx = filename.indexOf("-", filename.indexOf("-") + 1);
2808
- if (idx === -1) {
2809
- continue;
2810
- }
2811
- map.set(filename.slice(0, idx), (map.get(filename.slice(0, idx)) ?? 0) + 1);
2812
- }
2813
- diagnostics.storage = Array.from(map.entries()).sort((a, b) => b[1] - a[1]).map(([file, count]) => ({
2814
- file,
2815
- count
2816
- }));
2817
- }
2818
- const identity = serviceContext.identityManager.identity;
2819
- if (identity) {
2820
- diagnostics.identity = {
2821
- identityKey: identity.identityKey,
2822
- spaceKey: identity.space.key,
2823
- profile: identity.profileDocument
2824
- };
2825
- const { devices } = await getFirstStreamValue(clientServices.DevicesService.queryDevices(), {
2826
- timeout: DEFAULT_TIMEOUT
2827
- }).catch(() => void 0) ?? {};
2828
- diagnostics.devices = devices;
2829
- if (serviceContext.dataSpaceManager) {
2830
- diagnostics.spaces = await Promise.all(Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space)) ?? []);
2831
- }
2832
- const { feeds = [] } = await getFirstStreamValue(clientServices.DevtoolsHost.subscribeToFeeds({}), {
2833
- timeout: DEFAULT_TIMEOUT
2834
- }).catch(() => void 0) ?? {};
2835
- diagnostics.feeds = feeds.map(({ feedKey, bytes, length }) => ({
2836
- feedKey,
2837
- bytes,
2838
- length
2839
- }));
2840
- const status = await getFirstStreamValue(clientServices.NetworkService.queryStatus(), {
2841
- timeout: DEFAULT_TIMEOUT
2842
- }).catch(() => void 0);
2843
- diagnostics.networkStatus = status;
2844
- diagnostics.swarms = serviceContext.networkManager.connectionLog?.swarms;
2845
- }
2846
- diagnostics.config = config.values;
2847
- return diagnostics;
2848
- };
2849
- var getSpaceStats = async (space) => {
2850
- const stats = {
2851
- key: space.key,
2852
- metrics: space.metrics,
2853
- epochs: space.inner.spaceState.credentials.filter(credentialTypeFilter("dxos.halo.credentials.Epoch")).map((credential) => ({
2854
- ...credential.subject.assertion,
2855
- id: credential.id
2856
- })),
2857
- members: Array.from(space.inner.spaceState.members.values()).map((member) => ({
2858
- identity: {
2859
- identityKey: member.key,
2860
- profile: {
2861
- displayName: member.assertion.profile?.displayName
2862
- }
2863
- },
2864
- presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember.PresenceState.ONLINE : SpaceMember.PresenceState.OFFLINE
2865
- })),
2866
- pipeline: {
2867
- // TODO(burdon): Pick properties from credentials if needed.
2868
- currentEpoch: space.automergeSpaceState.lastEpoch,
2869
- appliedEpoch: space.automergeSpaceState.lastEpoch,
2870
- controlFeeds: space.inner.controlPipeline.state.feeds.map((feed) => feed.key),
2871
- currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
2872
- targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
2873
- totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe
2874
- }
2875
- };
2876
- if (stats.metrics) {
2877
- const { open, ready } = stats.metrics;
2878
- stats.metrics.startupTime = open && ready && ready.getTime() - open.getTime();
2879
- }
2880
- return stats;
2881
- };
2882
-
2883
2792
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2884
2793
  import { Event as Event6, asyncTimeout, scheduleTask as scheduleTask5, sleep as sleep2, synchronized, trackLeaks } from "@dxos/async";
2885
2794
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
@@ -2888,7 +2797,7 @@ import { timed, warnAfterTimeout } from "@dxos/debug";
2888
2797
  import { TYPE_PROPERTIES } from "@dxos/echo-db";
2889
2798
  import { createMappedFeedWriter } from "@dxos/echo-pipeline";
2890
2799
  import { AutomergeDocumentLoaderImpl } from "@dxos/echo-pipeline";
2891
- import { failedInvariant, invariant as invariant11 } from "@dxos/invariant";
2800
+ import { failedInvariant, invariant as invariant10 } from "@dxos/invariant";
2892
2801
  import { PublicKey as PublicKey8 } from "@dxos/keys";
2893
2802
  import { log as log9 } from "@dxos/log";
2894
2803
  import { CancelledError, SystemError } from "@dxos/protocols";
@@ -2939,13 +2848,13 @@ var AutomergeSpaceState = class {
2939
2848
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
2940
2849
  import { DeferredTask, Event as Event5, scheduleTask as scheduleTask4, sleep, TimeoutError as TimeoutError2, Trigger as Trigger4 } from "@dxos/async";
2941
2850
  import { Context as Context7, rejectOnDispose } from "@dxos/context";
2942
- import { invariant as invariant10 } from "@dxos/invariant";
2851
+ import { invariant as invariant9 } from "@dxos/invariant";
2943
2852
  import { PublicKey as PublicKey7 } from "@dxos/keys";
2944
2853
  import { log as log8 } from "@dxos/log";
2945
2854
  import { schema as schema3 } from "@dxos/protocols";
2946
2855
  import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
2947
2856
  import { ComplexMap as ComplexMap2, ComplexSet as ComplexSet2, entry } from "@dxos/util";
2948
- var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
2857
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
2949
2858
  var DEFAULT_RETRY_TIMEOUT = 1e3;
2950
2859
  var DEFAULT_SUCCESS_DELAY = 1e3;
2951
2860
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
@@ -2973,13 +2882,13 @@ var NotarizationPlugin = class {
2973
2882
  log8("notarize", {
2974
2883
  credentials
2975
2884
  }, {
2976
- F: __dxlog_file11,
2885
+ F: __dxlog_file10,
2977
2886
  L: 90,
2978
2887
  S: this,
2979
2888
  C: (f, a) => f(...a)
2980
2889
  });
2981
- invariant10(credentials.every((credential) => credential.id), "Credentials must have an id", {
2982
- F: __dxlog_file11,
2890
+ invariant9(credentials.every((credential) => credential.id), "Credentials must have an id", {
2891
+ F: __dxlog_file10,
2983
2892
  L: 91,
2984
2893
  S: this,
2985
2894
  A: [
@@ -2993,7 +2902,7 @@ var NotarizationPlugin = class {
2993
2902
  log8.warn("Notarization error", {
2994
2903
  err
2995
2904
  }, {
2996
- F: __dxlog_file11,
2905
+ F: __dxlog_file10,
2997
2906
  L: 99,
2998
2907
  S: this,
2999
2908
  C: (f, a) => f(...a)
@@ -3009,7 +2918,7 @@ var NotarizationPlugin = class {
3009
2918
  timeout,
3010
2919
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
3011
2920
  }, {
3012
- F: __dxlog_file11,
2921
+ F: __dxlog_file10,
3013
2922
  L: 111,
3014
2923
  S: this,
3015
2924
  C: (f, a) => f(...a)
@@ -3032,7 +2941,7 @@ var NotarizationPlugin = class {
3032
2941
  log8.info("Exhausted all peers to notarize with", {
3033
2942
  retryIn: retryTimeout
3034
2943
  }, {
3035
- F: __dxlog_file11,
2944
+ F: __dxlog_file10,
3036
2945
  L: 136,
3037
2946
  S: this,
3038
2947
  C: (f, a) => f(...a)
@@ -3046,7 +2955,7 @@ var NotarizationPlugin = class {
3046
2955
  peer: peer.localPeerId,
3047
2956
  credentialId: credentials.map((credential) => credential.id)
3048
2957
  }, {
3049
- F: __dxlog_file11,
2958
+ F: __dxlog_file10,
3050
2959
  L: 143,
3051
2960
  S: this,
3052
2961
  C: (f, a) => f(...a)
@@ -3055,7 +2964,7 @@ var NotarizationPlugin = class {
3055
2964
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
3056
2965
  });
3057
2966
  log8("success", void 0, {
3058
- F: __dxlog_file11,
2967
+ F: __dxlog_file10,
3059
2968
  L: 147,
3060
2969
  S: this,
3061
2970
  C: (f, a) => f(...a)
@@ -3064,7 +2973,7 @@ var NotarizationPlugin = class {
3064
2973
  } catch (err) {
3065
2974
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
3066
2975
  log8.info("error notarizing (recoverable)", err, {
3067
- F: __dxlog_file11,
2976
+ F: __dxlog_file10,
3068
2977
  L: 151,
3069
2978
  S: this,
3070
2979
  C: (f, a) => f(...a)
@@ -3082,7 +2991,7 @@ var NotarizationPlugin = class {
3082
2991
  errors.wait()
3083
2992
  ]);
3084
2993
  log8("done", void 0, {
3085
- F: __dxlog_file11,
2994
+ F: __dxlog_file10,
3086
2995
  L: 162,
3087
2996
  S: this,
3088
2997
  C: (f, a) => f(...a)
@@ -3103,8 +3012,8 @@ var NotarizationPlugin = class {
3103
3012
  this._processCredentialsTriggers.delete(credential.id);
3104
3013
  }
3105
3014
  setWriter(writer) {
3106
- invariant10(!this._writer, "Writer already set.", {
3107
- F: __dxlog_file11,
3015
+ invariant9(!this._writer, "Writer already set.", {
3016
+ F: __dxlog_file10,
3108
3017
  L: 181,
3109
3018
  S: this,
3110
3019
  A: [
@@ -3128,8 +3037,8 @@ var NotarizationPlugin = class {
3128
3037
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
3129
3038
  }
3130
3039
  for (const credential of request.credentials ?? []) {
3131
- invariant10(credential.id, "Credential must have an id", {
3132
- F: __dxlog_file11,
3040
+ invariant9(credential.id, "Credential must have an id", {
3041
+ F: __dxlog_file10,
3133
3042
  L: 200,
3134
3043
  S: this,
3135
3044
  A: [
@@ -3149,7 +3058,7 @@ var NotarizationPlugin = class {
3149
3058
  log8("extension opened", {
3150
3059
  peer: extension.localPeerId
3151
3060
  }, {
3152
- F: __dxlog_file11,
3061
+ F: __dxlog_file10,
3153
3062
  L: 211,
3154
3063
  S: this,
3155
3064
  C: (f, a) => f(...a)
@@ -3161,7 +3070,7 @@ var NotarizationPlugin = class {
3161
3070
  log8("extension closed", {
3162
3071
  peer: extension.localPeerId
3163
3072
  }, {
3164
- F: __dxlog_file11,
3073
+ F: __dxlog_file10,
3165
3074
  L: 216,
3166
3075
  S: this,
3167
3076
  C: (f, a) => f(...a)
@@ -3215,7 +3124,7 @@ function _ts_decorate4(decorators, target, key, desc) {
3215
3124
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3216
3125
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3217
3126
  }
3218
- var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
3127
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
3219
3128
  var DataSpace = class {
3220
3129
  constructor(params) {
3221
3130
  this._ctx = new Context8();
@@ -3250,7 +3159,7 @@ var DataSpace = class {
3250
3159
  log9("new state", {
3251
3160
  state: SpaceState[this._state]
3252
3161
  }, {
3253
- F: __dxlog_file12,
3162
+ F: __dxlog_file11,
3254
3163
  L: 140,
3255
3164
  S: this,
3256
3165
  C: (f, a) => f(...a)
@@ -3300,7 +3209,7 @@ var DataSpace = class {
3300
3209
  log9("new state", {
3301
3210
  state: SpaceState[this._state]
3302
3211
  }, {
3303
- F: __dxlog_file12,
3212
+ F: __dxlog_file11,
3304
3213
  L: 198,
3305
3214
  S: this,
3306
3215
  C: (f, a) => f(...a)
@@ -3318,7 +3227,7 @@ var DataSpace = class {
3318
3227
  log9("new state", {
3319
3228
  state: SpaceState[this._state]
3320
3229
  }, {
3321
- F: __dxlog_file12,
3230
+ F: __dxlog_file11,
3322
3231
  L: 212,
3323
3232
  S: this,
3324
3233
  C: (f, a) => f(...a)
@@ -3350,7 +3259,7 @@ var DataSpace = class {
3350
3259
  } catch (err) {
3351
3260
  if (err instanceof CancelledError || err instanceof ContextDisposedError) {
3352
3261
  log9("data pipeline initialization cancelled", err, {
3353
- F: __dxlog_file12,
3262
+ F: __dxlog_file11,
3354
3263
  L: 245,
3355
3264
  S: this,
3356
3265
  C: (f, a) => f(...a)
@@ -3358,7 +3267,7 @@ var DataSpace = class {
3358
3267
  return;
3359
3268
  }
3360
3269
  log9.error("Error initializing data pipeline", err, {
3361
- F: __dxlog_file12,
3270
+ F: __dxlog_file11,
3362
3271
  L: 249,
3363
3272
  S: this,
3364
3273
  C: (f, a) => f(...a)
@@ -3367,7 +3276,7 @@ var DataSpace = class {
3367
3276
  log9("new state", {
3368
3277
  state: SpaceState[this._state]
3369
3278
  }, {
3370
- F: __dxlog_file12,
3279
+ F: __dxlog_file11,
3371
3280
  L: 251,
3372
3281
  S: this,
3373
3282
  C: (f, a) => f(...a)
@@ -3387,7 +3296,7 @@ var DataSpace = class {
3387
3296
  log9("new state", {
3388
3297
  state: SpaceState[this._state]
3389
3298
  }, {
3390
- F: __dxlog_file12,
3299
+ F: __dxlog_file11,
3391
3300
  L: 267,
3392
3301
  S: this,
3393
3302
  C: (f, a) => f(...a)
@@ -3397,7 +3306,7 @@ var DataSpace = class {
3397
3306
  this._automergeSpaceState.startProcessingRootDocs();
3398
3307
  await cancelWithContext2(this._ctx, this.automergeSpaceState.ensureEpochInitialized());
3399
3308
  log9("data pipeline ready", void 0, {
3400
- F: __dxlog_file12,
3309
+ F: __dxlog_file11,
3401
3310
  L: 279,
3402
3311
  S: this,
3403
3312
  C: (f, a) => f(...a)
@@ -3407,7 +3316,7 @@ var DataSpace = class {
3407
3316
  log9("new state", {
3408
3317
  state: SpaceState[this._state]
3409
3318
  }, {
3410
- F: __dxlog_file12,
3319
+ F: __dxlog_file11,
3411
3320
  L: 283,
3412
3321
  S: this,
3413
3322
  C: (f, a) => f(...a)
@@ -3423,7 +3332,7 @@ var DataSpace = class {
3423
3332
  this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
3424
3333
  await this._createWritableFeeds();
3425
3334
  log9("writable feeds created", void 0, {
3426
- F: __dxlog_file12,
3335
+ F: __dxlog_file11,
3427
3336
  L: 299,
3428
3337
  S: this,
3429
3338
  C: (f, a) => f(...a)
@@ -3486,7 +3395,7 @@ var DataSpace = class {
3486
3395
  space: this.key,
3487
3396
  rootUrl
3488
3397
  }, {
3489
- F: __dxlog_file12,
3398
+ F: __dxlog_file11,
3490
3399
  L: 365,
3491
3400
  S: this,
3492
3401
  C: (f, a) => f(...a)
@@ -3518,7 +3427,7 @@ var DataSpace = class {
3518
3427
  rootUrl,
3519
3428
  err
3520
3429
  }, {
3521
- F: __dxlog_file12,
3430
+ F: __dxlog_file11,
3522
3431
  L: 388,
3523
3432
  S: this,
3524
3433
  C: (f, a) => f(...a)
@@ -3572,8 +3481,8 @@ var DataSpace = class {
3572
3481
  const rootHandle = this._automergeHost.repo.find(currentRootUrl);
3573
3482
  await cancelWithContext2(this._ctx, asyncTimeout(rootHandle.whenReady(), 1e4));
3574
3483
  const newRoot = this._automergeHost.repo.create(rootHandle.docSync());
3575
- invariant11(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3576
- F: __dxlog_file12,
3484
+ invariant10(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3485
+ F: __dxlog_file11,
3577
3486
  L: 438,
3578
3487
  S: this,
3579
3488
  A: [
@@ -3592,7 +3501,7 @@ var DataSpace = class {
3592
3501
  case CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT:
3593
3502
  {
3594
3503
  log9.info("Fragmenting", void 0, {
3595
- F: __dxlog_file12,
3504
+ F: __dxlog_file11,
3596
3505
  L: 450,
3597
3506
  S: this,
3598
3507
  C: (f, a) => f(...a)
@@ -3603,8 +3512,8 @@ var DataSpace = class {
3603
3512
  const objects = Object.entries(rootHandle.docSync().objects);
3604
3513
  const properties = objects.find(([_, value]) => value.system.type?.itemId === TYPE_PROPERTIES);
3605
3514
  const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
3606
- invariant11(properties, "Properties not found", {
3607
- F: __dxlog_file12,
3515
+ invariant10(properties, "Properties not found", {
3516
+ F: __dxlog_file11,
3608
3517
  L: 460,
3609
3518
  S: this,
3610
3519
  A: [
@@ -3619,8 +3528,8 @@ var DataSpace = class {
3619
3528
  ])
3620
3529
  };
3621
3530
  const newRoot = this._automergeHost.repo.create(newSpaceDoc);
3622
- invariant11(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3623
- F: __dxlog_file12,
3531
+ invariant10(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3532
+ F: __dxlog_file11,
3624
3533
  L: 465,
3625
3534
  S: this,
3626
3535
  A: [
@@ -3689,7 +3598,7 @@ var DataSpace = class {
3689
3598
  log9("new state", {
3690
3599
  state: SpaceState[this._state]
3691
3600
  }, {
3692
- F: __dxlog_file12,
3601
+ F: __dxlog_file11,
3693
3602
  L: 531,
3694
3603
  S: this,
3695
3604
  C: (f, a) => f(...a)
@@ -3747,7 +3656,7 @@ DataSpace = _ts_decorate4([
3747
3656
  import { Event as Event7, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
3748
3657
  import { Context as Context9, cancelWithContext as cancelWithContext3 } from "@dxos/context";
3749
3658
  import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
3750
- import { invariant as invariant12 } from "@dxos/invariant";
3659
+ import { invariant as invariant11 } from "@dxos/invariant";
3751
3660
  import { PublicKey as PublicKey9 } from "@dxos/keys";
3752
3661
  import { log as log10 } from "@dxos/log";
3753
3662
  import { trace as trace7 } from "@dxos/protocols";
@@ -3758,7 +3667,7 @@ import { ComplexMap as ComplexMap3, deferFunction as deferFunction2, forEachAsyn
3758
3667
  // packages/sdk/client-services/src/packlets/spaces/genesis.ts
3759
3668
  import { createCredential } from "@dxos/credentials";
3760
3669
  import { failUndefined } from "@dxos/debug";
3761
- import { AdmittedFeed as AdmittedFeed4, SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/halo/credentials";
3670
+ import { AdmittedFeed as AdmittedFeed4, SpaceMember } from "@dxos/protocols/proto/dxos/halo/credentials";
3762
3671
  import { Timeframe as Timeframe3 } from "@dxos/timeframe";
3763
3672
  var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3764
3673
  const credentials = [
@@ -3778,7 +3687,7 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3778
3687
  assertion: {
3779
3688
  "@type": "dxos.halo.credentials.SpaceMember",
3780
3689
  spaceKey: space.key,
3781
- role: SpaceMember2.Role.ADMIN,
3690
+ role: SpaceMember.Role.ADMIN,
3782
3691
  profile: signingContext.getProfile(),
3783
3692
  genesisFeedKey: space.controlFeedKey ?? failUndefined()
3784
3693
  }
@@ -3836,7 +3745,7 @@ function _ts_decorate5(decorators, target, key, desc) {
3836
3745
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3837
3746
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3838
3747
  }
3839
- var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
3748
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
3840
3749
  var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
3841
3750
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
3842
3751
  var DataSpaceManager = class {
@@ -3862,7 +3771,7 @@ var DataSpaceManager = class {
3862
3771
  }
3863
3772
  async open() {
3864
3773
  log10("open", void 0, {
3865
- F: __dxlog_file13,
3774
+ F: __dxlog_file12,
3866
3775
  L: 98,
3867
3776
  S: this,
3868
3777
  C: (f, a) => f(...a)
@@ -3870,7 +3779,7 @@ var DataSpaceManager = class {
3870
3779
  log10.trace("dxos.echo.data-space-manager.open", trace7.begin({
3871
3780
  id: this._instanceId
3872
3781
  }), {
3873
- F: __dxlog_file13,
3782
+ F: __dxlog_file12,
3874
3783
  L: 99,
3875
3784
  S: this,
3876
3785
  C: (f, a) => f(...a)
@@ -3878,7 +3787,7 @@ var DataSpaceManager = class {
3878
3787
  log10("metadata loaded", {
3879
3788
  spaces: this._metadataStore.spaces.length
3880
3789
  }, {
3881
- F: __dxlog_file13,
3790
+ F: __dxlog_file12,
3882
3791
  L: 100,
3883
3792
  S: this,
3884
3793
  C: (f, a) => f(...a)
@@ -3888,7 +3797,7 @@ var DataSpaceManager = class {
3888
3797
  log10("load space", {
3889
3798
  spaceMetadata
3890
3799
  }, {
3891
- F: __dxlog_file13,
3800
+ F: __dxlog_file12,
3892
3801
  L: 104,
3893
3802
  S: this,
3894
3803
  C: (f, a) => f(...a)
@@ -3899,7 +3808,7 @@ var DataSpaceManager = class {
3899
3808
  spaceMetadata,
3900
3809
  err
3901
3810
  }, {
3902
- F: __dxlog_file13,
3811
+ F: __dxlog_file12,
3903
3812
  L: 107,
3904
3813
  S: this,
3905
3814
  C: (f, a) => f(...a)
@@ -3916,7 +3825,7 @@ var DataSpaceManager = class {
3916
3825
  log10.trace("dxos.echo.data-space-manager.open", trace7.end({
3917
3826
  id: this._instanceId
3918
3827
  }), {
3919
- F: __dxlog_file13,
3828
+ F: __dxlog_file12,
3920
3829
  L: 120,
3921
3830
  S: this,
3922
3831
  C: (f, a) => f(...a)
@@ -3924,7 +3833,7 @@ var DataSpaceManager = class {
3924
3833
  }
3925
3834
  async close() {
3926
3835
  log10("close", void 0, {
3927
- F: __dxlog_file13,
3836
+ F: __dxlog_file12,
3928
3837
  L: 125,
3929
3838
  S: this,
3930
3839
  C: (f, a) => f(...a)
@@ -3939,8 +3848,8 @@ var DataSpaceManager = class {
3939
3848
  * Creates a new space writing the genesis credentials to the control feed.
3940
3849
  */
3941
3850
  async createSpace() {
3942
- invariant12(this._isOpen, "Not open.", {
3943
- F: __dxlog_file13,
3851
+ invariant11(this._isOpen, "Not open.", {
3852
+ F: __dxlog_file12,
3944
3853
  L: 138,
3945
3854
  S: this,
3946
3855
  A: [
@@ -3961,7 +3870,7 @@ var DataSpaceManager = class {
3961
3870
  log10("creating space...", {
3962
3871
  spaceKey
3963
3872
  }, {
3964
- F: __dxlog_file13,
3873
+ F: __dxlog_file12,
3965
3874
  L: 150,
3966
3875
  S: this,
3967
3876
  C: (f, a) => f(...a)
@@ -3976,8 +3885,8 @@ var DataSpaceManager = class {
3976
3885
  const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRoot.url);
3977
3886
  await this._metadataStore.addSpace(metadata);
3978
3887
  const memberCredential = credentials[1];
3979
- invariant12(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3980
- F: __dxlog_file13,
3888
+ invariant11(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3889
+ F: __dxlog_file12,
3981
3890
  L: 163,
3982
3891
  S: this,
3983
3892
  A: [
@@ -3995,13 +3904,13 @@ var DataSpaceManager = class {
3995
3904
  log10("accept space", {
3996
3905
  opts
3997
3906
  }, {
3998
- F: __dxlog_file13,
3907
+ F: __dxlog_file12,
3999
3908
  L: 175,
4000
3909
  S: this,
4001
3910
  C: (f, a) => f(...a)
4002
3911
  });
4003
- invariant12(this._isOpen, "Not open.", {
4004
- F: __dxlog_file13,
3912
+ invariant11(this._isOpen, "Not open.", {
3913
+ F: __dxlog_file12,
4005
3914
  L: 176,
4006
3915
  S: this,
4007
3916
  A: [
@@ -4009,8 +3918,8 @@ var DataSpaceManager = class {
4009
3918
  "'Not open.'"
4010
3919
  ]
4011
3920
  });
4012
- invariant12(!this._spaces.has(opts.spaceKey), "Space already exists.", {
4013
- F: __dxlog_file13,
3921
+ invariant11(!this._spaces.has(opts.spaceKey), "Space already exists.", {
3922
+ F: __dxlog_file12,
4014
3923
  L: 177,
4015
3924
  S: this,
4016
3925
  A: [
@@ -4045,7 +3954,7 @@ var DataSpaceManager = class {
4045
3954
  log10("construct space", {
4046
3955
  metadata
4047
3956
  }, {
4048
- F: __dxlog_file13,
3957
+ F: __dxlog_file12,
4049
3958
  L: 210,
4050
3959
  S: this,
4051
3960
  C: (f, a) => f(...a)
@@ -4083,7 +3992,7 @@ var DataSpaceManager = class {
4083
3992
  },
4084
3993
  onAuthFailure: () => {
4085
3994
  log10.warn("auth failure", void 0, {
4086
- F: __dxlog_file13,
3995
+ F: __dxlog_file12,
4087
3996
  L: 247,
4088
3997
  S: this,
4089
3998
  C: (f, a) => f(...a)
@@ -4107,7 +4016,7 @@ var DataSpaceManager = class {
4107
4016
  log10("before space ready", {
4108
4017
  space: space.key
4109
4018
  }, {
4110
- F: __dxlog_file13,
4019
+ F: __dxlog_file12,
4111
4020
  L: 265,
4112
4021
  S: this,
4113
4022
  C: (f, a) => f(...a)
@@ -4118,7 +4027,7 @@ var DataSpaceManager = class {
4118
4027
  space: space.key,
4119
4028
  open: this._isOpen
4120
4029
  }, {
4121
- F: __dxlog_file13,
4030
+ F: __dxlog_file12,
4122
4031
  L: 268,
4123
4032
  S: this,
4124
4033
  C: (f, a) => f(...a)
@@ -4131,7 +4040,7 @@ var DataSpaceManager = class {
4131
4040
  log10("before space close", {
4132
4041
  space: space.key
4133
4042
  }, {
4134
- F: __dxlog_file13,
4043
+ F: __dxlog_file12,
4135
4044
  L: 274,
4136
4045
  S: this,
4137
4046
  C: (f, a) => f(...a)
@@ -4171,11 +4080,11 @@ DataSpaceManager = _ts_decorate5([
4171
4080
  import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTask as scheduleTask6 } from "@dxos/async";
4172
4081
  import { Stream as Stream10 } from "@dxos/codec-protobuf";
4173
4082
  import { raise as raise2 } from "@dxos/debug";
4174
- import { invariant as invariant13 } from "@dxos/invariant";
4083
+ import { invariant as invariant12 } from "@dxos/invariant";
4175
4084
  import { log as log11 } from "@dxos/log";
4176
4085
  import { ApiError, SpaceNotFoundError, encodeError } from "@dxos/protocols";
4177
- import { SpaceMember as SpaceMember3, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
4178
- var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
4086
+ import { SpaceMember as SpaceMember2, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
4087
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
4179
4088
  var SpacesServiceImpl = class {
4180
4089
  constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
4181
4090
  this._identityManager = _identityManager;
@@ -4214,7 +4123,7 @@ var SpacesServiceImpl = class {
4214
4123
  log11("update", {
4215
4124
  spaces
4216
4125
  }, {
4217
- F: __dxlog_file14,
4126
+ F: __dxlog_file13,
4218
4127
  L: 77,
4219
4128
  S: this,
4220
4129
  C: (f, a) => f(...a)
@@ -4296,8 +4205,8 @@ var SpacesServiceImpl = class {
4296
4205
  }
4297
4206
  });
4298
4207
  } else {
4299
- invariant13(!credential.id, "Id on unsigned credentials is not allowed", {
4300
- F: __dxlog_file14,
4208
+ invariant12(!credential.id, "Id on unsigned credentials is not allowed", {
4209
+ F: __dxlog_file13,
4301
4210
  L: 164,
4302
4211
  S: this,
4303
4212
  A: [
@@ -4305,8 +4214,8 @@ var SpacesServiceImpl = class {
4305
4214
  "'Id on unsigned credentials is not allowed'"
4306
4215
  ]
4307
4216
  });
4308
- invariant13(this._identityManager.identity, "Identity is not available", {
4309
- F: __dxlog_file14,
4217
+ invariant12(this._identityManager.identity, "Identity is not available", {
4218
+ F: __dxlog_file13,
4310
4219
  L: 165,
4311
4220
  S: this,
4312
4221
  A: [
@@ -4315,8 +4224,8 @@ var SpacesServiceImpl = class {
4315
4224
  ]
4316
4225
  });
4317
4226
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
4318
- invariant13(credential.issuer.equals(signer.getIssuer()), void 0, {
4319
- F: __dxlog_file14,
4227
+ invariant12(credential.issuer.equals(signer.getIssuer()), void 0, {
4228
+ F: __dxlog_file13,
4320
4229
  L: 167,
4321
4230
  S: this,
4322
4231
  A: [
@@ -4372,7 +4281,7 @@ var SpacesServiceImpl = class {
4372
4281
  identityKey: member.key,
4373
4282
  profile: member.profile ?? {}
4374
4283
  },
4375
- presence: member.removed ? SpaceMember3.PresenceState.REMOVED : isMe || peers.length > 0 ? SpaceMember3.PresenceState.ONLINE : SpaceMember3.PresenceState.OFFLINE,
4284
+ presence: member.removed ? SpaceMember2.PresenceState.REMOVED : isMe || peers.length > 0 ? SpaceMember2.PresenceState.ONLINE : SpaceMember2.PresenceState.OFFLINE,
4376
4285
  peerStates: peers
4377
4286
  };
4378
4287
  }),
@@ -4391,12 +4300,12 @@ import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credent
4391
4300
  import { failUndefined as failUndefined2 } from "@dxos/debug";
4392
4301
  import { AutomergeHost, MetadataStore, SnapshotStore, SpaceManager, valueEncoding } from "@dxos/echo-pipeline";
4393
4302
  import { FeedFactory, FeedStore } from "@dxos/feed-store";
4394
- import { IndexMetadataStore, IndexStore, Indexer } from "@dxos/indexing";
4395
- import { invariant as invariant14 } from "@dxos/invariant";
4303
+ import { IndexMetadataStore, IndexStore, Indexer, createStorageCallbacks } from "@dxos/indexing";
4304
+ import { invariant as invariant13 } from "@dxos/invariant";
4396
4305
  import { Keyring } from "@dxos/keyring";
4397
4306
  import { PublicKey as PublicKey10 } from "@dxos/keys";
4398
4307
  import { log as log12 } from "@dxos/log";
4399
- import { InvalidStorageVersionError, STORAGE_VERSION as STORAGE_VERSION2, trace as trace8 } from "@dxos/protocols";
4308
+ import { InvalidStorageVersionError, STORAGE_VERSION, trace as trace8 } from "@dxos/protocols";
4400
4309
  import { Invitation as Invitation6 } from "@dxos/protocols/proto/dxos/client/services";
4401
4310
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
4402
4311
  import { trace as Trace2 } from "@dxos/tracing";
@@ -4492,7 +4401,7 @@ function _ts_decorate6(decorators, target, key, desc) {
4492
4401
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4493
4402
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4494
4403
  }
4495
- var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
4404
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
4496
4405
  var ServiceContext = class extends Resource {
4497
4406
  constructor(storage, level, networkManager, signalManager, _runtimeParams) {
4498
4407
  super();
@@ -4531,11 +4440,15 @@ var ServiceContext = class extends Resource {
4531
4440
  });
4532
4441
  this.automergeHost = new AutomergeHost({
4533
4442
  directory: storage.createDirectory("automerge"),
4534
- metadata: this.indexMetadata
4443
+ db: level.sublevel("automerge"),
4444
+ storageCallbacks: createStorageCallbacks({
4445
+ host: () => this.automergeHost,
4446
+ metadata: this.indexMetadata
4447
+ })
4535
4448
  });
4536
4449
  this.indexer = new Indexer({
4537
4450
  indexStore: new IndexStore({
4538
- directory: storage.createDirectory("index-store")
4451
+ db: level.sublevel("index-storage")
4539
4452
  }),
4540
4453
  metadataStore: this.indexMetadata,
4541
4454
  loadDocuments: createSelectedDocumentsIterator(this.automergeHost),
@@ -4547,21 +4460,22 @@ var ServiceContext = class extends Resource {
4547
4460
  async _open(ctx) {
4548
4461
  await this._checkStorageVersion();
4549
4462
  log12("opening...", void 0, {
4550
- F: __dxlog_file15,
4551
- L: 156,
4463
+ F: __dxlog_file14,
4464
+ L: 157,
4552
4465
  S: this,
4553
4466
  C: (f, a) => f(...a)
4554
4467
  });
4555
4468
  log12.trace("dxos.sdk.service-context.open", trace8.begin({
4556
4469
  id: this._instanceId
4557
4470
  }), {
4558
- F: __dxlog_file15,
4559
- L: 157,
4471
+ F: __dxlog_file14,
4472
+ L: 158,
4560
4473
  S: this,
4561
4474
  C: (f, a) => f(...a)
4562
4475
  });
4563
4476
  await this.signalManager.open();
4564
4477
  await this.networkManager.open();
4478
+ await this.automergeHost.open();
4565
4479
  await this.metadataStore.load();
4566
4480
  await this.spaceManager.open();
4567
4481
  await this.identityManager.open(ctx);
@@ -4571,22 +4485,22 @@ var ServiceContext = class extends Resource {
4571
4485
  log12.trace("dxos.sdk.service-context.open", trace8.end({
4572
4486
  id: this._instanceId
4573
4487
  }), {
4574
- F: __dxlog_file15,
4575
- L: 167,
4488
+ F: __dxlog_file14,
4489
+ L: 169,
4576
4490
  S: this,
4577
4491
  C: (f, a) => f(...a)
4578
4492
  });
4579
4493
  log12("opened", void 0, {
4580
- F: __dxlog_file15,
4581
- L: 168,
4494
+ F: __dxlog_file14,
4495
+ L: 170,
4582
4496
  S: this,
4583
4497
  C: (f, a) => f(...a)
4584
4498
  });
4585
4499
  }
4586
4500
  async _close() {
4587
4501
  log12("closing...", void 0, {
4588
- F: __dxlog_file15,
4589
- L: 172,
4502
+ F: __dxlog_file14,
4503
+ L: 174,
4590
4504
  S: this,
4591
4505
  C: (f, a) => f(...a)
4592
4506
  });
@@ -4603,8 +4517,8 @@ var ServiceContext = class extends Resource {
4603
4517
  await this.metadataStore.close();
4604
4518
  await this.indexer.destroy();
4605
4519
  log12("closed", void 0, {
4606
- F: __dxlog_file15,
4607
- L: 185,
4520
+ F: __dxlog_file14,
4521
+ L: 187,
4608
4522
  S: this,
4609
4523
  C: (f, a) => f(...a)
4610
4524
  });
@@ -4616,9 +4530,9 @@ var ServiceContext = class extends Resource {
4616
4530
  }
4617
4531
  getInvitationHandler(invitation) {
4618
4532
  const factory = this._handlerFactories.get(invitation.kind);
4619
- invariant14(factory, `Unknown invitation kind: ${invitation.kind}`, {
4620
- F: __dxlog_file15,
4621
- L: 196,
4533
+ invariant13(factory, `Unknown invitation kind: ${invitation.kind}`, {
4534
+ F: __dxlog_file14,
4535
+ L: 198,
4622
4536
  S: this,
4623
4537
  A: [
4624
4538
  "factory",
@@ -4642,15 +4556,15 @@ var ServiceContext = class extends Resource {
4642
4556
  }
4643
4557
  async _checkStorageVersion() {
4644
4558
  await this.metadataStore.load();
4645
- if (this.metadataStore.version !== STORAGE_VERSION2) {
4646
- throw new InvalidStorageVersionError(STORAGE_VERSION2, this.metadataStore.version);
4559
+ if (this.metadataStore.version !== STORAGE_VERSION) {
4560
+ throw new InvalidStorageVersionError(STORAGE_VERSION, this.metadataStore.version);
4647
4561
  }
4648
4562
  }
4649
4563
  // Called when identity is created.
4650
4564
  async _initialize(ctx) {
4651
4565
  log12("initializing spaces...", void 0, {
4652
- F: __dxlog_file15,
4653
- L: 227,
4566
+ F: __dxlog_file14,
4567
+ L: 229,
4654
4568
  S: this,
4655
4569
  C: (f, a) => f(...a)
4656
4570
  });
@@ -4671,9 +4585,9 @@ var ServiceContext = class extends Resource {
4671
4585
  this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.automergeHost, this._runtimeParams);
4672
4586
  await this.dataSpaceManager.open();
4673
4587
  this._handlerFactories.set(Invitation6.Kind.SPACE, (invitation) => {
4674
- invariant14(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4675
- F: __dxlog_file15,
4676
- L: 251,
4588
+ invariant13(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4589
+ F: __dxlog_file14,
4590
+ L: 253,
4677
4591
  S: this,
4678
4592
  A: [
4679
4593
  "this.dataSpaceManager",
@@ -4696,8 +4610,8 @@ var ServiceContext = class extends Resource {
4696
4610
  log12("dataSpaceManager not initialized yet, ignoring space admission", {
4697
4611
  details: assertion
4698
4612
  }, {
4699
- F: __dxlog_file15,
4700
- L: 267,
4613
+ F: __dxlog_file14,
4614
+ L: 269,
4701
4615
  S: this,
4702
4616
  C: (f, a) => f(...a)
4703
4617
  });
@@ -4707,8 +4621,8 @@ var ServiceContext = class extends Resource {
4707
4621
  log12("space already exists, ignoring space admission", {
4708
4622
  details: assertion
4709
4623
  }, {
4710
- F: __dxlog_file15,
4711
- L: 271,
4624
+ F: __dxlog_file14,
4625
+ L: 273,
4712
4626
  S: this,
4713
4627
  C: (f, a) => f(...a)
4714
4628
  });
@@ -4718,8 +4632,8 @@ var ServiceContext = class extends Resource {
4718
4632
  log12("accepting space recorded in halo", {
4719
4633
  details: assertion
4720
4634
  }, {
4721
- F: __dxlog_file15,
4722
- L: 276,
4635
+ F: __dxlog_file14,
4636
+ L: 278,
4723
4637
  S: this,
4724
4638
  C: (f, a) => f(...a)
4725
4639
  });
@@ -4729,8 +4643,8 @@ var ServiceContext = class extends Resource {
4729
4643
  });
4730
4644
  } catch (err) {
4731
4645
  log12.catch(err, void 0, {
4732
- F: __dxlog_file15,
4733
- L: 282,
4646
+ F: __dxlog_file14,
4647
+ L: 284,
4734
4648
  S: this,
4735
4649
  C: (f, a) => f(...a)
4736
4650
  });
@@ -4775,214 +4689,265 @@ var ServiceRegistry = class {
4775
4689
  }
4776
4690
  };
4777
4691
 
4778
- // packages/sdk/client-services/src/packlets/locks/browser.ts
4779
- import { asyncTimeout as asyncTimeout2, Trigger as Trigger6 } from "@dxos/async";
4780
- import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
4781
- import { log as log13, logInfo } from "@dxos/log";
4782
- function _ts_decorate7(decorators, target, key, desc) {
4783
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4784
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
4785
- r = Reflect.decorate(decorators, target, key, desc);
4786
- else
4787
- for (var i = decorators.length - 1; i >= 0; i--)
4788
- if (d = decorators[i])
4789
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4790
- return c > 3 && r && Object.defineProperty(target, key, r), r;
4791
- }
4792
- var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
4793
- var Message;
4794
- (function(Message2) {
4795
- Message2["ACQUIRING"] = "acquiring";
4796
- })(Message || (Message = {}));
4797
- var Lock = class {
4798
- constructor({ lockKey, onAcquire, onRelease }) {
4799
- this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
4800
- this._releaseTrigger = new Trigger6();
4801
- this._lockKey = lockKey;
4802
- this._onAcquire = onAcquire;
4803
- this._onRelease = onRelease;
4804
- this._broadcastChannel.onmessage = this._onMessage.bind(this);
4805
- }
4806
- get lockKey() {
4807
- return this._lockKey;
4808
- }
4809
- async acquire() {
4810
- this._broadcastChannel.postMessage({
4811
- message: "acquiring"
4812
- });
4813
- try {
4814
- log13("aquiring lock...", void 0, {
4815
- F: __dxlog_file16,
4816
- L: 42,
4817
- S: this,
4818
- C: (f, a) => f(...a)
4819
- });
4820
- await asyncTimeout2(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
4821
- log13("acquired lock", void 0, {
4822
- F: __dxlog_file16,
4823
- L: 44,
4824
- S: this,
4825
- C: (f, a) => f(...a)
4826
- });
4827
- } catch {
4828
- log13("stealing lock...", void 0, {
4829
- F: __dxlog_file16,
4830
- L: 46,
4831
- S: this,
4832
- C: (f, a) => f(...a)
4833
- });
4834
- await this._requestLock(true);
4835
- log13("stolen lock", void 0, {
4836
- F: __dxlog_file16,
4837
- L: 48,
4838
- S: this,
4839
- C: (f, a) => f(...a)
4840
- });
4692
+ // packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts
4693
+ import { getFirstStreamValue } from "@dxos/codec-protobuf";
4694
+ import { credentialTypeFilter } from "@dxos/credentials";
4695
+ import { invariant as invariant14 } from "@dxos/invariant";
4696
+ import { STORAGE_VERSION as STORAGE_VERSION2 } from "@dxos/protocols";
4697
+ import { SpaceMember as SpaceMember3 } from "@dxos/protocols/proto/dxos/client/services";
4698
+ import { TRACE_PROCESSOR } from "@dxos/tracing";
4699
+
4700
+ // packages/sdk/client-services/src/version.ts
4701
+ var DXOS_VERSION = "0.4.10-main.fe71b4c";
4702
+
4703
+ // packages/sdk/client-services/src/packlets/services/platform.ts
4704
+ import { Platform } from "@dxos/protocols/proto/dxos/client/services";
4705
+ var getPlatform = () => {
4706
+ if (process.browser) {
4707
+ if (typeof window !== "undefined") {
4708
+ const { userAgent } = window.navigator;
4709
+ return {
4710
+ type: Platform.PLATFORM_TYPE.BROWSER,
4711
+ userAgent,
4712
+ uptime: Math.floor((Date.now() - window.performance.timeOrigin) / 1e3)
4713
+ };
4714
+ } else {
4715
+ return {
4716
+ type: Platform.PLATFORM_TYPE.SHARED_WORKER,
4717
+ uptime: Math.floor((Date.now() - performance.timeOrigin) / 1e3)
4718
+ };
4841
4719
  }
4720
+ } else {
4721
+ const { platform: platform2, version, arch } = process;
4722
+ return {
4723
+ type: Platform.PLATFORM_TYPE.NODE,
4724
+ platform: platform2,
4725
+ arch,
4726
+ runtime: version,
4727
+ uptime: Math.floor(process.uptime()),
4728
+ memory: process.memoryUsage()
4729
+ };
4842
4730
  }
4843
- async release() {
4844
- this._releaseTrigger.wake();
4731
+ };
4732
+
4733
+ // packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts
4734
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts";
4735
+ var DEFAULT_TIMEOUT = 1e3;
4736
+ var createDiagnostics = async (clientServices, serviceContext, config) => {
4737
+ const diagnostics = {
4738
+ created: (/* @__PURE__ */ new Date()).toISOString(),
4739
+ platform: getPlatform(),
4740
+ client: {
4741
+ version: DXOS_VERSION,
4742
+ storage: {
4743
+ version: STORAGE_VERSION2
4744
+ }
4745
+ },
4746
+ trace: TRACE_PROCESSOR.getDiagnostics()
4747
+ };
4748
+ {
4749
+ invariant14(clientServices.LoggingService, "SystemService is not available.", {
4750
+ F: __dxlog_file15,
4751
+ L: 108,
4752
+ S: void 0,
4753
+ A: [
4754
+ "clientServices.LoggingService",
4755
+ "'SystemService is not available.'"
4756
+ ]
4757
+ });
4758
+ diagnostics.metrics = await getFirstStreamValue(clientServices.LoggingService.queryMetrics({}), {
4759
+ timeout: DEFAULT_TIMEOUT
4760
+ }).catch(() => void 0);
4845
4761
  }
4846
- _onMessage(event) {
4847
- if (event.data.message === "acquiring") {
4848
- this._releaseTrigger.wake();
4762
+ if (typeof navigator !== "undefined" && navigator.storage) {
4763
+ const map = /* @__PURE__ */ new Map();
4764
+ const dir = await navigator.storage.getDirectory();
4765
+ for await (const filename of dir?.keys()) {
4766
+ const idx = filename.indexOf("-", filename.indexOf("-") + 1);
4767
+ if (idx === -1) {
4768
+ continue;
4769
+ }
4770
+ map.set(filename.slice(0, idx), (map.get(filename.slice(0, idx)) ?? 0) + 1);
4849
4771
  }
4772
+ diagnostics.storage = Array.from(map.entries()).sort((a, b) => b[1] - a[1]).map(([file, count]) => ({
4773
+ file,
4774
+ count
4775
+ }));
4850
4776
  }
4851
- async _requestLock(steal = false) {
4852
- log13("requesting lock...", {
4853
- steal
4854
- }, {
4855
- F: __dxlog_file16,
4856
- L: 63,
4857
- S: this,
4858
- C: (f, a) => f(...a)
4859
- });
4860
- const acquired = new Trigger6();
4861
- void navigator.locks.request(this._lockKey, {
4862
- steal
4863
- }, async () => {
4864
- await this._onAcquire?.();
4865
- acquired.wake();
4866
- this._releaseTrigger = new Trigger6();
4867
- await this._releaseTrigger.wait();
4868
- log13("releasing lock...", void 0, {
4869
- F: __dxlog_file16,
4870
- L: 72,
4871
- S: this,
4872
- C: (f, a) => f(...a)
4873
- });
4874
- await this._onRelease?.();
4875
- log13("released lock", void 0, {
4876
- F: __dxlog_file16,
4877
- L: 74,
4878
- S: this,
4879
- C: (f, a) => f(...a)
4880
- });
4881
- }).catch(async () => {
4882
- await this._onRelease?.();
4883
- });
4884
- await acquired.wait();
4885
- log13("recieved lock", {
4886
- steal
4887
- }, {
4888
- F: __dxlog_file16,
4889
- L: 81,
4890
- S: this,
4891
- C: (f, a) => f(...a)
4892
- });
4777
+ const identity = serviceContext.identityManager.identity;
4778
+ if (identity) {
4779
+ diagnostics.identity = {
4780
+ identityKey: identity.identityKey,
4781
+ spaceKey: identity.space.key,
4782
+ profile: identity.profileDocument
4783
+ };
4784
+ const { devices } = await getFirstStreamValue(clientServices.DevicesService.queryDevices(), {
4785
+ timeout: DEFAULT_TIMEOUT
4786
+ }).catch(() => void 0) ?? {};
4787
+ diagnostics.devices = devices;
4788
+ if (serviceContext.dataSpaceManager) {
4789
+ diagnostics.spaces = await Promise.all(Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space)) ?? []);
4790
+ }
4791
+ const { feeds = [] } = await getFirstStreamValue(clientServices.DevtoolsHost.subscribeToFeeds({}), {
4792
+ timeout: DEFAULT_TIMEOUT
4793
+ }).catch(() => void 0) ?? {};
4794
+ diagnostics.feeds = feeds.map(({ feedKey, bytes, length }) => ({
4795
+ feedKey,
4796
+ bytes,
4797
+ length
4798
+ }));
4799
+ const status = await getFirstStreamValue(clientServices.NetworkService.queryStatus(), {
4800
+ timeout: DEFAULT_TIMEOUT
4801
+ }).catch(() => void 0);
4802
+ diagnostics.networkStatus = status;
4803
+ diagnostics.swarms = serviceContext.networkManager.connectionLog?.swarms;
4893
4804
  }
4805
+ diagnostics.config = config.values;
4806
+ return diagnostics;
4894
4807
  };
4895
- _ts_decorate7([
4896
- logInfo
4897
- ], Lock.prototype, "lockKey", null);
4898
- var isLocked = (lockPath) => {
4899
- throw new Error("Not implemented");
4900
- };
4901
-
4902
- // packages/sdk/client-services/src/packlets/storage/storage.ts
4903
- import { InvalidConfigError } from "@dxos/protocols";
4904
- import { Runtime as Runtime2 } from "@dxos/protocols/proto/dxos/config";
4905
- import { createStorage, StorageType } from "@dxos/random-access-storage";
4906
-
4907
- // packages/sdk/client-services/src/packlets/storage/util.ts
4908
- import { DX_DATA } from "@dxos/client-protocol";
4909
- import { Runtime } from "@dxos/protocols/proto/dxos/config";
4910
- import { isNode as isNode2 } from "@dxos/util";
4911
- var getRootPath = (config) => {
4912
- const { dataRoot = isNode2() ? DX_DATA : "dxos/storage" } = config ?? {};
4913
- return `${dataRoot}/`;
4914
- };
4915
- var isPersistent = (config) => {
4916
- const { persistent = false } = config ?? {};
4917
- return config.dataStore !== void 0 && config.dataStore !== Runtime.Client.Storage.StorageDriver.RAM || persistent;
4808
+ var getSpaceStats = async (space) => {
4809
+ const stats = {
4810
+ key: space.key,
4811
+ metrics: space.metrics,
4812
+ epochs: space.inner.spaceState.credentials.filter(credentialTypeFilter("dxos.halo.credentials.Epoch")).map((credential) => ({
4813
+ ...credential.subject.assertion,
4814
+ id: credential.id
4815
+ })),
4816
+ members: Array.from(space.inner.spaceState.members.values()).map((member) => ({
4817
+ identity: {
4818
+ identityKey: member.key,
4819
+ profile: {
4820
+ displayName: member.assertion.profile?.displayName
4821
+ }
4822
+ },
4823
+ presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember3.PresenceState.ONLINE : SpaceMember3.PresenceState.OFFLINE
4824
+ })),
4825
+ pipeline: {
4826
+ // TODO(burdon): Pick properties from credentials if needed.
4827
+ currentEpoch: space.automergeSpaceState.lastEpoch,
4828
+ appliedEpoch: space.automergeSpaceState.lastEpoch,
4829
+ controlFeeds: space.inner.controlPipeline.state.feeds.map((feed) => feed.key),
4830
+ currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
4831
+ targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
4832
+ totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe
4833
+ }
4834
+ };
4835
+ if (stats.metrics) {
4836
+ const { open, ready } = stats.metrics;
4837
+ stats.metrics.startupTime = open && ready && ready.getTime() - open.getTime();
4838
+ }
4839
+ return stats;
4918
4840
  };
4919
4841
 
4920
- // packages/sdk/client-services/src/packlets/storage/storage.ts
4921
- var StorageDriver = Runtime2.Client.Storage.StorageDriver;
4922
- var createStorageObjects = (config) => {
4923
- const { persistent = false, keyStore, dataStore } = config ?? {};
4924
- if (persistent && dataStore === StorageDriver.RAM) {
4925
- throw new InvalidConfigError("RAM storage cannot be used in persistent mode.");
4926
- }
4927
- if (!persistent && dataStore !== void 0 && dataStore !== StorageDriver.RAM) {
4928
- throw new InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
4929
- }
4930
- if (persistent && keyStore === StorageDriver.RAM) {
4931
- throw new InvalidConfigError("RAM key storage cannot be used in persistent mode.");
4932
- }
4933
- if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== void 0) {
4934
- throw new InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
4935
- }
4842
+ // packages/sdk/client-services/src/packlets/diagnostics/browser-diagnostics-broadcast.ts
4843
+ import { Trigger as Trigger6 } from "@dxos/async";
4844
+ import { log as log13 } from "@dxos/log";
4845
+ var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/browser-diagnostics-broadcast.ts";
4846
+ var CHANNEL_NAME = "dxos.diagnostics.broadcast";
4847
+ var MessageType;
4848
+ (function(MessageType2) {
4849
+ MessageType2["PROBE"] = "probe";
4850
+ MessageType2["PROBE_ACK"] = "probe-ack";
4851
+ MessageType2["REQUEST_DIAGNOSTICS"] = "request-diagnostics";
4852
+ MessageType2["RECEIVE_DIAGNOSTICS"] = "receive-diagnostics";
4853
+ })(MessageType || (MessageType = {}));
4854
+ var createCollectDiagnosticsBroadcastSender = () => {
4936
4855
  return {
4937
- storage: createStorage({
4938
- type: persistent ? toStorageType(dataStore) : StorageType.RAM,
4939
- root: getRootPath(config)
4940
- })
4941
- };
4942
- };
4943
- var toStorageType = (type) => {
4944
- switch (type) {
4945
- case void 0:
4946
- return void 0;
4947
- case StorageDriver.RAM:
4948
- return StorageType.RAM;
4949
- case StorageDriver.CHROME:
4950
- return StorageType.CHROME;
4951
- case StorageDriver.FIREFOX:
4952
- return StorageType.FIREFOX;
4953
- case StorageDriver.IDB:
4954
- return StorageType.IDB;
4955
- case StorageDriver.NODE:
4956
- return StorageType.NODE;
4957
- case StorageDriver.WEBFS:
4958
- return StorageType.WEBFS;
4959
- default:
4960
- throw new Error(`Invalid storage type: ${StorageDriver[type]}`);
4856
+ broadcastDiagnosticsRequest: async () => {
4857
+ let expectedResponse = "probe-ack";
4858
+ let channel;
4859
+ try {
4860
+ const trigger = new Trigger6();
4861
+ channel = new BroadcastChannel(CHANNEL_NAME);
4862
+ channel.onmessage = (msg) => {
4863
+ if (expectedResponse === msg.data.type) {
4864
+ trigger.wake(msg.data);
4865
+ }
4866
+ };
4867
+ channel.postMessage({
4868
+ type: "probe"
4869
+ });
4870
+ await trigger.wait({
4871
+ timeout: 200
4872
+ });
4873
+ expectedResponse = "receive-diagnostics";
4874
+ trigger.reset();
4875
+ channel.postMessage({
4876
+ type: "request-diagnostics"
4877
+ });
4878
+ const diagnostics = await trigger.wait({
4879
+ timeout: 5e3
4880
+ });
4881
+ return diagnostics.payload;
4882
+ } catch (e) {
4883
+ const errorDescription = e instanceof Error ? e.message : JSON.stringify(e);
4884
+ return {
4885
+ expectedResponse,
4886
+ errorDescription
4887
+ };
4888
+ } finally {
4889
+ safeClose(channel);
4890
+ }
4891
+ }
4892
+ };
4893
+ };
4894
+ var createCollectDiagnosticsBroadcastHandler = (systemService) => {
4895
+ let channel;
4896
+ return {
4897
+ start: () => {
4898
+ channel = new BroadcastChannel(CHANNEL_NAME);
4899
+ channel.onmessage = async (message) => {
4900
+ try {
4901
+ if (message.data.type === "probe") {
4902
+ channel?.postMessage({
4903
+ type: "probe-ack"
4904
+ });
4905
+ } else if (message.data.type === "request-diagnostics") {
4906
+ const diagnostics = await systemService.getDiagnostics({});
4907
+ channel?.postMessage({
4908
+ type: "receive-diagnostics",
4909
+ payload: diagnostics
4910
+ });
4911
+ }
4912
+ } catch (error) {
4913
+ log13.catch(error, void 0, {
4914
+ F: __dxlog_file16,
4915
+ L: 77,
4916
+ S: void 0,
4917
+ C: (f, a) => f(...a)
4918
+ });
4919
+ }
4920
+ };
4921
+ },
4922
+ stop: () => {
4923
+ safeClose(channel);
4924
+ channel = void 0;
4925
+ }
4926
+ };
4927
+ };
4928
+ var safeClose = (channel) => {
4929
+ try {
4930
+ channel?.close();
4931
+ } catch (e) {
4961
4932
  }
4962
4933
  };
4963
4934
 
4964
- // packages/sdk/client-services/src/packlets/storage/level.ts
4965
- import { Level } from "level";
4966
- import path from "@dxos/node-std/path";
4967
- import { PublicKey as PublicKey11 } from "@dxos/keys";
4968
- var createLevel = async (config) => {
4969
- const persistent = isPersistent(config);
4970
- const storagePath = persistent ? getRootPath(config) : path.join("tmp", "level", PublicKey11.random().toHex());
4971
- const level = new Level(storagePath);
4972
- await level.open();
4973
- return level;
4974
- };
4935
+ // packages/sdk/client-services/src/packlets/diagnostics/diagnostics-collector.ts
4936
+ import { ConfigResource } from "@dxos/config";
4937
+ import { GetDiagnosticsRequest as GetDiagnosticsRequest2 } from "@dxos/protocols/proto/dxos/client/services";
4938
+ import { TRACE_PROCESSOR as TRACE_PROCESSOR3 } from "@dxos/tracing";
4939
+ import { jsonKeyReplacer as jsonKeyReplacer2, nonNullable } from "@dxos/util";
4975
4940
 
4976
4941
  // packages/sdk/client-services/src/packlets/services/service-host.ts
4977
4942
  import { Event as Event9, synchronized as synchronized3 } from "@dxos/async";
4978
4943
  import { clientServiceBundle, defaultKey, Properties } from "@dxos/client-protocol";
4979
4944
  import { Context as Context11 } from "@dxos/context";
4980
4945
  import { DataServiceImpl, encodeReference } from "@dxos/echo-pipeline";
4981
- import * as E from "@dxos/echo-schema";
4946
+ import { getTypeReference } from "@dxos/echo-schema";
4982
4947
  import { IndexServiceImpl } from "@dxos/indexing";
4983
4948
  import { invariant as invariant16 } from "@dxos/invariant";
4984
4949
  import { PublicKey as PublicKey13 } from "@dxos/keys";
4985
- import { log as log15 } from "@dxos/log";
4950
+ import { log as log16 } from "@dxos/log";
4986
4951
  import { WebsocketSignalManager } from "@dxos/messaging";
4987
4952
  import { NetworkManager, createSimplePeerTransportFactory } from "@dxos/network-manager";
4988
4953
  import { trace as trace9 } from "@dxos/protocols";
@@ -5073,28 +5038,152 @@ var DevicesServiceImpl = class {
5073
5038
  }
5074
5039
  };
5075
5040
 
5041
+ // packages/sdk/client-services/src/packlets/locks/browser.ts
5042
+ import { asyncTimeout as asyncTimeout2, Trigger as Trigger7 } from "@dxos/async";
5043
+ import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
5044
+ import { log as log14, logInfo } from "@dxos/log";
5045
+ function _ts_decorate7(decorators, target, key, desc) {
5046
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5047
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
5048
+ r = Reflect.decorate(decorators, target, key, desc);
5049
+ else
5050
+ for (var i = decorators.length - 1; i >= 0; i--)
5051
+ if (d = decorators[i])
5052
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5053
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
5054
+ }
5055
+ var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
5056
+ var Message;
5057
+ (function(Message2) {
5058
+ Message2["ACQUIRING"] = "acquiring";
5059
+ })(Message || (Message = {}));
5060
+ var Lock = class {
5061
+ constructor({ lockKey, onAcquire, onRelease }) {
5062
+ this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
5063
+ this._releaseTrigger = new Trigger7();
5064
+ this._lockKey = lockKey;
5065
+ this._onAcquire = onAcquire;
5066
+ this._onRelease = onRelease;
5067
+ this._broadcastChannel.onmessage = this._onMessage.bind(this);
5068
+ }
5069
+ get lockKey() {
5070
+ return this._lockKey;
5071
+ }
5072
+ async acquire() {
5073
+ this._broadcastChannel.postMessage({
5074
+ message: "acquiring"
5075
+ });
5076
+ try {
5077
+ log14("aquiring lock...", void 0, {
5078
+ F: __dxlog_file18,
5079
+ L: 42,
5080
+ S: this,
5081
+ C: (f, a) => f(...a)
5082
+ });
5083
+ await asyncTimeout2(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
5084
+ log14("acquired lock", void 0, {
5085
+ F: __dxlog_file18,
5086
+ L: 44,
5087
+ S: this,
5088
+ C: (f, a) => f(...a)
5089
+ });
5090
+ } catch {
5091
+ log14("stealing lock...", void 0, {
5092
+ F: __dxlog_file18,
5093
+ L: 46,
5094
+ S: this,
5095
+ C: (f, a) => f(...a)
5096
+ });
5097
+ await this._requestLock(true);
5098
+ log14("stolen lock", void 0, {
5099
+ F: __dxlog_file18,
5100
+ L: 48,
5101
+ S: this,
5102
+ C: (f, a) => f(...a)
5103
+ });
5104
+ }
5105
+ }
5106
+ async release() {
5107
+ this._releaseTrigger.wake();
5108
+ }
5109
+ _onMessage(event) {
5110
+ if (event.data.message === "acquiring") {
5111
+ this._releaseTrigger.wake();
5112
+ }
5113
+ }
5114
+ async _requestLock(steal = false) {
5115
+ log14("requesting lock...", {
5116
+ steal
5117
+ }, {
5118
+ F: __dxlog_file18,
5119
+ L: 63,
5120
+ S: this,
5121
+ C: (f, a) => f(...a)
5122
+ });
5123
+ const acquired = new Trigger7();
5124
+ void navigator.locks.request(this._lockKey, {
5125
+ steal
5126
+ }, async () => {
5127
+ await this._onAcquire?.();
5128
+ acquired.wake();
5129
+ this._releaseTrigger = new Trigger7();
5130
+ await this._releaseTrigger.wait();
5131
+ log14("releasing lock...", void 0, {
5132
+ F: __dxlog_file18,
5133
+ L: 72,
5134
+ S: this,
5135
+ C: (f, a) => f(...a)
5136
+ });
5137
+ await this._onRelease?.();
5138
+ log14("released lock", void 0, {
5139
+ F: __dxlog_file18,
5140
+ L: 74,
5141
+ S: this,
5142
+ C: (f, a) => f(...a)
5143
+ });
5144
+ }).catch(async () => {
5145
+ await this._onRelease?.();
5146
+ });
5147
+ await acquired.wait();
5148
+ log14("recieved lock", {
5149
+ steal
5150
+ }, {
5151
+ F: __dxlog_file18,
5152
+ L: 81,
5153
+ S: this,
5154
+ C: (f, a) => f(...a)
5155
+ });
5156
+ }
5157
+ };
5158
+ _ts_decorate7([
5159
+ logInfo
5160
+ ], Lock.prototype, "lockKey", null);
5161
+ var isLocked = (lockPath) => {
5162
+ throw new Error("Not implemented");
5163
+ };
5164
+
5076
5165
  // packages/sdk/client-services/src/packlets/logging/logging-service.ts
5077
5166
  import { Event as Event8 } from "@dxos/async";
5078
5167
  import { Stream as Stream12 } from "@dxos/codec-protobuf";
5079
- import { PublicKey as PublicKey12 } from "@dxos/keys";
5080
- import { getContextFromEntry, log as log14 } from "@dxos/log";
5168
+ import { PublicKey as PublicKey11 } from "@dxos/keys";
5169
+ import { getContextFromEntry, log as log15 } from "@dxos/log";
5081
5170
  import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
5082
5171
  import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
5083
5172
  var LoggingServiceImpl = class {
5084
5173
  constructor() {
5085
5174
  this._logs = new Event8();
5086
5175
  this._started = Date.now();
5087
- this._sessionId = PublicKey12.random().toHex();
5176
+ this._sessionId = PublicKey11.random().toHex();
5088
5177
  this._logProcessor = (_config, entry2) => {
5089
5178
  this._logs.emit(entry2);
5090
5179
  };
5091
5180
  }
5092
5181
  async open() {
5093
- log14.runtimeConfig.processors.push(this._logProcessor);
5182
+ log15.runtimeConfig.processors.push(this._logProcessor);
5094
5183
  }
5095
5184
  async close() {
5096
- const index = log14.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
5097
- log14.runtimeConfig.processors.splice(index, 1);
5185
+ const index = log15.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
5186
+ log15.runtimeConfig.processors.splice(index, 1);
5098
5187
  }
5099
5188
  async controlMetrics({ reset, record }) {
5100
5189
  if (reset) {
@@ -5230,6 +5319,80 @@ var NetworkServiceImpl = class {
5230
5319
  }
5231
5320
  };
5232
5321
 
5322
+ // packages/sdk/client-services/src/packlets/storage/storage.ts
5323
+ import { InvalidConfigError } from "@dxos/protocols";
5324
+ import { Runtime as Runtime2 } from "@dxos/protocols/proto/dxos/config";
5325
+ import { createStorage, StorageType } from "@dxos/random-access-storage";
5326
+
5327
+ // packages/sdk/client-services/src/packlets/storage/util.ts
5328
+ import { DX_DATA } from "@dxos/client-protocol";
5329
+ import { Runtime } from "@dxos/protocols/proto/dxos/config";
5330
+ import { isNode as isNode2 } from "@dxos/util";
5331
+ var getRootPath = (config) => {
5332
+ const { dataRoot = isNode2() ? DX_DATA : "dxos/storage" } = config ?? {};
5333
+ return `${dataRoot}/`;
5334
+ };
5335
+ var isPersistent = (config) => {
5336
+ const { persistent = false } = config ?? {};
5337
+ return config.dataStore !== void 0 && config.dataStore !== Runtime.Client.Storage.StorageDriver.RAM || persistent;
5338
+ };
5339
+
5340
+ // packages/sdk/client-services/src/packlets/storage/storage.ts
5341
+ var StorageDriver = Runtime2.Client.Storage.StorageDriver;
5342
+ var createStorageObjects = (config) => {
5343
+ const { persistent = false, keyStore, dataStore } = config ?? {};
5344
+ if (persistent && dataStore === StorageDriver.RAM) {
5345
+ throw new InvalidConfigError("RAM storage cannot be used in persistent mode.");
5346
+ }
5347
+ if (!persistent && dataStore !== void 0 && dataStore !== StorageDriver.RAM) {
5348
+ throw new InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
5349
+ }
5350
+ if (persistent && keyStore === StorageDriver.RAM) {
5351
+ throw new InvalidConfigError("RAM key storage cannot be used in persistent mode.");
5352
+ }
5353
+ if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== void 0) {
5354
+ throw new InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
5355
+ }
5356
+ return {
5357
+ storage: createStorage({
5358
+ type: persistent ? toStorageType(dataStore) : StorageType.RAM,
5359
+ root: getRootPath(config)
5360
+ })
5361
+ };
5362
+ };
5363
+ var toStorageType = (type) => {
5364
+ switch (type) {
5365
+ case void 0:
5366
+ return void 0;
5367
+ case StorageDriver.RAM:
5368
+ return StorageType.RAM;
5369
+ case StorageDriver.CHROME:
5370
+ return StorageType.CHROME;
5371
+ case StorageDriver.FIREFOX:
5372
+ return StorageType.FIREFOX;
5373
+ case StorageDriver.IDB:
5374
+ return StorageType.IDB;
5375
+ case StorageDriver.NODE:
5376
+ return StorageType.NODE;
5377
+ case StorageDriver.WEBFS:
5378
+ return StorageType.WEBFS;
5379
+ default:
5380
+ throw new Error(`Invalid storage type: ${StorageDriver[type]}`);
5381
+ }
5382
+ };
5383
+
5384
+ // packages/sdk/client-services/src/packlets/storage/level.ts
5385
+ import { Level } from "level";
5386
+ import path from "@dxos/node-std/path";
5387
+ import { PublicKey as PublicKey12 } from "@dxos/keys";
5388
+ var createLevel = async (config) => {
5389
+ const persistent = isPersistent(config);
5390
+ const storagePath = persistent ? path.join(getRootPath(config), "level") : `/tmp/dxos-${PublicKey12.random().toHex()}`;
5391
+ const level = new Level(storagePath);
5392
+ await level.open();
5393
+ return level;
5394
+ };
5395
+
5233
5396
  // packages/sdk/client-services/src/packlets/system/system-service.ts
5234
5397
  import { Stream as Stream14 } from "@dxos/codec-protobuf";
5235
5398
  import { GetDiagnosticsRequest } from "@dxos/protocols/proto/dxos/client/services";
@@ -5298,13 +5461,14 @@ function _ts_decorate8(decorators, target, key, desc) {
5298
5461
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5299
5462
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5300
5463
  }
5301
- var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
5464
+ var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
5302
5465
  var ClientServicesHost = class {
5303
5466
  constructor({
5304
5467
  config,
5305
5468
  transportFactory,
5306
5469
  signalManager,
5307
5470
  storage,
5471
+ level,
5308
5472
  // TODO(wittjosiah): Turn this on by default.
5309
5473
  lockKey,
5310
5474
  callbacks,
@@ -5315,6 +5479,7 @@ var ClientServicesHost = class {
5315
5479
  this._opening = false;
5316
5480
  this._open = false;
5317
5481
  this._storage = storage;
5482
+ this._level = level;
5318
5483
  this._callbacks = callbacks;
5319
5484
  this._runtimeParams = runtimeParams;
5320
5485
  if (config) {
@@ -5353,6 +5518,7 @@ var ClientServicesHost = class {
5353
5518
  await this.reset();
5354
5519
  }
5355
5520
  });
5521
+ this.diagnosticsBroadcastHandler = createCollectDiagnosticsBroadcastHandler(this._systemService);
5356
5522
  this._loggingService = new LoggingServiceImpl();
5357
5523
  this._serviceRegistry = new ServiceRegistry(clientServiceBundle, {
5358
5524
  SystemService: this._systemService,
@@ -5384,24 +5550,24 @@ var ClientServicesHost = class {
5384
5550
  */
5385
5551
  initialize({ config, ...options }) {
5386
5552
  invariant16(!this._open, "service host is open", {
5387
- F: __dxlog_file18,
5388
- L: 182,
5553
+ F: __dxlog_file19,
5554
+ L: 197,
5389
5555
  S: this,
5390
5556
  A: [
5391
5557
  "!this._open",
5392
5558
  "'service host is open'"
5393
5559
  ]
5394
5560
  });
5395
- log15("initializing...", void 0, {
5396
- F: __dxlog_file18,
5397
- L: 183,
5561
+ log16("initializing...", void 0, {
5562
+ F: __dxlog_file19,
5563
+ L: 198,
5398
5564
  S: this,
5399
5565
  C: (f, a) => f(...a)
5400
5566
  });
5401
5567
  if (config) {
5402
5568
  invariant16(!this._config, "config already set", {
5403
- F: __dxlog_file18,
5404
- L: 186,
5569
+ F: __dxlog_file19,
5570
+ L: 201,
5405
5571
  S: this,
5406
5572
  A: [
5407
5573
  "!this._config",
@@ -5414,9 +5580,9 @@ var ClientServicesHost = class {
5414
5580
  }
5415
5581
  }
5416
5582
  if (!options.signalManager) {
5417
- log15.warn("running signaling without telemetry metadata.", void 0, {
5418
- F: __dxlog_file18,
5419
- L: 194,
5583
+ log16.warn("running signaling without telemetry metadata.", void 0, {
5584
+ F: __dxlog_file19,
5585
+ L: 209,
5420
5586
  S: this,
5421
5587
  C: (f, a) => f(...a)
5422
5588
  });
@@ -5426,8 +5592,8 @@ var ClientServicesHost = class {
5426
5592
  }), signalManager = new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
5427
5593
  this._signalManager = signalManager;
5428
5594
  invariant16(!this._networkManager, "network manager already set", {
5429
- F: __dxlog_file18,
5430
- L: 205,
5595
+ F: __dxlog_file19,
5596
+ L: 220,
5431
5597
  S: this,
5432
5598
  A: [
5433
5599
  "!this._networkManager",
@@ -5439,9 +5605,9 @@ var ClientServicesHost = class {
5439
5605
  transportFactory,
5440
5606
  signalManager
5441
5607
  });
5442
- log15("initialized", void 0, {
5443
- F: __dxlog_file18,
5444
- L: 212,
5608
+ log16("initialized", void 0, {
5609
+ F: __dxlog_file19,
5610
+ L: 227,
5445
5611
  S: this,
5446
5612
  C: (f, a) => f(...a)
5447
5613
  });
@@ -5451,17 +5617,17 @@ var ClientServicesHost = class {
5451
5617
  return;
5452
5618
  }
5453
5619
  const traceId = PublicKey13.random().toHex();
5454
- log15.trace("dxos.client-services.host.open", trace9.begin({
5620
+ log16.trace("dxos.client-services.host.open", trace9.begin({
5455
5621
  id: traceId
5456
5622
  }), {
5457
- F: __dxlog_file18,
5458
- L: 223,
5623
+ F: __dxlog_file19,
5624
+ L: 238,
5459
5625
  S: this,
5460
5626
  C: (f, a) => f(...a)
5461
5627
  });
5462
5628
  invariant16(this._config, "config not set", {
5463
- F: __dxlog_file18,
5464
- L: 225,
5629
+ F: __dxlog_file19,
5630
+ L: 240,
5465
5631
  S: this,
5466
5632
  A: [
5467
5633
  "this._config",
@@ -5469,8 +5635,8 @@ var ClientServicesHost = class {
5469
5635
  ]
5470
5636
  });
5471
5637
  invariant16(this._storage, "storage not set", {
5472
- F: __dxlog_file18,
5473
- L: 226,
5638
+ F: __dxlog_file19,
5639
+ L: 241,
5474
5640
  S: this,
5475
5641
  A: [
5476
5642
  "this._storage",
@@ -5478,8 +5644,8 @@ var ClientServicesHost = class {
5478
5644
  ]
5479
5645
  });
5480
5646
  invariant16(this._signalManager, "signal manager not set", {
5481
- F: __dxlog_file18,
5482
- L: 227,
5647
+ F: __dxlog_file19,
5648
+ L: 242,
5483
5649
  S: this,
5484
5650
  A: [
5485
5651
  "this._signalManager",
@@ -5487,8 +5653,8 @@ var ClientServicesHost = class {
5487
5653
  ]
5488
5654
  });
5489
5655
  invariant16(this._networkManager, "network manager not set", {
5490
- F: __dxlog_file18,
5491
- L: 228,
5656
+ F: __dxlog_file19,
5657
+ L: 243,
5492
5658
  S: this,
5493
5659
  A: [
5494
5660
  "this._networkManager",
@@ -5496,17 +5662,18 @@ var ClientServicesHost = class {
5496
5662
  ]
5497
5663
  });
5498
5664
  this._opening = true;
5499
- log15("opening...", {
5665
+ log16("opening...", {
5500
5666
  lockKey: this._resourceLock?.lockKey
5501
5667
  }, {
5502
- F: __dxlog_file18,
5503
- L: 231,
5668
+ F: __dxlog_file19,
5669
+ L: 246,
5504
5670
  S: this,
5505
5671
  C: (f, a) => f(...a)
5506
5672
  });
5507
5673
  if (!this._level) {
5508
5674
  this._level = await createLevel(this._config.get("runtime.client.storage", {}));
5509
5675
  }
5676
+ await this._level.open();
5510
5677
  await this._resourceLock?.acquire();
5511
5678
  await this._loggingService.open();
5512
5679
  this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._runtimeParams);
@@ -5536,8 +5703,8 @@ var ClientServicesHost = class {
5536
5703
  });
5537
5704
  await this._serviceContext.open(ctx);
5538
5705
  invariant16(this.serviceRegistry.services.InvitationsService, void 0, {
5539
- F: __dxlog_file18,
5540
- L: 297,
5706
+ F: __dxlog_file19,
5707
+ L: 314,
5541
5708
  S: this,
5542
5709
  A: [
5543
5710
  "this.serviceRegistry.services.InvitationsService",
@@ -5545,11 +5712,11 @@ var ClientServicesHost = class {
5545
5712
  ]
5546
5713
  });
5547
5714
  const loadedInvitations = await this.serviceRegistry.services.InvitationsService.loadPersistentInvitations();
5548
- log15("loaded persistent invitations", {
5715
+ log16("loaded persistent invitations", {
5549
5716
  count: loadedInvitations.invitations?.length
5550
5717
  }, {
5551
- F: __dxlog_file18,
5552
- L: 300,
5718
+ F: __dxlog_file19,
5719
+ L: 317,
5553
5720
  S: this,
5554
5721
  C: (f, a) => f(...a)
5555
5722
  });
@@ -5563,23 +5730,24 @@ var ClientServicesHost = class {
5563
5730
  });
5564
5731
  void this._devtoolsProxy.open();
5565
5732
  }
5733
+ this.diagnosticsBroadcastHandler.start();
5566
5734
  this._opening = false;
5567
5735
  this._open = true;
5568
5736
  this._statusUpdate.emit();
5569
5737
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
5570
- log15("opened", {
5738
+ log16("opened", {
5571
5739
  deviceKey
5572
5740
  }, {
5573
- F: __dxlog_file18,
5574
- L: 317,
5741
+ F: __dxlog_file19,
5742
+ L: 335,
5575
5743
  S: this,
5576
5744
  C: (f, a) => f(...a)
5577
5745
  });
5578
- log15.trace("dxos.client-services.host.open", trace9.end({
5746
+ log16.trace("dxos.client-services.host.open", trace9.end({
5579
5747
  id: traceId
5580
5748
  }), {
5581
- F: __dxlog_file18,
5582
- L: 318,
5749
+ F: __dxlog_file19,
5750
+ L: 336,
5583
5751
  S: this,
5584
5752
  C: (f, a) => f(...a)
5585
5753
  });
@@ -5589,14 +5757,15 @@ var ClientServicesHost = class {
5589
5757
  return;
5590
5758
  }
5591
5759
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
5592
- log15("closing...", {
5760
+ log16("closing...", {
5593
5761
  deviceKey
5594
5762
  }, {
5595
- F: __dxlog_file18,
5596
- L: 329,
5763
+ F: __dxlog_file19,
5764
+ L: 347,
5597
5765
  S: this,
5598
5766
  C: (f, a) => f(...a)
5599
5767
  });
5768
+ this.diagnosticsBroadcastHandler.stop();
5600
5769
  await this._devtoolsProxy?.close();
5601
5770
  this._serviceRegistry.setServices({
5602
5771
  SystemService: this._systemService
@@ -5606,44 +5775,44 @@ var ClientServicesHost = class {
5606
5775
  await this._level?.close();
5607
5776
  this._open = false;
5608
5777
  this._statusUpdate.emit();
5609
- log15("closed", {
5778
+ log16("closed", {
5610
5779
  deviceKey
5611
5780
  }, {
5612
- F: __dxlog_file18,
5613
- L: 337,
5781
+ F: __dxlog_file19,
5782
+ L: 356,
5614
5783
  S: this,
5615
5784
  C: (f, a) => f(...a)
5616
5785
  });
5617
5786
  }
5618
5787
  async reset() {
5619
5788
  const traceId = PublicKey13.random().toHex();
5620
- log15.trace("dxos.sdk.client-services-host.reset", trace9.begin({
5789
+ log16.trace("dxos.sdk.client-services-host.reset", trace9.begin({
5621
5790
  id: traceId
5622
5791
  }), {
5623
- F: __dxlog_file18,
5624
- L: 342,
5792
+ F: __dxlog_file19,
5793
+ L: 361,
5625
5794
  S: this,
5626
5795
  C: (f, a) => f(...a)
5627
5796
  });
5628
- log15("resetting...", void 0, {
5629
- F: __dxlog_file18,
5630
- L: 344,
5797
+ log16("resetting...", void 0, {
5798
+ F: __dxlog_file19,
5799
+ L: 363,
5631
5800
  S: this,
5632
5801
  C: (f, a) => f(...a)
5633
5802
  });
5634
5803
  await this._serviceContext?.close();
5635
5804
  await this._storage.reset();
5636
- log15("reset", void 0, {
5637
- F: __dxlog_file18,
5638
- L: 347,
5805
+ log16("reset", void 0, {
5806
+ F: __dxlog_file19,
5807
+ L: 366,
5639
5808
  S: this,
5640
5809
  C: (f, a) => f(...a)
5641
5810
  });
5642
- log15.trace("dxos.sdk.client-services-host.reset", trace9.end({
5811
+ log16.trace("dxos.sdk.client-services-host.reset", trace9.end({
5643
5812
  id: traceId
5644
5813
  }), {
5645
- F: __dxlog_file18,
5646
- L: 348,
5814
+ F: __dxlog_file19,
5815
+ L: 367,
5647
5816
  S: this,
5648
5817
  C: (f, a) => f(...a)
5649
5818
  });
@@ -5655,8 +5824,8 @@ var ClientServicesHost = class {
5655
5824
  const space = await this._serviceContext.dataSpaceManager.createSpace();
5656
5825
  const automergeIndex = space.automergeSpaceState.rootUrl;
5657
5826
  invariant16(automergeIndex, void 0, {
5658
- F: __dxlog_file18,
5659
- L: 360,
5827
+ F: __dxlog_file19,
5828
+ L: 379,
5660
5829
  S: this,
5661
5830
  A: [
5662
5831
  "automergeIndex",
@@ -5667,7 +5836,7 @@ var ClientServicesHost = class {
5667
5836
  await document.whenReady();
5668
5837
  const properties = {
5669
5838
  system: {
5670
- type: encodeReference(E.getTypeReference(Properties))
5839
+ type: encodeReference(getTypeReference(Properties))
5671
5840
  },
5672
5841
  data: {
5673
5842
  [defaultKey]: identity.identityKey.toHex()
@@ -5705,6 +5874,44 @@ ClientServicesHost = _ts_decorate8([
5705
5874
  Trace3.resource()
5706
5875
  ], ClientServicesHost);
5707
5876
 
5877
+ // packages/sdk/client-services/src/packlets/services/util.ts
5878
+ import { PublicKey as PublicKey14 } from "@dxos/keys";
5879
+ import { humanize } from "@dxos/util";
5880
+ var ClientServicesProviderResource = Symbol.for("dxos.resource.ClientServices");
5881
+
5882
+ // packages/sdk/client-services/src/packlets/diagnostics/diagnostics-collector.ts
5883
+ var DiagnosticsCollector = class {
5884
+ static {
5885
+ this.broadcastSender = createCollectDiagnosticsBroadcastSender();
5886
+ }
5887
+ static async collect(config = findConfigs(), services = findSystemServiceProvider(), options = {}) {
5888
+ const serviceDiagnostics = await services?.services?.SystemService?.getDiagnostics({
5889
+ keys: options.humanize ? GetDiagnosticsRequest2.KEY_OPTION.HUMANIZE : options.truncate ? GetDiagnosticsRequest2.KEY_OPTION.TRUNCATE : void 0
5890
+ });
5891
+ const clientDiagnostics = {
5892
+ config,
5893
+ trace: TRACE_PROCESSOR3.getDiagnostics()
5894
+ };
5895
+ const diagnostics = serviceDiagnostics != null ? {
5896
+ client: clientDiagnostics,
5897
+ services: serviceDiagnostics
5898
+ } : {
5899
+ client: clientDiagnostics,
5900
+ broadcast: await this.broadcastSender.broadcastDiagnosticsRequest()
5901
+ };
5902
+ return JSON.parse(JSON.stringify(diagnostics, jsonKeyReplacer2(options)));
5903
+ }
5904
+ };
5905
+ var findSystemServiceProvider = () => {
5906
+ const serviceProviders = TRACE_PROCESSOR3.findByAnnotation(ClientServicesProviderResource);
5907
+ const providerResource = serviceProviders.find((r) => r.instance.deref()?.services?.SystemService != null);
5908
+ return providerResource?.instance?.deref() ?? null;
5909
+ };
5910
+ var findConfigs = () => {
5911
+ const configs = TRACE_PROCESSOR3.findByAnnotation(ConfigResource);
5912
+ return configs.map((r) => r.instance.deref()).filter(nonNullable);
5913
+ };
5914
+
5708
5915
  export {
5709
5916
  Buffer,
5710
5917
  subscribeToFeeds,
@@ -5724,20 +5931,24 @@ export {
5724
5931
  IdentityServiceImpl,
5725
5932
  DeviceInvitationProtocol,
5726
5933
  InvitationsHandler,
5727
- invitationExpired,
5934
+ createAdmissionKeypair,
5728
5935
  InvitationsServiceImpl,
5729
5936
  SpaceInvitationProtocol,
5730
5937
  ClientRpcServer,
5731
- createDiagnostics,
5732
5938
  DataSpace,
5733
5939
  DataSpaceManager,
5734
5940
  SpacesServiceImpl,
5735
5941
  ServiceContext,
5736
5942
  ServiceRegistry,
5943
+ createDiagnostics,
5944
+ createCollectDiagnosticsBroadcastSender,
5945
+ createCollectDiagnosticsBroadcastHandler,
5946
+ DiagnosticsCollector,
5737
5947
  Lock,
5738
5948
  isLocked,
5739
5949
  createStorageObjects,
5740
5950
  createLevel,
5741
- ClientServicesHost
5951
+ ClientServicesHost,
5952
+ ClientServicesProviderResource
5742
5953
  };
5743
- //# sourceMappingURL=chunk-V2ALN47T.mjs.map
5954
+ //# sourceMappingURL=chunk-7S34JE6M.mjs.map