@dxos/client-services 0.1.56-main.5ff23aa → 0.1.56-main.6293c6e

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 (50) hide show
  1. package/dist/lib/browser/{chunk-MM7EFAUT.mjs → chunk-BD23GURE.mjs} +428 -366
  2. package/dist/lib/browser/chunk-BD23GURE.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +20 -23
  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 +443 -384
  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 +443 -392
  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/services/client-rpc-server.d.ts.map +1 -1
  20. package/dist/types/src/packlets/services/service-context.d.ts +2 -1
  21. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  22. package/dist/types/src/packlets/services/service-host.d.ts +3 -1
  23. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  24. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  25. package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts.map +1 -1
  26. package/dist/types/src/packlets/vault/worker-runtime.d.ts.map +1 -1
  27. package/dist/types/src/version.d.ts +1 -1
  28. package/package.json +34 -33
  29. package/src/packlets/devices/devices-service.test.ts +2 -1
  30. package/src/packlets/identity/identity-manager.test.ts +15 -3
  31. package/src/packlets/identity/identity-manager.ts +27 -6
  32. package/src/packlets/identity/identity-service.test.ts +17 -2
  33. package/src/packlets/identity/identity-service.ts +23 -14
  34. package/src/packlets/identity/identity.test.ts +7 -6
  35. package/src/packlets/identity/identity.ts +8 -3
  36. package/src/packlets/invitations/device-invitation-protocol.test.ts +2 -1
  37. package/src/packlets/network/network-service.test.ts +2 -1
  38. package/src/packlets/services/client-rpc-server.ts +4 -4
  39. package/src/packlets/services/service-context.test.ts +59 -0
  40. package/src/packlets/services/service-context.ts +14 -6
  41. package/src/packlets/services/service-host.test.ts +6 -5
  42. package/src/packlets/services/service-host.ts +26 -10
  43. package/src/packlets/services/service-registry.test.ts +2 -1
  44. package/src/packlets/spaces/data-space.ts +17 -5
  45. package/src/packlets/spaces/spaces-service.test.ts +2 -1
  46. package/src/packlets/testing/test-builder.ts +1 -1
  47. package/src/packlets/vault/iframe-host-runtime.ts +2 -1
  48. package/src/packlets/vault/worker-runtime.ts +2 -1
  49. package/src/version.ts +1 -1
  50. package/dist/lib/browser/chunk-MM7EFAUT.mjs.map +0 -7
@@ -75,7 +75,7 @@ var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
75
75
  const feedMap = new import_util.ComplexMap(import_keys.PublicKey.hash);
76
76
  const update = () => {
77
77
  const { feeds } = feedStore;
78
- feeds.filter((feed) => !(feedKeys == null ? void 0 : feedKeys.length) || feedKeys.some((feedKey) => feedKey.equals(feed.key))).forEach((feed) => {
78
+ feeds.filter((feed) => !feedKeys?.length || feedKeys.some((feedKey) => feedKey.equals(feed.key))).forEach((feed) => {
79
79
  if (!feedMap.has(feed.key)) {
80
80
  feedMap.set(feed.key, feed);
81
81
  feed.on("close", update);
@@ -83,15 +83,12 @@ var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
83
83
  }
84
84
  });
85
85
  next({
86
- feeds: Array.from(feedMap.values()).map((feed) => {
87
- var _a, _b;
88
- return {
89
- feedKey: feed.key,
90
- length: feed.properties.length,
91
- bytes: feed.core.byteLength,
92
- downloaded: (_b = (_a = feed.core.bitfield) == null ? void 0 : _a.data.toBuffer()) != null ? _b : new Uint8Array()
93
- };
94
- })
86
+ feeds: Array.from(feedMap.values()).map((feed) => ({
87
+ feedKey: feed.key,
88
+ length: feed.properties.length,
89
+ bytes: feed.core.byteLength,
90
+ downloaded: feed.core.bitfield?.data.toBuffer() ?? new Uint8Array()
91
+ }))
95
92
  });
96
93
  };
97
94
  subscriptions.add(feedStore.feedOpened.on(update));
@@ -191,13 +188,13 @@ var subscribeToSignal = ({ signalManager }) => new import_codec_protobuf4.Stream
191
188
  recipient: message.recipient.asUint8Array(),
192
189
  payload: message.payload
193
190
  },
194
- receivedAt: new Date()
191
+ receivedAt: /* @__PURE__ */ new Date()
195
192
  });
196
193
  });
197
194
  signalManager.swarmEvent.on(ctx, (swarmEvent) => {
198
195
  next({
199
196
  swarmEvent: swarmEvent.swarmEvent,
200
- receivedAt: new Date()
197
+ receivedAt: /* @__PURE__ */ new Date()
201
198
  });
202
199
  });
203
200
  return () => {
@@ -208,13 +205,10 @@ var subscribeToNetworkTopics = ({ networkManager }) => new import_codec_protobuf
208
205
  const update = () => {
209
206
  try {
210
207
  const topics = networkManager.topics;
211
- const labeledTopics = topics.map((topic) => {
212
- var _a, _b;
213
- return {
214
- topic,
215
- label: (_b = (_a = networkManager.getSwarm(topic)) == null ? void 0 : _a.label) != null ? _b : topic.toHex()
216
- };
217
- });
208
+ const labeledTopics = topics.map((topic) => ({
209
+ topic,
210
+ label: networkManager.getSwarm(topic)?.label ?? topic.toHex()
211
+ }));
218
212
  next({
219
213
  topics: labeledTopics
220
214
  });
@@ -226,17 +220,15 @@ var subscribeToNetworkTopics = ({ networkManager }) => new import_codec_protobuf
226
220
  update();
227
221
  });
228
222
  var subscribeToSwarmInfo = ({ networkManager }) => new import_codec_protobuf4.Stream(({ next }) => {
229
- var _a;
230
223
  const update = () => {
231
- var _a2;
232
- const info = (_a2 = networkManager.connectionLog) == null ? void 0 : _a2.swarms;
224
+ const info = networkManager.connectionLog?.swarms;
233
225
  if (info) {
234
226
  next({
235
227
  data: info
236
228
  });
237
229
  }
238
230
  };
239
- (_a = networkManager.connectionLog) == null ? void 0 : _a.update.on(update);
231
+ networkManager.connectionLog?.update.on(update);
240
232
  update();
241
233
  });
242
234
  var getNetworkPeers = ({ networkManager }, request) => {
@@ -245,7 +237,7 @@ var getNetworkPeers = ({ networkManager }, request) => {
245
237
  }
246
238
  const map = networkManager.getSwarmMap(import_keys2.PublicKey.from(request.topic));
247
239
  return {
248
- peers: map == null ? void 0 : map.peers.map((peer) => ({
240
+ peers: map?.peers.map((peer) => ({
249
241
  ...peer,
250
242
  connections: peer.connections.map((connection) => connection.asUint8Array())
251
243
  }))
@@ -261,14 +253,14 @@ var subscribeToSpaces = (context, { spaceKeys = [] }) => {
261
253
  const spaces = [
262
254
  ...context.spaceManager.spaces.values()
263
255
  ];
264
- const filteredSpaces = spaces.filter((space) => !(spaceKeys == null ? void 0 : spaceKeys.length) || spaceKeys.some((spaceKey) => spaceKey.equals(space.key)));
256
+ const filteredSpaces = spaces.filter((space) => !spaceKeys?.length || spaceKeys.some((spaceKey) => spaceKey.equals(space.key)));
265
257
  next({
266
258
  spaces: filteredSpaces.map((space) => {
267
259
  const spaceMetadata = context.metadataStore.spaces.find((spaceMetadata2) => spaceMetadata2.key.equals(space.key));
268
260
  return {
269
261
  key: space.key,
270
262
  isOpen: space.isOpen,
271
- timeframe: spaceMetadata == null ? void 0 : spaceMetadata.dataTimeframe,
263
+ timeframe: spaceMetadata?.dataTimeframe,
272
264
  genesisFeed: space.genesisFeedKey,
273
265
  controlFeed: space.controlFeedKey,
274
266
  dataFeed: space.dataFeedKey
@@ -282,7 +274,7 @@ var subscribeToSpaces = (context, { spaceKeys = [] }) => {
282
274
  await update();
283
275
  });
284
276
  return () => {
285
- unsubscribe == null ? void 0 : unsubscribe();
277
+ unsubscribe?.();
286
278
  clearTimeout(timeout);
287
279
  };
288
280
  });
@@ -313,16 +305,15 @@ var DevtoolsServiceImpl = class {
313
305
  };
314
306
  }
315
307
  async getStorageInfo() {
316
- var _a, _b, _c, _d, _e;
317
- const storageUsage = (_c = await ((_b = (_a = this.params.context.storage).getDiskInfo) == null ? void 0 : _b.call(_a))) != null ? _c : {
308
+ const storageUsage = await this.params.context.storage.getDiskInfo?.() ?? {
318
309
  used: 0
319
310
  };
320
311
  const navigatorInfo = typeof navigator === "object" ? await navigator.storage.estimate() : void 0;
321
312
  return {
322
313
  type: this.params.context.storage.type,
323
314
  storageUsage: storageUsage.used,
324
- originUsage: (_d = navigatorInfo == null ? void 0 : navigatorInfo.usage) != null ? _d : 0,
325
- usageQuota: (_e = navigatorInfo == null ? void 0 : navigatorInfo.quota) != null ? _e : 0
315
+ originUsage: navigatorInfo?.usage ?? 0,
316
+ usageQuota: navigatorInfo?.quota ?? 0
326
317
  };
327
318
  }
328
319
  async getBlobs() {
@@ -508,7 +499,7 @@ var TrustedKeySetAuthVerifier = class {
508
499
  return await trigger.wait({
509
500
  timeout: this._params.authTimeout
510
501
  });
511
- } catch (e) {
502
+ } catch {
512
503
  return false;
513
504
  } finally {
514
505
  clear();
@@ -530,8 +521,19 @@ var import_feed_store2 = require("@dxos/feed-store");
530
521
  var import_invariant = require("@dxos/invariant");
531
522
  var import_log2 = require("@dxos/log");
532
523
  var import_credentials3 = require("@dxos/protocols/proto/dxos/halo/credentials");
524
+ var import_tracing = require("@dxos/tracing");
525
+ function _ts_decorate(decorators, target, key, desc) {
526
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
527
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
528
+ r = Reflect.decorate(decorators, target, key, desc);
529
+ else
530
+ for (var i = decorators.length - 1; i >= 0; i--)
531
+ if (d = decorators[i])
532
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
533
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
534
+ }
533
535
  var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity.ts";
534
- var Identity = class {
536
+ var Identity = class Identity2 {
535
537
  constructor({ space, signer, identityKey, deviceKey }) {
536
538
  this.stateUpdate = new import_async5.Event();
537
539
  this.space = space;
@@ -557,12 +559,12 @@ var Identity = class {
557
559
  get authorizedDeviceKeys() {
558
560
  return this._deviceStateMachine.authorizedDeviceKeys;
559
561
  }
560
- async open() {
562
+ async open(ctx) {
561
563
  await this.space.spaceState.addCredentialProcessor(this._deviceStateMachine);
562
564
  await this.space.spaceState.addCredentialProcessor(this._profileStateMachine);
563
- await this.space.open();
565
+ await this.space.open(ctx);
564
566
  }
565
- async close() {
567
+ async close(ctx) {
566
568
  await this.authVerifier.close();
567
569
  await this.space.spaceState.removeCredentialProcessor(this._profileStateMachine);
568
570
  await this.space.spaceState.removeCredentialProcessor(this._deviceStateMachine);
@@ -593,11 +595,10 @@ var Identity = class {
593
595
  return this._deviceStateMachine.deviceCredentialChain;
594
596
  }
595
597
  getAdmissionCredentials() {
596
- var _a, _b;
597
598
  return {
598
599
  deviceKey: this.deviceKey,
599
- controlFeedKey: (_a = this.space.controlFeedKey) != null ? _a : (0, import_debug.failUndefined)(),
600
- dataFeedKey: (_b = this.space.dataFeedKey) != null ? _b : (0, import_debug.failUndefined)()
600
+ controlFeedKey: this.space.controlFeedKey ?? (0, import_debug.failUndefined)(),
601
+ dataFeedKey: this.space.dataFeedKey ?? (0, import_debug.failUndefined)()
601
602
  };
602
603
  }
603
604
  /**
@@ -607,7 +608,7 @@ var Identity = class {
607
608
  getIdentityCredentialSigner() {
608
609
  (0, import_invariant.invariant)(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.", {
609
610
  F: __dxlog_file2,
610
- L: 134,
611
+ L: 139,
611
612
  S: this,
612
613
  A: [
613
614
  "this._deviceStateMachine.deviceCredentialChain",
@@ -631,7 +632,7 @@ var Identity = class {
631
632
  dataFeedKey
632
633
  }, {
633
634
  F: __dxlog_file2,
634
- L: 150,
635
+ L: 155,
635
636
  S: this,
636
637
  C: (f, a) => f(...a)
637
638
  });
@@ -672,18 +673,40 @@ var Identity = class {
672
673
  })));
673
674
  }
674
675
  };
676
+ _ts_decorate([
677
+ import_tracing.trace.span()
678
+ ], Identity.prototype, "open", null);
679
+ _ts_decorate([
680
+ import_tracing.trace.span()
681
+ ], Identity.prototype, "close", null);
682
+ Identity = _ts_decorate([
683
+ import_tracing.trace.resource()
684
+ ], Identity);
675
685
 
676
686
  // packages/sdk/client-services/src/packlets/identity/identity-manager.ts
677
687
  var import_async6 = require("@dxos/async");
688
+ var import_context3 = require("@dxos/context");
678
689
  var import_credentials4 = require("@dxos/credentials");
679
690
  var import_invariant2 = require("@dxos/invariant");
680
691
  var import_keys4 = require("@dxos/keys");
681
692
  var import_log3 = require("@dxos/log");
682
693
  var import_protocols2 = require("@dxos/protocols");
683
694
  var import_credentials5 = require("@dxos/protocols/proto/dxos/halo/credentials");
695
+ var import_timeframe = require("@dxos/timeframe");
696
+ var import_tracing2 = require("@dxos/tracing");
684
697
  var import_util2 = require("@dxos/util");
698
+ function _ts_decorate2(decorators, target, key, desc) {
699
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
700
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
701
+ r = Reflect.decorate(decorators, target, key, desc);
702
+ else
703
+ for (var i = decorators.length - 1; i >= 0; i--)
704
+ if (d = decorators[i])
705
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
706
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
707
+ }
685
708
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-manager.ts";
686
- var IdentityManager = class {
709
+ var IdentityManager = class IdentityManager2 {
687
710
  // TODO(burdon): IdentityManagerParams.
688
711
  // TODO(dmaretskyi): Perhaps this should take/generate the peerKey outside of an initialized identity.
689
712
  constructor(_metadataStore, _keyring, _feedStore, _spaceManager) {
@@ -696,14 +719,13 @@ var IdentityManager = class {
696
719
  get identity() {
697
720
  return this._identity;
698
721
  }
699
- async open() {
700
- var _a;
722
+ async open(ctx) {
701
723
  const traceId = import_keys4.PublicKey.random().toHex();
702
724
  import_log3.log.trace("dxos.halo.identity-manager.open", import_protocols2.trace.begin({
703
725
  id: traceId
704
726
  }), {
705
727
  F: __dxlog_file3,
706
- L: 69,
728
+ L: 73,
707
729
  S: this,
708
730
  C: (f, a) => f(...a)
709
731
  });
@@ -713,20 +735,20 @@ var IdentityManager = class {
713
735
  identityRecord
714
736
  }, {
715
737
  F: __dxlog_file3,
716
- L: 73,
738
+ L: 77,
717
739
  S: this,
718
740
  C: (f, a) => f(...a)
719
741
  });
720
742
  if (identityRecord) {
721
743
  this._identity = await this._constructIdentity(identityRecord);
722
- await this._identity.open();
744
+ await this._identity.open(ctx);
723
745
  await this._identity.ready();
724
746
  import_log3.log.trace("dxos.halo.identity", {
725
747
  identityKey: identityRecord.identityKey,
726
- displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
748
+ displayName: this._identity.profileDocument?.displayName
727
749
  }, {
728
750
  F: __dxlog_file3,
729
- L: 78,
751
+ L: 82,
730
752
  S: this,
731
753
  C: (f, a) => f(...a)
732
754
  });
@@ -736,20 +758,18 @@ var IdentityManager = class {
736
758
  id: traceId
737
759
  }), {
738
760
  F: __dxlog_file3,
739
- L: 84,
761
+ L: 88,
740
762
  S: this,
741
763
  C: (f, a) => f(...a)
742
764
  });
743
765
  }
744
766
  async close() {
745
- var _a;
746
- await ((_a = this._identity) == null ? void 0 : _a.close());
767
+ await this._identity?.close(new import_context3.Context());
747
768
  }
748
769
  async createIdentity({ displayName } = {}) {
749
- var _a;
750
770
  (0, import_invariant2.invariant)(!this._identity, "Identity already exists.", {
751
771
  F: __dxlog_file3,
752
- L: 92,
772
+ L: 96,
753
773
  S: this,
754
774
  A: [
755
775
  "!this._identity",
@@ -758,7 +778,7 @@ var IdentityManager = class {
758
778
  });
759
779
  (0, import_log3.log)("creating identity...", void 0, {
760
780
  F: __dxlog_file3,
761
- L: 93,
781
+ L: 97,
762
782
  S: this,
763
783
  C: (f, a) => f(...a)
764
784
  });
@@ -774,12 +794,12 @@ var IdentityManager = class {
774
794
  }
775
795
  };
776
796
  const identity = await this._constructIdentity(identityRecord);
777
- await identity.open();
797
+ await identity.open(new import_context3.Context());
778
798
  {
779
799
  const generator = new import_credentials4.CredentialGenerator(this._keyring, identityRecord.identityKey, identityRecord.deviceKey);
780
800
  (0, import_invariant2.invariant)(identityRecord.haloSpace.genesisFeedKey, "Genesis feed key is required.", {
781
801
  F: __dxlog_file3,
782
- L: 112,
802
+ L: 116,
783
803
  S: this,
784
804
  A: [
785
805
  "identityRecord.haloSpace.genesisFeedKey",
@@ -788,7 +808,7 @@ var IdentityManager = class {
788
808
  });
789
809
  (0, import_invariant2.invariant)(identityRecord.haloSpace.dataFeedKey, "Data feed key is required.", {
790
810
  F: __dxlog_file3,
791
- L: 113,
811
+ L: 117,
792
812
  S: this,
793
813
  A: [
794
814
  "identityRecord.haloSpace.dataFeedKey",
@@ -820,10 +840,10 @@ var IdentityManager = class {
820
840
  await this._identity.ready();
821
841
  import_log3.log.trace("dxos.halo.identity", {
822
842
  identityKey: identityRecord.identityKey,
823
- displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
843
+ displayName: this._identity.profileDocument?.displayName
824
844
  }, {
825
845
  F: __dxlog_file3,
826
- L: 148,
846
+ L: 152,
827
847
  S: this,
828
848
  C: (f, a) => f(...a)
829
849
  });
@@ -833,7 +853,7 @@ var IdentityManager = class {
833
853
  deviceKey: identity.deviceKey
834
854
  }, {
835
855
  F: __dxlog_file3,
836
- L: 154,
856
+ L: 158,
837
857
  S: this,
838
858
  C: (f, a) => f(...a)
839
859
  });
@@ -843,18 +863,17 @@ var IdentityManager = class {
843
863
  * Accept an existing identity. Expects it's device key to be authorized (now or later).
844
864
  */
845
865
  async acceptIdentity(params) {
846
- var _a;
847
866
  (0, import_log3.log)("accepting identity", {
848
867
  params
849
868
  }, {
850
869
  F: __dxlog_file3,
851
- L: 162,
870
+ L: 166,
852
871
  S: this,
853
872
  C: (f, a) => f(...a)
854
873
  });
855
874
  (0, import_invariant2.invariant)(!this._identity, "Identity already exists.", {
856
875
  F: __dxlog_file3,
857
- L: 163,
876
+ L: 167,
858
877
  S: this,
859
878
  A: [
860
879
  "!this._identity",
@@ -873,16 +892,16 @@ var IdentityManager = class {
873
892
  }
874
893
  };
875
894
  const identity = await this._constructIdentity(identityRecord);
876
- await identity.open();
895
+ await identity.open(new import_context3.Context());
877
896
  this._identity = identity;
878
897
  await this._metadataStore.setIdentityRecord(identityRecord);
879
898
  await this._identity.ready();
880
899
  import_log3.log.trace("dxos.halo.identity", {
881
900
  identityKey: identityRecord.identityKey,
882
- displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
901
+ displayName: this._identity.profileDocument?.displayName
883
902
  }, {
884
903
  F: __dxlog_file3,
885
- L: 182,
904
+ L: 186,
886
905
  S: this,
887
906
  C: (f, a) => f(...a)
888
907
  });
@@ -892,16 +911,48 @@ var IdentityManager = class {
892
911
  deviceKey: identity.deviceKey
893
912
  }, {
894
913
  F: __dxlog_file3,
895
- L: 188,
914
+ L: 192,
896
915
  S: this,
897
916
  C: (f, a) => f(...a)
898
917
  });
899
918
  return identity;
900
919
  }
920
+ /**
921
+ * Update the profile document of an existing identity.
922
+ */
923
+ async updateProfile(profile) {
924
+ (0, import_invariant2.invariant)(this._identity, "Identity not initialized.", {
925
+ F: __dxlog_file3,
926
+ L: 200,
927
+ S: this,
928
+ A: [
929
+ "this._identity",
930
+ "'Identity not initialized.'"
931
+ ]
932
+ });
933
+ const credential = await this._identity.getIdentityCredentialSigner().createCredential({
934
+ subject: this._identity.identityKey,
935
+ assertion: {
936
+ "@type": "dxos.halo.credentials.IdentityProfile",
937
+ profile
938
+ }
939
+ });
940
+ const receipt = await this._identity.controlPipeline.writer.write({
941
+ credential: {
942
+ credential
943
+ }
944
+ });
945
+ await this._identity.controlPipeline.state.waitUntilTimeframe(new import_timeframe.Timeframe([
946
+ [
947
+ receipt.feedKey,
948
+ receipt.seq
949
+ ]
950
+ ]));
951
+ }
901
952
  async _constructIdentity(identityRecord) {
902
953
  (0, import_invariant2.invariant)(!this._identity, void 0, {
903
954
  F: __dxlog_file3,
904
- L: 193,
955
+ L: 214,
905
956
  S: this,
906
957
  A: [
907
958
  "!this._identity",
@@ -912,13 +963,13 @@ var IdentityManager = class {
912
963
  identityRecord
913
964
  }, {
914
965
  F: __dxlog_file3,
915
- L: 194,
966
+ L: 215,
916
967
  S: this,
917
968
  C: (f, a) => f(...a)
918
969
  });
919
970
  (0, import_invariant2.invariant)(identityRecord.haloSpace.controlFeedKey, void 0, {
920
971
  F: __dxlog_file3,
921
- L: 197,
972
+ L: 218,
922
973
  S: this,
923
974
  A: [
924
975
  "identityRecord.haloSpace.controlFeedKey",
@@ -930,7 +981,7 @@ var IdentityManager = class {
930
981
  });
931
982
  (0, import_invariant2.invariant)(identityRecord.haloSpace.dataFeedKey, void 0, {
932
983
  F: __dxlog_file3,
933
- L: 201,
984
+ L: 222,
934
985
  S: this,
935
986
  A: [
936
987
  "identityRecord.haloSpace.dataFeedKey",
@@ -962,7 +1013,7 @@ var IdentityManager = class {
962
1013
  identityKey: identityRecord.identityKey
963
1014
  }, {
964
1015
  F: __dxlog_file3,
965
- L: 225,
1016
+ L: 246,
966
1017
  S: this,
967
1018
  C: (f, a) => f(...a)
968
1019
  });
@@ -983,7 +1034,7 @@ var IdentityManager = class {
983
1034
  onAuthFailure: () => {
984
1035
  import_log3.log.warn("auth failure", void 0, {
985
1036
  F: __dxlog_file3,
986
- L: 244,
1037
+ L: 265,
987
1038
  S: this,
988
1039
  C: (f, a) => f(...a)
989
1040
  });
@@ -992,6 +1043,12 @@ var IdentityManager = class {
992
1043
  });
993
1044
  }
994
1045
  };
1046
+ _ts_decorate2([
1047
+ import_tracing2.trace.span()
1048
+ ], IdentityManager.prototype, "open", null);
1049
+ IdentityManager = _ts_decorate2([
1050
+ import_tracing2.trace.resource()
1051
+ ], IdentityManager);
995
1052
 
996
1053
  // packages/sdk/client-services/src/packlets/identity/identity-service.ts
997
1054
  var import_codec_protobuf7 = require("@dxos/codec-protobuf");
@@ -1000,12 +1057,13 @@ var import_debug2 = require("@dxos/debug");
1000
1057
  var import_invariant3 = require("@dxos/invariant");
1001
1058
  var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
1002
1059
  var IdentityServiceImpl = class {
1003
- // TODO(wittjosiah): Remove dependency on service context.
1004
- constructor(_serviceContext) {
1005
- this._serviceContext = _serviceContext;
1060
+ constructor(_createIdentity, _identityManager, _keyring) {
1061
+ this._createIdentity = _createIdentity;
1062
+ this._identityManager = _identityManager;
1063
+ this._keyring = _keyring;
1006
1064
  }
1007
1065
  async createIdentity(request) {
1008
- await this._serviceContext.createIdentity(request);
1066
+ await this._createIdentity(request);
1009
1067
  return this._getIdentity();
1010
1068
  }
1011
1069
  async recoverIdentity(request) {
@@ -1017,34 +1075,47 @@ var IdentityServiceImpl = class {
1017
1075
  identity: this._getIdentity()
1018
1076
  });
1019
1077
  emitNext();
1020
- return this._serviceContext.identityManager.stateUpdate.on(emitNext);
1078
+ return this._identityManager.stateUpdate.on(emitNext);
1021
1079
  });
1022
1080
  }
1023
1081
  _getIdentity() {
1024
- if (!this._serviceContext.identityManager.identity) {
1082
+ if (!this._identityManager.identity) {
1025
1083
  return void 0;
1026
1084
  }
1027
1085
  return {
1028
- identityKey: this._serviceContext.identityManager.identity.identityKey,
1029
- spaceKey: this._serviceContext.identityManager.identity.space.key,
1030
- profile: this._serviceContext.identityManager.identity.profileDocument
1086
+ identityKey: this._identityManager.identity.identityKey,
1087
+ spaceKey: this._identityManager.identity.space.key,
1088
+ profile: this._identityManager.identity.profileDocument
1031
1089
  };
1032
1090
  }
1091
+ async updateProfile(profile) {
1092
+ (0, import_invariant3.invariant)(this._identityManager.identity, "Identity not initialized.", {
1093
+ F: __dxlog_file4,
1094
+ L: 59,
1095
+ S: this,
1096
+ A: [
1097
+ "this._identityManager.identity",
1098
+ "'Identity not initialized.'"
1099
+ ]
1100
+ });
1101
+ await this._identityManager.updateProfile(profile);
1102
+ return this._getIdentity();
1103
+ }
1033
1104
  async signPresentation({ presentation, nonce }) {
1034
- (0, import_invariant3.invariant)(this._serviceContext.identityManager.identity, "Identity not initialized.", {
1105
+ (0, import_invariant3.invariant)(this._identityManager.identity, "Identity not initialized.", {
1035
1106
  F: __dxlog_file4,
1036
- L: 56,
1107
+ L: 65,
1037
1108
  S: this,
1038
1109
  A: [
1039
- "this._serviceContext.identityManager.identity",
1110
+ "this._identityManager.identity",
1040
1111
  "'Identity not initialized.'"
1041
1112
  ]
1042
1113
  });
1043
1114
  return await (0, import_credentials6.signPresentation)({
1044
1115
  presentation,
1045
- signer: this._serviceContext.keyring,
1046
- signerKey: this._serviceContext.identityManager.identity.deviceKey,
1047
- chain: this._serviceContext.identityManager.identity.deviceCredentialChain,
1116
+ signer: this._keyring,
1117
+ signerKey: this._identityManager.identity.deviceKey,
1118
+ chain: this._identityManager.identity.deviceCredentialChain,
1048
1119
  nonce
1049
1120
  });
1050
1121
  }
@@ -1143,7 +1214,7 @@ var DeviceInvitationProtocol = class {
1143
1214
  // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
1144
1215
  var import_async8 = require("@dxos/async");
1145
1216
  var import_client_protocol2 = require("@dxos/client-protocol");
1146
- var import_context4 = require("@dxos/context");
1217
+ var import_context5 = require("@dxos/context");
1147
1218
  var import_credentials7 = require("@dxos/credentials");
1148
1219
  var import_errors2 = require("@dxos/errors");
1149
1220
  var import_invariant6 = require("@dxos/invariant");
@@ -1156,7 +1227,7 @@ var import_invitations2 = require("@dxos/protocols/proto/dxos/halo/invitations")
1156
1227
 
1157
1228
  // packages/sdk/client-services/src/packlets/invitations/invitation-extension.ts
1158
1229
  var import_async7 = require("@dxos/async");
1159
- var import_context3 = require("@dxos/context");
1230
+ var import_context4 = require("@dxos/context");
1160
1231
  var import_errors = require("@dxos/errors");
1161
1232
  var import_invariant5 = require("@dxos/invariant");
1162
1233
  var import_keys5 = require("@dxos/keys");
@@ -1179,7 +1250,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1179
1250
  }
1180
1251
  });
1181
1252
  this._callbacks = _callbacks;
1182
- this._ctx = new import_context3.Context();
1253
+ this._ctx = new import_context4.Context();
1183
1254
  this._remoteOptionsTrigger = new import_async7.Trigger();
1184
1255
  this.invitation = void 0;
1185
1256
  this.guestProfile = void 0;
@@ -1380,16 +1451,15 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1380
1451
  };
1381
1452
  }
1382
1453
  async onOpen(context) {
1383
- var _a;
1384
1454
  await super.onOpen(context);
1385
1455
  try {
1386
1456
  await this.rpc.InvitationHostService.options({
1387
1457
  role: import_invitations.Options.Role.HOST
1388
1458
  });
1389
- await (0, import_context3.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
1459
+ await (0, import_context4.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
1390
1460
  timeout: OPTIONS_TIMEOUT
1391
1461
  }));
1392
- if (((_a = this._remoteOptions) == null ? void 0 : _a.role) !== import_invitations.Options.Role.GUEST) {
1462
+ if (this._remoteOptions?.role !== import_invitations.Options.Role.GUEST) {
1393
1463
  throw new import_errors.InvalidInvitationExtensionRoleError(void 0, {
1394
1464
  expected: import_invitations.Options.Role.GUEST,
1395
1465
  remoteOptions: this._remoteOptions
@@ -1415,7 +1485,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1415
1485
  }
1416
1486
  });
1417
1487
  this._callbacks = _callbacks;
1418
- this._ctx = new import_context3.Context();
1488
+ this._ctx = new import_context4.Context();
1419
1489
  this._remoteOptionsTrigger = new import_async7.Trigger();
1420
1490
  }
1421
1491
  async getHandlers() {
@@ -1447,7 +1517,6 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1447
1517
  };
1448
1518
  }
1449
1519
  async onOpen(context) {
1450
- var _a;
1451
1520
  await super.onOpen(context);
1452
1521
  try {
1453
1522
  (0, import_log4.log)("begin options", void 0, {
@@ -1456,10 +1525,10 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1456
1525
  S: this,
1457
1526
  C: (f, a) => f(...a)
1458
1527
  });
1459
- await (0, import_context3.cancelWithContext)(this._ctx, this.rpc.InvitationHostService.options({
1528
+ await (0, import_context4.cancelWithContext)(this._ctx, this.rpc.InvitationHostService.options({
1460
1529
  role: import_invitations.Options.Role.GUEST
1461
1530
  }));
1462
- await (0, import_context3.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
1531
+ await (0, import_context4.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
1463
1532
  timeout: OPTIONS_TIMEOUT
1464
1533
  }));
1465
1534
  (0, import_log4.log)("end options", void 0, {
@@ -1468,7 +1537,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1468
1537
  S: this,
1469
1538
  C: (f, a) => f(...a)
1470
1539
  });
1471
- if (((_a = this._remoteOptions) == null ? void 0 : _a.role) !== import_invitations.Options.Role.HOST) {
1540
+ if (this._remoteOptions?.role !== import_invitations.Options.Role.HOST) {
1472
1541
  throw new import_errors.InvalidInvitationExtensionRoleError(void 0, {
1473
1542
  expected: import_invitations.Options.Role.HOST,
1474
1543
  remoteOptions: this._remoteOptions
@@ -1507,9 +1576,8 @@ var InvitationsHandler = class {
1507
1576
  this._networkManager = _networkManager;
1508
1577
  }
1509
1578
  createInvitation(protocol, options) {
1510
- var _a;
1511
- const { invitationId = import_keys6.PublicKey.random().toHex(), type = import_services3.Invitation.Type.INTERACTIVE, authMethod = import_services3.Invitation.AuthMethod.SHARED_SECRET, state = import_services3.Invitation.State.INIT, timeout = import_client_protocol2.INVITATION_TIMEOUT, swarmKey = import_keys6.PublicKey.random() } = options != null ? options : {};
1512
- const authCode = (_a = options == null ? void 0 : options.authCode) != null ? _a : authMethod === import_services3.Invitation.AuthMethod.SHARED_SECRET ? (0, import_credentials7.generatePasscode)(import_client_protocol2.AUTHENTICATION_CODE_LENGTH) : void 0;
1579
+ const { invitationId = import_keys6.PublicKey.random().toHex(), type = import_services3.Invitation.Type.INTERACTIVE, authMethod = import_services3.Invitation.AuthMethod.SHARED_SECRET, state = import_services3.Invitation.State.INIT, timeout = import_client_protocol2.INVITATION_TIMEOUT, swarmKey = import_keys6.PublicKey.random() } = options ?? {};
1580
+ const authCode = options?.authCode ?? (authMethod === import_services3.Invitation.AuthMethod.SHARED_SECRET ? (0, import_credentials7.generatePasscode)(import_client_protocol2.AUTHENTICATION_CODE_LENGTH) : void 0);
1513
1581
  (0, import_invariant6.invariant)(protocol, void 0, {
1514
1582
  F: __dxlog_file7,
1515
1583
  L: 76,
@@ -1530,7 +1598,7 @@ var InvitationsHandler = class {
1530
1598
  ...protocol.getInvitationContext()
1531
1599
  };
1532
1600
  const stream = new import_async8.PushStream();
1533
- const ctx = new import_context4.Context({
1601
+ const ctx = new import_context5.Context({
1534
1602
  onError: (err) => {
1535
1603
  void ctx.dispose();
1536
1604
  stream.error(err);
@@ -1562,9 +1630,8 @@ var InvitationsHandler = class {
1562
1630
  return invitation;
1563
1631
  },
1564
1632
  admit: async (admissionRequest) => {
1565
- var _a2, _b, _c;
1566
1633
  try {
1567
- const deviceKey = (_c = (_a2 = admissionRequest.device) == null ? void 0 : _a2.deviceKey) != null ? _c : (_b = admissionRequest.space) == null ? void 0 : _b.deviceKey;
1634
+ const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
1568
1635
  (0, import_invariant6.invariant)(deviceKey, void 0, {
1569
1636
  F: __dxlog_file7,
1570
1637
  L: 119,
@@ -1761,7 +1828,7 @@ var InvitationsHandler = class {
1761
1828
  ...newData
1762
1829
  });
1763
1830
  };
1764
- const ctx = new import_context4.Context({
1831
+ const ctx = new import_context5.Context({
1765
1832
  onError: (err) => {
1766
1833
  if (err instanceof import_async8.TimeoutError) {
1767
1834
  (0, import_log5.log)("timeout", {
@@ -2263,7 +2330,6 @@ var SpaceInvitationProtocol = class {
2263
2330
  };
2264
2331
  }
2265
2332
  async admit(request, guestProfile) {
2266
- var _a;
2267
2333
  (0, import_invariant8.invariant)(this._spaceKey, void 0, {
2268
2334
  F: __dxlog_file9,
2269
2335
  L: 42,
@@ -2327,7 +2393,7 @@ var SpaceInvitationProtocol = class {
2327
2393
  space: {
2328
2394
  credential: spaceMemberCredential,
2329
2395
  controlTimeframe: space.inner.controlPipeline.state.timeframe,
2330
- dataTimeframe: (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.timeframe
2396
+ dataTimeframe: space.dataPipeline.pipelineState?.timeframe
2331
2397
  }
2332
2398
  };
2333
2399
  }
@@ -2431,9 +2497,8 @@ var ClientRpcServer = class {
2431
2497
  await this._rpcPeer.close();
2432
2498
  }
2433
2499
  _getServiceHandler(serviceName) {
2434
- var _a;
2435
2500
  if (!this._handlerCache.has(serviceName)) {
2436
- const [key, descriptor] = (_a = Object.entries(this._serviceRegistry.descriptors).find(([key2, descriptor2]) => descriptor2.name === serviceName)) != null ? _a : (0, import_debug3.raise)(new Error(`Service not available: ${serviceName}`));
2501
+ const [key, descriptor] = Object.entries(this._serviceRegistry.descriptors).find(([key2, descriptor2]) => descriptor2.name === serviceName) ?? (0, import_debug3.raise)(new Error(`Service not available: ${serviceName}`));
2437
2502
  const service = this._serviceRegistry.services[key];
2438
2503
  if (!service) {
2439
2504
  throw new Error(`Service not available: ${serviceName}`);
@@ -2454,7 +2519,7 @@ var import_protocols5 = require("@dxos/protocols");
2454
2519
  var import_services6 = require("@dxos/protocols/proto/dxos/client/services");
2455
2520
 
2456
2521
  // packages/sdk/client-services/src/version.ts
2457
- var DXOS_VERSION = "0.1.56-main.5ff23aa";
2522
+ var DXOS_VERSION = "0.1.56-main.6293c6e";
2458
2523
 
2459
2524
  // packages/sdk/client-services/src/packlets/services/platform.ts
2460
2525
  var getPlatform = () => {
@@ -2488,9 +2553,8 @@ var getPlatform = () => {
2488
2553
  var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
2489
2554
  var DEFAULT_TIMEOUT = 1e3;
2490
2555
  var createDiagnostics = async (clientServices, serviceContext, config) => {
2491
- var _a, _b, _c;
2492
2556
  const diagnostics = {
2493
- created: new Date().toISOString(),
2557
+ created: (/* @__PURE__ */ new Date()).toISOString(),
2494
2558
  platform: getPlatform(),
2495
2559
  client: {
2496
2560
  version: DXOS_VERSION,
@@ -2520,16 +2584,16 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
2520
2584
  spaceKey: identity.space.key,
2521
2585
  profile: identity.profileDocument
2522
2586
  };
2523
- const { devices } = (_a = await (0, import_codec_protobuf10.getFirstStreamValue)(clientServices.DevicesService.queryDevices(), {
2587
+ const { devices } = await (0, import_codec_protobuf10.getFirstStreamValue)(clientServices.DevicesService.queryDevices(), {
2524
2588
  timeout: DEFAULT_TIMEOUT
2525
- }).catch(() => void 0)) != null ? _a : {};
2589
+ }).catch(() => void 0) ?? {};
2526
2590
  diagnostics.devices = devices;
2527
2591
  if (serviceContext.dataSpaceManager) {
2528
- diagnostics.spaces = await Promise.all((_b = Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space))) != null ? _b : []);
2592
+ diagnostics.spaces = await Promise.all(Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space)) ?? []);
2529
2593
  }
2530
- const { feeds = [] } = (_c = await (0, import_codec_protobuf10.getFirstStreamValue)(clientServices.DevtoolsHost.subscribeToFeeds({}), {
2594
+ const { feeds = [] } = await (0, import_codec_protobuf10.getFirstStreamValue)(clientServices.DevtoolsHost.subscribeToFeeds({}), {
2531
2595
  timeout: DEFAULT_TIMEOUT
2532
- }).catch(() => void 0)) != null ? _c : {};
2596
+ }).catch(() => void 0) ?? {};
2533
2597
  diagnostics.feeds = feeds.map(({ feedKey, bytes, length }) => ({
2534
2598
  feedKey,
2535
2599
  bytes,
@@ -2542,12 +2606,9 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
2542
2606
  var getProperties = (space) => {
2543
2607
  let properties = {};
2544
2608
  try {
2545
- const propertiesItem = space.dataPipeline.itemManager.items.find((item) => {
2546
- var _a, _b;
2547
- return ((_a = item.modelMeta) == null ? void 0 : _a.type) === import_document_model.DocumentModel.meta.type && ((_b = item.state) == null ? void 0 : _b.type) === "dxos.sdk.client.Properties";
2548
- });
2549
- const state = propertiesItem == null ? void 0 : propertiesItem.state;
2550
- properties = state == null ? void 0 : state.data;
2609
+ const propertiesItem = space.dataPipeline.itemManager.items.find((item) => item.modelMeta?.type === import_document_model.DocumentModel.meta.type && item.state?.type === "dxos.sdk.client.Properties");
2610
+ const state = propertiesItem?.state;
2611
+ properties = state?.data;
2551
2612
  } catch (err) {
2552
2613
  import_log8.log.warn(err.message, void 0, {
2553
2614
  F: __dxlog_file10,
@@ -2559,7 +2620,6 @@ var getProperties = (space) => {
2559
2620
  return properties;
2560
2621
  };
2561
2622
  var getSpaceStats = async (space) => {
2562
- var _a, _b, _c, _d, _e, _f;
2563
2623
  const stats = {
2564
2624
  key: space.key,
2565
2625
  metrics: space.metrics,
@@ -2567,18 +2627,15 @@ var getSpaceStats = async (space) => {
2567
2627
  ...credential.subject.assertion,
2568
2628
  id: credential.id
2569
2629
  })),
2570
- members: Array.from(space.inner.spaceState.members.values()).map((member) => {
2571
- var _a2;
2572
- return {
2573
- identity: {
2574
- identityKey: member.key,
2575
- profile: {
2576
- displayName: (_a2 = member.assertion.profile) == null ? void 0 : _a2.displayName
2577
- }
2578
- },
2579
- presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? import_services6.SpaceMember.PresenceState.ONLINE : import_services6.SpaceMember.PresenceState.OFFLINE
2580
- };
2581
- }),
2630
+ members: Array.from(space.inner.spaceState.members.values()).map((member) => ({
2631
+ identity: {
2632
+ identityKey: member.key,
2633
+ profile: {
2634
+ displayName: member.assertion.profile?.displayName
2635
+ }
2636
+ },
2637
+ presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? import_services6.SpaceMember.PresenceState.ONLINE : import_services6.SpaceMember.PresenceState.OFFLINE
2638
+ })),
2582
2639
  pipeline: {
2583
2640
  // TODO(burdon): Pick properties from credentials if needed.
2584
2641
  // currentEpoch: space.dataPipeline.currentEpoch,
@@ -2588,11 +2645,11 @@ var getSpaceStats = async (space) => {
2588
2645
  targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
2589
2646
  totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe,
2590
2647
  // TODO(burdon): Empty?
2591
- dataFeeds: (_b = (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.feeds.map((feed) => feed.key)) != null ? _b : [],
2592
- startDataTimeframe: (_c = space.dataPipeline.pipelineState) == null ? void 0 : _c.startTimeframe,
2593
- currentDataTimeframe: (_d = space.dataPipeline.pipelineState) == null ? void 0 : _d.timeframe,
2594
- targetDataTimeframe: (_e = space.dataPipeline.pipelineState) == null ? void 0 : _e.targetTimeframe,
2595
- totalDataTimeframe: (_f = space.dataPipeline.pipelineState) == null ? void 0 : _f.endTimeframe
2648
+ dataFeeds: space.dataPipeline.pipelineState?.feeds.map((feed) => feed.key) ?? [],
2649
+ startDataTimeframe: space.dataPipeline.pipelineState?.startTimeframe,
2650
+ currentDataTimeframe: space.dataPipeline.pipelineState?.timeframe,
2651
+ targetDataTimeframe: space.dataPipeline.pipelineState?.targetTimeframe,
2652
+ totalDataTimeframe: space.dataPipeline.pipelineState?.endTimeframe
2596
2653
  }
2597
2654
  };
2598
2655
  if (space.dataPipeline.itemManager) {
@@ -2612,6 +2669,7 @@ var getSpaceStats = async (space) => {
2612
2669
 
2613
2670
  // packages/sdk/client-services/src/packlets/services/service-context.ts
2614
2671
  var import_async14 = require("@dxos/async");
2672
+ var import_context9 = require("@dxos/context");
2615
2673
  var import_credentials14 = require("@dxos/credentials");
2616
2674
  var import_debug7 = require("@dxos/debug");
2617
2675
  var import_echo_pipeline3 = require("@dxos/echo-pipeline");
@@ -2623,10 +2681,12 @@ var import_log13 = require("@dxos/log");
2623
2681
  var import_protocols9 = require("@dxos/protocols");
2624
2682
  var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
2625
2683
  var import_teleport_extension_object_sync = require("@dxos/teleport-extension-object-sync");
2684
+ var import_tracing3 = require("@dxos/tracing");
2685
+ var import_util7 = require("@dxos/util");
2626
2686
 
2627
2687
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
2628
2688
  var import_async12 = require("@dxos/async");
2629
- var import_context7 = require("@dxos/context");
2689
+ var import_context8 = require("@dxos/context");
2630
2690
  var import_credentials13 = require("@dxos/credentials");
2631
2691
  var import_invariant11 = require("@dxos/invariant");
2632
2692
  var import_keys9 = require("@dxos/keys");
@@ -2639,7 +2699,7 @@ var import_util5 = require("@dxos/util");
2639
2699
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2640
2700
  var import_async11 = require("@dxos/async");
2641
2701
  var import_client_protocol3 = require("@dxos/client-protocol");
2642
- var import_context6 = require("@dxos/context");
2702
+ var import_context7 = require("@dxos/context");
2643
2703
  var import_debug4 = require("@dxos/debug");
2644
2704
  var import_echo_pipeline = require("@dxos/echo-pipeline");
2645
2705
  var import_errors3 = require("@dxos/errors");
@@ -2647,12 +2707,12 @@ var import_keys8 = require("@dxos/keys");
2647
2707
  var import_log10 = require("@dxos/log");
2648
2708
  var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
2649
2709
  var import_credentials10 = require("@dxos/protocols/proto/dxos/halo/credentials");
2650
- var import_timeframe = require("@dxos/timeframe");
2710
+ var import_timeframe2 = require("@dxos/timeframe");
2651
2711
  var import_util4 = require("@dxos/util");
2652
2712
 
2653
2713
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
2654
2714
  var import_async10 = require("@dxos/async");
2655
- var import_context5 = require("@dxos/context");
2715
+ var import_context6 = require("@dxos/context");
2656
2716
  var import_invariant10 = require("@dxos/invariant");
2657
2717
  var import_keys7 = require("@dxos/keys");
2658
2718
  var import_log9 = require("@dxos/log");
@@ -2666,7 +2726,7 @@ var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
2666
2726
  var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
2667
2727
  var NotarizationPlugin = class {
2668
2728
  constructor() {
2669
- this._ctx = new import_context5.Context();
2729
+ this._ctx = new import_context6.Context();
2670
2730
  this._extensionOpened = new import_async10.Event();
2671
2731
  this._extensions = /* @__PURE__ */ new Set();
2672
2732
  this._processedCredentials = new import_util3.ComplexSet(import_keys7.PublicKey.hash);
@@ -2716,7 +2776,7 @@ var NotarizationPlugin = class {
2716
2776
  errors.throw(err);
2717
2777
  }
2718
2778
  });
2719
- opCtx == null ? void 0 : opCtx.onDispose(() => ctx.dispose());
2779
+ opCtx?.onDispose(() => ctx.dispose());
2720
2780
  if (timeout !== 0) {
2721
2781
  (0, import_async10.scheduleTask)(ctx, () => {
2722
2782
  import_log9.log.warn("Notarization timeout", {
@@ -2791,7 +2851,7 @@ var NotarizationPlugin = class {
2791
2851
  this._extensionOpened.on(ctx, () => notarizeTask.schedule());
2792
2852
  try {
2793
2853
  await Promise.race([
2794
- (0, import_context5.rejectOnDispose)(ctx),
2854
+ (0, import_context6.rejectOnDispose)(ctx),
2795
2855
  allNotarized,
2796
2856
  errors.wait()
2797
2857
  ]);
@@ -2809,11 +2869,10 @@ var NotarizationPlugin = class {
2809
2869
  * Called with credentials arriving from the control pipeline.
2810
2870
  */
2811
2871
  async processCredential(credential) {
2812
- var _a;
2813
2872
  if (!credential.id) {
2814
2873
  return;
2815
2874
  }
2816
- (_a = this._processCredentialsTriggers.get(credential.id)) == null ? void 0 : _a.wake();
2875
+ this._processCredentialsTriggers.get(credential.id)?.wake();
2817
2876
  this._processedCredentials.add(credential.id);
2818
2877
  this._processCredentialsTriggers.delete(credential.id);
2819
2878
  }
@@ -2839,11 +2898,10 @@ var NotarizationPlugin = class {
2839
2898
  * Requests from other peers to notarize credentials.
2840
2899
  */
2841
2900
  async _onNotarize(request) {
2842
- var _a;
2843
2901
  if (!this._writer) {
2844
2902
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
2845
2903
  }
2846
- for (const credential of (_a = request.credentials) != null ? _a : []) {
2904
+ for (const credential of request.credentials ?? []) {
2847
2905
  (0, import_invariant10.invariant)(credential.id, "Credential must have an id", {
2848
2906
  F: __dxlog_file11,
2849
2907
  L: 200,
@@ -2921,7 +2979,7 @@ var NotarizationTeleportExtension = class extends import_teleport2.RpcExtension
2921
2979
  };
2922
2980
 
2923
2981
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2924
- function _ts_decorate(decorators, target, key, desc) {
2982
+ function _ts_decorate3(decorators, target, key, desc) {
2925
2983
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2926
2984
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2927
2985
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2932,9 +2990,10 @@ function _ts_decorate(decorators, target, key, desc) {
2932
2990
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2933
2991
  }
2934
2992
  var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
2993
+ var ENABLE_FEED_PURGE = false;
2935
2994
  var DataSpace = class DataSpace2 {
2936
2995
  constructor(params) {
2937
- this._ctx = new import_context6.Context();
2996
+ this._ctx = new import_context7.Context();
2938
2997
  this._notarizationPlugin = new NotarizationPlugin();
2939
2998
  this._state = import_services7.SpaceState.CLOSED;
2940
2999
  /**
@@ -2943,7 +3002,6 @@ var DataSpace = class DataSpace2 {
2943
3002
  this.error = void 0;
2944
3003
  this.stateUpdate = new import_async11.Event();
2945
3004
  this.metrics = {};
2946
- var _a;
2947
3005
  this._inner = params.inner;
2948
3006
  this._inner.stateUpdate.on(this._ctx, () => this.stateUpdate.emit());
2949
3007
  this._gossip = params.gossip;
@@ -2952,7 +3010,7 @@ var DataSpace = class DataSpace2 {
2952
3010
  this._feedStore = params.feedStore;
2953
3011
  this._metadataStore = params.metadataStore;
2954
3012
  this._signingContext = params.signingContext;
2955
- this._callbacks = (_a = params.callbacks) != null ? _a : {};
3013
+ this._callbacks = params.callbacks ?? {};
2956
3014
  this.authVerifier = new TrustedKeySetAuthVerifier({
2957
3015
  trustedKeysProvider: () => new import_util4.ComplexSet(import_keys8.PublicKey.hash, Array.from(this._inner.spaceState.members.keys())),
2958
3016
  update: this._inner.stateUpdate,
@@ -2992,21 +3050,20 @@ var DataSpace = class DataSpace2 {
2992
3050
  async _open() {
2993
3051
  await this._notarizationPlugin.open();
2994
3052
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
2995
- await this._inner.open();
3053
+ await this._inner.open(new import_context7.Context());
2996
3054
  this._state = import_services7.SpaceState.CONTROL_ONLY;
2997
3055
  this.stateUpdate.emit();
2998
3056
  this.metrics = {};
2999
- this.metrics.open = new Date();
3057
+ this.metrics.open = /* @__PURE__ */ new Date();
3000
3058
  }
3001
3059
  async close() {
3002
3060
  await this._close();
3003
3061
  }
3004
3062
  async _close() {
3005
- var _a, _b;
3006
- await ((_b = (_a = this._callbacks).beforeClose) == null ? void 0 : _b.call(_a));
3063
+ await this._callbacks.beforeClose?.();
3007
3064
  this._state = import_services7.SpaceState.CLOSED;
3008
3065
  await this._ctx.dispose();
3009
- this._ctx = new import_context6.Context();
3066
+ this._ctx = new import_context7.Context();
3010
3067
  await this.authVerifier.close();
3011
3068
  await this._inner.close();
3012
3069
  await this._inner.spaceState.removeCredentialProcessor(this._notarizationPlugin);
@@ -3025,13 +3082,13 @@ var DataSpace = class DataSpace2 {
3025
3082
  initializeDataPipelineAsync() {
3026
3083
  (0, import_async11.scheduleTask)(this._ctx, async () => {
3027
3084
  try {
3028
- this.metrics.pipelineInitBegin = new Date();
3085
+ this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
3029
3086
  await this.initializeDataPipeline();
3030
3087
  } catch (err) {
3031
3088
  if (err instanceof import_errors3.CancelledError) {
3032
3089
  (0, import_log10.log)("data pipeline initialization cancelled", err, {
3033
3090
  F: __dxlog_file12,
3034
- L: 193,
3091
+ L: 199,
3035
3092
  S: this,
3036
3093
  C: (f, a) => f(...a)
3037
3094
  });
@@ -3039,7 +3096,7 @@ var DataSpace = class DataSpace2 {
3039
3096
  }
3040
3097
  import_log10.log.error("Error initializing data pipeline", err, {
3041
3098
  F: __dxlog_file12,
3042
- L: 197,
3099
+ L: 203,
3043
3100
  S: this,
3044
3101
  C: (f, a) => f(...a)
3045
3102
  });
@@ -3047,12 +3104,11 @@ var DataSpace = class DataSpace2 {
3047
3104
  this.error = err;
3048
3105
  this.stateUpdate.emit();
3049
3106
  } finally {
3050
- this.metrics.ready = new Date();
3107
+ this.metrics.ready = /* @__PURE__ */ new Date();
3051
3108
  }
3052
3109
  });
3053
3110
  }
3054
3111
  async initializeDataPipeline() {
3055
- var _a, _b, _c, _d;
3056
3112
  if (this._state !== import_services7.SpaceState.CONTROL_ONLY) {
3057
3113
  throw new import_errors3.SystemError("Invalid operation");
3058
3114
  }
@@ -3061,11 +3117,11 @@ var DataSpace = class DataSpace2 {
3061
3117
  ctx: this._ctx,
3062
3118
  breakOnStall: false
3063
3119
  });
3064
- this.metrics.controlPipelineReady = new Date();
3120
+ this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
3065
3121
  await this._createWritableFeeds();
3066
3122
  (0, import_log10.log)("writable feeds created", void 0, {
3067
3123
  F: __dxlog_file12,
3068
- L: 221,
3124
+ L: 227,
3069
3125
  S: this,
3070
3126
  C: (f, a) => f(...a)
3071
3127
  });
@@ -3078,11 +3134,11 @@ var DataSpace = class DataSpace2 {
3078
3134
  }), this._inner.controlPipeline.writer));
3079
3135
  }
3080
3136
  await this._inner.initializeDataPipeline();
3081
- this.metrics.dataPipelineOpen = new Date();
3082
- await (0, import_context6.cancelWithContext)(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
3137
+ this.metrics.dataPipelineOpen = /* @__PURE__ */ new Date();
3138
+ await (0, import_context7.cancelWithContext)(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
3083
3139
  (0, import_log10.log)("waiting for data pipeline to reach target timeframe", void 0, {
3084
3140
  F: __dxlog_file12,
3085
- L: 242,
3141
+ L: 248,
3086
3142
  S: this,
3087
3143
  C: (f, a) => f(...a)
3088
3144
  });
@@ -3090,17 +3146,17 @@ var DataSpace = class DataSpace2 {
3090
3146
  ctx: this._ctx,
3091
3147
  breakOnStall: false
3092
3148
  });
3093
- this.metrics.dataPipelineReady = new Date();
3149
+ this.metrics.dataPipelineReady = /* @__PURE__ */ new Date();
3094
3150
  (0, import_log10.log)("data pipeline ready", void 0, {
3095
3151
  F: __dxlog_file12,
3096
- L: 251,
3152
+ L: 257,
3097
3153
  S: this,
3098
3154
  C: (f, a) => f(...a)
3099
3155
  });
3100
- await ((_b = (_a = this._callbacks).beforeReady) == null ? void 0 : _b.call(_a));
3156
+ await this._callbacks.beforeReady?.();
3101
3157
  this._state = import_services7.SpaceState.READY;
3102
3158
  this.stateUpdate.emit();
3103
- await ((_d = (_c = this._callbacks).afterReady) == null ? void 0 : _d.call(_c));
3159
+ await this._callbacks.afterReady?.();
3104
3160
  }
3105
3161
  async _createWritableFeeds() {
3106
3162
  const credentials = [];
@@ -3147,7 +3203,6 @@ var DataSpace = class DataSpace2 {
3147
3203
  await this._metadataStore.setWritableFeedKeys(this.key, this.inner.controlFeedKey, this.inner.dataFeedKey);
3148
3204
  }
3149
3205
  async createEpoch() {
3150
- var _a, _b;
3151
3206
  const epoch = await this.dataPipeline.createEpoch();
3152
3207
  const receipt = await this.inner.controlPipeline.writer.write({
3153
3208
  credential: {
@@ -3160,16 +3215,19 @@ var DataSpace = class DataSpace2 {
3160
3215
  })
3161
3216
  }
3162
3217
  });
3163
- await this.inner.controlPipeline.state.waitUntilTimeframe(new import_timeframe.Timeframe([
3218
+ await this.inner.controlPipeline.state.waitUntilTimeframe(new import_timeframe2.Timeframe([
3164
3219
  [
3165
3220
  receipt.feedKey,
3166
3221
  receipt.seq
3167
3222
  ]
3168
3223
  ]));
3169
- for (const feed of (_b = (_a = this.inner.dataPipeline.pipelineState) == null ? void 0 : _a.feeds) != null ? _b : []) {
3170
- const indexBeforeEpoch = epoch.timeframe.get(feed.key);
3171
- if (indexBeforeEpoch) {
3172
- await feed.clear(0, indexBeforeEpoch + 1);
3224
+ if (ENABLE_FEED_PURGE) {
3225
+ for (const feed of this.inner.dataPipeline.pipelineState?.feeds ?? []) {
3226
+ const indexBeforeEpoch = epoch.timeframe.get(feed.key);
3227
+ if (indexBeforeEpoch === void 0) {
3228
+ continue;
3229
+ }
3230
+ await feed.safeClear(0, indexBeforeEpoch + 1);
3173
3231
  }
3174
3232
  }
3175
3233
  }
@@ -3191,22 +3249,22 @@ var DataSpace = class DataSpace2 {
3191
3249
  this.stateUpdate.emit();
3192
3250
  }
3193
3251
  };
3194
- _ts_decorate([
3252
+ _ts_decorate3([
3195
3253
  import_async11.synchronized
3196
3254
  ], DataSpace.prototype, "open", null);
3197
- _ts_decorate([
3255
+ _ts_decorate3([
3198
3256
  import_async11.synchronized
3199
3257
  ], DataSpace.prototype, "close", null);
3200
- _ts_decorate([
3258
+ _ts_decorate3([
3201
3259
  (0, import_debug4.timed)(1e4)
3202
3260
  ], DataSpace.prototype, "_createWritableFeeds", null);
3203
- _ts_decorate([
3261
+ _ts_decorate3([
3204
3262
  import_async11.synchronized
3205
3263
  ], DataSpace.prototype, "activate", null);
3206
- _ts_decorate([
3264
+ _ts_decorate3([
3207
3265
  import_async11.synchronized
3208
3266
  ], DataSpace.prototype, "deactivate", null);
3209
- DataSpace = _ts_decorate([
3267
+ DataSpace = _ts_decorate3([
3210
3268
  (0, import_async11.trackLeaks)("open", "close")
3211
3269
  ], DataSpace);
3212
3270
 
@@ -3214,9 +3272,8 @@ DataSpace = _ts_decorate([
3214
3272
  var import_credentials11 = require("@dxos/credentials");
3215
3273
  var import_debug5 = require("@dxos/debug");
3216
3274
  var import_credentials12 = require("@dxos/protocols/proto/dxos/halo/credentials");
3217
- var import_timeframe2 = require("@dxos/timeframe");
3275
+ var import_timeframe3 = require("@dxos/timeframe");
3218
3276
  var spaceGenesis = async (keyring, signingContext, space) => {
3219
- var _a, _b, _c, _d;
3220
3277
  const credentials = [
3221
3278
  await (0, import_credentials11.createCredential)({
3222
3279
  signer: keyring,
@@ -3236,11 +3293,11 @@ var spaceGenesis = async (keyring, signingContext, space) => {
3236
3293
  spaceKey: space.key,
3237
3294
  role: import_credentials12.SpaceMember.Role.ADMIN,
3238
3295
  profile: signingContext.profile,
3239
- genesisFeedKey: (_a = space.controlFeedKey) != null ? _a : (0, import_debug5.failUndefined)()
3296
+ genesisFeedKey: space.controlFeedKey ?? (0, import_debug5.failUndefined)()
3240
3297
  }
3241
3298
  }),
3242
3299
  await signingContext.credentialSigner.createCredential({
3243
- subject: (_b = space.controlFeedKey) != null ? _b : (0, import_debug5.failUndefined)(),
3300
+ subject: space.controlFeedKey ?? (0, import_debug5.failUndefined)(),
3244
3301
  assertion: {
3245
3302
  "@type": "dxos.halo.credentials.AdmittedFeed",
3246
3303
  spaceKey: space.key,
@@ -3250,7 +3307,7 @@ var spaceGenesis = async (keyring, signingContext, space) => {
3250
3307
  }
3251
3308
  }),
3252
3309
  await signingContext.credentialSigner.createCredential({
3253
- subject: (_c = space.dataFeedKey) != null ? _c : (0, import_debug5.failUndefined)(),
3310
+ subject: space.dataFeedKey ?? (0, import_debug5.failUndefined)(),
3254
3311
  assertion: {
3255
3312
  "@type": "dxos.halo.credentials.AdmittedFeed",
3256
3313
  spaceKey: space.key,
@@ -3260,12 +3317,12 @@ var spaceGenesis = async (keyring, signingContext, space) => {
3260
3317
  }
3261
3318
  }),
3262
3319
  await signingContext.credentialSigner.createCredential({
3263
- subject: (_d = space.key) != null ? _d : (0, import_debug5.failUndefined)(),
3320
+ subject: space.key ?? (0, import_debug5.failUndefined)(),
3264
3321
  assertion: {
3265
3322
  "@type": "dxos.halo.credentials.Epoch",
3266
3323
  number: 0,
3267
3324
  previousId: void 0,
3268
- timeframe: new import_timeframe2.Timeframe(),
3325
+ timeframe: new import_timeframe3.Timeframe(),
3269
3326
  snapshotCid: void 0
3270
3327
  }
3271
3328
  })
@@ -3281,7 +3338,7 @@ var spaceGenesis = async (keyring, signingContext, space) => {
3281
3338
  };
3282
3339
 
3283
3340
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
3284
- function _ts_decorate2(decorators, target, key, desc) {
3341
+ function _ts_decorate4(decorators, target, key, desc) {
3285
3342
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3286
3343
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3287
3344
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3300,7 +3357,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3300
3357
  this._keyring = _keyring;
3301
3358
  this._signingContext = _signingContext;
3302
3359
  this._feedStore = _feedStore;
3303
- this._ctx = new import_context7.Context();
3360
+ this._ctx = new import_context8.Context();
3304
3361
  this.updated = new import_async12.Event();
3305
3362
  this._spaces = new import_util5.ComplexMap(import_keys9.PublicKey.hash);
3306
3363
  this._isOpen = false;
@@ -3479,7 +3536,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3479
3536
  * TODO(dmaretskyi): Consider removing.
3480
3537
  */
3481
3538
  async waitUntilSpaceReady(spaceKey) {
3482
- await (0, import_context7.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
3539
+ await (0, import_context8.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
3483
3540
  const space = this._spaces.get(spaceKey);
3484
3541
  return !!space && space.state === import_services8.SpaceState.READY;
3485
3542
  }));
@@ -3596,19 +3653,19 @@ var DataSpaceManager = class DataSpaceManager2 {
3596
3653
  return dataSpace;
3597
3654
  }
3598
3655
  };
3599
- _ts_decorate2([
3656
+ _ts_decorate4([
3600
3657
  import_async12.synchronized
3601
3658
  ], DataSpaceManager.prototype, "open", null);
3602
- _ts_decorate2([
3659
+ _ts_decorate4([
3603
3660
  import_async12.synchronized
3604
3661
  ], DataSpaceManager.prototype, "close", null);
3605
- _ts_decorate2([
3662
+ _ts_decorate4([
3606
3663
  import_async12.synchronized
3607
3664
  ], DataSpaceManager.prototype, "createSpace", null);
3608
- _ts_decorate2([
3665
+ _ts_decorate4([
3609
3666
  import_async12.synchronized
3610
3667
  ], DataSpaceManager.prototype, "acceptSpace", null);
3611
- DataSpaceManager = _ts_decorate2([
3668
+ DataSpaceManager = _ts_decorate4([
3612
3669
  (0, import_async12.trackLeaks)("open", "close")
3613
3670
  ], DataSpaceManager);
3614
3671
 
@@ -3639,9 +3696,8 @@ var SpacesServiceImpl = class {
3639
3696
  return this._serializeSpace(space);
3640
3697
  }
3641
3698
  async updateSpace({ spaceKey, state }) {
3642
- var _a;
3643
3699
  const dataSpaceManager = await this._getDataSpaceManager();
3644
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3700
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3645
3701
  if (state) {
3646
3702
  switch (state) {
3647
3703
  case import_services9.SpaceState.ACTIVE:
@@ -3705,17 +3761,15 @@ var SpacesServiceImpl = class {
3705
3761
  });
3706
3762
  }
3707
3763
  async postMessage({ spaceKey, channel, message }) {
3708
- var _a;
3709
3764
  const dataSpaceManager = await this._getDataSpaceManager();
3710
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3765
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3711
3766
  await space.postMessage(getChannelId(channel), message);
3712
3767
  }
3713
3768
  subscribeMessages({ spaceKey, channel }) {
3714
3769
  return new import_codec_protobuf11.Stream(({ ctx, next }) => {
3715
3770
  (0, import_async13.scheduleTask)(ctx, async () => {
3716
- var _a;
3717
3771
  const dataSpaceManager = await this._getDataSpaceManager();
3718
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3772
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3719
3773
  const handle = space.listen(getChannelId(channel), (message) => {
3720
3774
  next(message);
3721
3775
  });
@@ -3725,8 +3779,7 @@ var SpacesServiceImpl = class {
3725
3779
  }
3726
3780
  queryCredentials({ spaceKey }) {
3727
3781
  return new import_codec_protobuf11.Stream(({ ctx, next }) => {
3728
- var _a;
3729
- const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3782
+ const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3730
3783
  const processor = {
3731
3784
  processCredential: async (credential) => {
3732
3785
  next(credential);
@@ -3737,9 +3790,8 @@ var SpacesServiceImpl = class {
3737
3790
  });
3738
3791
  }
3739
3792
  async writeCredentials({ spaceKey, credentials }) {
3740
- var _a;
3741
- const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3742
- for (const credential of credentials != null ? credentials : []) {
3793
+ const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3794
+ for (const credential of credentials ?? []) {
3743
3795
  await space.controlPipeline.writer.write({
3744
3796
  credential: {
3745
3797
  credential
@@ -3748,13 +3800,11 @@ var SpacesServiceImpl = class {
3748
3800
  }
3749
3801
  }
3750
3802
  async createEpoch({ spaceKey }) {
3751
- var _a;
3752
3803
  const dataSpaceManager = await this._getDataSpaceManager();
3753
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3804
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3754
3805
  await space.createEpoch();
3755
3806
  }
3756
3807
  _serializeSpace(space) {
3757
- var _a, _b, _c, _d, _e, _f, _g;
3758
3808
  return {
3759
3809
  spaceKey: space.key,
3760
3810
  state: space.state,
@@ -3766,16 +3816,15 @@ var SpacesServiceImpl = class {
3766
3816
  currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
3767
3817
  targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
3768
3818
  totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe,
3769
- dataFeeds: (_b = (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.feeds.map((feed) => feed.key)) != null ? _b : [],
3770
- startDataTimeframe: (_c = space.dataPipeline.pipelineState) == null ? void 0 : _c.startTimeframe,
3771
- currentDataTimeframe: (_d = space.dataPipeline.pipelineState) == null ? void 0 : _d.timeframe,
3772
- targetDataTimeframe: (_e = space.dataPipeline.pipelineState) == null ? void 0 : _e.targetTimeframe,
3773
- totalDataTimeframe: (_f = space.dataPipeline.pipelineState) == null ? void 0 : _f.endTimeframe
3819
+ dataFeeds: space.dataPipeline.pipelineState?.feeds.map((feed) => feed.key) ?? [],
3820
+ startDataTimeframe: space.dataPipeline.pipelineState?.startTimeframe,
3821
+ currentDataTimeframe: space.dataPipeline.pipelineState?.timeframe,
3822
+ targetDataTimeframe: space.dataPipeline.pipelineState?.targetTimeframe,
3823
+ totalDataTimeframe: space.dataPipeline.pipelineState?.endTimeframe
3774
3824
  },
3775
3825
  members: Array.from(space.inner.spaceState.members.values()).map((member) => {
3776
- var _a2, _b2, _c2;
3777
3826
  const peers = space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key));
3778
- const isMe = (_a2 = this._identityManager.identity) == null ? void 0 : _a2.identityKey.equals(member.key);
3827
+ const isMe = this._identityManager.identity?.identityKey.equals(member.key);
3779
3828
  if (isMe) {
3780
3829
  peers.push(space.presence.getLocalState());
3781
3830
  }
@@ -3783,14 +3832,14 @@ var SpacesServiceImpl = class {
3783
3832
  identity: {
3784
3833
  identityKey: member.key,
3785
3834
  profile: {
3786
- displayName: (_c2 = (_b2 = member.assertion.profile) == null ? void 0 : _b2.displayName) != null ? _c2 : (0, import_util6.humanize)(member.key)
3835
+ displayName: member.assertion.profile?.displayName ?? (0, import_util6.humanize)(member.key)
3787
3836
  }
3788
3837
  },
3789
3838
  presence: isMe || peers.length > 0 ? import_services9.SpaceMember.PresenceState.ONLINE : import_services9.SpaceMember.PresenceState.OFFLINE,
3790
3839
  peerStates: peers
3791
3840
  };
3792
3841
  }),
3793
- creator: (_g = space.inner.spaceState.creator) == null ? void 0 : _g.key,
3842
+ creator: space.inner.spaceState.creator?.key,
3794
3843
  cache: space.cache,
3795
3844
  metrics: space.metrics
3796
3845
  };
@@ -3799,8 +3848,18 @@ var SpacesServiceImpl = class {
3799
3848
  var getChannelId = (channel) => `user-channel/${channel}`;
3800
3849
 
3801
3850
  // packages/sdk/client-services/src/packlets/services/service-context.ts
3851
+ function _ts_decorate5(decorators, target, key, desc) {
3852
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3853
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3854
+ r = Reflect.decorate(decorators, target, key, desc);
3855
+ else
3856
+ for (var i = decorators.length - 1; i >= 0; i--)
3857
+ if (d = decorators[i])
3858
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3859
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
3860
+ }
3802
3861
  var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
3803
- var ServiceContext = class {
3862
+ var ServiceContext = class ServiceContext2 {
3804
3863
  // prettier-ignore
3805
3864
  constructor(storage, networkManager, signalManager, modelFactory) {
3806
3865
  this.storage = storage;
@@ -3834,16 +3893,13 @@ var ServiceContext = class {
3834
3893
  });
3835
3894
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager);
3836
3895
  this.invitations = new InvitationsHandler(this.networkManager);
3837
- this._handlerFactories.set(import_services10.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => {
3838
- var _a;
3839
- return (_a = this.identityManager.identity) != null ? _a : (0, import_debug7.failUndefined)();
3840
- }, this._acceptIdentity.bind(this)));
3896
+ this._handlerFactories.set(import_services10.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug7.failUndefined)(), this._acceptIdentity.bind(this)));
3841
3897
  }
3842
- async open() {
3898
+ async open(ctx) {
3843
3899
  await this._checkStorageVersion();
3844
3900
  (0, import_log13.log)("opening...", void 0, {
3845
3901
  F: __dxlog_file15,
3846
- L: 127,
3902
+ L: 134,
3847
3903
  S: this,
3848
3904
  C: (f, a) => f(...a)
3849
3905
  });
@@ -3851,44 +3907,43 @@ var ServiceContext = class {
3851
3907
  id: this._instanceId
3852
3908
  }), {
3853
3909
  F: __dxlog_file15,
3854
- L: 128,
3910
+ L: 135,
3855
3911
  S: this,
3856
3912
  C: (f, a) => f(...a)
3857
3913
  });
3858
3914
  await this.signalManager.open();
3859
3915
  await this.networkManager.open();
3860
3916
  await this.spaceManager.open();
3861
- await this.identityManager.open();
3917
+ await this.identityManager.open(ctx);
3862
3918
  if (this.identityManager.identity) {
3863
- await this._initialize();
3919
+ await this._initialize(ctx);
3864
3920
  }
3865
3921
  import_log13.log.trace("dxos.sdk.service-context.open", import_protocols9.trace.end({
3866
3922
  id: this._instanceId
3867
3923
  }), {
3868
3924
  F: __dxlog_file15,
3869
- L: 136,
3925
+ L: 143,
3870
3926
  S: this,
3871
3927
  C: (f, a) => f(...a)
3872
3928
  });
3873
3929
  (0, import_log13.log)("opened", void 0, {
3874
3930
  F: __dxlog_file15,
3875
- L: 137,
3931
+ L: 144,
3876
3932
  S: this,
3877
3933
  C: (f, a) => f(...a)
3878
3934
  });
3879
3935
  }
3880
3936
  async close() {
3881
- var _a;
3882
3937
  (0, import_log13.log)("closing...", void 0, {
3883
3938
  F: __dxlog_file15,
3884
- L: 141,
3939
+ L: 148,
3885
3940
  S: this,
3886
3941
  C: (f, a) => f(...a)
3887
3942
  });
3888
3943
  if (this._deviceSpaceSync && this.identityManager.identity) {
3889
3944
  await this.identityManager.identity.space.spaceState.removeCredentialProcessor(this._deviceSpaceSync);
3890
3945
  }
3891
- await ((_a = this.dataSpaceManager) == null ? void 0 : _a.close());
3946
+ await this.dataSpaceManager?.close();
3892
3947
  await this.identityManager.close();
3893
3948
  await this.spaceManager.close();
3894
3949
  await this.feedStore.close();
@@ -3897,21 +3952,21 @@ var ServiceContext = class {
3897
3952
  this.dataServiceSubscriptions.clear();
3898
3953
  (0, import_log13.log)("closed", void 0, {
3899
3954
  F: __dxlog_file15,
3900
- L: 152,
3955
+ L: 159,
3901
3956
  S: this,
3902
3957
  C: (f, a) => f(...a)
3903
3958
  });
3904
3959
  }
3905
3960
  async createIdentity(params = {}) {
3906
3961
  const identity = await this.identityManager.createIdentity(params);
3907
- await this._initialize();
3962
+ await this._initialize(new import_context9.Context());
3908
3963
  return identity;
3909
3964
  }
3910
3965
  getInvitationHandler(invitation) {
3911
3966
  const factory = this._handlerFactories.get(invitation.kind);
3912
3967
  (0, import_invariant12.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
3913
3968
  F: __dxlog_file15,
3914
- L: 164,
3969
+ L: 171,
3915
3970
  S: this,
3916
3971
  A: [
3917
3972
  "factory",
@@ -3922,7 +3977,7 @@ var ServiceContext = class {
3922
3977
  }
3923
3978
  async _acceptIdentity(params) {
3924
3979
  const identity = await this.identityManager.acceptIdentity(params);
3925
- await this._initialize();
3980
+ await this._initialize(new import_context9.Context());
3926
3981
  return identity;
3927
3982
  }
3928
3983
  async _checkStorageVersion() {
@@ -3932,15 +3987,14 @@ var ServiceContext = class {
3932
3987
  }
3933
3988
  }
3934
3989
  // Called when identity is created.
3935
- async _initialize() {
3936
- var _a;
3990
+ async _initialize(ctx) {
3937
3991
  (0, import_log13.log)("initializing spaces...", void 0, {
3938
3992
  F: __dxlog_file15,
3939
- L: 185,
3993
+ L: 193,
3940
3994
  S: this,
3941
3995
  C: (f, a) => f(...a)
3942
3996
  });
3943
- const identity = (_a = this.identityManager.identity) != null ? _a : (0, import_debug7.failUndefined)();
3997
+ const identity = this.identityManager.identity ?? (0, import_debug7.failUndefined)();
3944
3998
  const signingContext = {
3945
3999
  credentialSigner: identity.getIdentityCredentialSigner(),
3946
4000
  identityKey: identity.identityKey,
@@ -3959,7 +4013,7 @@ var ServiceContext = class {
3959
4013
  this._handlerFactories.set(import_services10.Invitation.Kind.SPACE, (invitation) => {
3960
4014
  (0, import_invariant12.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
3961
4015
  F: __dxlog_file15,
3962
- L: 208,
4016
+ L: 216,
3963
4017
  S: this,
3964
4018
  A: [
3965
4019
  "this.dataSpaceManager",
@@ -3983,7 +4037,7 @@ var ServiceContext = class {
3983
4037
  details: assertion
3984
4038
  }, {
3985
4039
  F: __dxlog_file15,
3986
- L: 224,
4040
+ L: 232,
3987
4041
  S: this,
3988
4042
  C: (f, a) => f(...a)
3989
4043
  });
@@ -3994,7 +4048,7 @@ var ServiceContext = class {
3994
4048
  details: assertion
3995
4049
  }, {
3996
4050
  F: __dxlog_file15,
3997
- L: 228,
4051
+ L: 236,
3998
4052
  S: this,
3999
4053
  C: (f, a) => f(...a)
4000
4054
  });
@@ -4005,7 +4059,7 @@ var ServiceContext = class {
4005
4059
  details: assertion
4006
4060
  }, {
4007
4061
  F: __dxlog_file15,
4008
- L: 233,
4062
+ L: 241,
4009
4063
  S: this,
4010
4064
  C: (f, a) => f(...a)
4011
4065
  });
@@ -4016,7 +4070,7 @@ var ServiceContext = class {
4016
4070
  } catch (err) {
4017
4071
  import_log13.log.catch(err, void 0, {
4018
4072
  F: __dxlog_file15,
4019
- L: 239,
4073
+ L: 247,
4020
4074
  S: this,
4021
4075
  C: (f, a) => f(...a)
4022
4076
  });
@@ -4026,10 +4080,21 @@ var ServiceContext = class {
4026
4080
  await identity.space.spaceState.addCredentialProcessor(this._deviceSpaceSync);
4027
4081
  }
4028
4082
  };
4083
+ _ts_decorate5([
4084
+ import_tracing3.trace.span()
4085
+ ], ServiceContext.prototype, "open", null);
4086
+ _ts_decorate5([
4087
+ import_tracing3.trace.span()
4088
+ ], ServiceContext.prototype, "_initialize", null);
4089
+ ServiceContext = _ts_decorate5([
4090
+ (0, import_util7.safeInstanceof)("dxos.client-services.ServiceContext"),
4091
+ import_tracing3.trace.resource()
4092
+ ], ServiceContext);
4029
4093
 
4030
4094
  // packages/sdk/client-services/src/packlets/services/service-host.ts
4031
4095
  var import_async17 = require("@dxos/async");
4032
4096
  var import_client_protocol5 = require("@dxos/client-protocol");
4097
+ var import_context10 = require("@dxos/context");
4033
4098
  var import_document_model2 = require("@dxos/document-model");
4034
4099
  var import_echo_pipeline4 = require("@dxos/echo-pipeline");
4035
4100
  var import_invariant14 = require("@dxos/invariant");
@@ -4041,6 +4106,7 @@ var import_network_manager2 = require("@dxos/network-manager");
4041
4106
  var import_protocols10 = require("@dxos/protocols");
4042
4107
  var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
4043
4108
  var import_text_model = require("@dxos/text-model");
4109
+ var import_tracing4 = require("@dxos/tracing");
4044
4110
 
4045
4111
  // packages/sdk/client-services/src/packlets/devices/devices-service.ts
4046
4112
  var import_async15 = require("@dxos/async");
@@ -4056,21 +4122,17 @@ var DevicesServiceImpl = class {
4056
4122
  queryDevices() {
4057
4123
  return new import_codec_protobuf12.Stream(({ next }) => {
4058
4124
  const update = () => {
4059
- var _a;
4060
- const deviceKeys = (_a = this._identityManager.identity) == null ? void 0 : _a.authorizedDeviceKeys;
4125
+ const deviceKeys = this._identityManager.identity?.authorizedDeviceKeys;
4061
4126
  if (!deviceKeys) {
4062
4127
  next({
4063
4128
  devices: []
4064
4129
  });
4065
4130
  } else {
4066
4131
  next({
4067
- devices: Array.from(deviceKeys.values()).map((key) => {
4068
- var _a2;
4069
- return {
4070
- deviceKey: key,
4071
- kind: ((_a2 = this._identityManager.identity) == null ? void 0 : _a2.deviceKey.equals(key)) ? import_services11.DeviceKind.CURRENT : import_services11.DeviceKind.TRUSTED
4072
- };
4073
- })
4132
+ devices: Array.from(deviceKeys.values()).map((key) => ({
4133
+ deviceKey: key,
4134
+ kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services11.DeviceKind.CURRENT : import_services11.DeviceKind.TRUSTED
4135
+ }))
4074
4136
  });
4075
4137
  }
4076
4138
  };
@@ -4093,7 +4155,7 @@ var DevicesServiceImpl = class {
4093
4155
  var import_invariant13 = require("@dxos/invariant");
4094
4156
  var import_lock_file = require("@dxos/lock-file");
4095
4157
  var import_log14 = require("@dxos/log");
4096
- function _ts_decorate3(decorators, target, key, desc) {
4158
+ function _ts_decorate6(decorators, target, key, desc) {
4097
4159
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4098
4160
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
4099
4161
  r = Reflect.decorate(decorators, target, key, desc);
@@ -4114,7 +4176,6 @@ var Lock = class {
4114
4176
  return this._lockPath;
4115
4177
  }
4116
4178
  async acquire() {
4117
- var _a;
4118
4179
  (0, import_log14.log)("acquiring lock...", void 0, {
4119
4180
  F: __dxlog_file16,
4120
4181
  L: 32,
@@ -4122,7 +4183,7 @@ var Lock = class {
4122
4183
  C: (f, a) => f(...a)
4123
4184
  });
4124
4185
  this._fileHandle = await import_lock_file.LockFile.acquire(this._lockPath);
4125
- await ((_a = this._onAcquire) == null ? void 0 : _a.call(this));
4186
+ await this._onAcquire?.();
4126
4187
  (0, import_log14.log)("acquired lock", void 0, {
4127
4188
  F: __dxlog_file16,
4128
4189
  L: 37,
@@ -4131,8 +4192,7 @@ var Lock = class {
4131
4192
  });
4132
4193
  }
4133
4194
  async release() {
4134
- var _a;
4135
- await ((_a = this._onRelease) == null ? void 0 : _a.call(this));
4195
+ await this._onRelease?.();
4136
4196
  (0, import_invariant13.invariant)(this._fileHandle, "Lock is not acquired", {
4137
4197
  F: __dxlog_file16,
4138
4198
  L: 42,
@@ -4145,7 +4205,7 @@ var Lock = class {
4145
4205
  await import_lock_file.LockFile.release(this._fileHandle);
4146
4206
  }
4147
4207
  };
4148
- _ts_decorate3([
4208
+ _ts_decorate6([
4149
4209
  import_log14.logInfo
4150
4210
  ], Lock.prototype, "lockKey", null);
4151
4211
  var isLocked = (lockPath) => import_lock_file.LockFile.isLocked(lockPath);
@@ -4155,11 +4215,11 @@ var import_async16 = require("@dxos/async");
4155
4215
  var import_codec_protobuf13 = require("@dxos/codec-protobuf");
4156
4216
  var import_log15 = require("@dxos/log");
4157
4217
  var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
4158
- var import_util7 = require("@dxos/util");
4218
+ var import_util8 = require("@dxos/util");
4159
4219
  var LoggingServiceImpl = class {
4160
4220
  constructor() {
4161
4221
  this._logs = new import_async16.Event();
4162
- this._started = new Date();
4222
+ this._started = /* @__PURE__ */ new Date();
4163
4223
  this._logProcessor = (_config, entry2) => {
4164
4224
  this._logs.emit(entry2);
4165
4225
  };
@@ -4173,15 +4233,15 @@ var LoggingServiceImpl = class {
4173
4233
  }
4174
4234
  async controlMetrics({ reset, record }) {
4175
4235
  if (reset) {
4176
- import_util7.tracer.clear();
4236
+ import_util8.tracer.clear();
4177
4237
  }
4178
4238
  if (record === true) {
4179
- import_util7.tracer.start();
4239
+ import_util8.tracer.start();
4180
4240
  } else if (record === false) {
4181
- import_util7.tracer.stop();
4241
+ import_util8.tracer.stop();
4182
4242
  }
4183
4243
  return {
4184
- recording: import_util7.tracer.recording
4244
+ recording: import_util8.tracer.recording
4185
4245
  };
4186
4246
  }
4187
4247
  /**
@@ -4189,24 +4249,23 @@ var LoggingServiceImpl = class {
4189
4249
  */
4190
4250
  queryMetrics({ interval = 5e3 }) {
4191
4251
  const getNumericalValues = (key) => {
4192
- var _a;
4193
- const events = (_a = import_util7.tracer.get(key)) != null ? _a : [];
4252
+ const events = import_util8.tracer.get(key) ?? [];
4194
4253
  return {
4195
4254
  key,
4196
- stats: (0, import_util7.numericalValues)(events, "duration")
4255
+ stats: (0, import_util8.numericalValues)(events, "duration")
4197
4256
  };
4198
4257
  };
4199
4258
  return new import_codec_protobuf13.Stream(({ next }) => {
4200
4259
  const update = () => {
4201
4260
  const metrics = {
4202
- timestamp: new Date(),
4261
+ timestamp: /* @__PURE__ */ new Date(),
4203
4262
  values: [
4204
4263
  getNumericalValues("dxos.echo.pipeline.control"),
4205
4264
  getNumericalValues("dxos.echo.pipeline.data")
4206
4265
  ].filter(Boolean)
4207
4266
  };
4208
4267
  next({
4209
- timestamp: new Date(),
4268
+ timestamp: /* @__PURE__ */ new Date(),
4210
4269
  metrics
4211
4270
  });
4212
4271
  };
@@ -4220,11 +4279,10 @@ var LoggingServiceImpl = class {
4220
4279
  queryLogs(request) {
4221
4280
  return new import_codec_protobuf13.Stream(({ ctx, next }) => {
4222
4281
  const handler = (entry2) => {
4223
- var _a, _b, _c, _d, _e;
4224
4282
  if (LOG_PROCESSING > 0) {
4225
4283
  return;
4226
4284
  }
4227
- 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"))) {
4285
+ if (entry2.meta?.F.includes("logging-service") || entry2.context && Object.values(entry2.context).some((value) => typeof value === "string" && value.includes("LoggingService"))) {
4228
4286
  return;
4229
4287
  }
4230
4288
  if (!shouldLog(entry2, request)) {
@@ -4232,12 +4290,12 @@ var LoggingServiceImpl = class {
4232
4290
  }
4233
4291
  const record = {
4234
4292
  ...entry2,
4235
- context: (0, import_util7.jsonify)((0, import_log15.getContextFromEntry)(entry2)),
4236
- timestamp: new Date(),
4293
+ context: (0, import_util8.jsonify)((0, import_log15.getContextFromEntry)(entry2)),
4294
+ timestamp: /* @__PURE__ */ new Date(),
4237
4295
  meta: {
4238
4296
  // TODO(dmaretskyi): Fix proto.
4239
- file: (_c = (_b = entry2.meta) == null ? void 0 : _b.F) != null ? _c : "",
4240
- line: (_e = (_d = entry2.meta) == null ? void 0 : _d.L) != null ? _e : 0
4297
+ file: entry2.meta?.F ?? "",
4298
+ line: entry2.meta?.L ?? 0
4241
4299
  }
4242
4300
  };
4243
4301
  try {
@@ -4260,15 +4318,11 @@ var matchFilter = (filter, level, path, options) => {
4260
4318
  }
4261
4319
  };
4262
4320
  var shouldLog = (entry2, request) => {
4263
- var _a;
4264
- const options = (_a = request.options) != null ? _a : import_services12.QueryLogsRequest.MatchingOptions.INCLUSIVE;
4321
+ const options = request.options ?? import_services12.QueryLogsRequest.MatchingOptions.INCLUSIVE;
4265
4322
  if (request.filters === void 0) {
4266
4323
  return options === import_services12.QueryLogsRequest.MatchingOptions.INCLUSIVE;
4267
4324
  } else {
4268
- return request.filters.some((filter) => {
4269
- var _a2, _b;
4270
- return matchFilter(filter, entry2.level, (_b = (_a2 = entry2.meta) == null ? void 0 : _a2.F) != null ? _b : "", options);
4271
- });
4325
+ return request.filters.some((filter) => matchFilter(filter, entry2.level, entry2.meta?.F ?? "", options));
4272
4326
  }
4273
4327
  };
4274
4328
  var LOG_PROCESSING = 0;
@@ -4310,10 +4364,10 @@ var import_client_protocol4 = require("@dxos/client-protocol");
4310
4364
  var import_errors5 = require("@dxos/errors");
4311
4365
  var import_config = require("@dxos/protocols/proto/dxos/config");
4312
4366
  var import_random_access_storage = require("@dxos/random-access-storage");
4313
- var import_util8 = require("@dxos/util");
4367
+ var import_util9 = require("@dxos/util");
4314
4368
  var StorageDriver = import_config.Runtime.Client.Storage.StorageDriver;
4315
4369
  var createStorageObjects = (config) => {
4316
- const { path = (0, import_util8.isNode)() ? import_client_protocol4.DX_DATA : "dxos/storage", storageType, keyStorage, persistent = false } = config != null ? config : {};
4370
+ const { path = (0, import_util9.isNode)() ? import_client_protocol4.DX_DATA : "dxos/storage", storageType, keyStorage, persistent = false } = config ?? {};
4317
4371
  if (persistent && storageType === StorageDriver.RAM) {
4318
4372
  throw new import_errors5.InvalidConfigError("RAM storage cannot be used in persistent mode.");
4319
4373
  }
@@ -4357,7 +4411,7 @@ var toStorageType = (type) => {
4357
4411
  // packages/sdk/client-services/src/packlets/system/system-service.ts
4358
4412
  var import_codec_protobuf15 = require("@dxos/codec-protobuf");
4359
4413
  var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
4360
- var import_util9 = require("@dxos/util");
4414
+ var import_util10 = require("@dxos/util");
4361
4415
  var SystemServiceImpl = class {
4362
4416
  constructor({ config, statusUpdate, getDiagnostics, onUpdateStatus, getCurrentStatus, onReset }) {
4363
4417
  this._config = config;
@@ -4368,8 +4422,7 @@ var SystemServiceImpl = class {
4368
4422
  this._onReset = onReset;
4369
4423
  }
4370
4424
  async getConfig() {
4371
- var _a, _b;
4372
- return (_b = (_a = this._config) == null ? void 0 : _a.values) != null ? _b : {};
4425
+ return this._config?.values ?? {};
4373
4426
  }
4374
4427
  /**
4375
4428
  * NOTE: Since this is serialized as a JSON object, we allow the option to serialize keys.
@@ -4377,8 +4430,8 @@ var SystemServiceImpl = class {
4377
4430
  async getDiagnostics({ keys } = {}) {
4378
4431
  const diagnostics = await this._getDiagnostics();
4379
4432
  return {
4380
- timestamp: new Date(),
4381
- diagnostics: JSON.parse(JSON.stringify(diagnostics, (0, import_util9.jsonKeyReplacer)({
4433
+ timestamp: /* @__PURE__ */ new Date(),
4434
+ diagnostics: JSON.parse(JSON.stringify(diagnostics, (0, import_util10.jsonKeyReplacer)({
4382
4435
  truncate: keys === import_services13.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
4383
4436
  humanize: keys === import_services13.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
4384
4437
  })))
@@ -4434,7 +4487,7 @@ var ServiceRegistry = class {
4434
4487
  };
4435
4488
 
4436
4489
  // packages/sdk/client-services/src/packlets/services/service-host.ts
4437
- function _ts_decorate4(decorators, target, key, desc) {
4490
+ function _ts_decorate7(decorators, target, key, desc) {
4438
4491
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4439
4492
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
4440
4493
  r = Reflect.decorate(decorators, target, key, desc);
@@ -4448,7 +4501,7 @@ var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/s
4448
4501
  var createDefaultModelFactory = () => {
4449
4502
  return new import_model_factory.ModelFactory().registerModel(import_document_model2.DocumentModel).registerModel(import_text_model.TextModel);
4450
4503
  };
4451
- var ClientServicesHost = class {
4504
+ var ClientServicesHost = class ClientServicesHost2 {
4452
4505
  constructor({
4453
4506
  config,
4454
4507
  modelFactory = createDefaultModelFactory(),
@@ -4459,6 +4512,7 @@ var ClientServicesHost = class {
4459
4512
  lockKey,
4460
4513
  callbacks
4461
4514
  } = {}) {
4515
+ this._tracingService = import_tracing4.TRACE_PROCESSOR.createTraceSender();
4462
4516
  this._statusUpdate = new import_async17.Event();
4463
4517
  this._opening = false;
4464
4518
  this._open = false;
@@ -4477,7 +4531,7 @@ var ClientServicesHost = class {
4477
4531
  lockKey,
4478
4532
  onAcquire: () => {
4479
4533
  if (!this._opening) {
4480
- void this.open();
4534
+ void this.open(new import_context10.Context());
4481
4535
  }
4482
4536
  },
4483
4537
  onRelease: () => this.close()
@@ -4491,11 +4545,10 @@ var ClientServicesHost = class {
4491
4545
  return createDiagnostics(this._serviceRegistry.services, this._serviceContext, this._config);
4492
4546
  },
4493
4547
  onUpdateStatus: async (status) => {
4494
- var _a, _b;
4495
4548
  if (!this.isOpen && status === import_services14.SystemStatus.ACTIVE) {
4496
- await ((_a = this._resourceLock) == null ? void 0 : _a.acquire());
4549
+ await this._resourceLock?.acquire();
4497
4550
  } else if (this.isOpen && status === import_services14.SystemStatus.INACTIVE) {
4498
- await ((_b = this._resourceLock) == null ? void 0 : _b.release());
4551
+ await this._resourceLock?.release();
4499
4552
  }
4500
4553
  },
4501
4554
  onReset: async () => {
@@ -4504,7 +4557,8 @@ var ClientServicesHost = class {
4504
4557
  });
4505
4558
  this._loggingService = new LoggingServiceImpl();
4506
4559
  this._serviceRegistry = new ServiceRegistry(import_client_protocol5.clientServiceBundle, {
4507
- SystemService: this._systemService
4560
+ SystemService: this._systemService,
4561
+ TracingService: this._tracingService
4508
4562
  });
4509
4563
  }
4510
4564
  get isOpen() {
@@ -4531,26 +4585,25 @@ var ClientServicesHost = class {
4531
4585
  * Can only be called once.
4532
4586
  */
4533
4587
  initialize({ config, ...options }) {
4534
- var _a, _b, _c;
4535
4588
  (0, import_invariant14.invariant)(!this._open, "service host is open", {
4536
4589
  F: __dxlog_file17,
4537
- L: 172,
4590
+ L: 181,
4538
4591
  S: this,
4539
4592
  A: [
4540
4593
  "!this._open",
4541
4594
  "'service host is open'"
4542
4595
  ]
4543
4596
  });
4544
- import_log16.log.info("initializing...", void 0, {
4597
+ (0, import_log16.log)("initializing...", void 0, {
4545
4598
  F: __dxlog_file17,
4546
- L: 173,
4599
+ L: 182,
4547
4600
  S: this,
4548
4601
  C: (f, a) => f(...a)
4549
4602
  });
4550
4603
  if (config) {
4551
4604
  (0, import_invariant14.invariant)(!this._config, "config already set", {
4552
4605
  F: __dxlog_file17,
4553
- L: 176,
4606
+ L: 185,
4554
4607
  S: this,
4555
4608
  A: [
4556
4609
  "!this._config",
@@ -4563,12 +4616,12 @@ var ClientServicesHost = class {
4563
4616
  }
4564
4617
  }
4565
4618
  const { connectionLog = true, transportFactory = (0, import_network_manager2.createWebRTCTransportFactory)({
4566
- iceServers: (_a = this._config) == null ? void 0 : _a.get("runtime.services.ice")
4567
- }), signalManager = new import_messaging.WebsocketSignalManager((_c = (_b = this._config) == null ? void 0 : _b.get("runtime.services.signaling")) != null ? _c : []) } = options;
4619
+ iceServers: this._config?.get("runtime.services.ice")
4620
+ }), signalManager = new import_messaging.WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
4568
4621
  this._signalManager = signalManager;
4569
4622
  (0, import_invariant14.invariant)(!this._networkManager, "network manager already set", {
4570
4623
  F: __dxlog_file17,
4571
- L: 192,
4624
+ L: 201,
4572
4625
  S: this,
4573
4626
  A: [
4574
4627
  "!this._networkManager",
@@ -4580,15 +4633,14 @@ var ClientServicesHost = class {
4580
4633
  transportFactory,
4581
4634
  signalManager
4582
4635
  });
4583
- import_log16.log.info("initialized", void 0, {
4636
+ (0, import_log16.log)("initialized", void 0, {
4584
4637
  F: __dxlog_file17,
4585
- L: 199,
4638
+ L: 208,
4586
4639
  S: this,
4587
4640
  C: (f, a) => f(...a)
4588
4641
  });
4589
4642
  }
4590
- async open() {
4591
- var _a, _b, _c;
4643
+ async open(ctx) {
4592
4644
  if (this._open) {
4593
4645
  return;
4594
4646
  }
@@ -4597,13 +4649,13 @@ var ClientServicesHost = class {
4597
4649
  id: traceId
4598
4650
  }), {
4599
4651
  F: __dxlog_file17,
4600
- L: 209,
4652
+ L: 219,
4601
4653
  S: this,
4602
4654
  C: (f, a) => f(...a)
4603
4655
  });
4604
4656
  (0, import_invariant14.invariant)(this._config, "config not set", {
4605
4657
  F: __dxlog_file17,
4606
- L: 211,
4658
+ L: 221,
4607
4659
  S: this,
4608
4660
  A: [
4609
4661
  "this._config",
@@ -4612,7 +4664,7 @@ var ClientServicesHost = class {
4612
4664
  });
4613
4665
  (0, import_invariant14.invariant)(this._storage, "storage not set", {
4614
4666
  F: __dxlog_file17,
4615
- L: 212,
4667
+ L: 222,
4616
4668
  S: this,
4617
4669
  A: [
4618
4670
  "this._storage",
@@ -4621,7 +4673,7 @@ var ClientServicesHost = class {
4621
4673
  });
4622
4674
  (0, import_invariant14.invariant)(this._signalManager, "signal manager not set", {
4623
4675
  F: __dxlog_file17,
4624
- L: 213,
4676
+ L: 223,
4625
4677
  S: this,
4626
4678
  A: [
4627
4679
  "this._signalManager",
@@ -4630,7 +4682,7 @@ var ClientServicesHost = class {
4630
4682
  });
4631
4683
  (0, import_invariant14.invariant)(this._networkManager, "network manager not set", {
4632
4684
  F: __dxlog_file17,
4633
- L: 214,
4685
+ L: 224,
4634
4686
  S: this,
4635
4687
  A: [
4636
4688
  "this._networkManager",
@@ -4638,20 +4690,20 @@ var ClientServicesHost = class {
4638
4690
  ]
4639
4691
  });
4640
4692
  this._opening = true;
4641
- import_log16.log.info("opening...", {
4642
- lockKey: (_a = this._resourceLock) == null ? void 0 : _a.lockKey
4693
+ (0, import_log16.log)("opening...", {
4694
+ lockKey: this._resourceLock?.lockKey
4643
4695
  }, {
4644
4696
  F: __dxlog_file17,
4645
- L: 217,
4697
+ L: 227,
4646
4698
  S: this,
4647
4699
  C: (f, a) => f(...a)
4648
4700
  });
4649
- await ((_b = this._resourceLock) == null ? void 0 : _b.acquire());
4701
+ await this._resourceLock?.acquire();
4650
4702
  await this._loggingService.open();
4651
4703
  this._serviceContext = new ServiceContext(this._storage, this._networkManager, this._signalManager, this._modelFactory);
4652
4704
  this._serviceRegistry.setServices({
4653
4705
  SystemService: this._systemService,
4654
- IdentityService: new IdentityServiceImpl(this._serviceContext),
4706
+ IdentityService: new IdentityServiceImpl((params) => this._serviceContext.createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring),
4655
4707
  InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitations, (invitation) => this._serviceContext.getInvitationHandler(invitation)),
4656
4708
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
4657
4709
  SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, this._serviceContext.dataServiceSubscriptions, async () => {
@@ -4661,6 +4713,7 @@ var ClientServicesHost = class {
4661
4713
  DataService: new import_echo_pipeline4.DataServiceImpl(this._serviceContext.dataServiceSubscriptions),
4662
4714
  NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager, this._serviceContext.signalManager),
4663
4715
  LoggingService: this._loggingService,
4716
+ TracingService: this._tracingService,
4664
4717
  // TODO(burdon): Move to new protobuf definitions.
4665
4718
  DevtoolsHost: new DevtoolsServiceImpl({
4666
4719
  events: new DevtoolsHostEvents(),
@@ -4668,16 +4721,16 @@ var ClientServicesHost = class {
4668
4721
  context: this._serviceContext
4669
4722
  })
4670
4723
  });
4671
- await this._serviceContext.open();
4724
+ await this._serviceContext.open(ctx);
4672
4725
  this._opening = false;
4673
4726
  this._open = true;
4674
4727
  this._statusUpdate.emit();
4675
- const deviceKey = (_c = this._serviceContext.identityManager.identity) == null ? void 0 : _c.deviceKey;
4676
- import_log16.log.info("opened", {
4728
+ const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
4729
+ (0, import_log16.log)("opened", {
4677
4730
  deviceKey
4678
4731
  }, {
4679
4732
  F: __dxlog_file17,
4680
- L: 269,
4733
+ L: 284,
4681
4734
  S: this,
4682
4735
  C: (f, a) => f(...a)
4683
4736
  });
@@ -4685,22 +4738,21 @@ var ClientServicesHost = class {
4685
4738
  id: traceId
4686
4739
  }), {
4687
4740
  F: __dxlog_file17,
4688
- L: 270,
4741
+ L: 285,
4689
4742
  S: this,
4690
4743
  C: (f, a) => f(...a)
4691
4744
  });
4692
4745
  }
4693
4746
  async close() {
4694
- var _a;
4695
4747
  if (!this._open) {
4696
4748
  return;
4697
4749
  }
4698
- const deviceKey = (_a = this._serviceContext.identityManager.identity) == null ? void 0 : _a.deviceKey;
4699
- import_log16.log.info("closing...", {
4750
+ const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
4751
+ (0, import_log16.log)("closing...", {
4700
4752
  deviceKey
4701
4753
  }, {
4702
4754
  F: __dxlog_file17,
4703
- L: 280,
4755
+ L: 296,
4704
4756
  S: this,
4705
4757
  C: (f, a) => f(...a)
4706
4758
  });
@@ -4711,37 +4763,36 @@ var ClientServicesHost = class {
4711
4763
  await this._serviceContext.close();
4712
4764
  this._open = false;
4713
4765
  this._statusUpdate.emit();
4714
- import_log16.log.info("closed", {
4766
+ (0, import_log16.log)("closed", {
4715
4767
  deviceKey
4716
4768
  }, {
4717
4769
  F: __dxlog_file17,
4718
- L: 286,
4770
+ L: 302,
4719
4771
  S: this,
4720
4772
  C: (f, a) => f(...a)
4721
4773
  });
4722
4774
  }
4723
4775
  async reset() {
4724
- var _a, _b, _c;
4725
4776
  const traceId = import_keys11.PublicKey.random().toHex();
4726
4777
  import_log16.log.trace("dxos.sdk.client-services-host.reset", import_protocols10.trace.begin({
4727
4778
  id: traceId
4728
4779
  }), {
4729
4780
  F: __dxlog_file17,
4730
- L: 291,
4781
+ L: 307,
4731
4782
  S: this,
4732
4783
  C: (f, a) => f(...a)
4733
4784
  });
4734
4785
  (0, import_log16.log)("resetting...", void 0, {
4735
4786
  F: __dxlog_file17,
4736
- L: 293,
4787
+ L: 309,
4737
4788
  S: this,
4738
4789
  C: (f, a) => f(...a)
4739
4790
  });
4740
- await ((_a = this._serviceContext) == null ? void 0 : _a.close());
4791
+ await this._serviceContext?.close();
4741
4792
  await this._storage.reset();
4742
4793
  (0, import_log16.log)("reset", void 0, {
4743
4794
  F: __dxlog_file17,
4744
- L: 296,
4795
+ L: 312,
4745
4796
  S: this,
4746
4797
  C: (f, a) => f(...a)
4747
4798
  });
@@ -4749,27 +4800,39 @@ var ClientServicesHost = class {
4749
4800
  id: traceId
4750
4801
  }), {
4751
4802
  F: __dxlog_file17,
4752
- L: 297,
4803
+ L: 313,
4753
4804
  S: this,
4754
4805
  C: (f, a) => f(...a)
4755
4806
  });
4756
- await ((_c = (_b = this._callbacks) == null ? void 0 : _b.onReset) == null ? void 0 : _c.call(_b));
4807
+ await this._callbacks?.onReset?.();
4757
4808
  }
4758
4809
  };
4759
- _ts_decorate4([
4760
- import_async17.synchronized
4810
+ _ts_decorate7([
4811
+ import_tracing4.trace.info()
4812
+ ], ClientServicesHost.prototype, "_opening", void 0);
4813
+ _ts_decorate7([
4814
+ import_tracing4.trace.info()
4815
+ ], ClientServicesHost.prototype, "_open", void 0);
4816
+ _ts_decorate7([
4817
+ import_async17.synchronized,
4818
+ import_tracing4.trace.span()
4761
4819
  ], ClientServicesHost.prototype, "open", null);
4762
- _ts_decorate4([
4763
- import_async17.synchronized
4820
+ _ts_decorate7([
4821
+ import_async17.synchronized,
4822
+ import_tracing4.trace.span()
4764
4823
  ], ClientServicesHost.prototype, "close", null);
4824
+ ClientServicesHost = _ts_decorate7([
4825
+ import_tracing4.trace.resource()
4826
+ ], ClientServicesHost);
4765
4827
 
4766
4828
  // packages/sdk/client-services/src/packlets/vault/iframe-host-runtime.ts
4767
4829
  var import_async19 = require("@dxos/async");
4768
4830
  var import_client_protocol7 = require("@dxos/client-protocol");
4831
+ var import_context11 = require("@dxos/context");
4769
4832
  var import_log17 = require("@dxos/log");
4770
4833
  var import_messaging2 = require("@dxos/messaging");
4771
4834
  var import_network_manager3 = require("@dxos/network-manager");
4772
- var import_util10 = require("@dxos/util");
4835
+ var import_util11 = require("@dxos/util");
4773
4836
 
4774
4837
  // packages/sdk/client-services/src/packlets/vault/shell-runtime.ts
4775
4838
  var import_async18 = require("@dxos/async");
@@ -4833,14 +4896,13 @@ var ShellRuntimeImpl = class {
4833
4896
  await this._appRpc.open();
4834
4897
  }
4835
4898
  async close() {
4836
- var _a;
4837
- await ((_a = this._appRpc) == null ? void 0 : _a.close());
4899
+ await this._appRpc?.close();
4838
4900
  this._appRpc = void 0;
4839
4901
  }
4840
4902
  };
4841
4903
 
4842
4904
  // packages/sdk/client-services/src/packlets/vault/iframe-host-runtime.ts
4843
- function _ts_decorate5(decorators, target, key, desc) {
4905
+ function _ts_decorate8(decorators, target, key, desc) {
4844
4906
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4845
4907
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
4846
4908
  r = Reflect.decorate(decorators, target, key, desc);
@@ -4870,15 +4932,14 @@ var IFrameHostRuntime = class {
4870
4932
  return this._shellRuntime;
4871
4933
  }
4872
4934
  async start() {
4873
- var _a;
4874
4935
  (0, import_log17.log)("starting...", void 0, {
4875
4936
  F: __dxlog_file19,
4876
- L: 70,
4937
+ L: 71,
4877
4938
  S: this,
4878
4939
  C: (f, a) => f(...a)
4879
4940
  });
4880
4941
  try {
4881
- this._config = await (0, import_util10.getAsyncValue)(this._configProvider);
4942
+ this._config = await (0, import_util11.getAsyncValue)(this._configProvider);
4882
4943
  this._transportFactory = (0, import_network_manager3.createWebRTCTransportFactory)({
4883
4944
  iceServers: this._config.get("runtime.services.ice")
4884
4945
  });
@@ -4915,14 +4976,14 @@ var IFrameHostRuntime = class {
4915
4976
  ...middleware
4916
4977
  });
4917
4978
  await Promise.all([
4918
- this._clientServices.open(),
4979
+ this._clientServices.open(new import_context11.Context()),
4919
4980
  this._clientRpc.open(),
4920
- (_a = this._shellRuntime) == null ? void 0 : _a.open()
4981
+ this._shellRuntime?.open()
4921
4982
  ]);
4922
4983
  this._ready.wake(void 0);
4923
4984
  (0, import_log17.log)("started", void 0, {
4924
4985
  F: __dxlog_file19,
4925
- L: 113,
4986
+ L: 114,
4926
4987
  S: this,
4927
4988
  C: (f, a) => f(...a)
4928
4989
  });
@@ -4930,32 +4991,31 @@ var IFrameHostRuntime = class {
4930
4991
  this._ready.wake(err);
4931
4992
  import_log17.log.catch(err, void 0, {
4932
4993
  F: __dxlog_file19,
4933
- L: 116,
4994
+ L: 117,
4934
4995
  S: this,
4935
4996
  C: (f, a) => f(...a)
4936
4997
  });
4937
4998
  }
4938
4999
  }
4939
5000
  async stop() {
4940
- var _a;
4941
5001
  (0, import_log17.log)("stopping...", void 0, {
4942
5002
  F: __dxlog_file19,
4943
- L: 121,
5003
+ L: 122,
4944
5004
  S: this,
4945
5005
  C: (f, a) => f(...a)
4946
5006
  });
4947
5007
  await this._clientRpc.close();
4948
5008
  await this._clientServices.close();
4949
- await ((_a = this._shellRuntime) == null ? void 0 : _a.close());
5009
+ await this._shellRuntime?.close();
4950
5010
  (0, import_log17.log)("stopped", void 0, {
4951
5011
  F: __dxlog_file19,
4952
- L: 125,
5012
+ L: 126,
4953
5013
  S: this,
4954
5014
  C: (f, a) => f(...a)
4955
5015
  });
4956
5016
  }
4957
5017
  };
4958
- _ts_decorate5([
5018
+ _ts_decorate8([
4959
5019
  import_log17.logInfo
4960
5020
  ], IFrameHostRuntime.prototype, "origin", void 0);
4961
5021
 
@@ -4966,7 +5026,7 @@ var import_errors6 = require("@dxos/errors");
4966
5026
  var import_log18 = require("@dxos/log");
4967
5027
  var import_network_manager4 = require("@dxos/network-manager");
4968
5028
  var import_rpc3 = require("@dxos/rpc");
4969
- var import_util11 = require("@dxos/util");
5029
+ var import_util12 = require("@dxos/util");
4970
5030
  var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/vault/iframe-proxy-runtime.ts";
4971
5031
  var IFrameProxyRuntime = class {
4972
5032
  constructor({ config, systemPort, shellPort }) {
@@ -4983,8 +5043,7 @@ var IFrameProxyRuntime = class {
4983
5043
  return this._shellRuntime;
4984
5044
  }
4985
5045
  async open(origin) {
4986
- var _a;
4987
- this._config = await (0, import_util11.getAsyncValue)(this._configProvider);
5046
+ this._config = await (0, import_util12.getAsyncValue)(this._configProvider);
4988
5047
  this._transportService = new import_network_manager4.WebRTCTransportService({
4989
5048
  iceServers: this._config.get("runtime.services.ice")
4990
5049
  });
@@ -5023,12 +5082,11 @@ var IFrameProxyRuntime = class {
5023
5082
  });
5024
5083
  throw new import_errors6.RemoteServiceConnectionError("Failed to connect to worker");
5025
5084
  }
5026
- await ((_a = this._shellRuntime) == null ? void 0 : _a.open());
5085
+ await this._shellRuntime?.open();
5027
5086
  }
5028
5087
  async close() {
5029
- var _a;
5030
5088
  this._release.wake();
5031
- await ((_a = this._shellRuntime) == null ? void 0 : _a.close());
5089
+ await this._shellRuntime?.close();
5032
5090
  await this._systemRpc.rpc.WorkerService.stop();
5033
5091
  await this._systemRpc.close();
5034
5092
  }
@@ -5039,6 +5097,7 @@ var IFrameProxyRuntime = class {
5039
5097
 
5040
5098
  // packages/sdk/client-services/src/packlets/vault/worker-runtime.ts
5041
5099
  var import_async22 = require("@dxos/async");
5100
+ var import_context12 = require("@dxos/context");
5042
5101
  var import_log20 = require("@dxos/log");
5043
5102
  var import_messaging3 = require("@dxos/messaging");
5044
5103
  var import_network_manager5 = require("@dxos/network-manager");
@@ -5049,8 +5108,8 @@ var import_client_protocol9 = require("@dxos/client-protocol");
5049
5108
  var import_invariant16 = require("@dxos/invariant");
5050
5109
  var import_log19 = require("@dxos/log");
5051
5110
  var import_rpc4 = require("@dxos/rpc");
5052
- var import_util12 = require("@dxos/util");
5053
- function _ts_decorate6(decorators, target, key, desc) {
5111
+ var import_util13 = require("@dxos/util");
5112
+ function _ts_decorate9(decorators, target, key, desc) {
5054
5113
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5055
5114
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
5056
5115
  r = Reflect.decorate(decorators, target, key, desc);
@@ -5064,7 +5123,7 @@ var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/s
5064
5123
  var WorkerSession = class {
5065
5124
  constructor({ serviceHost, systemPort, appPort, shellPort, readySignal }) {
5066
5125
  this._startTrigger = new import_async21.Trigger();
5067
- this.onClose = new import_util12.Callback();
5126
+ this.onClose = new import_util13.Callback();
5068
5127
  (0, import_invariant16.invariant)(serviceHost, void 0, {
5069
5128
  F: __dxlog_file21,
5070
5129
  L: 49,
@@ -5192,7 +5251,7 @@ var WorkerSession = class {
5192
5251
  async _maybeOpenShell() {
5193
5252
  try {
5194
5253
  await (0, import_async21.asyncTimeout)(this._shellClientRpc.open(), 1e3);
5195
- } catch (e) {
5254
+ } catch {
5196
5255
  import_log19.log.info("No shell connected.", void 0, {
5197
5256
  F: __dxlog_file21,
5198
5257
  L: 143,
@@ -5206,10 +5265,10 @@ var WorkerSession = class {
5206
5265
  }).then(callback);
5207
5266
  }
5208
5267
  };
5209
- _ts_decorate6([
5268
+ _ts_decorate9([
5210
5269
  import_log19.logInfo
5211
5270
  ], WorkerSession.prototype, "origin", void 0);
5212
- _ts_decorate6([
5271
+ _ts_decorate9([
5213
5272
  import_log19.logInfo
5214
5273
  ], WorkerSession.prototype, "lockKey", void 0);
5215
5274
 
@@ -5236,7 +5295,7 @@ var WorkerRuntime = class {
5236
5295
  async start() {
5237
5296
  (0, import_log20.log)("starting...", void 0, {
5238
5297
  F: __dxlog_file22,
5239
- L: 48,
5298
+ L: 49,
5240
5299
  S: this,
5241
5300
  C: (f, a) => f(...a)
5242
5301
  });
@@ -5248,11 +5307,11 @@ var WorkerRuntime = class {
5248
5307
  signalManager: signals ? new import_messaging3.WebsocketSignalManager(signals) : new import_messaging3.MemorySignalManager(new import_messaging3.MemorySignalManagerContext()),
5249
5308
  transportFactory: this._transportFactory
5250
5309
  });
5251
- await this._clientServices.open();
5310
+ await this._clientServices.open(new import_context12.Context());
5252
5311
  this._ready.wake(void 0);
5253
5312
  (0, import_log20.log)("started", void 0, {
5254
5313
  F: __dxlog_file22,
5255
- L: 62,
5314
+ L: 63,
5256
5315
  S: this,
5257
5316
  C: (f, a) => f(...a)
5258
5317
  });
@@ -5260,7 +5319,7 @@ var WorkerRuntime = class {
5260
5319
  this._ready.wake(err);
5261
5320
  import_log20.log.catch(err, void 0, {
5262
5321
  F: __dxlog_file22,
5263
- L: 65,
5322
+ L: 66,
5264
5323
  S: this,
5265
5324
  C: (f, a) => f(...a)
5266
5325
  });
@@ -5294,7 +5353,7 @@ var WorkerRuntime = class {
5294
5353
  _reconnectWebrtc() {
5295
5354
  (0, import_log20.log)("reconnecting webrtc...", void 0, {
5296
5355
  F: __dxlog_file22,
5297
- L: 102,
5356
+ L: 103,
5298
5357
  S: this,
5299
5358
  C: (f, a) => f(...a)
5300
5359
  });