@dxos/client-services 0.4.10-main.eedd150 → 0.4.10-main.f635fb0

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 (71) hide show
  1. package/dist/lib/browser/{chunk-I6GQX7F3.mjs → chunk-OYOZOELW.mjs} +842 -630
  2. package/dist/lib/browser/chunk-OYOZOELW.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-42TXJ32V.cjs → chunk-CLDZACGI.cjs} +859 -729
  9. package/dist/lib/node/chunk-CLDZACGI.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 +4 -4
  37. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  38. package/dist/types/src/packlets/services/service-host.d.ts +4 -1
  39. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  40. package/dist/types/src/packlets/services/util.d.ts +1 -0
  41. package/dist/types/src/packlets/services/util.d.ts.map +1 -1
  42. package/dist/types/src/packlets/system/system-service.d.ts +1 -1
  43. package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
  44. package/dist/types/src/packlets/testing/test-builder.d.ts +3 -1
  45. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  46. package/dist/types/src/version.d.ts +1 -1
  47. package/package.json +35 -34
  48. package/src/index.ts +1 -0
  49. package/src/packlets/diagnostics/browser-diagnostics-broadcast.ts +94 -0
  50. package/src/packlets/diagnostics/diagnostics-broadcast.ts +20 -0
  51. package/src/packlets/diagnostics/diagnostics-collector.ts +65 -0
  52. package/src/packlets/{services → diagnostics}/diagnostics.ts +2 -2
  53. package/src/packlets/diagnostics/index.ts +7 -0
  54. package/src/packlets/indexing/util.ts +2 -2
  55. package/src/packlets/invitations/invitation-extension.ts +28 -1
  56. package/src/packlets/invitations/invitations-handler.ts +73 -32
  57. package/src/packlets/invitations/invitations-service.ts +5 -5
  58. package/src/packlets/services/automerge-host.test.ts +9 -3
  59. package/src/packlets/services/index.ts +1 -1
  60. package/src/packlets/services/service-context.test.ts +4 -1
  61. package/src/packlets/services/service-context.ts +11 -7
  62. package/src/packlets/services/service-host.ts +23 -4
  63. package/src/packlets/services/util.ts +2 -0
  64. package/src/packlets/spaces/data-space-manager.test.ts +4 -4
  65. package/src/packlets/storage/level.ts +1 -1
  66. package/src/packlets/system/system-service.ts +1 -1
  67. package/src/packlets/testing/test-builder.ts +20 -4
  68. package/src/version.ts +1 -1
  69. package/dist/lib/browser/chunk-I6GQX7F3.mjs.map +0 -7
  70. package/dist/lib/node/chunk-42TXJ32V.cjs.map +0 -7
  71. 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.eedd150";
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
  }),
@@ -4386,17 +4295,17 @@ var getChannelId = (channel) => `user-channel/${channel}`;
4386
4295
 
4387
4296
  // packages/sdk/client-services/src/packlets/services/service-context.ts
4388
4297
  import { Trigger as Trigger5 } from "@dxos/async";
4389
- import { Context as Context10 } from "@dxos/context";
4298
+ import { Context as Context10, Resource } from "@dxos/context";
4390
4299
  import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
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,9 +4401,10 @@ 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";
4496
- var ServiceContext = class {
4404
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
4405
+ var ServiceContext = class extends Resource {
4497
4406
  constructor(storage, level, networkManager, signalManager, _runtimeParams) {
4407
+ super();
4498
4408
  this.storage = storage;
4499
4409
  this.level = level;
4500
4410
  this.networkManager = networkManager;
@@ -4530,11 +4440,15 @@ var ServiceContext = class {
4530
4440
  });
4531
4441
  this.automergeHost = new AutomergeHost({
4532
4442
  directory: storage.createDirectory("automerge"),
4533
- metadata: this.indexMetadata
4443
+ db: level.sublevel("automerge"),
4444
+ storageCallbacks: createStorageCallbacks({
4445
+ host: () => this.automergeHost,
4446
+ metadata: this.indexMetadata
4447
+ })
4534
4448
  });
4535
4449
  this.indexer = new Indexer({
4536
4450
  indexStore: new IndexStore({
4537
- directory: storage.createDirectory("index-store")
4451
+ db: level.sublevel("index-store")
4538
4452
  }),
4539
4453
  metadataStore: this.indexMetadata,
4540
4454
  loadDocuments: createSelectedDocumentsIterator(this.automergeHost),
@@ -4543,24 +4457,25 @@ var ServiceContext = class {
4543
4457
  this.invitations = new InvitationsHandler(this.networkManager);
4544
4458
  this._handlerFactories.set(Invitation6.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined2(), this._acceptIdentity.bind(this)));
4545
4459
  }
4546
- async open(ctx) {
4460
+ async _open(ctx) {
4547
4461
  await this._checkStorageVersion();
4548
4462
  log12("opening...", void 0, {
4549
- F: __dxlog_file15,
4550
- L: 154,
4463
+ F: __dxlog_file14,
4464
+ L: 157,
4551
4465
  S: this,
4552
4466
  C: (f, a) => f(...a)
4553
4467
  });
4554
4468
  log12.trace("dxos.sdk.service-context.open", trace8.begin({
4555
4469
  id: this._instanceId
4556
4470
  }), {
4557
- F: __dxlog_file15,
4558
- L: 155,
4471
+ F: __dxlog_file14,
4472
+ L: 158,
4559
4473
  S: this,
4560
4474
  C: (f, a) => f(...a)
4561
4475
  });
4562
4476
  await this.signalManager.open();
4563
4477
  await this.networkManager.open();
4478
+ await this.automergeHost.open();
4564
4479
  await this.metadataStore.load();
4565
4480
  await this.spaceManager.open();
4566
4481
  await this.identityManager.open(ctx);
@@ -4570,22 +4485,22 @@ var ServiceContext = class {
4570
4485
  log12.trace("dxos.sdk.service-context.open", trace8.end({
4571
4486
  id: this._instanceId
4572
4487
  }), {
4573
- F: __dxlog_file15,
4574
- L: 165,
4488
+ F: __dxlog_file14,
4489
+ L: 169,
4575
4490
  S: this,
4576
4491
  C: (f, a) => f(...a)
4577
4492
  });
4578
4493
  log12("opened", void 0, {
4579
- F: __dxlog_file15,
4580
- L: 166,
4494
+ F: __dxlog_file14,
4495
+ L: 170,
4581
4496
  S: this,
4582
4497
  C: (f, a) => f(...a)
4583
4498
  });
4584
4499
  }
4585
- async close() {
4500
+ async _close() {
4586
4501
  log12("closing...", void 0, {
4587
- F: __dxlog_file15,
4588
- L: 170,
4502
+ F: __dxlog_file14,
4503
+ L: 174,
4589
4504
  S: this,
4590
4505
  C: (f, a) => f(...a)
4591
4506
  });
@@ -4602,8 +4517,8 @@ var ServiceContext = class {
4602
4517
  await this.metadataStore.close();
4603
4518
  await this.indexer.destroy();
4604
4519
  log12("closed", void 0, {
4605
- F: __dxlog_file15,
4606
- L: 183,
4520
+ F: __dxlog_file14,
4521
+ L: 187,
4607
4522
  S: this,
4608
4523
  C: (f, a) => f(...a)
4609
4524
  });
@@ -4615,9 +4530,9 @@ var ServiceContext = class {
4615
4530
  }
4616
4531
  getInvitationHandler(invitation) {
4617
4532
  const factory = this._handlerFactories.get(invitation.kind);
4618
- invariant14(factory, `Unknown invitation kind: ${invitation.kind}`, {
4619
- F: __dxlog_file15,
4620
- L: 194,
4533
+ invariant13(factory, `Unknown invitation kind: ${invitation.kind}`, {
4534
+ F: __dxlog_file14,
4535
+ L: 198,
4621
4536
  S: this,
4622
4537
  A: [
4623
4538
  "factory",
@@ -4641,15 +4556,15 @@ var ServiceContext = class {
4641
4556
  }
4642
4557
  async _checkStorageVersion() {
4643
4558
  await this.metadataStore.load();
4644
- if (this.metadataStore.version !== STORAGE_VERSION2) {
4645
- throw new InvalidStorageVersionError(STORAGE_VERSION2, this.metadataStore.version);
4559
+ if (this.metadataStore.version !== STORAGE_VERSION) {
4560
+ throw new InvalidStorageVersionError(STORAGE_VERSION, this.metadataStore.version);
4646
4561
  }
4647
4562
  }
4648
4563
  // Called when identity is created.
4649
4564
  async _initialize(ctx) {
4650
4565
  log12("initializing spaces...", void 0, {
4651
- F: __dxlog_file15,
4652
- L: 225,
4566
+ F: __dxlog_file14,
4567
+ L: 229,
4653
4568
  S: this,
4654
4569
  C: (f, a) => f(...a)
4655
4570
  });
@@ -4670,9 +4585,9 @@ var ServiceContext = class {
4670
4585
  this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.automergeHost, this._runtimeParams);
4671
4586
  await this.dataSpaceManager.open();
4672
4587
  this._handlerFactories.set(Invitation6.Kind.SPACE, (invitation) => {
4673
- invariant14(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4674
- F: __dxlog_file15,
4675
- L: 249,
4588
+ invariant13(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4589
+ F: __dxlog_file14,
4590
+ L: 253,
4676
4591
  S: this,
4677
4592
  A: [
4678
4593
  "this.dataSpaceManager",
@@ -4695,8 +4610,8 @@ var ServiceContext = class {
4695
4610
  log12("dataSpaceManager not initialized yet, ignoring space admission", {
4696
4611
  details: assertion
4697
4612
  }, {
4698
- F: __dxlog_file15,
4699
- L: 265,
4613
+ F: __dxlog_file14,
4614
+ L: 269,
4700
4615
  S: this,
4701
4616
  C: (f, a) => f(...a)
4702
4617
  });
@@ -4706,8 +4621,8 @@ var ServiceContext = class {
4706
4621
  log12("space already exists, ignoring space admission", {
4707
4622
  details: assertion
4708
4623
  }, {
4709
- F: __dxlog_file15,
4710
- L: 269,
4624
+ F: __dxlog_file14,
4625
+ L: 273,
4711
4626
  S: this,
4712
4627
  C: (f, a) => f(...a)
4713
4628
  });
@@ -4717,8 +4632,8 @@ var ServiceContext = class {
4717
4632
  log12("accepting space recorded in halo", {
4718
4633
  details: assertion
4719
4634
  }, {
4720
- F: __dxlog_file15,
4721
- L: 274,
4635
+ F: __dxlog_file14,
4636
+ L: 278,
4722
4637
  S: this,
4723
4638
  C: (f, a) => f(...a)
4724
4639
  });
@@ -4728,8 +4643,8 @@ var ServiceContext = class {
4728
4643
  });
4729
4644
  } catch (err) {
4730
4645
  log12.catch(err, void 0, {
4731
- F: __dxlog_file15,
4732
- L: 280,
4646
+ F: __dxlog_file14,
4647
+ L: 284,
4733
4648
  S: this,
4734
4649
  C: (f, a) => f(...a)
4735
4650
  });
@@ -4741,7 +4656,7 @@ var ServiceContext = class {
4741
4656
  };
4742
4657
  _ts_decorate6([
4743
4658
  Trace2.span()
4744
- ], ServiceContext.prototype, "open", null);
4659
+ ], ServiceContext.prototype, "_open", null);
4745
4660
  _ts_decorate6([
4746
4661
  Trace2.span()
4747
4662
  ], ServiceContext.prototype, "_initialize", null);
@@ -4774,214 +4689,265 @@ var ServiceRegistry = class {
4774
4689
  }
4775
4690
  };
4776
4691
 
4777
- // packages/sdk/client-services/src/packlets/locks/browser.ts
4778
- import { asyncTimeout as asyncTimeout2, Trigger as Trigger6 } from "@dxos/async";
4779
- import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
4780
- import { log as log13, logInfo } from "@dxos/log";
4781
- function _ts_decorate7(decorators, target, key, desc) {
4782
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4783
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
4784
- r = Reflect.decorate(decorators, target, key, desc);
4785
- else
4786
- for (var i = decorators.length - 1; i >= 0; i--)
4787
- if (d = decorators[i])
4788
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4789
- return c > 3 && r && Object.defineProperty(target, key, r), r;
4790
- }
4791
- var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
4792
- var Message;
4793
- (function(Message2) {
4794
- Message2["ACQUIRING"] = "acquiring";
4795
- })(Message || (Message = {}));
4796
- var Lock = class {
4797
- constructor({ lockKey, onAcquire, onRelease }) {
4798
- this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
4799
- this._releaseTrigger = new Trigger6();
4800
- this._lockKey = lockKey;
4801
- this._onAcquire = onAcquire;
4802
- this._onRelease = onRelease;
4803
- this._broadcastChannel.onmessage = this._onMessage.bind(this);
4804
- }
4805
- get lockKey() {
4806
- return this._lockKey;
4807
- }
4808
- async acquire() {
4809
- this._broadcastChannel.postMessage({
4810
- message: "acquiring"
4811
- });
4812
- try {
4813
- log13("aquiring lock...", void 0, {
4814
- F: __dxlog_file16,
4815
- L: 42,
4816
- S: this,
4817
- C: (f, a) => f(...a)
4818
- });
4819
- await asyncTimeout2(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
4820
- log13("acquired lock", void 0, {
4821
- F: __dxlog_file16,
4822
- L: 44,
4823
- S: this,
4824
- C: (f, a) => f(...a)
4825
- });
4826
- } catch {
4827
- log13("stealing lock...", void 0, {
4828
- F: __dxlog_file16,
4829
- L: 46,
4830
- S: this,
4831
- C: (f, a) => f(...a)
4832
- });
4833
- await this._requestLock(true);
4834
- log13("stolen lock", void 0, {
4835
- F: __dxlog_file16,
4836
- L: 48,
4837
- S: this,
4838
- C: (f, a) => f(...a)
4839
- });
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.f635fb0";
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
+ };
4840
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
+ };
4841
4730
  }
4842
- async release() {
4843
- 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);
4844
4761
  }
4845
- _onMessage(event) {
4846
- if (event.data.message === "acquiring") {
4847
- 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);
4848
4771
  }
4772
+ diagnostics.storage = Array.from(map.entries()).sort((a, b) => b[1] - a[1]).map(([file, count]) => ({
4773
+ file,
4774
+ count
4775
+ }));
4849
4776
  }
4850
- async _requestLock(steal = false) {
4851
- log13("requesting lock...", {
4852
- steal
4853
- }, {
4854
- F: __dxlog_file16,
4855
- L: 63,
4856
- S: this,
4857
- C: (f, a) => f(...a)
4858
- });
4859
- const acquired = new Trigger6();
4860
- void navigator.locks.request(this._lockKey, {
4861
- steal
4862
- }, async () => {
4863
- await this._onAcquire?.();
4864
- acquired.wake();
4865
- this._releaseTrigger = new Trigger6();
4866
- await this._releaseTrigger.wait();
4867
- log13("releasing lock...", void 0, {
4868
- F: __dxlog_file16,
4869
- L: 72,
4870
- S: this,
4871
- C: (f, a) => f(...a)
4872
- });
4873
- await this._onRelease?.();
4874
- log13("released lock", void 0, {
4875
- F: __dxlog_file16,
4876
- L: 74,
4877
- S: this,
4878
- C: (f, a) => f(...a)
4879
- });
4880
- }).catch(async () => {
4881
- await this._onRelease?.();
4882
- });
4883
- await acquired.wait();
4884
- log13("recieved lock", {
4885
- steal
4886
- }, {
4887
- F: __dxlog_file16,
4888
- L: 81,
4889
- S: this,
4890
- C: (f, a) => f(...a)
4891
- });
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;
4892
4804
  }
4805
+ diagnostics.config = config.values;
4806
+ return diagnostics;
4893
4807
  };
4894
- _ts_decorate7([
4895
- logInfo
4896
- ], Lock.prototype, "lockKey", null);
4897
- var isLocked = (lockPath) => {
4898
- throw new Error("Not implemented");
4899
- };
4900
-
4901
- // packages/sdk/client-services/src/packlets/storage/storage.ts
4902
- import { InvalidConfigError } from "@dxos/protocols";
4903
- import { Runtime as Runtime2 } from "@dxos/protocols/proto/dxos/config";
4904
- import { createStorage, StorageType } from "@dxos/random-access-storage";
4905
-
4906
- // packages/sdk/client-services/src/packlets/storage/util.ts
4907
- import { DX_DATA } from "@dxos/client-protocol";
4908
- import { Runtime } from "@dxos/protocols/proto/dxos/config";
4909
- import { isNode as isNode2 } from "@dxos/util";
4910
- var getRootPath = (config) => {
4911
- const { dataRoot = isNode2() ? DX_DATA : "dxos/storage" } = config ?? {};
4912
- return `${dataRoot}/`;
4913
- };
4914
- var isPersistent = (config) => {
4915
- const { persistent = false } = config ?? {};
4916
- 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;
4917
4840
  };
4918
4841
 
4919
- // packages/sdk/client-services/src/packlets/storage/storage.ts
4920
- var StorageDriver = Runtime2.Client.Storage.StorageDriver;
4921
- var createStorageObjects = (config) => {
4922
- const { persistent = false, keyStore, dataStore } = config ?? {};
4923
- if (persistent && dataStore === StorageDriver.RAM) {
4924
- throw new InvalidConfigError("RAM storage cannot be used in persistent mode.");
4925
- }
4926
- if (!persistent && dataStore !== void 0 && dataStore !== StorageDriver.RAM) {
4927
- throw new InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
4928
- }
4929
- if (persistent && keyStore === StorageDriver.RAM) {
4930
- throw new InvalidConfigError("RAM key storage cannot be used in persistent mode.");
4931
- }
4932
- if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== void 0) {
4933
- throw new InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
4934
- }
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 = () => {
4935
4855
  return {
4936
- storage: createStorage({
4937
- type: persistent ? toStorageType(dataStore) : StorageType.RAM,
4938
- root: getRootPath(config)
4939
- })
4940
- };
4941
- };
4942
- var toStorageType = (type) => {
4943
- switch (type) {
4944
- case void 0:
4945
- return void 0;
4946
- case StorageDriver.RAM:
4947
- return StorageType.RAM;
4948
- case StorageDriver.CHROME:
4949
- return StorageType.CHROME;
4950
- case StorageDriver.FIREFOX:
4951
- return StorageType.FIREFOX;
4952
- case StorageDriver.IDB:
4953
- return StorageType.IDB;
4954
- case StorageDriver.NODE:
4955
- return StorageType.NODE;
4956
- case StorageDriver.WEBFS:
4957
- return StorageType.WEBFS;
4958
- default:
4959
- 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) {
4960
4932
  }
4961
4933
  };
4962
4934
 
4963
- // packages/sdk/client-services/src/packlets/storage/level.ts
4964
- import { Level } from "level";
4965
- import path from "@dxos/node-std/path";
4966
- import { PublicKey as PublicKey11 } from "@dxos/keys";
4967
- var createLevel = async (config) => {
4968
- const persistent = isPersistent(config);
4969
- const storagePath = persistent ? getRootPath(config) : path.join("tmp", "level", PublicKey11.random().toHex());
4970
- const level = new Level(storagePath);
4971
- await level.open();
4972
- return level;
4973
- };
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";
4974
4940
 
4975
4941
  // packages/sdk/client-services/src/packlets/services/service-host.ts
4976
4942
  import { Event as Event9, synchronized as synchronized3 } from "@dxos/async";
4977
4943
  import { clientServiceBundle, defaultKey, Properties } from "@dxos/client-protocol";
4978
4944
  import { Context as Context11 } from "@dxos/context";
4979
4945
  import { DataServiceImpl, encodeReference } from "@dxos/echo-pipeline";
4980
- import * as E from "@dxos/echo-schema";
4946
+ import { getTypeReference } from "@dxos/echo-schema";
4981
4947
  import { IndexServiceImpl } from "@dxos/indexing";
4982
4948
  import { invariant as invariant16 } from "@dxos/invariant";
4983
4949
  import { PublicKey as PublicKey13 } from "@dxos/keys";
4984
- import { log as log15 } from "@dxos/log";
4950
+ import { log as log16 } from "@dxos/log";
4985
4951
  import { WebsocketSignalManager } from "@dxos/messaging";
4986
4952
  import { NetworkManager, createSimplePeerTransportFactory } from "@dxos/network-manager";
4987
4953
  import { trace as trace9 } from "@dxos/protocols";
@@ -5072,28 +5038,152 @@ var DevicesServiceImpl = class {
5072
5038
  }
5073
5039
  };
5074
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
+
5075
5165
  // packages/sdk/client-services/src/packlets/logging/logging-service.ts
5076
5166
  import { Event as Event8 } from "@dxos/async";
5077
5167
  import { Stream as Stream12 } from "@dxos/codec-protobuf";
5078
- import { PublicKey as PublicKey12 } from "@dxos/keys";
5079
- 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";
5080
5170
  import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
5081
5171
  import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
5082
5172
  var LoggingServiceImpl = class {
5083
5173
  constructor() {
5084
5174
  this._logs = new Event8();
5085
5175
  this._started = Date.now();
5086
- this._sessionId = PublicKey12.random().toHex();
5176
+ this._sessionId = PublicKey11.random().toHex();
5087
5177
  this._logProcessor = (_config, entry2) => {
5088
5178
  this._logs.emit(entry2);
5089
5179
  };
5090
5180
  }
5091
5181
  async open() {
5092
- log14.runtimeConfig.processors.push(this._logProcessor);
5182
+ log15.runtimeConfig.processors.push(this._logProcessor);
5093
5183
  }
5094
5184
  async close() {
5095
- const index = log14.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
5096
- log14.runtimeConfig.processors.splice(index, 1);
5185
+ const index = log15.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
5186
+ log15.runtimeConfig.processors.splice(index, 1);
5097
5187
  }
5098
5188
  async controlMetrics({ reset, record }) {
5099
5189
  if (reset) {
@@ -5229,6 +5319,80 @@ var NetworkServiceImpl = class {
5229
5319
  }
5230
5320
  };
5231
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
+
5232
5396
  // packages/sdk/client-services/src/packlets/system/system-service.ts
5233
5397
  import { Stream as Stream14 } from "@dxos/codec-protobuf";
5234
5398
  import { GetDiagnosticsRequest } from "@dxos/protocols/proto/dxos/client/services";
@@ -5297,13 +5461,14 @@ function _ts_decorate8(decorators, target, key, desc) {
5297
5461
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5298
5462
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5299
5463
  }
5300
- 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";
5301
5465
  var ClientServicesHost = class {
5302
5466
  constructor({
5303
5467
  config,
5304
5468
  transportFactory,
5305
5469
  signalManager,
5306
5470
  storage,
5471
+ level,
5307
5472
  // TODO(wittjosiah): Turn this on by default.
5308
5473
  lockKey,
5309
5474
  callbacks,
@@ -5314,6 +5479,7 @@ var ClientServicesHost = class {
5314
5479
  this._opening = false;
5315
5480
  this._open = false;
5316
5481
  this._storage = storage;
5482
+ this._level = level;
5317
5483
  this._callbacks = callbacks;
5318
5484
  this._runtimeParams = runtimeParams;
5319
5485
  if (config) {
@@ -5352,6 +5518,7 @@ var ClientServicesHost = class {
5352
5518
  await this.reset();
5353
5519
  }
5354
5520
  });
5521
+ this.diagnosticsBroadcastHandler = createCollectDiagnosticsBroadcastHandler(this._systemService);
5355
5522
  this._loggingService = new LoggingServiceImpl();
5356
5523
  this._serviceRegistry = new ServiceRegistry(clientServiceBundle, {
5357
5524
  SystemService: this._systemService,
@@ -5383,24 +5550,24 @@ var ClientServicesHost = class {
5383
5550
  */
5384
5551
  initialize({ config, ...options }) {
5385
5552
  invariant16(!this._open, "service host is open", {
5386
- F: __dxlog_file18,
5387
- L: 182,
5553
+ F: __dxlog_file19,
5554
+ L: 197,
5388
5555
  S: this,
5389
5556
  A: [
5390
5557
  "!this._open",
5391
5558
  "'service host is open'"
5392
5559
  ]
5393
5560
  });
5394
- log15("initializing...", void 0, {
5395
- F: __dxlog_file18,
5396
- L: 183,
5561
+ log16("initializing...", void 0, {
5562
+ F: __dxlog_file19,
5563
+ L: 198,
5397
5564
  S: this,
5398
5565
  C: (f, a) => f(...a)
5399
5566
  });
5400
5567
  if (config) {
5401
5568
  invariant16(!this._config, "config already set", {
5402
- F: __dxlog_file18,
5403
- L: 186,
5569
+ F: __dxlog_file19,
5570
+ L: 201,
5404
5571
  S: this,
5405
5572
  A: [
5406
5573
  "!this._config",
@@ -5413,9 +5580,9 @@ var ClientServicesHost = class {
5413
5580
  }
5414
5581
  }
5415
5582
  if (!options.signalManager) {
5416
- log15.warn("running signaling without telemetry metadata.", void 0, {
5417
- F: __dxlog_file18,
5418
- L: 194,
5583
+ log16.warn("running signaling without telemetry metadata.", void 0, {
5584
+ F: __dxlog_file19,
5585
+ L: 209,
5419
5586
  S: this,
5420
5587
  C: (f, a) => f(...a)
5421
5588
  });
@@ -5425,8 +5592,8 @@ var ClientServicesHost = class {
5425
5592
  }), signalManager = new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
5426
5593
  this._signalManager = signalManager;
5427
5594
  invariant16(!this._networkManager, "network manager already set", {
5428
- F: __dxlog_file18,
5429
- L: 205,
5595
+ F: __dxlog_file19,
5596
+ L: 220,
5430
5597
  S: this,
5431
5598
  A: [
5432
5599
  "!this._networkManager",
@@ -5438,9 +5605,9 @@ var ClientServicesHost = class {
5438
5605
  transportFactory,
5439
5606
  signalManager
5440
5607
  });
5441
- log15("initialized", void 0, {
5442
- F: __dxlog_file18,
5443
- L: 212,
5608
+ log16("initialized", void 0, {
5609
+ F: __dxlog_file19,
5610
+ L: 227,
5444
5611
  S: this,
5445
5612
  C: (f, a) => f(...a)
5446
5613
  });
@@ -5450,17 +5617,17 @@ var ClientServicesHost = class {
5450
5617
  return;
5451
5618
  }
5452
5619
  const traceId = PublicKey13.random().toHex();
5453
- log15.trace("dxos.client-services.host.open", trace9.begin({
5620
+ log16.trace("dxos.client-services.host.open", trace9.begin({
5454
5621
  id: traceId
5455
5622
  }), {
5456
- F: __dxlog_file18,
5457
- L: 223,
5623
+ F: __dxlog_file19,
5624
+ L: 238,
5458
5625
  S: this,
5459
5626
  C: (f, a) => f(...a)
5460
5627
  });
5461
5628
  invariant16(this._config, "config not set", {
5462
- F: __dxlog_file18,
5463
- L: 225,
5629
+ F: __dxlog_file19,
5630
+ L: 240,
5464
5631
  S: this,
5465
5632
  A: [
5466
5633
  "this._config",
@@ -5468,8 +5635,8 @@ var ClientServicesHost = class {
5468
5635
  ]
5469
5636
  });
5470
5637
  invariant16(this._storage, "storage not set", {
5471
- F: __dxlog_file18,
5472
- L: 226,
5638
+ F: __dxlog_file19,
5639
+ L: 241,
5473
5640
  S: this,
5474
5641
  A: [
5475
5642
  "this._storage",
@@ -5477,8 +5644,8 @@ var ClientServicesHost = class {
5477
5644
  ]
5478
5645
  });
5479
5646
  invariant16(this._signalManager, "signal manager not set", {
5480
- F: __dxlog_file18,
5481
- L: 227,
5647
+ F: __dxlog_file19,
5648
+ L: 242,
5482
5649
  S: this,
5483
5650
  A: [
5484
5651
  "this._signalManager",
@@ -5486,8 +5653,8 @@ var ClientServicesHost = class {
5486
5653
  ]
5487
5654
  });
5488
5655
  invariant16(this._networkManager, "network manager not set", {
5489
- F: __dxlog_file18,
5490
- L: 228,
5656
+ F: __dxlog_file19,
5657
+ L: 243,
5491
5658
  S: this,
5492
5659
  A: [
5493
5660
  "this._networkManager",
@@ -5495,17 +5662,18 @@ var ClientServicesHost = class {
5495
5662
  ]
5496
5663
  });
5497
5664
  this._opening = true;
5498
- log15("opening...", {
5665
+ log16("opening...", {
5499
5666
  lockKey: this._resourceLock?.lockKey
5500
5667
  }, {
5501
- F: __dxlog_file18,
5502
- L: 231,
5668
+ F: __dxlog_file19,
5669
+ L: 246,
5503
5670
  S: this,
5504
5671
  C: (f, a) => f(...a)
5505
5672
  });
5506
5673
  if (!this._level) {
5507
5674
  this._level = await createLevel(this._config.get("runtime.client.storage", {}));
5508
5675
  }
5676
+ await this._level.open();
5509
5677
  await this._resourceLock?.acquire();
5510
5678
  await this._loggingService.open();
5511
5679
  this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._runtimeParams);
@@ -5535,8 +5703,8 @@ var ClientServicesHost = class {
5535
5703
  });
5536
5704
  await this._serviceContext.open(ctx);
5537
5705
  invariant16(this.serviceRegistry.services.InvitationsService, void 0, {
5538
- F: __dxlog_file18,
5539
- L: 297,
5706
+ F: __dxlog_file19,
5707
+ L: 314,
5540
5708
  S: this,
5541
5709
  A: [
5542
5710
  "this.serviceRegistry.services.InvitationsService",
@@ -5544,11 +5712,11 @@ var ClientServicesHost = class {
5544
5712
  ]
5545
5713
  });
5546
5714
  const loadedInvitations = await this.serviceRegistry.services.InvitationsService.loadPersistentInvitations();
5547
- log15("loaded persistent invitations", {
5715
+ log16("loaded persistent invitations", {
5548
5716
  count: loadedInvitations.invitations?.length
5549
5717
  }, {
5550
- F: __dxlog_file18,
5551
- L: 300,
5718
+ F: __dxlog_file19,
5719
+ L: 317,
5552
5720
  S: this,
5553
5721
  C: (f, a) => f(...a)
5554
5722
  });
@@ -5562,23 +5730,24 @@ var ClientServicesHost = class {
5562
5730
  });
5563
5731
  void this._devtoolsProxy.open();
5564
5732
  }
5733
+ this.diagnosticsBroadcastHandler.start();
5565
5734
  this._opening = false;
5566
5735
  this._open = true;
5567
5736
  this._statusUpdate.emit();
5568
5737
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
5569
- log15("opened", {
5738
+ log16("opened", {
5570
5739
  deviceKey
5571
5740
  }, {
5572
- F: __dxlog_file18,
5573
- L: 317,
5741
+ F: __dxlog_file19,
5742
+ L: 335,
5574
5743
  S: this,
5575
5744
  C: (f, a) => f(...a)
5576
5745
  });
5577
- log15.trace("dxos.client-services.host.open", trace9.end({
5746
+ log16.trace("dxos.client-services.host.open", trace9.end({
5578
5747
  id: traceId
5579
5748
  }), {
5580
- F: __dxlog_file18,
5581
- L: 318,
5749
+ F: __dxlog_file19,
5750
+ L: 336,
5582
5751
  S: this,
5583
5752
  C: (f, a) => f(...a)
5584
5753
  });
@@ -5588,14 +5757,15 @@ var ClientServicesHost = class {
5588
5757
  return;
5589
5758
  }
5590
5759
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
5591
- log15("closing...", {
5760
+ log16("closing...", {
5592
5761
  deviceKey
5593
5762
  }, {
5594
- F: __dxlog_file18,
5595
- L: 329,
5763
+ F: __dxlog_file19,
5764
+ L: 347,
5596
5765
  S: this,
5597
5766
  C: (f, a) => f(...a)
5598
5767
  });
5768
+ this.diagnosticsBroadcastHandler.stop();
5599
5769
  await this._devtoolsProxy?.close();
5600
5770
  this._serviceRegistry.setServices({
5601
5771
  SystemService: this._systemService
@@ -5605,44 +5775,44 @@ var ClientServicesHost = class {
5605
5775
  await this._level?.close();
5606
5776
  this._open = false;
5607
5777
  this._statusUpdate.emit();
5608
- log15("closed", {
5778
+ log16("closed", {
5609
5779
  deviceKey
5610
5780
  }, {
5611
- F: __dxlog_file18,
5612
- L: 337,
5781
+ F: __dxlog_file19,
5782
+ L: 356,
5613
5783
  S: this,
5614
5784
  C: (f, a) => f(...a)
5615
5785
  });
5616
5786
  }
5617
5787
  async reset() {
5618
5788
  const traceId = PublicKey13.random().toHex();
5619
- log15.trace("dxos.sdk.client-services-host.reset", trace9.begin({
5789
+ log16.trace("dxos.sdk.client-services-host.reset", trace9.begin({
5620
5790
  id: traceId
5621
5791
  }), {
5622
- F: __dxlog_file18,
5623
- L: 342,
5792
+ F: __dxlog_file19,
5793
+ L: 361,
5624
5794
  S: this,
5625
5795
  C: (f, a) => f(...a)
5626
5796
  });
5627
- log15("resetting...", void 0, {
5628
- F: __dxlog_file18,
5629
- L: 344,
5797
+ log16("resetting...", void 0, {
5798
+ F: __dxlog_file19,
5799
+ L: 363,
5630
5800
  S: this,
5631
5801
  C: (f, a) => f(...a)
5632
5802
  });
5633
5803
  await this._serviceContext?.close();
5634
5804
  await this._storage.reset();
5635
- log15("reset", void 0, {
5636
- F: __dxlog_file18,
5637
- L: 347,
5805
+ log16("reset", void 0, {
5806
+ F: __dxlog_file19,
5807
+ L: 366,
5638
5808
  S: this,
5639
5809
  C: (f, a) => f(...a)
5640
5810
  });
5641
- log15.trace("dxos.sdk.client-services-host.reset", trace9.end({
5811
+ log16.trace("dxos.sdk.client-services-host.reset", trace9.end({
5642
5812
  id: traceId
5643
5813
  }), {
5644
- F: __dxlog_file18,
5645
- L: 348,
5814
+ F: __dxlog_file19,
5815
+ L: 367,
5646
5816
  S: this,
5647
5817
  C: (f, a) => f(...a)
5648
5818
  });
@@ -5654,8 +5824,8 @@ var ClientServicesHost = class {
5654
5824
  const space = await this._serviceContext.dataSpaceManager.createSpace();
5655
5825
  const automergeIndex = space.automergeSpaceState.rootUrl;
5656
5826
  invariant16(automergeIndex, void 0, {
5657
- F: __dxlog_file18,
5658
- L: 360,
5827
+ F: __dxlog_file19,
5828
+ L: 379,
5659
5829
  S: this,
5660
5830
  A: [
5661
5831
  "automergeIndex",
@@ -5666,7 +5836,7 @@ var ClientServicesHost = class {
5666
5836
  await document.whenReady();
5667
5837
  const properties = {
5668
5838
  system: {
5669
- type: encodeReference(E.getTypeReference(Properties))
5839
+ type: encodeReference(getTypeReference(Properties))
5670
5840
  },
5671
5841
  data: {
5672
5842
  [defaultKey]: identity.identityKey.toHex()
@@ -5704,6 +5874,44 @@ ClientServicesHost = _ts_decorate8([
5704
5874
  Trace3.resource()
5705
5875
  ], ClientServicesHost);
5706
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
+
5707
5915
  export {
5708
5916
  Buffer,
5709
5917
  subscribeToFeeds,
@@ -5723,20 +5931,24 @@ export {
5723
5931
  IdentityServiceImpl,
5724
5932
  DeviceInvitationProtocol,
5725
5933
  InvitationsHandler,
5726
- invitationExpired,
5934
+ createAdmissionKeypair,
5727
5935
  InvitationsServiceImpl,
5728
5936
  SpaceInvitationProtocol,
5729
5937
  ClientRpcServer,
5730
- createDiagnostics,
5731
5938
  DataSpace,
5732
5939
  DataSpaceManager,
5733
5940
  SpacesServiceImpl,
5734
5941
  ServiceContext,
5735
5942
  ServiceRegistry,
5943
+ createDiagnostics,
5944
+ createCollectDiagnosticsBroadcastSender,
5945
+ createCollectDiagnosticsBroadcastHandler,
5946
+ DiagnosticsCollector,
5736
5947
  Lock,
5737
5948
  isLocked,
5738
5949
  createStorageObjects,
5739
5950
  createLevel,
5740
- ClientServicesHost
5951
+ ClientServicesHost,
5952
+ ClientServicesProviderResource
5741
5953
  };
5742
- //# sourceMappingURL=chunk-I6GQX7F3.mjs.map
5954
+ //# sourceMappingURL=chunk-OYOZOELW.mjs.map