@dxos/client-services 0.8.4-main.e098934 → 0.8.4-main.e8ec1fe

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 (33) hide show
  1. package/dist/lib/browser/{chunk-4MWNQXYP.mjs → chunk-CZSLDMSL.mjs} +796 -1142
  2. package/dist/lib/browser/chunk-CZSLDMSL.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +110 -135
  4. package/dist/lib/browser/index.mjs.map +2 -2
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/testing/index.mjs +37 -66
  7. package/dist/lib/browser/testing/index.mjs.map +2 -2
  8. package/dist/lib/node-esm/{chunk-CYXIPDHC.mjs → chunk-EUNILIU5.mjs} +796 -1142
  9. package/dist/lib/node-esm/chunk-EUNILIU5.mjs.map +7 -0
  10. package/dist/lib/node-esm/index.mjs +110 -135
  11. package/dist/lib/node-esm/index.mjs.map +2 -2
  12. package/dist/lib/node-esm/meta.json +1 -1
  13. package/dist/lib/node-esm/testing/index.mjs +37 -66
  14. package/dist/lib/node-esm/testing/index.mjs.map +2 -2
  15. package/dist/types/src/packlets/agents/edge-agent-service.d.ts.map +1 -1
  16. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  17. package/dist/types/src/packlets/space-export/space-archive-writer.d.ts.map +1 -1
  18. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  19. package/dist/types/src/version.d.ts +1 -1
  20. package/dist/types/tsconfig.tsbuildinfo +1 -1
  21. package/package.json +39 -39
  22. package/src/packlets/agents/edge-agent-service.ts +11 -1
  23. package/src/packlets/devices/devices-service.ts +1 -1
  24. package/src/packlets/identity/identity.test.ts +4 -4
  25. package/src/packlets/logging/logging-service.ts +1 -1
  26. package/src/packlets/services/service-host.ts +6 -0
  27. package/src/packlets/space-export/space-archive-writer.ts +2 -1
  28. package/src/packlets/spaces/data-space-manager.ts +14 -2
  29. package/src/packlets/spaces/edge-feed-replicator.test.ts +1 -1
  30. package/src/packlets/spaces/edge-feed-replicator.ts +1 -1
  31. package/src/version.ts +1 -1
  32. package/dist/lib/browser/chunk-4MWNQXYP.mjs.map +0 -7
  33. package/dist/lib/node-esm/chunk-CYXIPDHC.mjs.map +0 -7
@@ -274,25 +274,14 @@ var subscribeToMetadata = ({ context }) => new Stream5(({ next, ctx }) => {
274
274
  });
275
275
 
276
276
  // src/packlets/devtools/devtools.ts
277
- function _define_property(obj, key, value) {
278
- if (key in obj) {
279
- Object.defineProperty(obj, key, {
280
- value,
281
- enumerable: true,
282
- configurable: true,
283
- writable: true
284
- });
285
- } else {
286
- obj[key] = value;
287
- }
288
- return obj;
289
- }
290
277
  var DevtoolsHostEvents = class {
291
- constructor() {
292
- _define_property(this, "ready", new AsyncEvent());
293
- }
278
+ ready = new AsyncEvent();
294
279
  };
295
280
  var DevtoolsServiceImpl = class {
281
+ params;
282
+ constructor(params) {
283
+ this.params = params;
284
+ }
296
285
  events(_request) {
297
286
  return new Stream6(({ next }) => {
298
287
  this.params.events.ready.on(() => {
@@ -395,10 +384,6 @@ var DevtoolsServiceImpl = class {
395
384
  context: this.params.context
396
385
  });
397
386
  }
398
- constructor(params) {
399
- _define_property(this, "params", void 0);
400
- this.params = params;
401
- }
402
387
  };
403
388
 
404
389
  // src/packlets/diagnostics/diagnostics.ts
@@ -411,7 +396,7 @@ import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
411
396
  import { TRACE_PROCESSOR } from "@dxos/tracing";
412
397
 
413
398
  // src/version.ts
414
- var DXOS_VERSION = "0.8.4-main.e098934";
399
+ var DXOS_VERSION = "0.8.4-main.e8ec1fe";
415
400
 
416
401
  // src/packlets/services/platform.ts
417
402
  import { Platform } from "@dxos/protocols/proto/dxos/client/services";
@@ -657,21 +642,9 @@ import { ConfigResource } from "@dxos/config";
657
642
  import { GetDiagnosticsRequest } from "@dxos/protocols/proto/dxos/client/services";
658
643
  import { TRACE_PROCESSOR as TRACE_PROCESSOR2 } from "@dxos/tracing";
659
644
  import { isNonNullable, jsonKeyReplacer } from "@dxos/util";
660
- function _define_property2(obj, key, value) {
661
- if (key in obj) {
662
- Object.defineProperty(obj, key, {
663
- value,
664
- enumerable: true,
665
- configurable: true,
666
- writable: true
667
- });
668
- } else {
669
- obj[key] = value;
670
- }
671
- return obj;
672
- }
673
645
  var GET_DIAGNOSTICS_RPC_TIMEOUT = 1e4;
674
646
  var DiagnosticsCollector = class {
647
+ static broadcastSender = createCollectDiagnosticsBroadcastSender();
675
648
  static async collect(config = findConfigs(), services = findSystemServiceProvider(), options = {}) {
676
649
  const serviceDiagnostics = await services?.services?.SystemService?.getDiagnostics({
677
650
  keys: options.humanize ? GetDiagnosticsRequest.KEY_OPTION.HUMANIZE : options.truncate ? GetDiagnosticsRequest.KEY_OPTION.TRUNCATE : void 0
@@ -692,7 +665,6 @@ var DiagnosticsCollector = class {
692
665
  return JSON.parse(JSON.stringify(diagnostics, jsonKeyReplacer(options)));
693
666
  }
694
667
  };
695
- _define_property2(DiagnosticsCollector, "broadcastSender", createCollectDiagnosticsBroadcastSender());
696
668
  var findSystemServiceProvider = () => {
697
669
  const serviceProviders = TRACE_PROCESSOR2.findResourcesByAnnotation(ClientServicesProviderResource);
698
670
  const providerResource = serviceProviders.find((r) => r.instance.deref()?.services?.SystemService != null);
@@ -709,19 +681,6 @@ import { Context as Context2 } from "@dxos/context";
709
681
  import { verifyCredential } from "@dxos/credentials";
710
682
  import { log as log3 } from "@dxos/log";
711
683
  import { schema } from "@dxos/protocols/proto";
712
- function _define_property3(obj, key, value) {
713
- if (key in obj) {
714
- Object.defineProperty(obj, key, {
715
- value,
716
- enumerable: true,
717
- configurable: true,
718
- writable: true
719
- });
720
- } else {
721
- obj[key] = value;
722
- }
723
- return obj;
724
- }
725
684
  var __dxlog_file5 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/identity/authenticator.ts";
726
685
  var Credential = schema.getCodecForType("dxos.halo.credentials.Credential");
727
686
  var createAuthProvider = (signer) => async (nonce) => {
@@ -735,6 +694,14 @@ var createAuthProvider = (signer) => async (nonce) => {
735
694
  return Credential.encode(credential);
736
695
  };
737
696
  var TrustedKeySetAuthVerifier = class {
697
+ _params;
698
+ _ctx = new Context2(void 0, {
699
+ F: __dxlog_file5,
700
+ L: 45
701
+ });
702
+ constructor(_params) {
703
+ this._params = _params;
704
+ }
738
705
  async close() {
739
706
  await this._ctx.dispose();
740
707
  }
@@ -828,15 +795,6 @@ var TrustedKeySetAuthVerifier = class {
828
795
  const deviceSet = this._params.trustedKeysProvider();
829
796
  return deviceSet.has(deviceKey);
830
797
  }
831
- constructor(_params) {
832
- _define_property3(this, "_params", void 0);
833
- _define_property3(this, "_ctx", void 0);
834
- this._params = _params;
835
- this._ctx = new Context2(void 0, {
836
- F: __dxlog_file5,
837
- L: 45
838
- });
839
- }
840
798
  };
841
799
 
842
800
  // src/packlets/spaces/edge-feed-replicator.ts
@@ -852,19 +810,6 @@ import { buf } from "@dxos/protocols/buf";
852
810
  import { MessageSchema as RouterMessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
853
811
  import { EdgeStatus } from "@dxos/protocols/proto/dxos/client/services";
854
812
  import { ComplexMap as ComplexMap2, arrayToBuffer, bufferToArray, defaultMap, rangeFromTo } from "@dxos/util";
855
- function _define_property4(obj, key, value) {
856
- if (key in obj) {
857
- Object.defineProperty(obj, key, {
858
- value,
859
- enumerable: true,
860
- configurable: true,
861
- writable: true
862
- });
863
- } else {
864
- obj[key] = value;
865
- }
866
- return obj;
867
- }
868
813
  function _ts_decorate(decorators, target, key, desc) {
869
814
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
870
815
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -938,6 +883,24 @@ function _ts_dispose_resources(env) {
938
883
  }
939
884
  var __dxlog_file6 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/edge-feed-replicator.ts";
940
885
  var EdgeFeedReplicator = class extends Resource {
886
+ _messenger;
887
+ _spaceId;
888
+ _feeds = new ComplexMap2(PublicKey3.hash);
889
+ _connectionCtx = void 0;
890
+ _connected = false;
891
+ /**
892
+ * Feed length at service.
893
+ */
894
+ _remoteLength = new ComplexMap2(PublicKey3.hash);
895
+ /**
896
+ * Protects against concurrent pushes so that remote length is updated consistently.
897
+ */
898
+ _pushMutex = new ComplexMap2(PublicKey3.hash);
899
+ constructor({ messenger, spaceId }) {
900
+ super();
901
+ this._messenger = messenger;
902
+ this._spaceId = spaceId;
903
+ }
941
904
  async _open() {
942
905
  log4("open", void 0, {
943
906
  F: __dxlog_file6,
@@ -985,7 +948,7 @@ var EdgeFeedReplicator = class extends Resource {
985
948
  }
986
949
  async _handleReconnect() {
987
950
  await this._resetConnection();
988
- if (this._messenger.status === EdgeStatus.CONNECTED) {
951
+ if (this._messenger.status.state === EdgeStatus.ConnectionState.CONNECTED) {
989
952
  this._startReplication();
990
953
  }
991
954
  }
@@ -1334,17 +1297,6 @@ var EdgeFeedReplicator = class extends Resource {
1334
1297
  });
1335
1298
  return connectionCtx;
1336
1299
  }
1337
- constructor({ messenger, spaceId }) {
1338
- super(), _define_property4(this, "_messenger", void 0), _define_property4(this, "_spaceId", void 0), _define_property4(this, "_feeds", new ComplexMap2(PublicKey3.hash)), _define_property4(this, "_connectionCtx", void 0), _define_property4(this, "_connected", false), /**
1339
- * Feed length at service.
1340
- */
1341
- _define_property4(this, "_remoteLength", new ComplexMap2(PublicKey3.hash)), /**
1342
- * Protects against concurrent pushes so that remote length is updated consistently.
1343
- */
1344
- _define_property4(this, "_pushMutex", new ComplexMap2(PublicKey3.hash));
1345
- this._messenger = messenger;
1346
- this._spaceId = spaceId;
1347
- }
1348
1300
  };
1349
1301
  _ts_decorate([
1350
1302
  logInfo
@@ -1397,9 +1349,9 @@ import { Event as Event2, synchronized, trackLeaks } from "@dxos/async";
1397
1349
  import { PropertiesType, TYPE_PROPERTIES } from "@dxos/client-protocol";
1398
1350
  import { Context as Context4, LifecycleState, Resource as Resource2, cancelWithContext } from "@dxos/context";
1399
1351
  import { createAdmissionCredentials, getCredentialAssertion } from "@dxos/credentials";
1352
+ import { ObjectId, getTypeReference } from "@dxos/echo/internal";
1400
1353
  import { AuthStatus, CredentialServerExtension, DatabaseRoot, FIND_PARAMS, findInlineObjectOfType } from "@dxos/echo-pipeline";
1401
1354
  import { SpaceDocVersion, createIdFromSpaceKey, encodeReference } from "@dxos/echo-protocol";
1402
- import { ObjectId, getTypeReference } from "@dxos/echo-schema";
1403
1355
  import { writeMessages } from "@dxos/feed-store";
1404
1356
  import { assertArgument, assertState, failedInvariant, invariant as invariant3 } from "@dxos/invariant";
1405
1357
  import { PublicKey as PublicKey4 } from "@dxos/keys";
@@ -1483,19 +1435,6 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
1483
1435
  };
1484
1436
 
1485
1437
  // src/packlets/spaces/data-space-manager.ts
1486
- function _define_property5(obj, key, value) {
1487
- if (key in obj) {
1488
- Object.defineProperty(obj, key, {
1489
- value,
1490
- enumerable: true,
1491
- configurable: true,
1492
- writable: true
1493
- });
1494
- } else {
1495
- obj[key] = value;
1496
- }
1497
- return obj;
1498
- }
1499
1438
  function _ts_decorate2(decorators, target, key, desc) {
1500
1439
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1501
1440
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -1507,6 +1446,61 @@ var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
1507
1446
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
1508
1447
  var DEFAULT_SPACE_KEY = "__DEFAULT__";
1509
1448
  var DataSpaceManager = class extends Resource2 {
1449
+ updated = new Event2();
1450
+ _spaces = new ComplexMap3(PublicKey4.hash);
1451
+ _instanceId = PublicKey4.random().toHex();
1452
+ _spaceManager;
1453
+ _metadataStore;
1454
+ _keyring;
1455
+ _signingContext;
1456
+ _feedStore;
1457
+ _echoHost;
1458
+ _invitationsManager;
1459
+ _edgeConnection = void 0;
1460
+ _edgeHttpClient = void 0;
1461
+ _edgeFeatures = void 0;
1462
+ _meshReplicator = void 0;
1463
+ _echoEdgeReplicator = void 0;
1464
+ _runtimeParams = void 0;
1465
+ constructor(params) {
1466
+ super();
1467
+ this._spaceManager = params.spaceManager;
1468
+ this._metadataStore = params.metadataStore;
1469
+ this._keyring = params.keyring;
1470
+ this._signingContext = params.signingContext;
1471
+ this._feedStore = params.feedStore;
1472
+ this._echoHost = params.echoHost;
1473
+ this._meshReplicator = params.meshReplicator;
1474
+ this._invitationsManager = params.invitationsManager;
1475
+ this._edgeConnection = params.edgeConnection;
1476
+ this._edgeFeatures = params.edgeFeatures;
1477
+ this._echoEdgeReplicator = params.echoEdgeReplicator;
1478
+ this._edgeHttpClient = params.edgeHttpClient;
1479
+ this._runtimeParams = params.runtimeParams;
1480
+ trace.diagnostic({
1481
+ id: "spaces",
1482
+ name: "Spaces",
1483
+ fetch: async () => {
1484
+ return Promise.all(Array.from(this._spaces.values()).map(async (space) => {
1485
+ const rootUrl = space.automergeSpaceState.rootUrl;
1486
+ const rootHandle = rootUrl ? await this._echoHost.automergeRepo.find(rootUrl, FIND_PARAMS) : void 0;
1487
+ await rootHandle?.whenReady();
1488
+ const rootDoc = rootHandle?.doc();
1489
+ const properties = rootDoc && findInlineObjectOfType(rootDoc, TYPE_PROPERTIES);
1490
+ return {
1491
+ key: space.key.toHex(),
1492
+ state: SpaceState[space.state],
1493
+ name: properties?.[1].data.name ?? null,
1494
+ inlineObjects: rootDoc ? Object.keys(rootDoc.objects ?? {}).length : null,
1495
+ linkedObjects: rootDoc ? Object.keys(rootDoc.links ?? {}).length : null,
1496
+ credentials: space.inner.spaceState.credentials.length,
1497
+ members: space.inner.spaceState.members.size,
1498
+ rootUrl
1499
+ };
1500
+ }));
1501
+ }
1502
+ });
1503
+ }
1510
1504
  // TODO(burdon): Remove.
1511
1505
  get spaces() {
1512
1506
  return this._spaces;
@@ -1633,6 +1627,11 @@ var DataSpaceManager = class extends Resource2 {
1633
1627
  const newDoc = await this._echoHost.createDoc(data, {
1634
1628
  preserveHistory: true
1635
1629
  });
1630
+ if (newDoc.doc().access !== void 0 && newDoc.doc().access.spaceKey !== spaceKey.toHex()) {
1631
+ newDoc.change((doc) => {
1632
+ doc.access.spaceKey = spaceKey.toHex();
1633
+ });
1634
+ }
1636
1635
  documentIdMapping[documentId] = newDoc.documentId;
1637
1636
  }));
1638
1637
  }
@@ -1640,7 +1639,7 @@ var DataSpaceManager = class extends Resource2 {
1640
1639
  spaceKey
1641
1640
  }, {
1642
1641
  F: __dxlog_file7,
1643
- L: 288,
1642
+ L: 299,
1644
1643
  S: this,
1645
1644
  C: (f, a) => f(...a)
1646
1645
  });
@@ -1649,18 +1648,19 @@ var DataSpaceManager = class extends Resource2 {
1649
1648
  const newRootDocId = documentIdMapping[interpretAsDocumentId(options.rootUrl)] ?? failedInvariant();
1650
1649
  const rootDocHandle = await this._echoHost.loadDoc(Context4.default(void 0, {
1651
1650
  F: __dxlog_file7,
1652
- L: 293
1651
+ L: 304
1653
1652
  }), newRootDocId);
1654
1653
  DatabaseRoot.mapLinks(rootDocHandle, documentIdMapping);
1655
1654
  root = await this._echoHost.openSpaceRoot(spaceId, `automerge:${newRootDocId}`);
1656
1655
  } else {
1657
1656
  root = await this._echoHost.createSpaceRoot(spaceKey);
1658
1657
  }
1658
+ await this._echoHost.flush();
1659
1659
  log5("constructing space...", {
1660
1660
  spaceKey
1661
1661
  }, {
1662
1662
  F: __dxlog_file7,
1663
- L: 301,
1663
+ L: 313,
1664
1664
  S: this,
1665
1665
  C: (f, a) => f(...a)
1666
1666
  });
@@ -1670,7 +1670,7 @@ var DataSpaceManager = class extends Resource2 {
1670
1670
  spaceKey
1671
1671
  }, {
1672
1672
  F: __dxlog_file7,
1673
- L: 306,
1673
+ L: 318,
1674
1674
  S: this,
1675
1675
  C: (f, a) => f(...a)
1676
1676
  });
@@ -1679,7 +1679,7 @@ var DataSpaceManager = class extends Resource2 {
1679
1679
  const memberCredential = credentials[1];
1680
1680
  invariant3(getCredentialAssertion(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
1681
1681
  F: __dxlog_file7,
1682
- L: 312,
1682
+ L: 324,
1683
1683
  S: this,
1684
1684
  A: [
1685
1685
  "getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -1693,7 +1693,7 @@ var DataSpaceManager = class extends Resource2 {
1693
1693
  spaceKey
1694
1694
  }, {
1695
1695
  F: __dxlog_file7,
1696
- L: 317,
1696
+ L: 329,
1697
1697
  S: this,
1698
1698
  C: (f, a) => f(...a)
1699
1699
  });
@@ -1711,7 +1711,7 @@ var DataSpaceManager = class extends Resource2 {
1711
1711
  spaceId: space.id
1712
1712
  }, {
1713
1713
  F: __dxlog_file7,
1714
- L: 330,
1714
+ L: 342,
1715
1715
  S: this,
1716
1716
  C: (f, a) => f(...a)
1717
1717
  });
@@ -1729,7 +1729,7 @@ var DataSpaceManager = class extends Resource2 {
1729
1729
  spaceId: space.id
1730
1730
  }, {
1731
1731
  F: __dxlog_file7,
1732
- L: 341,
1732
+ L: 353,
1733
1733
  S: this,
1734
1734
  C: (f, a) => f(...a)
1735
1735
  });
@@ -1764,7 +1764,7 @@ var DataSpaceManager = class extends Resource2 {
1764
1764
  const automergeIndex = space.automergeSpaceState.rootUrl;
1765
1765
  invariant3(automergeIndex, void 0, {
1766
1766
  F: __dxlog_file7,
1767
- L: 374,
1767
+ L: 386,
1768
1768
  S: this,
1769
1769
  A: [
1770
1770
  "automergeIndex",
@@ -1781,13 +1781,13 @@ var DataSpaceManager = class extends Resource2 {
1781
1781
  opts
1782
1782
  }, {
1783
1783
  F: __dxlog_file7,
1784
- L: 383,
1784
+ L: 395,
1785
1785
  S: this,
1786
1786
  C: (f, a) => f(...a)
1787
1787
  });
1788
1788
  invariant3(this._lifecycleState === LifecycleState.OPEN, "Not open.", {
1789
1789
  F: __dxlog_file7,
1790
- L: 384,
1790
+ L: 396,
1791
1791
  S: this,
1792
1792
  A: [
1793
1793
  "this._lifecycleState === LifecycleState.OPEN",
@@ -1796,7 +1796,7 @@ var DataSpaceManager = class extends Resource2 {
1796
1796
  });
1797
1797
  invariant3(!this._spaces.has(opts.spaceKey), "Space already exists.", {
1798
1798
  F: __dxlog_file7,
1799
- L: 385,
1799
+ L: 397,
1800
1800
  S: this,
1801
1801
  A: [
1802
1802
  "!this._spaces.has(opts.spaceKey)",
@@ -1820,7 +1820,7 @@ var DataSpaceManager = class extends Resource2 {
1820
1820
  const space = this._spaceManager.spaces.get(options.spaceKey);
1821
1821
  invariant3(space, void 0, {
1822
1822
  F: __dxlog_file7,
1823
- L: 405,
1823
+ L: 417,
1824
1824
  S: this,
1825
1825
  A: [
1826
1826
  "space",
@@ -1833,7 +1833,7 @@ var DataSpaceManager = class extends Resource2 {
1833
1833
  const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, options.identityKey, space.key, space.genesisFeedKey, options.role, space.spaceState.membershipChainHeads, options.profile, options.delegationCredentialId);
1834
1834
  invariant3(credentials[0].credential, void 0, {
1835
1835
  F: __dxlog_file7,
1836
- L: 424,
1836
+ L: 436,
1837
1837
  S: this,
1838
1838
  A: [
1839
1839
  "credentials[0].credential",
@@ -1843,7 +1843,7 @@ var DataSpaceManager = class extends Resource2 {
1843
1843
  const spaceMemberCredential = credentials[0].credential.credential;
1844
1844
  invariant3(getCredentialAssertion(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
1845
1845
  F: __dxlog_file7,
1846
- L: 426,
1846
+ L: 438,
1847
1847
  S: this,
1848
1848
  A: [
1849
1849
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -1881,7 +1881,7 @@ var DataSpaceManager = class extends Resource2 {
1881
1881
  const space = this._spaces.get(spaceKey);
1882
1882
  invariant3(space, "Space not found.", {
1883
1883
  F: __dxlog_file7,
1884
- L: 463,
1884
+ L: 475,
1885
1885
  S: this,
1886
1886
  A: [
1887
1887
  "space",
@@ -1906,7 +1906,7 @@ var DataSpaceManager = class extends Resource2 {
1906
1906
  metadata
1907
1907
  }, {
1908
1908
  F: __dxlog_file7,
1909
- L: 482,
1909
+ L: 494,
1910
1910
  S: this,
1911
1911
  C: (f, a) => f(...a)
1912
1912
  });
@@ -1950,7 +1950,7 @@ var DataSpaceManager = class extends Resource2 {
1950
1950
  err
1951
1951
  }, {
1952
1952
  F: __dxlog_file7,
1953
- L: 524,
1953
+ L: 536,
1954
1954
  S: this,
1955
1955
  C: (f, a) => f(...a)
1956
1956
  });
@@ -1960,7 +1960,7 @@ var DataSpaceManager = class extends Resource2 {
1960
1960
  onAuthFailure: () => {
1961
1961
  log5.warn("auth failure", void 0, {
1962
1962
  F: __dxlog_file7,
1963
- L: 529,
1963
+ L: 541,
1964
1964
  S: this,
1965
1965
  C: (f, a) => f(...a)
1966
1966
  });
@@ -1993,7 +1993,7 @@ var DataSpaceManager = class extends Resource2 {
1993
1993
  space: space.key
1994
1994
  }, {
1995
1995
  F: __dxlog_file7,
1996
- L: 556,
1996
+ L: 568,
1997
1997
  S: this,
1998
1998
  C: (f, a) => f(...a)
1999
1999
  });
@@ -2004,7 +2004,7 @@ var DataSpaceManager = class extends Resource2 {
2004
2004
  open: this._lifecycleState === LifecycleState.OPEN
2005
2005
  }, {
2006
2006
  F: __dxlog_file7,
2007
- L: 559,
2007
+ L: 571,
2008
2008
  S: this,
2009
2009
  C: (f, a) => f(...a)
2010
2010
  });
@@ -2023,7 +2023,7 @@ var DataSpaceManager = class extends Resource2 {
2023
2023
  space: space.key
2024
2024
  }, {
2025
2025
  F: __dxlog_file7,
2026
- L: 567,
2026
+ L: 579,
2027
2027
  S: this,
2028
2028
  C: (f, a) => f(...a)
2029
2029
  });
@@ -2044,7 +2044,7 @@ var DataSpaceManager = class extends Resource2 {
2044
2044
  spaceId: dataSpace.id
2045
2045
  }, {
2046
2046
  F: __dxlog_file7,
2047
- L: 581,
2047
+ L: 593,
2048
2048
  S: this,
2049
2049
  C: (f, a) => f(...a)
2050
2050
  });
@@ -2074,7 +2074,7 @@ var DataSpaceManager = class extends Resource2 {
2074
2074
  space: space.key
2075
2075
  }, {
2076
2076
  F: __dxlog_file7,
2077
- L: 608,
2077
+ L: 620,
2078
2078
  S: this,
2079
2079
  C: (f, a) => f(...a)
2080
2080
  });
@@ -2107,7 +2107,7 @@ var DataSpaceManager = class extends Resource2 {
2107
2107
  closedSessions
2108
2108
  }, {
2109
2109
  F: __dxlog_file7,
2110
- L: 634,
2110
+ L: 646,
2111
2111
  S: this,
2112
2112
  C: (f, a) => f(...a)
2113
2113
  });
@@ -2122,7 +2122,7 @@ var DataSpaceManager = class extends Resource2 {
2122
2122
  peerId: peerState.peerId
2123
2123
  }, {
2124
2124
  F: __dxlog_file7,
2125
- L: 648,
2125
+ L: 660,
2126
2126
  S: this,
2127
2127
  C: (f, a) => f(...a)
2128
2128
  });
@@ -2165,45 +2165,6 @@ var DataSpaceManager = class extends Resource2 {
2165
2165
  });
2166
2166
  await Promise.all(tasks);
2167
2167
  }
2168
- constructor(params) {
2169
- super(), _define_property5(this, "updated", new Event2()), _define_property5(this, "_spaces", new ComplexMap3(PublicKey4.hash)), _define_property5(this, "_instanceId", PublicKey4.random().toHex()), _define_property5(this, "_spaceManager", void 0), _define_property5(this, "_metadataStore", void 0), _define_property5(this, "_keyring", void 0), _define_property5(this, "_signingContext", void 0), _define_property5(this, "_feedStore", void 0), _define_property5(this, "_echoHost", void 0), _define_property5(this, "_invitationsManager", void 0), _define_property5(this, "_edgeConnection", void 0), _define_property5(this, "_edgeHttpClient", void 0), _define_property5(this, "_edgeFeatures", void 0), _define_property5(this, "_meshReplicator", void 0), _define_property5(this, "_echoEdgeReplicator", void 0), _define_property5(this, "_runtimeParams", void 0);
2170
- this._spaceManager = params.spaceManager;
2171
- this._metadataStore = params.metadataStore;
2172
- this._keyring = params.keyring;
2173
- this._signingContext = params.signingContext;
2174
- this._feedStore = params.feedStore;
2175
- this._echoHost = params.echoHost;
2176
- this._meshReplicator = params.meshReplicator;
2177
- this._invitationsManager = params.invitationsManager;
2178
- this._edgeConnection = params.edgeConnection;
2179
- this._edgeFeatures = params.edgeFeatures;
2180
- this._echoEdgeReplicator = params.echoEdgeReplicator;
2181
- this._edgeHttpClient = params.edgeHttpClient;
2182
- this._runtimeParams = params.runtimeParams;
2183
- trace.diagnostic({
2184
- id: "spaces",
2185
- name: "Spaces",
2186
- fetch: async () => {
2187
- return Promise.all(Array.from(this._spaces.values()).map(async (space) => {
2188
- const rootUrl = space.automergeSpaceState.rootUrl;
2189
- const rootHandle = rootUrl ? await this._echoHost.automergeRepo.find(rootUrl, FIND_PARAMS) : void 0;
2190
- await rootHandle?.whenReady();
2191
- const rootDoc = rootHandle?.doc();
2192
- const properties = rootDoc && findInlineObjectOfType(rootDoc, TYPE_PROPERTIES);
2193
- return {
2194
- key: space.key.toHex(),
2195
- state: SpaceState[space.state],
2196
- name: properties?.[1].data.name ?? null,
2197
- inlineObjects: rootDoc ? Object.keys(rootDoc.objects ?? {}).length : null,
2198
- linkedObjects: rootDoc ? Object.keys(rootDoc.links ?? {}).length : null,
2199
- credentials: space.inner.spaceState.credentials.length,
2200
- members: space.inner.spaceState.members.size,
2201
- rootUrl
2202
- };
2203
- }));
2204
- }
2205
- });
2206
- }
2207
2168
  };
2208
2169
  _ts_decorate2([
2209
2170
  synchronized
@@ -2238,21 +2199,12 @@ import { trace as trace2 } from "@dxos/tracing";
2238
2199
  import { Resource as Resource3 } from "@dxos/context";
2239
2200
  import { assertArgument as assertArgument2, assertState as assertState2 } from "@dxos/invariant";
2240
2201
  import { SpaceArchiveFileStructure, SpaceArchiveVersion } from "@dxos/protocols";
2241
- function _define_property6(obj, key, value) {
2242
- if (key in obj) {
2243
- Object.defineProperty(obj, key, {
2244
- value,
2245
- enumerable: true,
2246
- configurable: true,
2247
- writable: true
2248
- });
2249
- } else {
2250
- obj[key] = value;
2251
- }
2252
- return obj;
2253
- }
2254
2202
  var CURRENT_VERSION = SpaceArchiveVersion.V1;
2255
2203
  var SpaceArchiveWriter = class extends Resource3 {
2204
+ _tar;
2205
+ _archive;
2206
+ _meta = void 0;
2207
+ _currentRootUrl = void 0;
2256
2208
  async _open(ctx) {
2257
2209
  this._tar = await import("@obsidize/tar-browserify");
2258
2210
  }
@@ -2292,13 +2244,11 @@ var SpaceArchiveWriter = class extends Resource3 {
2292
2244
  this._archive.addTextFile(SpaceArchiveFileStructure.metadata, JSON.stringify(metadata));
2293
2245
  const binary = this._archive.toUint8Array();
2294
2246
  return {
2295
- filename: `${this._meta.spaceId}.tar`,
2247
+ // TODO(wittjosiah): Factor out file name construction.
2248
+ filename: `${(/* @__PURE__ */ new Date()).toISOString()}-${this._meta.spaceId}.tar`,
2296
2249
  contents: binary
2297
2250
  };
2298
2251
  }
2299
- constructor(...args) {
2300
- super(...args), _define_property6(this, "_tar", void 0), _define_property6(this, "_archive", void 0), _define_property6(this, "_meta", void 0), _define_property6(this, "_currentRootUrl", void 0);
2301
- }
2302
2252
  };
2303
2253
 
2304
2254
  // src/packlets/space-export/space-archive-reader.ts
@@ -2342,19 +2292,6 @@ var extractSpaceArchive = async (archive) => {
2342
2292
  };
2343
2293
 
2344
2294
  // src/packlets/spaces/spaces-service.ts
2345
- function _define_property7(obj, key, value) {
2346
- if (key in obj) {
2347
- Object.defineProperty(obj, key, {
2348
- value,
2349
- enumerable: true,
2350
- configurable: true,
2351
- writable: true
2352
- });
2353
- } else {
2354
- obj[key] = value;
2355
- }
2356
- return obj;
2357
- }
2358
2295
  function _ts_add_disposable_resource2(env, value, async) {
2359
2296
  if (value !== null && value !== void 0) {
2360
2297
  if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
@@ -2422,6 +2359,14 @@ function _ts_dispose_resources2(env) {
2422
2359
  }
2423
2360
  var __dxlog_file9 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
2424
2361
  var SpacesServiceImpl = class {
2362
+ _identityManager;
2363
+ _spaceManager;
2364
+ _getDataSpaceManager;
2365
+ constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
2366
+ this._identityManager = _identityManager;
2367
+ this._spaceManager = _spaceManager;
2368
+ this._getDataSpaceManager = _getDataSpaceManager;
2369
+ }
2425
2370
  async createSpace() {
2426
2371
  this._requireIdentity();
2427
2372
  const dataSpaceManager = await this._getDataSpaceManager();
@@ -2799,14 +2744,6 @@ var SpacesServiceImpl = class {
2799
2744
  });
2800
2745
  }
2801
2746
  }
2802
- constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
2803
- _define_property7(this, "_identityManager", void 0);
2804
- _define_property7(this, "_spaceManager", void 0);
2805
- _define_property7(this, "_getDataSpaceManager", void 0);
2806
- this._identityManager = _identityManager;
2807
- this._spaceManager = _spaceManager;
2808
- this._getDataSpaceManager = _getDataSpaceManager;
2809
- }
2810
2747
  };
2811
2748
  var getChannelId = (channel) => `user-channel/${channel}`;
2812
2749
 
@@ -2814,21 +2751,13 @@ var getChannelId = (channel) => `user-channel/${channel}`;
2814
2751
  import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
2815
2752
  import { SpaceId as SpaceId2 } from "@dxos/keys";
2816
2753
  import { log as log8 } from "@dxos/log";
2817
- function _define_property8(obj, key, value) {
2818
- if (key in obj) {
2819
- Object.defineProperty(obj, key, {
2820
- value,
2821
- enumerable: true,
2822
- configurable: true,
2823
- writable: true
2824
- });
2825
- } else {
2826
- obj[key] = value;
2827
- }
2828
- return obj;
2829
- }
2830
2754
  var __dxlog_file10 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/identity/default-space-state-machine.ts";
2831
2755
  var DefaultSpaceStateMachine = class {
2756
+ _params;
2757
+ _spaceId;
2758
+ constructor(_params) {
2759
+ this._params = _params;
2760
+ }
2832
2761
  get spaceId() {
2833
2762
  return this._spaceId;
2834
2763
  }
@@ -2864,27 +2793,9 @@ var DefaultSpaceStateMachine = class {
2864
2793
  }
2865
2794
  }
2866
2795
  }
2867
- constructor(_params) {
2868
- _define_property8(this, "_params", void 0);
2869
- _define_property8(this, "_spaceId", void 0);
2870
- this._params = _params;
2871
- }
2872
2796
  };
2873
2797
 
2874
2798
  // src/packlets/identity/identity.ts
2875
- function _define_property9(obj, key, value) {
2876
- if (key in obj) {
2877
- Object.defineProperty(obj, key, {
2878
- value,
2879
- enumerable: true,
2880
- configurable: true,
2881
- writable: true
2882
- });
2883
- } else {
2884
- obj[key] = value;
2885
- }
2886
- return obj;
2887
- }
2888
2799
  function _ts_decorate3(decorators, target, key, desc) {
2889
2800
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2890
2801
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -2893,6 +2804,58 @@ function _ts_decorate3(decorators, target, key, desc) {
2893
2804
  }
2894
2805
  var __dxlog_file11 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity.ts";
2895
2806
  var Identity = class {
2807
+ space;
2808
+ _signer;
2809
+ _presence;
2810
+ _deviceStateMachine;
2811
+ _profileStateMachine;
2812
+ _defaultSpaceStateMachine;
2813
+ _edgeFeedReplicator = void 0;
2814
+ authVerifier;
2815
+ did;
2816
+ identityKey;
2817
+ deviceKey;
2818
+ stateUpdate = new Event3();
2819
+ constructor(params) {
2820
+ this.space = params.space;
2821
+ this._signer = params.signer;
2822
+ this._presence = params.presence;
2823
+ this.did = params.did;
2824
+ this.identityKey = params.identityKey;
2825
+ this.deviceKey = params.deviceKey;
2826
+ log9.trace("dxos.halo.device", {
2827
+ deviceKey: params.deviceKey
2828
+ }, {
2829
+ F: __dxlog_file11,
2830
+ L: 83,
2831
+ S: this,
2832
+ C: (f, a) => f(...a)
2833
+ });
2834
+ this._deviceStateMachine = new DeviceStateMachine({
2835
+ identityKey: this.identityKey,
2836
+ deviceKey: this.deviceKey,
2837
+ onUpdate: () => this.stateUpdate.emit()
2838
+ });
2839
+ this._profileStateMachine = new ProfileStateMachine({
2840
+ identityKey: this.identityKey,
2841
+ onUpdate: () => this.stateUpdate.emit()
2842
+ });
2843
+ this._defaultSpaceStateMachine = new DefaultSpaceStateMachine({
2844
+ identityKey: this.identityKey,
2845
+ onUpdate: () => this.stateUpdate.emit()
2846
+ });
2847
+ this.authVerifier = new TrustedKeySetAuthVerifier({
2848
+ trustedKeysProvider: () => new ComplexSet(PublicKey5.hash, this.authorizedDeviceKeys.keys()),
2849
+ update: this.stateUpdate,
2850
+ authTimeout: AUTH_TIMEOUT
2851
+ });
2852
+ if (params.edgeConnection && params.edgeFeatures?.feedReplicator) {
2853
+ this._edgeFeedReplicator = new EdgeFeedReplicator({
2854
+ messenger: params.edgeConnection,
2855
+ spaceId: this.space.id
2856
+ });
2857
+ }
2858
+ }
2896
2859
  // TODO(burdon): Expose state object?
2897
2860
  get authorizedDeviceKeys() {
2898
2861
  return this._deviceStateMachine.authorizedDeviceKeys;
@@ -3052,61 +3015,9 @@ var Identity = class {
3052
3015
  })));
3053
3016
  return deviceCredential;
3054
3017
  }
3055
- constructor(params) {
3056
- _define_property9(this, "space", void 0);
3057
- _define_property9(this, "_signer", void 0);
3058
- _define_property9(this, "_presence", void 0);
3059
- _define_property9(this, "_deviceStateMachine", void 0);
3060
- _define_property9(this, "_profileStateMachine", void 0);
3061
- _define_property9(this, "_defaultSpaceStateMachine", void 0);
3062
- _define_property9(this, "_edgeFeedReplicator", void 0);
3063
- _define_property9(this, "authVerifier", void 0);
3064
- _define_property9(this, "did", void 0);
3065
- _define_property9(this, "identityKey", void 0);
3066
- _define_property9(this, "deviceKey", void 0);
3067
- _define_property9(this, "stateUpdate", new Event3());
3068
- _define_property9(this, "_onFeedAdded", async (feed) => {
3069
- await this._edgeFeedReplicator.addFeed(feed);
3070
- });
3071
- this.space = params.space;
3072
- this._signer = params.signer;
3073
- this._presence = params.presence;
3074
- this.did = params.did;
3075
- this.identityKey = params.identityKey;
3076
- this.deviceKey = params.deviceKey;
3077
- log9.trace("dxos.halo.device", {
3078
- deviceKey: params.deviceKey
3079
- }, {
3080
- F: __dxlog_file11,
3081
- L: 83,
3082
- S: this,
3083
- C: (f, a) => f(...a)
3084
- });
3085
- this._deviceStateMachine = new DeviceStateMachine({
3086
- identityKey: this.identityKey,
3087
- deviceKey: this.deviceKey,
3088
- onUpdate: () => this.stateUpdate.emit()
3089
- });
3090
- this._profileStateMachine = new ProfileStateMachine({
3091
- identityKey: this.identityKey,
3092
- onUpdate: () => this.stateUpdate.emit()
3093
- });
3094
- this._defaultSpaceStateMachine = new DefaultSpaceStateMachine({
3095
- identityKey: this.identityKey,
3096
- onUpdate: () => this.stateUpdate.emit()
3097
- });
3098
- this.authVerifier = new TrustedKeySetAuthVerifier({
3099
- trustedKeysProvider: () => new ComplexSet(PublicKey5.hash, this.authorizedDeviceKeys.keys()),
3100
- update: this.stateUpdate,
3101
- authTimeout: AUTH_TIMEOUT
3102
- });
3103
- if (params.edgeConnection && params.edgeFeatures?.feedReplicator) {
3104
- this._edgeFeedReplicator = new EdgeFeedReplicator({
3105
- messenger: params.edgeConnection,
3106
- spaceId: this.space.id
3107
- });
3108
- }
3109
- }
3018
+ _onFeedAdded = async (feed) => {
3019
+ await this._edgeFeedReplicator.addFeed(feed);
3020
+ };
3110
3021
  };
3111
3022
  _ts_decorate3([
3112
3023
  trace3.span()
@@ -3133,19 +3044,6 @@ import { Gossip as Gossip2, Presence as Presence2 } from "@dxos/teleport-extensi
3133
3044
  import { Timeframe as Timeframe3 } from "@dxos/timeframe";
3134
3045
  import { trace as Trace2 } from "@dxos/tracing";
3135
3046
  import { deferFunction as deferFunction2, isNode } from "@dxos/util";
3136
- function _define_property10(obj, key, value) {
3137
- if (key in obj) {
3138
- Object.defineProperty(obj, key, {
3139
- value,
3140
- enumerable: true,
3141
- configurable: true,
3142
- writable: true
3143
- });
3144
- } else {
3145
- obj[key] = value;
3146
- }
3147
- return obj;
3148
- }
3149
3047
  function _ts_decorate4(decorators, target, key, desc) {
3150
3048
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3151
3049
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -3156,6 +3054,27 @@ var __dxlog_file12 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/i
3156
3054
  var DEVICE_PRESENCE_ANNOUNCE_INTERVAL = 1e4;
3157
3055
  var DEVICE_PRESENCE_OFFLINE_TIMEOUT = 2e4;
3158
3056
  var IdentityManager = class {
3057
+ stateUpdate = new Event4();
3058
+ _metadataStore;
3059
+ _keyring;
3060
+ _feedStore;
3061
+ _spaceManager;
3062
+ _devicePresenceAnnounceInterval;
3063
+ _devicePresenceOfflineTimeout;
3064
+ _edgeConnection;
3065
+ _edgeFeatures;
3066
+ _identity;
3067
+ // TODO(dmaretskyi): Perhaps this should take/generate the peerKey outside of an initialized identity.
3068
+ constructor(params) {
3069
+ this._metadataStore = params.metadataStore;
3070
+ this._keyring = params.keyring;
3071
+ this._feedStore = params.feedStore;
3072
+ this._spaceManager = params.spaceManager;
3073
+ this._edgeConnection = params.edgeConnection;
3074
+ this._edgeFeatures = params.edgeFeatures;
3075
+ this._devicePresenceAnnounceInterval = params.devicePresenceAnnounceInterval ?? DEVICE_PRESENCE_ANNOUNCE_INTERVAL;
3076
+ this._devicePresenceOfflineTimeout = params.devicePresenceOfflineTimeout ?? DEVICE_PRESENCE_OFFLINE_TIMEOUT;
3077
+ }
3159
3078
  get identity() {
3160
3079
  return this._identity;
3161
3080
  }
@@ -3590,27 +3509,6 @@ var IdentityManager = class {
3590
3509
  }
3591
3510
  });
3592
3511
  }
3593
- // TODO(dmaretskyi): Perhaps this should take/generate the peerKey outside of an initialized identity.
3594
- constructor(params) {
3595
- _define_property10(this, "stateUpdate", new Event4());
3596
- _define_property10(this, "_metadataStore", void 0);
3597
- _define_property10(this, "_keyring", void 0);
3598
- _define_property10(this, "_feedStore", void 0);
3599
- _define_property10(this, "_spaceManager", void 0);
3600
- _define_property10(this, "_devicePresenceAnnounceInterval", void 0);
3601
- _define_property10(this, "_devicePresenceOfflineTimeout", void 0);
3602
- _define_property10(this, "_edgeConnection", void 0);
3603
- _define_property10(this, "_edgeFeatures", void 0);
3604
- _define_property10(this, "_identity", void 0);
3605
- this._metadataStore = params.metadataStore;
3606
- this._keyring = params.keyring;
3607
- this._feedStore = params.feedStore;
3608
- this._spaceManager = params.spaceManager;
3609
- this._edgeConnection = params.edgeConnection;
3610
- this._edgeFeatures = params.edgeFeatures;
3611
- this._devicePresenceAnnounceInterval = params.devicePresenceAnnounceInterval ?? DEVICE_PRESENCE_ANNOUNCE_INTERVAL;
3612
- this._devicePresenceOfflineTimeout = params.devicePresenceOfflineTimeout ?? DEVICE_PRESENCE_OFFLINE_TIMEOUT;
3613
- }
3614
3512
  };
3615
3513
  _ts_decorate4([
3616
3514
  Trace2.span({
@@ -3630,22 +3528,18 @@ import { invariant as invariant8 } from "@dxos/invariant";
3630
3528
  import { log as log11 } from "@dxos/log";
3631
3529
  import { SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
3632
3530
  import { safeAwaitAll } from "@dxos/util";
3633
- function _define_property11(obj, key, value) {
3634
- if (key in obj) {
3635
- Object.defineProperty(obj, key, {
3636
- value,
3637
- enumerable: true,
3638
- configurable: true,
3639
- writable: true
3640
- });
3641
- } else {
3642
- obj[key] = value;
3643
- }
3644
- return obj;
3645
- }
3646
3531
  var __dxlog_file13 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
3647
3532
  var DEFAULT_SPACE_SEARCH_TIMEOUT = 1e4;
3648
3533
  var IdentityServiceImpl = class extends Resource4 {
3534
+ _identityManager;
3535
+ _recoveryManager;
3536
+ _keyring;
3537
+ _dataSpaceManagerProvider;
3538
+ _createIdentity;
3539
+ _onProfileUpdate;
3540
+ constructor(_identityManager, _recoveryManager, _keyring, _dataSpaceManagerProvider, _createIdentity, _onProfileUpdate) {
3541
+ super(), this._identityManager = _identityManager, this._recoveryManager = _recoveryManager, this._keyring = _keyring, this._dataSpaceManagerProvider = _dataSpaceManagerProvider, this._createIdentity = _createIdentity, this._onProfileUpdate = _onProfileUpdate;
3542
+ }
3649
3543
  async _open() {
3650
3544
  const identity = this._identityManager.identity;
3651
3545
  if (identity && !identity.defaultSpaceId) {
@@ -3820,29 +3714,21 @@ var IdentityServiceImpl = class extends Resource4 {
3820
3714
  await this._createDefaultSpace(dataSpaceManager);
3821
3715
  }
3822
3716
  }
3823
- constructor(_identityManager, _recoveryManager, _keyring, _dataSpaceManagerProvider, _createIdentity, _onProfileUpdate) {
3824
- super(), _define_property11(this, "_identityManager", void 0), _define_property11(this, "_recoveryManager", void 0), _define_property11(this, "_keyring", void 0), _define_property11(this, "_dataSpaceManagerProvider", void 0), _define_property11(this, "_createIdentity", void 0), _define_property11(this, "_onProfileUpdate", void 0), this._identityManager = _identityManager, this._recoveryManager = _recoveryManager, this._keyring = _keyring, this._dataSpaceManagerProvider = _dataSpaceManagerProvider, this._createIdentity = _createIdentity, this._onProfileUpdate = _onProfileUpdate;
3825
- }
3826
3717
  };
3827
3718
 
3828
3719
  // src/packlets/spaces/automerge-space-state.ts
3829
3720
  import { Event as Event5 } from "@dxos/async";
3830
3721
  import { Resource as Resource5 } from "@dxos/context";
3831
3722
  import { checkCredentialType } from "@dxos/credentials";
3832
- function _define_property12(obj, key, value) {
3833
- if (key in obj) {
3834
- Object.defineProperty(obj, key, {
3835
- value,
3836
- enumerable: true,
3837
- configurable: true,
3838
- writable: true
3839
- });
3840
- } else {
3841
- obj[key] = value;
3842
- }
3843
- return obj;
3844
- }
3845
3723
  var AutomergeSpaceState = class extends Resource5 {
3724
+ _onNewRoot;
3725
+ rootUrl = void 0;
3726
+ lastEpoch = void 0;
3727
+ onNewEpoch = new Event5();
3728
+ _isProcessingRootDocs = false;
3729
+ constructor(_onNewRoot) {
3730
+ super(), this._onNewRoot = _onNewRoot;
3731
+ }
3846
3732
  async _open(ctx) {
3847
3733
  }
3848
3734
  async _close(ctx) {
@@ -3873,9 +3759,6 @@ var AutomergeSpaceState = class extends Resource5 {
3873
3759
  async ensureEpochInitialized() {
3874
3760
  await this.onNewEpoch.waitForCondition(() => !!this.lastEpoch);
3875
3761
  }
3876
- constructor(_onNewRoot) {
3877
- super(), _define_property12(this, "_onNewRoot", void 0), _define_property12(this, "rootUrl", void 0), _define_property12(this, "lastEpoch", void 0), _define_property12(this, "onNewEpoch", void 0), _define_property12(this, "_isProcessingRootDocs", void 0), this._onNewRoot = _onNewRoot, this.rootUrl = void 0, this.lastEpoch = void 0, this.onNewEpoch = new Event5(), this._isProcessingRootDocs = false;
3878
- }
3879
3762
  };
3880
3763
 
3881
3764
  // src/packlets/spaces/epoch-migrations.ts
@@ -3942,19 +3825,6 @@ import { EdgeCallFailedError } from "@dxos/protocols";
3942
3825
  import { schema as schema2 } from "@dxos/protocols/proto";
3943
3826
  import { RpcExtension } from "@dxos/teleport";
3944
3827
  import { ComplexMap as ComplexMap4, ComplexSet as ComplexSet2, entry } from "@dxos/util";
3945
- function _define_property13(obj, key, value) {
3946
- if (key in obj) {
3947
- Object.defineProperty(obj, key, {
3948
- value,
3949
- enumerable: true,
3950
- configurable: true,
3951
- writable: true
3952
- });
3953
- } else {
3954
- obj[key] = value;
3955
- }
3956
- return obj;
3957
- }
3958
3828
  function _ts_decorate5(decorators, target, key, desc) {
3959
3829
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3960
3830
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -3970,6 +3840,24 @@ var MAX_EDGE_RETRIES = 2;
3970
3840
  var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
3971
3841
  var credentialCodec = schema2.getCodecForType("dxos.halo.credentials.Credential");
3972
3842
  var NotarizationPlugin = class extends Resource6 {
3843
+ _extensionOpened = new Event6();
3844
+ _writer;
3845
+ _extensions = /* @__PURE__ */ new Set();
3846
+ _processedCredentials = new ComplexSet2(PublicKey7.hash);
3847
+ _processCredentialsTriggers = new ComplexMap4(PublicKey7.hash);
3848
+ _activeEdgePollingIntervalHandle = void 0;
3849
+ _activeEdgePollingInterval;
3850
+ _activeEdgePollingEnabled = false;
3851
+ _spaceId;
3852
+ _edgeClient;
3853
+ constructor(params) {
3854
+ super();
3855
+ this._spaceId = params.spaceId;
3856
+ this._activeEdgePollingInterval = params.activeEdgePollingInterval ?? DEFAULT_ACTIVE_EDGE_POLLING_INTERVAL;
3857
+ if (params.edgeClient && params.edgeFeatures?.feedReplicator) {
3858
+ this._edgeClient = params.edgeClient;
3859
+ }
3860
+ }
3973
3861
  setActiveEdgePollingEnabled(enabled) {
3974
3862
  const client = this._edgeClient;
3975
3863
  invariant10(client, void 0, {
@@ -4329,14 +4217,6 @@ var NotarizationPlugin = class extends Resource6 {
4329
4217
  errors.throw(new TimeoutError(timeout, "Notarization timed out"));
4330
4218
  }, timeout);
4331
4219
  }
4332
- constructor(params) {
4333
- super(), _define_property13(this, "_extensionOpened", new Event6()), _define_property13(this, "_writer", void 0), _define_property13(this, "_extensions", /* @__PURE__ */ new Set()), _define_property13(this, "_processedCredentials", new ComplexSet2(PublicKey7.hash)), _define_property13(this, "_processCredentialsTriggers", new ComplexMap4(PublicKey7.hash)), _define_property13(this, "_activeEdgePollingIntervalHandle", void 0), _define_property13(this, "_activeEdgePollingInterval", void 0), _define_property13(this, "_activeEdgePollingEnabled", false), _define_property13(this, "_spaceId", void 0), _define_property13(this, "_edgeClient", void 0);
4334
- this._spaceId = params.spaceId;
4335
- this._activeEdgePollingInterval = params.activeEdgePollingInterval ?? DEFAULT_ACTIVE_EDGE_POLLING_INTERVAL;
4336
- if (params.edgeClient && params.edgeFeatures?.feedReplicator) {
4337
- this._edgeClient = params.edgeClient;
4338
- }
4339
- }
4340
4220
  };
4341
4221
  _ts_decorate5([
4342
4222
  logInfo2
@@ -4361,6 +4241,17 @@ var handleEdgeError = (error) => {
4361
4241
  }
4362
4242
  };
4363
4243
  var NotarizationTeleportExtension = class extends RpcExtension {
4244
+ _params;
4245
+ constructor(_params) {
4246
+ super({
4247
+ requested: {
4248
+ NotarizationService: schema2.getService("dxos.mesh.teleport.notarization.NotarizationService")
4249
+ },
4250
+ exposed: {
4251
+ NotarizationService: schema2.getService("dxos.mesh.teleport.notarization.NotarizationService")
4252
+ }
4253
+ }), this._params = _params;
4254
+ }
4364
4255
  async getHandlers() {
4365
4256
  return {
4366
4257
  NotarizationService: {
@@ -4378,32 +4269,9 @@ var NotarizationTeleportExtension = class extends RpcExtension {
4378
4269
  await this._params.onClose();
4379
4270
  await super.onClose(err);
4380
4271
  }
4381
- constructor(_params) {
4382
- super({
4383
- requested: {
4384
- NotarizationService: schema2.getService("dxos.mesh.teleport.notarization.NotarizationService")
4385
- },
4386
- exposed: {
4387
- NotarizationService: schema2.getService("dxos.mesh.teleport.notarization.NotarizationService")
4388
- }
4389
- }), _define_property13(this, "_params", void 0), this._params = _params;
4390
- }
4391
4272
  };
4392
4273
 
4393
4274
  // src/packlets/spaces/data-space.ts
4394
- function _define_property14(obj, key, value) {
4395
- if (key in obj) {
4396
- Object.defineProperty(obj, key, {
4397
- value,
4398
- enumerable: true,
4399
- configurable: true,
4400
- writable: true
4401
- });
4402
- } else {
4403
- obj[key] = value;
4404
- }
4405
- return obj;
4406
- }
4407
4275
  function _ts_decorate6(decorators, target, key, desc) {
4408
4276
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4409
4277
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -4477,6 +4345,75 @@ function _ts_dispose_resources3(env) {
4477
4345
  }
4478
4346
  var __dxlog_file16 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
4479
4347
  var DataSpace = class {
4348
+ _ctx = new Context6(void 0, {
4349
+ F: __dxlog_file16,
4350
+ L: 101
4351
+ });
4352
+ _inner;
4353
+ _gossip;
4354
+ _presence;
4355
+ _keyring;
4356
+ _feedStore;
4357
+ _metadataStore;
4358
+ _signingContext;
4359
+ _notarizationPlugin;
4360
+ _callbacks;
4361
+ _cache = void 0;
4362
+ _echoHost;
4363
+ _edgeFeedReplicator = void 0;
4364
+ // TODO(dmaretskyi): Move into Space?
4365
+ _automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
4366
+ _epochProcessingMutex = new Mutex2();
4367
+ _state = SpaceState4.SPACE_CLOSED;
4368
+ _databaseRoot = null;
4369
+ /**
4370
+ * Error for _state === SpaceState.SPACE_ERROR.
4371
+ */
4372
+ error = void 0;
4373
+ authVerifier;
4374
+ stateUpdate = new Event7();
4375
+ postOpen = new CallbackCollection();
4376
+ preClose = new CallbackCollection();
4377
+ metrics = {};
4378
+ constructor(params) {
4379
+ this._inner = params.inner;
4380
+ this._inner.stateUpdate.on(this._ctx, () => this.stateUpdate.emit());
4381
+ this._gossip = params.gossip;
4382
+ this._presence = params.presence;
4383
+ this._keyring = params.keyring;
4384
+ this._feedStore = params.feedStore;
4385
+ this._metadataStore = params.metadataStore;
4386
+ this._signingContext = params.signingContext;
4387
+ this._callbacks = params.callbacks ?? {};
4388
+ this._echoHost = params.echoHost;
4389
+ this._notarizationPlugin = new NotarizationPlugin({
4390
+ spaceId: this._inner.id,
4391
+ edgeClient: params.edgeHttpClient,
4392
+ edgeFeatures: params.edgeFeatures,
4393
+ activeEdgePollingInterval: params.activeEdgeNotarizationPollingInterval
4394
+ });
4395
+ this.authVerifier = new TrustedKeySetAuthVerifier({
4396
+ trustedKeysProvider: () => new ComplexSet3(PublicKey8.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => member.role !== SpaceMember5.Role.REMOVED).map((member) => member.key)),
4397
+ update: this._inner.stateUpdate,
4398
+ authTimeout: AUTH_TIMEOUT2
4399
+ });
4400
+ this._cache = params.cache;
4401
+ if (params.edgeConnection && params.edgeFeatures?.feedReplicator) {
4402
+ this._edgeFeedReplicator = new EdgeFeedReplicator({
4403
+ messenger: params.edgeConnection,
4404
+ spaceId: this.id
4405
+ });
4406
+ }
4407
+ this._state = params.initialState;
4408
+ log13("new state", {
4409
+ state: SpaceState4[this._state]
4410
+ }, {
4411
+ F: __dxlog_file16,
4412
+ L: 177,
4413
+ S: this,
4414
+ C: (f, a) => f(...a)
4415
+ });
4416
+ }
4480
4417
  get id() {
4481
4418
  return this._inner.id;
4482
4419
  }
@@ -4963,74 +4900,9 @@ var DataSpace = class {
4963
4900
  getEdgeReplicationSetting() {
4964
4901
  return this._metadataStore.getSpaceEdgeReplicationSetting(this.key);
4965
4902
  }
4966
- constructor(params) {
4967
- _define_property14(this, "_ctx", new Context6(void 0, {
4968
- F: __dxlog_file16,
4969
- L: 101
4970
- }));
4971
- _define_property14(this, "_inner", void 0);
4972
- _define_property14(this, "_gossip", void 0);
4973
- _define_property14(this, "_presence", void 0);
4974
- _define_property14(this, "_keyring", void 0);
4975
- _define_property14(this, "_feedStore", void 0);
4976
- _define_property14(this, "_metadataStore", void 0);
4977
- _define_property14(this, "_signingContext", void 0);
4978
- _define_property14(this, "_notarizationPlugin", void 0);
4979
- _define_property14(this, "_callbacks", void 0);
4980
- _define_property14(this, "_cache", void 0);
4981
- _define_property14(this, "_echoHost", void 0);
4982
- _define_property14(this, "_edgeFeedReplicator", void 0);
4983
- _define_property14(this, "_automergeSpaceState", new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl)));
4984
- _define_property14(this, "_epochProcessingMutex", new Mutex2());
4985
- _define_property14(this, "_state", SpaceState4.SPACE_CLOSED);
4986
- _define_property14(this, "_databaseRoot", null);
4987
- _define_property14(this, "error", void 0);
4988
- _define_property14(this, "authVerifier", void 0);
4989
- _define_property14(this, "stateUpdate", new Event7());
4990
- _define_property14(this, "postOpen", new CallbackCollection());
4991
- _define_property14(this, "preClose", new CallbackCollection());
4992
- _define_property14(this, "metrics", {});
4993
- _define_property14(this, "_onFeedAdded", async (feed) => {
4994
- await this._edgeFeedReplicator.addFeed(feed);
4995
- });
4996
- this._inner = params.inner;
4997
- this._inner.stateUpdate.on(this._ctx, () => this.stateUpdate.emit());
4998
- this._gossip = params.gossip;
4999
- this._presence = params.presence;
5000
- this._keyring = params.keyring;
5001
- this._feedStore = params.feedStore;
5002
- this._metadataStore = params.metadataStore;
5003
- this._signingContext = params.signingContext;
5004
- this._callbacks = params.callbacks ?? {};
5005
- this._echoHost = params.echoHost;
5006
- this._notarizationPlugin = new NotarizationPlugin({
5007
- spaceId: this._inner.id,
5008
- edgeClient: params.edgeHttpClient,
5009
- edgeFeatures: params.edgeFeatures,
5010
- activeEdgePollingInterval: params.activeEdgeNotarizationPollingInterval
5011
- });
5012
- this.authVerifier = new TrustedKeySetAuthVerifier({
5013
- trustedKeysProvider: () => new ComplexSet3(PublicKey8.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => member.role !== SpaceMember5.Role.REMOVED).map((member) => member.key)),
5014
- update: this._inner.stateUpdate,
5015
- authTimeout: AUTH_TIMEOUT2
5016
- });
5017
- this._cache = params.cache;
5018
- if (params.edgeConnection && params.edgeFeatures?.feedReplicator) {
5019
- this._edgeFeedReplicator = new EdgeFeedReplicator({
5020
- messenger: params.edgeConnection,
5021
- spaceId: this.id
5022
- });
5023
- }
5024
- this._state = params.initialState;
5025
- log13("new state", {
5026
- state: SpaceState4[this._state]
5027
- }, {
5028
- F: __dxlog_file16,
5029
- L: 177,
5030
- S: this,
5031
- C: (f, a) => f(...a)
5032
- });
5033
- }
4903
+ _onFeedAdded = async (feed) => {
4904
+ await this._edgeFeedReplicator.addFeed(feed);
4905
+ };
5034
4906
  };
5035
4907
  _ts_decorate6([
5036
4908
  trace5.info()
@@ -5086,21 +4958,16 @@ import { getCredentialAssertion as getCredentialAssertion4 } from "@dxos/credent
5086
4958
  import { invariant as invariant12 } from "@dxos/invariant";
5087
4959
  import { AlreadyJoinedError as AlreadyJoinedError2 } from "@dxos/protocols";
5088
4960
  import { Invitation as Invitation2 } from "@dxos/protocols/proto/dxos/client/services";
5089
- function _define_property15(obj, key, value) {
5090
- if (key in obj) {
5091
- Object.defineProperty(obj, key, {
5092
- value,
5093
- enumerable: true,
5094
- configurable: true,
5095
- writable: true
5096
- });
5097
- } else {
5098
- obj[key] = value;
5099
- }
5100
- return obj;
5101
- }
5102
4961
  var __dxlog_file17 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts";
5103
4962
  var DeviceInvitationProtocol = class {
4963
+ _keyring;
4964
+ _getIdentity;
4965
+ _acceptIdentity;
4966
+ constructor(_keyring, _getIdentity, _acceptIdentity) {
4967
+ this._keyring = _keyring;
4968
+ this._getIdentity = _getIdentity;
4969
+ this._acceptIdentity = _acceptIdentity;
4970
+ }
5104
4971
  toJSON() {
5105
4972
  return {
5106
4973
  kind: "device"
@@ -5212,14 +5079,6 @@ var DeviceInvitationProtocol = class {
5212
5079
  identityKey
5213
5080
  };
5214
5081
  }
5215
- constructor(_keyring, _getIdentity, _acceptIdentity) {
5216
- _define_property15(this, "_keyring", void 0);
5217
- _define_property15(this, "_getIdentity", void 0);
5218
- _define_property15(this, "_acceptIdentity", void 0);
5219
- this._keyring = _keyring;
5220
- this._getIdentity = _getIdentity;
5221
- this._acceptIdentity = _acceptIdentity;
5222
- }
5223
5082
  };
5224
5083
 
5225
5084
  // src/packlets/invitations/invitations-handler.ts
@@ -5274,24 +5133,22 @@ var tryAcquireBeforeContextDisposed = async (ctx, mutex) => {
5274
5133
  };
5275
5134
 
5276
5135
  // src/packlets/invitations/edge-invitation-handler.ts
5277
- function _define_property16(obj, key, value) {
5278
- if (key in obj) {
5279
- Object.defineProperty(obj, key, {
5280
- value,
5281
- enumerable: true,
5282
- configurable: true,
5283
- writable: true
5284
- });
5285
- } else {
5286
- obj[key] = value;
5287
- }
5288
- return obj;
5289
- }
5290
5136
  var __dxlog_file18 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/edge-invitation-handler.ts";
5291
5137
  var MAX_RETRIES_PER_INVITATION = 5;
5292
5138
  var DEFAULT_REQUEST_RETRY_INTERVAL_MS = 3e3;
5293
5139
  var DEFAULT_REQUEST_RETRY_JITTER_MS = 500;
5294
5140
  var EdgeInvitationHandler = class {
5141
+ _client;
5142
+ _callbacks;
5143
+ _flowLock;
5144
+ _retryInterval;
5145
+ _retryJitter;
5146
+ constructor(config, _client, _callbacks) {
5147
+ this._client = _client;
5148
+ this._callbacks = _callbacks;
5149
+ this._retryInterval = config?.retryInterval ?? DEFAULT_REQUEST_RETRY_INTERVAL_MS;
5150
+ this._retryJitter = config?.retryJitter ?? DEFAULT_REQUEST_RETRY_JITTER_MS;
5151
+ }
5295
5152
  handle(ctx, guardedState, protocol, deviceProfile) {
5296
5153
  if (!this._client) {
5297
5154
  log14("edge disabled", void 0, {
@@ -5434,17 +5291,6 @@ var EdgeInvitationHandler = class {
5434
5291
  _calculateNextRetryMs() {
5435
5292
  return this._retryInterval + Math.random() * this._retryJitter;
5436
5293
  }
5437
- constructor(config, _client, _callbacks) {
5438
- _define_property16(this, "_client", void 0);
5439
- _define_property16(this, "_callbacks", void 0);
5440
- _define_property16(this, "_flowLock", void 0);
5441
- _define_property16(this, "_retryInterval", void 0);
5442
- _define_property16(this, "_retryJitter", void 0);
5443
- this._client = _client;
5444
- this._callbacks = _callbacks;
5445
- this._retryInterval = config?.retryInterval ?? DEFAULT_REQUEST_RETRY_INTERVAL_MS;
5446
- this._retryJitter = config?.retryJitter ?? DEFAULT_REQUEST_RETRY_JITTER_MS;
5447
- }
5448
5294
  };
5449
5295
 
5450
5296
  // src/packlets/invitations/invitation-guest-extenstion.ts
@@ -5456,22 +5302,31 @@ import { InvalidInvitationExtensionRoleError } from "@dxos/protocols";
5456
5302
  import { schema as schema4 } from "@dxos/protocols/proto";
5457
5303
  import { InvitationOptions } from "@dxos/protocols/proto/dxos/halo/invitations";
5458
5304
  import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
5459
- function _define_property17(obj, key, value) {
5460
- if (key in obj) {
5461
- Object.defineProperty(obj, key, {
5462
- value,
5463
- enumerable: true,
5464
- configurable: true,
5465
- writable: true
5466
- });
5467
- } else {
5468
- obj[key] = value;
5469
- }
5470
- return obj;
5471
- }
5472
5305
  var __dxlog_file19 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts";
5473
5306
  var OPTIONS_TIMEOUT = 1e4;
5474
5307
  var InvitationGuestExtension = class extends RpcExtension2 {
5308
+ _invitationFlowMutex;
5309
+ _callbacks;
5310
+ _ctx = new Context7(void 0, {
5311
+ F: __dxlog_file19,
5312
+ L: 38
5313
+ });
5314
+ _remoteOptions;
5315
+ _remoteOptionsTrigger = new Trigger5();
5316
+ /**
5317
+ * Held to allow only one invitation flow at a time to be active.
5318
+ */
5319
+ _invitationFlowLock = null;
5320
+ constructor(_invitationFlowMutex, _callbacks) {
5321
+ super({
5322
+ requested: {
5323
+ InvitationHostService: schema4.getService("dxos.halo.invitations.InvitationHostService")
5324
+ },
5325
+ exposed: {
5326
+ InvitationHostService: schema4.getService("dxos.halo.invitations.InvitationHostService")
5327
+ }
5328
+ }), this._invitationFlowMutex = _invitationFlowMutex, this._callbacks = _callbacks;
5329
+ }
5475
5330
  hasFlowLock() {
5476
5331
  return this._invitationFlowLock != null;
5477
5332
  }
@@ -5573,22 +5428,6 @@ var InvitationGuestExtension = class extends RpcExtension2 {
5573
5428
  });
5574
5429
  }
5575
5430
  }
5576
- constructor(_invitationFlowMutex, _callbacks) {
5577
- super({
5578
- requested: {
5579
- InvitationHostService: schema4.getService("dxos.halo.invitations.InvitationHostService")
5580
- },
5581
- exposed: {
5582
- InvitationHostService: schema4.getService("dxos.halo.invitations.InvitationHostService")
5583
- }
5584
- }), _define_property17(this, "_invitationFlowMutex", void 0), _define_property17(this, "_callbacks", void 0), _define_property17(this, "_ctx", void 0), _define_property17(this, "_remoteOptions", void 0), _define_property17(this, "_remoteOptionsTrigger", void 0), /**
5585
- * Held to allow only one invitation flow at a time to be active.
5586
- */
5587
- _define_property17(this, "_invitationFlowLock", void 0), this._invitationFlowMutex = _invitationFlowMutex, this._callbacks = _callbacks, this._ctx = new Context7(void 0, {
5588
- F: __dxlog_file19,
5589
- L: 38
5590
- }), this._remoteOptionsTrigger = new Trigger5(), this._invitationFlowLock = null;
5591
- }
5592
5431
  };
5593
5432
 
5594
5433
  // src/packlets/invitations/invitation-host-extension.ts
@@ -5603,26 +5442,49 @@ import { schema as schema5 } from "@dxos/protocols/proto";
5603
5442
  import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
5604
5443
  import { AuthenticationResponse, InvitationOptions as InvitationOptions2 } from "@dxos/protocols/proto/dxos/halo/invitations";
5605
5444
  import { RpcExtension as RpcExtension3 } from "@dxos/teleport";
5606
- function _define_property18(obj, key, value) {
5607
- if (key in obj) {
5608
- Object.defineProperty(obj, key, {
5609
- value,
5610
- enumerable: true,
5611
- configurable: true,
5612
- writable: true
5613
- });
5614
- } else {
5615
- obj[key] = value;
5616
- }
5617
- return obj;
5618
- }
5619
5445
  var __dxlog_file20 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts";
5620
5446
  var OPTIONS_TIMEOUT2 = 1e4;
5621
5447
  var MAX_OTP_ATTEMPTS = 3;
5622
5448
  var InvitationHostExtension = class extends RpcExtension3 {
5623
- hasFlowLock() {
5624
- return this._invitationFlowLock != null;
5625
- }
5449
+ _invitationFlowMutex;
5450
+ _callbacks;
5451
+ /**
5452
+ * @internal
5453
+ */
5454
+ _ctx = new Context8(void 0, {
5455
+ F: __dxlog_file20,
5456
+ L: 57
5457
+ });
5458
+ _remoteOptions;
5459
+ _remoteOptionsTrigger = new Trigger6();
5460
+ _challenge = void 0;
5461
+ guestProfile = void 0;
5462
+ authenticationPassed = false;
5463
+ /**
5464
+ * Retry counter for SHARED_SECRET authentication method.
5465
+ */
5466
+ authenticationRetry = 0;
5467
+ /**
5468
+ * Resolved when admission is completed.
5469
+ */
5470
+ completedTrigger = new Trigger6();
5471
+ /**
5472
+ * Held to allow only one invitation flow at a time to be active.
5473
+ */
5474
+ _invitationFlowLock = null;
5475
+ constructor(_invitationFlowMutex, _callbacks) {
5476
+ super({
5477
+ requested: {
5478
+ InvitationHostService: schema5.getService("dxos.halo.invitations.InvitationHostService")
5479
+ },
5480
+ exposed: {
5481
+ InvitationHostService: schema5.getService("dxos.halo.invitations.InvitationHostService")
5482
+ }
5483
+ }), this._invitationFlowMutex = _invitationFlowMutex, this._callbacks = _callbacks;
5484
+ }
5485
+ hasFlowLock() {
5486
+ return this._invitationFlowLock != null;
5487
+ }
5626
5488
  async getHandlers() {
5627
5489
  return {
5628
5490
  // TODO(dmaretskyi): For now this is just forwarding the data to callbacks since we don't have session-specific logic.
@@ -5920,31 +5782,6 @@ var InvitationHostExtension = class extends RpcExtension3 {
5920
5782
  });
5921
5783
  }
5922
5784
  }
5923
- constructor(_invitationFlowMutex, _callbacks) {
5924
- super({
5925
- requested: {
5926
- InvitationHostService: schema5.getService("dxos.halo.invitations.InvitationHostService")
5927
- },
5928
- exposed: {
5929
- InvitationHostService: schema5.getService("dxos.halo.invitations.InvitationHostService")
5930
- }
5931
- }), _define_property18(this, "_invitationFlowMutex", void 0), _define_property18(this, "_callbacks", void 0), /**
5932
- * @internal
5933
- */
5934
- _define_property18(this, "_ctx", void 0), _define_property18(this, "_remoteOptions", void 0), _define_property18(this, "_remoteOptionsTrigger", void 0), _define_property18(this, "_challenge", void 0), _define_property18(this, "guestProfile", void 0), _define_property18(this, "authenticationPassed", void 0), /**
5935
- * Retry counter for SHARED_SECRET authentication method.
5936
- */
5937
- _define_property18(this, "authenticationRetry", void 0), /**
5938
- * Resolved when admission is completed.
5939
- */
5940
- _define_property18(this, "completedTrigger", void 0), /**
5941
- * Held to allow only one invitation flow at a time to be active.
5942
- */
5943
- _define_property18(this, "_invitationFlowLock", void 0), this._invitationFlowMutex = _invitationFlowMutex, this._callbacks = _callbacks, this._ctx = new Context8(void 0, {
5944
- F: __dxlog_file20,
5945
- L: 57
5946
- }), this._remoteOptionsTrigger = new Trigger6(), this._challenge = void 0, this.guestProfile = void 0, this.authenticationPassed = false, this.authenticationRetry = 0, this.completedTrigger = new Trigger6(), this._invitationFlowLock = null;
5947
- }
5948
5785
  };
5949
5786
  var isAuthenticationRequired = (invitation) => invitation.authMethod !== Invitation5.AuthMethod.NONE;
5950
5787
 
@@ -6050,21 +5887,22 @@ import { PublicKey as PublicKey10 } from "@dxos/keys";
6050
5887
  import { log as log18 } from "@dxos/log";
6051
5888
  import { InvitationOptions as InvitationOptions3 } from "@dxos/protocols/proto/dxos/halo/invitations";
6052
5889
  import { ComplexSet as ComplexSet4 } from "@dxos/util";
6053
- function _define_property19(obj, key, value) {
6054
- if (key in obj) {
6055
- Object.defineProperty(obj, key, {
6056
- value,
6057
- enumerable: true,
6058
- configurable: true,
6059
- writable: true
6060
- });
6061
- } else {
6062
- obj[key] = value;
6063
- }
6064
- return obj;
6065
- }
6066
5890
  var __dxlog_file22 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts";
6067
5891
  var InvitationTopology = class {
5892
+ _role;
5893
+ _controller;
5894
+ /**
5895
+ * Peers we tried to establish a connection with.
5896
+ * In invitation flow peers are assigned random ids when they join the swarm, so we'll retry
5897
+ * a peer if they reload an invitation.
5898
+ *
5899
+ * Consider keeping a separate set for peers we know are hosts and have some retry timeout
5900
+ * for guests we failed an invitation flow with (potentially due to a network error).
5901
+ */
5902
+ _seenPeers = new ComplexSet4(PublicKey10.hash);
5903
+ constructor(_role) {
5904
+ this._role = _role;
5905
+ }
6068
5906
  init(controller) {
6069
5907
  invariant16(!this._controller, "Already initialized.", {
6070
5908
  F: __dxlog_file22,
@@ -6129,33 +5967,24 @@ var InvitationTopology = class {
6129
5967
  toString() {
6130
5968
  return `InvitationTopology(${this._role === InvitationOptions3.Role.GUEST ? "guest" : "host"})`;
6131
5969
  }
6132
- constructor(_role) {
6133
- _define_property19(this, "_role", void 0);
6134
- _define_property19(this, "_controller", void 0);
6135
- _define_property19(this, "_seenPeers", void 0);
6136
- this._role = _role;
6137
- this._seenPeers = new ComplexSet4(PublicKey10.hash);
6138
- }
6139
5970
  };
6140
5971
 
6141
5972
  // src/packlets/invitations/invitations-handler.ts
6142
- function _define_property20(obj, key, value) {
6143
- if (key in obj) {
6144
- Object.defineProperty(obj, key, {
6145
- value,
6146
- enumerable: true,
6147
- configurable: true,
6148
- writable: true
6149
- });
6150
- } else {
6151
- obj[key] = value;
6152
- }
6153
- return obj;
6154
- }
6155
5973
  var __dxlog_file23 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts";
6156
5974
  var metrics = _trace.metrics;
6157
5975
  var MAX_DELEGATED_INVITATION_HOST_TRIES = 3;
6158
5976
  var InvitationsHandler = class {
5977
+ _networkManager;
5978
+ _edgeClient;
5979
+ _connectionParams;
5980
+ /**
5981
+ * @internal
5982
+ */
5983
+ constructor(_networkManager, _edgeClient, _connectionParams) {
5984
+ this._networkManager = _networkManager;
5985
+ this._edgeClient = _edgeClient;
5986
+ this._connectionParams = _connectionParams;
5987
+ }
6159
5988
  handleInvitationFlow(ctx, stream, protocol, invitation) {
6160
5989
  log19.verbose("dxos.sdk.invitations-handler.handleInvitationFlow", {
6161
5990
  state: invitation.state,
@@ -6726,17 +6555,6 @@ var InvitationsHandler = class {
6726
6555
  throw new Error(`Authentication failed with code: ${response.status}`);
6727
6556
  }
6728
6557
  }
6729
- /**
6730
- * @internal
6731
- */
6732
- constructor(_networkManager, _edgeClient, _connectionParams) {
6733
- _define_property20(this, "_networkManager", void 0);
6734
- _define_property20(this, "_edgeClient", void 0);
6735
- _define_property20(this, "_connectionParams", void 0);
6736
- this._networkManager = _networkManager;
6737
- this._edgeClient = _edgeClient;
6738
- this._connectionParams = _connectionParams;
6739
- }
6740
6558
  };
6741
6559
  var checkInvitation = (protocol, invitation) => {
6742
6560
  const expiresOn = getExpirationTime(invitation);
@@ -6757,20 +6575,11 @@ var createAdmissionKeypair = () => {
6757
6575
  import { Stream as Stream9 } from "@dxos/codec-protobuf/stream";
6758
6576
  import { QueryInvitationsResponse } from "@dxos/protocols/proto/dxos/client/services";
6759
6577
  import { trace as trace8 } from "@dxos/tracing";
6760
- function _define_property21(obj, key, value) {
6761
- if (key in obj) {
6762
- Object.defineProperty(obj, key, {
6763
- value,
6764
- enumerable: true,
6765
- configurable: true,
6766
- writable: true
6767
- });
6768
- } else {
6769
- obj[key] = value;
6770
- }
6771
- return obj;
6772
- }
6773
6578
  var InvitationsServiceImpl = class {
6579
+ _invitationsManager;
6580
+ constructor(_invitationsManager) {
6581
+ this._invitationsManager = _invitationsManager;
6582
+ }
6774
6583
  // TODO(burdon): Guest/host label.
6775
6584
  getLoggingContext() {
6776
6585
  return {};
@@ -6862,10 +6671,6 @@ var InvitationsServiceImpl = class {
6862
6671
  });
6863
6672
  });
6864
6673
  }
6865
- constructor(_invitationsManager) {
6866
- _define_property21(this, "_invitationsManager", void 0);
6867
- this._invitationsManager = _invitationsManager;
6868
- }
6869
6674
  };
6870
6675
 
6871
6676
  // src/packlets/invitations/space-invitation-protocol.ts
@@ -6876,21 +6681,18 @@ import { log as log20 } from "@dxos/log";
6876
6681
  import { AlreadyJoinedError as AlreadyJoinedError3, AuthorizationError as AuthorizationError2, InvalidInvitationError as InvalidInvitationError2, SpaceNotFoundError as SpaceNotFoundError2 } from "@dxos/protocols";
6877
6682
  import { Invitation as Invitation8 } from "@dxos/protocols/proto/dxos/client/services";
6878
6683
  import { SpaceMember as SpaceMember6 } from "@dxos/protocols/proto/dxos/halo/credentials";
6879
- function _define_property22(obj, key, value) {
6880
- if (key in obj) {
6881
- Object.defineProperty(obj, key, {
6882
- value,
6883
- enumerable: true,
6884
- configurable: true,
6885
- writable: true
6886
- });
6887
- } else {
6888
- obj[key] = value;
6889
- }
6890
- return obj;
6891
- }
6892
6684
  var __dxlog_file24 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
6893
6685
  var SpaceInvitationProtocol = class {
6686
+ _spaceManager;
6687
+ _signingContext;
6688
+ _keyring;
6689
+ _spaceKey;
6690
+ constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
6691
+ this._spaceManager = _spaceManager;
6692
+ this._signingContext = _signingContext;
6693
+ this._keyring = _keyring;
6694
+ this._spaceKey = _spaceKey;
6695
+ }
6894
6696
  toJSON() {
6895
6697
  return {
6896
6698
  kind: "space",
@@ -7155,16 +6957,6 @@ var SpaceInvitationProtocol = class {
7155
6957
  spaceKey: assertion.spaceKey
7156
6958
  };
7157
6959
  }
7158
- constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
7159
- _define_property22(this, "_spaceManager", void 0);
7160
- _define_property22(this, "_signingContext", void 0);
7161
- _define_property22(this, "_keyring", void 0);
7162
- _define_property22(this, "_spaceKey", void 0);
7163
- this._spaceManager = _spaceManager;
7164
- this._signingContext = _signingContext;
7165
- this._keyring = _keyring;
7166
- this._spaceKey = _spaceKey;
7167
- }
7168
6960
  };
7169
6961
 
7170
6962
  // src/packlets/invitations/invitations-manager.ts
@@ -7178,21 +6970,25 @@ import { PublicKey as PublicKey12 } from "@dxos/keys";
7178
6970
  import { log as log21 } from "@dxos/log";
7179
6971
  import { Invitation as Invitation9 } from "@dxos/protocols/proto/dxos/client/services";
7180
6972
  import { SpaceMember as SpaceMember7 } from "@dxos/protocols/proto/dxos/halo/credentials";
7181
- function _define_property23(obj, key, value) {
7182
- if (key in obj) {
7183
- Object.defineProperty(obj, key, {
7184
- value,
7185
- enumerable: true,
7186
- configurable: true,
7187
- writable: true
7188
- });
7189
- } else {
7190
- obj[key] = value;
7191
- }
7192
- return obj;
7193
- }
7194
6973
  var __dxlog_file25 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
7195
6974
  var InvitationsManager = class {
6975
+ _invitationsHandler;
6976
+ _getHandler;
6977
+ _metadataStore;
6978
+ _createInvitations = /* @__PURE__ */ new Map();
6979
+ _acceptInvitations = /* @__PURE__ */ new Map();
6980
+ invitationCreated = new Event8();
6981
+ invitationAccepted = new Event8();
6982
+ removedCreated = new Event8();
6983
+ removedAccepted = new Event8();
6984
+ saved = new Event8();
6985
+ _persistentInvitationsLoadedEvent = new Event8();
6986
+ _persistentInvitationsLoaded = false;
6987
+ constructor(_invitationsHandler, _getHandler, _metadataStore) {
6988
+ this._invitationsHandler = _invitationsHandler;
6989
+ this._getHandler = _getHandler;
6990
+ this._metadataStore = _metadataStore;
6991
+ }
7196
6992
  async createInvitation(options) {
7197
6993
  if (options.invitationId) {
7198
6994
  const existingInvitation = this._createInvitations.get(options.invitationId);
@@ -7536,51 +7332,12 @@ var InvitationsManager = class {
7536
7332
  }, () => {
7537
7333
  }, callback);
7538
7334
  }
7539
- constructor(_invitationsHandler, _getHandler, _metadataStore) {
7540
- _define_property23(this, "_invitationsHandler", void 0);
7541
- _define_property23(this, "_getHandler", void 0);
7542
- _define_property23(this, "_metadataStore", void 0);
7543
- _define_property23(this, "_createInvitations", void 0);
7544
- _define_property23(this, "_acceptInvitations", void 0);
7545
- _define_property23(this, "invitationCreated", void 0);
7546
- _define_property23(this, "invitationAccepted", void 0);
7547
- _define_property23(this, "removedCreated", void 0);
7548
- _define_property23(this, "removedAccepted", void 0);
7549
- _define_property23(this, "saved", void 0);
7550
- _define_property23(this, "_persistentInvitationsLoadedEvent", void 0);
7551
- _define_property23(this, "_persistentInvitationsLoaded", void 0);
7552
- this._invitationsHandler = _invitationsHandler;
7553
- this._getHandler = _getHandler;
7554
- this._metadataStore = _metadataStore;
7555
- this._createInvitations = /* @__PURE__ */ new Map();
7556
- this._acceptInvitations = /* @__PURE__ */ new Map();
7557
- this.invitationCreated = new Event8();
7558
- this.invitationAccepted = new Event8();
7559
- this.removedCreated = new Event8();
7560
- this.removedAccepted = new Event8();
7561
- this.saved = new Event8();
7562
- this._persistentInvitationsLoadedEvent = new Event8();
7563
- this._persistentInvitationsLoaded = false;
7564
- }
7565
7335
  };
7566
7336
 
7567
7337
  // src/packlets/locks/browser.ts
7568
7338
  import { Trigger as Trigger8, asyncTimeout as asyncTimeout2 } from "@dxos/async";
7569
7339
  import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
7570
7340
  import { log as log22, logInfo as logInfo3 } from "@dxos/log";
7571
- function _define_property24(obj, key, value) {
7572
- if (key in obj) {
7573
- Object.defineProperty(obj, key, {
7574
- value,
7575
- enumerable: true,
7576
- configurable: true,
7577
- writable: true
7578
- });
7579
- } else {
7580
- obj[key] = value;
7581
- }
7582
- return obj;
7583
- }
7584
7341
  function _ts_decorate7(decorators, target, key, desc) {
7585
7342
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
7586
7343
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -7589,6 +7346,17 @@ function _ts_decorate7(decorators, target, key, desc) {
7589
7346
  }
7590
7347
  var __dxlog_file26 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
7591
7348
  var Lock = class {
7349
+ _broadcastChannel = new BroadcastChannel("vault-resource-lock");
7350
+ _lockKey;
7351
+ _onAcquire;
7352
+ _onRelease;
7353
+ _releaseTrigger = new Trigger8();
7354
+ constructor({ lockKey, onAcquire, onRelease }) {
7355
+ this._lockKey = lockKey;
7356
+ this._onAcquire = onAcquire;
7357
+ this._onRelease = onRelease;
7358
+ this._broadcastChannel.onmessage = this._onMessage.bind(this);
7359
+ }
7592
7360
  get lockKey() {
7593
7361
  return this._lockKey;
7594
7362
  }
@@ -7677,17 +7445,6 @@ var Lock = class {
7677
7445
  C: (f, a) => f(...a)
7678
7446
  });
7679
7447
  }
7680
- constructor({ lockKey, onAcquire, onRelease }) {
7681
- _define_property24(this, "_broadcastChannel", new BroadcastChannel("vault-resource-lock"));
7682
- _define_property24(this, "_lockKey", void 0);
7683
- _define_property24(this, "_onAcquire", void 0);
7684
- _define_property24(this, "_onRelease", void 0);
7685
- _define_property24(this, "_releaseTrigger", new Trigger8());
7686
- this._lockKey = lockKey;
7687
- this._onAcquire = onAcquire;
7688
- this._onRelease = onRelease;
7689
- this._broadcastChannel.onmessage = this._onMessage.bind(this);
7690
- }
7691
7448
  };
7692
7449
  _ts_decorate7([
7693
7450
  logInfo3
@@ -7701,19 +7458,6 @@ import { Stream as Stream10 } from "@dxos/codec-protobuf";
7701
7458
  import { raise as raise2 } from "@dxos/debug";
7702
7459
  import { RpcPeer, parseMethodName } from "@dxos/rpc";
7703
7460
  import { MapCounter, trace as trace9 } from "@dxos/tracing";
7704
- function _define_property25(obj, key, value) {
7705
- if (key in obj) {
7706
- Object.defineProperty(obj, key, {
7707
- value,
7708
- enumerable: true,
7709
- configurable: true,
7710
- writable: true
7711
- });
7712
- } else {
7713
- obj[key] = value;
7714
- }
7715
- return obj;
7716
- }
7717
7461
  function _ts_decorate8(decorators, target, key, desc) {
7718
7462
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
7719
7463
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -7721,33 +7465,16 @@ function _ts_decorate8(decorators, target, key, desc) {
7721
7465
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7722
7466
  }
7723
7467
  var ClientRpcServer = class {
7468
+ _serviceRegistry;
7469
+ _rpcPeer;
7470
+ _handlerCache = /* @__PURE__ */ new Map();
7471
+ _handleCall;
7472
+ _handleStream;
7473
+ _callMetrics = new MapCounter();
7724
7474
  get _services() {
7725
7475
  return Object.keys(this._serviceRegistry.services);
7726
7476
  }
7727
- async open() {
7728
- await this._rpcPeer.open();
7729
- }
7730
- async close() {
7731
- await this._rpcPeer.close();
7732
- }
7733
- _getServiceHandler(serviceName) {
7734
- if (!this._handlerCache.has(serviceName)) {
7735
- const [key, descriptor] = Object.entries(this._serviceRegistry.descriptors).find(([key2, descriptor2]) => descriptor2.name === serviceName) ?? raise2(new Error(`Service not available: ${serviceName}`));
7736
- const service = this._serviceRegistry.services[key];
7737
- if (!service) {
7738
- throw new Error(`Service not available: ${serviceName}`);
7739
- }
7740
- this._handlerCache.set(serviceName, descriptor.createServer(service));
7741
- }
7742
- return this._handlerCache.get(serviceName);
7743
- }
7744
7477
  constructor(params) {
7745
- _define_property25(this, "_serviceRegistry", void 0);
7746
- _define_property25(this, "_rpcPeer", void 0);
7747
- _define_property25(this, "_handlerCache", /* @__PURE__ */ new Map());
7748
- _define_property25(this, "_handleCall", void 0);
7749
- _define_property25(this, "_handleStream", void 0);
7750
- _define_property25(this, "_callMetrics", new MapCounter());
7751
7478
  const { serviceRegistry, handleCall, handleStream, ...rpcOptions } = params;
7752
7479
  this._handleCall = handleCall;
7753
7480
  this._handleStream = handleStream;
@@ -7779,6 +7506,23 @@ var ClientRpcServer = class {
7779
7506
  }
7780
7507
  });
7781
7508
  }
7509
+ async open() {
7510
+ await this._rpcPeer.open();
7511
+ }
7512
+ async close() {
7513
+ await this._rpcPeer.close();
7514
+ }
7515
+ _getServiceHandler(serviceName) {
7516
+ if (!this._handlerCache.has(serviceName)) {
7517
+ const [key, descriptor] = Object.entries(this._serviceRegistry.descriptors).find(([key2, descriptor2]) => descriptor2.name === serviceName) ?? raise2(new Error(`Service not available: ${serviceName}`));
7518
+ const service = this._serviceRegistry.services[key];
7519
+ if (!service) {
7520
+ throw new Error(`Service not available: ${serviceName}`);
7521
+ }
7522
+ this._handlerCache.set(serviceName, descriptor.createServer(service));
7523
+ }
7524
+ return this._handlerCache.get(serviceName);
7525
+ }
7782
7526
  };
7783
7527
  _ts_decorate8([
7784
7528
  trace9.metricsCounter()
@@ -7799,19 +7543,6 @@ import { log as log23 } from "@dxos/log";
7799
7543
  import { EdgeAgentStatus, EdgeCallFailedError as EdgeCallFailedError3 } from "@dxos/protocols";
7800
7544
  import { SpaceState as SpaceState5 } from "@dxos/protocols/proto/dxos/client/services";
7801
7545
  import { EdgeReplicationSetting as EdgeReplicationSetting2 } from "@dxos/protocols/proto/dxos/echo/metadata";
7802
- function _define_property26(obj, key, value) {
7803
- if (key in obj) {
7804
- Object.defineProperty(obj, key, {
7805
- value,
7806
- enumerable: true,
7807
- configurable: true,
7808
- writable: true
7809
- });
7810
- } else {
7811
- obj[key] = value;
7812
- }
7813
- return obj;
7814
- }
7815
7546
  function _ts_decorate9(decorators, target, key, desc) {
7816
7547
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
7817
7548
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -7823,6 +7554,18 @@ var AGENT_STATUS_QUERY_RETRY_INTERVAL = 5e3;
7823
7554
  var AGENT_STATUS_QUERY_RETRY_JITTER = 1e3;
7824
7555
  var AGENT_FEED_ADDED_CHECK_INTERVAL_MS = 3e3;
7825
7556
  var EdgeAgentManager = class extends Resource7 {
7557
+ _edgeFeatures;
7558
+ _edgeHttpClient;
7559
+ _dataSpaceManager;
7560
+ _identity;
7561
+ agentStatusChanged = new Event9();
7562
+ _agentDeviceKey;
7563
+ _agentStatus;
7564
+ _lastKnownDeviceCount = 0;
7565
+ _fetchAgentStatusTask;
7566
+ constructor(_edgeFeatures, _edgeHttpClient, _dataSpaceManager, _identity) {
7567
+ super(), this._edgeFeatures = _edgeFeatures, this._edgeHttpClient = _edgeHttpClient, this._dataSpaceManager = _dataSpaceManager, this._identity = _identity;
7568
+ }
7826
7569
  get agentStatus() {
7827
7570
  return this._agentStatus;
7828
7571
  }
@@ -8031,9 +7774,6 @@ var EdgeAgentManager = class extends Resource7 {
8031
7774
  C: (f, a) => f(...a)
8032
7775
  });
8033
7776
  }
8034
- constructor(_edgeFeatures, _edgeHttpClient, _dataSpaceManager, _identity) {
8035
- super(), _define_property26(this, "_edgeFeatures", void 0), _define_property26(this, "_edgeHttpClient", void 0), _define_property26(this, "_dataSpaceManager", void 0), _define_property26(this, "_identity", void 0), _define_property26(this, "agentStatusChanged", void 0), _define_property26(this, "_agentDeviceKey", void 0), _define_property26(this, "_agentStatus", void 0), _define_property26(this, "_lastKnownDeviceCount", void 0), _define_property26(this, "_fetchAgentStatusTask", void 0), this._edgeFeatures = _edgeFeatures, this._edgeHttpClient = _edgeHttpClient, this._dataSpaceManager = _dataSpaceManager, this._identity = _identity, this.agentStatusChanged = new Event9(), this._lastKnownDeviceCount = 0;
8036
- }
8037
7777
  };
8038
7778
  _ts_decorate9([
8039
7779
  synchronized3
@@ -8043,26 +7783,27 @@ _ts_decorate9([
8043
7783
  import { Stream as Stream11 } from "@dxos/codec-protobuf/stream";
8044
7784
  import { EdgeAgentStatus as EdgeAgentStatus2 } from "@dxos/protocols";
8045
7785
  import { EdgeStatus as EdgeStatus2, QueryAgentStatusResponse } from "@dxos/protocols/proto/dxos/client/services";
8046
- function _define_property27(obj, key, value) {
8047
- if (key in obj) {
8048
- Object.defineProperty(obj, key, {
8049
- value,
8050
- enumerable: true,
8051
- configurable: true,
8052
- writable: true
8053
- });
8054
- } else {
8055
- obj[key] = value;
8056
- }
8057
- return obj;
8058
- }
8059
7786
  var EdgeAgentServiceImpl = class {
7787
+ _agentManagerProvider;
7788
+ _edgeConnection;
7789
+ constructor(_agentManagerProvider, _edgeConnection) {
7790
+ this._agentManagerProvider = _agentManagerProvider;
7791
+ this._edgeConnection = _edgeConnection;
7792
+ }
8060
7793
  // TODO(mykola): Reconcile with NetworkService.queryStatus.
8061
7794
  queryEdgeStatus() {
8062
7795
  return new Stream11(({ ctx, next }) => {
8063
7796
  const update = () => {
8064
7797
  next({
8065
- status: this._edgeConnection?.status ?? EdgeStatus2.NOT_CONNECTED
7798
+ status: this._edgeConnection?.status ?? {
7799
+ state: EdgeStatus2.ConnectionState.NOT_CONNECTED,
7800
+ rtt: 0,
7801
+ uptime: 0,
7802
+ rateBytesUp: 0,
7803
+ rateBytesDown: 0,
7804
+ messagesSent: 0,
7805
+ messagesReceived: 0
7806
+ }
8066
7807
  });
8067
7808
  };
8068
7809
  this._edgeConnection?.statusChanged.on(ctx, update);
@@ -8089,12 +7830,6 @@ var EdgeAgentServiceImpl = class {
8089
7830
  });
8090
7831
  });
8091
7832
  }
8092
- constructor(_agentManagerProvider, _edgeConnection) {
8093
- _define_property27(this, "_agentManagerProvider", void 0);
8094
- _define_property27(this, "_edgeConnection", void 0);
8095
- this._agentManagerProvider = _agentManagerProvider;
8096
- this._edgeConnection = _edgeConnection;
8097
- }
8098
7833
  };
8099
7834
  var mapStatus = (agentStatus) => {
8100
7835
  switch (agentStatus) {
@@ -8136,21 +7871,18 @@ import { log as log24 } from "@dxos/log";
8136
7871
  import { EdgeAuthChallengeError as EdgeAuthChallengeError2 } from "@dxos/protocols";
8137
7872
  import { schema as schema6 } from "@dxos/protocols/proto";
8138
7873
  import { Timeframe as Timeframe5 } from "@dxos/timeframe";
8139
- function _define_property28(obj, key, value) {
8140
- if (key in obj) {
8141
- Object.defineProperty(obj, key, {
8142
- value,
8143
- enumerable: true,
8144
- configurable: true,
8145
- writable: true
8146
- });
8147
- } else {
8148
- obj[key] = value;
8149
- }
8150
- return obj;
8151
- }
8152
7874
  var __dxlog_file28 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-recovery-manager.ts";
8153
7875
  var EdgeIdentityRecoveryManager = class {
7876
+ _keyring;
7877
+ _edgeClient;
7878
+ _identityProvider;
7879
+ _acceptRecoveredIdentity;
7880
+ constructor(_keyring, _edgeClient, _identityProvider, _acceptRecoveredIdentity) {
7881
+ this._keyring = _keyring;
7882
+ this._edgeClient = _edgeClient;
7883
+ this._identityProvider = _identityProvider;
7884
+ this._acceptRecoveredIdentity = _acceptRecoveredIdentity;
7885
+ }
8154
7886
  async createRecoveryCredential({ data }) {
8155
7887
  const identity = this._identityProvider();
8156
7888
  invariant21(identity, void 0, {
@@ -8343,16 +8075,6 @@ var EdgeIdentityRecoveryManager = class {
8343
8075
  dataFeedKey: await this._keyring.createKey()
8344
8076
  });
8345
8077
  }
8346
- constructor(_keyring, _edgeClient, _identityProvider, _acceptRecoveredIdentity) {
8347
- _define_property28(this, "_keyring", void 0);
8348
- _define_property28(this, "_edgeClient", void 0);
8349
- _define_property28(this, "_identityProvider", void 0);
8350
- _define_property28(this, "_acceptRecoveredIdentity", void 0);
8351
- this._keyring = _keyring;
8352
- this._edgeClient = _edgeClient;
8353
- this._identityProvider = _identityProvider;
8354
- this._acceptRecoveredIdentity = _acceptRecoveredIdentity;
8355
- }
8356
8078
  };
8357
8079
  var decodeCredential = (credentialBase64) => {
8358
8080
  const credentialBytes = Buffer.from(credentialBase64, "base64");
@@ -8361,19 +8083,6 @@ var decodeCredential = (credentialBase64) => {
8361
8083
  };
8362
8084
 
8363
8085
  // src/packlets/services/service-context.ts
8364
- function _define_property29(obj, key, value) {
8365
- if (key in obj) {
8366
- Object.defineProperty(obj, key, {
8367
- value,
8368
- enumerable: true,
8369
- configurable: true,
8370
- writable: true
8371
- });
8372
- } else {
8373
- obj[key] = value;
8374
- }
8375
- return obj;
8376
- }
8377
8086
  function _ts_decorate10(decorators, target, key, desc) {
8378
8087
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
8379
8088
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -8447,25 +8156,108 @@ function _ts_dispose_resources4(env) {
8447
8156
  }
8448
8157
  var __dxlog_file29 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
8449
8158
  var ServiceContext = class extends Resource8 {
8450
- async _open(ctx) {
8451
- await this._checkStorageVersion();
8452
- log25("opening...", void 0, {
8453
- F: __dxlog_file29,
8454
- L: 204,
8455
- S: this,
8456
- C: (f, a) => f(...a)
8159
+ storage;
8160
+ level;
8161
+ networkManager;
8162
+ signalManager;
8163
+ _edgeConnection;
8164
+ _edgeHttpClient;
8165
+ _runtimeParams;
8166
+ _edgeFeatures;
8167
+ _edgeIdentityUpdateMutex = new Mutex4();
8168
+ initialized = new Trigger9();
8169
+ metadataStore;
8170
+ blobStore;
8171
+ feedStore;
8172
+ keyring;
8173
+ spaceManager;
8174
+ identityManager;
8175
+ recoveryManager;
8176
+ invitations;
8177
+ invitationsManager;
8178
+ echoHost;
8179
+ _meshReplicator = void 0;
8180
+ _echoEdgeReplicator = void 0;
8181
+ // Initialized after identity is initialized.
8182
+ dataSpaceManager;
8183
+ edgeAgentManager;
8184
+ _handlerFactories = /* @__PURE__ */ new Map();
8185
+ _deviceSpaceSync;
8186
+ _instanceId = PublicKey15.random().toHex();
8187
+ constructor(storage, level, networkManager, signalManager, _edgeConnection, _edgeHttpClient, _runtimeParams, _edgeFeatures) {
8188
+ super(), this.storage = storage, this.level = level, this.networkManager = networkManager, this.signalManager = signalManager, this._edgeConnection = _edgeConnection, this._edgeHttpClient = _edgeHttpClient, this._runtimeParams = _runtimeParams, this._edgeFeatures = _edgeFeatures;
8189
+ this.metadataStore = new MetadataStore(storage.createDirectory("metadata"));
8190
+ this.blobStore = new BlobStore(storage.createDirectory("blobs"));
8191
+ this.keyring = new Keyring(storage.createDirectory("keyring"));
8192
+ this.feedStore = new FeedStore({
8193
+ factory: new FeedFactory({
8194
+ root: storage.createDirectory("feeds"),
8195
+ signer: this.keyring,
8196
+ hypercore: {
8197
+ valueEncoding,
8198
+ stats: true
8199
+ }
8200
+ })
8457
8201
  });
8458
- log25.trace("dxos.sdk.service-context.open", trace10.begin({
8459
- id: this._instanceId
8460
- }), {
8461
- F: __dxlog_file29,
8462
- L: 205,
8463
- S: this,
8464
- C: (f, a) => f(...a)
8202
+ this.spaceManager = new SpaceManager({
8203
+ feedStore: this.feedStore,
8204
+ networkManager: this.networkManager,
8205
+ blobStore: this.blobStore,
8206
+ metadataStore: this.metadataStore,
8207
+ disableP2pReplication: this._runtimeParams?.disableP2pReplication
8465
8208
  });
8466
- await this.identityManager.open(ctx);
8467
- await this._setNetworkIdentity();
8468
- await this._edgeConnection?.open();
8209
+ this.identityManager = new IdentityManager({
8210
+ metadataStore: this.metadataStore,
8211
+ keyring: this.keyring,
8212
+ feedStore: this.feedStore,
8213
+ spaceManager: this.spaceManager,
8214
+ devicePresenceOfflineTimeout: this._runtimeParams?.devicePresenceOfflineTimeout,
8215
+ devicePresenceAnnounceInterval: this._runtimeParams?.devicePresenceAnnounceInterval,
8216
+ edgeConnection: this._edgeConnection,
8217
+ edgeFeatures: this._edgeFeatures
8218
+ });
8219
+ this.recoveryManager = new EdgeIdentityRecoveryManager(this.keyring, this._edgeHttpClient, () => this.identityManager.identity, this._acceptIdentity.bind(this));
8220
+ this.echoHost = new EchoHost({
8221
+ kv: this.level,
8222
+ peerIdProvider: () => this.identityManager.identity?.deviceKey?.toHex(),
8223
+ getSpaceKeyByRootDocumentId: (documentId) => this.spaceManager.findSpaceByRootDocumentId(documentId)?.key,
8224
+ indexing: {
8225
+ vector: this._runtimeParams?.enableVectorIndexing
8226
+ }
8227
+ });
8228
+ this._meshReplicator = new MeshEchoReplicator();
8229
+ this.invitations = new InvitationsHandler(this.networkManager, this._edgeHttpClient, _runtimeParams?.invitationConnectionDefaultParams);
8230
+ this.invitationsManager = new InvitationsManager(this.invitations, (invitation) => this.getInvitationHandler(invitation), this.metadataStore);
8231
+ this._handlerFactories.set(Invitation10.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined2(), this._acceptIdentity.bind(this)));
8232
+ if (!this._runtimeParams?.disableP2pReplication) {
8233
+ this._meshReplicator = new MeshEchoReplicator();
8234
+ }
8235
+ if (this._edgeConnection && this._edgeFeatures?.echoReplicator && this._edgeHttpClient) {
8236
+ this._echoEdgeReplicator = new EchoEdgeReplicator({
8237
+ edgeConnection: this._edgeConnection,
8238
+ edgeHttpClient: this._edgeHttpClient
8239
+ });
8240
+ }
8241
+ }
8242
+ async _open(ctx) {
8243
+ await this._checkStorageVersion();
8244
+ log25("opening...", void 0, {
8245
+ F: __dxlog_file29,
8246
+ L: 204,
8247
+ S: this,
8248
+ C: (f, a) => f(...a)
8249
+ });
8250
+ log25.trace("dxos.sdk.service-context.open", trace10.begin({
8251
+ id: this._instanceId
8252
+ }), {
8253
+ F: __dxlog_file29,
8254
+ L: 205,
8255
+ S: this,
8256
+ C: (f, a) => f(...a)
8257
+ });
8258
+ await this.identityManager.open(ctx);
8259
+ await this._setNetworkIdentity();
8260
+ await this._edgeConnection?.open();
8469
8261
  await this.signalManager.open();
8470
8262
  await this.networkManager.open();
8471
8263
  await this.echoHost.open(ctx);
@@ -8749,62 +8541,6 @@ var ServiceContext = class extends Resource8 {
8749
8541
  _ts_dispose_resources4(env);
8750
8542
  }
8751
8543
  }
8752
- constructor(storage, level, networkManager, signalManager, _edgeConnection, _edgeHttpClient, _runtimeParams, _edgeFeatures) {
8753
- super(), _define_property29(this, "storage", void 0), _define_property29(this, "level", void 0), _define_property29(this, "networkManager", void 0), _define_property29(this, "signalManager", void 0), _define_property29(this, "_edgeConnection", void 0), _define_property29(this, "_edgeHttpClient", void 0), _define_property29(this, "_runtimeParams", void 0), _define_property29(this, "_edgeFeatures", void 0), _define_property29(this, "_edgeIdentityUpdateMutex", void 0), _define_property29(this, "initialized", void 0), _define_property29(this, "metadataStore", void 0), _define_property29(this, "blobStore", void 0), _define_property29(this, "feedStore", void 0), _define_property29(this, "keyring", void 0), _define_property29(this, "spaceManager", void 0), _define_property29(this, "identityManager", void 0), _define_property29(this, "recoveryManager", void 0), _define_property29(this, "invitations", void 0), _define_property29(this, "invitationsManager", void 0), _define_property29(this, "echoHost", void 0), _define_property29(this, "_meshReplicator", void 0), _define_property29(this, "_echoEdgeReplicator", void 0), // Initialized after identity is initialized.
8754
- _define_property29(this, "dataSpaceManager", void 0), _define_property29(this, "edgeAgentManager", void 0), _define_property29(this, "_handlerFactories", void 0), _define_property29(this, "_deviceSpaceSync", void 0), _define_property29(this, "_instanceId", void 0), this.storage = storage, this.level = level, this.networkManager = networkManager, this.signalManager = signalManager, this._edgeConnection = _edgeConnection, this._edgeHttpClient = _edgeHttpClient, this._runtimeParams = _runtimeParams, this._edgeFeatures = _edgeFeatures, this._edgeIdentityUpdateMutex = new Mutex4(), this.initialized = new Trigger9(), this._meshReplicator = void 0, this._echoEdgeReplicator = void 0, this._handlerFactories = /* @__PURE__ */ new Map(), this._instanceId = PublicKey15.random().toHex();
8755
- this.metadataStore = new MetadataStore(storage.createDirectory("metadata"));
8756
- this.blobStore = new BlobStore(storage.createDirectory("blobs"));
8757
- this.keyring = new Keyring(storage.createDirectory("keyring"));
8758
- this.feedStore = new FeedStore({
8759
- factory: new FeedFactory({
8760
- root: storage.createDirectory("feeds"),
8761
- signer: this.keyring,
8762
- hypercore: {
8763
- valueEncoding,
8764
- stats: true
8765
- }
8766
- })
8767
- });
8768
- this.spaceManager = new SpaceManager({
8769
- feedStore: this.feedStore,
8770
- networkManager: this.networkManager,
8771
- blobStore: this.blobStore,
8772
- metadataStore: this.metadataStore,
8773
- disableP2pReplication: this._runtimeParams?.disableP2pReplication
8774
- });
8775
- this.identityManager = new IdentityManager({
8776
- metadataStore: this.metadataStore,
8777
- keyring: this.keyring,
8778
- feedStore: this.feedStore,
8779
- spaceManager: this.spaceManager,
8780
- devicePresenceOfflineTimeout: this._runtimeParams?.devicePresenceOfflineTimeout,
8781
- devicePresenceAnnounceInterval: this._runtimeParams?.devicePresenceAnnounceInterval,
8782
- edgeConnection: this._edgeConnection,
8783
- edgeFeatures: this._edgeFeatures
8784
- });
8785
- this.recoveryManager = new EdgeIdentityRecoveryManager(this.keyring, this._edgeHttpClient, () => this.identityManager.identity, this._acceptIdentity.bind(this));
8786
- this.echoHost = new EchoHost({
8787
- kv: this.level,
8788
- peerIdProvider: () => this.identityManager.identity?.deviceKey?.toHex(),
8789
- getSpaceKeyByRootDocumentId: (documentId) => this.spaceManager.findSpaceByRootDocumentId(documentId)?.key,
8790
- indexing: {
8791
- vector: this._runtimeParams?.enableVectorIndexing
8792
- }
8793
- });
8794
- this._meshReplicator = new MeshEchoReplicator();
8795
- this.invitations = new InvitationsHandler(this.networkManager, this._edgeHttpClient, _runtimeParams?.invitationConnectionDefaultParams);
8796
- this.invitationsManager = new InvitationsManager(this.invitations, (invitation) => this.getInvitationHandler(invitation), this.metadataStore);
8797
- this._handlerFactories.set(Invitation10.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined2(), this._acceptIdentity.bind(this)));
8798
- if (!this._runtimeParams?.disableP2pReplication) {
8799
- this._meshReplicator = new MeshEchoReplicator();
8800
- }
8801
- if (this._edgeConnection && this._edgeFeatures?.echoReplicator && this._edgeHttpClient) {
8802
- this._echoEdgeReplicator = new EchoEdgeReplicator({
8803
- edgeConnection: this._edgeConnection,
8804
- edgeHttpClient: this._edgeHttpClient
8805
- });
8806
- }
8807
- }
8808
8544
  };
8809
8545
  _ts_decorate10([
8810
8546
  Trace3.span()
@@ -9051,20 +8787,14 @@ var importProfileData = async ({ storage, level }, archive) => {
9051
8787
  };
9052
8788
 
9053
8789
  // src/packlets/services/service-registry.ts
9054
- function _define_property30(obj, key, value) {
9055
- if (key in obj) {
9056
- Object.defineProperty(obj, key, {
9057
- value,
9058
- enumerable: true,
9059
- configurable: true,
9060
- writable: true
9061
- });
9062
- } else {
9063
- obj[key] = value;
9064
- }
9065
- return obj;
9066
- }
9067
8790
  var ServiceRegistry = class {
8791
+ _serviceBundle;
8792
+ _handlers;
8793
+ // prettier-ignore
8794
+ constructor(_serviceBundle, _handlers = {}) {
8795
+ this._serviceBundle = _serviceBundle;
8796
+ this._handlers = _handlers;
8797
+ }
9068
8798
  get descriptors() {
9069
8799
  return this._serviceBundle;
9070
8800
  }
@@ -9080,13 +8810,6 @@ var ServiceRegistry = class {
9080
8810
  removeService(name) {
9081
8811
  delete this._handlers[name];
9082
8812
  }
9083
- // prettier-ignore
9084
- constructor(_serviceBundle, _handlers = {}) {
9085
- _define_property30(this, "_serviceBundle", void 0);
9086
- _define_property30(this, "_handlers", void 0);
9087
- this._serviceBundle = _serviceBundle;
9088
- this._handlers = _handlers;
9089
- }
9090
8813
  };
9091
8814
 
9092
8815
  // src/packlets/services/service-host.ts
@@ -9109,21 +8832,14 @@ import { SubscriptionList as SubscriptionList3 } from "@dxos/async";
9109
8832
  import { Stream as Stream12 } from "@dxos/codec-protobuf/stream";
9110
8833
  import { invariant as invariant24 } from "@dxos/invariant";
9111
8834
  import { Device as Device2, DeviceKind as DeviceKind2, EdgeStatus as EdgeStatus3 } from "@dxos/protocols/proto/dxos/client/services";
9112
- function _define_property31(obj, key, value) {
9113
- if (key in obj) {
9114
- Object.defineProperty(obj, key, {
9115
- value,
9116
- enumerable: true,
9117
- configurable: true,
9118
- writable: true
9119
- });
9120
- } else {
9121
- obj[key] = value;
9122
- }
9123
- return obj;
9124
- }
9125
8835
  var __dxlog_file31 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
9126
8836
  var DevicesServiceImpl = class {
8837
+ _identityManager;
8838
+ _edgeConnection;
8839
+ constructor(_identityManager, _edgeConnection) {
8840
+ this._identityManager = _identityManager;
8841
+ this._edgeConnection = _edgeConnection;
8842
+ }
9127
8843
  async updateDevice(profile) {
9128
8844
  return this._identityManager.updateDeviceProfile(profile);
9129
8845
  }
@@ -9153,7 +8869,7 @@ var DevicesServiceImpl = class {
9153
8869
  if (isMe) {
9154
8870
  presence = Device2.PresenceState.ONLINE;
9155
8871
  } else if (profile.os?.toUpperCase() === "EDGE") {
9156
- presence = this._edgeConnection?.status === EdgeStatus3.CONNECTED ? Device2.PresenceState.ONLINE : Device2.PresenceState.OFFLINE;
8872
+ presence = this._edgeConnection?.status.state === EdgeStatus3.ConnectionState.CONNECTED ? Device2.PresenceState.ONLINE : Device2.PresenceState.OFFLINE;
9157
8873
  } else {
9158
8874
  presence = peers.some((peer) => peer.identityKey.equals(key)) ? Device2.PresenceState.ONLINE : Device2.PresenceState.OFFLINE;
9159
8875
  }
@@ -9201,12 +8917,6 @@ var DevicesServiceImpl = class {
9201
8917
  return () => subscriptions.clear();
9202
8918
  });
9203
8919
  }
9204
- constructor(_identityManager, _edgeConnection) {
9205
- _define_property31(this, "_identityManager", void 0);
9206
- _define_property31(this, "_edgeConnection", void 0);
9207
- this._identityManager = _identityManager;
9208
- this._edgeConnection = _edgeConnection;
9209
- }
9210
8920
  };
9211
8921
 
9212
8922
  // src/packlets/identity/contacts-service.ts
@@ -9214,20 +8924,15 @@ import { SubscriptionList as SubscriptionList4, UpdateScheduler as UpdateSchedul
9214
8924
  import { Stream as Stream13 } from "@dxos/codec-protobuf/stream";
9215
8925
  import { PublicKey as PublicKey17 } from "@dxos/keys";
9216
8926
  import { ComplexMap as ComplexMap5, ComplexSet as ComplexSet6 } from "@dxos/util";
9217
- function _define_property32(obj, key, value) {
9218
- if (key in obj) {
9219
- Object.defineProperty(obj, key, {
9220
- value,
9221
- enumerable: true,
9222
- configurable: true,
9223
- writable: true
9224
- });
9225
- } else {
9226
- obj[key] = value;
9227
- }
9228
- return obj;
9229
- }
9230
8927
  var ContactsServiceImpl = class {
8928
+ _identityManager;
8929
+ _spaceManager;
8930
+ _dataSpaceManagerProvider;
8931
+ constructor(_identityManager, _spaceManager, _dataSpaceManagerProvider) {
8932
+ this._identityManager = _identityManager;
8933
+ this._spaceManager = _spaceManager;
8934
+ this._dataSpaceManagerProvider = _dataSpaceManagerProvider;
8935
+ }
9231
8936
  async getContacts() {
9232
8937
  const identity = this._identityManager.identity;
9233
8938
  if (identity == null) {
@@ -9249,8 +8954,7 @@ var ContactsServiceImpl = class {
9249
8954
  }
9250
8955
  const existing = acc.get(memberInfo.key);
9251
8956
  if (existing != null) {
9252
- var _existing;
9253
- (_existing = existing).profile ?? (_existing.profile = memberInfo.profile);
8957
+ existing.profile ??= memberInfo.profile;
9254
8958
  existing.commonSpaces?.push(spaceKey);
9255
8959
  } else {
9256
8960
  acc.set(memberInfo.key, {
@@ -9299,14 +9003,6 @@ var ContactsServiceImpl = class {
9299
9003
  });
9300
9004
  });
9301
9005
  }
9302
- constructor(_identityManager, _spaceManager, _dataSpaceManagerProvider) {
9303
- _define_property32(this, "_identityManager", void 0);
9304
- _define_property32(this, "_spaceManager", void 0);
9305
- _define_property32(this, "_dataSpaceManagerProvider", void 0);
9306
- this._identityManager = _identityManager;
9307
- this._spaceManager = _spaceManager;
9308
- this._dataSpaceManagerProvider = _dataSpaceManagerProvider;
9309
- }
9310
9006
  };
9311
9007
 
9312
9008
  // src/packlets/logging/logging-service.ts
@@ -9316,20 +9012,10 @@ import { PublicKey as PublicKey18 } from "@dxos/keys";
9316
9012
  import { getContextFromEntry, log as log27 } from "@dxos/log";
9317
9013
  import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
9318
9014
  import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
9319
- function _define_property33(obj, key, value) {
9320
- if (key in obj) {
9321
- Object.defineProperty(obj, key, {
9322
- value,
9323
- enumerable: true,
9324
- configurable: true,
9325
- writable: true
9326
- });
9327
- } else {
9328
- obj[key] = value;
9329
- }
9330
- return obj;
9331
- }
9332
9015
  var LoggingServiceImpl = class {
9016
+ _logs = new Event10();
9017
+ _started = Date.now();
9018
+ _sessionId = PublicKey18.random().toHex();
9333
9019
  async open() {
9334
9020
  log27.runtimeConfig.processors.push(this._logProcessor);
9335
9021
  }
@@ -9420,14 +9106,9 @@ var LoggingServiceImpl = class {
9420
9106
  this._logs.on(ctx, handler);
9421
9107
  });
9422
9108
  }
9423
- constructor() {
9424
- _define_property33(this, "_logs", new Event10());
9425
- _define_property33(this, "_started", Date.now());
9426
- _define_property33(this, "_sessionId", PublicKey18.random().toHex());
9427
- _define_property33(this, "_logProcessor", (_config, entry2) => {
9428
- this._logs.emit(entry2);
9429
- });
9430
- }
9109
+ _logProcessor = (_config, entry2) => {
9110
+ this._logs.emit(entry2);
9111
+ };
9431
9112
  };
9432
9113
  var matchFilter = (filter, level, path2, options) => {
9433
9114
  switch (options) {
@@ -9449,20 +9130,15 @@ var LOG_PROCESSING = 0;
9449
9130
 
9450
9131
  // src/packlets/network/network-service.ts
9451
9132
  import { Stream as Stream15 } from "@dxos/codec-protobuf/stream";
9452
- function _define_property34(obj, key, value) {
9453
- if (key in obj) {
9454
- Object.defineProperty(obj, key, {
9455
- value,
9456
- enumerable: true,
9457
- configurable: true,
9458
- writable: true
9459
- });
9460
- } else {
9461
- obj[key] = value;
9462
- }
9463
- return obj;
9464
- }
9465
9133
  var NetworkServiceImpl = class {
9134
+ networkManager;
9135
+ signalManager;
9136
+ edgeConnection;
9137
+ constructor(networkManager, signalManager, edgeConnection) {
9138
+ this.networkManager = networkManager;
9139
+ this.signalManager = signalManager;
9140
+ this.edgeConnection = edgeConnection;
9141
+ }
9466
9142
  queryStatus() {
9467
9143
  return new Stream15(({ ctx, next }) => {
9468
9144
  const update = () => {
@@ -9513,34 +9189,27 @@ var NetworkServiceImpl = class {
9513
9189
  });
9514
9190
  });
9515
9191
  }
9516
- constructor(networkManager, signalManager, edgeConnection) {
9517
- _define_property34(this, "networkManager", void 0);
9518
- _define_property34(this, "signalManager", void 0);
9519
- _define_property34(this, "edgeConnection", void 0);
9520
- this.networkManager = networkManager;
9521
- this.signalManager = signalManager;
9522
- this.edgeConnection = edgeConnection;
9523
- }
9524
9192
  };
9525
9193
 
9526
9194
  // src/packlets/system/system-service.ts
9527
9195
  import { Stream as Stream16 } from "@dxos/codec-protobuf/stream";
9528
9196
  import { GetDiagnosticsRequest as GetDiagnosticsRequest2 } from "@dxos/protocols/proto/dxos/client/services";
9529
9197
  import { jsonKeyReplacer as jsonKeyReplacer2 } from "@dxos/util";
9530
- function _define_property35(obj, key, value) {
9531
- if (key in obj) {
9532
- Object.defineProperty(obj, key, {
9533
- value,
9534
- enumerable: true,
9535
- configurable: true,
9536
- writable: true
9537
- });
9538
- } else {
9539
- obj[key] = value;
9540
- }
9541
- return obj;
9542
- }
9543
9198
  var SystemServiceImpl = class {
9199
+ _config;
9200
+ _statusUpdate;
9201
+ _getCurrentStatus;
9202
+ _onUpdateStatus;
9203
+ _onReset;
9204
+ _getDiagnostics;
9205
+ constructor({ config, statusUpdate, getDiagnostics, onUpdateStatus, getCurrentStatus, onReset }) {
9206
+ this._config = config;
9207
+ this._statusUpdate = statusUpdate;
9208
+ this._getCurrentStatus = getCurrentStatus;
9209
+ this._getDiagnostics = getDiagnostics;
9210
+ this._onUpdateStatus = onUpdateStatus;
9211
+ this._onReset = onReset;
9212
+ }
9544
9213
  async getConfig() {
9545
9214
  return (await this._config?.())?.values ?? {};
9546
9215
  }
@@ -9583,36 +9252,9 @@ var SystemServiceImpl = class {
9583
9252
  async reset() {
9584
9253
  await this._onReset();
9585
9254
  }
9586
- constructor({ config, statusUpdate, getDiagnostics, onUpdateStatus, getCurrentStatus, onReset }) {
9587
- _define_property35(this, "_config", void 0);
9588
- _define_property35(this, "_statusUpdate", void 0);
9589
- _define_property35(this, "_getCurrentStatus", void 0);
9590
- _define_property35(this, "_onUpdateStatus", void 0);
9591
- _define_property35(this, "_onReset", void 0);
9592
- _define_property35(this, "_getDiagnostics", void 0);
9593
- this._config = config;
9594
- this._statusUpdate = statusUpdate;
9595
- this._getCurrentStatus = getCurrentStatus;
9596
- this._getDiagnostics = getDiagnostics;
9597
- this._onUpdateStatus = onUpdateStatus;
9598
- this._onReset = onReset;
9599
- }
9600
9255
  };
9601
9256
 
9602
9257
  // src/packlets/services/service-host.ts
9603
- function _define_property36(obj, key, value) {
9604
- if (key in obj) {
9605
- Object.defineProperty(obj, key, {
9606
- value,
9607
- enumerable: true,
9608
- configurable: true,
9609
- writable: true
9610
- });
9611
- } else {
9612
- obj[key] = value;
9613
- }
9614
- return obj;
9615
- }
9616
9258
  function _ts_decorate11(decorators, target, key, desc) {
9617
9259
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
9618
9260
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -9621,6 +9263,94 @@ function _ts_decorate11(decorators, target, key, desc) {
9621
9263
  }
9622
9264
  var __dxlog_file32 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
9623
9265
  var ClientServicesHost = class {
9266
+ _resourceLock;
9267
+ _serviceRegistry;
9268
+ _systemService;
9269
+ _loggingService;
9270
+ _tracingService = TRACE_PROCESSOR3.createTraceSender();
9271
+ _statusUpdate = new Event11();
9272
+ _config;
9273
+ _signalManager;
9274
+ _networkManager;
9275
+ _storage;
9276
+ _level;
9277
+ _callbacks;
9278
+ _devtoolsProxy;
9279
+ _edgeConnection = void 0;
9280
+ _edgeHttpClient = void 0;
9281
+ _serviceContext;
9282
+ _runtimeParams;
9283
+ diagnosticsBroadcastHandler;
9284
+ _opening = false;
9285
+ _open = false;
9286
+ _resetting = false;
9287
+ constructor({
9288
+ config,
9289
+ transportFactory,
9290
+ signalManager,
9291
+ storage,
9292
+ level,
9293
+ // TODO(wittjosiah): Turn this on by default.
9294
+ lockKey,
9295
+ callbacks,
9296
+ runtimeParams
9297
+ } = {}) {
9298
+ this._storage = storage;
9299
+ this._level = level;
9300
+ this._callbacks = callbacks;
9301
+ this._runtimeParams = runtimeParams ?? {};
9302
+ if (this._runtimeParams.disableP2pReplication === void 0) {
9303
+ this._runtimeParams.disableP2pReplication = config?.get("runtime.client.disableP2pReplication", false);
9304
+ }
9305
+ if (this._runtimeParams.enableVectorIndexing === void 0) {
9306
+ this._runtimeParams.enableVectorIndexing = config?.get("runtime.client.enableVectorIndexing", false);
9307
+ }
9308
+ if (config) {
9309
+ this.initialize({
9310
+ config,
9311
+ transportFactory,
9312
+ signalManager
9313
+ });
9314
+ }
9315
+ if (lockKey) {
9316
+ this._resourceLock = new Lock({
9317
+ lockKey,
9318
+ onAcquire: () => {
9319
+ if (!this._opening) {
9320
+ void this.open(new Context11(void 0, {
9321
+ F: __dxlog_file32,
9322
+ L: 143
9323
+ }));
9324
+ }
9325
+ },
9326
+ onRelease: () => this.close()
9327
+ });
9328
+ }
9329
+ this._systemService = new SystemServiceImpl({
9330
+ config: () => this._config,
9331
+ statusUpdate: this._statusUpdate,
9332
+ getCurrentStatus: () => this.isOpen && !this._resetting ? SystemStatus.ACTIVE : SystemStatus.INACTIVE,
9333
+ getDiagnostics: () => {
9334
+ return createDiagnostics(this._serviceRegistry.services, this._serviceContext, this._config);
9335
+ },
9336
+ onUpdateStatus: async (status) => {
9337
+ if (!this.isOpen && status === SystemStatus.ACTIVE) {
9338
+ await this._resourceLock?.acquire();
9339
+ } else if (this.isOpen && status === SystemStatus.INACTIVE) {
9340
+ await this._resourceLock?.release();
9341
+ }
9342
+ },
9343
+ onReset: async () => {
9344
+ await this.reset();
9345
+ }
9346
+ });
9347
+ this.diagnosticsBroadcastHandler = createCollectDiagnosticsBroadcastHandler(this._systemService);
9348
+ this._loggingService = new LoggingServiceImpl();
9349
+ this._serviceRegistry = new ServiceRegistry(clientServiceBundle, {
9350
+ SystemService: this._systemService,
9351
+ TracingService: this._tracingService
9352
+ });
9353
+ }
9624
9354
  get isOpen() {
9625
9355
  return this._open;
9626
9356
  }
@@ -9894,10 +9624,22 @@ var ClientServicesHost = class {
9894
9624
  this._resetting = true;
9895
9625
  this._statusUpdate.emit();
9896
9626
  await this._serviceContext?.close();
9627
+ try {
9628
+ await this._level.clear();
9629
+ } catch (err) {
9630
+ log28.warn("failed to clear leveldb during reset", {
9631
+ err
9632
+ }, {
9633
+ F: __dxlog_file32,
9634
+ L: 415,
9635
+ S: this,
9636
+ C: (f, a) => f(...a)
9637
+ });
9638
+ }
9897
9639
  await this._storage.reset();
9898
9640
  log28.info("reset", void 0, {
9899
9641
  F: __dxlog_file32,
9900
- L: 412,
9642
+ L: 418,
9901
9643
  S: this,
9902
9644
  C: (f, a) => f(...a)
9903
9645
  });
@@ -9905,7 +9647,7 @@ var ClientServicesHost = class {
9905
9647
  id: traceId
9906
9648
  }), {
9907
9649
  F: __dxlog_file32,
9908
- L: 413,
9650
+ L: 419,
9909
9651
  S: this,
9910
9652
  C: (f, a) => f(...a)
9911
9653
  });
@@ -9916,94 +9658,6 @@ var ClientServicesHost = class {
9916
9658
  await this._serviceContext.initialized.wait();
9917
9659
  return identity;
9918
9660
  }
9919
- constructor({
9920
- config,
9921
- transportFactory,
9922
- signalManager,
9923
- storage,
9924
- level,
9925
- // TODO(wittjosiah): Turn this on by default.
9926
- lockKey,
9927
- callbacks,
9928
- runtimeParams
9929
- } = {}) {
9930
- _define_property36(this, "_resourceLock", void 0);
9931
- _define_property36(this, "_serviceRegistry", void 0);
9932
- _define_property36(this, "_systemService", void 0);
9933
- _define_property36(this, "_loggingService", void 0);
9934
- _define_property36(this, "_tracingService", TRACE_PROCESSOR3.createTraceSender());
9935
- _define_property36(this, "_statusUpdate", new Event11());
9936
- _define_property36(this, "_config", void 0);
9937
- _define_property36(this, "_signalManager", void 0);
9938
- _define_property36(this, "_networkManager", void 0);
9939
- _define_property36(this, "_storage", void 0);
9940
- _define_property36(this, "_level", void 0);
9941
- _define_property36(this, "_callbacks", void 0);
9942
- _define_property36(this, "_devtoolsProxy", void 0);
9943
- _define_property36(this, "_edgeConnection", void 0);
9944
- _define_property36(this, "_edgeHttpClient", void 0);
9945
- _define_property36(this, "_serviceContext", void 0);
9946
- _define_property36(this, "_runtimeParams", void 0);
9947
- _define_property36(this, "diagnosticsBroadcastHandler", void 0);
9948
- _define_property36(this, "_opening", false);
9949
- _define_property36(this, "_open", false);
9950
- _define_property36(this, "_resetting", false);
9951
- this._storage = storage;
9952
- this._level = level;
9953
- this._callbacks = callbacks;
9954
- this._runtimeParams = runtimeParams ?? {};
9955
- if (this._runtimeParams.disableP2pReplication === void 0) {
9956
- this._runtimeParams.disableP2pReplication = config?.get("runtime.client.disableP2pReplication", false);
9957
- }
9958
- if (this._runtimeParams.enableVectorIndexing === void 0) {
9959
- this._runtimeParams.enableVectorIndexing = config?.get("runtime.client.enableVectorIndexing", false);
9960
- }
9961
- if (config) {
9962
- this.initialize({
9963
- config,
9964
- transportFactory,
9965
- signalManager
9966
- });
9967
- }
9968
- if (lockKey) {
9969
- this._resourceLock = new Lock({
9970
- lockKey,
9971
- onAcquire: () => {
9972
- if (!this._opening) {
9973
- void this.open(new Context11(void 0, {
9974
- F: __dxlog_file32,
9975
- L: 143
9976
- }));
9977
- }
9978
- },
9979
- onRelease: () => this.close()
9980
- });
9981
- }
9982
- this._systemService = new SystemServiceImpl({
9983
- config: () => this._config,
9984
- statusUpdate: this._statusUpdate,
9985
- getCurrentStatus: () => this.isOpen && !this._resetting ? SystemStatus.ACTIVE : SystemStatus.INACTIVE,
9986
- getDiagnostics: () => {
9987
- return createDiagnostics(this._serviceRegistry.services, this._serviceContext, this._config);
9988
- },
9989
- onUpdateStatus: async (status) => {
9990
- if (!this.isOpen && status === SystemStatus.ACTIVE) {
9991
- await this._resourceLock?.acquire();
9992
- } else if (this.isOpen && status === SystemStatus.INACTIVE) {
9993
- await this._resourceLock?.release();
9994
- }
9995
- },
9996
- onReset: async () => {
9997
- await this.reset();
9998
- }
9999
- });
10000
- this.diagnosticsBroadcastHandler = createCollectDiagnosticsBroadcastHandler(this._systemService);
10001
- this._loggingService = new LoggingServiceImpl();
10002
- this._serviceRegistry = new ServiceRegistry(clientServiceBundle, {
10003
- SystemService: this._systemService,
10004
- TracingService: this._tracingService
10005
- });
10006
- }
10007
9661
  };
10008
9662
  _ts_decorate11([
10009
9663
  Trace4.info()
@@ -10071,4 +9725,4 @@ export {
10071
9725
  ServiceRegistry,
10072
9726
  ClientServicesHost
10073
9727
  };
10074
- //# sourceMappingURL=chunk-4MWNQXYP.mjs.map
9728
+ //# sourceMappingURL=chunk-CZSLDMSL.mjs.map