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

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 (69) hide show
  1. package/dist/lib/browser/{chunk-FD4L7N4K.mjs → chunk-ZOTHWLK5.mjs} +623 -335
  2. package/dist/lib/browser/chunk-ZOTHWLK5.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +23 -19
  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 +2 -2
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/index.cjs +752 -461
  9. package/dist/lib/node/index.cjs.map +4 -4
  10. package/dist/lib/node/meta.json +1 -1
  11. package/dist/lib/node/packlets/testing/index.cjs +1016 -729
  12. package/dist/lib/node/packlets/testing/index.cjs.map +4 -4
  13. package/dist/types/src/packlets/identity/identity-manager.d.ts +2 -1
  14. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  15. package/dist/types/src/packlets/identity/identity.d.ts +3 -2
  16. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  17. package/dist/types/src/packlets/logging/logging-service.d.ts +6 -2
  18. package/dist/types/src/packlets/logging/logging-service.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/diagnostics.d.ts +46 -0
  21. package/dist/types/src/packlets/services/diagnostics.d.ts.map +1 -0
  22. package/dist/types/src/packlets/services/index.d.ts +1 -0
  23. package/dist/types/src/packlets/services/index.d.ts.map +1 -1
  24. package/dist/types/src/packlets/services/platform.d.ts +16 -0
  25. package/dist/types/src/packlets/services/platform.d.ts.map +1 -0
  26. package/dist/types/src/packlets/services/service-context.d.ts +2 -1
  27. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  28. package/dist/types/src/packlets/services/service-host.d.ts +7 -3
  29. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  30. package/dist/types/src/packlets/services/util.d.ts +6 -0
  31. package/dist/types/src/packlets/services/util.d.ts.map +1 -0
  32. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  33. package/dist/types/src/packlets/system/system-service.d.ts +12 -2
  34. package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
  35. package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts.map +1 -1
  36. package/dist/types/src/packlets/vault/worker-runtime.d.ts.map +1 -1
  37. package/dist/types/src/packlets/vault/worker-session.d.ts.map +1 -1
  38. package/dist/types/src/version.d.ts +2 -0
  39. package/dist/types/src/version.d.ts.map +1 -0
  40. package/package.json +34 -33
  41. package/src/packlets/devices/devices-service.test.ts +2 -1
  42. package/src/packlets/identity/identity-manager.test.ts +4 -3
  43. package/src/packlets/identity/identity-manager.ts +9 -5
  44. package/src/packlets/identity/identity-service.test.ts +2 -1
  45. package/src/packlets/identity/identity.test.ts +7 -6
  46. package/src/packlets/identity/identity.ts +8 -3
  47. package/src/packlets/invitations/device-invitation-protocol.test.ts +2 -1
  48. package/src/packlets/logging/logging-service.ts +17 -9
  49. package/src/packlets/network/network-service.test.ts +2 -1
  50. package/src/packlets/services/client-rpc-server.ts +4 -4
  51. package/src/packlets/services/diagnostics.ts +211 -0
  52. package/src/packlets/services/index.ts +1 -0
  53. package/src/packlets/services/platform.ts +48 -0
  54. package/src/packlets/services/service-context.test.ts +59 -0
  55. package/src/packlets/services/service-context.ts +13 -9
  56. package/src/packlets/services/service-host.test.ts +11 -10
  57. package/src/packlets/services/service-host.ts +37 -21
  58. package/src/packlets/services/service-registry.test.ts +3 -1
  59. package/src/packlets/services/util.ts +33 -0
  60. package/src/packlets/spaces/data-space.ts +17 -5
  61. package/src/packlets/spaces/spaces-service.test.ts +2 -1
  62. package/src/packlets/system/system-service.test.ts +1 -0
  63. package/src/packlets/system/system-service.ts +34 -2
  64. package/src/packlets/testing/test-builder.ts +1 -1
  65. package/src/packlets/vault/iframe-host-runtime.ts +2 -1
  66. package/src/packlets/vault/worker-runtime.ts +2 -1
  67. package/src/packlets/vault/worker-session.ts +6 -1
  68. package/src/version.ts +1 -0
  69. package/dist/lib/browser/chunk-FD4L7N4K.mjs.map +0 -7
@@ -471,8 +471,19 @@ import { writeMessages } from "@dxos/feed-store";
471
471
  import { invariant } from "@dxos/invariant";
472
472
  import { log as log2 } from "@dxos/log";
473
473
  import { AdmittedFeed } from "@dxos/protocols/proto/dxos/halo/credentials";
474
+ import { trace } from "@dxos/tracing";
475
+ function _ts_decorate(decorators, target, key, desc) {
476
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
477
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
478
+ r = Reflect.decorate(decorators, target, key, desc);
479
+ else
480
+ for (var i = decorators.length - 1; i >= 0; i--)
481
+ if (d = decorators[i])
482
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
483
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
484
+ }
474
485
  var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity.ts";
475
- var Identity = class {
486
+ var Identity = class Identity2 {
476
487
  constructor({ space, signer, identityKey, deviceKey }) {
477
488
  this.stateUpdate = new Event();
478
489
  this.space = space;
@@ -498,12 +509,12 @@ var Identity = class {
498
509
  get authorizedDeviceKeys() {
499
510
  return this._deviceStateMachine.authorizedDeviceKeys;
500
511
  }
501
- async open() {
512
+ async open(ctx) {
502
513
  await this.space.spaceState.addCredentialProcessor(this._deviceStateMachine);
503
514
  await this.space.spaceState.addCredentialProcessor(this._profileStateMachine);
504
- await this.space.open();
515
+ await this.space.open(ctx);
505
516
  }
506
- async close() {
517
+ async close(ctx) {
507
518
  await this.authVerifier.close();
508
519
  await this.space.spaceState.removeCredentialProcessor(this._profileStateMachine);
509
520
  await this.space.spaceState.removeCredentialProcessor(this._deviceStateMachine);
@@ -548,7 +559,7 @@ var Identity = class {
548
559
  getIdentityCredentialSigner() {
549
560
  invariant(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.", {
550
561
  F: __dxlog_file2,
551
- L: 134,
562
+ L: 139,
552
563
  S: this,
553
564
  A: [
554
565
  "this._deviceStateMachine.deviceCredentialChain",
@@ -572,7 +583,7 @@ var Identity = class {
572
583
  dataFeedKey
573
584
  }, {
574
585
  F: __dxlog_file2,
575
- L: 150,
586
+ L: 155,
576
587
  S: this,
577
588
  C: (f, a) => f(...a)
578
589
  });
@@ -613,18 +624,39 @@ var Identity = class {
613
624
  })));
614
625
  }
615
626
  };
627
+ _ts_decorate([
628
+ trace.span()
629
+ ], Identity.prototype, "open", null);
630
+ _ts_decorate([
631
+ trace.span()
632
+ ], Identity.prototype, "close", null);
633
+ Identity = _ts_decorate([
634
+ trace.resource()
635
+ ], Identity);
616
636
 
617
637
  // packages/sdk/client-services/src/packlets/identity/identity-manager.ts
618
638
  import { Event as Event2 } from "@dxos/async";
639
+ import { Context as Context3 } from "@dxos/context";
619
640
  import { createCredentialSignerWithKey as createCredentialSignerWithKey2, CredentialGenerator } from "@dxos/credentials";
620
641
  import { invariant as invariant2 } from "@dxos/invariant";
621
642
  import { PublicKey as PublicKey3 } from "@dxos/keys";
622
643
  import { log as log3 } from "@dxos/log";
623
- import { trace } from "@dxos/protocols";
644
+ import { trace as trace2 } from "@dxos/protocols";
624
645
  import { AdmittedFeed as AdmittedFeed2 } from "@dxos/protocols/proto/dxos/halo/credentials";
646
+ import { trace as Trace } from "@dxos/tracing";
625
647
  import { deferFunction } from "@dxos/util";
648
+ function _ts_decorate2(decorators, target, key, desc) {
649
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
650
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
651
+ r = Reflect.decorate(decorators, target, key, desc);
652
+ else
653
+ for (var i = decorators.length - 1; i >= 0; i--)
654
+ if (d = decorators[i])
655
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
656
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
657
+ }
626
658
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-manager.ts";
627
- var IdentityManager = class {
659
+ var IdentityManager = class IdentityManager2 {
628
660
  // TODO(burdon): IdentityManagerParams.
629
661
  // TODO(dmaretskyi): Perhaps this should take/generate the peerKey outside of an initialized identity.
630
662
  constructor(_metadataStore, _keyring, _feedStore, _spaceManager) {
@@ -637,14 +669,14 @@ var IdentityManager = class {
637
669
  get identity() {
638
670
  return this._identity;
639
671
  }
640
- async open() {
672
+ async open(ctx) {
641
673
  var _a;
642
674
  const traceId = PublicKey3.random().toHex();
643
- log3.trace("dxos.halo.identity-manager.open", trace.begin({
675
+ log3.trace("dxos.halo.identity-manager.open", trace2.begin({
644
676
  id: traceId
645
677
  }), {
646
678
  F: __dxlog_file3,
647
- L: 69,
679
+ L: 73,
648
680
  S: this,
649
681
  C: (f, a) => f(...a)
650
682
  });
@@ -654,43 +686,43 @@ var IdentityManager = class {
654
686
  identityRecord
655
687
  }, {
656
688
  F: __dxlog_file3,
657
- L: 73,
689
+ L: 77,
658
690
  S: this,
659
691
  C: (f, a) => f(...a)
660
692
  });
661
693
  if (identityRecord) {
662
694
  this._identity = await this._constructIdentity(identityRecord);
663
- await this._identity.open();
695
+ await this._identity.open(ctx);
664
696
  await this._identity.ready();
665
697
  log3.trace("dxos.halo.identity", {
666
698
  identityKey: identityRecord.identityKey,
667
699
  displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
668
700
  }, {
669
701
  F: __dxlog_file3,
670
- L: 78,
702
+ L: 82,
671
703
  S: this,
672
704
  C: (f, a) => f(...a)
673
705
  });
674
706
  this.stateUpdate.emit();
675
707
  }
676
- log3.trace("dxos.halo.identity-manager.open", trace.end({
708
+ log3.trace("dxos.halo.identity-manager.open", trace2.end({
677
709
  id: traceId
678
710
  }), {
679
711
  F: __dxlog_file3,
680
- L: 84,
712
+ L: 88,
681
713
  S: this,
682
714
  C: (f, a) => f(...a)
683
715
  });
684
716
  }
685
717
  async close() {
686
718
  var _a;
687
- await ((_a = this._identity) == null ? void 0 : _a.close());
719
+ await ((_a = this._identity) == null ? void 0 : _a.close(new Context3()));
688
720
  }
689
721
  async createIdentity({ displayName } = {}) {
690
722
  var _a;
691
723
  invariant2(!this._identity, "Identity already exists.", {
692
724
  F: __dxlog_file3,
693
- L: 92,
725
+ L: 96,
694
726
  S: this,
695
727
  A: [
696
728
  "!this._identity",
@@ -699,7 +731,7 @@ var IdentityManager = class {
699
731
  });
700
732
  log3("creating identity...", void 0, {
701
733
  F: __dxlog_file3,
702
- L: 93,
734
+ L: 97,
703
735
  S: this,
704
736
  C: (f, a) => f(...a)
705
737
  });
@@ -715,12 +747,12 @@ var IdentityManager = class {
715
747
  }
716
748
  };
717
749
  const identity = await this._constructIdentity(identityRecord);
718
- await identity.open();
750
+ await identity.open(new Context3());
719
751
  {
720
752
  const generator = new CredentialGenerator(this._keyring, identityRecord.identityKey, identityRecord.deviceKey);
721
753
  invariant2(identityRecord.haloSpace.genesisFeedKey, "Genesis feed key is required.", {
722
754
  F: __dxlog_file3,
723
- L: 112,
755
+ L: 116,
724
756
  S: this,
725
757
  A: [
726
758
  "identityRecord.haloSpace.genesisFeedKey",
@@ -729,7 +761,7 @@ var IdentityManager = class {
729
761
  });
730
762
  invariant2(identityRecord.haloSpace.dataFeedKey, "Data feed key is required.", {
731
763
  F: __dxlog_file3,
732
- L: 113,
764
+ L: 117,
733
765
  S: this,
734
766
  A: [
735
767
  "identityRecord.haloSpace.dataFeedKey",
@@ -764,7 +796,7 @@ var IdentityManager = class {
764
796
  displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
765
797
  }, {
766
798
  F: __dxlog_file3,
767
- L: 148,
799
+ L: 152,
768
800
  S: this,
769
801
  C: (f, a) => f(...a)
770
802
  });
@@ -774,7 +806,7 @@ var IdentityManager = class {
774
806
  deviceKey: identity.deviceKey
775
807
  }, {
776
808
  F: __dxlog_file3,
777
- L: 154,
809
+ L: 158,
778
810
  S: this,
779
811
  C: (f, a) => f(...a)
780
812
  });
@@ -789,13 +821,13 @@ var IdentityManager = class {
789
821
  params
790
822
  }, {
791
823
  F: __dxlog_file3,
792
- L: 162,
824
+ L: 166,
793
825
  S: this,
794
826
  C: (f, a) => f(...a)
795
827
  });
796
828
  invariant2(!this._identity, "Identity already exists.", {
797
829
  F: __dxlog_file3,
798
- L: 163,
830
+ L: 167,
799
831
  S: this,
800
832
  A: [
801
833
  "!this._identity",
@@ -814,7 +846,7 @@ var IdentityManager = class {
814
846
  }
815
847
  };
816
848
  const identity = await this._constructIdentity(identityRecord);
817
- await identity.open();
849
+ await identity.open(new Context3());
818
850
  this._identity = identity;
819
851
  await this._metadataStore.setIdentityRecord(identityRecord);
820
852
  await this._identity.ready();
@@ -823,7 +855,7 @@ var IdentityManager = class {
823
855
  displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
824
856
  }, {
825
857
  F: __dxlog_file3,
826
- L: 182,
858
+ L: 186,
827
859
  S: this,
828
860
  C: (f, a) => f(...a)
829
861
  });
@@ -833,7 +865,7 @@ var IdentityManager = class {
833
865
  deviceKey: identity.deviceKey
834
866
  }, {
835
867
  F: __dxlog_file3,
836
- L: 188,
868
+ L: 192,
837
869
  S: this,
838
870
  C: (f, a) => f(...a)
839
871
  });
@@ -842,7 +874,7 @@ var IdentityManager = class {
842
874
  async _constructIdentity(identityRecord) {
843
875
  invariant2(!this._identity, void 0, {
844
876
  F: __dxlog_file3,
845
- L: 193,
877
+ L: 197,
846
878
  S: this,
847
879
  A: [
848
880
  "!this._identity",
@@ -853,13 +885,13 @@ var IdentityManager = class {
853
885
  identityRecord
854
886
  }, {
855
887
  F: __dxlog_file3,
856
- L: 194,
888
+ L: 198,
857
889
  S: this,
858
890
  C: (f, a) => f(...a)
859
891
  });
860
892
  invariant2(identityRecord.haloSpace.controlFeedKey, void 0, {
861
893
  F: __dxlog_file3,
862
- L: 197,
894
+ L: 201,
863
895
  S: this,
864
896
  A: [
865
897
  "identityRecord.haloSpace.controlFeedKey",
@@ -871,7 +903,7 @@ var IdentityManager = class {
871
903
  });
872
904
  invariant2(identityRecord.haloSpace.dataFeedKey, void 0, {
873
905
  F: __dxlog_file3,
874
- L: 201,
906
+ L: 205,
875
907
  S: this,
876
908
  A: [
877
909
  "identityRecord.haloSpace.dataFeedKey",
@@ -903,7 +935,7 @@ var IdentityManager = class {
903
935
  identityKey: identityRecord.identityKey
904
936
  }, {
905
937
  F: __dxlog_file3,
906
- L: 225,
938
+ L: 229,
907
939
  S: this,
908
940
  C: (f, a) => f(...a)
909
941
  });
@@ -924,7 +956,7 @@ var IdentityManager = class {
924
956
  onAuthFailure: () => {
925
957
  log3.warn("auth failure", void 0, {
926
958
  F: __dxlog_file3,
927
- L: 244,
959
+ L: 248,
928
960
  S: this,
929
961
  C: (f, a) => f(...a)
930
962
  });
@@ -933,6 +965,12 @@ var IdentityManager = class {
933
965
  });
934
966
  }
935
967
  };
968
+ _ts_decorate2([
969
+ Trace.span()
970
+ ], IdentityManager.prototype, "open", null);
971
+ IdentityManager = _ts_decorate2([
972
+ Trace.resource()
973
+ ], IdentityManager);
936
974
 
937
975
  // packages/sdk/client-services/src/packlets/identity/identity-service.ts
938
976
  import { Stream as Stream7 } from "@dxos/codec-protobuf";
@@ -1084,25 +1122,25 @@ var DeviceInvitationProtocol = class {
1084
1122
  // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
1085
1123
  import { PushStream, scheduleTask as scheduleTask2, TimeoutError, Trigger as Trigger3 } from "@dxos/async";
1086
1124
  import { AuthenticatingInvitationObservable, AUTHENTICATION_CODE_LENGTH, CancellableInvitationObservable, INVITATION_TIMEOUT } from "@dxos/client-protocol";
1087
- import { Context as Context4 } from "@dxos/context";
1125
+ import { Context as Context5 } from "@dxos/context";
1088
1126
  import { generatePasscode } from "@dxos/credentials";
1089
1127
  import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError2 } from "@dxos/errors";
1090
1128
  import { invariant as invariant6 } from "@dxos/invariant";
1091
1129
  import { PublicKey as PublicKey5 } from "@dxos/keys";
1092
1130
  import { log as log5 } from "@dxos/log";
1093
1131
  import { createTeleportProtocolFactory, StarTopology } from "@dxos/network-manager";
1094
- import { trace as trace3 } from "@dxos/protocols";
1132
+ import { trace as trace4 } from "@dxos/protocols";
1095
1133
  import { Invitation as Invitation3 } from "@dxos/protocols/proto/dxos/client/services";
1096
1134
  import { AuthenticationResponse as AuthenticationResponse2 } from "@dxos/protocols/proto/dxos/halo/invitations";
1097
1135
 
1098
1136
  // packages/sdk/client-services/src/packlets/invitations/invitation-extension.ts
1099
1137
  import { Trigger as Trigger2 } from "@dxos/async";
1100
- import { cancelWithContext, Context as Context3 } from "@dxos/context";
1138
+ import { cancelWithContext, Context as Context4 } from "@dxos/context";
1101
1139
  import { InvalidInvitationExtensionRoleError } from "@dxos/errors";
1102
1140
  import { invariant as invariant5 } from "@dxos/invariant";
1103
1141
  import { PublicKey as PublicKey4 } from "@dxos/keys";
1104
1142
  import { log as log4 } from "@dxos/log";
1105
- import { schema as schema2, trace as trace2 } from "@dxos/protocols";
1143
+ import { schema as schema2, trace as trace3 } from "@dxos/protocols";
1106
1144
  import { Invitation as Invitation2 } from "@dxos/protocols/proto/dxos/client/services";
1107
1145
  import { AuthenticationResponse, Options } from "@dxos/protocols/proto/dxos/halo/invitations";
1108
1146
  import { RpcExtension } from "@dxos/teleport";
@@ -1120,7 +1158,7 @@ var InvitationHostExtension = class extends RpcExtension {
1120
1158
  }
1121
1159
  });
1122
1160
  this._callbacks = _callbacks;
1123
- this._ctx = new Context3();
1161
+ this._ctx = new Context4();
1124
1162
  this._remoteOptionsTrigger = new Trigger2();
1125
1163
  this.invitation = void 0;
1126
1164
  this.guestProfile = void 0;
@@ -1149,7 +1187,7 @@ var InvitationHostExtension = class extends RpcExtension {
1149
1187
  introduce: async (request) => {
1150
1188
  const { profile, invitationId } = request;
1151
1189
  const traceId = PublicKey4.random().toHex();
1152
- log4.trace("dxos.sdk.invitation-handler.host.introduce", trace2.begin({
1190
+ log4.trace("dxos.sdk.invitation-handler.host.introduce", trace3.begin({
1153
1191
  id: traceId
1154
1192
  }), {
1155
1193
  F: __dxlog_file6,
@@ -1186,7 +1224,7 @@ var InvitationHostExtension = class extends RpcExtension {
1186
1224
  ...this.invitation,
1187
1225
  state: Invitation2.State.READY_FOR_AUTHENTICATION
1188
1226
  });
1189
- log4.trace("dxos.sdk.invitation-handler.host.introduce", trace2.end({
1227
+ log4.trace("dxos.sdk.invitation-handler.host.introduce", trace3.end({
1190
1228
  id: traceId
1191
1229
  }), {
1192
1230
  F: __dxlog_file6,
@@ -1201,7 +1239,7 @@ var InvitationHostExtension = class extends RpcExtension {
1201
1239
  },
1202
1240
  authenticate: async ({ authCode: code }) => {
1203
1241
  const traceId = PublicKey4.random().toHex();
1204
- log4.trace("dxos.sdk.invitation-handler.host.authenticate", trace2.begin({
1242
+ log4.trace("dxos.sdk.invitation-handler.host.authenticate", trace3.begin({
1205
1243
  id: traceId
1206
1244
  }), {
1207
1245
  F: __dxlog_file6,
@@ -1264,7 +1302,7 @@ var InvitationHostExtension = class extends RpcExtension {
1264
1302
  break;
1265
1303
  }
1266
1304
  }
1267
- log4.trace("dxos.sdk.invitation-handler.host.authenticate", trace2.end({
1305
+ log4.trace("dxos.sdk.invitation-handler.host.authenticate", trace3.end({
1268
1306
  id: traceId,
1269
1307
  data: {
1270
1308
  status
@@ -1281,7 +1319,7 @@ var InvitationHostExtension = class extends RpcExtension {
1281
1319
  },
1282
1320
  admit: async (request) => {
1283
1321
  const traceId = PublicKey4.random().toHex();
1284
- log4.trace("dxos.sdk.invitation-handler.host.admit", trace2.begin({
1322
+ log4.trace("dxos.sdk.invitation-handler.host.admit", trace3.begin({
1285
1323
  id: traceId
1286
1324
  }), {
1287
1325
  F: __dxlog_file6,
@@ -1303,7 +1341,7 @@ var InvitationHostExtension = class extends RpcExtension {
1303
1341
  throw new Error("Not authenticated");
1304
1342
  }
1305
1343
  const response = await this._callbacks.admit(request);
1306
- log4.trace("dxos.sdk.invitation-handler.host.admit", trace2.end({
1344
+ log4.trace("dxos.sdk.invitation-handler.host.admit", trace3.end({
1307
1345
  id: traceId
1308
1346
  }), {
1309
1347
  F: __dxlog_file6,
@@ -1356,7 +1394,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1356
1394
  }
1357
1395
  });
1358
1396
  this._callbacks = _callbacks;
1359
- this._ctx = new Context3();
1397
+ this._ctx = new Context4();
1360
1398
  this._remoteOptionsTrigger = new Trigger2();
1361
1399
  }
1362
1400
  async getHandlers() {
@@ -1471,7 +1509,7 @@ var InvitationsHandler = class {
1471
1509
  ...protocol.getInvitationContext()
1472
1510
  };
1473
1511
  const stream = new PushStream();
1474
- const ctx = new Context4({
1512
+ const ctx = new Context5({
1475
1513
  onError: (err) => {
1476
1514
  void ctx.dispose();
1477
1515
  stream.error(err);
@@ -1527,7 +1565,7 @@ var InvitationsHandler = class {
1527
1565
  scheduleTask2(ctx, async () => {
1528
1566
  const traceId = PublicKey5.random().toHex();
1529
1567
  try {
1530
- log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace3.begin({
1568
+ log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace4.begin({
1531
1569
  id: traceId
1532
1570
  }), {
1533
1571
  F: __dxlog_file7,
@@ -1563,7 +1601,7 @@ var InvitationsHandler = class {
1563
1601
  ...invitation,
1564
1602
  state: Invitation3.State.SUCCESS
1565
1603
  });
1566
- log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace3.end({
1604
+ log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace4.end({
1567
1605
  id: traceId
1568
1606
  }), {
1569
1607
  F: __dxlog_file7,
@@ -1594,7 +1632,7 @@ var InvitationsHandler = class {
1594
1632
  });
1595
1633
  stream.error(err);
1596
1634
  }
1597
- log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace3.error({
1635
+ log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace4.error({
1598
1636
  id: traceId,
1599
1637
  error: err
1600
1638
  }), {
@@ -1702,7 +1740,7 @@ var InvitationsHandler = class {
1702
1740
  ...newData
1703
1741
  });
1704
1742
  };
1705
- const ctx = new Context4({
1743
+ const ctx = new Context5({
1706
1744
  onError: (err) => {
1707
1745
  if (err instanceof TimeoutError) {
1708
1746
  log5("timeout", {
@@ -1759,7 +1797,7 @@ var InvitationsHandler = class {
1759
1797
  scheduleTask2(ctx, async () => {
1760
1798
  const traceId = PublicKey5.random().toHex();
1761
1799
  try {
1762
- log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace3.begin({
1800
+ log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace4.begin({
1763
1801
  id: traceId
1764
1802
  }), {
1765
1803
  F: __dxlog_file7,
@@ -1878,7 +1916,7 @@ var InvitationsHandler = class {
1878
1916
  ...result,
1879
1917
  state: Invitation3.State.SUCCESS
1880
1918
  });
1881
- log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace3.end({
1919
+ log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace4.end({
1882
1920
  id: traceId
1883
1921
  }), {
1884
1922
  F: __dxlog_file7,
@@ -1908,7 +1946,7 @@ var InvitationsHandler = class {
1908
1946
  });
1909
1947
  stream.error(err);
1910
1948
  }
1911
- log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace3.error({
1949
+ log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace4.error({
1912
1950
  id: traceId,
1913
1951
  error: err
1914
1952
  }), {
@@ -2385,15 +2423,181 @@ var ClientRpcServer = class {
2385
2423
  }
2386
2424
  };
2387
2425
 
2426
+ // packages/sdk/client-services/src/packlets/services/diagnostics.ts
2427
+ import { getFirstStreamValue } from "@dxos/codec-protobuf";
2428
+ import { credentialTypeFilter } from "@dxos/credentials";
2429
+ import { DocumentModel } from "@dxos/document-model";
2430
+ import { invariant as invariant9 } from "@dxos/invariant";
2431
+ import { log as log8 } from "@dxos/log";
2432
+ import { STORAGE_VERSION } from "@dxos/protocols";
2433
+ import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
2434
+
2435
+ // packages/sdk/client-services/src/version.ts
2436
+ var DXOS_VERSION = "0.1.56-main.c19b7cd";
2437
+
2438
+ // packages/sdk/client-services/src/packlets/services/platform.ts
2439
+ var getPlatform = () => {
2440
+ if (process.browser) {
2441
+ if (typeof window !== "undefined") {
2442
+ const { userAgent } = window.navigator;
2443
+ return {
2444
+ type: "browser",
2445
+ userAgent,
2446
+ uptime: Math.floor((Date.now() - window.performance.timeOrigin) / 1e3)
2447
+ };
2448
+ } else {
2449
+ return {
2450
+ type: "shared-worker",
2451
+ uptime: Math.floor((Date.now() - performance.timeOrigin) / 1e3)
2452
+ };
2453
+ }
2454
+ } else {
2455
+ const { platform, version, arch } = process;
2456
+ return {
2457
+ type: "node",
2458
+ platform: `${platform} ${version} ${arch}`,
2459
+ runtime: process.version,
2460
+ uptime: Math.floor(process.uptime()),
2461
+ memory: process.memoryUsage()
2462
+ };
2463
+ }
2464
+ };
2465
+
2466
+ // packages/sdk/client-services/src/packlets/services/diagnostics.ts
2467
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
2468
+ var DEFAULT_TIMEOUT = 1e3;
2469
+ var createDiagnostics = async (clientServices, serviceContext, config) => {
2470
+ var _a, _b, _c;
2471
+ const diagnostics = {
2472
+ created: new Date().toISOString(),
2473
+ platform: getPlatform(),
2474
+ client: {
2475
+ version: DXOS_VERSION,
2476
+ storage: {
2477
+ version: STORAGE_VERSION
2478
+ }
2479
+ }
2480
+ };
2481
+ {
2482
+ invariant9(clientServices.LoggingService, "SystemService is not available.", {
2483
+ F: __dxlog_file10,
2484
+ L: 87,
2485
+ S: void 0,
2486
+ A: [
2487
+ "clientServices.LoggingService",
2488
+ "'SystemService is not available.'"
2489
+ ]
2490
+ });
2491
+ diagnostics.metrics = await getFirstStreamValue(clientServices.LoggingService.queryMetrics({}), {
2492
+ timeout: DEFAULT_TIMEOUT
2493
+ }).catch(() => void 0);
2494
+ }
2495
+ const identity = serviceContext.identityManager.identity;
2496
+ if (identity) {
2497
+ diagnostics.identity = {
2498
+ identityKey: identity.identityKey,
2499
+ spaceKey: identity.space.key,
2500
+ profile: identity.profileDocument
2501
+ };
2502
+ const { devices } = (_a = await getFirstStreamValue(clientServices.DevicesService.queryDevices(), {
2503
+ timeout: DEFAULT_TIMEOUT
2504
+ }).catch(() => void 0)) != null ? _a : {};
2505
+ diagnostics.devices = devices;
2506
+ if (serviceContext.dataSpaceManager) {
2507
+ diagnostics.spaces = await Promise.all((_b = Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space))) != null ? _b : []);
2508
+ }
2509
+ const { feeds = [] } = (_c = await getFirstStreamValue(clientServices.DevtoolsHost.subscribeToFeeds({}), {
2510
+ timeout: DEFAULT_TIMEOUT
2511
+ }).catch(() => void 0)) != null ? _c : {};
2512
+ diagnostics.feeds = feeds.map(({ feedKey, bytes, length }) => ({
2513
+ feedKey,
2514
+ bytes,
2515
+ length
2516
+ }));
2517
+ }
2518
+ diagnostics.config = config.values;
2519
+ return diagnostics;
2520
+ };
2521
+ var getProperties = (space) => {
2522
+ let properties = {};
2523
+ try {
2524
+ const propertiesItem = space.dataPipeline.itemManager.items.find((item) => {
2525
+ var _a, _b;
2526
+ return ((_a = item.modelMeta) == null ? void 0 : _a.type) === DocumentModel.meta.type && ((_b = item.state) == null ? void 0 : _b.type) === "dxos.sdk.client.Properties";
2527
+ });
2528
+ const state = propertiesItem == null ? void 0 : propertiesItem.state;
2529
+ properties = state == null ? void 0 : state.data;
2530
+ } catch (err) {
2531
+ log8.warn(err.message, void 0, {
2532
+ F: __dxlog_file10,
2533
+ L: 144,
2534
+ S: void 0,
2535
+ C: (f, a) => f(...a)
2536
+ });
2537
+ }
2538
+ return properties;
2539
+ };
2540
+ var getSpaceStats = async (space) => {
2541
+ var _a, _b, _c, _d, _e, _f;
2542
+ const stats = {
2543
+ key: space.key,
2544
+ metrics: space.metrics,
2545
+ epochs: space.inner.spaceState.credentials.filter(credentialTypeFilter("dxos.halo.credentials.Epoch")).map((credential) => ({
2546
+ ...credential.subject.assertion,
2547
+ id: credential.id
2548
+ })),
2549
+ members: Array.from(space.inner.spaceState.members.values()).map((member) => {
2550
+ var _a2;
2551
+ return {
2552
+ identity: {
2553
+ identityKey: member.key,
2554
+ profile: {
2555
+ displayName: (_a2 = member.assertion.profile) == null ? void 0 : _a2.displayName
2556
+ }
2557
+ },
2558
+ presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember.PresenceState.ONLINE : SpaceMember.PresenceState.OFFLINE
2559
+ };
2560
+ }),
2561
+ pipeline: {
2562
+ // TODO(burdon): Pick properties from credentials if needed.
2563
+ // currentEpoch: space.dataPipeline.currentEpoch,
2564
+ // appliedEpoch: space.dataPipeline.appliedEpoch,
2565
+ controlFeeds: space.inner.controlPipeline.state.feeds.map((feed) => feed.key),
2566
+ currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
2567
+ targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
2568
+ totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe,
2569
+ // TODO(burdon): Empty?
2570
+ dataFeeds: (_b = (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.feeds.map((feed) => feed.key)) != null ? _b : [],
2571
+ startDataTimeframe: (_c = space.dataPipeline.pipelineState) == null ? void 0 : _c.startTimeframe,
2572
+ currentDataTimeframe: (_d = space.dataPipeline.pipelineState) == null ? void 0 : _d.timeframe,
2573
+ targetDataTimeframe: (_e = space.dataPipeline.pipelineState) == null ? void 0 : _e.targetTimeframe,
2574
+ totalDataTimeframe: (_f = space.dataPipeline.pipelineState) == null ? void 0 : _f.endTimeframe
2575
+ }
2576
+ };
2577
+ if (space.dataPipeline.itemManager) {
2578
+ Object.assign(stats, {
2579
+ properties: getProperties(space),
2580
+ db: {
2581
+ objects: space.dataPipeline.itemManager.entities.size
2582
+ }
2583
+ });
2584
+ }
2585
+ if (stats.metrics) {
2586
+ const { open, ready } = stats.metrics;
2587
+ stats.metrics.startupTime = open && ready && ready.getTime() - open.getTime();
2588
+ }
2589
+ return stats;
2590
+ };
2591
+
2388
2592
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2389
2593
  import { Event as Event5, scheduleTask as scheduleTask4, synchronized, trackLeaks } from "@dxos/async";
2390
2594
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
2391
- import { cancelWithContext as cancelWithContext2, Context as Context6 } from "@dxos/context";
2595
+ import { cancelWithContext as cancelWithContext2, Context as Context7 } from "@dxos/context";
2392
2596
  import { timed } from "@dxos/debug";
2393
2597
  import { createMappedFeedWriter } from "@dxos/echo-pipeline";
2394
2598
  import { CancelledError, SystemError } from "@dxos/errors";
2395
2599
  import { PublicKey as PublicKey7 } from "@dxos/keys";
2396
- import { log as log9 } from "@dxos/log";
2600
+ import { log as log10 } from "@dxos/log";
2397
2601
  import { SpaceState } from "@dxos/protocols/proto/dxos/client/services";
2398
2602
  import { AdmittedFeed as AdmittedFeed3 } from "@dxos/protocols/proto/dxos/halo/credentials";
2399
2603
  import { Timeframe } from "@dxos/timeframe";
@@ -2401,21 +2605,21 @@ import { ComplexSet as ComplexSet2 } from "@dxos/util";
2401
2605
 
2402
2606
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
2403
2607
  import { DeferredTask, Event as Event4, scheduleTask as scheduleTask3, sleep, TimeoutError as TimeoutError2, Trigger as Trigger4 } from "@dxos/async";
2404
- import { Context as Context5, rejectOnDispose } from "@dxos/context";
2405
- import { invariant as invariant9 } from "@dxos/invariant";
2608
+ import { Context as Context6, rejectOnDispose } from "@dxos/context";
2609
+ import { invariant as invariant10 } from "@dxos/invariant";
2406
2610
  import { PublicKey as PublicKey6 } from "@dxos/keys";
2407
- import { log as log8 } from "@dxos/log";
2611
+ import { log as log9 } from "@dxos/log";
2408
2612
  import { schema as schema3 } from "@dxos/protocols";
2409
2613
  import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
2410
2614
  import { ComplexMap as ComplexMap2, ComplexSet, entry } from "@dxos/util";
2411
- var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
2615
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
2412
2616
  var DEFAULT_RETRY_TIMEOUT = 1e3;
2413
2617
  var DEFAULT_SUCCESS_DELAY = 1e3;
2414
2618
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
2415
2619
  var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
2416
2620
  var NotarizationPlugin = class {
2417
2621
  constructor() {
2418
- this._ctx = new Context5();
2622
+ this._ctx = new Context6();
2419
2623
  this._extensionOpened = new Event4();
2420
2624
  this._extensions = /* @__PURE__ */ new Set();
2421
2625
  this._processedCredentials = new ComplexSet(PublicKey6.hash);
@@ -2433,16 +2637,16 @@ var NotarizationPlugin = class {
2433
2637
  * Request credentials to be notarized.
2434
2638
  */
2435
2639
  async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
2436
- log8("notarize", {
2640
+ log9("notarize", {
2437
2641
  credentials
2438
2642
  }, {
2439
- F: __dxlog_file10,
2643
+ F: __dxlog_file11,
2440
2644
  L: 90,
2441
2645
  S: this,
2442
2646
  C: (f, a) => f(...a)
2443
2647
  });
2444
- invariant9(credentials.every((credential) => credential.id), "Credentials must have an id", {
2445
- F: __dxlog_file10,
2648
+ invariant10(credentials.every((credential) => credential.id), "Credentials must have an id", {
2649
+ F: __dxlog_file11,
2446
2650
  L: 91,
2447
2651
  S: this,
2448
2652
  A: [
@@ -2453,10 +2657,10 @@ var NotarizationPlugin = class {
2453
2657
  const errors = new Trigger4();
2454
2658
  const ctx = this._ctx.derive({
2455
2659
  onError: (err) => {
2456
- log8.warn("Notarization error", {
2660
+ log9.warn("Notarization error", {
2457
2661
  err
2458
2662
  }, {
2459
- F: __dxlog_file10,
2663
+ F: __dxlog_file11,
2460
2664
  L: 99,
2461
2665
  S: this,
2462
2666
  C: (f, a) => f(...a)
@@ -2468,11 +2672,11 @@ var NotarizationPlugin = class {
2468
2672
  opCtx == null ? void 0 : opCtx.onDispose(() => ctx.dispose());
2469
2673
  if (timeout !== 0) {
2470
2674
  scheduleTask3(ctx, () => {
2471
- log8.warn("Notarization timeout", {
2675
+ log9.warn("Notarization timeout", {
2472
2676
  timeout,
2473
2677
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
2474
2678
  }, {
2475
- F: __dxlog_file10,
2679
+ F: __dxlog_file11,
2476
2680
  L: 111,
2477
2681
  S: this,
2478
2682
  C: (f, a) => f(...a)
@@ -2492,10 +2696,10 @@ var NotarizationPlugin = class {
2492
2696
  ...this._extensions
2493
2697
  ].find((peer2) => !peersTried.has(peer2));
2494
2698
  if (!peer) {
2495
- log8.warn("Exhausted all peers to notarize with", {
2699
+ log9.warn("Exhausted all peers to notarize with", {
2496
2700
  retryIn: retryTimeout
2497
2701
  }, {
2498
- F: __dxlog_file10,
2702
+ F: __dxlog_file11,
2499
2703
  L: 136,
2500
2704
  S: this,
2501
2705
  C: (f, a) => f(...a)
@@ -2505,11 +2709,11 @@ var NotarizationPlugin = class {
2505
2709
  return;
2506
2710
  }
2507
2711
  peersTried.add(peer);
2508
- log8("try notarizing", {
2712
+ log9("try notarizing", {
2509
2713
  peer: peer.localPeerId,
2510
2714
  credentialId: credentials.map((credential) => credential.id)
2511
2715
  }, {
2512
- F: __dxlog_file10,
2716
+ F: __dxlog_file11,
2513
2717
  L: 143,
2514
2718
  S: this,
2515
2719
  C: (f, a) => f(...a)
@@ -2517,8 +2721,8 @@ var NotarizationPlugin = class {
2517
2721
  await peer.rpc.NotarizationService.notarize({
2518
2722
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
2519
2723
  });
2520
- log8("success", void 0, {
2521
- F: __dxlog_file10,
2724
+ log9("success", void 0, {
2725
+ F: __dxlog_file11,
2522
2726
  L: 147,
2523
2727
  S: this,
2524
2728
  C: (f, a) => f(...a)
@@ -2526,8 +2730,8 @@ var NotarizationPlugin = class {
2526
2730
  await sleep(successDelay);
2527
2731
  } catch (err) {
2528
2732
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
2529
- log8.warn("error notarizing (recoverable)", err, {
2530
- F: __dxlog_file10,
2733
+ log9.warn("error notarizing (recoverable)", err, {
2734
+ F: __dxlog_file11,
2531
2735
  L: 151,
2532
2736
  S: this,
2533
2737
  C: (f, a) => f(...a)
@@ -2544,8 +2748,8 @@ var NotarizationPlugin = class {
2544
2748
  allNotarized,
2545
2749
  errors.wait()
2546
2750
  ]);
2547
- log8("done", void 0, {
2548
- F: __dxlog_file10,
2751
+ log9("done", void 0, {
2752
+ F: __dxlog_file11,
2549
2753
  L: 162,
2550
2754
  S: this,
2551
2755
  C: (f, a) => f(...a)
@@ -2567,8 +2771,8 @@ var NotarizationPlugin = class {
2567
2771
  this._processCredentialsTriggers.delete(credential.id);
2568
2772
  }
2569
2773
  setWriter(writer) {
2570
- invariant9(!this._writer, "Writer already set.", {
2571
- F: __dxlog_file10,
2774
+ invariant10(!this._writer, "Writer already set.", {
2775
+ F: __dxlog_file11,
2572
2776
  L: 181,
2573
2777
  S: this,
2574
2778
  A: [
@@ -2593,8 +2797,8 @@ var NotarizationPlugin = class {
2593
2797
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
2594
2798
  }
2595
2799
  for (const credential of (_a = request.credentials) != null ? _a : []) {
2596
- invariant9(credential.id, "Credential must have an id", {
2597
- F: __dxlog_file10,
2800
+ invariant10(credential.id, "Credential must have an id", {
2801
+ F: __dxlog_file11,
2598
2802
  L: 200,
2599
2803
  S: this,
2600
2804
  A: [
@@ -2611,10 +2815,10 @@ var NotarizationPlugin = class {
2611
2815
  createExtension() {
2612
2816
  const extension = new NotarizationTeleportExtension({
2613
2817
  onOpen: async () => {
2614
- log8("extension opened", {
2818
+ log9("extension opened", {
2615
2819
  peer: extension.localPeerId
2616
2820
  }, {
2617
- F: __dxlog_file10,
2821
+ F: __dxlog_file11,
2618
2822
  L: 211,
2619
2823
  S: this,
2620
2824
  C: (f, a) => f(...a)
@@ -2623,10 +2827,10 @@ var NotarizationPlugin = class {
2623
2827
  this._extensionOpened.emit();
2624
2828
  },
2625
2829
  onClose: async () => {
2626
- log8("extension closed", {
2830
+ log9("extension closed", {
2627
2831
  peer: extension.localPeerId
2628
2832
  }, {
2629
- F: __dxlog_file10,
2833
+ F: __dxlog_file11,
2630
2834
  L: 216,
2631
2835
  S: this,
2632
2836
  C: (f, a) => f(...a)
@@ -2670,7 +2874,7 @@ var NotarizationTeleportExtension = class extends RpcExtension2 {
2670
2874
  };
2671
2875
 
2672
2876
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2673
- function _ts_decorate(decorators, target, key, desc) {
2877
+ function _ts_decorate3(decorators, target, key, desc) {
2674
2878
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2675
2879
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2676
2880
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2680,10 +2884,11 @@ function _ts_decorate(decorators, target, key, desc) {
2680
2884
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2681
2885
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2682
2886
  }
2683
- var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
2887
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
2888
+ var ENABLE_FEED_PURGE = false;
2684
2889
  var DataSpace = class DataSpace2 {
2685
2890
  constructor(params) {
2686
- this._ctx = new Context6();
2891
+ this._ctx = new Context7();
2687
2892
  this._notarizationPlugin = new NotarizationPlugin();
2688
2893
  this._state = SpaceState.CLOSED;
2689
2894
  /**
@@ -2741,7 +2946,7 @@ var DataSpace = class DataSpace2 {
2741
2946
  async _open() {
2742
2947
  await this._notarizationPlugin.open();
2743
2948
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
2744
- await this._inner.open();
2949
+ await this._inner.open(new Context7());
2745
2950
  this._state = SpaceState.CONTROL_ONLY;
2746
2951
  this.stateUpdate.emit();
2747
2952
  this.metrics = {};
@@ -2755,7 +2960,7 @@ var DataSpace = class DataSpace2 {
2755
2960
  await ((_b = (_a = this._callbacks).beforeClose) == null ? void 0 : _b.call(_a));
2756
2961
  this._state = SpaceState.CLOSED;
2757
2962
  await this._ctx.dispose();
2758
- this._ctx = new Context6();
2963
+ this._ctx = new Context7();
2759
2964
  await this.authVerifier.close();
2760
2965
  await this._inner.close();
2761
2966
  await this._inner.spaceState.removeCredentialProcessor(this._notarizationPlugin);
@@ -2778,17 +2983,17 @@ var DataSpace = class DataSpace2 {
2778
2983
  await this.initializeDataPipeline();
2779
2984
  } catch (err) {
2780
2985
  if (err instanceof CancelledError) {
2781
- log9("data pipeline initialization cancelled", err, {
2782
- F: __dxlog_file11,
2783
- L: 193,
2986
+ log10("data pipeline initialization cancelled", err, {
2987
+ F: __dxlog_file12,
2988
+ L: 199,
2784
2989
  S: this,
2785
2990
  C: (f, a) => f(...a)
2786
2991
  });
2787
2992
  return;
2788
2993
  }
2789
- log9.error("Error initializing data pipeline", err, {
2790
- F: __dxlog_file11,
2791
- L: 197,
2994
+ log10.error("Error initializing data pipeline", err, {
2995
+ F: __dxlog_file12,
2996
+ L: 203,
2792
2997
  S: this,
2793
2998
  C: (f, a) => f(...a)
2794
2999
  });
@@ -2812,9 +3017,9 @@ var DataSpace = class DataSpace2 {
2812
3017
  });
2813
3018
  this.metrics.controlPipelineReady = new Date();
2814
3019
  await this._createWritableFeeds();
2815
- log9("writable feeds created", void 0, {
2816
- F: __dxlog_file11,
2817
- L: 221,
3020
+ log10("writable feeds created", void 0, {
3021
+ F: __dxlog_file12,
3022
+ L: 227,
2818
3023
  S: this,
2819
3024
  C: (f, a) => f(...a)
2820
3025
  });
@@ -2829,9 +3034,9 @@ var DataSpace = class DataSpace2 {
2829
3034
  await this._inner.initializeDataPipeline();
2830
3035
  this.metrics.dataPipelineOpen = new Date();
2831
3036
  await cancelWithContext2(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
2832
- log9("waiting for data pipeline to reach target timeframe", void 0, {
2833
- F: __dxlog_file11,
2834
- L: 242,
3037
+ log10("waiting for data pipeline to reach target timeframe", void 0, {
3038
+ F: __dxlog_file12,
3039
+ L: 248,
2835
3040
  S: this,
2836
3041
  C: (f, a) => f(...a)
2837
3042
  });
@@ -2840,9 +3045,9 @@ var DataSpace = class DataSpace2 {
2840
3045
  breakOnStall: false
2841
3046
  });
2842
3047
  this.metrics.dataPipelineReady = new Date();
2843
- log9("data pipeline ready", void 0, {
2844
- F: __dxlog_file11,
2845
- L: 251,
3048
+ log10("data pipeline ready", void 0, {
3049
+ F: __dxlog_file12,
3050
+ L: 257,
2846
3051
  S: this,
2847
3052
  C: (f, a) => f(...a)
2848
3053
  });
@@ -2915,10 +3120,13 @@ var DataSpace = class DataSpace2 {
2915
3120
  receipt.seq
2916
3121
  ]
2917
3122
  ]));
2918
- for (const feed of (_b = (_a = this.inner.dataPipeline.pipelineState) == null ? void 0 : _a.feeds) != null ? _b : []) {
2919
- const indexBeforeEpoch = epoch.timeframe.get(feed.key);
2920
- if (indexBeforeEpoch) {
2921
- await feed.clear(0, indexBeforeEpoch + 1);
3123
+ if (ENABLE_FEED_PURGE) {
3124
+ for (const feed of (_b = (_a = this.inner.dataPipeline.pipelineState) == null ? void 0 : _a.feeds) != null ? _b : []) {
3125
+ const indexBeforeEpoch = epoch.timeframe.get(feed.key);
3126
+ if (indexBeforeEpoch === void 0) {
3127
+ continue;
3128
+ }
3129
+ await feed.safeClear(0, indexBeforeEpoch + 1);
2922
3130
  }
2923
3131
  }
2924
3132
  }
@@ -2940,33 +3148,33 @@ var DataSpace = class DataSpace2 {
2940
3148
  this.stateUpdate.emit();
2941
3149
  }
2942
3150
  };
2943
- _ts_decorate([
3151
+ _ts_decorate3([
2944
3152
  synchronized
2945
3153
  ], DataSpace.prototype, "open", null);
2946
- _ts_decorate([
3154
+ _ts_decorate3([
2947
3155
  synchronized
2948
3156
  ], DataSpace.prototype, "close", null);
2949
- _ts_decorate([
3157
+ _ts_decorate3([
2950
3158
  timed(1e4)
2951
3159
  ], DataSpace.prototype, "_createWritableFeeds", null);
2952
- _ts_decorate([
3160
+ _ts_decorate3([
2953
3161
  synchronized
2954
3162
  ], DataSpace.prototype, "activate", null);
2955
- _ts_decorate([
3163
+ _ts_decorate3([
2956
3164
  synchronized
2957
3165
  ], DataSpace.prototype, "deactivate", null);
2958
- DataSpace = _ts_decorate([
3166
+ DataSpace = _ts_decorate3([
2959
3167
  trackLeaks("open", "close")
2960
3168
  ], DataSpace);
2961
3169
 
2962
3170
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
2963
3171
  import { Event as Event6, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
2964
- import { cancelWithContext as cancelWithContext3, Context as Context7 } from "@dxos/context";
3172
+ import { cancelWithContext as cancelWithContext3, Context as Context8 } from "@dxos/context";
2965
3173
  import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
2966
- import { invariant as invariant10 } from "@dxos/invariant";
3174
+ import { invariant as invariant11 } from "@dxos/invariant";
2967
3175
  import { PublicKey as PublicKey8 } from "@dxos/keys";
2968
- import { log as log10 } from "@dxos/log";
2969
- import { trace as trace4 } from "@dxos/protocols";
3176
+ import { log as log11 } from "@dxos/log";
3177
+ import { trace as trace5 } from "@dxos/protocols";
2970
3178
  import { SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
2971
3179
  import { Gossip, Presence } from "@dxos/teleport-extension-gossip";
2972
3180
  import { ComplexMap as ComplexMap3, deferFunction as deferFunction2 } from "@dxos/util";
@@ -2974,7 +3182,7 @@ import { ComplexMap as ComplexMap3, deferFunction as deferFunction2 } from "@dxo
2974
3182
  // packages/sdk/client-services/src/packlets/spaces/genesis.ts
2975
3183
  import { createCredential } from "@dxos/credentials";
2976
3184
  import { failUndefined as failUndefined2 } from "@dxos/debug";
2977
- import { AdmittedFeed as AdmittedFeed4, SpaceMember } from "@dxos/protocols/proto/dxos/halo/credentials";
3185
+ import { AdmittedFeed as AdmittedFeed4, SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/halo/credentials";
2978
3186
  import { Timeframe as Timeframe2 } from "@dxos/timeframe";
2979
3187
  var spaceGenesis = async (keyring, signingContext, space) => {
2980
3188
  var _a, _b, _c, _d;
@@ -2995,7 +3203,7 @@ var spaceGenesis = async (keyring, signingContext, space) => {
2995
3203
  assertion: {
2996
3204
  "@type": "dxos.halo.credentials.SpaceMember",
2997
3205
  spaceKey: space.key,
2998
- role: SpaceMember.Role.ADMIN,
3206
+ role: SpaceMember2.Role.ADMIN,
2999
3207
  profile: signingContext.profile,
3000
3208
  genesisFeedKey: (_a = space.controlFeedKey) != null ? _a : failUndefined2()
3001
3209
  }
@@ -3042,7 +3250,7 @@ var spaceGenesis = async (keyring, signingContext, space) => {
3042
3250
  };
3043
3251
 
3044
3252
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
3045
- function _ts_decorate2(decorators, target, key, desc) {
3253
+ function _ts_decorate4(decorators, target, key, desc) {
3046
3254
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3047
3255
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3048
3256
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3052,7 +3260,7 @@ function _ts_decorate2(decorators, target, key, desc) {
3052
3260
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3053
3261
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3054
3262
  }
3055
- var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
3263
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
3056
3264
  var DataSpaceManager = class DataSpaceManager2 {
3057
3265
  constructor(_spaceManager, _metadataStore, _dataServiceSubscriptions, _keyring, _signingContext, _feedStore) {
3058
3266
  this._spaceManager = _spaceManager;
@@ -3061,7 +3269,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3061
3269
  this._keyring = _keyring;
3062
3270
  this._signingContext = _signingContext;
3063
3271
  this._feedStore = _feedStore;
3064
- this._ctx = new Context7();
3272
+ this._ctx = new Context8();
3065
3273
  this.updated = new Event6();
3066
3274
  this._spaces = new ComplexMap3(PublicKey8.hash);
3067
3275
  this._isOpen = false;
@@ -3072,35 +3280,35 @@ var DataSpaceManager = class DataSpaceManager2 {
3072
3280
  return this._spaces;
3073
3281
  }
3074
3282
  async open() {
3075
- log10("open", void 0, {
3076
- F: __dxlog_file12,
3283
+ log11("open", void 0, {
3284
+ F: __dxlog_file13,
3077
3285
  L: 79,
3078
3286
  S: this,
3079
3287
  C: (f, a) => f(...a)
3080
3288
  });
3081
- log10.trace("dxos.echo.data-space-manager.open", trace4.begin({
3289
+ log11.trace("dxos.echo.data-space-manager.open", trace5.begin({
3082
3290
  id: this._instanceId
3083
3291
  }), {
3084
- F: __dxlog_file12,
3292
+ F: __dxlog_file13,
3085
3293
  L: 80,
3086
3294
  S: this,
3087
3295
  C: (f, a) => f(...a)
3088
3296
  });
3089
3297
  await this._metadataStore.load();
3090
- log10("metadata loaded", {
3298
+ log11("metadata loaded", {
3091
3299
  spaces: this._metadataStore.spaces.length
3092
3300
  }, {
3093
- F: __dxlog_file12,
3301
+ F: __dxlog_file13,
3094
3302
  L: 82,
3095
3303
  S: this,
3096
3304
  C: (f, a) => f(...a)
3097
3305
  });
3098
3306
  for (const spaceMetadata of this._metadataStore.spaces) {
3099
3307
  try {
3100
- log10("load space", {
3308
+ log11("load space", {
3101
3309
  spaceMetadata
3102
3310
  }, {
3103
- F: __dxlog_file12,
3311
+ F: __dxlog_file13,
3104
3312
  L: 86,
3105
3313
  S: this,
3106
3314
  C: (f, a) => f(...a)
@@ -3110,11 +3318,11 @@ var DataSpaceManager = class DataSpaceManager2 {
3110
3318
  space.initializeDataPipelineAsync();
3111
3319
  }
3112
3320
  } catch (err) {
3113
- log10.error("Error loading space", {
3321
+ log11.error("Error loading space", {
3114
3322
  spaceMetadata,
3115
3323
  err
3116
3324
  }, {
3117
- F: __dxlog_file12,
3325
+ F: __dxlog_file13,
3118
3326
  L: 92,
3119
3327
  S: this,
3120
3328
  C: (f, a) => f(...a)
@@ -3123,18 +3331,18 @@ var DataSpaceManager = class DataSpaceManager2 {
3123
3331
  }
3124
3332
  this._isOpen = true;
3125
3333
  this.updated.emit();
3126
- log10.trace("dxos.echo.data-space-manager.open", trace4.end({
3334
+ log11.trace("dxos.echo.data-space-manager.open", trace5.end({
3127
3335
  id: this._instanceId
3128
3336
  }), {
3129
- F: __dxlog_file12,
3337
+ F: __dxlog_file13,
3130
3338
  L: 98,
3131
3339
  S: this,
3132
3340
  C: (f, a) => f(...a)
3133
3341
  });
3134
3342
  }
3135
3343
  async close() {
3136
- log10("close", void 0, {
3137
- F: __dxlog_file12,
3344
+ log11("close", void 0, {
3345
+ F: __dxlog_file13,
3138
3346
  L: 103,
3139
3347
  S: this,
3140
3348
  C: (f, a) => f(...a)
@@ -3149,8 +3357,8 @@ var DataSpaceManager = class DataSpaceManager2 {
3149
3357
  * Creates a new space writing the genesis credentials to the control feed.
3150
3358
  */
3151
3359
  async createSpace() {
3152
- invariant10(this._isOpen, "Not open.", {
3153
- F: __dxlog_file12,
3360
+ invariant11(this._isOpen, "Not open.", {
3361
+ F: __dxlog_file13,
3154
3362
  L: 116,
3155
3363
  S: this,
3156
3364
  A: [
@@ -3168,10 +3376,10 @@ var DataSpaceManager = class DataSpaceManager2 {
3168
3376
  dataFeedKey,
3169
3377
  state: SpaceState2.ACTIVE
3170
3378
  };
3171
- log10("creating space...", {
3379
+ log11("creating space...", {
3172
3380
  spaceKey
3173
3381
  }, {
3174
- F: __dxlog_file12,
3382
+ F: __dxlog_file13,
3175
3383
  L: 128,
3176
3384
  S: this,
3177
3385
  C: (f, a) => f(...a)
@@ -3180,8 +3388,8 @@ var DataSpaceManager = class DataSpaceManager2 {
3180
3388
  const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner);
3181
3389
  await this._metadataStore.addSpace(metadata);
3182
3390
  const memberCredential = credentials[1];
3183
- invariant10(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3184
- F: __dxlog_file12,
3391
+ invariant11(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3392
+ F: __dxlog_file13,
3185
3393
  L: 135,
3186
3394
  S: this,
3187
3395
  A: [
@@ -3196,16 +3404,16 @@ var DataSpaceManager = class DataSpaceManager2 {
3196
3404
  }
3197
3405
  // TODO(burdon): Rename join space.
3198
3406
  async acceptSpace(opts) {
3199
- log10("accept space", {
3407
+ log11("accept space", {
3200
3408
  opts
3201
3409
  }, {
3202
- F: __dxlog_file12,
3410
+ F: __dxlog_file13,
3203
3411
  L: 147,
3204
3412
  S: this,
3205
3413
  C: (f, a) => f(...a)
3206
3414
  });
3207
- invariant10(this._isOpen, "Not open.", {
3208
- F: __dxlog_file12,
3415
+ invariant11(this._isOpen, "Not open.", {
3416
+ F: __dxlog_file13,
3209
3417
  L: 148,
3210
3418
  S: this,
3211
3419
  A: [
@@ -3213,8 +3421,8 @@ var DataSpaceManager = class DataSpaceManager2 {
3213
3421
  "'Not open.'"
3214
3422
  ]
3215
3423
  });
3216
- invariant10(!this._spaces.has(opts.spaceKey), "Space already exists.", {
3217
- F: __dxlog_file12,
3424
+ invariant11(!this._spaces.has(opts.spaceKey), "Space already exists.", {
3425
+ F: __dxlog_file13,
3218
3426
  L: 149,
3219
3427
  S: this,
3220
3428
  A: [
@@ -3246,10 +3454,10 @@ var DataSpaceManager = class DataSpaceManager2 {
3246
3454
  }));
3247
3455
  }
3248
3456
  async _constructSpace(metadata) {
3249
- log10("construct space", {
3457
+ log11("construct space", {
3250
3458
  metadata
3251
3459
  }, {
3252
- F: __dxlog_file12,
3460
+ F: __dxlog_file13,
3253
3461
  L: 182,
3254
3462
  S: this,
3255
3463
  C: (f, a) => f(...a)
@@ -3284,8 +3492,8 @@ var DataSpaceManager = class DataSpaceManager2 {
3284
3492
  session.addExtension("dxos.mesh.teleport.notarization", dataSpace.notarizationPlugin.createExtension());
3285
3493
  },
3286
3494
  onAuthFailure: () => {
3287
- log10.warn("auth failure", void 0, {
3288
- F: __dxlog_file12,
3495
+ log11.warn("auth failure", void 0, {
3496
+ F: __dxlog_file13,
3289
3497
  L: 213,
3290
3498
  S: this,
3291
3499
  C: (f, a) => f(...a)
@@ -3306,10 +3514,10 @@ var DataSpaceManager = class DataSpaceManager2 {
3306
3514
  signingContext: this._signingContext,
3307
3515
  callbacks: {
3308
3516
  beforeReady: async () => {
3309
- log10("before space ready", {
3517
+ log11("before space ready", {
3310
3518
  space: space.key
3311
3519
  }, {
3312
- F: __dxlog_file12,
3520
+ F: __dxlog_file13,
3313
3521
  L: 231,
3314
3522
  S: this,
3315
3523
  C: (f, a) => f(...a)
@@ -3317,11 +3525,11 @@ var DataSpaceManager = class DataSpaceManager2 {
3317
3525
  await this._dataServiceSubscriptions.registerSpace(space.key, dataSpace.dataPipeline.databaseHost.createDataServiceHost());
3318
3526
  },
3319
3527
  afterReady: async () => {
3320
- log10("after space ready", {
3528
+ log11("after space ready", {
3321
3529
  space: space.key,
3322
3530
  open: this._isOpen
3323
3531
  }, {
3324
- F: __dxlog_file12,
3532
+ F: __dxlog_file13,
3325
3533
  L: 238,
3326
3534
  S: this,
3327
3535
  C: (f, a) => f(...a)
@@ -3331,10 +3539,10 @@ var DataSpaceManager = class DataSpaceManager2 {
3331
3539
  }
3332
3540
  },
3333
3541
  beforeClose: async () => {
3334
- log10("before space close", {
3542
+ log11("before space close", {
3335
3543
  space: space.key
3336
3544
  }, {
3337
- F: __dxlog_file12,
3545
+ F: __dxlog_file13,
3338
3546
  L: 244,
3339
3547
  S: this,
3340
3548
  C: (f, a) => f(...a)
@@ -3357,19 +3565,19 @@ var DataSpaceManager = class DataSpaceManager2 {
3357
3565
  return dataSpace;
3358
3566
  }
3359
3567
  };
3360
- _ts_decorate2([
3568
+ _ts_decorate4([
3361
3569
  synchronized2
3362
3570
  ], DataSpaceManager.prototype, "open", null);
3363
- _ts_decorate2([
3571
+ _ts_decorate4([
3364
3572
  synchronized2
3365
3573
  ], DataSpaceManager.prototype, "close", null);
3366
- _ts_decorate2([
3574
+ _ts_decorate4([
3367
3575
  synchronized2
3368
3576
  ], DataSpaceManager.prototype, "createSpace", null);
3369
- _ts_decorate2([
3577
+ _ts_decorate4([
3370
3578
  synchronized2
3371
3579
  ], DataSpaceManager.prototype, "acceptSpace", null);
3372
- DataSpaceManager = _ts_decorate2([
3580
+ DataSpaceManager = _ts_decorate4([
3373
3581
  trackLeaks2("open", "close")
3374
3582
  ], DataSpaceManager);
3375
3583
 
@@ -3379,11 +3587,11 @@ import { Stream as Stream10 } from "@dxos/codec-protobuf";
3379
3587
  import { raise as raise2 } from "@dxos/debug";
3380
3588
  import { SpaceNotFoundError } from "@dxos/echo-pipeline";
3381
3589
  import { ApiError } from "@dxos/errors";
3382
- import { log as log11 } from "@dxos/log";
3590
+ import { log as log12 } from "@dxos/log";
3383
3591
  import { encodeError } from "@dxos/protocols";
3384
- import { SpaceMember as SpaceMember2, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
3592
+ import { SpaceMember as SpaceMember3, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
3385
3593
  import { humanize } from "@dxos/util";
3386
- var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
3594
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
3387
3595
  var SpacesServiceImpl = class {
3388
3596
  constructor(_identityManager, _spaceManager, _dataServiceSubscriptions, _getDataSpaceManager) {
3389
3597
  this._identityManager = _identityManager;
@@ -3421,10 +3629,10 @@ var SpacesServiceImpl = class {
3421
3629
  const scheduler = new UpdateScheduler(ctx, async () => {
3422
3630
  const dataSpaceManager = await this._getDataSpaceManager();
3423
3631
  const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
3424
- log11("update", {
3632
+ log12("update", {
3425
3633
  spaces
3426
3634
  }, {
3427
- F: __dxlog_file13,
3635
+ F: __dxlog_file14,
3428
3636
  L: 78,
3429
3637
  S: this,
3430
3638
  C: (f, a) => f(...a)
@@ -3547,7 +3755,7 @@ var SpacesServiceImpl = class {
3547
3755
  displayName: (_c2 = (_b2 = member.assertion.profile) == null ? void 0 : _b2.displayName) != null ? _c2 : humanize(member.key)
3548
3756
  }
3549
3757
  },
3550
- presence: isMe || peers.length > 0 ? SpaceMember2.PresenceState.ONLINE : SpaceMember2.PresenceState.OFFLINE,
3758
+ presence: isMe || peers.length > 0 ? SpaceMember3.PresenceState.ONLINE : SpaceMember3.PresenceState.OFFLINE,
3551
3759
  peerStates: peers
3552
3760
  };
3553
3761
  }),
@@ -3561,19 +3769,31 @@ var getChannelId = (channel) => `user-channel/${channel}`;
3561
3769
 
3562
3770
  // packages/sdk/client-services/src/packlets/services/service-context.ts
3563
3771
  import { Trigger as Trigger5 } from "@dxos/async";
3772
+ import { Context as Context9 } from "@dxos/context";
3564
3773
  import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
3565
3774
  import { failUndefined as failUndefined3 } from "@dxos/debug";
3566
3775
  import { valueEncoding, MetadataStore, SpaceManager, DataServiceSubscriptions, SnapshotStore } from "@dxos/echo-pipeline";
3567
3776
  import { FeedFactory, FeedStore } from "@dxos/feed-store";
3568
- import { invariant as invariant11 } from "@dxos/invariant";
3777
+ import { invariant as invariant12 } from "@dxos/invariant";
3569
3778
  import { Keyring } from "@dxos/keyring";
3570
3779
  import { PublicKey as PublicKey9 } from "@dxos/keys";
3571
- import { log as log12 } from "@dxos/log";
3572
- import { STORAGE_VERSION, trace as trace5 } from "@dxos/protocols";
3780
+ import { log as log13 } from "@dxos/log";
3781
+ import { STORAGE_VERSION as STORAGE_VERSION2, trace as trace6 } from "@dxos/protocols";
3573
3782
  import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
3574
3783
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
3575
- var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
3576
- var ServiceContext = class {
3784
+ import { trace as Trace2 } from "@dxos/tracing";
3785
+ function _ts_decorate5(decorators, target, key, desc) {
3786
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3787
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3788
+ r = Reflect.decorate(decorators, target, key, desc);
3789
+ else
3790
+ for (var i = decorators.length - 1; i >= 0; i--)
3791
+ if (d = decorators[i])
3792
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3793
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
3794
+ }
3795
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
3796
+ var ServiceContext = class ServiceContext2 {
3577
3797
  // prettier-ignore
3578
3798
  constructor(storage, networkManager, signalManager, modelFactory) {
3579
3799
  this.storage = storage;
@@ -3612,49 +3832,49 @@ var ServiceContext = class {
3612
3832
  return (_a = this.identityManager.identity) != null ? _a : failUndefined3();
3613
3833
  }, this._acceptIdentity.bind(this)));
3614
3834
  }
3615
- async open() {
3616
- log12.trace("dxos.sdk.service-context.open", trace5.begin({
3617
- id: this._instanceId
3618
- }), {
3619
- F: __dxlog_file14,
3620
- L: 125,
3835
+ async open(ctx) {
3836
+ await this._checkStorageVersion();
3837
+ log13("opening...", void 0, {
3838
+ F: __dxlog_file15,
3839
+ L: 131,
3621
3840
  S: this,
3622
3841
  C: (f, a) => f(...a)
3623
3842
  });
3624
- await this._checkStorageVersion();
3625
- log12("opening...", void 0, {
3626
- F: __dxlog_file14,
3627
- L: 129,
3843
+ log13.trace("dxos.sdk.service-context.open", trace6.begin({
3844
+ id: this._instanceId
3845
+ }), {
3846
+ F: __dxlog_file15,
3847
+ L: 132,
3628
3848
  S: this,
3629
3849
  C: (f, a) => f(...a)
3630
3850
  });
3631
3851
  await this.signalManager.open();
3632
3852
  await this.networkManager.open();
3633
3853
  await this.spaceManager.open();
3634
- await this.identityManager.open();
3854
+ await this.identityManager.open(ctx);
3635
3855
  if (this.identityManager.identity) {
3636
- await this._initialize();
3856
+ await this._initialize(ctx);
3637
3857
  }
3638
- log12("opened", void 0, {
3639
- F: __dxlog_file14,
3640
- L: 137,
3858
+ log13.trace("dxos.sdk.service-context.open", trace6.end({
3859
+ id: this._instanceId
3860
+ }), {
3861
+ F: __dxlog_file15,
3862
+ L: 140,
3641
3863
  S: this,
3642
3864
  C: (f, a) => f(...a)
3643
3865
  });
3644
- log12.trace("dxos.sdk.service-context.open", trace5.end({
3645
- id: this._instanceId
3646
- }), {
3647
- F: __dxlog_file14,
3648
- L: 138,
3866
+ log13("opened", void 0, {
3867
+ F: __dxlog_file15,
3868
+ L: 141,
3649
3869
  S: this,
3650
3870
  C: (f, a) => f(...a)
3651
3871
  });
3652
3872
  }
3653
3873
  async close() {
3654
3874
  var _a;
3655
- log12("closing...", void 0, {
3656
- F: __dxlog_file14,
3657
- L: 142,
3875
+ log13("closing...", void 0, {
3876
+ F: __dxlog_file15,
3877
+ L: 145,
3658
3878
  S: this,
3659
3879
  C: (f, a) => f(...a)
3660
3880
  });
@@ -3668,23 +3888,23 @@ var ServiceContext = class {
3668
3888
  await this.networkManager.close();
3669
3889
  await this.signalManager.close();
3670
3890
  this.dataServiceSubscriptions.clear();
3671
- log12("closed", void 0, {
3672
- F: __dxlog_file14,
3673
- L: 153,
3891
+ log13("closed", void 0, {
3892
+ F: __dxlog_file15,
3893
+ L: 156,
3674
3894
  S: this,
3675
3895
  C: (f, a) => f(...a)
3676
3896
  });
3677
3897
  }
3678
3898
  async createIdentity(params = {}) {
3679
3899
  const identity = await this.identityManager.createIdentity(params);
3680
- await this._initialize();
3900
+ await this._initialize(new Context9());
3681
3901
  return identity;
3682
3902
  }
3683
3903
  getInvitationHandler(invitation) {
3684
3904
  const factory = this._handlerFactories.get(invitation.kind);
3685
- invariant11(factory, `Unknown invitation kind: ${invitation.kind}`, {
3686
- F: __dxlog_file14,
3687
- L: 165,
3905
+ invariant12(factory, `Unknown invitation kind: ${invitation.kind}`, {
3906
+ F: __dxlog_file15,
3907
+ L: 168,
3688
3908
  S: this,
3689
3909
  A: [
3690
3910
  "factory",
@@ -3695,21 +3915,21 @@ var ServiceContext = class {
3695
3915
  }
3696
3916
  async _acceptIdentity(params) {
3697
3917
  const identity = await this.identityManager.acceptIdentity(params);
3698
- await this._initialize();
3918
+ await this._initialize(new Context9());
3699
3919
  return identity;
3700
3920
  }
3701
3921
  async _checkStorageVersion() {
3702
3922
  await this.metadataStore.load();
3703
- if (this.metadataStore.version !== STORAGE_VERSION) {
3704
- throw new Error(`Invalid storage version: current=${this.metadataStore.version}, expected=${STORAGE_VERSION}`);
3923
+ if (this.metadataStore.version !== STORAGE_VERSION2) {
3924
+ throw new Error(`Invalid storage version: current=${this.metadataStore.version}, expected=${STORAGE_VERSION2}`);
3705
3925
  }
3706
3926
  }
3707
3927
  // Called when identity is created.
3708
- async _initialize() {
3928
+ async _initialize(ctx) {
3709
3929
  var _a;
3710
- log12("initializing spaces...", void 0, {
3711
- F: __dxlog_file14,
3712
- L: 186,
3930
+ log13("initializing spaces...", void 0, {
3931
+ F: __dxlog_file15,
3932
+ L: 190,
3713
3933
  S: this,
3714
3934
  C: (f, a) => f(...a)
3715
3935
  });
@@ -3730,9 +3950,9 @@ var ServiceContext = class {
3730
3950
  this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.dataServiceSubscriptions, this.keyring, signingContext, this.feedStore);
3731
3951
  await this.dataSpaceManager.open();
3732
3952
  this._handlerFactories.set(Invitation5.Kind.SPACE, (invitation) => {
3733
- invariant11(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
3734
- F: __dxlog_file14,
3735
- L: 209,
3953
+ invariant12(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
3954
+ F: __dxlog_file15,
3955
+ L: 213,
3736
3956
  S: this,
3737
3957
  A: [
3738
3958
  "this.dataSpaceManager",
@@ -3752,33 +3972,33 @@ var ServiceContext = class {
3752
3972
  return;
3753
3973
  }
3754
3974
  if (!this.dataSpaceManager) {
3755
- log12("dataSpaceManager not initialized yet, ignoring space admission", {
3975
+ log13("dataSpaceManager not initialized yet, ignoring space admission", {
3756
3976
  details: assertion
3757
3977
  }, {
3758
- F: __dxlog_file14,
3759
- L: 225,
3978
+ F: __dxlog_file15,
3979
+ L: 229,
3760
3980
  S: this,
3761
3981
  C: (f, a) => f(...a)
3762
3982
  });
3763
3983
  return;
3764
3984
  }
3765
3985
  if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
3766
- log12("space already exists, ignoring space admission", {
3986
+ log13("space already exists, ignoring space admission", {
3767
3987
  details: assertion
3768
3988
  }, {
3769
- F: __dxlog_file14,
3770
- L: 229,
3989
+ F: __dxlog_file15,
3990
+ L: 233,
3771
3991
  S: this,
3772
3992
  C: (f, a) => f(...a)
3773
3993
  });
3774
3994
  return;
3775
3995
  }
3776
3996
  try {
3777
- log12("accepting space recorded in halo", {
3997
+ log13("accepting space recorded in halo", {
3778
3998
  details: assertion
3779
3999
  }, {
3780
- F: __dxlog_file14,
3781
- L: 234,
4000
+ F: __dxlog_file15,
4001
+ L: 238,
3782
4002
  S: this,
3783
4003
  C: (f, a) => f(...a)
3784
4004
  });
@@ -3787,9 +4007,9 @@ var ServiceContext = class {
3787
4007
  genesisFeedKey: assertion.genesisFeedKey
3788
4008
  });
3789
4009
  } catch (err) {
3790
- log12.catch(err, void 0, {
3791
- F: __dxlog_file14,
3792
- L: 240,
4010
+ log13.catch(err, void 0, {
4011
+ F: __dxlog_file15,
4012
+ L: 244,
3793
4013
  S: this,
3794
4014
  C: (f, a) => f(...a)
3795
4015
  });
@@ -3799,12 +4019,21 @@ var ServiceContext = class {
3799
4019
  await identity.space.spaceState.addCredentialProcessor(this._deviceSpaceSync);
3800
4020
  }
3801
4021
  };
4022
+ _ts_decorate5([
4023
+ Trace2.span()
4024
+ ], ServiceContext.prototype, "open", null);
4025
+ _ts_decorate5([
4026
+ Trace2.span()
4027
+ ], ServiceContext.prototype, "_initialize", null);
4028
+ ServiceContext = _ts_decorate5([
4029
+ Trace2.resource()
4030
+ ], ServiceContext);
3802
4031
 
3803
4032
  // packages/sdk/client-services/src/packlets/locks/browser.ts
3804
4033
  import { asyncTimeout, Trigger as Trigger6 } from "@dxos/async";
3805
4034
  import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
3806
- import { log as log13, logInfo } from "@dxos/log";
3807
- function _ts_decorate3(decorators, target, key, desc) {
4035
+ import { log as log14, logInfo } from "@dxos/log";
4036
+ function _ts_decorate6(decorators, target, key, desc) {
3808
4037
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3809
4038
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3810
4039
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3814,7 +4043,7 @@ function _ts_decorate3(decorators, target, key, desc) {
3814
4043
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3815
4044
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3816
4045
  }
3817
- var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
4046
+ var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
3818
4047
  var Message;
3819
4048
  (function(Message2) {
3820
4049
  Message2["ACQUIRING"] = "acquiring";
@@ -3836,29 +4065,29 @@ var Lock = class {
3836
4065
  message: Message.ACQUIRING
3837
4066
  });
3838
4067
  try {
3839
- log13("aquiring lock...", void 0, {
3840
- F: __dxlog_file15,
4068
+ log14("aquiring lock...", void 0, {
4069
+ F: __dxlog_file16,
3841
4070
  L: 42,
3842
4071
  S: this,
3843
4072
  C: (f, a) => f(...a)
3844
4073
  });
3845
4074
  await asyncTimeout(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
3846
- log13("acquired lock", void 0, {
3847
- F: __dxlog_file15,
4075
+ log14("acquired lock", void 0, {
4076
+ F: __dxlog_file16,
3848
4077
  L: 44,
3849
4078
  S: this,
3850
4079
  C: (f, a) => f(...a)
3851
4080
  });
3852
4081
  } catch (e) {
3853
- log13("stealing lock...", void 0, {
3854
- F: __dxlog_file15,
4082
+ log14("stealing lock...", void 0, {
4083
+ F: __dxlog_file16,
3855
4084
  L: 46,
3856
4085
  S: this,
3857
4086
  C: (f, a) => f(...a)
3858
4087
  });
3859
4088
  await this._requestLock(true);
3860
- log13("stolen lock", void 0, {
3861
- F: __dxlog_file15,
4089
+ log14("stolen lock", void 0, {
4090
+ F: __dxlog_file16,
3862
4091
  L: 48,
3863
4092
  S: this,
3864
4093
  C: (f, a) => f(...a)
@@ -3874,10 +4103,10 @@ var Lock = class {
3874
4103
  }
3875
4104
  }
3876
4105
  async _requestLock(steal = false) {
3877
- log13("requesting lock...", {
4106
+ log14("requesting lock...", {
3878
4107
  steal
3879
4108
  }, {
3880
- F: __dxlog_file15,
4109
+ F: __dxlog_file16,
3881
4110
  L: 63,
3882
4111
  S: this,
3883
4112
  C: (f, a) => f(...a)
@@ -3891,15 +4120,15 @@ var Lock = class {
3891
4120
  acquired.wake();
3892
4121
  this._releaseTrigger = new Trigger6();
3893
4122
  await this._releaseTrigger.wait();
3894
- log13("releasing lock...", void 0, {
3895
- F: __dxlog_file15,
4123
+ log14("releasing lock...", void 0, {
4124
+ F: __dxlog_file16,
3896
4125
  L: 72,
3897
4126
  S: this,
3898
4127
  C: (f, a) => f(...a)
3899
4128
  });
3900
4129
  await ((_b = this._onRelease) == null ? void 0 : _b.call(this));
3901
- log13("released lock", void 0, {
3902
- F: __dxlog_file15,
4130
+ log14("released lock", void 0, {
4131
+ F: __dxlog_file16,
3903
4132
  L: 74,
3904
4133
  S: this,
3905
4134
  C: (f, a) => f(...a)
@@ -3909,17 +4138,17 @@ var Lock = class {
3909
4138
  await ((_a = this._onRelease) == null ? void 0 : _a.call(this));
3910
4139
  });
3911
4140
  await acquired.wait();
3912
- log13("recieved lock", {
4141
+ log14("recieved lock", {
3913
4142
  steal
3914
4143
  }, {
3915
- F: __dxlog_file15,
4144
+ F: __dxlog_file16,
3916
4145
  L: 81,
3917
4146
  S: this,
3918
4147
  C: (f, a) => f(...a)
3919
4148
  });
3920
4149
  }
3921
4150
  };
3922
- _ts_decorate3([
4151
+ _ts_decorate6([
3923
4152
  logInfo
3924
4153
  ], Lock.prototype, "lockKey", null);
3925
4154
  var isLocked = (lockPath) => {
@@ -4002,17 +4231,19 @@ var ServiceRegistry = class {
4002
4231
  // packages/sdk/client-services/src/packlets/services/service-host.ts
4003
4232
  import { Event as Event8, synchronized as synchronized3 } from "@dxos/async";
4004
4233
  import { clientServiceBundle } from "@dxos/client-protocol";
4005
- import { DocumentModel } from "@dxos/document-model";
4234
+ import { Context as Context10 } from "@dxos/context";
4235
+ import { DocumentModel as DocumentModel2 } from "@dxos/document-model";
4006
4236
  import { DataServiceImpl } from "@dxos/echo-pipeline";
4007
- import { invariant as invariant12 } from "@dxos/invariant";
4237
+ import { invariant as invariant13 } from "@dxos/invariant";
4008
4238
  import { PublicKey as PublicKey10 } from "@dxos/keys";
4009
- import { log as log15 } from "@dxos/log";
4239
+ import { log as log16 } from "@dxos/log";
4010
4240
  import { WebsocketSignalManager } from "@dxos/messaging";
4011
4241
  import { ModelFactory } from "@dxos/model-factory";
4012
4242
  import { createWebRTCTransportFactory, NetworkManager } from "@dxos/network-manager";
4013
- import { trace as trace6 } from "@dxos/protocols";
4243
+ import { trace as trace7 } from "@dxos/protocols";
4014
4244
  import { SystemStatus } from "@dxos/protocols/proto/dxos/client/services";
4015
4245
  import { TextModel } from "@dxos/text-model";
4246
+ import { TRACE_PROCESSOR, trace as Trace3 } from "@dxos/tracing";
4016
4247
 
4017
4248
  // packages/sdk/client-services/src/packlets/devices/devices-service.ts
4018
4249
  import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
@@ -4064,22 +4295,23 @@ var DevicesServiceImpl = class {
4064
4295
  // packages/sdk/client-services/src/packlets/logging/logging-service.ts
4065
4296
  import { Event as Event7 } from "@dxos/async";
4066
4297
  import { Stream as Stream12 } from "@dxos/codec-protobuf";
4067
- import { getContextFromEntry, log as log14 } from "@dxos/log";
4298
+ import { getContextFromEntry, log as log15 } from "@dxos/log";
4068
4299
  import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
4069
4300
  import { jsonify, numericalValues, tracer } from "@dxos/util";
4070
4301
  var LoggingServiceImpl = class {
4071
4302
  constructor() {
4072
4303
  this._logs = new Event7();
4304
+ this._started = new Date();
4073
4305
  this._logProcessor = (_config, entry2) => {
4074
4306
  this._logs.emit(entry2);
4075
4307
  };
4076
4308
  }
4077
4309
  async open() {
4078
- log14.runtimeConfig.processors.push(this._logProcessor);
4310
+ log15.runtimeConfig.processors.push(this._logProcessor);
4079
4311
  }
4080
4312
  async close() {
4081
- const index = log14.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
4082
- log14.runtimeConfig.processors.splice(index, 1);
4313
+ const index = log15.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
4314
+ log15.runtimeConfig.processors.splice(index, 1);
4083
4315
  }
4084
4316
  async controlMetrics({ reset, record }) {
4085
4317
  if (reset) {
@@ -4094,13 +4326,16 @@ var LoggingServiceImpl = class {
4094
4326
  recording: tracer.recording
4095
4327
  };
4096
4328
  }
4097
- queryMetrics({ interval }) {
4098
- const createNumericalValues = (key) => {
4329
+ /**
4330
+ * @deprecated (Move to diagnostics).
4331
+ */
4332
+ queryMetrics({ interval = 5e3 }) {
4333
+ const getNumericalValues = (key) => {
4099
4334
  var _a;
4100
- const consume = (_a = tracer.get(key)) != null ? _a : [];
4335
+ const events = (_a = tracer.get(key)) != null ? _a : [];
4101
4336
  return {
4102
4337
  key,
4103
- stats: numericalValues(consume, "duration")
4338
+ stats: numericalValues(events, "duration")
4104
4339
  };
4105
4340
  };
4106
4341
  return new Stream12(({ next }) => {
@@ -4108,14 +4343,17 @@ var LoggingServiceImpl = class {
4108
4343
  const metrics = {
4109
4344
  timestamp: new Date(),
4110
4345
  values: [
4111
- createNumericalValues("dxos.echo.pipeline.control"),
4112
- createNumericalValues("dxos.echo.pipeline.data")
4113
- ]
4346
+ getNumericalValues("dxos.echo.pipeline.control"),
4347
+ getNumericalValues("dxos.echo.pipeline.data")
4348
+ ].filter(Boolean)
4114
4349
  };
4115
- next(metrics);
4350
+ next({
4351
+ timestamp: new Date(),
4352
+ metrics
4353
+ });
4116
4354
  };
4117
4355
  update();
4118
- const i = setInterval(update, interval);
4356
+ const i = setInterval(update, Math.max(interval, 1e3));
4119
4357
  return () => {
4120
4358
  clearInterval(i);
4121
4359
  };
@@ -4211,11 +4449,14 @@ var NetworkServiceImpl = class {
4211
4449
 
4212
4450
  // packages/sdk/client-services/src/packlets/system/system-service.ts
4213
4451
  import { Stream as Stream14 } from "@dxos/codec-protobuf";
4452
+ import { GetDiagnosticsRequest } from "@dxos/protocols/proto/dxos/client/services";
4453
+ import { jsonKeyReplacer } from "@dxos/util";
4214
4454
  var SystemServiceImpl = class {
4215
- constructor({ config, statusUpdate, onUpdateStatus, getCurrentStatus, onReset }) {
4455
+ constructor({ config, statusUpdate, getDiagnostics, onUpdateStatus, getCurrentStatus, onReset }) {
4216
4456
  this._config = config;
4217
4457
  this._statusUpdate = statusUpdate;
4218
4458
  this._getCurrentStatus = getCurrentStatus;
4459
+ this._getDiagnostics = getDiagnostics;
4219
4460
  this._onUpdateStatus = onUpdateStatus;
4220
4461
  this._onReset = onReset;
4221
4462
  }
@@ -4223,6 +4464,19 @@ var SystemServiceImpl = class {
4223
4464
  var _a, _b;
4224
4465
  return (_b = (_a = this._config) == null ? void 0 : _a.values) != null ? _b : {};
4225
4466
  }
4467
+ /**
4468
+ * NOTE: Since this is serialized as a JSON object, we allow the option to serialize keys.
4469
+ */
4470
+ async getDiagnostics({ keys } = {}) {
4471
+ const diagnostics = await this._getDiagnostics();
4472
+ return {
4473
+ timestamp: new Date(),
4474
+ diagnostics: JSON.parse(JSON.stringify(diagnostics, jsonKeyReplacer({
4475
+ truncate: keys === GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
4476
+ humanize: keys === GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
4477
+ })))
4478
+ };
4479
+ }
4226
4480
  async updateStatus({ status }) {
4227
4481
  await this._onUpdateStatus(status);
4228
4482
  }
@@ -4249,7 +4503,7 @@ var SystemServiceImpl = class {
4249
4503
  };
4250
4504
 
4251
4505
  // packages/sdk/client-services/src/packlets/services/service-host.ts
4252
- function _ts_decorate4(decorators, target, key, desc) {
4506
+ function _ts_decorate7(decorators, target, key, desc) {
4253
4507
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4254
4508
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
4255
4509
  r = Reflect.decorate(decorators, target, key, desc);
@@ -4259,23 +4513,22 @@ function _ts_decorate4(decorators, target, key, desc) {
4259
4513
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4260
4514
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4261
4515
  }
4262
- var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
4516
+ var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
4263
4517
  var createDefaultModelFactory = () => {
4264
- return new ModelFactory().registerModel(DocumentModel).registerModel(TextModel);
4518
+ return new ModelFactory().registerModel(DocumentModel2).registerModel(TextModel);
4265
4519
  };
4266
- var ClientServicesHost = class {
4520
+ var ClientServicesHost = class ClientServicesHost2 {
4267
4521
  constructor({
4268
4522
  config,
4269
4523
  modelFactory = createDefaultModelFactory(),
4270
- // TODO(burdon): Create ApolloLink abstraction (see Client).
4271
4524
  transportFactory,
4272
4525
  signalManager,
4273
- connectionLog,
4274
4526
  storage,
4275
4527
  // TODO(wittjosiah): Turn this on by default.
4276
4528
  lockKey,
4277
4529
  callbacks
4278
4530
  } = {}) {
4531
+ this._tracingService = TRACE_PROCESSOR.createTraceSender();
4279
4532
  this._statusUpdate = new Event8();
4280
4533
  this._opening = false;
4281
4534
  this._open = false;
@@ -4294,7 +4547,7 @@ var ClientServicesHost = class {
4294
4547
  lockKey,
4295
4548
  onAcquire: () => {
4296
4549
  if (!this._opening) {
4297
- void this.open();
4550
+ void this.open(new Context10());
4298
4551
  }
4299
4552
  },
4300
4553
  onRelease: () => this.close()
@@ -4304,6 +4557,9 @@ var ClientServicesHost = class {
4304
4557
  config: this._config,
4305
4558
  statusUpdate: this._statusUpdate,
4306
4559
  getCurrentStatus: () => this.isOpen ? SystemStatus.ACTIVE : SystemStatus.INACTIVE,
4560
+ getDiagnostics: () => {
4561
+ return createDiagnostics(this._serviceRegistry.services, this._serviceContext, this._config);
4562
+ },
4307
4563
  onUpdateStatus: async (status) => {
4308
4564
  var _a, _b;
4309
4565
  if (!this.isOpen && status === SystemStatus.ACTIVE) {
@@ -4318,12 +4574,19 @@ var ClientServicesHost = class {
4318
4574
  });
4319
4575
  this._loggingService = new LoggingServiceImpl();
4320
4576
  this._serviceRegistry = new ServiceRegistry(clientServiceBundle, {
4321
- SystemService: this._systemService
4577
+ SystemService: this._systemService,
4578
+ TracingService: this._tracingService
4322
4579
  });
4323
4580
  }
4324
4581
  get isOpen() {
4325
4582
  return this._open;
4326
4583
  }
4584
+ get config() {
4585
+ return this._config;
4586
+ }
4587
+ get context() {
4588
+ return this._serviceContext;
4589
+ }
4327
4590
  get serviceRegistry() {
4328
4591
  return this._serviceRegistry;
4329
4592
  }
@@ -4340,19 +4603,25 @@ var ClientServicesHost = class {
4340
4603
  */
4341
4604
  initialize({ config, ...options }) {
4342
4605
  var _a, _b, _c;
4343
- invariant12(!this._open, "service host is open", {
4344
- F: __dxlog_file16,
4345
- L: 167,
4606
+ invariant13(!this._open, "service host is open", {
4607
+ F: __dxlog_file17,
4608
+ L: 181,
4346
4609
  S: this,
4347
4610
  A: [
4348
4611
  "!this._open",
4349
4612
  "'service host is open'"
4350
4613
  ]
4351
4614
  });
4615
+ log16.info("initializing...", void 0, {
4616
+ F: __dxlog_file17,
4617
+ L: 182,
4618
+ S: this,
4619
+ C: (f, a) => f(...a)
4620
+ });
4352
4621
  if (config) {
4353
- invariant12(!this._config, "config already set", {
4354
- F: __dxlog_file16,
4355
- L: 170,
4622
+ invariant13(!this._config, "config already set", {
4623
+ F: __dxlog_file17,
4624
+ L: 185,
4356
4625
  S: this,
4357
4626
  A: [
4358
4627
  "!this._config",
@@ -4368,9 +4637,9 @@ var ClientServicesHost = class {
4368
4637
  iceServers: (_a = this._config) == null ? void 0 : _a.get("runtime.services.ice")
4369
4638
  }), signalManager = new WebsocketSignalManager((_c = (_b = this._config) == null ? void 0 : _b.get("runtime.services.signaling")) != null ? _c : []) } = options;
4370
4639
  this._signalManager = signalManager;
4371
- invariant12(!this._networkManager, "network manager already set", {
4372
- F: __dxlog_file16,
4373
- L: 187,
4640
+ invariant13(!this._networkManager, "network manager already set", {
4641
+ F: __dxlog_file17,
4642
+ L: 201,
4374
4643
  S: this,
4375
4644
  A: [
4376
4645
  "!this._networkManager",
@@ -4382,51 +4651,57 @@ var ClientServicesHost = class {
4382
4651
  transportFactory,
4383
4652
  signalManager
4384
4653
  });
4654
+ log16.info("initialized", void 0, {
4655
+ F: __dxlog_file17,
4656
+ L: 208,
4657
+ S: this,
4658
+ C: (f, a) => f(...a)
4659
+ });
4385
4660
  }
4386
- async open() {
4661
+ async open(ctx) {
4387
4662
  var _a, _b, _c;
4388
4663
  if (this._open) {
4389
4664
  return;
4390
4665
  }
4391
4666
  const traceId = PublicKey10.random().toHex();
4392
- log15.trace("dxos.sdk.client-services-host.open", trace6.begin({
4667
+ log16.trace("dxos.client-services.host.open", trace7.begin({
4393
4668
  id: traceId
4394
4669
  }), {
4395
- F: __dxlog_file16,
4396
- L: 202,
4670
+ F: __dxlog_file17,
4671
+ L: 219,
4397
4672
  S: this,
4398
4673
  C: (f, a) => f(...a)
4399
4674
  });
4400
- invariant12(this._config, "config not set", {
4401
- F: __dxlog_file16,
4402
- L: 204,
4675
+ invariant13(this._config, "config not set", {
4676
+ F: __dxlog_file17,
4677
+ L: 221,
4403
4678
  S: this,
4404
4679
  A: [
4405
4680
  "this._config",
4406
4681
  "'config not set'"
4407
4682
  ]
4408
4683
  });
4409
- invariant12(this._storage, "storage not set", {
4410
- F: __dxlog_file16,
4411
- L: 205,
4684
+ invariant13(this._storage, "storage not set", {
4685
+ F: __dxlog_file17,
4686
+ L: 222,
4412
4687
  S: this,
4413
4688
  A: [
4414
4689
  "this._storage",
4415
4690
  "'storage not set'"
4416
4691
  ]
4417
4692
  });
4418
- invariant12(this._signalManager, "signal manager not set", {
4419
- F: __dxlog_file16,
4420
- L: 206,
4693
+ invariant13(this._signalManager, "signal manager not set", {
4694
+ F: __dxlog_file17,
4695
+ L: 223,
4421
4696
  S: this,
4422
4697
  A: [
4423
4698
  "this._signalManager",
4424
4699
  "'signal manager not set'"
4425
4700
  ]
4426
4701
  });
4427
- invariant12(this._networkManager, "network manager not set", {
4428
- F: __dxlog_file16,
4429
- L: 207,
4702
+ invariant13(this._networkManager, "network manager not set", {
4703
+ F: __dxlog_file17,
4704
+ L: 224,
4430
4705
  S: this,
4431
4706
  A: [
4432
4707
  "this._networkManager",
@@ -4434,11 +4709,11 @@ var ClientServicesHost = class {
4434
4709
  ]
4435
4710
  });
4436
4711
  this._opening = true;
4437
- log15("opening...", {
4712
+ log16.info("opening...", {
4438
4713
  lockKey: (_a = this._resourceLock) == null ? void 0 : _a.lockKey
4439
4714
  }, {
4440
- F: __dxlog_file16,
4441
- L: 210,
4715
+ F: __dxlog_file17,
4716
+ L: 227,
4442
4717
  S: this,
4443
4718
  C: (f, a) => f(...a)
4444
4719
  });
@@ -4457,6 +4732,7 @@ var ClientServicesHost = class {
4457
4732
  DataService: new DataServiceImpl(this._serviceContext.dataServiceSubscriptions),
4458
4733
  NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager, this._serviceContext.signalManager),
4459
4734
  LoggingService: this._loggingService,
4735
+ TracingService: this._tracingService,
4460
4736
  // TODO(burdon): Move to new protobuf definitions.
4461
4737
  DevtoolsHost: new DevtoolsServiceImpl({
4462
4738
  events: new DevtoolsHostEvents(),
@@ -4464,24 +4740,24 @@ var ClientServicesHost = class {
4464
4740
  context: this._serviceContext
4465
4741
  })
4466
4742
  });
4467
- await this._serviceContext.open();
4743
+ await this._serviceContext.open(ctx);
4468
4744
  this._opening = false;
4469
4745
  this._open = true;
4470
4746
  this._statusUpdate.emit();
4471
4747
  const deviceKey = (_c = this._serviceContext.identityManager.identity) == null ? void 0 : _c.deviceKey;
4472
- log15("opened", {
4748
+ log16.info("opened", {
4473
4749
  deviceKey
4474
4750
  }, {
4475
- F: __dxlog_file16,
4476
- L: 265,
4751
+ F: __dxlog_file17,
4752
+ L: 280,
4477
4753
  S: this,
4478
4754
  C: (f, a) => f(...a)
4479
4755
  });
4480
- log15.trace("dxos.sdk.client-services-host.open", trace6.end({
4756
+ log16.trace("dxos.client-services.host.open", trace7.end({
4481
4757
  id: traceId
4482
4758
  }), {
4483
- F: __dxlog_file16,
4484
- L: 266,
4759
+ F: __dxlog_file17,
4760
+ L: 281,
4485
4761
  S: this,
4486
4762
  C: (f, a) => f(...a)
4487
4763
  });
@@ -4492,11 +4768,11 @@ var ClientServicesHost = class {
4492
4768
  return;
4493
4769
  }
4494
4770
  const deviceKey = (_a = this._serviceContext.identityManager.identity) == null ? void 0 : _a.deviceKey;
4495
- log15("closing...", {
4771
+ log16.info("closing...", {
4496
4772
  deviceKey
4497
4773
  }, {
4498
- F: __dxlog_file16,
4499
- L: 276,
4774
+ F: __dxlog_file17,
4775
+ L: 292,
4500
4776
  S: this,
4501
4777
  C: (f, a) => f(...a)
4502
4778
  });
@@ -4507,11 +4783,11 @@ var ClientServicesHost = class {
4507
4783
  await this._serviceContext.close();
4508
4784
  this._open = false;
4509
4785
  this._statusUpdate.emit();
4510
- log15("closed", {
4786
+ log16.info("closed", {
4511
4787
  deviceKey
4512
4788
  }, {
4513
- F: __dxlog_file16,
4514
- L: 282,
4789
+ F: __dxlog_file17,
4790
+ L: 298,
4515
4791
  S: this,
4516
4792
  C: (f, a) => f(...a)
4517
4793
  });
@@ -4519,45 +4795,56 @@ var ClientServicesHost = class {
4519
4795
  async reset() {
4520
4796
  var _a, _b, _c;
4521
4797
  const traceId = PublicKey10.random().toHex();
4522
- log15.trace("dxos.sdk.client-services-host.reset", trace6.begin({
4798
+ log16.trace("dxos.sdk.client-services-host.reset", trace7.begin({
4523
4799
  id: traceId
4524
4800
  }), {
4525
- F: __dxlog_file16,
4526
- L: 287,
4801
+ F: __dxlog_file17,
4802
+ L: 303,
4527
4803
  S: this,
4528
4804
  C: (f, a) => f(...a)
4529
4805
  });
4530
- log15("resetting...", void 0, {
4531
- F: __dxlog_file16,
4532
- L: 289,
4806
+ log16("resetting...", void 0, {
4807
+ F: __dxlog_file17,
4808
+ L: 305,
4533
4809
  S: this,
4534
4810
  C: (f, a) => f(...a)
4535
4811
  });
4536
4812
  await ((_a = this._serviceContext) == null ? void 0 : _a.close());
4537
4813
  await this._storage.reset();
4538
- log15("reset", void 0, {
4539
- F: __dxlog_file16,
4540
- L: 292,
4814
+ log16("reset", void 0, {
4815
+ F: __dxlog_file17,
4816
+ L: 308,
4541
4817
  S: this,
4542
4818
  C: (f, a) => f(...a)
4543
4819
  });
4544
- log15.trace("dxos.sdk.client-services-host.reset", trace6.end({
4820
+ log16.trace("dxos.sdk.client-services-host.reset", trace7.end({
4545
4821
  id: traceId
4546
4822
  }), {
4547
- F: __dxlog_file16,
4548
- L: 293,
4823
+ F: __dxlog_file17,
4824
+ L: 309,
4549
4825
  S: this,
4550
4826
  C: (f, a) => f(...a)
4551
4827
  });
4552
4828
  await ((_c = (_b = this._callbacks) == null ? void 0 : _b.onReset) == null ? void 0 : _c.call(_b));
4553
4829
  }
4554
4830
  };
4555
- _ts_decorate4([
4556
- synchronized3
4831
+ _ts_decorate7([
4832
+ Trace3.info()
4833
+ ], ClientServicesHost.prototype, "_opening", void 0);
4834
+ _ts_decorate7([
4835
+ Trace3.info()
4836
+ ], ClientServicesHost.prototype, "_open", void 0);
4837
+ _ts_decorate7([
4838
+ synchronized3,
4839
+ Trace3.span()
4557
4840
  ], ClientServicesHost.prototype, "open", null);
4558
- _ts_decorate4([
4559
- synchronized3
4841
+ _ts_decorate7([
4842
+ synchronized3,
4843
+ Trace3.span()
4560
4844
  ], ClientServicesHost.prototype, "close", null);
4845
+ ClientServicesHost = _ts_decorate7([
4846
+ Trace3.resource()
4847
+ ], ClientServicesHost);
4561
4848
 
4562
4849
  export {
4563
4850
  subscribeToFeeds,
@@ -4580,6 +4867,7 @@ export {
4580
4867
  InvitationsServiceImpl,
4581
4868
  SpaceInvitationProtocol,
4582
4869
  ClientRpcServer,
4870
+ createDiagnostics,
4583
4871
  DataSpace,
4584
4872
  DataSpaceManager,
4585
4873
  SpacesServiceImpl,
@@ -4591,4 +4879,4 @@ export {
4591
4879
  createDefaultModelFactory,
4592
4880
  ClientServicesHost
4593
4881
  };
4594
- //# sourceMappingURL=chunk-FD4L7N4K.mjs.map
4882
+ //# sourceMappingURL=chunk-ZOTHWLK5.mjs.map