@dxos/client-services 0.5.9-main.d9a4917 → 0.5.9-main.df0042a

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 (53) hide show
  1. package/dist/lib/browser/{chunk-XEG7XZN4.mjs → chunk-SLSPX47D.mjs} +1061 -788
  2. package/dist/lib/browser/chunk-SLSPX47D.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -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-VOMDZDUH.cjs → chunk-2K5VPBW6.cjs} +1319 -1053
  9. package/dist/lib/node/chunk-2K5VPBW6.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +41 -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/testing/test-builder.d.ts +8 -6
  35. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  36. package/dist/types/src/version.d.ts +1 -1
  37. package/package.json +36 -36
  38. package/src/packlets/identity/default-space-state-machine.ts +44 -0
  39. package/src/packlets/identity/identity-service.test.ts +35 -5
  40. package/src/packlets/identity/identity-service.ts +55 -8
  41. package/src/packlets/identity/identity.ts +25 -2
  42. package/src/packlets/services/service-context.ts +1 -4
  43. package/src/packlets/services/service-host.ts +13 -40
  44. package/src/packlets/spaces/automerge-space-state.ts +11 -2
  45. package/src/packlets/spaces/data-space-manager.test.ts +46 -1
  46. package/src/packlets/spaces/data-space-manager.ts +81 -31
  47. package/src/packlets/spaces/data-space.ts +82 -149
  48. package/src/packlets/spaces/epoch-migrations.ts +135 -0
  49. package/src/packlets/spaces/spaces-service.ts +4 -2
  50. package/src/packlets/testing/test-builder.ts +12 -10
  51. package/src/version.ts +1 -1
  52. package/dist/lib/browser/chunk-XEG7XZN4.mjs.map +0 -7
  53. package/dist/lib/node/chunk-VOMDZDUH.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.d9a4917";
358
+ var DXOS_VERSION = "0.5.9-main.df0042a";
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)
@@ -1441,24 +1520,50 @@ IdentityManager = _ts_decorate3([
1441
1520
 
1442
1521
  // packages/sdk/client-services/src/packlets/identity/identity-service.ts
1443
1522
  import { Stream as Stream8 } from "@dxos/codec-protobuf";
1523
+ import { Resource } from "@dxos/context";
1444
1524
  import { signPresentation } from "@dxos/credentials";
1445
1525
  import { todo } from "@dxos/debug";
1446
1526
  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;
1527
+ import { SpaceState } from "@dxos/protocols/proto/dxos/client/services";
1528
+ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
1529
+ var IdentityServiceImpl = class extends Resource {
1530
+ constructor(_identityManager, _keyring, _dataSpaceManagerProvider, _createIdentity, _onProfileUpdate) {
1531
+ super();
1451
1532
  this._identityManager = _identityManager;
1452
1533
  this._keyring = _keyring;
1534
+ this._dataSpaceManagerProvider = _dataSpaceManagerProvider;
1535
+ this._createIdentity = _createIdentity;
1453
1536
  this._onProfileUpdate = _onProfileUpdate;
1454
1537
  }
1538
+ async _open() {
1539
+ const identity = this._identityManager.identity;
1540
+ if (identity && !identity.defaultSpaceId) {
1541
+ await this._fixIdentityWithoutDefaultSpace(identity);
1542
+ }
1543
+ }
1455
1544
  async createIdentity(request) {
1456
1545
  await this._createIdentity({
1457
1546
  displayName: request.profile?.displayName,
1458
1547
  deviceProfile: request.deviceProfile
1459
1548
  });
1549
+ const dataSpaceManager = this._dataSpaceManagerProvider();
1550
+ await this._createDefaultSpace(dataSpaceManager);
1460
1551
  return this._getIdentity();
1461
1552
  }
1553
+ async _createDefaultSpace(dataSpaceManager) {
1554
+ const space = await dataSpaceManager.createDefaultSpace();
1555
+ const identity = this._identityManager.identity;
1556
+ invariant4(identity, void 0, {
1557
+ F: __dxlog_file7,
1558
+ L: 54,
1559
+ S: this,
1560
+ A: [
1561
+ "identity",
1562
+ ""
1563
+ ]
1564
+ });
1565
+ await identity.updateDefaultSpace(space.id);
1566
+ }
1462
1567
  async recoverIdentity(request) {
1463
1568
  return todo();
1464
1569
  }
@@ -1483,8 +1588,8 @@ var IdentityServiceImpl = class {
1483
1588
  }
1484
1589
  async updateProfile(profile) {
1485
1590
  invariant4(this._identityManager.identity, "Identity not initialized.", {
1486
- F: __dxlog_file6,
1487
- L: 61,
1591
+ F: __dxlog_file7,
1592
+ L: 84,
1488
1593
  S: this,
1489
1594
  A: [
1490
1595
  "this._identityManager.identity",
@@ -1497,8 +1602,8 @@ var IdentityServiceImpl = class {
1497
1602
  }
1498
1603
  async signPresentation({ presentation, nonce }) {
1499
1604
  invariant4(this._identityManager.identity, "Identity not initialized.", {
1500
- F: __dxlog_file6,
1501
- L: 68,
1605
+ F: __dxlog_file7,
1606
+ L: 91,
1502
1607
  S: this,
1503
1608
  A: [
1504
1609
  "this._identityManager.identity",
@@ -1513,13 +1618,35 @@ var IdentityServiceImpl = class {
1513
1618
  nonce
1514
1619
  });
1515
1620
  }
1621
+ async _fixIdentityWithoutDefaultSpace(identity) {
1622
+ let hasDefaultSpace = false;
1623
+ const dataSpaceManager = this._dataSpaceManagerProvider();
1624
+ for (const space of dataSpaceManager.spaces.values()) {
1625
+ if (space.state === SpaceState.CLOSED) {
1626
+ await space.open();
1627
+ const requiresMigration = space.stateUpdate.waitForCondition(() => space.state === SpaceState.REQUIRES_MIGRATION);
1628
+ await Promise.race([
1629
+ space.initializeDataPipeline(),
1630
+ requiresMigration
1631
+ ]);
1632
+ }
1633
+ if (await dataSpaceManager.isDefaultSpace(space)) {
1634
+ await identity.updateDefaultSpace(space.id);
1635
+ hasDefaultSpace = true;
1636
+ break;
1637
+ }
1638
+ }
1639
+ if (!hasDefaultSpace) {
1640
+ await this._createDefaultSpace(dataSpaceManager);
1641
+ }
1642
+ }
1516
1643
  };
1517
1644
 
1518
1645
  // packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts
1519
1646
  import { invariant as invariant5 } from "@dxos/invariant";
1520
1647
  import { AlreadyJoinedError } from "@dxos/protocols";
1521
1648
  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";
1649
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts";
1523
1650
  var DeviceInvitationProtocol = class {
1524
1651
  constructor(_keyring, _getIdentity, _acceptIdentity) {
1525
1652
  this._keyring = _keyring;
@@ -1545,7 +1672,7 @@ var DeviceInvitationProtocol = class {
1545
1672
  }
1546
1673
  async admit(_, request) {
1547
1674
  invariant5(request.device, void 0, {
1548
- F: __dxlog_file7,
1675
+ F: __dxlog_file8,
1549
1676
  L: 50,
1550
1677
  S: this,
1551
1678
  A: [
@@ -1591,7 +1718,7 @@ var DeviceInvitationProtocol = class {
1591
1718
  }
1592
1719
  async accept(response, request) {
1593
1720
  invariant5(response.device, void 0, {
1594
- F: __dxlog_file7,
1721
+ F: __dxlog_file8,
1595
1722
  L: 95,
1596
1723
  S: this,
1597
1724
  A: [
@@ -1601,7 +1728,7 @@ var DeviceInvitationProtocol = class {
1601
1728
  });
1602
1729
  const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
1603
1730
  invariant5(request.device, void 0, {
1604
- F: __dxlog_file7,
1731
+ F: __dxlog_file8,
1605
1732
  L: 98,
1606
1733
  S: this,
1607
1734
  A: [
@@ -1633,7 +1760,7 @@ import { ContextDisposedError as ContextDisposedError2 } from "@dxos/context";
1633
1760
  import { createKeyPair, sign } from "@dxos/crypto";
1634
1761
  import { invariant as invariant9 } from "@dxos/invariant";
1635
1762
  import { PublicKey as PublicKey7 } from "@dxos/keys";
1636
- import { log as log8 } from "@dxos/log";
1763
+ import { log as log9 } from "@dxos/log";
1637
1764
  import { createTeleportProtocolFactory } from "@dxos/network-manager";
1638
1765
  import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError3, trace as trace5 } from "@dxos/protocols";
1639
1766
  import { Invitation as Invitation4 } from "@dxos/protocols/proto/dxos/client/services";
@@ -1645,7 +1772,7 @@ import { ComplexSet as ComplexSet3 } from "@dxos/util";
1645
1772
  import { Trigger as Trigger3 } from "@dxos/async";
1646
1773
  import { cancelWithContext as cancelWithContext2, Context as Context4 } from "@dxos/context";
1647
1774
  import { invariant as invariant6 } from "@dxos/invariant";
1648
- import { log as log5 } from "@dxos/log";
1775
+ import { log as log6 } from "@dxos/log";
1649
1776
  import { InvalidInvitationExtensionRoleError, schema as schema2 } from "@dxos/protocols";
1650
1777
  import { Options } from "@dxos/protocols/proto/dxos/halo/invitations";
1651
1778
  import { RpcExtension } from "@dxos/teleport";
@@ -1670,7 +1797,7 @@ var tryAcquireBeforeContextDisposed = async (ctx, mutex) => {
1670
1797
  };
1671
1798
 
1672
1799
  // 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";
1800
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts";
1674
1801
  var OPTIONS_TIMEOUT = 1e4;
1675
1802
  var InvitationGuestExtension = class extends RpcExtension {
1676
1803
  constructor(_invitationFlowMutex, _callbacks) {
@@ -1696,7 +1823,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1696
1823
  InvitationHostService: {
1697
1824
  options: async (options) => {
1698
1825
  invariant6(!this._remoteOptions, "Remote options already set.", {
1699
- F: __dxlog_file8,
1826
+ F: __dxlog_file9,
1700
1827
  L: 63,
1701
1828
  S: this,
1702
1829
  A: [
@@ -1722,15 +1849,15 @@ var InvitationGuestExtension = class extends RpcExtension {
1722
1849
  async onOpen(context) {
1723
1850
  await super.onOpen(context);
1724
1851
  try {
1725
- log5("guest acquire lock", void 0, {
1726
- F: __dxlog_file8,
1852
+ log6("guest acquire lock", void 0, {
1853
+ F: __dxlog_file9,
1727
1854
  L: 84,
1728
1855
  S: this,
1729
1856
  C: (f, a) => f(...a)
1730
1857
  });
1731
1858
  this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
1732
- log5("guest lock acquired", void 0, {
1733
- F: __dxlog_file8,
1859
+ log6("guest lock acquired", void 0, {
1860
+ F: __dxlog_file9,
1734
1861
  L: 86,
1735
1862
  S: this,
1736
1863
  C: (f, a) => f(...a)
@@ -1738,8 +1865,8 @@ var InvitationGuestExtension = class extends RpcExtension {
1738
1865
  await cancelWithContext2(this._ctx, this.rpc.InvitationHostService.options({
1739
1866
  role: Options.Role.GUEST
1740
1867
  }));
1741
- log5("options sent", void 0, {
1742
- F: __dxlog_file8,
1868
+ log6("options sent", void 0, {
1869
+ F: __dxlog_file9,
1743
1870
  L: 88,
1744
1871
  S: this,
1745
1872
  C: (f, a) => f(...a)
@@ -1747,8 +1874,8 @@ var InvitationGuestExtension = class extends RpcExtension {
1747
1874
  await cancelWithContext2(this._ctx, this._remoteOptionsTrigger.wait({
1748
1875
  timeout: OPTIONS_TIMEOUT
1749
1876
  }));
1750
- log5("options received", void 0, {
1751
- F: __dxlog_file8,
1877
+ log6("options received", void 0, {
1878
+ F: __dxlog_file9,
1752
1879
  L: 90,
1753
1880
  S: this,
1754
1881
  C: (f, a) => f(...a)
@@ -1781,8 +1908,8 @@ var InvitationGuestExtension = class extends RpcExtension {
1781
1908
  if (this._invitationFlowLock != null) {
1782
1909
  this._invitationFlowLock.release();
1783
1910
  this._invitationFlowLock = null;
1784
- log5("invitation flow lock released", void 0, {
1785
- F: __dxlog_file8,
1911
+ log6("invitation flow lock released", void 0, {
1912
+ F: __dxlog_file9,
1786
1913
  L: 123,
1787
1914
  S: this,
1788
1915
  C: (f, a) => f(...a)
@@ -1797,12 +1924,12 @@ import { cancelWithContext as cancelWithContext3, Context as Context5 } from "@d
1797
1924
  import { randomBytes, verify } from "@dxos/crypto";
1798
1925
  import { invariant as invariant7, InvariantViolation } from "@dxos/invariant";
1799
1926
  import { PublicKey as PublicKey5 } from "@dxos/keys";
1800
- import { log as log6 } from "@dxos/log";
1927
+ import { log as log7 } from "@dxos/log";
1801
1928
  import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError2, schema as schema3, trace as trace4 } from "@dxos/protocols";
1802
1929
  import { Invitation as Invitation3 } from "@dxos/protocols/proto/dxos/client/services";
1803
1930
  import { AuthenticationResponse, Options as Options2 } from "@dxos/protocols/proto/dxos/halo/invitations";
1804
1931
  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";
1932
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts";
1806
1933
  var OPTIONS_TIMEOUT2 = 1e4;
1807
1934
  var MAX_OTP_ATTEMPTS = 3;
1808
1935
  var InvitationHostExtension = class extends RpcExtension2 {
@@ -1836,7 +1963,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
1836
1963
  InvitationHostService: {
1837
1964
  options: async (options) => {
1838
1965
  invariant7(!this._remoteOptions, "Remote options already set.", {
1839
- F: __dxlog_file9,
1966
+ F: __dxlog_file10,
1840
1967
  L: 101,
1841
1968
  S: this,
1842
1969
  A: [
@@ -1850,10 +1977,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
1850
1977
  introduce: async (request) => {
1851
1978
  const { profile, invitationId } = request;
1852
1979
  const traceId = PublicKey5.random().toHex();
1853
- log6.trace("dxos.sdk.invitation-handler.host.introduce", trace4.begin({
1980
+ log7.trace("dxos.sdk.invitation-handler.host.introduce", trace4.begin({
1854
1981
  id: traceId
1855
1982
  }), {
1856
- F: __dxlog_file9,
1983
+ F: __dxlog_file10,
1857
1984
  L: 110,
1858
1985
  S: this,
1859
1986
  C: (f, a) => f(...a)
@@ -1861,11 +1988,11 @@ var InvitationHostExtension = class extends RpcExtension2 {
1861
1988
  const invitation = this._requireActiveInvitation();
1862
1989
  this._assertInvitationState(Invitation3.State.CONNECTED);
1863
1990
  if (invitationId !== invitation?.invitationId) {
1864
- log6.warn("incorrect invitationId", {
1991
+ log7.warn("incorrect invitationId", {
1865
1992
  expected: invitation.invitationId,
1866
1993
  actual: invitationId
1867
1994
  }, {
1868
- F: __dxlog_file9,
1995
+ F: __dxlog_file10,
1869
1996
  L: 116,
1870
1997
  S: this,
1871
1998
  C: (f, a) => f(...a)
@@ -1876,10 +2003,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
1876
2003
  authMethod: Invitation3.AuthMethod.NONE
1877
2004
  };
1878
2005
  }
1879
- log6("guest introduced themselves", {
2006
+ log7("guest introduced themselves", {
1880
2007
  guestProfile: profile
1881
2008
  }, {
1882
- F: __dxlog_file9,
2009
+ F: __dxlog_file10,
1883
2010
  L: 125,
1884
2011
  S: this,
1885
2012
  C: (f, a) => f(...a)
@@ -1887,10 +2014,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
1887
2014
  this.guestProfile = profile;
1888
2015
  this._callbacks.onStateUpdate(Invitation3.State.READY_FOR_AUTHENTICATION);
1889
2016
  this._challenge = invitation.authMethod === Invitation3.AuthMethod.KNOWN_PUBLIC_KEY ? randomBytes(32) : void 0;
1890
- log6.trace("dxos.sdk.invitation-handler.host.introduce", trace4.end({
2017
+ log7.trace("dxos.sdk.invitation-handler.host.introduce", trace4.end({
1891
2018
  id: traceId
1892
2019
  }), {
1893
- F: __dxlog_file9,
2020
+ F: __dxlog_file10,
1894
2021
  L: 132,
1895
2022
  S: this,
1896
2023
  C: (f, a) => f(...a)
@@ -1902,19 +2029,19 @@ var InvitationHostExtension = class extends RpcExtension2 {
1902
2029
  },
1903
2030
  authenticate: async ({ authCode: code, signedChallenge }) => {
1904
2031
  const traceId = PublicKey5.random().toHex();
1905
- log6.trace("dxos.sdk.invitation-handler.host.authenticate", trace4.begin({
2032
+ log7.trace("dxos.sdk.invitation-handler.host.authenticate", trace4.begin({
1906
2033
  id: traceId
1907
2034
  }), {
1908
- F: __dxlog_file9,
2035
+ F: __dxlog_file10,
1909
2036
  L: 141,
1910
2037
  S: this,
1911
2038
  C: (f, a) => f(...a)
1912
2039
  });
1913
2040
  const invitation = this._requireActiveInvitation();
1914
- log6("received authentication request", {
2041
+ log7("received authentication request", {
1915
2042
  authCode: code
1916
2043
  }, {
1917
- F: __dxlog_file9,
2044
+ F: __dxlog_file10,
1918
2045
  L: 144,
1919
2046
  S: this,
1920
2047
  C: (f, a) => f(...a)
@@ -1927,8 +2054,8 @@ var InvitationHostExtension = class extends RpcExtension2 {
1927
2054
  this._callbacks.onStateUpdate(Invitation3.State.AUTHENTICATING);
1928
2055
  switch (invitation.authMethod) {
1929
2056
  case Invitation3.AuthMethod.NONE: {
1930
- log6("authentication not required", void 0, {
1931
- F: __dxlog_file9,
2057
+ log7("authentication not required", void 0, {
2058
+ F: __dxlog_file10,
1932
2059
  L: 152,
1933
2060
  S: this,
1934
2061
  C: (f, a) => f(...a)
@@ -1963,10 +2090,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
1963
2090
  break;
1964
2091
  }
1965
2092
  default: {
1966
- log6.error("invalid authentication method", {
2093
+ log7.error("invalid authentication method", {
1967
2094
  authMethod: invitation.authMethod
1968
2095
  }, {
1969
- F: __dxlog_file9,
2096
+ F: __dxlog_file10,
1970
2097
  L: 190,
1971
2098
  S: this,
1972
2099
  C: (f, a) => f(...a)
@@ -1985,13 +2112,13 @@ var InvitationHostExtension = class extends RpcExtension2 {
1985
2112
  status
1986
2113
  };
1987
2114
  }
1988
- log6.trace("dxos.sdk.invitation-handler.host.authenticate", trace4.end({
2115
+ log7.trace("dxos.sdk.invitation-handler.host.authenticate", trace4.end({
1989
2116
  id: traceId,
1990
2117
  data: {
1991
2118
  status
1992
2119
  }
1993
2120
  }), {
1994
- F: __dxlog_file9,
2121
+ F: __dxlog_file10,
1995
2122
  L: 202,
1996
2123
  S: this,
1997
2124
  C: (f, a) => f(...a)
@@ -2002,10 +2129,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
2002
2129
  },
2003
2130
  admit: async (request) => {
2004
2131
  const traceId = PublicKey5.random().toHex();
2005
- log6.trace("dxos.sdk.invitation-handler.host.admit", trace4.begin({
2132
+ log7.trace("dxos.sdk.invitation-handler.host.admit", trace4.begin({
2006
2133
  id: traceId
2007
2134
  }), {
2008
- F: __dxlog_file9,
2135
+ F: __dxlog_file10,
2009
2136
  L: 208,
2010
2137
  S: this,
2011
2138
  C: (f, a) => f(...a)
@@ -2019,10 +2146,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
2019
2146
  }
2020
2147
  }
2021
2148
  const response = await this._callbacks.admit(request);
2022
- log6.trace("dxos.sdk.invitation-handler.host.admit", trace4.end({
2149
+ log7.trace("dxos.sdk.invitation-handler.host.admit", trace4.end({
2023
2150
  id: traceId
2024
2151
  }), {
2025
- F: __dxlog_file9,
2152
+ F: __dxlog_file10,
2026
2153
  L: 222,
2027
2154
  S: this,
2028
2155
  C: (f, a) => f(...a)
@@ -2039,15 +2166,15 @@ var InvitationHostExtension = class extends RpcExtension2 {
2039
2166
  async onOpen(context) {
2040
2167
  await super.onOpen(context);
2041
2168
  try {
2042
- log6("host acquire lock", void 0, {
2043
- F: __dxlog_file9,
2169
+ log7("host acquire lock", void 0, {
2170
+ F: __dxlog_file10,
2044
2171
  L: 237,
2045
2172
  S: this,
2046
2173
  C: (f, a) => f(...a)
2047
2174
  });
2048
2175
  this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
2049
- log6("host lock acquired", void 0, {
2050
- F: __dxlog_file9,
2176
+ log7("host lock acquired", void 0, {
2177
+ F: __dxlog_file10,
2051
2178
  L: 239,
2052
2179
  S: this,
2053
2180
  C: (f, a) => f(...a)
@@ -2057,8 +2184,8 @@ var InvitationHostExtension = class extends RpcExtension2 {
2057
2184
  await this.rpc.InvitationHostService.options({
2058
2185
  role: Options2.Role.HOST
2059
2186
  });
2060
- log6("options sent", void 0, {
2061
- F: __dxlog_file9,
2187
+ log7("options sent", void 0, {
2188
+ F: __dxlog_file10,
2062
2189
  L: 243,
2063
2190
  S: this,
2064
2191
  C: (f, a) => f(...a)
@@ -2066,8 +2193,8 @@ var InvitationHostExtension = class extends RpcExtension2 {
2066
2193
  await cancelWithContext3(this._ctx, this._remoteOptionsTrigger.wait({
2067
2194
  timeout: OPTIONS_TIMEOUT2
2068
2195
  }));
2069
- log6("options received", void 0, {
2070
- F: __dxlog_file9,
2196
+ log7("options received", void 0, {
2197
+ F: __dxlog_file10,
2071
2198
  L: 245,
2072
2199
  S: this,
2073
2200
  C: (f, a) => f(...a)
@@ -2120,8 +2247,8 @@ var InvitationHostExtension = class extends RpcExtension2 {
2120
2247
  if (this._invitationFlowLock != null) {
2121
2248
  this._invitationFlowLock?.release();
2122
2249
  this._invitationFlowLock = null;
2123
- log6("invitation flow lock released", void 0, {
2124
- F: __dxlog_file9,
2250
+ log7("invitation flow lock released", void 0, {
2251
+ F: __dxlog_file10,
2125
2252
  L: 300,
2126
2253
  S: this,
2127
2254
  C: (f, a) => f(...a)
@@ -2134,10 +2261,10 @@ var isAuthenticationRequired = (invitation) => invitation.authMethod !== Invitat
2134
2261
  // packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts
2135
2262
  import { invariant as invariant8 } from "@dxos/invariant";
2136
2263
  import { PublicKey as PublicKey6 } from "@dxos/keys";
2137
- import { log as log7 } from "@dxos/log";
2264
+ import { log as log8 } from "@dxos/log";
2138
2265
  import { Options as Options3 } from "@dxos/protocols/proto/dxos/halo/invitations";
2139
2266
  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";
2267
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts";
2141
2268
  var InvitationTopology = class {
2142
2269
  constructor(_role) {
2143
2270
  this._role = _role;
@@ -2145,7 +2272,7 @@ var InvitationTopology = class {
2145
2272
  }
2146
2273
  init(controller) {
2147
2274
  invariant8(!this._controller, "Already initialized.", {
2148
- F: __dxlog_file10,
2275
+ F: __dxlog_file11,
2149
2276
  L: 42,
2150
2277
  S: this,
2151
2278
  A: [
@@ -2157,7 +2284,7 @@ var InvitationTopology = class {
2157
2284
  }
2158
2285
  update() {
2159
2286
  invariant8(this._controller, "Not initialized.", {
2160
- F: __dxlog_file10,
2287
+ F: __dxlog_file11,
2161
2288
  L: 47,
2162
2289
  S: this,
2163
2290
  A: [
@@ -2176,11 +2303,11 @@ var InvitationTopology = class {
2176
2303
  const firstUnknownPeer = candidates.find((peerId) => !this._seenPeers.has(peerId));
2177
2304
  this._seenPeers = new ComplexSet2(PublicKey6.hash, allPeers.filter((peerId) => this._seenPeers.has(peerId)));
2178
2305
  if (firstUnknownPeer != null) {
2179
- log7("invitation connect", {
2306
+ log8("invitation connect", {
2180
2307
  ownPeerId,
2181
2308
  remotePeerId: firstUnknownPeer
2182
2309
  }, {
2183
- F: __dxlog_file10,
2310
+ F: __dxlog_file11,
2184
2311
  L: 69,
2185
2312
  S: this,
2186
2313
  C: (f, a) => f(...a)
@@ -2191,7 +2318,7 @@ var InvitationTopology = class {
2191
2318
  }
2192
2319
  async onOffer(peer) {
2193
2320
  invariant8(this._controller, "Not initialized.", {
2194
- F: __dxlog_file10,
2321
+ F: __dxlog_file11,
2195
2322
  L: 76,
2196
2323
  S: this,
2197
2324
  A: [
@@ -2210,7 +2337,7 @@ var InvitationTopology = class {
2210
2337
  };
2211
2338
 
2212
2339
  // 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";
2340
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts";
2214
2341
  var MAX_DELEGATED_INVITATION_HOST_TRIES = 3;
2215
2342
  var InvitationsHandler = class {
2216
2343
  /**
@@ -2235,7 +2362,7 @@ var InvitationsHandler = class {
2235
2362
  try {
2236
2363
  const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
2237
2364
  invariant9(deviceKey, void 0, {
2238
- F: __dxlog_file11,
2365
+ F: __dxlog_file12,
2239
2366
  L: 90,
2240
2367
  S: this,
2241
2368
  A: [
@@ -2261,18 +2388,18 @@ var InvitationsHandler = class {
2261
2388
  scheduleTask3(connectionCtx, async () => {
2262
2389
  const traceId = PublicKey7.random().toHex();
2263
2390
  try {
2264
- log8.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.begin({
2391
+ log9.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.begin({
2265
2392
  id: traceId
2266
2393
  }), {
2267
- F: __dxlog_file11,
2394
+ F: __dxlog_file12,
2268
2395
  L: 115,
2269
2396
  S: this,
2270
2397
  C: (f, a) => f(...a)
2271
2398
  });
2272
- log8("connected", {
2399
+ log9("connected", {
2273
2400
  ...protocol.toJSON()
2274
2401
  }, {
2275
- F: __dxlog_file11,
2402
+ F: __dxlog_file12,
2276
2403
  L: 116,
2277
2404
  S: this,
2278
2405
  C: (f, a) => f(...a)
@@ -2280,20 +2407,20 @@ var InvitationsHandler = class {
2280
2407
  const deviceKey = await extension.completedTrigger.wait({
2281
2408
  timeout: invitation.timeout
2282
2409
  });
2283
- log8("admitted guest", {
2410
+ log9("admitted guest", {
2284
2411
  guest: deviceKey,
2285
2412
  ...protocol.toJSON()
2286
2413
  }, {
2287
- F: __dxlog_file11,
2414
+ F: __dxlog_file12,
2288
2415
  L: 118,
2289
2416
  S: this,
2290
2417
  C: (f, a) => f(...a)
2291
2418
  });
2292
2419
  guardedState.set(extension, Invitation4.State.SUCCESS);
2293
- log8.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.end({
2420
+ log9.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.end({
2294
2421
  id: traceId
2295
2422
  }), {
2296
- F: __dxlog_file11,
2423
+ F: __dxlog_file12,
2297
2424
  L: 120,
2298
2425
  S: this,
2299
2426
  C: (f, a) => f(...a)
@@ -2305,10 +2432,10 @@ var InvitationsHandler = class {
2305
2432
  } catch (err) {
2306
2433
  if (err instanceof TimeoutError) {
2307
2434
  if (guardedState.set(extension, Invitation4.State.TIMEOUT)) {
2308
- log8("timeout", {
2435
+ log9("timeout", {
2309
2436
  ...protocol.toJSON()
2310
2437
  }, {
2311
- F: __dxlog_file11,
2438
+ F: __dxlog_file12,
2312
2439
  L: 129,
2313
2440
  S: this,
2314
2441
  C: (f, a) => f(...a)
@@ -2316,19 +2443,19 @@ var InvitationsHandler = class {
2316
2443
  }
2317
2444
  } else {
2318
2445
  if (guardedState.error(extension, err)) {
2319
- log8.error("failed", err, {
2320
- F: __dxlog_file11,
2446
+ log9.error("failed", err, {
2447
+ F: __dxlog_file12,
2321
2448
  L: 133,
2322
2449
  S: this,
2323
2450
  C: (f, a) => f(...a)
2324
2451
  });
2325
2452
  }
2326
2453
  }
2327
- log8.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.error({
2454
+ log9.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.error({
2328
2455
  id: traceId,
2329
2456
  error: err
2330
2457
  }), {
2331
- F: __dxlog_file11,
2458
+ F: __dxlog_file12,
2332
2459
  L: 136,
2333
2460
  S: this,
2334
2461
  C: (f, a) => f(...a)
@@ -2339,10 +2466,10 @@ var InvitationsHandler = class {
2339
2466
  },
2340
2467
  onError: (err) => {
2341
2468
  if (err instanceof InvalidInvitationExtensionRoleError3) {
2342
- log8("invalid role", {
2469
+ log9("invalid role", {
2343
2470
  ...err.context
2344
2471
  }, {
2345
- F: __dxlog_file11,
2472
+ F: __dxlog_file12,
2346
2473
  L: 144,
2347
2474
  S: this,
2348
2475
  C: (f, a) => f(...a)
@@ -2351,10 +2478,10 @@ var InvitationsHandler = class {
2351
2478
  }
2352
2479
  if (err instanceof TimeoutError) {
2353
2480
  if (guardedState.set(extension, Invitation4.State.TIMEOUT)) {
2354
- log8("timeout", {
2481
+ log9("timeout", {
2355
2482
  err
2356
2483
  }, {
2357
- F: __dxlog_file11,
2484
+ F: __dxlog_file12,
2358
2485
  L: 149,
2359
2486
  S: this,
2360
2487
  C: (f, a) => f(...a)
@@ -2362,8 +2489,8 @@ var InvitationsHandler = class {
2362
2489
  }
2363
2490
  } else {
2364
2491
  if (guardedState.error(extension, err)) {
2365
- log8.error("failed", err, {
2366
- F: __dxlog_file11,
2492
+ log9.error("failed", err, {
2493
+ F: __dxlog_file12,
2367
2494
  L: 153,
2368
2495
  S: this,
2369
2496
  C: (f, a) => f(...a)
@@ -2376,8 +2503,8 @@ var InvitationsHandler = class {
2376
2503
  };
2377
2504
  if (invitation.lifetime && invitation.created) {
2378
2505
  if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
2379
- log8.warn("invitation has already expired", void 0, {
2380
- F: __dxlog_file11,
2506
+ log9.warn("invitation has already expired", void 0, {
2507
+ F: __dxlog_file12,
2381
2508
  L: 164,
2382
2509
  S: this,
2383
2510
  C: (f, a) => f(...a)
@@ -2400,7 +2527,7 @@ var InvitationsHandler = class {
2400
2527
  const { timeout = INVITATION_TIMEOUT } = invitation;
2401
2528
  if (deviceProfile) {
2402
2529
  invariant9(invitation.kind === Invitation4.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
2403
- F: __dxlog_file11,
2530
+ F: __dxlog_file12,
2404
2531
  L: 197,
2405
2532
  S: this,
2406
2533
  A: [
@@ -2413,12 +2540,12 @@ var InvitationsHandler = class {
2413
2540
  const guardedState = this._createGuardedState(ctx, invitation, stream);
2414
2541
  const shouldCancelInvitationFlow = (extension) => {
2415
2542
  const isLockedByAnotherConnection = guardedState.mutex.isLocked() && !extension.hasFlowLock();
2416
- log8("should cancel invitation flow", {
2543
+ log9("should cancel invitation flow", {
2417
2544
  isLockedByAnotherConnection,
2418
2545
  invitationType: Invitation4.Type.DELEGATED,
2419
2546
  triedPeers: triedPeersIds.size
2420
2547
  }, {
2421
- F: __dxlog_file11,
2548
+ F: __dxlog_file12,
2422
2549
  L: 205,
2423
2550
  S: this,
2424
2551
  C: (f, a) => f(...a)
@@ -2441,11 +2568,11 @@ var InvitationsHandler = class {
2441
2568
  return;
2442
2569
  }
2443
2570
  connectionCtx.onDispose(async () => {
2444
- log8("extension disposed", {
2571
+ log9("extension disposed", {
2445
2572
  admitted,
2446
2573
  currentState: guardedState.current.state
2447
2574
  }, {
2448
- F: __dxlog_file11,
2575
+ F: __dxlog_file12,
2449
2576
  L: 233,
2450
2577
  S: this,
2451
2578
  C: (f, a) => f(...a)
@@ -2460,10 +2587,10 @@ var InvitationsHandler = class {
2460
2587
  scheduleTask3(connectionCtx, async () => {
2461
2588
  const traceId = PublicKey7.random().toHex();
2462
2589
  try {
2463
- log8.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.begin({
2590
+ log9.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.begin({
2464
2591
  id: traceId
2465
2592
  }), {
2466
- F: __dxlog_file11,
2593
+ F: __dxlog_file12,
2467
2594
  L: 245,
2468
2595
  S: this,
2469
2596
  C: (f, a) => f(...a)
@@ -2472,19 +2599,19 @@ var InvitationsHandler = class {
2472
2599
  guardedState.set(extension, Invitation4.State.TIMEOUT);
2473
2600
  extensionCtx.close();
2474
2601
  }, timeout);
2475
- log8("connected", {
2602
+ log9("connected", {
2476
2603
  ...protocol.toJSON()
2477
2604
  }, {
2478
- F: __dxlog_file11,
2605
+ F: __dxlog_file12,
2479
2606
  L: 256,
2480
2607
  S: this,
2481
2608
  C: (f, a) => f(...a)
2482
2609
  });
2483
2610
  guardedState.set(extension, Invitation4.State.CONNECTED);
2484
- log8("introduce", {
2611
+ log9("introduce", {
2485
2612
  ...protocol.toJSON()
2486
2613
  }, {
2487
- F: __dxlog_file11,
2614
+ F: __dxlog_file12,
2488
2615
  L: 260,
2489
2616
  S: this,
2490
2617
  C: (f, a) => f(...a)
@@ -2493,11 +2620,11 @@ var InvitationsHandler = class {
2493
2620
  invitationId: invitation.invitationId,
2494
2621
  ...protocol.createIntroduction()
2495
2622
  });
2496
- log8("introduce response", {
2623
+ log9("introduce response", {
2497
2624
  ...protocol.toJSON(),
2498
2625
  response: introductionResponse
2499
2626
  }, {
2500
- F: __dxlog_file11,
2627
+ F: __dxlog_file12,
2501
2628
  L: 265,
2502
2629
  S: this,
2503
2630
  C: (f, a) => f(...a)
@@ -2515,10 +2642,10 @@ var InvitationsHandler = class {
2515
2642
  break;
2516
2643
  }
2517
2644
  }
2518
- log8("request admission", {
2645
+ log9("request admission", {
2519
2646
  ...protocol.toJSON()
2520
2647
  }, {
2521
- F: __dxlog_file11,
2648
+ F: __dxlog_file12,
2522
2649
  L: 291,
2523
2650
  S: this,
2524
2651
  C: (f, a) => f(...a)
@@ -2527,10 +2654,10 @@ var InvitationsHandler = class {
2527
2654
  const admissionResponse = await extension.rpc.InvitationHostService.admit(admissionRequest);
2528
2655
  admitted = true;
2529
2656
  const result = await protocol.accept(admissionResponse, admissionRequest);
2530
- log8("admitted by host", {
2657
+ log9("admitted by host", {
2531
2658
  ...protocol.toJSON()
2532
2659
  }, {
2533
- F: __dxlog_file11,
2660
+ F: __dxlog_file12,
2534
2661
  L: 302,
2535
2662
  S: this,
2536
2663
  C: (f, a) => f(...a)
@@ -2540,28 +2667,28 @@ var InvitationsHandler = class {
2540
2667
  ...result,
2541
2668
  state: Invitation4.State.SUCCESS
2542
2669
  });
2543
- log8.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.end({
2670
+ log9.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.end({
2544
2671
  id: traceId
2545
2672
  }), {
2546
- F: __dxlog_file11,
2673
+ F: __dxlog_file12,
2547
2674
  L: 308,
2548
2675
  S: this,
2549
2676
  C: (f, a) => f(...a)
2550
2677
  });
2551
2678
  } catch (err) {
2552
2679
  if (err instanceof TimeoutError) {
2553
- log8("timeout", {
2680
+ log9("timeout", {
2554
2681
  ...protocol.toJSON()
2555
2682
  }, {
2556
- F: __dxlog_file11,
2683
+ F: __dxlog_file12,
2557
2684
  L: 311,
2558
2685
  S: this,
2559
2686
  C: (f, a) => f(...a)
2560
2687
  });
2561
2688
  guardedState.set(extension, Invitation4.State.TIMEOUT);
2562
2689
  } else {
2563
- log8("auth failed", err, {
2564
- F: __dxlog_file11,
2690
+ log9("auth failed", err, {
2691
+ F: __dxlog_file12,
2565
2692
  L: 314,
2566
2693
  S: this,
2567
2694
  C: (f, a) => f(...a)
@@ -2569,11 +2696,11 @@ var InvitationsHandler = class {
2569
2696
  guardedState.error(extension, err);
2570
2697
  }
2571
2698
  extensionCtx.close(err);
2572
- log8.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.error({
2699
+ log9.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.error({
2573
2700
  id: traceId,
2574
2701
  error: err
2575
2702
  }), {
2576
- F: __dxlog_file11,
2703
+ F: __dxlog_file12,
2577
2704
  L: 318,
2578
2705
  S: this,
2579
2706
  C: (f, a) => f(...a)
@@ -2586,18 +2713,18 @@ var InvitationsHandler = class {
2586
2713
  return;
2587
2714
  }
2588
2715
  if (err instanceof TimeoutError) {
2589
- log8("timeout", {
2716
+ log9("timeout", {
2590
2717
  ...protocol.toJSON()
2591
2718
  }, {
2592
- F: __dxlog_file11,
2719
+ F: __dxlog_file12,
2593
2720
  L: 327,
2594
2721
  S: this,
2595
2722
  C: (f, a) => f(...a)
2596
2723
  });
2597
2724
  guardedState.set(extension, Invitation4.State.TIMEOUT);
2598
2725
  } else {
2599
- log8("auth failed", err, {
2600
- F: __dxlog_file11,
2726
+ log9("auth failed", err, {
2727
+ F: __dxlog_file12,
2601
2728
  L: 330,
2602
2729
  S: this,
2603
2730
  C: (f, a) => f(...a)
@@ -2615,7 +2742,7 @@ var InvitationsHandler = class {
2615
2742
  await ctx.dispose();
2616
2743
  } else {
2617
2744
  invariant9(invitation.swarmKey, void 0, {
2618
- F: __dxlog_file11,
2745
+ F: __dxlog_file12,
2619
2746
  L: 345,
2620
2747
  S: this,
2621
2748
  A: [
@@ -2709,12 +2836,12 @@ var InvitationsHandler = class {
2709
2836
  };
2710
2837
  }
2711
2838
  _logStateUpdate(invitation, actor, newState) {
2712
- log8("invitation state update", {
2839
+ log9("invitation state update", {
2713
2840
  actor: actor?.constructor.name,
2714
2841
  newState: stateToString(newState),
2715
2842
  oldState: stateToString(invitation.state)
2716
2843
  }, {
2717
- F: __dxlog_file11,
2844
+ F: __dxlog_file12,
2718
2845
  L: 438,
2719
2846
  S: this,
2720
2847
  C: (f, a) => f(...a)
@@ -2731,16 +2858,16 @@ var InvitationsHandler = class {
2731
2858
  }
2732
2859
  async _handleGuestOtpAuth(extension, setState, authenticated, options) {
2733
2860
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2734
- log8("guest waiting for authentication code...", void 0, {
2735
- F: __dxlog_file11,
2861
+ log9("guest waiting for authentication code...", void 0, {
2862
+ F: __dxlog_file12,
2736
2863
  L: 462,
2737
2864
  S: this,
2738
2865
  C: (f, a) => f(...a)
2739
2866
  });
2740
2867
  setState(Invitation4.State.READY_FOR_AUTHENTICATION);
2741
2868
  const authCode = await authenticated.wait(options);
2742
- log8("sending authentication request", void 0, {
2743
- F: __dxlog_file11,
2869
+ log9("sending authentication request", void 0, {
2870
+ F: __dxlog_file12,
2744
2871
  L: 466,
2745
2872
  S: this,
2746
2873
  C: (f, a) => f(...a)
@@ -2756,10 +2883,10 @@ var InvitationsHandler = class {
2756
2883
  if (attempt === MAX_OTP_ATTEMPTS) {
2757
2884
  throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
2758
2885
  } else {
2759
- log8("retrying invalid code", {
2886
+ log9("retrying invalid code", {
2760
2887
  attempt
2761
2888
  }, {
2762
- F: __dxlog_file11,
2889
+ F: __dxlog_file12,
2763
2890
  L: 477,
2764
2891
  S: this,
2765
2892
  C: (f, a) => f(...a)
@@ -2776,8 +2903,8 @@ var InvitationsHandler = class {
2776
2903
  if (introductionResponse.challenge == null) {
2777
2904
  throw new Error("challenge missing in the introduction");
2778
2905
  }
2779
- log8("sending authentication request", void 0, {
2780
- F: __dxlog_file11,
2906
+ log9("sending authentication request", void 0, {
2907
+ F: __dxlog_file12,
2781
2908
  L: 496,
2782
2909
  S: this,
2783
2910
  C: (f, a) => f(...a)
@@ -2898,14 +3025,14 @@ var InvitationsServiceImpl = class {
2898
3025
  };
2899
3026
 
2900
3027
  // packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts
2901
- import { createAdmissionCredentials, createCancelDelegatedSpaceInvitationCredential, createDelegatedSpaceInvitationCredential, getCredentialAssertion } from "@dxos/credentials";
3028
+ import { createAdmissionCredentials, createCancelDelegatedSpaceInvitationCredential, createDelegatedSpaceInvitationCredential, getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
2902
3029
  import { writeMessages as writeMessages2 } from "@dxos/feed-store";
2903
3030
  import { invariant as invariant10 } from "@dxos/invariant";
2904
- import { log as log9 } from "@dxos/log";
3031
+ import { log as log10 } from "@dxos/log";
2905
3032
  import { AlreadyJoinedError as AlreadyJoinedError2, AuthorizationError, InvalidInvitationError, SpaceNotFoundError } from "@dxos/protocols";
2906
3033
  import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
2907
3034
  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";
3035
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
2909
3036
  var SpaceInvitationProtocol = class {
2910
3037
  constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
2911
3038
  this._spaceManager = _spaceManager;
@@ -2940,7 +3067,7 @@ var SpaceInvitationProtocol = class {
2940
3067
  }
2941
3068
  async admit(invitation, request, guestProfile) {
2942
3069
  invariant10(this._spaceKey, void 0, {
2943
- F: __dxlog_file12,
3070
+ F: __dxlog_file13,
2944
3071
  L: 76,
2945
3072
  S: this,
2946
3073
  A: [
@@ -2950,7 +3077,7 @@ var SpaceInvitationProtocol = class {
2950
3077
  });
2951
3078
  const space = this._spaceManager.spaces.get(this._spaceKey);
2952
3079
  invariant10(space, void 0, {
2953
- F: __dxlog_file12,
3080
+ F: __dxlog_file13,
2954
3081
  L: 78,
2955
3082
  S: this,
2956
3083
  A: [
@@ -2959,7 +3086,7 @@ var SpaceInvitationProtocol = class {
2959
3086
  ]
2960
3087
  });
2961
3088
  invariant10(request.space, void 0, {
2962
- F: __dxlog_file12,
3089
+ F: __dxlog_file13,
2963
3090
  L: 80,
2964
3091
  S: this,
2965
3092
  A: [
@@ -2971,18 +3098,18 @@ var SpaceInvitationProtocol = class {
2971
3098
  if (space.inner.spaceState.getMemberRole(identityKey) !== SpaceMember2.Role.REMOVED) {
2972
3099
  throw new AlreadyJoinedError2();
2973
3100
  }
2974
- log9("writing guest credentials", {
3101
+ log10("writing guest credentials", {
2975
3102
  host: this._signingContext.deviceKey,
2976
3103
  guest: deviceKey
2977
3104
  }, {
2978
- F: __dxlog_file12,
3105
+ F: __dxlog_file13,
2979
3106
  L: 87,
2980
3107
  S: this,
2981
3108
  C: (f, a) => f(...a)
2982
3109
  });
2983
3110
  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
3111
  invariant10(credentials[0].credential, void 0, {
2985
- F: __dxlog_file12,
3112
+ F: __dxlog_file13,
2986
3113
  L: 101,
2987
3114
  S: this,
2988
3115
  A: [
@@ -2991,8 +3118,8 @@ var SpaceInvitationProtocol = class {
2991
3118
  ]
2992
3119
  });
2993
3120
  const spaceMemberCredential = credentials[0].credential.credential;
2994
- invariant10(getCredentialAssertion(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2995
- F: __dxlog_file12,
3121
+ invariant10(getCredentialAssertion2(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3122
+ F: __dxlog_file13,
2996
3123
  L: 103,
2997
3124
  S: this,
2998
3125
  A: [
@@ -3010,7 +3137,7 @@ var SpaceInvitationProtocol = class {
3010
3137
  }
3011
3138
  async delegate(invitation) {
3012
3139
  invariant10(this._spaceKey, void 0, {
3013
- F: __dxlog_file12,
3140
+ F: __dxlog_file13,
3014
3141
  L: 116,
3015
3142
  S: this,
3016
3143
  A: [
@@ -3020,7 +3147,7 @@ var SpaceInvitationProtocol = class {
3020
3147
  });
3021
3148
  const space = this._spaceManager.spaces.get(this._spaceKey);
3022
3149
  invariant10(space, void 0, {
3023
- F: __dxlog_file12,
3150
+ F: __dxlog_file13,
3024
3151
  L: 118,
3025
3152
  S: this,
3026
3153
  A: [
@@ -3030,7 +3157,7 @@ var SpaceInvitationProtocol = class {
3030
3157
  });
3031
3158
  if (invitation.authMethod === Invitation5.AuthMethod.KNOWN_PUBLIC_KEY) {
3032
3159
  invariant10(invitation.guestKeypair?.publicKey, void 0, {
3033
- F: __dxlog_file12,
3160
+ F: __dxlog_file13,
3034
3161
  L: 120,
3035
3162
  S: this,
3036
3163
  A: [
@@ -3039,11 +3166,11 @@ var SpaceInvitationProtocol = class {
3039
3166
  ]
3040
3167
  });
3041
3168
  }
3042
- log9("writing delegate space invitation", {
3169
+ log10("writing delegate space invitation", {
3043
3170
  host: this._signingContext.deviceKey,
3044
3171
  id: invitation.invitationId
3045
3172
  }, {
3046
- F: __dxlog_file12,
3173
+ F: __dxlog_file13,
3047
3174
  L: 123,
3048
3175
  S: this,
3049
3176
  C: (f, a) => f(...a)
@@ -3058,7 +3185,7 @@ var SpaceInvitationProtocol = class {
3058
3185
  guestKey: invitation.authMethod === Invitation5.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
3059
3186
  });
3060
3187
  invariant10(credential.credential, void 0, {
3061
- F: __dxlog_file12,
3188
+ F: __dxlog_file13,
3062
3189
  L: 143,
3063
3190
  S: this,
3064
3191
  A: [
@@ -3073,7 +3200,7 @@ var SpaceInvitationProtocol = class {
3073
3200
  }
3074
3201
  async cancelDelegation(invitation) {
3075
3202
  invariant10(this._spaceKey, void 0, {
3076
- F: __dxlog_file12,
3203
+ F: __dxlog_file13,
3077
3204
  L: 149,
3078
3205
  S: this,
3079
3206
  A: [
@@ -3082,7 +3209,7 @@ var SpaceInvitationProtocol = class {
3082
3209
  ]
3083
3210
  });
3084
3211
  invariant10(invitation.type === Invitation5.Type.DELEGATED && invitation.delegationCredentialId, void 0, {
3085
- F: __dxlog_file12,
3212
+ F: __dxlog_file13,
3086
3213
  L: 150,
3087
3214
  S: this,
3088
3215
  A: [
@@ -3092,7 +3219,7 @@ var SpaceInvitationProtocol = class {
3092
3219
  });
3093
3220
  const space = this._spaceManager.spaces.get(this._spaceKey);
3094
3221
  invariant10(space, void 0, {
3095
- F: __dxlog_file12,
3222
+ F: __dxlog_file13,
3096
3223
  L: 152,
3097
3224
  S: this,
3098
3225
  A: [
@@ -3100,18 +3227,18 @@ var SpaceInvitationProtocol = class {
3100
3227
  ""
3101
3228
  ]
3102
3229
  });
3103
- log9("cancelling delegated space invitation", {
3230
+ log10("cancelling delegated space invitation", {
3104
3231
  host: this._signingContext.deviceKey,
3105
3232
  id: invitation.invitationId
3106
3233
  }, {
3107
- F: __dxlog_file12,
3234
+ F: __dxlog_file13,
3108
3235
  L: 154,
3109
3236
  S: this,
3110
3237
  C: (f, a) => f(...a)
3111
3238
  });
3112
3239
  const credential = await createCancelDelegatedSpaceInvitationCredential(this._signingContext.credentialSigner, space.key, invitation.delegationCredentialId);
3113
3240
  invariant10(credential.credential, void 0, {
3114
- F: __dxlog_file12,
3241
+ F: __dxlog_file13,
3115
3242
  L: 161,
3116
3243
  S: this,
3117
3244
  A: [
@@ -3150,7 +3277,7 @@ var SpaceInvitationProtocol = class {
3150
3277
  }
3151
3278
  async accept(response) {
3152
3279
  invariant10(response.space, void 0, {
3153
- F: __dxlog_file12,
3280
+ F: __dxlog_file13,
3154
3281
  L: 196,
3155
3282
  S: this,
3156
3283
  A: [
@@ -3159,9 +3286,9 @@ var SpaceInvitationProtocol = class {
3159
3286
  ]
3160
3287
  });
3161
3288
  const { credential, controlTimeframe, dataTimeframe } = response.space;
3162
- const assertion = getCredentialAssertion(credential);
3289
+ const assertion = getCredentialAssertion2(credential);
3163
3290
  invariant10(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
3164
- F: __dxlog_file12,
3291
+ F: __dxlog_file13,
3165
3292
  L: 199,
3166
3293
  S: this,
3167
3294
  A: [
@@ -3170,7 +3297,7 @@ var SpaceInvitationProtocol = class {
3170
3297
  ]
3171
3298
  });
3172
3299
  invariant10(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
3173
- F: __dxlog_file12,
3300
+ F: __dxlog_file13,
3174
3301
  L: 200,
3175
3302
  S: this,
3176
3303
  A: [
@@ -3202,10 +3329,10 @@ import { generatePasscode } from "@dxos/credentials";
3202
3329
  import { hasInvitationExpired } from "@dxos/echo-pipeline";
3203
3330
  import { invariant as invariant11 } from "@dxos/invariant";
3204
3331
  import { PublicKey as PublicKey8 } from "@dxos/keys";
3205
- import { log as log10 } from "@dxos/log";
3332
+ import { log as log11 } from "@dxos/log";
3206
3333
  import { Invitation as Invitation6 } from "@dxos/protocols/proto/dxos/client/services";
3207
3334
  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";
3335
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
3209
3336
  var InvitationsManager = class {
3210
3337
  constructor(_invitationsHandler, _getHandler, _metadataStore) {
3211
3338
  this._invitationsHandler = _invitationsHandler;
@@ -3247,8 +3374,8 @@ var InvitationsManager = class {
3247
3374
  try {
3248
3375
  await this._persistIfRequired(handler, stream, invitation);
3249
3376
  } catch (err) {
3250
- log10.catch(err, void 0, {
3251
- F: __dxlog_file13,
3377
+ log11.catch(err, void 0, {
3378
+ F: __dxlog_file14,
3252
3379
  L: 82,
3253
3380
  S: this,
3254
3381
  C: (f, a) => f(...a)
@@ -3271,7 +3398,7 @@ var InvitationsManager = class {
3271
3398
  const freshInvitations = persistentInvitations.filter((invitation) => !hasInvitationExpired(invitation));
3272
3399
  const loadTasks = freshInvitations.map((persistentInvitation) => {
3273
3400
  invariant11(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
3274
- F: __dxlog_file13,
3401
+ F: __dxlog_file14,
3275
3402
  L: 103,
3276
3403
  S: this,
3277
3404
  A: [
@@ -3289,8 +3416,8 @@ var InvitationsManager = class {
3289
3416
  invitations: cInvitations.map((invitation) => invitation.get())
3290
3417
  };
3291
3418
  } catch (err) {
3292
- log10.catch(err, void 0, {
3293
- F: __dxlog_file13,
3419
+ log11.catch(err, void 0, {
3420
+ F: __dxlog_file14,
3294
3421
  L: 110,
3295
3422
  S: this,
3296
3423
  C: (f, a) => f(...a)
@@ -3321,14 +3448,14 @@ var InvitationsManager = class {
3321
3448
  return invitation;
3322
3449
  }
3323
3450
  async authenticate({ invitationId, authCode }) {
3324
- log10("authenticating...", void 0, {
3325
- F: __dxlog_file13,
3451
+ log11("authenticating...", void 0, {
3452
+ F: __dxlog_file14,
3326
3453
  L: 140,
3327
3454
  S: this,
3328
3455
  C: (f, a) => f(...a)
3329
3456
  });
3330
3457
  invariant11(invitationId, void 0, {
3331
- F: __dxlog_file13,
3458
+ F: __dxlog_file14,
3332
3459
  L: 141,
3333
3460
  S: this,
3334
3461
  A: [
@@ -3338,10 +3465,10 @@ var InvitationsManager = class {
3338
3465
  });
3339
3466
  const observable = this._acceptInvitations.get(invitationId);
3340
3467
  if (!observable) {
3341
- log10.warn("invalid invitation", {
3468
+ log11.warn("invalid invitation", {
3342
3469
  invitationId
3343
3470
  }, {
3344
- F: __dxlog_file13,
3471
+ F: __dxlog_file14,
3345
3472
  L: 144,
3346
3473
  S: this,
3347
3474
  C: (f, a) => f(...a)
@@ -3351,16 +3478,16 @@ var InvitationsManager = class {
3351
3478
  }
3352
3479
  }
3353
3480
  async cancelInvitation({ invitationId }) {
3354
- log10("cancelInvitation...", {
3481
+ log11("cancelInvitation...", {
3355
3482
  invitationId
3356
3483
  }, {
3357
- F: __dxlog_file13,
3484
+ F: __dxlog_file14,
3358
3485
  L: 151,
3359
3486
  S: this,
3360
3487
  C: (f, a) => f(...a)
3361
3488
  });
3362
3489
  invariant11(invitationId, void 0, {
3363
- F: __dxlog_file13,
3490
+ F: __dxlog_file14,
3364
3491
  L: 152,
3365
3492
  S: this,
3366
3493
  A: [
@@ -3436,10 +3563,10 @@ var InvitationsManager = class {
3436
3563
  }
3437
3564
  });
3438
3565
  ctx.onDispose(() => {
3439
- log10("complete", {
3566
+ log11("complete", {
3440
3567
  ...handler.toJSON()
3441
3568
  }, {
3442
- F: __dxlog_file13,
3569
+ F: __dxlog_file14,
3443
3570
  L: 241,
3444
3571
  S: this,
3445
3572
  C: (f, a) => f(...a)
@@ -3469,10 +3596,10 @@ var InvitationsManager = class {
3469
3596
  const ctx = new Context6({
3470
3597
  onError: (err) => {
3471
3598
  if (err instanceof TimeoutError2) {
3472
- log10("timeout", {
3599
+ log11("timeout", {
3473
3600
  ...handler.toJSON()
3474
3601
  }, {
3475
- F: __dxlog_file13,
3602
+ F: __dxlog_file14,
3476
3603
  L: 261,
3477
3604
  S: this,
3478
3605
  C: (f, a) => f(...a)
@@ -3482,8 +3609,8 @@ var InvitationsManager = class {
3482
3609
  state: Invitation6.State.TIMEOUT
3483
3610
  });
3484
3611
  } else {
3485
- log10.warn("auth failed", err, {
3486
- F: __dxlog_file13,
3612
+ log11.warn("auth failed", err, {
3613
+ F: __dxlog_file14,
3487
3614
  L: 264,
3488
3615
  S: this,
3489
3616
  C: (f, a) => f(...a)
@@ -3497,10 +3624,10 @@ var InvitationsManager = class {
3497
3624
  }
3498
3625
  });
3499
3626
  ctx.onDispose(() => {
3500
- log10("complete", {
3627
+ log11("complete", {
3501
3628
  ...handler.toJSON()
3502
3629
  }, {
3503
- F: __dxlog_file13,
3630
+ F: __dxlog_file14,
3504
3631
  L: 271,
3505
3632
  S: this,
3506
3633
  C: (f, a) => f(...a)
@@ -3544,8 +3671,8 @@ var InvitationsManager = class {
3544
3671
  try {
3545
3672
  await this._metadataStore.removeInvitation(invitation.invitationId);
3546
3673
  } catch (err) {
3547
- log10.catch(err, void 0, {
3548
- F: __dxlog_file13,
3674
+ log11.catch(err, void 0, {
3675
+ F: __dxlog_file14,
3549
3676
  L: 307,
3550
3677
  S: this,
3551
3678
  C: (f, a) => f(...a)
@@ -3560,33 +3687,40 @@ var InvitationsManager = class {
3560
3687
  };
3561
3688
 
3562
3689
  // 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";
3690
+ import { Event as Event6, Mutex as Mutex2, scheduleTask as scheduleTask5, sleep as sleep2, synchronized, trackLeaks } from "@dxos/async";
3564
3691
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
3565
- import { Context as Context8, ContextDisposedError as ContextDisposedError3, cancelWithContext as cancelWithContext4 } from "@dxos/context";
3692
+ import { Context as Context8, ContextDisposedError as ContextDisposedError3, cancelWithContext as cancelWithContext5 } from "@dxos/context";
3566
3693
  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";
3694
+ import { createMappedFeedWriter } from "@dxos/echo-pipeline";
3695
+ import { SpaceDocVersion } from "@dxos/echo-protocol";
3696
+ import { failedInvariant } from "@dxos/invariant";
3570
3697
  import { PublicKey as PublicKey10 } from "@dxos/keys";
3571
- import { log as log12 } from "@dxos/log";
3698
+ import { log as log14 } from "@dxos/log";
3572
3699
  import { CancelledError, SystemError } from "@dxos/protocols";
3573
- import { CreateEpochRequest, SpaceState } from "@dxos/protocols/proto/dxos/client/services";
3700
+ import { SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
3574
3701
  import { AdmittedFeed as AdmittedFeed3, SpaceMember as SpaceMember4 } from "@dxos/protocols/proto/dxos/halo/credentials";
3575
- import { Timeframe as Timeframe2 } from "@dxos/timeframe";
3702
+ import { Timeframe as Timeframe3 } from "@dxos/timeframe";
3576
3703
  import { trace as trace6 } from "@dxos/tracing";
3577
- import { ComplexSet as ComplexSet5, assignDeep } from "@dxos/util";
3704
+ import { ComplexSet as ComplexSet5 } from "@dxos/util";
3578
3705
 
3579
3706
  // packages/sdk/client-services/src/packlets/spaces/automerge-space-state.ts
3580
3707
  import { Event as Event4 } from "@dxos/async";
3708
+ import { Resource as Resource2 } from "@dxos/context";
3581
3709
  import { checkCredentialType } from "@dxos/credentials";
3582
- var AutomergeSpaceState = class {
3710
+ var AutomergeSpaceState = class extends Resource2 {
3583
3711
  constructor(_onNewRoot) {
3712
+ super();
3584
3713
  this._onNewRoot = _onNewRoot;
3585
3714
  this.rootUrl = void 0;
3586
3715
  this.lastEpoch = void 0;
3587
3716
  this.onNewEpoch = new Event4();
3588
3717
  this._isProcessingRootDocs = false;
3589
3718
  }
3719
+ async _open(ctx) {
3720
+ }
3721
+ async _close(ctx) {
3722
+ this._isProcessingRootDocs = false;
3723
+ }
3590
3724
  async processCredential(credential) {
3591
3725
  if (!checkCredentialType(credential, "dxos.halo.credentials.Epoch")) {
3592
3726
  return;
@@ -3614,16 +3748,162 @@ var AutomergeSpaceState = class {
3614
3748
  }
3615
3749
  };
3616
3750
 
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";
3751
+ // packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts
3752
+ import { asyncTimeout as asyncTimeout2 } from "@dxos/async";
3753
+ import { next as am } from "@dxos/automerge/automerge";
3754
+ import { cancelWithContext as cancelWithContext4 } from "@dxos/context";
3755
+ import { convertLegacyReferences, convertLegacySpaceRootDoc, findInlineObjectOfType, migrateDocument } from "@dxos/echo-db";
3756
+ import { AutomergeDocumentLoaderImpl } from "@dxos/echo-pipeline";
3757
+ import { TYPE_PROPERTIES } from "@dxos/echo-schema";
3620
3758
  import { invariant as invariant12 } from "@dxos/invariant";
3759
+ import { log as log12 } from "@dxos/log";
3760
+ import { CreateEpochRequest } from "@dxos/protocols/proto/dxos/client/services";
3761
+ import { assignDeep } from "@dxos/util";
3762
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts";
3763
+ var runEpochMigration = async (ctx, context) => {
3764
+ switch (context.migration) {
3765
+ case CreateEpochRequest.Migration.INIT_AUTOMERGE: {
3766
+ const document = context.repo.create();
3767
+ await context.repo.flush();
3768
+ return {
3769
+ newRoot: document.url
3770
+ };
3771
+ }
3772
+ case CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY: {
3773
+ if (!context.currentRoot) {
3774
+ throw new Error("Space does not have an automerge root");
3775
+ }
3776
+ const rootHandle = context.repo.find(context.currentRoot);
3777
+ await cancelWithContext4(ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
3778
+ const newRoot = context.repo.create(rootHandle.docSync());
3779
+ await context.repo.flush();
3780
+ return {
3781
+ newRoot: newRoot.url
3782
+ };
3783
+ }
3784
+ case CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT: {
3785
+ log12.info("Fragmenting", void 0, {
3786
+ F: __dxlog_file15,
3787
+ L: 63,
3788
+ S: void 0,
3789
+ C: (f, a) => f(...a)
3790
+ });
3791
+ const currentRootUrl = context.currentRoot;
3792
+ const rootHandle = context.repo.find(currentRootUrl);
3793
+ await cancelWithContext4(ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
3794
+ const objects = Object.entries(rootHandle.docSync().objects);
3795
+ const properties = findInlineObjectOfType(rootHandle.docSync(), TYPE_PROPERTIES);
3796
+ const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
3797
+ invariant12(properties, "Properties not found", {
3798
+ F: __dxlog_file15,
3799
+ L: 73,
3800
+ S: void 0,
3801
+ A: [
3802
+ "properties",
3803
+ "'Properties not found'"
3804
+ ]
3805
+ });
3806
+ const newSpaceDoc = {
3807
+ ...rootHandle.docSync(),
3808
+ objects: Object.fromEntries([
3809
+ properties
3810
+ ])
3811
+ };
3812
+ const newRoot = context.repo.create(newSpaceDoc);
3813
+ invariant12(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3814
+ F: __dxlog_file15,
3815
+ L: 78,
3816
+ S: void 0,
3817
+ A: [
3818
+ "typeof newRoot.url === 'string' && newRoot.url.length > 0",
3819
+ ""
3820
+ ]
3821
+ });
3822
+ const docLoader = new AutomergeDocumentLoaderImpl(context.spaceId, context.repo, context.spaceKey);
3823
+ await docLoader.loadSpaceRootDocHandle(ctx, {
3824
+ rootUrl: newRoot.url
3825
+ });
3826
+ otherObjects.forEach(([key, value]) => {
3827
+ const handle = docLoader.createDocumentForObject(key);
3828
+ handle.change((doc) => {
3829
+ assignDeep(doc, [
3830
+ "objects",
3831
+ key
3832
+ ], value);
3833
+ });
3834
+ });
3835
+ await context.repo.flush();
3836
+ return {
3837
+ newRoot: newRoot.url
3838
+ };
3839
+ }
3840
+ case CreateEpochRequest.Migration.MIGRATE_REFERENCES_TO_DXN: {
3841
+ const currentRootUrl = context.currentRoot;
3842
+ const rootHandle = context.repo.find(currentRootUrl);
3843
+ await cancelWithContext4(ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
3844
+ invariant12(rootHandle.docSync(), "Root doc not found", {
3845
+ F: __dxlog_file15,
3846
+ L: 100,
3847
+ S: void 0,
3848
+ A: [
3849
+ "rootHandle.docSync()",
3850
+ "'Root doc not found'"
3851
+ ]
3852
+ });
3853
+ const newRootContent = await convertLegacySpaceRootDoc(structuredClone(rootHandle.docSync()));
3854
+ for (const [id, url] of Object.entries(newRootContent.links ?? {})) {
3855
+ const handle = context.repo.find(url);
3856
+ await cancelWithContext4(ctx, asyncTimeout2(handle.whenReady(), 1e4));
3857
+ invariant12(handle.docSync(), "Doc not found", {
3858
+ F: __dxlog_file15,
3859
+ L: 107,
3860
+ S: void 0,
3861
+ A: [
3862
+ "handle.docSync()",
3863
+ "'Doc not found'"
3864
+ ]
3865
+ });
3866
+ const newDoc = await convertLegacyReferences(structuredClone(handle.docSync()));
3867
+ const migratedDoc = migrateDocument(handle.docSync(), newDoc);
3868
+ const newHandle = context.repo.import(am.save(migratedDoc));
3869
+ newRootContent.links[id] = newHandle.url;
3870
+ }
3871
+ const migratedRoot = migrateDocument(rootHandle.docSync(), newRootContent);
3872
+ const newRoot = context.repo.import(am.save(migratedRoot));
3873
+ await context.repo.flush();
3874
+ return {
3875
+ newRoot: newRoot.url
3876
+ };
3877
+ }
3878
+ case CreateEpochRequest.Migration.REPLACE_AUTOMERGE_ROOT: {
3879
+ invariant12(context.newAutomergeRoot, void 0, {
3880
+ F: __dxlog_file15,
3881
+ L: 124,
3882
+ S: void 0,
3883
+ A: [
3884
+ "context.newAutomergeRoot",
3885
+ ""
3886
+ ]
3887
+ });
3888
+ await context.repo.flush();
3889
+ return {
3890
+ newRoot: context.newAutomergeRoot
3891
+ };
3892
+ }
3893
+ }
3894
+ return {};
3895
+ };
3896
+
3897
+ // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
3898
+ import { DeferredTask, Event as Event5, scheduleTask as scheduleTask4, sleep, TimeoutError as TimeoutError3, Trigger as Trigger6 } from "@dxos/async";
3899
+ import { Context as Context7, rejectOnDispose } from "@dxos/context";
3900
+ import { invariant as invariant13 } from "@dxos/invariant";
3621
3901
  import { PublicKey as PublicKey9 } from "@dxos/keys";
3622
- import { log as log11 } from "@dxos/log";
3902
+ import { log as log13 } from "@dxos/log";
3623
3903
  import { schema as schema4 } from "@dxos/protocols";
3624
3904
  import { RpcExtension as RpcExtension3 } from "@dxos/teleport";
3625
3905
  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";
3906
+ var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
3627
3907
  var DEFAULT_RETRY_TIMEOUT = 1e3;
3628
3908
  var DEFAULT_SUCCESS_DELAY = 1e3;
3629
3909
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
@@ -3648,16 +3928,16 @@ var NotarizationPlugin = class {
3648
3928
  * Request credentials to be notarized.
3649
3929
  */
3650
3930
  async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
3651
- log11("notarize", {
3931
+ log13("notarize", {
3652
3932
  credentials
3653
3933
  }, {
3654
- F: __dxlog_file14,
3934
+ F: __dxlog_file16,
3655
3935
  L: 90,
3656
3936
  S: this,
3657
3937
  C: (f, a) => f(...a)
3658
3938
  });
3659
- invariant12(credentials.every((credential) => credential.id), "Credentials must have an id", {
3660
- F: __dxlog_file14,
3939
+ invariant13(credentials.every((credential) => credential.id), "Credentials must have an id", {
3940
+ F: __dxlog_file16,
3661
3941
  L: 91,
3662
3942
  S: this,
3663
3943
  A: [
@@ -3668,10 +3948,10 @@ var NotarizationPlugin = class {
3668
3948
  const errors = new Trigger6();
3669
3949
  const ctx = this._ctx.derive({
3670
3950
  onError: (err) => {
3671
- log11.warn("Notarization error", {
3951
+ log13.warn("Notarization error", {
3672
3952
  err
3673
3953
  }, {
3674
- F: __dxlog_file14,
3954
+ F: __dxlog_file16,
3675
3955
  L: 99,
3676
3956
  S: this,
3677
3957
  C: (f, a) => f(...a)
@@ -3683,11 +3963,11 @@ var NotarizationPlugin = class {
3683
3963
  opCtx?.onDispose(() => ctx.dispose());
3684
3964
  if (timeout !== 0) {
3685
3965
  scheduleTask4(ctx, () => {
3686
- log11.warn("Notarization timeout", {
3966
+ log13.warn("Notarization timeout", {
3687
3967
  timeout,
3688
3968
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
3689
3969
  }, {
3690
- F: __dxlog_file14,
3970
+ F: __dxlog_file16,
3691
3971
  L: 111,
3692
3972
  S: this,
3693
3973
  C: (f, a) => f(...a)
@@ -3707,10 +3987,10 @@ var NotarizationPlugin = class {
3707
3987
  ...this._extensions
3708
3988
  ].find((peer2) => !peersTried.has(peer2));
3709
3989
  if (!peer) {
3710
- log11.info("Exhausted all peers to notarize with", {
3990
+ log13.info("Exhausted all peers to notarize with", {
3711
3991
  retryIn: retryTimeout
3712
3992
  }, {
3713
- F: __dxlog_file14,
3993
+ F: __dxlog_file16,
3714
3994
  L: 136,
3715
3995
  S: this,
3716
3996
  C: (f, a) => f(...a)
@@ -3720,11 +4000,11 @@ var NotarizationPlugin = class {
3720
4000
  return;
3721
4001
  }
3722
4002
  peersTried.add(peer);
3723
- log11("try notarizing", {
4003
+ log13("try notarizing", {
3724
4004
  peer: peer.localPeerId,
3725
4005
  credentialId: credentials.map((credential) => credential.id)
3726
4006
  }, {
3727
- F: __dxlog_file14,
4007
+ F: __dxlog_file16,
3728
4008
  L: 143,
3729
4009
  S: this,
3730
4010
  C: (f, a) => f(...a)
@@ -3732,8 +4012,8 @@ var NotarizationPlugin = class {
3732
4012
  await peer.rpc.NotarizationService.notarize({
3733
4013
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
3734
4014
  });
3735
- log11("success", void 0, {
3736
- F: __dxlog_file14,
4015
+ log13("success", void 0, {
4016
+ F: __dxlog_file16,
3737
4017
  L: 147,
3738
4018
  S: this,
3739
4019
  C: (f, a) => f(...a)
@@ -3741,8 +4021,8 @@ var NotarizationPlugin = class {
3741
4021
  await sleep(successDelay);
3742
4022
  } catch (err) {
3743
4023
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
3744
- log11.info("error notarizing (recoverable)", err, {
3745
- F: __dxlog_file14,
4024
+ log13.info("error notarizing (recoverable)", err, {
4025
+ F: __dxlog_file16,
3746
4026
  L: 151,
3747
4027
  S: this,
3748
4028
  C: (f, a) => f(...a)
@@ -3759,8 +4039,8 @@ var NotarizationPlugin = class {
3759
4039
  allNotarized,
3760
4040
  errors.wait()
3761
4041
  ]);
3762
- log11("done", void 0, {
3763
- F: __dxlog_file14,
4042
+ log13("done", void 0, {
4043
+ F: __dxlog_file16,
3764
4044
  L: 162,
3765
4045
  S: this,
3766
4046
  C: (f, a) => f(...a)
@@ -3781,8 +4061,8 @@ var NotarizationPlugin = class {
3781
4061
  this._processCredentialsTriggers.delete(credential.id);
3782
4062
  }
3783
4063
  setWriter(writer) {
3784
- invariant12(!this._writer, "Writer already set.", {
3785
- F: __dxlog_file14,
4064
+ invariant13(!this._writer, "Writer already set.", {
4065
+ F: __dxlog_file16,
3786
4066
  L: 181,
3787
4067
  S: this,
3788
4068
  A: [
@@ -3806,8 +4086,8 @@ var NotarizationPlugin = class {
3806
4086
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
3807
4087
  }
3808
4088
  for (const credential of request.credentials ?? []) {
3809
- invariant12(credential.id, "Credential must have an id", {
3810
- F: __dxlog_file14,
4089
+ invariant13(credential.id, "Credential must have an id", {
4090
+ F: __dxlog_file16,
3811
4091
  L: 200,
3812
4092
  S: this,
3813
4093
  A: [
@@ -3824,10 +4104,10 @@ var NotarizationPlugin = class {
3824
4104
  createExtension() {
3825
4105
  const extension = new NotarizationTeleportExtension({
3826
4106
  onOpen: async () => {
3827
- log11("extension opened", {
4107
+ log13("extension opened", {
3828
4108
  peer: extension.localPeerId
3829
4109
  }, {
3830
- F: __dxlog_file14,
4110
+ F: __dxlog_file16,
3831
4111
  L: 211,
3832
4112
  S: this,
3833
4113
  C: (f, a) => f(...a)
@@ -3836,10 +4116,10 @@ var NotarizationPlugin = class {
3836
4116
  this._extensionOpened.emit();
3837
4117
  },
3838
4118
  onClose: async () => {
3839
- log11("extension closed", {
4119
+ log13("extension closed", {
3840
4120
  peer: extension.localPeerId
3841
4121
  }, {
3842
- F: __dxlog_file14,
4122
+ F: __dxlog_file16,
3843
4123
  L: 216,
3844
4124
  S: this,
3845
4125
  C: (f, a) => f(...a)
@@ -3893,7 +4173,70 @@ function _ts_decorate4(decorators, target, key, desc) {
3893
4173
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3894
4174
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3895
4175
  }
3896
- var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
4176
+ function _using_ctx() {
4177
+ var _disposeSuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed) {
4178
+ var err = new Error();
4179
+ err.name = "SuppressedError";
4180
+ err.suppressed = suppressed;
4181
+ err.error = error;
4182
+ return err;
4183
+ }, empty = {}, stack = [];
4184
+ function using(isAwait, value) {
4185
+ if (value != null) {
4186
+ if (Object(value) !== value) {
4187
+ throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
4188
+ }
4189
+ if (isAwait) {
4190
+ var dispose = value[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")];
4191
+ }
4192
+ if (dispose == null) {
4193
+ dispose = value[Symbol.dispose || Symbol.for("Symbol.dispose")];
4194
+ }
4195
+ if (typeof dispose !== "function") {
4196
+ throw new TypeError(`Property [Symbol.dispose] is not a function.`);
4197
+ }
4198
+ stack.push({
4199
+ v: value,
4200
+ d: dispose,
4201
+ a: isAwait
4202
+ });
4203
+ } else if (isAwait) {
4204
+ stack.push({
4205
+ d: value,
4206
+ a: isAwait
4207
+ });
4208
+ }
4209
+ return value;
4210
+ }
4211
+ return {
4212
+ e: empty,
4213
+ u: using.bind(null, false),
4214
+ a: using.bind(null, true),
4215
+ d: function() {
4216
+ var error = this.e;
4217
+ function next() {
4218
+ while (resource = stack.pop()) {
4219
+ try {
4220
+ var resource, disposalResult = resource.d && resource.d.call(resource.v);
4221
+ if (resource.a) {
4222
+ return Promise.resolve(disposalResult).then(next, err);
4223
+ }
4224
+ } catch (e) {
4225
+ return err(e);
4226
+ }
4227
+ }
4228
+ if (error !== empty)
4229
+ throw error;
4230
+ }
4231
+ function err(e) {
4232
+ error = error !== empty ? new _disposeSuppressedError(error, e) : e;
4233
+ return next();
4234
+ }
4235
+ return next();
4236
+ }
4237
+ };
4238
+ }
4239
+ var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
3897
4240
  var DataSpace = class {
3898
4241
  constructor(params) {
3899
4242
  this._ctx = new Context8();
@@ -3901,7 +4244,9 @@ var DataSpace = class {
3901
4244
  this._cache = void 0;
3902
4245
  // TODO(dmaretskyi): Move into Space?
3903
4246
  this._automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
3904
- this._state = SpaceState.CLOSED;
4247
+ this._epochProcessingMutex = new Mutex2();
4248
+ this._state = SpaceState2.CLOSED;
4249
+ this._databaseRoot = null;
3905
4250
  /**
3906
4251
  * Error for _state === SpaceState.ERROR.
3907
4252
  */
@@ -3925,11 +4270,11 @@ var DataSpace = class {
3925
4270
  });
3926
4271
  this._cache = params.cache;
3927
4272
  this._state = params.initialState;
3928
- log12("new state", {
3929
- state: SpaceState[this._state]
4273
+ log14("new state", {
4274
+ state: SpaceState2[this._state]
3930
4275
  }, {
3931
- F: __dxlog_file15,
3932
- L: 143,
4276
+ F: __dxlog_file17,
4277
+ L: 146,
3933
4278
  S: this,
3934
4279
  C: (f, a) => f(...a)
3935
4280
  });
@@ -3962,6 +4307,9 @@ var DataSpace = class {
3962
4307
  get automergeSpaceState() {
3963
4308
  return this._automergeSpaceState;
3964
4309
  }
4310
+ get databaseRoot() {
4311
+ return this._databaseRoot;
4312
+ }
3965
4313
  get _automergeInfo() {
3966
4314
  return {
3967
4315
  rootUrl: this._automergeSpaceState.rootUrl,
@@ -3969,20 +4317,24 @@ var DataSpace = class {
3969
4317
  };
3970
4318
  }
3971
4319
  async open() {
3972
- await this._open();
4320
+ if (this._state === SpaceState2.CLOSED) {
4321
+ await this._open();
4322
+ }
3973
4323
  }
3974
4324
  async _open() {
4325
+ await this._presence.open();
3975
4326
  await this._gossip.open();
3976
4327
  await this._notarizationPlugin.open();
3977
4328
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
4329
+ await this._automergeSpaceState.open();
3978
4330
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
3979
4331
  await this._inner.open(new Context8());
3980
- this._state = SpaceState.CONTROL_ONLY;
3981
- log12("new state", {
3982
- state: SpaceState[this._state]
4332
+ this._state = SpaceState2.CONTROL_ONLY;
4333
+ log14("new state", {
4334
+ state: SpaceState2[this._state]
3983
4335
  }, {
3984
- F: __dxlog_file15,
3985
- L: 206,
4336
+ F: __dxlog_file17,
4337
+ L: 217,
3986
4338
  S: this,
3987
4339
  C: (f, a) => f(...a)
3988
4340
  });
@@ -3995,12 +4347,12 @@ var DataSpace = class {
3995
4347
  }
3996
4348
  async _close() {
3997
4349
  await this._callbacks.beforeClose?.();
3998
- this._state = SpaceState.CLOSED;
3999
- log12("new state", {
4000
- state: SpaceState[this._state]
4350
+ this._state = SpaceState2.CLOSED;
4351
+ log14("new state", {
4352
+ state: SpaceState2[this._state]
4001
4353
  }, {
4002
- F: __dxlog_file15,
4003
- L: 220,
4354
+ F: __dxlog_file17,
4355
+ L: 231,
4004
4356
  S: this,
4005
4357
  C: (f, a) => f(...a)
4006
4358
  });
@@ -4009,9 +4361,10 @@ var DataSpace = class {
4009
4361
  await this.authVerifier.close();
4010
4362
  await this._inner.close();
4011
4363
  await this._inner.spaceState.removeCredentialProcessor(this._automergeSpaceState);
4364
+ await this._automergeSpaceState.close();
4012
4365
  await this._inner.spaceState.removeCredentialProcessor(this._notarizationPlugin);
4013
4366
  await this._notarizationPlugin.close();
4014
- await this._presence.destroy();
4367
+ await this._presence.close();
4015
4368
  await this._gossip.close();
4016
4369
  }
4017
4370
  async postMessage(channel, message) {
@@ -4030,26 +4383,26 @@ var DataSpace = class {
4030
4383
  await this.initializeDataPipeline();
4031
4384
  } catch (err) {
4032
4385
  if (err instanceof CancelledError || err instanceof ContextDisposedError3) {
4033
- log12("data pipeline initialization cancelled", err, {
4034
- F: __dxlog_file15,
4035
- L: 253,
4386
+ log14("data pipeline initialization cancelled", err, {
4387
+ F: __dxlog_file17,
4388
+ L: 265,
4036
4389
  S: this,
4037
4390
  C: (f, a) => f(...a)
4038
4391
  });
4039
4392
  return;
4040
4393
  }
4041
- log12.error("Error initializing data pipeline", err, {
4042
- F: __dxlog_file15,
4043
- L: 257,
4394
+ log14.error("Error initializing data pipeline", err, {
4395
+ F: __dxlog_file17,
4396
+ L: 269,
4044
4397
  S: this,
4045
4398
  C: (f, a) => f(...a)
4046
4399
  });
4047
- this._state = SpaceState.ERROR;
4048
- log12("new state", {
4049
- state: SpaceState[this._state]
4400
+ this._state = SpaceState2.ERROR;
4401
+ log14("new state", {
4402
+ state: SpaceState2[this._state]
4050
4403
  }, {
4051
- F: __dxlog_file15,
4052
- L: 259,
4404
+ F: __dxlog_file17,
4405
+ L: 271,
4053
4406
  S: this,
4054
4407
  C: (f, a) => f(...a)
4055
4408
  });
@@ -4061,35 +4414,32 @@ var DataSpace = class {
4061
4414
  });
4062
4415
  }
4063
4416
  async initializeDataPipeline() {
4064
- if (this._state !== SpaceState.CONTROL_ONLY) {
4417
+ if (this._state !== SpaceState2.CONTROL_ONLY) {
4065
4418
  throw new SystemError("Invalid operation");
4066
4419
  }
4067
- this._state = SpaceState.INITIALIZING;
4068
- log12("new state", {
4069
- state: SpaceState[this._state]
4420
+ this._state = SpaceState2.INITIALIZING;
4421
+ log14("new state", {
4422
+ state: SpaceState2[this._state]
4070
4423
  }, {
4071
- F: __dxlog_file15,
4072
- L: 275,
4424
+ F: __dxlog_file17,
4425
+ L: 287,
4073
4426
  S: this,
4074
4427
  C: (f, a) => f(...a)
4075
4428
  });
4076
4429
  await this._initializeAndReadControlPipeline();
4077
4430
  await sleep2(1);
4431
+ const ready = this.stateUpdate.waitForCondition(() => this._state === SpaceState2.READY);
4078
4432
  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
- });
4433
+ await ready;
4434
+ }
4435
+ async _enterReadyState() {
4086
4436
  await this._callbacks.beforeReady?.();
4087
- this._state = SpaceState.READY;
4088
- log12("new state", {
4089
- state: SpaceState[this._state]
4437
+ this._state = SpaceState2.READY;
4438
+ log14("new state", {
4439
+ state: SpaceState2[this._state]
4090
4440
  }, {
4091
- F: __dxlog_file15,
4092
- L: 291,
4441
+ F: __dxlog_file17,
4442
+ L: 306,
4093
4443
  S: this,
4094
4444
  C: (f, a) => f(...a)
4095
4445
  });
@@ -4103,9 +4453,9 @@ var DataSpace = class {
4103
4453
  });
4104
4454
  this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
4105
4455
  await this._createWritableFeeds();
4106
- log12("writable feeds created", void 0, {
4107
- F: __dxlog_file15,
4108
- L: 307,
4456
+ log14("writable feeds created", void 0, {
4457
+ F: __dxlog_file17,
4458
+ L: 322,
4109
4459
  S: this,
4110
4460
  C: (f, a) => f(...a)
4111
4461
  });
@@ -4163,12 +4513,12 @@ var DataSpace = class {
4163
4513
  }
4164
4514
  }
4165
4515
  _onNewAutomergeRoot(rootUrl) {
4166
- log12("loading automerge root doc for space", {
4516
+ log14("loading automerge root doc for space", {
4167
4517
  space: this.key,
4168
4518
  rootUrl
4169
4519
  }, {
4170
- F: __dxlog_file15,
4171
- L: 373,
4520
+ F: __dxlog_file17,
4521
+ L: 388,
4172
4522
  S: this,
4173
4523
  C: (f, a) => f(...a)
4174
4524
  });
@@ -4176,44 +4526,52 @@ var DataSpace = class {
4176
4526
  const handle = this._echoHost.automergeRepo.find(rootUrl);
4177
4527
  queueMicrotask(async () => {
4178
4528
  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)
4529
+ try {
4530
+ var _usingCtx = _using_ctx();
4531
+ await warnAfterTimeout(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
4532
+ await cancelWithContext5(this._ctx, handle.whenReady());
4204
4533
  });
4534
+ if (this._ctx.disposed) {
4535
+ return;
4536
+ }
4537
+ const _guard = (
4538
+ // Ensure only one root is processed at a time.
4539
+ _usingCtx.u(await this._epochProcessingMutex.acquire())
4540
+ );
4541
+ const doc = handle.docSync() ?? failedInvariant();
4542
+ if (!doc.access?.spaceKey) {
4543
+ handle.change((doc2) => {
4544
+ doc2.access = {
4545
+ spaceKey: this.key.toHex()
4546
+ };
4547
+ });
4548
+ }
4549
+ const root = await this._echoHost.openSpaceRoot(handle.url);
4550
+ this._databaseRoot = root;
4551
+ if (root.getVersion() !== SpaceDocVersion.CURRENT) {
4552
+ this._state = SpaceState2.REQUIRES_MIGRATION;
4553
+ this.stateUpdate.emit();
4554
+ } else {
4555
+ if (this._state !== SpaceState2.READY) {
4556
+ await this._enterReadyState();
4557
+ }
4558
+ }
4559
+ } catch (_) {
4560
+ _usingCtx.e = _;
4561
+ } finally {
4562
+ _usingCtx.d();
4205
4563
  }
4206
4564
  } catch (err) {
4207
4565
  if (err instanceof ContextDisposedError3) {
4208
4566
  return;
4209
4567
  }
4210
- log12.warn("error loading automerge root doc", {
4568
+ log14.warn("error loading automerge root doc", {
4211
4569
  space: this.key,
4212
4570
  rootUrl,
4213
4571
  err
4214
4572
  }, {
4215
- F: __dxlog_file15,
4216
- L: 406,
4573
+ F: __dxlog_file17,
4574
+ L: 431,
4217
4575
  S: this,
4218
4576
  C: (f, a) => f(...a)
4219
4577
  });
@@ -4236,175 +4594,70 @@ var DataSpace = class {
4236
4594
  });
4237
4595
  }
4238
4596
  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;
4597
+ const ctx = this._ctx.derive();
4598
+ if (!options?.migration) {
4599
+ return null;
4368
4600
  }
4601
+ const { newRoot } = await runEpochMigration(ctx, {
4602
+ repo: this._echoHost.automergeRepo,
4603
+ spaceId: this.id,
4604
+ spaceKey: this.key,
4605
+ migration: options.migration,
4606
+ currentRoot: this._automergeSpaceState.rootUrl ?? null,
4607
+ newAutomergeRoot: options.newAutomergeRoot
4608
+ });
4609
+ const epoch = {
4610
+ previousId: this._automergeSpaceState.lastEpoch?.id,
4611
+ number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
4612
+ timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe3(),
4613
+ automergeRoot: newRoot ?? this._automergeSpaceState.rootUrl
4614
+ };
4615
+ const credential = await this._signingContext.credentialSigner.createCredential({
4616
+ subject: this.key,
4617
+ assertion: {
4618
+ "@type": "dxos.halo.credentials.Epoch",
4619
+ ...epoch
4620
+ }
4621
+ });
4369
4622
  const receipt = await this.inner.controlPipeline.writer.write({
4370
4623
  credential: {
4371
- credential: await this._signingContext.credentialSigner.createCredential({
4372
- subject: this.key,
4373
- assertion: {
4374
- "@type": "dxos.halo.credentials.Epoch",
4375
- ...epoch
4376
- }
4377
- })
4624
+ credential
4378
4625
  }
4379
4626
  });
4380
- await this.inner.controlPipeline.state.waitUntilTimeframe(new Timeframe2([
4627
+ await this.inner.controlPipeline.state.waitUntilTimeframe(new Timeframe3([
4381
4628
  [
4382
4629
  receipt.feedKey,
4383
4630
  receipt.seq
4384
4631
  ]
4385
4632
  ]));
4386
4633
  await this._echoHost.updateIndexes();
4634
+ return credential;
4387
4635
  }
4388
4636
  async activate() {
4389
- if (this._state !== SpaceState.INACTIVE) {
4637
+ if (![
4638
+ SpaceState2.CLOSED,
4639
+ SpaceState2.INACTIVE
4640
+ ].includes(this._state)) {
4390
4641
  return;
4391
4642
  }
4392
- await this._metadataStore.setSpaceState(this.key, SpaceState.ACTIVE);
4643
+ await this._metadataStore.setSpaceState(this.key, SpaceState2.ACTIVE);
4393
4644
  await this._open();
4394
4645
  this.initializeDataPipelineAsync();
4395
4646
  }
4396
4647
  async deactivate() {
4397
- if (this._state === SpaceState.INACTIVE) {
4648
+ if (this._state === SpaceState2.INACTIVE) {
4398
4649
  return;
4399
4650
  }
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]
4651
+ await this._metadataStore.setSpaceState(this.key, SpaceState2.INACTIVE);
4652
+ if (this._state !== SpaceState2.CLOSED) {
4653
+ await this._close();
4654
+ }
4655
+ this._state = SpaceState2.INACTIVE;
4656
+ log14("new state", {
4657
+ state: SpaceState2[this._state]
4405
4658
  }, {
4406
- F: __dxlog_file15,
4407
- L: 566,
4659
+ F: __dxlog_file17,
4660
+ L: 512,
4408
4661
  S: this,
4409
4662
  C: (f, a) => f(...a)
4410
4663
  });
@@ -4422,7 +4675,7 @@ _ts_decorate4([
4422
4675
  ], DataSpace.prototype, "key", null);
4423
4676
  _ts_decorate4([
4424
4677
  trace6.info({
4425
- enum: SpaceState
4678
+ enum: SpaceState2
4426
4679
  })
4427
4680
  ], DataSpace.prototype, "state", null);
4428
4681
  _ts_decorate4([
@@ -4459,39 +4712,31 @@ DataSpace = _ts_decorate4([
4459
4712
  trackLeaks("open", "close"),
4460
4713
  trace6.resource()
4461
4714
  ], 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
4715
 
4475
4716
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
4476
4717
  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";
4718
+ import { PropertiesType } from "@dxos/client-protocol";
4719
+ import { Context as Context9, cancelWithContext as cancelWithContext6 } from "@dxos/context";
4720
+ import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
4721
+ import { convertLegacyReferences as convertLegacyReferences2, findInlineObjectOfType as findInlineObjectOfType2 } from "@dxos/echo-db";
4479
4722
  import { AuthStatus } from "@dxos/echo-pipeline";
4723
+ import { LEGACY_TYPE_PROPERTIES, SpaceDocVersion as SpaceDocVersion2, encodeReference } from "@dxos/echo-protocol";
4724
+ import { TYPE_PROPERTIES as TYPE_PROPERTIES2, generateEchoId, getTypeReference } from "@dxos/echo-schema";
4480
4725
  import { invariant as invariant14 } from "@dxos/invariant";
4481
4726
  import { PublicKey as PublicKey11 } from "@dxos/keys";
4482
- import { log as log13 } from "@dxos/log";
4727
+ import { log as log15 } from "@dxos/log";
4483
4728
  import { trace as Trace2 } from "@dxos/protocols";
4484
- import { Invitation as Invitation7, SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
4729
+ import { Invitation as Invitation7, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
4485
4730
  import { SpaceMember as SpaceMember6 } from "@dxos/protocols/proto/dxos/halo/credentials";
4486
4731
  import { Gossip as Gossip2, Presence as Presence2 } from "@dxos/teleport-extension-gossip";
4487
4732
  import { trace as trace7 } from "@dxos/tracing";
4488
- import { ComplexMap as ComplexMap3, deferFunction as deferFunction2, forEachAsync } from "@dxos/util";
4733
+ import { ComplexMap as ComplexMap3, assignDeep as assignDeep2, deferFunction as deferFunction2, forEachAsync } from "@dxos/util";
4489
4734
 
4490
4735
  // packages/sdk/client-services/src/packlets/spaces/genesis.ts
4491
4736
  import { createCredential } from "@dxos/credentials";
4492
4737
  import { failUndefined } from "@dxos/debug";
4493
4738
  import { AdmittedFeed as AdmittedFeed4, SpaceMember as SpaceMember5 } from "@dxos/protocols/proto/dxos/halo/credentials";
4494
- import { Timeframe as Timeframe3 } from "@dxos/timeframe";
4739
+ import { Timeframe as Timeframe4 } from "@dxos/timeframe";
4495
4740
  var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
4496
4741
  const credentials = [
4497
4742
  await createCredential({
@@ -4541,7 +4786,7 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
4541
4786
  "@type": "dxos.halo.credentials.Epoch",
4542
4787
  number: 0,
4543
4788
  previousId: void 0,
4544
- timeframe: new Timeframe3(),
4789
+ timeframe: new Timeframe4(),
4545
4790
  snapshotCid: void 0,
4546
4791
  automergeRoot
4547
4792
  }
@@ -4568,11 +4813,12 @@ function _ts_decorate5(decorators, target, key, desc) {
4568
4813
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4569
4814
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4570
4815
  }
4571
- var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
4816
+ var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
4572
4817
  var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
4573
4818
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
4819
+ var DEFAULT_SPACE_KEY = "__DEFAULT__";
4574
4820
  var DataSpaceManager = class {
4575
- constructor(_spaceManager, _metadataStore, _keyring, _signingContext, _feedStore, _echoHost, _invitationsManager, params) {
4821
+ constructor(_spaceManager, _metadataStore, _keyring, _signingContext, _feedStore, _echoHost, _invitationsManager, _params) {
4576
4822
  this._spaceManager = _spaceManager;
4577
4823
  this._metadataStore = _metadataStore;
4578
4824
  this._keyring = _keyring;
@@ -4580,14 +4826,12 @@ var DataSpaceManager = class {
4580
4826
  this._feedStore = _feedStore;
4581
4827
  this._echoHost = _echoHost;
4582
4828
  this._invitationsManager = _invitationsManager;
4829
+ this._params = _params;
4583
4830
  this._ctx = new Context9();
4584
4831
  this.updated = new Event7();
4585
4832
  this._spaces = new ComplexMap3(PublicKey11.hash);
4586
4833
  this._isOpen = false;
4587
4834
  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
4835
  trace7.diagnostic({
4592
4836
  id: "spaces",
4593
4837
  name: "Spaces",
@@ -4596,10 +4840,10 @@ var DataSpaceManager = class {
4596
4840
  const rootUrl = space.automergeSpaceState.rootUrl;
4597
4841
  const rootHandle = rootUrl ? this._echoHost.automergeRepo.find(rootUrl) : void 0;
4598
4842
  const rootDoc = rootHandle?.docSync();
4599
- const properties = rootDoc && findPropertiesObject(rootDoc);
4843
+ const properties = rootDoc && findInlineObjectOfType2(rootDoc, TYPE_PROPERTIES2);
4600
4844
  return {
4601
4845
  key: space.key.toHex(),
4602
- state: SpaceState2[space.state],
4846
+ state: SpaceState3[space.state],
4603
4847
  name: properties?.[1].data.name ?? null,
4604
4848
  inlineObjects: rootDoc ? Object.keys(rootDoc.objects ?? {}).length : null,
4605
4849
  linkedObjects: rootDoc ? Object.keys(rootDoc.links ?? {}).length : null,
@@ -4616,46 +4860,46 @@ var DataSpaceManager = class {
4616
4860
  return this._spaces;
4617
4861
  }
4618
4862
  async open() {
4619
- log13("open", void 0, {
4620
- F: __dxlog_file16,
4621
- L: 144,
4863
+ log15("open", void 0, {
4864
+ F: __dxlog_file18,
4865
+ L: 146,
4622
4866
  S: this,
4623
4867
  C: (f, a) => f(...a)
4624
4868
  });
4625
- log13.trace("dxos.echo.data-space-manager.open", Trace2.begin({
4869
+ log15.trace("dxos.echo.data-space-manager.open", Trace2.begin({
4626
4870
  id: this._instanceId
4627
4871
  }), {
4628
- F: __dxlog_file16,
4629
- L: 145,
4872
+ F: __dxlog_file18,
4873
+ L: 147,
4630
4874
  S: this,
4631
4875
  C: (f, a) => f(...a)
4632
4876
  });
4633
- log13("metadata loaded", {
4877
+ log15("metadata loaded", {
4634
4878
  spaces: this._metadataStore.spaces.length
4635
4879
  }, {
4636
- F: __dxlog_file16,
4637
- L: 146,
4880
+ F: __dxlog_file18,
4881
+ L: 148,
4638
4882
  S: this,
4639
4883
  C: (f, a) => f(...a)
4640
4884
  });
4641
4885
  await forEachAsync(this._metadataStore.spaces, async (spaceMetadata) => {
4642
4886
  try {
4643
- log13("load space", {
4887
+ log15("load space", {
4644
4888
  spaceMetadata
4645
4889
  }, {
4646
- F: __dxlog_file16,
4647
- L: 150,
4890
+ F: __dxlog_file18,
4891
+ L: 152,
4648
4892
  S: this,
4649
4893
  C: (f, a) => f(...a)
4650
4894
  });
4651
4895
  await this._constructSpace(spaceMetadata);
4652
4896
  } catch (err) {
4653
- log13.error("Error loading space", {
4897
+ log15.error("Error loading space", {
4654
4898
  spaceMetadata,
4655
4899
  err
4656
4900
  }, {
4657
- F: __dxlog_file16,
4658
- L: 153,
4901
+ F: __dxlog_file18,
4902
+ L: 155,
4659
4903
  S: this,
4660
4904
  C: (f, a) => f(...a)
4661
4905
  });
@@ -4663,24 +4907,19 @@ var DataSpaceManager = class {
4663
4907
  });
4664
4908
  this._isOpen = true;
4665
4909
  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({
4910
+ log15.trace("dxos.echo.data-space-manager.open", Trace2.end({
4672
4911
  id: this._instanceId
4673
4912
  }), {
4674
- F: __dxlog_file16,
4675
- L: 166,
4913
+ F: __dxlog_file18,
4914
+ L: 162,
4676
4915
  S: this,
4677
4916
  C: (f, a) => f(...a)
4678
4917
  });
4679
4918
  }
4680
4919
  async close() {
4681
- log13("close", void 0, {
4682
- F: __dxlog_file16,
4683
- L: 171,
4920
+ log15("close", void 0, {
4921
+ F: __dxlog_file18,
4922
+ L: 167,
4684
4923
  S: this,
4685
4924
  C: (f, a) => f(...a)
4686
4925
  });
@@ -4689,14 +4928,15 @@ var DataSpaceManager = class {
4689
4928
  for (const space of this._spaces.values()) {
4690
4929
  await space.close();
4691
4930
  }
4931
+ this._spaces.clear();
4692
4932
  }
4693
4933
  /**
4694
4934
  * Creates a new space writing the genesis credentials to the control feed.
4695
4935
  */
4696
4936
  async createSpace() {
4697
4937
  invariant14(this._isOpen, "Not open.", {
4698
- F: __dxlog_file16,
4699
- L: 184,
4938
+ F: __dxlog_file18,
4939
+ L: 181,
4700
4940
  S: this,
4701
4941
  A: [
4702
4942
  "this._isOpen",
@@ -4711,24 +4951,25 @@ var DataSpaceManager = class {
4711
4951
  genesisFeedKey: controlFeedKey,
4712
4952
  controlFeedKey,
4713
4953
  dataFeedKey,
4714
- state: SpaceState2.ACTIVE
4954
+ state: SpaceState3.ACTIVE
4715
4955
  };
4716
- log13("creating space...", {
4956
+ log15("creating space...", {
4717
4957
  spaceKey
4718
4958
  }, {
4719
- F: __dxlog_file16,
4720
- L: 196,
4959
+ F: __dxlog_file18,
4960
+ L: 193,
4721
4961
  S: this,
4722
4962
  C: (f, a) => f(...a)
4723
4963
  });
4724
4964
  const root = await this._echoHost.createSpaceRoot(spaceKey);
4725
4965
  const space = await this._constructSpace(metadata);
4966
+ await space.open();
4726
4967
  const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, root.url);
4727
4968
  await this._metadataStore.addSpace(metadata);
4728
4969
  const memberCredential = credentials[1];
4729
- invariant14(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4730
- F: __dxlog_file16,
4731
- L: 205,
4970
+ invariant14(getCredentialAssertion3(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4971
+ F: __dxlog_file18,
4972
+ L: 203,
4732
4973
  S: this,
4733
4974
  A: [
4734
4975
  "getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -4740,19 +4981,85 @@ var DataSpaceManager = class {
4740
4981
  this.updated.emit();
4741
4982
  return space;
4742
4983
  }
4984
+ async isDefaultSpace(space) {
4985
+ if (!space.databaseRoot) {
4986
+ return false;
4987
+ }
4988
+ switch (space.databaseRoot.getVersion()) {
4989
+ case SpaceDocVersion2.CURRENT: {
4990
+ const [_, properties] = findInlineObjectOfType2(space.databaseRoot.docSync(), TYPE_PROPERTIES2) ?? [];
4991
+ return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
4992
+ }
4993
+ case SpaceDocVersion2.LEGACY: {
4994
+ const convertedDoc = await convertLegacyReferences2(space.databaseRoot.docSync());
4995
+ const [_, properties] = findInlineObjectOfType2(convertedDoc, LEGACY_TYPE_PROPERTIES) ?? [];
4996
+ return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
4997
+ }
4998
+ default:
4999
+ log15.warn("unknown space version", {
5000
+ version: space.databaseRoot.getVersion(),
5001
+ spaceId: space.id
5002
+ }, {
5003
+ F: __dxlog_file18,
5004
+ L: 228,
5005
+ S: this,
5006
+ C: (f, a) => f(...a)
5007
+ });
5008
+ return false;
5009
+ }
5010
+ }
5011
+ async createDefaultSpace() {
5012
+ const space = await this.createSpace();
5013
+ const document = await this._getSpaceRootDocument(space);
5014
+ const properties = {
5015
+ system: {
5016
+ type: encodeReference(getTypeReference(PropertiesType))
5017
+ },
5018
+ data: {
5019
+ [DEFAULT_SPACE_KEY]: this._signingContext.identityKey.toHex()
5020
+ },
5021
+ meta: {
5022
+ keys: []
5023
+ }
5024
+ };
5025
+ const propertiesId = generateEchoId();
5026
+ document.change((doc) => {
5027
+ assignDeep2(doc, [
5028
+ "objects",
5029
+ propertiesId
5030
+ ], properties);
5031
+ });
5032
+ await this._echoHost.flush();
5033
+ return space;
5034
+ }
5035
+ async _getSpaceRootDocument(space) {
5036
+ const automergeIndex = space.automergeSpaceState.rootUrl;
5037
+ invariant14(automergeIndex, void 0, {
5038
+ F: __dxlog_file18,
5039
+ L: 261,
5040
+ S: this,
5041
+ A: [
5042
+ "automergeIndex",
5043
+ ""
5044
+ ]
5045
+ });
5046
+ const document = this._echoHost.automergeRepo.find(automergeIndex);
5047
+ await document.whenReady();
5048
+ return document;
5049
+ }
4743
5050
  // TODO(burdon): Rename join space.
4744
5051
  async acceptSpace(opts) {
4745
- log13("accept space", {
5052
+ log15("accept space", {
4746
5053
  opts
4747
5054
  }, {
4748
- F: __dxlog_file16,
4749
- L: 217,
5055
+ F: __dxlog_file18,
5056
+ L: 270,
4750
5057
  S: this,
4751
5058
  C: (f, a) => f(...a)
4752
5059
  });
4753
5060
  invariant14(this._isOpen, "Not open.", {
4754
- F: __dxlog_file16,
4755
- L: 218,
5061
+ F: __dxlog_file18,
5062
+ L: 271,
4756
5063
  S: this,
4757
5064
  A: [
4758
5065
  "this._isOpen",
@@ -4760,8 +5067,8 @@ var DataSpaceManager = class {
4760
5067
  ]
4761
5068
  });
4762
5069
  invariant14(!this._spaces.has(opts.spaceKey), "Space already exists.", {
4763
- F: __dxlog_file16,
4764
- L: 219,
5070
+ F: __dxlog_file18,
5071
+ L: 272,
4765
5072
  S: this,
4766
5073
  A: [
4767
5074
  "!this._spaces.has(opts.spaceKey)",
@@ -4775,6 +5082,7 @@ var DataSpaceManager = class {
4775
5082
  dataTimeframe: opts.dataTimeframe
4776
5083
  };
4777
5084
  const space = await this._constructSpace(metadata);
5085
+ await space.open();
4778
5086
  await this._metadataStore.addSpace(metadata);
4779
5087
  space.initializeDataPipelineAsync();
4780
5088
  this.updated.emit();
@@ -4786,17 +5094,17 @@ var DataSpaceManager = class {
4786
5094
  * TODO(dmaretskyi): Consider removing.
4787
5095
  */
4788
5096
  async waitUntilSpaceReady(spaceKey) {
4789
- await cancelWithContext5(this._ctx, this.updated.waitForCondition(() => {
5097
+ await cancelWithContext6(this._ctx, this.updated.waitForCondition(() => {
4790
5098
  const space = this._spaces.get(spaceKey);
4791
- return !!space && space.state === SpaceState2.READY;
5099
+ return !!space && space.state === SpaceState3.READY;
4792
5100
  }));
4793
5101
  }
4794
5102
  async _constructSpace(metadata) {
4795
- log13("construct space", {
5103
+ log15("construct space", {
4796
5104
  metadata
4797
5105
  }, {
4798
- F: __dxlog_file16,
4799
- L: 252,
5106
+ F: __dxlog_file18,
5107
+ L: 306,
4800
5108
  S: this,
4801
5109
  C: (f, a) => f(...a)
4802
5110
  });
@@ -4804,8 +5112,8 @@ var DataSpaceManager = class {
4804
5112
  localPeerId: this._signingContext.deviceKey
4805
5113
  });
4806
5114
  const presence = new Presence2({
4807
- announceInterval: this._spaceMemberPresenceAnnounceInterval,
4808
- offlineTimeout: this._spaceMemberPresenceOfflineTimeout,
5115
+ announceInterval: this._params?.spaceMemberPresenceAnnounceInterval ?? PRESENCE_ANNOUNCE_INTERVAL,
5116
+ offlineTimeout: this._params?.spaceMemberPresenceOfflineTimeout ?? PRESENCE_OFFLINE_TIMEOUT,
4809
5117
  identityKey: this._signingContext.identityKey,
4810
5118
  gossip
4811
5119
  });
@@ -4832,15 +5140,15 @@ var DataSpaceManager = class {
4832
5140
  session.addExtension("dxos.mesh.teleport.automerge", this._echoHost.createReplicationExtension());
4833
5141
  },
4834
5142
  onAuthFailure: () => {
4835
- log13.warn("auth failure", void 0, {
4836
- F: __dxlog_file16,
4837
- L: 289,
5143
+ log15.warn("auth failure", void 0, {
5144
+ F: __dxlog_file18,
5145
+ L: 343,
4838
5146
  S: this,
4839
5147
  C: (f, a) => f(...a)
4840
5148
  });
4841
5149
  },
4842
5150
  onMemberRolesChanged: async (members) => {
4843
- if (dataSpace?.state === SpaceState2.READY) {
5151
+ if (dataSpace?.state === SpaceState3.READY) {
4844
5152
  this._handleMemberRoleChanges(presence, space.protocol, members);
4845
5153
  }
4846
5154
  },
@@ -4853,7 +5161,7 @@ var DataSpaceManager = class {
4853
5161
  dataFeed && await space.setDataFeed(dataFeed);
4854
5162
  const dataSpace = new DataSpace({
4855
5163
  inner: space,
4856
- initialState: metadata.state === SpaceState2.INACTIVE ? SpaceState2.INACTIVE : SpaceState2.CLOSED,
5164
+ initialState: metadata.state === SpaceState3.INACTIVE ? SpaceState3.INACTIVE : SpaceState3.CLOSED,
4857
5165
  metadataStore: this._metadataStore,
4858
5166
  gossip,
4859
5167
  presence,
@@ -4863,22 +5171,22 @@ var DataSpaceManager = class {
4863
5171
  signingContext: this._signingContext,
4864
5172
  callbacks: {
4865
5173
  beforeReady: async () => {
4866
- log13("before space ready", {
5174
+ log15("before space ready", {
4867
5175
  space: space.key
4868
5176
  }, {
4869
- F: __dxlog_file16,
4870
- L: 316,
5177
+ F: __dxlog_file18,
5178
+ L: 370,
4871
5179
  S: this,
4872
5180
  C: (f, a) => f(...a)
4873
5181
  });
4874
5182
  },
4875
5183
  afterReady: async () => {
4876
- log13("after space ready", {
5184
+ log15("after space ready", {
4877
5185
  space: space.key,
4878
5186
  open: this._isOpen
4879
5187
  }, {
4880
- F: __dxlog_file16,
4881
- L: 319,
5188
+ F: __dxlog_file18,
5189
+ L: 373,
4882
5190
  S: this,
4883
5191
  C: (f, a) => f(...a)
4884
5192
  });
@@ -4893,11 +5201,11 @@ var DataSpaceManager = class {
4893
5201
  }
4894
5202
  },
4895
5203
  beforeClose: async () => {
4896
- log13("before space close", {
5204
+ log15("before space close", {
4897
5205
  space: space.key
4898
5206
  }, {
4899
- F: __dxlog_file16,
4900
- L: 327,
5207
+ F: __dxlog_file18,
5208
+ L: 381,
4901
5209
  S: this,
4902
5210
  C: (f, a) => f(...a)
4903
5211
  });
@@ -4906,13 +5214,10 @@ var DataSpaceManager = class {
4906
5214
  cache: metadata.cache
4907
5215
  });
4908
5216
  presence.newPeer.on((peerState) => {
4909
- if (dataSpace.state === SpaceState2.READY) {
5217
+ if (dataSpace.state === SpaceState3.READY) {
4910
5218
  this._handleNewPeerConnected(space, peerState);
4911
5219
  }
4912
5220
  });
4913
- if (metadata.state !== SpaceState2.INACTIVE) {
4914
- await dataSpace.open();
4915
- }
4916
5221
  if (metadata.controlTimeframe) {
4917
5222
  dataSpace.inner.controlPipeline.state.setTargetTimeframe(metadata.controlTimeframe);
4918
5223
  }
@@ -4931,17 +5236,17 @@ var DataSpaceManager = class {
4931
5236
  return (s && member.role === SpaceMember6.Role.REMOVED !== (s.authStatus === AuthStatus.FAILURE)) ?? false;
4932
5237
  });
4933
5238
  sessionsToClose.forEach((session) => {
4934
- void session.close().catch(log13.error);
5239
+ void session.close().catch(log15.error);
4935
5240
  });
4936
5241
  closedSessions += sessionsToClose.length;
4937
5242
  }
4938
- log13("processed member role changes", {
5243
+ log15("processed member role changes", {
4939
5244
  roleChangeCount: memberInfo.length,
4940
5245
  peersOnline: presence.getPeersOnline().length,
4941
5246
  closedSessions
4942
5247
  }, {
4943
- F: __dxlog_file16,
4944
- L: 367,
5248
+ F: __dxlog_file18,
5249
+ L: 417,
4945
5250
  S: this,
4946
5251
  C: (f, a) => f(...a)
4947
5252
  });
@@ -4952,20 +5257,20 @@ var DataSpaceManager = class {
4952
5257
  if (role === SpaceMember6.Role.REMOVED) {
4953
5258
  const session = peerState.peerId && space.protocol.sessions.get(peerState.peerId);
4954
5259
  if (session != null) {
4955
- log13("closing a session with a removed peer", {
5260
+ log15("closing a session with a removed peer", {
4956
5261
  peerId: peerState.peerId
4957
5262
  }, {
4958
- F: __dxlog_file16,
4959
- L: 381,
5263
+ F: __dxlog_file18,
5264
+ L: 431,
4960
5265
  S: this,
4961
5266
  C: (f, a) => f(...a)
4962
5267
  });
4963
- void session.close().catch(log13.error);
5268
+ void session.close().catch(log15.error);
4964
5269
  }
4965
5270
  }
4966
5271
  }
4967
5272
  async _handleInvitationStatusChange(dataSpace, delegatedInvitation, isActive) {
4968
- if (dataSpace?.state !== SpaceState2.READY) {
5273
+ if (dataSpace?.state !== SpaceState3.READY) {
4969
5274
  return;
4970
5275
  }
4971
5276
  if (isActive) {
@@ -5019,15 +5324,15 @@ DataSpaceManager = _ts_decorate5([
5019
5324
  // packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
5020
5325
  import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTask as scheduleTask6 } from "@dxos/async";
5021
5326
  import { Stream as Stream10 } from "@dxos/codec-protobuf";
5022
- import { createAdmissionCredentials as createAdmissionCredentials2, getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
5327
+ import { createAdmissionCredentials as createAdmissionCredentials2, getCredentialAssertion as getCredentialAssertion4 } from "@dxos/credentials";
5023
5328
  import { raise as raise2 } from "@dxos/debug";
5024
5329
  import { writeMessages as writeMessages3 } from "@dxos/feed-store";
5025
5330
  import { invariant as invariant15 } from "@dxos/invariant";
5026
- import { log as log14 } from "@dxos/log";
5331
+ import { log as log16 } from "@dxos/log";
5027
5332
  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";
5333
+ import { SpaceMember as SpaceMember7, SpaceState as SpaceState4 } from "@dxos/protocols/proto/dxos/client/services";
5029
5334
  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";
5335
+ var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
5031
5336
  var SpacesServiceImpl = class {
5032
5337
  constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
5033
5338
  this._identityManager = _identityManager;
@@ -5046,10 +5351,10 @@ var SpacesServiceImpl = class {
5046
5351
  const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError2(spaceKey));
5047
5352
  if (state) {
5048
5353
  switch (state) {
5049
- case SpaceState3.ACTIVE:
5354
+ case SpaceState4.ACTIVE:
5050
5355
  await space.activate();
5051
5356
  break;
5052
- case SpaceState3.INACTIVE:
5357
+ case SpaceState4.INACTIVE:
5053
5358
  await space.deactivate();
5054
5359
  break;
5055
5360
  default:
@@ -5071,8 +5376,8 @@ var SpacesServiceImpl = class {
5071
5376
  }
5072
5377
  const credentials = await createAdmissionCredentials2(identity.getIdentityCredentialSigner(), request.memberKey, space.key, space.genesisFeedKey, request.newRole, space.spaceState.membershipChainHeads);
5073
5378
  invariant15(credentials[0].credential, void 0, {
5074
- F: __dxlog_file17,
5075
- L: 97,
5379
+ F: __dxlog_file19,
5380
+ L: 98,
5076
5381
  S: this,
5077
5382
  A: [
5078
5383
  "credentials[0].credential",
@@ -5080,9 +5385,9 @@ var SpacesServiceImpl = class {
5080
5385
  ]
5081
5386
  });
5082
5387
  const spaceMemberCredential = credentials[0].credential.credential;
5083
- invariant15(getCredentialAssertion3(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
5084
- F: __dxlog_file17,
5085
- L: 99,
5388
+ invariant15(getCredentialAssertion4(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
5389
+ F: __dxlog_file19,
5390
+ L: 100,
5086
5391
  S: this,
5087
5392
  A: [
5088
5393
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -5096,11 +5401,11 @@ var SpacesServiceImpl = class {
5096
5401
  const scheduler = new UpdateScheduler(ctx, async () => {
5097
5402
  const dataSpaceManager = await this._getDataSpaceManager();
5098
5403
  const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
5099
- log14("update", {
5404
+ log16("update", {
5100
5405
  spaces
5101
5406
  }, {
5102
- F: __dxlog_file17,
5103
- L: 110,
5407
+ F: __dxlog_file19,
5408
+ L: 111,
5104
5409
  S: this,
5105
5410
  C: (f, a) => f(...a)
5106
5411
  });
@@ -5183,8 +5488,8 @@ var SpacesServiceImpl = class {
5183
5488
  });
5184
5489
  } else {
5185
5490
  invariant15(!credential.id, "Id on unsigned credentials is not allowed", {
5186
- F: __dxlog_file17,
5187
- L: 198,
5491
+ F: __dxlog_file19,
5492
+ L: 199,
5188
5493
  S: this,
5189
5494
  A: [
5190
5495
  "!credential.id",
@@ -5192,8 +5497,8 @@ var SpacesServiceImpl = class {
5192
5497
  ]
5193
5498
  });
5194
5499
  invariant15(this._identityManager.identity, "Identity is not available", {
5195
- F: __dxlog_file17,
5196
- L: 199,
5500
+ F: __dxlog_file19,
5501
+ L: 200,
5197
5502
  S: this,
5198
5503
  A: [
5199
5504
  "this._identityManager.identity",
@@ -5202,8 +5507,8 @@ var SpacesServiceImpl = class {
5202
5507
  });
5203
5508
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
5204
5509
  invariant15(credential.issuer.equals(signer.getIssuer()), void 0, {
5205
- F: __dxlog_file17,
5206
- L: 201,
5510
+ F: __dxlog_file19,
5511
+ L: 202,
5207
5512
  S: this,
5208
5513
  A: [
5209
5514
  "credential.issuer.equals(signer.getIssuer())",
@@ -5225,10 +5530,13 @@ var SpacesServiceImpl = class {
5225
5530
  async createEpoch({ spaceKey, migration, automergeRootUrl }) {
5226
5531
  const dataSpaceManager = await this._getDataSpaceManager();
5227
5532
  const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError2(spaceKey));
5228
- await space.createEpoch({
5533
+ const credential = await space.createEpoch({
5229
5534
  migration,
5230
5535
  newAutomergeRoot: automergeRootUrl
5231
5536
  });
5537
+ return {
5538
+ epochCredential: credential ?? void 0
5539
+ };
5232
5540
  }
5233
5541
  _serializeSpace(space) {
5234
5542
  return {
@@ -5292,8 +5600,8 @@ var getChannelId = (channel) => `user-channel/${channel}`;
5292
5600
 
5293
5601
  // packages/sdk/client-services/src/packlets/services/service-context.ts
5294
5602
  import { Trigger as Trigger7 } from "@dxos/async";
5295
- import { Context as Context10, Resource } from "@dxos/context";
5296
- import { getCredentialAssertion as getCredentialAssertion4 } from "@dxos/credentials";
5603
+ import { Context as Context10, Resource as Resource3 } from "@dxos/context";
5604
+ import { getCredentialAssertion as getCredentialAssertion5 } from "@dxos/credentials";
5297
5605
  import { failUndefined as failUndefined2 } from "@dxos/debug";
5298
5606
  import { EchoHost } from "@dxos/echo-db";
5299
5607
  import { MetadataStore, SnapshotStore, SpaceManager, valueEncoding } from "@dxos/echo-pipeline";
@@ -5301,7 +5609,7 @@ import { FeedFactory, FeedStore } from "@dxos/feed-store";
5301
5609
  import { invariant as invariant16 } from "@dxos/invariant";
5302
5610
  import { Keyring } from "@dxos/keyring";
5303
5611
  import { PublicKey as PublicKey12 } from "@dxos/keys";
5304
- import { log as log15 } from "@dxos/log";
5612
+ import { log as log17 } from "@dxos/log";
5305
5613
  import { InvalidStorageVersionError, STORAGE_VERSION as STORAGE_VERSION2, trace as trace9 } from "@dxos/protocols";
5306
5614
  import { Invitation as Invitation8 } from "@dxos/protocols/proto/dxos/client/services";
5307
5615
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
@@ -5317,8 +5625,8 @@ function _ts_decorate6(decorators, target, key, desc) {
5317
5625
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5318
5626
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5319
5627
  }
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 {
5628
+ var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
5629
+ var ServiceContext = class extends Resource3 {
5322
5630
  constructor(storage, level, networkManager, signalManager, _runtimeParams) {
5323
5631
  super();
5324
5632
  this.storage = storage;
@@ -5352,8 +5660,7 @@ var ServiceContext = class extends Resource {
5352
5660
  });
5353
5661
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager, this._runtimeParams);
5354
5662
  this.echoHost = new EchoHost({
5355
- kv: this.level,
5356
- storage: this.storage
5663
+ kv: this.level
5357
5664
  });
5358
5665
  this.invitations = new InvitationsHandler(this.networkManager, _runtimeParams?.invitationConnectionDefaultParams);
5359
5666
  this.invitationsManager = new InvitationsManager(this.invitations, (invitation) => this.getInvitationHandler(invitation), this.metadataStore);
@@ -5361,17 +5668,17 @@ var ServiceContext = class extends Resource {
5361
5668
  }
5362
5669
  async _open(ctx) {
5363
5670
  await this._checkStorageVersion();
5364
- log15("opening...", void 0, {
5365
- F: __dxlog_file18,
5366
- L: 152,
5671
+ log17("opening...", void 0, {
5672
+ F: __dxlog_file20,
5673
+ L: 149,
5367
5674
  S: this,
5368
5675
  C: (f, a) => f(...a)
5369
5676
  });
5370
- log15.trace("dxos.sdk.service-context.open", trace9.begin({
5677
+ log17.trace("dxos.sdk.service-context.open", trace9.begin({
5371
5678
  id: this._instanceId
5372
5679
  }), {
5373
- F: __dxlog_file18,
5374
- L: 153,
5680
+ F: __dxlog_file20,
5681
+ L: 150,
5375
5682
  S: this,
5376
5683
  C: (f, a) => f(...a)
5377
5684
  });
@@ -5385,33 +5692,33 @@ var ServiceContext = class extends Resource {
5385
5692
  await this._initialize(ctx);
5386
5693
  }
5387
5694
  const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
5388
- log15("loaded persistent invitations", {
5695
+ log17("loaded persistent invitations", {
5389
5696
  count: loadedInvitations.invitations?.length
5390
5697
  }, {
5391
- F: __dxlog_file18,
5392
- L: 166,
5698
+ F: __dxlog_file20,
5699
+ L: 163,
5393
5700
  S: this,
5394
5701
  C: (f, a) => f(...a)
5395
5702
  });
5396
- log15.trace("dxos.sdk.service-context.open", trace9.end({
5703
+ log17.trace("dxos.sdk.service-context.open", trace9.end({
5397
5704
  id: this._instanceId
5398
5705
  }), {
5399
- F: __dxlog_file18,
5400
- L: 168,
5706
+ F: __dxlog_file20,
5707
+ L: 165,
5401
5708
  S: this,
5402
5709
  C: (f, a) => f(...a)
5403
5710
  });
5404
- log15("opened", void 0, {
5405
- F: __dxlog_file18,
5406
- L: 169,
5711
+ log17("opened", void 0, {
5712
+ F: __dxlog_file20,
5713
+ L: 166,
5407
5714
  S: this,
5408
5715
  C: (f, a) => f(...a)
5409
5716
  });
5410
5717
  }
5411
5718
  async _close(ctx) {
5412
- log15("closing...", void 0, {
5413
- F: __dxlog_file18,
5414
- L: 173,
5719
+ log17("closing...", void 0, {
5720
+ F: __dxlog_file20,
5721
+ L: 170,
5415
5722
  S: this,
5416
5723
  C: (f, a) => f(...a)
5417
5724
  });
@@ -5426,9 +5733,9 @@ var ServiceContext = class extends Resource {
5426
5733
  await this.echoHost.close(ctx);
5427
5734
  await this.networkManager.close();
5428
5735
  await this.signalManager.close();
5429
- log15("closed", void 0, {
5430
- F: __dxlog_file18,
5431
- L: 185,
5736
+ log17("closed", void 0, {
5737
+ F: __dxlog_file20,
5738
+ L: 182,
5432
5739
  S: this,
5433
5740
  C: (f, a) => f(...a)
5434
5741
  });
@@ -5441,8 +5748,8 @@ var ServiceContext = class extends Resource {
5441
5748
  getInvitationHandler(invitation) {
5442
5749
  const factory = this._handlerFactories.get(invitation.kind);
5443
5750
  invariant16(factory, `Unknown invitation kind: ${invitation.kind}`, {
5444
- F: __dxlog_file18,
5445
- L: 196,
5751
+ F: __dxlog_file20,
5752
+ L: 193,
5446
5753
  S: this,
5447
5754
  A: [
5448
5755
  "factory",
@@ -5472,9 +5779,9 @@ var ServiceContext = class extends Resource {
5472
5779
  }
5473
5780
  // Called when identity is created.
5474
5781
  async _initialize(ctx) {
5475
- log15("initializing spaces...", void 0, {
5476
- F: __dxlog_file18,
5477
- L: 227,
5782
+ log17("initializing spaces...", void 0, {
5783
+ F: __dxlog_file20,
5784
+ L: 224,
5478
5785
  S: this,
5479
5786
  C: (f, a) => f(...a)
5480
5787
  });
@@ -5496,8 +5803,8 @@ var ServiceContext = class extends Resource {
5496
5803
  await this.dataSpaceManager.open();
5497
5804
  this._handlerFactories.set(Invitation8.Kind.SPACE, (invitation) => {
5498
5805
  invariant16(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
5499
- F: __dxlog_file18,
5500
- L: 252,
5806
+ F: __dxlog_file20,
5807
+ L: 249,
5501
5808
  S: this,
5502
5809
  A: [
5503
5810
  "this.dataSpaceManager",
@@ -5509,7 +5816,7 @@ var ServiceContext = class extends Resource {
5509
5816
  this.initialized.wake();
5510
5817
  this._deviceSpaceSync = {
5511
5818
  processCredential: async (credential) => {
5512
- const assertion = getCredentialAssertion4(credential);
5819
+ const assertion = getCredentialAssertion5(credential);
5513
5820
  if (assertion["@type"] !== "dxos.halo.credentials.SpaceMember") {
5514
5821
  return;
5515
5822
  }
@@ -5517,33 +5824,33 @@ var ServiceContext = class extends Resource {
5517
5824
  return;
5518
5825
  }
5519
5826
  if (!this.dataSpaceManager) {
5520
- log15("dataSpaceManager not initialized yet, ignoring space admission", {
5827
+ log17("dataSpaceManager not initialized yet, ignoring space admission", {
5521
5828
  details: assertion
5522
5829
  }, {
5523
- F: __dxlog_file18,
5524
- L: 268,
5830
+ F: __dxlog_file20,
5831
+ L: 265,
5525
5832
  S: this,
5526
5833
  C: (f, a) => f(...a)
5527
5834
  });
5528
5835
  return;
5529
5836
  }
5530
5837
  if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
5531
- log15("space already exists, ignoring space admission", {
5838
+ log17("space already exists, ignoring space admission", {
5532
5839
  details: assertion
5533
5840
  }, {
5534
- F: __dxlog_file18,
5535
- L: 272,
5841
+ F: __dxlog_file20,
5842
+ L: 269,
5536
5843
  S: this,
5537
5844
  C: (f, a) => f(...a)
5538
5845
  });
5539
5846
  return;
5540
5847
  }
5541
5848
  try {
5542
- log15("accepting space recorded in halo", {
5849
+ log17("accepting space recorded in halo", {
5543
5850
  details: assertion
5544
5851
  }, {
5545
- F: __dxlog_file18,
5546
- L: 277,
5852
+ F: __dxlog_file20,
5853
+ L: 274,
5547
5854
  S: this,
5548
5855
  C: (f, a) => f(...a)
5549
5856
  });
@@ -5552,9 +5859,9 @@ var ServiceContext = class extends Resource {
5552
5859
  genesisFeedKey: assertion.genesisFeedKey
5553
5860
  });
5554
5861
  } catch (err) {
5555
- log15.catch(err, void 0, {
5556
- F: __dxlog_file18,
5557
- L: 283,
5862
+ log17.catch(err, void 0, {
5863
+ F: __dxlog_file20,
5864
+ L: 280,
5558
5865
  S: this,
5559
5866
  C: (f, a) => f(...a)
5560
5867
  });
@@ -5602,7 +5909,7 @@ var ServiceRegistry = class {
5602
5909
  // packages/sdk/client-services/src/packlets/locks/browser.ts
5603
5910
  import { asyncTimeout as asyncTimeout3, Trigger as Trigger8 } from "@dxos/async";
5604
5911
  import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
5605
- import { log as log16, logInfo } from "@dxos/log";
5912
+ import { log as log18, logInfo } from "@dxos/log";
5606
5913
  function _ts_decorate7(decorators, target, key, desc) {
5607
5914
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5608
5915
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -5613,7 +5920,7 @@ function _ts_decorate7(decorators, target, key, desc) {
5613
5920
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5614
5921
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5615
5922
  }
5616
- var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
5923
+ var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
5617
5924
  var Message;
5618
5925
  (function(Message2) {
5619
5926
  Message2["ACQUIRING"] = "acquiring";
@@ -5635,29 +5942,29 @@ var Lock = class {
5635
5942
  message: "acquiring"
5636
5943
  });
5637
5944
  try {
5638
- log16("aquiring lock...", void 0, {
5639
- F: __dxlog_file19,
5945
+ log18("aquiring lock...", void 0, {
5946
+ F: __dxlog_file21,
5640
5947
  L: 42,
5641
5948
  S: this,
5642
5949
  C: (f, a) => f(...a)
5643
5950
  });
5644
5951
  await asyncTimeout3(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
5645
- log16("acquired lock", void 0, {
5646
- F: __dxlog_file19,
5952
+ log18("acquired lock", void 0, {
5953
+ F: __dxlog_file21,
5647
5954
  L: 44,
5648
5955
  S: this,
5649
5956
  C: (f, a) => f(...a)
5650
5957
  });
5651
5958
  } catch {
5652
- log16("stealing lock...", void 0, {
5653
- F: __dxlog_file19,
5959
+ log18("stealing lock...", void 0, {
5960
+ F: __dxlog_file21,
5654
5961
  L: 46,
5655
5962
  S: this,
5656
5963
  C: (f, a) => f(...a)
5657
5964
  });
5658
5965
  await this._requestLock(true);
5659
- log16("stolen lock", void 0, {
5660
- F: __dxlog_file19,
5966
+ log18("stolen lock", void 0, {
5967
+ F: __dxlog_file21,
5661
5968
  L: 48,
5662
5969
  S: this,
5663
5970
  C: (f, a) => f(...a)
@@ -5673,10 +5980,10 @@ var Lock = class {
5673
5980
  }
5674
5981
  }
5675
5982
  async _requestLock(steal = false) {
5676
- log16("requesting lock...", {
5983
+ log18("requesting lock...", {
5677
5984
  steal
5678
5985
  }, {
5679
- F: __dxlog_file19,
5986
+ F: __dxlog_file21,
5680
5987
  L: 63,
5681
5988
  S: this,
5682
5989
  C: (f, a) => f(...a)
@@ -5689,15 +5996,15 @@ var Lock = class {
5689
5996
  acquired.wake();
5690
5997
  this._releaseTrigger = new Trigger8();
5691
5998
  await this._releaseTrigger.wait();
5692
- log16("releasing lock...", void 0, {
5693
- F: __dxlog_file19,
5999
+ log18("releasing lock...", void 0, {
6000
+ F: __dxlog_file21,
5694
6001
  L: 72,
5695
6002
  S: this,
5696
6003
  C: (f, a) => f(...a)
5697
6004
  });
5698
6005
  await this._onRelease?.();
5699
- log16("released lock", void 0, {
5700
- F: __dxlog_file19,
6006
+ log18("released lock", void 0, {
6007
+ F: __dxlog_file21,
5701
6008
  L: 74,
5702
6009
  S: this,
5703
6010
  C: (f, a) => f(...a)
@@ -5706,10 +6013,10 @@ var Lock = class {
5706
6013
  await this._onRelease?.();
5707
6014
  });
5708
6015
  await acquired.wait();
5709
- log16("recieved lock", {
6016
+ log18("recieved lock", {
5710
6017
  steal
5711
6018
  }, {
5712
- F: __dxlog_file19,
6019
+ F: __dxlog_file21,
5713
6020
  L: 81,
5714
6021
  S: this,
5715
6022
  C: (f, a) => f(...a)
@@ -5799,19 +6106,16 @@ var createLevel = async (config) => {
5799
6106
 
5800
6107
  // packages/sdk/client-services/src/packlets/services/service-host.ts
5801
6108
  import { Event as Event9, synchronized as synchronized3 } from "@dxos/async";
5802
- import { clientServiceBundle, defaultKey, PropertiesType } from "@dxos/client-protocol";
6109
+ import { clientServiceBundle } from "@dxos/client-protocol";
5803
6110
  import { Context as Context11 } from "@dxos/context";
5804
- import { encodeReference } from "@dxos/echo-protocol";
5805
- import { getTypeReference } from "@dxos/echo-schema";
5806
6111
  import { invariant as invariant18 } from "@dxos/invariant";
5807
6112
  import { PublicKey as PublicKey16 } from "@dxos/keys";
5808
- import { log as log18 } from "@dxos/log";
6113
+ import { log as log20 } from "@dxos/log";
5809
6114
  import { WebsocketSignalManager } from "@dxos/messaging";
5810
6115
  import { SwarmNetworkManager, createSimplePeerTransportFactory } from "@dxos/network-manager";
5811
6116
  import { trace as trace10 } from "@dxos/protocols";
5812
6117
  import { SystemStatus } from "@dxos/protocols/proto/dxos/client/services";
5813
6118
  import { TRACE_PROCESSOR as TRACE_PROCESSOR3, trace as Trace4 } from "@dxos/tracing";
5814
- import { assignDeep as assignDeep2 } from "@dxos/util";
5815
6119
  import { WebsocketRpcClient } from "@dxos/websocket-rpc";
5816
6120
 
5817
6121
  // packages/sdk/client-services/src/packlets/devices/devices-service.ts
@@ -5819,7 +6123,7 @@ import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
5819
6123
  import { Stream as Stream11 } from "@dxos/codec-protobuf";
5820
6124
  import { invariant as invariant17 } from "@dxos/invariant";
5821
6125
  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";
6126
+ var __dxlog_file22 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
5823
6127
  var DevicesServiceImpl = class {
5824
6128
  constructor(_identityManager) {
5825
6129
  this._identityManager = _identityManager;
@@ -5837,7 +6141,7 @@ var DevicesServiceImpl = class {
5837
6141
  });
5838
6142
  } else {
5839
6143
  invariant17(this._identityManager.identity?.presence, "presence not present", {
5840
- F: __dxlog_file20,
6144
+ F: __dxlog_file22,
5841
6145
  L: 32,
5842
6146
  S: this,
5843
6147
  A: [
@@ -5947,7 +6251,7 @@ var findConfigs = () => {
5947
6251
  import { Event as Event8 } from "@dxos/async";
5948
6252
  import { Stream as Stream12 } from "@dxos/codec-protobuf";
5949
6253
  import { PublicKey as PublicKey15 } from "@dxos/keys";
5950
- import { getContextFromEntry, log as log17 } from "@dxos/log";
6254
+ import { getContextFromEntry, log as log19 } from "@dxos/log";
5951
6255
  import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
5952
6256
  import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
5953
6257
  var LoggingServiceImpl = class {
@@ -5960,11 +6264,11 @@ var LoggingServiceImpl = class {
5960
6264
  };
5961
6265
  }
5962
6266
  async open() {
5963
- log17.runtimeConfig.processors.push(this._logProcessor);
6267
+ log19.runtimeConfig.processors.push(this._logProcessor);
5964
6268
  }
5965
6269
  async close() {
5966
- const index = log17.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
5967
- log17.runtimeConfig.processors.splice(index, 1);
6270
+ const index = log19.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
6271
+ log19.runtimeConfig.processors.splice(index, 1);
5968
6272
  }
5969
6273
  async controlMetrics({ reset, record }) {
5970
6274
  if (reset) {
@@ -6168,7 +6472,7 @@ function _ts_decorate8(decorators, target, key, desc) {
6168
6472
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6169
6473
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6170
6474
  }
6171
- var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
6475
+ var __dxlog_file23 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
6172
6476
  var ClientServicesHost = class {
6173
6477
  constructor({
6174
6478
  config,
@@ -6188,7 +6492,7 @@ var ClientServicesHost = class {
6188
6492
  this._storage = storage;
6189
6493
  this._level = level;
6190
6494
  this._callbacks = callbacks;
6191
- this._runtimeParams = runtimeParams;
6495
+ this._runtimeParams = runtimeParams ?? {};
6192
6496
  if (config) {
6193
6497
  this.initialize({
6194
6498
  config,
@@ -6257,24 +6561,24 @@ var ClientServicesHost = class {
6257
6561
  */
6258
6562
  initialize({ config, ...options }) {
6259
6563
  invariant18(!this._open, "service host is open", {
6260
- F: __dxlog_file21,
6261
- L: 189,
6564
+ F: __dxlog_file23,
6565
+ L: 186,
6262
6566
  S: this,
6263
6567
  A: [
6264
6568
  "!this._open",
6265
6569
  "'service host is open'"
6266
6570
  ]
6267
6571
  });
6268
- log18("initializing...", void 0, {
6269
- F: __dxlog_file21,
6270
- L: 190,
6572
+ log20("initializing...", void 0, {
6573
+ F: __dxlog_file23,
6574
+ L: 187,
6271
6575
  S: this,
6272
6576
  C: (f, a) => f(...a)
6273
6577
  });
6274
6578
  if (config) {
6275
6579
  invariant18(!this._config, "config already set", {
6276
- F: __dxlog_file21,
6277
- L: 193,
6580
+ F: __dxlog_file23,
6581
+ L: 190,
6278
6582
  S: this,
6279
6583
  A: [
6280
6584
  "!this._config",
@@ -6287,9 +6591,9 @@ var ClientServicesHost = class {
6287
6591
  }
6288
6592
  }
6289
6593
  if (!options.signalManager) {
6290
- log18.warn("running signaling without telemetry metadata.", void 0, {
6291
- F: __dxlog_file21,
6292
- L: 201,
6594
+ log20.warn("running signaling without telemetry metadata.", void 0, {
6595
+ F: __dxlog_file23,
6596
+ L: 198,
6293
6597
  S: this,
6294
6598
  C: (f, a) => f(...a)
6295
6599
  });
@@ -6299,8 +6603,8 @@ var ClientServicesHost = class {
6299
6603
  }), signalManager = new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
6300
6604
  this._signalManager = signalManager;
6301
6605
  invariant18(!this._networkManager, "network manager already set", {
6302
- F: __dxlog_file21,
6303
- L: 212,
6606
+ F: __dxlog_file23,
6607
+ L: 209,
6304
6608
  S: this,
6305
6609
  A: [
6306
6610
  "!this._networkManager",
@@ -6312,9 +6616,9 @@ var ClientServicesHost = class {
6312
6616
  transportFactory,
6313
6617
  signalManager
6314
6618
  });
6315
- log18("initialized", void 0, {
6316
- F: __dxlog_file21,
6317
- L: 219,
6619
+ log20("initialized", void 0, {
6620
+ F: __dxlog_file23,
6621
+ L: 216,
6318
6622
  S: this,
6319
6623
  C: (f, a) => f(...a)
6320
6624
  });
@@ -6324,17 +6628,17 @@ var ClientServicesHost = class {
6324
6628
  return;
6325
6629
  }
6326
6630
  const traceId = PublicKey16.random().toHex();
6327
- log18.trace("dxos.client-services.host.open", trace10.begin({
6631
+ log20.trace("dxos.client-services.host.open", trace10.begin({
6328
6632
  id: traceId
6329
6633
  }), {
6330
- F: __dxlog_file21,
6331
- L: 230,
6634
+ F: __dxlog_file23,
6635
+ L: 227,
6332
6636
  S: this,
6333
6637
  C: (f, a) => f(...a)
6334
6638
  });
6335
6639
  invariant18(this._config, "config not set", {
6336
- F: __dxlog_file21,
6337
- L: 232,
6640
+ F: __dxlog_file23,
6641
+ L: 229,
6338
6642
  S: this,
6339
6643
  A: [
6340
6644
  "this._config",
@@ -6342,8 +6646,8 @@ var ClientServicesHost = class {
6342
6646
  ]
6343
6647
  });
6344
6648
  invariant18(this._storage, "storage not set", {
6345
- F: __dxlog_file21,
6346
- L: 233,
6649
+ F: __dxlog_file23,
6650
+ L: 230,
6347
6651
  S: this,
6348
6652
  A: [
6349
6653
  "this._storage",
@@ -6351,8 +6655,8 @@ var ClientServicesHost = class {
6351
6655
  ]
6352
6656
  });
6353
6657
  invariant18(this._signalManager, "signal manager not set", {
6354
- F: __dxlog_file21,
6355
- L: 234,
6658
+ F: __dxlog_file23,
6659
+ L: 231,
6356
6660
  S: this,
6357
6661
  A: [
6358
6662
  "this._signalManager",
@@ -6360,8 +6664,8 @@ var ClientServicesHost = class {
6360
6664
  ]
6361
6665
  });
6362
6666
  invariant18(this._networkManager, "network manager not set", {
6363
- F: __dxlog_file21,
6364
- L: 235,
6667
+ F: __dxlog_file23,
6668
+ L: 232,
6365
6669
  S: this,
6366
6670
  A: [
6367
6671
  "this._networkManager",
@@ -6369,11 +6673,11 @@ var ClientServicesHost = class {
6369
6673
  ]
6370
6674
  });
6371
6675
  this._opening = true;
6372
- log18("opening...", {
6676
+ log20("opening...", {
6373
6677
  lockKey: this._resourceLock?.lockKey
6374
6678
  }, {
6375
- F: __dxlog_file21,
6376
- L: 238,
6679
+ F: __dxlog_file23,
6680
+ L: 235,
6377
6681
  S: this,
6378
6682
  C: (f, a) => f(...a)
6379
6683
  });
@@ -6384,9 +6688,10 @@ var ClientServicesHost = class {
6384
6688
  await this._level.open();
6385
6689
  await this._loggingService.open();
6386
6690
  this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._runtimeParams);
6691
+ const identityService = new IdentityServiceImpl(this._serviceContext.identityManager, this._serviceContext.keyring, () => this._serviceContext.dataSpaceManager, (params) => this._createIdentity(params), (profile) => this._serviceContext.broadcastProfileUpdate(profile));
6387
6692
  this._serviceRegistry.setServices({
6388
6693
  SystemService: this._systemService,
6389
- IdentityService: new IdentityServiceImpl((params) => this._createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring, (profile) => this._serviceContext.broadcastProfileUpdate(profile)),
6694
+ IdentityService: identityService,
6390
6695
  InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitationsManager),
6391
6696
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
6392
6697
  SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, async () => {
@@ -6406,6 +6711,7 @@ var ClientServicesHost = class {
6406
6711
  })
6407
6712
  });
6408
6713
  await this._serviceContext.open(ctx);
6714
+ await identityService.open();
6409
6715
  const devtoolsProxy = this._config?.get("runtime.client.devtoolsProxy");
6410
6716
  if (devtoolsProxy) {
6411
6717
  this._devtoolsProxy = new WebsocketRpcClient({
@@ -6421,18 +6727,18 @@ var ClientServicesHost = class {
6421
6727
  this._open = true;
6422
6728
  this._statusUpdate.emit();
6423
6729
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
6424
- log18("opened", {
6730
+ log20("opened", {
6425
6731
  deviceKey
6426
6732
  }, {
6427
- F: __dxlog_file21,
6733
+ F: __dxlog_file23,
6428
6734
  L: 314,
6429
6735
  S: this,
6430
6736
  C: (f, a) => f(...a)
6431
6737
  });
6432
- log18.trace("dxos.client-services.host.open", trace10.end({
6738
+ log20.trace("dxos.client-services.host.open", trace10.end({
6433
6739
  id: traceId
6434
6740
  }), {
6435
- F: __dxlog_file21,
6741
+ F: __dxlog_file23,
6436
6742
  L: 315,
6437
6743
  S: this,
6438
6744
  C: (f, a) => f(...a)
@@ -6443,10 +6749,10 @@ var ClientServicesHost = class {
6443
6749
  return;
6444
6750
  }
6445
6751
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
6446
- log18("closing...", {
6752
+ log20("closing...", {
6447
6753
  deviceKey
6448
6754
  }, {
6449
- F: __dxlog_file21,
6755
+ F: __dxlog_file23,
6450
6756
  L: 326,
6451
6757
  S: this,
6452
6758
  C: (f, a) => f(...a)
@@ -6461,10 +6767,10 @@ var ClientServicesHost = class {
6461
6767
  await this._level?.close();
6462
6768
  this._open = false;
6463
6769
  this._statusUpdate.emit();
6464
- log18("closed", {
6770
+ log20("closed", {
6465
6771
  deviceKey
6466
6772
  }, {
6467
- F: __dxlog_file21,
6773
+ F: __dxlog_file23,
6468
6774
  L: 335,
6469
6775
  S: this,
6470
6776
  C: (f, a) => f(...a)
@@ -6472,32 +6778,32 @@ var ClientServicesHost = class {
6472
6778
  }
6473
6779
  async reset() {
6474
6780
  const traceId = PublicKey16.random().toHex();
6475
- log18.trace("dxos.sdk.client-services-host.reset", trace10.begin({
6781
+ log20.trace("dxos.sdk.client-services-host.reset", trace10.begin({
6476
6782
  id: traceId
6477
6783
  }), {
6478
- F: __dxlog_file21,
6784
+ F: __dxlog_file23,
6479
6785
  L: 340,
6480
6786
  S: this,
6481
6787
  C: (f, a) => f(...a)
6482
6788
  });
6483
- log18.info("resetting...", void 0, {
6484
- F: __dxlog_file21,
6789
+ log20.info("resetting...", void 0, {
6790
+ F: __dxlog_file23,
6485
6791
  L: 342,
6486
6792
  S: this,
6487
6793
  C: (f, a) => f(...a)
6488
6794
  });
6489
6795
  await this._serviceContext?.close();
6490
6796
  await this._storage.reset();
6491
- log18.info("reset", void 0, {
6492
- F: __dxlog_file21,
6797
+ log20.info("reset", void 0, {
6798
+ F: __dxlog_file23,
6493
6799
  L: 345,
6494
6800
  S: this,
6495
6801
  C: (f, a) => f(...a)
6496
6802
  });
6497
- log18.trace("dxos.sdk.client-services-host.reset", trace10.end({
6803
+ log20.trace("dxos.sdk.client-services-host.reset", trace10.end({
6498
6804
  id: traceId
6499
6805
  }), {
6500
- F: __dxlog_file21,
6806
+ F: __dxlog_file23,
6501
6807
  L: 346,
6502
6808
  S: this,
6503
6809
  C: (f, a) => f(...a)
@@ -6507,38 +6813,6 @@ var ClientServicesHost = class {
6507
6813
  async _createIdentity(params) {
6508
6814
  const identity = await this._serviceContext.createIdentity(params);
6509
6815
  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
6816
  return identity;
6543
6817
  }
6544
6818
  };
@@ -6588,7 +6862,6 @@ export {
6588
6862
  SpaceInvitationProtocol,
6589
6863
  InvitationsManager,
6590
6864
  DataSpace,
6591
- findPropertiesObject,
6592
6865
  DataSpaceManager,
6593
6866
  SpacesServiceImpl,
6594
6867
  ServiceContext,
@@ -6601,4 +6874,4 @@ export {
6601
6874
  ClientServicesProviderResource,
6602
6875
  DiagnosticsCollector
6603
6876
  };
6604
- //# sourceMappingURL=chunk-XEG7XZN4.mjs.map
6877
+ //# sourceMappingURL=chunk-SLSPX47D.mjs.map