@dxos/client-services 0.1.56-main.b3438d9 → 0.1.56-main.b78d3e3

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 (61) hide show
  1. package/dist/lib/browser/{chunk-TPF4SOZO.mjs → chunk-KIT7RSH3.mjs} +481 -420
  2. package/dist/lib/browser/chunk-KIT7RSH3.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +21 -24
  4. package/dist/lib/browser/index.mjs.map +3 -3
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +31 -46
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/index.cjs +497 -432
  9. package/dist/lib/node/index.cjs.map +3 -3
  10. package/dist/lib/node/meta.json +1 -1
  11. package/dist/lib/node/packlets/testing/index.cjs +496 -439
  12. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  13. package/dist/types/src/packlets/identity/identity-manager.d.ts +7 -1
  14. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  15. package/dist/types/src/packlets/identity/identity-service.d.ts +7 -3
  16. package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
  17. package/dist/types/src/packlets/identity/identity.d.ts +3 -2
  18. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  19. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  20. package/dist/types/src/packlets/services/client-rpc-server.d.ts.map +1 -1
  21. package/dist/types/src/packlets/services/diagnostics.d.ts.map +1 -1
  22. package/dist/types/src/packlets/services/platform.d.ts +3 -2
  23. package/dist/types/src/packlets/services/platform.d.ts.map +1 -1
  24. package/dist/types/src/packlets/services/service-context.d.ts +2 -1
  25. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  26. package/dist/types/src/packlets/services/service-host.d.ts +3 -1
  27. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  28. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  29. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  30. package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts.map +1 -1
  31. package/dist/types/src/packlets/vault/worker-runtime.d.ts.map +1 -1
  32. package/dist/types/src/version.d.ts +1 -1
  33. package/package.json +34 -33
  34. package/src/packlets/devices/devices-service.test.ts +2 -1
  35. package/src/packlets/identity/identity-manager.test.ts +15 -3
  36. package/src/packlets/identity/identity-manager.ts +27 -6
  37. package/src/packlets/identity/identity-service.test.ts +17 -2
  38. package/src/packlets/identity/identity-service.ts +23 -14
  39. package/src/packlets/identity/identity.test.ts +7 -6
  40. package/src/packlets/identity/identity.ts +8 -3
  41. package/src/packlets/invitations/device-invitation-protocol.test.ts +2 -1
  42. package/src/packlets/invitations/invitations-handler.ts +2 -0
  43. package/src/packlets/network/network-service.test.ts +2 -1
  44. package/src/packlets/services/client-rpc-server.ts +4 -4
  45. package/src/packlets/services/diagnostics.ts +2 -1
  46. package/src/packlets/services/platform.ts +23 -21
  47. package/src/packlets/services/service-context.test.ts +59 -0
  48. package/src/packlets/services/service-context.ts +18 -10
  49. package/src/packlets/services/service-host.test.ts +7 -6
  50. package/src/packlets/services/service-host.ts +26 -13
  51. package/src/packlets/services/service-registry.test.ts +2 -1
  52. package/src/packlets/spaces/data-space-manager.test.ts +80 -22
  53. package/src/packlets/spaces/data-space-manager.ts +5 -1
  54. package/src/packlets/spaces/data-space.ts +17 -5
  55. package/src/packlets/spaces/spaces-service.test.ts +2 -1
  56. package/src/packlets/spaces/spaces-service.ts +1 -1
  57. package/src/packlets/testing/test-builder.ts +1 -1
  58. package/src/packlets/vault/iframe-host-runtime.ts +2 -1
  59. package/src/packlets/vault/worker-runtime.ts +3 -2
  60. package/src/version.ts +1 -1
  61. package/dist/lib/browser/chunk-TPF4SOZO.mjs.map +0 -7
@@ -1,11 +1,4 @@
1
1
  import "@dxos/node-std/globals";
2
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
- }) : x)(function(x) {
5
- if (typeof require !== "undefined")
6
- return require.apply(this, arguments);
7
- throw new Error('Dynamic require of "' + x + '" is not supported');
8
- });
9
2
 
10
3
  // packages/sdk/client-services/src/packlets/devtools/feeds.ts
11
4
  import { EventSubscriptions } from "@dxos/async";
@@ -19,7 +12,7 @@ var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
19
12
  const feedMap = new ComplexMap(PublicKey.hash);
20
13
  const update = () => {
21
14
  const { feeds } = feedStore;
22
- 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) => {
23
16
  if (!feedMap.has(feed.key)) {
24
17
  feedMap.set(feed.key, feed);
25
18
  feed.on("close", update);
@@ -27,15 +20,12 @@ var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
27
20
  }
28
21
  });
29
22
  next({
30
- feeds: Array.from(feedMap.values()).map((feed) => {
31
- var _a, _b;
32
- return {
33
- feedKey: feed.key,
34
- length: feed.properties.length,
35
- bytes: feed.core.byteLength,
36
- downloaded: (_b = (_a = feed.core.bitfield) == null ? void 0 : _a.data.toBuffer()) != null ? _b : new Uint8Array()
37
- };
38
- })
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
+ }))
39
29
  });
40
30
  };
41
31
  subscriptions.add(feedStore.feedOpened.on(update));
@@ -111,13 +101,13 @@ var subscribeToSignal = ({ signalManager }) => new Stream2(({ next }) => {
111
101
  recipient: message.recipient.asUint8Array(),
112
102
  payload: message.payload
113
103
  },
114
- receivedAt: new Date()
104
+ receivedAt: /* @__PURE__ */ new Date()
115
105
  });
116
106
  });
117
107
  signalManager.swarmEvent.on(ctx, (swarmEvent) => {
118
108
  next({
119
109
  swarmEvent: swarmEvent.swarmEvent,
120
- receivedAt: new Date()
110
+ receivedAt: /* @__PURE__ */ new Date()
121
111
  });
122
112
  });
123
113
  return () => {
@@ -128,13 +118,10 @@ var subscribeToNetworkTopics = ({ networkManager }) => new Stream2(({ next, clos
128
118
  const update = () => {
129
119
  try {
130
120
  const topics = networkManager.topics;
131
- const labeledTopics = topics.map((topic) => {
132
- var _a, _b;
133
- return {
134
- topic,
135
- label: (_b = (_a = networkManager.getSwarm(topic)) == null ? void 0 : _a.label) != null ? _b : topic.toHex()
136
- };
137
- });
121
+ const labeledTopics = topics.map((topic) => ({
122
+ topic,
123
+ label: networkManager.getSwarm(topic)?.label ?? topic.toHex()
124
+ }));
138
125
  next({
139
126
  topics: labeledTopics
140
127
  });
@@ -146,17 +133,15 @@ var subscribeToNetworkTopics = ({ networkManager }) => new Stream2(({ next, clos
146
133
  update();
147
134
  });
148
135
  var subscribeToSwarmInfo = ({ networkManager }) => new Stream2(({ next }) => {
149
- var _a;
150
136
  const update = () => {
151
- var _a2;
152
- const info = (_a2 = networkManager.connectionLog) == null ? void 0 : _a2.swarms;
137
+ const info = networkManager.connectionLog?.swarms;
153
138
  if (info) {
154
139
  next({
155
140
  data: info
156
141
  });
157
142
  }
158
143
  };
159
- (_a = networkManager.connectionLog) == null ? void 0 : _a.update.on(update);
144
+ networkManager.connectionLog?.update.on(update);
160
145
  update();
161
146
  });
162
147
  var getNetworkPeers = ({ networkManager }, request) => {
@@ -165,7 +150,7 @@ var getNetworkPeers = ({ networkManager }, request) => {
165
150
  }
166
151
  const map = networkManager.getSwarmMap(PublicKey2.from(request.topic));
167
152
  return {
168
- peers: map == null ? void 0 : map.peers.map((peer) => ({
153
+ peers: map?.peers.map((peer) => ({
169
154
  ...peer,
170
155
  connections: peer.connections.map((connection) => connection.asUint8Array())
171
156
  }))
@@ -181,14 +166,14 @@ var subscribeToSpaces = (context, { spaceKeys = [] }) => {
181
166
  const spaces = [
182
167
  ...context.spaceManager.spaces.values()
183
168
  ];
184
- 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)));
185
170
  next({
186
171
  spaces: filteredSpaces.map((space) => {
187
172
  const spaceMetadata = context.metadataStore.spaces.find((spaceMetadata2) => spaceMetadata2.key.equals(space.key));
188
173
  return {
189
174
  key: space.key,
190
175
  isOpen: space.isOpen,
191
- timeframe: spaceMetadata == null ? void 0 : spaceMetadata.dataTimeframe,
176
+ timeframe: spaceMetadata?.dataTimeframe,
192
177
  genesisFeed: space.genesisFeedKey,
193
178
  controlFeed: space.controlFeedKey,
194
179
  dataFeed: space.dataFeedKey
@@ -202,7 +187,7 @@ var subscribeToSpaces = (context, { spaceKeys = [] }) => {
202
187
  await update();
203
188
  });
204
189
  return () => {
205
- unsubscribe == null ? void 0 : unsubscribe();
190
+ unsubscribe?.();
206
191
  clearTimeout(timeout);
207
192
  };
208
193
  });
@@ -261,16 +246,15 @@ var DevtoolsServiceImpl = class {
261
246
  };
262
247
  }
263
248
  async getStorageInfo() {
264
- var _a, _b, _c, _d, _e;
265
- 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?.() ?? {
266
250
  used: 0
267
251
  };
268
252
  const navigatorInfo = typeof navigator === "object" ? await navigator.storage.estimate() : void 0;
269
253
  return {
270
254
  type: this.params.context.storage.type,
271
255
  storageUsage: storageUsage.used,
272
- originUsage: (_d = navigatorInfo == null ? void 0 : navigatorInfo.usage) != null ? _d : 0,
273
- usageQuota: (_e = navigatorInfo == null ? void 0 : navigatorInfo.quota) != null ? _e : 0
256
+ originUsage: navigatorInfo?.usage ?? 0,
257
+ usageQuota: navigatorInfo?.quota ?? 0
274
258
  };
275
259
  }
276
260
  async getBlobs() {
@@ -456,7 +440,7 @@ var TrustedKeySetAuthVerifier = class {
456
440
  return await trigger.wait({
457
441
  timeout: this._params.authTimeout
458
442
  });
459
- } catch (e) {
443
+ } catch {
460
444
  return false;
461
445
  } finally {
462
446
  clear();
@@ -478,8 +462,19 @@ import { writeMessages } from "@dxos/feed-store";
478
462
  import { invariant } from "@dxos/invariant";
479
463
  import { log as log2 } from "@dxos/log";
480
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
+ }
481
476
  var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity.ts";
482
- var Identity = class {
477
+ var Identity = class Identity2 {
483
478
  constructor({ space, signer, identityKey, deviceKey }) {
484
479
  this.stateUpdate = new Event();
485
480
  this.space = space;
@@ -505,12 +500,12 @@ var Identity = class {
505
500
  get authorizedDeviceKeys() {
506
501
  return this._deviceStateMachine.authorizedDeviceKeys;
507
502
  }
508
- async open() {
503
+ async open(ctx) {
509
504
  await this.space.spaceState.addCredentialProcessor(this._deviceStateMachine);
510
505
  await this.space.spaceState.addCredentialProcessor(this._profileStateMachine);
511
- await this.space.open();
506
+ await this.space.open(ctx);
512
507
  }
513
- async close() {
508
+ async close(ctx) {
514
509
  await this.authVerifier.close();
515
510
  await this.space.spaceState.removeCredentialProcessor(this._profileStateMachine);
516
511
  await this.space.spaceState.removeCredentialProcessor(this._deviceStateMachine);
@@ -541,11 +536,10 @@ var Identity = class {
541
536
  return this._deviceStateMachine.deviceCredentialChain;
542
537
  }
543
538
  getAdmissionCredentials() {
544
- var _a, _b;
545
539
  return {
546
540
  deviceKey: this.deviceKey,
547
- controlFeedKey: (_a = this.space.controlFeedKey) != null ? _a : failUndefined(),
548
- dataFeedKey: (_b = this.space.dataFeedKey) != null ? _b : failUndefined()
541
+ controlFeedKey: this.space.controlFeedKey ?? failUndefined(),
542
+ dataFeedKey: this.space.dataFeedKey ?? failUndefined()
549
543
  };
550
544
  }
551
545
  /**
@@ -555,7 +549,7 @@ var Identity = class {
555
549
  getIdentityCredentialSigner() {
556
550
  invariant(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.", {
557
551
  F: __dxlog_file2,
558
- L: 134,
552
+ L: 139,
559
553
  S: this,
560
554
  A: [
561
555
  "this._deviceStateMachine.deviceCredentialChain",
@@ -579,7 +573,7 @@ var Identity = class {
579
573
  dataFeedKey
580
574
  }, {
581
575
  F: __dxlog_file2,
582
- L: 150,
576
+ L: 155,
583
577
  S: this,
584
578
  C: (f, a) => f(...a)
585
579
  });
@@ -620,18 +614,40 @@ var Identity = class {
620
614
  })));
621
615
  }
622
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);
623
626
 
624
627
  // packages/sdk/client-services/src/packlets/identity/identity-manager.ts
625
628
  import { Event as Event2 } from "@dxos/async";
629
+ import { Context as Context3 } from "@dxos/context";
626
630
  import { createCredentialSignerWithKey as createCredentialSignerWithKey2, CredentialGenerator } from "@dxos/credentials";
627
631
  import { invariant as invariant2 } from "@dxos/invariant";
628
632
  import { PublicKey as PublicKey3 } from "@dxos/keys";
629
633
  import { log as log3 } from "@dxos/log";
630
- import { trace } from "@dxos/protocols";
634
+ import { trace as trace2 } from "@dxos/protocols";
631
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";
632
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
+ }
633
649
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-manager.ts";
634
- var IdentityManager = class {
650
+ var IdentityManager = class IdentityManager2 {
635
651
  // TODO(burdon): IdentityManagerParams.
636
652
  // TODO(dmaretskyi): Perhaps this should take/generate the peerKey outside of an initialized identity.
637
653
  constructor(_metadataStore, _keyring, _feedStore, _spaceManager) {
@@ -644,14 +660,13 @@ var IdentityManager = class {
644
660
  get identity() {
645
661
  return this._identity;
646
662
  }
647
- async open() {
648
- var _a;
663
+ async open(ctx) {
649
664
  const traceId = PublicKey3.random().toHex();
650
- log3.trace("dxos.halo.identity-manager.open", trace.begin({
665
+ log3.trace("dxos.halo.identity-manager.open", trace2.begin({
651
666
  id: traceId
652
667
  }), {
653
668
  F: __dxlog_file3,
654
- L: 69,
669
+ L: 73,
655
670
  S: this,
656
671
  C: (f, a) => f(...a)
657
672
  });
@@ -661,43 +676,41 @@ var IdentityManager = class {
661
676
  identityRecord
662
677
  }, {
663
678
  F: __dxlog_file3,
664
- L: 73,
679
+ L: 77,
665
680
  S: this,
666
681
  C: (f, a) => f(...a)
667
682
  });
668
683
  if (identityRecord) {
669
684
  this._identity = await this._constructIdentity(identityRecord);
670
- await this._identity.open();
685
+ await this._identity.open(ctx);
671
686
  await this._identity.ready();
672
687
  log3.trace("dxos.halo.identity", {
673
688
  identityKey: identityRecord.identityKey,
674
- displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
689
+ displayName: this._identity.profileDocument?.displayName
675
690
  }, {
676
691
  F: __dxlog_file3,
677
- L: 78,
692
+ L: 82,
678
693
  S: this,
679
694
  C: (f, a) => f(...a)
680
695
  });
681
696
  this.stateUpdate.emit();
682
697
  }
683
- log3.trace("dxos.halo.identity-manager.open", trace.end({
698
+ log3.trace("dxos.halo.identity-manager.open", trace2.end({
684
699
  id: traceId
685
700
  }), {
686
701
  F: __dxlog_file3,
687
- L: 84,
702
+ L: 88,
688
703
  S: this,
689
704
  C: (f, a) => f(...a)
690
705
  });
691
706
  }
692
707
  async close() {
693
- var _a;
694
- await ((_a = this._identity) == null ? void 0 : _a.close());
708
+ await this._identity?.close(new Context3());
695
709
  }
696
710
  async createIdentity({ displayName } = {}) {
697
- var _a;
698
711
  invariant2(!this._identity, "Identity already exists.", {
699
712
  F: __dxlog_file3,
700
- L: 92,
713
+ L: 96,
701
714
  S: this,
702
715
  A: [
703
716
  "!this._identity",
@@ -706,7 +719,7 @@ var IdentityManager = class {
706
719
  });
707
720
  log3("creating identity...", void 0, {
708
721
  F: __dxlog_file3,
709
- L: 93,
722
+ L: 97,
710
723
  S: this,
711
724
  C: (f, a) => f(...a)
712
725
  });
@@ -722,12 +735,12 @@ var IdentityManager = class {
722
735
  }
723
736
  };
724
737
  const identity = await this._constructIdentity(identityRecord);
725
- await identity.open();
738
+ await identity.open(new Context3());
726
739
  {
727
740
  const generator = new CredentialGenerator(this._keyring, identityRecord.identityKey, identityRecord.deviceKey);
728
741
  invariant2(identityRecord.haloSpace.genesisFeedKey, "Genesis feed key is required.", {
729
742
  F: __dxlog_file3,
730
- L: 112,
743
+ L: 116,
731
744
  S: this,
732
745
  A: [
733
746
  "identityRecord.haloSpace.genesisFeedKey",
@@ -736,7 +749,7 @@ var IdentityManager = class {
736
749
  });
737
750
  invariant2(identityRecord.haloSpace.dataFeedKey, "Data feed key is required.", {
738
751
  F: __dxlog_file3,
739
- L: 113,
752
+ L: 117,
740
753
  S: this,
741
754
  A: [
742
755
  "identityRecord.haloSpace.dataFeedKey",
@@ -768,10 +781,10 @@ var IdentityManager = class {
768
781
  await this._identity.ready();
769
782
  log3.trace("dxos.halo.identity", {
770
783
  identityKey: identityRecord.identityKey,
771
- displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
784
+ displayName: this._identity.profileDocument?.displayName
772
785
  }, {
773
786
  F: __dxlog_file3,
774
- L: 148,
787
+ L: 152,
775
788
  S: this,
776
789
  C: (f, a) => f(...a)
777
790
  });
@@ -781,7 +794,7 @@ var IdentityManager = class {
781
794
  deviceKey: identity.deviceKey
782
795
  }, {
783
796
  F: __dxlog_file3,
784
- L: 154,
797
+ L: 158,
785
798
  S: this,
786
799
  C: (f, a) => f(...a)
787
800
  });
@@ -791,18 +804,17 @@ var IdentityManager = class {
791
804
  * Accept an existing identity. Expects it's device key to be authorized (now or later).
792
805
  */
793
806
  async acceptIdentity(params) {
794
- var _a;
795
807
  log3("accepting identity", {
796
808
  params
797
809
  }, {
798
810
  F: __dxlog_file3,
799
- L: 162,
811
+ L: 166,
800
812
  S: this,
801
813
  C: (f, a) => f(...a)
802
814
  });
803
815
  invariant2(!this._identity, "Identity already exists.", {
804
816
  F: __dxlog_file3,
805
- L: 163,
817
+ L: 167,
806
818
  S: this,
807
819
  A: [
808
820
  "!this._identity",
@@ -821,16 +833,16 @@ var IdentityManager = class {
821
833
  }
822
834
  };
823
835
  const identity = await this._constructIdentity(identityRecord);
824
- await identity.open();
836
+ await identity.open(new Context3());
825
837
  this._identity = identity;
826
838
  await this._metadataStore.setIdentityRecord(identityRecord);
827
839
  await this._identity.ready();
828
840
  log3.trace("dxos.halo.identity", {
829
841
  identityKey: identityRecord.identityKey,
830
- displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
842
+ displayName: this._identity.profileDocument?.displayName
831
843
  }, {
832
844
  F: __dxlog_file3,
833
- L: 182,
845
+ L: 186,
834
846
  S: this,
835
847
  C: (f, a) => f(...a)
836
848
  });
@@ -840,16 +852,48 @@ var IdentityManager = class {
840
852
  deviceKey: identity.deviceKey
841
853
  }, {
842
854
  F: __dxlog_file3,
843
- L: 188,
855
+ L: 192,
844
856
  S: this,
845
857
  C: (f, a) => f(...a)
846
858
  });
847
859
  return identity;
848
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
+ }
849
893
  async _constructIdentity(identityRecord) {
850
894
  invariant2(!this._identity, void 0, {
851
895
  F: __dxlog_file3,
852
- L: 193,
896
+ L: 214,
853
897
  S: this,
854
898
  A: [
855
899
  "!this._identity",
@@ -860,13 +904,13 @@ var IdentityManager = class {
860
904
  identityRecord
861
905
  }, {
862
906
  F: __dxlog_file3,
863
- L: 194,
907
+ L: 215,
864
908
  S: this,
865
909
  C: (f, a) => f(...a)
866
910
  });
867
911
  invariant2(identityRecord.haloSpace.controlFeedKey, void 0, {
868
912
  F: __dxlog_file3,
869
- L: 197,
913
+ L: 218,
870
914
  S: this,
871
915
  A: [
872
916
  "identityRecord.haloSpace.controlFeedKey",
@@ -878,7 +922,7 @@ var IdentityManager = class {
878
922
  });
879
923
  invariant2(identityRecord.haloSpace.dataFeedKey, void 0, {
880
924
  F: __dxlog_file3,
881
- L: 201,
925
+ L: 222,
882
926
  S: this,
883
927
  A: [
884
928
  "identityRecord.haloSpace.dataFeedKey",
@@ -910,7 +954,7 @@ var IdentityManager = class {
910
954
  identityKey: identityRecord.identityKey
911
955
  }, {
912
956
  F: __dxlog_file3,
913
- L: 225,
957
+ L: 246,
914
958
  S: this,
915
959
  C: (f, a) => f(...a)
916
960
  });
@@ -931,7 +975,7 @@ var IdentityManager = class {
931
975
  onAuthFailure: () => {
932
976
  log3.warn("auth failure", void 0, {
933
977
  F: __dxlog_file3,
934
- L: 244,
978
+ L: 265,
935
979
  S: this,
936
980
  C: (f, a) => f(...a)
937
981
  });
@@ -940,6 +984,12 @@ var IdentityManager = class {
940
984
  });
941
985
  }
942
986
  };
987
+ _ts_decorate2([
988
+ Trace.span()
989
+ ], IdentityManager.prototype, "open", null);
990
+ IdentityManager = _ts_decorate2([
991
+ Trace.resource()
992
+ ], IdentityManager);
943
993
 
944
994
  // packages/sdk/client-services/src/packlets/identity/identity-service.ts
945
995
  import { Stream as Stream7 } from "@dxos/codec-protobuf";
@@ -948,12 +998,13 @@ import { todo } from "@dxos/debug";
948
998
  import { invariant as invariant3 } from "@dxos/invariant";
949
999
  var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
950
1000
  var IdentityServiceImpl = class {
951
- // TODO(wittjosiah): Remove dependency on service context.
952
- constructor(_serviceContext) {
953
- this._serviceContext = _serviceContext;
1001
+ constructor(_createIdentity, _identityManager, _keyring) {
1002
+ this._createIdentity = _createIdentity;
1003
+ this._identityManager = _identityManager;
1004
+ this._keyring = _keyring;
954
1005
  }
955
1006
  async createIdentity(request) {
956
- await this._serviceContext.createIdentity(request);
1007
+ await this._createIdentity(request);
957
1008
  return this._getIdentity();
958
1009
  }
959
1010
  async recoverIdentity(request) {
@@ -965,34 +1016,47 @@ var IdentityServiceImpl = class {
965
1016
  identity: this._getIdentity()
966
1017
  });
967
1018
  emitNext();
968
- return this._serviceContext.identityManager.stateUpdate.on(emitNext);
1019
+ return this._identityManager.stateUpdate.on(emitNext);
969
1020
  });
970
1021
  }
971
1022
  _getIdentity() {
972
- if (!this._serviceContext.identityManager.identity) {
1023
+ if (!this._identityManager.identity) {
973
1024
  return void 0;
974
1025
  }
975
1026
  return {
976
- identityKey: this._serviceContext.identityManager.identity.identityKey,
977
- spaceKey: this._serviceContext.identityManager.identity.space.key,
978
- 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
979
1030
  };
980
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
+ }
981
1045
  async signPresentation({ presentation, nonce }) {
982
- invariant3(this._serviceContext.identityManager.identity, "Identity not initialized.", {
1046
+ invariant3(this._identityManager.identity, "Identity not initialized.", {
983
1047
  F: __dxlog_file4,
984
- L: 56,
1048
+ L: 65,
985
1049
  S: this,
986
1050
  A: [
987
- "this._serviceContext.identityManager.identity",
1051
+ "this._identityManager.identity",
988
1052
  "'Identity not initialized.'"
989
1053
  ]
990
1054
  });
991
1055
  return await signPresentation({
992
1056
  presentation,
993
- signer: this._serviceContext.keyring,
994
- signerKey: this._serviceContext.identityManager.identity.deviceKey,
995
- chain: this._serviceContext.identityManager.identity.deviceCredentialChain,
1057
+ signer: this._keyring,
1058
+ signerKey: this._identityManager.identity.deviceKey,
1059
+ chain: this._identityManager.identity.deviceCredentialChain,
996
1060
  nonce
997
1061
  });
998
1062
  }
@@ -1091,25 +1155,25 @@ var DeviceInvitationProtocol = class {
1091
1155
  // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
1092
1156
  import { PushStream, scheduleTask as scheduleTask2, TimeoutError, Trigger as Trigger3 } from "@dxos/async";
1093
1157
  import { AuthenticatingInvitationObservable, AUTHENTICATION_CODE_LENGTH, CancellableInvitationObservable, INVITATION_TIMEOUT } from "@dxos/client-protocol";
1094
- import { Context as Context4 } from "@dxos/context";
1158
+ import { Context as Context5 } from "@dxos/context";
1095
1159
  import { generatePasscode } from "@dxos/credentials";
1096
1160
  import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError2 } from "@dxos/errors";
1097
1161
  import { invariant as invariant6 } from "@dxos/invariant";
1098
1162
  import { PublicKey as PublicKey5 } from "@dxos/keys";
1099
1163
  import { log as log5 } from "@dxos/log";
1100
1164
  import { createTeleportProtocolFactory, StarTopology } from "@dxos/network-manager";
1101
- import { trace as trace3 } from "@dxos/protocols";
1165
+ import { trace as trace4 } from "@dxos/protocols";
1102
1166
  import { Invitation as Invitation3 } from "@dxos/protocols/proto/dxos/client/services";
1103
1167
  import { AuthenticationResponse as AuthenticationResponse2 } from "@dxos/protocols/proto/dxos/halo/invitations";
1104
1168
 
1105
1169
  // packages/sdk/client-services/src/packlets/invitations/invitation-extension.ts
1106
1170
  import { Trigger as Trigger2 } from "@dxos/async";
1107
- import { cancelWithContext, Context as Context3 } from "@dxos/context";
1171
+ import { cancelWithContext, Context as Context4 } from "@dxos/context";
1108
1172
  import { InvalidInvitationExtensionRoleError } from "@dxos/errors";
1109
1173
  import { invariant as invariant5 } from "@dxos/invariant";
1110
1174
  import { PublicKey as PublicKey4 } from "@dxos/keys";
1111
1175
  import { log as log4 } from "@dxos/log";
1112
- import { schema as schema2, trace as trace2 } from "@dxos/protocols";
1176
+ import { schema as schema2, trace as trace3 } from "@dxos/protocols";
1113
1177
  import { Invitation as Invitation2 } from "@dxos/protocols/proto/dxos/client/services";
1114
1178
  import { AuthenticationResponse, Options } from "@dxos/protocols/proto/dxos/halo/invitations";
1115
1179
  import { RpcExtension } from "@dxos/teleport";
@@ -1127,7 +1191,7 @@ var InvitationHostExtension = class extends RpcExtension {
1127
1191
  }
1128
1192
  });
1129
1193
  this._callbacks = _callbacks;
1130
- this._ctx = new Context3();
1194
+ this._ctx = new Context4();
1131
1195
  this._remoteOptionsTrigger = new Trigger2();
1132
1196
  this.invitation = void 0;
1133
1197
  this.guestProfile = void 0;
@@ -1156,7 +1220,7 @@ var InvitationHostExtension = class extends RpcExtension {
1156
1220
  introduce: async (request) => {
1157
1221
  const { profile, invitationId } = request;
1158
1222
  const traceId = PublicKey4.random().toHex();
1159
- log4.trace("dxos.sdk.invitation-handler.host.introduce", trace2.begin({
1223
+ log4.trace("dxos.sdk.invitation-handler.host.introduce", trace3.begin({
1160
1224
  id: traceId
1161
1225
  }), {
1162
1226
  F: __dxlog_file6,
@@ -1193,7 +1257,7 @@ var InvitationHostExtension = class extends RpcExtension {
1193
1257
  ...this.invitation,
1194
1258
  state: Invitation2.State.READY_FOR_AUTHENTICATION
1195
1259
  });
1196
- log4.trace("dxos.sdk.invitation-handler.host.introduce", trace2.end({
1260
+ log4.trace("dxos.sdk.invitation-handler.host.introduce", trace3.end({
1197
1261
  id: traceId
1198
1262
  }), {
1199
1263
  F: __dxlog_file6,
@@ -1208,7 +1272,7 @@ var InvitationHostExtension = class extends RpcExtension {
1208
1272
  },
1209
1273
  authenticate: async ({ authCode: code }) => {
1210
1274
  const traceId = PublicKey4.random().toHex();
1211
- log4.trace("dxos.sdk.invitation-handler.host.authenticate", trace2.begin({
1275
+ log4.trace("dxos.sdk.invitation-handler.host.authenticate", trace3.begin({
1212
1276
  id: traceId
1213
1277
  }), {
1214
1278
  F: __dxlog_file6,
@@ -1271,7 +1335,7 @@ var InvitationHostExtension = class extends RpcExtension {
1271
1335
  break;
1272
1336
  }
1273
1337
  }
1274
- log4.trace("dxos.sdk.invitation-handler.host.authenticate", trace2.end({
1338
+ log4.trace("dxos.sdk.invitation-handler.host.authenticate", trace3.end({
1275
1339
  id: traceId,
1276
1340
  data: {
1277
1341
  status
@@ -1288,7 +1352,7 @@ var InvitationHostExtension = class extends RpcExtension {
1288
1352
  },
1289
1353
  admit: async (request) => {
1290
1354
  const traceId = PublicKey4.random().toHex();
1291
- log4.trace("dxos.sdk.invitation-handler.host.admit", trace2.begin({
1355
+ log4.trace("dxos.sdk.invitation-handler.host.admit", trace3.begin({
1292
1356
  id: traceId
1293
1357
  }), {
1294
1358
  F: __dxlog_file6,
@@ -1310,7 +1374,7 @@ var InvitationHostExtension = class extends RpcExtension {
1310
1374
  throw new Error("Not authenticated");
1311
1375
  }
1312
1376
  const response = await this._callbacks.admit(request);
1313
- log4.trace("dxos.sdk.invitation-handler.host.admit", trace2.end({
1377
+ log4.trace("dxos.sdk.invitation-handler.host.admit", trace3.end({
1314
1378
  id: traceId
1315
1379
  }), {
1316
1380
  F: __dxlog_file6,
@@ -1328,7 +1392,6 @@ var InvitationHostExtension = class extends RpcExtension {
1328
1392
  };
1329
1393
  }
1330
1394
  async onOpen(context) {
1331
- var _a;
1332
1395
  await super.onOpen(context);
1333
1396
  try {
1334
1397
  await this.rpc.InvitationHostService.options({
@@ -1337,7 +1400,7 @@ var InvitationHostExtension = class extends RpcExtension {
1337
1400
  await cancelWithContext(this._ctx, this._remoteOptionsTrigger.wait({
1338
1401
  timeout: OPTIONS_TIMEOUT
1339
1402
  }));
1340
- if (((_a = this._remoteOptions) == null ? void 0 : _a.role) !== Options.Role.GUEST) {
1403
+ if (this._remoteOptions?.role !== Options.Role.GUEST) {
1341
1404
  throw new InvalidInvitationExtensionRoleError(void 0, {
1342
1405
  expected: Options.Role.GUEST,
1343
1406
  remoteOptions: this._remoteOptions
@@ -1363,7 +1426,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1363
1426
  }
1364
1427
  });
1365
1428
  this._callbacks = _callbacks;
1366
- this._ctx = new Context3();
1429
+ this._ctx = new Context4();
1367
1430
  this._remoteOptionsTrigger = new Trigger2();
1368
1431
  }
1369
1432
  async getHandlers() {
@@ -1395,7 +1458,6 @@ var InvitationGuestExtension = class extends RpcExtension {
1395
1458
  };
1396
1459
  }
1397
1460
  async onOpen(context) {
1398
- var _a;
1399
1461
  await super.onOpen(context);
1400
1462
  try {
1401
1463
  log4("begin options", void 0, {
@@ -1416,7 +1478,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1416
1478
  S: this,
1417
1479
  C: (f, a) => f(...a)
1418
1480
  });
1419
- if (((_a = this._remoteOptions) == null ? void 0 : _a.role) !== Options.Role.HOST) {
1481
+ if (this._remoteOptions?.role !== Options.Role.HOST) {
1420
1482
  throw new InvalidInvitationExtensionRoleError(void 0, {
1421
1483
  expected: Options.Role.HOST,
1422
1484
  remoteOptions: this._remoteOptions
@@ -1455,9 +1517,8 @@ var InvitationsHandler = class {
1455
1517
  this._networkManager = _networkManager;
1456
1518
  }
1457
1519
  createInvitation(protocol, options) {
1458
- var _a;
1459
- 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 : {};
1460
- 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);
1461
1522
  invariant6(protocol, void 0, {
1462
1523
  F: __dxlog_file7,
1463
1524
  L: 76,
@@ -1478,7 +1539,7 @@ var InvitationsHandler = class {
1478
1539
  ...protocol.getInvitationContext()
1479
1540
  };
1480
1541
  const stream = new PushStream();
1481
- const ctx = new Context4({
1542
+ const ctx = new Context5({
1482
1543
  onError: (err) => {
1483
1544
  void ctx.dispose();
1484
1545
  stream.error(err);
@@ -1510,9 +1571,8 @@ var InvitationsHandler = class {
1510
1571
  return invitation;
1511
1572
  },
1512
1573
  admit: async (admissionRequest) => {
1513
- var _a2, _b, _c;
1514
1574
  try {
1515
- 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;
1516
1576
  invariant6(deviceKey, void 0, {
1517
1577
  F: __dxlog_file7,
1518
1578
  L: 119,
@@ -1534,7 +1594,7 @@ var InvitationsHandler = class {
1534
1594
  scheduleTask2(ctx, async () => {
1535
1595
  const traceId = PublicKey5.random().toHex();
1536
1596
  try {
1537
- log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace3.begin({
1597
+ log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace4.begin({
1538
1598
  id: traceId
1539
1599
  }), {
1540
1600
  F: __dxlog_file7,
@@ -1570,7 +1630,7 @@ var InvitationsHandler = class {
1570
1630
  ...invitation,
1571
1631
  state: Invitation3.State.SUCCESS
1572
1632
  });
1573
- log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace3.end({
1633
+ log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace4.end({
1574
1634
  id: traceId
1575
1635
  }), {
1576
1636
  F: __dxlog_file7,
@@ -1601,7 +1661,7 @@ var InvitationsHandler = class {
1601
1661
  });
1602
1662
  stream.error(err);
1603
1663
  }
1604
- log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace3.error({
1664
+ log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace4.error({
1605
1665
  id: traceId,
1606
1666
  error: err
1607
1667
  }), {
@@ -1657,7 +1717,8 @@ var InvitationsHandler = class {
1657
1717
  protocolProvider: createTeleportProtocolFactory(async (teleport) => {
1658
1718
  teleport.addExtension("dxos.halo.invitations", createExtension());
1659
1719
  }),
1660
- topology: new StarTopology(topic)
1720
+ topology: new StarTopology(topic),
1721
+ label: "invitation host"
1661
1722
  });
1662
1723
  ctx.onDispose(() => swarmConnection.close());
1663
1724
  stream.next({
@@ -1682,7 +1743,7 @@ var InvitationsHandler = class {
1682
1743
  const { timeout = INVITATION_TIMEOUT } = invitation;
1683
1744
  invariant6(protocol, void 0, {
1684
1745
  F: __dxlog_file7,
1685
- L: 210,
1746
+ L: 211,
1686
1747
  S: this,
1687
1748
  A: [
1688
1749
  "protocol",
@@ -1696,7 +1757,7 @@ var InvitationsHandler = class {
1696
1757
  const setState = (newData) => {
1697
1758
  invariant6(newData.state !== void 0, void 0, {
1698
1759
  F: __dxlog_file7,
1699
- L: 221,
1760
+ L: 222,
1700
1761
  S: this,
1701
1762
  A: [
1702
1763
  "newData.state !== undefined",
@@ -1709,14 +1770,14 @@ var InvitationsHandler = class {
1709
1770
  ...newData
1710
1771
  });
1711
1772
  };
1712
- const ctx = new Context4({
1773
+ const ctx = new Context5({
1713
1774
  onError: (err) => {
1714
1775
  if (err instanceof TimeoutError) {
1715
1776
  log5("timeout", {
1716
1777
  ...protocol.toJSON()
1717
1778
  }, {
1718
1779
  F: __dxlog_file7,
1719
- L: 229,
1780
+ L: 230,
1720
1781
  S: this,
1721
1782
  C: (f, a) => f(...a)
1722
1783
  });
@@ -1726,7 +1787,7 @@ var InvitationsHandler = class {
1726
1787
  } else {
1727
1788
  log5.warn("auth failed", err, {
1728
1789
  F: __dxlog_file7,
1729
- L: 232,
1790
+ L: 233,
1730
1791
  S: this,
1731
1792
  C: (f, a) => f(...a)
1732
1793
  });
@@ -1740,7 +1801,7 @@ var InvitationsHandler = class {
1740
1801
  ...protocol.toJSON()
1741
1802
  }, {
1742
1803
  F: __dxlog_file7,
1743
- L: 240,
1804
+ L: 241,
1744
1805
  S: this,
1745
1806
  C: (f, a) => f(...a)
1746
1807
  });
@@ -1755,7 +1816,7 @@ var InvitationsHandler = class {
1755
1816
  currentState
1756
1817
  }, {
1757
1818
  F: __dxlog_file7,
1758
- L: 250,
1819
+ L: 251,
1759
1820
  S: this,
1760
1821
  C: (f, a) => f(...a)
1761
1822
  });
@@ -1766,11 +1827,11 @@ var InvitationsHandler = class {
1766
1827
  scheduleTask2(ctx, async () => {
1767
1828
  const traceId = PublicKey5.random().toHex();
1768
1829
  try {
1769
- log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace3.begin({
1830
+ log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace4.begin({
1770
1831
  id: traceId
1771
1832
  }), {
1772
1833
  F: __dxlog_file7,
1773
- L: 259,
1834
+ L: 260,
1774
1835
  S: this,
1775
1836
  C: (f, a) => f(...a)
1776
1837
  });
@@ -1782,7 +1843,7 @@ var InvitationsHandler = class {
1782
1843
  ...protocol.toJSON()
1783
1844
  }, {
1784
1845
  F: __dxlog_file7,
1785
- L: 267,
1846
+ L: 268,
1786
1847
  S: this,
1787
1848
  C: (f, a) => f(...a)
1788
1849
  });
@@ -1793,7 +1854,7 @@ var InvitationsHandler = class {
1793
1854
  ...protocol.toJSON()
1794
1855
  }, {
1795
1856
  F: __dxlog_file7,
1796
- L: 271,
1857
+ L: 272,
1797
1858
  S: this,
1798
1859
  C: (f, a) => f(...a)
1799
1860
  });
@@ -1803,7 +1864,7 @@ var InvitationsHandler = class {
1803
1864
  response: introductionResponse
1804
1865
  }, {
1805
1866
  F: __dxlog_file7,
1806
- L: 275,
1867
+ L: 276,
1807
1868
  S: this,
1808
1869
  C: (f, a) => f(...a)
1809
1870
  });
@@ -1815,7 +1876,7 @@ var InvitationsHandler = class {
1815
1876
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
1816
1877
  log5("guest waiting for authentication code...", void 0, {
1817
1878
  F: __dxlog_file7,
1818
- L: 284,
1879
+ L: 285,
1819
1880
  S: this,
1820
1881
  C: (f, a) => f(...a)
1821
1882
  });
@@ -1827,7 +1888,7 @@ var InvitationsHandler = class {
1827
1888
  });
1828
1889
  log5("sending authentication request", void 0, {
1829
1890
  F: __dxlog_file7,
1830
- L: 288,
1891
+ L: 289,
1831
1892
  S: this,
1832
1893
  C: (f, a) => f(...a)
1833
1894
  });
@@ -1848,7 +1909,7 @@ var InvitationsHandler = class {
1848
1909
  attempt
1849
1910
  }, {
1850
1911
  F: __dxlog_file7,
1851
- L: 299,
1912
+ L: 300,
1852
1913
  S: this,
1853
1914
  C: (f, a) => f(...a)
1854
1915
  });
@@ -1865,7 +1926,7 @@ var InvitationsHandler = class {
1865
1926
  ...protocol.toJSON()
1866
1927
  }, {
1867
1928
  F: __dxlog_file7,
1868
- L: 310,
1929
+ L: 311,
1869
1930
  S: this,
1870
1931
  C: (f, a) => f(...a)
1871
1932
  });
@@ -1877,7 +1938,7 @@ var InvitationsHandler = class {
1877
1938
  ...protocol.toJSON()
1878
1939
  }, {
1879
1940
  F: __dxlog_file7,
1880
- L: 321,
1941
+ L: 322,
1881
1942
  S: this,
1882
1943
  C: (f, a) => f(...a)
1883
1944
  });
@@ -1885,11 +1946,11 @@ var InvitationsHandler = class {
1885
1946
  ...result,
1886
1947
  state: Invitation3.State.SUCCESS
1887
1948
  });
1888
- log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace3.end({
1949
+ log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace4.end({
1889
1950
  id: traceId
1890
1951
  }), {
1891
1952
  F: __dxlog_file7,
1892
- L: 323,
1953
+ L: 324,
1893
1954
  S: this,
1894
1955
  C: (f, a) => f(...a)
1895
1956
  });
@@ -1899,7 +1960,7 @@ var InvitationsHandler = class {
1899
1960
  ...protocol.toJSON()
1900
1961
  }, {
1901
1962
  F: __dxlog_file7,
1902
- L: 326,
1963
+ L: 327,
1903
1964
  S: this,
1904
1965
  C: (f, a) => f(...a)
1905
1966
  });
@@ -1909,18 +1970,18 @@ var InvitationsHandler = class {
1909
1970
  } else {
1910
1971
  log5("auth failed", err, {
1911
1972
  F: __dxlog_file7,
1912
- L: 329,
1973
+ L: 330,
1913
1974
  S: this,
1914
1975
  C: (f, a) => f(...a)
1915
1976
  });
1916
1977
  stream.error(err);
1917
1978
  }
1918
- log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace3.error({
1979
+ log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace4.error({
1919
1980
  id: traceId,
1920
1981
  error: err
1921
1982
  }), {
1922
1983
  F: __dxlog_file7,
1923
- L: 332,
1984
+ L: 333,
1924
1985
  S: this,
1925
1986
  C: (f, a) => f(...a)
1926
1987
  });
@@ -1938,7 +1999,7 @@ var InvitationsHandler = class {
1938
1999
  ...protocol.toJSON()
1939
2000
  }, {
1940
2001
  F: __dxlog_file7,
1941
- L: 343,
2002
+ L: 344,
1942
2003
  S: this,
1943
2004
  C: (f, a) => f(...a)
1944
2005
  });
@@ -1948,7 +2009,7 @@ var InvitationsHandler = class {
1948
2009
  } else {
1949
2010
  log5("auth failed", err, {
1950
2011
  F: __dxlog_file7,
1951
- L: 346,
2012
+ L: 347,
1952
2013
  S: this,
1953
2014
  C: (f, a) => f(...a)
1954
2015
  });
@@ -1961,7 +2022,7 @@ var InvitationsHandler = class {
1961
2022
  scheduleTask2(ctx, async () => {
1962
2023
  invariant6(invitation.swarmKey, void 0, {
1963
2024
  F: __dxlog_file7,
1964
- L: 356,
2025
+ L: 357,
1965
2026
  S: this,
1966
2027
  A: [
1967
2028
  "invitation.swarmKey",
@@ -1975,7 +2036,8 @@ var InvitationsHandler = class {
1975
2036
  protocolProvider: createTeleportProtocolFactory(async (teleport) => {
1976
2037
  teleport.addExtension("dxos.halo.invitations", createExtension());
1977
2038
  }),
1978
- topology: new StarTopology(topic)
2039
+ topology: new StarTopology(topic),
2040
+ label: "invitation guest"
1979
2041
  });
1980
2042
  ctx.onDispose(() => swarmConnection.close());
1981
2043
  setState({
@@ -2211,7 +2273,6 @@ var SpaceInvitationProtocol = class {
2211
2273
  };
2212
2274
  }
2213
2275
  async admit(request, guestProfile) {
2214
- var _a;
2215
2276
  invariant8(this._spaceKey, void 0, {
2216
2277
  F: __dxlog_file9,
2217
2278
  L: 42,
@@ -2275,7 +2336,7 @@ var SpaceInvitationProtocol = class {
2275
2336
  space: {
2276
2337
  credential: spaceMemberCredential,
2277
2338
  controlTimeframe: space.inner.controlPipeline.state.timeframe,
2278
- dataTimeframe: (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.timeframe
2339
+ dataTimeframe: space.dataPipeline.pipelineState?.timeframe
2279
2340
  }
2280
2341
  };
2281
2342
  }
@@ -2379,9 +2440,8 @@ var ClientRpcServer = class {
2379
2440
  await this._rpcPeer.close();
2380
2441
  }
2381
2442
  _getServiceHandler(serviceName) {
2382
- var _a;
2383
2443
  if (!this._handlerCache.has(serviceName)) {
2384
- 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}`));
2385
2445
  const service = this._serviceRegistry.services[key];
2386
2446
  if (!service) {
2387
2447
  throw new Error(`Service not available: ${serviceName}`);
@@ -2396,37 +2456,40 @@ var ClientRpcServer = class {
2396
2456
  import { getFirstStreamValue } from "@dxos/codec-protobuf";
2397
2457
  import { credentialTypeFilter } from "@dxos/credentials";
2398
2458
  import { DocumentModel } from "@dxos/document-model";
2459
+ import { TYPE_PROPERTIES } from "@dxos/echo-db";
2399
2460
  import { invariant as invariant9 } from "@dxos/invariant";
2400
2461
  import { log as log8 } from "@dxos/log";
2401
2462
  import { STORAGE_VERSION } from "@dxos/protocols";
2402
2463
  import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
2403
2464
 
2404
2465
  // packages/sdk/client-services/src/version.ts
2405
- var DXOS_VERSION = "0.1.56-main.b3438d9";
2466
+ var DXOS_VERSION = "0.1.56-main.b78d3e3";
2406
2467
 
2407
2468
  // packages/sdk/client-services/src/packlets/services/platform.ts
2408
2469
  var getPlatform = () => {
2409
- if (typeof window !== "undefined") {
2410
- const { userAgent } = window.navigator;
2411
- return {
2412
- type: "browser",
2413
- platform: userAgent
2414
- };
2415
- }
2416
- try {
2417
- const { machine, platform, release } = __require("@dxos/node-std/os");
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;
2418
2486
  return {
2419
2487
  type: "node",
2420
- platform: `${platform()} ${release()} ${machine()}`,
2488
+ platform: `${platform} ${version} ${arch}`,
2421
2489
  runtime: process.version,
2422
2490
  uptime: Math.floor(process.uptime()),
2423
2491
  memory: process.memoryUsage()
2424
2492
  };
2425
- } catch (err) {
2426
- return {
2427
- type: "node",
2428
- platform: ""
2429
- };
2430
2493
  }
2431
2494
  };
2432
2495
 
@@ -2434,9 +2497,8 @@ var getPlatform = () => {
2434
2497
  var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
2435
2498
  var DEFAULT_TIMEOUT = 1e3;
2436
2499
  var createDiagnostics = async (clientServices, serviceContext, config) => {
2437
- var _a, _b, _c;
2438
2500
  const diagnostics = {
2439
- created: new Date().toISOString(),
2501
+ created: (/* @__PURE__ */ new Date()).toISOString(),
2440
2502
  platform: getPlatform(),
2441
2503
  client: {
2442
2504
  version: DXOS_VERSION,
@@ -2448,7 +2510,7 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
2448
2510
  {
2449
2511
  invariant9(clientServices.LoggingService, "SystemService is not available.", {
2450
2512
  F: __dxlog_file10,
2451
- L: 87,
2513
+ L: 88,
2452
2514
  S: void 0,
2453
2515
  A: [
2454
2516
  "clientServices.LoggingService",
@@ -2466,16 +2528,16 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
2466
2528
  spaceKey: identity.space.key,
2467
2529
  profile: identity.profileDocument
2468
2530
  };
2469
- const { devices } = (_a = await getFirstStreamValue(clientServices.DevicesService.queryDevices(), {
2531
+ const { devices } = await getFirstStreamValue(clientServices.DevicesService.queryDevices(), {
2470
2532
  timeout: DEFAULT_TIMEOUT
2471
- }).catch(() => void 0)) != null ? _a : {};
2533
+ }).catch(() => void 0) ?? {};
2472
2534
  diagnostics.devices = devices;
2473
2535
  if (serviceContext.dataSpaceManager) {
2474
- diagnostics.spaces = await Promise.all((_b = Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space))) != null ? _b : []);
2536
+ diagnostics.spaces = await Promise.all(Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space)) ?? []);
2475
2537
  }
2476
- const { feeds = [] } = (_c = await getFirstStreamValue(clientServices.DevtoolsHost.subscribeToFeeds({}), {
2538
+ const { feeds = [] } = await getFirstStreamValue(clientServices.DevtoolsHost.subscribeToFeeds({}), {
2477
2539
  timeout: DEFAULT_TIMEOUT
2478
- }).catch(() => void 0)) != null ? _c : {};
2540
+ }).catch(() => void 0) ?? {};
2479
2541
  diagnostics.feeds = feeds.map(({ feedKey, bytes, length }) => ({
2480
2542
  feedKey,
2481
2543
  bytes,
@@ -2488,16 +2550,13 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
2488
2550
  var getProperties = (space) => {
2489
2551
  let properties = {};
2490
2552
  try {
2491
- const propertiesItem = space.dataPipeline.itemManager.items.find((item) => {
2492
- var _a, _b;
2493
- return ((_a = item.modelMeta) == null ? void 0 : _a.type) === DocumentModel.meta.type && ((_b = item.state) == null ? void 0 : _b.type) === "dxos.sdk.client.Properties";
2494
- });
2495
- const state = propertiesItem == null ? void 0 : propertiesItem.state;
2496
- properties = state == null ? void 0 : state.data;
2553
+ const propertiesItem = space.dataPipeline.itemManager.items.find((item) => item.modelMeta?.type === DocumentModel.meta.type && item.state?.type === TYPE_PROPERTIES);
2554
+ const state = propertiesItem?.state;
2555
+ properties = state?.data;
2497
2556
  } catch (err) {
2498
2557
  log8.warn(err.message, void 0, {
2499
2558
  F: __dxlog_file10,
2500
- L: 144,
2559
+ L: 145,
2501
2560
  S: void 0,
2502
2561
  C: (f, a) => f(...a)
2503
2562
  });
@@ -2505,7 +2564,6 @@ var getProperties = (space) => {
2505
2564
  return properties;
2506
2565
  };
2507
2566
  var getSpaceStats = async (space) => {
2508
- var _a, _b, _c, _d, _e, _f;
2509
2567
  const stats = {
2510
2568
  key: space.key,
2511
2569
  metrics: space.metrics,
@@ -2513,18 +2571,15 @@ var getSpaceStats = async (space) => {
2513
2571
  ...credential.subject.assertion,
2514
2572
  id: credential.id
2515
2573
  })),
2516
- members: Array.from(space.inner.spaceState.members.values()).map((member) => {
2517
- var _a2;
2518
- return {
2519
- identity: {
2520
- identityKey: member.key,
2521
- profile: {
2522
- displayName: (_a2 = member.assertion.profile) == null ? void 0 : _a2.displayName
2523
- }
2524
- },
2525
- presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember.PresenceState.ONLINE : SpaceMember.PresenceState.OFFLINE
2526
- };
2527
- }),
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
+ })),
2528
2583
  pipeline: {
2529
2584
  // TODO(burdon): Pick properties from credentials if needed.
2530
2585
  // currentEpoch: space.dataPipeline.currentEpoch,
@@ -2534,11 +2589,11 @@ var getSpaceStats = async (space) => {
2534
2589
  targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
2535
2590
  totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe,
2536
2591
  // TODO(burdon): Empty?
2537
- dataFeeds: (_b = (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.feeds.map((feed) => feed.key)) != null ? _b : [],
2538
- startDataTimeframe: (_c = space.dataPipeline.pipelineState) == null ? void 0 : _c.startTimeframe,
2539
- currentDataTimeframe: (_d = space.dataPipeline.pipelineState) == null ? void 0 : _d.timeframe,
2540
- targetDataTimeframe: (_e = space.dataPipeline.pipelineState) == null ? void 0 : _e.targetTimeframe,
2541
- totalDataTimeframe: (_f = space.dataPipeline.pipelineState) == null ? void 0 : _f.endTimeframe
2592
+ dataFeeds: space.dataPipeline.pipelineState?.feeds.map((feed) => feed.key) ?? [],
2593
+ startDataTimeframe: space.dataPipeline.pipelineState?.startTimeframe,
2594
+ currentDataTimeframe: space.dataPipeline.pipelineState?.timeframe,
2595
+ targetDataTimeframe: space.dataPipeline.pipelineState?.targetTimeframe,
2596
+ totalDataTimeframe: space.dataPipeline.pipelineState?.endTimeframe
2542
2597
  }
2543
2598
  };
2544
2599
  if (space.dataPipeline.itemManager) {
@@ -2559,7 +2614,7 @@ var getSpaceStats = async (space) => {
2559
2614
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2560
2615
  import { Event as Event5, scheduleTask as scheduleTask4, synchronized, trackLeaks } from "@dxos/async";
2561
2616
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
2562
- import { cancelWithContext as cancelWithContext2, Context as Context6 } from "@dxos/context";
2617
+ import { cancelWithContext as cancelWithContext2, Context as Context7 } from "@dxos/context";
2563
2618
  import { timed } from "@dxos/debug";
2564
2619
  import { createMappedFeedWriter } from "@dxos/echo-pipeline";
2565
2620
  import { CancelledError, SystemError } from "@dxos/errors";
@@ -2567,12 +2622,12 @@ import { PublicKey as PublicKey7 } from "@dxos/keys";
2567
2622
  import { log as log10 } from "@dxos/log";
2568
2623
  import { SpaceState } from "@dxos/protocols/proto/dxos/client/services";
2569
2624
  import { AdmittedFeed as AdmittedFeed3 } from "@dxos/protocols/proto/dxos/halo/credentials";
2570
- import { Timeframe } from "@dxos/timeframe";
2625
+ import { Timeframe as Timeframe2 } from "@dxos/timeframe";
2571
2626
  import { ComplexSet as ComplexSet2 } from "@dxos/util";
2572
2627
 
2573
2628
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
2574
2629
  import { DeferredTask, Event as Event4, scheduleTask as scheduleTask3, sleep, TimeoutError as TimeoutError2, Trigger as Trigger4 } from "@dxos/async";
2575
- import { Context as Context5, rejectOnDispose } from "@dxos/context";
2630
+ import { Context as Context6, rejectOnDispose } from "@dxos/context";
2576
2631
  import { invariant as invariant10 } from "@dxos/invariant";
2577
2632
  import { PublicKey as PublicKey6 } from "@dxos/keys";
2578
2633
  import { log as log9 } from "@dxos/log";
@@ -2586,7 +2641,7 @@ var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
2586
2641
  var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
2587
2642
  var NotarizationPlugin = class {
2588
2643
  constructor() {
2589
- this._ctx = new Context5();
2644
+ this._ctx = new Context6();
2590
2645
  this._extensionOpened = new Event4();
2591
2646
  this._extensions = /* @__PURE__ */ new Set();
2592
2647
  this._processedCredentials = new ComplexSet(PublicKey6.hash);
@@ -2636,7 +2691,7 @@ var NotarizationPlugin = class {
2636
2691
  errors.throw(err);
2637
2692
  }
2638
2693
  });
2639
- opCtx == null ? void 0 : opCtx.onDispose(() => ctx.dispose());
2694
+ opCtx?.onDispose(() => ctx.dispose());
2640
2695
  if (timeout !== 0) {
2641
2696
  scheduleTask3(ctx, () => {
2642
2697
  log9.warn("Notarization timeout", {
@@ -2729,11 +2784,10 @@ var NotarizationPlugin = class {
2729
2784
  * Called with credentials arriving from the control pipeline.
2730
2785
  */
2731
2786
  async processCredential(credential) {
2732
- var _a;
2733
2787
  if (!credential.id) {
2734
2788
  return;
2735
2789
  }
2736
- (_a = this._processCredentialsTriggers.get(credential.id)) == null ? void 0 : _a.wake();
2790
+ this._processCredentialsTriggers.get(credential.id)?.wake();
2737
2791
  this._processedCredentials.add(credential.id);
2738
2792
  this._processCredentialsTriggers.delete(credential.id);
2739
2793
  }
@@ -2759,11 +2813,10 @@ var NotarizationPlugin = class {
2759
2813
  * Requests from other peers to notarize credentials.
2760
2814
  */
2761
2815
  async _onNotarize(request) {
2762
- var _a;
2763
2816
  if (!this._writer) {
2764
2817
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
2765
2818
  }
2766
- for (const credential of (_a = request.credentials) != null ? _a : []) {
2819
+ for (const credential of request.credentials ?? []) {
2767
2820
  invariant10(credential.id, "Credential must have an id", {
2768
2821
  F: __dxlog_file11,
2769
2822
  L: 200,
@@ -2841,7 +2894,7 @@ var NotarizationTeleportExtension = class extends RpcExtension2 {
2841
2894
  };
2842
2895
 
2843
2896
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2844
- function _ts_decorate(decorators, target, key, desc) {
2897
+ function _ts_decorate3(decorators, target, key, desc) {
2845
2898
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2846
2899
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2847
2900
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2852,9 +2905,10 @@ function _ts_decorate(decorators, target, key, desc) {
2852
2905
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2853
2906
  }
2854
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;
2855
2909
  var DataSpace = class DataSpace2 {
2856
2910
  constructor(params) {
2857
- this._ctx = new Context6();
2911
+ this._ctx = new Context7();
2858
2912
  this._notarizationPlugin = new NotarizationPlugin();
2859
2913
  this._state = SpaceState.CLOSED;
2860
2914
  /**
@@ -2863,7 +2917,6 @@ var DataSpace = class DataSpace2 {
2863
2917
  this.error = void 0;
2864
2918
  this.stateUpdate = new Event5();
2865
2919
  this.metrics = {};
2866
- var _a;
2867
2920
  this._inner = params.inner;
2868
2921
  this._inner.stateUpdate.on(this._ctx, () => this.stateUpdate.emit());
2869
2922
  this._gossip = params.gossip;
@@ -2872,7 +2925,7 @@ var DataSpace = class DataSpace2 {
2872
2925
  this._feedStore = params.feedStore;
2873
2926
  this._metadataStore = params.metadataStore;
2874
2927
  this._signingContext = params.signingContext;
2875
- this._callbacks = (_a = params.callbacks) != null ? _a : {};
2928
+ this._callbacks = params.callbacks ?? {};
2876
2929
  this.authVerifier = new TrustedKeySetAuthVerifier({
2877
2930
  trustedKeysProvider: () => new ComplexSet2(PublicKey7.hash, Array.from(this._inner.spaceState.members.keys())),
2878
2931
  update: this._inner.stateUpdate,
@@ -2912,21 +2965,20 @@ var DataSpace = class DataSpace2 {
2912
2965
  async _open() {
2913
2966
  await this._notarizationPlugin.open();
2914
2967
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
2915
- await this._inner.open();
2968
+ await this._inner.open(new Context7());
2916
2969
  this._state = SpaceState.CONTROL_ONLY;
2917
2970
  this.stateUpdate.emit();
2918
2971
  this.metrics = {};
2919
- this.metrics.open = new Date();
2972
+ this.metrics.open = /* @__PURE__ */ new Date();
2920
2973
  }
2921
2974
  async close() {
2922
2975
  await this._close();
2923
2976
  }
2924
2977
  async _close() {
2925
- var _a, _b;
2926
- await ((_b = (_a = this._callbacks).beforeClose) == null ? void 0 : _b.call(_a));
2978
+ await this._callbacks.beforeClose?.();
2927
2979
  this._state = SpaceState.CLOSED;
2928
2980
  await this._ctx.dispose();
2929
- this._ctx = new Context6();
2981
+ this._ctx = new Context7();
2930
2982
  await this.authVerifier.close();
2931
2983
  await this._inner.close();
2932
2984
  await this._inner.spaceState.removeCredentialProcessor(this._notarizationPlugin);
@@ -2945,13 +2997,13 @@ var DataSpace = class DataSpace2 {
2945
2997
  initializeDataPipelineAsync() {
2946
2998
  scheduleTask4(this._ctx, async () => {
2947
2999
  try {
2948
- this.metrics.pipelineInitBegin = new Date();
3000
+ this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
2949
3001
  await this.initializeDataPipeline();
2950
3002
  } catch (err) {
2951
3003
  if (err instanceof CancelledError) {
2952
3004
  log10("data pipeline initialization cancelled", err, {
2953
3005
  F: __dxlog_file12,
2954
- L: 193,
3006
+ L: 199,
2955
3007
  S: this,
2956
3008
  C: (f, a) => f(...a)
2957
3009
  });
@@ -2959,7 +3011,7 @@ var DataSpace = class DataSpace2 {
2959
3011
  }
2960
3012
  log10.error("Error initializing data pipeline", err, {
2961
3013
  F: __dxlog_file12,
2962
- L: 197,
3014
+ L: 203,
2963
3015
  S: this,
2964
3016
  C: (f, a) => f(...a)
2965
3017
  });
@@ -2967,12 +3019,11 @@ var DataSpace = class DataSpace2 {
2967
3019
  this.error = err;
2968
3020
  this.stateUpdate.emit();
2969
3021
  } finally {
2970
- this.metrics.ready = new Date();
3022
+ this.metrics.ready = /* @__PURE__ */ new Date();
2971
3023
  }
2972
3024
  });
2973
3025
  }
2974
3026
  async initializeDataPipeline() {
2975
- var _a, _b, _c, _d;
2976
3027
  if (this._state !== SpaceState.CONTROL_ONLY) {
2977
3028
  throw new SystemError("Invalid operation");
2978
3029
  }
@@ -2981,11 +3032,11 @@ var DataSpace = class DataSpace2 {
2981
3032
  ctx: this._ctx,
2982
3033
  breakOnStall: false
2983
3034
  });
2984
- this.metrics.controlPipelineReady = new Date();
3035
+ this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
2985
3036
  await this._createWritableFeeds();
2986
3037
  log10("writable feeds created", void 0, {
2987
3038
  F: __dxlog_file12,
2988
- L: 221,
3039
+ L: 227,
2989
3040
  S: this,
2990
3041
  C: (f, a) => f(...a)
2991
3042
  });
@@ -2998,11 +3049,11 @@ var DataSpace = class DataSpace2 {
2998
3049
  }), this._inner.controlPipeline.writer));
2999
3050
  }
3000
3051
  await this._inner.initializeDataPipeline();
3001
- this.metrics.dataPipelineOpen = new Date();
3052
+ this.metrics.dataPipelineOpen = /* @__PURE__ */ new Date();
3002
3053
  await cancelWithContext2(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
3003
3054
  log10("waiting for data pipeline to reach target timeframe", void 0, {
3004
3055
  F: __dxlog_file12,
3005
- L: 242,
3056
+ L: 248,
3006
3057
  S: this,
3007
3058
  C: (f, a) => f(...a)
3008
3059
  });
@@ -3010,17 +3061,17 @@ var DataSpace = class DataSpace2 {
3010
3061
  ctx: this._ctx,
3011
3062
  breakOnStall: false
3012
3063
  });
3013
- this.metrics.dataPipelineReady = new Date();
3064
+ this.metrics.dataPipelineReady = /* @__PURE__ */ new Date();
3014
3065
  log10("data pipeline ready", void 0, {
3015
3066
  F: __dxlog_file12,
3016
- L: 251,
3067
+ L: 257,
3017
3068
  S: this,
3018
3069
  C: (f, a) => f(...a)
3019
3070
  });
3020
- await ((_b = (_a = this._callbacks).beforeReady) == null ? void 0 : _b.call(_a));
3071
+ await this._callbacks.beforeReady?.();
3021
3072
  this._state = SpaceState.READY;
3022
3073
  this.stateUpdate.emit();
3023
- await ((_d = (_c = this._callbacks).afterReady) == null ? void 0 : _d.call(_c));
3074
+ await this._callbacks.afterReady?.();
3024
3075
  }
3025
3076
  async _createWritableFeeds() {
3026
3077
  const credentials = [];
@@ -3067,7 +3118,6 @@ var DataSpace = class DataSpace2 {
3067
3118
  await this._metadataStore.setWritableFeedKeys(this.key, this.inner.controlFeedKey, this.inner.dataFeedKey);
3068
3119
  }
3069
3120
  async createEpoch() {
3070
- var _a, _b;
3071
3121
  const epoch = await this.dataPipeline.createEpoch();
3072
3122
  const receipt = await this.inner.controlPipeline.writer.write({
3073
3123
  credential: {
@@ -3080,16 +3130,19 @@ var DataSpace = class DataSpace2 {
3080
3130
  })
3081
3131
  }
3082
3132
  });
3083
- await this.inner.controlPipeline.state.waitUntilTimeframe(new Timeframe([
3133
+ await this.inner.controlPipeline.state.waitUntilTimeframe(new Timeframe2([
3084
3134
  [
3085
3135
  receipt.feedKey,
3086
3136
  receipt.seq
3087
3137
  ]
3088
3138
  ]));
3089
- for (const feed of (_b = (_a = this.inner.dataPipeline.pipelineState) == null ? void 0 : _a.feeds) != null ? _b : []) {
3090
- const indexBeforeEpoch = epoch.timeframe.get(feed.key);
3091
- if (indexBeforeEpoch) {
3092
- 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);
3093
3146
  }
3094
3147
  }
3095
3148
  }
@@ -3111,33 +3164,33 @@ var DataSpace = class DataSpace2 {
3111
3164
  this.stateUpdate.emit();
3112
3165
  }
3113
3166
  };
3114
- _ts_decorate([
3167
+ _ts_decorate3([
3115
3168
  synchronized
3116
3169
  ], DataSpace.prototype, "open", null);
3117
- _ts_decorate([
3170
+ _ts_decorate3([
3118
3171
  synchronized
3119
3172
  ], DataSpace.prototype, "close", null);
3120
- _ts_decorate([
3173
+ _ts_decorate3([
3121
3174
  timed(1e4)
3122
3175
  ], DataSpace.prototype, "_createWritableFeeds", null);
3123
- _ts_decorate([
3176
+ _ts_decorate3([
3124
3177
  synchronized
3125
3178
  ], DataSpace.prototype, "activate", null);
3126
- _ts_decorate([
3179
+ _ts_decorate3([
3127
3180
  synchronized
3128
3181
  ], DataSpace.prototype, "deactivate", null);
3129
- DataSpace = _ts_decorate([
3182
+ DataSpace = _ts_decorate3([
3130
3183
  trackLeaks("open", "close")
3131
3184
  ], DataSpace);
3132
3185
 
3133
3186
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
3134
3187
  import { Event as Event6, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
3135
- import { cancelWithContext as cancelWithContext3, Context as Context7 } from "@dxos/context";
3188
+ import { cancelWithContext as cancelWithContext3, Context as Context8 } from "@dxos/context";
3136
3189
  import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
3137
3190
  import { invariant as invariant11 } from "@dxos/invariant";
3138
3191
  import { PublicKey as PublicKey8 } from "@dxos/keys";
3139
3192
  import { log as log11 } from "@dxos/log";
3140
- import { trace as trace4 } from "@dxos/protocols";
3193
+ import { trace as trace5 } from "@dxos/protocols";
3141
3194
  import { SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
3142
3195
  import { Gossip, Presence } from "@dxos/teleport-extension-gossip";
3143
3196
  import { ComplexMap as ComplexMap3, deferFunction as deferFunction2 } from "@dxos/util";
@@ -3146,9 +3199,8 @@ import { ComplexMap as ComplexMap3, deferFunction as deferFunction2 } from "@dxo
3146
3199
  import { createCredential } from "@dxos/credentials";
3147
3200
  import { failUndefined as failUndefined2 } from "@dxos/debug";
3148
3201
  import { AdmittedFeed as AdmittedFeed4, SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/halo/credentials";
3149
- import { Timeframe as Timeframe2 } from "@dxos/timeframe";
3202
+ import { Timeframe as Timeframe3 } from "@dxos/timeframe";
3150
3203
  var spaceGenesis = async (keyring, signingContext, space) => {
3151
- var _a, _b, _c, _d;
3152
3204
  const credentials = [
3153
3205
  await createCredential({
3154
3206
  signer: keyring,
@@ -3168,11 +3220,11 @@ var spaceGenesis = async (keyring, signingContext, space) => {
3168
3220
  spaceKey: space.key,
3169
3221
  role: SpaceMember2.Role.ADMIN,
3170
3222
  profile: signingContext.profile,
3171
- genesisFeedKey: (_a = space.controlFeedKey) != null ? _a : failUndefined2()
3223
+ genesisFeedKey: space.controlFeedKey ?? failUndefined2()
3172
3224
  }
3173
3225
  }),
3174
3226
  await signingContext.credentialSigner.createCredential({
3175
- subject: (_b = space.controlFeedKey) != null ? _b : failUndefined2(),
3227
+ subject: space.controlFeedKey ?? failUndefined2(),
3176
3228
  assertion: {
3177
3229
  "@type": "dxos.halo.credentials.AdmittedFeed",
3178
3230
  spaceKey: space.key,
@@ -3182,7 +3234,7 @@ var spaceGenesis = async (keyring, signingContext, space) => {
3182
3234
  }
3183
3235
  }),
3184
3236
  await signingContext.credentialSigner.createCredential({
3185
- subject: (_c = space.dataFeedKey) != null ? _c : failUndefined2(),
3237
+ subject: space.dataFeedKey ?? failUndefined2(),
3186
3238
  assertion: {
3187
3239
  "@type": "dxos.halo.credentials.AdmittedFeed",
3188
3240
  spaceKey: space.key,
@@ -3192,12 +3244,12 @@ var spaceGenesis = async (keyring, signingContext, space) => {
3192
3244
  }
3193
3245
  }),
3194
3246
  await signingContext.credentialSigner.createCredential({
3195
- subject: (_d = space.key) != null ? _d : failUndefined2(),
3247
+ subject: space.key ?? failUndefined2(),
3196
3248
  assertion: {
3197
3249
  "@type": "dxos.halo.credentials.Epoch",
3198
3250
  number: 0,
3199
3251
  previousId: void 0,
3200
- timeframe: new Timeframe2(),
3252
+ timeframe: new Timeframe3(),
3201
3253
  snapshotCid: void 0
3202
3254
  }
3203
3255
  })
@@ -3213,7 +3265,7 @@ var spaceGenesis = async (keyring, signingContext, space) => {
3213
3265
  };
3214
3266
 
3215
3267
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
3216
- function _ts_decorate2(decorators, target, key, desc) {
3268
+ function _ts_decorate4(decorators, target, key, desc) {
3217
3269
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3218
3270
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3219
3271
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3232,7 +3284,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3232
3284
  this._keyring = _keyring;
3233
3285
  this._signingContext = _signingContext;
3234
3286
  this._feedStore = _feedStore;
3235
- this._ctx = new Context7();
3287
+ this._ctx = new Context8();
3236
3288
  this.updated = new Event6();
3237
3289
  this._spaces = new ComplexMap3(PublicKey8.hash);
3238
3290
  this._isOpen = false;
@@ -3249,7 +3301,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3249
3301
  S: this,
3250
3302
  C: (f, a) => f(...a)
3251
3303
  });
3252
- log11.trace("dxos.echo.data-space-manager.open", trace4.begin({
3304
+ log11.trace("dxos.echo.data-space-manager.open", trace5.begin({
3253
3305
  id: this._instanceId
3254
3306
  }), {
3255
3307
  F: __dxlog_file13,
@@ -3294,7 +3346,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3294
3346
  }
3295
3347
  this._isOpen = true;
3296
3348
  this.updated.emit();
3297
- log11.trace("dxos.echo.data-space-manager.open", trace4.end({
3349
+ log11.trace("dxos.echo.data-space-manager.open", trace5.end({
3298
3350
  id: this._instanceId
3299
3351
  }), {
3300
3352
  F: __dxlog_file13,
@@ -3457,7 +3509,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3457
3509
  onAuthFailure: () => {
3458
3510
  log11.warn("auth failure", void 0, {
3459
3511
  F: __dxlog_file13,
3460
- L: 213,
3512
+ L: 217,
3461
3513
  S: this,
3462
3514
  C: (f, a) => f(...a)
3463
3515
  });
@@ -3481,7 +3533,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3481
3533
  space: space.key
3482
3534
  }, {
3483
3535
  F: __dxlog_file13,
3484
- L: 231,
3536
+ L: 235,
3485
3537
  S: this,
3486
3538
  C: (f, a) => f(...a)
3487
3539
  });
@@ -3493,7 +3545,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3493
3545
  open: this._isOpen
3494
3546
  }, {
3495
3547
  F: __dxlog_file13,
3496
- L: 238,
3548
+ L: 242,
3497
3549
  S: this,
3498
3550
  C: (f, a) => f(...a)
3499
3551
  });
@@ -3506,7 +3558,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3506
3558
  space: space.key
3507
3559
  }, {
3508
3560
  F: __dxlog_file13,
3509
- L: 244,
3561
+ L: 248,
3510
3562
  S: this,
3511
3563
  C: (f, a) => f(...a)
3512
3564
  });
@@ -3528,19 +3580,19 @@ var DataSpaceManager = class DataSpaceManager2 {
3528
3580
  return dataSpace;
3529
3581
  }
3530
3582
  };
3531
- _ts_decorate2([
3583
+ _ts_decorate4([
3532
3584
  synchronized2
3533
3585
  ], DataSpaceManager.prototype, "open", null);
3534
- _ts_decorate2([
3586
+ _ts_decorate4([
3535
3587
  synchronized2
3536
3588
  ], DataSpaceManager.prototype, "close", null);
3537
- _ts_decorate2([
3589
+ _ts_decorate4([
3538
3590
  synchronized2
3539
3591
  ], DataSpaceManager.prototype, "createSpace", null);
3540
- _ts_decorate2([
3592
+ _ts_decorate4([
3541
3593
  synchronized2
3542
3594
  ], DataSpaceManager.prototype, "acceptSpace", null);
3543
- DataSpaceManager = _ts_decorate2([
3595
+ DataSpaceManager = _ts_decorate4([
3544
3596
  trackLeaks2("open", "close")
3545
3597
  ], DataSpaceManager);
3546
3598
 
@@ -3571,9 +3623,8 @@ var SpacesServiceImpl = class {
3571
3623
  return this._serializeSpace(space);
3572
3624
  }
3573
3625
  async updateSpace({ spaceKey, state }) {
3574
- var _a;
3575
3626
  const dataSpaceManager = await this._getDataSpaceManager();
3576
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3627
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3577
3628
  if (state) {
3578
3629
  switch (state) {
3579
3630
  case SpaceState3.ACTIVE:
@@ -3604,7 +3655,7 @@ var SpacesServiceImpl = class {
3604
3655
  spaces
3605
3656
  });
3606
3657
  }, {
3607
- maxFrequency: 2
3658
+ maxFrequency: false ? void 0 : 2
3608
3659
  });
3609
3660
  scheduleTask5(ctx, async () => {
3610
3661
  const dataSpaceManager = await this._getDataSpaceManager();
@@ -3637,17 +3688,15 @@ var SpacesServiceImpl = class {
3637
3688
  });
3638
3689
  }
3639
3690
  async postMessage({ spaceKey, channel, message }) {
3640
- var _a;
3641
3691
  const dataSpaceManager = await this._getDataSpaceManager();
3642
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3692
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3643
3693
  await space.postMessage(getChannelId(channel), message);
3644
3694
  }
3645
3695
  subscribeMessages({ spaceKey, channel }) {
3646
3696
  return new Stream10(({ ctx, next }) => {
3647
3697
  scheduleTask5(ctx, async () => {
3648
- var _a;
3649
3698
  const dataSpaceManager = await this._getDataSpaceManager();
3650
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3699
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3651
3700
  const handle = space.listen(getChannelId(channel), (message) => {
3652
3701
  next(message);
3653
3702
  });
@@ -3657,8 +3706,7 @@ var SpacesServiceImpl = class {
3657
3706
  }
3658
3707
  queryCredentials({ spaceKey }) {
3659
3708
  return new Stream10(({ ctx, next }) => {
3660
- var _a;
3661
- 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));
3662
3710
  const processor = {
3663
3711
  processCredential: async (credential) => {
3664
3712
  next(credential);
@@ -3669,9 +3717,8 @@ var SpacesServiceImpl = class {
3669
3717
  });
3670
3718
  }
3671
3719
  async writeCredentials({ spaceKey, credentials }) {
3672
- var _a;
3673
- const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3674
- 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 ?? []) {
3675
3722
  await space.controlPipeline.writer.write({
3676
3723
  credential: {
3677
3724
  credential
@@ -3680,13 +3727,11 @@ var SpacesServiceImpl = class {
3680
3727
  }
3681
3728
  }
3682
3729
  async createEpoch({ spaceKey }) {
3683
- var _a;
3684
3730
  const dataSpaceManager = await this._getDataSpaceManager();
3685
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3731
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3686
3732
  await space.createEpoch();
3687
3733
  }
3688
3734
  _serializeSpace(space) {
3689
- var _a, _b, _c, _d, _e, _f, _g;
3690
3735
  return {
3691
3736
  spaceKey: space.key,
3692
3737
  state: space.state,
@@ -3698,16 +3743,15 @@ var SpacesServiceImpl = class {
3698
3743
  currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
3699
3744
  targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
3700
3745
  totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe,
3701
- dataFeeds: (_b = (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.feeds.map((feed) => feed.key)) != null ? _b : [],
3702
- startDataTimeframe: (_c = space.dataPipeline.pipelineState) == null ? void 0 : _c.startTimeframe,
3703
- currentDataTimeframe: (_d = space.dataPipeline.pipelineState) == null ? void 0 : _d.timeframe,
3704
- targetDataTimeframe: (_e = space.dataPipeline.pipelineState) == null ? void 0 : _e.targetTimeframe,
3705
- 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
3706
3751
  },
3707
3752
  members: Array.from(space.inner.spaceState.members.values()).map((member) => {
3708
- var _a2, _b2, _c2;
3709
3753
  const peers = space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key));
3710
- const isMe = (_a2 = this._identityManager.identity) == null ? void 0 : _a2.identityKey.equals(member.key);
3754
+ const isMe = this._identityManager.identity?.identityKey.equals(member.key);
3711
3755
  if (isMe) {
3712
3756
  peers.push(space.presence.getLocalState());
3713
3757
  }
@@ -3715,14 +3759,14 @@ var SpacesServiceImpl = class {
3715
3759
  identity: {
3716
3760
  identityKey: member.key,
3717
3761
  profile: {
3718
- 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)
3719
3763
  }
3720
3764
  },
3721
3765
  presence: isMe || peers.length > 0 ? SpaceMember3.PresenceState.ONLINE : SpaceMember3.PresenceState.OFFLINE,
3722
3766
  peerStates: peers
3723
3767
  };
3724
3768
  }),
3725
- creator: (_g = space.inner.spaceState.creator) == null ? void 0 : _g.key,
3769
+ creator: space.inner.spaceState.creator?.key,
3726
3770
  cache: space.cache,
3727
3771
  metrics: space.metrics
3728
3772
  };
@@ -3732,6 +3776,7 @@ var getChannelId = (channel) => `user-channel/${channel}`;
3732
3776
 
3733
3777
  // packages/sdk/client-services/src/packlets/services/service-context.ts
3734
3778
  import { Trigger as Trigger5 } from "@dxos/async";
3779
+ import { Context as Context9 } from "@dxos/context";
3735
3780
  import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
3736
3781
  import { failUndefined as failUndefined3 } from "@dxos/debug";
3737
3782
  import { valueEncoding, MetadataStore, SpaceManager, DataServiceSubscriptions, SnapshotStore } from "@dxos/echo-pipeline";
@@ -3740,11 +3785,23 @@ import { invariant as invariant12 } from "@dxos/invariant";
3740
3785
  import { Keyring } from "@dxos/keyring";
3741
3786
  import { PublicKey as PublicKey9 } from "@dxos/keys";
3742
3787
  import { log as log13 } from "@dxos/log";
3743
- import { STORAGE_VERSION as STORAGE_VERSION2, trace as trace5 } from "@dxos/protocols";
3788
+ import { STORAGE_VERSION as STORAGE_VERSION2, trace as trace6 } from "@dxos/protocols";
3744
3789
  import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
3745
3790
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
3791
+ import { trace as Trace2 } from "@dxos/tracing";
3792
+ import { safeInstanceof } from "@dxos/util";
3793
+ function _ts_decorate5(decorators, target, key, desc) {
3794
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3795
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3796
+ r = Reflect.decorate(decorators, target, key, desc);
3797
+ else
3798
+ for (var i = decorators.length - 1; i >= 0; i--)
3799
+ if (d = decorators[i])
3800
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3801
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
3802
+ }
3746
3803
  var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
3747
- var ServiceContext = class {
3804
+ var ServiceContext = class ServiceContext2 {
3748
3805
  // prettier-ignore
3749
3806
  constructor(storage, networkManager, signalManager, modelFactory) {
3750
3807
  this.storage = storage;
@@ -3764,7 +3821,8 @@ var ServiceContext = class {
3764
3821
  root: storage.createDirectory("feeds"),
3765
3822
  signer: this.keyring,
3766
3823
  hypercore: {
3767
- valueEncoding
3824
+ valueEncoding,
3825
+ stats: true
3768
3826
  }
3769
3827
  })
3770
3828
  });
@@ -3778,61 +3836,57 @@ var ServiceContext = class {
3778
3836
  });
3779
3837
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager);
3780
3838
  this.invitations = new InvitationsHandler(this.networkManager);
3781
- this._handlerFactories.set(Invitation5.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => {
3782
- var _a;
3783
- return (_a = this.identityManager.identity) != null ? _a : failUndefined3();
3784
- }, this._acceptIdentity.bind(this)));
3839
+ this._handlerFactories.set(Invitation5.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined3(), this._acceptIdentity.bind(this)));
3785
3840
  }
3786
- async open() {
3841
+ async open(ctx) {
3787
3842
  await this._checkStorageVersion();
3788
3843
  log13("opening...", void 0, {
3789
3844
  F: __dxlog_file15,
3790
- L: 127,
3845
+ L: 135,
3791
3846
  S: this,
3792
3847
  C: (f, a) => f(...a)
3793
3848
  });
3794
- log13.trace("dxos.sdk.service-context.open", trace5.begin({
3849
+ log13.trace("dxos.sdk.service-context.open", trace6.begin({
3795
3850
  id: this._instanceId
3796
3851
  }), {
3797
3852
  F: __dxlog_file15,
3798
- L: 128,
3853
+ L: 136,
3799
3854
  S: this,
3800
3855
  C: (f, a) => f(...a)
3801
3856
  });
3802
3857
  await this.signalManager.open();
3803
3858
  await this.networkManager.open();
3804
3859
  await this.spaceManager.open();
3805
- await this.identityManager.open();
3860
+ await this.identityManager.open(ctx);
3806
3861
  if (this.identityManager.identity) {
3807
- await this._initialize();
3862
+ await this._initialize(ctx);
3808
3863
  }
3809
- log13.trace("dxos.sdk.service-context.open", trace5.end({
3864
+ log13.trace("dxos.sdk.service-context.open", trace6.end({
3810
3865
  id: this._instanceId
3811
3866
  }), {
3812
3867
  F: __dxlog_file15,
3813
- L: 136,
3868
+ L: 144,
3814
3869
  S: this,
3815
3870
  C: (f, a) => f(...a)
3816
3871
  });
3817
3872
  log13("opened", void 0, {
3818
3873
  F: __dxlog_file15,
3819
- L: 137,
3874
+ L: 145,
3820
3875
  S: this,
3821
3876
  C: (f, a) => f(...a)
3822
3877
  });
3823
3878
  }
3824
3879
  async close() {
3825
- var _a;
3826
3880
  log13("closing...", void 0, {
3827
3881
  F: __dxlog_file15,
3828
- L: 141,
3882
+ L: 149,
3829
3883
  S: this,
3830
3884
  C: (f, a) => f(...a)
3831
3885
  });
3832
3886
  if (this._deviceSpaceSync && this.identityManager.identity) {
3833
3887
  await this.identityManager.identity.space.spaceState.removeCredentialProcessor(this._deviceSpaceSync);
3834
3888
  }
3835
- await ((_a = this.dataSpaceManager) == null ? void 0 : _a.close());
3889
+ await this.dataSpaceManager?.close();
3836
3890
  await this.identityManager.close();
3837
3891
  await this.spaceManager.close();
3838
3892
  await this.feedStore.close();
@@ -3841,21 +3895,21 @@ var ServiceContext = class {
3841
3895
  this.dataServiceSubscriptions.clear();
3842
3896
  log13("closed", void 0, {
3843
3897
  F: __dxlog_file15,
3844
- L: 152,
3898
+ L: 160,
3845
3899
  S: this,
3846
3900
  C: (f, a) => f(...a)
3847
3901
  });
3848
3902
  }
3849
3903
  async createIdentity(params = {}) {
3850
3904
  const identity = await this.identityManager.createIdentity(params);
3851
- await this._initialize();
3905
+ await this._initialize(new Context9());
3852
3906
  return identity;
3853
3907
  }
3854
3908
  getInvitationHandler(invitation) {
3855
3909
  const factory = this._handlerFactories.get(invitation.kind);
3856
3910
  invariant12(factory, `Unknown invitation kind: ${invitation.kind}`, {
3857
3911
  F: __dxlog_file15,
3858
- L: 164,
3912
+ L: 171,
3859
3913
  S: this,
3860
3914
  A: [
3861
3915
  "factory",
@@ -3866,7 +3920,7 @@ var ServiceContext = class {
3866
3920
  }
3867
3921
  async _acceptIdentity(params) {
3868
3922
  const identity = await this.identityManager.acceptIdentity(params);
3869
- await this._initialize();
3923
+ await this._initialize(new Context9());
3870
3924
  return identity;
3871
3925
  }
3872
3926
  async _checkStorageVersion() {
@@ -3876,15 +3930,14 @@ var ServiceContext = class {
3876
3930
  }
3877
3931
  }
3878
3932
  // Called when identity is created.
3879
- async _initialize() {
3880
- var _a;
3933
+ async _initialize(ctx) {
3881
3934
  log13("initializing spaces...", void 0, {
3882
3935
  F: __dxlog_file15,
3883
- L: 185,
3936
+ L: 192,
3884
3937
  S: this,
3885
3938
  C: (f, a) => f(...a)
3886
3939
  });
3887
- const identity = (_a = this.identityManager.identity) != null ? _a : failUndefined3();
3940
+ const identity = this.identityManager.identity ?? failUndefined3();
3888
3941
  const signingContext = {
3889
3942
  credentialSigner: identity.getIdentityCredentialSigner(),
3890
3943
  identityKey: identity.identityKey,
@@ -3903,7 +3956,7 @@ var ServiceContext = class {
3903
3956
  this._handlerFactories.set(Invitation5.Kind.SPACE, (invitation) => {
3904
3957
  invariant12(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
3905
3958
  F: __dxlog_file15,
3906
- L: 208,
3959
+ L: 215,
3907
3960
  S: this,
3908
3961
  A: [
3909
3962
  "this.dataSpaceManager",
@@ -3927,7 +3980,7 @@ var ServiceContext = class {
3927
3980
  details: assertion
3928
3981
  }, {
3929
3982
  F: __dxlog_file15,
3930
- L: 224,
3983
+ L: 231,
3931
3984
  S: this,
3932
3985
  C: (f, a) => f(...a)
3933
3986
  });
@@ -3938,7 +3991,7 @@ var ServiceContext = class {
3938
3991
  details: assertion
3939
3992
  }, {
3940
3993
  F: __dxlog_file15,
3941
- L: 228,
3994
+ L: 235,
3942
3995
  S: this,
3943
3996
  C: (f, a) => f(...a)
3944
3997
  });
@@ -3949,7 +4002,7 @@ var ServiceContext = class {
3949
4002
  details: assertion
3950
4003
  }, {
3951
4004
  F: __dxlog_file15,
3952
- L: 233,
4005
+ L: 240,
3953
4006
  S: this,
3954
4007
  C: (f, a) => f(...a)
3955
4008
  });
@@ -3960,7 +4013,7 @@ var ServiceContext = class {
3960
4013
  } catch (err) {
3961
4014
  log13.catch(err, void 0, {
3962
4015
  F: __dxlog_file15,
3963
- L: 239,
4016
+ L: 246,
3964
4017
  S: this,
3965
4018
  C: (f, a) => f(...a)
3966
4019
  });
@@ -3970,12 +4023,22 @@ var ServiceContext = class {
3970
4023
  await identity.space.spaceState.addCredentialProcessor(this._deviceSpaceSync);
3971
4024
  }
3972
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);
3973
4036
 
3974
4037
  // packages/sdk/client-services/src/packlets/locks/browser.ts
3975
4038
  import { asyncTimeout, Trigger as Trigger6 } from "@dxos/async";
3976
4039
  import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
3977
4040
  import { log as log14, logInfo } from "@dxos/log";
3978
- function _ts_decorate3(decorators, target, key, desc) {
4041
+ function _ts_decorate6(decorators, target, key, desc) {
3979
4042
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3980
4043
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3981
4044
  r = Reflect.decorate(decorators, target, key, desc);
@@ -4020,7 +4083,7 @@ var Lock = class {
4020
4083
  S: this,
4021
4084
  C: (f, a) => f(...a)
4022
4085
  });
4023
- } catch (e) {
4086
+ } catch {
4024
4087
  log14("stealing lock...", void 0, {
4025
4088
  F: __dxlog_file16,
4026
4089
  L: 46,
@@ -4057,8 +4120,7 @@ var Lock = class {
4057
4120
  void navigator.locks.request(this._lockKey, {
4058
4121
  steal
4059
4122
  }, async () => {
4060
- var _a, _b;
4061
- await ((_a = this._onAcquire) == null ? void 0 : _a.call(this));
4123
+ await this._onAcquire?.();
4062
4124
  acquired.wake();
4063
4125
  this._releaseTrigger = new Trigger6();
4064
4126
  await this._releaseTrigger.wait();
@@ -4068,7 +4130,7 @@ var Lock = class {
4068
4130
  S: this,
4069
4131
  C: (f, a) => f(...a)
4070
4132
  });
4071
- await ((_b = this._onRelease) == null ? void 0 : _b.call(this));
4133
+ await this._onRelease?.();
4072
4134
  log14("released lock", void 0, {
4073
4135
  F: __dxlog_file16,
4074
4136
  L: 74,
@@ -4076,8 +4138,7 @@ var Lock = class {
4076
4138
  C: (f, a) => f(...a)
4077
4139
  });
4078
4140
  }).catch(async () => {
4079
- var _a;
4080
- await ((_a = this._onRelease) == null ? void 0 : _a.call(this));
4141
+ await this._onRelease?.();
4081
4142
  });
4082
4143
  await acquired.wait();
4083
4144
  log14("recieved lock", {
@@ -4090,7 +4151,7 @@ var Lock = class {
4090
4151
  });
4091
4152
  }
4092
4153
  };
4093
- _ts_decorate3([
4154
+ _ts_decorate6([
4094
4155
  logInfo
4095
4156
  ], Lock.prototype, "lockKey", null);
4096
4157
  var isLocked = (lockPath) => {
@@ -4105,7 +4166,7 @@ import { createStorage, StorageType } from "@dxos/random-access-storage";
4105
4166
  import { isNode } from "@dxos/util";
4106
4167
  var StorageDriver = Runtime.Client.Storage.StorageDriver;
4107
4168
  var createStorageObjects = (config) => {
4108
- 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 ?? {};
4109
4170
  if (persistent && storageType === StorageDriver.RAM) {
4110
4171
  throw new InvalidConfigError("RAM storage cannot be used in persistent mode.");
4111
4172
  }
@@ -4173,6 +4234,7 @@ var ServiceRegistry = class {
4173
4234
  // packages/sdk/client-services/src/packlets/services/service-host.ts
4174
4235
  import { Event as Event8, synchronized as synchronized3 } from "@dxos/async";
4175
4236
  import { clientServiceBundle } from "@dxos/client-protocol";
4237
+ import { Context as Context10 } from "@dxos/context";
4176
4238
  import { DocumentModel as DocumentModel2 } from "@dxos/document-model";
4177
4239
  import { DataServiceImpl } from "@dxos/echo-pipeline";
4178
4240
  import { invariant as invariant13 } from "@dxos/invariant";
@@ -4181,9 +4243,10 @@ import { log as log16 } from "@dxos/log";
4181
4243
  import { WebsocketSignalManager } from "@dxos/messaging";
4182
4244
  import { ModelFactory } from "@dxos/model-factory";
4183
4245
  import { createWebRTCTransportFactory, NetworkManager } from "@dxos/network-manager";
4184
- import { trace as trace6 } from "@dxos/protocols";
4246
+ import { trace as trace7 } from "@dxos/protocols";
4185
4247
  import { SystemStatus } from "@dxos/protocols/proto/dxos/client/services";
4186
4248
  import { TextModel } from "@dxos/text-model";
4249
+ import { TRACE_PROCESSOR, trace as Trace3 } from "@dxos/tracing";
4187
4250
 
4188
4251
  // packages/sdk/client-services/src/packlets/devices/devices-service.ts
4189
4252
  import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
@@ -4199,21 +4262,17 @@ var DevicesServiceImpl = class {
4199
4262
  queryDevices() {
4200
4263
  return new Stream11(({ next }) => {
4201
4264
  const update = () => {
4202
- var _a;
4203
- const deviceKeys = (_a = this._identityManager.identity) == null ? void 0 : _a.authorizedDeviceKeys;
4265
+ const deviceKeys = this._identityManager.identity?.authorizedDeviceKeys;
4204
4266
  if (!deviceKeys) {
4205
4267
  next({
4206
4268
  devices: []
4207
4269
  });
4208
4270
  } else {
4209
4271
  next({
4210
- devices: Array.from(deviceKeys.values()).map((key) => {
4211
- var _a2;
4212
- return {
4213
- deviceKey: key,
4214
- kind: ((_a2 = this._identityManager.identity) == null ? void 0 : _a2.deviceKey.equals(key)) ? DeviceKind.CURRENT : DeviceKind.TRUSTED
4215
- };
4216
- })
4272
+ devices: Array.from(deviceKeys.values()).map((key) => ({
4273
+ deviceKey: key,
4274
+ kind: this._identityManager.identity?.deviceKey.equals(key) ? DeviceKind.CURRENT : DeviceKind.TRUSTED
4275
+ }))
4217
4276
  });
4218
4277
  }
4219
4278
  };
@@ -4241,7 +4300,7 @@ import { jsonify, numericalValues, tracer } from "@dxos/util";
4241
4300
  var LoggingServiceImpl = class {
4242
4301
  constructor() {
4243
4302
  this._logs = new Event7();
4244
- this._started = new Date();
4303
+ this._started = /* @__PURE__ */ new Date();
4245
4304
  this._logProcessor = (_config, entry2) => {
4246
4305
  this._logs.emit(entry2);
4247
4306
  };
@@ -4271,8 +4330,7 @@ var LoggingServiceImpl = class {
4271
4330
  */
4272
4331
  queryMetrics({ interval = 5e3 }) {
4273
4332
  const getNumericalValues = (key) => {
4274
- var _a;
4275
- const events = (_a = tracer.get(key)) != null ? _a : [];
4333
+ const events = tracer.get(key) ?? [];
4276
4334
  return {
4277
4335
  key,
4278
4336
  stats: numericalValues(events, "duration")
@@ -4281,14 +4339,14 @@ var LoggingServiceImpl = class {
4281
4339
  return new Stream12(({ next }) => {
4282
4340
  const update = () => {
4283
4341
  const metrics = {
4284
- timestamp: new Date(),
4342
+ timestamp: /* @__PURE__ */ new Date(),
4285
4343
  values: [
4286
4344
  getNumericalValues("dxos.echo.pipeline.control"),
4287
4345
  getNumericalValues("dxos.echo.pipeline.data")
4288
4346
  ].filter(Boolean)
4289
4347
  };
4290
4348
  next({
4291
- timestamp: new Date(),
4349
+ timestamp: /* @__PURE__ */ new Date(),
4292
4350
  metrics
4293
4351
  });
4294
4352
  };
@@ -4302,11 +4360,10 @@ var LoggingServiceImpl = class {
4302
4360
  queryLogs(request) {
4303
4361
  return new Stream12(({ ctx, next }) => {
4304
4362
  const handler = (entry2) => {
4305
- var _a, _b, _c, _d, _e;
4306
4363
  if (LOG_PROCESSING > 0) {
4307
4364
  return;
4308
4365
  }
4309
- 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"))) {
4310
4367
  return;
4311
4368
  }
4312
4369
  if (!shouldLog(entry2, request)) {
@@ -4315,11 +4372,11 @@ var LoggingServiceImpl = class {
4315
4372
  const record = {
4316
4373
  ...entry2,
4317
4374
  context: jsonify(getContextFromEntry(entry2)),
4318
- timestamp: new Date(),
4375
+ timestamp: /* @__PURE__ */ new Date(),
4319
4376
  meta: {
4320
4377
  // TODO(dmaretskyi): Fix proto.
4321
- file: (_c = (_b = entry2.meta) == null ? void 0 : _b.F) != null ? _c : "",
4322
- line: (_e = (_d = entry2.meta) == null ? void 0 : _d.L) != null ? _e : 0
4378
+ file: entry2.meta?.F ?? "",
4379
+ line: entry2.meta?.L ?? 0
4323
4380
  }
4324
4381
  };
4325
4382
  try {
@@ -4342,15 +4399,11 @@ var matchFilter = (filter, level, path, options) => {
4342
4399
  }
4343
4400
  };
4344
4401
  var shouldLog = (entry2, request) => {
4345
- var _a;
4346
- const options = (_a = request.options) != null ? _a : QueryLogsRequest.MatchingOptions.INCLUSIVE;
4402
+ const options = request.options ?? QueryLogsRequest.MatchingOptions.INCLUSIVE;
4347
4403
  if (request.filters === void 0) {
4348
4404
  return options === QueryLogsRequest.MatchingOptions.INCLUSIVE;
4349
4405
  } else {
4350
- return request.filters.some((filter) => {
4351
- var _a2, _b;
4352
- return matchFilter(filter, entry2.level, (_b = (_a2 = entry2.meta) == null ? void 0 : _a2.F) != null ? _b : "", options);
4353
- });
4406
+ return request.filters.some((filter) => matchFilter(filter, entry2.level, entry2.meta?.F ?? "", options));
4354
4407
  }
4355
4408
  };
4356
4409
  var LOG_PROCESSING = 0;
@@ -4401,8 +4454,7 @@ var SystemServiceImpl = class {
4401
4454
  this._onReset = onReset;
4402
4455
  }
4403
4456
  async getConfig() {
4404
- var _a, _b;
4405
- return (_b = (_a = this._config) == null ? void 0 : _a.values) != null ? _b : {};
4457
+ return this._config?.values ?? {};
4406
4458
  }
4407
4459
  /**
4408
4460
  * NOTE: Since this is serialized as a JSON object, we allow the option to serialize keys.
@@ -4410,7 +4462,7 @@ var SystemServiceImpl = class {
4410
4462
  async getDiagnostics({ keys } = {}) {
4411
4463
  const diagnostics = await this._getDiagnostics();
4412
4464
  return {
4413
- timestamp: new Date(),
4465
+ timestamp: /* @__PURE__ */ new Date(),
4414
4466
  diagnostics: JSON.parse(JSON.stringify(diagnostics, jsonKeyReplacer({
4415
4467
  truncate: keys === GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
4416
4468
  humanize: keys === GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
@@ -4443,7 +4495,7 @@ var SystemServiceImpl = class {
4443
4495
  };
4444
4496
 
4445
4497
  // packages/sdk/client-services/src/packlets/services/service-host.ts
4446
- function _ts_decorate4(decorators, target, key, desc) {
4498
+ function _ts_decorate7(decorators, target, key, desc) {
4447
4499
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4448
4500
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
4449
4501
  r = Reflect.decorate(decorators, target, key, desc);
@@ -4457,7 +4509,7 @@ var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/s
4457
4509
  var createDefaultModelFactory = () => {
4458
4510
  return new ModelFactory().registerModel(DocumentModel2).registerModel(TextModel);
4459
4511
  };
4460
- var ClientServicesHost = class {
4512
+ var ClientServicesHost = class ClientServicesHost2 {
4461
4513
  constructor({
4462
4514
  config,
4463
4515
  modelFactory = createDefaultModelFactory(),
@@ -4468,6 +4520,7 @@ var ClientServicesHost = class {
4468
4520
  lockKey,
4469
4521
  callbacks
4470
4522
  } = {}) {
4523
+ this._tracingService = TRACE_PROCESSOR.createTraceSender();
4471
4524
  this._statusUpdate = new Event8();
4472
4525
  this._opening = false;
4473
4526
  this._open = false;
@@ -4486,7 +4539,7 @@ var ClientServicesHost = class {
4486
4539
  lockKey,
4487
4540
  onAcquire: () => {
4488
4541
  if (!this._opening) {
4489
- void this.open();
4542
+ void this.open(new Context10());
4490
4543
  }
4491
4544
  },
4492
4545
  onRelease: () => this.close()
@@ -4500,11 +4553,10 @@ var ClientServicesHost = class {
4500
4553
  return createDiagnostics(this._serviceRegistry.services, this._serviceContext, this._config);
4501
4554
  },
4502
4555
  onUpdateStatus: async (status) => {
4503
- var _a, _b;
4504
4556
  if (!this.isOpen && status === SystemStatus.ACTIVE) {
4505
- await ((_a = this._resourceLock) == null ? void 0 : _a.acquire());
4557
+ await this._resourceLock?.acquire();
4506
4558
  } else if (this.isOpen && status === SystemStatus.INACTIVE) {
4507
- await ((_b = this._resourceLock) == null ? void 0 : _b.release());
4559
+ await this._resourceLock?.release();
4508
4560
  }
4509
4561
  },
4510
4562
  onReset: async () => {
@@ -4513,7 +4565,8 @@ var ClientServicesHost = class {
4513
4565
  });
4514
4566
  this._loggingService = new LoggingServiceImpl();
4515
4567
  this._serviceRegistry = new ServiceRegistry(clientServiceBundle, {
4516
- SystemService: this._systemService
4568
+ SystemService: this._systemService,
4569
+ TracingService: this._tracingService
4517
4570
  });
4518
4571
  }
4519
4572
  get isOpen() {
@@ -4540,26 +4593,25 @@ var ClientServicesHost = class {
4540
4593
  * Can only be called once.
4541
4594
  */
4542
4595
  initialize({ config, ...options }) {
4543
- var _a, _b, _c;
4544
4596
  invariant13(!this._open, "service host is open", {
4545
4597
  F: __dxlog_file17,
4546
- L: 172,
4598
+ L: 181,
4547
4599
  S: this,
4548
4600
  A: [
4549
4601
  "!this._open",
4550
4602
  "'service host is open'"
4551
4603
  ]
4552
4604
  });
4553
- log16.info("initializing...", void 0, {
4605
+ log16("initializing...", void 0, {
4554
4606
  F: __dxlog_file17,
4555
- L: 173,
4607
+ L: 182,
4556
4608
  S: this,
4557
4609
  C: (f, a) => f(...a)
4558
4610
  });
4559
4611
  if (config) {
4560
4612
  invariant13(!this._config, "config already set", {
4561
4613
  F: __dxlog_file17,
4562
- L: 176,
4614
+ L: 185,
4563
4615
  S: this,
4564
4616
  A: [
4565
4617
  "!this._config",
@@ -4572,12 +4624,12 @@ var ClientServicesHost = class {
4572
4624
  }
4573
4625
  }
4574
4626
  const { connectionLog = true, transportFactory = createWebRTCTransportFactory({
4575
- iceServers: (_a = this._config) == null ? void 0 : _a.get("runtime.services.ice")
4576
- }), 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;
4577
4629
  this._signalManager = signalManager;
4578
4630
  invariant13(!this._networkManager, "network manager already set", {
4579
4631
  F: __dxlog_file17,
4580
- L: 192,
4632
+ L: 201,
4581
4633
  S: this,
4582
4634
  A: [
4583
4635
  "!this._networkManager",
@@ -4589,30 +4641,29 @@ var ClientServicesHost = class {
4589
4641
  transportFactory,
4590
4642
  signalManager
4591
4643
  });
4592
- log16.info("initialized", void 0, {
4644
+ log16("initialized", void 0, {
4593
4645
  F: __dxlog_file17,
4594
- L: 199,
4646
+ L: 208,
4595
4647
  S: this,
4596
4648
  C: (f, a) => f(...a)
4597
4649
  });
4598
4650
  }
4599
- async open() {
4600
- var _a, _b, _c;
4651
+ async open(ctx) {
4601
4652
  if (this._open) {
4602
4653
  return;
4603
4654
  }
4604
4655
  const traceId = PublicKey10.random().toHex();
4605
- log16.trace("dxos.client-services.host.open", trace6.begin({
4656
+ log16.trace("dxos.client-services.host.open", trace7.begin({
4606
4657
  id: traceId
4607
4658
  }), {
4608
4659
  F: __dxlog_file17,
4609
- L: 209,
4660
+ L: 219,
4610
4661
  S: this,
4611
4662
  C: (f, a) => f(...a)
4612
4663
  });
4613
4664
  invariant13(this._config, "config not set", {
4614
4665
  F: __dxlog_file17,
4615
- L: 211,
4666
+ L: 221,
4616
4667
  S: this,
4617
4668
  A: [
4618
4669
  "this._config",
@@ -4621,7 +4672,7 @@ var ClientServicesHost = class {
4621
4672
  });
4622
4673
  invariant13(this._storage, "storage not set", {
4623
4674
  F: __dxlog_file17,
4624
- L: 212,
4675
+ L: 222,
4625
4676
  S: this,
4626
4677
  A: [
4627
4678
  "this._storage",
@@ -4630,7 +4681,7 @@ var ClientServicesHost = class {
4630
4681
  });
4631
4682
  invariant13(this._signalManager, "signal manager not set", {
4632
4683
  F: __dxlog_file17,
4633
- L: 213,
4684
+ L: 223,
4634
4685
  S: this,
4635
4686
  A: [
4636
4687
  "this._signalManager",
@@ -4639,7 +4690,7 @@ var ClientServicesHost = class {
4639
4690
  });
4640
4691
  invariant13(this._networkManager, "network manager not set", {
4641
4692
  F: __dxlog_file17,
4642
- L: 214,
4693
+ L: 224,
4643
4694
  S: this,
4644
4695
  A: [
4645
4696
  "this._networkManager",
@@ -4647,20 +4698,20 @@ var ClientServicesHost = class {
4647
4698
  ]
4648
4699
  });
4649
4700
  this._opening = true;
4650
- log16.info("opening...", {
4651
- lockKey: (_a = this._resourceLock) == null ? void 0 : _a.lockKey
4701
+ log16("opening...", {
4702
+ lockKey: this._resourceLock?.lockKey
4652
4703
  }, {
4653
4704
  F: __dxlog_file17,
4654
- L: 217,
4705
+ L: 227,
4655
4706
  S: this,
4656
4707
  C: (f, a) => f(...a)
4657
4708
  });
4658
- await ((_b = this._resourceLock) == null ? void 0 : _b.acquire());
4709
+ await this._resourceLock?.acquire();
4659
4710
  await this._loggingService.open();
4660
4711
  this._serviceContext = new ServiceContext(this._storage, this._networkManager, this._signalManager, this._modelFactory);
4661
4712
  this._serviceRegistry.setServices({
4662
4713
  SystemService: this._systemService,
4663
- IdentityService: new IdentityServiceImpl(this._serviceContext),
4714
+ IdentityService: new IdentityServiceImpl((params) => this._serviceContext.createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring),
4664
4715
  InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitations, (invitation) => this._serviceContext.getInvitationHandler(invitation)),
4665
4716
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
4666
4717
  SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, this._serviceContext.dataServiceSubscriptions, async () => {
@@ -4670,6 +4721,7 @@ var ClientServicesHost = class {
4670
4721
  DataService: new DataServiceImpl(this._serviceContext.dataServiceSubscriptions),
4671
4722
  NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager, this._serviceContext.signalManager),
4672
4723
  LoggingService: this._loggingService,
4724
+ TracingService: this._tracingService,
4673
4725
  // TODO(burdon): Move to new protobuf definitions.
4674
4726
  DevtoolsHost: new DevtoolsServiceImpl({
4675
4727
  events: new DevtoolsHostEvents(),
@@ -4677,39 +4729,38 @@ var ClientServicesHost = class {
4677
4729
  context: this._serviceContext
4678
4730
  })
4679
4731
  });
4680
- await this._serviceContext.open();
4732
+ await this._serviceContext.open(ctx);
4681
4733
  this._opening = false;
4682
4734
  this._open = true;
4683
4735
  this._statusUpdate.emit();
4684
- const deviceKey = (_c = this._serviceContext.identityManager.identity) == null ? void 0 : _c.deviceKey;
4685
- log16.info("opened", {
4736
+ const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
4737
+ log16("opened", {
4686
4738
  deviceKey
4687
4739
  }, {
4688
4740
  F: __dxlog_file17,
4689
- L: 272,
4741
+ L: 284,
4690
4742
  S: this,
4691
4743
  C: (f, a) => f(...a)
4692
4744
  });
4693
- log16.trace("dxos.client-services.host.open", trace6.end({
4745
+ log16.trace("dxos.client-services.host.open", trace7.end({
4694
4746
  id: traceId
4695
4747
  }), {
4696
4748
  F: __dxlog_file17,
4697
- L: 273,
4749
+ L: 285,
4698
4750
  S: this,
4699
4751
  C: (f, a) => f(...a)
4700
4752
  });
4701
4753
  }
4702
4754
  async close() {
4703
- var _a;
4704
4755
  if (!this._open) {
4705
4756
  return;
4706
4757
  }
4707
- const deviceKey = (_a = this._serviceContext.identityManager.identity) == null ? void 0 : _a.deviceKey;
4708
- log16.info("closing...", {
4758
+ const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
4759
+ log16("closing...", {
4709
4760
  deviceKey
4710
4761
  }, {
4711
4762
  F: __dxlog_file17,
4712
- L: 283,
4763
+ L: 296,
4713
4764
  S: this,
4714
4765
  C: (f, a) => f(...a)
4715
4766
  });
@@ -4720,57 +4771,67 @@ var ClientServicesHost = class {
4720
4771
  await this._serviceContext.close();
4721
4772
  this._open = false;
4722
4773
  this._statusUpdate.emit();
4723
- log16.info("closed", {
4774
+ log16("closed", {
4724
4775
  deviceKey
4725
4776
  }, {
4726
4777
  F: __dxlog_file17,
4727
- L: 289,
4778
+ L: 302,
4728
4779
  S: this,
4729
4780
  C: (f, a) => f(...a)
4730
4781
  });
4731
4782
  }
4732
4783
  async reset() {
4733
- var _a, _b, _c;
4734
4784
  const traceId = PublicKey10.random().toHex();
4735
- log16.trace("dxos.sdk.client-services-host.reset", trace6.begin({
4785
+ log16.trace("dxos.sdk.client-services-host.reset", trace7.begin({
4736
4786
  id: traceId
4737
4787
  }), {
4738
4788
  F: __dxlog_file17,
4739
- L: 294,
4789
+ L: 307,
4740
4790
  S: this,
4741
4791
  C: (f, a) => f(...a)
4742
4792
  });
4743
4793
  log16("resetting...", void 0, {
4744
4794
  F: __dxlog_file17,
4745
- L: 296,
4795
+ L: 309,
4746
4796
  S: this,
4747
4797
  C: (f, a) => f(...a)
4748
4798
  });
4749
- await ((_a = this._serviceContext) == null ? void 0 : _a.close());
4799
+ await this._serviceContext?.close();
4750
4800
  await this._storage.reset();
4751
4801
  log16("reset", void 0, {
4752
4802
  F: __dxlog_file17,
4753
- L: 299,
4803
+ L: 312,
4754
4804
  S: this,
4755
4805
  C: (f, a) => f(...a)
4756
4806
  });
4757
- log16.trace("dxos.sdk.client-services-host.reset", trace6.end({
4807
+ log16.trace("dxos.sdk.client-services-host.reset", trace7.end({
4758
4808
  id: traceId
4759
4809
  }), {
4760
4810
  F: __dxlog_file17,
4761
- L: 300,
4811
+ L: 313,
4762
4812
  S: this,
4763
4813
  C: (f, a) => f(...a)
4764
4814
  });
4765
- await ((_c = (_b = this._callbacks) == null ? void 0 : _b.onReset) == null ? void 0 : _c.call(_b));
4815
+ await this._callbacks?.onReset?.();
4766
4816
  }
4767
4817
  };
4768
- _ts_decorate4([
4769
- 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()
4770
4827
  ], ClientServicesHost.prototype, "open", null);
4771
- _ts_decorate4([
4772
- synchronized3
4828
+ _ts_decorate7([
4829
+ synchronized3,
4830
+ Trace3.span()
4773
4831
  ], ClientServicesHost.prototype, "close", null);
4832
+ ClientServicesHost = _ts_decorate7([
4833
+ Trace3.resource()
4834
+ ], ClientServicesHost);
4774
4835
 
4775
4836
  export {
4776
4837
  subscribeToFeeds,
@@ -4805,4 +4866,4 @@ export {
4805
4866
  createDefaultModelFactory,
4806
4867
  ClientServicesHost
4807
4868
  };
4808
- //# sourceMappingURL=chunk-TPF4SOZO.mjs.map
4869
+ //# sourceMappingURL=chunk-KIT7RSH3.mjs.map