@dxos/client-services 0.5.9-main.bdf733d → 0.5.9-main.bf3bb8f

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 (66) hide show
  1. package/dist/lib/browser/{chunk-KNGR7BYM.mjs → chunk-IUSAD4RP.mjs} +1678 -935
  2. package/dist/lib/browser/chunk-IUSAD4RP.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +13 -4
  4. package/dist/lib/browser/index.mjs.map +1 -1
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +20 -13
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/{chunk-WWHTBQNR.cjs → chunk-5PALJZPW.cjs} +1936 -1200
  9. package/dist/lib/node/chunk-5PALJZPW.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +53 -44
  11. package/dist/lib/node/index.cjs.map +1 -1
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/packlets/testing/index.cjs +26 -19
  14. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  15. package/dist/types/src/packlets/identity/contacts-service.d.ts +14 -0
  16. package/dist/types/src/packlets/identity/contacts-service.d.ts.map +1 -0
  17. package/dist/types/src/packlets/identity/default-space-state-machine.d.ts +19 -0
  18. package/dist/types/src/packlets/identity/default-space-state-machine.d.ts.map +1 -0
  19. package/dist/types/src/packlets/identity/identity-service.d.ts +14 -7
  20. package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
  21. package/dist/types/src/packlets/identity/identity.d.ts +4 -1
  22. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  23. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  24. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  25. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  26. package/dist/types/src/packlets/services/service-host.d.ts +1 -1
  27. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  28. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts +4 -1
  29. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts.map +1 -1
  30. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +15 -4
  31. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  32. package/dist/types/src/packlets/spaces/data-space.d.ts +10 -9
  33. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  34. package/dist/types/src/packlets/spaces/epoch-migrations.d.ts +23 -0
  35. package/dist/types/src/packlets/spaces/epoch-migrations.d.ts.map +1 -0
  36. package/dist/types/src/packlets/spaces/spaces-service.d.ts +5 -2
  37. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  38. package/dist/types/src/packlets/storage/index.d.ts +1 -0
  39. package/dist/types/src/packlets/storage/index.d.ts.map +1 -1
  40. package/dist/types/src/packlets/storage/profile-archive.d.ts +14 -0
  41. package/dist/types/src/packlets/storage/profile-archive.d.ts.map +1 -0
  42. package/dist/types/src/packlets/testing/test-builder.d.ts +8 -6
  43. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  44. package/dist/types/src/version.d.ts +1 -1
  45. package/package.json +36 -36
  46. package/src/packlets/identity/contacts-service.ts +85 -0
  47. package/src/packlets/identity/default-space-state-machine.ts +44 -0
  48. package/src/packlets/identity/identity-service.test.ts +35 -5
  49. package/src/packlets/identity/identity-service.ts +82 -8
  50. package/src/packlets/identity/identity.ts +25 -2
  51. package/src/packlets/invitations/invitations-handler.ts +13 -5
  52. package/src/packlets/invitations/space-invitation-protocol.ts +11 -32
  53. package/src/packlets/services/service-context.ts +1 -4
  54. package/src/packlets/services/service-host.ts +23 -42
  55. package/src/packlets/spaces/automerge-space-state.ts +11 -2
  56. package/src/packlets/spaces/data-space-manager.test.ts +46 -1
  57. package/src/packlets/spaces/data-space-manager.ts +136 -33
  58. package/src/packlets/spaces/data-space.ts +89 -140
  59. package/src/packlets/spaces/epoch-migrations.ts +154 -0
  60. package/src/packlets/spaces/spaces-service.ts +56 -4
  61. package/src/packlets/storage/index.ts +1 -0
  62. package/src/packlets/storage/profile-archive.ts +111 -0
  63. package/src/packlets/testing/test-builder.ts +12 -10
  64. package/src/version.ts +1 -1
  65. package/dist/lib/browser/chunk-KNGR7BYM.mjs.map +0 -7
  66. package/dist/lib/node/chunk-WWHTBQNR.cjs.map +0 -7
@@ -85,6 +85,7 @@ var subscribeToFeedBlocks = ({ feedStore }, { feedKey, maxBlocks = 10 }) => {
85
85
  import { Stream as Stream2 } from "@dxos/codec-protobuf";
86
86
  import { Context } from "@dxos/context";
87
87
  import { PublicKey as PublicKey2 } from "@dxos/keys";
88
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devtools/network.ts";
88
89
  var subscribeToNetworkStatus = ({ signalManager }) => new Stream2(({ next, close }) => {
89
90
  const update = () => {
90
91
  try {
@@ -100,7 +101,10 @@ var subscribeToNetworkStatus = ({ signalManager }) => new Stream2(({ next, close
100
101
  update();
101
102
  });
102
103
  var subscribeToSignal = ({ signalManager }) => new Stream2(({ next }) => {
103
- const ctx = new Context();
104
+ const ctx = new Context(void 0, {
105
+ F: __dxlog_file,
106
+ L: 36
107
+ });
104
108
  signalManager.onMessage.on(ctx, (message) => {
105
109
  next({
106
110
  message: {
@@ -355,7 +359,7 @@ import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
355
359
  import { TRACE_PROCESSOR } from "@dxos/tracing";
356
360
 
357
361
  // packages/sdk/client-services/src/version.ts
358
- var DXOS_VERSION = "0.5.9-main.bdf733d";
362
+ var DXOS_VERSION = "0.5.9-main.bf3bb8f";
359
363
 
360
364
  // packages/sdk/client-services/src/packlets/services/platform.ts
361
365
  import { Platform } from "@dxos/protocols/proto/dxos/client/services";
@@ -388,7 +392,7 @@ var getPlatform = () => {
388
392
  };
389
393
 
390
394
  // packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts
391
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts";
395
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts";
392
396
  var DEFAULT_TIMEOUT = 1e3;
393
397
  var createDiagnostics = async (clientServices, serviceContext, config) => {
394
398
  const diagnostics = {
@@ -405,7 +409,7 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
405
409
  await Promise.all([
406
410
  (async () => {
407
411
  invariant(clientServices.LoggingService, "SystemService is not available.", {
408
- F: __dxlog_file,
412
+ F: __dxlog_file2,
409
413
  L: 110,
410
414
  S: void 0,
411
415
  A: [
@@ -510,7 +514,7 @@ var getStorageDiagnostics = async () => {
510
514
  // packages/sdk/client-services/src/packlets/diagnostics/browser-diagnostics-broadcast.ts
511
515
  import { Trigger } from "@dxos/async";
512
516
  import { log } from "@dxos/log";
513
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/browser-diagnostics-broadcast.ts";
517
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/browser-diagnostics-broadcast.ts";
514
518
  var CHANNEL_NAME = "dxos.diagnostics.broadcast";
515
519
  var MessageType;
516
520
  (function(MessageType2) {
@@ -579,7 +583,7 @@ var createCollectDiagnosticsBroadcastHandler = (systemService) => {
579
583
  }
580
584
  } catch (error) {
581
585
  log.catch(error, void 0, {
582
- F: __dxlog_file2,
586
+ F: __dxlog_file3,
583
587
  L: 77,
584
588
  S: void 0,
585
589
  C: (f, a) => f(...a)
@@ -687,7 +691,7 @@ import { Context as Context2 } from "@dxos/context";
687
691
  import { verifyCredential } from "@dxos/credentials";
688
692
  import { log as log2 } from "@dxos/log";
689
693
  import { schema } from "@dxos/protocols";
690
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/authenticator.ts";
694
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/authenticator.ts";
691
695
  var Credential = schema.getCodecForType("dxos.halo.credentials.Credential");
692
696
  var createAuthProvider = (signer) => async (nonce) => {
693
697
  const credential = await signer.createCredential({
@@ -702,7 +706,10 @@ var createAuthProvider = (signer) => async (nonce) => {
702
706
  var TrustedKeySetAuthVerifier = class {
703
707
  constructor(_params) {
704
708
  this._params = _params;
705
- this._ctx = new Context2();
709
+ this._ctx = new Context2(void 0, {
710
+ F: __dxlog_file4,
711
+ L: 45
712
+ });
706
713
  }
707
714
  async close() {
708
715
  await this._ctx.dispose();
@@ -713,7 +720,7 @@ var TrustedKeySetAuthVerifier = class {
713
720
  log2("authenticating...", {
714
721
  credential
715
722
  }, {
716
- F: __dxlog_file3,
723
+ F: __dxlog_file4,
717
724
  L: 56,
718
725
  S: this,
719
726
  C: (f, a) => f(...a)
@@ -723,7 +730,7 @@ var TrustedKeySetAuthVerifier = class {
723
730
  log2("Invalid credential", {
724
731
  result
725
732
  }, {
726
- F: __dxlog_file3,
733
+ F: __dxlog_file4,
727
734
  L: 60,
728
735
  S: this,
729
736
  C: (f, a) => f(...a)
@@ -735,7 +742,7 @@ var TrustedKeySetAuthVerifier = class {
735
742
  nonce,
736
743
  credential
737
744
  }, {
738
- F: __dxlog_file3,
745
+ F: __dxlog_file4,
739
746
  L: 65,
740
747
  S: this,
741
748
  C: (f, a) => f(...a)
@@ -746,7 +753,7 @@ var TrustedKeySetAuthVerifier = class {
746
753
  log2("key is not currently in trusted set, waiting...", {
747
754
  key: credential.issuer
748
755
  }, {
749
- F: __dxlog_file3,
756
+ F: __dxlog_file4,
750
757
  L: 70,
751
758
  S: this,
752
759
  C: (f, a) => f(...a)
@@ -762,7 +769,7 @@ var TrustedKeySetAuthVerifier = class {
762
769
  log2("auth success", {
763
770
  key: credential.issuer
764
771
  }, {
765
- F: __dxlog_file3,
772
+ F: __dxlog_file4,
766
773
  L: 81,
767
774
  S: this,
768
775
  C: (f, a) => f(...a)
@@ -772,7 +779,7 @@ var TrustedKeySetAuthVerifier = class {
772
779
  log2("key is not currently in trusted set, waiting...", {
773
780
  key: credential.issuer
774
781
  }, {
775
- F: __dxlog_file3,
782
+ F: __dxlog_file4,
776
783
  L: 84,
777
784
  S: this,
778
785
  C: (f, a) => f(...a)
@@ -803,10 +810,59 @@ import { DeviceStateMachine, createCredentialSignerWithKey, createCredentialSign
803
810
  import { writeMessages } from "@dxos/feed-store";
804
811
  import { invariant as invariant2 } from "@dxos/invariant";
805
812
  import { PublicKey as PublicKey3 } from "@dxos/keys";
806
- import { log as log3 } from "@dxos/log";
813
+ import { log as log4 } from "@dxos/log";
807
814
  import { AdmittedFeed } from "@dxos/protocols/proto/dxos/halo/credentials";
815
+ import { Timeframe } from "@dxos/timeframe";
808
816
  import { trace as trace2 } from "@dxos/tracing";
809
817
  import { ComplexSet } from "@dxos/util";
818
+
819
+ // packages/sdk/client-services/src/packlets/identity/default-space-state-machine.ts
820
+ import { getCredentialAssertion } from "@dxos/credentials";
821
+ import { SpaceId } from "@dxos/keys";
822
+ import { log as log3 } from "@dxos/log";
823
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/default-space-state-machine.ts";
824
+ var DefaultSpaceStateMachine = class {
825
+ constructor(_params) {
826
+ this._params = _params;
827
+ }
828
+ get spaceId() {
829
+ return this._spaceId;
830
+ }
831
+ async processCredential(credential) {
832
+ const assertion = getCredentialAssertion(credential);
833
+ switch (assertion["@type"]) {
834
+ case "dxos.halo.credentials.DefaultSpace": {
835
+ if (!credential.subject.id.equals(this._params.identityKey)) {
836
+ log3.warn("Invalid default space credential", {
837
+ expectedIdentity: this._params.identityKey,
838
+ credential
839
+ }, {
840
+ F: __dxlog_file5,
841
+ L: 32,
842
+ S: this,
843
+ C: (f, a) => f(...a)
844
+ });
845
+ return;
846
+ }
847
+ if (!SpaceId.isValid(assertion.spaceId)) {
848
+ log3.warn("Invalid default space id", {
849
+ id: assertion.spaceId
850
+ }, {
851
+ F: __dxlog_file5,
852
+ L: 36,
853
+ S: this,
854
+ C: (f, a) => f(...a)
855
+ });
856
+ return;
857
+ }
858
+ this._spaceId = assertion.spaceId;
859
+ break;
860
+ }
861
+ }
862
+ }
863
+ };
864
+
865
+ // packages/sdk/client-services/src/packlets/identity/identity.ts
810
866
  function _ts_decorate2(decorators, target, key, desc) {
811
867
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
812
868
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -817,7 +873,7 @@ function _ts_decorate2(decorators, target, key, desc) {
817
873
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
818
874
  return c > 3 && r && Object.defineProperty(target, key, r), r;
819
875
  }
820
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity.ts";
876
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity.ts";
821
877
  var Identity = class {
822
878
  constructor({ space, signer, identityKey, deviceKey, presence }) {
823
879
  this.stateUpdate = new Event();
@@ -826,11 +882,11 @@ var Identity = class {
826
882
  this._presence = presence;
827
883
  this.identityKey = identityKey;
828
884
  this.deviceKey = deviceKey;
829
- log3.trace("dxos.halo.device", {
885
+ log4.trace("dxos.halo.device", {
830
886
  deviceKey
831
887
  }, {
832
- F: __dxlog_file4,
833
- L: 67,
888
+ F: __dxlog_file6,
889
+ L: 70,
834
890
  S: this,
835
891
  C: (f, a) => f(...a)
836
892
  });
@@ -843,6 +899,10 @@ var Identity = class {
843
899
  identityKey: this.identityKey,
844
900
  onUpdate: () => this.stateUpdate.emit()
845
901
  });
902
+ this._defaultSpaceStateMachine = new DefaultSpaceStateMachine({
903
+ identityKey: this.identityKey,
904
+ onUpdate: () => this.stateUpdate.emit()
905
+ });
846
906
  this.authVerifier = new TrustedKeySetAuthVerifier({
847
907
  trustedKeysProvider: () => new ComplexSet(PublicKey3.hash, this.authorizedDeviceKeys.keys()),
848
908
  update: this.stateUpdate,
@@ -853,14 +913,20 @@ var Identity = class {
853
913
  get authorizedDeviceKeys() {
854
914
  return this._deviceStateMachine.authorizedDeviceKeys;
855
915
  }
916
+ get defaultSpaceId() {
917
+ return this._defaultSpaceStateMachine.spaceId;
918
+ }
856
919
  async open(ctx) {
920
+ await this._presence?.open();
857
921
  await this.space.spaceState.addCredentialProcessor(this._deviceStateMachine);
858
922
  await this.space.spaceState.addCredentialProcessor(this._profileStateMachine);
923
+ await this.space.spaceState.addCredentialProcessor(this._defaultSpaceStateMachine);
859
924
  await this.space.open(ctx);
860
925
  }
861
926
  async close(ctx) {
862
- await this._presence?.destroy();
927
+ await this._presence?.close();
863
928
  await this.authVerifier.close();
929
+ await this.space.spaceState.removeCredentialProcessor(this._defaultSpaceStateMachine);
864
930
  await this.space.spaceState.removeCredentialProcessor(this._profileStateMachine);
865
931
  await this.space.spaceState.removeCredentialProcessor(this._deviceStateMachine);
866
932
  await this.space.close();
@@ -898,8 +964,8 @@ var Identity = class {
898
964
  */
899
965
  getIdentityCredentialSigner() {
900
966
  invariant2(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.", {
901
- F: __dxlog_file4,
902
- L: 145,
967
+ F: __dxlog_file6,
968
+ L: 159,
903
969
  S: this,
904
970
  A: [
905
971
  "this._deviceStateMachine.deviceCredentialChain",
@@ -914,16 +980,36 @@ var Identity = class {
914
980
  getDeviceCredentialSigner() {
915
981
  return createCredentialSignerWithKey(this._signer, this.deviceKey);
916
982
  }
983
+ async updateDefaultSpace(spaceId) {
984
+ const credential = await this.getDeviceCredentialSigner().createCredential({
985
+ subject: this.identityKey,
986
+ assertion: {
987
+ "@type": "dxos.halo.credentials.DefaultSpace",
988
+ spaceId
989
+ }
990
+ });
991
+ const receipt = await this.controlPipeline.writer.write({
992
+ credential: {
993
+ credential
994
+ }
995
+ });
996
+ await this.controlPipeline.state.waitUntilTimeframe(new Timeframe([
997
+ [
998
+ receipt.feedKey,
999
+ receipt.seq
1000
+ ]
1001
+ ]));
1002
+ }
917
1003
  async admitDevice({ deviceKey, controlFeedKey, dataFeedKey }) {
918
- log3("Admitting device:", {
1004
+ log4("Admitting device:", {
919
1005
  identityKey: this.identityKey,
920
1006
  hostDevice: this.deviceKey,
921
1007
  deviceKey,
922
1008
  controlFeedKey,
923
1009
  dataFeedKey
924
1010
  }, {
925
- F: __dxlog_file4,
926
- L: 161,
1011
+ F: __dxlog_file6,
1012
+ L: 184,
927
1013
  S: this,
928
1014
  C: (f, a) => f(...a)
929
1015
  });
@@ -981,12 +1067,12 @@ import { Context as Context3 } from "@dxos/context";
981
1067
  import { createCredentialSignerWithKey as createCredentialSignerWithKey2, CredentialGenerator } from "@dxos/credentials";
982
1068
  import { invariant as invariant3 } from "@dxos/invariant";
983
1069
  import { PublicKey as PublicKey4 } from "@dxos/keys";
984
- import { log as log4 } from "@dxos/log";
1070
+ import { log as log5 } from "@dxos/log";
985
1071
  import { trace as trace3 } from "@dxos/protocols";
986
1072
  import { Device, DeviceKind } from "@dxos/protocols/proto/dxos/client/services";
987
1073
  import { AdmittedFeed as AdmittedFeed2, DeviceType } from "@dxos/protocols/proto/dxos/halo/credentials";
988
1074
  import { Gossip, Presence } from "@dxos/teleport-extension-gossip";
989
- import { Timeframe } from "@dxos/timeframe";
1075
+ import { Timeframe as Timeframe2 } from "@dxos/timeframe";
990
1076
  import { trace as Trace } from "@dxos/tracing";
991
1077
  import { isNode, deferFunction } from "@dxos/util";
992
1078
  function _ts_decorate3(decorators, target, key, desc) {
@@ -999,7 +1085,7 @@ function _ts_decorate3(decorators, target, key, desc) {
999
1085
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1000
1086
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1001
1087
  }
1002
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-manager.ts";
1088
+ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-manager.ts";
1003
1089
  var DEVICE_PRESENCE_ANNOUNCE_INTERVAL = 1e4;
1004
1090
  var DEVICE_PRESENCE_OFFLINE_TIMEOUT = 2e4;
1005
1091
  var IdentityManager = class {
@@ -1020,19 +1106,19 @@ var IdentityManager = class {
1020
1106
  }
1021
1107
  async open(ctx) {
1022
1108
  const traceId = PublicKey4.random().toHex();
1023
- log4.trace("dxos.halo.identity-manager.open", trace3.begin({
1109
+ log5.trace("dxos.halo.identity-manager.open", trace3.begin({
1024
1110
  id: traceId
1025
1111
  }), {
1026
- F: __dxlog_file5,
1112
+ F: __dxlog_file7,
1027
1113
  L: 104,
1028
1114
  S: this,
1029
1115
  C: (f, a) => f(...a)
1030
1116
  });
1031
1117
  const identityRecord = this._metadataStore.getIdentityRecord();
1032
- log4("identity record", {
1118
+ log5("identity record", {
1033
1119
  identityRecord
1034
1120
  }, {
1035
- F: __dxlog_file5,
1121
+ F: __dxlog_file7,
1036
1122
  L: 107,
1037
1123
  S: this,
1038
1124
  C: (f, a) => f(...a)
@@ -1041,32 +1127,35 @@ var IdentityManager = class {
1041
1127
  this._identity = await this._constructIdentity(identityRecord);
1042
1128
  await this._identity.open(ctx);
1043
1129
  await this._identity.ready();
1044
- log4.trace("dxos.halo.identity", {
1130
+ log5.trace("dxos.halo.identity", {
1045
1131
  identityKey: identityRecord.identityKey,
1046
1132
  displayName: this._identity.profileDocument?.displayName
1047
1133
  }, {
1048
- F: __dxlog_file5,
1134
+ F: __dxlog_file7,
1049
1135
  L: 112,
1050
1136
  S: this,
1051
1137
  C: (f, a) => f(...a)
1052
1138
  });
1053
1139
  this.stateUpdate.emit();
1054
1140
  }
1055
- log4.trace("dxos.halo.identity-manager.open", trace3.end({
1141
+ log5.trace("dxos.halo.identity-manager.open", trace3.end({
1056
1142
  id: traceId
1057
1143
  }), {
1058
- F: __dxlog_file5,
1144
+ F: __dxlog_file7,
1059
1145
  L: 119,
1060
1146
  S: this,
1061
1147
  C: (f, a) => f(...a)
1062
1148
  });
1063
1149
  }
1064
1150
  async close() {
1065
- await this._identity?.close(new Context3());
1151
+ await this._identity?.close(new Context3(void 0, {
1152
+ F: __dxlog_file7,
1153
+ L: 123
1154
+ }));
1066
1155
  }
1067
1156
  async createIdentity({ displayName, deviceProfile } = {}) {
1068
1157
  invariant3(!this._identity, "Identity already exists.", {
1069
- F: __dxlog_file5,
1158
+ F: __dxlog_file7,
1070
1159
  L: 128,
1071
1160
  S: this,
1072
1161
  A: [
@@ -1074,8 +1163,8 @@ var IdentityManager = class {
1074
1163
  "'Identity already exists.'"
1075
1164
  ]
1076
1165
  });
1077
- log4("creating identity...", void 0, {
1078
- F: __dxlog_file5,
1166
+ log5("creating identity...", void 0, {
1167
+ F: __dxlog_file7,
1079
1168
  L: 129,
1080
1169
  S: this,
1081
1170
  C: (f, a) => f(...a)
@@ -1092,11 +1181,14 @@ var IdentityManager = class {
1092
1181
  }
1093
1182
  };
1094
1183
  const identity = await this._constructIdentity(identityRecord);
1095
- await identity.open(new Context3());
1184
+ await identity.open(new Context3(void 0, {
1185
+ F: __dxlog_file7,
1186
+ L: 144
1187
+ }));
1096
1188
  {
1097
1189
  const generator = new CredentialGenerator(this._keyring, identityRecord.identityKey, identityRecord.deviceKey);
1098
1190
  invariant3(identityRecord.haloSpace.genesisFeedKey, "Genesis feed key is required.", {
1099
- F: __dxlog_file5,
1191
+ F: __dxlog_file7,
1100
1192
  L: 148,
1101
1193
  S: this,
1102
1194
  A: [
@@ -1105,7 +1197,7 @@ var IdentityManager = class {
1105
1197
  ]
1106
1198
  });
1107
1199
  invariant3(identityRecord.haloSpace.dataFeedKey, "Data feed key is required.", {
1108
- F: __dxlog_file5,
1200
+ F: __dxlog_file7,
1109
1201
  L: 149,
1110
1202
  S: this,
1111
1203
  A: [
@@ -1140,22 +1232,22 @@ var IdentityManager = class {
1140
1232
  await this._metadataStore.setIdentityRecord(identityRecord);
1141
1233
  this._identity = identity;
1142
1234
  await this._identity.ready();
1143
- log4.trace("dxos.halo.identity", {
1235
+ log5.trace("dxos.halo.identity", {
1144
1236
  identityKey: identityRecord.identityKey,
1145
1237
  displayName: this._identity.profileDocument?.displayName
1146
1238
  }, {
1147
- F: __dxlog_file5,
1239
+ F: __dxlog_file7,
1148
1240
  L: 191,
1149
1241
  S: this,
1150
1242
  C: (f, a) => f(...a)
1151
1243
  });
1152
1244
  this.stateUpdate.emit();
1153
- log4("created identity", {
1245
+ log5("created identity", {
1154
1246
  identityKey: identity.identityKey,
1155
1247
  deviceKey: identity.deviceKey,
1156
1248
  profile: identity.profileDocument
1157
1249
  }, {
1158
- F: __dxlog_file5,
1250
+ F: __dxlog_file7,
1159
1251
  L: 197,
1160
1252
  S: this,
1161
1253
  C: (f, a) => f(...a)
@@ -1189,16 +1281,16 @@ var IdentityManager = class {
1189
1281
  * Accept an existing identity. Expects its device key to be authorized (now or later).
1190
1282
  */
1191
1283
  async acceptIdentity(params) {
1192
- log4("accepting identity", {
1284
+ log5("accepting identity", {
1193
1285
  params
1194
1286
  }, {
1195
- F: __dxlog_file5,
1287
+ F: __dxlog_file7,
1196
1288
  L: 235,
1197
1289
  S: this,
1198
1290
  C: (f, a) => f(...a)
1199
1291
  });
1200
1292
  invariant3(!this._identity, "Identity already exists.", {
1201
- F: __dxlog_file5,
1293
+ F: __dxlog_file7,
1202
1294
  L: 236,
1203
1295
  S: this,
1204
1296
  A: [
@@ -1218,15 +1310,18 @@ var IdentityManager = class {
1218
1310
  }
1219
1311
  };
1220
1312
  const identity = await this._constructIdentity(identityRecord);
1221
- await identity.open(new Context3());
1313
+ await identity.open(new Context3(void 0, {
1314
+ F: __dxlog_file7,
1315
+ L: 251
1316
+ }));
1222
1317
  this._identity = identity;
1223
1318
  await this._metadataStore.setIdentityRecord(identityRecord);
1224
1319
  await this._identity.ready();
1225
- log4.trace("dxos.halo.identity", {
1320
+ log5.trace("dxos.halo.identity", {
1226
1321
  identityKey: identityRecord.identityKey,
1227
1322
  displayName: this._identity.profileDocument?.displayName
1228
1323
  }, {
1229
- F: __dxlog_file5,
1324
+ F: __dxlog_file7,
1230
1325
  L: 255,
1231
1326
  S: this,
1232
1327
  C: (f, a) => f(...a)
@@ -1236,11 +1331,11 @@ var IdentityManager = class {
1236
1331
  ...params.deviceProfile
1237
1332
  });
1238
1333
  this.stateUpdate.emit();
1239
- log4("accepted identity", {
1334
+ log5("accepted identity", {
1240
1335
  identityKey: identity.identityKey,
1241
1336
  deviceKey: identity.deviceKey
1242
1337
  }, {
1243
- F: __dxlog_file5,
1338
+ F: __dxlog_file7,
1244
1339
  L: 265,
1245
1340
  S: this,
1246
1341
  C: (f, a) => f(...a)
@@ -1252,7 +1347,7 @@ var IdentityManager = class {
1252
1347
  */
1253
1348
  async updateProfile(profile) {
1254
1349
  invariant3(this._identity, "Identity not initialized.", {
1255
- F: __dxlog_file5,
1350
+ F: __dxlog_file7,
1256
1351
  L: 273,
1257
1352
  S: this,
1258
1353
  A: [
@@ -1272,7 +1367,7 @@ var IdentityManager = class {
1272
1367
  credential
1273
1368
  }
1274
1369
  });
1275
- await this._identity.controlPipeline.state.waitUntilTimeframe(new Timeframe([
1370
+ await this._identity.controlPipeline.state.waitUntilTimeframe(new Timeframe2([
1276
1371
  [
1277
1372
  receipt.feedKey,
1278
1373
  receipt.seq
@@ -1283,7 +1378,7 @@ var IdentityManager = class {
1283
1378
  }
1284
1379
  async updateDeviceProfile(profile) {
1285
1380
  invariant3(this._identity, "Identity not initialized.", {
1286
- F: __dxlog_file5,
1381
+ F: __dxlog_file7,
1287
1382
  L: 290,
1288
1383
  S: this,
1289
1384
  A: [
@@ -1303,7 +1398,7 @@ var IdentityManager = class {
1303
1398
  credential
1304
1399
  }
1305
1400
  });
1306
- await this._identity.controlPipeline.state.waitUntilTimeframe(new Timeframe([
1401
+ await this._identity.controlPipeline.state.waitUntilTimeframe(new Timeframe2([
1307
1402
  [
1308
1403
  receipt.feedKey,
1309
1404
  receipt.seq
@@ -1319,7 +1414,7 @@ var IdentityManager = class {
1319
1414
  }
1320
1415
  async _constructIdentity(identityRecord) {
1321
1416
  invariant3(!this._identity, void 0, {
1322
- F: __dxlog_file5,
1417
+ F: __dxlog_file7,
1323
1418
  L: 316,
1324
1419
  S: this,
1325
1420
  A: [
@@ -1327,10 +1422,10 @@ var IdentityManager = class {
1327
1422
  ""
1328
1423
  ]
1329
1424
  });
1330
- log4("constructing identity", {
1425
+ log5("constructing identity", {
1331
1426
  identityRecord
1332
1427
  }, {
1333
- F: __dxlog_file5,
1428
+ F: __dxlog_file7,
1334
1429
  L: 317,
1335
1430
  S: this,
1336
1431
  C: (f, a) => f(...a)
@@ -1345,7 +1440,7 @@ var IdentityManager = class {
1345
1440
  gossip
1346
1441
  });
1347
1442
  invariant3(identityRecord.haloSpace.controlFeedKey, void 0, {
1348
- F: __dxlog_file5,
1443
+ F: __dxlog_file7,
1349
1444
  L: 330,
1350
1445
  S: this,
1351
1446
  A: [
@@ -1357,7 +1452,7 @@ var IdentityManager = class {
1357
1452
  writable: true
1358
1453
  });
1359
1454
  invariant3(identityRecord.haloSpace.dataFeedKey, void 0, {
1360
- F: __dxlog_file5,
1455
+ F: __dxlog_file7,
1361
1456
  L: 334,
1362
1457
  S: this,
1363
1458
  A: [
@@ -1388,10 +1483,10 @@ var IdentityManager = class {
1388
1483
  identityKey: identityRecord.identityKey,
1389
1484
  deviceKey: identityRecord.deviceKey
1390
1485
  });
1391
- log4("done", {
1486
+ log5("done", {
1392
1487
  identityKey: identityRecord.identityKey
1393
1488
  }, {
1394
- F: __dxlog_file5,
1489
+ F: __dxlog_file7,
1395
1490
  L: 360,
1396
1491
  S: this,
1397
1492
  C: (f, a) => f(...a)
@@ -1415,8 +1510,8 @@ var IdentityManager = class {
1415
1510
  }));
1416
1511
  },
1417
1512
  onAuthFailure: () => {
1418
- log4.warn("auth failure", void 0, {
1419
- F: __dxlog_file5,
1513
+ log5.warn("auth failure", void 0, {
1514
+ F: __dxlog_file7,
1420
1515
  L: 385,
1421
1516
  S: this,
1422
1517
  C: (f, a) => f(...a)
@@ -1440,25 +1535,55 @@ IdentityManager = _ts_decorate3([
1440
1535
  ], IdentityManager);
1441
1536
 
1442
1537
  // packages/sdk/client-services/src/packlets/identity/identity-service.ts
1538
+ import { Trigger as Trigger3, sleep } from "@dxos/async";
1443
1539
  import { Stream as Stream8 } from "@dxos/codec-protobuf";
1540
+ import { Resource } from "@dxos/context";
1444
1541
  import { signPresentation } from "@dxos/credentials";
1445
1542
  import { todo } from "@dxos/debug";
1446
1543
  import { invariant as invariant4 } from "@dxos/invariant";
1447
- var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
1448
- var IdentityServiceImpl = class {
1449
- constructor(_createIdentity, _identityManager, _keyring, _onProfileUpdate) {
1450
- this._createIdentity = _createIdentity;
1544
+ import { log as log6 } from "@dxos/log";
1545
+ import { SpaceState } from "@dxos/protocols/proto/dxos/client/services";
1546
+ import { safeAwaitAll } from "@dxos/util";
1547
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
1548
+ var DEFAULT_SPACE_SEARCH_TIMEOUT = 1e4;
1549
+ var IdentityServiceImpl = class extends Resource {
1550
+ constructor(_identityManager, _keyring, _dataSpaceManagerProvider, _createIdentity, _onProfileUpdate) {
1551
+ super();
1451
1552
  this._identityManager = _identityManager;
1452
1553
  this._keyring = _keyring;
1554
+ this._dataSpaceManagerProvider = _dataSpaceManagerProvider;
1555
+ this._createIdentity = _createIdentity;
1453
1556
  this._onProfileUpdate = _onProfileUpdate;
1454
1557
  }
1558
+ async _open() {
1559
+ const identity = this._identityManager.identity;
1560
+ if (identity && !identity.defaultSpaceId) {
1561
+ await this._fixIdentityWithoutDefaultSpace(identity);
1562
+ }
1563
+ }
1455
1564
  async createIdentity(request) {
1456
1565
  await this._createIdentity({
1457
1566
  displayName: request.profile?.displayName,
1458
1567
  deviceProfile: request.deviceProfile
1459
1568
  });
1569
+ const dataSpaceManager = this._dataSpaceManagerProvider();
1570
+ await this._createDefaultSpace(dataSpaceManager);
1460
1571
  return this._getIdentity();
1461
1572
  }
1573
+ async _createDefaultSpace(dataSpaceManager) {
1574
+ const space = await dataSpaceManager.createDefaultSpace();
1575
+ const identity = this._identityManager.identity;
1576
+ invariant4(identity, void 0, {
1577
+ F: __dxlog_file8,
1578
+ L: 59,
1579
+ S: this,
1580
+ A: [
1581
+ "identity",
1582
+ ""
1583
+ ]
1584
+ });
1585
+ await identity.updateDefaultSpace(space.id);
1586
+ }
1462
1587
  async recoverIdentity(request) {
1463
1588
  return todo();
1464
1589
  }
@@ -1483,8 +1608,8 @@ var IdentityServiceImpl = class {
1483
1608
  }
1484
1609
  async updateProfile(profile) {
1485
1610
  invariant4(this._identityManager.identity, "Identity not initialized.", {
1486
- F: __dxlog_file6,
1487
- L: 61,
1611
+ F: __dxlog_file8,
1612
+ L: 89,
1488
1613
  S: this,
1489
1614
  A: [
1490
1615
  "this._identityManager.identity",
@@ -1497,8 +1622,8 @@ var IdentityServiceImpl = class {
1497
1622
  }
1498
1623
  async signPresentation({ presentation, nonce }) {
1499
1624
  invariant4(this._identityManager.identity, "Identity not initialized.", {
1500
- F: __dxlog_file6,
1501
- L: 68,
1625
+ F: __dxlog_file8,
1626
+ L: 96,
1502
1627
  S: this,
1503
1628
  A: [
1504
1629
  "this._identityManager.identity",
@@ -1513,13 +1638,61 @@ var IdentityServiceImpl = class {
1513
1638
  nonce
1514
1639
  });
1515
1640
  }
1641
+ async _fixIdentityWithoutDefaultSpace(identity) {
1642
+ let recodedDefaultSpace = false;
1643
+ let foundDefaultSpace = false;
1644
+ const dataSpaceManager = this._dataSpaceManagerProvider();
1645
+ const recordedDefaultSpaceTrigger = new Trigger3();
1646
+ const allProcessed = safeAwaitAll(dataSpaceManager.spaces.values(), async (space) => {
1647
+ if (space.state === SpaceState.CLOSED) {
1648
+ await space.open();
1649
+ const requiresMigration = space.stateUpdate.waitForCondition(() => space.state === SpaceState.REQUIRES_MIGRATION);
1650
+ await Promise.race([
1651
+ space.initializeDataPipeline(),
1652
+ requiresMigration
1653
+ ]);
1654
+ }
1655
+ if (await dataSpaceManager.isDefaultSpace(space)) {
1656
+ if (foundDefaultSpace) {
1657
+ log6.warn("Multiple default spaces found. Using the first one.", {
1658
+ duplicate: space.id
1659
+ }, {
1660
+ F: __dxlog_file8,
1661
+ L: 129,
1662
+ S: this,
1663
+ C: (f, a) => f(...a)
1664
+ });
1665
+ return;
1666
+ }
1667
+ foundDefaultSpace = true;
1668
+ await identity.updateDefaultSpace(space.id);
1669
+ recodedDefaultSpace = true;
1670
+ recordedDefaultSpaceTrigger.wake();
1671
+ }
1672
+ }, (err) => {
1673
+ log6.catch(err, void 0, {
1674
+ F: __dxlog_file8,
1675
+ L: 140,
1676
+ S: this,
1677
+ C: (f, a) => f(...a)
1678
+ });
1679
+ });
1680
+ await Promise.race([
1681
+ allProcessed,
1682
+ recordedDefaultSpaceTrigger.wait(),
1683
+ sleep(DEFAULT_SPACE_SEARCH_TIMEOUT)
1684
+ ]);
1685
+ if (!recodedDefaultSpace) {
1686
+ await this._createDefaultSpace(dataSpaceManager);
1687
+ }
1688
+ }
1516
1689
  };
1517
1690
 
1518
1691
  // packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts
1519
1692
  import { invariant as invariant5 } from "@dxos/invariant";
1520
1693
  import { AlreadyJoinedError } from "@dxos/protocols";
1521
1694
  import { Invitation } from "@dxos/protocols/proto/dxos/client/services";
1522
- var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts";
1695
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts";
1523
1696
  var DeviceInvitationProtocol = class {
1524
1697
  constructor(_keyring, _getIdentity, _acceptIdentity) {
1525
1698
  this._keyring = _keyring;
@@ -1545,7 +1718,7 @@ var DeviceInvitationProtocol = class {
1545
1718
  }
1546
1719
  async admit(_, request) {
1547
1720
  invariant5(request.device, void 0, {
1548
- F: __dxlog_file7,
1721
+ F: __dxlog_file9,
1549
1722
  L: 50,
1550
1723
  S: this,
1551
1724
  A: [
@@ -1591,7 +1764,7 @@ var DeviceInvitationProtocol = class {
1591
1764
  }
1592
1765
  async accept(response, request) {
1593
1766
  invariant5(response.device, void 0, {
1594
- F: __dxlog_file7,
1767
+ F: __dxlog_file9,
1595
1768
  L: 95,
1596
1769
  S: this,
1597
1770
  A: [
@@ -1601,7 +1774,7 @@ var DeviceInvitationProtocol = class {
1601
1774
  });
1602
1775
  const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
1603
1776
  invariant5(request.device, void 0, {
1604
- F: __dxlog_file7,
1777
+ F: __dxlog_file9,
1605
1778
  L: 98,
1606
1779
  S: this,
1607
1780
  A: [
@@ -1633,7 +1806,7 @@ import { ContextDisposedError as ContextDisposedError2 } from "@dxos/context";
1633
1806
  import { createKeyPair, sign } from "@dxos/crypto";
1634
1807
  import { invariant as invariant9 } from "@dxos/invariant";
1635
1808
  import { PublicKey as PublicKey7 } from "@dxos/keys";
1636
- import { log as log8 } from "@dxos/log";
1809
+ import { log as log10 } from "@dxos/log";
1637
1810
  import { createTeleportProtocolFactory } from "@dxos/network-manager";
1638
1811
  import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError3, trace as trace5 } from "@dxos/protocols";
1639
1812
  import { Invitation as Invitation4 } from "@dxos/protocols/proto/dxos/client/services";
@@ -1642,10 +1815,10 @@ import { Options as Options4 } from "@dxos/protocols/proto/dxos/halo/invitations
1642
1815
  import { ComplexSet as ComplexSet3 } from "@dxos/util";
1643
1816
 
1644
1817
  // packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts
1645
- import { Trigger as Trigger3 } from "@dxos/async";
1818
+ import { Trigger as Trigger4 } from "@dxos/async";
1646
1819
  import { cancelWithContext as cancelWithContext2, Context as Context4 } from "@dxos/context";
1647
1820
  import { invariant as invariant6 } from "@dxos/invariant";
1648
- import { log as log5 } from "@dxos/log";
1821
+ import { log as log7 } from "@dxos/log";
1649
1822
  import { InvalidInvitationExtensionRoleError, schema as schema2 } from "@dxos/protocols";
1650
1823
  import { Options } from "@dxos/protocols/proto/dxos/halo/invitations";
1651
1824
  import { RpcExtension } from "@dxos/teleport";
@@ -1670,7 +1843,7 @@ var tryAcquireBeforeContextDisposed = async (ctx, mutex) => {
1670
1843
  };
1671
1844
 
1672
1845
  // packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts
1673
- var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts";
1846
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts";
1674
1847
  var OPTIONS_TIMEOUT = 1e4;
1675
1848
  var InvitationGuestExtension = class extends RpcExtension {
1676
1849
  constructor(_invitationFlowMutex, _callbacks) {
@@ -1684,8 +1857,11 @@ var InvitationGuestExtension = class extends RpcExtension {
1684
1857
  });
1685
1858
  this._invitationFlowMutex = _invitationFlowMutex;
1686
1859
  this._callbacks = _callbacks;
1687
- this._ctx = new Context4();
1688
- this._remoteOptionsTrigger = new Trigger3();
1860
+ this._ctx = new Context4(void 0, {
1861
+ F: __dxlog_file10,
1862
+ L: 33
1863
+ });
1864
+ this._remoteOptionsTrigger = new Trigger4();
1689
1865
  this._invitationFlowLock = null;
1690
1866
  }
1691
1867
  hasFlowLock() {
@@ -1696,7 +1872,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1696
1872
  InvitationHostService: {
1697
1873
  options: async (options) => {
1698
1874
  invariant6(!this._remoteOptions, "Remote options already set.", {
1699
- F: __dxlog_file8,
1875
+ F: __dxlog_file10,
1700
1876
  L: 63,
1701
1877
  S: this,
1702
1878
  A: [
@@ -1722,15 +1898,15 @@ var InvitationGuestExtension = class extends RpcExtension {
1722
1898
  async onOpen(context) {
1723
1899
  await super.onOpen(context);
1724
1900
  try {
1725
- log5("guest acquire lock", void 0, {
1726
- F: __dxlog_file8,
1901
+ log7("guest acquire lock", void 0, {
1902
+ F: __dxlog_file10,
1727
1903
  L: 84,
1728
1904
  S: this,
1729
1905
  C: (f, a) => f(...a)
1730
1906
  });
1731
1907
  this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
1732
- log5("guest lock acquired", void 0, {
1733
- F: __dxlog_file8,
1908
+ log7("guest lock acquired", void 0, {
1909
+ F: __dxlog_file10,
1734
1910
  L: 86,
1735
1911
  S: this,
1736
1912
  C: (f, a) => f(...a)
@@ -1738,8 +1914,8 @@ var InvitationGuestExtension = class extends RpcExtension {
1738
1914
  await cancelWithContext2(this._ctx, this.rpc.InvitationHostService.options({
1739
1915
  role: Options.Role.GUEST
1740
1916
  }));
1741
- log5("options sent", void 0, {
1742
- F: __dxlog_file8,
1917
+ log7("options sent", void 0, {
1918
+ F: __dxlog_file10,
1743
1919
  L: 88,
1744
1920
  S: this,
1745
1921
  C: (f, a) => f(...a)
@@ -1747,8 +1923,8 @@ var InvitationGuestExtension = class extends RpcExtension {
1747
1923
  await cancelWithContext2(this._ctx, this._remoteOptionsTrigger.wait({
1748
1924
  timeout: OPTIONS_TIMEOUT
1749
1925
  }));
1750
- log5("options received", void 0, {
1751
- F: __dxlog_file8,
1926
+ log7("options received", void 0, {
1927
+ F: __dxlog_file10,
1752
1928
  L: 90,
1753
1929
  S: this,
1754
1930
  C: (f, a) => f(...a)
@@ -1781,8 +1957,8 @@ var InvitationGuestExtension = class extends RpcExtension {
1781
1957
  if (this._invitationFlowLock != null) {
1782
1958
  this._invitationFlowLock.release();
1783
1959
  this._invitationFlowLock = null;
1784
- log5("invitation flow lock released", void 0, {
1785
- F: __dxlog_file8,
1960
+ log7("invitation flow lock released", void 0, {
1961
+ F: __dxlog_file10,
1786
1962
  L: 123,
1787
1963
  S: this,
1788
1964
  C: (f, a) => f(...a)
@@ -1792,17 +1968,17 @@ var InvitationGuestExtension = class extends RpcExtension {
1792
1968
  };
1793
1969
 
1794
1970
  // packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts
1795
- import { Trigger as Trigger4, scheduleTask as scheduleTask2 } from "@dxos/async";
1971
+ import { Trigger as Trigger5, scheduleTask as scheduleTask2 } from "@dxos/async";
1796
1972
  import { cancelWithContext as cancelWithContext3, Context as Context5 } from "@dxos/context";
1797
1973
  import { randomBytes, verify } from "@dxos/crypto";
1798
1974
  import { invariant as invariant7, InvariantViolation } from "@dxos/invariant";
1799
1975
  import { PublicKey as PublicKey5 } from "@dxos/keys";
1800
- import { log as log6 } from "@dxos/log";
1976
+ import { log as log8 } from "@dxos/log";
1801
1977
  import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError2, schema as schema3, trace as trace4 } from "@dxos/protocols";
1802
1978
  import { Invitation as Invitation3 } from "@dxos/protocols/proto/dxos/client/services";
1803
1979
  import { AuthenticationResponse, Options as Options2 } from "@dxos/protocols/proto/dxos/halo/invitations";
1804
1980
  import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
1805
- var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts";
1981
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts";
1806
1982
  var OPTIONS_TIMEOUT2 = 1e4;
1807
1983
  var MAX_OTP_ATTEMPTS = 3;
1808
1984
  var InvitationHostExtension = class extends RpcExtension2 {
@@ -1817,13 +1993,16 @@ var InvitationHostExtension = class extends RpcExtension2 {
1817
1993
  });
1818
1994
  this._invitationFlowMutex = _invitationFlowMutex;
1819
1995
  this._callbacks = _callbacks;
1820
- this._ctx = new Context5();
1821
- this._remoteOptionsTrigger = new Trigger4();
1996
+ this._ctx = new Context5(void 0, {
1997
+ F: __dxlog_file11,
1998
+ L: 52
1999
+ });
2000
+ this._remoteOptionsTrigger = new Trigger5();
1822
2001
  this._challenge = void 0;
1823
2002
  this.guestProfile = void 0;
1824
2003
  this.authenticationPassed = false;
1825
2004
  this.authenticationRetry = 0;
1826
- this.completedTrigger = new Trigger4();
2005
+ this.completedTrigger = new Trigger5();
1827
2006
  this._invitationFlowLock = null;
1828
2007
  }
1829
2008
  hasFlowLock() {
@@ -1836,7 +2015,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
1836
2015
  InvitationHostService: {
1837
2016
  options: async (options) => {
1838
2017
  invariant7(!this._remoteOptions, "Remote options already set.", {
1839
- F: __dxlog_file9,
2018
+ F: __dxlog_file11,
1840
2019
  L: 101,
1841
2020
  S: this,
1842
2021
  A: [
@@ -1850,10 +2029,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
1850
2029
  introduce: async (request) => {
1851
2030
  const { profile, invitationId } = request;
1852
2031
  const traceId = PublicKey5.random().toHex();
1853
- log6.trace("dxos.sdk.invitation-handler.host.introduce", trace4.begin({
2032
+ log8.trace("dxos.sdk.invitation-handler.host.introduce", trace4.begin({
1854
2033
  id: traceId
1855
2034
  }), {
1856
- F: __dxlog_file9,
2035
+ F: __dxlog_file11,
1857
2036
  L: 110,
1858
2037
  S: this,
1859
2038
  C: (f, a) => f(...a)
@@ -1861,11 +2040,11 @@ var InvitationHostExtension = class extends RpcExtension2 {
1861
2040
  const invitation = this._requireActiveInvitation();
1862
2041
  this._assertInvitationState(Invitation3.State.CONNECTED);
1863
2042
  if (invitationId !== invitation?.invitationId) {
1864
- log6.warn("incorrect invitationId", {
2043
+ log8.warn("incorrect invitationId", {
1865
2044
  expected: invitation.invitationId,
1866
2045
  actual: invitationId
1867
2046
  }, {
1868
- F: __dxlog_file9,
2047
+ F: __dxlog_file11,
1869
2048
  L: 116,
1870
2049
  S: this,
1871
2050
  C: (f, a) => f(...a)
@@ -1876,10 +2055,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
1876
2055
  authMethod: Invitation3.AuthMethod.NONE
1877
2056
  };
1878
2057
  }
1879
- log6("guest introduced themselves", {
2058
+ log8("guest introduced themselves", {
1880
2059
  guestProfile: profile
1881
2060
  }, {
1882
- F: __dxlog_file9,
2061
+ F: __dxlog_file11,
1883
2062
  L: 125,
1884
2063
  S: this,
1885
2064
  C: (f, a) => f(...a)
@@ -1887,10 +2066,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
1887
2066
  this.guestProfile = profile;
1888
2067
  this._callbacks.onStateUpdate(Invitation3.State.READY_FOR_AUTHENTICATION);
1889
2068
  this._challenge = invitation.authMethod === Invitation3.AuthMethod.KNOWN_PUBLIC_KEY ? randomBytes(32) : void 0;
1890
- log6.trace("dxos.sdk.invitation-handler.host.introduce", trace4.end({
2069
+ log8.trace("dxos.sdk.invitation-handler.host.introduce", trace4.end({
1891
2070
  id: traceId
1892
2071
  }), {
1893
- F: __dxlog_file9,
2072
+ F: __dxlog_file11,
1894
2073
  L: 132,
1895
2074
  S: this,
1896
2075
  C: (f, a) => f(...a)
@@ -1902,19 +2081,19 @@ var InvitationHostExtension = class extends RpcExtension2 {
1902
2081
  },
1903
2082
  authenticate: async ({ authCode: code, signedChallenge }) => {
1904
2083
  const traceId = PublicKey5.random().toHex();
1905
- log6.trace("dxos.sdk.invitation-handler.host.authenticate", trace4.begin({
2084
+ log8.trace("dxos.sdk.invitation-handler.host.authenticate", trace4.begin({
1906
2085
  id: traceId
1907
2086
  }), {
1908
- F: __dxlog_file9,
2087
+ F: __dxlog_file11,
1909
2088
  L: 141,
1910
2089
  S: this,
1911
2090
  C: (f, a) => f(...a)
1912
2091
  });
1913
2092
  const invitation = this._requireActiveInvitation();
1914
- log6("received authentication request", {
2093
+ log8("received authentication request", {
1915
2094
  authCode: code
1916
2095
  }, {
1917
- F: __dxlog_file9,
2096
+ F: __dxlog_file11,
1918
2097
  L: 144,
1919
2098
  S: this,
1920
2099
  C: (f, a) => f(...a)
@@ -1927,8 +2106,8 @@ var InvitationHostExtension = class extends RpcExtension2 {
1927
2106
  this._callbacks.onStateUpdate(Invitation3.State.AUTHENTICATING);
1928
2107
  switch (invitation.authMethod) {
1929
2108
  case Invitation3.AuthMethod.NONE: {
1930
- log6("authentication not required", void 0, {
1931
- F: __dxlog_file9,
2109
+ log8("authentication not required", void 0, {
2110
+ F: __dxlog_file11,
1932
2111
  L: 152,
1933
2112
  S: this,
1934
2113
  C: (f, a) => f(...a)
@@ -1963,10 +2142,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
1963
2142
  break;
1964
2143
  }
1965
2144
  default: {
1966
- log6.error("invalid authentication method", {
2145
+ log8.error("invalid authentication method", {
1967
2146
  authMethod: invitation.authMethod
1968
2147
  }, {
1969
- F: __dxlog_file9,
2148
+ F: __dxlog_file11,
1970
2149
  L: 190,
1971
2150
  S: this,
1972
2151
  C: (f, a) => f(...a)
@@ -1985,13 +2164,13 @@ var InvitationHostExtension = class extends RpcExtension2 {
1985
2164
  status
1986
2165
  };
1987
2166
  }
1988
- log6.trace("dxos.sdk.invitation-handler.host.authenticate", trace4.end({
2167
+ log8.trace("dxos.sdk.invitation-handler.host.authenticate", trace4.end({
1989
2168
  id: traceId,
1990
2169
  data: {
1991
2170
  status
1992
2171
  }
1993
2172
  }), {
1994
- F: __dxlog_file9,
2173
+ F: __dxlog_file11,
1995
2174
  L: 202,
1996
2175
  S: this,
1997
2176
  C: (f, a) => f(...a)
@@ -2002,10 +2181,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
2002
2181
  },
2003
2182
  admit: async (request) => {
2004
2183
  const traceId = PublicKey5.random().toHex();
2005
- log6.trace("dxos.sdk.invitation-handler.host.admit", trace4.begin({
2184
+ log8.trace("dxos.sdk.invitation-handler.host.admit", trace4.begin({
2006
2185
  id: traceId
2007
2186
  }), {
2008
- F: __dxlog_file9,
2187
+ F: __dxlog_file11,
2009
2188
  L: 208,
2010
2189
  S: this,
2011
2190
  C: (f, a) => f(...a)
@@ -2019,10 +2198,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
2019
2198
  }
2020
2199
  }
2021
2200
  const response = await this._callbacks.admit(request);
2022
- log6.trace("dxos.sdk.invitation-handler.host.admit", trace4.end({
2201
+ log8.trace("dxos.sdk.invitation-handler.host.admit", trace4.end({
2023
2202
  id: traceId
2024
2203
  }), {
2025
- F: __dxlog_file9,
2204
+ F: __dxlog_file11,
2026
2205
  L: 222,
2027
2206
  S: this,
2028
2207
  C: (f, a) => f(...a)
@@ -2039,15 +2218,15 @@ var InvitationHostExtension = class extends RpcExtension2 {
2039
2218
  async onOpen(context) {
2040
2219
  await super.onOpen(context);
2041
2220
  try {
2042
- log6("host acquire lock", void 0, {
2043
- F: __dxlog_file9,
2221
+ log8("host acquire lock", void 0, {
2222
+ F: __dxlog_file11,
2044
2223
  L: 237,
2045
2224
  S: this,
2046
2225
  C: (f, a) => f(...a)
2047
2226
  });
2048
2227
  this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
2049
- log6("host lock acquired", void 0, {
2050
- F: __dxlog_file9,
2228
+ log8("host lock acquired", void 0, {
2229
+ F: __dxlog_file11,
2051
2230
  L: 239,
2052
2231
  S: this,
2053
2232
  C: (f, a) => f(...a)
@@ -2057,8 +2236,8 @@ var InvitationHostExtension = class extends RpcExtension2 {
2057
2236
  await this.rpc.InvitationHostService.options({
2058
2237
  role: Options2.Role.HOST
2059
2238
  });
2060
- log6("options sent", void 0, {
2061
- F: __dxlog_file9,
2239
+ log8("options sent", void 0, {
2240
+ F: __dxlog_file11,
2062
2241
  L: 243,
2063
2242
  S: this,
2064
2243
  C: (f, a) => f(...a)
@@ -2066,8 +2245,8 @@ var InvitationHostExtension = class extends RpcExtension2 {
2066
2245
  await cancelWithContext3(this._ctx, this._remoteOptionsTrigger.wait({
2067
2246
  timeout: OPTIONS_TIMEOUT2
2068
2247
  }));
2069
- log6("options received", void 0, {
2070
- F: __dxlog_file9,
2248
+ log8("options received", void 0, {
2249
+ F: __dxlog_file11,
2071
2250
  L: 245,
2072
2251
  S: this,
2073
2252
  C: (f, a) => f(...a)
@@ -2120,8 +2299,8 @@ var InvitationHostExtension = class extends RpcExtension2 {
2120
2299
  if (this._invitationFlowLock != null) {
2121
2300
  this._invitationFlowLock?.release();
2122
2301
  this._invitationFlowLock = null;
2123
- log6("invitation flow lock released", void 0, {
2124
- F: __dxlog_file9,
2302
+ log8("invitation flow lock released", void 0, {
2303
+ F: __dxlog_file11,
2125
2304
  L: 300,
2126
2305
  S: this,
2127
2306
  C: (f, a) => f(...a)
@@ -2134,10 +2313,10 @@ var isAuthenticationRequired = (invitation) => invitation.authMethod !== Invitat
2134
2313
  // packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts
2135
2314
  import { invariant as invariant8 } from "@dxos/invariant";
2136
2315
  import { PublicKey as PublicKey6 } from "@dxos/keys";
2137
- import { log as log7 } from "@dxos/log";
2316
+ import { log as log9 } from "@dxos/log";
2138
2317
  import { Options as Options3 } from "@dxos/protocols/proto/dxos/halo/invitations";
2139
2318
  import { ComplexSet as ComplexSet2 } from "@dxos/util";
2140
- var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts";
2319
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts";
2141
2320
  var InvitationTopology = class {
2142
2321
  constructor(_role) {
2143
2322
  this._role = _role;
@@ -2145,7 +2324,7 @@ var InvitationTopology = class {
2145
2324
  }
2146
2325
  init(controller) {
2147
2326
  invariant8(!this._controller, "Already initialized.", {
2148
- F: __dxlog_file10,
2327
+ F: __dxlog_file12,
2149
2328
  L: 42,
2150
2329
  S: this,
2151
2330
  A: [
@@ -2157,7 +2336,7 @@ var InvitationTopology = class {
2157
2336
  }
2158
2337
  update() {
2159
2338
  invariant8(this._controller, "Not initialized.", {
2160
- F: __dxlog_file10,
2339
+ F: __dxlog_file12,
2161
2340
  L: 47,
2162
2341
  S: this,
2163
2342
  A: [
@@ -2176,11 +2355,11 @@ var InvitationTopology = class {
2176
2355
  const firstUnknownPeer = candidates.find((peerId) => !this._seenPeers.has(peerId));
2177
2356
  this._seenPeers = new ComplexSet2(PublicKey6.hash, allPeers.filter((peerId) => this._seenPeers.has(peerId)));
2178
2357
  if (firstUnknownPeer != null) {
2179
- log7("invitation connect", {
2358
+ log9("invitation connect", {
2180
2359
  ownPeerId,
2181
2360
  remotePeerId: firstUnknownPeer
2182
2361
  }, {
2183
- F: __dxlog_file10,
2362
+ F: __dxlog_file12,
2184
2363
  L: 69,
2185
2364
  S: this,
2186
2365
  C: (f, a) => f(...a)
@@ -2191,7 +2370,7 @@ var InvitationTopology = class {
2191
2370
  }
2192
2371
  async onOffer(peer) {
2193
2372
  invariant8(this._controller, "Not initialized.", {
2194
- F: __dxlog_file10,
2373
+ F: __dxlog_file12,
2195
2374
  L: 76,
2196
2375
  S: this,
2197
2376
  A: [
@@ -2210,7 +2389,7 @@ var InvitationTopology = class {
2210
2389
  };
2211
2390
 
2212
2391
  // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
2213
- var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts";
2392
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts";
2214
2393
  var MAX_DELEGATED_INVITATION_HOST_TRIES = 3;
2215
2394
  var InvitationsHandler = class {
2216
2395
  /**
@@ -2235,7 +2414,7 @@ var InvitationsHandler = class {
2235
2414
  try {
2236
2415
  const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
2237
2416
  invariant9(deviceKey, void 0, {
2238
- F: __dxlog_file11,
2417
+ F: __dxlog_file13,
2239
2418
  L: 90,
2240
2419
  S: this,
2241
2420
  A: [
@@ -2261,18 +2440,18 @@ var InvitationsHandler = class {
2261
2440
  scheduleTask3(connectionCtx, async () => {
2262
2441
  const traceId = PublicKey7.random().toHex();
2263
2442
  try {
2264
- log8.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.begin({
2443
+ log10.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.begin({
2265
2444
  id: traceId
2266
2445
  }), {
2267
- F: __dxlog_file11,
2446
+ F: __dxlog_file13,
2268
2447
  L: 115,
2269
2448
  S: this,
2270
2449
  C: (f, a) => f(...a)
2271
2450
  });
2272
- log8("connected", {
2451
+ log10("connected", {
2273
2452
  ...protocol.toJSON()
2274
2453
  }, {
2275
- F: __dxlog_file11,
2454
+ F: __dxlog_file13,
2276
2455
  L: 116,
2277
2456
  S: this,
2278
2457
  C: (f, a) => f(...a)
@@ -2280,20 +2459,20 @@ var InvitationsHandler = class {
2280
2459
  const deviceKey = await extension.completedTrigger.wait({
2281
2460
  timeout: invitation.timeout
2282
2461
  });
2283
- log8("admitted guest", {
2462
+ log10("admitted guest", {
2284
2463
  guest: deviceKey,
2285
2464
  ...protocol.toJSON()
2286
2465
  }, {
2287
- F: __dxlog_file11,
2466
+ F: __dxlog_file13,
2288
2467
  L: 118,
2289
2468
  S: this,
2290
2469
  C: (f, a) => f(...a)
2291
2470
  });
2292
2471
  guardedState.set(extension, Invitation4.State.SUCCESS);
2293
- log8.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.end({
2472
+ log10.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.end({
2294
2473
  id: traceId
2295
2474
  }), {
2296
- F: __dxlog_file11,
2475
+ F: __dxlog_file13,
2297
2476
  L: 120,
2298
2477
  S: this,
2299
2478
  C: (f, a) => f(...a)
@@ -2305,10 +2484,10 @@ var InvitationsHandler = class {
2305
2484
  } catch (err) {
2306
2485
  if (err instanceof TimeoutError) {
2307
2486
  if (guardedState.set(extension, Invitation4.State.TIMEOUT)) {
2308
- log8("timeout", {
2487
+ log10("timeout", {
2309
2488
  ...protocol.toJSON()
2310
2489
  }, {
2311
- F: __dxlog_file11,
2490
+ F: __dxlog_file13,
2312
2491
  L: 129,
2313
2492
  S: this,
2314
2493
  C: (f, a) => f(...a)
@@ -2316,19 +2495,19 @@ var InvitationsHandler = class {
2316
2495
  }
2317
2496
  } else {
2318
2497
  if (guardedState.error(extension, err)) {
2319
- log8.error("failed", err, {
2320
- F: __dxlog_file11,
2498
+ log10.error("failed", err, {
2499
+ F: __dxlog_file13,
2321
2500
  L: 133,
2322
2501
  S: this,
2323
2502
  C: (f, a) => f(...a)
2324
2503
  });
2325
2504
  }
2326
2505
  }
2327
- log8.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.error({
2506
+ log10.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.error({
2328
2507
  id: traceId,
2329
2508
  error: err
2330
2509
  }), {
2331
- F: __dxlog_file11,
2510
+ F: __dxlog_file13,
2332
2511
  L: 136,
2333
2512
  S: this,
2334
2513
  C: (f, a) => f(...a)
@@ -2339,10 +2518,10 @@ var InvitationsHandler = class {
2339
2518
  },
2340
2519
  onError: (err) => {
2341
2520
  if (err instanceof InvalidInvitationExtensionRoleError3) {
2342
- log8("invalid role", {
2521
+ log10("invalid role", {
2343
2522
  ...err.context
2344
2523
  }, {
2345
- F: __dxlog_file11,
2524
+ F: __dxlog_file13,
2346
2525
  L: 144,
2347
2526
  S: this,
2348
2527
  C: (f, a) => f(...a)
@@ -2351,10 +2530,10 @@ var InvitationsHandler = class {
2351
2530
  }
2352
2531
  if (err instanceof TimeoutError) {
2353
2532
  if (guardedState.set(extension, Invitation4.State.TIMEOUT)) {
2354
- log8("timeout", {
2533
+ log10("timeout", {
2355
2534
  err
2356
2535
  }, {
2357
- F: __dxlog_file11,
2536
+ F: __dxlog_file13,
2358
2537
  L: 149,
2359
2538
  S: this,
2360
2539
  C: (f, a) => f(...a)
@@ -2362,8 +2541,8 @@ var InvitationsHandler = class {
2362
2541
  }
2363
2542
  } else {
2364
2543
  if (guardedState.error(extension, err)) {
2365
- log8.error("failed", err, {
2366
- F: __dxlog_file11,
2544
+ log10.error("failed", err, {
2545
+ F: __dxlog_file13,
2367
2546
  L: 153,
2368
2547
  S: this,
2369
2548
  C: (f, a) => f(...a)
@@ -2376,8 +2555,8 @@ var InvitationsHandler = class {
2376
2555
  };
2377
2556
  if (invitation.lifetime && invitation.created) {
2378
2557
  if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
2379
- log8.warn("invitation has already expired", void 0, {
2380
- F: __dxlog_file11,
2558
+ log10.warn("invitation has already expired", void 0, {
2559
+ F: __dxlog_file13,
2381
2560
  L: 164,
2382
2561
  S: this,
2383
2562
  C: (f, a) => f(...a)
@@ -2400,7 +2579,7 @@ var InvitationsHandler = class {
2400
2579
  const { timeout = INVITATION_TIMEOUT } = invitation;
2401
2580
  if (deviceProfile) {
2402
2581
  invariant9(invitation.kind === Invitation4.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
2403
- F: __dxlog_file11,
2582
+ F: __dxlog_file13,
2404
2583
  L: 197,
2405
2584
  S: this,
2406
2585
  A: [
@@ -2413,12 +2592,12 @@ var InvitationsHandler = class {
2413
2592
  const guardedState = this._createGuardedState(ctx, invitation, stream);
2414
2593
  const shouldCancelInvitationFlow = (extension) => {
2415
2594
  const isLockedByAnotherConnection = guardedState.mutex.isLocked() && !extension.hasFlowLock();
2416
- log8("should cancel invitation flow", {
2595
+ log10("should cancel invitation flow", {
2417
2596
  isLockedByAnotherConnection,
2418
2597
  invitationType: Invitation4.Type.DELEGATED,
2419
2598
  triedPeers: triedPeersIds.size
2420
2599
  }, {
2421
- F: __dxlog_file11,
2600
+ F: __dxlog_file13,
2422
2601
  L: 205,
2423
2602
  S: this,
2424
2603
  C: (f, a) => f(...a)
@@ -2441,11 +2620,11 @@ var InvitationsHandler = class {
2441
2620
  return;
2442
2621
  }
2443
2622
  connectionCtx.onDispose(async () => {
2444
- log8("extension disposed", {
2623
+ log10("extension disposed", {
2445
2624
  admitted,
2446
2625
  currentState: guardedState.current.state
2447
2626
  }, {
2448
- F: __dxlog_file11,
2627
+ F: __dxlog_file13,
2449
2628
  L: 233,
2450
2629
  S: this,
2451
2630
  C: (f, a) => f(...a)
@@ -2460,10 +2639,10 @@ var InvitationsHandler = class {
2460
2639
  scheduleTask3(connectionCtx, async () => {
2461
2640
  const traceId = PublicKey7.random().toHex();
2462
2641
  try {
2463
- log8.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.begin({
2642
+ log10.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.begin({
2464
2643
  id: traceId
2465
2644
  }), {
2466
- F: __dxlog_file11,
2645
+ F: __dxlog_file13,
2467
2646
  L: 245,
2468
2647
  S: this,
2469
2648
  C: (f, a) => f(...a)
@@ -2472,19 +2651,19 @@ var InvitationsHandler = class {
2472
2651
  guardedState.set(extension, Invitation4.State.TIMEOUT);
2473
2652
  extensionCtx.close();
2474
2653
  }, timeout);
2475
- log8("connected", {
2654
+ log10("connected", {
2476
2655
  ...protocol.toJSON()
2477
2656
  }, {
2478
- F: __dxlog_file11,
2657
+ F: __dxlog_file13,
2479
2658
  L: 256,
2480
2659
  S: this,
2481
2660
  C: (f, a) => f(...a)
2482
2661
  });
2483
2662
  guardedState.set(extension, Invitation4.State.CONNECTED);
2484
- log8("introduce", {
2663
+ log10("introduce", {
2485
2664
  ...protocol.toJSON()
2486
2665
  }, {
2487
- F: __dxlog_file11,
2666
+ F: __dxlog_file13,
2488
2667
  L: 260,
2489
2668
  S: this,
2490
2669
  C: (f, a) => f(...a)
@@ -2493,11 +2672,11 @@ var InvitationsHandler = class {
2493
2672
  invitationId: invitation.invitationId,
2494
2673
  ...protocol.createIntroduction()
2495
2674
  });
2496
- log8("introduce response", {
2675
+ log10("introduce response", {
2497
2676
  ...protocol.toJSON(),
2498
2677
  response: introductionResponse
2499
2678
  }, {
2500
- F: __dxlog_file11,
2679
+ F: __dxlog_file13,
2501
2680
  L: 265,
2502
2681
  S: this,
2503
2682
  C: (f, a) => f(...a)
@@ -2515,10 +2694,10 @@ var InvitationsHandler = class {
2515
2694
  break;
2516
2695
  }
2517
2696
  }
2518
- log8("request admission", {
2697
+ log10("request admission", {
2519
2698
  ...protocol.toJSON()
2520
2699
  }, {
2521
- F: __dxlog_file11,
2700
+ F: __dxlog_file13,
2522
2701
  L: 291,
2523
2702
  S: this,
2524
2703
  C: (f, a) => f(...a)
@@ -2527,10 +2706,10 @@ var InvitationsHandler = class {
2527
2706
  const admissionResponse = await extension.rpc.InvitationHostService.admit(admissionRequest);
2528
2707
  admitted = true;
2529
2708
  const result = await protocol.accept(admissionResponse, admissionRequest);
2530
- log8("admitted by host", {
2709
+ log10("admitted by host", {
2531
2710
  ...protocol.toJSON()
2532
2711
  }, {
2533
- F: __dxlog_file11,
2712
+ F: __dxlog_file13,
2534
2713
  L: 302,
2535
2714
  S: this,
2536
2715
  C: (f, a) => f(...a)
@@ -2540,28 +2719,28 @@ var InvitationsHandler = class {
2540
2719
  ...result,
2541
2720
  state: Invitation4.State.SUCCESS
2542
2721
  });
2543
- log8.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.end({
2722
+ log10.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.end({
2544
2723
  id: traceId
2545
2724
  }), {
2546
- F: __dxlog_file11,
2725
+ F: __dxlog_file13,
2547
2726
  L: 308,
2548
2727
  S: this,
2549
2728
  C: (f, a) => f(...a)
2550
2729
  });
2551
2730
  } catch (err) {
2552
2731
  if (err instanceof TimeoutError) {
2553
- log8("timeout", {
2732
+ log10("timeout", {
2554
2733
  ...protocol.toJSON()
2555
2734
  }, {
2556
- F: __dxlog_file11,
2735
+ F: __dxlog_file13,
2557
2736
  L: 311,
2558
2737
  S: this,
2559
2738
  C: (f, a) => f(...a)
2560
2739
  });
2561
2740
  guardedState.set(extension, Invitation4.State.TIMEOUT);
2562
2741
  } else {
2563
- log8("auth failed", err, {
2564
- F: __dxlog_file11,
2742
+ log10("auth failed", err, {
2743
+ F: __dxlog_file13,
2565
2744
  L: 314,
2566
2745
  S: this,
2567
2746
  C: (f, a) => f(...a)
@@ -2569,11 +2748,11 @@ var InvitationsHandler = class {
2569
2748
  guardedState.error(extension, err);
2570
2749
  }
2571
2750
  extensionCtx.close(err);
2572
- log8.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.error({
2751
+ log10.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.error({
2573
2752
  id: traceId,
2574
2753
  error: err
2575
2754
  }), {
2576
- F: __dxlog_file11,
2755
+ F: __dxlog_file13,
2577
2756
  L: 318,
2578
2757
  S: this,
2579
2758
  C: (f, a) => f(...a)
@@ -2586,18 +2765,18 @@ var InvitationsHandler = class {
2586
2765
  return;
2587
2766
  }
2588
2767
  if (err instanceof TimeoutError) {
2589
- log8("timeout", {
2768
+ log10("timeout", {
2590
2769
  ...protocol.toJSON()
2591
2770
  }, {
2592
- F: __dxlog_file11,
2771
+ F: __dxlog_file13,
2593
2772
  L: 327,
2594
2773
  S: this,
2595
2774
  C: (f, a) => f(...a)
2596
2775
  });
2597
2776
  guardedState.set(extension, Invitation4.State.TIMEOUT);
2598
2777
  } else {
2599
- log8("auth failed", err, {
2600
- F: __dxlog_file11,
2778
+ log10("auth failed", err, {
2779
+ F: __dxlog_file13,
2601
2780
  L: 330,
2602
2781
  S: this,
2603
2782
  C: (f, a) => f(...a)
@@ -2615,7 +2794,7 @@ var InvitationsHandler = class {
2615
2794
  await ctx.dispose();
2616
2795
  } else {
2617
2796
  invariant9(invitation.swarmKey, void 0, {
2618
- F: __dxlog_file11,
2797
+ F: __dxlog_file13,
2619
2798
  L: 345,
2620
2799
  S: this,
2621
2800
  A: [
@@ -2709,16 +2888,29 @@ var InvitationsHandler = class {
2709
2888
  };
2710
2889
  }
2711
2890
  _logStateUpdate(invitation, actor, newState) {
2712
- log8("invitation state update", {
2713
- actor: actor?.constructor.name,
2714
- newState: stateToString(newState),
2715
- oldState: stateToString(invitation.state)
2716
- }, {
2717
- F: __dxlog_file11,
2718
- L: 438,
2719
- S: this,
2720
- C: (f, a) => f(...a)
2721
- });
2891
+ if (this._isNotTerminal(newState)) {
2892
+ log10("invitation state update", {
2893
+ actor: actor?.constructor.name,
2894
+ newState: stateToString(newState),
2895
+ oldState: stateToString(invitation.state)
2896
+ }, {
2897
+ F: __dxlog_file13,
2898
+ L: 439,
2899
+ S: this,
2900
+ C: (f, a) => f(...a)
2901
+ });
2902
+ } else {
2903
+ log10.info("invitation state update", {
2904
+ actor: actor?.constructor.name,
2905
+ newState: stateToString(newState),
2906
+ oldState: stateToString(invitation.state)
2907
+ }, {
2908
+ F: __dxlog_file13,
2909
+ L: 445,
2910
+ S: this,
2911
+ C: (f, a) => f(...a)
2912
+ });
2913
+ }
2722
2914
  }
2723
2915
  _isNotTerminal(currentState) {
2724
2916
  return ![
@@ -2731,17 +2923,17 @@ var InvitationsHandler = class {
2731
2923
  }
2732
2924
  async _handleGuestOtpAuth(extension, setState, authenticated, options) {
2733
2925
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2734
- log8("guest waiting for authentication code...", void 0, {
2735
- F: __dxlog_file11,
2736
- L: 462,
2926
+ log10("guest waiting for authentication code...", void 0, {
2927
+ F: __dxlog_file13,
2928
+ L: 470,
2737
2929
  S: this,
2738
2930
  C: (f, a) => f(...a)
2739
2931
  });
2740
2932
  setState(Invitation4.State.READY_FOR_AUTHENTICATION);
2741
2933
  const authCode = await authenticated.wait(options);
2742
- log8("sending authentication request", void 0, {
2743
- F: __dxlog_file11,
2744
- L: 466,
2934
+ log10("sending authentication request", void 0, {
2935
+ F: __dxlog_file13,
2936
+ L: 474,
2745
2937
  S: this,
2746
2938
  C: (f, a) => f(...a)
2747
2939
  });
@@ -2756,11 +2948,11 @@ var InvitationsHandler = class {
2756
2948
  if (attempt === MAX_OTP_ATTEMPTS) {
2757
2949
  throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
2758
2950
  } else {
2759
- log8("retrying invalid code", {
2951
+ log10("retrying invalid code", {
2760
2952
  attempt
2761
2953
  }, {
2762
- F: __dxlog_file11,
2763
- L: 477,
2954
+ F: __dxlog_file13,
2955
+ L: 485,
2764
2956
  S: this,
2765
2957
  C: (f, a) => f(...a)
2766
2958
  });
@@ -2776,9 +2968,9 @@ var InvitationsHandler = class {
2776
2968
  if (introductionResponse.challenge == null) {
2777
2969
  throw new Error("challenge missing in the introduction");
2778
2970
  }
2779
- log8("sending authentication request", void 0, {
2780
- F: __dxlog_file11,
2781
- L: 496,
2971
+ log10("sending authentication request", void 0, {
2972
+ F: __dxlog_file13,
2973
+ L: 504,
2782
2974
  S: this,
2783
2975
  C: (f, a) => f(...a)
2784
2976
  });
@@ -2898,14 +3090,14 @@ var InvitationsServiceImpl = class {
2898
3090
  };
2899
3091
 
2900
3092
  // packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts
2901
- import { createAdmissionCredentials, createCancelDelegatedSpaceInvitationCredential, createDelegatedSpaceInvitationCredential, getCredentialAssertion } from "@dxos/credentials";
3093
+ import { createCancelDelegatedSpaceInvitationCredential, createDelegatedSpaceInvitationCredential, getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
2902
3094
  import { writeMessages as writeMessages2 } from "@dxos/feed-store";
2903
3095
  import { invariant as invariant10 } from "@dxos/invariant";
2904
- import { log as log9 } from "@dxos/log";
3096
+ import { log as log11 } from "@dxos/log";
2905
3097
  import { AlreadyJoinedError as AlreadyJoinedError2, AuthorizationError, InvalidInvitationError, SpaceNotFoundError } from "@dxos/protocols";
2906
3098
  import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
2907
3099
  import { SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/halo/credentials";
2908
- var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
3100
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
2909
3101
  var SpaceInvitationProtocol = class {
2910
3102
  constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
2911
3103
  this._spaceManager = _spaceManager;
@@ -2939,89 +3131,53 @@ var SpaceInvitationProtocol = class {
2939
3131
  };
2940
3132
  }
2941
3133
  async admit(invitation, request, guestProfile) {
2942
- invariant10(this._spaceKey, void 0, {
2943
- F: __dxlog_file12,
2944
- L: 76,
3134
+ invariant10(this._spaceKey && request.space, void 0, {
3135
+ F: __dxlog_file14,
3136
+ L: 74,
2945
3137
  S: this,
2946
3138
  A: [
2947
- "this._spaceKey",
3139
+ "this._spaceKey && request.space",
2948
3140
  ""
2949
3141
  ]
2950
3142
  });
3143
+ log11("writing guest credentials", {
3144
+ host: this._signingContext.deviceKey,
3145
+ guest: request.space.deviceKey
3146
+ }, {
3147
+ F: __dxlog_file14,
3148
+ L: 75,
3149
+ S: this,
3150
+ C: (f, a) => f(...a)
3151
+ });
3152
+ const spaceMemberCredential = await this._spaceManager.admitMember({
3153
+ spaceKey: this._spaceKey,
3154
+ identityKey: request.space.identityKey,
3155
+ role: invitation.role ?? SpaceMember2.Role.ADMIN,
3156
+ profile: guestProfile,
3157
+ delegationCredentialId: invitation.delegationCredentialId
3158
+ });
2951
3159
  const space = this._spaceManager.spaces.get(this._spaceKey);
2952
- invariant10(space, void 0, {
2953
- F: __dxlog_file12,
2954
- L: 78,
3160
+ return {
3161
+ space: {
3162
+ credential: spaceMemberCredential,
3163
+ controlTimeframe: space?.inner.controlPipeline.state.timeframe
3164
+ }
3165
+ };
3166
+ }
3167
+ async delegate(invitation) {
3168
+ invariant10(this._spaceKey, void 0, {
3169
+ F: __dxlog_file14,
3170
+ L: 95,
2955
3171
  S: this,
2956
3172
  A: [
2957
- "space",
2958
- ""
2959
- ]
2960
- });
2961
- invariant10(request.space, void 0, {
2962
- F: __dxlog_file12,
2963
- L: 80,
2964
- S: this,
2965
- A: [
2966
- "request.space",
2967
- ""
2968
- ]
2969
- });
2970
- const { identityKey, deviceKey } = request.space;
2971
- if (space.inner.spaceState.getMemberRole(identityKey) !== SpaceMember2.Role.REMOVED) {
2972
- throw new AlreadyJoinedError2();
2973
- }
2974
- log9("writing guest credentials", {
2975
- host: this._signingContext.deviceKey,
2976
- guest: deviceKey
2977
- }, {
2978
- F: __dxlog_file12,
2979
- L: 87,
2980
- S: this,
2981
- C: (f, a) => f(...a)
2982
- });
2983
- const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, invitation.role ?? SpaceMember2.Role.ADMIN, space.inner.spaceState.membershipChainHeads, guestProfile, invitation.delegationCredentialId);
2984
- invariant10(credentials[0].credential, void 0, {
2985
- F: __dxlog_file12,
2986
- L: 101,
2987
- S: this,
2988
- A: [
2989
- "credentials[0].credential",
2990
- ""
2991
- ]
2992
- });
2993
- const spaceMemberCredential = credentials[0].credential.credential;
2994
- invariant10(getCredentialAssertion(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2995
- F: __dxlog_file12,
2996
- L: 103,
2997
- S: this,
2998
- A: [
2999
- "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
3000
- ""
3001
- ]
3002
- });
3003
- await writeMessages2(space.inner.controlPipeline.writer, credentials);
3004
- return {
3005
- space: {
3006
- credential: spaceMemberCredential,
3007
- controlTimeframe: space.inner.controlPipeline.state.timeframe
3008
- }
3009
- };
3010
- }
3011
- async delegate(invitation) {
3012
- invariant10(this._spaceKey, void 0, {
3013
- F: __dxlog_file12,
3014
- L: 116,
3015
- S: this,
3016
- A: [
3017
- "this._spaceKey",
3173
+ "this._spaceKey",
3018
3174
  ""
3019
3175
  ]
3020
3176
  });
3021
3177
  const space = this._spaceManager.spaces.get(this._spaceKey);
3022
3178
  invariant10(space, void 0, {
3023
- F: __dxlog_file12,
3024
- L: 118,
3179
+ F: __dxlog_file14,
3180
+ L: 97,
3025
3181
  S: this,
3026
3182
  A: [
3027
3183
  "space",
@@ -3030,8 +3186,8 @@ var SpaceInvitationProtocol = class {
3030
3186
  });
3031
3187
  if (invitation.authMethod === Invitation5.AuthMethod.KNOWN_PUBLIC_KEY) {
3032
3188
  invariant10(invitation.guestKeypair?.publicKey, void 0, {
3033
- F: __dxlog_file12,
3034
- L: 120,
3189
+ F: __dxlog_file14,
3190
+ L: 99,
3035
3191
  S: this,
3036
3192
  A: [
3037
3193
  "invitation.guestKeypair?.publicKey",
@@ -3039,12 +3195,12 @@ var SpaceInvitationProtocol = class {
3039
3195
  ]
3040
3196
  });
3041
3197
  }
3042
- log9("writing delegate space invitation", {
3198
+ log11("writing delegate space invitation", {
3043
3199
  host: this._signingContext.deviceKey,
3044
3200
  id: invitation.invitationId
3045
3201
  }, {
3046
- F: __dxlog_file12,
3047
- L: 123,
3202
+ F: __dxlog_file14,
3203
+ L: 102,
3048
3204
  S: this,
3049
3205
  C: (f, a) => f(...a)
3050
3206
  });
@@ -3058,8 +3214,8 @@ var SpaceInvitationProtocol = class {
3058
3214
  guestKey: invitation.authMethod === Invitation5.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
3059
3215
  });
3060
3216
  invariant10(credential.credential, void 0, {
3061
- F: __dxlog_file12,
3062
- L: 143,
3217
+ F: __dxlog_file14,
3218
+ L: 122,
3063
3219
  S: this,
3064
3220
  A: [
3065
3221
  "credential.credential",
@@ -3073,8 +3229,8 @@ var SpaceInvitationProtocol = class {
3073
3229
  }
3074
3230
  async cancelDelegation(invitation) {
3075
3231
  invariant10(this._spaceKey, void 0, {
3076
- F: __dxlog_file12,
3077
- L: 149,
3232
+ F: __dxlog_file14,
3233
+ L: 128,
3078
3234
  S: this,
3079
3235
  A: [
3080
3236
  "this._spaceKey",
@@ -3082,8 +3238,8 @@ var SpaceInvitationProtocol = class {
3082
3238
  ]
3083
3239
  });
3084
3240
  invariant10(invitation.type === Invitation5.Type.DELEGATED && invitation.delegationCredentialId, void 0, {
3085
- F: __dxlog_file12,
3086
- L: 150,
3241
+ F: __dxlog_file14,
3242
+ L: 129,
3087
3243
  S: this,
3088
3244
  A: [
3089
3245
  "invitation.type === Invitation.Type.DELEGATED && invitation.delegationCredentialId",
@@ -3092,27 +3248,27 @@ var SpaceInvitationProtocol = class {
3092
3248
  });
3093
3249
  const space = this._spaceManager.spaces.get(this._spaceKey);
3094
3250
  invariant10(space, void 0, {
3095
- F: __dxlog_file12,
3096
- L: 152,
3251
+ F: __dxlog_file14,
3252
+ L: 131,
3097
3253
  S: this,
3098
3254
  A: [
3099
3255
  "space",
3100
3256
  ""
3101
3257
  ]
3102
3258
  });
3103
- log9("cancelling delegated space invitation", {
3259
+ log11("cancelling delegated space invitation", {
3104
3260
  host: this._signingContext.deviceKey,
3105
3261
  id: invitation.invitationId
3106
3262
  }, {
3107
- F: __dxlog_file12,
3108
- L: 154,
3263
+ F: __dxlog_file14,
3264
+ L: 133,
3109
3265
  S: this,
3110
3266
  C: (f, a) => f(...a)
3111
3267
  });
3112
3268
  const credential = await createCancelDelegatedSpaceInvitationCredential(this._signingContext.credentialSigner, space.key, invitation.delegationCredentialId);
3113
3269
  invariant10(credential.credential, void 0, {
3114
- F: __dxlog_file12,
3115
- L: 161,
3270
+ F: __dxlog_file14,
3271
+ L: 140,
3116
3272
  S: this,
3117
3273
  A: [
3118
3274
  "credential.credential",
@@ -3150,8 +3306,8 @@ var SpaceInvitationProtocol = class {
3150
3306
  }
3151
3307
  async accept(response) {
3152
3308
  invariant10(response.space, void 0, {
3153
- F: __dxlog_file12,
3154
- L: 196,
3309
+ F: __dxlog_file14,
3310
+ L: 175,
3155
3311
  S: this,
3156
3312
  A: [
3157
3313
  "response.space",
@@ -3159,10 +3315,10 @@ var SpaceInvitationProtocol = class {
3159
3315
  ]
3160
3316
  });
3161
3317
  const { credential, controlTimeframe, dataTimeframe } = response.space;
3162
- const assertion = getCredentialAssertion(credential);
3318
+ const assertion = getCredentialAssertion2(credential);
3163
3319
  invariant10(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
3164
- F: __dxlog_file12,
3165
- L: 199,
3320
+ F: __dxlog_file14,
3321
+ L: 178,
3166
3322
  S: this,
3167
3323
  A: [
3168
3324
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -3170,8 +3326,8 @@ var SpaceInvitationProtocol = class {
3170
3326
  ]
3171
3327
  });
3172
3328
  invariant10(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
3173
- F: __dxlog_file12,
3174
- L: 200,
3329
+ F: __dxlog_file14,
3330
+ L: 179,
3175
3331
  S: this,
3176
3332
  A: [
3177
3333
  "credential.subject.id.equals(this._signingContext.identityKey)",
@@ -3195,17 +3351,17 @@ var SpaceInvitationProtocol = class {
3195
3351
  };
3196
3352
 
3197
3353
  // packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts
3198
- import { Event as Event3, PushStream, TimeoutError as TimeoutError2, Trigger as Trigger5 } from "@dxos/async";
3354
+ import { Event as Event3, PushStream, TimeoutError as TimeoutError2, Trigger as Trigger6 } from "@dxos/async";
3199
3355
  import { AuthenticatingInvitation, AUTHENTICATION_CODE_LENGTH, CancellableInvitation, INVITATION_TIMEOUT as INVITATION_TIMEOUT2 } from "@dxos/client-protocol";
3200
3356
  import { Context as Context6 } from "@dxos/context";
3201
3357
  import { generatePasscode } from "@dxos/credentials";
3202
3358
  import { hasInvitationExpired } from "@dxos/echo-pipeline";
3203
3359
  import { invariant as invariant11 } from "@dxos/invariant";
3204
3360
  import { PublicKey as PublicKey8 } from "@dxos/keys";
3205
- import { log as log10 } from "@dxos/log";
3361
+ import { log as log12 } from "@dxos/log";
3206
3362
  import { Invitation as Invitation6 } from "@dxos/protocols/proto/dxos/client/services";
3207
3363
  import { SpaceMember as SpaceMember3 } from "@dxos/protocols/proto/dxos/halo/credentials";
3208
- var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
3364
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
3209
3365
  var InvitationsManager = class {
3210
3366
  constructor(_invitationsHandler, _getHandler, _metadataStore) {
3211
3367
  this._invitationsHandler = _invitationsHandler;
@@ -3247,8 +3403,8 @@ var InvitationsManager = class {
3247
3403
  try {
3248
3404
  await this._persistIfRequired(handler, stream, invitation);
3249
3405
  } catch (err) {
3250
- log10.catch(err, void 0, {
3251
- F: __dxlog_file13,
3406
+ log12.catch(err, void 0, {
3407
+ F: __dxlog_file15,
3252
3408
  L: 82,
3253
3409
  S: this,
3254
3410
  C: (f, a) => f(...a)
@@ -3271,7 +3427,7 @@ var InvitationsManager = class {
3271
3427
  const freshInvitations = persistentInvitations.filter((invitation) => !hasInvitationExpired(invitation));
3272
3428
  const loadTasks = freshInvitations.map((persistentInvitation) => {
3273
3429
  invariant11(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
3274
- F: __dxlog_file13,
3430
+ F: __dxlog_file15,
3275
3431
  L: 103,
3276
3432
  S: this,
3277
3433
  A: [
@@ -3289,8 +3445,8 @@ var InvitationsManager = class {
3289
3445
  invitations: cInvitations.map((invitation) => invitation.get())
3290
3446
  };
3291
3447
  } catch (err) {
3292
- log10.catch(err, void 0, {
3293
- F: __dxlog_file13,
3448
+ log12.catch(err, void 0, {
3449
+ F: __dxlog_file15,
3294
3450
  L: 110,
3295
3451
  S: this,
3296
3452
  C: (f, a) => f(...a)
@@ -3321,14 +3477,14 @@ var InvitationsManager = class {
3321
3477
  return invitation;
3322
3478
  }
3323
3479
  async authenticate({ invitationId, authCode }) {
3324
- log10("authenticating...", void 0, {
3325
- F: __dxlog_file13,
3480
+ log12("authenticating...", void 0, {
3481
+ F: __dxlog_file15,
3326
3482
  L: 140,
3327
3483
  S: this,
3328
3484
  C: (f, a) => f(...a)
3329
3485
  });
3330
3486
  invariant11(invitationId, void 0, {
3331
- F: __dxlog_file13,
3487
+ F: __dxlog_file15,
3332
3488
  L: 141,
3333
3489
  S: this,
3334
3490
  A: [
@@ -3338,10 +3494,10 @@ var InvitationsManager = class {
3338
3494
  });
3339
3495
  const observable = this._acceptInvitations.get(invitationId);
3340
3496
  if (!observable) {
3341
- log10.warn("invalid invitation", {
3497
+ log12.warn("invalid invitation", {
3342
3498
  invitationId
3343
3499
  }, {
3344
- F: __dxlog_file13,
3500
+ F: __dxlog_file15,
3345
3501
  L: 144,
3346
3502
  S: this,
3347
3503
  C: (f, a) => f(...a)
@@ -3351,16 +3507,16 @@ var InvitationsManager = class {
3351
3507
  }
3352
3508
  }
3353
3509
  async cancelInvitation({ invitationId }) {
3354
- log10("cancelInvitation...", {
3510
+ log12("cancelInvitation...", {
3355
3511
  invitationId
3356
3512
  }, {
3357
- F: __dxlog_file13,
3513
+ F: __dxlog_file15,
3358
3514
  L: 151,
3359
3515
  S: this,
3360
3516
  C: (f, a) => f(...a)
3361
3517
  });
3362
3518
  invariant11(invitationId, void 0, {
3363
- F: __dxlog_file13,
3519
+ F: __dxlog_file15,
3364
3520
  L: 152,
3365
3521
  S: this,
3366
3522
  A: [
@@ -3434,12 +3590,15 @@ var InvitationsManager = class {
3434
3590
  stream.error(err);
3435
3591
  void ctx.dispose();
3436
3592
  }
3593
+ }, {
3594
+ F: __dxlog_file15,
3595
+ L: 234
3437
3596
  });
3438
3597
  ctx.onDispose(() => {
3439
- log10("complete", {
3598
+ log12("complete", {
3440
3599
  ...handler.toJSON()
3441
3600
  }, {
3442
- F: __dxlog_file13,
3601
+ F: __dxlog_file15,
3443
3602
  L: 241,
3444
3603
  S: this,
3445
3604
  C: (f, a) => f(...a)
@@ -3464,15 +3623,15 @@ var InvitationsManager = class {
3464
3623
  };
3465
3624
  }
3466
3625
  _createObservableAcceptingInvitation(handler, initialState) {
3467
- const otpEnteredTrigger = new Trigger5();
3626
+ const otpEnteredTrigger = new Trigger6();
3468
3627
  const stream = new PushStream();
3469
3628
  const ctx = new Context6({
3470
3629
  onError: (err) => {
3471
3630
  if (err instanceof TimeoutError2) {
3472
- log10("timeout", {
3631
+ log12("timeout", {
3473
3632
  ...handler.toJSON()
3474
3633
  }, {
3475
- F: __dxlog_file13,
3634
+ F: __dxlog_file15,
3476
3635
  L: 261,
3477
3636
  S: this,
3478
3637
  C: (f, a) => f(...a)
@@ -3482,8 +3641,8 @@ var InvitationsManager = class {
3482
3641
  state: Invitation6.State.TIMEOUT
3483
3642
  });
3484
3643
  } else {
3485
- log10.warn("auth failed", err, {
3486
- F: __dxlog_file13,
3644
+ log12.warn("auth failed", err, {
3645
+ F: __dxlog_file15,
3487
3646
  L: 264,
3488
3647
  S: this,
3489
3648
  C: (f, a) => f(...a)
@@ -3495,12 +3654,15 @@ var InvitationsManager = class {
3495
3654
  }
3496
3655
  void ctx.dispose();
3497
3656
  }
3657
+ }, {
3658
+ F: __dxlog_file15,
3659
+ L: 258
3498
3660
  });
3499
3661
  ctx.onDispose(() => {
3500
- log10("complete", {
3662
+ log12("complete", {
3501
3663
  ...handler.toJSON()
3502
3664
  }, {
3503
- F: __dxlog_file13,
3665
+ F: __dxlog_file15,
3504
3666
  L: 271,
3505
3667
  S: this,
3506
3668
  C: (f, a) => f(...a)
@@ -3544,8 +3706,8 @@ var InvitationsManager = class {
3544
3706
  try {
3545
3707
  await this._metadataStore.removeInvitation(invitation.invitationId);
3546
3708
  } catch (err) {
3547
- log10.catch(err, void 0, {
3548
- F: __dxlog_file13,
3709
+ log12.catch(err, void 0, {
3710
+ F: __dxlog_file15,
3549
3711
  L: 307,
3550
3712
  S: this,
3551
3713
  C: (f, a) => f(...a)
@@ -3560,33 +3722,40 @@ var InvitationsManager = class {
3560
3722
  };
3561
3723
 
3562
3724
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
3563
- import { Event as Event6, asyncTimeout as asyncTimeout2, scheduleTask as scheduleTask5, sleep as sleep2, synchronized, trackLeaks } from "@dxos/async";
3725
+ import { Event as Event6, Mutex as Mutex2, scheduleTask as scheduleTask5, sleep as sleep3, synchronized, trackLeaks } from "@dxos/async";
3564
3726
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
3565
3727
  import { Context as Context8, ContextDisposedError as ContextDisposedError3, cancelWithContext as cancelWithContext4 } from "@dxos/context";
3566
3728
  import { timed, warnAfterTimeout } from "@dxos/debug";
3567
- import { AutomergeDocumentLoaderImpl, createIdFromSpaceKey, createMappedFeedWriter } from "@dxos/echo-pipeline";
3568
- import { TYPE_PROPERTIES } from "@dxos/echo-schema";
3569
- import { failedInvariant, invariant as invariant13 } from "@dxos/invariant";
3729
+ import { createMappedFeedWriter } from "@dxos/echo-pipeline";
3730
+ import { SpaceDocVersion as SpaceDocVersion2 } from "@dxos/echo-protocol";
3731
+ import { failedInvariant } from "@dxos/invariant";
3570
3732
  import { PublicKey as PublicKey10 } from "@dxos/keys";
3571
- import { log as log12 } from "@dxos/log";
3733
+ import { log as log15 } from "@dxos/log";
3572
3734
  import { CancelledError, SystemError } from "@dxos/protocols";
3573
- import { CreateEpochRequest, SpaceState } from "@dxos/protocols/proto/dxos/client/services";
3735
+ import { SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
3574
3736
  import { AdmittedFeed as AdmittedFeed3, SpaceMember as SpaceMember4 } from "@dxos/protocols/proto/dxos/halo/credentials";
3575
- import { Timeframe as Timeframe2 } from "@dxos/timeframe";
3737
+ import { Timeframe as Timeframe3 } from "@dxos/timeframe";
3576
3738
  import { trace as trace6 } from "@dxos/tracing";
3577
- import { ComplexSet as ComplexSet5, assignDeep } from "@dxos/util";
3739
+ import { ComplexSet as ComplexSet5 } from "@dxos/util";
3578
3740
 
3579
3741
  // packages/sdk/client-services/src/packlets/spaces/automerge-space-state.ts
3580
3742
  import { Event as Event4 } from "@dxos/async";
3743
+ import { Resource as Resource2 } from "@dxos/context";
3581
3744
  import { checkCredentialType } from "@dxos/credentials";
3582
- var AutomergeSpaceState = class {
3745
+ var AutomergeSpaceState = class extends Resource2 {
3583
3746
  constructor(_onNewRoot) {
3747
+ super();
3584
3748
  this._onNewRoot = _onNewRoot;
3585
3749
  this.rootUrl = void 0;
3586
3750
  this.lastEpoch = void 0;
3587
3751
  this.onNewEpoch = new Event4();
3588
3752
  this._isProcessingRootDocs = false;
3589
3753
  }
3754
+ async _open(ctx) {
3755
+ }
3756
+ async _close(ctx) {
3757
+ this._isProcessingRootDocs = false;
3758
+ }
3590
3759
  async processCredential(credential) {
3591
3760
  if (!checkCredentialType(credential, "dxos.halo.credentials.Epoch")) {
3592
3761
  return;
@@ -3614,23 +3783,199 @@ var AutomergeSpaceState = class {
3614
3783
  }
3615
3784
  };
3616
3785
 
3786
+ // packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts
3787
+ import { convertLegacyReferences, convertLegacySpaceRootDoc, findInlineObjectOfType, migrateDocument } from "@dxos/echo-db";
3788
+ import { SpaceDocVersion } from "@dxos/echo-protocol";
3789
+ import { TYPE_PROPERTIES } from "@dxos/echo-schema";
3790
+ import { invariant as invariant12 } from "@dxos/invariant";
3791
+ import { log as log13 } from "@dxos/log";
3792
+ import { CreateEpochRequest } from "@dxos/protocols/proto/dxos/client/services";
3793
+ var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts";
3794
+ var LOAD_DOC_TIMEOUT = 1e4;
3795
+ var runEpochMigration = async (ctx, context) => {
3796
+ switch (context.migration) {
3797
+ case CreateEpochRequest.Migration.INIT_AUTOMERGE: {
3798
+ const document = context.echoHost.createDoc();
3799
+ await context.echoHost.flush();
3800
+ return {
3801
+ newRoot: document.url
3802
+ };
3803
+ }
3804
+ case CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY: {
3805
+ if (!context.currentRoot) {
3806
+ throw new Error("Space does not have an automerge root");
3807
+ }
3808
+ const rootHandle = await context.echoHost.loadDoc(ctx, context.currentRoot, {
3809
+ timeout: LOAD_DOC_TIMEOUT
3810
+ });
3811
+ const newRoot = context.echoHost.createDoc(rootHandle.docSync());
3812
+ await context.echoHost.flush();
3813
+ return {
3814
+ newRoot: newRoot.url
3815
+ };
3816
+ }
3817
+ case CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT: {
3818
+ log13.info("Fragmenting", void 0, {
3819
+ F: __dxlog_file16,
3820
+ L: 64,
3821
+ S: void 0,
3822
+ C: (f, a) => f(...a)
3823
+ });
3824
+ const currentRootUrl = context.currentRoot;
3825
+ const rootHandle = await context.echoHost.loadDoc(ctx, currentRootUrl, {
3826
+ timeout: LOAD_DOC_TIMEOUT
3827
+ });
3828
+ const objects = Object.entries(rootHandle.docSync().objects);
3829
+ const properties = findInlineObjectOfType(rootHandle.docSync(), TYPE_PROPERTIES);
3830
+ const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
3831
+ invariant12(properties, "Properties not found", {
3832
+ F: __dxlog_file16,
3833
+ L: 75,
3834
+ S: void 0,
3835
+ A: [
3836
+ "properties",
3837
+ "'Properties not found'"
3838
+ ]
3839
+ });
3840
+ const newRoot = context.echoHost.createDoc({
3841
+ ...rootHandle.docSync(),
3842
+ objects: Object.fromEntries([
3843
+ properties
3844
+ ])
3845
+ });
3846
+ invariant12(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3847
+ F: __dxlog_file16,
3848
+ L: 82,
3849
+ S: void 0,
3850
+ A: [
3851
+ "typeof newRoot.url === 'string' && newRoot.url.length > 0",
3852
+ ""
3853
+ ]
3854
+ });
3855
+ const newLinks = [];
3856
+ for (const [id, objData] of otherObjects) {
3857
+ const handle = context.echoHost.createDoc({
3858
+ version: SpaceDocVersion.CURRENT,
3859
+ access: {
3860
+ spaceKey: context.spaceKey.toHex()
3861
+ },
3862
+ objects: {
3863
+ [id]: objData
3864
+ }
3865
+ });
3866
+ newLinks.push([
3867
+ id,
3868
+ handle.url
3869
+ ]);
3870
+ }
3871
+ newRoot.change((doc) => {
3872
+ doc.links ??= {};
3873
+ for (const [id, url] of newLinks) {
3874
+ doc.links[id] = url;
3875
+ }
3876
+ });
3877
+ await context.echoHost.flush();
3878
+ return {
3879
+ newRoot: newRoot.url
3880
+ };
3881
+ }
3882
+ case CreateEpochRequest.Migration.MIGRATE_REFERENCES_TO_DXN: {
3883
+ const currentRootUrl = context.currentRoot;
3884
+ const rootHandle = await context.echoHost.loadDoc(ctx, currentRootUrl, {
3885
+ timeout: LOAD_DOC_TIMEOUT
3886
+ });
3887
+ invariant12(rootHandle.docSync(), "Root doc not found", {
3888
+ F: __dxlog_file16,
3889
+ L: 115,
3890
+ S: void 0,
3891
+ A: [
3892
+ "rootHandle.docSync()",
3893
+ "'Root doc not found'"
3894
+ ]
3895
+ });
3896
+ const newRootContent = await convertLegacySpaceRootDoc(structuredClone(rootHandle.docSync()));
3897
+ for (const [id, url] of Object.entries(newRootContent.links ?? {})) {
3898
+ try {
3899
+ const handle = await context.echoHost.loadDoc(ctx, url, {
3900
+ timeout: LOAD_DOC_TIMEOUT
3901
+ });
3902
+ invariant12(handle.docSync(), void 0, {
3903
+ F: __dxlog_file16,
3904
+ L: 122,
3905
+ S: void 0,
3906
+ A: [
3907
+ "handle.docSync()",
3908
+ ""
3909
+ ]
3910
+ });
3911
+ const newDoc = await convertLegacyReferences(structuredClone(handle.docSync()));
3912
+ const migratedDoc = migrateDocument(handle.docSync(), newDoc);
3913
+ const newHandle = context.echoHost.createDoc(migratedDoc, {
3914
+ preserveHistory: true
3915
+ });
3916
+ newRootContent.links[id] = newHandle.url;
3917
+ } catch (err) {
3918
+ log13.warn("Failed to migrate reference", {
3919
+ id,
3920
+ url,
3921
+ error: err
3922
+ }, {
3923
+ F: __dxlog_file16,
3924
+ L: 128,
3925
+ S: void 0,
3926
+ C: (f, a) => f(...a)
3927
+ });
3928
+ delete newRootContent.links[id];
3929
+ }
3930
+ }
3931
+ const migratedRoot = migrateDocument(rootHandle.docSync(), newRootContent);
3932
+ const newRoot = context.echoHost.createDoc(migratedRoot, {
3933
+ preserveHistory: true
3934
+ });
3935
+ await context.echoHost.flush();
3936
+ return {
3937
+ newRoot: newRoot.url
3938
+ };
3939
+ }
3940
+ case CreateEpochRequest.Migration.REPLACE_AUTOMERGE_ROOT: {
3941
+ invariant12(context.newAutomergeRoot, void 0, {
3942
+ F: __dxlog_file16,
3943
+ L: 143,
3944
+ S: void 0,
3945
+ A: [
3946
+ "context.newAutomergeRoot",
3947
+ ""
3948
+ ]
3949
+ });
3950
+ await context.echoHost.flush();
3951
+ return {
3952
+ newRoot: context.newAutomergeRoot
3953
+ };
3954
+ }
3955
+ }
3956
+ return {};
3957
+ };
3958
+
3617
3959
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
3618
- import { DeferredTask, Event as Event5, scheduleTask as scheduleTask4, sleep, TimeoutError as TimeoutError3, Trigger as Trigger6 } from "@dxos/async";
3960
+ import { DeferredTask, Event as Event5, scheduleTask as scheduleTask4, sleep as sleep2, TimeoutError as TimeoutError3, Trigger as Trigger7 } from "@dxos/async";
3619
3961
  import { Context as Context7, rejectOnDispose } from "@dxos/context";
3620
- import { invariant as invariant12 } from "@dxos/invariant";
3962
+ import { invariant as invariant13 } from "@dxos/invariant";
3621
3963
  import { PublicKey as PublicKey9 } from "@dxos/keys";
3622
- import { log as log11 } from "@dxos/log";
3964
+ import { log as log14 } from "@dxos/log";
3623
3965
  import { schema as schema4 } from "@dxos/protocols";
3624
3966
  import { RpcExtension as RpcExtension3 } from "@dxos/teleport";
3625
3967
  import { ComplexMap as ComplexMap2, ComplexSet as ComplexSet4, entry } from "@dxos/util";
3626
- var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
3968
+ var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
3627
3969
  var DEFAULT_RETRY_TIMEOUT = 1e3;
3628
3970
  var DEFAULT_SUCCESS_DELAY = 1e3;
3629
3971
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
3630
3972
  var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
3631
3973
  var NotarizationPlugin = class {
3632
3974
  constructor() {
3633
- this._ctx = new Context7();
3975
+ this._ctx = new Context7(void 0, {
3976
+ F: __dxlog_file17,
3977
+ L: 62
3978
+ });
3634
3979
  this._extensionOpened = new Event5();
3635
3980
  this._extensions = /* @__PURE__ */ new Set();
3636
3981
  this._processedCredentials = new ComplexSet4(PublicKey9.hash);
@@ -3648,16 +3993,16 @@ var NotarizationPlugin = class {
3648
3993
  * Request credentials to be notarized.
3649
3994
  */
3650
3995
  async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
3651
- log11("notarize", {
3996
+ log14("notarize", {
3652
3997
  credentials
3653
3998
  }, {
3654
- F: __dxlog_file14,
3999
+ F: __dxlog_file17,
3655
4000
  L: 90,
3656
4001
  S: this,
3657
4002
  C: (f, a) => f(...a)
3658
4003
  });
3659
- invariant12(credentials.every((credential) => credential.id), "Credentials must have an id", {
3660
- F: __dxlog_file14,
4004
+ invariant13(credentials.every((credential) => credential.id), "Credentials must have an id", {
4005
+ F: __dxlog_file17,
3661
4006
  L: 91,
3662
4007
  S: this,
3663
4008
  A: [
@@ -3665,13 +4010,13 @@ var NotarizationPlugin = class {
3665
4010
  "'Credentials must have an id'"
3666
4011
  ]
3667
4012
  });
3668
- const errors = new Trigger6();
4013
+ const errors = new Trigger7();
3669
4014
  const ctx = this._ctx.derive({
3670
4015
  onError: (err) => {
3671
- log11.warn("Notarization error", {
4016
+ log14.warn("Notarization error", {
3672
4017
  err
3673
4018
  }, {
3674
- F: __dxlog_file14,
4019
+ F: __dxlog_file17,
3675
4020
  L: 99,
3676
4021
  S: this,
3677
4022
  C: (f, a) => f(...a)
@@ -3683,11 +4028,11 @@ var NotarizationPlugin = class {
3683
4028
  opCtx?.onDispose(() => ctx.dispose());
3684
4029
  if (timeout !== 0) {
3685
4030
  scheduleTask4(ctx, () => {
3686
- log11.warn("Notarization timeout", {
4031
+ log14.warn("Notarization timeout", {
3687
4032
  timeout,
3688
4033
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
3689
4034
  }, {
3690
- F: __dxlog_file14,
4035
+ F: __dxlog_file17,
3691
4036
  L: 111,
3692
4037
  S: this,
3693
4038
  C: (f, a) => f(...a)
@@ -3707,10 +4052,10 @@ var NotarizationPlugin = class {
3707
4052
  ...this._extensions
3708
4053
  ].find((peer2) => !peersTried.has(peer2));
3709
4054
  if (!peer) {
3710
- log11.info("Exhausted all peers to notarize with", {
4055
+ log14.info("Exhausted all peers to notarize with", {
3711
4056
  retryIn: retryTimeout
3712
4057
  }, {
3713
- F: __dxlog_file14,
4058
+ F: __dxlog_file17,
3714
4059
  L: 136,
3715
4060
  S: this,
3716
4061
  C: (f, a) => f(...a)
@@ -3720,11 +4065,11 @@ var NotarizationPlugin = class {
3720
4065
  return;
3721
4066
  }
3722
4067
  peersTried.add(peer);
3723
- log11("try notarizing", {
4068
+ log14("try notarizing", {
3724
4069
  peer: peer.localPeerId,
3725
4070
  credentialId: credentials.map((credential) => credential.id)
3726
4071
  }, {
3727
- F: __dxlog_file14,
4072
+ F: __dxlog_file17,
3728
4073
  L: 143,
3729
4074
  S: this,
3730
4075
  C: (f, a) => f(...a)
@@ -3732,17 +4077,17 @@ var NotarizationPlugin = class {
3732
4077
  await peer.rpc.NotarizationService.notarize({
3733
4078
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
3734
4079
  });
3735
- log11("success", void 0, {
3736
- F: __dxlog_file14,
4080
+ log14("success", void 0, {
4081
+ F: __dxlog_file17,
3737
4082
  L: 147,
3738
4083
  S: this,
3739
4084
  C: (f, a) => f(...a)
3740
4085
  });
3741
- await sleep(successDelay);
4086
+ await sleep2(successDelay);
3742
4087
  } catch (err) {
3743
4088
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
3744
- log11.info("error notarizing (recoverable)", err, {
3745
- F: __dxlog_file14,
4089
+ log14.info("error notarizing (recoverable)", err, {
4090
+ F: __dxlog_file17,
3746
4091
  L: 151,
3747
4092
  S: this,
3748
4093
  C: (f, a) => f(...a)
@@ -3759,8 +4104,8 @@ var NotarizationPlugin = class {
3759
4104
  allNotarized,
3760
4105
  errors.wait()
3761
4106
  ]);
3762
- log11("done", void 0, {
3763
- F: __dxlog_file14,
4107
+ log14("done", void 0, {
4108
+ F: __dxlog_file17,
3764
4109
  L: 162,
3765
4110
  S: this,
3766
4111
  C: (f, a) => f(...a)
@@ -3781,8 +4126,8 @@ var NotarizationPlugin = class {
3781
4126
  this._processCredentialsTriggers.delete(credential.id);
3782
4127
  }
3783
4128
  setWriter(writer) {
3784
- invariant12(!this._writer, "Writer already set.", {
3785
- F: __dxlog_file14,
4129
+ invariant13(!this._writer, "Writer already set.", {
4130
+ F: __dxlog_file17,
3786
4131
  L: 181,
3787
4132
  S: this,
3788
4133
  A: [
@@ -3796,7 +4141,7 @@ var NotarizationPlugin = class {
3796
4141
  if (this._processedCredentials.has(id)) {
3797
4142
  return;
3798
4143
  }
3799
- await entry(this._processCredentialsTriggers, id).orInsert(new Trigger6()).value.wait();
4144
+ await entry(this._processCredentialsTriggers, id).orInsert(new Trigger7()).value.wait();
3800
4145
  }
3801
4146
  /**
3802
4147
  * Requests from other peers to notarize credentials.
@@ -3806,8 +4151,8 @@ var NotarizationPlugin = class {
3806
4151
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
3807
4152
  }
3808
4153
  for (const credential of request.credentials ?? []) {
3809
- invariant12(credential.id, "Credential must have an id", {
3810
- F: __dxlog_file14,
4154
+ invariant13(credential.id, "Credential must have an id", {
4155
+ F: __dxlog_file17,
3811
4156
  L: 200,
3812
4157
  S: this,
3813
4158
  A: [
@@ -3824,10 +4169,10 @@ var NotarizationPlugin = class {
3824
4169
  createExtension() {
3825
4170
  const extension = new NotarizationTeleportExtension({
3826
4171
  onOpen: async () => {
3827
- log11("extension opened", {
4172
+ log14("extension opened", {
3828
4173
  peer: extension.localPeerId
3829
4174
  }, {
3830
- F: __dxlog_file14,
4175
+ F: __dxlog_file17,
3831
4176
  L: 211,
3832
4177
  S: this,
3833
4178
  C: (f, a) => f(...a)
@@ -3836,10 +4181,10 @@ var NotarizationPlugin = class {
3836
4181
  this._extensionOpened.emit();
3837
4182
  },
3838
4183
  onClose: async () => {
3839
- log11("extension closed", {
4184
+ log14("extension closed", {
3840
4185
  peer: extension.localPeerId
3841
4186
  }, {
3842
- F: __dxlog_file14,
4187
+ F: __dxlog_file17,
3843
4188
  L: 216,
3844
4189
  S: this,
3845
4190
  C: (f, a) => f(...a)
@@ -3893,15 +4238,83 @@ function _ts_decorate4(decorators, target, key, desc) {
3893
4238
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3894
4239
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3895
4240
  }
3896
- var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
4241
+ function _using_ctx() {
4242
+ var _disposeSuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed) {
4243
+ var err = new Error();
4244
+ err.name = "SuppressedError";
4245
+ err.suppressed = suppressed;
4246
+ err.error = error;
4247
+ return err;
4248
+ }, empty = {}, stack = [];
4249
+ function using(isAwait, value) {
4250
+ if (value != null) {
4251
+ if (Object(value) !== value) {
4252
+ throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
4253
+ }
4254
+ if (isAwait) {
4255
+ var dispose = value[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")];
4256
+ }
4257
+ if (dispose == null) {
4258
+ dispose = value[Symbol.dispose || Symbol.for("Symbol.dispose")];
4259
+ }
4260
+ if (typeof dispose !== "function") {
4261
+ throw new TypeError(`Property [Symbol.dispose] is not a function.`);
4262
+ }
4263
+ stack.push({
4264
+ v: value,
4265
+ d: dispose,
4266
+ a: isAwait
4267
+ });
4268
+ } else if (isAwait) {
4269
+ stack.push({
4270
+ d: value,
4271
+ a: isAwait
4272
+ });
4273
+ }
4274
+ return value;
4275
+ }
4276
+ return {
4277
+ e: empty,
4278
+ u: using.bind(null, false),
4279
+ a: using.bind(null, true),
4280
+ d: function() {
4281
+ var error = this.e;
4282
+ function next() {
4283
+ while (resource = stack.pop()) {
4284
+ try {
4285
+ var resource, disposalResult = resource.d && resource.d.call(resource.v);
4286
+ if (resource.a) {
4287
+ return Promise.resolve(disposalResult).then(next, err);
4288
+ }
4289
+ } catch (e) {
4290
+ return err(e);
4291
+ }
4292
+ }
4293
+ if (error !== empty)
4294
+ throw error;
4295
+ }
4296
+ function err(e) {
4297
+ error = error !== empty ? new _disposeSuppressedError(error, e) : e;
4298
+ return next();
4299
+ }
4300
+ return next();
4301
+ }
4302
+ };
4303
+ }
4304
+ var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
3897
4305
  var DataSpace = class {
3898
4306
  constructor(params) {
3899
- this._ctx = new Context8();
4307
+ this._ctx = new Context8(void 0, {
4308
+ F: __dxlog_file18,
4309
+ L: 84
4310
+ });
3900
4311
  this._notarizationPlugin = new NotarizationPlugin();
3901
4312
  this._cache = void 0;
3902
4313
  // TODO(dmaretskyi): Move into Space?
3903
4314
  this._automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
3904
- this._state = SpaceState.CLOSED;
4315
+ this._epochProcessingMutex = new Mutex2();
4316
+ this._state = SpaceState2.CLOSED;
4317
+ this._databaseRoot = null;
3905
4318
  /**
3906
4319
  * Error for _state === SpaceState.ERROR.
3907
4320
  */
@@ -3925,11 +4338,11 @@ var DataSpace = class {
3925
4338
  });
3926
4339
  this._cache = params.cache;
3927
4340
  this._state = params.initialState;
3928
- log12("new state", {
3929
- state: SpaceState[this._state]
4341
+ log15("new state", {
4342
+ state: SpaceState2[this._state]
3930
4343
  }, {
3931
- F: __dxlog_file15,
3932
- L: 142,
4344
+ F: __dxlog_file18,
4345
+ L: 146,
3933
4346
  S: this,
3934
4347
  C: (f, a) => f(...a)
3935
4348
  });
@@ -3962,6 +4375,9 @@ var DataSpace = class {
3962
4375
  get automergeSpaceState() {
3963
4376
  return this._automergeSpaceState;
3964
4377
  }
4378
+ get databaseRoot() {
4379
+ return this._databaseRoot;
4380
+ }
3965
4381
  get _automergeInfo() {
3966
4382
  return {
3967
4383
  rootUrl: this._automergeSpaceState.rootUrl,
@@ -3969,20 +4385,27 @@ var DataSpace = class {
3969
4385
  };
3970
4386
  }
3971
4387
  async open() {
3972
- await this._open();
4388
+ if (this._state === SpaceState2.CLOSED) {
4389
+ await this._open();
4390
+ }
3973
4391
  }
3974
4392
  async _open() {
4393
+ await this._presence.open();
3975
4394
  await this._gossip.open();
3976
4395
  await this._notarizationPlugin.open();
3977
4396
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
4397
+ await this._automergeSpaceState.open();
3978
4398
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
3979
- await this._inner.open(new Context8());
3980
- this._state = SpaceState.CONTROL_ONLY;
3981
- log12("new state", {
3982
- state: SpaceState[this._state]
4399
+ await this._inner.open(new Context8(void 0, {
4400
+ F: __dxlog_file18,
4401
+ L: 215
4402
+ }));
4403
+ this._state = SpaceState2.CONTROL_ONLY;
4404
+ log15("new state", {
4405
+ state: SpaceState2[this._state]
3983
4406
  }, {
3984
- F: __dxlog_file15,
3985
- L: 205,
4407
+ F: __dxlog_file18,
4408
+ L: 217,
3986
4409
  S: this,
3987
4410
  C: (f, a) => f(...a)
3988
4411
  });
@@ -3995,23 +4418,27 @@ var DataSpace = class {
3995
4418
  }
3996
4419
  async _close() {
3997
4420
  await this._callbacks.beforeClose?.();
3998
- this._state = SpaceState.CLOSED;
3999
- log12("new state", {
4000
- state: SpaceState[this._state]
4421
+ this._state = SpaceState2.CLOSED;
4422
+ log15("new state", {
4423
+ state: SpaceState2[this._state]
4001
4424
  }, {
4002
- F: __dxlog_file15,
4003
- L: 219,
4425
+ F: __dxlog_file18,
4426
+ L: 231,
4004
4427
  S: this,
4005
4428
  C: (f, a) => f(...a)
4006
4429
  });
4007
4430
  await this._ctx.dispose();
4008
- this._ctx = new Context8();
4431
+ this._ctx = new Context8(void 0, {
4432
+ F: __dxlog_file18,
4433
+ L: 233
4434
+ });
4009
4435
  await this.authVerifier.close();
4010
4436
  await this._inner.close();
4011
4437
  await this._inner.spaceState.removeCredentialProcessor(this._automergeSpaceState);
4438
+ await this._automergeSpaceState.close();
4012
4439
  await this._inner.spaceState.removeCredentialProcessor(this._notarizationPlugin);
4013
4440
  await this._notarizationPlugin.close();
4014
- await this._presence.destroy();
4441
+ await this._presence.close();
4015
4442
  await this._gossip.close();
4016
4443
  }
4017
4444
  async postMessage(channel, message) {
@@ -4030,26 +4457,26 @@ var DataSpace = class {
4030
4457
  await this.initializeDataPipeline();
4031
4458
  } catch (err) {
4032
4459
  if (err instanceof CancelledError || err instanceof ContextDisposedError3) {
4033
- log12("data pipeline initialization cancelled", err, {
4034
- F: __dxlog_file15,
4035
- L: 252,
4460
+ log15("data pipeline initialization cancelled", err, {
4461
+ F: __dxlog_file18,
4462
+ L: 265,
4036
4463
  S: this,
4037
4464
  C: (f, a) => f(...a)
4038
4465
  });
4039
4466
  return;
4040
4467
  }
4041
- log12.error("Error initializing data pipeline", err, {
4042
- F: __dxlog_file15,
4043
- L: 256,
4468
+ log15.error("Error initializing data pipeline", err, {
4469
+ F: __dxlog_file18,
4470
+ L: 269,
4044
4471
  S: this,
4045
4472
  C: (f, a) => f(...a)
4046
4473
  });
4047
- this._state = SpaceState.ERROR;
4048
- log12("new state", {
4049
- state: SpaceState[this._state]
4474
+ this._state = SpaceState2.ERROR;
4475
+ log15("new state", {
4476
+ state: SpaceState2[this._state]
4050
4477
  }, {
4051
- F: __dxlog_file15,
4052
- L: 258,
4478
+ F: __dxlog_file18,
4479
+ L: 271,
4053
4480
  S: this,
4054
4481
  C: (f, a) => f(...a)
4055
4482
  });
@@ -4061,35 +4488,32 @@ var DataSpace = class {
4061
4488
  });
4062
4489
  }
4063
4490
  async initializeDataPipeline() {
4064
- if (this._state !== SpaceState.CONTROL_ONLY) {
4491
+ if (this._state !== SpaceState2.CONTROL_ONLY) {
4065
4492
  throw new SystemError("Invalid operation");
4066
4493
  }
4067
- this._state = SpaceState.INITIALIZING;
4068
- log12("new state", {
4069
- state: SpaceState[this._state]
4494
+ this._state = SpaceState2.INITIALIZING;
4495
+ log15("new state", {
4496
+ state: SpaceState2[this._state]
4070
4497
  }, {
4071
- F: __dxlog_file15,
4072
- L: 274,
4498
+ F: __dxlog_file18,
4499
+ L: 287,
4073
4500
  S: this,
4074
4501
  C: (f, a) => f(...a)
4075
4502
  });
4076
4503
  await this._initializeAndReadControlPipeline();
4077
- await sleep2(1);
4504
+ await sleep3(1);
4505
+ const ready = this.stateUpdate.waitForCondition(() => this._state === SpaceState2.READY);
4078
4506
  this._automergeSpaceState.startProcessingRootDocs();
4079
- await cancelWithContext4(this._ctx, this.automergeSpaceState.ensureEpochInitialized());
4080
- log12("data pipeline ready", void 0, {
4081
- F: __dxlog_file15,
4082
- L: 286,
4083
- S: this,
4084
- C: (f, a) => f(...a)
4085
- });
4507
+ await ready;
4508
+ }
4509
+ async _enterReadyState() {
4086
4510
  await this._callbacks.beforeReady?.();
4087
- this._state = SpaceState.READY;
4088
- log12("new state", {
4089
- state: SpaceState[this._state]
4511
+ this._state = SpaceState2.READY;
4512
+ log15("new state", {
4513
+ state: SpaceState2[this._state]
4090
4514
  }, {
4091
- F: __dxlog_file15,
4092
- L: 290,
4515
+ F: __dxlog_file18,
4516
+ L: 306,
4093
4517
  S: this,
4094
4518
  C: (f, a) => f(...a)
4095
4519
  });
@@ -4103,9 +4527,9 @@ var DataSpace = class {
4103
4527
  });
4104
4528
  this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
4105
4529
  await this._createWritableFeeds();
4106
- log12("writable feeds created", void 0, {
4107
- F: __dxlog_file15,
4108
- L: 306,
4530
+ log15("writable feeds created", void 0, {
4531
+ F: __dxlog_file18,
4532
+ L: 322,
4109
4533
  S: this,
4110
4534
  C: (f, a) => f(...a)
4111
4535
  });
@@ -4163,57 +4587,66 @@ var DataSpace = class {
4163
4587
  }
4164
4588
  }
4165
4589
  _onNewAutomergeRoot(rootUrl) {
4166
- log12("loading automerge root doc for space", {
4590
+ log15("loading automerge root doc for space", {
4167
4591
  space: this.key,
4168
4592
  rootUrl
4169
4593
  }, {
4170
- F: __dxlog_file15,
4171
- L: 372,
4594
+ F: __dxlog_file18,
4595
+ L: 388,
4172
4596
  S: this,
4173
4597
  C: (f, a) => f(...a)
4174
4598
  });
4175
- this._echoHost.replicateDocument(rootUrl);
4176
4599
  const handle = this._echoHost.automergeRepo.find(rootUrl);
4177
4600
  queueMicrotask(async () => {
4178
4601
  try {
4179
- await warnAfterTimeout(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
4180
- await cancelWithContext4(this._ctx, handle.whenReady());
4181
- });
4182
- if (this._ctx.disposed) {
4183
- return;
4184
- }
4185
- const doc = handle.docSync() ?? failedInvariant();
4186
- if (!doc.access?.spaceKey) {
4187
- handle.change((doc2) => {
4188
- doc2.access = {
4189
- spaceKey: this.key.toHex()
4190
- };
4191
- });
4192
- }
4193
- if (!this._echoHost.roots.has(handle.documentId)) {
4194
- await this._echoHost.openSpaceRoot(handle.url);
4195
- } else {
4196
- log12.warn("echo database root already exists", {
4197
- space: this.key,
4198
- rootUrl
4199
- }, {
4200
- F: __dxlog_file15,
4201
- L: 399,
4202
- S: this,
4203
- C: (f, a) => f(...a)
4602
+ try {
4603
+ var _usingCtx = _using_ctx();
4604
+ await warnAfterTimeout(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
4605
+ await cancelWithContext4(this._ctx, handle.whenReady());
4204
4606
  });
4607
+ if (this._ctx.disposed) {
4608
+ return;
4609
+ }
4610
+ const _guard = (
4611
+ // Ensure only one root is processed at a time.
4612
+ _usingCtx.u(await this._epochProcessingMutex.acquire())
4613
+ );
4614
+ const doc = handle.docSync() ?? failedInvariant();
4615
+ if (!doc.access?.spaceKey) {
4616
+ handle.change((doc2) => {
4617
+ doc2.access = {
4618
+ spaceKey: this.key.toHex()
4619
+ };
4620
+ });
4621
+ }
4622
+ const root = await this._echoHost.openSpaceRoot(handle.url);
4623
+ this._databaseRoot = root;
4624
+ if (root.getVersion() !== SpaceDocVersion2.CURRENT) {
4625
+ if (this._state !== SpaceState2.REQUIRES_MIGRATION) {
4626
+ this._state = SpaceState2.REQUIRES_MIGRATION;
4627
+ this.stateUpdate.emit();
4628
+ }
4629
+ } else {
4630
+ if (this._state !== SpaceState2.READY) {
4631
+ await this._enterReadyState();
4632
+ }
4633
+ }
4634
+ } catch (_) {
4635
+ _usingCtx.e = _;
4636
+ } finally {
4637
+ _usingCtx.d();
4205
4638
  }
4206
4639
  } catch (err) {
4207
4640
  if (err instanceof ContextDisposedError3) {
4208
4641
  return;
4209
4642
  }
4210
- log12.warn("error loading automerge root doc", {
4643
+ log15.warn("error loading automerge root doc", {
4211
4644
  space: this.key,
4212
4645
  rootUrl,
4213
4646
  err
4214
4647
  }, {
4215
- F: __dxlog_file15,
4216
- L: 405,
4648
+ F: __dxlog_file18,
4649
+ L: 433,
4217
4650
  S: this,
4218
4651
  C: (f, a) => f(...a)
4219
4652
  });
@@ -4236,155 +4669,70 @@ var DataSpace = class {
4236
4669
  });
4237
4670
  }
4238
4671
  async createEpoch(options) {
4239
- let epoch;
4240
- switch (options?.migration) {
4241
- case void 0:
4242
- case CreateEpochRequest.Migration.NONE:
4243
- {
4244
- epoch = {
4245
- previousId: this._automergeSpaceState.lastEpoch?.id,
4246
- number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
4247
- timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe2(),
4248
- automergeRoot: this._automergeSpaceState.lastEpoch?.subject.assertion?.automergeRoot
4249
- };
4250
- }
4251
- break;
4252
- case CreateEpochRequest.Migration.INIT_AUTOMERGE:
4253
- {
4254
- const document = this._echoHost.automergeRepo.create();
4255
- epoch = {
4256
- previousId: this._automergeSpaceState.lastEpoch?.id,
4257
- number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
4258
- timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe2(),
4259
- automergeRoot: document.url
4260
- };
4261
- }
4262
- break;
4263
- case CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY:
4264
- {
4265
- const currentRootUrl = this._automergeSpaceState.rootUrl;
4266
- const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
4267
- await cancelWithContext4(this._ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
4268
- const newRoot = this._echoHost.automergeRepo.create(rootHandle.docSync());
4269
- invariant13(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
4270
- F: __dxlog_file15,
4271
- L: 455,
4272
- S: this,
4273
- A: [
4274
- "typeof newRoot.url === 'string' && newRoot.url.length > 0",
4275
- ""
4276
- ]
4277
- });
4278
- epoch = {
4279
- previousId: this._automergeSpaceState.lastEpoch?.id,
4280
- number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
4281
- timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe2(),
4282
- automergeRoot: newRoot.url
4283
- };
4284
- }
4285
- break;
4286
- case CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT:
4287
- {
4288
- log12.info("Fragmenting", void 0, {
4289
- F: __dxlog_file15,
4290
- L: 467,
4291
- S: this,
4292
- C: (f, a) => f(...a)
4293
- });
4294
- const currentRootUrl = this._automergeSpaceState.rootUrl;
4295
- const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
4296
- await cancelWithContext4(this._ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
4297
- const objects = Object.entries(rootHandle.docSync().objects);
4298
- const properties = findPropertiesObject(rootHandle.docSync());
4299
- const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
4300
- invariant13(properties, "Properties not found", {
4301
- F: __dxlog_file15,
4302
- L: 477,
4303
- S: this,
4304
- A: [
4305
- "properties",
4306
- "'Properties not found'"
4307
- ]
4308
- });
4309
- const newSpaceDoc = {
4310
- ...rootHandle.docSync(),
4311
- objects: Object.fromEntries([
4312
- properties
4313
- ])
4314
- };
4315
- const newRoot = this._echoHost.automergeRepo.create(newSpaceDoc);
4316
- invariant13(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
4317
- F: __dxlog_file15,
4318
- L: 482,
4319
- S: this,
4320
- A: [
4321
- "typeof newRoot.url === 'string' && newRoot.url.length > 0",
4322
- ""
4323
- ]
4324
- });
4325
- const docLoader = new AutomergeDocumentLoaderImpl(await createIdFromSpaceKey(this.key), this._echoHost.automergeRepo, this.key);
4326
- await docLoader.loadSpaceRootDocHandle(this._ctx, {
4327
- rootUrl: newRoot.url
4328
- });
4329
- otherObjects.forEach(([key, value]) => {
4330
- const handle = docLoader.createDocumentForObject(key);
4331
- handle.change((doc) => {
4332
- assignDeep(doc, [
4333
- "objects",
4334
- key
4335
- ], value);
4336
- });
4337
- });
4338
- epoch = {
4339
- previousId: this._automergeSpaceState.lastEpoch?.id,
4340
- number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
4341
- timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe2(),
4342
- automergeRoot: newRoot.url
4343
- };
4344
- }
4345
- break;
4346
- }
4347
- if (!epoch) {
4348
- return;
4672
+ const ctx = this._ctx.derive();
4673
+ if (!options?.migration) {
4674
+ return null;
4349
4675
  }
4676
+ const { newRoot } = await runEpochMigration(ctx, {
4677
+ echoHost: this._echoHost,
4678
+ spaceId: this.id,
4679
+ spaceKey: this.key,
4680
+ migration: options.migration,
4681
+ currentRoot: this._automergeSpaceState.rootUrl ?? null,
4682
+ newAutomergeRoot: options.newAutomergeRoot
4683
+ });
4684
+ const epoch = {
4685
+ previousId: this._automergeSpaceState.lastEpoch?.id,
4686
+ number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
4687
+ timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe3(),
4688
+ automergeRoot: newRoot ?? this._automergeSpaceState.rootUrl
4689
+ };
4690
+ const credential = await this._signingContext.credentialSigner.createCredential({
4691
+ subject: this.key,
4692
+ assertion: {
4693
+ "@type": "dxos.halo.credentials.Epoch",
4694
+ ...epoch
4695
+ }
4696
+ });
4350
4697
  const receipt = await this.inner.controlPipeline.writer.write({
4351
4698
  credential: {
4352
- credential: await this._signingContext.credentialSigner.createCredential({
4353
- subject: this.key,
4354
- assertion: {
4355
- "@type": "dxos.halo.credentials.Epoch",
4356
- ...epoch
4357
- }
4358
- })
4699
+ credential
4359
4700
  }
4360
4701
  });
4361
- await this.inner.controlPipeline.state.waitUntilTimeframe(new Timeframe2([
4702
+ await this.inner.controlPipeline.state.waitUntilTimeframe(new Timeframe3([
4362
4703
  [
4363
4704
  receipt.feedKey,
4364
4705
  receipt.seq
4365
4706
  ]
4366
4707
  ]));
4708
+ await this._echoHost.updateIndexes();
4709
+ return credential;
4367
4710
  }
4368
4711
  async activate() {
4369
- if (this._state !== SpaceState.INACTIVE) {
4712
+ if (![
4713
+ SpaceState2.CLOSED,
4714
+ SpaceState2.INACTIVE
4715
+ ].includes(this._state)) {
4370
4716
  return;
4371
4717
  }
4372
- await this._metadataStore.setSpaceState(this.key, SpaceState.ACTIVE);
4718
+ await this._metadataStore.setSpaceState(this.key, SpaceState2.ACTIVE);
4373
4719
  await this._open();
4374
4720
  this.initializeDataPipelineAsync();
4375
4721
  }
4376
4722
  async deactivate() {
4377
- if (this._state === SpaceState.INACTIVE) {
4723
+ if (this._state === SpaceState2.INACTIVE) {
4378
4724
  return;
4379
4725
  }
4380
- await this._metadataStore.setSpaceState(this.key, SpaceState.INACTIVE);
4381
- await this._close();
4382
- this._state = SpaceState.INACTIVE;
4383
- log12("new state", {
4384
- state: SpaceState[this._state]
4726
+ await this._metadataStore.setSpaceState(this.key, SpaceState2.INACTIVE);
4727
+ if (this._state !== SpaceState2.CLOSED) {
4728
+ await this._close();
4729
+ }
4730
+ this._state = SpaceState2.INACTIVE;
4731
+ log15("new state", {
4732
+ state: SpaceState2[this._state]
4385
4733
  }, {
4386
- F: __dxlog_file15,
4387
- L: 552,
4734
+ F: __dxlog_file18,
4735
+ L: 514,
4388
4736
  S: this,
4389
4737
  C: (f, a) => f(...a)
4390
4738
  });
@@ -4402,7 +4750,7 @@ _ts_decorate4([
4402
4750
  ], DataSpace.prototype, "key", null);
4403
4751
  _ts_decorate4([
4404
4752
  trace6.info({
4405
- enum: SpaceState
4753
+ enum: SpaceState2
4406
4754
  })
4407
4755
  ], DataSpace.prototype, "state", null);
4408
4756
  _ts_decorate4([
@@ -4439,39 +4787,33 @@ DataSpace = _ts_decorate4([
4439
4787
  trackLeaks("open", "close"),
4440
4788
  trace6.resource()
4441
4789
  ], DataSpace);
4442
- var findPropertiesObject = (spaceDoc) => {
4443
- for (const id in spaceDoc.objects ?? {}) {
4444
- const obj = spaceDoc.objects[id];
4445
- if (obj.system.type?.itemId === TYPE_PROPERTIES) {
4446
- return [
4447
- id,
4448
- obj
4449
- ];
4450
- }
4451
- }
4452
- return void 0;
4453
- };
4454
4790
 
4455
4791
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
4456
4792
  import { Event as Event7, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
4457
- import { cancelWithContext as cancelWithContext5, Context as Context9 } from "@dxos/context";
4458
- import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
4793
+ import { PropertiesType } from "@dxos/client-protocol";
4794
+ import { Context as Context9, cancelWithContext as cancelWithContext5 } from "@dxos/context";
4795
+ import { getCredentialAssertion as getCredentialAssertion3, createAdmissionCredentials } from "@dxos/credentials";
4796
+ import { convertLegacyReferences as convertLegacyReferences2, findInlineObjectOfType as findInlineObjectOfType2 } from "@dxos/echo-db";
4459
4797
  import { AuthStatus } from "@dxos/echo-pipeline";
4798
+ import { CredentialServerExtension } from "@dxos/echo-pipeline";
4799
+ import { LEGACY_TYPE_PROPERTIES, SpaceDocVersion as SpaceDocVersion3, encodeReference } from "@dxos/echo-protocol";
4800
+ import { TYPE_PROPERTIES as TYPE_PROPERTIES2, generateEchoId, getTypeReference } from "@dxos/echo-schema";
4801
+ import { writeMessages as writeMessages3 } from "@dxos/feed-store";
4460
4802
  import { invariant as invariant14 } from "@dxos/invariant";
4461
4803
  import { PublicKey as PublicKey11 } from "@dxos/keys";
4462
- import { log as log13 } from "@dxos/log";
4463
- import { trace as Trace2 } from "@dxos/protocols";
4464
- import { Invitation as Invitation7, SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
4804
+ import { log as log16 } from "@dxos/log";
4805
+ import { trace as Trace2, AlreadyJoinedError as AlreadyJoinedError3 } from "@dxos/protocols";
4806
+ import { Invitation as Invitation7, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
4465
4807
  import { SpaceMember as SpaceMember6 } from "@dxos/protocols/proto/dxos/halo/credentials";
4466
4808
  import { Gossip as Gossip2, Presence as Presence2 } from "@dxos/teleport-extension-gossip";
4467
4809
  import { trace as trace7 } from "@dxos/tracing";
4468
- import { ComplexMap as ComplexMap3, deferFunction as deferFunction2, forEachAsync } from "@dxos/util";
4810
+ import { ComplexMap as ComplexMap3, assignDeep, deferFunction as deferFunction2, forEachAsync } from "@dxos/util";
4469
4811
 
4470
4812
  // packages/sdk/client-services/src/packlets/spaces/genesis.ts
4471
4813
  import { createCredential } from "@dxos/credentials";
4472
4814
  import { failUndefined } from "@dxos/debug";
4473
4815
  import { AdmittedFeed as AdmittedFeed4, SpaceMember as SpaceMember5 } from "@dxos/protocols/proto/dxos/halo/credentials";
4474
- import { Timeframe as Timeframe3 } from "@dxos/timeframe";
4816
+ import { Timeframe as Timeframe4 } from "@dxos/timeframe";
4475
4817
  var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
4476
4818
  const credentials = [
4477
4819
  await createCredential({
@@ -4521,7 +4863,7 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
4521
4863
  "@type": "dxos.halo.credentials.Epoch",
4522
4864
  number: 0,
4523
4865
  previousId: void 0,
4524
- timeframe: new Timeframe3(),
4866
+ timeframe: new Timeframe4(),
4525
4867
  snapshotCid: void 0,
4526
4868
  automergeRoot
4527
4869
  }
@@ -4548,11 +4890,12 @@ function _ts_decorate5(decorators, target, key, desc) {
4548
4890
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4549
4891
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4550
4892
  }
4551
- var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
4893
+ var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
4552
4894
  var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
4553
4895
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
4896
+ var DEFAULT_SPACE_KEY = "__DEFAULT__";
4554
4897
  var DataSpaceManager = class {
4555
- constructor(_spaceManager, _metadataStore, _keyring, _signingContext, _feedStore, _echoHost, _invitationsManager, params) {
4898
+ constructor(_spaceManager, _metadataStore, _keyring, _signingContext, _feedStore, _echoHost, _invitationsManager, _params) {
4556
4899
  this._spaceManager = _spaceManager;
4557
4900
  this._metadataStore = _metadataStore;
4558
4901
  this._keyring = _keyring;
@@ -4560,14 +4903,15 @@ var DataSpaceManager = class {
4560
4903
  this._feedStore = _feedStore;
4561
4904
  this._echoHost = _echoHost;
4562
4905
  this._invitationsManager = _invitationsManager;
4563
- this._ctx = new Context9();
4906
+ this._params = _params;
4907
+ this._ctx = new Context9(void 0, {
4908
+ F: __dxlog_file19,
4909
+ L: 104
4910
+ });
4564
4911
  this.updated = new Event7();
4565
4912
  this._spaces = new ComplexMap3(PublicKey11.hash);
4566
4913
  this._isOpen = false;
4567
4914
  this._instanceId = PublicKey11.random().toHex();
4568
- const { spaceMemberPresenceAnnounceInterval = PRESENCE_ANNOUNCE_INTERVAL, spaceMemberPresenceOfflineTimeout = PRESENCE_OFFLINE_TIMEOUT } = params ?? {};
4569
- this._spaceMemberPresenceAnnounceInterval = spaceMemberPresenceAnnounceInterval;
4570
- this._spaceMemberPresenceOfflineTimeout = spaceMemberPresenceOfflineTimeout;
4571
4915
  trace7.diagnostic({
4572
4916
  id: "spaces",
4573
4917
  name: "Spaces",
@@ -4576,10 +4920,10 @@ var DataSpaceManager = class {
4576
4920
  const rootUrl = space.automergeSpaceState.rootUrl;
4577
4921
  const rootHandle = rootUrl ? this._echoHost.automergeRepo.find(rootUrl) : void 0;
4578
4922
  const rootDoc = rootHandle?.docSync();
4579
- const properties = rootDoc && findPropertiesObject(rootDoc);
4923
+ const properties = rootDoc && findInlineObjectOfType2(rootDoc, TYPE_PROPERTIES2);
4580
4924
  return {
4581
4925
  key: space.key.toHex(),
4582
- state: SpaceState2[space.state],
4926
+ state: SpaceState3[space.state],
4583
4927
  name: properties?.[1].data.name ?? null,
4584
4928
  inlineObjects: rootDoc ? Object.keys(rootDoc.objects ?? {}).length : null,
4585
4929
  linkedObjects: rootDoc ? Object.keys(rootDoc.links ?? {}).length : null,
@@ -4596,46 +4940,46 @@ var DataSpaceManager = class {
4596
4940
  return this._spaces;
4597
4941
  }
4598
4942
  async open() {
4599
- log13("open", void 0, {
4600
- F: __dxlog_file16,
4601
- L: 144,
4943
+ log16("open", void 0, {
4944
+ F: __dxlog_file19,
4945
+ L: 156,
4602
4946
  S: this,
4603
4947
  C: (f, a) => f(...a)
4604
4948
  });
4605
- log13.trace("dxos.echo.data-space-manager.open", Trace2.begin({
4949
+ log16.trace("dxos.echo.data-space-manager.open", Trace2.begin({
4606
4950
  id: this._instanceId
4607
4951
  }), {
4608
- F: __dxlog_file16,
4609
- L: 145,
4952
+ F: __dxlog_file19,
4953
+ L: 157,
4610
4954
  S: this,
4611
4955
  C: (f, a) => f(...a)
4612
4956
  });
4613
- log13("metadata loaded", {
4957
+ log16("metadata loaded", {
4614
4958
  spaces: this._metadataStore.spaces.length
4615
4959
  }, {
4616
- F: __dxlog_file16,
4617
- L: 146,
4960
+ F: __dxlog_file19,
4961
+ L: 158,
4618
4962
  S: this,
4619
4963
  C: (f, a) => f(...a)
4620
4964
  });
4621
4965
  await forEachAsync(this._metadataStore.spaces, async (spaceMetadata) => {
4622
4966
  try {
4623
- log13("load space", {
4967
+ log16("load space", {
4624
4968
  spaceMetadata
4625
4969
  }, {
4626
- F: __dxlog_file16,
4627
- L: 150,
4970
+ F: __dxlog_file19,
4971
+ L: 162,
4628
4972
  S: this,
4629
4973
  C: (f, a) => f(...a)
4630
4974
  });
4631
4975
  await this._constructSpace(spaceMetadata);
4632
4976
  } catch (err) {
4633
- log13.error("Error loading space", {
4977
+ log16.error("Error loading space", {
4634
4978
  spaceMetadata,
4635
4979
  err
4636
4980
  }, {
4637
- F: __dxlog_file16,
4638
- L: 153,
4981
+ F: __dxlog_file19,
4982
+ L: 165,
4639
4983
  S: this,
4640
4984
  C: (f, a) => f(...a)
4641
4985
  });
@@ -4643,24 +4987,19 @@ var DataSpaceManager = class {
4643
4987
  });
4644
4988
  this._isOpen = true;
4645
4989
  this.updated.emit();
4646
- for (const space of this._spaces.values()) {
4647
- if (space.state !== SpaceState2.INACTIVE) {
4648
- space.initializeDataPipelineAsync();
4649
- }
4650
- }
4651
- log13.trace("dxos.echo.data-space-manager.open", Trace2.end({
4990
+ log16.trace("dxos.echo.data-space-manager.open", Trace2.end({
4652
4991
  id: this._instanceId
4653
4992
  }), {
4654
- F: __dxlog_file16,
4655
- L: 166,
4993
+ F: __dxlog_file19,
4994
+ L: 172,
4656
4995
  S: this,
4657
4996
  C: (f, a) => f(...a)
4658
4997
  });
4659
4998
  }
4660
4999
  async close() {
4661
- log13("close", void 0, {
4662
- F: __dxlog_file16,
4663
- L: 171,
5000
+ log16("close", void 0, {
5001
+ F: __dxlog_file19,
5002
+ L: 177,
4664
5003
  S: this,
4665
5004
  C: (f, a) => f(...a)
4666
5005
  });
@@ -4669,14 +5008,15 @@ var DataSpaceManager = class {
4669
5008
  for (const space of this._spaces.values()) {
4670
5009
  await space.close();
4671
5010
  }
5011
+ this._spaces.clear();
4672
5012
  }
4673
5013
  /**
4674
5014
  * Creates a new space writing the genesis credentials to the control feed.
4675
5015
  */
4676
5016
  async createSpace() {
4677
5017
  invariant14(this._isOpen, "Not open.", {
4678
- F: __dxlog_file16,
4679
- L: 184,
5018
+ F: __dxlog_file19,
5019
+ L: 191,
4680
5020
  S: this,
4681
5021
  A: [
4682
5022
  "this._isOpen",
@@ -4691,24 +5031,25 @@ var DataSpaceManager = class {
4691
5031
  genesisFeedKey: controlFeedKey,
4692
5032
  controlFeedKey,
4693
5033
  dataFeedKey,
4694
- state: SpaceState2.ACTIVE
5034
+ state: SpaceState3.ACTIVE
4695
5035
  };
4696
- log13("creating space...", {
5036
+ log16("creating space...", {
4697
5037
  spaceKey
4698
5038
  }, {
4699
- F: __dxlog_file16,
4700
- L: 196,
5039
+ F: __dxlog_file19,
5040
+ L: 203,
4701
5041
  S: this,
4702
5042
  C: (f, a) => f(...a)
4703
5043
  });
4704
5044
  const root = await this._echoHost.createSpaceRoot(spaceKey);
4705
5045
  const space = await this._constructSpace(metadata);
5046
+ await space.open();
4706
5047
  const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, root.url);
4707
5048
  await this._metadataStore.addSpace(metadata);
4708
5049
  const memberCredential = credentials[1];
4709
- invariant14(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4710
- F: __dxlog_file16,
4711
- L: 205,
5050
+ invariant14(getCredentialAssertion3(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
5051
+ F: __dxlog_file19,
5052
+ L: 213,
4712
5053
  S: this,
4713
5054
  A: [
4714
5055
  "getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -4720,19 +5061,85 @@ var DataSpaceManager = class {
4720
5061
  this.updated.emit();
4721
5062
  return space;
4722
5063
  }
5064
+ async isDefaultSpace(space) {
5065
+ if (!space.databaseRoot) {
5066
+ return false;
5067
+ }
5068
+ switch (space.databaseRoot.getVersion()) {
5069
+ case SpaceDocVersion3.CURRENT: {
5070
+ const [_, properties] = findInlineObjectOfType2(space.databaseRoot.docSync(), TYPE_PROPERTIES2) ?? [];
5071
+ return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
5072
+ }
5073
+ case SpaceDocVersion3.LEGACY: {
5074
+ const convertedDoc = await convertLegacyReferences2(space.databaseRoot.docSync());
5075
+ const [_, properties] = findInlineObjectOfType2(convertedDoc, LEGACY_TYPE_PROPERTIES) ?? [];
5076
+ return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
5077
+ }
5078
+ default:
5079
+ log16.warn("unknown space version", {
5080
+ version: space.databaseRoot.getVersion(),
5081
+ spaceId: space.id
5082
+ }, {
5083
+ F: __dxlog_file19,
5084
+ L: 238,
5085
+ S: this,
5086
+ C: (f, a) => f(...a)
5087
+ });
5088
+ return false;
5089
+ }
5090
+ }
5091
+ async createDefaultSpace() {
5092
+ const space = await this.createSpace();
5093
+ const document = await this._getSpaceRootDocument(space);
5094
+ const properties = {
5095
+ system: {
5096
+ type: encodeReference(getTypeReference(PropertiesType))
5097
+ },
5098
+ data: {
5099
+ [DEFAULT_SPACE_KEY]: this._signingContext.identityKey.toHex()
5100
+ },
5101
+ meta: {
5102
+ keys: []
5103
+ }
5104
+ };
5105
+ const propertiesId = generateEchoId();
5106
+ document.change((doc) => {
5107
+ assignDeep(doc, [
5108
+ "objects",
5109
+ propertiesId
5110
+ ], properties);
5111
+ });
5112
+ await this._echoHost.flush();
5113
+ return space;
5114
+ }
5115
+ async _getSpaceRootDocument(space) {
5116
+ const automergeIndex = space.automergeSpaceState.rootUrl;
5117
+ invariant14(automergeIndex, void 0, {
5118
+ F: __dxlog_file19,
5119
+ L: 271,
5120
+ S: this,
5121
+ A: [
5122
+ "automergeIndex",
5123
+ ""
5124
+ ]
5125
+ });
5126
+ const document = this._echoHost.automergeRepo.find(automergeIndex);
5127
+ await document.whenReady();
5128
+ return document;
5129
+ }
4723
5130
  // TODO(burdon): Rename join space.
4724
5131
  async acceptSpace(opts) {
4725
- log13("accept space", {
5132
+ log16("accept space", {
4726
5133
  opts
4727
5134
  }, {
4728
- F: __dxlog_file16,
4729
- L: 217,
5135
+ F: __dxlog_file19,
5136
+ L: 280,
4730
5137
  S: this,
4731
5138
  C: (f, a) => f(...a)
4732
5139
  });
4733
5140
  invariant14(this._isOpen, "Not open.", {
4734
- F: __dxlog_file16,
4735
- L: 218,
5141
+ F: __dxlog_file19,
5142
+ L: 281,
4736
5143
  S: this,
4737
5144
  A: [
4738
5145
  "this._isOpen",
@@ -4740,8 +5147,8 @@ var DataSpaceManager = class {
4740
5147
  ]
4741
5148
  });
4742
5149
  invariant14(!this._spaces.has(opts.spaceKey), "Space already exists.", {
4743
- F: __dxlog_file16,
4744
- L: 219,
5150
+ F: __dxlog_file19,
5151
+ L: 282,
4745
5152
  S: this,
4746
5153
  A: [
4747
5154
  "!this._spaces.has(opts.spaceKey)",
@@ -4755,11 +5162,49 @@ var DataSpaceManager = class {
4755
5162
  dataTimeframe: opts.dataTimeframe
4756
5163
  };
4757
5164
  const space = await this._constructSpace(metadata);
5165
+ await space.open();
4758
5166
  await this._metadataStore.addSpace(metadata);
4759
5167
  space.initializeDataPipelineAsync();
4760
5168
  this.updated.emit();
4761
5169
  return space;
4762
5170
  }
5171
+ async admitMember(options) {
5172
+ const space = this._spaceManager.spaces.get(options.spaceKey);
5173
+ invariant14(space, void 0, {
5174
+ F: __dxlog_file19,
5175
+ L: 302,
5176
+ S: this,
5177
+ A: [
5178
+ "space",
5179
+ ""
5180
+ ]
5181
+ });
5182
+ if (space.spaceState.getMemberRole(options.identityKey) !== SpaceMember6.Role.REMOVED) {
5183
+ throw new AlreadyJoinedError3();
5184
+ }
5185
+ const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, options.identityKey, space.key, space.genesisFeedKey, options.role, space.spaceState.membershipChainHeads, options.profile, options.delegationCredentialId);
5186
+ invariant14(credentials[0].credential, void 0, {
5187
+ F: __dxlog_file19,
5188
+ L: 321,
5189
+ S: this,
5190
+ A: [
5191
+ "credentials[0].credential",
5192
+ ""
5193
+ ]
5194
+ });
5195
+ const spaceMemberCredential = credentials[0].credential.credential;
5196
+ invariant14(getCredentialAssertion3(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
5197
+ F: __dxlog_file19,
5198
+ L: 323,
5199
+ S: this,
5200
+ A: [
5201
+ "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
5202
+ ""
5203
+ ]
5204
+ });
5205
+ await writeMessages3(space.controlPipeline.writer, credentials);
5206
+ return spaceMemberCredential;
5207
+ }
4763
5208
  /**
4764
5209
  * Wait until the space data pipeline is fully initialized.
4765
5210
  * Used by invitation handler.
@@ -4768,15 +5213,27 @@ var DataSpaceManager = class {
4768
5213
  async waitUntilSpaceReady(spaceKey) {
4769
5214
  await cancelWithContext5(this._ctx, this.updated.waitForCondition(() => {
4770
5215
  const space = this._spaces.get(spaceKey);
4771
- return !!space && space.state === SpaceState2.READY;
5216
+ return !!space && space.state === SpaceState3.READY;
4772
5217
  }));
4773
5218
  }
5219
+ async requestSpaceAdmissionCredential(spaceKey) {
5220
+ return this._spaceManager.requestSpaceAdmissionCredential({
5221
+ spaceKey,
5222
+ identityKey: this._signingContext.identityKey,
5223
+ timeout: 15e3,
5224
+ swarmIdentity: {
5225
+ peerKey: this._signingContext.deviceKey,
5226
+ credentialProvider: createAuthProvider(this._signingContext.credentialSigner),
5227
+ credentialAuthenticator: async () => true
5228
+ }
5229
+ });
5230
+ }
4774
5231
  async _constructSpace(metadata) {
4775
- log13("construct space", {
5232
+ log16("construct space", {
4776
5233
  metadata
4777
5234
  }, {
4778
- F: __dxlog_file16,
4779
- L: 252,
5235
+ F: __dxlog_file19,
5236
+ L: 358,
4780
5237
  S: this,
4781
5238
  C: (f, a) => f(...a)
4782
5239
  });
@@ -4784,8 +5241,8 @@ var DataSpaceManager = class {
4784
5241
  localPeerId: this._signingContext.deviceKey
4785
5242
  });
4786
5243
  const presence = new Presence2({
4787
- announceInterval: this._spaceMemberPresenceAnnounceInterval,
4788
- offlineTimeout: this._spaceMemberPresenceOfflineTimeout,
5244
+ announceInterval: this._params?.spaceMemberPresenceAnnounceInterval ?? PRESENCE_ANNOUNCE_INTERVAL,
5245
+ offlineTimeout: this._params?.spaceMemberPresenceOfflineTimeout ?? PRESENCE_OFFLINE_TIMEOUT,
4789
5246
  identityKey: this._signingContext.identityKey,
4790
5247
  gossip
4791
5248
  });
@@ -4804,6 +5261,7 @@ var DataSpaceManager = class {
4804
5261
  credentialAuthenticator: deferFunction2(() => dataSpace.authVerifier.verifier)
4805
5262
  },
4806
5263
  onAuthorizedConnection: (session) => {
5264
+ session.addExtension("dxos.mesh.teleport.admission-discovery", new CredentialServerExtension(space));
4807
5265
  session.addExtension("dxos.mesh.teleport.gossip", gossip.createExtension({
4808
5266
  remotePeerId: session.remotePeerId
4809
5267
  }));
@@ -4812,15 +5270,15 @@ var DataSpaceManager = class {
4812
5270
  session.addExtension("dxos.mesh.teleport.automerge", this._echoHost.createReplicationExtension());
4813
5271
  },
4814
5272
  onAuthFailure: () => {
4815
- log13.warn("auth failure", void 0, {
4816
- F: __dxlog_file16,
4817
- L: 289,
5273
+ log16.warn("auth failure", void 0, {
5274
+ F: __dxlog_file19,
5275
+ L: 396,
4818
5276
  S: this,
4819
5277
  C: (f, a) => f(...a)
4820
5278
  });
4821
5279
  },
4822
5280
  onMemberRolesChanged: async (members) => {
4823
- if (dataSpace?.state === SpaceState2.READY) {
5281
+ if (dataSpace?.state === SpaceState3.READY) {
4824
5282
  this._handleMemberRoleChanges(presence, space.protocol, members);
4825
5283
  }
4826
5284
  },
@@ -4833,7 +5291,7 @@ var DataSpaceManager = class {
4833
5291
  dataFeed && await space.setDataFeed(dataFeed);
4834
5292
  const dataSpace = new DataSpace({
4835
5293
  inner: space,
4836
- initialState: metadata.state === SpaceState2.INACTIVE ? SpaceState2.INACTIVE : SpaceState2.CLOSED,
5294
+ initialState: metadata.state === SpaceState3.INACTIVE ? SpaceState3.INACTIVE : SpaceState3.CLOSED,
4837
5295
  metadataStore: this._metadataStore,
4838
5296
  gossip,
4839
5297
  presence,
@@ -4843,22 +5301,22 @@ var DataSpaceManager = class {
4843
5301
  signingContext: this._signingContext,
4844
5302
  callbacks: {
4845
5303
  beforeReady: async () => {
4846
- log13("before space ready", {
5304
+ log16("before space ready", {
4847
5305
  space: space.key
4848
5306
  }, {
4849
- F: __dxlog_file16,
4850
- L: 316,
5307
+ F: __dxlog_file19,
5308
+ L: 423,
4851
5309
  S: this,
4852
5310
  C: (f, a) => f(...a)
4853
5311
  });
4854
5312
  },
4855
5313
  afterReady: async () => {
4856
- log13("after space ready", {
5314
+ log16("after space ready", {
4857
5315
  space: space.key,
4858
5316
  open: this._isOpen
4859
5317
  }, {
4860
- F: __dxlog_file16,
4861
- L: 319,
5318
+ F: __dxlog_file19,
5319
+ L: 426,
4862
5320
  S: this,
4863
5321
  C: (f, a) => f(...a)
4864
5322
  });
@@ -4873,11 +5331,11 @@ var DataSpaceManager = class {
4873
5331
  }
4874
5332
  },
4875
5333
  beforeClose: async () => {
4876
- log13("before space close", {
5334
+ log16("before space close", {
4877
5335
  space: space.key
4878
5336
  }, {
4879
- F: __dxlog_file16,
4880
- L: 327,
5337
+ F: __dxlog_file19,
5338
+ L: 434,
4881
5339
  S: this,
4882
5340
  C: (f, a) => f(...a)
4883
5341
  });
@@ -4886,13 +5344,10 @@ var DataSpaceManager = class {
4886
5344
  cache: metadata.cache
4887
5345
  });
4888
5346
  presence.newPeer.on((peerState) => {
4889
- if (dataSpace.state === SpaceState2.READY) {
5347
+ if (dataSpace.state === SpaceState3.READY) {
4890
5348
  this._handleNewPeerConnected(space, peerState);
4891
5349
  }
4892
5350
  });
4893
- if (metadata.state !== SpaceState2.INACTIVE) {
4894
- await dataSpace.open();
4895
- }
4896
5351
  if (metadata.controlTimeframe) {
4897
5352
  dataSpace.inner.controlPipeline.state.setTargetTimeframe(metadata.controlTimeframe);
4898
5353
  }
@@ -4911,17 +5366,17 @@ var DataSpaceManager = class {
4911
5366
  return (s && member.role === SpaceMember6.Role.REMOVED !== (s.authStatus === AuthStatus.FAILURE)) ?? false;
4912
5367
  });
4913
5368
  sessionsToClose.forEach((session) => {
4914
- void session.close().catch(log13.error);
5369
+ void session.close().catch(log16.error);
4915
5370
  });
4916
5371
  closedSessions += sessionsToClose.length;
4917
5372
  }
4918
- log13("processed member role changes", {
5373
+ log16("processed member role changes", {
4919
5374
  roleChangeCount: memberInfo.length,
4920
5375
  peersOnline: presence.getPeersOnline().length,
4921
5376
  closedSessions
4922
5377
  }, {
4923
- F: __dxlog_file16,
4924
- L: 367,
5378
+ F: __dxlog_file19,
5379
+ L: 470,
4925
5380
  S: this,
4926
5381
  C: (f, a) => f(...a)
4927
5382
  });
@@ -4932,20 +5387,20 @@ var DataSpaceManager = class {
4932
5387
  if (role === SpaceMember6.Role.REMOVED) {
4933
5388
  const session = peerState.peerId && space.protocol.sessions.get(peerState.peerId);
4934
5389
  if (session != null) {
4935
- log13("closing a session with a removed peer", {
5390
+ log16("closing a session with a removed peer", {
4936
5391
  peerId: peerState.peerId
4937
5392
  }, {
4938
- F: __dxlog_file16,
4939
- L: 381,
5393
+ F: __dxlog_file19,
5394
+ L: 484,
4940
5395
  S: this,
4941
5396
  C: (f, a) => f(...a)
4942
5397
  });
4943
- void session.close().catch(log13.error);
5398
+ void session.close().catch(log16.error);
4944
5399
  }
4945
5400
  }
4946
5401
  }
4947
5402
  async _handleInvitationStatusChange(dataSpace, delegatedInvitation, isActive) {
4948
- if (dataSpace?.state !== SpaceState2.READY) {
5403
+ if (dataSpace?.state !== SpaceState3.READY) {
4949
5404
  return;
4950
5405
  }
4951
5406
  if (isActive) {
@@ -4999,15 +5454,15 @@ DataSpaceManager = _ts_decorate5([
4999
5454
  // packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
5000
5455
  import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTask as scheduleTask6 } from "@dxos/async";
5001
5456
  import { Stream as Stream10 } from "@dxos/codec-protobuf";
5002
- import { createAdmissionCredentials as createAdmissionCredentials2, getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
5457
+ import { createAdmissionCredentials as createAdmissionCredentials2, getCredentialAssertion as getCredentialAssertion4 } from "@dxos/credentials";
5003
5458
  import { raise as raise2 } from "@dxos/debug";
5004
- import { writeMessages as writeMessages3 } from "@dxos/feed-store";
5459
+ import { writeMessages as writeMessages4 } from "@dxos/feed-store";
5005
5460
  import { invariant as invariant15 } from "@dxos/invariant";
5006
- import { log as log14 } from "@dxos/log";
5461
+ import { log as log17 } from "@dxos/log";
5007
5462
  import { ApiError, SpaceNotFoundError as SpaceNotFoundError2, encodeError, IdentityNotInitializedError, AuthorizationError as AuthorizationError2 } from "@dxos/protocols";
5008
- import { SpaceMember as SpaceMember7, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
5463
+ import { SpaceMember as SpaceMember7, SpaceState as SpaceState4 } from "@dxos/protocols/proto/dxos/client/services";
5009
5464
  import { trace as trace8 } from "@dxos/tracing";
5010
- var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
5465
+ var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
5011
5466
  var SpacesServiceImpl = class {
5012
5467
  constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
5013
5468
  this._identityManager = _identityManager;
@@ -5026,10 +5481,10 @@ var SpacesServiceImpl = class {
5026
5481
  const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError2(spaceKey));
5027
5482
  if (state) {
5028
5483
  switch (state) {
5029
- case SpaceState3.ACTIVE:
5484
+ case SpaceState4.ACTIVE:
5030
5485
  await space.activate();
5031
5486
  break;
5032
- case SpaceState3.INACTIVE:
5487
+ case SpaceState4.INACTIVE:
5033
5488
  await space.deactivate();
5034
5489
  break;
5035
5490
  default:
@@ -5051,8 +5506,8 @@ var SpacesServiceImpl = class {
5051
5506
  }
5052
5507
  const credentials = await createAdmissionCredentials2(identity.getIdentityCredentialSigner(), request.memberKey, space.key, space.genesisFeedKey, request.newRole, space.spaceState.membershipChainHeads);
5053
5508
  invariant15(credentials[0].credential, void 0, {
5054
- F: __dxlog_file17,
5055
- L: 97,
5509
+ F: __dxlog_file20,
5510
+ L: 102,
5056
5511
  S: this,
5057
5512
  A: [
5058
5513
  "credentials[0].credential",
@@ -5060,27 +5515,27 @@ var SpacesServiceImpl = class {
5060
5515
  ]
5061
5516
  });
5062
5517
  const spaceMemberCredential = credentials[0].credential.credential;
5063
- invariant15(getCredentialAssertion3(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
5064
- F: __dxlog_file17,
5065
- L: 99,
5518
+ invariant15(getCredentialAssertion4(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
5519
+ F: __dxlog_file20,
5520
+ L: 104,
5066
5521
  S: this,
5067
5522
  A: [
5068
5523
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
5069
5524
  ""
5070
5525
  ]
5071
5526
  });
5072
- await writeMessages3(space.controlPipeline.writer, credentials);
5527
+ await writeMessages4(space.controlPipeline.writer, credentials);
5073
5528
  }
5074
5529
  querySpaces() {
5075
5530
  return new Stream10(({ next, ctx }) => {
5076
5531
  const scheduler = new UpdateScheduler(ctx, async () => {
5077
5532
  const dataSpaceManager = await this._getDataSpaceManager();
5078
5533
  const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
5079
- log14("update", {
5534
+ log17("update", {
5080
5535
  spaces
5081
5536
  }, {
5082
- F: __dxlog_file17,
5083
- L: 110,
5537
+ F: __dxlog_file20,
5538
+ L: 115,
5084
5539
  S: this,
5085
5540
  C: (f, a) => f(...a)
5086
5541
  });
@@ -5098,7 +5553,15 @@ var SpacesServiceImpl = class {
5098
5553
  const subscribeSpaces = () => {
5099
5554
  subscriptions.clear();
5100
5555
  for (const space of dataSpaceManager.spaces.values()) {
5101
- subscriptions.add(space.stateUpdate.on(ctx, () => scheduler.forceTrigger()));
5556
+ let lastState;
5557
+ subscriptions.add(space.stateUpdate.on(ctx, () => {
5558
+ if (space.state !== lastState) {
5559
+ scheduler.forceTrigger();
5560
+ } else {
5561
+ scheduler.trigger();
5562
+ }
5563
+ lastState = space.state;
5564
+ }));
5102
5565
  subscriptions.add(space.presence.updated.on(ctx, () => scheduler.trigger()));
5103
5566
  subscriptions.add(space.automergeSpaceState.onNewEpoch.on(ctx, () => scheduler.trigger()));
5104
5567
  subscriptions.add(space.inner.controlPipeline.state.timeframeUpdate.on(ctx, () => scheduler.trigger()));
@@ -5163,8 +5626,8 @@ var SpacesServiceImpl = class {
5163
5626
  });
5164
5627
  } else {
5165
5628
  invariant15(!credential.id, "Id on unsigned credentials is not allowed", {
5166
- F: __dxlog_file17,
5167
- L: 198,
5629
+ F: __dxlog_file20,
5630
+ L: 213,
5168
5631
  S: this,
5169
5632
  A: [
5170
5633
  "!credential.id",
@@ -5172,8 +5635,8 @@ var SpacesServiceImpl = class {
5172
5635
  ]
5173
5636
  });
5174
5637
  invariant15(this._identityManager.identity, "Identity is not available", {
5175
- F: __dxlog_file17,
5176
- L: 199,
5638
+ F: __dxlog_file20,
5639
+ L: 214,
5177
5640
  S: this,
5178
5641
  A: [
5179
5642
  "this._identityManager.identity",
@@ -5182,8 +5645,8 @@ var SpacesServiceImpl = class {
5182
5645
  });
5183
5646
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
5184
5647
  invariant15(credential.issuer.equals(signer.getIssuer()), void 0, {
5185
- F: __dxlog_file17,
5186
- L: 201,
5648
+ F: __dxlog_file20,
5649
+ L: 216,
5187
5650
  S: this,
5188
5651
  A: [
5189
5652
  "credential.issuer.equals(signer.getIssuer())",
@@ -5202,12 +5665,69 @@ var SpacesServiceImpl = class {
5202
5665
  }
5203
5666
  }
5204
5667
  }
5205
- async createEpoch({ spaceKey, migration }) {
5668
+ async createEpoch({ spaceKey, migration, automergeRootUrl }) {
5206
5669
  const dataSpaceManager = await this._getDataSpaceManager();
5207
5670
  const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError2(spaceKey));
5208
- await space.createEpoch({
5209
- migration
5671
+ const credential = await space.createEpoch({
5672
+ migration,
5673
+ newAutomergeRoot: automergeRootUrl
5674
+ });
5675
+ return {
5676
+ epochCredential: credential ?? void 0
5677
+ };
5678
+ }
5679
+ async admitContact(request) {
5680
+ const dataSpaceManager = await this._getDataSpaceManager();
5681
+ await dataSpaceManager.admitMember({
5682
+ spaceKey: request.spaceKey,
5683
+ identityKey: request.contact.identityKey,
5684
+ role: request.role
5685
+ });
5686
+ }
5687
+ async joinBySpaceKey({ spaceKey }) {
5688
+ const dataSpaceManager = await this._getDataSpaceManager();
5689
+ const credential = await dataSpaceManager.requestSpaceAdmissionCredential(spaceKey);
5690
+ return this._joinByAdmission({
5691
+ credential
5692
+ });
5693
+ }
5694
+ async _joinByAdmission({ credential }) {
5695
+ const assertion = getCredentialAssertion4(credential);
5696
+ invariant15(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
5697
+ F: __dxlog_file20,
5698
+ L: 250,
5699
+ S: this,
5700
+ A: [
5701
+ "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
5702
+ "'Invalid credential'"
5703
+ ]
5704
+ });
5705
+ const myIdentity = this._identityManager.identity;
5706
+ invariant15(myIdentity && credential.subject.id.equals(myIdentity.identityKey), void 0, {
5707
+ F: __dxlog_file20,
5708
+ L: 252,
5709
+ S: this,
5710
+ A: [
5711
+ "myIdentity && credential.subject.id.equals(myIdentity.identityKey)",
5712
+ ""
5713
+ ]
5210
5714
  });
5715
+ const dataSpaceManager = await this._getDataSpaceManager();
5716
+ let dataSpace = dataSpaceManager.spaces.get(assertion.spaceKey);
5717
+ if (!dataSpace) {
5718
+ dataSpace = await dataSpaceManager.acceptSpace({
5719
+ spaceKey: assertion.spaceKey,
5720
+ genesisFeedKey: assertion.genesisFeedKey
5721
+ });
5722
+ await myIdentity.controlPipeline.writer.write({
5723
+ credential: {
5724
+ credential
5725
+ }
5726
+ });
5727
+ }
5728
+ return {
5729
+ space: this._serializeSpace(dataSpace)
5730
+ };
5211
5731
  }
5212
5732
  _serializeSpace(space) {
5213
5733
  return {
@@ -5226,7 +5746,8 @@ var SpacesServiceImpl = class {
5226
5746
  startDataTimeframe: void 0,
5227
5747
  currentDataTimeframe: void 0,
5228
5748
  targetDataTimeframe: void 0,
5229
- totalDataTimeframe: void 0
5749
+ totalDataTimeframe: void 0,
5750
+ spaceRootUrl: space.databaseRoot?.url
5230
5751
  },
5231
5752
  members: Array.from(space.inner.spaceState.members.values()).map((member) => {
5232
5753
  const peers = space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key));
@@ -5270,9 +5791,9 @@ var SpacesServiceImpl = class {
5270
5791
  var getChannelId = (channel) => `user-channel/${channel}`;
5271
5792
 
5272
5793
  // packages/sdk/client-services/src/packlets/services/service-context.ts
5273
- import { Trigger as Trigger7 } from "@dxos/async";
5274
- import { Context as Context10, Resource } from "@dxos/context";
5275
- import { getCredentialAssertion as getCredentialAssertion4 } from "@dxos/credentials";
5794
+ import { Trigger as Trigger8 } from "@dxos/async";
5795
+ import { Context as Context10, Resource as Resource3 } from "@dxos/context";
5796
+ import { getCredentialAssertion as getCredentialAssertion5 } from "@dxos/credentials";
5276
5797
  import { failUndefined as failUndefined2 } from "@dxos/debug";
5277
5798
  import { EchoHost } from "@dxos/echo-db";
5278
5799
  import { MetadataStore, SnapshotStore, SpaceManager, valueEncoding } from "@dxos/echo-pipeline";
@@ -5280,7 +5801,7 @@ import { FeedFactory, FeedStore } from "@dxos/feed-store";
5280
5801
  import { invariant as invariant16 } from "@dxos/invariant";
5281
5802
  import { Keyring } from "@dxos/keyring";
5282
5803
  import { PublicKey as PublicKey12 } from "@dxos/keys";
5283
- import { log as log15 } from "@dxos/log";
5804
+ import { log as log18 } from "@dxos/log";
5284
5805
  import { InvalidStorageVersionError, STORAGE_VERSION as STORAGE_VERSION2, trace as trace9 } from "@dxos/protocols";
5285
5806
  import { Invitation as Invitation8 } from "@dxos/protocols/proto/dxos/client/services";
5286
5807
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
@@ -5296,8 +5817,8 @@ function _ts_decorate6(decorators, target, key, desc) {
5296
5817
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5297
5818
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5298
5819
  }
5299
- var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
5300
- var ServiceContext = class extends Resource {
5820
+ var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
5821
+ var ServiceContext = class extends Resource3 {
5301
5822
  constructor(storage, level, networkManager, signalManager, _runtimeParams) {
5302
5823
  super();
5303
5824
  this.storage = storage;
@@ -5305,7 +5826,7 @@ var ServiceContext = class extends Resource {
5305
5826
  this.networkManager = networkManager;
5306
5827
  this.signalManager = signalManager;
5307
5828
  this._runtimeParams = _runtimeParams;
5308
- this.initialized = new Trigger7();
5829
+ this.initialized = new Trigger8();
5309
5830
  this._handlerFactories = /* @__PURE__ */ new Map();
5310
5831
  this._instanceId = PublicKey12.random().toHex();
5311
5832
  this.metadataStore = new MetadataStore(storage.createDirectory("metadata"));
@@ -5331,8 +5852,7 @@ var ServiceContext = class extends Resource {
5331
5852
  });
5332
5853
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager, this._runtimeParams);
5333
5854
  this.echoHost = new EchoHost({
5334
- kv: this.level,
5335
- storage: this.storage
5855
+ kv: this.level
5336
5856
  });
5337
5857
  this.invitations = new InvitationsHandler(this.networkManager, _runtimeParams?.invitationConnectionDefaultParams);
5338
5858
  this.invitationsManager = new InvitationsManager(this.invitations, (invitation) => this.getInvitationHandler(invitation), this.metadataStore);
@@ -5340,17 +5860,17 @@ var ServiceContext = class extends Resource {
5340
5860
  }
5341
5861
  async _open(ctx) {
5342
5862
  await this._checkStorageVersion();
5343
- log15("opening...", void 0, {
5344
- F: __dxlog_file18,
5345
- L: 152,
5863
+ log18("opening...", void 0, {
5864
+ F: __dxlog_file21,
5865
+ L: 149,
5346
5866
  S: this,
5347
5867
  C: (f, a) => f(...a)
5348
5868
  });
5349
- log15.trace("dxos.sdk.service-context.open", trace9.begin({
5869
+ log18.trace("dxos.sdk.service-context.open", trace9.begin({
5350
5870
  id: this._instanceId
5351
5871
  }), {
5352
- F: __dxlog_file18,
5353
- L: 153,
5872
+ F: __dxlog_file21,
5873
+ L: 150,
5354
5874
  S: this,
5355
5875
  C: (f, a) => f(...a)
5356
5876
  });
@@ -5364,33 +5884,33 @@ var ServiceContext = class extends Resource {
5364
5884
  await this._initialize(ctx);
5365
5885
  }
5366
5886
  const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
5367
- log15("loaded persistent invitations", {
5887
+ log18("loaded persistent invitations", {
5368
5888
  count: loadedInvitations.invitations?.length
5369
5889
  }, {
5370
- F: __dxlog_file18,
5371
- L: 166,
5890
+ F: __dxlog_file21,
5891
+ L: 163,
5372
5892
  S: this,
5373
5893
  C: (f, a) => f(...a)
5374
5894
  });
5375
- log15.trace("dxos.sdk.service-context.open", trace9.end({
5895
+ log18.trace("dxos.sdk.service-context.open", trace9.end({
5376
5896
  id: this._instanceId
5377
5897
  }), {
5378
- F: __dxlog_file18,
5379
- L: 168,
5898
+ F: __dxlog_file21,
5899
+ L: 165,
5380
5900
  S: this,
5381
5901
  C: (f, a) => f(...a)
5382
5902
  });
5383
- log15("opened", void 0, {
5384
- F: __dxlog_file18,
5385
- L: 169,
5903
+ log18("opened", void 0, {
5904
+ F: __dxlog_file21,
5905
+ L: 166,
5386
5906
  S: this,
5387
5907
  C: (f, a) => f(...a)
5388
5908
  });
5389
5909
  }
5390
5910
  async _close(ctx) {
5391
- log15("closing...", void 0, {
5392
- F: __dxlog_file18,
5393
- L: 173,
5911
+ log18("closing...", void 0, {
5912
+ F: __dxlog_file21,
5913
+ L: 170,
5394
5914
  S: this,
5395
5915
  C: (f, a) => f(...a)
5396
5916
  });
@@ -5405,23 +5925,26 @@ var ServiceContext = class extends Resource {
5405
5925
  await this.echoHost.close(ctx);
5406
5926
  await this.networkManager.close();
5407
5927
  await this.signalManager.close();
5408
- log15("closed", void 0, {
5409
- F: __dxlog_file18,
5410
- L: 185,
5928
+ log18("closed", void 0, {
5929
+ F: __dxlog_file21,
5930
+ L: 182,
5411
5931
  S: this,
5412
5932
  C: (f, a) => f(...a)
5413
5933
  });
5414
5934
  }
5415
5935
  async createIdentity(params = {}) {
5416
5936
  const identity = await this.identityManager.createIdentity(params);
5417
- await this._initialize(new Context10());
5937
+ await this._initialize(new Context10(void 0, {
5938
+ F: __dxlog_file21,
5939
+ L: 187
5940
+ }));
5418
5941
  return identity;
5419
5942
  }
5420
5943
  getInvitationHandler(invitation) {
5421
5944
  const factory = this._handlerFactories.get(invitation.kind);
5422
5945
  invariant16(factory, `Unknown invitation kind: ${invitation.kind}`, {
5423
- F: __dxlog_file18,
5424
- L: 196,
5946
+ F: __dxlog_file21,
5947
+ L: 193,
5425
5948
  S: this,
5426
5949
  A: [
5427
5950
  "factory",
@@ -5440,7 +5963,10 @@ var ServiceContext = class extends Resource {
5440
5963
  }
5441
5964
  async _acceptIdentity(params) {
5442
5965
  const identity = await this.identityManager.acceptIdentity(params);
5443
- await this._initialize(new Context10());
5966
+ await this._initialize(new Context10(void 0, {
5967
+ F: __dxlog_file21,
5968
+ L: 209
5969
+ }));
5444
5970
  return identity;
5445
5971
  }
5446
5972
  async _checkStorageVersion() {
@@ -5451,9 +5977,9 @@ var ServiceContext = class extends Resource {
5451
5977
  }
5452
5978
  // Called when identity is created.
5453
5979
  async _initialize(ctx) {
5454
- log15("initializing spaces...", void 0, {
5455
- F: __dxlog_file18,
5456
- L: 227,
5980
+ log18("initializing spaces...", void 0, {
5981
+ F: __dxlog_file21,
5982
+ L: 224,
5457
5983
  S: this,
5458
5984
  C: (f, a) => f(...a)
5459
5985
  });
@@ -5475,8 +6001,8 @@ var ServiceContext = class extends Resource {
5475
6001
  await this.dataSpaceManager.open();
5476
6002
  this._handlerFactories.set(Invitation8.Kind.SPACE, (invitation) => {
5477
6003
  invariant16(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
5478
- F: __dxlog_file18,
5479
- L: 252,
6004
+ F: __dxlog_file21,
6005
+ L: 249,
5480
6006
  S: this,
5481
6007
  A: [
5482
6008
  "this.dataSpaceManager",
@@ -5488,7 +6014,7 @@ var ServiceContext = class extends Resource {
5488
6014
  this.initialized.wake();
5489
6015
  this._deviceSpaceSync = {
5490
6016
  processCredential: async (credential) => {
5491
- const assertion = getCredentialAssertion4(credential);
6017
+ const assertion = getCredentialAssertion5(credential);
5492
6018
  if (assertion["@type"] !== "dxos.halo.credentials.SpaceMember") {
5493
6019
  return;
5494
6020
  }
@@ -5496,33 +6022,33 @@ var ServiceContext = class extends Resource {
5496
6022
  return;
5497
6023
  }
5498
6024
  if (!this.dataSpaceManager) {
5499
- log15("dataSpaceManager not initialized yet, ignoring space admission", {
6025
+ log18("dataSpaceManager not initialized yet, ignoring space admission", {
5500
6026
  details: assertion
5501
6027
  }, {
5502
- F: __dxlog_file18,
5503
- L: 268,
6028
+ F: __dxlog_file21,
6029
+ L: 265,
5504
6030
  S: this,
5505
6031
  C: (f, a) => f(...a)
5506
6032
  });
5507
6033
  return;
5508
6034
  }
5509
6035
  if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
5510
- log15("space already exists, ignoring space admission", {
6036
+ log18("space already exists, ignoring space admission", {
5511
6037
  details: assertion
5512
6038
  }, {
5513
- F: __dxlog_file18,
5514
- L: 272,
6039
+ F: __dxlog_file21,
6040
+ L: 269,
5515
6041
  S: this,
5516
6042
  C: (f, a) => f(...a)
5517
6043
  });
5518
6044
  return;
5519
6045
  }
5520
6046
  try {
5521
- log15("accepting space recorded in halo", {
6047
+ log18("accepting space recorded in halo", {
5522
6048
  details: assertion
5523
6049
  }, {
5524
- F: __dxlog_file18,
5525
- L: 277,
6050
+ F: __dxlog_file21,
6051
+ L: 274,
5526
6052
  S: this,
5527
6053
  C: (f, a) => f(...a)
5528
6054
  });
@@ -5531,9 +6057,9 @@ var ServiceContext = class extends Resource {
5531
6057
  genesisFeedKey: assertion.genesisFeedKey
5532
6058
  });
5533
6059
  } catch (err) {
5534
- log15.catch(err, void 0, {
5535
- F: __dxlog_file18,
5536
- L: 283,
6060
+ log18.catch(err, void 0, {
6061
+ F: __dxlog_file21,
6062
+ L: 280,
5537
6063
  S: this,
5538
6064
  C: (f, a) => f(...a)
5539
6065
  });
@@ -5579,9 +6105,9 @@ var ServiceRegistry = class {
5579
6105
  };
5580
6106
 
5581
6107
  // packages/sdk/client-services/src/packlets/locks/browser.ts
5582
- import { asyncTimeout as asyncTimeout3, Trigger as Trigger8 } from "@dxos/async";
6108
+ import { asyncTimeout as asyncTimeout2, Trigger as Trigger9 } from "@dxos/async";
5583
6109
  import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
5584
- import { log as log16, logInfo } from "@dxos/log";
6110
+ import { log as log19, logInfo } from "@dxos/log";
5585
6111
  function _ts_decorate7(decorators, target, key, desc) {
5586
6112
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5587
6113
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -5592,7 +6118,7 @@ function _ts_decorate7(decorators, target, key, desc) {
5592
6118
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5593
6119
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5594
6120
  }
5595
- var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
6121
+ var __dxlog_file22 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
5596
6122
  var Message;
5597
6123
  (function(Message2) {
5598
6124
  Message2["ACQUIRING"] = "acquiring";
@@ -5600,7 +6126,7 @@ var Message;
5600
6126
  var Lock = class {
5601
6127
  constructor({ lockKey, onAcquire, onRelease }) {
5602
6128
  this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
5603
- this._releaseTrigger = new Trigger8();
6129
+ this._releaseTrigger = new Trigger9();
5604
6130
  this._lockKey = lockKey;
5605
6131
  this._onAcquire = onAcquire;
5606
6132
  this._onRelease = onRelease;
@@ -5614,29 +6140,29 @@ var Lock = class {
5614
6140
  message: "acquiring"
5615
6141
  });
5616
6142
  try {
5617
- log16("aquiring lock...", void 0, {
5618
- F: __dxlog_file19,
6143
+ log19("aquiring lock...", void 0, {
6144
+ F: __dxlog_file22,
5619
6145
  L: 42,
5620
6146
  S: this,
5621
6147
  C: (f, a) => f(...a)
5622
6148
  });
5623
- await asyncTimeout3(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
5624
- log16("acquired lock", void 0, {
5625
- F: __dxlog_file19,
6149
+ await asyncTimeout2(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
6150
+ log19("acquired lock", void 0, {
6151
+ F: __dxlog_file22,
5626
6152
  L: 44,
5627
6153
  S: this,
5628
6154
  C: (f, a) => f(...a)
5629
6155
  });
5630
6156
  } catch {
5631
- log16("stealing lock...", void 0, {
5632
- F: __dxlog_file19,
6157
+ log19("stealing lock...", void 0, {
6158
+ F: __dxlog_file22,
5633
6159
  L: 46,
5634
6160
  S: this,
5635
6161
  C: (f, a) => f(...a)
5636
6162
  });
5637
6163
  await this._requestLock(true);
5638
- log16("stolen lock", void 0, {
5639
- F: __dxlog_file19,
6164
+ log19("stolen lock", void 0, {
6165
+ F: __dxlog_file22,
5640
6166
  L: 48,
5641
6167
  S: this,
5642
6168
  C: (f, a) => f(...a)
@@ -5652,31 +6178,31 @@ var Lock = class {
5652
6178
  }
5653
6179
  }
5654
6180
  async _requestLock(steal = false) {
5655
- log16("requesting lock...", {
6181
+ log19("requesting lock...", {
5656
6182
  steal
5657
6183
  }, {
5658
- F: __dxlog_file19,
6184
+ F: __dxlog_file22,
5659
6185
  L: 63,
5660
6186
  S: this,
5661
6187
  C: (f, a) => f(...a)
5662
6188
  });
5663
- const acquired = new Trigger8();
6189
+ const acquired = new Trigger9();
5664
6190
  void navigator.locks.request(this._lockKey, {
5665
6191
  steal
5666
6192
  }, async () => {
5667
6193
  await this._onAcquire?.();
5668
6194
  acquired.wake();
5669
- this._releaseTrigger = new Trigger8();
6195
+ this._releaseTrigger = new Trigger9();
5670
6196
  await this._releaseTrigger.wait();
5671
- log16("releasing lock...", void 0, {
5672
- F: __dxlog_file19,
6197
+ log19("releasing lock...", void 0, {
6198
+ F: __dxlog_file22,
5673
6199
  L: 72,
5674
6200
  S: this,
5675
6201
  C: (f, a) => f(...a)
5676
6202
  });
5677
6203
  await this._onRelease?.();
5678
- log16("released lock", void 0, {
5679
- F: __dxlog_file19,
6204
+ log19("released lock", void 0, {
6205
+ F: __dxlog_file22,
5680
6206
  L: 74,
5681
6207
  S: this,
5682
6208
  C: (f, a) => f(...a)
@@ -5685,10 +6211,10 @@ var Lock = class {
5685
6211
  await this._onRelease?.();
5686
6212
  });
5687
6213
  await acquired.wait();
5688
- log16("recieved lock", {
6214
+ log19("recieved lock", {
5689
6215
  steal
5690
6216
  }, {
5691
- F: __dxlog_file19,
6217
+ F: __dxlog_file22,
5692
6218
  L: 81,
5693
6219
  S: this,
5694
6220
  C: (f, a) => f(...a)
@@ -5776,29 +6302,185 @@ var createLevel = async (config) => {
5776
6302
  return level;
5777
6303
  };
5778
6304
 
6305
+ // packages/sdk/client-services/src/packlets/storage/profile-archive.ts
6306
+ import { cbor } from "@dxos/automerge/automerge-repo";
6307
+ import { invariant as invariant17 } from "@dxos/invariant";
6308
+ import { log as log20 } from "@dxos/log";
6309
+ import { ProfileArchiveEntryType } from "@dxos/protocols";
6310
+ import { arrayToBuffer } from "@dxos/util";
6311
+ var __dxlog_file23 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/storage/profile-archive.ts";
6312
+ var encodeProfileArchive = (profile) => cbor.encode(profile);
6313
+ var decodeProfileArchive = (data) => cbor.decode(data);
6314
+ var exportProfileData = async ({ storage, level }) => {
6315
+ const archive = {
6316
+ storage: [],
6317
+ meta: {
6318
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
6319
+ }
6320
+ };
6321
+ {
6322
+ const directory = await storage.createDirectory();
6323
+ const files = await directory.list();
6324
+ log20.info("begin exporting files", {
6325
+ count: files.length
6326
+ }, {
6327
+ F: __dxlog_file23,
6328
+ L: 30,
6329
+ S: void 0,
6330
+ C: (f, a) => f(...a)
6331
+ });
6332
+ for (const filename of files) {
6333
+ const file = await directory.getOrCreateFile(filename);
6334
+ const { size } = await file.stat();
6335
+ const data = await file.read(0, size);
6336
+ archive.storage.push({
6337
+ type: ProfileArchiveEntryType.FILE,
6338
+ key: filename,
6339
+ value: data
6340
+ });
6341
+ }
6342
+ log20.info("done exporting files", {
6343
+ count: files.length
6344
+ }, {
6345
+ F: __dxlog_file23,
6346
+ L: 41,
6347
+ S: void 0,
6348
+ C: (f, a) => f(...a)
6349
+ });
6350
+ }
6351
+ {
6352
+ log20.info("begin exporting kv pairs", void 0, {
6353
+ F: __dxlog_file23,
6354
+ L: 45,
6355
+ S: void 0,
6356
+ C: (f, a) => f(...a)
6357
+ });
6358
+ const iter = await level.iterator({
6359
+ keyEncoding: "binary",
6360
+ valueEncoding: "binary"
6361
+ });
6362
+ let count = 0;
6363
+ for await (const [key, value] of iter) {
6364
+ archive.storage.push({
6365
+ type: ProfileArchiveEntryType.KEY_VALUE,
6366
+ key,
6367
+ value
6368
+ });
6369
+ count++;
6370
+ }
6371
+ log20.info("done exporting kv pairs", {
6372
+ count
6373
+ }, {
6374
+ F: __dxlog_file23,
6375
+ L: 56,
6376
+ S: void 0,
6377
+ C: (f, a) => f(...a)
6378
+ });
6379
+ }
6380
+ return archive;
6381
+ };
6382
+ var importProfileData = async ({ storage, level }, archive) => {
6383
+ let batch = level.batch();
6384
+ let count = 0;
6385
+ for (const entry2 of archive.storage) {
6386
+ switch (entry2.type) {
6387
+ case ProfileArchiveEntryType.FILE: {
6388
+ const directory = await storage.createDirectory();
6389
+ invariant17(typeof entry2.key === "string", "Invalid key type", {
6390
+ F: __dxlog_file23,
6391
+ L: 79,
6392
+ S: void 0,
6393
+ A: [
6394
+ "typeof entry.key === 'string'",
6395
+ "'Invalid key type'"
6396
+ ]
6397
+ });
6398
+ const file = await directory.getOrCreateFile(entry2.key);
6399
+ invariant17(entry2.value instanceof Uint8Array, "Invalid value type", {
6400
+ F: __dxlog_file23,
6401
+ L: 81,
6402
+ S: void 0,
6403
+ A: [
6404
+ "entry.value instanceof Uint8Array",
6405
+ "'Invalid value type'"
6406
+ ]
6407
+ });
6408
+ await file.write(0, arrayToBuffer(entry2.value));
6409
+ await file.close();
6410
+ break;
6411
+ }
6412
+ case ProfileArchiveEntryType.KEY_VALUE: {
6413
+ invariant17(entry2.key instanceof Uint8Array, "Invalid key type", {
6414
+ F: __dxlog_file23,
6415
+ L: 87,
6416
+ S: void 0,
6417
+ A: [
6418
+ "entry.key instanceof Uint8Array",
6419
+ "'Invalid key type'"
6420
+ ]
6421
+ });
6422
+ invariant17(entry2.value instanceof Uint8Array, "Invalid value type", {
6423
+ F: __dxlog_file23,
6424
+ L: 88,
6425
+ S: void 0,
6426
+ A: [
6427
+ "entry.value instanceof Uint8Array",
6428
+ "'Invalid value type'"
6429
+ ]
6430
+ });
6431
+ batch.put(entry2.key, entry2.value, {
6432
+ keyEncoding: "binary",
6433
+ valueEncoding: "binary"
6434
+ });
6435
+ break;
6436
+ }
6437
+ default:
6438
+ throw new Error(`Invalid entry type: ${entry2.type}`);
6439
+ }
6440
+ if (++count % 1e3 === 0) {
6441
+ await batch.write();
6442
+ batch = level.batch();
6443
+ log20.info("importing", {
6444
+ count,
6445
+ total: archive.storage.length,
6446
+ progress: `${(count / archive.storage.length * 100).toFixed()}%`
6447
+ }, {
6448
+ F: __dxlog_file23,
6449
+ L: 101,
6450
+ S: void 0,
6451
+ C: (f, a) => f(...a)
6452
+ });
6453
+ }
6454
+ }
6455
+ log20.info("committing changes..", void 0, {
6456
+ F: __dxlog_file23,
6457
+ L: 109,
6458
+ S: void 0,
6459
+ C: (f, a) => f(...a)
6460
+ });
6461
+ await batch.write();
6462
+ };
6463
+
5779
6464
  // packages/sdk/client-services/src/packlets/services/service-host.ts
5780
6465
  import { Event as Event9, synchronized as synchronized3 } from "@dxos/async";
5781
- import { clientServiceBundle, defaultKey, PropertiesType } from "@dxos/client-protocol";
6466
+ import { clientServiceBundle } from "@dxos/client-protocol";
5782
6467
  import { Context as Context11 } from "@dxos/context";
5783
- import { encodeReference } from "@dxos/echo-protocol";
5784
- import { getTypeReference } from "@dxos/echo-schema";
5785
- import { invariant as invariant18 } from "@dxos/invariant";
5786
- import { PublicKey as PublicKey16 } from "@dxos/keys";
5787
- import { log as log18 } from "@dxos/log";
6468
+ import { invariant as invariant19 } from "@dxos/invariant";
6469
+ import { PublicKey as PublicKey17 } from "@dxos/keys";
6470
+ import { log as log22 } from "@dxos/log";
5788
6471
  import { WebsocketSignalManager } from "@dxos/messaging";
5789
6472
  import { SwarmNetworkManager, createSimplePeerTransportFactory } from "@dxos/network-manager";
5790
6473
  import { trace as trace10 } from "@dxos/protocols";
5791
6474
  import { SystemStatus } from "@dxos/protocols/proto/dxos/client/services";
5792
6475
  import { TRACE_PROCESSOR as TRACE_PROCESSOR3, trace as Trace4 } from "@dxos/tracing";
5793
- import { assignDeep as assignDeep2 } from "@dxos/util";
5794
6476
  import { WebsocketRpcClient } from "@dxos/websocket-rpc";
5795
6477
 
5796
6478
  // packages/sdk/client-services/src/packlets/devices/devices-service.ts
5797
6479
  import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
5798
6480
  import { Stream as Stream11 } from "@dxos/codec-protobuf";
5799
- import { invariant as invariant17 } from "@dxos/invariant";
6481
+ import { invariant as invariant18 } from "@dxos/invariant";
5800
6482
  import { Device as Device2, DeviceKind as DeviceKind2 } from "@dxos/protocols/proto/dxos/client/services";
5801
- var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
6483
+ var __dxlog_file24 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
5802
6484
  var DevicesServiceImpl = class {
5803
6485
  constructor(_identityManager) {
5804
6486
  this._identityManager = _identityManager;
@@ -5815,8 +6497,8 @@ var DevicesServiceImpl = class {
5815
6497
  devices: []
5816
6498
  });
5817
6499
  } else {
5818
- invariant17(this._identityManager.identity?.presence, "presence not present", {
5819
- F: __dxlog_file20,
6500
+ invariant18(this._identityManager.identity?.presence, "presence not present", {
6501
+ F: __dxlog_file24,
5820
6502
  L: 32,
5821
6503
  S: this,
5822
6504
  A: [
@@ -5922,28 +6604,111 @@ var findConfigs = () => {
5922
6604
  return configs.map((r) => r.instance.deref()).filter(nonNullable);
5923
6605
  };
5924
6606
 
5925
- // packages/sdk/client-services/src/packlets/logging/logging-service.ts
5926
- import { Event as Event8 } from "@dxos/async";
6607
+ // packages/sdk/client-services/src/packlets/identity/contacts-service.ts
6608
+ import { EventSubscriptions as EventSubscriptions4, scheduleTask as scheduleTask7, UpdateScheduler as UpdateScheduler2 } from "@dxos/async";
5927
6609
  import { Stream as Stream12 } from "@dxos/codec-protobuf";
5928
6610
  import { PublicKey as PublicKey15 } from "@dxos/keys";
5929
- import { getContextFromEntry, log as log17 } from "@dxos/log";
6611
+ import { ComplexMap as ComplexMap4, ComplexSet as ComplexSet6 } from "@dxos/util";
6612
+ var ContactsServiceImpl = class {
6613
+ constructor(_identityManager, _spaceManager, _dataSpaceManagerProvider) {
6614
+ this._identityManager = _identityManager;
6615
+ this._spaceManager = _spaceManager;
6616
+ this._dataSpaceManagerProvider = _dataSpaceManagerProvider;
6617
+ }
6618
+ async getContacts() {
6619
+ const identity = this._identityManager.identity;
6620
+ if (identity == null) {
6621
+ return {
6622
+ contacts: []
6623
+ };
6624
+ }
6625
+ const contacts = [
6626
+ ...this._spaceManager.spaces.values()
6627
+ ].flatMap((s) => [
6628
+ ...s.spaceState.members.values()
6629
+ ].map((m) => [
6630
+ s.key,
6631
+ m
6632
+ ])).reduce((acc, v) => {
6633
+ const [spaceKey, memberInfo] = v;
6634
+ if (memberInfo.key.equals(identity.identityKey)) {
6635
+ return acc;
6636
+ }
6637
+ const existing = acc.get(memberInfo.key);
6638
+ if (existing != null) {
6639
+ existing.profile ??= memberInfo.profile;
6640
+ existing.commonSpaces?.push(spaceKey);
6641
+ } else {
6642
+ acc.set(memberInfo.key, {
6643
+ identityKey: memberInfo.key,
6644
+ profile: memberInfo.profile,
6645
+ commonSpaces: [
6646
+ spaceKey
6647
+ ]
6648
+ });
6649
+ }
6650
+ return acc;
6651
+ }, new ComplexMap4(PublicKey15.hash));
6652
+ return {
6653
+ contacts: [
6654
+ ...contacts.values()
6655
+ ]
6656
+ };
6657
+ }
6658
+ queryContacts() {
6659
+ const subscribedSpaceKeySet = new ComplexSet6(PublicKey15.hash);
6660
+ return new Stream12(({ next, ctx }) => {
6661
+ const pushUpdateTask = new UpdateScheduler2(ctx, async () => {
6662
+ const contacts = await this.getContacts();
6663
+ next(contacts);
6664
+ }, {
6665
+ maxFrequency: 2
6666
+ });
6667
+ scheduleTask7(ctx, async () => {
6668
+ const subscriptions = new EventSubscriptions4();
6669
+ ctx.onDispose(() => subscriptions.clear());
6670
+ const subscribeToSpaceAndUpdate = () => {
6671
+ const oldSetSize = subscribedSpaceKeySet.size;
6672
+ for (const space of this._spaceManager.spaces.values()) {
6673
+ if (!subscribedSpaceKeySet.has(space.key)) {
6674
+ subscriptions.add(space.stateUpdate.on(ctx, () => pushUpdateTask.trigger()));
6675
+ subscribedSpaceKeySet.add(space.key);
6676
+ }
6677
+ }
6678
+ if (oldSetSize !== subscribedSpaceKeySet.size) {
6679
+ pushUpdateTask.trigger();
6680
+ }
6681
+ };
6682
+ const unsubscribe = (await this._dataSpaceManagerProvider()).updated.on(ctx, subscribeToSpaceAndUpdate);
6683
+ ctx.onDispose(unsubscribe);
6684
+ subscribeToSpaceAndUpdate();
6685
+ });
6686
+ });
6687
+ }
6688
+ };
6689
+
6690
+ // packages/sdk/client-services/src/packlets/logging/logging-service.ts
6691
+ import { Event as Event8 } from "@dxos/async";
6692
+ import { Stream as Stream13 } from "@dxos/codec-protobuf";
6693
+ import { PublicKey as PublicKey16 } from "@dxos/keys";
6694
+ import { getContextFromEntry, log as log21 } from "@dxos/log";
5930
6695
  import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
5931
6696
  import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
5932
6697
  var LoggingServiceImpl = class {
5933
6698
  constructor() {
5934
6699
  this._logs = new Event8();
5935
6700
  this._started = Date.now();
5936
- this._sessionId = PublicKey15.random().toHex();
6701
+ this._sessionId = PublicKey16.random().toHex();
5937
6702
  this._logProcessor = (_config, entry2) => {
5938
6703
  this._logs.emit(entry2);
5939
6704
  };
5940
6705
  }
5941
6706
  async open() {
5942
- log17.runtimeConfig.processors.push(this._logProcessor);
6707
+ log21.runtimeConfig.processors.push(this._logProcessor);
5943
6708
  }
5944
6709
  async close() {
5945
- const index = log17.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
5946
- log17.runtimeConfig.processors.splice(index, 1);
6710
+ const index = log21.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
6711
+ log21.runtimeConfig.processors.splice(index, 1);
5947
6712
  }
5948
6713
  async controlMetrics({ reset, record }) {
5949
6714
  if (reset) {
@@ -5969,7 +6734,7 @@ var LoggingServiceImpl = class {
5969
6734
  stats: numericalValues(events, "duration")
5970
6735
  };
5971
6736
  };
5972
- return new Stream12(({ next }) => {
6737
+ return new Stream13(({ next }) => {
5973
6738
  const update = () => {
5974
6739
  const metrics = {
5975
6740
  timestamp: /* @__PURE__ */ new Date(),
@@ -5991,7 +6756,7 @@ var LoggingServiceImpl = class {
5991
6756
  });
5992
6757
  }
5993
6758
  queryLogs(request) {
5994
- return new Stream12(({ ctx, next }) => {
6759
+ return new Stream13(({ ctx, next }) => {
5995
6760
  const handler = (entry2) => {
5996
6761
  if (LOG_PROCESSING > 0) {
5997
6762
  return;
@@ -6047,14 +6812,14 @@ var shouldLog = (entry2, request) => {
6047
6812
  var LOG_PROCESSING = 0;
6048
6813
 
6049
6814
  // packages/sdk/client-services/src/packlets/network/network-service.ts
6050
- import { Stream as Stream13 } from "@dxos/codec-protobuf";
6815
+ import { Stream as Stream14 } from "@dxos/codec-protobuf";
6051
6816
  var NetworkServiceImpl = class {
6052
6817
  constructor(networkManager, signalManager) {
6053
6818
  this.networkManager = networkManager;
6054
6819
  this.signalManager = signalManager;
6055
6820
  }
6056
6821
  queryStatus() {
6057
- return new Stream13(({ next }) => {
6822
+ return new Stream14(({ next }) => {
6058
6823
  const update = () => {
6059
6824
  next({
6060
6825
  swarm: this.networkManager.connectionState,
@@ -6080,7 +6845,7 @@ var NetworkServiceImpl = class {
6080
6845
  };
6081
6846
 
6082
6847
  // packages/sdk/client-services/src/packlets/system/system-service.ts
6083
- import { Stream as Stream14 } from "@dxos/codec-protobuf";
6848
+ import { Stream as Stream15 } from "@dxos/codec-protobuf";
6084
6849
  import { GetDiagnosticsRequest as GetDiagnosticsRequest2 } from "@dxos/protocols/proto/dxos/client/services";
6085
6850
  import { jsonKeyReplacer as jsonKeyReplacer2 } from "@dxos/util";
6086
6851
  var SystemServiceImpl = class {
@@ -6116,7 +6881,7 @@ var SystemServiceImpl = class {
6116
6881
  }
6117
6882
  // TODO(burdon): Standardize interval option in stream request?
6118
6883
  queryStatus({ interval = 3e3 } = {}) {
6119
- return new Stream14(({ next }) => {
6884
+ return new Stream15(({ next }) => {
6120
6885
  const update = () => {
6121
6886
  next({
6122
6887
  status: this._getCurrentStatus()
@@ -6147,7 +6912,7 @@ function _ts_decorate8(decorators, target, key, desc) {
6147
6912
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6148
6913
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6149
6914
  }
6150
- var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
6915
+ var __dxlog_file25 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
6151
6916
  var ClientServicesHost = class {
6152
6917
  constructor({
6153
6918
  config,
@@ -6167,7 +6932,7 @@ var ClientServicesHost = class {
6167
6932
  this._storage = storage;
6168
6933
  this._level = level;
6169
6934
  this._callbacks = callbacks;
6170
- this._runtimeParams = runtimeParams;
6935
+ this._runtimeParams = runtimeParams ?? {};
6171
6936
  if (config) {
6172
6937
  this.initialize({
6173
6938
  config,
@@ -6180,7 +6945,10 @@ var ClientServicesHost = class {
6180
6945
  lockKey,
6181
6946
  onAcquire: () => {
6182
6947
  if (!this._opening) {
6183
- void this.open(new Context11());
6948
+ void this.open(new Context11(void 0, {
6949
+ F: __dxlog_file25,
6950
+ L: 121
6951
+ }));
6184
6952
  }
6185
6953
  },
6186
6954
  onRelease: () => this.close()
@@ -6235,25 +7003,25 @@ var ClientServicesHost = class {
6235
7003
  * Can only be called once.
6236
7004
  */
6237
7005
  initialize({ config, ...options }) {
6238
- invariant18(!this._open, "service host is open", {
6239
- F: __dxlog_file21,
6240
- L: 189,
7006
+ invariant19(!this._open, "service host is open", {
7007
+ F: __dxlog_file25,
7008
+ L: 187,
6241
7009
  S: this,
6242
7010
  A: [
6243
7011
  "!this._open",
6244
7012
  "'service host is open'"
6245
7013
  ]
6246
7014
  });
6247
- log18("initializing...", void 0, {
6248
- F: __dxlog_file21,
6249
- L: 190,
7015
+ log22("initializing...", void 0, {
7016
+ F: __dxlog_file25,
7017
+ L: 188,
6250
7018
  S: this,
6251
7019
  C: (f, a) => f(...a)
6252
7020
  });
6253
7021
  if (config) {
6254
- invariant18(!this._config, "config already set", {
6255
- F: __dxlog_file21,
6256
- L: 193,
7022
+ invariant19(!this._config, "config already set", {
7023
+ F: __dxlog_file25,
7024
+ L: 191,
6257
7025
  S: this,
6258
7026
  A: [
6259
7027
  "!this._config",
@@ -6266,9 +7034,9 @@ var ClientServicesHost = class {
6266
7034
  }
6267
7035
  }
6268
7036
  if (!options.signalManager) {
6269
- log18.warn("running signaling without telemetry metadata.", void 0, {
6270
- F: __dxlog_file21,
6271
- L: 201,
7037
+ log22.warn("running signaling without telemetry metadata.", void 0, {
7038
+ F: __dxlog_file25,
7039
+ L: 199,
6272
7040
  S: this,
6273
7041
  C: (f, a) => f(...a)
6274
7042
  });
@@ -6277,9 +7045,9 @@ var ClientServicesHost = class {
6277
7045
  iceServers: this._config?.get("runtime.services.ice")
6278
7046
  }), signalManager = new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
6279
7047
  this._signalManager = signalManager;
6280
- invariant18(!this._networkManager, "network manager already set", {
6281
- F: __dxlog_file21,
6282
- L: 212,
7048
+ invariant19(!this._networkManager, "network manager already set", {
7049
+ F: __dxlog_file25,
7050
+ L: 210,
6283
7051
  S: this,
6284
7052
  A: [
6285
7053
  "!this._networkManager",
@@ -6291,9 +7059,9 @@ var ClientServicesHost = class {
6291
7059
  transportFactory,
6292
7060
  signalManager
6293
7061
  });
6294
- log18("initialized", void 0, {
6295
- F: __dxlog_file21,
6296
- L: 219,
7062
+ log22("initialized", void 0, {
7063
+ F: __dxlog_file25,
7064
+ L: 217,
6297
7065
  S: this,
6298
7066
  C: (f, a) => f(...a)
6299
7067
  });
@@ -6302,45 +7070,45 @@ var ClientServicesHost = class {
6302
7070
  if (this._open) {
6303
7071
  return;
6304
7072
  }
6305
- const traceId = PublicKey16.random().toHex();
6306
- log18.trace("dxos.client-services.host.open", trace10.begin({
7073
+ const traceId = PublicKey17.random().toHex();
7074
+ log22.trace("dxos.client-services.host.open", trace10.begin({
6307
7075
  id: traceId
6308
7076
  }), {
6309
- F: __dxlog_file21,
6310
- L: 230,
7077
+ F: __dxlog_file25,
7078
+ L: 228,
6311
7079
  S: this,
6312
7080
  C: (f, a) => f(...a)
6313
7081
  });
6314
- invariant18(this._config, "config not set", {
6315
- F: __dxlog_file21,
6316
- L: 232,
7082
+ invariant19(this._config, "config not set", {
7083
+ F: __dxlog_file25,
7084
+ L: 230,
6317
7085
  S: this,
6318
7086
  A: [
6319
7087
  "this._config",
6320
7088
  "'config not set'"
6321
7089
  ]
6322
7090
  });
6323
- invariant18(this._storage, "storage not set", {
6324
- F: __dxlog_file21,
6325
- L: 233,
7091
+ invariant19(this._storage, "storage not set", {
7092
+ F: __dxlog_file25,
7093
+ L: 231,
6326
7094
  S: this,
6327
7095
  A: [
6328
7096
  "this._storage",
6329
7097
  "'storage not set'"
6330
7098
  ]
6331
7099
  });
6332
- invariant18(this._signalManager, "signal manager not set", {
6333
- F: __dxlog_file21,
6334
- L: 234,
7100
+ invariant19(this._signalManager, "signal manager not set", {
7101
+ F: __dxlog_file25,
7102
+ L: 232,
6335
7103
  S: this,
6336
7104
  A: [
6337
7105
  "this._signalManager",
6338
7106
  "'signal manager not set'"
6339
7107
  ]
6340
7108
  });
6341
- invariant18(this._networkManager, "network manager not set", {
6342
- F: __dxlog_file21,
6343
- L: 235,
7109
+ invariant19(this._networkManager, "network manager not set", {
7110
+ F: __dxlog_file25,
7111
+ L: 233,
6344
7112
  S: this,
6345
7113
  A: [
6346
7114
  "this._networkManager",
@@ -6348,11 +7116,11 @@ var ClientServicesHost = class {
6348
7116
  ]
6349
7117
  });
6350
7118
  this._opening = true;
6351
- log18("opening...", {
7119
+ log22("opening...", {
6352
7120
  lockKey: this._resourceLock?.lockKey
6353
7121
  }, {
6354
- F: __dxlog_file21,
6355
- L: 238,
7122
+ F: __dxlog_file25,
7123
+ L: 236,
6356
7124
  S: this,
6357
7125
  C: (f, a) => f(...a)
6358
7126
  });
@@ -6363,15 +7131,18 @@ var ClientServicesHost = class {
6363
7131
  await this._level.open();
6364
7132
  await this._loggingService.open();
6365
7133
  this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._runtimeParams);
7134
+ const dataSpaceManagerProvider = async () => {
7135
+ await this._serviceContext.initialized.wait();
7136
+ return this._serviceContext.dataSpaceManager;
7137
+ };
7138
+ const identityService = new IdentityServiceImpl(this._serviceContext.identityManager, this._serviceContext.keyring, () => this._serviceContext.dataSpaceManager, (params) => this._createIdentity(params), (profile) => this._serviceContext.broadcastProfileUpdate(profile));
6366
7139
  this._serviceRegistry.setServices({
6367
7140
  SystemService: this._systemService,
6368
- IdentityService: new IdentityServiceImpl((params) => this._createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring, (profile) => this._serviceContext.broadcastProfileUpdate(profile)),
7141
+ IdentityService: identityService,
7142
+ ContactsService: new ContactsServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, dataSpaceManagerProvider),
6369
7143
  InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitationsManager),
6370
7144
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
6371
- SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, async () => {
6372
- await this._serviceContext.initialized.wait();
6373
- return this._serviceContext.dataSpaceManager;
6374
- }),
7145
+ SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, dataSpaceManagerProvider),
6375
7146
  DataService: this._serviceContext.echoHost.dataService,
6376
7147
  QueryService: this._serviceContext.echoHost.queryService,
6377
7148
  NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager, this._serviceContext.signalManager),
@@ -6385,6 +7156,7 @@ var ClientServicesHost = class {
6385
7156
  })
6386
7157
  });
6387
7158
  await this._serviceContext.open(ctx);
7159
+ await identityService.open();
6388
7160
  const devtoolsProxy = this._config?.get("runtime.client.devtoolsProxy");
6389
7161
  if (devtoolsProxy) {
6390
7162
  this._devtoolsProxy = new WebsocketRpcClient({
@@ -6400,19 +7172,19 @@ var ClientServicesHost = class {
6400
7172
  this._open = true;
6401
7173
  this._statusUpdate.emit();
6402
7174
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
6403
- log18("opened", {
7175
+ log22("opened", {
6404
7176
  deviceKey
6405
7177
  }, {
6406
- F: __dxlog_file21,
6407
- L: 314,
7178
+ F: __dxlog_file25,
7179
+ L: 322,
6408
7180
  S: this,
6409
7181
  C: (f, a) => f(...a)
6410
7182
  });
6411
- log18.trace("dxos.client-services.host.open", trace10.end({
7183
+ log22.trace("dxos.client-services.host.open", trace10.end({
6412
7184
  id: traceId
6413
7185
  }), {
6414
- F: __dxlog_file21,
6415
- L: 315,
7186
+ F: __dxlog_file25,
7187
+ L: 323,
6416
7188
  S: this,
6417
7189
  C: (f, a) => f(...a)
6418
7190
  });
@@ -6422,11 +7194,11 @@ var ClientServicesHost = class {
6422
7194
  return;
6423
7195
  }
6424
7196
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
6425
- log18("closing...", {
7197
+ log22("closing...", {
6426
7198
  deviceKey
6427
7199
  }, {
6428
- F: __dxlog_file21,
6429
- L: 326,
7200
+ F: __dxlog_file25,
7201
+ L: 334,
6430
7202
  S: this,
6431
7203
  C: (f, a) => f(...a)
6432
7204
  });
@@ -6440,44 +7212,44 @@ var ClientServicesHost = class {
6440
7212
  await this._level?.close();
6441
7213
  this._open = false;
6442
7214
  this._statusUpdate.emit();
6443
- log18("closed", {
7215
+ log22("closed", {
6444
7216
  deviceKey
6445
7217
  }, {
6446
- F: __dxlog_file21,
6447
- L: 335,
7218
+ F: __dxlog_file25,
7219
+ L: 343,
6448
7220
  S: this,
6449
7221
  C: (f, a) => f(...a)
6450
7222
  });
6451
7223
  }
6452
7224
  async reset() {
6453
- const traceId = PublicKey16.random().toHex();
6454
- log18.trace("dxos.sdk.client-services-host.reset", trace10.begin({
7225
+ const traceId = PublicKey17.random().toHex();
7226
+ log22.trace("dxos.sdk.client-services-host.reset", trace10.begin({
6455
7227
  id: traceId
6456
7228
  }), {
6457
- F: __dxlog_file21,
6458
- L: 340,
7229
+ F: __dxlog_file25,
7230
+ L: 348,
6459
7231
  S: this,
6460
7232
  C: (f, a) => f(...a)
6461
7233
  });
6462
- log18.info("resetting...", void 0, {
6463
- F: __dxlog_file21,
6464
- L: 342,
7234
+ log22.info("resetting...", void 0, {
7235
+ F: __dxlog_file25,
7236
+ L: 350,
6465
7237
  S: this,
6466
7238
  C: (f, a) => f(...a)
6467
7239
  });
6468
7240
  await this._serviceContext?.close();
6469
7241
  await this._storage.reset();
6470
- log18.info("reset", void 0, {
6471
- F: __dxlog_file21,
6472
- L: 345,
7242
+ log22.info("reset", void 0, {
7243
+ F: __dxlog_file25,
7244
+ L: 353,
6473
7245
  S: this,
6474
7246
  C: (f, a) => f(...a)
6475
7247
  });
6476
- log18.trace("dxos.sdk.client-services-host.reset", trace10.end({
7248
+ log22.trace("dxos.sdk.client-services-host.reset", trace10.end({
6477
7249
  id: traceId
6478
7250
  }), {
6479
- F: __dxlog_file21,
6480
- L: 346,
7251
+ F: __dxlog_file25,
7252
+ L: 354,
6481
7253
  S: this,
6482
7254
  C: (f, a) => f(...a)
6483
7255
  });
@@ -6486,38 +7258,6 @@ var ClientServicesHost = class {
6486
7258
  async _createIdentity(params) {
6487
7259
  const identity = await this._serviceContext.createIdentity(params);
6488
7260
  await this._serviceContext.initialized.wait();
6489
- const space = await this._serviceContext.dataSpaceManager.createSpace();
6490
- const automergeIndex = space.automergeSpaceState.rootUrl;
6491
- invariant18(automergeIndex, void 0, {
6492
- F: __dxlog_file21,
6493
- L: 358,
6494
- S: this,
6495
- A: [
6496
- "automergeIndex",
6497
- ""
6498
- ]
6499
- });
6500
- const document = this._serviceContext.echoHost.automergeRepo.find(automergeIndex);
6501
- await document.whenReady();
6502
- const properties = {
6503
- system: {
6504
- type: encodeReference(getTypeReference(PropertiesType))
6505
- },
6506
- data: {
6507
- [defaultKey]: identity.identityKey.toHex()
6508
- },
6509
- meta: {
6510
- keys: []
6511
- }
6512
- };
6513
- const propertiesId = PublicKey16.random().toHex();
6514
- document.change((doc) => {
6515
- assignDeep2(doc, [
6516
- "objects",
6517
- propertiesId
6518
- ], properties);
6519
- });
6520
- await this._serviceContext.echoHost.flush();
6521
7261
  return identity;
6522
7262
  }
6523
7263
  };
@@ -6567,7 +7307,6 @@ export {
6567
7307
  SpaceInvitationProtocol,
6568
7308
  InvitationsManager,
6569
7309
  DataSpace,
6570
- findPropertiesObject,
6571
7310
  DataSpaceManager,
6572
7311
  SpacesServiceImpl,
6573
7312
  ServiceContext,
@@ -6576,8 +7315,12 @@ export {
6576
7315
  isLocked,
6577
7316
  createStorageObjects,
6578
7317
  createLevel,
7318
+ encodeProfileArchive,
7319
+ decodeProfileArchive,
7320
+ exportProfileData,
7321
+ importProfileData,
6579
7322
  ClientServicesHost,
6580
7323
  ClientServicesProviderResource,
6581
7324
  DiagnosticsCollector
6582
7325
  };
6583
- //# sourceMappingURL=chunk-KNGR7BYM.mjs.map
7326
+ //# sourceMappingURL=chunk-IUSAD4RP.mjs.map