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

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