@dxos/client-services 0.1.56-main.bf228a7 → 0.1.56-main.c277f68

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 (78) hide show
  1. package/dist/lib/browser/{chunk-FD4L7N4K.mjs → chunk-E7EKG5QQ.mjs} +816 -541
  2. package/dist/lib/browser/chunk-E7EKG5QQ.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +30 -31
  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 +952 -679
  9. package/dist/lib/node/index.cjs.map +4 -4
  10. package/dist/lib/node/meta.json +1 -1
  11. package/dist/lib/node/packlets/testing/index.cjs +1232 -969
  12. package/dist/lib/node/packlets/testing/index.cjs.map +4 -4
  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/logging/logging-service.d.ts +6 -2
  21. package/dist/types/src/packlets/logging/logging-service.d.ts.map +1 -1
  22. package/dist/types/src/packlets/services/client-rpc-server.d.ts.map +1 -1
  23. package/dist/types/src/packlets/services/diagnostics.d.ts +46 -0
  24. package/dist/types/src/packlets/services/diagnostics.d.ts.map +1 -0
  25. package/dist/types/src/packlets/services/index.d.ts +1 -0
  26. package/dist/types/src/packlets/services/index.d.ts.map +1 -1
  27. package/dist/types/src/packlets/services/platform.d.ts +16 -0
  28. package/dist/types/src/packlets/services/platform.d.ts.map +1 -0
  29. package/dist/types/src/packlets/services/service-context.d.ts +2 -1
  30. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  31. package/dist/types/src/packlets/services/service-host.d.ts +7 -3
  32. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  33. package/dist/types/src/packlets/services/util.d.ts +6 -0
  34. package/dist/types/src/packlets/services/util.d.ts.map +1 -0
  35. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  36. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  37. package/dist/types/src/packlets/system/system-service.d.ts +12 -2
  38. package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
  39. package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts.map +1 -1
  40. package/dist/types/src/packlets/vault/worker-runtime.d.ts.map +1 -1
  41. package/dist/types/src/packlets/vault/worker-session.d.ts.map +1 -1
  42. package/dist/types/src/version.d.ts +2 -0
  43. package/dist/types/src/version.d.ts.map +1 -0
  44. package/package.json +34 -33
  45. package/src/packlets/devices/devices-service.test.ts +2 -1
  46. package/src/packlets/identity/identity-manager.test.ts +15 -3
  47. package/src/packlets/identity/identity-manager.ts +27 -6
  48. package/src/packlets/identity/identity-service.test.ts +17 -2
  49. package/src/packlets/identity/identity-service.ts +23 -14
  50. package/src/packlets/identity/identity.test.ts +7 -6
  51. package/src/packlets/identity/identity.ts +8 -3
  52. package/src/packlets/invitations/device-invitation-protocol.test.ts +2 -1
  53. package/src/packlets/invitations/invitations-handler.ts +2 -0
  54. package/src/packlets/logging/logging-service.ts +17 -9
  55. package/src/packlets/network/network-service.test.ts +2 -1
  56. package/src/packlets/services/client-rpc-server.ts +4 -4
  57. package/src/packlets/services/diagnostics.ts +212 -0
  58. package/src/packlets/services/index.ts +1 -0
  59. package/src/packlets/services/platform.ts +48 -0
  60. package/src/packlets/services/service-context.test.ts +59 -0
  61. package/src/packlets/services/service-context.ts +20 -13
  62. package/src/packlets/services/service-host.test.ts +12 -11
  63. package/src/packlets/services/service-host.ts +38 -18
  64. package/src/packlets/services/service-registry.test.ts +3 -1
  65. package/src/packlets/services/util.ts +33 -0
  66. package/src/packlets/spaces/data-space-manager.test.ts +80 -22
  67. package/src/packlets/spaces/data-space-manager.ts +5 -1
  68. package/src/packlets/spaces/data-space.ts +17 -5
  69. package/src/packlets/spaces/spaces-service.test.ts +2 -1
  70. package/src/packlets/spaces/spaces-service.ts +1 -1
  71. package/src/packlets/system/system-service.test.ts +1 -0
  72. package/src/packlets/system/system-service.ts +34 -2
  73. package/src/packlets/testing/test-builder.ts +1 -1
  74. package/src/packlets/vault/iframe-host-runtime.ts +2 -1
  75. package/src/packlets/vault/worker-runtime.ts +3 -2
  76. package/src/packlets/vault/worker-session.ts +6 -1
  77. package/src/version.ts +1 -0
  78. package/dist/lib/browser/chunk-FD4L7N4K.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}`);
@@ -2385,37 +2452,196 @@ var ClientRpcServer = class {
2385
2452
  }
2386
2453
  };
2387
2454
 
2455
+ // packages/sdk/client-services/src/packlets/services/diagnostics.ts
2456
+ import { getFirstStreamValue } from "@dxos/codec-protobuf";
2457
+ import { credentialTypeFilter } from "@dxos/credentials";
2458
+ import { DocumentModel } from "@dxos/document-model";
2459
+ import { TYPE_PROPERTIES } from "@dxos/echo-db";
2460
+ import { invariant as invariant9 } from "@dxos/invariant";
2461
+ import { log as log8 } from "@dxos/log";
2462
+ import { STORAGE_VERSION } from "@dxos/protocols";
2463
+ import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
2464
+
2465
+ // packages/sdk/client-services/src/version.ts
2466
+ var DXOS_VERSION = "0.1.56-main.c277f68";
2467
+
2468
+ // packages/sdk/client-services/src/packlets/services/platform.ts
2469
+ var getPlatform = () => {
2470
+ if (process.browser) {
2471
+ if (typeof window !== "undefined") {
2472
+ const { userAgent } = window.navigator;
2473
+ return {
2474
+ type: "browser",
2475
+ userAgent,
2476
+ uptime: Math.floor((Date.now() - window.performance.timeOrigin) / 1e3)
2477
+ };
2478
+ } else {
2479
+ return {
2480
+ type: "shared-worker",
2481
+ uptime: Math.floor((Date.now() - performance.timeOrigin) / 1e3)
2482
+ };
2483
+ }
2484
+ } else {
2485
+ const { platform, version, arch } = process;
2486
+ return {
2487
+ type: "node",
2488
+ platform: `${platform} ${version} ${arch}`,
2489
+ runtime: process.version,
2490
+ uptime: Math.floor(process.uptime()),
2491
+ memory: process.memoryUsage()
2492
+ };
2493
+ }
2494
+ };
2495
+
2496
+ // packages/sdk/client-services/src/packlets/services/diagnostics.ts
2497
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
2498
+ var DEFAULT_TIMEOUT = 1e3;
2499
+ var createDiagnostics = async (clientServices, serviceContext, config) => {
2500
+ const diagnostics = {
2501
+ created: (/* @__PURE__ */ new Date()).toISOString(),
2502
+ platform: getPlatform(),
2503
+ client: {
2504
+ version: DXOS_VERSION,
2505
+ storage: {
2506
+ version: STORAGE_VERSION
2507
+ }
2508
+ }
2509
+ };
2510
+ {
2511
+ invariant9(clientServices.LoggingService, "SystemService is not available.", {
2512
+ F: __dxlog_file10,
2513
+ L: 88,
2514
+ S: void 0,
2515
+ A: [
2516
+ "clientServices.LoggingService",
2517
+ "'SystemService is not available.'"
2518
+ ]
2519
+ });
2520
+ diagnostics.metrics = await getFirstStreamValue(clientServices.LoggingService.queryMetrics({}), {
2521
+ timeout: DEFAULT_TIMEOUT
2522
+ }).catch(() => void 0);
2523
+ }
2524
+ const identity = serviceContext.identityManager.identity;
2525
+ if (identity) {
2526
+ diagnostics.identity = {
2527
+ identityKey: identity.identityKey,
2528
+ spaceKey: identity.space.key,
2529
+ profile: identity.profileDocument
2530
+ };
2531
+ const { devices } = await getFirstStreamValue(clientServices.DevicesService.queryDevices(), {
2532
+ timeout: DEFAULT_TIMEOUT
2533
+ }).catch(() => void 0) ?? {};
2534
+ diagnostics.devices = devices;
2535
+ if (serviceContext.dataSpaceManager) {
2536
+ diagnostics.spaces = await Promise.all(Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space)) ?? []);
2537
+ }
2538
+ const { feeds = [] } = await getFirstStreamValue(clientServices.DevtoolsHost.subscribeToFeeds({}), {
2539
+ timeout: DEFAULT_TIMEOUT
2540
+ }).catch(() => void 0) ?? {};
2541
+ diagnostics.feeds = feeds.map(({ feedKey, bytes, length }) => ({
2542
+ feedKey,
2543
+ bytes,
2544
+ length
2545
+ }));
2546
+ }
2547
+ diagnostics.config = config.values;
2548
+ return diagnostics;
2549
+ };
2550
+ var getProperties = (space) => {
2551
+ let properties = {};
2552
+ try {
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;
2556
+ } catch (err) {
2557
+ log8.warn(err.message, void 0, {
2558
+ F: __dxlog_file10,
2559
+ L: 145,
2560
+ S: void 0,
2561
+ C: (f, a) => f(...a)
2562
+ });
2563
+ }
2564
+ return properties;
2565
+ };
2566
+ var getSpaceStats = async (space) => {
2567
+ const stats = {
2568
+ key: space.key,
2569
+ metrics: space.metrics,
2570
+ epochs: space.inner.spaceState.credentials.filter(credentialTypeFilter("dxos.halo.credentials.Epoch")).map((credential) => ({
2571
+ ...credential.subject.assertion,
2572
+ id: credential.id
2573
+ })),
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
+ })),
2583
+ pipeline: {
2584
+ // TODO(burdon): Pick properties from credentials if needed.
2585
+ // currentEpoch: space.dataPipeline.currentEpoch,
2586
+ // appliedEpoch: space.dataPipeline.appliedEpoch,
2587
+ controlFeeds: space.inner.controlPipeline.state.feeds.map((feed) => feed.key),
2588
+ currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
2589
+ targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
2590
+ totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe,
2591
+ // TODO(burdon): Empty?
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
2597
+ }
2598
+ };
2599
+ if (space.dataPipeline.itemManager) {
2600
+ Object.assign(stats, {
2601
+ properties: getProperties(space),
2602
+ db: {
2603
+ objects: space.dataPipeline.itemManager.entities.size
2604
+ }
2605
+ });
2606
+ }
2607
+ if (stats.metrics) {
2608
+ const { open, ready } = stats.metrics;
2609
+ stats.metrics.startupTime = open && ready && ready.getTime() - open.getTime();
2610
+ }
2611
+ return stats;
2612
+ };
2613
+
2388
2614
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2389
2615
  import { Event as Event5, scheduleTask as scheduleTask4, synchronized, trackLeaks } from "@dxos/async";
2390
2616
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
2391
- import { cancelWithContext as cancelWithContext2, Context as Context6 } from "@dxos/context";
2617
+ import { cancelWithContext as cancelWithContext2, Context as Context7 } from "@dxos/context";
2392
2618
  import { timed } from "@dxos/debug";
2393
2619
  import { createMappedFeedWriter } from "@dxos/echo-pipeline";
2394
2620
  import { CancelledError, SystemError } from "@dxos/errors";
2395
2621
  import { PublicKey as PublicKey7 } from "@dxos/keys";
2396
- import { log as log9 } from "@dxos/log";
2622
+ import { log as log10 } from "@dxos/log";
2397
2623
  import { SpaceState } from "@dxos/protocols/proto/dxos/client/services";
2398
2624
  import { AdmittedFeed as AdmittedFeed3 } from "@dxos/protocols/proto/dxos/halo/credentials";
2399
- import { Timeframe } from "@dxos/timeframe";
2625
+ import { Timeframe as Timeframe2 } from "@dxos/timeframe";
2400
2626
  import { ComplexSet as ComplexSet2 } from "@dxos/util";
2401
2627
 
2402
2628
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
2403
2629
  import { DeferredTask, Event as Event4, scheduleTask as scheduleTask3, sleep, TimeoutError as TimeoutError2, Trigger as Trigger4 } from "@dxos/async";
2404
- import { Context as Context5, rejectOnDispose } from "@dxos/context";
2405
- import { invariant as invariant9 } from "@dxos/invariant";
2630
+ import { Context as Context6, rejectOnDispose } from "@dxos/context";
2631
+ import { invariant as invariant10 } from "@dxos/invariant";
2406
2632
  import { PublicKey as PublicKey6 } from "@dxos/keys";
2407
- import { log as log8 } from "@dxos/log";
2633
+ import { log as log9 } from "@dxos/log";
2408
2634
  import { schema as schema3 } from "@dxos/protocols";
2409
2635
  import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
2410
2636
  import { ComplexMap as ComplexMap2, ComplexSet, entry } from "@dxos/util";
2411
- var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
2637
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
2412
2638
  var DEFAULT_RETRY_TIMEOUT = 1e3;
2413
2639
  var DEFAULT_SUCCESS_DELAY = 1e3;
2414
2640
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
2415
2641
  var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
2416
2642
  var NotarizationPlugin = class {
2417
2643
  constructor() {
2418
- this._ctx = new Context5();
2644
+ this._ctx = new Context6();
2419
2645
  this._extensionOpened = new Event4();
2420
2646
  this._extensions = /* @__PURE__ */ new Set();
2421
2647
  this._processedCredentials = new ComplexSet(PublicKey6.hash);
@@ -2433,16 +2659,16 @@ var NotarizationPlugin = class {
2433
2659
  * Request credentials to be notarized.
2434
2660
  */
2435
2661
  async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
2436
- log8("notarize", {
2662
+ log9("notarize", {
2437
2663
  credentials
2438
2664
  }, {
2439
- F: __dxlog_file10,
2665
+ F: __dxlog_file11,
2440
2666
  L: 90,
2441
2667
  S: this,
2442
2668
  C: (f, a) => f(...a)
2443
2669
  });
2444
- invariant9(credentials.every((credential) => credential.id), "Credentials must have an id", {
2445
- F: __dxlog_file10,
2670
+ invariant10(credentials.every((credential) => credential.id), "Credentials must have an id", {
2671
+ F: __dxlog_file11,
2446
2672
  L: 91,
2447
2673
  S: this,
2448
2674
  A: [
@@ -2453,10 +2679,10 @@ var NotarizationPlugin = class {
2453
2679
  const errors = new Trigger4();
2454
2680
  const ctx = this._ctx.derive({
2455
2681
  onError: (err) => {
2456
- log8.warn("Notarization error", {
2682
+ log9.warn("Notarization error", {
2457
2683
  err
2458
2684
  }, {
2459
- F: __dxlog_file10,
2685
+ F: __dxlog_file11,
2460
2686
  L: 99,
2461
2687
  S: this,
2462
2688
  C: (f, a) => f(...a)
@@ -2465,14 +2691,14 @@ var NotarizationPlugin = class {
2465
2691
  errors.throw(err);
2466
2692
  }
2467
2693
  });
2468
- opCtx == null ? void 0 : opCtx.onDispose(() => ctx.dispose());
2694
+ opCtx?.onDispose(() => ctx.dispose());
2469
2695
  if (timeout !== 0) {
2470
2696
  scheduleTask3(ctx, () => {
2471
- log8.warn("Notarization timeout", {
2697
+ log9.warn("Notarization timeout", {
2472
2698
  timeout,
2473
2699
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
2474
2700
  }, {
2475
- F: __dxlog_file10,
2701
+ F: __dxlog_file11,
2476
2702
  L: 111,
2477
2703
  S: this,
2478
2704
  C: (f, a) => f(...a)
@@ -2492,10 +2718,10 @@ var NotarizationPlugin = class {
2492
2718
  ...this._extensions
2493
2719
  ].find((peer2) => !peersTried.has(peer2));
2494
2720
  if (!peer) {
2495
- log8.warn("Exhausted all peers to notarize with", {
2721
+ log9.warn("Exhausted all peers to notarize with", {
2496
2722
  retryIn: retryTimeout
2497
2723
  }, {
2498
- F: __dxlog_file10,
2724
+ F: __dxlog_file11,
2499
2725
  L: 136,
2500
2726
  S: this,
2501
2727
  C: (f, a) => f(...a)
@@ -2505,11 +2731,11 @@ var NotarizationPlugin = class {
2505
2731
  return;
2506
2732
  }
2507
2733
  peersTried.add(peer);
2508
- log8("try notarizing", {
2734
+ log9("try notarizing", {
2509
2735
  peer: peer.localPeerId,
2510
2736
  credentialId: credentials.map((credential) => credential.id)
2511
2737
  }, {
2512
- F: __dxlog_file10,
2738
+ F: __dxlog_file11,
2513
2739
  L: 143,
2514
2740
  S: this,
2515
2741
  C: (f, a) => f(...a)
@@ -2517,8 +2743,8 @@ var NotarizationPlugin = class {
2517
2743
  await peer.rpc.NotarizationService.notarize({
2518
2744
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
2519
2745
  });
2520
- log8("success", void 0, {
2521
- F: __dxlog_file10,
2746
+ log9("success", void 0, {
2747
+ F: __dxlog_file11,
2522
2748
  L: 147,
2523
2749
  S: this,
2524
2750
  C: (f, a) => f(...a)
@@ -2526,8 +2752,8 @@ var NotarizationPlugin = class {
2526
2752
  await sleep(successDelay);
2527
2753
  } catch (err) {
2528
2754
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
2529
- log8.warn("error notarizing (recoverable)", err, {
2530
- F: __dxlog_file10,
2755
+ log9.warn("error notarizing (recoverable)", err, {
2756
+ F: __dxlog_file11,
2531
2757
  L: 151,
2532
2758
  S: this,
2533
2759
  C: (f, a) => f(...a)
@@ -2544,8 +2770,8 @@ var NotarizationPlugin = class {
2544
2770
  allNotarized,
2545
2771
  errors.wait()
2546
2772
  ]);
2547
- log8("done", void 0, {
2548
- F: __dxlog_file10,
2773
+ log9("done", void 0, {
2774
+ F: __dxlog_file11,
2549
2775
  L: 162,
2550
2776
  S: this,
2551
2777
  C: (f, a) => f(...a)
@@ -2558,17 +2784,16 @@ var NotarizationPlugin = class {
2558
2784
  * Called with credentials arriving from the control pipeline.
2559
2785
  */
2560
2786
  async processCredential(credential) {
2561
- var _a;
2562
2787
  if (!credential.id) {
2563
2788
  return;
2564
2789
  }
2565
- (_a = this._processCredentialsTriggers.get(credential.id)) == null ? void 0 : _a.wake();
2790
+ this._processCredentialsTriggers.get(credential.id)?.wake();
2566
2791
  this._processedCredentials.add(credential.id);
2567
2792
  this._processCredentialsTriggers.delete(credential.id);
2568
2793
  }
2569
2794
  setWriter(writer) {
2570
- invariant9(!this._writer, "Writer already set.", {
2571
- F: __dxlog_file10,
2795
+ invariant10(!this._writer, "Writer already set.", {
2796
+ F: __dxlog_file11,
2572
2797
  L: 181,
2573
2798
  S: this,
2574
2799
  A: [
@@ -2588,13 +2813,12 @@ var NotarizationPlugin = class {
2588
2813
  * Requests from other peers to notarize credentials.
2589
2814
  */
2590
2815
  async _onNotarize(request) {
2591
- var _a;
2592
2816
  if (!this._writer) {
2593
2817
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
2594
2818
  }
2595
- for (const credential of (_a = request.credentials) != null ? _a : []) {
2596
- invariant9(credential.id, "Credential must have an id", {
2597
- F: __dxlog_file10,
2819
+ for (const credential of request.credentials ?? []) {
2820
+ invariant10(credential.id, "Credential must have an id", {
2821
+ F: __dxlog_file11,
2598
2822
  L: 200,
2599
2823
  S: this,
2600
2824
  A: [
@@ -2611,10 +2835,10 @@ var NotarizationPlugin = class {
2611
2835
  createExtension() {
2612
2836
  const extension = new NotarizationTeleportExtension({
2613
2837
  onOpen: async () => {
2614
- log8("extension opened", {
2838
+ log9("extension opened", {
2615
2839
  peer: extension.localPeerId
2616
2840
  }, {
2617
- F: __dxlog_file10,
2841
+ F: __dxlog_file11,
2618
2842
  L: 211,
2619
2843
  S: this,
2620
2844
  C: (f, a) => f(...a)
@@ -2623,10 +2847,10 @@ var NotarizationPlugin = class {
2623
2847
  this._extensionOpened.emit();
2624
2848
  },
2625
2849
  onClose: async () => {
2626
- log8("extension closed", {
2850
+ log9("extension closed", {
2627
2851
  peer: extension.localPeerId
2628
2852
  }, {
2629
- F: __dxlog_file10,
2853
+ F: __dxlog_file11,
2630
2854
  L: 216,
2631
2855
  S: this,
2632
2856
  C: (f, a) => f(...a)
@@ -2670,7 +2894,7 @@ var NotarizationTeleportExtension = class extends RpcExtension2 {
2670
2894
  };
2671
2895
 
2672
2896
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2673
- function _ts_decorate(decorators, target, key, desc) {
2897
+ function _ts_decorate3(decorators, target, key, desc) {
2674
2898
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2675
2899
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2676
2900
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2680,10 +2904,11 @@ function _ts_decorate(decorators, target, key, desc) {
2680
2904
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2681
2905
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2682
2906
  }
2683
- var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
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;
2684
2909
  var DataSpace = class DataSpace2 {
2685
2910
  constructor(params) {
2686
- this._ctx = new Context6();
2911
+ this._ctx = new Context7();
2687
2912
  this._notarizationPlugin = new NotarizationPlugin();
2688
2913
  this._state = SpaceState.CLOSED;
2689
2914
  /**
@@ -2692,7 +2917,6 @@ var DataSpace = class DataSpace2 {
2692
2917
  this.error = void 0;
2693
2918
  this.stateUpdate = new Event5();
2694
2919
  this.metrics = {};
2695
- var _a;
2696
2920
  this._inner = params.inner;
2697
2921
  this._inner.stateUpdate.on(this._ctx, () => this.stateUpdate.emit());
2698
2922
  this._gossip = params.gossip;
@@ -2701,7 +2925,7 @@ var DataSpace = class DataSpace2 {
2701
2925
  this._feedStore = params.feedStore;
2702
2926
  this._metadataStore = params.metadataStore;
2703
2927
  this._signingContext = params.signingContext;
2704
- this._callbacks = (_a = params.callbacks) != null ? _a : {};
2928
+ this._callbacks = params.callbacks ?? {};
2705
2929
  this.authVerifier = new TrustedKeySetAuthVerifier({
2706
2930
  trustedKeysProvider: () => new ComplexSet2(PublicKey7.hash, Array.from(this._inner.spaceState.members.keys())),
2707
2931
  update: this._inner.stateUpdate,
@@ -2741,21 +2965,20 @@ var DataSpace = class DataSpace2 {
2741
2965
  async _open() {
2742
2966
  await this._notarizationPlugin.open();
2743
2967
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
2744
- await this._inner.open();
2968
+ await this._inner.open(new Context7());
2745
2969
  this._state = SpaceState.CONTROL_ONLY;
2746
2970
  this.stateUpdate.emit();
2747
2971
  this.metrics = {};
2748
- this.metrics.open = new Date();
2972
+ this.metrics.open = /* @__PURE__ */ new Date();
2749
2973
  }
2750
2974
  async close() {
2751
2975
  await this._close();
2752
2976
  }
2753
2977
  async _close() {
2754
- var _a, _b;
2755
- await ((_b = (_a = this._callbacks).beforeClose) == null ? void 0 : _b.call(_a));
2978
+ await this._callbacks.beforeClose?.();
2756
2979
  this._state = SpaceState.CLOSED;
2757
2980
  await this._ctx.dispose();
2758
- this._ctx = new Context6();
2981
+ this._ctx = new Context7();
2759
2982
  await this.authVerifier.close();
2760
2983
  await this._inner.close();
2761
2984
  await this._inner.spaceState.removeCredentialProcessor(this._notarizationPlugin);
@@ -2774,21 +2997,21 @@ var DataSpace = class DataSpace2 {
2774
2997
  initializeDataPipelineAsync() {
2775
2998
  scheduleTask4(this._ctx, async () => {
2776
2999
  try {
2777
- this.metrics.pipelineInitBegin = new Date();
3000
+ this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
2778
3001
  await this.initializeDataPipeline();
2779
3002
  } catch (err) {
2780
3003
  if (err instanceof CancelledError) {
2781
- log9("data pipeline initialization cancelled", err, {
2782
- F: __dxlog_file11,
2783
- L: 193,
3004
+ log10("data pipeline initialization cancelled", err, {
3005
+ F: __dxlog_file12,
3006
+ L: 199,
2784
3007
  S: this,
2785
3008
  C: (f, a) => f(...a)
2786
3009
  });
2787
3010
  return;
2788
3011
  }
2789
- log9.error("Error initializing data pipeline", err, {
2790
- F: __dxlog_file11,
2791
- L: 197,
3012
+ log10.error("Error initializing data pipeline", err, {
3013
+ F: __dxlog_file12,
3014
+ L: 203,
2792
3015
  S: this,
2793
3016
  C: (f, a) => f(...a)
2794
3017
  });
@@ -2796,12 +3019,11 @@ var DataSpace = class DataSpace2 {
2796
3019
  this.error = err;
2797
3020
  this.stateUpdate.emit();
2798
3021
  } finally {
2799
- this.metrics.ready = new Date();
3022
+ this.metrics.ready = /* @__PURE__ */ new Date();
2800
3023
  }
2801
3024
  });
2802
3025
  }
2803
3026
  async initializeDataPipeline() {
2804
- var _a, _b, _c, _d;
2805
3027
  if (this._state !== SpaceState.CONTROL_ONLY) {
2806
3028
  throw new SystemError("Invalid operation");
2807
3029
  }
@@ -2810,11 +3032,11 @@ var DataSpace = class DataSpace2 {
2810
3032
  ctx: this._ctx,
2811
3033
  breakOnStall: false
2812
3034
  });
2813
- this.metrics.controlPipelineReady = new Date();
3035
+ this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
2814
3036
  await this._createWritableFeeds();
2815
- log9("writable feeds created", void 0, {
2816
- F: __dxlog_file11,
2817
- L: 221,
3037
+ log10("writable feeds created", void 0, {
3038
+ F: __dxlog_file12,
3039
+ L: 227,
2818
3040
  S: this,
2819
3041
  C: (f, a) => f(...a)
2820
3042
  });
@@ -2827,11 +3049,11 @@ var DataSpace = class DataSpace2 {
2827
3049
  }), this._inner.controlPipeline.writer));
2828
3050
  }
2829
3051
  await this._inner.initializeDataPipeline();
2830
- this.metrics.dataPipelineOpen = new Date();
3052
+ this.metrics.dataPipelineOpen = /* @__PURE__ */ new Date();
2831
3053
  await cancelWithContext2(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
2832
- log9("waiting for data pipeline to reach target timeframe", void 0, {
2833
- F: __dxlog_file11,
2834
- L: 242,
3054
+ log10("waiting for data pipeline to reach target timeframe", void 0, {
3055
+ F: __dxlog_file12,
3056
+ L: 248,
2835
3057
  S: this,
2836
3058
  C: (f, a) => f(...a)
2837
3059
  });
@@ -2839,17 +3061,17 @@ var DataSpace = class DataSpace2 {
2839
3061
  ctx: this._ctx,
2840
3062
  breakOnStall: false
2841
3063
  });
2842
- this.metrics.dataPipelineReady = new Date();
2843
- log9("data pipeline ready", void 0, {
2844
- F: __dxlog_file11,
2845
- L: 251,
3064
+ this.metrics.dataPipelineReady = /* @__PURE__ */ new Date();
3065
+ log10("data pipeline ready", void 0, {
3066
+ F: __dxlog_file12,
3067
+ L: 257,
2846
3068
  S: this,
2847
3069
  C: (f, a) => f(...a)
2848
3070
  });
2849
- await ((_b = (_a = this._callbacks).beforeReady) == null ? void 0 : _b.call(_a));
3071
+ await this._callbacks.beforeReady?.();
2850
3072
  this._state = SpaceState.READY;
2851
3073
  this.stateUpdate.emit();
2852
- await ((_d = (_c = this._callbacks).afterReady) == null ? void 0 : _d.call(_c));
3074
+ await this._callbacks.afterReady?.();
2853
3075
  }
2854
3076
  async _createWritableFeeds() {
2855
3077
  const credentials = [];
@@ -2896,7 +3118,6 @@ var DataSpace = class DataSpace2 {
2896
3118
  await this._metadataStore.setWritableFeedKeys(this.key, this.inner.controlFeedKey, this.inner.dataFeedKey);
2897
3119
  }
2898
3120
  async createEpoch() {
2899
- var _a, _b;
2900
3121
  const epoch = await this.dataPipeline.createEpoch();
2901
3122
  const receipt = await this.inner.controlPipeline.writer.write({
2902
3123
  credential: {
@@ -2909,16 +3130,19 @@ var DataSpace = class DataSpace2 {
2909
3130
  })
2910
3131
  }
2911
3132
  });
2912
- await this.inner.controlPipeline.state.waitUntilTimeframe(new Timeframe([
3133
+ await this.inner.controlPipeline.state.waitUntilTimeframe(new Timeframe2([
2913
3134
  [
2914
3135
  receipt.feedKey,
2915
3136
  receipt.seq
2916
3137
  ]
2917
3138
  ]));
2918
- for (const feed of (_b = (_a = this.inner.dataPipeline.pipelineState) == null ? void 0 : _a.feeds) != null ? _b : []) {
2919
- const indexBeforeEpoch = epoch.timeframe.get(feed.key);
2920
- if (indexBeforeEpoch) {
2921
- 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);
2922
3146
  }
2923
3147
  }
2924
3148
  }
@@ -2940,33 +3164,33 @@ var DataSpace = class DataSpace2 {
2940
3164
  this.stateUpdate.emit();
2941
3165
  }
2942
3166
  };
2943
- _ts_decorate([
3167
+ _ts_decorate3([
2944
3168
  synchronized
2945
3169
  ], DataSpace.prototype, "open", null);
2946
- _ts_decorate([
3170
+ _ts_decorate3([
2947
3171
  synchronized
2948
3172
  ], DataSpace.prototype, "close", null);
2949
- _ts_decorate([
3173
+ _ts_decorate3([
2950
3174
  timed(1e4)
2951
3175
  ], DataSpace.prototype, "_createWritableFeeds", null);
2952
- _ts_decorate([
3176
+ _ts_decorate3([
2953
3177
  synchronized
2954
3178
  ], DataSpace.prototype, "activate", null);
2955
- _ts_decorate([
3179
+ _ts_decorate3([
2956
3180
  synchronized
2957
3181
  ], DataSpace.prototype, "deactivate", null);
2958
- DataSpace = _ts_decorate([
3182
+ DataSpace = _ts_decorate3([
2959
3183
  trackLeaks("open", "close")
2960
3184
  ], DataSpace);
2961
3185
 
2962
3186
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
2963
3187
  import { Event as Event6, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
2964
- import { cancelWithContext as cancelWithContext3, Context as Context7 } from "@dxos/context";
3188
+ import { cancelWithContext as cancelWithContext3, Context as Context8 } from "@dxos/context";
2965
3189
  import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
2966
- import { invariant as invariant10 } from "@dxos/invariant";
3190
+ import { invariant as invariant11 } from "@dxos/invariant";
2967
3191
  import { PublicKey as PublicKey8 } from "@dxos/keys";
2968
- import { log as log10 } from "@dxos/log";
2969
- import { trace as trace4 } from "@dxos/protocols";
3192
+ import { log as log11 } from "@dxos/log";
3193
+ import { trace as trace5 } from "@dxos/protocols";
2970
3194
  import { SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
2971
3195
  import { Gossip, Presence } from "@dxos/teleport-extension-gossip";
2972
3196
  import { ComplexMap as ComplexMap3, deferFunction as deferFunction2 } from "@dxos/util";
@@ -2974,10 +3198,9 @@ import { ComplexMap as ComplexMap3, deferFunction as deferFunction2 } from "@dxo
2974
3198
  // packages/sdk/client-services/src/packlets/spaces/genesis.ts
2975
3199
  import { createCredential } from "@dxos/credentials";
2976
3200
  import { failUndefined as failUndefined2 } from "@dxos/debug";
2977
- import { AdmittedFeed as AdmittedFeed4, SpaceMember } from "@dxos/protocols/proto/dxos/halo/credentials";
2978
- import { Timeframe as Timeframe2 } from "@dxos/timeframe";
3201
+ import { AdmittedFeed as AdmittedFeed4, SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/halo/credentials";
3202
+ import { Timeframe as Timeframe3 } from "@dxos/timeframe";
2979
3203
  var spaceGenesis = async (keyring, signingContext, space) => {
2980
- var _a, _b, _c, _d;
2981
3204
  const credentials = [
2982
3205
  await createCredential({
2983
3206
  signer: keyring,
@@ -2995,13 +3218,13 @@ var spaceGenesis = async (keyring, signingContext, space) => {
2995
3218
  assertion: {
2996
3219
  "@type": "dxos.halo.credentials.SpaceMember",
2997
3220
  spaceKey: space.key,
2998
- role: SpaceMember.Role.ADMIN,
3221
+ role: SpaceMember2.Role.ADMIN,
2999
3222
  profile: signingContext.profile,
3000
- genesisFeedKey: (_a = space.controlFeedKey) != null ? _a : failUndefined2()
3223
+ genesisFeedKey: space.controlFeedKey ?? failUndefined2()
3001
3224
  }
3002
3225
  }),
3003
3226
  await signingContext.credentialSigner.createCredential({
3004
- subject: (_b = space.controlFeedKey) != null ? _b : failUndefined2(),
3227
+ subject: space.controlFeedKey ?? failUndefined2(),
3005
3228
  assertion: {
3006
3229
  "@type": "dxos.halo.credentials.AdmittedFeed",
3007
3230
  spaceKey: space.key,
@@ -3011,7 +3234,7 @@ var spaceGenesis = async (keyring, signingContext, space) => {
3011
3234
  }
3012
3235
  }),
3013
3236
  await signingContext.credentialSigner.createCredential({
3014
- subject: (_c = space.dataFeedKey) != null ? _c : failUndefined2(),
3237
+ subject: space.dataFeedKey ?? failUndefined2(),
3015
3238
  assertion: {
3016
3239
  "@type": "dxos.halo.credentials.AdmittedFeed",
3017
3240
  spaceKey: space.key,
@@ -3021,12 +3244,12 @@ var spaceGenesis = async (keyring, signingContext, space) => {
3021
3244
  }
3022
3245
  }),
3023
3246
  await signingContext.credentialSigner.createCredential({
3024
- subject: (_d = space.key) != null ? _d : failUndefined2(),
3247
+ subject: space.key ?? failUndefined2(),
3025
3248
  assertion: {
3026
3249
  "@type": "dxos.halo.credentials.Epoch",
3027
3250
  number: 0,
3028
3251
  previousId: void 0,
3029
- timeframe: new Timeframe2(),
3252
+ timeframe: new Timeframe3(),
3030
3253
  snapshotCid: void 0
3031
3254
  }
3032
3255
  })
@@ -3042,7 +3265,7 @@ var spaceGenesis = async (keyring, signingContext, space) => {
3042
3265
  };
3043
3266
 
3044
3267
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
3045
- function _ts_decorate2(decorators, target, key, desc) {
3268
+ function _ts_decorate4(decorators, target, key, desc) {
3046
3269
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3047
3270
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3048
3271
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3052,7 +3275,7 @@ function _ts_decorate2(decorators, target, key, desc) {
3052
3275
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3053
3276
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3054
3277
  }
3055
- var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
3278
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
3056
3279
  var DataSpaceManager = class DataSpaceManager2 {
3057
3280
  constructor(_spaceManager, _metadataStore, _dataServiceSubscriptions, _keyring, _signingContext, _feedStore) {
3058
3281
  this._spaceManager = _spaceManager;
@@ -3061,7 +3284,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3061
3284
  this._keyring = _keyring;
3062
3285
  this._signingContext = _signingContext;
3063
3286
  this._feedStore = _feedStore;
3064
- this._ctx = new Context7();
3287
+ this._ctx = new Context8();
3065
3288
  this.updated = new Event6();
3066
3289
  this._spaces = new ComplexMap3(PublicKey8.hash);
3067
3290
  this._isOpen = false;
@@ -3072,35 +3295,35 @@ var DataSpaceManager = class DataSpaceManager2 {
3072
3295
  return this._spaces;
3073
3296
  }
3074
3297
  async open() {
3075
- log10("open", void 0, {
3076
- F: __dxlog_file12,
3298
+ log11("open", void 0, {
3299
+ F: __dxlog_file13,
3077
3300
  L: 79,
3078
3301
  S: this,
3079
3302
  C: (f, a) => f(...a)
3080
3303
  });
3081
- log10.trace("dxos.echo.data-space-manager.open", trace4.begin({
3304
+ log11.trace("dxos.echo.data-space-manager.open", trace5.begin({
3082
3305
  id: this._instanceId
3083
3306
  }), {
3084
- F: __dxlog_file12,
3307
+ F: __dxlog_file13,
3085
3308
  L: 80,
3086
3309
  S: this,
3087
3310
  C: (f, a) => f(...a)
3088
3311
  });
3089
3312
  await this._metadataStore.load();
3090
- log10("metadata loaded", {
3313
+ log11("metadata loaded", {
3091
3314
  spaces: this._metadataStore.spaces.length
3092
3315
  }, {
3093
- F: __dxlog_file12,
3316
+ F: __dxlog_file13,
3094
3317
  L: 82,
3095
3318
  S: this,
3096
3319
  C: (f, a) => f(...a)
3097
3320
  });
3098
3321
  for (const spaceMetadata of this._metadataStore.spaces) {
3099
3322
  try {
3100
- log10("load space", {
3323
+ log11("load space", {
3101
3324
  spaceMetadata
3102
3325
  }, {
3103
- F: __dxlog_file12,
3326
+ F: __dxlog_file13,
3104
3327
  L: 86,
3105
3328
  S: this,
3106
3329
  C: (f, a) => f(...a)
@@ -3110,11 +3333,11 @@ var DataSpaceManager = class DataSpaceManager2 {
3110
3333
  space.initializeDataPipelineAsync();
3111
3334
  }
3112
3335
  } catch (err) {
3113
- log10.error("Error loading space", {
3336
+ log11.error("Error loading space", {
3114
3337
  spaceMetadata,
3115
3338
  err
3116
3339
  }, {
3117
- F: __dxlog_file12,
3340
+ F: __dxlog_file13,
3118
3341
  L: 92,
3119
3342
  S: this,
3120
3343
  C: (f, a) => f(...a)
@@ -3123,18 +3346,18 @@ var DataSpaceManager = class DataSpaceManager2 {
3123
3346
  }
3124
3347
  this._isOpen = true;
3125
3348
  this.updated.emit();
3126
- log10.trace("dxos.echo.data-space-manager.open", trace4.end({
3349
+ log11.trace("dxos.echo.data-space-manager.open", trace5.end({
3127
3350
  id: this._instanceId
3128
3351
  }), {
3129
- F: __dxlog_file12,
3352
+ F: __dxlog_file13,
3130
3353
  L: 98,
3131
3354
  S: this,
3132
3355
  C: (f, a) => f(...a)
3133
3356
  });
3134
3357
  }
3135
3358
  async close() {
3136
- log10("close", void 0, {
3137
- F: __dxlog_file12,
3359
+ log11("close", void 0, {
3360
+ F: __dxlog_file13,
3138
3361
  L: 103,
3139
3362
  S: this,
3140
3363
  C: (f, a) => f(...a)
@@ -3149,8 +3372,8 @@ var DataSpaceManager = class DataSpaceManager2 {
3149
3372
  * Creates a new space writing the genesis credentials to the control feed.
3150
3373
  */
3151
3374
  async createSpace() {
3152
- invariant10(this._isOpen, "Not open.", {
3153
- F: __dxlog_file12,
3375
+ invariant11(this._isOpen, "Not open.", {
3376
+ F: __dxlog_file13,
3154
3377
  L: 116,
3155
3378
  S: this,
3156
3379
  A: [
@@ -3168,10 +3391,10 @@ var DataSpaceManager = class DataSpaceManager2 {
3168
3391
  dataFeedKey,
3169
3392
  state: SpaceState2.ACTIVE
3170
3393
  };
3171
- log10("creating space...", {
3394
+ log11("creating space...", {
3172
3395
  spaceKey
3173
3396
  }, {
3174
- F: __dxlog_file12,
3397
+ F: __dxlog_file13,
3175
3398
  L: 128,
3176
3399
  S: this,
3177
3400
  C: (f, a) => f(...a)
@@ -3180,8 +3403,8 @@ var DataSpaceManager = class DataSpaceManager2 {
3180
3403
  const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner);
3181
3404
  await this._metadataStore.addSpace(metadata);
3182
3405
  const memberCredential = credentials[1];
3183
- invariant10(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3184
- F: __dxlog_file12,
3406
+ invariant11(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3407
+ F: __dxlog_file13,
3185
3408
  L: 135,
3186
3409
  S: this,
3187
3410
  A: [
@@ -3196,16 +3419,16 @@ var DataSpaceManager = class DataSpaceManager2 {
3196
3419
  }
3197
3420
  // TODO(burdon): Rename join space.
3198
3421
  async acceptSpace(opts) {
3199
- log10("accept space", {
3422
+ log11("accept space", {
3200
3423
  opts
3201
3424
  }, {
3202
- F: __dxlog_file12,
3425
+ F: __dxlog_file13,
3203
3426
  L: 147,
3204
3427
  S: this,
3205
3428
  C: (f, a) => f(...a)
3206
3429
  });
3207
- invariant10(this._isOpen, "Not open.", {
3208
- F: __dxlog_file12,
3430
+ invariant11(this._isOpen, "Not open.", {
3431
+ F: __dxlog_file13,
3209
3432
  L: 148,
3210
3433
  S: this,
3211
3434
  A: [
@@ -3213,8 +3436,8 @@ var DataSpaceManager = class DataSpaceManager2 {
3213
3436
  "'Not open.'"
3214
3437
  ]
3215
3438
  });
3216
- invariant10(!this._spaces.has(opts.spaceKey), "Space already exists.", {
3217
- F: __dxlog_file12,
3439
+ invariant11(!this._spaces.has(opts.spaceKey), "Space already exists.", {
3440
+ F: __dxlog_file13,
3218
3441
  L: 149,
3219
3442
  S: this,
3220
3443
  A: [
@@ -3246,10 +3469,10 @@ var DataSpaceManager = class DataSpaceManager2 {
3246
3469
  }));
3247
3470
  }
3248
3471
  async _constructSpace(metadata) {
3249
- log10("construct space", {
3472
+ log11("construct space", {
3250
3473
  metadata
3251
3474
  }, {
3252
- F: __dxlog_file12,
3475
+ F: __dxlog_file13,
3253
3476
  L: 182,
3254
3477
  S: this,
3255
3478
  C: (f, a) => f(...a)
@@ -3284,9 +3507,9 @@ var DataSpaceManager = class DataSpaceManager2 {
3284
3507
  session.addExtension("dxos.mesh.teleport.notarization", dataSpace.notarizationPlugin.createExtension());
3285
3508
  },
3286
3509
  onAuthFailure: () => {
3287
- log10.warn("auth failure", void 0, {
3288
- F: __dxlog_file12,
3289
- L: 213,
3510
+ log11.warn("auth failure", void 0, {
3511
+ F: __dxlog_file13,
3512
+ L: 217,
3290
3513
  S: this,
3291
3514
  C: (f, a) => f(...a)
3292
3515
  });
@@ -3306,23 +3529,23 @@ var DataSpaceManager = class DataSpaceManager2 {
3306
3529
  signingContext: this._signingContext,
3307
3530
  callbacks: {
3308
3531
  beforeReady: async () => {
3309
- log10("before space ready", {
3532
+ log11("before space ready", {
3310
3533
  space: space.key
3311
3534
  }, {
3312
- F: __dxlog_file12,
3313
- L: 231,
3535
+ F: __dxlog_file13,
3536
+ L: 235,
3314
3537
  S: this,
3315
3538
  C: (f, a) => f(...a)
3316
3539
  });
3317
3540
  await this._dataServiceSubscriptions.registerSpace(space.key, dataSpace.dataPipeline.databaseHost.createDataServiceHost());
3318
3541
  },
3319
3542
  afterReady: async () => {
3320
- log10("after space ready", {
3543
+ log11("after space ready", {
3321
3544
  space: space.key,
3322
3545
  open: this._isOpen
3323
3546
  }, {
3324
- F: __dxlog_file12,
3325
- L: 238,
3547
+ F: __dxlog_file13,
3548
+ L: 242,
3326
3549
  S: this,
3327
3550
  C: (f, a) => f(...a)
3328
3551
  });
@@ -3331,11 +3554,11 @@ var DataSpaceManager = class DataSpaceManager2 {
3331
3554
  }
3332
3555
  },
3333
3556
  beforeClose: async () => {
3334
- log10("before space close", {
3557
+ log11("before space close", {
3335
3558
  space: space.key
3336
3559
  }, {
3337
- F: __dxlog_file12,
3338
- L: 244,
3560
+ F: __dxlog_file13,
3561
+ L: 248,
3339
3562
  S: this,
3340
3563
  C: (f, a) => f(...a)
3341
3564
  });
@@ -3357,19 +3580,19 @@ var DataSpaceManager = class DataSpaceManager2 {
3357
3580
  return dataSpace;
3358
3581
  }
3359
3582
  };
3360
- _ts_decorate2([
3583
+ _ts_decorate4([
3361
3584
  synchronized2
3362
3585
  ], DataSpaceManager.prototype, "open", null);
3363
- _ts_decorate2([
3586
+ _ts_decorate4([
3364
3587
  synchronized2
3365
3588
  ], DataSpaceManager.prototype, "close", null);
3366
- _ts_decorate2([
3589
+ _ts_decorate4([
3367
3590
  synchronized2
3368
3591
  ], DataSpaceManager.prototype, "createSpace", null);
3369
- _ts_decorate2([
3592
+ _ts_decorate4([
3370
3593
  synchronized2
3371
3594
  ], DataSpaceManager.prototype, "acceptSpace", null);
3372
- DataSpaceManager = _ts_decorate2([
3595
+ DataSpaceManager = _ts_decorate4([
3373
3596
  trackLeaks2("open", "close")
3374
3597
  ], DataSpaceManager);
3375
3598
 
@@ -3379,11 +3602,11 @@ import { Stream as Stream10 } from "@dxos/codec-protobuf";
3379
3602
  import { raise as raise2 } from "@dxos/debug";
3380
3603
  import { SpaceNotFoundError } from "@dxos/echo-pipeline";
3381
3604
  import { ApiError } from "@dxos/errors";
3382
- import { log as log11 } from "@dxos/log";
3605
+ import { log as log12 } from "@dxos/log";
3383
3606
  import { encodeError } from "@dxos/protocols";
3384
- import { SpaceMember as SpaceMember2, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
3607
+ import { SpaceMember as SpaceMember3, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
3385
3608
  import { humanize } from "@dxos/util";
3386
- var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
3609
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
3387
3610
  var SpacesServiceImpl = class {
3388
3611
  constructor(_identityManager, _spaceManager, _dataServiceSubscriptions, _getDataSpaceManager) {
3389
3612
  this._identityManager = _identityManager;
@@ -3400,9 +3623,8 @@ var SpacesServiceImpl = class {
3400
3623
  return this._serializeSpace(space);
3401
3624
  }
3402
3625
  async updateSpace({ spaceKey, state }) {
3403
- var _a;
3404
3626
  const dataSpaceManager = await this._getDataSpaceManager();
3405
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3627
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3406
3628
  if (state) {
3407
3629
  switch (state) {
3408
3630
  case SpaceState3.ACTIVE:
@@ -3421,10 +3643,10 @@ var SpacesServiceImpl = class {
3421
3643
  const scheduler = new UpdateScheduler(ctx, async () => {
3422
3644
  const dataSpaceManager = await this._getDataSpaceManager();
3423
3645
  const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
3424
- log11("update", {
3646
+ log12("update", {
3425
3647
  spaces
3426
3648
  }, {
3427
- F: __dxlog_file13,
3649
+ F: __dxlog_file14,
3428
3650
  L: 78,
3429
3651
  S: this,
3430
3652
  C: (f, a) => f(...a)
@@ -3433,7 +3655,7 @@ var SpacesServiceImpl = class {
3433
3655
  spaces
3434
3656
  });
3435
3657
  }, {
3436
- maxFrequency: 2
3658
+ maxFrequency: false ? void 0 : 2
3437
3659
  });
3438
3660
  scheduleTask5(ctx, async () => {
3439
3661
  const dataSpaceManager = await this._getDataSpaceManager();
@@ -3466,17 +3688,15 @@ var SpacesServiceImpl = class {
3466
3688
  });
3467
3689
  }
3468
3690
  async postMessage({ spaceKey, channel, message }) {
3469
- var _a;
3470
3691
  const dataSpaceManager = await this._getDataSpaceManager();
3471
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3692
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3472
3693
  await space.postMessage(getChannelId(channel), message);
3473
3694
  }
3474
3695
  subscribeMessages({ spaceKey, channel }) {
3475
3696
  return new Stream10(({ ctx, next }) => {
3476
3697
  scheduleTask5(ctx, async () => {
3477
- var _a;
3478
3698
  const dataSpaceManager = await this._getDataSpaceManager();
3479
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3699
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3480
3700
  const handle = space.listen(getChannelId(channel), (message) => {
3481
3701
  next(message);
3482
3702
  });
@@ -3486,8 +3706,7 @@ var SpacesServiceImpl = class {
3486
3706
  }
3487
3707
  queryCredentials({ spaceKey }) {
3488
3708
  return new Stream10(({ ctx, next }) => {
3489
- var _a;
3490
- 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));
3491
3710
  const processor = {
3492
3711
  processCredential: async (credential) => {
3493
3712
  next(credential);
@@ -3498,9 +3717,8 @@ var SpacesServiceImpl = class {
3498
3717
  });
3499
3718
  }
3500
3719
  async writeCredentials({ spaceKey, credentials }) {
3501
- var _a;
3502
- const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3503
- 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 ?? []) {
3504
3722
  await space.controlPipeline.writer.write({
3505
3723
  credential: {
3506
3724
  credential
@@ -3509,13 +3727,11 @@ var SpacesServiceImpl = class {
3509
3727
  }
3510
3728
  }
3511
3729
  async createEpoch({ spaceKey }) {
3512
- var _a;
3513
3730
  const dataSpaceManager = await this._getDataSpaceManager();
3514
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3731
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3515
3732
  await space.createEpoch();
3516
3733
  }
3517
3734
  _serializeSpace(space) {
3518
- var _a, _b, _c, _d, _e, _f, _g;
3519
3735
  return {
3520
3736
  spaceKey: space.key,
3521
3737
  state: space.state,
@@ -3527,16 +3743,15 @@ var SpacesServiceImpl = class {
3527
3743
  currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
3528
3744
  targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
3529
3745
  totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe,
3530
- dataFeeds: (_b = (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.feeds.map((feed) => feed.key)) != null ? _b : [],
3531
- startDataTimeframe: (_c = space.dataPipeline.pipelineState) == null ? void 0 : _c.startTimeframe,
3532
- currentDataTimeframe: (_d = space.dataPipeline.pipelineState) == null ? void 0 : _d.timeframe,
3533
- targetDataTimeframe: (_e = space.dataPipeline.pipelineState) == null ? void 0 : _e.targetTimeframe,
3534
- 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
3535
3751
  },
3536
3752
  members: Array.from(space.inner.spaceState.members.values()).map((member) => {
3537
- var _a2, _b2, _c2;
3538
3753
  const peers = space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key));
3539
- const isMe = (_a2 = this._identityManager.identity) == null ? void 0 : _a2.identityKey.equals(member.key);
3754
+ const isMe = this._identityManager.identity?.identityKey.equals(member.key);
3540
3755
  if (isMe) {
3541
3756
  peers.push(space.presence.getLocalState());
3542
3757
  }
@@ -3544,14 +3759,14 @@ var SpacesServiceImpl = class {
3544
3759
  identity: {
3545
3760
  identityKey: member.key,
3546
3761
  profile: {
3547
- 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)
3548
3763
  }
3549
3764
  },
3550
- presence: isMe || peers.length > 0 ? SpaceMember2.PresenceState.ONLINE : SpaceMember2.PresenceState.OFFLINE,
3765
+ presence: isMe || peers.length > 0 ? SpaceMember3.PresenceState.ONLINE : SpaceMember3.PresenceState.OFFLINE,
3551
3766
  peerStates: peers
3552
3767
  };
3553
3768
  }),
3554
- creator: (_g = space.inner.spaceState.creator) == null ? void 0 : _g.key,
3769
+ creator: space.inner.spaceState.creator?.key,
3555
3770
  cache: space.cache,
3556
3771
  metrics: space.metrics
3557
3772
  };
@@ -3561,19 +3776,32 @@ var getChannelId = (channel) => `user-channel/${channel}`;
3561
3776
 
3562
3777
  // packages/sdk/client-services/src/packlets/services/service-context.ts
3563
3778
  import { Trigger as Trigger5 } from "@dxos/async";
3779
+ import { Context as Context9 } from "@dxos/context";
3564
3780
  import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
3565
3781
  import { failUndefined as failUndefined3 } from "@dxos/debug";
3566
3782
  import { valueEncoding, MetadataStore, SpaceManager, DataServiceSubscriptions, SnapshotStore } from "@dxos/echo-pipeline";
3567
3783
  import { FeedFactory, FeedStore } from "@dxos/feed-store";
3568
- import { invariant as invariant11 } from "@dxos/invariant";
3784
+ import { invariant as invariant12 } from "@dxos/invariant";
3569
3785
  import { Keyring } from "@dxos/keyring";
3570
3786
  import { PublicKey as PublicKey9 } from "@dxos/keys";
3571
- import { log as log12 } from "@dxos/log";
3572
- import { STORAGE_VERSION, trace as trace5 } from "@dxos/protocols";
3787
+ import { log as log13 } from "@dxos/log";
3788
+ import { STORAGE_VERSION as STORAGE_VERSION2, trace as trace6 } from "@dxos/protocols";
3573
3789
  import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
3574
3790
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
3575
- var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
3576
- var ServiceContext = class {
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
+ }
3803
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
3804
+ var ServiceContext = class ServiceContext2 {
3577
3805
  // prettier-ignore
3578
3806
  constructor(storage, networkManager, signalManager, modelFactory) {
3579
3807
  this.storage = storage;
@@ -3593,7 +3821,8 @@ var ServiceContext = class {
3593
3821
  root: storage.createDirectory("feeds"),
3594
3822
  signer: this.keyring,
3595
3823
  hypercore: {
3596
- valueEncoding
3824
+ valueEncoding,
3825
+ stats: true
3597
3826
  }
3598
3827
  })
3599
3828
  });
@@ -3607,84 +3836,80 @@ var ServiceContext = class {
3607
3836
  });
3608
3837
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager);
3609
3838
  this.invitations = new InvitationsHandler(this.networkManager);
3610
- this._handlerFactories.set(Invitation5.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => {
3611
- var _a;
3612
- return (_a = this.identityManager.identity) != null ? _a : failUndefined3();
3613
- }, this._acceptIdentity.bind(this)));
3839
+ this._handlerFactories.set(Invitation5.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined3(), this._acceptIdentity.bind(this)));
3614
3840
  }
3615
- async open() {
3616
- log12.trace("dxos.sdk.service-context.open", trace5.begin({
3617
- id: this._instanceId
3618
- }), {
3619
- F: __dxlog_file14,
3620
- L: 125,
3841
+ async open(ctx) {
3842
+ await this._checkStorageVersion();
3843
+ log13("opening...", void 0, {
3844
+ F: __dxlog_file15,
3845
+ L: 135,
3621
3846
  S: this,
3622
3847
  C: (f, a) => f(...a)
3623
3848
  });
3624
- await this._checkStorageVersion();
3625
- log12("opening...", void 0, {
3626
- F: __dxlog_file14,
3627
- L: 129,
3849
+ log13.trace("dxos.sdk.service-context.open", trace6.begin({
3850
+ id: this._instanceId
3851
+ }), {
3852
+ F: __dxlog_file15,
3853
+ L: 136,
3628
3854
  S: this,
3629
3855
  C: (f, a) => f(...a)
3630
3856
  });
3631
3857
  await this.signalManager.open();
3632
3858
  await this.networkManager.open();
3633
3859
  await this.spaceManager.open();
3634
- await this.identityManager.open();
3860
+ await this.identityManager.open(ctx);
3635
3861
  if (this.identityManager.identity) {
3636
- await this._initialize();
3862
+ await this._initialize(ctx);
3637
3863
  }
3638
- log12("opened", void 0, {
3639
- F: __dxlog_file14,
3640
- L: 137,
3864
+ log13.trace("dxos.sdk.service-context.open", trace6.end({
3865
+ id: this._instanceId
3866
+ }), {
3867
+ F: __dxlog_file15,
3868
+ L: 144,
3641
3869
  S: this,
3642
3870
  C: (f, a) => f(...a)
3643
3871
  });
3644
- log12.trace("dxos.sdk.service-context.open", trace5.end({
3645
- id: this._instanceId
3646
- }), {
3647
- F: __dxlog_file14,
3648
- L: 138,
3872
+ log13("opened", void 0, {
3873
+ F: __dxlog_file15,
3874
+ L: 145,
3649
3875
  S: this,
3650
3876
  C: (f, a) => f(...a)
3651
3877
  });
3652
3878
  }
3653
3879
  async close() {
3654
- var _a;
3655
- log12("closing...", void 0, {
3656
- F: __dxlog_file14,
3657
- L: 142,
3880
+ log13("closing...", void 0, {
3881
+ F: __dxlog_file15,
3882
+ L: 149,
3658
3883
  S: this,
3659
3884
  C: (f, a) => f(...a)
3660
3885
  });
3661
3886
  if (this._deviceSpaceSync && this.identityManager.identity) {
3662
3887
  await this.identityManager.identity.space.spaceState.removeCredentialProcessor(this._deviceSpaceSync);
3663
3888
  }
3664
- await ((_a = this.dataSpaceManager) == null ? void 0 : _a.close());
3889
+ await this.dataSpaceManager?.close();
3665
3890
  await this.identityManager.close();
3666
3891
  await this.spaceManager.close();
3667
3892
  await this.feedStore.close();
3668
3893
  await this.networkManager.close();
3669
3894
  await this.signalManager.close();
3670
3895
  this.dataServiceSubscriptions.clear();
3671
- log12("closed", void 0, {
3672
- F: __dxlog_file14,
3673
- L: 153,
3896
+ log13("closed", void 0, {
3897
+ F: __dxlog_file15,
3898
+ L: 160,
3674
3899
  S: this,
3675
3900
  C: (f, a) => f(...a)
3676
3901
  });
3677
3902
  }
3678
3903
  async createIdentity(params = {}) {
3679
3904
  const identity = await this.identityManager.createIdentity(params);
3680
- await this._initialize();
3905
+ await this._initialize(new Context9());
3681
3906
  return identity;
3682
3907
  }
3683
3908
  getInvitationHandler(invitation) {
3684
3909
  const factory = this._handlerFactories.get(invitation.kind);
3685
- invariant11(factory, `Unknown invitation kind: ${invitation.kind}`, {
3686
- F: __dxlog_file14,
3687
- L: 165,
3910
+ invariant12(factory, `Unknown invitation kind: ${invitation.kind}`, {
3911
+ F: __dxlog_file15,
3912
+ L: 171,
3688
3913
  S: this,
3689
3914
  A: [
3690
3915
  "factory",
@@ -3695,25 +3920,24 @@ var ServiceContext = class {
3695
3920
  }
3696
3921
  async _acceptIdentity(params) {
3697
3922
  const identity = await this.identityManager.acceptIdentity(params);
3698
- await this._initialize();
3923
+ await this._initialize(new Context9());
3699
3924
  return identity;
3700
3925
  }
3701
3926
  async _checkStorageVersion() {
3702
3927
  await this.metadataStore.load();
3703
- if (this.metadataStore.version !== STORAGE_VERSION) {
3704
- throw new Error(`Invalid storage version: current=${this.metadataStore.version}, expected=${STORAGE_VERSION}`);
3928
+ if (this.metadataStore.version !== STORAGE_VERSION2) {
3929
+ throw new Error(`Invalid storage version: current=${this.metadataStore.version}, expected=${STORAGE_VERSION2}`);
3705
3930
  }
3706
3931
  }
3707
3932
  // Called when identity is created.
3708
- async _initialize() {
3709
- var _a;
3710
- log12("initializing spaces...", void 0, {
3711
- F: __dxlog_file14,
3712
- L: 186,
3933
+ async _initialize(ctx) {
3934
+ log13("initializing spaces...", void 0, {
3935
+ F: __dxlog_file15,
3936
+ L: 192,
3713
3937
  S: this,
3714
3938
  C: (f, a) => f(...a)
3715
3939
  });
3716
- const identity = (_a = this.identityManager.identity) != null ? _a : failUndefined3();
3940
+ const identity = this.identityManager.identity ?? failUndefined3();
3717
3941
  const signingContext = {
3718
3942
  credentialSigner: identity.getIdentityCredentialSigner(),
3719
3943
  identityKey: identity.identityKey,
@@ -3730,9 +3954,9 @@ var ServiceContext = class {
3730
3954
  this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.dataServiceSubscriptions, this.keyring, signingContext, this.feedStore);
3731
3955
  await this.dataSpaceManager.open();
3732
3956
  this._handlerFactories.set(Invitation5.Kind.SPACE, (invitation) => {
3733
- invariant11(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
3734
- F: __dxlog_file14,
3735
- L: 209,
3957
+ invariant12(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
3958
+ F: __dxlog_file15,
3959
+ L: 215,
3736
3960
  S: this,
3737
3961
  A: [
3738
3962
  "this.dataSpaceManager",
@@ -3752,33 +3976,33 @@ var ServiceContext = class {
3752
3976
  return;
3753
3977
  }
3754
3978
  if (!this.dataSpaceManager) {
3755
- log12("dataSpaceManager not initialized yet, ignoring space admission", {
3979
+ log13("dataSpaceManager not initialized yet, ignoring space admission", {
3756
3980
  details: assertion
3757
3981
  }, {
3758
- F: __dxlog_file14,
3759
- L: 225,
3982
+ F: __dxlog_file15,
3983
+ L: 231,
3760
3984
  S: this,
3761
3985
  C: (f, a) => f(...a)
3762
3986
  });
3763
3987
  return;
3764
3988
  }
3765
3989
  if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
3766
- log12("space already exists, ignoring space admission", {
3990
+ log13("space already exists, ignoring space admission", {
3767
3991
  details: assertion
3768
3992
  }, {
3769
- F: __dxlog_file14,
3770
- L: 229,
3993
+ F: __dxlog_file15,
3994
+ L: 235,
3771
3995
  S: this,
3772
3996
  C: (f, a) => f(...a)
3773
3997
  });
3774
3998
  return;
3775
3999
  }
3776
4000
  try {
3777
- log12("accepting space recorded in halo", {
4001
+ log13("accepting space recorded in halo", {
3778
4002
  details: assertion
3779
4003
  }, {
3780
- F: __dxlog_file14,
3781
- L: 234,
4004
+ F: __dxlog_file15,
4005
+ L: 240,
3782
4006
  S: this,
3783
4007
  C: (f, a) => f(...a)
3784
4008
  });
@@ -3787,9 +4011,9 @@ var ServiceContext = class {
3787
4011
  genesisFeedKey: assertion.genesisFeedKey
3788
4012
  });
3789
4013
  } catch (err) {
3790
- log12.catch(err, void 0, {
3791
- F: __dxlog_file14,
3792
- L: 240,
4014
+ log13.catch(err, void 0, {
4015
+ F: __dxlog_file15,
4016
+ L: 246,
3793
4017
  S: this,
3794
4018
  C: (f, a) => f(...a)
3795
4019
  });
@@ -3799,12 +4023,22 @@ var ServiceContext = class {
3799
4023
  await identity.space.spaceState.addCredentialProcessor(this._deviceSpaceSync);
3800
4024
  }
3801
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);
3802
4036
 
3803
4037
  // packages/sdk/client-services/src/packlets/locks/browser.ts
3804
4038
  import { asyncTimeout, Trigger as Trigger6 } from "@dxos/async";
3805
4039
  import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
3806
- import { log as log13, logInfo } from "@dxos/log";
3807
- function _ts_decorate3(decorators, target, key, desc) {
4040
+ import { log as log14, logInfo } from "@dxos/log";
4041
+ function _ts_decorate6(decorators, target, key, desc) {
3808
4042
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3809
4043
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3810
4044
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3814,7 +4048,7 @@ function _ts_decorate3(decorators, target, key, desc) {
3814
4048
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3815
4049
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3816
4050
  }
3817
- var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
4051
+ var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
3818
4052
  var Message;
3819
4053
  (function(Message2) {
3820
4054
  Message2["ACQUIRING"] = "acquiring";
@@ -3836,29 +4070,29 @@ var Lock = class {
3836
4070
  message: Message.ACQUIRING
3837
4071
  });
3838
4072
  try {
3839
- log13("aquiring lock...", void 0, {
3840
- F: __dxlog_file15,
4073
+ log14("aquiring lock...", void 0, {
4074
+ F: __dxlog_file16,
3841
4075
  L: 42,
3842
4076
  S: this,
3843
4077
  C: (f, a) => f(...a)
3844
4078
  });
3845
4079
  await asyncTimeout(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
3846
- log13("acquired lock", void 0, {
3847
- F: __dxlog_file15,
4080
+ log14("acquired lock", void 0, {
4081
+ F: __dxlog_file16,
3848
4082
  L: 44,
3849
4083
  S: this,
3850
4084
  C: (f, a) => f(...a)
3851
4085
  });
3852
- } catch (e) {
3853
- log13("stealing lock...", void 0, {
3854
- F: __dxlog_file15,
4086
+ } catch {
4087
+ log14("stealing lock...", void 0, {
4088
+ F: __dxlog_file16,
3855
4089
  L: 46,
3856
4090
  S: this,
3857
4091
  C: (f, a) => f(...a)
3858
4092
  });
3859
4093
  await this._requestLock(true);
3860
- log13("stolen lock", void 0, {
3861
- F: __dxlog_file15,
4094
+ log14("stolen lock", void 0, {
4095
+ F: __dxlog_file16,
3862
4096
  L: 48,
3863
4097
  S: this,
3864
4098
  C: (f, a) => f(...a)
@@ -3874,10 +4108,10 @@ var Lock = class {
3874
4108
  }
3875
4109
  }
3876
4110
  async _requestLock(steal = false) {
3877
- log13("requesting lock...", {
4111
+ log14("requesting lock...", {
3878
4112
  steal
3879
4113
  }, {
3880
- F: __dxlog_file15,
4114
+ F: __dxlog_file16,
3881
4115
  L: 63,
3882
4116
  S: this,
3883
4117
  C: (f, a) => f(...a)
@@ -3886,40 +4120,38 @@ var Lock = class {
3886
4120
  void navigator.locks.request(this._lockKey, {
3887
4121
  steal
3888
4122
  }, async () => {
3889
- var _a, _b;
3890
- await ((_a = this._onAcquire) == null ? void 0 : _a.call(this));
4123
+ await this._onAcquire?.();
3891
4124
  acquired.wake();
3892
4125
  this._releaseTrigger = new Trigger6();
3893
4126
  await this._releaseTrigger.wait();
3894
- log13("releasing lock...", void 0, {
3895
- F: __dxlog_file15,
4127
+ log14("releasing lock...", void 0, {
4128
+ F: __dxlog_file16,
3896
4129
  L: 72,
3897
4130
  S: this,
3898
4131
  C: (f, a) => f(...a)
3899
4132
  });
3900
- await ((_b = this._onRelease) == null ? void 0 : _b.call(this));
3901
- log13("released lock", void 0, {
3902
- F: __dxlog_file15,
4133
+ await this._onRelease?.();
4134
+ log14("released lock", void 0, {
4135
+ F: __dxlog_file16,
3903
4136
  L: 74,
3904
4137
  S: this,
3905
4138
  C: (f, a) => f(...a)
3906
4139
  });
3907
4140
  }).catch(async () => {
3908
- var _a;
3909
- await ((_a = this._onRelease) == null ? void 0 : _a.call(this));
4141
+ await this._onRelease?.();
3910
4142
  });
3911
4143
  await acquired.wait();
3912
- log13("recieved lock", {
4144
+ log14("recieved lock", {
3913
4145
  steal
3914
4146
  }, {
3915
- F: __dxlog_file15,
4147
+ F: __dxlog_file16,
3916
4148
  L: 81,
3917
4149
  S: this,
3918
4150
  C: (f, a) => f(...a)
3919
4151
  });
3920
4152
  }
3921
4153
  };
3922
- _ts_decorate3([
4154
+ _ts_decorate6([
3923
4155
  logInfo
3924
4156
  ], Lock.prototype, "lockKey", null);
3925
4157
  var isLocked = (lockPath) => {
@@ -3934,7 +4166,7 @@ import { createStorage, StorageType } from "@dxos/random-access-storage";
3934
4166
  import { isNode } from "@dxos/util";
3935
4167
  var StorageDriver = Runtime.Client.Storage.StorageDriver;
3936
4168
  var createStorageObjects = (config) => {
3937
- 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 ?? {};
3938
4170
  if (persistent && storageType === StorageDriver.RAM) {
3939
4171
  throw new InvalidConfigError("RAM storage cannot be used in persistent mode.");
3940
4172
  }
@@ -4002,17 +4234,19 @@ var ServiceRegistry = class {
4002
4234
  // packages/sdk/client-services/src/packlets/services/service-host.ts
4003
4235
  import { Event as Event8, synchronized as synchronized3 } from "@dxos/async";
4004
4236
  import { clientServiceBundle } from "@dxos/client-protocol";
4005
- import { DocumentModel } from "@dxos/document-model";
4237
+ import { Context as Context10 } from "@dxos/context";
4238
+ import { DocumentModel as DocumentModel2 } from "@dxos/document-model";
4006
4239
  import { DataServiceImpl } from "@dxos/echo-pipeline";
4007
- import { invariant as invariant12 } from "@dxos/invariant";
4240
+ import { invariant as invariant13 } from "@dxos/invariant";
4008
4241
  import { PublicKey as PublicKey10 } from "@dxos/keys";
4009
- import { log as log15 } from "@dxos/log";
4242
+ import { log as log16 } from "@dxos/log";
4010
4243
  import { WebsocketSignalManager } from "@dxos/messaging";
4011
4244
  import { ModelFactory } from "@dxos/model-factory";
4012
4245
  import { createWebRTCTransportFactory, NetworkManager } from "@dxos/network-manager";
4013
- import { trace as trace6 } from "@dxos/protocols";
4246
+ import { trace as trace7 } from "@dxos/protocols";
4014
4247
  import { SystemStatus } from "@dxos/protocols/proto/dxos/client/services";
4015
4248
  import { TextModel } from "@dxos/text-model";
4249
+ import { TRACE_PROCESSOR, trace as Trace3 } from "@dxos/tracing";
4016
4250
 
4017
4251
  // packages/sdk/client-services/src/packlets/devices/devices-service.ts
4018
4252
  import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
@@ -4028,21 +4262,17 @@ var DevicesServiceImpl = class {
4028
4262
  queryDevices() {
4029
4263
  return new Stream11(({ next }) => {
4030
4264
  const update = () => {
4031
- var _a;
4032
- const deviceKeys = (_a = this._identityManager.identity) == null ? void 0 : _a.authorizedDeviceKeys;
4265
+ const deviceKeys = this._identityManager.identity?.authorizedDeviceKeys;
4033
4266
  if (!deviceKeys) {
4034
4267
  next({
4035
4268
  devices: []
4036
4269
  });
4037
4270
  } else {
4038
4271
  next({
4039
- devices: Array.from(deviceKeys.values()).map((key) => {
4040
- var _a2;
4041
- return {
4042
- deviceKey: key,
4043
- kind: ((_a2 = this._identityManager.identity) == null ? void 0 : _a2.deviceKey.equals(key)) ? DeviceKind.CURRENT : DeviceKind.TRUSTED
4044
- };
4045
- })
4272
+ devices: Array.from(deviceKeys.values()).map((key) => ({
4273
+ deviceKey: key,
4274
+ kind: this._identityManager.identity?.deviceKey.equals(key) ? DeviceKind.CURRENT : DeviceKind.TRUSTED
4275
+ }))
4046
4276
  });
4047
4277
  }
4048
4278
  };
@@ -4064,22 +4294,23 @@ var DevicesServiceImpl = class {
4064
4294
  // packages/sdk/client-services/src/packlets/logging/logging-service.ts
4065
4295
  import { Event as Event7 } from "@dxos/async";
4066
4296
  import { Stream as Stream12 } from "@dxos/codec-protobuf";
4067
- import { getContextFromEntry, log as log14 } from "@dxos/log";
4297
+ import { getContextFromEntry, log as log15 } from "@dxos/log";
4068
4298
  import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
4069
4299
  import { jsonify, numericalValues, tracer } from "@dxos/util";
4070
4300
  var LoggingServiceImpl = class {
4071
4301
  constructor() {
4072
4302
  this._logs = new Event7();
4303
+ this._started = /* @__PURE__ */ new Date();
4073
4304
  this._logProcessor = (_config, entry2) => {
4074
4305
  this._logs.emit(entry2);
4075
4306
  };
4076
4307
  }
4077
4308
  async open() {
4078
- log14.runtimeConfig.processors.push(this._logProcessor);
4309
+ log15.runtimeConfig.processors.push(this._logProcessor);
4079
4310
  }
4080
4311
  async close() {
4081
- const index = log14.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
4082
- log14.runtimeConfig.processors.splice(index, 1);
4312
+ const index = log15.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
4313
+ log15.runtimeConfig.processors.splice(index, 1);
4083
4314
  }
4084
4315
  async controlMetrics({ reset, record }) {
4085
4316
  if (reset) {
@@ -4094,28 +4325,33 @@ var LoggingServiceImpl = class {
4094
4325
  recording: tracer.recording
4095
4326
  };
4096
4327
  }
4097
- queryMetrics({ interval }) {
4098
- const createNumericalValues = (key) => {
4099
- var _a;
4100
- const consume = (_a = tracer.get(key)) != null ? _a : [];
4328
+ /**
4329
+ * @deprecated (Move to diagnostics).
4330
+ */
4331
+ queryMetrics({ interval = 5e3 }) {
4332
+ const getNumericalValues = (key) => {
4333
+ const events = tracer.get(key) ?? [];
4101
4334
  return {
4102
4335
  key,
4103
- stats: numericalValues(consume, "duration")
4336
+ stats: numericalValues(events, "duration")
4104
4337
  };
4105
4338
  };
4106
4339
  return new Stream12(({ next }) => {
4107
4340
  const update = () => {
4108
4341
  const metrics = {
4109
- timestamp: new Date(),
4342
+ timestamp: /* @__PURE__ */ new Date(),
4110
4343
  values: [
4111
- createNumericalValues("dxos.echo.pipeline.control"),
4112
- createNumericalValues("dxos.echo.pipeline.data")
4113
- ]
4344
+ getNumericalValues("dxos.echo.pipeline.control"),
4345
+ getNumericalValues("dxos.echo.pipeline.data")
4346
+ ].filter(Boolean)
4114
4347
  };
4115
- next(metrics);
4348
+ next({
4349
+ timestamp: /* @__PURE__ */ new Date(),
4350
+ metrics
4351
+ });
4116
4352
  };
4117
4353
  update();
4118
- const i = setInterval(update, interval);
4354
+ const i = setInterval(update, Math.max(interval, 1e3));
4119
4355
  return () => {
4120
4356
  clearInterval(i);
4121
4357
  };
@@ -4124,11 +4360,10 @@ var LoggingServiceImpl = class {
4124
4360
  queryLogs(request) {
4125
4361
  return new Stream12(({ ctx, next }) => {
4126
4362
  const handler = (entry2) => {
4127
- var _a, _b, _c, _d, _e;
4128
4363
  if (LOG_PROCESSING > 0) {
4129
4364
  return;
4130
4365
  }
4131
- 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"))) {
4132
4367
  return;
4133
4368
  }
4134
4369
  if (!shouldLog(entry2, request)) {
@@ -4137,11 +4372,11 @@ var LoggingServiceImpl = class {
4137
4372
  const record = {
4138
4373
  ...entry2,
4139
4374
  context: jsonify(getContextFromEntry(entry2)),
4140
- timestamp: new Date(),
4375
+ timestamp: /* @__PURE__ */ new Date(),
4141
4376
  meta: {
4142
4377
  // TODO(dmaretskyi): Fix proto.
4143
- file: (_c = (_b = entry2.meta) == null ? void 0 : _b.F) != null ? _c : "",
4144
- line: (_e = (_d = entry2.meta) == null ? void 0 : _d.L) != null ? _e : 0
4378
+ file: entry2.meta?.F ?? "",
4379
+ line: entry2.meta?.L ?? 0
4145
4380
  }
4146
4381
  };
4147
4382
  try {
@@ -4164,15 +4399,11 @@ var matchFilter = (filter, level, path, options) => {
4164
4399
  }
4165
4400
  };
4166
4401
  var shouldLog = (entry2, request) => {
4167
- var _a;
4168
- const options = (_a = request.options) != null ? _a : QueryLogsRequest.MatchingOptions.INCLUSIVE;
4402
+ const options = request.options ?? QueryLogsRequest.MatchingOptions.INCLUSIVE;
4169
4403
  if (request.filters === void 0) {
4170
4404
  return options === QueryLogsRequest.MatchingOptions.INCLUSIVE;
4171
4405
  } else {
4172
- return request.filters.some((filter) => {
4173
- var _a2, _b;
4174
- return matchFilter(filter, entry2.level, (_b = (_a2 = entry2.meta) == null ? void 0 : _a2.F) != null ? _b : "", options);
4175
- });
4406
+ return request.filters.some((filter) => matchFilter(filter, entry2.level, entry2.meta?.F ?? "", options));
4176
4407
  }
4177
4408
  };
4178
4409
  var LOG_PROCESSING = 0;
@@ -4211,17 +4442,32 @@ var NetworkServiceImpl = class {
4211
4442
 
4212
4443
  // packages/sdk/client-services/src/packlets/system/system-service.ts
4213
4444
  import { Stream as Stream14 } from "@dxos/codec-protobuf";
4445
+ import { GetDiagnosticsRequest } from "@dxos/protocols/proto/dxos/client/services";
4446
+ import { jsonKeyReplacer } from "@dxos/util";
4214
4447
  var SystemServiceImpl = class {
4215
- constructor({ config, statusUpdate, onUpdateStatus, getCurrentStatus, onReset }) {
4448
+ constructor({ config, statusUpdate, getDiagnostics, onUpdateStatus, getCurrentStatus, onReset }) {
4216
4449
  this._config = config;
4217
4450
  this._statusUpdate = statusUpdate;
4218
4451
  this._getCurrentStatus = getCurrentStatus;
4452
+ this._getDiagnostics = getDiagnostics;
4219
4453
  this._onUpdateStatus = onUpdateStatus;
4220
4454
  this._onReset = onReset;
4221
4455
  }
4222
4456
  async getConfig() {
4223
- var _a, _b;
4224
- return (_b = (_a = this._config) == null ? void 0 : _a.values) != null ? _b : {};
4457
+ return this._config?.values ?? {};
4458
+ }
4459
+ /**
4460
+ * NOTE: Since this is serialized as a JSON object, we allow the option to serialize keys.
4461
+ */
4462
+ async getDiagnostics({ keys } = {}) {
4463
+ const diagnostics = await this._getDiagnostics();
4464
+ return {
4465
+ timestamp: /* @__PURE__ */ new Date(),
4466
+ diagnostics: JSON.parse(JSON.stringify(diagnostics, jsonKeyReplacer({
4467
+ truncate: keys === GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
4468
+ humanize: keys === GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
4469
+ })))
4470
+ };
4225
4471
  }
4226
4472
  async updateStatus({ status }) {
4227
4473
  await this._onUpdateStatus(status);
@@ -4249,7 +4495,7 @@ var SystemServiceImpl = class {
4249
4495
  };
4250
4496
 
4251
4497
  // packages/sdk/client-services/src/packlets/services/service-host.ts
4252
- function _ts_decorate4(decorators, target, key, desc) {
4498
+ function _ts_decorate7(decorators, target, key, desc) {
4253
4499
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4254
4500
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
4255
4501
  r = Reflect.decorate(decorators, target, key, desc);
@@ -4259,23 +4505,22 @@ function _ts_decorate4(decorators, target, key, desc) {
4259
4505
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4260
4506
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4261
4507
  }
4262
- var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
4508
+ var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
4263
4509
  var createDefaultModelFactory = () => {
4264
- return new ModelFactory().registerModel(DocumentModel).registerModel(TextModel);
4510
+ return new ModelFactory().registerModel(DocumentModel2).registerModel(TextModel);
4265
4511
  };
4266
- var ClientServicesHost = class {
4512
+ var ClientServicesHost = class ClientServicesHost2 {
4267
4513
  constructor({
4268
4514
  config,
4269
4515
  modelFactory = createDefaultModelFactory(),
4270
- // TODO(burdon): Create ApolloLink abstraction (see Client).
4271
4516
  transportFactory,
4272
4517
  signalManager,
4273
- connectionLog,
4274
4518
  storage,
4275
4519
  // TODO(wittjosiah): Turn this on by default.
4276
4520
  lockKey,
4277
4521
  callbacks
4278
4522
  } = {}) {
4523
+ this._tracingService = TRACE_PROCESSOR.createTraceSender();
4279
4524
  this._statusUpdate = new Event8();
4280
4525
  this._opening = false;
4281
4526
  this._open = false;
@@ -4294,7 +4539,7 @@ var ClientServicesHost = class {
4294
4539
  lockKey,
4295
4540
  onAcquire: () => {
4296
4541
  if (!this._opening) {
4297
- void this.open();
4542
+ void this.open(new Context10());
4298
4543
  }
4299
4544
  },
4300
4545
  onRelease: () => this.close()
@@ -4304,12 +4549,14 @@ var ClientServicesHost = class {
4304
4549
  config: this._config,
4305
4550
  statusUpdate: this._statusUpdate,
4306
4551
  getCurrentStatus: () => this.isOpen ? SystemStatus.ACTIVE : SystemStatus.INACTIVE,
4552
+ getDiagnostics: () => {
4553
+ return createDiagnostics(this._serviceRegistry.services, this._serviceContext, this._config);
4554
+ },
4307
4555
  onUpdateStatus: async (status) => {
4308
- var _a, _b;
4309
4556
  if (!this.isOpen && status === SystemStatus.ACTIVE) {
4310
- await ((_a = this._resourceLock) == null ? void 0 : _a.acquire());
4557
+ await this._resourceLock?.acquire();
4311
4558
  } else if (this.isOpen && status === SystemStatus.INACTIVE) {
4312
- await ((_b = this._resourceLock) == null ? void 0 : _b.release());
4559
+ await this._resourceLock?.release();
4313
4560
  }
4314
4561
  },
4315
4562
  onReset: async () => {
@@ -4318,12 +4565,19 @@ var ClientServicesHost = class {
4318
4565
  });
4319
4566
  this._loggingService = new LoggingServiceImpl();
4320
4567
  this._serviceRegistry = new ServiceRegistry(clientServiceBundle, {
4321
- SystemService: this._systemService
4568
+ SystemService: this._systemService,
4569
+ TracingService: this._tracingService
4322
4570
  });
4323
4571
  }
4324
4572
  get isOpen() {
4325
4573
  return this._open;
4326
4574
  }
4575
+ get config() {
4576
+ return this._config;
4577
+ }
4578
+ get context() {
4579
+ return this._serviceContext;
4580
+ }
4327
4581
  get serviceRegistry() {
4328
4582
  return this._serviceRegistry;
4329
4583
  }
@@ -4339,20 +4593,25 @@ var ClientServicesHost = class {
4339
4593
  * Can only be called once.
4340
4594
  */
4341
4595
  initialize({ config, ...options }) {
4342
- var _a, _b, _c;
4343
- invariant12(!this._open, "service host is open", {
4344
- F: __dxlog_file16,
4345
- L: 167,
4596
+ invariant13(!this._open, "service host is open", {
4597
+ F: __dxlog_file17,
4598
+ L: 181,
4346
4599
  S: this,
4347
4600
  A: [
4348
4601
  "!this._open",
4349
4602
  "'service host is open'"
4350
4603
  ]
4351
4604
  });
4605
+ log16("initializing...", void 0, {
4606
+ F: __dxlog_file17,
4607
+ L: 182,
4608
+ S: this,
4609
+ C: (f, a) => f(...a)
4610
+ });
4352
4611
  if (config) {
4353
- invariant12(!this._config, "config already set", {
4354
- F: __dxlog_file16,
4355
- L: 170,
4612
+ invariant13(!this._config, "config already set", {
4613
+ F: __dxlog_file17,
4614
+ L: 185,
4356
4615
  S: this,
4357
4616
  A: [
4358
4617
  "!this._config",
@@ -4365,12 +4624,12 @@ var ClientServicesHost = class {
4365
4624
  }
4366
4625
  }
4367
4626
  const { connectionLog = true, transportFactory = createWebRTCTransportFactory({
4368
- iceServers: (_a = this._config) == null ? void 0 : _a.get("runtime.services.ice")
4369
- }), 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;
4370
4629
  this._signalManager = signalManager;
4371
- invariant12(!this._networkManager, "network manager already set", {
4372
- F: __dxlog_file16,
4373
- L: 187,
4630
+ invariant13(!this._networkManager, "network manager already set", {
4631
+ F: __dxlog_file17,
4632
+ L: 201,
4374
4633
  S: this,
4375
4634
  A: [
4376
4635
  "!this._networkManager",
@@ -4382,51 +4641,56 @@ var ClientServicesHost = class {
4382
4641
  transportFactory,
4383
4642
  signalManager
4384
4643
  });
4644
+ log16("initialized", void 0, {
4645
+ F: __dxlog_file17,
4646
+ L: 208,
4647
+ S: this,
4648
+ C: (f, a) => f(...a)
4649
+ });
4385
4650
  }
4386
- async open() {
4387
- var _a, _b, _c;
4651
+ async open(ctx) {
4388
4652
  if (this._open) {
4389
4653
  return;
4390
4654
  }
4391
4655
  const traceId = PublicKey10.random().toHex();
4392
- log15.trace("dxos.sdk.client-services-host.open", trace6.begin({
4656
+ log16.trace("dxos.client-services.host.open", trace7.begin({
4393
4657
  id: traceId
4394
4658
  }), {
4395
- F: __dxlog_file16,
4396
- L: 202,
4659
+ F: __dxlog_file17,
4660
+ L: 219,
4397
4661
  S: this,
4398
4662
  C: (f, a) => f(...a)
4399
4663
  });
4400
- invariant12(this._config, "config not set", {
4401
- F: __dxlog_file16,
4402
- L: 204,
4664
+ invariant13(this._config, "config not set", {
4665
+ F: __dxlog_file17,
4666
+ L: 221,
4403
4667
  S: this,
4404
4668
  A: [
4405
4669
  "this._config",
4406
4670
  "'config not set'"
4407
4671
  ]
4408
4672
  });
4409
- invariant12(this._storage, "storage not set", {
4410
- F: __dxlog_file16,
4411
- L: 205,
4673
+ invariant13(this._storage, "storage not set", {
4674
+ F: __dxlog_file17,
4675
+ L: 222,
4412
4676
  S: this,
4413
4677
  A: [
4414
4678
  "this._storage",
4415
4679
  "'storage not set'"
4416
4680
  ]
4417
4681
  });
4418
- invariant12(this._signalManager, "signal manager not set", {
4419
- F: __dxlog_file16,
4420
- L: 206,
4682
+ invariant13(this._signalManager, "signal manager not set", {
4683
+ F: __dxlog_file17,
4684
+ L: 223,
4421
4685
  S: this,
4422
4686
  A: [
4423
4687
  "this._signalManager",
4424
4688
  "'signal manager not set'"
4425
4689
  ]
4426
4690
  });
4427
- invariant12(this._networkManager, "network manager not set", {
4428
- F: __dxlog_file16,
4429
- L: 207,
4691
+ invariant13(this._networkManager, "network manager not set", {
4692
+ F: __dxlog_file17,
4693
+ L: 224,
4430
4694
  S: this,
4431
4695
  A: [
4432
4696
  "this._networkManager",
@@ -4434,20 +4698,20 @@ var ClientServicesHost = class {
4434
4698
  ]
4435
4699
  });
4436
4700
  this._opening = true;
4437
- log15("opening...", {
4438
- lockKey: (_a = this._resourceLock) == null ? void 0 : _a.lockKey
4701
+ log16("opening...", {
4702
+ lockKey: this._resourceLock?.lockKey
4439
4703
  }, {
4440
- F: __dxlog_file16,
4441
- L: 210,
4704
+ F: __dxlog_file17,
4705
+ L: 227,
4442
4706
  S: this,
4443
4707
  C: (f, a) => f(...a)
4444
4708
  });
4445
- await ((_b = this._resourceLock) == null ? void 0 : _b.acquire());
4709
+ await this._resourceLock?.acquire();
4446
4710
  await this._loggingService.open();
4447
4711
  this._serviceContext = new ServiceContext(this._storage, this._networkManager, this._signalManager, this._modelFactory);
4448
4712
  this._serviceRegistry.setServices({
4449
4713
  SystemService: this._systemService,
4450
- IdentityService: new IdentityServiceImpl(this._serviceContext),
4714
+ IdentityService: new IdentityServiceImpl((params) => this._serviceContext.createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring),
4451
4715
  InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitations, (invitation) => this._serviceContext.getInvitationHandler(invitation)),
4452
4716
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
4453
4717
  SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, this._serviceContext.dataServiceSubscriptions, async () => {
@@ -4457,6 +4721,7 @@ var ClientServicesHost = class {
4457
4721
  DataService: new DataServiceImpl(this._serviceContext.dataServiceSubscriptions),
4458
4722
  NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager, this._serviceContext.signalManager),
4459
4723
  LoggingService: this._loggingService,
4724
+ TracingService: this._tracingService,
4460
4725
  // TODO(burdon): Move to new protobuf definitions.
4461
4726
  DevtoolsHost: new DevtoolsServiceImpl({
4462
4727
  events: new DevtoolsHostEvents(),
@@ -4464,39 +4729,38 @@ var ClientServicesHost = class {
4464
4729
  context: this._serviceContext
4465
4730
  })
4466
4731
  });
4467
- await this._serviceContext.open();
4732
+ await this._serviceContext.open(ctx);
4468
4733
  this._opening = false;
4469
4734
  this._open = true;
4470
4735
  this._statusUpdate.emit();
4471
- const deviceKey = (_c = this._serviceContext.identityManager.identity) == null ? void 0 : _c.deviceKey;
4472
- log15("opened", {
4736
+ const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
4737
+ log16("opened", {
4473
4738
  deviceKey
4474
4739
  }, {
4475
- F: __dxlog_file16,
4476
- L: 265,
4740
+ F: __dxlog_file17,
4741
+ L: 284,
4477
4742
  S: this,
4478
4743
  C: (f, a) => f(...a)
4479
4744
  });
4480
- log15.trace("dxos.sdk.client-services-host.open", trace6.end({
4745
+ log16.trace("dxos.client-services.host.open", trace7.end({
4481
4746
  id: traceId
4482
4747
  }), {
4483
- F: __dxlog_file16,
4484
- L: 266,
4748
+ F: __dxlog_file17,
4749
+ L: 285,
4485
4750
  S: this,
4486
4751
  C: (f, a) => f(...a)
4487
4752
  });
4488
4753
  }
4489
4754
  async close() {
4490
- var _a;
4491
4755
  if (!this._open) {
4492
4756
  return;
4493
4757
  }
4494
- const deviceKey = (_a = this._serviceContext.identityManager.identity) == null ? void 0 : _a.deviceKey;
4495
- log15("closing...", {
4758
+ const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
4759
+ log16("closing...", {
4496
4760
  deviceKey
4497
4761
  }, {
4498
- F: __dxlog_file16,
4499
- L: 276,
4762
+ F: __dxlog_file17,
4763
+ L: 296,
4500
4764
  S: this,
4501
4765
  C: (f, a) => f(...a)
4502
4766
  });
@@ -4507,57 +4771,67 @@ var ClientServicesHost = class {
4507
4771
  await this._serviceContext.close();
4508
4772
  this._open = false;
4509
4773
  this._statusUpdate.emit();
4510
- log15("closed", {
4774
+ log16("closed", {
4511
4775
  deviceKey
4512
4776
  }, {
4513
- F: __dxlog_file16,
4514
- L: 282,
4777
+ F: __dxlog_file17,
4778
+ L: 302,
4515
4779
  S: this,
4516
4780
  C: (f, a) => f(...a)
4517
4781
  });
4518
4782
  }
4519
4783
  async reset() {
4520
- var _a, _b, _c;
4521
4784
  const traceId = PublicKey10.random().toHex();
4522
- log15.trace("dxos.sdk.client-services-host.reset", trace6.begin({
4785
+ log16.trace("dxos.sdk.client-services-host.reset", trace7.begin({
4523
4786
  id: traceId
4524
4787
  }), {
4525
- F: __dxlog_file16,
4526
- L: 287,
4788
+ F: __dxlog_file17,
4789
+ L: 307,
4527
4790
  S: this,
4528
4791
  C: (f, a) => f(...a)
4529
4792
  });
4530
- log15("resetting...", void 0, {
4531
- F: __dxlog_file16,
4532
- L: 289,
4793
+ log16("resetting...", void 0, {
4794
+ F: __dxlog_file17,
4795
+ L: 309,
4533
4796
  S: this,
4534
4797
  C: (f, a) => f(...a)
4535
4798
  });
4536
- await ((_a = this._serviceContext) == null ? void 0 : _a.close());
4799
+ await this._serviceContext?.close();
4537
4800
  await this._storage.reset();
4538
- log15("reset", void 0, {
4539
- F: __dxlog_file16,
4540
- L: 292,
4801
+ log16("reset", void 0, {
4802
+ F: __dxlog_file17,
4803
+ L: 312,
4541
4804
  S: this,
4542
4805
  C: (f, a) => f(...a)
4543
4806
  });
4544
- log15.trace("dxos.sdk.client-services-host.reset", trace6.end({
4807
+ log16.trace("dxos.sdk.client-services-host.reset", trace7.end({
4545
4808
  id: traceId
4546
4809
  }), {
4547
- F: __dxlog_file16,
4548
- L: 293,
4810
+ F: __dxlog_file17,
4811
+ L: 313,
4549
4812
  S: this,
4550
4813
  C: (f, a) => f(...a)
4551
4814
  });
4552
- await ((_c = (_b = this._callbacks) == null ? void 0 : _b.onReset) == null ? void 0 : _c.call(_b));
4815
+ await this._callbacks?.onReset?.();
4553
4816
  }
4554
4817
  };
4555
- _ts_decorate4([
4556
- 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()
4557
4827
  ], ClientServicesHost.prototype, "open", null);
4558
- _ts_decorate4([
4559
- synchronized3
4828
+ _ts_decorate7([
4829
+ synchronized3,
4830
+ Trace3.span()
4560
4831
  ], ClientServicesHost.prototype, "close", null);
4832
+ ClientServicesHost = _ts_decorate7([
4833
+ Trace3.resource()
4834
+ ], ClientServicesHost);
4561
4835
 
4562
4836
  export {
4563
4837
  subscribeToFeeds,
@@ -4580,6 +4854,7 @@ export {
4580
4854
  InvitationsServiceImpl,
4581
4855
  SpaceInvitationProtocol,
4582
4856
  ClientRpcServer,
4857
+ createDiagnostics,
4583
4858
  DataSpace,
4584
4859
  DataSpaceManager,
4585
4860
  SpacesServiceImpl,
@@ -4591,4 +4866,4 @@ export {
4591
4866
  createDefaultModelFactory,
4592
4867
  ClientServicesHost
4593
4868
  };
4594
- //# sourceMappingURL=chunk-FD4L7N4K.mjs.map
4869
+ //# sourceMappingURL=chunk-E7EKG5QQ.mjs.map