@dxos/client-services 0.1.56-main.738e1fa → 0.1.56-main.76a8709

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 (58) hide show
  1. package/dist/lib/browser/{chunk-7TROD4O2.mjs → chunk-SYAA4V6R.mjs} +464 -398
  2. package/dist/lib/browser/chunk-SYAA4V6R.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +21 -24
  4. package/dist/lib/browser/index.mjs.map +3 -3
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +31 -46
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/index.cjs +480 -417
  9. package/dist/lib/node/index.cjs.map +3 -3
  10. package/dist/lib/node/meta.json +1 -1
  11. package/dist/lib/node/packlets/testing/index.cjs +479 -424
  12. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  13. package/dist/types/src/packlets/identity/identity-manager.d.ts +7 -1
  14. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  15. package/dist/types/src/packlets/identity/identity-service.d.ts +7 -3
  16. package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
  17. package/dist/types/src/packlets/identity/identity.d.ts +3 -2
  18. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  19. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  20. package/dist/types/src/packlets/services/client-rpc-server.d.ts.map +1 -1
  21. package/dist/types/src/packlets/services/diagnostics.d.ts.map +1 -1
  22. package/dist/types/src/packlets/services/service-context.d.ts +2 -1
  23. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  24. package/dist/types/src/packlets/services/service-host.d.ts +3 -1
  25. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  26. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  27. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  28. package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts.map +1 -1
  29. package/dist/types/src/packlets/vault/worker-runtime.d.ts.map +1 -1
  30. package/dist/types/src/version.d.ts +1 -1
  31. package/package.json +34 -33
  32. package/src/packlets/devices/devices-service.test.ts +2 -1
  33. package/src/packlets/identity/identity-manager.test.ts +15 -3
  34. package/src/packlets/identity/identity-manager.ts +27 -6
  35. package/src/packlets/identity/identity-service.test.ts +17 -2
  36. package/src/packlets/identity/identity-service.ts +23 -14
  37. package/src/packlets/identity/identity.test.ts +7 -6
  38. package/src/packlets/identity/identity.ts +8 -3
  39. package/src/packlets/invitations/device-invitation-protocol.test.ts +2 -1
  40. package/src/packlets/invitations/invitations-handler.ts +2 -0
  41. package/src/packlets/network/network-service.test.ts +2 -1
  42. package/src/packlets/services/client-rpc-server.ts +4 -4
  43. package/src/packlets/services/diagnostics.ts +2 -1
  44. package/src/packlets/services/service-context.test.ts +59 -0
  45. package/src/packlets/services/service-context.ts +18 -10
  46. package/src/packlets/services/service-host.test.ts +7 -6
  47. package/src/packlets/services/service-host.ts +26 -10
  48. package/src/packlets/services/service-registry.test.ts +2 -1
  49. package/src/packlets/spaces/data-space-manager.test.ts +80 -22
  50. package/src/packlets/spaces/data-space-manager.ts +5 -1
  51. package/src/packlets/spaces/data-space.ts +17 -5
  52. package/src/packlets/spaces/spaces-service.test.ts +2 -1
  53. package/src/packlets/spaces/spaces-service.ts +1 -1
  54. package/src/packlets/testing/test-builder.ts +1 -1
  55. package/src/packlets/vault/iframe-host-runtime.ts +2 -1
  56. package/src/packlets/vault/worker-runtime.ts +3 -2
  57. package/src/version.ts +1 -1
  58. package/dist/lib/browser/chunk-7TROD4O2.mjs.map +0 -7
@@ -12,7 +12,7 @@ var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
12
12
  const feedMap = new ComplexMap(PublicKey.hash);
13
13
  const update = () => {
14
14
  const { feeds } = feedStore;
15
- feeds.filter((feed) => !(feedKeys == null ? void 0 : feedKeys.length) || feedKeys.some((feedKey) => feedKey.equals(feed.key))).forEach((feed) => {
15
+ feeds.filter((feed) => !feedKeys?.length || feedKeys.some((feedKey) => feedKey.equals(feed.key))).forEach((feed) => {
16
16
  if (!feedMap.has(feed.key)) {
17
17
  feedMap.set(feed.key, feed);
18
18
  feed.on("close", update);
@@ -20,15 +20,12 @@ var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
20
20
  }
21
21
  });
22
22
  next({
23
- feeds: Array.from(feedMap.values()).map((feed) => {
24
- var _a, _b;
25
- return {
26
- feedKey: feed.key,
27
- length: feed.properties.length,
28
- bytes: feed.core.byteLength,
29
- downloaded: (_b = (_a = feed.core.bitfield) == null ? void 0 : _a.data.toBuffer()) != null ? _b : new Uint8Array()
30
- };
31
- })
23
+ feeds: Array.from(feedMap.values()).map((feed) => ({
24
+ feedKey: feed.key,
25
+ length: feed.properties.length,
26
+ bytes: feed.core.byteLength,
27
+ downloaded: feed.core.bitfield?.data.toBuffer() ?? new Uint8Array()
28
+ }))
32
29
  });
33
30
  };
34
31
  subscriptions.add(feedStore.feedOpened.on(update));
@@ -104,13 +101,13 @@ var subscribeToSignal = ({ signalManager }) => new Stream2(({ next }) => {
104
101
  recipient: message.recipient.asUint8Array(),
105
102
  payload: message.payload
106
103
  },
107
- receivedAt: new Date()
104
+ receivedAt: /* @__PURE__ */ new Date()
108
105
  });
109
106
  });
110
107
  signalManager.swarmEvent.on(ctx, (swarmEvent) => {
111
108
  next({
112
109
  swarmEvent: swarmEvent.swarmEvent,
113
- receivedAt: new Date()
110
+ receivedAt: /* @__PURE__ */ new Date()
114
111
  });
115
112
  });
116
113
  return () => {
@@ -121,13 +118,10 @@ var subscribeToNetworkTopics = ({ networkManager }) => new Stream2(({ next, clos
121
118
  const update = () => {
122
119
  try {
123
120
  const topics = networkManager.topics;
124
- const labeledTopics = topics.map((topic) => {
125
- var _a, _b;
126
- return {
127
- topic,
128
- label: (_b = (_a = networkManager.getSwarm(topic)) == null ? void 0 : _a.label) != null ? _b : topic.toHex()
129
- };
130
- });
121
+ const labeledTopics = topics.map((topic) => ({
122
+ topic,
123
+ label: networkManager.getSwarm(topic)?.label ?? topic.toHex()
124
+ }));
131
125
  next({
132
126
  topics: labeledTopics
133
127
  });
@@ -139,17 +133,15 @@ var subscribeToNetworkTopics = ({ networkManager }) => new Stream2(({ next, clos
139
133
  update();
140
134
  });
141
135
  var subscribeToSwarmInfo = ({ networkManager }) => new Stream2(({ next }) => {
142
- var _a;
143
136
  const update = () => {
144
- var _a2;
145
- const info = (_a2 = networkManager.connectionLog) == null ? void 0 : _a2.swarms;
137
+ const info = networkManager.connectionLog?.swarms;
146
138
  if (info) {
147
139
  next({
148
140
  data: info
149
141
  });
150
142
  }
151
143
  };
152
- (_a = networkManager.connectionLog) == null ? void 0 : _a.update.on(update);
144
+ networkManager.connectionLog?.update.on(update);
153
145
  update();
154
146
  });
155
147
  var getNetworkPeers = ({ networkManager }, request) => {
@@ -158,7 +150,7 @@ var getNetworkPeers = ({ networkManager }, request) => {
158
150
  }
159
151
  const map = networkManager.getSwarmMap(PublicKey2.from(request.topic));
160
152
  return {
161
- peers: map == null ? void 0 : map.peers.map((peer) => ({
153
+ peers: map?.peers.map((peer) => ({
162
154
  ...peer,
163
155
  connections: peer.connections.map((connection) => connection.asUint8Array())
164
156
  }))
@@ -174,14 +166,14 @@ var subscribeToSpaces = (context, { spaceKeys = [] }) => {
174
166
  const spaces = [
175
167
  ...context.spaceManager.spaces.values()
176
168
  ];
177
- const filteredSpaces = spaces.filter((space) => !(spaceKeys == null ? void 0 : spaceKeys.length) || spaceKeys.some((spaceKey) => spaceKey.equals(space.key)));
169
+ const filteredSpaces = spaces.filter((space) => !spaceKeys?.length || spaceKeys.some((spaceKey) => spaceKey.equals(space.key)));
178
170
  next({
179
171
  spaces: filteredSpaces.map((space) => {
180
172
  const spaceMetadata = context.metadataStore.spaces.find((spaceMetadata2) => spaceMetadata2.key.equals(space.key));
181
173
  return {
182
174
  key: space.key,
183
175
  isOpen: space.isOpen,
184
- timeframe: spaceMetadata == null ? void 0 : spaceMetadata.dataTimeframe,
176
+ timeframe: spaceMetadata?.dataTimeframe,
185
177
  genesisFeed: space.genesisFeedKey,
186
178
  controlFeed: space.controlFeedKey,
187
179
  dataFeed: space.dataFeedKey
@@ -195,7 +187,7 @@ var subscribeToSpaces = (context, { spaceKeys = [] }) => {
195
187
  await update();
196
188
  });
197
189
  return () => {
198
- unsubscribe == null ? void 0 : unsubscribe();
190
+ unsubscribe?.();
199
191
  clearTimeout(timeout);
200
192
  };
201
193
  });
@@ -254,16 +246,15 @@ var DevtoolsServiceImpl = class {
254
246
  };
255
247
  }
256
248
  async getStorageInfo() {
257
- var _a, _b, _c, _d, _e;
258
- const storageUsage = (_c = await ((_b = (_a = this.params.context.storage).getDiskInfo) == null ? void 0 : _b.call(_a))) != null ? _c : {
249
+ const storageUsage = await this.params.context.storage.getDiskInfo?.() ?? {
259
250
  used: 0
260
251
  };
261
252
  const navigatorInfo = typeof navigator === "object" ? await navigator.storage.estimate() : void 0;
262
253
  return {
263
254
  type: this.params.context.storage.type,
264
255
  storageUsage: storageUsage.used,
265
- originUsage: (_d = navigatorInfo == null ? void 0 : navigatorInfo.usage) != null ? _d : 0,
266
- usageQuota: (_e = navigatorInfo == null ? void 0 : navigatorInfo.quota) != null ? _e : 0
256
+ originUsage: navigatorInfo?.usage ?? 0,
257
+ usageQuota: navigatorInfo?.quota ?? 0
267
258
  };
268
259
  }
269
260
  async getBlobs() {
@@ -449,7 +440,7 @@ var TrustedKeySetAuthVerifier = class {
449
440
  return await trigger.wait({
450
441
  timeout: this._params.authTimeout
451
442
  });
452
- } catch (e) {
443
+ } catch {
453
444
  return false;
454
445
  } finally {
455
446
  clear();
@@ -471,8 +462,19 @@ import { writeMessages } from "@dxos/feed-store";
471
462
  import { invariant } from "@dxos/invariant";
472
463
  import { log as log2 } from "@dxos/log";
473
464
  import { AdmittedFeed } from "@dxos/protocols/proto/dxos/halo/credentials";
465
+ import { trace } from "@dxos/tracing";
466
+ function _ts_decorate(decorators, target, key, desc) {
467
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
468
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
469
+ r = Reflect.decorate(decorators, target, key, desc);
470
+ else
471
+ for (var i = decorators.length - 1; i >= 0; i--)
472
+ if (d = decorators[i])
473
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
474
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
475
+ }
474
476
  var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity.ts";
475
- var Identity = class {
477
+ var Identity = class Identity2 {
476
478
  constructor({ space, signer, identityKey, deviceKey }) {
477
479
  this.stateUpdate = new Event();
478
480
  this.space = space;
@@ -498,12 +500,12 @@ var Identity = class {
498
500
  get authorizedDeviceKeys() {
499
501
  return this._deviceStateMachine.authorizedDeviceKeys;
500
502
  }
501
- async open() {
503
+ async open(ctx) {
502
504
  await this.space.spaceState.addCredentialProcessor(this._deviceStateMachine);
503
505
  await this.space.spaceState.addCredentialProcessor(this._profileStateMachine);
504
- await this.space.open();
506
+ await this.space.open(ctx);
505
507
  }
506
- async close() {
508
+ async close(ctx) {
507
509
  await this.authVerifier.close();
508
510
  await this.space.spaceState.removeCredentialProcessor(this._profileStateMachine);
509
511
  await this.space.spaceState.removeCredentialProcessor(this._deviceStateMachine);
@@ -534,11 +536,10 @@ var Identity = class {
534
536
  return this._deviceStateMachine.deviceCredentialChain;
535
537
  }
536
538
  getAdmissionCredentials() {
537
- var _a, _b;
538
539
  return {
539
540
  deviceKey: this.deviceKey,
540
- controlFeedKey: (_a = this.space.controlFeedKey) != null ? _a : failUndefined(),
541
- dataFeedKey: (_b = this.space.dataFeedKey) != null ? _b : failUndefined()
541
+ controlFeedKey: this.space.controlFeedKey ?? failUndefined(),
542
+ dataFeedKey: this.space.dataFeedKey ?? failUndefined()
542
543
  };
543
544
  }
544
545
  /**
@@ -548,7 +549,7 @@ var Identity = class {
548
549
  getIdentityCredentialSigner() {
549
550
  invariant(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.", {
550
551
  F: __dxlog_file2,
551
- L: 134,
552
+ L: 139,
552
553
  S: this,
553
554
  A: [
554
555
  "this._deviceStateMachine.deviceCredentialChain",
@@ -572,7 +573,7 @@ var Identity = class {
572
573
  dataFeedKey
573
574
  }, {
574
575
  F: __dxlog_file2,
575
- L: 150,
576
+ L: 155,
576
577
  S: this,
577
578
  C: (f, a) => f(...a)
578
579
  });
@@ -613,18 +614,40 @@ var Identity = class {
613
614
  })));
614
615
  }
615
616
  };
617
+ _ts_decorate([
618
+ trace.span()
619
+ ], Identity.prototype, "open", null);
620
+ _ts_decorate([
621
+ trace.span()
622
+ ], Identity.prototype, "close", null);
623
+ Identity = _ts_decorate([
624
+ trace.resource()
625
+ ], Identity);
616
626
 
617
627
  // packages/sdk/client-services/src/packlets/identity/identity-manager.ts
618
628
  import { Event as Event2 } from "@dxos/async";
629
+ import { Context as Context3 } from "@dxos/context";
619
630
  import { createCredentialSignerWithKey as createCredentialSignerWithKey2, CredentialGenerator } from "@dxos/credentials";
620
631
  import { invariant as invariant2 } from "@dxos/invariant";
621
632
  import { PublicKey as PublicKey3 } from "@dxos/keys";
622
633
  import { log as log3 } from "@dxos/log";
623
- import { trace } from "@dxos/protocols";
634
+ import { trace as trace2 } from "@dxos/protocols";
624
635
  import { AdmittedFeed as AdmittedFeed2 } from "@dxos/protocols/proto/dxos/halo/credentials";
636
+ import { Timeframe } from "@dxos/timeframe";
637
+ import { trace as Trace } from "@dxos/tracing";
625
638
  import { deferFunction } from "@dxos/util";
639
+ function _ts_decorate2(decorators, target, key, desc) {
640
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
641
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
642
+ r = Reflect.decorate(decorators, target, key, desc);
643
+ else
644
+ for (var i = decorators.length - 1; i >= 0; i--)
645
+ if (d = decorators[i])
646
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
647
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
648
+ }
626
649
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-manager.ts";
627
- var IdentityManager = class {
650
+ var IdentityManager = class IdentityManager2 {
628
651
  // TODO(burdon): IdentityManagerParams.
629
652
  // TODO(dmaretskyi): Perhaps this should take/generate the peerKey outside of an initialized identity.
630
653
  constructor(_metadataStore, _keyring, _feedStore, _spaceManager) {
@@ -637,14 +660,13 @@ var IdentityManager = class {
637
660
  get identity() {
638
661
  return this._identity;
639
662
  }
640
- async open() {
641
- var _a;
663
+ async open(ctx) {
642
664
  const traceId = PublicKey3.random().toHex();
643
- log3.trace("dxos.halo.identity-manager.open", trace.begin({
665
+ log3.trace("dxos.halo.identity-manager.open", trace2.begin({
644
666
  id: traceId
645
667
  }), {
646
668
  F: __dxlog_file3,
647
- L: 69,
669
+ L: 73,
648
670
  S: this,
649
671
  C: (f, a) => f(...a)
650
672
  });
@@ -654,43 +676,41 @@ var IdentityManager = class {
654
676
  identityRecord
655
677
  }, {
656
678
  F: __dxlog_file3,
657
- L: 73,
679
+ L: 77,
658
680
  S: this,
659
681
  C: (f, a) => f(...a)
660
682
  });
661
683
  if (identityRecord) {
662
684
  this._identity = await this._constructIdentity(identityRecord);
663
- await this._identity.open();
685
+ await this._identity.open(ctx);
664
686
  await this._identity.ready();
665
687
  log3.trace("dxos.halo.identity", {
666
688
  identityKey: identityRecord.identityKey,
667
- displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
689
+ displayName: this._identity.profileDocument?.displayName
668
690
  }, {
669
691
  F: __dxlog_file3,
670
- L: 78,
692
+ L: 82,
671
693
  S: this,
672
694
  C: (f, a) => f(...a)
673
695
  });
674
696
  this.stateUpdate.emit();
675
697
  }
676
- log3.trace("dxos.halo.identity-manager.open", trace.end({
698
+ log3.trace("dxos.halo.identity-manager.open", trace2.end({
677
699
  id: traceId
678
700
  }), {
679
701
  F: __dxlog_file3,
680
- L: 84,
702
+ L: 88,
681
703
  S: this,
682
704
  C: (f, a) => f(...a)
683
705
  });
684
706
  }
685
707
  async close() {
686
- var _a;
687
- await ((_a = this._identity) == null ? void 0 : _a.close());
708
+ await this._identity?.close(new Context3());
688
709
  }
689
710
  async createIdentity({ displayName } = {}) {
690
- var _a;
691
711
  invariant2(!this._identity, "Identity already exists.", {
692
712
  F: __dxlog_file3,
693
- L: 92,
713
+ L: 96,
694
714
  S: this,
695
715
  A: [
696
716
  "!this._identity",
@@ -699,7 +719,7 @@ var IdentityManager = class {
699
719
  });
700
720
  log3("creating identity...", void 0, {
701
721
  F: __dxlog_file3,
702
- L: 93,
722
+ L: 97,
703
723
  S: this,
704
724
  C: (f, a) => f(...a)
705
725
  });
@@ -715,12 +735,12 @@ var IdentityManager = class {
715
735
  }
716
736
  };
717
737
  const identity = await this._constructIdentity(identityRecord);
718
- await identity.open();
738
+ await identity.open(new Context3());
719
739
  {
720
740
  const generator = new CredentialGenerator(this._keyring, identityRecord.identityKey, identityRecord.deviceKey);
721
741
  invariant2(identityRecord.haloSpace.genesisFeedKey, "Genesis feed key is required.", {
722
742
  F: __dxlog_file3,
723
- L: 112,
743
+ L: 116,
724
744
  S: this,
725
745
  A: [
726
746
  "identityRecord.haloSpace.genesisFeedKey",
@@ -729,7 +749,7 @@ var IdentityManager = class {
729
749
  });
730
750
  invariant2(identityRecord.haloSpace.dataFeedKey, "Data feed key is required.", {
731
751
  F: __dxlog_file3,
732
- L: 113,
752
+ L: 117,
733
753
  S: this,
734
754
  A: [
735
755
  "identityRecord.haloSpace.dataFeedKey",
@@ -761,10 +781,10 @@ var IdentityManager = class {
761
781
  await this._identity.ready();
762
782
  log3.trace("dxos.halo.identity", {
763
783
  identityKey: identityRecord.identityKey,
764
- displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
784
+ displayName: this._identity.profileDocument?.displayName
765
785
  }, {
766
786
  F: __dxlog_file3,
767
- L: 148,
787
+ L: 152,
768
788
  S: this,
769
789
  C: (f, a) => f(...a)
770
790
  });
@@ -774,7 +794,7 @@ var IdentityManager = class {
774
794
  deviceKey: identity.deviceKey
775
795
  }, {
776
796
  F: __dxlog_file3,
777
- L: 154,
797
+ L: 158,
778
798
  S: this,
779
799
  C: (f, a) => f(...a)
780
800
  });
@@ -784,18 +804,17 @@ var IdentityManager = class {
784
804
  * Accept an existing identity. Expects it's device key to be authorized (now or later).
785
805
  */
786
806
  async acceptIdentity(params) {
787
- var _a;
788
807
  log3("accepting identity", {
789
808
  params
790
809
  }, {
791
810
  F: __dxlog_file3,
792
- L: 162,
811
+ L: 166,
793
812
  S: this,
794
813
  C: (f, a) => f(...a)
795
814
  });
796
815
  invariant2(!this._identity, "Identity already exists.", {
797
816
  F: __dxlog_file3,
798
- L: 163,
817
+ L: 167,
799
818
  S: this,
800
819
  A: [
801
820
  "!this._identity",
@@ -814,16 +833,16 @@ var IdentityManager = class {
814
833
  }
815
834
  };
816
835
  const identity = await this._constructIdentity(identityRecord);
817
- await identity.open();
836
+ await identity.open(new Context3());
818
837
  this._identity = identity;
819
838
  await this._metadataStore.setIdentityRecord(identityRecord);
820
839
  await this._identity.ready();
821
840
  log3.trace("dxos.halo.identity", {
822
841
  identityKey: identityRecord.identityKey,
823
- displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
842
+ displayName: this._identity.profileDocument?.displayName
824
843
  }, {
825
844
  F: __dxlog_file3,
826
- L: 182,
845
+ L: 186,
827
846
  S: this,
828
847
  C: (f, a) => f(...a)
829
848
  });
@@ -833,16 +852,48 @@ var IdentityManager = class {
833
852
  deviceKey: identity.deviceKey
834
853
  }, {
835
854
  F: __dxlog_file3,
836
- L: 188,
855
+ L: 192,
837
856
  S: this,
838
857
  C: (f, a) => f(...a)
839
858
  });
840
859
  return identity;
841
860
  }
861
+ /**
862
+ * Update the profile document of an existing identity.
863
+ */
864
+ async updateProfile(profile) {
865
+ invariant2(this._identity, "Identity not initialized.", {
866
+ F: __dxlog_file3,
867
+ L: 200,
868
+ S: this,
869
+ A: [
870
+ "this._identity",
871
+ "'Identity not initialized.'"
872
+ ]
873
+ });
874
+ const credential = await this._identity.getIdentityCredentialSigner().createCredential({
875
+ subject: this._identity.identityKey,
876
+ assertion: {
877
+ "@type": "dxos.halo.credentials.IdentityProfile",
878
+ profile
879
+ }
880
+ });
881
+ const receipt = await this._identity.controlPipeline.writer.write({
882
+ credential: {
883
+ credential
884
+ }
885
+ });
886
+ await this._identity.controlPipeline.state.waitUntilTimeframe(new Timeframe([
887
+ [
888
+ receipt.feedKey,
889
+ receipt.seq
890
+ ]
891
+ ]));
892
+ }
842
893
  async _constructIdentity(identityRecord) {
843
894
  invariant2(!this._identity, void 0, {
844
895
  F: __dxlog_file3,
845
- L: 193,
896
+ L: 214,
846
897
  S: this,
847
898
  A: [
848
899
  "!this._identity",
@@ -853,13 +904,13 @@ var IdentityManager = class {
853
904
  identityRecord
854
905
  }, {
855
906
  F: __dxlog_file3,
856
- L: 194,
907
+ L: 215,
857
908
  S: this,
858
909
  C: (f, a) => f(...a)
859
910
  });
860
911
  invariant2(identityRecord.haloSpace.controlFeedKey, void 0, {
861
912
  F: __dxlog_file3,
862
- L: 197,
913
+ L: 218,
863
914
  S: this,
864
915
  A: [
865
916
  "identityRecord.haloSpace.controlFeedKey",
@@ -871,7 +922,7 @@ var IdentityManager = class {
871
922
  });
872
923
  invariant2(identityRecord.haloSpace.dataFeedKey, void 0, {
873
924
  F: __dxlog_file3,
874
- L: 201,
925
+ L: 222,
875
926
  S: this,
876
927
  A: [
877
928
  "identityRecord.haloSpace.dataFeedKey",
@@ -903,7 +954,7 @@ var IdentityManager = class {
903
954
  identityKey: identityRecord.identityKey
904
955
  }, {
905
956
  F: __dxlog_file3,
906
- L: 225,
957
+ L: 246,
907
958
  S: this,
908
959
  C: (f, a) => f(...a)
909
960
  });
@@ -924,7 +975,7 @@ var IdentityManager = class {
924
975
  onAuthFailure: () => {
925
976
  log3.warn("auth failure", void 0, {
926
977
  F: __dxlog_file3,
927
- L: 244,
978
+ L: 265,
928
979
  S: this,
929
980
  C: (f, a) => f(...a)
930
981
  });
@@ -933,6 +984,12 @@ var IdentityManager = class {
933
984
  });
934
985
  }
935
986
  };
987
+ _ts_decorate2([
988
+ Trace.span()
989
+ ], IdentityManager.prototype, "open", null);
990
+ IdentityManager = _ts_decorate2([
991
+ Trace.resource()
992
+ ], IdentityManager);
936
993
 
937
994
  // packages/sdk/client-services/src/packlets/identity/identity-service.ts
938
995
  import { Stream as Stream7 } from "@dxos/codec-protobuf";
@@ -941,12 +998,13 @@ import { todo } from "@dxos/debug";
941
998
  import { invariant as invariant3 } from "@dxos/invariant";
942
999
  var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
943
1000
  var IdentityServiceImpl = class {
944
- // TODO(wittjosiah): Remove dependency on service context.
945
- constructor(_serviceContext) {
946
- this._serviceContext = _serviceContext;
1001
+ constructor(_createIdentity, _identityManager, _keyring) {
1002
+ this._createIdentity = _createIdentity;
1003
+ this._identityManager = _identityManager;
1004
+ this._keyring = _keyring;
947
1005
  }
948
1006
  async createIdentity(request) {
949
- await this._serviceContext.createIdentity(request);
1007
+ await this._createIdentity(request);
950
1008
  return this._getIdentity();
951
1009
  }
952
1010
  async recoverIdentity(request) {
@@ -958,34 +1016,47 @@ var IdentityServiceImpl = class {
958
1016
  identity: this._getIdentity()
959
1017
  });
960
1018
  emitNext();
961
- return this._serviceContext.identityManager.stateUpdate.on(emitNext);
1019
+ return this._identityManager.stateUpdate.on(emitNext);
962
1020
  });
963
1021
  }
964
1022
  _getIdentity() {
965
- if (!this._serviceContext.identityManager.identity) {
1023
+ if (!this._identityManager.identity) {
966
1024
  return void 0;
967
1025
  }
968
1026
  return {
969
- identityKey: this._serviceContext.identityManager.identity.identityKey,
970
- spaceKey: this._serviceContext.identityManager.identity.space.key,
971
- profile: this._serviceContext.identityManager.identity.profileDocument
1027
+ identityKey: this._identityManager.identity.identityKey,
1028
+ spaceKey: this._identityManager.identity.space.key,
1029
+ profile: this._identityManager.identity.profileDocument
972
1030
  };
973
1031
  }
1032
+ async updateProfile(profile) {
1033
+ invariant3(this._identityManager.identity, "Identity not initialized.", {
1034
+ F: __dxlog_file4,
1035
+ L: 59,
1036
+ S: this,
1037
+ A: [
1038
+ "this._identityManager.identity",
1039
+ "'Identity not initialized.'"
1040
+ ]
1041
+ });
1042
+ await this._identityManager.updateProfile(profile);
1043
+ return this._getIdentity();
1044
+ }
974
1045
  async signPresentation({ presentation, nonce }) {
975
- invariant3(this._serviceContext.identityManager.identity, "Identity not initialized.", {
1046
+ invariant3(this._identityManager.identity, "Identity not initialized.", {
976
1047
  F: __dxlog_file4,
977
- L: 56,
1048
+ L: 65,
978
1049
  S: this,
979
1050
  A: [
980
- "this._serviceContext.identityManager.identity",
1051
+ "this._identityManager.identity",
981
1052
  "'Identity not initialized.'"
982
1053
  ]
983
1054
  });
984
1055
  return await signPresentation({
985
1056
  presentation,
986
- signer: this._serviceContext.keyring,
987
- signerKey: this._serviceContext.identityManager.identity.deviceKey,
988
- chain: this._serviceContext.identityManager.identity.deviceCredentialChain,
1057
+ signer: this._keyring,
1058
+ signerKey: this._identityManager.identity.deviceKey,
1059
+ chain: this._identityManager.identity.deviceCredentialChain,
989
1060
  nonce
990
1061
  });
991
1062
  }
@@ -1084,25 +1155,25 @@ var DeviceInvitationProtocol = class {
1084
1155
  // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
1085
1156
  import { PushStream, scheduleTask as scheduleTask2, TimeoutError, Trigger as Trigger3 } from "@dxos/async";
1086
1157
  import { AuthenticatingInvitationObservable, AUTHENTICATION_CODE_LENGTH, CancellableInvitationObservable, INVITATION_TIMEOUT } from "@dxos/client-protocol";
1087
- import { Context as Context4 } from "@dxos/context";
1158
+ import { Context as Context5 } from "@dxos/context";
1088
1159
  import { generatePasscode } from "@dxos/credentials";
1089
1160
  import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError2 } from "@dxos/errors";
1090
1161
  import { invariant as invariant6 } from "@dxos/invariant";
1091
1162
  import { PublicKey as PublicKey5 } from "@dxos/keys";
1092
1163
  import { log as log5 } from "@dxos/log";
1093
1164
  import { createTeleportProtocolFactory, StarTopology } from "@dxos/network-manager";
1094
- import { trace as trace3 } from "@dxos/protocols";
1165
+ import { trace as trace4 } from "@dxos/protocols";
1095
1166
  import { Invitation as Invitation3 } from "@dxos/protocols/proto/dxos/client/services";
1096
1167
  import { AuthenticationResponse as AuthenticationResponse2 } from "@dxos/protocols/proto/dxos/halo/invitations";
1097
1168
 
1098
1169
  // packages/sdk/client-services/src/packlets/invitations/invitation-extension.ts
1099
1170
  import { Trigger as Trigger2 } from "@dxos/async";
1100
- import { cancelWithContext, Context as Context3 } from "@dxos/context";
1171
+ import { cancelWithContext, Context as Context4 } from "@dxos/context";
1101
1172
  import { InvalidInvitationExtensionRoleError } from "@dxos/errors";
1102
1173
  import { invariant as invariant5 } from "@dxos/invariant";
1103
1174
  import { PublicKey as PublicKey4 } from "@dxos/keys";
1104
1175
  import { log as log4 } from "@dxos/log";
1105
- import { schema as schema2, trace as trace2 } from "@dxos/protocols";
1176
+ import { schema as schema2, trace as trace3 } from "@dxos/protocols";
1106
1177
  import { Invitation as Invitation2 } from "@dxos/protocols/proto/dxos/client/services";
1107
1178
  import { AuthenticationResponse, Options } from "@dxos/protocols/proto/dxos/halo/invitations";
1108
1179
  import { RpcExtension } from "@dxos/teleport";
@@ -1120,7 +1191,7 @@ var InvitationHostExtension = class extends RpcExtension {
1120
1191
  }
1121
1192
  });
1122
1193
  this._callbacks = _callbacks;
1123
- this._ctx = new Context3();
1194
+ this._ctx = new Context4();
1124
1195
  this._remoteOptionsTrigger = new Trigger2();
1125
1196
  this.invitation = void 0;
1126
1197
  this.guestProfile = void 0;
@@ -1149,7 +1220,7 @@ var InvitationHostExtension = class extends RpcExtension {
1149
1220
  introduce: async (request) => {
1150
1221
  const { profile, invitationId } = request;
1151
1222
  const traceId = PublicKey4.random().toHex();
1152
- log4.trace("dxos.sdk.invitation-handler.host.introduce", trace2.begin({
1223
+ log4.trace("dxos.sdk.invitation-handler.host.introduce", trace3.begin({
1153
1224
  id: traceId
1154
1225
  }), {
1155
1226
  F: __dxlog_file6,
@@ -1186,7 +1257,7 @@ var InvitationHostExtension = class extends RpcExtension {
1186
1257
  ...this.invitation,
1187
1258
  state: Invitation2.State.READY_FOR_AUTHENTICATION
1188
1259
  });
1189
- log4.trace("dxos.sdk.invitation-handler.host.introduce", trace2.end({
1260
+ log4.trace("dxos.sdk.invitation-handler.host.introduce", trace3.end({
1190
1261
  id: traceId
1191
1262
  }), {
1192
1263
  F: __dxlog_file6,
@@ -1201,7 +1272,7 @@ var InvitationHostExtension = class extends RpcExtension {
1201
1272
  },
1202
1273
  authenticate: async ({ authCode: code }) => {
1203
1274
  const traceId = PublicKey4.random().toHex();
1204
- log4.trace("dxos.sdk.invitation-handler.host.authenticate", trace2.begin({
1275
+ log4.trace("dxos.sdk.invitation-handler.host.authenticate", trace3.begin({
1205
1276
  id: traceId
1206
1277
  }), {
1207
1278
  F: __dxlog_file6,
@@ -1264,7 +1335,7 @@ var InvitationHostExtension = class extends RpcExtension {
1264
1335
  break;
1265
1336
  }
1266
1337
  }
1267
- log4.trace("dxos.sdk.invitation-handler.host.authenticate", trace2.end({
1338
+ log4.trace("dxos.sdk.invitation-handler.host.authenticate", trace3.end({
1268
1339
  id: traceId,
1269
1340
  data: {
1270
1341
  status
@@ -1281,7 +1352,7 @@ var InvitationHostExtension = class extends RpcExtension {
1281
1352
  },
1282
1353
  admit: async (request) => {
1283
1354
  const traceId = PublicKey4.random().toHex();
1284
- log4.trace("dxos.sdk.invitation-handler.host.admit", trace2.begin({
1355
+ log4.trace("dxos.sdk.invitation-handler.host.admit", trace3.begin({
1285
1356
  id: traceId
1286
1357
  }), {
1287
1358
  F: __dxlog_file6,
@@ -1303,7 +1374,7 @@ var InvitationHostExtension = class extends RpcExtension {
1303
1374
  throw new Error("Not authenticated");
1304
1375
  }
1305
1376
  const response = await this._callbacks.admit(request);
1306
- log4.trace("dxos.sdk.invitation-handler.host.admit", trace2.end({
1377
+ log4.trace("dxos.sdk.invitation-handler.host.admit", trace3.end({
1307
1378
  id: traceId
1308
1379
  }), {
1309
1380
  F: __dxlog_file6,
@@ -1321,7 +1392,6 @@ var InvitationHostExtension = class extends RpcExtension {
1321
1392
  };
1322
1393
  }
1323
1394
  async onOpen(context) {
1324
- var _a;
1325
1395
  await super.onOpen(context);
1326
1396
  try {
1327
1397
  await this.rpc.InvitationHostService.options({
@@ -1330,7 +1400,7 @@ var InvitationHostExtension = class extends RpcExtension {
1330
1400
  await cancelWithContext(this._ctx, this._remoteOptionsTrigger.wait({
1331
1401
  timeout: OPTIONS_TIMEOUT
1332
1402
  }));
1333
- if (((_a = this._remoteOptions) == null ? void 0 : _a.role) !== Options.Role.GUEST) {
1403
+ if (this._remoteOptions?.role !== Options.Role.GUEST) {
1334
1404
  throw new InvalidInvitationExtensionRoleError(void 0, {
1335
1405
  expected: Options.Role.GUEST,
1336
1406
  remoteOptions: this._remoteOptions
@@ -1356,7 +1426,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1356
1426
  }
1357
1427
  });
1358
1428
  this._callbacks = _callbacks;
1359
- this._ctx = new Context3();
1429
+ this._ctx = new Context4();
1360
1430
  this._remoteOptionsTrigger = new Trigger2();
1361
1431
  }
1362
1432
  async getHandlers() {
@@ -1388,7 +1458,6 @@ var InvitationGuestExtension = class extends RpcExtension {
1388
1458
  };
1389
1459
  }
1390
1460
  async onOpen(context) {
1391
- var _a;
1392
1461
  await super.onOpen(context);
1393
1462
  try {
1394
1463
  log4("begin options", void 0, {
@@ -1409,7 +1478,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1409
1478
  S: this,
1410
1479
  C: (f, a) => f(...a)
1411
1480
  });
1412
- if (((_a = this._remoteOptions) == null ? void 0 : _a.role) !== Options.Role.HOST) {
1481
+ if (this._remoteOptions?.role !== Options.Role.HOST) {
1413
1482
  throw new InvalidInvitationExtensionRoleError(void 0, {
1414
1483
  expected: Options.Role.HOST,
1415
1484
  remoteOptions: this._remoteOptions
@@ -1448,9 +1517,8 @@ var InvitationsHandler = class {
1448
1517
  this._networkManager = _networkManager;
1449
1518
  }
1450
1519
  createInvitation(protocol, options) {
1451
- var _a;
1452
- const { invitationId = PublicKey5.random().toHex(), type = Invitation3.Type.INTERACTIVE, authMethod = Invitation3.AuthMethod.SHARED_SECRET, state = Invitation3.State.INIT, timeout = INVITATION_TIMEOUT, swarmKey = PublicKey5.random() } = options != null ? options : {};
1453
- const authCode = (_a = options == null ? void 0 : options.authCode) != null ? _a : authMethod === Invitation3.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0;
1520
+ const { invitationId = PublicKey5.random().toHex(), type = Invitation3.Type.INTERACTIVE, authMethod = Invitation3.AuthMethod.SHARED_SECRET, state = Invitation3.State.INIT, timeout = INVITATION_TIMEOUT, swarmKey = PublicKey5.random() } = options ?? {};
1521
+ const authCode = options?.authCode ?? (authMethod === Invitation3.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0);
1454
1522
  invariant6(protocol, void 0, {
1455
1523
  F: __dxlog_file7,
1456
1524
  L: 76,
@@ -1471,7 +1539,7 @@ var InvitationsHandler = class {
1471
1539
  ...protocol.getInvitationContext()
1472
1540
  };
1473
1541
  const stream = new PushStream();
1474
- const ctx = new Context4({
1542
+ const ctx = new Context5({
1475
1543
  onError: (err) => {
1476
1544
  void ctx.dispose();
1477
1545
  stream.error(err);
@@ -1503,9 +1571,8 @@ var InvitationsHandler = class {
1503
1571
  return invitation;
1504
1572
  },
1505
1573
  admit: async (admissionRequest) => {
1506
- var _a2, _b, _c;
1507
1574
  try {
1508
- const deviceKey = (_c = (_a2 = admissionRequest.device) == null ? void 0 : _a2.deviceKey) != null ? _c : (_b = admissionRequest.space) == null ? void 0 : _b.deviceKey;
1575
+ const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
1509
1576
  invariant6(deviceKey, void 0, {
1510
1577
  F: __dxlog_file7,
1511
1578
  L: 119,
@@ -1527,7 +1594,7 @@ var InvitationsHandler = class {
1527
1594
  scheduleTask2(ctx, async () => {
1528
1595
  const traceId = PublicKey5.random().toHex();
1529
1596
  try {
1530
- log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace3.begin({
1597
+ log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace4.begin({
1531
1598
  id: traceId
1532
1599
  }), {
1533
1600
  F: __dxlog_file7,
@@ -1563,7 +1630,7 @@ var InvitationsHandler = class {
1563
1630
  ...invitation,
1564
1631
  state: Invitation3.State.SUCCESS
1565
1632
  });
1566
- log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace3.end({
1633
+ log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace4.end({
1567
1634
  id: traceId
1568
1635
  }), {
1569
1636
  F: __dxlog_file7,
@@ -1594,7 +1661,7 @@ var InvitationsHandler = class {
1594
1661
  });
1595
1662
  stream.error(err);
1596
1663
  }
1597
- log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace3.error({
1664
+ log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace4.error({
1598
1665
  id: traceId,
1599
1666
  error: err
1600
1667
  }), {
@@ -1650,7 +1717,8 @@ var InvitationsHandler = class {
1650
1717
  protocolProvider: createTeleportProtocolFactory(async (teleport) => {
1651
1718
  teleport.addExtension("dxos.halo.invitations", createExtension());
1652
1719
  }),
1653
- topology: new StarTopology(topic)
1720
+ topology: new StarTopology(topic),
1721
+ label: "invitation host"
1654
1722
  });
1655
1723
  ctx.onDispose(() => swarmConnection.close());
1656
1724
  stream.next({
@@ -1675,7 +1743,7 @@ var InvitationsHandler = class {
1675
1743
  const { timeout = INVITATION_TIMEOUT } = invitation;
1676
1744
  invariant6(protocol, void 0, {
1677
1745
  F: __dxlog_file7,
1678
- L: 210,
1746
+ L: 211,
1679
1747
  S: this,
1680
1748
  A: [
1681
1749
  "protocol",
@@ -1689,7 +1757,7 @@ var InvitationsHandler = class {
1689
1757
  const setState = (newData) => {
1690
1758
  invariant6(newData.state !== void 0, void 0, {
1691
1759
  F: __dxlog_file7,
1692
- L: 221,
1760
+ L: 222,
1693
1761
  S: this,
1694
1762
  A: [
1695
1763
  "newData.state !== undefined",
@@ -1702,14 +1770,14 @@ var InvitationsHandler = class {
1702
1770
  ...newData
1703
1771
  });
1704
1772
  };
1705
- const ctx = new Context4({
1773
+ const ctx = new Context5({
1706
1774
  onError: (err) => {
1707
1775
  if (err instanceof TimeoutError) {
1708
1776
  log5("timeout", {
1709
1777
  ...protocol.toJSON()
1710
1778
  }, {
1711
1779
  F: __dxlog_file7,
1712
- L: 229,
1780
+ L: 230,
1713
1781
  S: this,
1714
1782
  C: (f, a) => f(...a)
1715
1783
  });
@@ -1719,7 +1787,7 @@ var InvitationsHandler = class {
1719
1787
  } else {
1720
1788
  log5.warn("auth failed", err, {
1721
1789
  F: __dxlog_file7,
1722
- L: 232,
1790
+ L: 233,
1723
1791
  S: this,
1724
1792
  C: (f, a) => f(...a)
1725
1793
  });
@@ -1733,7 +1801,7 @@ var InvitationsHandler = class {
1733
1801
  ...protocol.toJSON()
1734
1802
  }, {
1735
1803
  F: __dxlog_file7,
1736
- L: 240,
1804
+ L: 241,
1737
1805
  S: this,
1738
1806
  C: (f, a) => f(...a)
1739
1807
  });
@@ -1748,7 +1816,7 @@ var InvitationsHandler = class {
1748
1816
  currentState
1749
1817
  }, {
1750
1818
  F: __dxlog_file7,
1751
- L: 250,
1819
+ L: 251,
1752
1820
  S: this,
1753
1821
  C: (f, a) => f(...a)
1754
1822
  });
@@ -1759,11 +1827,11 @@ var InvitationsHandler = class {
1759
1827
  scheduleTask2(ctx, async () => {
1760
1828
  const traceId = PublicKey5.random().toHex();
1761
1829
  try {
1762
- log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace3.begin({
1830
+ log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace4.begin({
1763
1831
  id: traceId
1764
1832
  }), {
1765
1833
  F: __dxlog_file7,
1766
- L: 259,
1834
+ L: 260,
1767
1835
  S: this,
1768
1836
  C: (f, a) => f(...a)
1769
1837
  });
@@ -1775,7 +1843,7 @@ var InvitationsHandler = class {
1775
1843
  ...protocol.toJSON()
1776
1844
  }, {
1777
1845
  F: __dxlog_file7,
1778
- L: 267,
1846
+ L: 268,
1779
1847
  S: this,
1780
1848
  C: (f, a) => f(...a)
1781
1849
  });
@@ -1786,7 +1854,7 @@ var InvitationsHandler = class {
1786
1854
  ...protocol.toJSON()
1787
1855
  }, {
1788
1856
  F: __dxlog_file7,
1789
- L: 271,
1857
+ L: 272,
1790
1858
  S: this,
1791
1859
  C: (f, a) => f(...a)
1792
1860
  });
@@ -1796,7 +1864,7 @@ var InvitationsHandler = class {
1796
1864
  response: introductionResponse
1797
1865
  }, {
1798
1866
  F: __dxlog_file7,
1799
- L: 275,
1867
+ L: 276,
1800
1868
  S: this,
1801
1869
  C: (f, a) => f(...a)
1802
1870
  });
@@ -1808,7 +1876,7 @@ var InvitationsHandler = class {
1808
1876
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
1809
1877
  log5("guest waiting for authentication code...", void 0, {
1810
1878
  F: __dxlog_file7,
1811
- L: 284,
1879
+ L: 285,
1812
1880
  S: this,
1813
1881
  C: (f, a) => f(...a)
1814
1882
  });
@@ -1820,7 +1888,7 @@ var InvitationsHandler = class {
1820
1888
  });
1821
1889
  log5("sending authentication request", void 0, {
1822
1890
  F: __dxlog_file7,
1823
- L: 288,
1891
+ L: 289,
1824
1892
  S: this,
1825
1893
  C: (f, a) => f(...a)
1826
1894
  });
@@ -1841,7 +1909,7 @@ var InvitationsHandler = class {
1841
1909
  attempt
1842
1910
  }, {
1843
1911
  F: __dxlog_file7,
1844
- L: 299,
1912
+ L: 300,
1845
1913
  S: this,
1846
1914
  C: (f, a) => f(...a)
1847
1915
  });
@@ -1858,7 +1926,7 @@ var InvitationsHandler = class {
1858
1926
  ...protocol.toJSON()
1859
1927
  }, {
1860
1928
  F: __dxlog_file7,
1861
- L: 310,
1929
+ L: 311,
1862
1930
  S: this,
1863
1931
  C: (f, a) => f(...a)
1864
1932
  });
@@ -1870,7 +1938,7 @@ var InvitationsHandler = class {
1870
1938
  ...protocol.toJSON()
1871
1939
  }, {
1872
1940
  F: __dxlog_file7,
1873
- L: 321,
1941
+ L: 322,
1874
1942
  S: this,
1875
1943
  C: (f, a) => f(...a)
1876
1944
  });
@@ -1878,11 +1946,11 @@ var InvitationsHandler = class {
1878
1946
  ...result,
1879
1947
  state: Invitation3.State.SUCCESS
1880
1948
  });
1881
- log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace3.end({
1949
+ log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace4.end({
1882
1950
  id: traceId
1883
1951
  }), {
1884
1952
  F: __dxlog_file7,
1885
- L: 323,
1953
+ L: 324,
1886
1954
  S: this,
1887
1955
  C: (f, a) => f(...a)
1888
1956
  });
@@ -1892,7 +1960,7 @@ var InvitationsHandler = class {
1892
1960
  ...protocol.toJSON()
1893
1961
  }, {
1894
1962
  F: __dxlog_file7,
1895
- L: 326,
1963
+ L: 327,
1896
1964
  S: this,
1897
1965
  C: (f, a) => f(...a)
1898
1966
  });
@@ -1902,18 +1970,18 @@ var InvitationsHandler = class {
1902
1970
  } else {
1903
1971
  log5("auth failed", err, {
1904
1972
  F: __dxlog_file7,
1905
- L: 329,
1973
+ L: 330,
1906
1974
  S: this,
1907
1975
  C: (f, a) => f(...a)
1908
1976
  });
1909
1977
  stream.error(err);
1910
1978
  }
1911
- log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace3.error({
1979
+ log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace4.error({
1912
1980
  id: traceId,
1913
1981
  error: err
1914
1982
  }), {
1915
1983
  F: __dxlog_file7,
1916
- L: 332,
1984
+ L: 333,
1917
1985
  S: this,
1918
1986
  C: (f, a) => f(...a)
1919
1987
  });
@@ -1931,7 +1999,7 @@ var InvitationsHandler = class {
1931
1999
  ...protocol.toJSON()
1932
2000
  }, {
1933
2001
  F: __dxlog_file7,
1934
- L: 343,
2002
+ L: 344,
1935
2003
  S: this,
1936
2004
  C: (f, a) => f(...a)
1937
2005
  });
@@ -1941,7 +2009,7 @@ var InvitationsHandler = class {
1941
2009
  } else {
1942
2010
  log5("auth failed", err, {
1943
2011
  F: __dxlog_file7,
1944
- L: 346,
2012
+ L: 347,
1945
2013
  S: this,
1946
2014
  C: (f, a) => f(...a)
1947
2015
  });
@@ -1954,7 +2022,7 @@ var InvitationsHandler = class {
1954
2022
  scheduleTask2(ctx, async () => {
1955
2023
  invariant6(invitation.swarmKey, void 0, {
1956
2024
  F: __dxlog_file7,
1957
- L: 356,
2025
+ L: 357,
1958
2026
  S: this,
1959
2027
  A: [
1960
2028
  "invitation.swarmKey",
@@ -1968,7 +2036,8 @@ var InvitationsHandler = class {
1968
2036
  protocolProvider: createTeleportProtocolFactory(async (teleport) => {
1969
2037
  teleport.addExtension("dxos.halo.invitations", createExtension());
1970
2038
  }),
1971
- topology: new StarTopology(topic)
2039
+ topology: new StarTopology(topic),
2040
+ label: "invitation guest"
1972
2041
  });
1973
2042
  ctx.onDispose(() => swarmConnection.close());
1974
2043
  setState({
@@ -2204,7 +2273,6 @@ var SpaceInvitationProtocol = class {
2204
2273
  };
2205
2274
  }
2206
2275
  async admit(request, guestProfile) {
2207
- var _a;
2208
2276
  invariant8(this._spaceKey, void 0, {
2209
2277
  F: __dxlog_file9,
2210
2278
  L: 42,
@@ -2268,7 +2336,7 @@ var SpaceInvitationProtocol = class {
2268
2336
  space: {
2269
2337
  credential: spaceMemberCredential,
2270
2338
  controlTimeframe: space.inner.controlPipeline.state.timeframe,
2271
- dataTimeframe: (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.timeframe
2339
+ dataTimeframe: space.dataPipeline.pipelineState?.timeframe
2272
2340
  }
2273
2341
  };
2274
2342
  }
@@ -2372,9 +2440,8 @@ var ClientRpcServer = class {
2372
2440
  await this._rpcPeer.close();
2373
2441
  }
2374
2442
  _getServiceHandler(serviceName) {
2375
- var _a;
2376
2443
  if (!this._handlerCache.has(serviceName)) {
2377
- const [key, descriptor] = (_a = Object.entries(this._serviceRegistry.descriptors).find(([key2, descriptor2]) => descriptor2.name === serviceName)) != null ? _a : raise(new Error(`Service not available: ${serviceName}`));
2444
+ const [key, descriptor] = Object.entries(this._serviceRegistry.descriptors).find(([key2, descriptor2]) => descriptor2.name === serviceName) ?? raise(new Error(`Service not available: ${serviceName}`));
2378
2445
  const service = this._serviceRegistry.services[key];
2379
2446
  if (!service) {
2380
2447
  throw new Error(`Service not available: ${serviceName}`);
@@ -2389,13 +2456,14 @@ var ClientRpcServer = class {
2389
2456
  import { getFirstStreamValue } from "@dxos/codec-protobuf";
2390
2457
  import { credentialTypeFilter } from "@dxos/credentials";
2391
2458
  import { DocumentModel } from "@dxos/document-model";
2459
+ import { TYPE_PROPERTIES } from "@dxos/echo-db";
2392
2460
  import { invariant as invariant9 } from "@dxos/invariant";
2393
2461
  import { log as log8 } from "@dxos/log";
2394
2462
  import { STORAGE_VERSION } from "@dxos/protocols";
2395
2463
  import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
2396
2464
 
2397
2465
  // packages/sdk/client-services/src/version.ts
2398
- var DXOS_VERSION = "0.1.56-main.738e1fa";
2466
+ var DXOS_VERSION = "0.1.56-main.76a8709";
2399
2467
 
2400
2468
  // packages/sdk/client-services/src/packlets/services/platform.ts
2401
2469
  var getPlatform = () => {
@@ -2429,9 +2497,8 @@ var getPlatform = () => {
2429
2497
  var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
2430
2498
  var DEFAULT_TIMEOUT = 1e3;
2431
2499
  var createDiagnostics = async (clientServices, serviceContext, config) => {
2432
- var _a, _b, _c;
2433
2500
  const diagnostics = {
2434
- created: new Date().toISOString(),
2501
+ created: (/* @__PURE__ */ new Date()).toISOString(),
2435
2502
  platform: getPlatform(),
2436
2503
  client: {
2437
2504
  version: DXOS_VERSION,
@@ -2443,7 +2510,7 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
2443
2510
  {
2444
2511
  invariant9(clientServices.LoggingService, "SystemService is not available.", {
2445
2512
  F: __dxlog_file10,
2446
- L: 87,
2513
+ L: 88,
2447
2514
  S: void 0,
2448
2515
  A: [
2449
2516
  "clientServices.LoggingService",
@@ -2461,16 +2528,16 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
2461
2528
  spaceKey: identity.space.key,
2462
2529
  profile: identity.profileDocument
2463
2530
  };
2464
- const { devices } = (_a = await getFirstStreamValue(clientServices.DevicesService.queryDevices(), {
2531
+ const { devices } = await getFirstStreamValue(clientServices.DevicesService.queryDevices(), {
2465
2532
  timeout: DEFAULT_TIMEOUT
2466
- }).catch(() => void 0)) != null ? _a : {};
2533
+ }).catch(() => void 0) ?? {};
2467
2534
  diagnostics.devices = devices;
2468
2535
  if (serviceContext.dataSpaceManager) {
2469
- diagnostics.spaces = await Promise.all((_b = Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space))) != null ? _b : []);
2536
+ diagnostics.spaces = await Promise.all(Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space)) ?? []);
2470
2537
  }
2471
- const { feeds = [] } = (_c = await getFirstStreamValue(clientServices.DevtoolsHost.subscribeToFeeds({}), {
2538
+ const { feeds = [] } = await getFirstStreamValue(clientServices.DevtoolsHost.subscribeToFeeds({}), {
2472
2539
  timeout: DEFAULT_TIMEOUT
2473
- }).catch(() => void 0)) != null ? _c : {};
2540
+ }).catch(() => void 0) ?? {};
2474
2541
  diagnostics.feeds = feeds.map(({ feedKey, bytes, length }) => ({
2475
2542
  feedKey,
2476
2543
  bytes,
@@ -2483,16 +2550,13 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
2483
2550
  var getProperties = (space) => {
2484
2551
  let properties = {};
2485
2552
  try {
2486
- const propertiesItem = space.dataPipeline.itemManager.items.find((item) => {
2487
- var _a, _b;
2488
- return ((_a = item.modelMeta) == null ? void 0 : _a.type) === DocumentModel.meta.type && ((_b = item.state) == null ? void 0 : _b.type) === "dxos.sdk.client.Properties";
2489
- });
2490
- const state = propertiesItem == null ? void 0 : propertiesItem.state;
2491
- properties = state == null ? void 0 : state.data;
2553
+ const propertiesItem = space.dataPipeline.itemManager.items.find((item) => item.modelMeta?.type === DocumentModel.meta.type && item.state?.type === TYPE_PROPERTIES);
2554
+ const state = propertiesItem?.state;
2555
+ properties = state?.data;
2492
2556
  } catch (err) {
2493
2557
  log8.warn(err.message, void 0, {
2494
2558
  F: __dxlog_file10,
2495
- L: 144,
2559
+ L: 145,
2496
2560
  S: void 0,
2497
2561
  C: (f, a) => f(...a)
2498
2562
  });
@@ -2500,7 +2564,6 @@ var getProperties = (space) => {
2500
2564
  return properties;
2501
2565
  };
2502
2566
  var getSpaceStats = async (space) => {
2503
- var _a, _b, _c, _d, _e, _f;
2504
2567
  const stats = {
2505
2568
  key: space.key,
2506
2569
  metrics: space.metrics,
@@ -2508,18 +2571,15 @@ var getSpaceStats = async (space) => {
2508
2571
  ...credential.subject.assertion,
2509
2572
  id: credential.id
2510
2573
  })),
2511
- members: Array.from(space.inner.spaceState.members.values()).map((member) => {
2512
- var _a2;
2513
- return {
2514
- identity: {
2515
- identityKey: member.key,
2516
- profile: {
2517
- displayName: (_a2 = member.assertion.profile) == null ? void 0 : _a2.displayName
2518
- }
2519
- },
2520
- presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember.PresenceState.ONLINE : SpaceMember.PresenceState.OFFLINE
2521
- };
2522
- }),
2574
+ members: Array.from(space.inner.spaceState.members.values()).map((member) => ({
2575
+ identity: {
2576
+ identityKey: member.key,
2577
+ profile: {
2578
+ displayName: member.assertion.profile?.displayName
2579
+ }
2580
+ },
2581
+ presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember.PresenceState.ONLINE : SpaceMember.PresenceState.OFFLINE
2582
+ })),
2523
2583
  pipeline: {
2524
2584
  // TODO(burdon): Pick properties from credentials if needed.
2525
2585
  // currentEpoch: space.dataPipeline.currentEpoch,
@@ -2529,11 +2589,11 @@ var getSpaceStats = async (space) => {
2529
2589
  targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
2530
2590
  totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe,
2531
2591
  // TODO(burdon): Empty?
2532
- dataFeeds: (_b = (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.feeds.map((feed) => feed.key)) != null ? _b : [],
2533
- startDataTimeframe: (_c = space.dataPipeline.pipelineState) == null ? void 0 : _c.startTimeframe,
2534
- currentDataTimeframe: (_d = space.dataPipeline.pipelineState) == null ? void 0 : _d.timeframe,
2535
- targetDataTimeframe: (_e = space.dataPipeline.pipelineState) == null ? void 0 : _e.targetTimeframe,
2536
- totalDataTimeframe: (_f = space.dataPipeline.pipelineState) == null ? void 0 : _f.endTimeframe
2592
+ dataFeeds: space.dataPipeline.pipelineState?.feeds.map((feed) => feed.key) ?? [],
2593
+ startDataTimeframe: space.dataPipeline.pipelineState?.startTimeframe,
2594
+ currentDataTimeframe: space.dataPipeline.pipelineState?.timeframe,
2595
+ targetDataTimeframe: space.dataPipeline.pipelineState?.targetTimeframe,
2596
+ totalDataTimeframe: space.dataPipeline.pipelineState?.endTimeframe
2537
2597
  }
2538
2598
  };
2539
2599
  if (space.dataPipeline.itemManager) {
@@ -2554,7 +2614,7 @@ var getSpaceStats = async (space) => {
2554
2614
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2555
2615
  import { Event as Event5, scheduleTask as scheduleTask4, synchronized, trackLeaks } from "@dxos/async";
2556
2616
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
2557
- import { cancelWithContext as cancelWithContext2, Context as Context6 } from "@dxos/context";
2617
+ import { cancelWithContext as cancelWithContext2, Context as Context7 } from "@dxos/context";
2558
2618
  import { timed } from "@dxos/debug";
2559
2619
  import { createMappedFeedWriter } from "@dxos/echo-pipeline";
2560
2620
  import { CancelledError, SystemError } from "@dxos/errors";
@@ -2562,12 +2622,12 @@ import { PublicKey as PublicKey7 } from "@dxos/keys";
2562
2622
  import { log as log10 } from "@dxos/log";
2563
2623
  import { SpaceState } from "@dxos/protocols/proto/dxos/client/services";
2564
2624
  import { AdmittedFeed as AdmittedFeed3 } from "@dxos/protocols/proto/dxos/halo/credentials";
2565
- import { Timeframe } from "@dxos/timeframe";
2625
+ import { Timeframe as Timeframe2 } from "@dxos/timeframe";
2566
2626
  import { ComplexSet as ComplexSet2 } from "@dxos/util";
2567
2627
 
2568
2628
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
2569
2629
  import { DeferredTask, Event as Event4, scheduleTask as scheduleTask3, sleep, TimeoutError as TimeoutError2, Trigger as Trigger4 } from "@dxos/async";
2570
- import { Context as Context5, rejectOnDispose } from "@dxos/context";
2630
+ import { Context as Context6, rejectOnDispose } from "@dxos/context";
2571
2631
  import { invariant as invariant10 } from "@dxos/invariant";
2572
2632
  import { PublicKey as PublicKey6 } from "@dxos/keys";
2573
2633
  import { log as log9 } from "@dxos/log";
@@ -2581,7 +2641,7 @@ var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
2581
2641
  var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
2582
2642
  var NotarizationPlugin = class {
2583
2643
  constructor() {
2584
- this._ctx = new Context5();
2644
+ this._ctx = new Context6();
2585
2645
  this._extensionOpened = new Event4();
2586
2646
  this._extensions = /* @__PURE__ */ new Set();
2587
2647
  this._processedCredentials = new ComplexSet(PublicKey6.hash);
@@ -2631,7 +2691,7 @@ var NotarizationPlugin = class {
2631
2691
  errors.throw(err);
2632
2692
  }
2633
2693
  });
2634
- opCtx == null ? void 0 : opCtx.onDispose(() => ctx.dispose());
2694
+ opCtx?.onDispose(() => ctx.dispose());
2635
2695
  if (timeout !== 0) {
2636
2696
  scheduleTask3(ctx, () => {
2637
2697
  log9.warn("Notarization timeout", {
@@ -2724,11 +2784,10 @@ var NotarizationPlugin = class {
2724
2784
  * Called with credentials arriving from the control pipeline.
2725
2785
  */
2726
2786
  async processCredential(credential) {
2727
- var _a;
2728
2787
  if (!credential.id) {
2729
2788
  return;
2730
2789
  }
2731
- (_a = this._processCredentialsTriggers.get(credential.id)) == null ? void 0 : _a.wake();
2790
+ this._processCredentialsTriggers.get(credential.id)?.wake();
2732
2791
  this._processedCredentials.add(credential.id);
2733
2792
  this._processCredentialsTriggers.delete(credential.id);
2734
2793
  }
@@ -2754,11 +2813,10 @@ var NotarizationPlugin = class {
2754
2813
  * Requests from other peers to notarize credentials.
2755
2814
  */
2756
2815
  async _onNotarize(request) {
2757
- var _a;
2758
2816
  if (!this._writer) {
2759
2817
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
2760
2818
  }
2761
- for (const credential of (_a = request.credentials) != null ? _a : []) {
2819
+ for (const credential of request.credentials ?? []) {
2762
2820
  invariant10(credential.id, "Credential must have an id", {
2763
2821
  F: __dxlog_file11,
2764
2822
  L: 200,
@@ -2836,7 +2894,7 @@ var NotarizationTeleportExtension = class extends RpcExtension2 {
2836
2894
  };
2837
2895
 
2838
2896
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2839
- function _ts_decorate(decorators, target, key, desc) {
2897
+ function _ts_decorate3(decorators, target, key, desc) {
2840
2898
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2841
2899
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2842
2900
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2847,9 +2905,10 @@ function _ts_decorate(decorators, target, key, desc) {
2847
2905
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2848
2906
  }
2849
2907
  var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
2908
+ var ENABLE_FEED_PURGE = false;
2850
2909
  var DataSpace = class DataSpace2 {
2851
2910
  constructor(params) {
2852
- this._ctx = new Context6();
2911
+ this._ctx = new Context7();
2853
2912
  this._notarizationPlugin = new NotarizationPlugin();
2854
2913
  this._state = SpaceState.CLOSED;
2855
2914
  /**
@@ -2858,7 +2917,6 @@ var DataSpace = class DataSpace2 {
2858
2917
  this.error = void 0;
2859
2918
  this.stateUpdate = new Event5();
2860
2919
  this.metrics = {};
2861
- var _a;
2862
2920
  this._inner = params.inner;
2863
2921
  this._inner.stateUpdate.on(this._ctx, () => this.stateUpdate.emit());
2864
2922
  this._gossip = params.gossip;
@@ -2867,7 +2925,7 @@ var DataSpace = class DataSpace2 {
2867
2925
  this._feedStore = params.feedStore;
2868
2926
  this._metadataStore = params.metadataStore;
2869
2927
  this._signingContext = params.signingContext;
2870
- this._callbacks = (_a = params.callbacks) != null ? _a : {};
2928
+ this._callbacks = params.callbacks ?? {};
2871
2929
  this.authVerifier = new TrustedKeySetAuthVerifier({
2872
2930
  trustedKeysProvider: () => new ComplexSet2(PublicKey7.hash, Array.from(this._inner.spaceState.members.keys())),
2873
2931
  update: this._inner.stateUpdate,
@@ -2907,21 +2965,20 @@ var DataSpace = class DataSpace2 {
2907
2965
  async _open() {
2908
2966
  await this._notarizationPlugin.open();
2909
2967
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
2910
- await this._inner.open();
2968
+ await this._inner.open(new Context7());
2911
2969
  this._state = SpaceState.CONTROL_ONLY;
2912
2970
  this.stateUpdate.emit();
2913
2971
  this.metrics = {};
2914
- this.metrics.open = new Date();
2972
+ this.metrics.open = /* @__PURE__ */ new Date();
2915
2973
  }
2916
2974
  async close() {
2917
2975
  await this._close();
2918
2976
  }
2919
2977
  async _close() {
2920
- var _a, _b;
2921
- await ((_b = (_a = this._callbacks).beforeClose) == null ? void 0 : _b.call(_a));
2978
+ await this._callbacks.beforeClose?.();
2922
2979
  this._state = SpaceState.CLOSED;
2923
2980
  await this._ctx.dispose();
2924
- this._ctx = new Context6();
2981
+ this._ctx = new Context7();
2925
2982
  await this.authVerifier.close();
2926
2983
  await this._inner.close();
2927
2984
  await this._inner.spaceState.removeCredentialProcessor(this._notarizationPlugin);
@@ -2940,13 +2997,13 @@ var DataSpace = class DataSpace2 {
2940
2997
  initializeDataPipelineAsync() {
2941
2998
  scheduleTask4(this._ctx, async () => {
2942
2999
  try {
2943
- this.metrics.pipelineInitBegin = new Date();
3000
+ this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
2944
3001
  await this.initializeDataPipeline();
2945
3002
  } catch (err) {
2946
3003
  if (err instanceof CancelledError) {
2947
3004
  log10("data pipeline initialization cancelled", err, {
2948
3005
  F: __dxlog_file12,
2949
- L: 193,
3006
+ L: 199,
2950
3007
  S: this,
2951
3008
  C: (f, a) => f(...a)
2952
3009
  });
@@ -2954,7 +3011,7 @@ var DataSpace = class DataSpace2 {
2954
3011
  }
2955
3012
  log10.error("Error initializing data pipeline", err, {
2956
3013
  F: __dxlog_file12,
2957
- L: 197,
3014
+ L: 203,
2958
3015
  S: this,
2959
3016
  C: (f, a) => f(...a)
2960
3017
  });
@@ -2962,12 +3019,11 @@ var DataSpace = class DataSpace2 {
2962
3019
  this.error = err;
2963
3020
  this.stateUpdate.emit();
2964
3021
  } finally {
2965
- this.metrics.ready = new Date();
3022
+ this.metrics.ready = /* @__PURE__ */ new Date();
2966
3023
  }
2967
3024
  });
2968
3025
  }
2969
3026
  async initializeDataPipeline() {
2970
- var _a, _b, _c, _d;
2971
3027
  if (this._state !== SpaceState.CONTROL_ONLY) {
2972
3028
  throw new SystemError("Invalid operation");
2973
3029
  }
@@ -2976,11 +3032,11 @@ var DataSpace = class DataSpace2 {
2976
3032
  ctx: this._ctx,
2977
3033
  breakOnStall: false
2978
3034
  });
2979
- this.metrics.controlPipelineReady = new Date();
3035
+ this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
2980
3036
  await this._createWritableFeeds();
2981
3037
  log10("writable feeds created", void 0, {
2982
3038
  F: __dxlog_file12,
2983
- L: 221,
3039
+ L: 227,
2984
3040
  S: this,
2985
3041
  C: (f, a) => f(...a)
2986
3042
  });
@@ -2993,11 +3049,11 @@ var DataSpace = class DataSpace2 {
2993
3049
  }), this._inner.controlPipeline.writer));
2994
3050
  }
2995
3051
  await this._inner.initializeDataPipeline();
2996
- this.metrics.dataPipelineOpen = new Date();
3052
+ this.metrics.dataPipelineOpen = /* @__PURE__ */ new Date();
2997
3053
  await cancelWithContext2(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
2998
3054
  log10("waiting for data pipeline to reach target timeframe", void 0, {
2999
3055
  F: __dxlog_file12,
3000
- L: 242,
3056
+ L: 248,
3001
3057
  S: this,
3002
3058
  C: (f, a) => f(...a)
3003
3059
  });
@@ -3005,17 +3061,17 @@ var DataSpace = class DataSpace2 {
3005
3061
  ctx: this._ctx,
3006
3062
  breakOnStall: false
3007
3063
  });
3008
- this.metrics.dataPipelineReady = new Date();
3064
+ this.metrics.dataPipelineReady = /* @__PURE__ */ new Date();
3009
3065
  log10("data pipeline ready", void 0, {
3010
3066
  F: __dxlog_file12,
3011
- L: 251,
3067
+ L: 257,
3012
3068
  S: this,
3013
3069
  C: (f, a) => f(...a)
3014
3070
  });
3015
- await ((_b = (_a = this._callbacks).beforeReady) == null ? void 0 : _b.call(_a));
3071
+ await this._callbacks.beforeReady?.();
3016
3072
  this._state = SpaceState.READY;
3017
3073
  this.stateUpdate.emit();
3018
- await ((_d = (_c = this._callbacks).afterReady) == null ? void 0 : _d.call(_c));
3074
+ await this._callbacks.afterReady?.();
3019
3075
  }
3020
3076
  async _createWritableFeeds() {
3021
3077
  const credentials = [];
@@ -3062,7 +3118,6 @@ var DataSpace = class DataSpace2 {
3062
3118
  await this._metadataStore.setWritableFeedKeys(this.key, this.inner.controlFeedKey, this.inner.dataFeedKey);
3063
3119
  }
3064
3120
  async createEpoch() {
3065
- var _a, _b;
3066
3121
  const epoch = await this.dataPipeline.createEpoch();
3067
3122
  const receipt = await this.inner.controlPipeline.writer.write({
3068
3123
  credential: {
@@ -3075,16 +3130,19 @@ var DataSpace = class DataSpace2 {
3075
3130
  })
3076
3131
  }
3077
3132
  });
3078
- await this.inner.controlPipeline.state.waitUntilTimeframe(new Timeframe([
3133
+ await this.inner.controlPipeline.state.waitUntilTimeframe(new Timeframe2([
3079
3134
  [
3080
3135
  receipt.feedKey,
3081
3136
  receipt.seq
3082
3137
  ]
3083
3138
  ]));
3084
- for (const feed of (_b = (_a = this.inner.dataPipeline.pipelineState) == null ? void 0 : _a.feeds) != null ? _b : []) {
3085
- const indexBeforeEpoch = epoch.timeframe.get(feed.key);
3086
- if (indexBeforeEpoch) {
3087
- await feed.clear(0, indexBeforeEpoch + 1);
3139
+ if (ENABLE_FEED_PURGE) {
3140
+ for (const feed of this.inner.dataPipeline.pipelineState?.feeds ?? []) {
3141
+ const indexBeforeEpoch = epoch.timeframe.get(feed.key);
3142
+ if (indexBeforeEpoch === void 0) {
3143
+ continue;
3144
+ }
3145
+ await feed.safeClear(0, indexBeforeEpoch + 1);
3088
3146
  }
3089
3147
  }
3090
3148
  }
@@ -3106,33 +3164,33 @@ var DataSpace = class DataSpace2 {
3106
3164
  this.stateUpdate.emit();
3107
3165
  }
3108
3166
  };
3109
- _ts_decorate([
3167
+ _ts_decorate3([
3110
3168
  synchronized
3111
3169
  ], DataSpace.prototype, "open", null);
3112
- _ts_decorate([
3170
+ _ts_decorate3([
3113
3171
  synchronized
3114
3172
  ], DataSpace.prototype, "close", null);
3115
- _ts_decorate([
3173
+ _ts_decorate3([
3116
3174
  timed(1e4)
3117
3175
  ], DataSpace.prototype, "_createWritableFeeds", null);
3118
- _ts_decorate([
3176
+ _ts_decorate3([
3119
3177
  synchronized
3120
3178
  ], DataSpace.prototype, "activate", null);
3121
- _ts_decorate([
3179
+ _ts_decorate3([
3122
3180
  synchronized
3123
3181
  ], DataSpace.prototype, "deactivate", null);
3124
- DataSpace = _ts_decorate([
3182
+ DataSpace = _ts_decorate3([
3125
3183
  trackLeaks("open", "close")
3126
3184
  ], DataSpace);
3127
3185
 
3128
3186
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
3129
3187
  import { Event as Event6, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
3130
- import { cancelWithContext as cancelWithContext3, Context as Context7 } from "@dxos/context";
3188
+ import { cancelWithContext as cancelWithContext3, Context as Context8 } from "@dxos/context";
3131
3189
  import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
3132
3190
  import { invariant as invariant11 } from "@dxos/invariant";
3133
3191
  import { PublicKey as PublicKey8 } from "@dxos/keys";
3134
3192
  import { log as log11 } from "@dxos/log";
3135
- import { trace as trace4 } from "@dxos/protocols";
3193
+ import { trace as trace5 } from "@dxos/protocols";
3136
3194
  import { SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
3137
3195
  import { Gossip, Presence } from "@dxos/teleport-extension-gossip";
3138
3196
  import { ComplexMap as ComplexMap3, deferFunction as deferFunction2 } from "@dxos/util";
@@ -3141,9 +3199,8 @@ import { ComplexMap as ComplexMap3, deferFunction as deferFunction2 } from "@dxo
3141
3199
  import { createCredential } from "@dxos/credentials";
3142
3200
  import { failUndefined as failUndefined2 } from "@dxos/debug";
3143
3201
  import { AdmittedFeed as AdmittedFeed4, SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/halo/credentials";
3144
- import { Timeframe as Timeframe2 } from "@dxos/timeframe";
3202
+ import { Timeframe as Timeframe3 } from "@dxos/timeframe";
3145
3203
  var spaceGenesis = async (keyring, signingContext, space) => {
3146
- var _a, _b, _c, _d;
3147
3204
  const credentials = [
3148
3205
  await createCredential({
3149
3206
  signer: keyring,
@@ -3163,11 +3220,11 @@ var spaceGenesis = async (keyring, signingContext, space) => {
3163
3220
  spaceKey: space.key,
3164
3221
  role: SpaceMember2.Role.ADMIN,
3165
3222
  profile: signingContext.profile,
3166
- genesisFeedKey: (_a = space.controlFeedKey) != null ? _a : failUndefined2()
3223
+ genesisFeedKey: space.controlFeedKey ?? failUndefined2()
3167
3224
  }
3168
3225
  }),
3169
3226
  await signingContext.credentialSigner.createCredential({
3170
- subject: (_b = space.controlFeedKey) != null ? _b : failUndefined2(),
3227
+ subject: space.controlFeedKey ?? failUndefined2(),
3171
3228
  assertion: {
3172
3229
  "@type": "dxos.halo.credentials.AdmittedFeed",
3173
3230
  spaceKey: space.key,
@@ -3177,7 +3234,7 @@ var spaceGenesis = async (keyring, signingContext, space) => {
3177
3234
  }
3178
3235
  }),
3179
3236
  await signingContext.credentialSigner.createCredential({
3180
- subject: (_c = space.dataFeedKey) != null ? _c : failUndefined2(),
3237
+ subject: space.dataFeedKey ?? failUndefined2(),
3181
3238
  assertion: {
3182
3239
  "@type": "dxos.halo.credentials.AdmittedFeed",
3183
3240
  spaceKey: space.key,
@@ -3187,12 +3244,12 @@ var spaceGenesis = async (keyring, signingContext, space) => {
3187
3244
  }
3188
3245
  }),
3189
3246
  await signingContext.credentialSigner.createCredential({
3190
- subject: (_d = space.key) != null ? _d : failUndefined2(),
3247
+ subject: space.key ?? failUndefined2(),
3191
3248
  assertion: {
3192
3249
  "@type": "dxos.halo.credentials.Epoch",
3193
3250
  number: 0,
3194
3251
  previousId: void 0,
3195
- timeframe: new Timeframe2(),
3252
+ timeframe: new Timeframe3(),
3196
3253
  snapshotCid: void 0
3197
3254
  }
3198
3255
  })
@@ -3208,7 +3265,7 @@ var spaceGenesis = async (keyring, signingContext, space) => {
3208
3265
  };
3209
3266
 
3210
3267
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
3211
- function _ts_decorate2(decorators, target, key, desc) {
3268
+ function _ts_decorate4(decorators, target, key, desc) {
3212
3269
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3213
3270
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3214
3271
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3227,7 +3284,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3227
3284
  this._keyring = _keyring;
3228
3285
  this._signingContext = _signingContext;
3229
3286
  this._feedStore = _feedStore;
3230
- this._ctx = new Context7();
3287
+ this._ctx = new Context8();
3231
3288
  this.updated = new Event6();
3232
3289
  this._spaces = new ComplexMap3(PublicKey8.hash);
3233
3290
  this._isOpen = false;
@@ -3244,7 +3301,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3244
3301
  S: this,
3245
3302
  C: (f, a) => f(...a)
3246
3303
  });
3247
- log11.trace("dxos.echo.data-space-manager.open", trace4.begin({
3304
+ log11.trace("dxos.echo.data-space-manager.open", trace5.begin({
3248
3305
  id: this._instanceId
3249
3306
  }), {
3250
3307
  F: __dxlog_file13,
@@ -3289,7 +3346,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3289
3346
  }
3290
3347
  this._isOpen = true;
3291
3348
  this.updated.emit();
3292
- log11.trace("dxos.echo.data-space-manager.open", trace4.end({
3349
+ log11.trace("dxos.echo.data-space-manager.open", trace5.end({
3293
3350
  id: this._instanceId
3294
3351
  }), {
3295
3352
  F: __dxlog_file13,
@@ -3452,7 +3509,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3452
3509
  onAuthFailure: () => {
3453
3510
  log11.warn("auth failure", void 0, {
3454
3511
  F: __dxlog_file13,
3455
- L: 213,
3512
+ L: 217,
3456
3513
  S: this,
3457
3514
  C: (f, a) => f(...a)
3458
3515
  });
@@ -3476,7 +3533,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3476
3533
  space: space.key
3477
3534
  }, {
3478
3535
  F: __dxlog_file13,
3479
- L: 231,
3536
+ L: 235,
3480
3537
  S: this,
3481
3538
  C: (f, a) => f(...a)
3482
3539
  });
@@ -3488,7 +3545,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3488
3545
  open: this._isOpen
3489
3546
  }, {
3490
3547
  F: __dxlog_file13,
3491
- L: 238,
3548
+ L: 242,
3492
3549
  S: this,
3493
3550
  C: (f, a) => f(...a)
3494
3551
  });
@@ -3501,7 +3558,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3501
3558
  space: space.key
3502
3559
  }, {
3503
3560
  F: __dxlog_file13,
3504
- L: 244,
3561
+ L: 248,
3505
3562
  S: this,
3506
3563
  C: (f, a) => f(...a)
3507
3564
  });
@@ -3523,19 +3580,19 @@ var DataSpaceManager = class DataSpaceManager2 {
3523
3580
  return dataSpace;
3524
3581
  }
3525
3582
  };
3526
- _ts_decorate2([
3583
+ _ts_decorate4([
3527
3584
  synchronized2
3528
3585
  ], DataSpaceManager.prototype, "open", null);
3529
- _ts_decorate2([
3586
+ _ts_decorate4([
3530
3587
  synchronized2
3531
3588
  ], DataSpaceManager.prototype, "close", null);
3532
- _ts_decorate2([
3589
+ _ts_decorate4([
3533
3590
  synchronized2
3534
3591
  ], DataSpaceManager.prototype, "createSpace", null);
3535
- _ts_decorate2([
3592
+ _ts_decorate4([
3536
3593
  synchronized2
3537
3594
  ], DataSpaceManager.prototype, "acceptSpace", null);
3538
- DataSpaceManager = _ts_decorate2([
3595
+ DataSpaceManager = _ts_decorate4([
3539
3596
  trackLeaks2("open", "close")
3540
3597
  ], DataSpaceManager);
3541
3598
 
@@ -3566,9 +3623,8 @@ var SpacesServiceImpl = class {
3566
3623
  return this._serializeSpace(space);
3567
3624
  }
3568
3625
  async updateSpace({ spaceKey, state }) {
3569
- var _a;
3570
3626
  const dataSpaceManager = await this._getDataSpaceManager();
3571
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3627
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3572
3628
  if (state) {
3573
3629
  switch (state) {
3574
3630
  case SpaceState3.ACTIVE:
@@ -3599,7 +3655,7 @@ var SpacesServiceImpl = class {
3599
3655
  spaces
3600
3656
  });
3601
3657
  }, {
3602
- maxFrequency: 2
3658
+ maxFrequency: false ? void 0 : 2
3603
3659
  });
3604
3660
  scheduleTask5(ctx, async () => {
3605
3661
  const dataSpaceManager = await this._getDataSpaceManager();
@@ -3632,17 +3688,15 @@ var SpacesServiceImpl = class {
3632
3688
  });
3633
3689
  }
3634
3690
  async postMessage({ spaceKey, channel, message }) {
3635
- var _a;
3636
3691
  const dataSpaceManager = await this._getDataSpaceManager();
3637
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3692
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3638
3693
  await space.postMessage(getChannelId(channel), message);
3639
3694
  }
3640
3695
  subscribeMessages({ spaceKey, channel }) {
3641
3696
  return new Stream10(({ ctx, next }) => {
3642
3697
  scheduleTask5(ctx, async () => {
3643
- var _a;
3644
3698
  const dataSpaceManager = await this._getDataSpaceManager();
3645
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3699
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3646
3700
  const handle = space.listen(getChannelId(channel), (message) => {
3647
3701
  next(message);
3648
3702
  });
@@ -3652,8 +3706,7 @@ var SpacesServiceImpl = class {
3652
3706
  }
3653
3707
  queryCredentials({ spaceKey }) {
3654
3708
  return new Stream10(({ ctx, next }) => {
3655
- var _a;
3656
- const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3709
+ const space = this._spaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3657
3710
  const processor = {
3658
3711
  processCredential: async (credential) => {
3659
3712
  next(credential);
@@ -3664,9 +3717,8 @@ var SpacesServiceImpl = class {
3664
3717
  });
3665
3718
  }
3666
3719
  async writeCredentials({ spaceKey, credentials }) {
3667
- var _a;
3668
- const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3669
- for (const credential of credentials != null ? credentials : []) {
3720
+ const space = this._spaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3721
+ for (const credential of credentials ?? []) {
3670
3722
  await space.controlPipeline.writer.write({
3671
3723
  credential: {
3672
3724
  credential
@@ -3675,13 +3727,11 @@ var SpacesServiceImpl = class {
3675
3727
  }
3676
3728
  }
3677
3729
  async createEpoch({ spaceKey }) {
3678
- var _a;
3679
3730
  const dataSpaceManager = await this._getDataSpaceManager();
3680
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3731
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3681
3732
  await space.createEpoch();
3682
3733
  }
3683
3734
  _serializeSpace(space) {
3684
- var _a, _b, _c, _d, _e, _f, _g;
3685
3735
  return {
3686
3736
  spaceKey: space.key,
3687
3737
  state: space.state,
@@ -3693,16 +3743,15 @@ var SpacesServiceImpl = class {
3693
3743
  currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
3694
3744
  targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
3695
3745
  totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe,
3696
- dataFeeds: (_b = (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.feeds.map((feed) => feed.key)) != null ? _b : [],
3697
- startDataTimeframe: (_c = space.dataPipeline.pipelineState) == null ? void 0 : _c.startTimeframe,
3698
- currentDataTimeframe: (_d = space.dataPipeline.pipelineState) == null ? void 0 : _d.timeframe,
3699
- targetDataTimeframe: (_e = space.dataPipeline.pipelineState) == null ? void 0 : _e.targetTimeframe,
3700
- totalDataTimeframe: (_f = space.dataPipeline.pipelineState) == null ? void 0 : _f.endTimeframe
3746
+ dataFeeds: space.dataPipeline.pipelineState?.feeds.map((feed) => feed.key) ?? [],
3747
+ startDataTimeframe: space.dataPipeline.pipelineState?.startTimeframe,
3748
+ currentDataTimeframe: space.dataPipeline.pipelineState?.timeframe,
3749
+ targetDataTimeframe: space.dataPipeline.pipelineState?.targetTimeframe,
3750
+ totalDataTimeframe: space.dataPipeline.pipelineState?.endTimeframe
3701
3751
  },
3702
3752
  members: Array.from(space.inner.spaceState.members.values()).map((member) => {
3703
- var _a2, _b2, _c2;
3704
3753
  const peers = space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key));
3705
- const isMe = (_a2 = this._identityManager.identity) == null ? void 0 : _a2.identityKey.equals(member.key);
3754
+ const isMe = this._identityManager.identity?.identityKey.equals(member.key);
3706
3755
  if (isMe) {
3707
3756
  peers.push(space.presence.getLocalState());
3708
3757
  }
@@ -3710,14 +3759,14 @@ var SpacesServiceImpl = class {
3710
3759
  identity: {
3711
3760
  identityKey: member.key,
3712
3761
  profile: {
3713
- displayName: (_c2 = (_b2 = member.assertion.profile) == null ? void 0 : _b2.displayName) != null ? _c2 : humanize(member.key)
3762
+ displayName: member.assertion.profile?.displayName ?? humanize(member.key)
3714
3763
  }
3715
3764
  },
3716
3765
  presence: isMe || peers.length > 0 ? SpaceMember3.PresenceState.ONLINE : SpaceMember3.PresenceState.OFFLINE,
3717
3766
  peerStates: peers
3718
3767
  };
3719
3768
  }),
3720
- creator: (_g = space.inner.spaceState.creator) == null ? void 0 : _g.key,
3769
+ creator: space.inner.spaceState.creator?.key,
3721
3770
  cache: space.cache,
3722
3771
  metrics: space.metrics
3723
3772
  };
@@ -3727,6 +3776,7 @@ var getChannelId = (channel) => `user-channel/${channel}`;
3727
3776
 
3728
3777
  // packages/sdk/client-services/src/packlets/services/service-context.ts
3729
3778
  import { Trigger as Trigger5 } from "@dxos/async";
3779
+ import { Context as Context9 } from "@dxos/context";
3730
3780
  import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
3731
3781
  import { failUndefined as failUndefined3 } from "@dxos/debug";
3732
3782
  import { valueEncoding, MetadataStore, SpaceManager, DataServiceSubscriptions, SnapshotStore } from "@dxos/echo-pipeline";
@@ -3735,11 +3785,23 @@ import { invariant as invariant12 } from "@dxos/invariant";
3735
3785
  import { Keyring } from "@dxos/keyring";
3736
3786
  import { PublicKey as PublicKey9 } from "@dxos/keys";
3737
3787
  import { log as log13 } from "@dxos/log";
3738
- import { STORAGE_VERSION as STORAGE_VERSION2, trace as trace5 } from "@dxos/protocols";
3788
+ import { STORAGE_VERSION as STORAGE_VERSION2, trace as trace6 } from "@dxos/protocols";
3739
3789
  import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
3740
3790
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
3791
+ import { trace as Trace2 } from "@dxos/tracing";
3792
+ import { safeInstanceof } from "@dxos/util";
3793
+ function _ts_decorate5(decorators, target, key, desc) {
3794
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3795
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3796
+ r = Reflect.decorate(decorators, target, key, desc);
3797
+ else
3798
+ for (var i = decorators.length - 1; i >= 0; i--)
3799
+ if (d = decorators[i])
3800
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3801
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
3802
+ }
3741
3803
  var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
3742
- var ServiceContext = class {
3804
+ var ServiceContext = class ServiceContext2 {
3743
3805
  // prettier-ignore
3744
3806
  constructor(storage, networkManager, signalManager, modelFactory) {
3745
3807
  this.storage = storage;
@@ -3759,7 +3821,8 @@ var ServiceContext = class {
3759
3821
  root: storage.createDirectory("feeds"),
3760
3822
  signer: this.keyring,
3761
3823
  hypercore: {
3762
- valueEncoding
3824
+ valueEncoding,
3825
+ stats: true
3763
3826
  }
3764
3827
  })
3765
3828
  });
@@ -3773,61 +3836,57 @@ var ServiceContext = class {
3773
3836
  });
3774
3837
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager);
3775
3838
  this.invitations = new InvitationsHandler(this.networkManager);
3776
- this._handlerFactories.set(Invitation5.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => {
3777
- var _a;
3778
- return (_a = this.identityManager.identity) != null ? _a : failUndefined3();
3779
- }, this._acceptIdentity.bind(this)));
3839
+ this._handlerFactories.set(Invitation5.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined3(), this._acceptIdentity.bind(this)));
3780
3840
  }
3781
- async open() {
3841
+ async open(ctx) {
3782
3842
  await this._checkStorageVersion();
3783
3843
  log13("opening...", void 0, {
3784
3844
  F: __dxlog_file15,
3785
- L: 127,
3845
+ L: 135,
3786
3846
  S: this,
3787
3847
  C: (f, a) => f(...a)
3788
3848
  });
3789
- log13.trace("dxos.sdk.service-context.open", trace5.begin({
3849
+ log13.trace("dxos.sdk.service-context.open", trace6.begin({
3790
3850
  id: this._instanceId
3791
3851
  }), {
3792
3852
  F: __dxlog_file15,
3793
- L: 128,
3853
+ L: 136,
3794
3854
  S: this,
3795
3855
  C: (f, a) => f(...a)
3796
3856
  });
3797
3857
  await this.signalManager.open();
3798
3858
  await this.networkManager.open();
3799
3859
  await this.spaceManager.open();
3800
- await this.identityManager.open();
3860
+ await this.identityManager.open(ctx);
3801
3861
  if (this.identityManager.identity) {
3802
- await this._initialize();
3862
+ await this._initialize(ctx);
3803
3863
  }
3804
- log13.trace("dxos.sdk.service-context.open", trace5.end({
3864
+ log13.trace("dxos.sdk.service-context.open", trace6.end({
3805
3865
  id: this._instanceId
3806
3866
  }), {
3807
3867
  F: __dxlog_file15,
3808
- L: 136,
3868
+ L: 144,
3809
3869
  S: this,
3810
3870
  C: (f, a) => f(...a)
3811
3871
  });
3812
3872
  log13("opened", void 0, {
3813
3873
  F: __dxlog_file15,
3814
- L: 137,
3874
+ L: 145,
3815
3875
  S: this,
3816
3876
  C: (f, a) => f(...a)
3817
3877
  });
3818
3878
  }
3819
3879
  async close() {
3820
- var _a;
3821
3880
  log13("closing...", void 0, {
3822
3881
  F: __dxlog_file15,
3823
- L: 141,
3882
+ L: 149,
3824
3883
  S: this,
3825
3884
  C: (f, a) => f(...a)
3826
3885
  });
3827
3886
  if (this._deviceSpaceSync && this.identityManager.identity) {
3828
3887
  await this.identityManager.identity.space.spaceState.removeCredentialProcessor(this._deviceSpaceSync);
3829
3888
  }
3830
- await ((_a = this.dataSpaceManager) == null ? void 0 : _a.close());
3889
+ await this.dataSpaceManager?.close();
3831
3890
  await this.identityManager.close();
3832
3891
  await this.spaceManager.close();
3833
3892
  await this.feedStore.close();
@@ -3836,21 +3895,21 @@ var ServiceContext = class {
3836
3895
  this.dataServiceSubscriptions.clear();
3837
3896
  log13("closed", void 0, {
3838
3897
  F: __dxlog_file15,
3839
- L: 152,
3898
+ L: 160,
3840
3899
  S: this,
3841
3900
  C: (f, a) => f(...a)
3842
3901
  });
3843
3902
  }
3844
3903
  async createIdentity(params = {}) {
3845
3904
  const identity = await this.identityManager.createIdentity(params);
3846
- await this._initialize();
3905
+ await this._initialize(new Context9());
3847
3906
  return identity;
3848
3907
  }
3849
3908
  getInvitationHandler(invitation) {
3850
3909
  const factory = this._handlerFactories.get(invitation.kind);
3851
3910
  invariant12(factory, `Unknown invitation kind: ${invitation.kind}`, {
3852
3911
  F: __dxlog_file15,
3853
- L: 164,
3912
+ L: 171,
3854
3913
  S: this,
3855
3914
  A: [
3856
3915
  "factory",
@@ -3861,7 +3920,7 @@ var ServiceContext = class {
3861
3920
  }
3862
3921
  async _acceptIdentity(params) {
3863
3922
  const identity = await this.identityManager.acceptIdentity(params);
3864
- await this._initialize();
3923
+ await this._initialize(new Context9());
3865
3924
  return identity;
3866
3925
  }
3867
3926
  async _checkStorageVersion() {
@@ -3871,15 +3930,14 @@ var ServiceContext = class {
3871
3930
  }
3872
3931
  }
3873
3932
  // Called when identity is created.
3874
- async _initialize() {
3875
- var _a;
3933
+ async _initialize(ctx) {
3876
3934
  log13("initializing spaces...", void 0, {
3877
3935
  F: __dxlog_file15,
3878
- L: 185,
3936
+ L: 192,
3879
3937
  S: this,
3880
3938
  C: (f, a) => f(...a)
3881
3939
  });
3882
- const identity = (_a = this.identityManager.identity) != null ? _a : failUndefined3();
3940
+ const identity = this.identityManager.identity ?? failUndefined3();
3883
3941
  const signingContext = {
3884
3942
  credentialSigner: identity.getIdentityCredentialSigner(),
3885
3943
  identityKey: identity.identityKey,
@@ -3898,7 +3956,7 @@ var ServiceContext = class {
3898
3956
  this._handlerFactories.set(Invitation5.Kind.SPACE, (invitation) => {
3899
3957
  invariant12(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
3900
3958
  F: __dxlog_file15,
3901
- L: 208,
3959
+ L: 215,
3902
3960
  S: this,
3903
3961
  A: [
3904
3962
  "this.dataSpaceManager",
@@ -3922,7 +3980,7 @@ var ServiceContext = class {
3922
3980
  details: assertion
3923
3981
  }, {
3924
3982
  F: __dxlog_file15,
3925
- L: 224,
3983
+ L: 231,
3926
3984
  S: this,
3927
3985
  C: (f, a) => f(...a)
3928
3986
  });
@@ -3933,7 +3991,7 @@ var ServiceContext = class {
3933
3991
  details: assertion
3934
3992
  }, {
3935
3993
  F: __dxlog_file15,
3936
- L: 228,
3994
+ L: 235,
3937
3995
  S: this,
3938
3996
  C: (f, a) => f(...a)
3939
3997
  });
@@ -3944,7 +4002,7 @@ var ServiceContext = class {
3944
4002
  details: assertion
3945
4003
  }, {
3946
4004
  F: __dxlog_file15,
3947
- L: 233,
4005
+ L: 240,
3948
4006
  S: this,
3949
4007
  C: (f, a) => f(...a)
3950
4008
  });
@@ -3955,7 +4013,7 @@ var ServiceContext = class {
3955
4013
  } catch (err) {
3956
4014
  log13.catch(err, void 0, {
3957
4015
  F: __dxlog_file15,
3958
- L: 239,
4016
+ L: 246,
3959
4017
  S: this,
3960
4018
  C: (f, a) => f(...a)
3961
4019
  });
@@ -3965,12 +4023,22 @@ var ServiceContext = class {
3965
4023
  await identity.space.spaceState.addCredentialProcessor(this._deviceSpaceSync);
3966
4024
  }
3967
4025
  };
4026
+ _ts_decorate5([
4027
+ Trace2.span()
4028
+ ], ServiceContext.prototype, "open", null);
4029
+ _ts_decorate5([
4030
+ Trace2.span()
4031
+ ], ServiceContext.prototype, "_initialize", null);
4032
+ ServiceContext = _ts_decorate5([
4033
+ safeInstanceof("dxos.client-services.ServiceContext"),
4034
+ Trace2.resource()
4035
+ ], ServiceContext);
3968
4036
 
3969
4037
  // packages/sdk/client-services/src/packlets/locks/browser.ts
3970
4038
  import { asyncTimeout, Trigger as Trigger6 } from "@dxos/async";
3971
4039
  import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
3972
4040
  import { log as log14, logInfo } from "@dxos/log";
3973
- function _ts_decorate3(decorators, target, key, desc) {
4041
+ function _ts_decorate6(decorators, target, key, desc) {
3974
4042
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3975
4043
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3976
4044
  r = Reflect.decorate(decorators, target, key, desc);
@@ -4015,7 +4083,7 @@ var Lock = class {
4015
4083
  S: this,
4016
4084
  C: (f, a) => f(...a)
4017
4085
  });
4018
- } catch (e) {
4086
+ } catch {
4019
4087
  log14("stealing lock...", void 0, {
4020
4088
  F: __dxlog_file16,
4021
4089
  L: 46,
@@ -4052,8 +4120,7 @@ var Lock = class {
4052
4120
  void navigator.locks.request(this._lockKey, {
4053
4121
  steal
4054
4122
  }, async () => {
4055
- var _a, _b;
4056
- await ((_a = this._onAcquire) == null ? void 0 : _a.call(this));
4123
+ await this._onAcquire?.();
4057
4124
  acquired.wake();
4058
4125
  this._releaseTrigger = new Trigger6();
4059
4126
  await this._releaseTrigger.wait();
@@ -4063,7 +4130,7 @@ var Lock = class {
4063
4130
  S: this,
4064
4131
  C: (f, a) => f(...a)
4065
4132
  });
4066
- await ((_b = this._onRelease) == null ? void 0 : _b.call(this));
4133
+ await this._onRelease?.();
4067
4134
  log14("released lock", void 0, {
4068
4135
  F: __dxlog_file16,
4069
4136
  L: 74,
@@ -4071,8 +4138,7 @@ var Lock = class {
4071
4138
  C: (f, a) => f(...a)
4072
4139
  });
4073
4140
  }).catch(async () => {
4074
- var _a;
4075
- await ((_a = this._onRelease) == null ? void 0 : _a.call(this));
4141
+ await this._onRelease?.();
4076
4142
  });
4077
4143
  await acquired.wait();
4078
4144
  log14("recieved lock", {
@@ -4085,7 +4151,7 @@ var Lock = class {
4085
4151
  });
4086
4152
  }
4087
4153
  };
4088
- _ts_decorate3([
4154
+ _ts_decorate6([
4089
4155
  logInfo
4090
4156
  ], Lock.prototype, "lockKey", null);
4091
4157
  var isLocked = (lockPath) => {
@@ -4100,7 +4166,7 @@ import { createStorage, StorageType } from "@dxos/random-access-storage";
4100
4166
  import { isNode } from "@dxos/util";
4101
4167
  var StorageDriver = Runtime.Client.Storage.StorageDriver;
4102
4168
  var createStorageObjects = (config) => {
4103
- const { path = isNode() ? DX_DATA : "dxos/storage", storageType, keyStorage, persistent = false } = config != null ? config : {};
4169
+ const { path = isNode() ? DX_DATA : "dxos/storage", storageType, keyStorage, persistent = false } = config ?? {};
4104
4170
  if (persistent && storageType === StorageDriver.RAM) {
4105
4171
  throw new InvalidConfigError("RAM storage cannot be used in persistent mode.");
4106
4172
  }
@@ -4168,6 +4234,7 @@ var ServiceRegistry = class {
4168
4234
  // packages/sdk/client-services/src/packlets/services/service-host.ts
4169
4235
  import { Event as Event8, synchronized as synchronized3 } from "@dxos/async";
4170
4236
  import { clientServiceBundle } from "@dxos/client-protocol";
4237
+ import { Context as Context10 } from "@dxos/context";
4171
4238
  import { DocumentModel as DocumentModel2 } from "@dxos/document-model";
4172
4239
  import { DataServiceImpl } from "@dxos/echo-pipeline";
4173
4240
  import { invariant as invariant13 } from "@dxos/invariant";
@@ -4176,9 +4243,10 @@ import { log as log16 } from "@dxos/log";
4176
4243
  import { WebsocketSignalManager } from "@dxos/messaging";
4177
4244
  import { ModelFactory } from "@dxos/model-factory";
4178
4245
  import { createWebRTCTransportFactory, NetworkManager } from "@dxos/network-manager";
4179
- import { trace as trace6 } from "@dxos/protocols";
4246
+ import { trace as trace7 } from "@dxos/protocols";
4180
4247
  import { SystemStatus } from "@dxos/protocols/proto/dxos/client/services";
4181
4248
  import { TextModel } from "@dxos/text-model";
4249
+ import { TRACE_PROCESSOR, trace as Trace3 } from "@dxos/tracing";
4182
4250
 
4183
4251
  // packages/sdk/client-services/src/packlets/devices/devices-service.ts
4184
4252
  import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
@@ -4194,21 +4262,17 @@ var DevicesServiceImpl = class {
4194
4262
  queryDevices() {
4195
4263
  return new Stream11(({ next }) => {
4196
4264
  const update = () => {
4197
- var _a;
4198
- const deviceKeys = (_a = this._identityManager.identity) == null ? void 0 : _a.authorizedDeviceKeys;
4265
+ const deviceKeys = this._identityManager.identity?.authorizedDeviceKeys;
4199
4266
  if (!deviceKeys) {
4200
4267
  next({
4201
4268
  devices: []
4202
4269
  });
4203
4270
  } else {
4204
4271
  next({
4205
- devices: Array.from(deviceKeys.values()).map((key) => {
4206
- var _a2;
4207
- return {
4208
- deviceKey: key,
4209
- kind: ((_a2 = this._identityManager.identity) == null ? void 0 : _a2.deviceKey.equals(key)) ? DeviceKind.CURRENT : DeviceKind.TRUSTED
4210
- };
4211
- })
4272
+ devices: Array.from(deviceKeys.values()).map((key) => ({
4273
+ deviceKey: key,
4274
+ kind: this._identityManager.identity?.deviceKey.equals(key) ? DeviceKind.CURRENT : DeviceKind.TRUSTED
4275
+ }))
4212
4276
  });
4213
4277
  }
4214
4278
  };
@@ -4236,7 +4300,7 @@ import { jsonify, numericalValues, tracer } from "@dxos/util";
4236
4300
  var LoggingServiceImpl = class {
4237
4301
  constructor() {
4238
4302
  this._logs = new Event7();
4239
- this._started = new Date();
4303
+ this._started = /* @__PURE__ */ new Date();
4240
4304
  this._logProcessor = (_config, entry2) => {
4241
4305
  this._logs.emit(entry2);
4242
4306
  };
@@ -4266,8 +4330,7 @@ var LoggingServiceImpl = class {
4266
4330
  */
4267
4331
  queryMetrics({ interval = 5e3 }) {
4268
4332
  const getNumericalValues = (key) => {
4269
- var _a;
4270
- const events = (_a = tracer.get(key)) != null ? _a : [];
4333
+ const events = tracer.get(key) ?? [];
4271
4334
  return {
4272
4335
  key,
4273
4336
  stats: numericalValues(events, "duration")
@@ -4276,14 +4339,14 @@ var LoggingServiceImpl = class {
4276
4339
  return new Stream12(({ next }) => {
4277
4340
  const update = () => {
4278
4341
  const metrics = {
4279
- timestamp: new Date(),
4342
+ timestamp: /* @__PURE__ */ new Date(),
4280
4343
  values: [
4281
4344
  getNumericalValues("dxos.echo.pipeline.control"),
4282
4345
  getNumericalValues("dxos.echo.pipeline.data")
4283
4346
  ].filter(Boolean)
4284
4347
  };
4285
4348
  next({
4286
- timestamp: new Date(),
4349
+ timestamp: /* @__PURE__ */ new Date(),
4287
4350
  metrics
4288
4351
  });
4289
4352
  };
@@ -4297,11 +4360,10 @@ var LoggingServiceImpl = class {
4297
4360
  queryLogs(request) {
4298
4361
  return new Stream12(({ ctx, next }) => {
4299
4362
  const handler = (entry2) => {
4300
- var _a, _b, _c, _d, _e;
4301
4363
  if (LOG_PROCESSING > 0) {
4302
4364
  return;
4303
4365
  }
4304
- if (((_a = entry2.meta) == null ? void 0 : _a.F.includes("logging-service")) || entry2.context && Object.values(entry2.context).some((value) => typeof value === "string" && value.includes("LoggingService"))) {
4366
+ if (entry2.meta?.F.includes("logging-service") || entry2.context && Object.values(entry2.context).some((value) => typeof value === "string" && value.includes("LoggingService"))) {
4305
4367
  return;
4306
4368
  }
4307
4369
  if (!shouldLog(entry2, request)) {
@@ -4310,11 +4372,11 @@ var LoggingServiceImpl = class {
4310
4372
  const record = {
4311
4373
  ...entry2,
4312
4374
  context: jsonify(getContextFromEntry(entry2)),
4313
- timestamp: new Date(),
4375
+ timestamp: /* @__PURE__ */ new Date(),
4314
4376
  meta: {
4315
4377
  // TODO(dmaretskyi): Fix proto.
4316
- file: (_c = (_b = entry2.meta) == null ? void 0 : _b.F) != null ? _c : "",
4317
- line: (_e = (_d = entry2.meta) == null ? void 0 : _d.L) != null ? _e : 0
4378
+ file: entry2.meta?.F ?? "",
4379
+ line: entry2.meta?.L ?? 0
4318
4380
  }
4319
4381
  };
4320
4382
  try {
@@ -4337,15 +4399,11 @@ var matchFilter = (filter, level, path, options) => {
4337
4399
  }
4338
4400
  };
4339
4401
  var shouldLog = (entry2, request) => {
4340
- var _a;
4341
- const options = (_a = request.options) != null ? _a : QueryLogsRequest.MatchingOptions.INCLUSIVE;
4402
+ const options = request.options ?? QueryLogsRequest.MatchingOptions.INCLUSIVE;
4342
4403
  if (request.filters === void 0) {
4343
4404
  return options === QueryLogsRequest.MatchingOptions.INCLUSIVE;
4344
4405
  } else {
4345
- return request.filters.some((filter) => {
4346
- var _a2, _b;
4347
- return matchFilter(filter, entry2.level, (_b = (_a2 = entry2.meta) == null ? void 0 : _a2.F) != null ? _b : "", options);
4348
- });
4406
+ return request.filters.some((filter) => matchFilter(filter, entry2.level, entry2.meta?.F ?? "", options));
4349
4407
  }
4350
4408
  };
4351
4409
  var LOG_PROCESSING = 0;
@@ -4396,8 +4454,7 @@ var SystemServiceImpl = class {
4396
4454
  this._onReset = onReset;
4397
4455
  }
4398
4456
  async getConfig() {
4399
- var _a, _b;
4400
- return (_b = (_a = this._config) == null ? void 0 : _a.values) != null ? _b : {};
4457
+ return this._config?.values ?? {};
4401
4458
  }
4402
4459
  /**
4403
4460
  * NOTE: Since this is serialized as a JSON object, we allow the option to serialize keys.
@@ -4405,7 +4462,7 @@ var SystemServiceImpl = class {
4405
4462
  async getDiagnostics({ keys } = {}) {
4406
4463
  const diagnostics = await this._getDiagnostics();
4407
4464
  return {
4408
- timestamp: new Date(),
4465
+ timestamp: /* @__PURE__ */ new Date(),
4409
4466
  diagnostics: JSON.parse(JSON.stringify(diagnostics, jsonKeyReplacer({
4410
4467
  truncate: keys === GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
4411
4468
  humanize: keys === GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
@@ -4438,7 +4495,7 @@ var SystemServiceImpl = class {
4438
4495
  };
4439
4496
 
4440
4497
  // packages/sdk/client-services/src/packlets/services/service-host.ts
4441
- function _ts_decorate4(decorators, target, key, desc) {
4498
+ function _ts_decorate7(decorators, target, key, desc) {
4442
4499
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4443
4500
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
4444
4501
  r = Reflect.decorate(decorators, target, key, desc);
@@ -4452,7 +4509,7 @@ var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/s
4452
4509
  var createDefaultModelFactory = () => {
4453
4510
  return new ModelFactory().registerModel(DocumentModel2).registerModel(TextModel);
4454
4511
  };
4455
- var ClientServicesHost = class {
4512
+ var ClientServicesHost = class ClientServicesHost2 {
4456
4513
  constructor({
4457
4514
  config,
4458
4515
  modelFactory = createDefaultModelFactory(),
@@ -4463,6 +4520,7 @@ var ClientServicesHost = class {
4463
4520
  lockKey,
4464
4521
  callbacks
4465
4522
  } = {}) {
4523
+ this._tracingService = TRACE_PROCESSOR.createTraceSender();
4466
4524
  this._statusUpdate = new Event8();
4467
4525
  this._opening = false;
4468
4526
  this._open = false;
@@ -4481,7 +4539,7 @@ var ClientServicesHost = class {
4481
4539
  lockKey,
4482
4540
  onAcquire: () => {
4483
4541
  if (!this._opening) {
4484
- void this.open();
4542
+ void this.open(new Context10());
4485
4543
  }
4486
4544
  },
4487
4545
  onRelease: () => this.close()
@@ -4495,11 +4553,10 @@ var ClientServicesHost = class {
4495
4553
  return createDiagnostics(this._serviceRegistry.services, this._serviceContext, this._config);
4496
4554
  },
4497
4555
  onUpdateStatus: async (status) => {
4498
- var _a, _b;
4499
4556
  if (!this.isOpen && status === SystemStatus.ACTIVE) {
4500
- await ((_a = this._resourceLock) == null ? void 0 : _a.acquire());
4557
+ await this._resourceLock?.acquire();
4501
4558
  } else if (this.isOpen && status === SystemStatus.INACTIVE) {
4502
- await ((_b = this._resourceLock) == null ? void 0 : _b.release());
4559
+ await this._resourceLock?.release();
4503
4560
  }
4504
4561
  },
4505
4562
  onReset: async () => {
@@ -4508,7 +4565,8 @@ var ClientServicesHost = class {
4508
4565
  });
4509
4566
  this._loggingService = new LoggingServiceImpl();
4510
4567
  this._serviceRegistry = new ServiceRegistry(clientServiceBundle, {
4511
- SystemService: this._systemService
4568
+ SystemService: this._systemService,
4569
+ TracingService: this._tracingService
4512
4570
  });
4513
4571
  }
4514
4572
  get isOpen() {
@@ -4535,26 +4593,25 @@ var ClientServicesHost = class {
4535
4593
  * Can only be called once.
4536
4594
  */
4537
4595
  initialize({ config, ...options }) {
4538
- var _a, _b, _c;
4539
4596
  invariant13(!this._open, "service host is open", {
4540
4597
  F: __dxlog_file17,
4541
- L: 172,
4598
+ L: 181,
4542
4599
  S: this,
4543
4600
  A: [
4544
4601
  "!this._open",
4545
4602
  "'service host is open'"
4546
4603
  ]
4547
4604
  });
4548
- log16.info("initializing...", void 0, {
4605
+ log16("initializing...", void 0, {
4549
4606
  F: __dxlog_file17,
4550
- L: 173,
4607
+ L: 182,
4551
4608
  S: this,
4552
4609
  C: (f, a) => f(...a)
4553
4610
  });
4554
4611
  if (config) {
4555
4612
  invariant13(!this._config, "config already set", {
4556
4613
  F: __dxlog_file17,
4557
- L: 176,
4614
+ L: 185,
4558
4615
  S: this,
4559
4616
  A: [
4560
4617
  "!this._config",
@@ -4567,12 +4624,12 @@ var ClientServicesHost = class {
4567
4624
  }
4568
4625
  }
4569
4626
  const { connectionLog = true, transportFactory = createWebRTCTransportFactory({
4570
- iceServers: (_a = this._config) == null ? void 0 : _a.get("runtime.services.ice")
4571
- }), signalManager = new WebsocketSignalManager((_c = (_b = this._config) == null ? void 0 : _b.get("runtime.services.signaling")) != null ? _c : []) } = options;
4627
+ iceServers: this._config?.get("runtime.services.ice")
4628
+ }), signalManager = new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
4572
4629
  this._signalManager = signalManager;
4573
4630
  invariant13(!this._networkManager, "network manager already set", {
4574
4631
  F: __dxlog_file17,
4575
- L: 192,
4632
+ L: 201,
4576
4633
  S: this,
4577
4634
  A: [
4578
4635
  "!this._networkManager",
@@ -4584,30 +4641,29 @@ var ClientServicesHost = class {
4584
4641
  transportFactory,
4585
4642
  signalManager
4586
4643
  });
4587
- log16.info("initialized", void 0, {
4644
+ log16("initialized", void 0, {
4588
4645
  F: __dxlog_file17,
4589
- L: 199,
4646
+ L: 208,
4590
4647
  S: this,
4591
4648
  C: (f, a) => f(...a)
4592
4649
  });
4593
4650
  }
4594
- async open() {
4595
- var _a, _b, _c;
4651
+ async open(ctx) {
4596
4652
  if (this._open) {
4597
4653
  return;
4598
4654
  }
4599
4655
  const traceId = PublicKey10.random().toHex();
4600
- log16.trace("dxos.client-services.host.open", trace6.begin({
4656
+ log16.trace("dxos.client-services.host.open", trace7.begin({
4601
4657
  id: traceId
4602
4658
  }), {
4603
4659
  F: __dxlog_file17,
4604
- L: 209,
4660
+ L: 219,
4605
4661
  S: this,
4606
4662
  C: (f, a) => f(...a)
4607
4663
  });
4608
4664
  invariant13(this._config, "config not set", {
4609
4665
  F: __dxlog_file17,
4610
- L: 211,
4666
+ L: 221,
4611
4667
  S: this,
4612
4668
  A: [
4613
4669
  "this._config",
@@ -4616,7 +4672,7 @@ var ClientServicesHost = class {
4616
4672
  });
4617
4673
  invariant13(this._storage, "storage not set", {
4618
4674
  F: __dxlog_file17,
4619
- L: 212,
4675
+ L: 222,
4620
4676
  S: this,
4621
4677
  A: [
4622
4678
  "this._storage",
@@ -4625,7 +4681,7 @@ var ClientServicesHost = class {
4625
4681
  });
4626
4682
  invariant13(this._signalManager, "signal manager not set", {
4627
4683
  F: __dxlog_file17,
4628
- L: 213,
4684
+ L: 223,
4629
4685
  S: this,
4630
4686
  A: [
4631
4687
  "this._signalManager",
@@ -4634,7 +4690,7 @@ var ClientServicesHost = class {
4634
4690
  });
4635
4691
  invariant13(this._networkManager, "network manager not set", {
4636
4692
  F: __dxlog_file17,
4637
- L: 214,
4693
+ L: 224,
4638
4694
  S: this,
4639
4695
  A: [
4640
4696
  "this._networkManager",
@@ -4642,20 +4698,20 @@ var ClientServicesHost = class {
4642
4698
  ]
4643
4699
  });
4644
4700
  this._opening = true;
4645
- log16.info("opening...", {
4646
- lockKey: (_a = this._resourceLock) == null ? void 0 : _a.lockKey
4701
+ log16("opening...", {
4702
+ lockKey: this._resourceLock?.lockKey
4647
4703
  }, {
4648
4704
  F: __dxlog_file17,
4649
- L: 217,
4705
+ L: 227,
4650
4706
  S: this,
4651
4707
  C: (f, a) => f(...a)
4652
4708
  });
4653
- await ((_b = this._resourceLock) == null ? void 0 : _b.acquire());
4709
+ await this._resourceLock?.acquire();
4654
4710
  await this._loggingService.open();
4655
4711
  this._serviceContext = new ServiceContext(this._storage, this._networkManager, this._signalManager, this._modelFactory);
4656
4712
  this._serviceRegistry.setServices({
4657
4713
  SystemService: this._systemService,
4658
- IdentityService: new IdentityServiceImpl(this._serviceContext),
4714
+ IdentityService: new IdentityServiceImpl((params) => this._serviceContext.createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring),
4659
4715
  InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitations, (invitation) => this._serviceContext.getInvitationHandler(invitation)),
4660
4716
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
4661
4717
  SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, this._serviceContext.dataServiceSubscriptions, async () => {
@@ -4665,6 +4721,7 @@ var ClientServicesHost = class {
4665
4721
  DataService: new DataServiceImpl(this._serviceContext.dataServiceSubscriptions),
4666
4722
  NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager, this._serviceContext.signalManager),
4667
4723
  LoggingService: this._loggingService,
4724
+ TracingService: this._tracingService,
4668
4725
  // TODO(burdon): Move to new protobuf definitions.
4669
4726
  DevtoolsHost: new DevtoolsServiceImpl({
4670
4727
  events: new DevtoolsHostEvents(),
@@ -4672,39 +4729,38 @@ var ClientServicesHost = class {
4672
4729
  context: this._serviceContext
4673
4730
  })
4674
4731
  });
4675
- await this._serviceContext.open();
4732
+ await this._serviceContext.open(ctx);
4676
4733
  this._opening = false;
4677
4734
  this._open = true;
4678
4735
  this._statusUpdate.emit();
4679
- const deviceKey = (_c = this._serviceContext.identityManager.identity) == null ? void 0 : _c.deviceKey;
4680
- log16.info("opened", {
4736
+ const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
4737
+ log16("opened", {
4681
4738
  deviceKey
4682
4739
  }, {
4683
4740
  F: __dxlog_file17,
4684
- L: 269,
4741
+ L: 284,
4685
4742
  S: this,
4686
4743
  C: (f, a) => f(...a)
4687
4744
  });
4688
- log16.trace("dxos.client-services.host.open", trace6.end({
4745
+ log16.trace("dxos.client-services.host.open", trace7.end({
4689
4746
  id: traceId
4690
4747
  }), {
4691
4748
  F: __dxlog_file17,
4692
- L: 270,
4749
+ L: 285,
4693
4750
  S: this,
4694
4751
  C: (f, a) => f(...a)
4695
4752
  });
4696
4753
  }
4697
4754
  async close() {
4698
- var _a;
4699
4755
  if (!this._open) {
4700
4756
  return;
4701
4757
  }
4702
- const deviceKey = (_a = this._serviceContext.identityManager.identity) == null ? void 0 : _a.deviceKey;
4703
- log16.info("closing...", {
4758
+ const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
4759
+ log16("closing...", {
4704
4760
  deviceKey
4705
4761
  }, {
4706
4762
  F: __dxlog_file17,
4707
- L: 280,
4763
+ L: 296,
4708
4764
  S: this,
4709
4765
  C: (f, a) => f(...a)
4710
4766
  });
@@ -4715,57 +4771,67 @@ var ClientServicesHost = class {
4715
4771
  await this._serviceContext.close();
4716
4772
  this._open = false;
4717
4773
  this._statusUpdate.emit();
4718
- log16.info("closed", {
4774
+ log16("closed", {
4719
4775
  deviceKey
4720
4776
  }, {
4721
4777
  F: __dxlog_file17,
4722
- L: 286,
4778
+ L: 302,
4723
4779
  S: this,
4724
4780
  C: (f, a) => f(...a)
4725
4781
  });
4726
4782
  }
4727
4783
  async reset() {
4728
- var _a, _b, _c;
4729
4784
  const traceId = PublicKey10.random().toHex();
4730
- log16.trace("dxos.sdk.client-services-host.reset", trace6.begin({
4785
+ log16.trace("dxos.sdk.client-services-host.reset", trace7.begin({
4731
4786
  id: traceId
4732
4787
  }), {
4733
4788
  F: __dxlog_file17,
4734
- L: 291,
4789
+ L: 307,
4735
4790
  S: this,
4736
4791
  C: (f, a) => f(...a)
4737
4792
  });
4738
4793
  log16("resetting...", void 0, {
4739
4794
  F: __dxlog_file17,
4740
- L: 293,
4795
+ L: 309,
4741
4796
  S: this,
4742
4797
  C: (f, a) => f(...a)
4743
4798
  });
4744
- await ((_a = this._serviceContext) == null ? void 0 : _a.close());
4799
+ await this._serviceContext?.close();
4745
4800
  await this._storage.reset();
4746
4801
  log16("reset", void 0, {
4747
4802
  F: __dxlog_file17,
4748
- L: 296,
4803
+ L: 312,
4749
4804
  S: this,
4750
4805
  C: (f, a) => f(...a)
4751
4806
  });
4752
- log16.trace("dxos.sdk.client-services-host.reset", trace6.end({
4807
+ log16.trace("dxos.sdk.client-services-host.reset", trace7.end({
4753
4808
  id: traceId
4754
4809
  }), {
4755
4810
  F: __dxlog_file17,
4756
- L: 297,
4811
+ L: 313,
4757
4812
  S: this,
4758
4813
  C: (f, a) => f(...a)
4759
4814
  });
4760
- await ((_c = (_b = this._callbacks) == null ? void 0 : _b.onReset) == null ? void 0 : _c.call(_b));
4815
+ await this._callbacks?.onReset?.();
4761
4816
  }
4762
4817
  };
4763
- _ts_decorate4([
4764
- synchronized3
4818
+ _ts_decorate7([
4819
+ Trace3.info()
4820
+ ], ClientServicesHost.prototype, "_opening", void 0);
4821
+ _ts_decorate7([
4822
+ Trace3.info()
4823
+ ], ClientServicesHost.prototype, "_open", void 0);
4824
+ _ts_decorate7([
4825
+ synchronized3,
4826
+ Trace3.span()
4765
4827
  ], ClientServicesHost.prototype, "open", null);
4766
- _ts_decorate4([
4767
- synchronized3
4828
+ _ts_decorate7([
4829
+ synchronized3,
4830
+ Trace3.span()
4768
4831
  ], ClientServicesHost.prototype, "close", null);
4832
+ ClientServicesHost = _ts_decorate7([
4833
+ Trace3.resource()
4834
+ ], ClientServicesHost);
4769
4835
 
4770
4836
  export {
4771
4837
  subscribeToFeeds,
@@ -4800,4 +4866,4 @@ export {
4800
4866
  createDefaultModelFactory,
4801
4867
  ClientServicesHost
4802
4868
  };
4803
- //# sourceMappingURL=chunk-7TROD4O2.mjs.map
4869
+ //# sourceMappingURL=chunk-SYAA4V6R.mjs.map