@dxos/client-services 0.5.9-main.ea1d25b → 0.5.9-next.728078d

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 (59) hide show
  1. package/dist/lib/browser/{chunk-LKSDZ2AB.mjs → chunk-Q2PH3QCC.mjs} +1264 -817
  2. package/dist/lib/browser/chunk-Q2PH3QCC.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +9 -3
  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 +11 -11
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/{chunk-FBXXJHAL.cjs → chunk-XZHIBOD3.cjs} +1568 -1126
  9. package/dist/lib/node/chunk-XZHIBOD3.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +49 -43
  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 +17 -17
  14. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  15. package/dist/types/src/packlets/identity/default-space-state-machine.d.ts +19 -0
  16. package/dist/types/src/packlets/identity/default-space-state-machine.d.ts.map +1 -0
  17. package/dist/types/src/packlets/identity/identity-service.d.ts +14 -7
  18. package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
  19. package/dist/types/src/packlets/identity/identity.d.ts +4 -1
  20. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  21. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  22. package/dist/types/src/packlets/services/service-host.d.ts +1 -1
  23. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  24. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts +4 -1
  25. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts.map +1 -1
  26. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +5 -3
  27. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  28. package/dist/types/src/packlets/spaces/data-space.d.ts +9 -9
  29. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  30. package/dist/types/src/packlets/spaces/epoch-migrations.d.ts +23 -0
  31. package/dist/types/src/packlets/spaces/epoch-migrations.d.ts.map +1 -0
  32. package/dist/types/src/packlets/spaces/spaces-service.d.ts +2 -2
  33. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  34. package/dist/types/src/packlets/storage/index.d.ts +1 -0
  35. package/dist/types/src/packlets/storage/index.d.ts.map +1 -1
  36. package/dist/types/src/packlets/storage/profile-archive.d.ts +14 -0
  37. package/dist/types/src/packlets/storage/profile-archive.d.ts.map +1 -0
  38. package/dist/types/src/packlets/testing/test-builder.d.ts +8 -6
  39. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  40. package/dist/types/src/version.d.ts +1 -1
  41. package/package.json +36 -36
  42. package/src/packlets/identity/default-space-state-machine.ts +44 -0
  43. package/src/packlets/identity/identity-service.test.ts +35 -5
  44. package/src/packlets/identity/identity-service.ts +76 -8
  45. package/src/packlets/identity/identity.ts +25 -2
  46. package/src/packlets/services/service-context.ts +1 -4
  47. package/src/packlets/services/service-host.ts +13 -40
  48. package/src/packlets/spaces/automerge-space-state.ts +11 -2
  49. package/src/packlets/spaces/data-space-manager.test.ts +46 -1
  50. package/src/packlets/spaces/data-space-manager.ts +81 -31
  51. package/src/packlets/spaces/data-space.ts +85 -152
  52. package/src/packlets/spaces/epoch-migrations.ts +135 -0
  53. package/src/packlets/spaces/spaces-service.ts +16 -4
  54. package/src/packlets/storage/index.ts +1 -0
  55. package/src/packlets/storage/profile-archive.ts +97 -0
  56. package/src/packlets/testing/test-builder.ts +12 -10
  57. package/src/version.ts +1 -1
  58. package/dist/lib/browser/chunk-LKSDZ2AB.mjs.map +0 -7
  59. package/dist/lib/node/chunk-FBXXJHAL.cjs.map +0 -7
@@ -355,7 +355,7 @@ import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
355
355
  import { TRACE_PROCESSOR } from "@dxos/tracing";
356
356
 
357
357
  // packages/sdk/client-services/src/version.ts
358
- var DXOS_VERSION = "0.5.9-main.ea1d25b";
358
+ var DXOS_VERSION = "0.5.9-next.728078d";
359
359
 
360
360
  // packages/sdk/client-services/src/packlets/services/platform.ts
361
361
  import { Platform } from "@dxos/protocols/proto/dxos/client/services";
@@ -803,10 +803,59 @@ import { DeviceStateMachine, createCredentialSignerWithKey, createCredentialSign
803
803
  import { writeMessages } from "@dxos/feed-store";
804
804
  import { invariant as invariant2 } from "@dxos/invariant";
805
805
  import { PublicKey as PublicKey3 } from "@dxos/keys";
806
- import { log as log3 } from "@dxos/log";
806
+ import { log as log4 } from "@dxos/log";
807
807
  import { AdmittedFeed } from "@dxos/protocols/proto/dxos/halo/credentials";
808
+ import { Timeframe } from "@dxos/timeframe";
808
809
  import { trace as trace2 } from "@dxos/tracing";
809
810
  import { ComplexSet } from "@dxos/util";
811
+
812
+ // packages/sdk/client-services/src/packlets/identity/default-space-state-machine.ts
813
+ import { getCredentialAssertion } from "@dxos/credentials";
814
+ import { SpaceId } from "@dxos/keys";
815
+ import { log as log3 } from "@dxos/log";
816
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/default-space-state-machine.ts";
817
+ var DefaultSpaceStateMachine = class {
818
+ constructor(_params) {
819
+ this._params = _params;
820
+ }
821
+ get spaceId() {
822
+ return this._spaceId;
823
+ }
824
+ async processCredential(credential) {
825
+ const assertion = getCredentialAssertion(credential);
826
+ switch (assertion["@type"]) {
827
+ case "dxos.halo.credentials.DefaultSpace": {
828
+ if (!credential.subject.id.equals(this._params.identityKey)) {
829
+ log3.warn("Invalid default space credential", {
830
+ expectedIdentity: this._params.identityKey,
831
+ credential
832
+ }, {
833
+ F: __dxlog_file4,
834
+ L: 32,
835
+ S: this,
836
+ C: (f, a) => f(...a)
837
+ });
838
+ return;
839
+ }
840
+ if (!SpaceId.isValid(assertion.spaceId)) {
841
+ log3.warn("Invalid default space id", {
842
+ id: assertion.spaceId
843
+ }, {
844
+ F: __dxlog_file4,
845
+ L: 36,
846
+ S: this,
847
+ C: (f, a) => f(...a)
848
+ });
849
+ return;
850
+ }
851
+ this._spaceId = assertion.spaceId;
852
+ break;
853
+ }
854
+ }
855
+ }
856
+ };
857
+
858
+ // packages/sdk/client-services/src/packlets/identity/identity.ts
810
859
  function _ts_decorate2(decorators, target, key, desc) {
811
860
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
812
861
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -817,7 +866,7 @@ function _ts_decorate2(decorators, target, key, desc) {
817
866
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
818
867
  return c > 3 && r && Object.defineProperty(target, key, r), r;
819
868
  }
820
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity.ts";
869
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity.ts";
821
870
  var Identity = class {
822
871
  constructor({ space, signer, identityKey, deviceKey, presence }) {
823
872
  this.stateUpdate = new Event();
@@ -826,11 +875,11 @@ var Identity = class {
826
875
  this._presence = presence;
827
876
  this.identityKey = identityKey;
828
877
  this.deviceKey = deviceKey;
829
- log3.trace("dxos.halo.device", {
878
+ log4.trace("dxos.halo.device", {
830
879
  deviceKey
831
880
  }, {
832
- F: __dxlog_file4,
833
- L: 67,
881
+ F: __dxlog_file5,
882
+ L: 70,
834
883
  S: this,
835
884
  C: (f, a) => f(...a)
836
885
  });
@@ -843,6 +892,10 @@ var Identity = class {
843
892
  identityKey: this.identityKey,
844
893
  onUpdate: () => this.stateUpdate.emit()
845
894
  });
895
+ this._defaultSpaceStateMachine = new DefaultSpaceStateMachine({
896
+ identityKey: this.identityKey,
897
+ onUpdate: () => this.stateUpdate.emit()
898
+ });
846
899
  this.authVerifier = new TrustedKeySetAuthVerifier({
847
900
  trustedKeysProvider: () => new ComplexSet(PublicKey3.hash, this.authorizedDeviceKeys.keys()),
848
901
  update: this.stateUpdate,
@@ -853,14 +906,20 @@ var Identity = class {
853
906
  get authorizedDeviceKeys() {
854
907
  return this._deviceStateMachine.authorizedDeviceKeys;
855
908
  }
909
+ get defaultSpaceId() {
910
+ return this._defaultSpaceStateMachine.spaceId;
911
+ }
856
912
  async open(ctx) {
913
+ await this._presence?.open();
857
914
  await this.space.spaceState.addCredentialProcessor(this._deviceStateMachine);
858
915
  await this.space.spaceState.addCredentialProcessor(this._profileStateMachine);
916
+ await this.space.spaceState.addCredentialProcessor(this._defaultSpaceStateMachine);
859
917
  await this.space.open(ctx);
860
918
  }
861
919
  async close(ctx) {
862
- await this._presence?.destroy();
920
+ await this._presence?.close();
863
921
  await this.authVerifier.close();
922
+ await this.space.spaceState.removeCredentialProcessor(this._defaultSpaceStateMachine);
864
923
  await this.space.spaceState.removeCredentialProcessor(this._profileStateMachine);
865
924
  await this.space.spaceState.removeCredentialProcessor(this._deviceStateMachine);
866
925
  await this.space.close();
@@ -898,8 +957,8 @@ var Identity = class {
898
957
  */
899
958
  getIdentityCredentialSigner() {
900
959
  invariant2(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.", {
901
- F: __dxlog_file4,
902
- L: 145,
960
+ F: __dxlog_file5,
961
+ L: 159,
903
962
  S: this,
904
963
  A: [
905
964
  "this._deviceStateMachine.deviceCredentialChain",
@@ -914,16 +973,36 @@ var Identity = class {
914
973
  getDeviceCredentialSigner() {
915
974
  return createCredentialSignerWithKey(this._signer, this.deviceKey);
916
975
  }
976
+ async updateDefaultSpace(spaceId) {
977
+ const credential = await this.getDeviceCredentialSigner().createCredential({
978
+ subject: this.identityKey,
979
+ assertion: {
980
+ "@type": "dxos.halo.credentials.DefaultSpace",
981
+ spaceId
982
+ }
983
+ });
984
+ const receipt = await this.controlPipeline.writer.write({
985
+ credential: {
986
+ credential
987
+ }
988
+ });
989
+ await this.controlPipeline.state.waitUntilTimeframe(new Timeframe([
990
+ [
991
+ receipt.feedKey,
992
+ receipt.seq
993
+ ]
994
+ ]));
995
+ }
917
996
  async admitDevice({ deviceKey, controlFeedKey, dataFeedKey }) {
918
- log3("Admitting device:", {
997
+ log4("Admitting device:", {
919
998
  identityKey: this.identityKey,
920
999
  hostDevice: this.deviceKey,
921
1000
  deviceKey,
922
1001
  controlFeedKey,
923
1002
  dataFeedKey
924
1003
  }, {
925
- F: __dxlog_file4,
926
- L: 161,
1004
+ F: __dxlog_file5,
1005
+ L: 184,
927
1006
  S: this,
928
1007
  C: (f, a) => f(...a)
929
1008
  });
@@ -981,12 +1060,12 @@ import { Context as Context3 } from "@dxos/context";
981
1060
  import { createCredentialSignerWithKey as createCredentialSignerWithKey2, CredentialGenerator } from "@dxos/credentials";
982
1061
  import { invariant as invariant3 } from "@dxos/invariant";
983
1062
  import { PublicKey as PublicKey4 } from "@dxos/keys";
984
- import { log as log4 } from "@dxos/log";
1063
+ import { log as log5 } from "@dxos/log";
985
1064
  import { trace as trace3 } from "@dxos/protocols";
986
1065
  import { Device, DeviceKind } from "@dxos/protocols/proto/dxos/client/services";
987
1066
  import { AdmittedFeed as AdmittedFeed2, DeviceType } from "@dxos/protocols/proto/dxos/halo/credentials";
988
1067
  import { Gossip, Presence } from "@dxos/teleport-extension-gossip";
989
- import { Timeframe } from "@dxos/timeframe";
1068
+ import { Timeframe as Timeframe2 } from "@dxos/timeframe";
990
1069
  import { trace as Trace } from "@dxos/tracing";
991
1070
  import { isNode, deferFunction } from "@dxos/util";
992
1071
  function _ts_decorate3(decorators, target, key, desc) {
@@ -999,7 +1078,7 @@ function _ts_decorate3(decorators, target, key, desc) {
999
1078
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1000
1079
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1001
1080
  }
1002
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-manager.ts";
1081
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-manager.ts";
1003
1082
  var DEVICE_PRESENCE_ANNOUNCE_INTERVAL = 1e4;
1004
1083
  var DEVICE_PRESENCE_OFFLINE_TIMEOUT = 2e4;
1005
1084
  var IdentityManager = class {
@@ -1020,19 +1099,19 @@ var IdentityManager = class {
1020
1099
  }
1021
1100
  async open(ctx) {
1022
1101
  const traceId = PublicKey4.random().toHex();
1023
- log4.trace("dxos.halo.identity-manager.open", trace3.begin({
1102
+ log5.trace("dxos.halo.identity-manager.open", trace3.begin({
1024
1103
  id: traceId
1025
1104
  }), {
1026
- F: __dxlog_file5,
1105
+ F: __dxlog_file6,
1027
1106
  L: 104,
1028
1107
  S: this,
1029
1108
  C: (f, a) => f(...a)
1030
1109
  });
1031
1110
  const identityRecord = this._metadataStore.getIdentityRecord();
1032
- log4("identity record", {
1111
+ log5("identity record", {
1033
1112
  identityRecord
1034
1113
  }, {
1035
- F: __dxlog_file5,
1114
+ F: __dxlog_file6,
1036
1115
  L: 107,
1037
1116
  S: this,
1038
1117
  C: (f, a) => f(...a)
@@ -1041,21 +1120,21 @@ var IdentityManager = class {
1041
1120
  this._identity = await this._constructIdentity(identityRecord);
1042
1121
  await this._identity.open(ctx);
1043
1122
  await this._identity.ready();
1044
- log4.trace("dxos.halo.identity", {
1123
+ log5.trace("dxos.halo.identity", {
1045
1124
  identityKey: identityRecord.identityKey,
1046
1125
  displayName: this._identity.profileDocument?.displayName
1047
1126
  }, {
1048
- F: __dxlog_file5,
1127
+ F: __dxlog_file6,
1049
1128
  L: 112,
1050
1129
  S: this,
1051
1130
  C: (f, a) => f(...a)
1052
1131
  });
1053
1132
  this.stateUpdate.emit();
1054
1133
  }
1055
- log4.trace("dxos.halo.identity-manager.open", trace3.end({
1134
+ log5.trace("dxos.halo.identity-manager.open", trace3.end({
1056
1135
  id: traceId
1057
1136
  }), {
1058
- F: __dxlog_file5,
1137
+ F: __dxlog_file6,
1059
1138
  L: 119,
1060
1139
  S: this,
1061
1140
  C: (f, a) => f(...a)
@@ -1066,7 +1145,7 @@ var IdentityManager = class {
1066
1145
  }
1067
1146
  async createIdentity({ displayName, deviceProfile } = {}) {
1068
1147
  invariant3(!this._identity, "Identity already exists.", {
1069
- F: __dxlog_file5,
1148
+ F: __dxlog_file6,
1070
1149
  L: 128,
1071
1150
  S: this,
1072
1151
  A: [
@@ -1074,8 +1153,8 @@ var IdentityManager = class {
1074
1153
  "'Identity already exists.'"
1075
1154
  ]
1076
1155
  });
1077
- log4("creating identity...", void 0, {
1078
- F: __dxlog_file5,
1156
+ log5("creating identity...", void 0, {
1157
+ F: __dxlog_file6,
1079
1158
  L: 129,
1080
1159
  S: this,
1081
1160
  C: (f, a) => f(...a)
@@ -1096,7 +1175,7 @@ var IdentityManager = class {
1096
1175
  {
1097
1176
  const generator = new CredentialGenerator(this._keyring, identityRecord.identityKey, identityRecord.deviceKey);
1098
1177
  invariant3(identityRecord.haloSpace.genesisFeedKey, "Genesis feed key is required.", {
1099
- F: __dxlog_file5,
1178
+ F: __dxlog_file6,
1100
1179
  L: 148,
1101
1180
  S: this,
1102
1181
  A: [
@@ -1105,7 +1184,7 @@ var IdentityManager = class {
1105
1184
  ]
1106
1185
  });
1107
1186
  invariant3(identityRecord.haloSpace.dataFeedKey, "Data feed key is required.", {
1108
- F: __dxlog_file5,
1187
+ F: __dxlog_file6,
1109
1188
  L: 149,
1110
1189
  S: this,
1111
1190
  A: [
@@ -1140,22 +1219,22 @@ var IdentityManager = class {
1140
1219
  await this._metadataStore.setIdentityRecord(identityRecord);
1141
1220
  this._identity = identity;
1142
1221
  await this._identity.ready();
1143
- log4.trace("dxos.halo.identity", {
1222
+ log5.trace("dxos.halo.identity", {
1144
1223
  identityKey: identityRecord.identityKey,
1145
1224
  displayName: this._identity.profileDocument?.displayName
1146
1225
  }, {
1147
- F: __dxlog_file5,
1226
+ F: __dxlog_file6,
1148
1227
  L: 191,
1149
1228
  S: this,
1150
1229
  C: (f, a) => f(...a)
1151
1230
  });
1152
1231
  this.stateUpdate.emit();
1153
- log4("created identity", {
1232
+ log5("created identity", {
1154
1233
  identityKey: identity.identityKey,
1155
1234
  deviceKey: identity.deviceKey,
1156
1235
  profile: identity.profileDocument
1157
1236
  }, {
1158
- F: __dxlog_file5,
1237
+ F: __dxlog_file6,
1159
1238
  L: 197,
1160
1239
  S: this,
1161
1240
  C: (f, a) => f(...a)
@@ -1189,16 +1268,16 @@ var IdentityManager = class {
1189
1268
  * Accept an existing identity. Expects its device key to be authorized (now or later).
1190
1269
  */
1191
1270
  async acceptIdentity(params) {
1192
- log4("accepting identity", {
1271
+ log5("accepting identity", {
1193
1272
  params
1194
1273
  }, {
1195
- F: __dxlog_file5,
1274
+ F: __dxlog_file6,
1196
1275
  L: 235,
1197
1276
  S: this,
1198
1277
  C: (f, a) => f(...a)
1199
1278
  });
1200
1279
  invariant3(!this._identity, "Identity already exists.", {
1201
- F: __dxlog_file5,
1280
+ F: __dxlog_file6,
1202
1281
  L: 236,
1203
1282
  S: this,
1204
1283
  A: [
@@ -1222,11 +1301,11 @@ var IdentityManager = class {
1222
1301
  this._identity = identity;
1223
1302
  await this._metadataStore.setIdentityRecord(identityRecord);
1224
1303
  await this._identity.ready();
1225
- log4.trace("dxos.halo.identity", {
1304
+ log5.trace("dxos.halo.identity", {
1226
1305
  identityKey: identityRecord.identityKey,
1227
1306
  displayName: this._identity.profileDocument?.displayName
1228
1307
  }, {
1229
- F: __dxlog_file5,
1308
+ F: __dxlog_file6,
1230
1309
  L: 255,
1231
1310
  S: this,
1232
1311
  C: (f, a) => f(...a)
@@ -1236,11 +1315,11 @@ var IdentityManager = class {
1236
1315
  ...params.deviceProfile
1237
1316
  });
1238
1317
  this.stateUpdate.emit();
1239
- log4("accepted identity", {
1318
+ log5("accepted identity", {
1240
1319
  identityKey: identity.identityKey,
1241
1320
  deviceKey: identity.deviceKey
1242
1321
  }, {
1243
- F: __dxlog_file5,
1322
+ F: __dxlog_file6,
1244
1323
  L: 265,
1245
1324
  S: this,
1246
1325
  C: (f, a) => f(...a)
@@ -1252,7 +1331,7 @@ var IdentityManager = class {
1252
1331
  */
1253
1332
  async updateProfile(profile) {
1254
1333
  invariant3(this._identity, "Identity not initialized.", {
1255
- F: __dxlog_file5,
1334
+ F: __dxlog_file6,
1256
1335
  L: 273,
1257
1336
  S: this,
1258
1337
  A: [
@@ -1272,7 +1351,7 @@ var IdentityManager = class {
1272
1351
  credential
1273
1352
  }
1274
1353
  });
1275
- await this._identity.controlPipeline.state.waitUntilTimeframe(new Timeframe([
1354
+ await this._identity.controlPipeline.state.waitUntilTimeframe(new Timeframe2([
1276
1355
  [
1277
1356
  receipt.feedKey,
1278
1357
  receipt.seq
@@ -1283,7 +1362,7 @@ var IdentityManager = class {
1283
1362
  }
1284
1363
  async updateDeviceProfile(profile) {
1285
1364
  invariant3(this._identity, "Identity not initialized.", {
1286
- F: __dxlog_file5,
1365
+ F: __dxlog_file6,
1287
1366
  L: 290,
1288
1367
  S: this,
1289
1368
  A: [
@@ -1303,7 +1382,7 @@ var IdentityManager = class {
1303
1382
  credential
1304
1383
  }
1305
1384
  });
1306
- await this._identity.controlPipeline.state.waitUntilTimeframe(new Timeframe([
1385
+ await this._identity.controlPipeline.state.waitUntilTimeframe(new Timeframe2([
1307
1386
  [
1308
1387
  receipt.feedKey,
1309
1388
  receipt.seq
@@ -1319,7 +1398,7 @@ var IdentityManager = class {
1319
1398
  }
1320
1399
  async _constructIdentity(identityRecord) {
1321
1400
  invariant3(!this._identity, void 0, {
1322
- F: __dxlog_file5,
1401
+ F: __dxlog_file6,
1323
1402
  L: 316,
1324
1403
  S: this,
1325
1404
  A: [
@@ -1327,10 +1406,10 @@ var IdentityManager = class {
1327
1406
  ""
1328
1407
  ]
1329
1408
  });
1330
- log4("constructing identity", {
1409
+ log5("constructing identity", {
1331
1410
  identityRecord
1332
1411
  }, {
1333
- F: __dxlog_file5,
1412
+ F: __dxlog_file6,
1334
1413
  L: 317,
1335
1414
  S: this,
1336
1415
  C: (f, a) => f(...a)
@@ -1345,7 +1424,7 @@ var IdentityManager = class {
1345
1424
  gossip
1346
1425
  });
1347
1426
  invariant3(identityRecord.haloSpace.controlFeedKey, void 0, {
1348
- F: __dxlog_file5,
1427
+ F: __dxlog_file6,
1349
1428
  L: 330,
1350
1429
  S: this,
1351
1430
  A: [
@@ -1357,7 +1436,7 @@ var IdentityManager = class {
1357
1436
  writable: true
1358
1437
  });
1359
1438
  invariant3(identityRecord.haloSpace.dataFeedKey, void 0, {
1360
- F: __dxlog_file5,
1439
+ F: __dxlog_file6,
1361
1440
  L: 334,
1362
1441
  S: this,
1363
1442
  A: [
@@ -1388,10 +1467,10 @@ var IdentityManager = class {
1388
1467
  identityKey: identityRecord.identityKey,
1389
1468
  deviceKey: identityRecord.deviceKey
1390
1469
  });
1391
- log4("done", {
1470
+ log5("done", {
1392
1471
  identityKey: identityRecord.identityKey
1393
1472
  }, {
1394
- F: __dxlog_file5,
1473
+ F: __dxlog_file6,
1395
1474
  L: 360,
1396
1475
  S: this,
1397
1476
  C: (f, a) => f(...a)
@@ -1415,8 +1494,8 @@ var IdentityManager = class {
1415
1494
  }));
1416
1495
  },
1417
1496
  onAuthFailure: () => {
1418
- log4.warn("auth failure", void 0, {
1419
- F: __dxlog_file5,
1497
+ log5.warn("auth failure", void 0, {
1498
+ F: __dxlog_file6,
1420
1499
  L: 385,
1421
1500
  S: this,
1422
1501
  C: (f, a) => f(...a)
@@ -1440,25 +1519,55 @@ IdentityManager = _ts_decorate3([
1440
1519
  ], IdentityManager);
1441
1520
 
1442
1521
  // packages/sdk/client-services/src/packlets/identity/identity-service.ts
1522
+ import { Trigger as Trigger3, sleep } from "@dxos/async";
1443
1523
  import { Stream as Stream8 } from "@dxos/codec-protobuf";
1524
+ import { Resource } from "@dxos/context";
1444
1525
  import { signPresentation } from "@dxos/credentials";
1445
1526
  import { todo } from "@dxos/debug";
1446
1527
  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;
1528
+ import { log as log6 } from "@dxos/log";
1529
+ import { SpaceState } from "@dxos/protocols/proto/dxos/client/services";
1530
+ import { safeAwaitAll } from "@dxos/util";
1531
+ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
1532
+ var DEFAULT_SPACE_SEARCH_TIMEOUT = 1e4;
1533
+ var IdentityServiceImpl = class extends Resource {
1534
+ constructor(_identityManager, _keyring, _dataSpaceManagerProvider, _createIdentity, _onProfileUpdate) {
1535
+ super();
1451
1536
  this._identityManager = _identityManager;
1452
1537
  this._keyring = _keyring;
1538
+ this._dataSpaceManagerProvider = _dataSpaceManagerProvider;
1539
+ this._createIdentity = _createIdentity;
1453
1540
  this._onProfileUpdate = _onProfileUpdate;
1454
1541
  }
1542
+ async _open() {
1543
+ const identity = this._identityManager.identity;
1544
+ if (identity && !identity.defaultSpaceId) {
1545
+ await this._fixIdentityWithoutDefaultSpace(identity);
1546
+ }
1547
+ }
1455
1548
  async createIdentity(request) {
1456
1549
  await this._createIdentity({
1457
1550
  displayName: request.profile?.displayName,
1458
1551
  deviceProfile: request.deviceProfile
1459
1552
  });
1553
+ const dataSpaceManager = this._dataSpaceManagerProvider();
1554
+ await this._createDefaultSpace(dataSpaceManager);
1460
1555
  return this._getIdentity();
1461
1556
  }
1557
+ async _createDefaultSpace(dataSpaceManager) {
1558
+ const space = await dataSpaceManager.createDefaultSpace();
1559
+ const identity = this._identityManager.identity;
1560
+ invariant4(identity, void 0, {
1561
+ F: __dxlog_file7,
1562
+ L: 59,
1563
+ S: this,
1564
+ A: [
1565
+ "identity",
1566
+ ""
1567
+ ]
1568
+ });
1569
+ await identity.updateDefaultSpace(space.id);
1570
+ }
1462
1571
  async recoverIdentity(request) {
1463
1572
  return todo();
1464
1573
  }
@@ -1483,8 +1592,8 @@ var IdentityServiceImpl = class {
1483
1592
  }
1484
1593
  async updateProfile(profile) {
1485
1594
  invariant4(this._identityManager.identity, "Identity not initialized.", {
1486
- F: __dxlog_file6,
1487
- L: 61,
1595
+ F: __dxlog_file7,
1596
+ L: 89,
1488
1597
  S: this,
1489
1598
  A: [
1490
1599
  "this._identityManager.identity",
@@ -1497,8 +1606,8 @@ var IdentityServiceImpl = class {
1497
1606
  }
1498
1607
  async signPresentation({ presentation, nonce }) {
1499
1608
  invariant4(this._identityManager.identity, "Identity not initialized.", {
1500
- F: __dxlog_file6,
1501
- L: 68,
1609
+ F: __dxlog_file7,
1610
+ L: 96,
1502
1611
  S: this,
1503
1612
  A: [
1504
1613
  "this._identityManager.identity",
@@ -1513,13 +1622,54 @@ var IdentityServiceImpl = class {
1513
1622
  nonce
1514
1623
  });
1515
1624
  }
1625
+ async _fixIdentityWithoutDefaultSpace(identity) {
1626
+ let recodedDefaultSpace = false;
1627
+ let foundDefaultSpace = false;
1628
+ const dataSpaceManager = this._dataSpaceManagerProvider();
1629
+ const recordedDefaultSpaceTrigger = new Trigger3();
1630
+ const allProcessed = safeAwaitAll(dataSpaceManager.spaces.values(), async (space) => {
1631
+ if (space.state === SpaceState.CLOSED) {
1632
+ await space.open();
1633
+ const requiresMigration = space.stateUpdate.waitForCondition(() => space.state === SpaceState.REQUIRES_MIGRATION);
1634
+ await Promise.race([
1635
+ space.initializeDataPipeline(),
1636
+ requiresMigration
1637
+ ]);
1638
+ }
1639
+ if (await dataSpaceManager.isDefaultSpace(space)) {
1640
+ if (foundDefaultSpace) {
1641
+ log6.warn("Multiple default spaces found. Using the first one.", {
1642
+ duplicate: space.id
1643
+ }, {
1644
+ F: __dxlog_file7,
1645
+ L: 127,
1646
+ S: this,
1647
+ C: (f, a) => f(...a)
1648
+ });
1649
+ return;
1650
+ }
1651
+ foundDefaultSpace = true;
1652
+ await identity.updateDefaultSpace(space.id);
1653
+ recodedDefaultSpace = true;
1654
+ recordedDefaultSpaceTrigger.wake();
1655
+ }
1656
+ });
1657
+ await Promise.race([
1658
+ allProcessed,
1659
+ recordedDefaultSpaceTrigger.wait(),
1660
+ sleep(DEFAULT_SPACE_SEARCH_TIMEOUT)
1661
+ ]);
1662
+ if (!recodedDefaultSpace) {
1663
+ await this._createDefaultSpace(dataSpaceManager);
1664
+ }
1665
+ }
1516
1666
  };
1517
1667
 
1518
1668
  // packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts
1519
1669
  import { invariant as invariant5 } from "@dxos/invariant";
1520
1670
  import { AlreadyJoinedError } from "@dxos/protocols";
1521
1671
  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";
1672
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts";
1523
1673
  var DeviceInvitationProtocol = class {
1524
1674
  constructor(_keyring, _getIdentity, _acceptIdentity) {
1525
1675
  this._keyring = _keyring;
@@ -1545,7 +1695,7 @@ var DeviceInvitationProtocol = class {
1545
1695
  }
1546
1696
  async admit(_, request) {
1547
1697
  invariant5(request.device, void 0, {
1548
- F: __dxlog_file7,
1698
+ F: __dxlog_file8,
1549
1699
  L: 50,
1550
1700
  S: this,
1551
1701
  A: [
@@ -1591,7 +1741,7 @@ var DeviceInvitationProtocol = class {
1591
1741
  }
1592
1742
  async accept(response, request) {
1593
1743
  invariant5(response.device, void 0, {
1594
- F: __dxlog_file7,
1744
+ F: __dxlog_file8,
1595
1745
  L: 95,
1596
1746
  S: this,
1597
1747
  A: [
@@ -1601,7 +1751,7 @@ var DeviceInvitationProtocol = class {
1601
1751
  });
1602
1752
  const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
1603
1753
  invariant5(request.device, void 0, {
1604
- F: __dxlog_file7,
1754
+ F: __dxlog_file8,
1605
1755
  L: 98,
1606
1756
  S: this,
1607
1757
  A: [
@@ -1633,7 +1783,7 @@ import { ContextDisposedError as ContextDisposedError2 } from "@dxos/context";
1633
1783
  import { createKeyPair, sign } from "@dxos/crypto";
1634
1784
  import { invariant as invariant9 } from "@dxos/invariant";
1635
1785
  import { PublicKey as PublicKey7 } from "@dxos/keys";
1636
- import { log as log8 } from "@dxos/log";
1786
+ import { log as log10 } from "@dxos/log";
1637
1787
  import { createTeleportProtocolFactory } from "@dxos/network-manager";
1638
1788
  import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError3, trace as trace5 } from "@dxos/protocols";
1639
1789
  import { Invitation as Invitation4 } from "@dxos/protocols/proto/dxos/client/services";
@@ -1642,10 +1792,10 @@ import { Options as Options4 } from "@dxos/protocols/proto/dxos/halo/invitations
1642
1792
  import { ComplexSet as ComplexSet3 } from "@dxos/util";
1643
1793
 
1644
1794
  // packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts
1645
- import { Trigger as Trigger3 } from "@dxos/async";
1795
+ import { Trigger as Trigger4 } from "@dxos/async";
1646
1796
  import { cancelWithContext as cancelWithContext2, Context as Context4 } from "@dxos/context";
1647
1797
  import { invariant as invariant6 } from "@dxos/invariant";
1648
- import { log as log5 } from "@dxos/log";
1798
+ import { log as log7 } from "@dxos/log";
1649
1799
  import { InvalidInvitationExtensionRoleError, schema as schema2 } from "@dxos/protocols";
1650
1800
  import { Options } from "@dxos/protocols/proto/dxos/halo/invitations";
1651
1801
  import { RpcExtension } from "@dxos/teleport";
@@ -1670,7 +1820,7 @@ var tryAcquireBeforeContextDisposed = async (ctx, mutex) => {
1670
1820
  };
1671
1821
 
1672
1822
  // 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";
1823
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts";
1674
1824
  var OPTIONS_TIMEOUT = 1e4;
1675
1825
  var InvitationGuestExtension = class extends RpcExtension {
1676
1826
  constructor(_invitationFlowMutex, _callbacks) {
@@ -1685,7 +1835,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1685
1835
  this._invitationFlowMutex = _invitationFlowMutex;
1686
1836
  this._callbacks = _callbacks;
1687
1837
  this._ctx = new Context4();
1688
- this._remoteOptionsTrigger = new Trigger3();
1838
+ this._remoteOptionsTrigger = new Trigger4();
1689
1839
  this._invitationFlowLock = null;
1690
1840
  }
1691
1841
  hasFlowLock() {
@@ -1696,7 +1846,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1696
1846
  InvitationHostService: {
1697
1847
  options: async (options) => {
1698
1848
  invariant6(!this._remoteOptions, "Remote options already set.", {
1699
- F: __dxlog_file8,
1849
+ F: __dxlog_file9,
1700
1850
  L: 63,
1701
1851
  S: this,
1702
1852
  A: [
@@ -1722,15 +1872,15 @@ var InvitationGuestExtension = class extends RpcExtension {
1722
1872
  async onOpen(context) {
1723
1873
  await super.onOpen(context);
1724
1874
  try {
1725
- log5("guest acquire lock", void 0, {
1726
- F: __dxlog_file8,
1875
+ log7("guest acquire lock", void 0, {
1876
+ F: __dxlog_file9,
1727
1877
  L: 84,
1728
1878
  S: this,
1729
1879
  C: (f, a) => f(...a)
1730
1880
  });
1731
1881
  this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
1732
- log5("guest lock acquired", void 0, {
1733
- F: __dxlog_file8,
1882
+ log7("guest lock acquired", void 0, {
1883
+ F: __dxlog_file9,
1734
1884
  L: 86,
1735
1885
  S: this,
1736
1886
  C: (f, a) => f(...a)
@@ -1738,8 +1888,8 @@ var InvitationGuestExtension = class extends RpcExtension {
1738
1888
  await cancelWithContext2(this._ctx, this.rpc.InvitationHostService.options({
1739
1889
  role: Options.Role.GUEST
1740
1890
  }));
1741
- log5("options sent", void 0, {
1742
- F: __dxlog_file8,
1891
+ log7("options sent", void 0, {
1892
+ F: __dxlog_file9,
1743
1893
  L: 88,
1744
1894
  S: this,
1745
1895
  C: (f, a) => f(...a)
@@ -1747,8 +1897,8 @@ var InvitationGuestExtension = class extends RpcExtension {
1747
1897
  await cancelWithContext2(this._ctx, this._remoteOptionsTrigger.wait({
1748
1898
  timeout: OPTIONS_TIMEOUT
1749
1899
  }));
1750
- log5("options received", void 0, {
1751
- F: __dxlog_file8,
1900
+ log7("options received", void 0, {
1901
+ F: __dxlog_file9,
1752
1902
  L: 90,
1753
1903
  S: this,
1754
1904
  C: (f, a) => f(...a)
@@ -1781,8 +1931,8 @@ var InvitationGuestExtension = class extends RpcExtension {
1781
1931
  if (this._invitationFlowLock != null) {
1782
1932
  this._invitationFlowLock.release();
1783
1933
  this._invitationFlowLock = null;
1784
- log5("invitation flow lock released", void 0, {
1785
- F: __dxlog_file8,
1934
+ log7("invitation flow lock released", void 0, {
1935
+ F: __dxlog_file9,
1786
1936
  L: 123,
1787
1937
  S: this,
1788
1938
  C: (f, a) => f(...a)
@@ -1792,17 +1942,17 @@ var InvitationGuestExtension = class extends RpcExtension {
1792
1942
  };
1793
1943
 
1794
1944
  // packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts
1795
- import { Trigger as Trigger4, scheduleTask as scheduleTask2 } from "@dxos/async";
1945
+ import { Trigger as Trigger5, scheduleTask as scheduleTask2 } from "@dxos/async";
1796
1946
  import { cancelWithContext as cancelWithContext3, Context as Context5 } from "@dxos/context";
1797
1947
  import { randomBytes, verify } from "@dxos/crypto";
1798
1948
  import { invariant as invariant7, InvariantViolation } from "@dxos/invariant";
1799
1949
  import { PublicKey as PublicKey5 } from "@dxos/keys";
1800
- import { log as log6 } from "@dxos/log";
1950
+ import { log as log8 } from "@dxos/log";
1801
1951
  import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError2, schema as schema3, trace as trace4 } from "@dxos/protocols";
1802
1952
  import { Invitation as Invitation3 } from "@dxos/protocols/proto/dxos/client/services";
1803
1953
  import { AuthenticationResponse, Options as Options2 } from "@dxos/protocols/proto/dxos/halo/invitations";
1804
1954
  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";
1955
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts";
1806
1956
  var OPTIONS_TIMEOUT2 = 1e4;
1807
1957
  var MAX_OTP_ATTEMPTS = 3;
1808
1958
  var InvitationHostExtension = class extends RpcExtension2 {
@@ -1818,12 +1968,12 @@ var InvitationHostExtension = class extends RpcExtension2 {
1818
1968
  this._invitationFlowMutex = _invitationFlowMutex;
1819
1969
  this._callbacks = _callbacks;
1820
1970
  this._ctx = new Context5();
1821
- this._remoteOptionsTrigger = new Trigger4();
1971
+ this._remoteOptionsTrigger = new Trigger5();
1822
1972
  this._challenge = void 0;
1823
1973
  this.guestProfile = void 0;
1824
1974
  this.authenticationPassed = false;
1825
1975
  this.authenticationRetry = 0;
1826
- this.completedTrigger = new Trigger4();
1976
+ this.completedTrigger = new Trigger5();
1827
1977
  this._invitationFlowLock = null;
1828
1978
  }
1829
1979
  hasFlowLock() {
@@ -1836,7 +1986,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
1836
1986
  InvitationHostService: {
1837
1987
  options: async (options) => {
1838
1988
  invariant7(!this._remoteOptions, "Remote options already set.", {
1839
- F: __dxlog_file9,
1989
+ F: __dxlog_file10,
1840
1990
  L: 101,
1841
1991
  S: this,
1842
1992
  A: [
@@ -1850,10 +2000,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
1850
2000
  introduce: async (request) => {
1851
2001
  const { profile, invitationId } = request;
1852
2002
  const traceId = PublicKey5.random().toHex();
1853
- log6.trace("dxos.sdk.invitation-handler.host.introduce", trace4.begin({
2003
+ log8.trace("dxos.sdk.invitation-handler.host.introduce", trace4.begin({
1854
2004
  id: traceId
1855
2005
  }), {
1856
- F: __dxlog_file9,
2006
+ F: __dxlog_file10,
1857
2007
  L: 110,
1858
2008
  S: this,
1859
2009
  C: (f, a) => f(...a)
@@ -1861,11 +2011,11 @@ var InvitationHostExtension = class extends RpcExtension2 {
1861
2011
  const invitation = this._requireActiveInvitation();
1862
2012
  this._assertInvitationState(Invitation3.State.CONNECTED);
1863
2013
  if (invitationId !== invitation?.invitationId) {
1864
- log6.warn("incorrect invitationId", {
2014
+ log8.warn("incorrect invitationId", {
1865
2015
  expected: invitation.invitationId,
1866
2016
  actual: invitationId
1867
2017
  }, {
1868
- F: __dxlog_file9,
2018
+ F: __dxlog_file10,
1869
2019
  L: 116,
1870
2020
  S: this,
1871
2021
  C: (f, a) => f(...a)
@@ -1876,10 +2026,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
1876
2026
  authMethod: Invitation3.AuthMethod.NONE
1877
2027
  };
1878
2028
  }
1879
- log6("guest introduced themselves", {
2029
+ log8("guest introduced themselves", {
1880
2030
  guestProfile: profile
1881
2031
  }, {
1882
- F: __dxlog_file9,
2032
+ F: __dxlog_file10,
1883
2033
  L: 125,
1884
2034
  S: this,
1885
2035
  C: (f, a) => f(...a)
@@ -1887,10 +2037,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
1887
2037
  this.guestProfile = profile;
1888
2038
  this._callbacks.onStateUpdate(Invitation3.State.READY_FOR_AUTHENTICATION);
1889
2039
  this._challenge = invitation.authMethod === Invitation3.AuthMethod.KNOWN_PUBLIC_KEY ? randomBytes(32) : void 0;
1890
- log6.trace("dxos.sdk.invitation-handler.host.introduce", trace4.end({
2040
+ log8.trace("dxos.sdk.invitation-handler.host.introduce", trace4.end({
1891
2041
  id: traceId
1892
2042
  }), {
1893
- F: __dxlog_file9,
2043
+ F: __dxlog_file10,
1894
2044
  L: 132,
1895
2045
  S: this,
1896
2046
  C: (f, a) => f(...a)
@@ -1902,19 +2052,19 @@ var InvitationHostExtension = class extends RpcExtension2 {
1902
2052
  },
1903
2053
  authenticate: async ({ authCode: code, signedChallenge }) => {
1904
2054
  const traceId = PublicKey5.random().toHex();
1905
- log6.trace("dxos.sdk.invitation-handler.host.authenticate", trace4.begin({
2055
+ log8.trace("dxos.sdk.invitation-handler.host.authenticate", trace4.begin({
1906
2056
  id: traceId
1907
2057
  }), {
1908
- F: __dxlog_file9,
2058
+ F: __dxlog_file10,
1909
2059
  L: 141,
1910
2060
  S: this,
1911
2061
  C: (f, a) => f(...a)
1912
2062
  });
1913
2063
  const invitation = this._requireActiveInvitation();
1914
- log6("received authentication request", {
2064
+ log8("received authentication request", {
1915
2065
  authCode: code
1916
2066
  }, {
1917
- F: __dxlog_file9,
2067
+ F: __dxlog_file10,
1918
2068
  L: 144,
1919
2069
  S: this,
1920
2070
  C: (f, a) => f(...a)
@@ -1927,8 +2077,8 @@ var InvitationHostExtension = class extends RpcExtension2 {
1927
2077
  this._callbacks.onStateUpdate(Invitation3.State.AUTHENTICATING);
1928
2078
  switch (invitation.authMethod) {
1929
2079
  case Invitation3.AuthMethod.NONE: {
1930
- log6("authentication not required", void 0, {
1931
- F: __dxlog_file9,
2080
+ log8("authentication not required", void 0, {
2081
+ F: __dxlog_file10,
1932
2082
  L: 152,
1933
2083
  S: this,
1934
2084
  C: (f, a) => f(...a)
@@ -1963,10 +2113,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
1963
2113
  break;
1964
2114
  }
1965
2115
  default: {
1966
- log6.error("invalid authentication method", {
2116
+ log8.error("invalid authentication method", {
1967
2117
  authMethod: invitation.authMethod
1968
2118
  }, {
1969
- F: __dxlog_file9,
2119
+ F: __dxlog_file10,
1970
2120
  L: 190,
1971
2121
  S: this,
1972
2122
  C: (f, a) => f(...a)
@@ -1985,13 +2135,13 @@ var InvitationHostExtension = class extends RpcExtension2 {
1985
2135
  status
1986
2136
  };
1987
2137
  }
1988
- log6.trace("dxos.sdk.invitation-handler.host.authenticate", trace4.end({
2138
+ log8.trace("dxos.sdk.invitation-handler.host.authenticate", trace4.end({
1989
2139
  id: traceId,
1990
2140
  data: {
1991
2141
  status
1992
2142
  }
1993
2143
  }), {
1994
- F: __dxlog_file9,
2144
+ F: __dxlog_file10,
1995
2145
  L: 202,
1996
2146
  S: this,
1997
2147
  C: (f, a) => f(...a)
@@ -2002,10 +2152,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
2002
2152
  },
2003
2153
  admit: async (request) => {
2004
2154
  const traceId = PublicKey5.random().toHex();
2005
- log6.trace("dxos.sdk.invitation-handler.host.admit", trace4.begin({
2155
+ log8.trace("dxos.sdk.invitation-handler.host.admit", trace4.begin({
2006
2156
  id: traceId
2007
2157
  }), {
2008
- F: __dxlog_file9,
2158
+ F: __dxlog_file10,
2009
2159
  L: 208,
2010
2160
  S: this,
2011
2161
  C: (f, a) => f(...a)
@@ -2019,10 +2169,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
2019
2169
  }
2020
2170
  }
2021
2171
  const response = await this._callbacks.admit(request);
2022
- log6.trace("dxos.sdk.invitation-handler.host.admit", trace4.end({
2172
+ log8.trace("dxos.sdk.invitation-handler.host.admit", trace4.end({
2023
2173
  id: traceId
2024
2174
  }), {
2025
- F: __dxlog_file9,
2175
+ F: __dxlog_file10,
2026
2176
  L: 222,
2027
2177
  S: this,
2028
2178
  C: (f, a) => f(...a)
@@ -2039,15 +2189,15 @@ var InvitationHostExtension = class extends RpcExtension2 {
2039
2189
  async onOpen(context) {
2040
2190
  await super.onOpen(context);
2041
2191
  try {
2042
- log6("host acquire lock", void 0, {
2043
- F: __dxlog_file9,
2192
+ log8("host acquire lock", void 0, {
2193
+ F: __dxlog_file10,
2044
2194
  L: 237,
2045
2195
  S: this,
2046
2196
  C: (f, a) => f(...a)
2047
2197
  });
2048
2198
  this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
2049
- log6("host lock acquired", void 0, {
2050
- F: __dxlog_file9,
2199
+ log8("host lock acquired", void 0, {
2200
+ F: __dxlog_file10,
2051
2201
  L: 239,
2052
2202
  S: this,
2053
2203
  C: (f, a) => f(...a)
@@ -2057,8 +2207,8 @@ var InvitationHostExtension = class extends RpcExtension2 {
2057
2207
  await this.rpc.InvitationHostService.options({
2058
2208
  role: Options2.Role.HOST
2059
2209
  });
2060
- log6("options sent", void 0, {
2061
- F: __dxlog_file9,
2210
+ log8("options sent", void 0, {
2211
+ F: __dxlog_file10,
2062
2212
  L: 243,
2063
2213
  S: this,
2064
2214
  C: (f, a) => f(...a)
@@ -2066,8 +2216,8 @@ var InvitationHostExtension = class extends RpcExtension2 {
2066
2216
  await cancelWithContext3(this._ctx, this._remoteOptionsTrigger.wait({
2067
2217
  timeout: OPTIONS_TIMEOUT2
2068
2218
  }));
2069
- log6("options received", void 0, {
2070
- F: __dxlog_file9,
2219
+ log8("options received", void 0, {
2220
+ F: __dxlog_file10,
2071
2221
  L: 245,
2072
2222
  S: this,
2073
2223
  C: (f, a) => f(...a)
@@ -2120,8 +2270,8 @@ var InvitationHostExtension = class extends RpcExtension2 {
2120
2270
  if (this._invitationFlowLock != null) {
2121
2271
  this._invitationFlowLock?.release();
2122
2272
  this._invitationFlowLock = null;
2123
- log6("invitation flow lock released", void 0, {
2124
- F: __dxlog_file9,
2273
+ log8("invitation flow lock released", void 0, {
2274
+ F: __dxlog_file10,
2125
2275
  L: 300,
2126
2276
  S: this,
2127
2277
  C: (f, a) => f(...a)
@@ -2134,10 +2284,10 @@ var isAuthenticationRequired = (invitation) => invitation.authMethod !== Invitat
2134
2284
  // packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts
2135
2285
  import { invariant as invariant8 } from "@dxos/invariant";
2136
2286
  import { PublicKey as PublicKey6 } from "@dxos/keys";
2137
- import { log as log7 } from "@dxos/log";
2287
+ import { log as log9 } from "@dxos/log";
2138
2288
  import { Options as Options3 } from "@dxos/protocols/proto/dxos/halo/invitations";
2139
2289
  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";
2290
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts";
2141
2291
  var InvitationTopology = class {
2142
2292
  constructor(_role) {
2143
2293
  this._role = _role;
@@ -2145,7 +2295,7 @@ var InvitationTopology = class {
2145
2295
  }
2146
2296
  init(controller) {
2147
2297
  invariant8(!this._controller, "Already initialized.", {
2148
- F: __dxlog_file10,
2298
+ F: __dxlog_file11,
2149
2299
  L: 42,
2150
2300
  S: this,
2151
2301
  A: [
@@ -2157,7 +2307,7 @@ var InvitationTopology = class {
2157
2307
  }
2158
2308
  update() {
2159
2309
  invariant8(this._controller, "Not initialized.", {
2160
- F: __dxlog_file10,
2310
+ F: __dxlog_file11,
2161
2311
  L: 47,
2162
2312
  S: this,
2163
2313
  A: [
@@ -2176,11 +2326,11 @@ var InvitationTopology = class {
2176
2326
  const firstUnknownPeer = candidates.find((peerId) => !this._seenPeers.has(peerId));
2177
2327
  this._seenPeers = new ComplexSet2(PublicKey6.hash, allPeers.filter((peerId) => this._seenPeers.has(peerId)));
2178
2328
  if (firstUnknownPeer != null) {
2179
- log7("invitation connect", {
2329
+ log9("invitation connect", {
2180
2330
  ownPeerId,
2181
2331
  remotePeerId: firstUnknownPeer
2182
2332
  }, {
2183
- F: __dxlog_file10,
2333
+ F: __dxlog_file11,
2184
2334
  L: 69,
2185
2335
  S: this,
2186
2336
  C: (f, a) => f(...a)
@@ -2191,7 +2341,7 @@ var InvitationTopology = class {
2191
2341
  }
2192
2342
  async onOffer(peer) {
2193
2343
  invariant8(this._controller, "Not initialized.", {
2194
- F: __dxlog_file10,
2344
+ F: __dxlog_file11,
2195
2345
  L: 76,
2196
2346
  S: this,
2197
2347
  A: [
@@ -2210,7 +2360,7 @@ var InvitationTopology = class {
2210
2360
  };
2211
2361
 
2212
2362
  // 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";
2363
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts";
2214
2364
  var MAX_DELEGATED_INVITATION_HOST_TRIES = 3;
2215
2365
  var InvitationsHandler = class {
2216
2366
  /**
@@ -2235,7 +2385,7 @@ var InvitationsHandler = class {
2235
2385
  try {
2236
2386
  const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
2237
2387
  invariant9(deviceKey, void 0, {
2238
- F: __dxlog_file11,
2388
+ F: __dxlog_file12,
2239
2389
  L: 90,
2240
2390
  S: this,
2241
2391
  A: [
@@ -2261,18 +2411,18 @@ var InvitationsHandler = class {
2261
2411
  scheduleTask3(connectionCtx, async () => {
2262
2412
  const traceId = PublicKey7.random().toHex();
2263
2413
  try {
2264
- log8.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.begin({
2414
+ log10.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.begin({
2265
2415
  id: traceId
2266
2416
  }), {
2267
- F: __dxlog_file11,
2417
+ F: __dxlog_file12,
2268
2418
  L: 115,
2269
2419
  S: this,
2270
2420
  C: (f, a) => f(...a)
2271
2421
  });
2272
- log8("connected", {
2422
+ log10("connected", {
2273
2423
  ...protocol.toJSON()
2274
2424
  }, {
2275
- F: __dxlog_file11,
2425
+ F: __dxlog_file12,
2276
2426
  L: 116,
2277
2427
  S: this,
2278
2428
  C: (f, a) => f(...a)
@@ -2280,20 +2430,20 @@ var InvitationsHandler = class {
2280
2430
  const deviceKey = await extension.completedTrigger.wait({
2281
2431
  timeout: invitation.timeout
2282
2432
  });
2283
- log8("admitted guest", {
2433
+ log10("admitted guest", {
2284
2434
  guest: deviceKey,
2285
2435
  ...protocol.toJSON()
2286
2436
  }, {
2287
- F: __dxlog_file11,
2437
+ F: __dxlog_file12,
2288
2438
  L: 118,
2289
2439
  S: this,
2290
2440
  C: (f, a) => f(...a)
2291
2441
  });
2292
2442
  guardedState.set(extension, Invitation4.State.SUCCESS);
2293
- log8.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.end({
2443
+ log10.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.end({
2294
2444
  id: traceId
2295
2445
  }), {
2296
- F: __dxlog_file11,
2446
+ F: __dxlog_file12,
2297
2447
  L: 120,
2298
2448
  S: this,
2299
2449
  C: (f, a) => f(...a)
@@ -2305,10 +2455,10 @@ var InvitationsHandler = class {
2305
2455
  } catch (err) {
2306
2456
  if (err instanceof TimeoutError) {
2307
2457
  if (guardedState.set(extension, Invitation4.State.TIMEOUT)) {
2308
- log8("timeout", {
2458
+ log10("timeout", {
2309
2459
  ...protocol.toJSON()
2310
2460
  }, {
2311
- F: __dxlog_file11,
2461
+ F: __dxlog_file12,
2312
2462
  L: 129,
2313
2463
  S: this,
2314
2464
  C: (f, a) => f(...a)
@@ -2316,19 +2466,19 @@ var InvitationsHandler = class {
2316
2466
  }
2317
2467
  } else {
2318
2468
  if (guardedState.error(extension, err)) {
2319
- log8.error("failed", err, {
2320
- F: __dxlog_file11,
2469
+ log10.error("failed", err, {
2470
+ F: __dxlog_file12,
2321
2471
  L: 133,
2322
2472
  S: this,
2323
2473
  C: (f, a) => f(...a)
2324
2474
  });
2325
2475
  }
2326
2476
  }
2327
- log8.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.error({
2477
+ log10.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.error({
2328
2478
  id: traceId,
2329
2479
  error: err
2330
2480
  }), {
2331
- F: __dxlog_file11,
2481
+ F: __dxlog_file12,
2332
2482
  L: 136,
2333
2483
  S: this,
2334
2484
  C: (f, a) => f(...a)
@@ -2339,10 +2489,10 @@ var InvitationsHandler = class {
2339
2489
  },
2340
2490
  onError: (err) => {
2341
2491
  if (err instanceof InvalidInvitationExtensionRoleError3) {
2342
- log8("invalid role", {
2492
+ log10("invalid role", {
2343
2493
  ...err.context
2344
2494
  }, {
2345
- F: __dxlog_file11,
2495
+ F: __dxlog_file12,
2346
2496
  L: 144,
2347
2497
  S: this,
2348
2498
  C: (f, a) => f(...a)
@@ -2351,10 +2501,10 @@ var InvitationsHandler = class {
2351
2501
  }
2352
2502
  if (err instanceof TimeoutError) {
2353
2503
  if (guardedState.set(extension, Invitation4.State.TIMEOUT)) {
2354
- log8("timeout", {
2504
+ log10("timeout", {
2355
2505
  err
2356
2506
  }, {
2357
- F: __dxlog_file11,
2507
+ F: __dxlog_file12,
2358
2508
  L: 149,
2359
2509
  S: this,
2360
2510
  C: (f, a) => f(...a)
@@ -2362,8 +2512,8 @@ var InvitationsHandler = class {
2362
2512
  }
2363
2513
  } else {
2364
2514
  if (guardedState.error(extension, err)) {
2365
- log8.error("failed", err, {
2366
- F: __dxlog_file11,
2515
+ log10.error("failed", err, {
2516
+ F: __dxlog_file12,
2367
2517
  L: 153,
2368
2518
  S: this,
2369
2519
  C: (f, a) => f(...a)
@@ -2376,8 +2526,8 @@ var InvitationsHandler = class {
2376
2526
  };
2377
2527
  if (invitation.lifetime && invitation.created) {
2378
2528
  if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
2379
- log8.warn("invitation has already expired", void 0, {
2380
- F: __dxlog_file11,
2529
+ log10.warn("invitation has already expired", void 0, {
2530
+ F: __dxlog_file12,
2381
2531
  L: 164,
2382
2532
  S: this,
2383
2533
  C: (f, a) => f(...a)
@@ -2400,7 +2550,7 @@ var InvitationsHandler = class {
2400
2550
  const { timeout = INVITATION_TIMEOUT } = invitation;
2401
2551
  if (deviceProfile) {
2402
2552
  invariant9(invitation.kind === Invitation4.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
2403
- F: __dxlog_file11,
2553
+ F: __dxlog_file12,
2404
2554
  L: 197,
2405
2555
  S: this,
2406
2556
  A: [
@@ -2413,12 +2563,12 @@ var InvitationsHandler = class {
2413
2563
  const guardedState = this._createGuardedState(ctx, invitation, stream);
2414
2564
  const shouldCancelInvitationFlow = (extension) => {
2415
2565
  const isLockedByAnotherConnection = guardedState.mutex.isLocked() && !extension.hasFlowLock();
2416
- log8("should cancel invitation flow", {
2566
+ log10("should cancel invitation flow", {
2417
2567
  isLockedByAnotherConnection,
2418
2568
  invitationType: Invitation4.Type.DELEGATED,
2419
2569
  triedPeers: triedPeersIds.size
2420
2570
  }, {
2421
- F: __dxlog_file11,
2571
+ F: __dxlog_file12,
2422
2572
  L: 205,
2423
2573
  S: this,
2424
2574
  C: (f, a) => f(...a)
@@ -2441,11 +2591,11 @@ var InvitationsHandler = class {
2441
2591
  return;
2442
2592
  }
2443
2593
  connectionCtx.onDispose(async () => {
2444
- log8("extension disposed", {
2594
+ log10("extension disposed", {
2445
2595
  admitted,
2446
2596
  currentState: guardedState.current.state
2447
2597
  }, {
2448
- F: __dxlog_file11,
2598
+ F: __dxlog_file12,
2449
2599
  L: 233,
2450
2600
  S: this,
2451
2601
  C: (f, a) => f(...a)
@@ -2460,10 +2610,10 @@ var InvitationsHandler = class {
2460
2610
  scheduleTask3(connectionCtx, async () => {
2461
2611
  const traceId = PublicKey7.random().toHex();
2462
2612
  try {
2463
- log8.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.begin({
2613
+ log10.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.begin({
2464
2614
  id: traceId
2465
2615
  }), {
2466
- F: __dxlog_file11,
2616
+ F: __dxlog_file12,
2467
2617
  L: 245,
2468
2618
  S: this,
2469
2619
  C: (f, a) => f(...a)
@@ -2472,19 +2622,19 @@ var InvitationsHandler = class {
2472
2622
  guardedState.set(extension, Invitation4.State.TIMEOUT);
2473
2623
  extensionCtx.close();
2474
2624
  }, timeout);
2475
- log8("connected", {
2625
+ log10("connected", {
2476
2626
  ...protocol.toJSON()
2477
2627
  }, {
2478
- F: __dxlog_file11,
2628
+ F: __dxlog_file12,
2479
2629
  L: 256,
2480
2630
  S: this,
2481
2631
  C: (f, a) => f(...a)
2482
2632
  });
2483
2633
  guardedState.set(extension, Invitation4.State.CONNECTED);
2484
- log8("introduce", {
2634
+ log10("introduce", {
2485
2635
  ...protocol.toJSON()
2486
2636
  }, {
2487
- F: __dxlog_file11,
2637
+ F: __dxlog_file12,
2488
2638
  L: 260,
2489
2639
  S: this,
2490
2640
  C: (f, a) => f(...a)
@@ -2493,11 +2643,11 @@ var InvitationsHandler = class {
2493
2643
  invitationId: invitation.invitationId,
2494
2644
  ...protocol.createIntroduction()
2495
2645
  });
2496
- log8("introduce response", {
2646
+ log10("introduce response", {
2497
2647
  ...protocol.toJSON(),
2498
2648
  response: introductionResponse
2499
2649
  }, {
2500
- F: __dxlog_file11,
2650
+ F: __dxlog_file12,
2501
2651
  L: 265,
2502
2652
  S: this,
2503
2653
  C: (f, a) => f(...a)
@@ -2515,10 +2665,10 @@ var InvitationsHandler = class {
2515
2665
  break;
2516
2666
  }
2517
2667
  }
2518
- log8("request admission", {
2668
+ log10("request admission", {
2519
2669
  ...protocol.toJSON()
2520
2670
  }, {
2521
- F: __dxlog_file11,
2671
+ F: __dxlog_file12,
2522
2672
  L: 291,
2523
2673
  S: this,
2524
2674
  C: (f, a) => f(...a)
@@ -2527,10 +2677,10 @@ var InvitationsHandler = class {
2527
2677
  const admissionResponse = await extension.rpc.InvitationHostService.admit(admissionRequest);
2528
2678
  admitted = true;
2529
2679
  const result = await protocol.accept(admissionResponse, admissionRequest);
2530
- log8("admitted by host", {
2680
+ log10("admitted by host", {
2531
2681
  ...protocol.toJSON()
2532
2682
  }, {
2533
- F: __dxlog_file11,
2683
+ F: __dxlog_file12,
2534
2684
  L: 302,
2535
2685
  S: this,
2536
2686
  C: (f, a) => f(...a)
@@ -2540,28 +2690,28 @@ var InvitationsHandler = class {
2540
2690
  ...result,
2541
2691
  state: Invitation4.State.SUCCESS
2542
2692
  });
2543
- log8.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.end({
2693
+ log10.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.end({
2544
2694
  id: traceId
2545
2695
  }), {
2546
- F: __dxlog_file11,
2696
+ F: __dxlog_file12,
2547
2697
  L: 308,
2548
2698
  S: this,
2549
2699
  C: (f, a) => f(...a)
2550
2700
  });
2551
2701
  } catch (err) {
2552
2702
  if (err instanceof TimeoutError) {
2553
- log8("timeout", {
2703
+ log10("timeout", {
2554
2704
  ...protocol.toJSON()
2555
2705
  }, {
2556
- F: __dxlog_file11,
2706
+ F: __dxlog_file12,
2557
2707
  L: 311,
2558
2708
  S: this,
2559
2709
  C: (f, a) => f(...a)
2560
2710
  });
2561
2711
  guardedState.set(extension, Invitation4.State.TIMEOUT);
2562
2712
  } else {
2563
- log8("auth failed", err, {
2564
- F: __dxlog_file11,
2713
+ log10("auth failed", err, {
2714
+ F: __dxlog_file12,
2565
2715
  L: 314,
2566
2716
  S: this,
2567
2717
  C: (f, a) => f(...a)
@@ -2569,11 +2719,11 @@ var InvitationsHandler = class {
2569
2719
  guardedState.error(extension, err);
2570
2720
  }
2571
2721
  extensionCtx.close(err);
2572
- log8.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.error({
2722
+ log10.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.error({
2573
2723
  id: traceId,
2574
2724
  error: err
2575
2725
  }), {
2576
- F: __dxlog_file11,
2726
+ F: __dxlog_file12,
2577
2727
  L: 318,
2578
2728
  S: this,
2579
2729
  C: (f, a) => f(...a)
@@ -2586,18 +2736,18 @@ var InvitationsHandler = class {
2586
2736
  return;
2587
2737
  }
2588
2738
  if (err instanceof TimeoutError) {
2589
- log8("timeout", {
2739
+ log10("timeout", {
2590
2740
  ...protocol.toJSON()
2591
2741
  }, {
2592
- F: __dxlog_file11,
2742
+ F: __dxlog_file12,
2593
2743
  L: 327,
2594
2744
  S: this,
2595
2745
  C: (f, a) => f(...a)
2596
2746
  });
2597
2747
  guardedState.set(extension, Invitation4.State.TIMEOUT);
2598
2748
  } else {
2599
- log8("auth failed", err, {
2600
- F: __dxlog_file11,
2749
+ log10("auth failed", err, {
2750
+ F: __dxlog_file12,
2601
2751
  L: 330,
2602
2752
  S: this,
2603
2753
  C: (f, a) => f(...a)
@@ -2615,7 +2765,7 @@ var InvitationsHandler = class {
2615
2765
  await ctx.dispose();
2616
2766
  } else {
2617
2767
  invariant9(invitation.swarmKey, void 0, {
2618
- F: __dxlog_file11,
2768
+ F: __dxlog_file12,
2619
2769
  L: 345,
2620
2770
  S: this,
2621
2771
  A: [
@@ -2709,12 +2859,12 @@ var InvitationsHandler = class {
2709
2859
  };
2710
2860
  }
2711
2861
  _logStateUpdate(invitation, actor, newState) {
2712
- log8("invitation state update", {
2862
+ log10("invitation state update", {
2713
2863
  actor: actor?.constructor.name,
2714
2864
  newState: stateToString(newState),
2715
2865
  oldState: stateToString(invitation.state)
2716
2866
  }, {
2717
- F: __dxlog_file11,
2867
+ F: __dxlog_file12,
2718
2868
  L: 438,
2719
2869
  S: this,
2720
2870
  C: (f, a) => f(...a)
@@ -2731,16 +2881,16 @@ var InvitationsHandler = class {
2731
2881
  }
2732
2882
  async _handleGuestOtpAuth(extension, setState, authenticated, options) {
2733
2883
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2734
- log8("guest waiting for authentication code...", void 0, {
2735
- F: __dxlog_file11,
2884
+ log10("guest waiting for authentication code...", void 0, {
2885
+ F: __dxlog_file12,
2736
2886
  L: 462,
2737
2887
  S: this,
2738
2888
  C: (f, a) => f(...a)
2739
2889
  });
2740
2890
  setState(Invitation4.State.READY_FOR_AUTHENTICATION);
2741
2891
  const authCode = await authenticated.wait(options);
2742
- log8("sending authentication request", void 0, {
2743
- F: __dxlog_file11,
2892
+ log10("sending authentication request", void 0, {
2893
+ F: __dxlog_file12,
2744
2894
  L: 466,
2745
2895
  S: this,
2746
2896
  C: (f, a) => f(...a)
@@ -2756,10 +2906,10 @@ var InvitationsHandler = class {
2756
2906
  if (attempt === MAX_OTP_ATTEMPTS) {
2757
2907
  throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
2758
2908
  } else {
2759
- log8("retrying invalid code", {
2909
+ log10("retrying invalid code", {
2760
2910
  attempt
2761
2911
  }, {
2762
- F: __dxlog_file11,
2912
+ F: __dxlog_file12,
2763
2913
  L: 477,
2764
2914
  S: this,
2765
2915
  C: (f, a) => f(...a)
@@ -2776,8 +2926,8 @@ var InvitationsHandler = class {
2776
2926
  if (introductionResponse.challenge == null) {
2777
2927
  throw new Error("challenge missing in the introduction");
2778
2928
  }
2779
- log8("sending authentication request", void 0, {
2780
- F: __dxlog_file11,
2929
+ log10("sending authentication request", void 0, {
2930
+ F: __dxlog_file12,
2781
2931
  L: 496,
2782
2932
  S: this,
2783
2933
  C: (f, a) => f(...a)
@@ -2898,14 +3048,14 @@ var InvitationsServiceImpl = class {
2898
3048
  };
2899
3049
 
2900
3050
  // packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts
2901
- import { createAdmissionCredentials, createCancelDelegatedSpaceInvitationCredential, createDelegatedSpaceInvitationCredential, getCredentialAssertion } from "@dxos/credentials";
3051
+ import { createAdmissionCredentials, createCancelDelegatedSpaceInvitationCredential, createDelegatedSpaceInvitationCredential, getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
2902
3052
  import { writeMessages as writeMessages2 } from "@dxos/feed-store";
2903
3053
  import { invariant as invariant10 } from "@dxos/invariant";
2904
- import { log as log9 } from "@dxos/log";
3054
+ import { log as log11 } from "@dxos/log";
2905
3055
  import { AlreadyJoinedError as AlreadyJoinedError2, AuthorizationError, InvalidInvitationError, SpaceNotFoundError } from "@dxos/protocols";
2906
3056
  import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
2907
3057
  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";
3058
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
2909
3059
  var SpaceInvitationProtocol = class {
2910
3060
  constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
2911
3061
  this._spaceManager = _spaceManager;
@@ -2940,7 +3090,7 @@ var SpaceInvitationProtocol = class {
2940
3090
  }
2941
3091
  async admit(invitation, request, guestProfile) {
2942
3092
  invariant10(this._spaceKey, void 0, {
2943
- F: __dxlog_file12,
3093
+ F: __dxlog_file13,
2944
3094
  L: 76,
2945
3095
  S: this,
2946
3096
  A: [
@@ -2950,7 +3100,7 @@ var SpaceInvitationProtocol = class {
2950
3100
  });
2951
3101
  const space = this._spaceManager.spaces.get(this._spaceKey);
2952
3102
  invariant10(space, void 0, {
2953
- F: __dxlog_file12,
3103
+ F: __dxlog_file13,
2954
3104
  L: 78,
2955
3105
  S: this,
2956
3106
  A: [
@@ -2959,7 +3109,7 @@ var SpaceInvitationProtocol = class {
2959
3109
  ]
2960
3110
  });
2961
3111
  invariant10(request.space, void 0, {
2962
- F: __dxlog_file12,
3112
+ F: __dxlog_file13,
2963
3113
  L: 80,
2964
3114
  S: this,
2965
3115
  A: [
@@ -2971,18 +3121,18 @@ var SpaceInvitationProtocol = class {
2971
3121
  if (space.inner.spaceState.getMemberRole(identityKey) !== SpaceMember2.Role.REMOVED) {
2972
3122
  throw new AlreadyJoinedError2();
2973
3123
  }
2974
- log9("writing guest credentials", {
3124
+ log11("writing guest credentials", {
2975
3125
  host: this._signingContext.deviceKey,
2976
3126
  guest: deviceKey
2977
3127
  }, {
2978
- F: __dxlog_file12,
3128
+ F: __dxlog_file13,
2979
3129
  L: 87,
2980
3130
  S: this,
2981
3131
  C: (f, a) => f(...a)
2982
3132
  });
2983
3133
  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
3134
  invariant10(credentials[0].credential, void 0, {
2985
- F: __dxlog_file12,
3135
+ F: __dxlog_file13,
2986
3136
  L: 101,
2987
3137
  S: this,
2988
3138
  A: [
@@ -2991,8 +3141,8 @@ var SpaceInvitationProtocol = class {
2991
3141
  ]
2992
3142
  });
2993
3143
  const spaceMemberCredential = credentials[0].credential.credential;
2994
- invariant10(getCredentialAssertion(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2995
- F: __dxlog_file12,
3144
+ invariant10(getCredentialAssertion2(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3145
+ F: __dxlog_file13,
2996
3146
  L: 103,
2997
3147
  S: this,
2998
3148
  A: [
@@ -3010,7 +3160,7 @@ var SpaceInvitationProtocol = class {
3010
3160
  }
3011
3161
  async delegate(invitation) {
3012
3162
  invariant10(this._spaceKey, void 0, {
3013
- F: __dxlog_file12,
3163
+ F: __dxlog_file13,
3014
3164
  L: 116,
3015
3165
  S: this,
3016
3166
  A: [
@@ -3020,7 +3170,7 @@ var SpaceInvitationProtocol = class {
3020
3170
  });
3021
3171
  const space = this._spaceManager.spaces.get(this._spaceKey);
3022
3172
  invariant10(space, void 0, {
3023
- F: __dxlog_file12,
3173
+ F: __dxlog_file13,
3024
3174
  L: 118,
3025
3175
  S: this,
3026
3176
  A: [
@@ -3030,7 +3180,7 @@ var SpaceInvitationProtocol = class {
3030
3180
  });
3031
3181
  if (invitation.authMethod === Invitation5.AuthMethod.KNOWN_PUBLIC_KEY) {
3032
3182
  invariant10(invitation.guestKeypair?.publicKey, void 0, {
3033
- F: __dxlog_file12,
3183
+ F: __dxlog_file13,
3034
3184
  L: 120,
3035
3185
  S: this,
3036
3186
  A: [
@@ -3039,11 +3189,11 @@ var SpaceInvitationProtocol = class {
3039
3189
  ]
3040
3190
  });
3041
3191
  }
3042
- log9("writing delegate space invitation", {
3192
+ log11("writing delegate space invitation", {
3043
3193
  host: this._signingContext.deviceKey,
3044
3194
  id: invitation.invitationId
3045
3195
  }, {
3046
- F: __dxlog_file12,
3196
+ F: __dxlog_file13,
3047
3197
  L: 123,
3048
3198
  S: this,
3049
3199
  C: (f, a) => f(...a)
@@ -3058,7 +3208,7 @@ var SpaceInvitationProtocol = class {
3058
3208
  guestKey: invitation.authMethod === Invitation5.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
3059
3209
  });
3060
3210
  invariant10(credential.credential, void 0, {
3061
- F: __dxlog_file12,
3211
+ F: __dxlog_file13,
3062
3212
  L: 143,
3063
3213
  S: this,
3064
3214
  A: [
@@ -3073,7 +3223,7 @@ var SpaceInvitationProtocol = class {
3073
3223
  }
3074
3224
  async cancelDelegation(invitation) {
3075
3225
  invariant10(this._spaceKey, void 0, {
3076
- F: __dxlog_file12,
3226
+ F: __dxlog_file13,
3077
3227
  L: 149,
3078
3228
  S: this,
3079
3229
  A: [
@@ -3082,7 +3232,7 @@ var SpaceInvitationProtocol = class {
3082
3232
  ]
3083
3233
  });
3084
3234
  invariant10(invitation.type === Invitation5.Type.DELEGATED && invitation.delegationCredentialId, void 0, {
3085
- F: __dxlog_file12,
3235
+ F: __dxlog_file13,
3086
3236
  L: 150,
3087
3237
  S: this,
3088
3238
  A: [
@@ -3092,7 +3242,7 @@ var SpaceInvitationProtocol = class {
3092
3242
  });
3093
3243
  const space = this._spaceManager.spaces.get(this._spaceKey);
3094
3244
  invariant10(space, void 0, {
3095
- F: __dxlog_file12,
3245
+ F: __dxlog_file13,
3096
3246
  L: 152,
3097
3247
  S: this,
3098
3248
  A: [
@@ -3100,18 +3250,18 @@ var SpaceInvitationProtocol = class {
3100
3250
  ""
3101
3251
  ]
3102
3252
  });
3103
- log9("cancelling delegated space invitation", {
3253
+ log11("cancelling delegated space invitation", {
3104
3254
  host: this._signingContext.deviceKey,
3105
3255
  id: invitation.invitationId
3106
3256
  }, {
3107
- F: __dxlog_file12,
3257
+ F: __dxlog_file13,
3108
3258
  L: 154,
3109
3259
  S: this,
3110
3260
  C: (f, a) => f(...a)
3111
3261
  });
3112
3262
  const credential = await createCancelDelegatedSpaceInvitationCredential(this._signingContext.credentialSigner, space.key, invitation.delegationCredentialId);
3113
3263
  invariant10(credential.credential, void 0, {
3114
- F: __dxlog_file12,
3264
+ F: __dxlog_file13,
3115
3265
  L: 161,
3116
3266
  S: this,
3117
3267
  A: [
@@ -3150,7 +3300,7 @@ var SpaceInvitationProtocol = class {
3150
3300
  }
3151
3301
  async accept(response) {
3152
3302
  invariant10(response.space, void 0, {
3153
- F: __dxlog_file12,
3303
+ F: __dxlog_file13,
3154
3304
  L: 196,
3155
3305
  S: this,
3156
3306
  A: [
@@ -3159,9 +3309,9 @@ var SpaceInvitationProtocol = class {
3159
3309
  ]
3160
3310
  });
3161
3311
  const { credential, controlTimeframe, dataTimeframe } = response.space;
3162
- const assertion = getCredentialAssertion(credential);
3312
+ const assertion = getCredentialAssertion2(credential);
3163
3313
  invariant10(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
3164
- F: __dxlog_file12,
3314
+ F: __dxlog_file13,
3165
3315
  L: 199,
3166
3316
  S: this,
3167
3317
  A: [
@@ -3170,7 +3320,7 @@ var SpaceInvitationProtocol = class {
3170
3320
  ]
3171
3321
  });
3172
3322
  invariant10(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
3173
- F: __dxlog_file12,
3323
+ F: __dxlog_file13,
3174
3324
  L: 200,
3175
3325
  S: this,
3176
3326
  A: [
@@ -3195,17 +3345,17 @@ var SpaceInvitationProtocol = class {
3195
3345
  };
3196
3346
 
3197
3347
  // 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";
3348
+ import { Event as Event3, PushStream, TimeoutError as TimeoutError2, Trigger as Trigger6 } from "@dxos/async";
3199
3349
  import { AuthenticatingInvitation, AUTHENTICATION_CODE_LENGTH, CancellableInvitation, INVITATION_TIMEOUT as INVITATION_TIMEOUT2 } from "@dxos/client-protocol";
3200
3350
  import { Context as Context6 } from "@dxos/context";
3201
3351
  import { generatePasscode } from "@dxos/credentials";
3202
3352
  import { hasInvitationExpired } from "@dxos/echo-pipeline";
3203
3353
  import { invariant as invariant11 } from "@dxos/invariant";
3204
3354
  import { PublicKey as PublicKey8 } from "@dxos/keys";
3205
- import { log as log10 } from "@dxos/log";
3355
+ import { log as log12 } from "@dxos/log";
3206
3356
  import { Invitation as Invitation6 } from "@dxos/protocols/proto/dxos/client/services";
3207
3357
  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";
3358
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
3209
3359
  var InvitationsManager = class {
3210
3360
  constructor(_invitationsHandler, _getHandler, _metadataStore) {
3211
3361
  this._invitationsHandler = _invitationsHandler;
@@ -3247,8 +3397,8 @@ var InvitationsManager = class {
3247
3397
  try {
3248
3398
  await this._persistIfRequired(handler, stream, invitation);
3249
3399
  } catch (err) {
3250
- log10.catch(err, void 0, {
3251
- F: __dxlog_file13,
3400
+ log12.catch(err, void 0, {
3401
+ F: __dxlog_file14,
3252
3402
  L: 82,
3253
3403
  S: this,
3254
3404
  C: (f, a) => f(...a)
@@ -3271,7 +3421,7 @@ var InvitationsManager = class {
3271
3421
  const freshInvitations = persistentInvitations.filter((invitation) => !hasInvitationExpired(invitation));
3272
3422
  const loadTasks = freshInvitations.map((persistentInvitation) => {
3273
3423
  invariant11(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
3274
- F: __dxlog_file13,
3424
+ F: __dxlog_file14,
3275
3425
  L: 103,
3276
3426
  S: this,
3277
3427
  A: [
@@ -3289,8 +3439,8 @@ var InvitationsManager = class {
3289
3439
  invitations: cInvitations.map((invitation) => invitation.get())
3290
3440
  };
3291
3441
  } catch (err) {
3292
- log10.catch(err, void 0, {
3293
- F: __dxlog_file13,
3442
+ log12.catch(err, void 0, {
3443
+ F: __dxlog_file14,
3294
3444
  L: 110,
3295
3445
  S: this,
3296
3446
  C: (f, a) => f(...a)
@@ -3321,14 +3471,14 @@ var InvitationsManager = class {
3321
3471
  return invitation;
3322
3472
  }
3323
3473
  async authenticate({ invitationId, authCode }) {
3324
- log10("authenticating...", void 0, {
3325
- F: __dxlog_file13,
3474
+ log12("authenticating...", void 0, {
3475
+ F: __dxlog_file14,
3326
3476
  L: 140,
3327
3477
  S: this,
3328
3478
  C: (f, a) => f(...a)
3329
3479
  });
3330
3480
  invariant11(invitationId, void 0, {
3331
- F: __dxlog_file13,
3481
+ F: __dxlog_file14,
3332
3482
  L: 141,
3333
3483
  S: this,
3334
3484
  A: [
@@ -3338,10 +3488,10 @@ var InvitationsManager = class {
3338
3488
  });
3339
3489
  const observable = this._acceptInvitations.get(invitationId);
3340
3490
  if (!observable) {
3341
- log10.warn("invalid invitation", {
3491
+ log12.warn("invalid invitation", {
3342
3492
  invitationId
3343
3493
  }, {
3344
- F: __dxlog_file13,
3494
+ F: __dxlog_file14,
3345
3495
  L: 144,
3346
3496
  S: this,
3347
3497
  C: (f, a) => f(...a)
@@ -3351,16 +3501,16 @@ var InvitationsManager = class {
3351
3501
  }
3352
3502
  }
3353
3503
  async cancelInvitation({ invitationId }) {
3354
- log10("cancelInvitation...", {
3504
+ log12("cancelInvitation...", {
3355
3505
  invitationId
3356
3506
  }, {
3357
- F: __dxlog_file13,
3507
+ F: __dxlog_file14,
3358
3508
  L: 151,
3359
3509
  S: this,
3360
3510
  C: (f, a) => f(...a)
3361
3511
  });
3362
3512
  invariant11(invitationId, void 0, {
3363
- F: __dxlog_file13,
3513
+ F: __dxlog_file14,
3364
3514
  L: 152,
3365
3515
  S: this,
3366
3516
  A: [
@@ -3436,10 +3586,10 @@ var InvitationsManager = class {
3436
3586
  }
3437
3587
  });
3438
3588
  ctx.onDispose(() => {
3439
- log10("complete", {
3589
+ log12("complete", {
3440
3590
  ...handler.toJSON()
3441
3591
  }, {
3442
- F: __dxlog_file13,
3592
+ F: __dxlog_file14,
3443
3593
  L: 241,
3444
3594
  S: this,
3445
3595
  C: (f, a) => f(...a)
@@ -3464,15 +3614,15 @@ var InvitationsManager = class {
3464
3614
  };
3465
3615
  }
3466
3616
  _createObservableAcceptingInvitation(handler, initialState) {
3467
- const otpEnteredTrigger = new Trigger5();
3617
+ const otpEnteredTrigger = new Trigger6();
3468
3618
  const stream = new PushStream();
3469
3619
  const ctx = new Context6({
3470
3620
  onError: (err) => {
3471
3621
  if (err instanceof TimeoutError2) {
3472
- log10("timeout", {
3622
+ log12("timeout", {
3473
3623
  ...handler.toJSON()
3474
3624
  }, {
3475
- F: __dxlog_file13,
3625
+ F: __dxlog_file14,
3476
3626
  L: 261,
3477
3627
  S: this,
3478
3628
  C: (f, a) => f(...a)
@@ -3482,8 +3632,8 @@ var InvitationsManager = class {
3482
3632
  state: Invitation6.State.TIMEOUT
3483
3633
  });
3484
3634
  } else {
3485
- log10.warn("auth failed", err, {
3486
- F: __dxlog_file13,
3635
+ log12.warn("auth failed", err, {
3636
+ F: __dxlog_file14,
3487
3637
  L: 264,
3488
3638
  S: this,
3489
3639
  C: (f, a) => f(...a)
@@ -3497,10 +3647,10 @@ var InvitationsManager = class {
3497
3647
  }
3498
3648
  });
3499
3649
  ctx.onDispose(() => {
3500
- log10("complete", {
3650
+ log12("complete", {
3501
3651
  ...handler.toJSON()
3502
3652
  }, {
3503
- F: __dxlog_file13,
3653
+ F: __dxlog_file14,
3504
3654
  L: 271,
3505
3655
  S: this,
3506
3656
  C: (f, a) => f(...a)
@@ -3544,8 +3694,8 @@ var InvitationsManager = class {
3544
3694
  try {
3545
3695
  await this._metadataStore.removeInvitation(invitation.invitationId);
3546
3696
  } catch (err) {
3547
- log10.catch(err, void 0, {
3548
- F: __dxlog_file13,
3697
+ log12.catch(err, void 0, {
3698
+ F: __dxlog_file14,
3549
3699
  L: 307,
3550
3700
  S: this,
3551
3701
  C: (f, a) => f(...a)
@@ -3560,33 +3710,40 @@ var InvitationsManager = class {
3560
3710
  };
3561
3711
 
3562
3712
  // 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";
3713
+ import { Event as Event6, Mutex as Mutex2, scheduleTask as scheduleTask5, sleep as sleep3, synchronized, trackLeaks } from "@dxos/async";
3564
3714
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
3565
- import { Context as Context8, ContextDisposedError as ContextDisposedError3, cancelWithContext as cancelWithContext4 } from "@dxos/context";
3715
+ import { Context as Context8, ContextDisposedError as ContextDisposedError3, cancelWithContext as cancelWithContext5 } from "@dxos/context";
3566
3716
  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";
3717
+ import { createMappedFeedWriter } from "@dxos/echo-pipeline";
3718
+ import { SpaceDocVersion } from "@dxos/echo-protocol";
3719
+ import { failedInvariant } from "@dxos/invariant";
3570
3720
  import { PublicKey as PublicKey10 } from "@dxos/keys";
3571
- import { log as log12 } from "@dxos/log";
3721
+ import { log as log15 } from "@dxos/log";
3572
3722
  import { CancelledError, SystemError } from "@dxos/protocols";
3573
- import { CreateEpochRequest, SpaceState } from "@dxos/protocols/proto/dxos/client/services";
3723
+ import { SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
3574
3724
  import { AdmittedFeed as AdmittedFeed3, SpaceMember as SpaceMember4 } from "@dxos/protocols/proto/dxos/halo/credentials";
3575
- import { Timeframe as Timeframe2 } from "@dxos/timeframe";
3725
+ import { Timeframe as Timeframe3 } from "@dxos/timeframe";
3576
3726
  import { trace as trace6 } from "@dxos/tracing";
3577
- import { ComplexSet as ComplexSet5, assignDeep } from "@dxos/util";
3727
+ import { ComplexSet as ComplexSet5 } from "@dxos/util";
3578
3728
 
3579
3729
  // packages/sdk/client-services/src/packlets/spaces/automerge-space-state.ts
3580
3730
  import { Event as Event4 } from "@dxos/async";
3731
+ import { Resource as Resource2 } from "@dxos/context";
3581
3732
  import { checkCredentialType } from "@dxos/credentials";
3582
- var AutomergeSpaceState = class {
3733
+ var AutomergeSpaceState = class extends Resource2 {
3583
3734
  constructor(_onNewRoot) {
3735
+ super();
3584
3736
  this._onNewRoot = _onNewRoot;
3585
3737
  this.rootUrl = void 0;
3586
3738
  this.lastEpoch = void 0;
3587
3739
  this.onNewEpoch = new Event4();
3588
3740
  this._isProcessingRootDocs = false;
3589
3741
  }
3742
+ async _open(ctx) {
3743
+ }
3744
+ async _close(ctx) {
3745
+ this._isProcessingRootDocs = false;
3746
+ }
3590
3747
  async processCredential(credential) {
3591
3748
  if (!checkCredentialType(credential, "dxos.halo.credentials.Epoch")) {
3592
3749
  return;
@@ -3614,16 +3771,162 @@ var AutomergeSpaceState = class {
3614
3771
  }
3615
3772
  };
3616
3773
 
3617
- // 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";
3619
- import { Context as Context7, rejectOnDispose } from "@dxos/context";
3774
+ // packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts
3775
+ import { asyncTimeout as asyncTimeout2 } from "@dxos/async";
3776
+ import { next as am } from "@dxos/automerge/automerge";
3777
+ import { cancelWithContext as cancelWithContext4 } from "@dxos/context";
3778
+ import { convertLegacyReferences, convertLegacySpaceRootDoc, findInlineObjectOfType, migrateDocument } from "@dxos/echo-db";
3779
+ import { AutomergeDocumentLoaderImpl } from "@dxos/echo-pipeline";
3780
+ import { TYPE_PROPERTIES } from "@dxos/echo-schema";
3620
3781
  import { invariant as invariant12 } from "@dxos/invariant";
3782
+ import { log as log13 } from "@dxos/log";
3783
+ import { CreateEpochRequest } from "@dxos/protocols/proto/dxos/client/services";
3784
+ import { assignDeep } from "@dxos/util";
3785
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts";
3786
+ var runEpochMigration = async (ctx, context) => {
3787
+ switch (context.migration) {
3788
+ case CreateEpochRequest.Migration.INIT_AUTOMERGE: {
3789
+ const document = context.repo.create();
3790
+ await context.repo.flush();
3791
+ return {
3792
+ newRoot: document.url
3793
+ };
3794
+ }
3795
+ case CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY: {
3796
+ if (!context.currentRoot) {
3797
+ throw new Error("Space does not have an automerge root");
3798
+ }
3799
+ const rootHandle = context.repo.find(context.currentRoot);
3800
+ await cancelWithContext4(ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
3801
+ const newRoot = context.repo.create(rootHandle.docSync());
3802
+ await context.repo.flush();
3803
+ return {
3804
+ newRoot: newRoot.url
3805
+ };
3806
+ }
3807
+ case CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT: {
3808
+ log13.info("Fragmenting", void 0, {
3809
+ F: __dxlog_file15,
3810
+ L: 63,
3811
+ S: void 0,
3812
+ C: (f, a) => f(...a)
3813
+ });
3814
+ const currentRootUrl = context.currentRoot;
3815
+ const rootHandle = context.repo.find(currentRootUrl);
3816
+ await cancelWithContext4(ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
3817
+ const objects = Object.entries(rootHandle.docSync().objects);
3818
+ const properties = findInlineObjectOfType(rootHandle.docSync(), TYPE_PROPERTIES);
3819
+ const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
3820
+ invariant12(properties, "Properties not found", {
3821
+ F: __dxlog_file15,
3822
+ L: 73,
3823
+ S: void 0,
3824
+ A: [
3825
+ "properties",
3826
+ "'Properties not found'"
3827
+ ]
3828
+ });
3829
+ const newSpaceDoc = {
3830
+ ...rootHandle.docSync(),
3831
+ objects: Object.fromEntries([
3832
+ properties
3833
+ ])
3834
+ };
3835
+ const newRoot = context.repo.create(newSpaceDoc);
3836
+ invariant12(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3837
+ F: __dxlog_file15,
3838
+ L: 78,
3839
+ S: void 0,
3840
+ A: [
3841
+ "typeof newRoot.url === 'string' && newRoot.url.length > 0",
3842
+ ""
3843
+ ]
3844
+ });
3845
+ const docLoader = new AutomergeDocumentLoaderImpl(context.spaceId, context.repo, context.spaceKey);
3846
+ await docLoader.loadSpaceRootDocHandle(ctx, {
3847
+ rootUrl: newRoot.url
3848
+ });
3849
+ otherObjects.forEach(([key, value]) => {
3850
+ const handle = docLoader.createDocumentForObject(key);
3851
+ handle.change((doc) => {
3852
+ assignDeep(doc, [
3853
+ "objects",
3854
+ key
3855
+ ], value);
3856
+ });
3857
+ });
3858
+ await context.repo.flush();
3859
+ return {
3860
+ newRoot: newRoot.url
3861
+ };
3862
+ }
3863
+ case CreateEpochRequest.Migration.MIGRATE_REFERENCES_TO_DXN: {
3864
+ const currentRootUrl = context.currentRoot;
3865
+ const rootHandle = context.repo.find(currentRootUrl);
3866
+ await cancelWithContext4(ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
3867
+ invariant12(rootHandle.docSync(), "Root doc not found", {
3868
+ F: __dxlog_file15,
3869
+ L: 100,
3870
+ S: void 0,
3871
+ A: [
3872
+ "rootHandle.docSync()",
3873
+ "'Root doc not found'"
3874
+ ]
3875
+ });
3876
+ const newRootContent = await convertLegacySpaceRootDoc(structuredClone(rootHandle.docSync()));
3877
+ for (const [id, url] of Object.entries(newRootContent.links ?? {})) {
3878
+ const handle = context.repo.find(url);
3879
+ await cancelWithContext4(ctx, asyncTimeout2(handle.whenReady(), 1e4));
3880
+ invariant12(handle.docSync(), "Doc not found", {
3881
+ F: __dxlog_file15,
3882
+ L: 107,
3883
+ S: void 0,
3884
+ A: [
3885
+ "handle.docSync()",
3886
+ "'Doc not found'"
3887
+ ]
3888
+ });
3889
+ const newDoc = await convertLegacyReferences(structuredClone(handle.docSync()));
3890
+ const migratedDoc = migrateDocument(handle.docSync(), newDoc);
3891
+ const newHandle = context.repo.import(am.save(migratedDoc));
3892
+ newRootContent.links[id] = newHandle.url;
3893
+ }
3894
+ const migratedRoot = migrateDocument(rootHandle.docSync(), newRootContent);
3895
+ const newRoot = context.repo.import(am.save(migratedRoot));
3896
+ await context.repo.flush();
3897
+ return {
3898
+ newRoot: newRoot.url
3899
+ };
3900
+ }
3901
+ case CreateEpochRequest.Migration.REPLACE_AUTOMERGE_ROOT: {
3902
+ invariant12(context.newAutomergeRoot, void 0, {
3903
+ F: __dxlog_file15,
3904
+ L: 124,
3905
+ S: void 0,
3906
+ A: [
3907
+ "context.newAutomergeRoot",
3908
+ ""
3909
+ ]
3910
+ });
3911
+ await context.repo.flush();
3912
+ return {
3913
+ newRoot: context.newAutomergeRoot
3914
+ };
3915
+ }
3916
+ }
3917
+ return {};
3918
+ };
3919
+
3920
+ // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
3921
+ import { DeferredTask, Event as Event5, scheduleTask as scheduleTask4, sleep as sleep2, TimeoutError as TimeoutError3, Trigger as Trigger7 } from "@dxos/async";
3922
+ import { Context as Context7, rejectOnDispose } from "@dxos/context";
3923
+ import { invariant as invariant13 } from "@dxos/invariant";
3621
3924
  import { PublicKey as PublicKey9 } from "@dxos/keys";
3622
- import { log as log11 } from "@dxos/log";
3925
+ import { log as log14 } from "@dxos/log";
3623
3926
  import { schema as schema4 } from "@dxos/protocols";
3624
3927
  import { RpcExtension as RpcExtension3 } from "@dxos/teleport";
3625
3928
  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";
3929
+ var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
3627
3930
  var DEFAULT_RETRY_TIMEOUT = 1e3;
3628
3931
  var DEFAULT_SUCCESS_DELAY = 1e3;
3629
3932
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
@@ -3648,16 +3951,16 @@ var NotarizationPlugin = class {
3648
3951
  * Request credentials to be notarized.
3649
3952
  */
3650
3953
  async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
3651
- log11("notarize", {
3954
+ log14("notarize", {
3652
3955
  credentials
3653
3956
  }, {
3654
- F: __dxlog_file14,
3957
+ F: __dxlog_file16,
3655
3958
  L: 90,
3656
3959
  S: this,
3657
3960
  C: (f, a) => f(...a)
3658
3961
  });
3659
- invariant12(credentials.every((credential) => credential.id), "Credentials must have an id", {
3660
- F: __dxlog_file14,
3962
+ invariant13(credentials.every((credential) => credential.id), "Credentials must have an id", {
3963
+ F: __dxlog_file16,
3661
3964
  L: 91,
3662
3965
  S: this,
3663
3966
  A: [
@@ -3665,13 +3968,13 @@ var NotarizationPlugin = class {
3665
3968
  "'Credentials must have an id'"
3666
3969
  ]
3667
3970
  });
3668
- const errors = new Trigger6();
3971
+ const errors = new Trigger7();
3669
3972
  const ctx = this._ctx.derive({
3670
3973
  onError: (err) => {
3671
- log11.warn("Notarization error", {
3974
+ log14.warn("Notarization error", {
3672
3975
  err
3673
3976
  }, {
3674
- F: __dxlog_file14,
3977
+ F: __dxlog_file16,
3675
3978
  L: 99,
3676
3979
  S: this,
3677
3980
  C: (f, a) => f(...a)
@@ -3683,11 +3986,11 @@ var NotarizationPlugin = class {
3683
3986
  opCtx?.onDispose(() => ctx.dispose());
3684
3987
  if (timeout !== 0) {
3685
3988
  scheduleTask4(ctx, () => {
3686
- log11.warn("Notarization timeout", {
3989
+ log14.warn("Notarization timeout", {
3687
3990
  timeout,
3688
3991
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
3689
3992
  }, {
3690
- F: __dxlog_file14,
3993
+ F: __dxlog_file16,
3691
3994
  L: 111,
3692
3995
  S: this,
3693
3996
  C: (f, a) => f(...a)
@@ -3707,10 +4010,10 @@ var NotarizationPlugin = class {
3707
4010
  ...this._extensions
3708
4011
  ].find((peer2) => !peersTried.has(peer2));
3709
4012
  if (!peer) {
3710
- log11.info("Exhausted all peers to notarize with", {
4013
+ log14.info("Exhausted all peers to notarize with", {
3711
4014
  retryIn: retryTimeout
3712
4015
  }, {
3713
- F: __dxlog_file14,
4016
+ F: __dxlog_file16,
3714
4017
  L: 136,
3715
4018
  S: this,
3716
4019
  C: (f, a) => f(...a)
@@ -3720,11 +4023,11 @@ var NotarizationPlugin = class {
3720
4023
  return;
3721
4024
  }
3722
4025
  peersTried.add(peer);
3723
- log11("try notarizing", {
4026
+ log14("try notarizing", {
3724
4027
  peer: peer.localPeerId,
3725
4028
  credentialId: credentials.map((credential) => credential.id)
3726
4029
  }, {
3727
- F: __dxlog_file14,
4030
+ F: __dxlog_file16,
3728
4031
  L: 143,
3729
4032
  S: this,
3730
4033
  C: (f, a) => f(...a)
@@ -3732,17 +4035,17 @@ var NotarizationPlugin = class {
3732
4035
  await peer.rpc.NotarizationService.notarize({
3733
4036
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
3734
4037
  });
3735
- log11("success", void 0, {
3736
- F: __dxlog_file14,
4038
+ log14("success", void 0, {
4039
+ F: __dxlog_file16,
3737
4040
  L: 147,
3738
4041
  S: this,
3739
4042
  C: (f, a) => f(...a)
3740
4043
  });
3741
- await sleep(successDelay);
4044
+ await sleep2(successDelay);
3742
4045
  } catch (err) {
3743
4046
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
3744
- log11.info("error notarizing (recoverable)", err, {
3745
- F: __dxlog_file14,
4047
+ log14.info("error notarizing (recoverable)", err, {
4048
+ F: __dxlog_file16,
3746
4049
  L: 151,
3747
4050
  S: this,
3748
4051
  C: (f, a) => f(...a)
@@ -3759,8 +4062,8 @@ var NotarizationPlugin = class {
3759
4062
  allNotarized,
3760
4063
  errors.wait()
3761
4064
  ]);
3762
- log11("done", void 0, {
3763
- F: __dxlog_file14,
4065
+ log14("done", void 0, {
4066
+ F: __dxlog_file16,
3764
4067
  L: 162,
3765
4068
  S: this,
3766
4069
  C: (f, a) => f(...a)
@@ -3781,8 +4084,8 @@ var NotarizationPlugin = class {
3781
4084
  this._processCredentialsTriggers.delete(credential.id);
3782
4085
  }
3783
4086
  setWriter(writer) {
3784
- invariant12(!this._writer, "Writer already set.", {
3785
- F: __dxlog_file14,
4087
+ invariant13(!this._writer, "Writer already set.", {
4088
+ F: __dxlog_file16,
3786
4089
  L: 181,
3787
4090
  S: this,
3788
4091
  A: [
@@ -3796,7 +4099,7 @@ var NotarizationPlugin = class {
3796
4099
  if (this._processedCredentials.has(id)) {
3797
4100
  return;
3798
4101
  }
3799
- await entry(this._processCredentialsTriggers, id).orInsert(new Trigger6()).value.wait();
4102
+ await entry(this._processCredentialsTriggers, id).orInsert(new Trigger7()).value.wait();
3800
4103
  }
3801
4104
  /**
3802
4105
  * Requests from other peers to notarize credentials.
@@ -3806,8 +4109,8 @@ var NotarizationPlugin = class {
3806
4109
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
3807
4110
  }
3808
4111
  for (const credential of request.credentials ?? []) {
3809
- invariant12(credential.id, "Credential must have an id", {
3810
- F: __dxlog_file14,
4112
+ invariant13(credential.id, "Credential must have an id", {
4113
+ F: __dxlog_file16,
3811
4114
  L: 200,
3812
4115
  S: this,
3813
4116
  A: [
@@ -3824,10 +4127,10 @@ var NotarizationPlugin = class {
3824
4127
  createExtension() {
3825
4128
  const extension = new NotarizationTeleportExtension({
3826
4129
  onOpen: async () => {
3827
- log11("extension opened", {
4130
+ log14("extension opened", {
3828
4131
  peer: extension.localPeerId
3829
4132
  }, {
3830
- F: __dxlog_file14,
4133
+ F: __dxlog_file16,
3831
4134
  L: 211,
3832
4135
  S: this,
3833
4136
  C: (f, a) => f(...a)
@@ -3836,10 +4139,10 @@ var NotarizationPlugin = class {
3836
4139
  this._extensionOpened.emit();
3837
4140
  },
3838
4141
  onClose: async () => {
3839
- log11("extension closed", {
4142
+ log14("extension closed", {
3840
4143
  peer: extension.localPeerId
3841
4144
  }, {
3842
- F: __dxlog_file14,
4145
+ F: __dxlog_file16,
3843
4146
  L: 216,
3844
4147
  S: this,
3845
4148
  C: (f, a) => f(...a)
@@ -3893,7 +4196,70 @@ function _ts_decorate4(decorators, target, key, desc) {
3893
4196
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3894
4197
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3895
4198
  }
3896
- var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
4199
+ function _using_ctx() {
4200
+ var _disposeSuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed) {
4201
+ var err = new Error();
4202
+ err.name = "SuppressedError";
4203
+ err.suppressed = suppressed;
4204
+ err.error = error;
4205
+ return err;
4206
+ }, empty = {}, stack = [];
4207
+ function using(isAwait, value) {
4208
+ if (value != null) {
4209
+ if (Object(value) !== value) {
4210
+ throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
4211
+ }
4212
+ if (isAwait) {
4213
+ var dispose = value[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")];
4214
+ }
4215
+ if (dispose == null) {
4216
+ dispose = value[Symbol.dispose || Symbol.for("Symbol.dispose")];
4217
+ }
4218
+ if (typeof dispose !== "function") {
4219
+ throw new TypeError(`Property [Symbol.dispose] is not a function.`);
4220
+ }
4221
+ stack.push({
4222
+ v: value,
4223
+ d: dispose,
4224
+ a: isAwait
4225
+ });
4226
+ } else if (isAwait) {
4227
+ stack.push({
4228
+ d: value,
4229
+ a: isAwait
4230
+ });
4231
+ }
4232
+ return value;
4233
+ }
4234
+ return {
4235
+ e: empty,
4236
+ u: using.bind(null, false),
4237
+ a: using.bind(null, true),
4238
+ d: function() {
4239
+ var error = this.e;
4240
+ function next() {
4241
+ while (resource = stack.pop()) {
4242
+ try {
4243
+ var resource, disposalResult = resource.d && resource.d.call(resource.v);
4244
+ if (resource.a) {
4245
+ return Promise.resolve(disposalResult).then(next, err);
4246
+ }
4247
+ } catch (e) {
4248
+ return err(e);
4249
+ }
4250
+ }
4251
+ if (error !== empty)
4252
+ throw error;
4253
+ }
4254
+ function err(e) {
4255
+ error = error !== empty ? new _disposeSuppressedError(error, e) : e;
4256
+ return next();
4257
+ }
4258
+ return next();
4259
+ }
4260
+ };
4261
+ }
4262
+ var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
3897
4263
  var DataSpace = class {
3898
4264
  constructor(params) {
3899
4265
  this._ctx = new Context8();
@@ -3901,7 +4267,9 @@ var DataSpace = class {
3901
4267
  this._cache = void 0;
3902
4268
  // TODO(dmaretskyi): Move into Space?
3903
4269
  this._automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
3904
- this._state = SpaceState.CLOSED;
4270
+ this._epochProcessingMutex = new Mutex2();
4271
+ this._state = SpaceState2.CLOSED;
4272
+ this._databaseRoot = null;
3905
4273
  /**
3906
4274
  * Error for _state === SpaceState.ERROR.
3907
4275
  */
@@ -3925,11 +4293,11 @@ var DataSpace = class {
3925
4293
  });
3926
4294
  this._cache = params.cache;
3927
4295
  this._state = params.initialState;
3928
- log12("new state", {
3929
- state: SpaceState[this._state]
4296
+ log15("new state", {
4297
+ state: SpaceState2[this._state]
3930
4298
  }, {
3931
- F: __dxlog_file15,
3932
- L: 143,
4299
+ F: __dxlog_file17,
4300
+ L: 146,
3933
4301
  S: this,
3934
4302
  C: (f, a) => f(...a)
3935
4303
  });
@@ -3962,6 +4330,9 @@ var DataSpace = class {
3962
4330
  get automergeSpaceState() {
3963
4331
  return this._automergeSpaceState;
3964
4332
  }
4333
+ get databaseRoot() {
4334
+ return this._databaseRoot;
4335
+ }
3965
4336
  get _automergeInfo() {
3966
4337
  return {
3967
4338
  rootUrl: this._automergeSpaceState.rootUrl,
@@ -3969,20 +4340,24 @@ var DataSpace = class {
3969
4340
  };
3970
4341
  }
3971
4342
  async open() {
3972
- await this._open();
4343
+ if (this._state === SpaceState2.CLOSED) {
4344
+ await this._open();
4345
+ }
3973
4346
  }
3974
4347
  async _open() {
4348
+ await this._presence.open();
3975
4349
  await this._gossip.open();
3976
4350
  await this._notarizationPlugin.open();
3977
4351
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
4352
+ await this._automergeSpaceState.open();
3978
4353
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
3979
4354
  await this._inner.open(new Context8());
3980
- this._state = SpaceState.CONTROL_ONLY;
3981
- log12("new state", {
3982
- state: SpaceState[this._state]
4355
+ this._state = SpaceState2.CONTROL_ONLY;
4356
+ log15("new state", {
4357
+ state: SpaceState2[this._state]
3983
4358
  }, {
3984
- F: __dxlog_file15,
3985
- L: 206,
4359
+ F: __dxlog_file17,
4360
+ L: 217,
3986
4361
  S: this,
3987
4362
  C: (f, a) => f(...a)
3988
4363
  });
@@ -3995,12 +4370,12 @@ var DataSpace = class {
3995
4370
  }
3996
4371
  async _close() {
3997
4372
  await this._callbacks.beforeClose?.();
3998
- this._state = SpaceState.CLOSED;
3999
- log12("new state", {
4000
- state: SpaceState[this._state]
4373
+ this._state = SpaceState2.CLOSED;
4374
+ log15("new state", {
4375
+ state: SpaceState2[this._state]
4001
4376
  }, {
4002
- F: __dxlog_file15,
4003
- L: 220,
4377
+ F: __dxlog_file17,
4378
+ L: 231,
4004
4379
  S: this,
4005
4380
  C: (f, a) => f(...a)
4006
4381
  });
@@ -4009,9 +4384,10 @@ var DataSpace = class {
4009
4384
  await this.authVerifier.close();
4010
4385
  await this._inner.close();
4011
4386
  await this._inner.spaceState.removeCredentialProcessor(this._automergeSpaceState);
4387
+ await this._automergeSpaceState.close();
4012
4388
  await this._inner.spaceState.removeCredentialProcessor(this._notarizationPlugin);
4013
4389
  await this._notarizationPlugin.close();
4014
- await this._presence.destroy();
4390
+ await this._presence.close();
4015
4391
  await this._gossip.close();
4016
4392
  }
4017
4393
  async postMessage(channel, message) {
@@ -4030,26 +4406,26 @@ var DataSpace = class {
4030
4406
  await this.initializeDataPipeline();
4031
4407
  } catch (err) {
4032
4408
  if (err instanceof CancelledError || err instanceof ContextDisposedError3) {
4033
- log12("data pipeline initialization cancelled", err, {
4034
- F: __dxlog_file15,
4035
- L: 253,
4409
+ log15("data pipeline initialization cancelled", err, {
4410
+ F: __dxlog_file17,
4411
+ L: 265,
4036
4412
  S: this,
4037
4413
  C: (f, a) => f(...a)
4038
4414
  });
4039
4415
  return;
4040
4416
  }
4041
- log12.error("Error initializing data pipeline", err, {
4042
- F: __dxlog_file15,
4043
- L: 257,
4417
+ log15.error("Error initializing data pipeline", err, {
4418
+ F: __dxlog_file17,
4419
+ L: 269,
4044
4420
  S: this,
4045
4421
  C: (f, a) => f(...a)
4046
4422
  });
4047
- this._state = SpaceState.ERROR;
4048
- log12("new state", {
4049
- state: SpaceState[this._state]
4423
+ this._state = SpaceState2.ERROR;
4424
+ log15("new state", {
4425
+ state: SpaceState2[this._state]
4050
4426
  }, {
4051
- F: __dxlog_file15,
4052
- L: 259,
4427
+ F: __dxlog_file17,
4428
+ L: 271,
4053
4429
  S: this,
4054
4430
  C: (f, a) => f(...a)
4055
4431
  });
@@ -4061,35 +4437,32 @@ var DataSpace = class {
4061
4437
  });
4062
4438
  }
4063
4439
  async initializeDataPipeline() {
4064
- if (this._state !== SpaceState.CONTROL_ONLY) {
4440
+ if (this._state !== SpaceState2.CONTROL_ONLY) {
4065
4441
  throw new SystemError("Invalid operation");
4066
4442
  }
4067
- this._state = SpaceState.INITIALIZING;
4068
- log12("new state", {
4069
- state: SpaceState[this._state]
4443
+ this._state = SpaceState2.INITIALIZING;
4444
+ log15("new state", {
4445
+ state: SpaceState2[this._state]
4070
4446
  }, {
4071
- F: __dxlog_file15,
4072
- L: 275,
4447
+ F: __dxlog_file17,
4448
+ L: 287,
4073
4449
  S: this,
4074
4450
  C: (f, a) => f(...a)
4075
4451
  });
4076
4452
  await this._initializeAndReadControlPipeline();
4077
- await sleep2(1);
4453
+ await sleep3(1);
4454
+ const ready = this.stateUpdate.waitForCondition(() => this._state === SpaceState2.READY);
4078
4455
  this._automergeSpaceState.startProcessingRootDocs();
4079
- await cancelWithContext4(this._ctx, this.automergeSpaceState.ensureEpochInitialized());
4080
- log12("data pipeline ready", void 0, {
4081
- F: __dxlog_file15,
4082
- L: 287,
4083
- S: this,
4084
- C: (f, a) => f(...a)
4085
- });
4456
+ await ready;
4457
+ }
4458
+ async _enterReadyState() {
4086
4459
  await this._callbacks.beforeReady?.();
4087
- this._state = SpaceState.READY;
4088
- log12("new state", {
4089
- state: SpaceState[this._state]
4460
+ this._state = SpaceState2.READY;
4461
+ log15("new state", {
4462
+ state: SpaceState2[this._state]
4090
4463
  }, {
4091
- F: __dxlog_file15,
4092
- L: 291,
4464
+ F: __dxlog_file17,
4465
+ L: 306,
4093
4466
  S: this,
4094
4467
  C: (f, a) => f(...a)
4095
4468
  });
@@ -4103,9 +4476,9 @@ var DataSpace = class {
4103
4476
  });
4104
4477
  this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
4105
4478
  await this._createWritableFeeds();
4106
- log12("writable feeds created", void 0, {
4107
- F: __dxlog_file15,
4108
- L: 307,
4479
+ log15("writable feeds created", void 0, {
4480
+ F: __dxlog_file17,
4481
+ L: 322,
4109
4482
  S: this,
4110
4483
  C: (f, a) => f(...a)
4111
4484
  });
@@ -4163,57 +4536,66 @@ var DataSpace = class {
4163
4536
  }
4164
4537
  }
4165
4538
  _onNewAutomergeRoot(rootUrl) {
4166
- log12("loading automerge root doc for space", {
4539
+ log15("loading automerge root doc for space", {
4167
4540
  space: this.key,
4168
4541
  rootUrl
4169
4542
  }, {
4170
- F: __dxlog_file15,
4171
- L: 373,
4543
+ F: __dxlog_file17,
4544
+ L: 388,
4172
4545
  S: this,
4173
4546
  C: (f, a) => f(...a)
4174
4547
  });
4175
- this._echoHost.replicateDocument(rootUrl);
4176
4548
  const handle = this._echoHost.automergeRepo.find(rootUrl);
4177
4549
  queueMicrotask(async () => {
4178
4550
  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: 400,
4202
- S: this,
4203
- C: (f, a) => f(...a)
4551
+ try {
4552
+ var _usingCtx = _using_ctx();
4553
+ await warnAfterTimeout(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
4554
+ await cancelWithContext5(this._ctx, handle.whenReady());
4204
4555
  });
4556
+ if (this._ctx.disposed) {
4557
+ return;
4558
+ }
4559
+ const _guard = (
4560
+ // Ensure only one root is processed at a time.
4561
+ _usingCtx.u(await this._epochProcessingMutex.acquire())
4562
+ );
4563
+ const doc = handle.docSync() ?? failedInvariant();
4564
+ if (!doc.access?.spaceKey) {
4565
+ handle.change((doc2) => {
4566
+ doc2.access = {
4567
+ spaceKey: this.key.toHex()
4568
+ };
4569
+ });
4570
+ }
4571
+ const root = await this._echoHost.openSpaceRoot(handle.url);
4572
+ this._databaseRoot = root;
4573
+ if (root.getVersion() !== SpaceDocVersion.CURRENT) {
4574
+ if (this._state !== SpaceState2.REQUIRES_MIGRATION) {
4575
+ this._state = SpaceState2.REQUIRES_MIGRATION;
4576
+ this.stateUpdate.emit();
4577
+ }
4578
+ } else {
4579
+ if (this._state !== SpaceState2.READY) {
4580
+ await this._enterReadyState();
4581
+ }
4582
+ }
4583
+ } catch (_) {
4584
+ _usingCtx.e = _;
4585
+ } finally {
4586
+ _usingCtx.d();
4205
4587
  }
4206
4588
  } catch (err) {
4207
4589
  if (err instanceof ContextDisposedError3) {
4208
4590
  return;
4209
4591
  }
4210
- log12.warn("error loading automerge root doc", {
4592
+ log15.warn("error loading automerge root doc", {
4211
4593
  space: this.key,
4212
4594
  rootUrl,
4213
4595
  err
4214
4596
  }, {
4215
- F: __dxlog_file15,
4216
- L: 406,
4597
+ F: __dxlog_file17,
4598
+ L: 431,
4217
4599
  S: this,
4218
4600
  C: (f, a) => f(...a)
4219
4601
  });
@@ -4236,175 +4618,70 @@ var DataSpace = class {
4236
4618
  });
4237
4619
  }
4238
4620
  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: 456,
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: 468,
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: 478,
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: 483,
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
- case CreateEpochRequest.Migration.REPLACE_AUTOMERGE_ROOT:
4347
- {
4348
- invariant13(options.newAutomergeRoot, void 0, {
4349
- F: __dxlog_file15,
4350
- L: 513,
4351
- S: this,
4352
- A: [
4353
- "options.newAutomergeRoot",
4354
- ""
4355
- ]
4356
- });
4357
- epoch = {
4358
- previousId: this._automergeSpaceState.lastEpoch?.id,
4359
- number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
4360
- timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe2(),
4361
- automergeRoot: options.newAutomergeRoot
4362
- };
4363
- }
4364
- break;
4365
- }
4366
- if (!epoch) {
4367
- return;
4621
+ const ctx = this._ctx.derive();
4622
+ if (!options?.migration) {
4623
+ return null;
4368
4624
  }
4625
+ const { newRoot } = await runEpochMigration(ctx, {
4626
+ repo: this._echoHost.automergeRepo,
4627
+ spaceId: this.id,
4628
+ spaceKey: this.key,
4629
+ migration: options.migration,
4630
+ currentRoot: this._automergeSpaceState.rootUrl ?? null,
4631
+ newAutomergeRoot: options.newAutomergeRoot
4632
+ });
4633
+ const epoch = {
4634
+ previousId: this._automergeSpaceState.lastEpoch?.id,
4635
+ number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
4636
+ timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe3(),
4637
+ automergeRoot: newRoot ?? this._automergeSpaceState.rootUrl
4638
+ };
4639
+ const credential = await this._signingContext.credentialSigner.createCredential({
4640
+ subject: this.key,
4641
+ assertion: {
4642
+ "@type": "dxos.halo.credentials.Epoch",
4643
+ ...epoch
4644
+ }
4645
+ });
4369
4646
  const receipt = await this.inner.controlPipeline.writer.write({
4370
4647
  credential: {
4371
- credential: await this._signingContext.credentialSigner.createCredential({
4372
- subject: this.key,
4373
- assertion: {
4374
- "@type": "dxos.halo.credentials.Epoch",
4375
- ...epoch
4376
- }
4377
- })
4648
+ credential
4378
4649
  }
4379
4650
  });
4380
- await this.inner.controlPipeline.state.waitUntilTimeframe(new Timeframe2([
4651
+ await this.inner.controlPipeline.state.waitUntilTimeframe(new Timeframe3([
4381
4652
  [
4382
4653
  receipt.feedKey,
4383
4654
  receipt.seq
4384
4655
  ]
4385
4656
  ]));
4386
4657
  await this._echoHost.updateIndexes();
4658
+ return credential;
4387
4659
  }
4388
4660
  async activate() {
4389
- if (this._state !== SpaceState.INACTIVE) {
4661
+ if (![
4662
+ SpaceState2.CLOSED,
4663
+ SpaceState2.INACTIVE
4664
+ ].includes(this._state)) {
4390
4665
  return;
4391
4666
  }
4392
- await this._metadataStore.setSpaceState(this.key, SpaceState.ACTIVE);
4667
+ await this._metadataStore.setSpaceState(this.key, SpaceState2.ACTIVE);
4393
4668
  await this._open();
4394
4669
  this.initializeDataPipelineAsync();
4395
4670
  }
4396
4671
  async deactivate() {
4397
- if (this._state === SpaceState.INACTIVE) {
4672
+ if (this._state === SpaceState2.INACTIVE) {
4398
4673
  return;
4399
4674
  }
4400
- await this._metadataStore.setSpaceState(this.key, SpaceState.INACTIVE);
4401
- await this._close();
4402
- this._state = SpaceState.INACTIVE;
4403
- log12("new state", {
4404
- state: SpaceState[this._state]
4675
+ await this._metadataStore.setSpaceState(this.key, SpaceState2.INACTIVE);
4676
+ if (this._state !== SpaceState2.CLOSED) {
4677
+ await this._close();
4678
+ }
4679
+ this._state = SpaceState2.INACTIVE;
4680
+ log15("new state", {
4681
+ state: SpaceState2[this._state]
4405
4682
  }, {
4406
- F: __dxlog_file15,
4407
- L: 566,
4683
+ F: __dxlog_file17,
4684
+ L: 512,
4408
4685
  S: this,
4409
4686
  C: (f, a) => f(...a)
4410
4687
  });
@@ -4422,7 +4699,7 @@ _ts_decorate4([
4422
4699
  ], DataSpace.prototype, "key", null);
4423
4700
  _ts_decorate4([
4424
4701
  trace6.info({
4425
- enum: SpaceState
4702
+ enum: SpaceState2
4426
4703
  })
4427
4704
  ], DataSpace.prototype, "state", null);
4428
4705
  _ts_decorate4([
@@ -4459,39 +4736,31 @@ DataSpace = _ts_decorate4([
4459
4736
  trackLeaks("open", "close"),
4460
4737
  trace6.resource()
4461
4738
  ], DataSpace);
4462
- var findPropertiesObject = (spaceDoc) => {
4463
- for (const id in spaceDoc.objects ?? {}) {
4464
- const obj = spaceDoc.objects[id];
4465
- if (obj.system.type?.itemId === TYPE_PROPERTIES) {
4466
- return [
4467
- id,
4468
- obj
4469
- ];
4470
- }
4471
- }
4472
- return void 0;
4473
- };
4474
4739
 
4475
4740
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
4476
4741
  import { Event as Event7, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
4477
- import { cancelWithContext as cancelWithContext5, Context as Context9 } from "@dxos/context";
4478
- import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
4742
+ import { PropertiesType } from "@dxos/client-protocol";
4743
+ import { Context as Context9, cancelWithContext as cancelWithContext6 } from "@dxos/context";
4744
+ import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
4745
+ import { convertLegacyReferences as convertLegacyReferences2, findInlineObjectOfType as findInlineObjectOfType2 } from "@dxos/echo-db";
4479
4746
  import { AuthStatus } from "@dxos/echo-pipeline";
4747
+ import { LEGACY_TYPE_PROPERTIES, SpaceDocVersion as SpaceDocVersion2, encodeReference } from "@dxos/echo-protocol";
4748
+ import { TYPE_PROPERTIES as TYPE_PROPERTIES2, generateEchoId, getTypeReference } from "@dxos/echo-schema";
4480
4749
  import { invariant as invariant14 } from "@dxos/invariant";
4481
4750
  import { PublicKey as PublicKey11 } from "@dxos/keys";
4482
- import { log as log13 } from "@dxos/log";
4751
+ import { log as log16 } from "@dxos/log";
4483
4752
  import { trace as Trace2 } from "@dxos/protocols";
4484
- import { Invitation as Invitation7, SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
4753
+ import { Invitation as Invitation7, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
4485
4754
  import { SpaceMember as SpaceMember6 } from "@dxos/protocols/proto/dxos/halo/credentials";
4486
4755
  import { Gossip as Gossip2, Presence as Presence2 } from "@dxos/teleport-extension-gossip";
4487
4756
  import { trace as trace7 } from "@dxos/tracing";
4488
- import { ComplexMap as ComplexMap3, deferFunction as deferFunction2, forEachAsync } from "@dxos/util";
4757
+ import { ComplexMap as ComplexMap3, assignDeep as assignDeep2, deferFunction as deferFunction2, forEachAsync } from "@dxos/util";
4489
4758
 
4490
4759
  // packages/sdk/client-services/src/packlets/spaces/genesis.ts
4491
4760
  import { createCredential } from "@dxos/credentials";
4492
4761
  import { failUndefined } from "@dxos/debug";
4493
4762
  import { AdmittedFeed as AdmittedFeed4, SpaceMember as SpaceMember5 } from "@dxos/protocols/proto/dxos/halo/credentials";
4494
- import { Timeframe as Timeframe3 } from "@dxos/timeframe";
4763
+ import { Timeframe as Timeframe4 } from "@dxos/timeframe";
4495
4764
  var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
4496
4765
  const credentials = [
4497
4766
  await createCredential({
@@ -4541,7 +4810,7 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
4541
4810
  "@type": "dxos.halo.credentials.Epoch",
4542
4811
  number: 0,
4543
4812
  previousId: void 0,
4544
- timeframe: new Timeframe3(),
4813
+ timeframe: new Timeframe4(),
4545
4814
  snapshotCid: void 0,
4546
4815
  automergeRoot
4547
4816
  }
@@ -4568,11 +4837,12 @@ function _ts_decorate5(decorators, target, key, desc) {
4568
4837
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4569
4838
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4570
4839
  }
4571
- var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
4840
+ var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
4572
4841
  var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
4573
4842
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
4843
+ var DEFAULT_SPACE_KEY = "__DEFAULT__";
4574
4844
  var DataSpaceManager = class {
4575
- constructor(_spaceManager, _metadataStore, _keyring, _signingContext, _feedStore, _echoHost, _invitationsManager, params) {
4845
+ constructor(_spaceManager, _metadataStore, _keyring, _signingContext, _feedStore, _echoHost, _invitationsManager, _params) {
4576
4846
  this._spaceManager = _spaceManager;
4577
4847
  this._metadataStore = _metadataStore;
4578
4848
  this._keyring = _keyring;
@@ -4580,14 +4850,12 @@ var DataSpaceManager = class {
4580
4850
  this._feedStore = _feedStore;
4581
4851
  this._echoHost = _echoHost;
4582
4852
  this._invitationsManager = _invitationsManager;
4853
+ this._params = _params;
4583
4854
  this._ctx = new Context9();
4584
4855
  this.updated = new Event7();
4585
4856
  this._spaces = new ComplexMap3(PublicKey11.hash);
4586
4857
  this._isOpen = false;
4587
4858
  this._instanceId = PublicKey11.random().toHex();
4588
- const { spaceMemberPresenceAnnounceInterval = PRESENCE_ANNOUNCE_INTERVAL, spaceMemberPresenceOfflineTimeout = PRESENCE_OFFLINE_TIMEOUT } = params ?? {};
4589
- this._spaceMemberPresenceAnnounceInterval = spaceMemberPresenceAnnounceInterval;
4590
- this._spaceMemberPresenceOfflineTimeout = spaceMemberPresenceOfflineTimeout;
4591
4859
  trace7.diagnostic({
4592
4860
  id: "spaces",
4593
4861
  name: "Spaces",
@@ -4596,10 +4864,10 @@ var DataSpaceManager = class {
4596
4864
  const rootUrl = space.automergeSpaceState.rootUrl;
4597
4865
  const rootHandle = rootUrl ? this._echoHost.automergeRepo.find(rootUrl) : void 0;
4598
4866
  const rootDoc = rootHandle?.docSync();
4599
- const properties = rootDoc && findPropertiesObject(rootDoc);
4867
+ const properties = rootDoc && findInlineObjectOfType2(rootDoc, TYPE_PROPERTIES2);
4600
4868
  return {
4601
4869
  key: space.key.toHex(),
4602
- state: SpaceState2[space.state],
4870
+ state: SpaceState3[space.state],
4603
4871
  name: properties?.[1].data.name ?? null,
4604
4872
  inlineObjects: rootDoc ? Object.keys(rootDoc.objects ?? {}).length : null,
4605
4873
  linkedObjects: rootDoc ? Object.keys(rootDoc.links ?? {}).length : null,
@@ -4616,46 +4884,46 @@ var DataSpaceManager = class {
4616
4884
  return this._spaces;
4617
4885
  }
4618
4886
  async open() {
4619
- log13("open", void 0, {
4620
- F: __dxlog_file16,
4621
- L: 144,
4887
+ log16("open", void 0, {
4888
+ F: __dxlog_file18,
4889
+ L: 146,
4622
4890
  S: this,
4623
4891
  C: (f, a) => f(...a)
4624
4892
  });
4625
- log13.trace("dxos.echo.data-space-manager.open", Trace2.begin({
4893
+ log16.trace("dxos.echo.data-space-manager.open", Trace2.begin({
4626
4894
  id: this._instanceId
4627
4895
  }), {
4628
- F: __dxlog_file16,
4629
- L: 145,
4896
+ F: __dxlog_file18,
4897
+ L: 147,
4630
4898
  S: this,
4631
4899
  C: (f, a) => f(...a)
4632
4900
  });
4633
- log13("metadata loaded", {
4901
+ log16("metadata loaded", {
4634
4902
  spaces: this._metadataStore.spaces.length
4635
4903
  }, {
4636
- F: __dxlog_file16,
4637
- L: 146,
4904
+ F: __dxlog_file18,
4905
+ L: 148,
4638
4906
  S: this,
4639
4907
  C: (f, a) => f(...a)
4640
4908
  });
4641
4909
  await forEachAsync(this._metadataStore.spaces, async (spaceMetadata) => {
4642
4910
  try {
4643
- log13("load space", {
4911
+ log16("load space", {
4644
4912
  spaceMetadata
4645
4913
  }, {
4646
- F: __dxlog_file16,
4647
- L: 150,
4914
+ F: __dxlog_file18,
4915
+ L: 152,
4648
4916
  S: this,
4649
4917
  C: (f, a) => f(...a)
4650
4918
  });
4651
4919
  await this._constructSpace(spaceMetadata);
4652
4920
  } catch (err) {
4653
- log13.error("Error loading space", {
4921
+ log16.error("Error loading space", {
4654
4922
  spaceMetadata,
4655
4923
  err
4656
4924
  }, {
4657
- F: __dxlog_file16,
4658
- L: 153,
4925
+ F: __dxlog_file18,
4926
+ L: 155,
4659
4927
  S: this,
4660
4928
  C: (f, a) => f(...a)
4661
4929
  });
@@ -4663,24 +4931,19 @@ var DataSpaceManager = class {
4663
4931
  });
4664
4932
  this._isOpen = true;
4665
4933
  this.updated.emit();
4666
- for (const space of this._spaces.values()) {
4667
- if (space.state !== SpaceState2.INACTIVE) {
4668
- space.initializeDataPipelineAsync();
4669
- }
4670
- }
4671
- log13.trace("dxos.echo.data-space-manager.open", Trace2.end({
4934
+ log16.trace("dxos.echo.data-space-manager.open", Trace2.end({
4672
4935
  id: this._instanceId
4673
4936
  }), {
4674
- F: __dxlog_file16,
4675
- L: 166,
4937
+ F: __dxlog_file18,
4938
+ L: 162,
4676
4939
  S: this,
4677
4940
  C: (f, a) => f(...a)
4678
4941
  });
4679
4942
  }
4680
4943
  async close() {
4681
- log13("close", void 0, {
4682
- F: __dxlog_file16,
4683
- L: 171,
4944
+ log16("close", void 0, {
4945
+ F: __dxlog_file18,
4946
+ L: 167,
4684
4947
  S: this,
4685
4948
  C: (f, a) => f(...a)
4686
4949
  });
@@ -4689,14 +4952,15 @@ var DataSpaceManager = class {
4689
4952
  for (const space of this._spaces.values()) {
4690
4953
  await space.close();
4691
4954
  }
4955
+ this._spaces.clear();
4692
4956
  }
4693
4957
  /**
4694
4958
  * Creates a new space writing the genesis credentials to the control feed.
4695
4959
  */
4696
4960
  async createSpace() {
4697
4961
  invariant14(this._isOpen, "Not open.", {
4698
- F: __dxlog_file16,
4699
- L: 184,
4962
+ F: __dxlog_file18,
4963
+ L: 181,
4700
4964
  S: this,
4701
4965
  A: [
4702
4966
  "this._isOpen",
@@ -4711,24 +4975,25 @@ var DataSpaceManager = class {
4711
4975
  genesisFeedKey: controlFeedKey,
4712
4976
  controlFeedKey,
4713
4977
  dataFeedKey,
4714
- state: SpaceState2.ACTIVE
4978
+ state: SpaceState3.ACTIVE
4715
4979
  };
4716
- log13("creating space...", {
4980
+ log16("creating space...", {
4717
4981
  spaceKey
4718
4982
  }, {
4719
- F: __dxlog_file16,
4720
- L: 196,
4983
+ F: __dxlog_file18,
4984
+ L: 193,
4721
4985
  S: this,
4722
4986
  C: (f, a) => f(...a)
4723
4987
  });
4724
4988
  const root = await this._echoHost.createSpaceRoot(spaceKey);
4725
4989
  const space = await this._constructSpace(metadata);
4990
+ await space.open();
4726
4991
  const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, root.url);
4727
4992
  await this._metadataStore.addSpace(metadata);
4728
4993
  const memberCredential = credentials[1];
4729
- invariant14(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4730
- F: __dxlog_file16,
4731
- L: 205,
4994
+ invariant14(getCredentialAssertion3(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4995
+ F: __dxlog_file18,
4996
+ L: 203,
4732
4997
  S: this,
4733
4998
  A: [
4734
4999
  "getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -4740,19 +5005,85 @@ var DataSpaceManager = class {
4740
5005
  this.updated.emit();
4741
5006
  return space;
4742
5007
  }
5008
+ async isDefaultSpace(space) {
5009
+ if (!space.databaseRoot) {
5010
+ return false;
5011
+ }
5012
+ switch (space.databaseRoot.getVersion()) {
5013
+ case SpaceDocVersion2.CURRENT: {
5014
+ const [_, properties] = findInlineObjectOfType2(space.databaseRoot.docSync(), TYPE_PROPERTIES2) ?? [];
5015
+ return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
5016
+ }
5017
+ case SpaceDocVersion2.LEGACY: {
5018
+ const convertedDoc = await convertLegacyReferences2(space.databaseRoot.docSync());
5019
+ const [_, properties] = findInlineObjectOfType2(convertedDoc, LEGACY_TYPE_PROPERTIES) ?? [];
5020
+ return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
5021
+ }
5022
+ default:
5023
+ log16.warn("unknown space version", {
5024
+ version: space.databaseRoot.getVersion(),
5025
+ spaceId: space.id
5026
+ }, {
5027
+ F: __dxlog_file18,
5028
+ L: 228,
5029
+ S: this,
5030
+ C: (f, a) => f(...a)
5031
+ });
5032
+ return false;
5033
+ }
5034
+ }
5035
+ async createDefaultSpace() {
5036
+ const space = await this.createSpace();
5037
+ const document = await this._getSpaceRootDocument(space);
5038
+ const properties = {
5039
+ system: {
5040
+ type: encodeReference(getTypeReference(PropertiesType))
5041
+ },
5042
+ data: {
5043
+ [DEFAULT_SPACE_KEY]: this._signingContext.identityKey.toHex()
5044
+ },
5045
+ meta: {
5046
+ keys: []
5047
+ }
5048
+ };
5049
+ const propertiesId = generateEchoId();
5050
+ document.change((doc) => {
5051
+ assignDeep2(doc, [
5052
+ "objects",
5053
+ propertiesId
5054
+ ], properties);
5055
+ });
5056
+ await this._echoHost.flush();
5057
+ return space;
5058
+ }
5059
+ async _getSpaceRootDocument(space) {
5060
+ const automergeIndex = space.automergeSpaceState.rootUrl;
5061
+ invariant14(automergeIndex, void 0, {
5062
+ F: __dxlog_file18,
5063
+ L: 261,
5064
+ S: this,
5065
+ A: [
5066
+ "automergeIndex",
5067
+ ""
5068
+ ]
5069
+ });
5070
+ const document = this._echoHost.automergeRepo.find(automergeIndex);
5071
+ await document.whenReady();
5072
+ return document;
5073
+ }
4743
5074
  // TODO(burdon): Rename join space.
4744
5075
  async acceptSpace(opts) {
4745
- log13("accept space", {
5076
+ log16("accept space", {
4746
5077
  opts
4747
5078
  }, {
4748
- F: __dxlog_file16,
4749
- L: 217,
5079
+ F: __dxlog_file18,
5080
+ L: 270,
4750
5081
  S: this,
4751
5082
  C: (f, a) => f(...a)
4752
5083
  });
4753
5084
  invariant14(this._isOpen, "Not open.", {
4754
- F: __dxlog_file16,
4755
- L: 218,
5085
+ F: __dxlog_file18,
5086
+ L: 271,
4756
5087
  S: this,
4757
5088
  A: [
4758
5089
  "this._isOpen",
@@ -4760,8 +5091,8 @@ var DataSpaceManager = class {
4760
5091
  ]
4761
5092
  });
4762
5093
  invariant14(!this._spaces.has(opts.spaceKey), "Space already exists.", {
4763
- F: __dxlog_file16,
4764
- L: 219,
5094
+ F: __dxlog_file18,
5095
+ L: 272,
4765
5096
  S: this,
4766
5097
  A: [
4767
5098
  "!this._spaces.has(opts.spaceKey)",
@@ -4775,6 +5106,7 @@ var DataSpaceManager = class {
4775
5106
  dataTimeframe: opts.dataTimeframe
4776
5107
  };
4777
5108
  const space = await this._constructSpace(metadata);
5109
+ await space.open();
4778
5110
  await this._metadataStore.addSpace(metadata);
4779
5111
  space.initializeDataPipelineAsync();
4780
5112
  this.updated.emit();
@@ -4786,17 +5118,17 @@ var DataSpaceManager = class {
4786
5118
  * TODO(dmaretskyi): Consider removing.
4787
5119
  */
4788
5120
  async waitUntilSpaceReady(spaceKey) {
4789
- await cancelWithContext5(this._ctx, this.updated.waitForCondition(() => {
5121
+ await cancelWithContext6(this._ctx, this.updated.waitForCondition(() => {
4790
5122
  const space = this._spaces.get(spaceKey);
4791
- return !!space && space.state === SpaceState2.READY;
5123
+ return !!space && space.state === SpaceState3.READY;
4792
5124
  }));
4793
5125
  }
4794
5126
  async _constructSpace(metadata) {
4795
- log13("construct space", {
5127
+ log16("construct space", {
4796
5128
  metadata
4797
5129
  }, {
4798
- F: __dxlog_file16,
4799
- L: 252,
5130
+ F: __dxlog_file18,
5131
+ L: 306,
4800
5132
  S: this,
4801
5133
  C: (f, a) => f(...a)
4802
5134
  });
@@ -4804,8 +5136,8 @@ var DataSpaceManager = class {
4804
5136
  localPeerId: this._signingContext.deviceKey
4805
5137
  });
4806
5138
  const presence = new Presence2({
4807
- announceInterval: this._spaceMemberPresenceAnnounceInterval,
4808
- offlineTimeout: this._spaceMemberPresenceOfflineTimeout,
5139
+ announceInterval: this._params?.spaceMemberPresenceAnnounceInterval ?? PRESENCE_ANNOUNCE_INTERVAL,
5140
+ offlineTimeout: this._params?.spaceMemberPresenceOfflineTimeout ?? PRESENCE_OFFLINE_TIMEOUT,
4809
5141
  identityKey: this._signingContext.identityKey,
4810
5142
  gossip
4811
5143
  });
@@ -4832,15 +5164,15 @@ var DataSpaceManager = class {
4832
5164
  session.addExtension("dxos.mesh.teleport.automerge", this._echoHost.createReplicationExtension());
4833
5165
  },
4834
5166
  onAuthFailure: () => {
4835
- log13.warn("auth failure", void 0, {
4836
- F: __dxlog_file16,
4837
- L: 289,
5167
+ log16.warn("auth failure", void 0, {
5168
+ F: __dxlog_file18,
5169
+ L: 343,
4838
5170
  S: this,
4839
5171
  C: (f, a) => f(...a)
4840
5172
  });
4841
5173
  },
4842
5174
  onMemberRolesChanged: async (members) => {
4843
- if (dataSpace?.state === SpaceState2.READY) {
5175
+ if (dataSpace?.state === SpaceState3.READY) {
4844
5176
  this._handleMemberRoleChanges(presence, space.protocol, members);
4845
5177
  }
4846
5178
  },
@@ -4853,7 +5185,7 @@ var DataSpaceManager = class {
4853
5185
  dataFeed && await space.setDataFeed(dataFeed);
4854
5186
  const dataSpace = new DataSpace({
4855
5187
  inner: space,
4856
- initialState: metadata.state === SpaceState2.INACTIVE ? SpaceState2.INACTIVE : SpaceState2.CLOSED,
5188
+ initialState: metadata.state === SpaceState3.INACTIVE ? SpaceState3.INACTIVE : SpaceState3.CLOSED,
4857
5189
  metadataStore: this._metadataStore,
4858
5190
  gossip,
4859
5191
  presence,
@@ -4863,22 +5195,22 @@ var DataSpaceManager = class {
4863
5195
  signingContext: this._signingContext,
4864
5196
  callbacks: {
4865
5197
  beforeReady: async () => {
4866
- log13("before space ready", {
5198
+ log16("before space ready", {
4867
5199
  space: space.key
4868
5200
  }, {
4869
- F: __dxlog_file16,
4870
- L: 316,
5201
+ F: __dxlog_file18,
5202
+ L: 370,
4871
5203
  S: this,
4872
5204
  C: (f, a) => f(...a)
4873
5205
  });
4874
5206
  },
4875
5207
  afterReady: async () => {
4876
- log13("after space ready", {
5208
+ log16("after space ready", {
4877
5209
  space: space.key,
4878
5210
  open: this._isOpen
4879
5211
  }, {
4880
- F: __dxlog_file16,
4881
- L: 319,
5212
+ F: __dxlog_file18,
5213
+ L: 373,
4882
5214
  S: this,
4883
5215
  C: (f, a) => f(...a)
4884
5216
  });
@@ -4893,11 +5225,11 @@ var DataSpaceManager = class {
4893
5225
  }
4894
5226
  },
4895
5227
  beforeClose: async () => {
4896
- log13("before space close", {
5228
+ log16("before space close", {
4897
5229
  space: space.key
4898
5230
  }, {
4899
- F: __dxlog_file16,
4900
- L: 327,
5231
+ F: __dxlog_file18,
5232
+ L: 381,
4901
5233
  S: this,
4902
5234
  C: (f, a) => f(...a)
4903
5235
  });
@@ -4906,13 +5238,10 @@ var DataSpaceManager = class {
4906
5238
  cache: metadata.cache
4907
5239
  });
4908
5240
  presence.newPeer.on((peerState) => {
4909
- if (dataSpace.state === SpaceState2.READY) {
5241
+ if (dataSpace.state === SpaceState3.READY) {
4910
5242
  this._handleNewPeerConnected(space, peerState);
4911
5243
  }
4912
5244
  });
4913
- if (metadata.state !== SpaceState2.INACTIVE) {
4914
- await dataSpace.open();
4915
- }
4916
5245
  if (metadata.controlTimeframe) {
4917
5246
  dataSpace.inner.controlPipeline.state.setTargetTimeframe(metadata.controlTimeframe);
4918
5247
  }
@@ -4931,17 +5260,17 @@ var DataSpaceManager = class {
4931
5260
  return (s && member.role === SpaceMember6.Role.REMOVED !== (s.authStatus === AuthStatus.FAILURE)) ?? false;
4932
5261
  });
4933
5262
  sessionsToClose.forEach((session) => {
4934
- void session.close().catch(log13.error);
5263
+ void session.close().catch(log16.error);
4935
5264
  });
4936
5265
  closedSessions += sessionsToClose.length;
4937
5266
  }
4938
- log13("processed member role changes", {
5267
+ log16("processed member role changes", {
4939
5268
  roleChangeCount: memberInfo.length,
4940
5269
  peersOnline: presence.getPeersOnline().length,
4941
5270
  closedSessions
4942
5271
  }, {
4943
- F: __dxlog_file16,
4944
- L: 367,
5272
+ F: __dxlog_file18,
5273
+ L: 417,
4945
5274
  S: this,
4946
5275
  C: (f, a) => f(...a)
4947
5276
  });
@@ -4952,20 +5281,20 @@ var DataSpaceManager = class {
4952
5281
  if (role === SpaceMember6.Role.REMOVED) {
4953
5282
  const session = peerState.peerId && space.protocol.sessions.get(peerState.peerId);
4954
5283
  if (session != null) {
4955
- log13("closing a session with a removed peer", {
5284
+ log16("closing a session with a removed peer", {
4956
5285
  peerId: peerState.peerId
4957
5286
  }, {
4958
- F: __dxlog_file16,
4959
- L: 381,
5287
+ F: __dxlog_file18,
5288
+ L: 431,
4960
5289
  S: this,
4961
5290
  C: (f, a) => f(...a)
4962
5291
  });
4963
- void session.close().catch(log13.error);
5292
+ void session.close().catch(log16.error);
4964
5293
  }
4965
5294
  }
4966
5295
  }
4967
5296
  async _handleInvitationStatusChange(dataSpace, delegatedInvitation, isActive) {
4968
- if (dataSpace?.state !== SpaceState2.READY) {
5297
+ if (dataSpace?.state !== SpaceState3.READY) {
4969
5298
  return;
4970
5299
  }
4971
5300
  if (isActive) {
@@ -5019,15 +5348,15 @@ DataSpaceManager = _ts_decorate5([
5019
5348
  // packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
5020
5349
  import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTask as scheduleTask6 } from "@dxos/async";
5021
5350
  import { Stream as Stream10 } from "@dxos/codec-protobuf";
5022
- import { createAdmissionCredentials as createAdmissionCredentials2, getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
5351
+ import { createAdmissionCredentials as createAdmissionCredentials2, getCredentialAssertion as getCredentialAssertion4 } from "@dxos/credentials";
5023
5352
  import { raise as raise2 } from "@dxos/debug";
5024
5353
  import { writeMessages as writeMessages3 } from "@dxos/feed-store";
5025
5354
  import { invariant as invariant15 } from "@dxos/invariant";
5026
- import { log as log14 } from "@dxos/log";
5355
+ import { log as log17 } from "@dxos/log";
5027
5356
  import { ApiError, SpaceNotFoundError as SpaceNotFoundError2, encodeError, IdentityNotInitializedError, AuthorizationError as AuthorizationError2 } from "@dxos/protocols";
5028
- import { SpaceMember as SpaceMember7, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
5357
+ import { SpaceMember as SpaceMember7, SpaceState as SpaceState4 } from "@dxos/protocols/proto/dxos/client/services";
5029
5358
  import { trace as trace8 } from "@dxos/tracing";
5030
- var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
5359
+ var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
5031
5360
  var SpacesServiceImpl = class {
5032
5361
  constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
5033
5362
  this._identityManager = _identityManager;
@@ -5046,10 +5375,10 @@ var SpacesServiceImpl = class {
5046
5375
  const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError2(spaceKey));
5047
5376
  if (state) {
5048
5377
  switch (state) {
5049
- case SpaceState3.ACTIVE:
5378
+ case SpaceState4.ACTIVE:
5050
5379
  await space.activate();
5051
5380
  break;
5052
- case SpaceState3.INACTIVE:
5381
+ case SpaceState4.INACTIVE:
5053
5382
  await space.deactivate();
5054
5383
  break;
5055
5384
  default:
@@ -5071,8 +5400,8 @@ var SpacesServiceImpl = class {
5071
5400
  }
5072
5401
  const credentials = await createAdmissionCredentials2(identity.getIdentityCredentialSigner(), request.memberKey, space.key, space.genesisFeedKey, request.newRole, space.spaceState.membershipChainHeads);
5073
5402
  invariant15(credentials[0].credential, void 0, {
5074
- F: __dxlog_file17,
5075
- L: 97,
5403
+ F: __dxlog_file19,
5404
+ L: 98,
5076
5405
  S: this,
5077
5406
  A: [
5078
5407
  "credentials[0].credential",
@@ -5080,9 +5409,9 @@ var SpacesServiceImpl = class {
5080
5409
  ]
5081
5410
  });
5082
5411
  const spaceMemberCredential = credentials[0].credential.credential;
5083
- invariant15(getCredentialAssertion3(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
5084
- F: __dxlog_file17,
5085
- L: 99,
5412
+ invariant15(getCredentialAssertion4(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
5413
+ F: __dxlog_file19,
5414
+ L: 100,
5086
5415
  S: this,
5087
5416
  A: [
5088
5417
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -5096,11 +5425,11 @@ var SpacesServiceImpl = class {
5096
5425
  const scheduler = new UpdateScheduler(ctx, async () => {
5097
5426
  const dataSpaceManager = await this._getDataSpaceManager();
5098
5427
  const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
5099
- log14("update", {
5428
+ log17("update", {
5100
5429
  spaces
5101
5430
  }, {
5102
- F: __dxlog_file17,
5103
- L: 110,
5431
+ F: __dxlog_file19,
5432
+ L: 111,
5104
5433
  S: this,
5105
5434
  C: (f, a) => f(...a)
5106
5435
  });
@@ -5118,7 +5447,15 @@ var SpacesServiceImpl = class {
5118
5447
  const subscribeSpaces = () => {
5119
5448
  subscriptions.clear();
5120
5449
  for (const space of dataSpaceManager.spaces.values()) {
5121
- subscriptions.add(space.stateUpdate.on(ctx, () => scheduler.forceTrigger()));
5450
+ let lastState;
5451
+ subscriptions.add(space.stateUpdate.on(ctx, () => {
5452
+ if (space.state !== lastState) {
5453
+ scheduler.forceTrigger();
5454
+ } else {
5455
+ scheduler.trigger();
5456
+ }
5457
+ lastState = space.state;
5458
+ }));
5122
5459
  subscriptions.add(space.presence.updated.on(ctx, () => scheduler.trigger()));
5123
5460
  subscriptions.add(space.automergeSpaceState.onNewEpoch.on(ctx, () => scheduler.trigger()));
5124
5461
  subscriptions.add(space.inner.controlPipeline.state.timeframeUpdate.on(ctx, () => scheduler.trigger()));
@@ -5183,8 +5520,8 @@ var SpacesServiceImpl = class {
5183
5520
  });
5184
5521
  } else {
5185
5522
  invariant15(!credential.id, "Id on unsigned credentials is not allowed", {
5186
- F: __dxlog_file17,
5187
- L: 198,
5523
+ F: __dxlog_file19,
5524
+ L: 209,
5188
5525
  S: this,
5189
5526
  A: [
5190
5527
  "!credential.id",
@@ -5192,8 +5529,8 @@ var SpacesServiceImpl = class {
5192
5529
  ]
5193
5530
  });
5194
5531
  invariant15(this._identityManager.identity, "Identity is not available", {
5195
- F: __dxlog_file17,
5196
- L: 199,
5532
+ F: __dxlog_file19,
5533
+ L: 210,
5197
5534
  S: this,
5198
5535
  A: [
5199
5536
  "this._identityManager.identity",
@@ -5202,8 +5539,8 @@ var SpacesServiceImpl = class {
5202
5539
  });
5203
5540
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
5204
5541
  invariant15(credential.issuer.equals(signer.getIssuer()), void 0, {
5205
- F: __dxlog_file17,
5206
- L: 201,
5542
+ F: __dxlog_file19,
5543
+ L: 212,
5207
5544
  S: this,
5208
5545
  A: [
5209
5546
  "credential.issuer.equals(signer.getIssuer())",
@@ -5225,10 +5562,13 @@ var SpacesServiceImpl = class {
5225
5562
  async createEpoch({ spaceKey, migration, automergeRootUrl }) {
5226
5563
  const dataSpaceManager = await this._getDataSpaceManager();
5227
5564
  const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError2(spaceKey));
5228
- await space.createEpoch({
5565
+ const credential = await space.createEpoch({
5229
5566
  migration,
5230
5567
  newAutomergeRoot: automergeRootUrl
5231
5568
  });
5569
+ return {
5570
+ epochCredential: credential ?? void 0
5571
+ };
5232
5572
  }
5233
5573
  _serializeSpace(space) {
5234
5574
  return {
@@ -5291,9 +5631,9 @@ var SpacesServiceImpl = class {
5291
5631
  var getChannelId = (channel) => `user-channel/${channel}`;
5292
5632
 
5293
5633
  // packages/sdk/client-services/src/packlets/services/service-context.ts
5294
- import { Trigger as Trigger7 } from "@dxos/async";
5295
- import { Context as Context10, Resource } from "@dxos/context";
5296
- import { getCredentialAssertion as getCredentialAssertion4 } from "@dxos/credentials";
5634
+ import { Trigger as Trigger8 } from "@dxos/async";
5635
+ import { Context as Context10, Resource as Resource3 } from "@dxos/context";
5636
+ import { getCredentialAssertion as getCredentialAssertion5 } from "@dxos/credentials";
5297
5637
  import { failUndefined as failUndefined2 } from "@dxos/debug";
5298
5638
  import { EchoHost } from "@dxos/echo-db";
5299
5639
  import { MetadataStore, SnapshotStore, SpaceManager, valueEncoding } from "@dxos/echo-pipeline";
@@ -5301,7 +5641,7 @@ import { FeedFactory, FeedStore } from "@dxos/feed-store";
5301
5641
  import { invariant as invariant16 } from "@dxos/invariant";
5302
5642
  import { Keyring } from "@dxos/keyring";
5303
5643
  import { PublicKey as PublicKey12 } from "@dxos/keys";
5304
- import { log as log15 } from "@dxos/log";
5644
+ import { log as log18 } from "@dxos/log";
5305
5645
  import { InvalidStorageVersionError, STORAGE_VERSION as STORAGE_VERSION2, trace as trace9 } from "@dxos/protocols";
5306
5646
  import { Invitation as Invitation8 } from "@dxos/protocols/proto/dxos/client/services";
5307
5647
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
@@ -5317,8 +5657,8 @@ function _ts_decorate6(decorators, target, key, desc) {
5317
5657
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5318
5658
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5319
5659
  }
5320
- var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
5321
- var ServiceContext = class extends Resource {
5660
+ var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
5661
+ var ServiceContext = class extends Resource3 {
5322
5662
  constructor(storage, level, networkManager, signalManager, _runtimeParams) {
5323
5663
  super();
5324
5664
  this.storage = storage;
@@ -5326,7 +5666,7 @@ var ServiceContext = class extends Resource {
5326
5666
  this.networkManager = networkManager;
5327
5667
  this.signalManager = signalManager;
5328
5668
  this._runtimeParams = _runtimeParams;
5329
- this.initialized = new Trigger7();
5669
+ this.initialized = new Trigger8();
5330
5670
  this._handlerFactories = /* @__PURE__ */ new Map();
5331
5671
  this._instanceId = PublicKey12.random().toHex();
5332
5672
  this.metadataStore = new MetadataStore(storage.createDirectory("metadata"));
@@ -5352,8 +5692,7 @@ var ServiceContext = class extends Resource {
5352
5692
  });
5353
5693
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager, this._runtimeParams);
5354
5694
  this.echoHost = new EchoHost({
5355
- kv: this.level,
5356
- storage: this.storage
5695
+ kv: this.level
5357
5696
  });
5358
5697
  this.invitations = new InvitationsHandler(this.networkManager, _runtimeParams?.invitationConnectionDefaultParams);
5359
5698
  this.invitationsManager = new InvitationsManager(this.invitations, (invitation) => this.getInvitationHandler(invitation), this.metadataStore);
@@ -5361,17 +5700,17 @@ var ServiceContext = class extends Resource {
5361
5700
  }
5362
5701
  async _open(ctx) {
5363
5702
  await this._checkStorageVersion();
5364
- log15("opening...", void 0, {
5365
- F: __dxlog_file18,
5366
- L: 152,
5703
+ log18("opening...", void 0, {
5704
+ F: __dxlog_file20,
5705
+ L: 149,
5367
5706
  S: this,
5368
5707
  C: (f, a) => f(...a)
5369
5708
  });
5370
- log15.trace("dxos.sdk.service-context.open", trace9.begin({
5709
+ log18.trace("dxos.sdk.service-context.open", trace9.begin({
5371
5710
  id: this._instanceId
5372
5711
  }), {
5373
- F: __dxlog_file18,
5374
- L: 153,
5712
+ F: __dxlog_file20,
5713
+ L: 150,
5375
5714
  S: this,
5376
5715
  C: (f, a) => f(...a)
5377
5716
  });
@@ -5385,33 +5724,33 @@ var ServiceContext = class extends Resource {
5385
5724
  await this._initialize(ctx);
5386
5725
  }
5387
5726
  const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
5388
- log15("loaded persistent invitations", {
5727
+ log18("loaded persistent invitations", {
5389
5728
  count: loadedInvitations.invitations?.length
5390
5729
  }, {
5391
- F: __dxlog_file18,
5392
- L: 166,
5730
+ F: __dxlog_file20,
5731
+ L: 163,
5393
5732
  S: this,
5394
5733
  C: (f, a) => f(...a)
5395
5734
  });
5396
- log15.trace("dxos.sdk.service-context.open", trace9.end({
5735
+ log18.trace("dxos.sdk.service-context.open", trace9.end({
5397
5736
  id: this._instanceId
5398
5737
  }), {
5399
- F: __dxlog_file18,
5400
- L: 168,
5738
+ F: __dxlog_file20,
5739
+ L: 165,
5401
5740
  S: this,
5402
5741
  C: (f, a) => f(...a)
5403
5742
  });
5404
- log15("opened", void 0, {
5405
- F: __dxlog_file18,
5406
- L: 169,
5743
+ log18("opened", void 0, {
5744
+ F: __dxlog_file20,
5745
+ L: 166,
5407
5746
  S: this,
5408
5747
  C: (f, a) => f(...a)
5409
5748
  });
5410
5749
  }
5411
5750
  async _close(ctx) {
5412
- log15("closing...", void 0, {
5413
- F: __dxlog_file18,
5414
- L: 173,
5751
+ log18("closing...", void 0, {
5752
+ F: __dxlog_file20,
5753
+ L: 170,
5415
5754
  S: this,
5416
5755
  C: (f, a) => f(...a)
5417
5756
  });
@@ -5426,9 +5765,9 @@ var ServiceContext = class extends Resource {
5426
5765
  await this.echoHost.close(ctx);
5427
5766
  await this.networkManager.close();
5428
5767
  await this.signalManager.close();
5429
- log15("closed", void 0, {
5430
- F: __dxlog_file18,
5431
- L: 185,
5768
+ log18("closed", void 0, {
5769
+ F: __dxlog_file20,
5770
+ L: 182,
5432
5771
  S: this,
5433
5772
  C: (f, a) => f(...a)
5434
5773
  });
@@ -5441,8 +5780,8 @@ var ServiceContext = class extends Resource {
5441
5780
  getInvitationHandler(invitation) {
5442
5781
  const factory = this._handlerFactories.get(invitation.kind);
5443
5782
  invariant16(factory, `Unknown invitation kind: ${invitation.kind}`, {
5444
- F: __dxlog_file18,
5445
- L: 196,
5783
+ F: __dxlog_file20,
5784
+ L: 193,
5446
5785
  S: this,
5447
5786
  A: [
5448
5787
  "factory",
@@ -5472,9 +5811,9 @@ var ServiceContext = class extends Resource {
5472
5811
  }
5473
5812
  // Called when identity is created.
5474
5813
  async _initialize(ctx) {
5475
- log15("initializing spaces...", void 0, {
5476
- F: __dxlog_file18,
5477
- L: 227,
5814
+ log18("initializing spaces...", void 0, {
5815
+ F: __dxlog_file20,
5816
+ L: 224,
5478
5817
  S: this,
5479
5818
  C: (f, a) => f(...a)
5480
5819
  });
@@ -5496,8 +5835,8 @@ var ServiceContext = class extends Resource {
5496
5835
  await this.dataSpaceManager.open();
5497
5836
  this._handlerFactories.set(Invitation8.Kind.SPACE, (invitation) => {
5498
5837
  invariant16(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
5499
- F: __dxlog_file18,
5500
- L: 252,
5838
+ F: __dxlog_file20,
5839
+ L: 249,
5501
5840
  S: this,
5502
5841
  A: [
5503
5842
  "this.dataSpaceManager",
@@ -5509,7 +5848,7 @@ var ServiceContext = class extends Resource {
5509
5848
  this.initialized.wake();
5510
5849
  this._deviceSpaceSync = {
5511
5850
  processCredential: async (credential) => {
5512
- const assertion = getCredentialAssertion4(credential);
5851
+ const assertion = getCredentialAssertion5(credential);
5513
5852
  if (assertion["@type"] !== "dxos.halo.credentials.SpaceMember") {
5514
5853
  return;
5515
5854
  }
@@ -5517,33 +5856,33 @@ var ServiceContext = class extends Resource {
5517
5856
  return;
5518
5857
  }
5519
5858
  if (!this.dataSpaceManager) {
5520
- log15("dataSpaceManager not initialized yet, ignoring space admission", {
5859
+ log18("dataSpaceManager not initialized yet, ignoring space admission", {
5521
5860
  details: assertion
5522
5861
  }, {
5523
- F: __dxlog_file18,
5524
- L: 268,
5862
+ F: __dxlog_file20,
5863
+ L: 265,
5525
5864
  S: this,
5526
5865
  C: (f, a) => f(...a)
5527
5866
  });
5528
5867
  return;
5529
5868
  }
5530
5869
  if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
5531
- log15("space already exists, ignoring space admission", {
5870
+ log18("space already exists, ignoring space admission", {
5532
5871
  details: assertion
5533
5872
  }, {
5534
- F: __dxlog_file18,
5535
- L: 272,
5873
+ F: __dxlog_file20,
5874
+ L: 269,
5536
5875
  S: this,
5537
5876
  C: (f, a) => f(...a)
5538
5877
  });
5539
5878
  return;
5540
5879
  }
5541
5880
  try {
5542
- log15("accepting space recorded in halo", {
5881
+ log18("accepting space recorded in halo", {
5543
5882
  details: assertion
5544
5883
  }, {
5545
- F: __dxlog_file18,
5546
- L: 277,
5884
+ F: __dxlog_file20,
5885
+ L: 274,
5547
5886
  S: this,
5548
5887
  C: (f, a) => f(...a)
5549
5888
  });
@@ -5552,9 +5891,9 @@ var ServiceContext = class extends Resource {
5552
5891
  genesisFeedKey: assertion.genesisFeedKey
5553
5892
  });
5554
5893
  } catch (err) {
5555
- log15.catch(err, void 0, {
5556
- F: __dxlog_file18,
5557
- L: 283,
5894
+ log18.catch(err, void 0, {
5895
+ F: __dxlog_file20,
5896
+ L: 280,
5558
5897
  S: this,
5559
5898
  C: (f, a) => f(...a)
5560
5899
  });
@@ -5600,9 +5939,9 @@ var ServiceRegistry = class {
5600
5939
  };
5601
5940
 
5602
5941
  // packages/sdk/client-services/src/packlets/locks/browser.ts
5603
- import { asyncTimeout as asyncTimeout3, Trigger as Trigger8 } from "@dxos/async";
5942
+ import { asyncTimeout as asyncTimeout3, Trigger as Trigger9 } from "@dxos/async";
5604
5943
  import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
5605
- import { log as log16, logInfo } from "@dxos/log";
5944
+ import { log as log19, logInfo } from "@dxos/log";
5606
5945
  function _ts_decorate7(decorators, target, key, desc) {
5607
5946
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5608
5947
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -5613,7 +5952,7 @@ function _ts_decorate7(decorators, target, key, desc) {
5613
5952
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5614
5953
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5615
5954
  }
5616
- var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
5955
+ var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
5617
5956
  var Message;
5618
5957
  (function(Message2) {
5619
5958
  Message2["ACQUIRING"] = "acquiring";
@@ -5621,7 +5960,7 @@ var Message;
5621
5960
  var Lock = class {
5622
5961
  constructor({ lockKey, onAcquire, onRelease }) {
5623
5962
  this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
5624
- this._releaseTrigger = new Trigger8();
5963
+ this._releaseTrigger = new Trigger9();
5625
5964
  this._lockKey = lockKey;
5626
5965
  this._onAcquire = onAcquire;
5627
5966
  this._onRelease = onRelease;
@@ -5635,29 +5974,29 @@ var Lock = class {
5635
5974
  message: "acquiring"
5636
5975
  });
5637
5976
  try {
5638
- log16("aquiring lock...", void 0, {
5639
- F: __dxlog_file19,
5977
+ log19("aquiring lock...", void 0, {
5978
+ F: __dxlog_file21,
5640
5979
  L: 42,
5641
5980
  S: this,
5642
5981
  C: (f, a) => f(...a)
5643
5982
  });
5644
5983
  await asyncTimeout3(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
5645
- log16("acquired lock", void 0, {
5646
- F: __dxlog_file19,
5984
+ log19("acquired lock", void 0, {
5985
+ F: __dxlog_file21,
5647
5986
  L: 44,
5648
5987
  S: this,
5649
5988
  C: (f, a) => f(...a)
5650
5989
  });
5651
5990
  } catch {
5652
- log16("stealing lock...", void 0, {
5653
- F: __dxlog_file19,
5991
+ log19("stealing lock...", void 0, {
5992
+ F: __dxlog_file21,
5654
5993
  L: 46,
5655
5994
  S: this,
5656
5995
  C: (f, a) => f(...a)
5657
5996
  });
5658
5997
  await this._requestLock(true);
5659
- log16("stolen lock", void 0, {
5660
- F: __dxlog_file19,
5998
+ log19("stolen lock", void 0, {
5999
+ F: __dxlog_file21,
5661
6000
  L: 48,
5662
6001
  S: this,
5663
6002
  C: (f, a) => f(...a)
@@ -5673,31 +6012,31 @@ var Lock = class {
5673
6012
  }
5674
6013
  }
5675
6014
  async _requestLock(steal = false) {
5676
- log16("requesting lock...", {
6015
+ log19("requesting lock...", {
5677
6016
  steal
5678
6017
  }, {
5679
- F: __dxlog_file19,
6018
+ F: __dxlog_file21,
5680
6019
  L: 63,
5681
6020
  S: this,
5682
6021
  C: (f, a) => f(...a)
5683
6022
  });
5684
- const acquired = new Trigger8();
6023
+ const acquired = new Trigger9();
5685
6024
  void navigator.locks.request(this._lockKey, {
5686
6025
  steal
5687
6026
  }, async () => {
5688
6027
  await this._onAcquire?.();
5689
6028
  acquired.wake();
5690
- this._releaseTrigger = new Trigger8();
6029
+ this._releaseTrigger = new Trigger9();
5691
6030
  await this._releaseTrigger.wait();
5692
- log16("releasing lock...", void 0, {
5693
- F: __dxlog_file19,
6031
+ log19("releasing lock...", void 0, {
6032
+ F: __dxlog_file21,
5694
6033
  L: 72,
5695
6034
  S: this,
5696
6035
  C: (f, a) => f(...a)
5697
6036
  });
5698
6037
  await this._onRelease?.();
5699
- log16("released lock", void 0, {
5700
- F: __dxlog_file19,
6038
+ log19("released lock", void 0, {
6039
+ F: __dxlog_file21,
5701
6040
  L: 74,
5702
6041
  S: this,
5703
6042
  C: (f, a) => f(...a)
@@ -5706,10 +6045,10 @@ var Lock = class {
5706
6045
  await this._onRelease?.();
5707
6046
  });
5708
6047
  await acquired.wait();
5709
- log16("recieved lock", {
6048
+ log19("recieved lock", {
5710
6049
  steal
5711
6050
  }, {
5712
- F: __dxlog_file19,
6051
+ F: __dxlog_file21,
5713
6052
  L: 81,
5714
6053
  S: this,
5715
6054
  C: (f, a) => f(...a)
@@ -5797,29 +6136,164 @@ var createLevel = async (config) => {
5797
6136
  return level;
5798
6137
  };
5799
6138
 
6139
+ // packages/sdk/client-services/src/packlets/storage/profile-archive.ts
6140
+ import { cbor } from "@dxos/automerge/automerge-repo";
6141
+ import { invariant as invariant17 } from "@dxos/invariant";
6142
+ import { log as log20 } from "@dxos/log";
6143
+ import { ProfileArchiveEntryType } from "@dxos/protocols";
6144
+ import { arrayToBuffer } from "@dxos/util";
6145
+ var __dxlog_file22 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/storage/profile-archive.ts";
6146
+ var encodeProfileArchive = (profile) => cbor.encode(profile);
6147
+ var decodeProfileArchive = (data) => cbor.decode(data);
6148
+ var exportProfileData = async ({ storage, level }) => {
6149
+ const archive = {
6150
+ storage: [],
6151
+ meta: {
6152
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
6153
+ }
6154
+ };
6155
+ {
6156
+ const directory = await storage.createDirectory();
6157
+ const files = await directory.list();
6158
+ log20.info("begin exporting files", {
6159
+ count: files.length
6160
+ }, {
6161
+ F: __dxlog_file22,
6162
+ L: 30,
6163
+ S: void 0,
6164
+ C: (f, a) => f(...a)
6165
+ });
6166
+ for (const filename of files) {
6167
+ const file = await directory.getOrCreateFile(filename);
6168
+ const { size } = await file.stat();
6169
+ const data = await file.read(0, size);
6170
+ archive.storage.push({
6171
+ type: ProfileArchiveEntryType.FILE,
6172
+ key: filename,
6173
+ value: data
6174
+ });
6175
+ }
6176
+ log20.info("done exporting files", {
6177
+ count: files.length
6178
+ }, {
6179
+ F: __dxlog_file22,
6180
+ L: 41,
6181
+ S: void 0,
6182
+ C: (f, a) => f(...a)
6183
+ });
6184
+ }
6185
+ {
6186
+ log20.info("begin exporting kv pairs", void 0, {
6187
+ F: __dxlog_file22,
6188
+ L: 45,
6189
+ S: void 0,
6190
+ C: (f, a) => f(...a)
6191
+ });
6192
+ const iter = await level.iterator({
6193
+ keyEncoding: "binary",
6194
+ valueEncoding: "binary"
6195
+ });
6196
+ let count = 0;
6197
+ for await (const [key, value] of iter) {
6198
+ archive.storage.push({
6199
+ type: ProfileArchiveEntryType.KEY_VALUE,
6200
+ key,
6201
+ value
6202
+ });
6203
+ count++;
6204
+ }
6205
+ log20.info("done exporting kv pairs", {
6206
+ count
6207
+ }, {
6208
+ F: __dxlog_file22,
6209
+ L: 56,
6210
+ S: void 0,
6211
+ C: (f, a) => f(...a)
6212
+ });
6213
+ }
6214
+ return archive;
6215
+ };
6216
+ var importProfileData = async ({ storage, level }, archive) => {
6217
+ const batch = level.batch();
6218
+ for (const entry2 of archive.storage) {
6219
+ switch (entry2.type) {
6220
+ case ProfileArchiveEntryType.FILE: {
6221
+ const directory = await storage.createDirectory();
6222
+ invariant17(typeof entry2.key === "string", "Invalid key type", {
6223
+ F: __dxlog_file22,
6224
+ L: 78,
6225
+ S: void 0,
6226
+ A: [
6227
+ "typeof entry.key === 'string'",
6228
+ "'Invalid key type'"
6229
+ ]
6230
+ });
6231
+ const file = await directory.getOrCreateFile(entry2.key);
6232
+ invariant17(entry2.value instanceof Uint8Array, "Invalid value type", {
6233
+ F: __dxlog_file22,
6234
+ L: 80,
6235
+ S: void 0,
6236
+ A: [
6237
+ "entry.value instanceof Uint8Array",
6238
+ "'Invalid value type'"
6239
+ ]
6240
+ });
6241
+ await file.write(0, arrayToBuffer(entry2.value));
6242
+ await file.close();
6243
+ break;
6244
+ }
6245
+ case ProfileArchiveEntryType.KEY_VALUE: {
6246
+ invariant17(entry2.key instanceof Uint8Array, "Invalid key type", {
6247
+ F: __dxlog_file22,
6248
+ L: 86,
6249
+ S: void 0,
6250
+ A: [
6251
+ "entry.key instanceof Uint8Array",
6252
+ "'Invalid key type'"
6253
+ ]
6254
+ });
6255
+ invariant17(entry2.value instanceof Uint8Array, "Invalid value type", {
6256
+ F: __dxlog_file22,
6257
+ L: 87,
6258
+ S: void 0,
6259
+ A: [
6260
+ "entry.value instanceof Uint8Array",
6261
+ "'Invalid value type'"
6262
+ ]
6263
+ });
6264
+ batch.put(entry2.key, entry2.value, {
6265
+ keyEncoding: "binary",
6266
+ valueEncoding: "binary"
6267
+ });
6268
+ break;
6269
+ }
6270
+ default:
6271
+ throw new Error(`Invalid entry type: ${entry2.type}`);
6272
+ }
6273
+ }
6274
+ await batch.write();
6275
+ };
6276
+
5800
6277
  // packages/sdk/client-services/src/packlets/services/service-host.ts
5801
6278
  import { Event as Event9, synchronized as synchronized3 } from "@dxos/async";
5802
- import { clientServiceBundle, defaultKey, PropertiesType } from "@dxos/client-protocol";
6279
+ import { clientServiceBundle } from "@dxos/client-protocol";
5803
6280
  import { Context as Context11 } from "@dxos/context";
5804
- import { encodeReference } from "@dxos/echo-protocol";
5805
- import { getTypeReference } from "@dxos/echo-schema";
5806
- import { invariant as invariant18 } from "@dxos/invariant";
6281
+ import { invariant as invariant19 } from "@dxos/invariant";
5807
6282
  import { PublicKey as PublicKey16 } from "@dxos/keys";
5808
- import { log as log18 } from "@dxos/log";
6283
+ import { log as log22 } from "@dxos/log";
5809
6284
  import { WebsocketSignalManager } from "@dxos/messaging";
5810
6285
  import { SwarmNetworkManager, createSimplePeerTransportFactory } from "@dxos/network-manager";
5811
6286
  import { trace as trace10 } from "@dxos/protocols";
5812
6287
  import { SystemStatus } from "@dxos/protocols/proto/dxos/client/services";
5813
6288
  import { TRACE_PROCESSOR as TRACE_PROCESSOR3, trace as Trace4 } from "@dxos/tracing";
5814
- import { assignDeep as assignDeep2 } from "@dxos/util";
5815
6289
  import { WebsocketRpcClient } from "@dxos/websocket-rpc";
5816
6290
 
5817
6291
  // packages/sdk/client-services/src/packlets/devices/devices-service.ts
5818
6292
  import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
5819
6293
  import { Stream as Stream11 } from "@dxos/codec-protobuf";
5820
- import { invariant as invariant17 } from "@dxos/invariant";
6294
+ import { invariant as invariant18 } from "@dxos/invariant";
5821
6295
  import { Device as Device2, DeviceKind as DeviceKind2 } from "@dxos/protocols/proto/dxos/client/services";
5822
- var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
6296
+ var __dxlog_file23 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
5823
6297
  var DevicesServiceImpl = class {
5824
6298
  constructor(_identityManager) {
5825
6299
  this._identityManager = _identityManager;
@@ -5836,8 +6310,8 @@ var DevicesServiceImpl = class {
5836
6310
  devices: []
5837
6311
  });
5838
6312
  } else {
5839
- invariant17(this._identityManager.identity?.presence, "presence not present", {
5840
- F: __dxlog_file20,
6313
+ invariant18(this._identityManager.identity?.presence, "presence not present", {
6314
+ F: __dxlog_file23,
5841
6315
  L: 32,
5842
6316
  S: this,
5843
6317
  A: [
@@ -5947,7 +6421,7 @@ var findConfigs = () => {
5947
6421
  import { Event as Event8 } from "@dxos/async";
5948
6422
  import { Stream as Stream12 } from "@dxos/codec-protobuf";
5949
6423
  import { PublicKey as PublicKey15 } from "@dxos/keys";
5950
- import { getContextFromEntry, log as log17 } from "@dxos/log";
6424
+ import { getContextFromEntry, log as log21 } from "@dxos/log";
5951
6425
  import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
5952
6426
  import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
5953
6427
  var LoggingServiceImpl = class {
@@ -5960,11 +6434,11 @@ var LoggingServiceImpl = class {
5960
6434
  };
5961
6435
  }
5962
6436
  async open() {
5963
- log17.runtimeConfig.processors.push(this._logProcessor);
6437
+ log21.runtimeConfig.processors.push(this._logProcessor);
5964
6438
  }
5965
6439
  async close() {
5966
- const index = log17.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
5967
- log17.runtimeConfig.processors.splice(index, 1);
6440
+ const index = log21.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
6441
+ log21.runtimeConfig.processors.splice(index, 1);
5968
6442
  }
5969
6443
  async controlMetrics({ reset, record }) {
5970
6444
  if (reset) {
@@ -6168,7 +6642,7 @@ function _ts_decorate8(decorators, target, key, desc) {
6168
6642
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6169
6643
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6170
6644
  }
6171
- var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
6645
+ var __dxlog_file24 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
6172
6646
  var ClientServicesHost = class {
6173
6647
  constructor({
6174
6648
  config,
@@ -6188,7 +6662,7 @@ var ClientServicesHost = class {
6188
6662
  this._storage = storage;
6189
6663
  this._level = level;
6190
6664
  this._callbacks = callbacks;
6191
- this._runtimeParams = runtimeParams;
6665
+ this._runtimeParams = runtimeParams ?? {};
6192
6666
  if (config) {
6193
6667
  this.initialize({
6194
6668
  config,
@@ -6256,25 +6730,25 @@ var ClientServicesHost = class {
6256
6730
  * Can only be called once.
6257
6731
  */
6258
6732
  initialize({ config, ...options }) {
6259
- invariant18(!this._open, "service host is open", {
6260
- F: __dxlog_file21,
6261
- L: 189,
6733
+ invariant19(!this._open, "service host is open", {
6734
+ F: __dxlog_file24,
6735
+ L: 186,
6262
6736
  S: this,
6263
6737
  A: [
6264
6738
  "!this._open",
6265
6739
  "'service host is open'"
6266
6740
  ]
6267
6741
  });
6268
- log18("initializing...", void 0, {
6269
- F: __dxlog_file21,
6270
- L: 190,
6742
+ log22("initializing...", void 0, {
6743
+ F: __dxlog_file24,
6744
+ L: 187,
6271
6745
  S: this,
6272
6746
  C: (f, a) => f(...a)
6273
6747
  });
6274
6748
  if (config) {
6275
- invariant18(!this._config, "config already set", {
6276
- F: __dxlog_file21,
6277
- L: 193,
6749
+ invariant19(!this._config, "config already set", {
6750
+ F: __dxlog_file24,
6751
+ L: 190,
6278
6752
  S: this,
6279
6753
  A: [
6280
6754
  "!this._config",
@@ -6287,9 +6761,9 @@ var ClientServicesHost = class {
6287
6761
  }
6288
6762
  }
6289
6763
  if (!options.signalManager) {
6290
- log18.warn("running signaling without telemetry metadata.", void 0, {
6291
- F: __dxlog_file21,
6292
- L: 201,
6764
+ log22.warn("running signaling without telemetry metadata.", void 0, {
6765
+ F: __dxlog_file24,
6766
+ L: 198,
6293
6767
  S: this,
6294
6768
  C: (f, a) => f(...a)
6295
6769
  });
@@ -6298,9 +6772,9 @@ var ClientServicesHost = class {
6298
6772
  iceServers: this._config?.get("runtime.services.ice")
6299
6773
  }), signalManager = new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
6300
6774
  this._signalManager = signalManager;
6301
- invariant18(!this._networkManager, "network manager already set", {
6302
- F: __dxlog_file21,
6303
- L: 212,
6775
+ invariant19(!this._networkManager, "network manager already set", {
6776
+ F: __dxlog_file24,
6777
+ L: 209,
6304
6778
  S: this,
6305
6779
  A: [
6306
6780
  "!this._networkManager",
@@ -6312,9 +6786,9 @@ var ClientServicesHost = class {
6312
6786
  transportFactory,
6313
6787
  signalManager
6314
6788
  });
6315
- log18("initialized", void 0, {
6316
- F: __dxlog_file21,
6317
- L: 219,
6789
+ log22("initialized", void 0, {
6790
+ F: __dxlog_file24,
6791
+ L: 216,
6318
6792
  S: this,
6319
6793
  C: (f, a) => f(...a)
6320
6794
  });
@@ -6324,44 +6798,44 @@ var ClientServicesHost = class {
6324
6798
  return;
6325
6799
  }
6326
6800
  const traceId = PublicKey16.random().toHex();
6327
- log18.trace("dxos.client-services.host.open", trace10.begin({
6801
+ log22.trace("dxos.client-services.host.open", trace10.begin({
6328
6802
  id: traceId
6329
6803
  }), {
6330
- F: __dxlog_file21,
6331
- L: 230,
6804
+ F: __dxlog_file24,
6805
+ L: 227,
6332
6806
  S: this,
6333
6807
  C: (f, a) => f(...a)
6334
6808
  });
6335
- invariant18(this._config, "config not set", {
6336
- F: __dxlog_file21,
6337
- L: 232,
6809
+ invariant19(this._config, "config not set", {
6810
+ F: __dxlog_file24,
6811
+ L: 229,
6338
6812
  S: this,
6339
6813
  A: [
6340
6814
  "this._config",
6341
6815
  "'config not set'"
6342
6816
  ]
6343
6817
  });
6344
- invariant18(this._storage, "storage not set", {
6345
- F: __dxlog_file21,
6346
- L: 233,
6818
+ invariant19(this._storage, "storage not set", {
6819
+ F: __dxlog_file24,
6820
+ L: 230,
6347
6821
  S: this,
6348
6822
  A: [
6349
6823
  "this._storage",
6350
6824
  "'storage not set'"
6351
6825
  ]
6352
6826
  });
6353
- invariant18(this._signalManager, "signal manager not set", {
6354
- F: __dxlog_file21,
6355
- L: 234,
6827
+ invariant19(this._signalManager, "signal manager not set", {
6828
+ F: __dxlog_file24,
6829
+ L: 231,
6356
6830
  S: this,
6357
6831
  A: [
6358
6832
  "this._signalManager",
6359
6833
  "'signal manager not set'"
6360
6834
  ]
6361
6835
  });
6362
- invariant18(this._networkManager, "network manager not set", {
6363
- F: __dxlog_file21,
6364
- L: 235,
6836
+ invariant19(this._networkManager, "network manager not set", {
6837
+ F: __dxlog_file24,
6838
+ L: 232,
6365
6839
  S: this,
6366
6840
  A: [
6367
6841
  "this._networkManager",
@@ -6369,11 +6843,11 @@ var ClientServicesHost = class {
6369
6843
  ]
6370
6844
  });
6371
6845
  this._opening = true;
6372
- log18("opening...", {
6846
+ log22("opening...", {
6373
6847
  lockKey: this._resourceLock?.lockKey
6374
6848
  }, {
6375
- F: __dxlog_file21,
6376
- L: 238,
6849
+ F: __dxlog_file24,
6850
+ L: 235,
6377
6851
  S: this,
6378
6852
  C: (f, a) => f(...a)
6379
6853
  });
@@ -6384,9 +6858,10 @@ var ClientServicesHost = class {
6384
6858
  await this._level.open();
6385
6859
  await this._loggingService.open();
6386
6860
  this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._runtimeParams);
6861
+ const identityService = new IdentityServiceImpl(this._serviceContext.identityManager, this._serviceContext.keyring, () => this._serviceContext.dataSpaceManager, (params) => this._createIdentity(params), (profile) => this._serviceContext.broadcastProfileUpdate(profile));
6387
6862
  this._serviceRegistry.setServices({
6388
6863
  SystemService: this._systemService,
6389
- IdentityService: new IdentityServiceImpl((params) => this._createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring, (profile) => this._serviceContext.broadcastProfileUpdate(profile)),
6864
+ IdentityService: identityService,
6390
6865
  InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitationsManager),
6391
6866
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
6392
6867
  SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, async () => {
@@ -6406,6 +6881,7 @@ var ClientServicesHost = class {
6406
6881
  })
6407
6882
  });
6408
6883
  await this._serviceContext.open(ctx);
6884
+ await identityService.open();
6409
6885
  const devtoolsProxy = this._config?.get("runtime.client.devtoolsProxy");
6410
6886
  if (devtoolsProxy) {
6411
6887
  this._devtoolsProxy = new WebsocketRpcClient({
@@ -6421,18 +6897,18 @@ var ClientServicesHost = class {
6421
6897
  this._open = true;
6422
6898
  this._statusUpdate.emit();
6423
6899
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
6424
- log18("opened", {
6900
+ log22("opened", {
6425
6901
  deviceKey
6426
6902
  }, {
6427
- F: __dxlog_file21,
6903
+ F: __dxlog_file24,
6428
6904
  L: 314,
6429
6905
  S: this,
6430
6906
  C: (f, a) => f(...a)
6431
6907
  });
6432
- log18.trace("dxos.client-services.host.open", trace10.end({
6908
+ log22.trace("dxos.client-services.host.open", trace10.end({
6433
6909
  id: traceId
6434
6910
  }), {
6435
- F: __dxlog_file21,
6911
+ F: __dxlog_file24,
6436
6912
  L: 315,
6437
6913
  S: this,
6438
6914
  C: (f, a) => f(...a)
@@ -6443,10 +6919,10 @@ var ClientServicesHost = class {
6443
6919
  return;
6444
6920
  }
6445
6921
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
6446
- log18("closing...", {
6922
+ log22("closing...", {
6447
6923
  deviceKey
6448
6924
  }, {
6449
- F: __dxlog_file21,
6925
+ F: __dxlog_file24,
6450
6926
  L: 326,
6451
6927
  S: this,
6452
6928
  C: (f, a) => f(...a)
@@ -6461,10 +6937,10 @@ var ClientServicesHost = class {
6461
6937
  await this._level?.close();
6462
6938
  this._open = false;
6463
6939
  this._statusUpdate.emit();
6464
- log18("closed", {
6940
+ log22("closed", {
6465
6941
  deviceKey
6466
6942
  }, {
6467
- F: __dxlog_file21,
6943
+ F: __dxlog_file24,
6468
6944
  L: 335,
6469
6945
  S: this,
6470
6946
  C: (f, a) => f(...a)
@@ -6472,32 +6948,32 @@ var ClientServicesHost = class {
6472
6948
  }
6473
6949
  async reset() {
6474
6950
  const traceId = PublicKey16.random().toHex();
6475
- log18.trace("dxos.sdk.client-services-host.reset", trace10.begin({
6951
+ log22.trace("dxos.sdk.client-services-host.reset", trace10.begin({
6476
6952
  id: traceId
6477
6953
  }), {
6478
- F: __dxlog_file21,
6954
+ F: __dxlog_file24,
6479
6955
  L: 340,
6480
6956
  S: this,
6481
6957
  C: (f, a) => f(...a)
6482
6958
  });
6483
- log18.info("resetting...", void 0, {
6484
- F: __dxlog_file21,
6959
+ log22.info("resetting...", void 0, {
6960
+ F: __dxlog_file24,
6485
6961
  L: 342,
6486
6962
  S: this,
6487
6963
  C: (f, a) => f(...a)
6488
6964
  });
6489
6965
  await this._serviceContext?.close();
6490
6966
  await this._storage.reset();
6491
- log18.info("reset", void 0, {
6492
- F: __dxlog_file21,
6967
+ log22.info("reset", void 0, {
6968
+ F: __dxlog_file24,
6493
6969
  L: 345,
6494
6970
  S: this,
6495
6971
  C: (f, a) => f(...a)
6496
6972
  });
6497
- log18.trace("dxos.sdk.client-services-host.reset", trace10.end({
6973
+ log22.trace("dxos.sdk.client-services-host.reset", trace10.end({
6498
6974
  id: traceId
6499
6975
  }), {
6500
- F: __dxlog_file21,
6976
+ F: __dxlog_file24,
6501
6977
  L: 346,
6502
6978
  S: this,
6503
6979
  C: (f, a) => f(...a)
@@ -6507,38 +6983,6 @@ var ClientServicesHost = class {
6507
6983
  async _createIdentity(params) {
6508
6984
  const identity = await this._serviceContext.createIdentity(params);
6509
6985
  await this._serviceContext.initialized.wait();
6510
- const space = await this._serviceContext.dataSpaceManager.createSpace();
6511
- const automergeIndex = space.automergeSpaceState.rootUrl;
6512
- invariant18(automergeIndex, void 0, {
6513
- F: __dxlog_file21,
6514
- L: 358,
6515
- S: this,
6516
- A: [
6517
- "automergeIndex",
6518
- ""
6519
- ]
6520
- });
6521
- const document = this._serviceContext.echoHost.automergeRepo.find(automergeIndex);
6522
- await document.whenReady();
6523
- const properties = {
6524
- system: {
6525
- type: encodeReference(getTypeReference(PropertiesType))
6526
- },
6527
- data: {
6528
- [defaultKey]: identity.identityKey.toHex()
6529
- },
6530
- meta: {
6531
- keys: []
6532
- }
6533
- };
6534
- const propertiesId = PublicKey16.random().toHex();
6535
- document.change((doc) => {
6536
- assignDeep2(doc, [
6537
- "objects",
6538
- propertiesId
6539
- ], properties);
6540
- });
6541
- await this._serviceContext.echoHost.flush();
6542
6986
  return identity;
6543
6987
  }
6544
6988
  };
@@ -6588,7 +7032,6 @@ export {
6588
7032
  SpaceInvitationProtocol,
6589
7033
  InvitationsManager,
6590
7034
  DataSpace,
6591
- findPropertiesObject,
6592
7035
  DataSpaceManager,
6593
7036
  SpacesServiceImpl,
6594
7037
  ServiceContext,
@@ -6597,8 +7040,12 @@ export {
6597
7040
  isLocked,
6598
7041
  createStorageObjects,
6599
7042
  createLevel,
7043
+ encodeProfileArchive,
7044
+ decodeProfileArchive,
7045
+ exportProfileData,
7046
+ importProfileData,
6600
7047
  ClientServicesHost,
6601
7048
  ClientServicesProviderResource,
6602
7049
  DiagnosticsCollector
6603
7050
  };
6604
- //# sourceMappingURL=chunk-LKSDZ2AB.mjs.map
7051
+ //# sourceMappingURL=chunk-Q2PH3QCC.mjs.map