@dxos/client-services 0.4.10-main.c32f430 → 0.4.10-main.ccba876

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 (85) hide show
  1. package/dist/lib/browser/{chunk-FPOYSPWD.mjs → chunk-LGZBUJLB.mjs} +874 -623
  2. package/dist/lib/browser/chunk-LGZBUJLB.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +13 -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 +11 -5
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/{chunk-ZILMQKKB.cjs → chunk-HM374IDE.cjs} +838 -674
  9. package/dist/lib/node/chunk-HM374IDE.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +48 -38
  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 +15 -9
  14. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  15. package/dist/types/src/index.d.ts +1 -0
  16. package/dist/types/src/index.d.ts.map +1 -1
  17. package/dist/types/src/packlets/diagnostics/browser-diagnostics-broadcast.d.ts +5 -0
  18. package/dist/types/src/packlets/diagnostics/browser-diagnostics-broadcast.d.ts.map +1 -0
  19. package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts +5 -0
  20. package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts.map +1 -0
  21. package/dist/types/src/packlets/diagnostics/diagnostics-collector.d.ts +15 -0
  22. package/dist/types/src/packlets/diagnostics/diagnostics-collector.d.ts.map +1 -0
  23. package/dist/types/src/packlets/{services → diagnostics}/diagnostics.d.ts +1 -1
  24. package/dist/types/src/packlets/diagnostics/diagnostics.d.ts.map +1 -0
  25. package/dist/types/src/packlets/diagnostics/index.d.ts +4 -0
  26. package/dist/types/src/packlets/diagnostics/index.d.ts.map +1 -0
  27. package/dist/types/src/packlets/invitations/invitation-extension.d.ts +1 -0
  28. package/dist/types/src/packlets/invitations/invitation-extension.d.ts.map +1 -1
  29. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +4 -2
  30. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  31. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  32. package/dist/types/src/packlets/services/index.d.ts +1 -1
  33. package/dist/types/src/packlets/services/index.d.ts.map +1 -1
  34. package/dist/types/src/packlets/services/service-context.d.ts +7 -5
  35. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  36. package/dist/types/src/packlets/services/service-host.d.ts +5 -1
  37. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  38. package/dist/types/src/packlets/services/util.d.ts +1 -0
  39. package/dist/types/src/packlets/services/util.d.ts.map +1 -1
  40. package/dist/types/src/packlets/storage/index.d.ts +1 -0
  41. package/dist/types/src/packlets/storage/index.d.ts.map +1 -1
  42. package/dist/types/src/packlets/storage/level.d.ts +4 -0
  43. package/dist/types/src/packlets/storage/level.d.ts.map +1 -0
  44. package/dist/types/src/packlets/storage/storage.d.ts.map +1 -1
  45. package/dist/types/src/packlets/storage/util.d.ts +4 -0
  46. package/dist/types/src/packlets/storage/util.d.ts.map +1 -0
  47. package/dist/types/src/packlets/system/system-service.d.ts +1 -1
  48. package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
  49. package/dist/types/src/packlets/testing/test-builder.d.ts +5 -2
  50. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  51. package/dist/types/src/version.d.ts +1 -1
  52. package/package.json +36 -34
  53. package/src/index.ts +1 -0
  54. package/src/packlets/devices/devices-service.test.ts +1 -1
  55. package/src/packlets/diagnostics/browser-diagnostics-broadcast.ts +94 -0
  56. package/src/packlets/diagnostics/diagnostics-broadcast.ts +20 -0
  57. package/src/packlets/diagnostics/diagnostics-collector.ts +65 -0
  58. package/src/packlets/{services → diagnostics}/diagnostics.ts +2 -2
  59. package/src/packlets/diagnostics/index.ts +7 -0
  60. package/src/packlets/identity/identity-service.test.ts +1 -1
  61. package/src/packlets/indexing/util.ts +1 -1
  62. package/src/packlets/invitations/device-invitation-protocol.test.ts +1 -1
  63. package/src/packlets/invitations/invitation-extension.ts +28 -1
  64. package/src/packlets/invitations/invitations-handler.ts +73 -32
  65. package/src/packlets/invitations/invitations-service.ts +5 -5
  66. package/src/packlets/network/network-service.test.ts +1 -1
  67. package/src/packlets/services/automerge-host.test.ts +9 -3
  68. package/src/packlets/services/index.ts +1 -1
  69. package/src/packlets/services/service-context.test.ts +9 -6
  70. package/src/packlets/services/service-context.ts +12 -5
  71. package/src/packlets/services/service-host.ts +49 -9
  72. package/src/packlets/services/service-registry.test.ts +1 -1
  73. package/src/packlets/services/util.ts +2 -0
  74. package/src/packlets/spaces/data-space-manager.test.ts +4 -4
  75. package/src/packlets/spaces/spaces-service.test.ts +1 -1
  76. package/src/packlets/storage/index.ts +1 -0
  77. package/src/packlets/storage/level.ts +19 -0
  78. package/src/packlets/storage/storage.ts +3 -9
  79. package/src/packlets/storage/util.ts +19 -0
  80. package/src/packlets/system/system-service.ts +1 -1
  81. package/src/packlets/testing/test-builder.ts +23 -5
  82. package/src/version.ts +1 -1
  83. package/dist/lib/browser/chunk-FPOYSPWD.mjs.map +0 -7
  84. package/dist/lib/node/chunk-ZILMQKKB.cjs.map +0 -7
  85. 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.c32f430";
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
4303
  import { IndexMetadataStore, IndexStore, Indexer } from "@dxos/indexing";
4395
- import { invariant as invariant14 } from "@dxos/invariant";
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";
@@ -4419,13 +4328,13 @@ var createSelectedDocumentsIterator = (automergeHost) => (
4419
4328
  await warnAfterTimeout2(5e3, "to long to load doc", () => handle.whenReady());
4420
4329
  const doc = handle.docSync();
4421
4330
  const hash = getHeads(doc).join("");
4422
- yield [
4331
+ yield doc.objects?.[objectId] ? [
4423
4332
  {
4424
4333
  id,
4425
4334
  object: doc.objects[objectId],
4426
4335
  currentHash: hash
4427
4336
  }
4428
- ];
4337
+ ] : [];
4429
4338
  }
4430
4339
  }
4431
4340
  );
@@ -4492,10 +4401,12 @@ 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 {
4497
- constructor(storage, networkManager, signalManager, _runtimeParams) {
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 {
4406
+ constructor(storage, level, networkManager, signalManager, _runtimeParams) {
4407
+ super();
4498
4408
  this.storage = storage;
4409
+ this.level = level;
4499
4410
  this.networkManager = networkManager;
4500
4411
  this.signalManager = signalManager;
4501
4412
  this._runtimeParams = _runtimeParams;
@@ -4525,10 +4436,11 @@ var ServiceContext = class {
4525
4436
  });
4526
4437
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager, this._runtimeParams);
4527
4438
  this.indexMetadata = new IndexMetadataStore({
4528
- directory: storage.createDirectory("index-metadata")
4439
+ db: level.sublevel("index-metadata")
4529
4440
  });
4530
4441
  this.automergeHost = new AutomergeHost({
4531
4442
  directory: storage.createDirectory("automerge"),
4443
+ db: level.sublevel("automerge"),
4532
4444
  metadata: this.indexMetadata
4533
4445
  });
4534
4446
  this.indexer = new Indexer({
@@ -4542,24 +4454,25 @@ var ServiceContext = class {
4542
4454
  this.invitations = new InvitationsHandler(this.networkManager);
4543
4455
  this._handlerFactories.set(Invitation6.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined2(), this._acceptIdentity.bind(this)));
4544
4456
  }
4545
- async open(ctx) {
4457
+ async _open(ctx) {
4546
4458
  await this._checkStorageVersion();
4547
4459
  log12("opening...", void 0, {
4548
- F: __dxlog_file15,
4549
- L: 151,
4460
+ F: __dxlog_file14,
4461
+ L: 157,
4550
4462
  S: this,
4551
4463
  C: (f, a) => f(...a)
4552
4464
  });
4553
4465
  log12.trace("dxos.sdk.service-context.open", trace8.begin({
4554
4466
  id: this._instanceId
4555
4467
  }), {
4556
- F: __dxlog_file15,
4557
- L: 152,
4468
+ F: __dxlog_file14,
4469
+ L: 158,
4558
4470
  S: this,
4559
4471
  C: (f, a) => f(...a)
4560
4472
  });
4561
4473
  await this.signalManager.open();
4562
4474
  await this.networkManager.open();
4475
+ await this.automergeHost.open();
4563
4476
  await this.metadataStore.load();
4564
4477
  await this.spaceManager.open();
4565
4478
  await this.identityManager.open(ctx);
@@ -4569,22 +4482,22 @@ var ServiceContext = class {
4569
4482
  log12.trace("dxos.sdk.service-context.open", trace8.end({
4570
4483
  id: this._instanceId
4571
4484
  }), {
4572
- F: __dxlog_file15,
4573
- L: 162,
4485
+ F: __dxlog_file14,
4486
+ L: 169,
4574
4487
  S: this,
4575
4488
  C: (f, a) => f(...a)
4576
4489
  });
4577
4490
  log12("opened", void 0, {
4578
- F: __dxlog_file15,
4579
- L: 163,
4491
+ F: __dxlog_file14,
4492
+ L: 170,
4580
4493
  S: this,
4581
4494
  C: (f, a) => f(...a)
4582
4495
  });
4583
4496
  }
4584
- async close() {
4497
+ async _close() {
4585
4498
  log12("closing...", void 0, {
4586
- F: __dxlog_file15,
4587
- L: 167,
4499
+ F: __dxlog_file14,
4500
+ L: 174,
4588
4501
  S: this,
4589
4502
  C: (f, a) => f(...a)
4590
4503
  });
@@ -4601,8 +4514,8 @@ var ServiceContext = class {
4601
4514
  await this.metadataStore.close();
4602
4515
  await this.indexer.destroy();
4603
4516
  log12("closed", void 0, {
4604
- F: __dxlog_file15,
4605
- L: 180,
4517
+ F: __dxlog_file14,
4518
+ L: 187,
4606
4519
  S: this,
4607
4520
  C: (f, a) => f(...a)
4608
4521
  });
@@ -4614,9 +4527,9 @@ var ServiceContext = class {
4614
4527
  }
4615
4528
  getInvitationHandler(invitation) {
4616
4529
  const factory = this._handlerFactories.get(invitation.kind);
4617
- invariant14(factory, `Unknown invitation kind: ${invitation.kind}`, {
4618
- F: __dxlog_file15,
4619
- L: 191,
4530
+ invariant13(factory, `Unknown invitation kind: ${invitation.kind}`, {
4531
+ F: __dxlog_file14,
4532
+ L: 198,
4620
4533
  S: this,
4621
4534
  A: [
4622
4535
  "factory",
@@ -4640,15 +4553,15 @@ var ServiceContext = class {
4640
4553
  }
4641
4554
  async _checkStorageVersion() {
4642
4555
  await this.metadataStore.load();
4643
- if (this.metadataStore.version !== STORAGE_VERSION2) {
4644
- throw new InvalidStorageVersionError(STORAGE_VERSION2, this.metadataStore.version);
4556
+ if (this.metadataStore.version !== STORAGE_VERSION) {
4557
+ throw new InvalidStorageVersionError(STORAGE_VERSION, this.metadataStore.version);
4645
4558
  }
4646
4559
  }
4647
4560
  // Called when identity is created.
4648
4561
  async _initialize(ctx) {
4649
4562
  log12("initializing spaces...", void 0, {
4650
- F: __dxlog_file15,
4651
- L: 222,
4563
+ F: __dxlog_file14,
4564
+ L: 229,
4652
4565
  S: this,
4653
4566
  C: (f, a) => f(...a)
4654
4567
  });
@@ -4669,9 +4582,9 @@ var ServiceContext = class {
4669
4582
  this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.automergeHost, this._runtimeParams);
4670
4583
  await this.dataSpaceManager.open();
4671
4584
  this._handlerFactories.set(Invitation6.Kind.SPACE, (invitation) => {
4672
- invariant14(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4673
- F: __dxlog_file15,
4674
- L: 246,
4585
+ invariant13(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4586
+ F: __dxlog_file14,
4587
+ L: 253,
4675
4588
  S: this,
4676
4589
  A: [
4677
4590
  "this.dataSpaceManager",
@@ -4694,8 +4607,8 @@ var ServiceContext = class {
4694
4607
  log12("dataSpaceManager not initialized yet, ignoring space admission", {
4695
4608
  details: assertion
4696
4609
  }, {
4697
- F: __dxlog_file15,
4698
- L: 262,
4610
+ F: __dxlog_file14,
4611
+ L: 269,
4699
4612
  S: this,
4700
4613
  C: (f, a) => f(...a)
4701
4614
  });
@@ -4705,8 +4618,8 @@ var ServiceContext = class {
4705
4618
  log12("space already exists, ignoring space admission", {
4706
4619
  details: assertion
4707
4620
  }, {
4708
- F: __dxlog_file15,
4709
- L: 266,
4621
+ F: __dxlog_file14,
4622
+ L: 273,
4710
4623
  S: this,
4711
4624
  C: (f, a) => f(...a)
4712
4625
  });
@@ -4716,8 +4629,8 @@ var ServiceContext = class {
4716
4629
  log12("accepting space recorded in halo", {
4717
4630
  details: assertion
4718
4631
  }, {
4719
- F: __dxlog_file15,
4720
- L: 271,
4632
+ F: __dxlog_file14,
4633
+ L: 278,
4721
4634
  S: this,
4722
4635
  C: (f, a) => f(...a)
4723
4636
  });
@@ -4727,8 +4640,8 @@ var ServiceContext = class {
4727
4640
  });
4728
4641
  } catch (err) {
4729
4642
  log12.catch(err, void 0, {
4730
- F: __dxlog_file15,
4731
- L: 277,
4643
+ F: __dxlog_file14,
4644
+ L: 284,
4732
4645
  S: this,
4733
4646
  C: (f, a) => f(...a)
4734
4647
  });
@@ -4740,7 +4653,7 @@ var ServiceContext = class {
4740
4653
  };
4741
4654
  _ts_decorate6([
4742
4655
  Trace2.span()
4743
- ], ServiceContext.prototype, "open", null);
4656
+ ], ServiceContext.prototype, "_open", null);
4744
4657
  _ts_decorate6([
4745
4658
  Trace2.span()
4746
4659
  ], ServiceContext.prototype, "_initialize", null);
@@ -4773,10 +4686,359 @@ var ServiceRegistry = class {
4773
4686
  }
4774
4687
  };
4775
4688
 
4689
+ // packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts
4690
+ import { getFirstStreamValue } from "@dxos/codec-protobuf";
4691
+ import { credentialTypeFilter } from "@dxos/credentials";
4692
+ import { invariant as invariant14 } from "@dxos/invariant";
4693
+ import { STORAGE_VERSION as STORAGE_VERSION2 } from "@dxos/protocols";
4694
+ import { SpaceMember as SpaceMember3 } from "@dxos/protocols/proto/dxos/client/services";
4695
+ import { TRACE_PROCESSOR } from "@dxos/tracing";
4696
+
4697
+ // packages/sdk/client-services/src/version.ts
4698
+ var DXOS_VERSION = "0.4.10-main.ccba876";
4699
+
4700
+ // packages/sdk/client-services/src/packlets/services/platform.ts
4701
+ import { Platform } from "@dxos/protocols/proto/dxos/client/services";
4702
+ var getPlatform = () => {
4703
+ if (process.browser) {
4704
+ if (typeof window !== "undefined") {
4705
+ const { userAgent } = window.navigator;
4706
+ return {
4707
+ type: Platform.PLATFORM_TYPE.BROWSER,
4708
+ userAgent,
4709
+ uptime: Math.floor((Date.now() - window.performance.timeOrigin) / 1e3)
4710
+ };
4711
+ } else {
4712
+ return {
4713
+ type: Platform.PLATFORM_TYPE.SHARED_WORKER,
4714
+ uptime: Math.floor((Date.now() - performance.timeOrigin) / 1e3)
4715
+ };
4716
+ }
4717
+ } else {
4718
+ const { platform: platform2, version, arch } = process;
4719
+ return {
4720
+ type: Platform.PLATFORM_TYPE.NODE,
4721
+ platform: platform2,
4722
+ arch,
4723
+ runtime: version,
4724
+ uptime: Math.floor(process.uptime()),
4725
+ memory: process.memoryUsage()
4726
+ };
4727
+ }
4728
+ };
4729
+
4730
+ // packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts
4731
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts";
4732
+ var DEFAULT_TIMEOUT = 1e3;
4733
+ var createDiagnostics = async (clientServices, serviceContext, config) => {
4734
+ const diagnostics = {
4735
+ created: (/* @__PURE__ */ new Date()).toISOString(),
4736
+ platform: getPlatform(),
4737
+ client: {
4738
+ version: DXOS_VERSION,
4739
+ storage: {
4740
+ version: STORAGE_VERSION2
4741
+ }
4742
+ },
4743
+ trace: TRACE_PROCESSOR.getDiagnostics()
4744
+ };
4745
+ {
4746
+ invariant14(clientServices.LoggingService, "SystemService is not available.", {
4747
+ F: __dxlog_file15,
4748
+ L: 108,
4749
+ S: void 0,
4750
+ A: [
4751
+ "clientServices.LoggingService",
4752
+ "'SystemService is not available.'"
4753
+ ]
4754
+ });
4755
+ diagnostics.metrics = await getFirstStreamValue(clientServices.LoggingService.queryMetrics({}), {
4756
+ timeout: DEFAULT_TIMEOUT
4757
+ }).catch(() => void 0);
4758
+ }
4759
+ if (typeof navigator !== "undefined" && navigator.storage) {
4760
+ const map = /* @__PURE__ */ new Map();
4761
+ const dir = await navigator.storage.getDirectory();
4762
+ for await (const filename of dir?.keys()) {
4763
+ const idx = filename.indexOf("-", filename.indexOf("-") + 1);
4764
+ if (idx === -1) {
4765
+ continue;
4766
+ }
4767
+ map.set(filename.slice(0, idx), (map.get(filename.slice(0, idx)) ?? 0) + 1);
4768
+ }
4769
+ diagnostics.storage = Array.from(map.entries()).sort((a, b) => b[1] - a[1]).map(([file, count]) => ({
4770
+ file,
4771
+ count
4772
+ }));
4773
+ }
4774
+ const identity = serviceContext.identityManager.identity;
4775
+ if (identity) {
4776
+ diagnostics.identity = {
4777
+ identityKey: identity.identityKey,
4778
+ spaceKey: identity.space.key,
4779
+ profile: identity.profileDocument
4780
+ };
4781
+ const { devices } = await getFirstStreamValue(clientServices.DevicesService.queryDevices(), {
4782
+ timeout: DEFAULT_TIMEOUT
4783
+ }).catch(() => void 0) ?? {};
4784
+ diagnostics.devices = devices;
4785
+ if (serviceContext.dataSpaceManager) {
4786
+ diagnostics.spaces = await Promise.all(Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space)) ?? []);
4787
+ }
4788
+ const { feeds = [] } = await getFirstStreamValue(clientServices.DevtoolsHost.subscribeToFeeds({}), {
4789
+ timeout: DEFAULT_TIMEOUT
4790
+ }).catch(() => void 0) ?? {};
4791
+ diagnostics.feeds = feeds.map(({ feedKey, bytes, length }) => ({
4792
+ feedKey,
4793
+ bytes,
4794
+ length
4795
+ }));
4796
+ const status = await getFirstStreamValue(clientServices.NetworkService.queryStatus(), {
4797
+ timeout: DEFAULT_TIMEOUT
4798
+ }).catch(() => void 0);
4799
+ diagnostics.networkStatus = status;
4800
+ diagnostics.swarms = serviceContext.networkManager.connectionLog?.swarms;
4801
+ }
4802
+ diagnostics.config = config.values;
4803
+ return diagnostics;
4804
+ };
4805
+ var getSpaceStats = async (space) => {
4806
+ const stats = {
4807
+ key: space.key,
4808
+ metrics: space.metrics,
4809
+ epochs: space.inner.spaceState.credentials.filter(credentialTypeFilter("dxos.halo.credentials.Epoch")).map((credential) => ({
4810
+ ...credential.subject.assertion,
4811
+ id: credential.id
4812
+ })),
4813
+ members: Array.from(space.inner.spaceState.members.values()).map((member) => ({
4814
+ identity: {
4815
+ identityKey: member.key,
4816
+ profile: {
4817
+ displayName: member.assertion.profile?.displayName
4818
+ }
4819
+ },
4820
+ presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember3.PresenceState.ONLINE : SpaceMember3.PresenceState.OFFLINE
4821
+ })),
4822
+ pipeline: {
4823
+ // TODO(burdon): Pick properties from credentials if needed.
4824
+ currentEpoch: space.automergeSpaceState.lastEpoch,
4825
+ appliedEpoch: space.automergeSpaceState.lastEpoch,
4826
+ controlFeeds: space.inner.controlPipeline.state.feeds.map((feed) => feed.key),
4827
+ currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
4828
+ targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
4829
+ totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe
4830
+ }
4831
+ };
4832
+ if (stats.metrics) {
4833
+ const { open, ready } = stats.metrics;
4834
+ stats.metrics.startupTime = open && ready && ready.getTime() - open.getTime();
4835
+ }
4836
+ return stats;
4837
+ };
4838
+
4839
+ // packages/sdk/client-services/src/packlets/diagnostics/browser-diagnostics-broadcast.ts
4840
+ import { Trigger as Trigger6 } from "@dxos/async";
4841
+ import { log as log13 } from "@dxos/log";
4842
+ var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/browser-diagnostics-broadcast.ts";
4843
+ var CHANNEL_NAME = "dxos.diagnostics.broadcast";
4844
+ var MessageType;
4845
+ (function(MessageType2) {
4846
+ MessageType2["PROBE"] = "probe";
4847
+ MessageType2["PROBE_ACK"] = "probe-ack";
4848
+ MessageType2["REQUEST_DIAGNOSTICS"] = "request-diagnostics";
4849
+ MessageType2["RECEIVE_DIAGNOSTICS"] = "receive-diagnostics";
4850
+ })(MessageType || (MessageType = {}));
4851
+ var createCollectDiagnosticsBroadcastSender = () => {
4852
+ return {
4853
+ broadcastDiagnosticsRequest: async () => {
4854
+ let expectedResponse = "probe-ack";
4855
+ let channel;
4856
+ try {
4857
+ const trigger = new Trigger6();
4858
+ channel = new BroadcastChannel(CHANNEL_NAME);
4859
+ channel.onmessage = (msg) => {
4860
+ if (expectedResponse === msg.data.type) {
4861
+ trigger.wake(msg.data);
4862
+ }
4863
+ };
4864
+ channel.postMessage({
4865
+ type: "probe"
4866
+ });
4867
+ await trigger.wait({
4868
+ timeout: 200
4869
+ });
4870
+ expectedResponse = "receive-diagnostics";
4871
+ trigger.reset();
4872
+ channel.postMessage({
4873
+ type: "request-diagnostics"
4874
+ });
4875
+ const diagnostics = await trigger.wait({
4876
+ timeout: 5e3
4877
+ });
4878
+ return diagnostics.payload;
4879
+ } catch (e) {
4880
+ const errorDescription = e instanceof Error ? e.message : JSON.stringify(e);
4881
+ return {
4882
+ expectedResponse,
4883
+ errorDescription
4884
+ };
4885
+ } finally {
4886
+ safeClose(channel);
4887
+ }
4888
+ }
4889
+ };
4890
+ };
4891
+ var createCollectDiagnosticsBroadcastHandler = (systemService) => {
4892
+ let channel;
4893
+ return {
4894
+ start: () => {
4895
+ channel = new BroadcastChannel(CHANNEL_NAME);
4896
+ channel.onmessage = async (message) => {
4897
+ try {
4898
+ if (message.data.type === "probe") {
4899
+ channel?.postMessage({
4900
+ type: "probe-ack"
4901
+ });
4902
+ } else if (message.data.type === "request-diagnostics") {
4903
+ const diagnostics = await systemService.getDiagnostics({});
4904
+ channel?.postMessage({
4905
+ type: "receive-diagnostics",
4906
+ payload: diagnostics
4907
+ });
4908
+ }
4909
+ } catch (error) {
4910
+ log13.catch(error, void 0, {
4911
+ F: __dxlog_file16,
4912
+ L: 77,
4913
+ S: void 0,
4914
+ C: (f, a) => f(...a)
4915
+ });
4916
+ }
4917
+ };
4918
+ },
4919
+ stop: () => {
4920
+ safeClose(channel);
4921
+ channel = void 0;
4922
+ }
4923
+ };
4924
+ };
4925
+ var safeClose = (channel) => {
4926
+ try {
4927
+ channel?.close();
4928
+ } catch (e) {
4929
+ }
4930
+ };
4931
+
4932
+ // packages/sdk/client-services/src/packlets/diagnostics/diagnostics-collector.ts
4933
+ import { ConfigResource } from "@dxos/config";
4934
+ import { GetDiagnosticsRequest as GetDiagnosticsRequest2 } from "@dxos/protocols/proto/dxos/client/services";
4935
+ import { TRACE_PROCESSOR as TRACE_PROCESSOR3 } from "@dxos/tracing";
4936
+ import { jsonKeyReplacer as jsonKeyReplacer2, nonNullable } from "@dxos/util";
4937
+
4938
+ // packages/sdk/client-services/src/packlets/services/service-host.ts
4939
+ import { Event as Event9, synchronized as synchronized3 } from "@dxos/async";
4940
+ import { clientServiceBundle, defaultKey, Properties } from "@dxos/client-protocol";
4941
+ import { Context as Context11 } from "@dxos/context";
4942
+ import { DataServiceImpl, encodeReference } from "@dxos/echo-pipeline";
4943
+ import * as E from "@dxos/echo-schema";
4944
+ import { IndexServiceImpl } from "@dxos/indexing";
4945
+ import { invariant as invariant16 } from "@dxos/invariant";
4946
+ import { PublicKey as PublicKey13 } from "@dxos/keys";
4947
+ import { log as log16 } from "@dxos/log";
4948
+ import { WebsocketSignalManager } from "@dxos/messaging";
4949
+ import { NetworkManager, createSimplePeerTransportFactory } from "@dxos/network-manager";
4950
+ import { trace as trace9 } from "@dxos/protocols";
4951
+ import { SystemStatus } from "@dxos/protocols/proto/dxos/client/services";
4952
+ import { TRACE_PROCESSOR as TRACE_PROCESSOR2, trace as Trace3 } from "@dxos/tracing";
4953
+ import { assignDeep as assignDeep2 } from "@dxos/util";
4954
+ import { WebsocketRpcClient } from "@dxos/websocket-rpc";
4955
+
4956
+ // packages/sdk/client-services/src/packlets/devices/devices-service.ts
4957
+ import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
4958
+ import { Stream as Stream11 } from "@dxos/codec-protobuf";
4959
+ import { invariant as invariant15 } from "@dxos/invariant";
4960
+ import { Device as Device2, DeviceKind as DeviceKind2 } from "@dxos/protocols/proto/dxos/client/services";
4961
+ var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
4962
+ var DevicesServiceImpl = class {
4963
+ constructor(_identityManager) {
4964
+ this._identityManager = _identityManager;
4965
+ }
4966
+ async updateDevice(profile) {
4967
+ return this._identityManager.updateDeviceProfile(profile);
4968
+ }
4969
+ queryDevices() {
4970
+ return new Stream11(({ next }) => {
4971
+ const update = () => {
4972
+ const deviceKeys = this._identityManager.identity?.authorizedDeviceKeys;
4973
+ if (!deviceKeys) {
4974
+ next({
4975
+ devices: []
4976
+ });
4977
+ } else {
4978
+ invariant15(this._identityManager.identity?.presence, "presence not present", {
4979
+ F: __dxlog_file17,
4980
+ L: 32,
4981
+ S: this,
4982
+ A: [
4983
+ "this._identityManager.identity?.presence",
4984
+ "'presence not present'"
4985
+ ]
4986
+ });
4987
+ const peers = this._identityManager.identity.presence.getPeersOnline();
4988
+ next({
4989
+ devices: Array.from(deviceKeys.entries()).map(([key, profile]) => {
4990
+ const isMe = this._identityManager.identity?.deviceKey.equals(key);
4991
+ const peerState = peers.find((peer) => peer.identityKey.equals(key));
4992
+ return {
4993
+ deviceKey: key,
4994
+ kind: this._identityManager.identity?.deviceKey.equals(key) ? DeviceKind2.CURRENT : DeviceKind2.TRUSTED,
4995
+ profile,
4996
+ presence: isMe ? Device2.PresenceState.ONLINE : peerState ? Device2.PresenceState.ONLINE : Device2.PresenceState.OFFLINE
4997
+ };
4998
+ })
4999
+ });
5000
+ }
5001
+ };
5002
+ let identitySubscribed = false;
5003
+ let presenceSubscribed = false;
5004
+ const subscribeIdentity = () => {
5005
+ if (!identitySubscribed) {
5006
+ this._identityManager.identity?.stateUpdate.on(() => {
5007
+ update();
5008
+ });
5009
+ identitySubscribed = true;
5010
+ }
5011
+ };
5012
+ const subscribePresence = () => {
5013
+ if (!presenceSubscribed) {
5014
+ this._identityManager.identity?.presence?.updated.on(() => {
5015
+ update();
5016
+ });
5017
+ presenceSubscribed = true;
5018
+ }
5019
+ };
5020
+ const subscriptions = new EventSubscriptions3();
5021
+ if (this._identityManager.identity) {
5022
+ subscribeIdentity();
5023
+ subscribePresence();
5024
+ }
5025
+ subscriptions.add(this._identityManager.stateUpdate.on(() => {
5026
+ update();
5027
+ if (this._identityManager.identity) {
5028
+ subscribeIdentity();
5029
+ subscribePresence();
5030
+ }
5031
+ }));
5032
+ update();
5033
+ return () => subscriptions.clear();
5034
+ });
5035
+ }
5036
+ };
5037
+
4776
5038
  // packages/sdk/client-services/src/packlets/locks/browser.ts
4777
- import { asyncTimeout as asyncTimeout2, Trigger as Trigger6 } from "@dxos/async";
5039
+ import { asyncTimeout as asyncTimeout2, Trigger as Trigger7 } from "@dxos/async";
4778
5040
  import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
4779
- import { log as log13, logInfo } from "@dxos/log";
5041
+ import { log as log14, logInfo } from "@dxos/log";
4780
5042
  function _ts_decorate7(decorators, target, key, desc) {
4781
5043
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4782
5044
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -4787,7 +5049,7 @@ function _ts_decorate7(decorators, target, key, desc) {
4787
5049
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4788
5050
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4789
5051
  }
4790
- var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
5052
+ var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
4791
5053
  var Message;
4792
5054
  (function(Message2) {
4793
5055
  Message2["ACQUIRING"] = "acquiring";
@@ -4795,7 +5057,7 @@ var Message;
4795
5057
  var Lock = class {
4796
5058
  constructor({ lockKey, onAcquire, onRelease }) {
4797
5059
  this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
4798
- this._releaseTrigger = new Trigger6();
5060
+ this._releaseTrigger = new Trigger7();
4799
5061
  this._lockKey = lockKey;
4800
5062
  this._onAcquire = onAcquire;
4801
5063
  this._onRelease = onRelease;
@@ -4809,29 +5071,29 @@ var Lock = class {
4809
5071
  message: "acquiring"
4810
5072
  });
4811
5073
  try {
4812
- log13("aquiring lock...", void 0, {
4813
- F: __dxlog_file16,
5074
+ log14("aquiring lock...", void 0, {
5075
+ F: __dxlog_file18,
4814
5076
  L: 42,
4815
5077
  S: this,
4816
5078
  C: (f, a) => f(...a)
4817
5079
  });
4818
5080
  await asyncTimeout2(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
4819
- log13("acquired lock", void 0, {
4820
- F: __dxlog_file16,
5081
+ log14("acquired lock", void 0, {
5082
+ F: __dxlog_file18,
4821
5083
  L: 44,
4822
5084
  S: this,
4823
5085
  C: (f, a) => f(...a)
4824
5086
  });
4825
5087
  } catch {
4826
- log13("stealing lock...", void 0, {
4827
- F: __dxlog_file16,
5088
+ log14("stealing lock...", void 0, {
5089
+ F: __dxlog_file18,
4828
5090
  L: 46,
4829
5091
  S: this,
4830
5092
  C: (f, a) => f(...a)
4831
5093
  });
4832
5094
  await this._requestLock(true);
4833
- log13("stolen lock", void 0, {
4834
- F: __dxlog_file16,
5095
+ log14("stolen lock", void 0, {
5096
+ F: __dxlog_file18,
4835
5097
  L: 48,
4836
5098
  S: this,
4837
5099
  C: (f, a) => f(...a)
@@ -4847,31 +5109,31 @@ var Lock = class {
4847
5109
  }
4848
5110
  }
4849
5111
  async _requestLock(steal = false) {
4850
- log13("requesting lock...", {
5112
+ log14("requesting lock...", {
4851
5113
  steal
4852
5114
  }, {
4853
- F: __dxlog_file16,
5115
+ F: __dxlog_file18,
4854
5116
  L: 63,
4855
5117
  S: this,
4856
5118
  C: (f, a) => f(...a)
4857
5119
  });
4858
- const acquired = new Trigger6();
5120
+ const acquired = new Trigger7();
4859
5121
  void navigator.locks.request(this._lockKey, {
4860
5122
  steal
4861
5123
  }, async () => {
4862
5124
  await this._onAcquire?.();
4863
5125
  acquired.wake();
4864
- this._releaseTrigger = new Trigger6();
5126
+ this._releaseTrigger = new Trigger7();
4865
5127
  await this._releaseTrigger.wait();
4866
- log13("releasing lock...", void 0, {
4867
- F: __dxlog_file16,
5128
+ log14("releasing lock...", void 0, {
5129
+ F: __dxlog_file18,
4868
5130
  L: 72,
4869
5131
  S: this,
4870
5132
  C: (f, a) => f(...a)
4871
5133
  });
4872
5134
  await this._onRelease?.();
4873
- log13("released lock", void 0, {
4874
- F: __dxlog_file16,
5135
+ log14("released lock", void 0, {
5136
+ F: __dxlog_file18,
4875
5137
  L: 74,
4876
5138
  S: this,
4877
5139
  C: (f, a) => f(...a)
@@ -4880,10 +5142,10 @@ var Lock = class {
4880
5142
  await this._onRelease?.();
4881
5143
  });
4882
5144
  await acquired.wait();
4883
- log13("recieved lock", {
5145
+ log14("recieved lock", {
4884
5146
  steal
4885
5147
  }, {
4886
- F: __dxlog_file16,
5148
+ F: __dxlog_file18,
4887
5149
  L: 81,
4888
5150
  S: this,
4889
5151
  C: (f, a) => f(...a)
@@ -4897,160 +5159,11 @@ var isLocked = (lockPath) => {
4897
5159
  throw new Error("Not implemented");
4898
5160
  };
4899
5161
 
4900
- // packages/sdk/client-services/src/packlets/storage/storage.ts
4901
- import { DX_DATA } from "@dxos/client-protocol";
4902
- import { InvalidConfigError } from "@dxos/protocols";
4903
- import { Runtime } from "@dxos/protocols/proto/dxos/config";
4904
- import { createStorage, StorageType } from "@dxos/random-access-storage";
4905
- import { isNode as isNode2 } from "@dxos/util";
4906
- var StorageDriver = Runtime.Client.Storage.StorageDriver;
4907
- var createStorageObjects = (config) => {
4908
- const { persistent = false, keyStore, dataStore, dataRoot = isNode2() ? DX_DATA : "dxos/storage" } = config ?? {};
4909
- if (persistent && dataStore === StorageDriver.RAM) {
4910
- throw new InvalidConfigError("RAM storage cannot be used in persistent mode.");
4911
- }
4912
- if (!persistent && dataStore !== void 0 && dataStore !== StorageDriver.RAM) {
4913
- throw new InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
4914
- }
4915
- if (persistent && keyStore === StorageDriver.RAM) {
4916
- throw new InvalidConfigError("RAM key storage cannot be used in persistent mode.");
4917
- }
4918
- if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== void 0) {
4919
- throw new InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
4920
- }
4921
- return {
4922
- storage: createStorage({
4923
- type: persistent ? toStorageType(dataStore) : StorageType.RAM,
4924
- root: `${dataRoot}/`
4925
- })
4926
- };
4927
- };
4928
- var toStorageType = (type) => {
4929
- switch (type) {
4930
- case void 0:
4931
- return void 0;
4932
- case StorageDriver.RAM:
4933
- return StorageType.RAM;
4934
- case StorageDriver.CHROME:
4935
- return StorageType.CHROME;
4936
- case StorageDriver.FIREFOX:
4937
- return StorageType.FIREFOX;
4938
- case StorageDriver.IDB:
4939
- return StorageType.IDB;
4940
- case StorageDriver.NODE:
4941
- return StorageType.NODE;
4942
- case StorageDriver.WEBFS:
4943
- return StorageType.WEBFS;
4944
- default:
4945
- throw new Error(`Invalid storage type: ${StorageDriver[type]}`);
4946
- }
4947
- };
4948
-
4949
- // packages/sdk/client-services/src/packlets/services/service-host.ts
4950
- import { Event as Event9, synchronized as synchronized3 } from "@dxos/async";
4951
- import { Properties, clientServiceBundle, defaultKey } from "@dxos/client-protocol";
4952
- import { Context as Context11 } from "@dxos/context";
4953
- import { DataServiceImpl } from "@dxos/echo-pipeline";
4954
- import { getAutomergeObjectCore, getRawDoc } from "@dxos/echo-schema";
4955
- import { IndexServiceImpl } from "@dxos/indexing";
4956
- import { invariant as invariant16 } from "@dxos/invariant";
4957
- import { PublicKey as PublicKey12 } from "@dxos/keys";
4958
- import { log as log15 } from "@dxos/log";
4959
- import { WebsocketSignalManager } from "@dxos/messaging";
4960
- import { NetworkManager, createSimplePeerTransportFactory } from "@dxos/network-manager";
4961
- import { trace as trace9 } from "@dxos/protocols";
4962
- import { SystemStatus } from "@dxos/protocols/proto/dxos/client/services";
4963
- import { TRACE_PROCESSOR as TRACE_PROCESSOR2, trace as Trace3 } from "@dxos/tracing";
4964
- import { assignDeep as assignDeep2 } from "@dxos/util";
4965
- import { WebsocketRpcClient } from "@dxos/websocket-rpc";
4966
-
4967
- // packages/sdk/client-services/src/packlets/devices/devices-service.ts
4968
- import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
4969
- import { Stream as Stream11 } from "@dxos/codec-protobuf";
4970
- import { invariant as invariant15 } from "@dxos/invariant";
4971
- import { Device as Device2, DeviceKind as DeviceKind2 } from "@dxos/protocols/proto/dxos/client/services";
4972
- var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
4973
- var DevicesServiceImpl = class {
4974
- constructor(_identityManager) {
4975
- this._identityManager = _identityManager;
4976
- }
4977
- async updateDevice(profile) {
4978
- return this._identityManager.updateDeviceProfile(profile);
4979
- }
4980
- queryDevices() {
4981
- return new Stream11(({ next }) => {
4982
- const update = () => {
4983
- const deviceKeys = this._identityManager.identity?.authorizedDeviceKeys;
4984
- if (!deviceKeys) {
4985
- next({
4986
- devices: []
4987
- });
4988
- } else {
4989
- invariant15(this._identityManager.identity?.presence, "presence not present", {
4990
- F: __dxlog_file17,
4991
- L: 32,
4992
- S: this,
4993
- A: [
4994
- "this._identityManager.identity?.presence",
4995
- "'presence not present'"
4996
- ]
4997
- });
4998
- const peers = this._identityManager.identity.presence.getPeersOnline();
4999
- next({
5000
- devices: Array.from(deviceKeys.entries()).map(([key, profile]) => {
5001
- const isMe = this._identityManager.identity?.deviceKey.equals(key);
5002
- const peerState = peers.find((peer) => peer.identityKey.equals(key));
5003
- return {
5004
- deviceKey: key,
5005
- kind: this._identityManager.identity?.deviceKey.equals(key) ? DeviceKind2.CURRENT : DeviceKind2.TRUSTED,
5006
- profile,
5007
- presence: isMe ? Device2.PresenceState.ONLINE : peerState ? Device2.PresenceState.ONLINE : Device2.PresenceState.OFFLINE
5008
- };
5009
- })
5010
- });
5011
- }
5012
- };
5013
- let identitySubscribed = false;
5014
- let presenceSubscribed = false;
5015
- const subscribeIdentity = () => {
5016
- if (!identitySubscribed) {
5017
- this._identityManager.identity?.stateUpdate.on(() => {
5018
- update();
5019
- });
5020
- identitySubscribed = true;
5021
- }
5022
- };
5023
- const subscribePresence = () => {
5024
- if (!presenceSubscribed) {
5025
- this._identityManager.identity?.presence?.updated.on(() => {
5026
- update();
5027
- });
5028
- presenceSubscribed = true;
5029
- }
5030
- };
5031
- const subscriptions = new EventSubscriptions3();
5032
- if (this._identityManager.identity) {
5033
- subscribeIdentity();
5034
- subscribePresence();
5035
- }
5036
- subscriptions.add(this._identityManager.stateUpdate.on(() => {
5037
- update();
5038
- if (this._identityManager.identity) {
5039
- subscribeIdentity();
5040
- subscribePresence();
5041
- }
5042
- }));
5043
- update();
5044
- return () => subscriptions.clear();
5045
- });
5046
- }
5047
- };
5048
-
5049
5162
  // packages/sdk/client-services/src/packlets/logging/logging-service.ts
5050
5163
  import { Event as Event8 } from "@dxos/async";
5051
5164
  import { Stream as Stream12 } from "@dxos/codec-protobuf";
5052
5165
  import { PublicKey as PublicKey11 } from "@dxos/keys";
5053
- import { getContextFromEntry, log as log14 } from "@dxos/log";
5166
+ import { getContextFromEntry, log as log15 } from "@dxos/log";
5054
5167
  import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
5055
5168
  import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
5056
5169
  var LoggingServiceImpl = class {
@@ -5063,11 +5176,11 @@ var LoggingServiceImpl = class {
5063
5176
  };
5064
5177
  }
5065
5178
  async open() {
5066
- log14.runtimeConfig.processors.push(this._logProcessor);
5179
+ log15.runtimeConfig.processors.push(this._logProcessor);
5067
5180
  }
5068
5181
  async close() {
5069
- const index = log14.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
5070
- log14.runtimeConfig.processors.splice(index, 1);
5182
+ const index = log15.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
5183
+ log15.runtimeConfig.processors.splice(index, 1);
5071
5184
  }
5072
5185
  async controlMetrics({ reset, record }) {
5073
5186
  if (reset) {
@@ -5152,12 +5265,12 @@ var LoggingServiceImpl = class {
5152
5265
  });
5153
5266
  }
5154
5267
  };
5155
- var matchFilter = (filter, level, path, options) => {
5268
+ var matchFilter = (filter, level, path2, options) => {
5156
5269
  switch (options) {
5157
5270
  case QueryLogsRequest.MatchingOptions.INCLUSIVE:
5158
- return level >= filter.level && (!filter.pattern || path.includes(filter.pattern));
5271
+ return level >= filter.level && (!filter.pattern || path2.includes(filter.pattern));
5159
5272
  case QueryLogsRequest.MatchingOptions.EXPLICIT:
5160
- return level === filter.level && (!filter.pattern || path.includes(filter.pattern));
5273
+ return level === filter.level && (!filter.pattern || path2.includes(filter.pattern));
5161
5274
  }
5162
5275
  };
5163
5276
  var shouldLog = (entry2, request) => {
@@ -5203,6 +5316,80 @@ var NetworkServiceImpl = class {
5203
5316
  }
5204
5317
  };
5205
5318
 
5319
+ // packages/sdk/client-services/src/packlets/storage/storage.ts
5320
+ import { InvalidConfigError } from "@dxos/protocols";
5321
+ import { Runtime as Runtime2 } from "@dxos/protocols/proto/dxos/config";
5322
+ import { createStorage, StorageType } from "@dxos/random-access-storage";
5323
+
5324
+ // packages/sdk/client-services/src/packlets/storage/util.ts
5325
+ import { DX_DATA } from "@dxos/client-protocol";
5326
+ import { Runtime } from "@dxos/protocols/proto/dxos/config";
5327
+ import { isNode as isNode2 } from "@dxos/util";
5328
+ var getRootPath = (config) => {
5329
+ const { dataRoot = isNode2() ? DX_DATA : "dxos/storage" } = config ?? {};
5330
+ return `${dataRoot}/`;
5331
+ };
5332
+ var isPersistent = (config) => {
5333
+ const { persistent = false } = config ?? {};
5334
+ return config.dataStore !== void 0 && config.dataStore !== Runtime.Client.Storage.StorageDriver.RAM || persistent;
5335
+ };
5336
+
5337
+ // packages/sdk/client-services/src/packlets/storage/storage.ts
5338
+ var StorageDriver = Runtime2.Client.Storage.StorageDriver;
5339
+ var createStorageObjects = (config) => {
5340
+ const { persistent = false, keyStore, dataStore } = config ?? {};
5341
+ if (persistent && dataStore === StorageDriver.RAM) {
5342
+ throw new InvalidConfigError("RAM storage cannot be used in persistent mode.");
5343
+ }
5344
+ if (!persistent && dataStore !== void 0 && dataStore !== StorageDriver.RAM) {
5345
+ throw new InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
5346
+ }
5347
+ if (persistent && keyStore === StorageDriver.RAM) {
5348
+ throw new InvalidConfigError("RAM key storage cannot be used in persistent mode.");
5349
+ }
5350
+ if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== void 0) {
5351
+ throw new InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
5352
+ }
5353
+ return {
5354
+ storage: createStorage({
5355
+ type: persistent ? toStorageType(dataStore) : StorageType.RAM,
5356
+ root: getRootPath(config)
5357
+ })
5358
+ };
5359
+ };
5360
+ var toStorageType = (type) => {
5361
+ switch (type) {
5362
+ case void 0:
5363
+ return void 0;
5364
+ case StorageDriver.RAM:
5365
+ return StorageType.RAM;
5366
+ case StorageDriver.CHROME:
5367
+ return StorageType.CHROME;
5368
+ case StorageDriver.FIREFOX:
5369
+ return StorageType.FIREFOX;
5370
+ case StorageDriver.IDB:
5371
+ return StorageType.IDB;
5372
+ case StorageDriver.NODE:
5373
+ return StorageType.NODE;
5374
+ case StorageDriver.WEBFS:
5375
+ return StorageType.WEBFS;
5376
+ default:
5377
+ throw new Error(`Invalid storage type: ${StorageDriver[type]}`);
5378
+ }
5379
+ };
5380
+
5381
+ // packages/sdk/client-services/src/packlets/storage/level.ts
5382
+ import { Level } from "level";
5383
+ import path from "@dxos/node-std/path";
5384
+ import { PublicKey as PublicKey12 } from "@dxos/keys";
5385
+ var createLevel = async (config) => {
5386
+ const persistent = isPersistent(config);
5387
+ const storagePath = persistent ? path.join(getRootPath(config), "level") : `/tmp/dxos-${PublicKey12.random().toHex()}`;
5388
+ const level = new Level(storagePath);
5389
+ await level.open();
5390
+ return level;
5391
+ };
5392
+
5206
5393
  // packages/sdk/client-services/src/packlets/system/system-service.ts
5207
5394
  import { Stream as Stream14 } from "@dxos/codec-protobuf";
5208
5395
  import { GetDiagnosticsRequest } from "@dxos/protocols/proto/dxos/client/services";
@@ -5271,13 +5458,14 @@ function _ts_decorate8(decorators, target, key, desc) {
5271
5458
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5272
5459
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5273
5460
  }
5274
- var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
5461
+ var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
5275
5462
  var ClientServicesHost = class {
5276
5463
  constructor({
5277
5464
  config,
5278
5465
  transportFactory,
5279
5466
  signalManager,
5280
5467
  storage,
5468
+ level,
5281
5469
  // TODO(wittjosiah): Turn this on by default.
5282
5470
  lockKey,
5283
5471
  callbacks,
@@ -5288,6 +5476,7 @@ var ClientServicesHost = class {
5288
5476
  this._opening = false;
5289
5477
  this._open = false;
5290
5478
  this._storage = storage;
5479
+ this._level = level;
5291
5480
  this._callbacks = callbacks;
5292
5481
  this._runtimeParams = runtimeParams;
5293
5482
  if (config) {
@@ -5326,6 +5515,7 @@ var ClientServicesHost = class {
5326
5515
  await this.reset();
5327
5516
  }
5328
5517
  });
5518
+ this.diagnosticsBroadcastHandler = createCollectDiagnosticsBroadcastHandler(this._systemService);
5329
5519
  this._loggingService = new LoggingServiceImpl();
5330
5520
  this._serviceRegistry = new ServiceRegistry(clientServiceBundle, {
5331
5521
  SystemService: this._systemService,
@@ -5357,24 +5547,24 @@ var ClientServicesHost = class {
5357
5547
  */
5358
5548
  initialize({ config, ...options }) {
5359
5549
  invariant16(!this._open, "service host is open", {
5360
- F: __dxlog_file18,
5361
- L: 179,
5550
+ F: __dxlog_file19,
5551
+ L: 197,
5362
5552
  S: this,
5363
5553
  A: [
5364
5554
  "!this._open",
5365
5555
  "'service host is open'"
5366
5556
  ]
5367
5557
  });
5368
- log15("initializing...", void 0, {
5369
- F: __dxlog_file18,
5370
- L: 180,
5558
+ log16("initializing...", void 0, {
5559
+ F: __dxlog_file19,
5560
+ L: 198,
5371
5561
  S: this,
5372
5562
  C: (f, a) => f(...a)
5373
5563
  });
5374
5564
  if (config) {
5375
5565
  invariant16(!this._config, "config already set", {
5376
- F: __dxlog_file18,
5377
- L: 183,
5566
+ F: __dxlog_file19,
5567
+ L: 201,
5378
5568
  S: this,
5379
5569
  A: [
5380
5570
  "!this._config",
@@ -5387,9 +5577,9 @@ var ClientServicesHost = class {
5387
5577
  }
5388
5578
  }
5389
5579
  if (!options.signalManager) {
5390
- log15.warn("running signaling without telemetry metadata.", void 0, {
5391
- F: __dxlog_file18,
5392
- L: 191,
5580
+ log16.warn("running signaling without telemetry metadata.", void 0, {
5581
+ F: __dxlog_file19,
5582
+ L: 209,
5393
5583
  S: this,
5394
5584
  C: (f, a) => f(...a)
5395
5585
  });
@@ -5399,8 +5589,8 @@ var ClientServicesHost = class {
5399
5589
  }), signalManager = new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
5400
5590
  this._signalManager = signalManager;
5401
5591
  invariant16(!this._networkManager, "network manager already set", {
5402
- F: __dxlog_file18,
5403
- L: 202,
5592
+ F: __dxlog_file19,
5593
+ L: 220,
5404
5594
  S: this,
5405
5595
  A: [
5406
5596
  "!this._networkManager",
@@ -5412,9 +5602,9 @@ var ClientServicesHost = class {
5412
5602
  transportFactory,
5413
5603
  signalManager
5414
5604
  });
5415
- log15("initialized", void 0, {
5416
- F: __dxlog_file18,
5417
- L: 209,
5605
+ log16("initialized", void 0, {
5606
+ F: __dxlog_file19,
5607
+ L: 227,
5418
5608
  S: this,
5419
5609
  C: (f, a) => f(...a)
5420
5610
  });
@@ -5423,18 +5613,18 @@ var ClientServicesHost = class {
5423
5613
  if (this._open) {
5424
5614
  return;
5425
5615
  }
5426
- const traceId = PublicKey12.random().toHex();
5427
- log15.trace("dxos.client-services.host.open", trace9.begin({
5616
+ const traceId = PublicKey13.random().toHex();
5617
+ log16.trace("dxos.client-services.host.open", trace9.begin({
5428
5618
  id: traceId
5429
5619
  }), {
5430
- F: __dxlog_file18,
5431
- L: 220,
5620
+ F: __dxlog_file19,
5621
+ L: 238,
5432
5622
  S: this,
5433
5623
  C: (f, a) => f(...a)
5434
5624
  });
5435
5625
  invariant16(this._config, "config not set", {
5436
- F: __dxlog_file18,
5437
- L: 222,
5626
+ F: __dxlog_file19,
5627
+ L: 240,
5438
5628
  S: this,
5439
5629
  A: [
5440
5630
  "this._config",
@@ -5442,8 +5632,8 @@ var ClientServicesHost = class {
5442
5632
  ]
5443
5633
  });
5444
5634
  invariant16(this._storage, "storage not set", {
5445
- F: __dxlog_file18,
5446
- L: 223,
5635
+ F: __dxlog_file19,
5636
+ L: 241,
5447
5637
  S: this,
5448
5638
  A: [
5449
5639
  "this._storage",
@@ -5451,8 +5641,8 @@ var ClientServicesHost = class {
5451
5641
  ]
5452
5642
  });
5453
5643
  invariant16(this._signalManager, "signal manager not set", {
5454
- F: __dxlog_file18,
5455
- L: 224,
5644
+ F: __dxlog_file19,
5645
+ L: 242,
5456
5646
  S: this,
5457
5647
  A: [
5458
5648
  "this._signalManager",
@@ -5460,8 +5650,8 @@ var ClientServicesHost = class {
5460
5650
  ]
5461
5651
  });
5462
5652
  invariant16(this._networkManager, "network manager not set", {
5463
- F: __dxlog_file18,
5464
- L: 225,
5653
+ F: __dxlog_file19,
5654
+ L: 243,
5465
5655
  S: this,
5466
5656
  A: [
5467
5657
  "this._networkManager",
@@ -5469,17 +5659,21 @@ var ClientServicesHost = class {
5469
5659
  ]
5470
5660
  });
5471
5661
  this._opening = true;
5472
- log15("opening...", {
5662
+ log16("opening...", {
5473
5663
  lockKey: this._resourceLock?.lockKey
5474
5664
  }, {
5475
- F: __dxlog_file18,
5476
- L: 228,
5665
+ F: __dxlog_file19,
5666
+ L: 246,
5477
5667
  S: this,
5478
5668
  C: (f, a) => f(...a)
5479
5669
  });
5670
+ if (!this._level) {
5671
+ this._level = await createLevel(this._config.get("runtime.client.storage", {}));
5672
+ }
5673
+ await this._level.open();
5480
5674
  await this._resourceLock?.acquire();
5481
5675
  await this._loggingService.open();
5482
- this._serviceContext = new ServiceContext(this._storage, this._networkManager, this._signalManager, this._runtimeParams);
5676
+ this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._runtimeParams);
5483
5677
  this._serviceRegistry.setServices({
5484
5678
  SystemService: this._systemService,
5485
5679
  IdentityService: new IdentityServiceImpl((params) => this._createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring, (profile) => this._serviceContext.broadcastProfileUpdate(profile)),
@@ -5506,8 +5700,8 @@ var ClientServicesHost = class {
5506
5700
  });
5507
5701
  await this._serviceContext.open(ctx);
5508
5702
  invariant16(this.serviceRegistry.services.InvitationsService, void 0, {
5509
- F: __dxlog_file18,
5510
- L: 289,
5703
+ F: __dxlog_file19,
5704
+ L: 314,
5511
5705
  S: this,
5512
5706
  A: [
5513
5707
  "this.serviceRegistry.services.InvitationsService",
@@ -5515,11 +5709,11 @@ var ClientServicesHost = class {
5515
5709
  ]
5516
5710
  });
5517
5711
  const loadedInvitations = await this.serviceRegistry.services.InvitationsService.loadPersistentInvitations();
5518
- log15("loaded persistent invitations", {
5712
+ log16("loaded persistent invitations", {
5519
5713
  count: loadedInvitations.invitations?.length
5520
5714
  }, {
5521
- F: __dxlog_file18,
5522
- L: 292,
5715
+ F: __dxlog_file19,
5716
+ L: 317,
5523
5717
  S: this,
5524
5718
  C: (f, a) => f(...a)
5525
5719
  });
@@ -5533,23 +5727,24 @@ var ClientServicesHost = class {
5533
5727
  });
5534
5728
  void this._devtoolsProxy.open();
5535
5729
  }
5730
+ this.diagnosticsBroadcastHandler.start();
5536
5731
  this._opening = false;
5537
5732
  this._open = true;
5538
5733
  this._statusUpdate.emit();
5539
5734
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
5540
- log15("opened", {
5735
+ log16("opened", {
5541
5736
  deviceKey
5542
5737
  }, {
5543
- F: __dxlog_file18,
5544
- L: 309,
5738
+ F: __dxlog_file19,
5739
+ L: 335,
5545
5740
  S: this,
5546
5741
  C: (f, a) => f(...a)
5547
5742
  });
5548
- log15.trace("dxos.client-services.host.open", trace9.end({
5743
+ log16.trace("dxos.client-services.host.open", trace9.end({
5549
5744
  id: traceId
5550
5745
  }), {
5551
- F: __dxlog_file18,
5552
- L: 310,
5746
+ F: __dxlog_file19,
5747
+ L: 336,
5553
5748
  S: this,
5554
5749
  C: (f, a) => f(...a)
5555
5750
  });
@@ -5559,60 +5754,62 @@ var ClientServicesHost = class {
5559
5754
  return;
5560
5755
  }
5561
5756
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
5562
- log15("closing...", {
5757
+ log16("closing...", {
5563
5758
  deviceKey
5564
5759
  }, {
5565
- F: __dxlog_file18,
5566
- L: 321,
5760
+ F: __dxlog_file19,
5761
+ L: 347,
5567
5762
  S: this,
5568
5763
  C: (f, a) => f(...a)
5569
5764
  });
5765
+ this.diagnosticsBroadcastHandler.stop();
5570
5766
  await this._devtoolsProxy?.close();
5571
5767
  this._serviceRegistry.setServices({
5572
5768
  SystemService: this._systemService
5573
5769
  });
5574
5770
  await this._loggingService.close();
5575
5771
  await this._serviceContext.close();
5772
+ await this._level?.close();
5576
5773
  this._open = false;
5577
5774
  this._statusUpdate.emit();
5578
- log15("closed", {
5775
+ log16("closed", {
5579
5776
  deviceKey
5580
5777
  }, {
5581
- F: __dxlog_file18,
5582
- L: 328,
5778
+ F: __dxlog_file19,
5779
+ L: 356,
5583
5780
  S: this,
5584
5781
  C: (f, a) => f(...a)
5585
5782
  });
5586
5783
  }
5587
5784
  async reset() {
5588
- const traceId = PublicKey12.random().toHex();
5589
- log15.trace("dxos.sdk.client-services-host.reset", trace9.begin({
5785
+ const traceId = PublicKey13.random().toHex();
5786
+ log16.trace("dxos.sdk.client-services-host.reset", trace9.begin({
5590
5787
  id: traceId
5591
5788
  }), {
5592
- F: __dxlog_file18,
5593
- L: 333,
5789
+ F: __dxlog_file19,
5790
+ L: 361,
5594
5791
  S: this,
5595
5792
  C: (f, a) => f(...a)
5596
5793
  });
5597
- log15("resetting...", void 0, {
5598
- F: __dxlog_file18,
5599
- L: 335,
5794
+ log16("resetting...", void 0, {
5795
+ F: __dxlog_file19,
5796
+ L: 363,
5600
5797
  S: this,
5601
5798
  C: (f, a) => f(...a)
5602
5799
  });
5603
5800
  await this._serviceContext?.close();
5604
5801
  await this._storage.reset();
5605
- log15("reset", void 0, {
5606
- F: __dxlog_file18,
5607
- L: 338,
5802
+ log16("reset", void 0, {
5803
+ F: __dxlog_file19,
5804
+ L: 366,
5608
5805
  S: this,
5609
5806
  C: (f, a) => f(...a)
5610
5807
  });
5611
- log15.trace("dxos.sdk.client-services-host.reset", trace9.end({
5808
+ log16.trace("dxos.sdk.client-services-host.reset", trace9.end({
5612
5809
  id: traceId
5613
5810
  }), {
5614
- F: __dxlog_file18,
5615
- L: 339,
5811
+ F: __dxlog_file19,
5812
+ L: 367,
5616
5813
  S: this,
5617
5814
  C: (f, a) => f(...a)
5618
5815
  });
@@ -5622,12 +5819,10 @@ var ClientServicesHost = class {
5622
5819
  const identity = await this._serviceContext.createIdentity(params);
5623
5820
  await this._serviceContext.initialized.wait();
5624
5821
  const space = await this._serviceContext.dataSpaceManager.createSpace();
5625
- const obj = new Properties(void 0);
5626
- obj[defaultKey] = identity.identityKey.toHex();
5627
5822
  const automergeIndex = space.automergeSpaceState.rootUrl;
5628
5823
  invariant16(automergeIndex, void 0, {
5629
- F: __dxlog_file18,
5630
- L: 354,
5824
+ F: __dxlog_file19,
5825
+ L: 379,
5631
5826
  S: this,
5632
5827
  A: [
5633
5828
  "automergeIndex",
@@ -5636,12 +5831,25 @@ var ClientServicesHost = class {
5636
5831
  });
5637
5832
  const document = await this._serviceContext.automergeHost.repo.find(automergeIndex);
5638
5833
  await document.whenReady();
5834
+ const properties = {
5835
+ system: {
5836
+ type: encodeReference(E.getTypeReference(Properties))
5837
+ },
5838
+ data: {
5839
+ [defaultKey]: identity.identityKey.toHex()
5840
+ },
5841
+ meta: {
5842
+ keys: []
5843
+ }
5844
+ };
5845
+ const propertiesId = PublicKey13.random().toHex();
5639
5846
  document.change((doc) => {
5640
5847
  assignDeep2(doc, [
5641
5848
  "objects",
5642
- getAutomergeObjectCore(obj).id
5643
- ], getRawDoc(obj).handle.docSync());
5849
+ propertiesId
5850
+ ], properties);
5644
5851
  });
5852
+ await this._serviceContext.automergeHost.repo.flush();
5645
5853
  return identity;
5646
5854
  }
5647
5855
  };
@@ -5663,6 +5871,44 @@ ClientServicesHost = _ts_decorate8([
5663
5871
  Trace3.resource()
5664
5872
  ], ClientServicesHost);
5665
5873
 
5874
+ // packages/sdk/client-services/src/packlets/services/util.ts
5875
+ import { PublicKey as PublicKey14 } from "@dxos/keys";
5876
+ import { humanize } from "@dxos/util";
5877
+ var ClientServicesProviderResource = Symbol.for("dxos.resource.ClientServices");
5878
+
5879
+ // packages/sdk/client-services/src/packlets/diagnostics/diagnostics-collector.ts
5880
+ var DiagnosticsCollector = class {
5881
+ static {
5882
+ this.broadcastSender = createCollectDiagnosticsBroadcastSender();
5883
+ }
5884
+ static async collect(config = findConfigs(), services = findSystemServiceProvider(), options = {}) {
5885
+ const serviceDiagnostics = await services?.services?.SystemService?.getDiagnostics({
5886
+ keys: options.humanize ? GetDiagnosticsRequest2.KEY_OPTION.HUMANIZE : options.truncate ? GetDiagnosticsRequest2.KEY_OPTION.TRUNCATE : void 0
5887
+ });
5888
+ const clientDiagnostics = {
5889
+ config,
5890
+ trace: TRACE_PROCESSOR3.getDiagnostics()
5891
+ };
5892
+ const diagnostics = serviceDiagnostics != null ? {
5893
+ client: clientDiagnostics,
5894
+ services: serviceDiagnostics
5895
+ } : {
5896
+ client: clientDiagnostics,
5897
+ broadcast: await this.broadcastSender.broadcastDiagnosticsRequest()
5898
+ };
5899
+ return JSON.parse(JSON.stringify(diagnostics, jsonKeyReplacer2(options)));
5900
+ }
5901
+ };
5902
+ var findSystemServiceProvider = () => {
5903
+ const serviceProviders = TRACE_PROCESSOR3.findByAnnotation(ClientServicesProviderResource);
5904
+ const providerResource = serviceProviders.find((r) => r.instance.deref()?.services?.SystemService != null);
5905
+ return providerResource?.instance?.deref() ?? null;
5906
+ };
5907
+ var findConfigs = () => {
5908
+ const configs = TRACE_PROCESSOR3.findByAnnotation(ConfigResource);
5909
+ return configs.map((r) => r.instance.deref()).filter(nonNullable);
5910
+ };
5911
+
5666
5912
  export {
5667
5913
  Buffer,
5668
5914
  subscribeToFeeds,
@@ -5682,19 +5928,24 @@ export {
5682
5928
  IdentityServiceImpl,
5683
5929
  DeviceInvitationProtocol,
5684
5930
  InvitationsHandler,
5685
- invitationExpired,
5931
+ createAdmissionKeypair,
5686
5932
  InvitationsServiceImpl,
5687
5933
  SpaceInvitationProtocol,
5688
5934
  ClientRpcServer,
5689
- createDiagnostics,
5690
5935
  DataSpace,
5691
5936
  DataSpaceManager,
5692
5937
  SpacesServiceImpl,
5693
5938
  ServiceContext,
5694
5939
  ServiceRegistry,
5940
+ createDiagnostics,
5941
+ createCollectDiagnosticsBroadcastSender,
5942
+ createCollectDiagnosticsBroadcastHandler,
5943
+ DiagnosticsCollector,
5695
5944
  Lock,
5696
5945
  isLocked,
5697
5946
  createStorageObjects,
5698
- ClientServicesHost
5947
+ createLevel,
5948
+ ClientServicesHost,
5949
+ ClientServicesProviderResource
5699
5950
  };
5700
- //# sourceMappingURL=chunk-FPOYSPWD.mjs.map
5951
+ //# sourceMappingURL=chunk-LGZBUJLB.mjs.map