@dxos/client-services 0.5.9-main.b06c86b → 0.5.9-main.b752d7f

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 (45) hide show
  1. package/dist/lib/browser/{chunk-2JCI5YEM.mjs → chunk-PA5DAU64.mjs} +906 -502
  2. package/dist/lib/browser/chunk-PA5DAU64.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +13 -2
  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 +10 -3
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +1 -1
  8. package/dist/lib/node/{chunk-HRQTR7UW.cjs → chunk-G6UXW6DQ.cjs} +950 -546
  9. package/dist/lib/node/chunk-G6UXW6DQ.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +53 -42
  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 -10
  14. package/dist/lib/node/packlets/testing/index.cjs.map +1 -1
  15. package/dist/types/src/packlets/identity/contacts-service.d.ts +14 -0
  16. package/dist/types/src/packlets/identity/contacts-service.d.ts.map +1 -0
  17. package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
  18. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  19. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  20. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +10 -1
  21. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  22. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  23. package/dist/types/src/packlets/spaces/epoch-migrations.d.ts +2 -2
  24. package/dist/types/src/packlets/spaces/epoch-migrations.d.ts.map +1 -1
  25. package/dist/types/src/packlets/spaces/spaces-service.d.ts +4 -1
  26. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  27. package/dist/types/src/packlets/storage/index.d.ts +1 -0
  28. package/dist/types/src/packlets/storage/index.d.ts.map +1 -1
  29. package/dist/types/src/packlets/storage/profile-archive.d.ts +14 -0
  30. package/dist/types/src/packlets/storage/profile-archive.d.ts.map +1 -0
  31. package/dist/types/src/version.d.ts +1 -1
  32. package/package.json +36 -36
  33. package/src/packlets/identity/contacts-service.ts +85 -0
  34. package/src/packlets/identity/identity-service.ts +28 -22
  35. package/src/packlets/invitations/space-invitation-protocol.ts +11 -32
  36. package/src/packlets/services/service-host.ts +12 -4
  37. package/src/packlets/spaces/data-space-manager.ts +55 -2
  38. package/src/packlets/spaces/data-space.ts +3 -1
  39. package/src/packlets/spaces/epoch-migrations.ts +57 -38
  40. package/src/packlets/spaces/spaces-service.ts +40 -0
  41. package/src/packlets/storage/index.ts +1 -0
  42. package/src/packlets/storage/profile-archive.ts +111 -0
  43. package/src/version.ts +1 -1
  44. package/dist/lib/browser/chunk-2JCI5YEM.mjs.map +0 -7
  45. package/dist/lib/node/chunk-HRQTR7UW.cjs.map +0 -7
@@ -85,6 +85,7 @@ var subscribeToFeedBlocks = ({ feedStore }, { feedKey, maxBlocks = 10 }) => {
85
85
  import { Stream as Stream2 } from "@dxos/codec-protobuf";
86
86
  import { Context } from "@dxos/context";
87
87
  import { PublicKey as PublicKey2 } from "@dxos/keys";
88
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devtools/network.ts";
88
89
  var subscribeToNetworkStatus = ({ signalManager }) => new Stream2(({ next, close }) => {
89
90
  const update = () => {
90
91
  try {
@@ -100,7 +101,10 @@ var subscribeToNetworkStatus = ({ signalManager }) => new Stream2(({ next, close
100
101
  update();
101
102
  });
102
103
  var subscribeToSignal = ({ signalManager }) => new Stream2(({ next }) => {
103
- const ctx = new Context();
104
+ const ctx = new Context(void 0, {
105
+ F: __dxlog_file,
106
+ L: 36
107
+ });
104
108
  signalManager.onMessage.on(ctx, (message) => {
105
109
  next({
106
110
  message: {
@@ -355,7 +359,7 @@ import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
355
359
  import { TRACE_PROCESSOR } from "@dxos/tracing";
356
360
 
357
361
  // packages/sdk/client-services/src/version.ts
358
- var DXOS_VERSION = "0.5.9-main.b06c86b";
362
+ var DXOS_VERSION = "0.5.9-main.b752d7f";
359
363
 
360
364
  // packages/sdk/client-services/src/packlets/services/platform.ts
361
365
  import { Platform } from "@dxos/protocols/proto/dxos/client/services";
@@ -388,7 +392,7 @@ var getPlatform = () => {
388
392
  };
389
393
 
390
394
  // packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts
391
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts";
395
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts";
392
396
  var DEFAULT_TIMEOUT = 1e3;
393
397
  var createDiagnostics = async (clientServices, serviceContext, config) => {
394
398
  const diagnostics = {
@@ -405,7 +409,7 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
405
409
  await Promise.all([
406
410
  (async () => {
407
411
  invariant(clientServices.LoggingService, "SystemService is not available.", {
408
- F: __dxlog_file,
412
+ F: __dxlog_file2,
409
413
  L: 110,
410
414
  S: void 0,
411
415
  A: [
@@ -510,7 +514,7 @@ var getStorageDiagnostics = async () => {
510
514
  // packages/sdk/client-services/src/packlets/diagnostics/browser-diagnostics-broadcast.ts
511
515
  import { Trigger } from "@dxos/async";
512
516
  import { log } from "@dxos/log";
513
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/browser-diagnostics-broadcast.ts";
517
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/browser-diagnostics-broadcast.ts";
514
518
  var CHANNEL_NAME = "dxos.diagnostics.broadcast";
515
519
  var MessageType;
516
520
  (function(MessageType2) {
@@ -579,7 +583,7 @@ var createCollectDiagnosticsBroadcastHandler = (systemService) => {
579
583
  }
580
584
  } catch (error) {
581
585
  log.catch(error, void 0, {
582
- F: __dxlog_file2,
586
+ F: __dxlog_file3,
583
587
  L: 77,
584
588
  S: void 0,
585
589
  C: (f, a) => f(...a)
@@ -687,7 +691,7 @@ import { Context as Context2 } from "@dxos/context";
687
691
  import { verifyCredential } from "@dxos/credentials";
688
692
  import { log as log2 } from "@dxos/log";
689
693
  import { schema } from "@dxos/protocols";
690
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/authenticator.ts";
694
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/authenticator.ts";
691
695
  var Credential = schema.getCodecForType("dxos.halo.credentials.Credential");
692
696
  var createAuthProvider = (signer) => async (nonce) => {
693
697
  const credential = await signer.createCredential({
@@ -702,7 +706,10 @@ var createAuthProvider = (signer) => async (nonce) => {
702
706
  var TrustedKeySetAuthVerifier = class {
703
707
  constructor(_params) {
704
708
  this._params = _params;
705
- this._ctx = new Context2();
709
+ this._ctx = new Context2(void 0, {
710
+ F: __dxlog_file4,
711
+ L: 45
712
+ });
706
713
  }
707
714
  async close() {
708
715
  await this._ctx.dispose();
@@ -713,7 +720,7 @@ var TrustedKeySetAuthVerifier = class {
713
720
  log2("authenticating...", {
714
721
  credential
715
722
  }, {
716
- F: __dxlog_file3,
723
+ F: __dxlog_file4,
717
724
  L: 56,
718
725
  S: this,
719
726
  C: (f, a) => f(...a)
@@ -723,7 +730,7 @@ var TrustedKeySetAuthVerifier = class {
723
730
  log2("Invalid credential", {
724
731
  result
725
732
  }, {
726
- F: __dxlog_file3,
733
+ F: __dxlog_file4,
727
734
  L: 60,
728
735
  S: this,
729
736
  C: (f, a) => f(...a)
@@ -735,7 +742,7 @@ var TrustedKeySetAuthVerifier = class {
735
742
  nonce,
736
743
  credential
737
744
  }, {
738
- F: __dxlog_file3,
745
+ F: __dxlog_file4,
739
746
  L: 65,
740
747
  S: this,
741
748
  C: (f, a) => f(...a)
@@ -746,7 +753,7 @@ var TrustedKeySetAuthVerifier = class {
746
753
  log2("key is not currently in trusted set, waiting...", {
747
754
  key: credential.issuer
748
755
  }, {
749
- F: __dxlog_file3,
756
+ F: __dxlog_file4,
750
757
  L: 70,
751
758
  S: this,
752
759
  C: (f, a) => f(...a)
@@ -762,7 +769,7 @@ var TrustedKeySetAuthVerifier = class {
762
769
  log2("auth success", {
763
770
  key: credential.issuer
764
771
  }, {
765
- F: __dxlog_file3,
772
+ F: __dxlog_file4,
766
773
  L: 81,
767
774
  S: this,
768
775
  C: (f, a) => f(...a)
@@ -772,7 +779,7 @@ var TrustedKeySetAuthVerifier = class {
772
779
  log2("key is not currently in trusted set, waiting...", {
773
780
  key: credential.issuer
774
781
  }, {
775
- F: __dxlog_file3,
782
+ F: __dxlog_file4,
776
783
  L: 84,
777
784
  S: this,
778
785
  C: (f, a) => f(...a)
@@ -813,7 +820,7 @@ import { ComplexSet } from "@dxos/util";
813
820
  import { getCredentialAssertion } from "@dxos/credentials";
814
821
  import { SpaceId } from "@dxos/keys";
815
822
  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";
823
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/default-space-state-machine.ts";
817
824
  var DefaultSpaceStateMachine = class {
818
825
  constructor(_params) {
819
826
  this._params = _params;
@@ -830,7 +837,7 @@ var DefaultSpaceStateMachine = class {
830
837
  expectedIdentity: this._params.identityKey,
831
838
  credential
832
839
  }, {
833
- F: __dxlog_file4,
840
+ F: __dxlog_file5,
834
841
  L: 32,
835
842
  S: this,
836
843
  C: (f, a) => f(...a)
@@ -841,7 +848,7 @@ var DefaultSpaceStateMachine = class {
841
848
  log3.warn("Invalid default space id", {
842
849
  id: assertion.spaceId
843
850
  }, {
844
- F: __dxlog_file4,
851
+ F: __dxlog_file5,
845
852
  L: 36,
846
853
  S: this,
847
854
  C: (f, a) => f(...a)
@@ -866,7 +873,7 @@ function _ts_decorate2(decorators, target, key, desc) {
866
873
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
867
874
  return c > 3 && r && Object.defineProperty(target, key, r), r;
868
875
  }
869
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity.ts";
876
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity.ts";
870
877
  var Identity = class {
871
878
  constructor({ space, signer, identityKey, deviceKey, presence }) {
872
879
  this.stateUpdate = new Event();
@@ -878,7 +885,7 @@ var Identity = class {
878
885
  log4.trace("dxos.halo.device", {
879
886
  deviceKey
880
887
  }, {
881
- F: __dxlog_file5,
888
+ F: __dxlog_file6,
882
889
  L: 70,
883
890
  S: this,
884
891
  C: (f, a) => f(...a)
@@ -957,7 +964,7 @@ var Identity = class {
957
964
  */
958
965
  getIdentityCredentialSigner() {
959
966
  invariant2(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.", {
960
- F: __dxlog_file5,
967
+ F: __dxlog_file6,
961
968
  L: 159,
962
969
  S: this,
963
970
  A: [
@@ -1001,7 +1008,7 @@ var Identity = class {
1001
1008
  controlFeedKey,
1002
1009
  dataFeedKey
1003
1010
  }, {
1004
- F: __dxlog_file5,
1011
+ F: __dxlog_file6,
1005
1012
  L: 184,
1006
1013
  S: this,
1007
1014
  C: (f, a) => f(...a)
@@ -1078,7 +1085,7 @@ function _ts_decorate3(decorators, target, key, desc) {
1078
1085
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1079
1086
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1080
1087
  }
1081
- var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-manager.ts";
1088
+ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-manager.ts";
1082
1089
  var DEVICE_PRESENCE_ANNOUNCE_INTERVAL = 1e4;
1083
1090
  var DEVICE_PRESENCE_OFFLINE_TIMEOUT = 2e4;
1084
1091
  var IdentityManager = class {
@@ -1102,7 +1109,7 @@ var IdentityManager = class {
1102
1109
  log5.trace("dxos.halo.identity-manager.open", trace3.begin({
1103
1110
  id: traceId
1104
1111
  }), {
1105
- F: __dxlog_file6,
1112
+ F: __dxlog_file7,
1106
1113
  L: 104,
1107
1114
  S: this,
1108
1115
  C: (f, a) => f(...a)
@@ -1111,7 +1118,7 @@ var IdentityManager = class {
1111
1118
  log5("identity record", {
1112
1119
  identityRecord
1113
1120
  }, {
1114
- F: __dxlog_file6,
1121
+ F: __dxlog_file7,
1115
1122
  L: 107,
1116
1123
  S: this,
1117
1124
  C: (f, a) => f(...a)
@@ -1124,7 +1131,7 @@ var IdentityManager = class {
1124
1131
  identityKey: identityRecord.identityKey,
1125
1132
  displayName: this._identity.profileDocument?.displayName
1126
1133
  }, {
1127
- F: __dxlog_file6,
1134
+ F: __dxlog_file7,
1128
1135
  L: 112,
1129
1136
  S: this,
1130
1137
  C: (f, a) => f(...a)
@@ -1134,18 +1141,21 @@ var IdentityManager = class {
1134
1141
  log5.trace("dxos.halo.identity-manager.open", trace3.end({
1135
1142
  id: traceId
1136
1143
  }), {
1137
- F: __dxlog_file6,
1144
+ F: __dxlog_file7,
1138
1145
  L: 119,
1139
1146
  S: this,
1140
1147
  C: (f, a) => f(...a)
1141
1148
  });
1142
1149
  }
1143
1150
  async close() {
1144
- await this._identity?.close(new Context3());
1151
+ await this._identity?.close(new Context3(void 0, {
1152
+ F: __dxlog_file7,
1153
+ L: 123
1154
+ }));
1145
1155
  }
1146
1156
  async createIdentity({ displayName, deviceProfile } = {}) {
1147
1157
  invariant3(!this._identity, "Identity already exists.", {
1148
- F: __dxlog_file6,
1158
+ F: __dxlog_file7,
1149
1159
  L: 128,
1150
1160
  S: this,
1151
1161
  A: [
@@ -1154,7 +1164,7 @@ var IdentityManager = class {
1154
1164
  ]
1155
1165
  });
1156
1166
  log5("creating identity...", void 0, {
1157
- F: __dxlog_file6,
1167
+ F: __dxlog_file7,
1158
1168
  L: 129,
1159
1169
  S: this,
1160
1170
  C: (f, a) => f(...a)
@@ -1171,11 +1181,14 @@ var IdentityManager = class {
1171
1181
  }
1172
1182
  };
1173
1183
  const identity = await this._constructIdentity(identityRecord);
1174
- await identity.open(new Context3());
1184
+ await identity.open(new Context3(void 0, {
1185
+ F: __dxlog_file7,
1186
+ L: 144
1187
+ }));
1175
1188
  {
1176
1189
  const generator = new CredentialGenerator(this._keyring, identityRecord.identityKey, identityRecord.deviceKey);
1177
1190
  invariant3(identityRecord.haloSpace.genesisFeedKey, "Genesis feed key is required.", {
1178
- F: __dxlog_file6,
1191
+ F: __dxlog_file7,
1179
1192
  L: 148,
1180
1193
  S: this,
1181
1194
  A: [
@@ -1184,7 +1197,7 @@ var IdentityManager = class {
1184
1197
  ]
1185
1198
  });
1186
1199
  invariant3(identityRecord.haloSpace.dataFeedKey, "Data feed key is required.", {
1187
- F: __dxlog_file6,
1200
+ F: __dxlog_file7,
1188
1201
  L: 149,
1189
1202
  S: this,
1190
1203
  A: [
@@ -1223,7 +1236,7 @@ var IdentityManager = class {
1223
1236
  identityKey: identityRecord.identityKey,
1224
1237
  displayName: this._identity.profileDocument?.displayName
1225
1238
  }, {
1226
- F: __dxlog_file6,
1239
+ F: __dxlog_file7,
1227
1240
  L: 191,
1228
1241
  S: this,
1229
1242
  C: (f, a) => f(...a)
@@ -1234,7 +1247,7 @@ var IdentityManager = class {
1234
1247
  deviceKey: identity.deviceKey,
1235
1248
  profile: identity.profileDocument
1236
1249
  }, {
1237
- F: __dxlog_file6,
1250
+ F: __dxlog_file7,
1238
1251
  L: 197,
1239
1252
  S: this,
1240
1253
  C: (f, a) => f(...a)
@@ -1271,13 +1284,13 @@ var IdentityManager = class {
1271
1284
  log5("accepting identity", {
1272
1285
  params
1273
1286
  }, {
1274
- F: __dxlog_file6,
1287
+ F: __dxlog_file7,
1275
1288
  L: 235,
1276
1289
  S: this,
1277
1290
  C: (f, a) => f(...a)
1278
1291
  });
1279
1292
  invariant3(!this._identity, "Identity already exists.", {
1280
- F: __dxlog_file6,
1293
+ F: __dxlog_file7,
1281
1294
  L: 236,
1282
1295
  S: this,
1283
1296
  A: [
@@ -1297,7 +1310,10 @@ var IdentityManager = class {
1297
1310
  }
1298
1311
  };
1299
1312
  const identity = await this._constructIdentity(identityRecord);
1300
- await identity.open(new Context3());
1313
+ await identity.open(new Context3(void 0, {
1314
+ F: __dxlog_file7,
1315
+ L: 251
1316
+ }));
1301
1317
  this._identity = identity;
1302
1318
  await this._metadataStore.setIdentityRecord(identityRecord);
1303
1319
  await this._identity.ready();
@@ -1305,7 +1321,7 @@ var IdentityManager = class {
1305
1321
  identityKey: identityRecord.identityKey,
1306
1322
  displayName: this._identity.profileDocument?.displayName
1307
1323
  }, {
1308
- F: __dxlog_file6,
1324
+ F: __dxlog_file7,
1309
1325
  L: 255,
1310
1326
  S: this,
1311
1327
  C: (f, a) => f(...a)
@@ -1319,7 +1335,7 @@ var IdentityManager = class {
1319
1335
  identityKey: identity.identityKey,
1320
1336
  deviceKey: identity.deviceKey
1321
1337
  }, {
1322
- F: __dxlog_file6,
1338
+ F: __dxlog_file7,
1323
1339
  L: 265,
1324
1340
  S: this,
1325
1341
  C: (f, a) => f(...a)
@@ -1331,7 +1347,7 @@ var IdentityManager = class {
1331
1347
  */
1332
1348
  async updateProfile(profile) {
1333
1349
  invariant3(this._identity, "Identity not initialized.", {
1334
- F: __dxlog_file6,
1350
+ F: __dxlog_file7,
1335
1351
  L: 273,
1336
1352
  S: this,
1337
1353
  A: [
@@ -1362,7 +1378,7 @@ var IdentityManager = class {
1362
1378
  }
1363
1379
  async updateDeviceProfile(profile) {
1364
1380
  invariant3(this._identity, "Identity not initialized.", {
1365
- F: __dxlog_file6,
1381
+ F: __dxlog_file7,
1366
1382
  L: 290,
1367
1383
  S: this,
1368
1384
  A: [
@@ -1398,7 +1414,7 @@ var IdentityManager = class {
1398
1414
  }
1399
1415
  async _constructIdentity(identityRecord) {
1400
1416
  invariant3(!this._identity, void 0, {
1401
- F: __dxlog_file6,
1417
+ F: __dxlog_file7,
1402
1418
  L: 316,
1403
1419
  S: this,
1404
1420
  A: [
@@ -1409,7 +1425,7 @@ var IdentityManager = class {
1409
1425
  log5("constructing identity", {
1410
1426
  identityRecord
1411
1427
  }, {
1412
- F: __dxlog_file6,
1428
+ F: __dxlog_file7,
1413
1429
  L: 317,
1414
1430
  S: this,
1415
1431
  C: (f, a) => f(...a)
@@ -1424,7 +1440,7 @@ var IdentityManager = class {
1424
1440
  gossip
1425
1441
  });
1426
1442
  invariant3(identityRecord.haloSpace.controlFeedKey, void 0, {
1427
- F: __dxlog_file6,
1443
+ F: __dxlog_file7,
1428
1444
  L: 330,
1429
1445
  S: this,
1430
1446
  A: [
@@ -1436,7 +1452,7 @@ var IdentityManager = class {
1436
1452
  writable: true
1437
1453
  });
1438
1454
  invariant3(identityRecord.haloSpace.dataFeedKey, void 0, {
1439
- F: __dxlog_file6,
1455
+ F: __dxlog_file7,
1440
1456
  L: 334,
1441
1457
  S: this,
1442
1458
  A: [
@@ -1470,7 +1486,7 @@ var IdentityManager = class {
1470
1486
  log5("done", {
1471
1487
  identityKey: identityRecord.identityKey
1472
1488
  }, {
1473
- F: __dxlog_file6,
1489
+ F: __dxlog_file7,
1474
1490
  L: 360,
1475
1491
  S: this,
1476
1492
  C: (f, a) => f(...a)
@@ -1495,7 +1511,7 @@ var IdentityManager = class {
1495
1511
  },
1496
1512
  onAuthFailure: () => {
1497
1513
  log5.warn("auth failure", void 0, {
1498
- F: __dxlog_file6,
1514
+ F: __dxlog_file7,
1499
1515
  L: 385,
1500
1516
  S: this,
1501
1517
  C: (f, a) => f(...a)
@@ -1528,7 +1544,7 @@ import { invariant as invariant4 } from "@dxos/invariant";
1528
1544
  import { log as log6 } from "@dxos/log";
1529
1545
  import { SpaceState } from "@dxos/protocols/proto/dxos/client/services";
1530
1546
  import { safeAwaitAll } from "@dxos/util";
1531
- var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
1547
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
1532
1548
  var DEFAULT_SPACE_SEARCH_TIMEOUT = 1e4;
1533
1549
  var IdentityServiceImpl = class extends Resource {
1534
1550
  constructor(_identityManager, _keyring, _dataSpaceManagerProvider, _createIdentity, _onProfileUpdate) {
@@ -1558,7 +1574,7 @@ var IdentityServiceImpl = class extends Resource {
1558
1574
  const space = await dataSpaceManager.createDefaultSpace();
1559
1575
  const identity = this._identityManager.identity;
1560
1576
  invariant4(identity, void 0, {
1561
- F: __dxlog_file7,
1577
+ F: __dxlog_file8,
1562
1578
  L: 59,
1563
1579
  S: this,
1564
1580
  A: [
@@ -1592,7 +1608,7 @@ var IdentityServiceImpl = class extends Resource {
1592
1608
  }
1593
1609
  async updateProfile(profile) {
1594
1610
  invariant4(this._identityManager.identity, "Identity not initialized.", {
1595
- F: __dxlog_file7,
1611
+ F: __dxlog_file8,
1596
1612
  L: 89,
1597
1613
  S: this,
1598
1614
  A: [
@@ -1606,7 +1622,7 @@ var IdentityServiceImpl = class extends Resource {
1606
1622
  }
1607
1623
  async signPresentation({ presentation, nonce }) {
1608
1624
  invariant4(this._identityManager.identity, "Identity not initialized.", {
1609
- F: __dxlog_file7,
1625
+ F: __dxlog_file8,
1610
1626
  L: 96,
1611
1627
  S: this,
1612
1628
  A: [
@@ -1641,8 +1657,8 @@ var IdentityServiceImpl = class extends Resource {
1641
1657
  log6.warn("Multiple default spaces found. Using the first one.", {
1642
1658
  duplicate: space.id
1643
1659
  }, {
1644
- F: __dxlog_file7,
1645
- L: 127,
1660
+ F: __dxlog_file8,
1661
+ L: 129,
1646
1662
  S: this,
1647
1663
  C: (f, a) => f(...a)
1648
1664
  });
@@ -1653,6 +1669,13 @@ var IdentityServiceImpl = class extends Resource {
1653
1669
  recodedDefaultSpace = true;
1654
1670
  recordedDefaultSpaceTrigger.wake();
1655
1671
  }
1672
+ }, (err) => {
1673
+ log6.catch(err, void 0, {
1674
+ F: __dxlog_file8,
1675
+ L: 140,
1676
+ S: this,
1677
+ C: (f, a) => f(...a)
1678
+ });
1656
1679
  });
1657
1680
  await Promise.race([
1658
1681
  allProcessed,
@@ -1669,7 +1692,7 @@ var IdentityServiceImpl = class extends Resource {
1669
1692
  import { invariant as invariant5 } from "@dxos/invariant";
1670
1693
  import { AlreadyJoinedError } from "@dxos/protocols";
1671
1694
  import { Invitation } from "@dxos/protocols/proto/dxos/client/services";
1672
- var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts";
1695
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts";
1673
1696
  var DeviceInvitationProtocol = class {
1674
1697
  constructor(_keyring, _getIdentity, _acceptIdentity) {
1675
1698
  this._keyring = _keyring;
@@ -1695,7 +1718,7 @@ var DeviceInvitationProtocol = class {
1695
1718
  }
1696
1719
  async admit(_, request) {
1697
1720
  invariant5(request.device, void 0, {
1698
- F: __dxlog_file8,
1721
+ F: __dxlog_file9,
1699
1722
  L: 50,
1700
1723
  S: this,
1701
1724
  A: [
@@ -1741,7 +1764,7 @@ var DeviceInvitationProtocol = class {
1741
1764
  }
1742
1765
  async accept(response, request) {
1743
1766
  invariant5(response.device, void 0, {
1744
- F: __dxlog_file8,
1767
+ F: __dxlog_file9,
1745
1768
  L: 95,
1746
1769
  S: this,
1747
1770
  A: [
@@ -1751,7 +1774,7 @@ var DeviceInvitationProtocol = class {
1751
1774
  });
1752
1775
  const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
1753
1776
  invariant5(request.device, void 0, {
1754
- F: __dxlog_file8,
1777
+ F: __dxlog_file9,
1755
1778
  L: 98,
1756
1779
  S: this,
1757
1780
  A: [
@@ -1820,7 +1843,7 @@ var tryAcquireBeforeContextDisposed = async (ctx, mutex) => {
1820
1843
  };
1821
1844
 
1822
1845
  // 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";
1846
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts";
1824
1847
  var OPTIONS_TIMEOUT = 1e4;
1825
1848
  var InvitationGuestExtension = class extends RpcExtension {
1826
1849
  constructor(_invitationFlowMutex, _callbacks) {
@@ -1834,7 +1857,10 @@ var InvitationGuestExtension = class extends RpcExtension {
1834
1857
  });
1835
1858
  this._invitationFlowMutex = _invitationFlowMutex;
1836
1859
  this._callbacks = _callbacks;
1837
- this._ctx = new Context4();
1860
+ this._ctx = new Context4(void 0, {
1861
+ F: __dxlog_file10,
1862
+ L: 33
1863
+ });
1838
1864
  this._remoteOptionsTrigger = new Trigger4();
1839
1865
  this._invitationFlowLock = null;
1840
1866
  }
@@ -1846,7 +1872,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1846
1872
  InvitationHostService: {
1847
1873
  options: async (options) => {
1848
1874
  invariant6(!this._remoteOptions, "Remote options already set.", {
1849
- F: __dxlog_file9,
1875
+ F: __dxlog_file10,
1850
1876
  L: 63,
1851
1877
  S: this,
1852
1878
  A: [
@@ -1873,14 +1899,14 @@ var InvitationGuestExtension = class extends RpcExtension {
1873
1899
  await super.onOpen(context);
1874
1900
  try {
1875
1901
  log7("guest acquire lock", void 0, {
1876
- F: __dxlog_file9,
1902
+ F: __dxlog_file10,
1877
1903
  L: 84,
1878
1904
  S: this,
1879
1905
  C: (f, a) => f(...a)
1880
1906
  });
1881
1907
  this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
1882
1908
  log7("guest lock acquired", void 0, {
1883
- F: __dxlog_file9,
1909
+ F: __dxlog_file10,
1884
1910
  L: 86,
1885
1911
  S: this,
1886
1912
  C: (f, a) => f(...a)
@@ -1889,7 +1915,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1889
1915
  role: Options.Role.GUEST
1890
1916
  }));
1891
1917
  log7("options sent", void 0, {
1892
- F: __dxlog_file9,
1918
+ F: __dxlog_file10,
1893
1919
  L: 88,
1894
1920
  S: this,
1895
1921
  C: (f, a) => f(...a)
@@ -1898,7 +1924,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1898
1924
  timeout: OPTIONS_TIMEOUT
1899
1925
  }));
1900
1926
  log7("options received", void 0, {
1901
- F: __dxlog_file9,
1927
+ F: __dxlog_file10,
1902
1928
  L: 90,
1903
1929
  S: this,
1904
1930
  C: (f, a) => f(...a)
@@ -1932,7 +1958,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1932
1958
  this._invitationFlowLock.release();
1933
1959
  this._invitationFlowLock = null;
1934
1960
  log7("invitation flow lock released", void 0, {
1935
- F: __dxlog_file9,
1961
+ F: __dxlog_file10,
1936
1962
  L: 123,
1937
1963
  S: this,
1938
1964
  C: (f, a) => f(...a)
@@ -1952,7 +1978,7 @@ import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleEr
1952
1978
  import { Invitation as Invitation3 } from "@dxos/protocols/proto/dxos/client/services";
1953
1979
  import { AuthenticationResponse, Options as Options2 } from "@dxos/protocols/proto/dxos/halo/invitations";
1954
1980
  import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
1955
- var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts";
1981
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts";
1956
1982
  var OPTIONS_TIMEOUT2 = 1e4;
1957
1983
  var MAX_OTP_ATTEMPTS = 3;
1958
1984
  var InvitationHostExtension = class extends RpcExtension2 {
@@ -1967,7 +1993,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
1967
1993
  });
1968
1994
  this._invitationFlowMutex = _invitationFlowMutex;
1969
1995
  this._callbacks = _callbacks;
1970
- this._ctx = new Context5();
1996
+ this._ctx = new Context5(void 0, {
1997
+ F: __dxlog_file11,
1998
+ L: 52
1999
+ });
1971
2000
  this._remoteOptionsTrigger = new Trigger5();
1972
2001
  this._challenge = void 0;
1973
2002
  this.guestProfile = void 0;
@@ -1986,7 +2015,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
1986
2015
  InvitationHostService: {
1987
2016
  options: async (options) => {
1988
2017
  invariant7(!this._remoteOptions, "Remote options already set.", {
1989
- F: __dxlog_file10,
2018
+ F: __dxlog_file11,
1990
2019
  L: 101,
1991
2020
  S: this,
1992
2021
  A: [
@@ -2003,7 +2032,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
2003
2032
  log8.trace("dxos.sdk.invitation-handler.host.introduce", trace4.begin({
2004
2033
  id: traceId
2005
2034
  }), {
2006
- F: __dxlog_file10,
2035
+ F: __dxlog_file11,
2007
2036
  L: 110,
2008
2037
  S: this,
2009
2038
  C: (f, a) => f(...a)
@@ -2015,7 +2044,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
2015
2044
  expected: invitation.invitationId,
2016
2045
  actual: invitationId
2017
2046
  }, {
2018
- F: __dxlog_file10,
2047
+ F: __dxlog_file11,
2019
2048
  L: 116,
2020
2049
  S: this,
2021
2050
  C: (f, a) => f(...a)
@@ -2029,7 +2058,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
2029
2058
  log8("guest introduced themselves", {
2030
2059
  guestProfile: profile
2031
2060
  }, {
2032
- F: __dxlog_file10,
2061
+ F: __dxlog_file11,
2033
2062
  L: 125,
2034
2063
  S: this,
2035
2064
  C: (f, a) => f(...a)
@@ -2040,7 +2069,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
2040
2069
  log8.trace("dxos.sdk.invitation-handler.host.introduce", trace4.end({
2041
2070
  id: traceId
2042
2071
  }), {
2043
- F: __dxlog_file10,
2072
+ F: __dxlog_file11,
2044
2073
  L: 132,
2045
2074
  S: this,
2046
2075
  C: (f, a) => f(...a)
@@ -2055,7 +2084,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
2055
2084
  log8.trace("dxos.sdk.invitation-handler.host.authenticate", trace4.begin({
2056
2085
  id: traceId
2057
2086
  }), {
2058
- F: __dxlog_file10,
2087
+ F: __dxlog_file11,
2059
2088
  L: 141,
2060
2089
  S: this,
2061
2090
  C: (f, a) => f(...a)
@@ -2064,7 +2093,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
2064
2093
  log8("received authentication request", {
2065
2094
  authCode: code
2066
2095
  }, {
2067
- F: __dxlog_file10,
2096
+ F: __dxlog_file11,
2068
2097
  L: 144,
2069
2098
  S: this,
2070
2099
  C: (f, a) => f(...a)
@@ -2078,7 +2107,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
2078
2107
  switch (invitation.authMethod) {
2079
2108
  case Invitation3.AuthMethod.NONE: {
2080
2109
  log8("authentication not required", void 0, {
2081
- F: __dxlog_file10,
2110
+ F: __dxlog_file11,
2082
2111
  L: 152,
2083
2112
  S: this,
2084
2113
  C: (f, a) => f(...a)
@@ -2116,7 +2145,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
2116
2145
  log8.error("invalid authentication method", {
2117
2146
  authMethod: invitation.authMethod
2118
2147
  }, {
2119
- F: __dxlog_file10,
2148
+ F: __dxlog_file11,
2120
2149
  L: 190,
2121
2150
  S: this,
2122
2151
  C: (f, a) => f(...a)
@@ -2141,7 +2170,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
2141
2170
  status
2142
2171
  }
2143
2172
  }), {
2144
- F: __dxlog_file10,
2173
+ F: __dxlog_file11,
2145
2174
  L: 202,
2146
2175
  S: this,
2147
2176
  C: (f, a) => f(...a)
@@ -2155,7 +2184,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
2155
2184
  log8.trace("dxos.sdk.invitation-handler.host.admit", trace4.begin({
2156
2185
  id: traceId
2157
2186
  }), {
2158
- F: __dxlog_file10,
2187
+ F: __dxlog_file11,
2159
2188
  L: 208,
2160
2189
  S: this,
2161
2190
  C: (f, a) => f(...a)
@@ -2172,7 +2201,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
2172
2201
  log8.trace("dxos.sdk.invitation-handler.host.admit", trace4.end({
2173
2202
  id: traceId
2174
2203
  }), {
2175
- F: __dxlog_file10,
2204
+ F: __dxlog_file11,
2176
2205
  L: 222,
2177
2206
  S: this,
2178
2207
  C: (f, a) => f(...a)
@@ -2190,14 +2219,14 @@ var InvitationHostExtension = class extends RpcExtension2 {
2190
2219
  await super.onOpen(context);
2191
2220
  try {
2192
2221
  log8("host acquire lock", void 0, {
2193
- F: __dxlog_file10,
2222
+ F: __dxlog_file11,
2194
2223
  L: 237,
2195
2224
  S: this,
2196
2225
  C: (f, a) => f(...a)
2197
2226
  });
2198
2227
  this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
2199
2228
  log8("host lock acquired", void 0, {
2200
- F: __dxlog_file10,
2229
+ F: __dxlog_file11,
2201
2230
  L: 239,
2202
2231
  S: this,
2203
2232
  C: (f, a) => f(...a)
@@ -2208,7 +2237,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
2208
2237
  role: Options2.Role.HOST
2209
2238
  });
2210
2239
  log8("options sent", void 0, {
2211
- F: __dxlog_file10,
2240
+ F: __dxlog_file11,
2212
2241
  L: 243,
2213
2242
  S: this,
2214
2243
  C: (f, a) => f(...a)
@@ -2217,7 +2246,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
2217
2246
  timeout: OPTIONS_TIMEOUT2
2218
2247
  }));
2219
2248
  log8("options received", void 0, {
2220
- F: __dxlog_file10,
2249
+ F: __dxlog_file11,
2221
2250
  L: 245,
2222
2251
  S: this,
2223
2252
  C: (f, a) => f(...a)
@@ -2271,7 +2300,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
2271
2300
  this._invitationFlowLock?.release();
2272
2301
  this._invitationFlowLock = null;
2273
2302
  log8("invitation flow lock released", void 0, {
2274
- F: __dxlog_file10,
2303
+ F: __dxlog_file11,
2275
2304
  L: 300,
2276
2305
  S: this,
2277
2306
  C: (f, a) => f(...a)
@@ -2287,7 +2316,7 @@ import { PublicKey as PublicKey6 } from "@dxos/keys";
2287
2316
  import { log as log9 } from "@dxos/log";
2288
2317
  import { Options as Options3 } from "@dxos/protocols/proto/dxos/halo/invitations";
2289
2318
  import { ComplexSet as ComplexSet2 } from "@dxos/util";
2290
- var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts";
2319
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts";
2291
2320
  var InvitationTopology = class {
2292
2321
  constructor(_role) {
2293
2322
  this._role = _role;
@@ -2295,7 +2324,7 @@ var InvitationTopology = class {
2295
2324
  }
2296
2325
  init(controller) {
2297
2326
  invariant8(!this._controller, "Already initialized.", {
2298
- F: __dxlog_file11,
2327
+ F: __dxlog_file12,
2299
2328
  L: 42,
2300
2329
  S: this,
2301
2330
  A: [
@@ -2307,7 +2336,7 @@ var InvitationTopology = class {
2307
2336
  }
2308
2337
  update() {
2309
2338
  invariant8(this._controller, "Not initialized.", {
2310
- F: __dxlog_file11,
2339
+ F: __dxlog_file12,
2311
2340
  L: 47,
2312
2341
  S: this,
2313
2342
  A: [
@@ -2330,7 +2359,7 @@ var InvitationTopology = class {
2330
2359
  ownPeerId,
2331
2360
  remotePeerId: firstUnknownPeer
2332
2361
  }, {
2333
- F: __dxlog_file11,
2362
+ F: __dxlog_file12,
2334
2363
  L: 69,
2335
2364
  S: this,
2336
2365
  C: (f, a) => f(...a)
@@ -2341,7 +2370,7 @@ var InvitationTopology = class {
2341
2370
  }
2342
2371
  async onOffer(peer) {
2343
2372
  invariant8(this._controller, "Not initialized.", {
2344
- F: __dxlog_file11,
2373
+ F: __dxlog_file12,
2345
2374
  L: 76,
2346
2375
  S: this,
2347
2376
  A: [
@@ -2360,7 +2389,7 @@ var InvitationTopology = class {
2360
2389
  };
2361
2390
 
2362
2391
  // 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";
2392
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts";
2364
2393
  var MAX_DELEGATED_INVITATION_HOST_TRIES = 3;
2365
2394
  var InvitationsHandler = class {
2366
2395
  /**
@@ -2385,7 +2414,7 @@ var InvitationsHandler = class {
2385
2414
  try {
2386
2415
  const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
2387
2416
  invariant9(deviceKey, void 0, {
2388
- F: __dxlog_file12,
2417
+ F: __dxlog_file13,
2389
2418
  L: 90,
2390
2419
  S: this,
2391
2420
  A: [
@@ -2414,7 +2443,7 @@ var InvitationsHandler = class {
2414
2443
  log10.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.begin({
2415
2444
  id: traceId
2416
2445
  }), {
2417
- F: __dxlog_file12,
2446
+ F: __dxlog_file13,
2418
2447
  L: 115,
2419
2448
  S: this,
2420
2449
  C: (f, a) => f(...a)
@@ -2422,7 +2451,7 @@ var InvitationsHandler = class {
2422
2451
  log10("connected", {
2423
2452
  ...protocol.toJSON()
2424
2453
  }, {
2425
- F: __dxlog_file12,
2454
+ F: __dxlog_file13,
2426
2455
  L: 116,
2427
2456
  S: this,
2428
2457
  C: (f, a) => f(...a)
@@ -2434,7 +2463,7 @@ var InvitationsHandler = class {
2434
2463
  guest: deviceKey,
2435
2464
  ...protocol.toJSON()
2436
2465
  }, {
2437
- F: __dxlog_file12,
2466
+ F: __dxlog_file13,
2438
2467
  L: 118,
2439
2468
  S: this,
2440
2469
  C: (f, a) => f(...a)
@@ -2443,7 +2472,7 @@ var InvitationsHandler = class {
2443
2472
  log10.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.end({
2444
2473
  id: traceId
2445
2474
  }), {
2446
- F: __dxlog_file12,
2475
+ F: __dxlog_file13,
2447
2476
  L: 120,
2448
2477
  S: this,
2449
2478
  C: (f, a) => f(...a)
@@ -2458,7 +2487,7 @@ var InvitationsHandler = class {
2458
2487
  log10("timeout", {
2459
2488
  ...protocol.toJSON()
2460
2489
  }, {
2461
- F: __dxlog_file12,
2490
+ F: __dxlog_file13,
2462
2491
  L: 129,
2463
2492
  S: this,
2464
2493
  C: (f, a) => f(...a)
@@ -2467,7 +2496,7 @@ var InvitationsHandler = class {
2467
2496
  } else {
2468
2497
  if (guardedState.error(extension, err)) {
2469
2498
  log10.error("failed", err, {
2470
- F: __dxlog_file12,
2499
+ F: __dxlog_file13,
2471
2500
  L: 133,
2472
2501
  S: this,
2473
2502
  C: (f, a) => f(...a)
@@ -2478,7 +2507,7 @@ var InvitationsHandler = class {
2478
2507
  id: traceId,
2479
2508
  error: err
2480
2509
  }), {
2481
- F: __dxlog_file12,
2510
+ F: __dxlog_file13,
2482
2511
  L: 136,
2483
2512
  S: this,
2484
2513
  C: (f, a) => f(...a)
@@ -2492,7 +2521,7 @@ var InvitationsHandler = class {
2492
2521
  log10("invalid role", {
2493
2522
  ...err.context
2494
2523
  }, {
2495
- F: __dxlog_file12,
2524
+ F: __dxlog_file13,
2496
2525
  L: 144,
2497
2526
  S: this,
2498
2527
  C: (f, a) => f(...a)
@@ -2504,7 +2533,7 @@ var InvitationsHandler = class {
2504
2533
  log10("timeout", {
2505
2534
  err
2506
2535
  }, {
2507
- F: __dxlog_file12,
2536
+ F: __dxlog_file13,
2508
2537
  L: 149,
2509
2538
  S: this,
2510
2539
  C: (f, a) => f(...a)
@@ -2513,7 +2542,7 @@ var InvitationsHandler = class {
2513
2542
  } else {
2514
2543
  if (guardedState.error(extension, err)) {
2515
2544
  log10.error("failed", err, {
2516
- F: __dxlog_file12,
2545
+ F: __dxlog_file13,
2517
2546
  L: 153,
2518
2547
  S: this,
2519
2548
  C: (f, a) => f(...a)
@@ -2527,7 +2556,7 @@ var InvitationsHandler = class {
2527
2556
  if (invitation.lifetime && invitation.created) {
2528
2557
  if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
2529
2558
  log10.warn("invitation has already expired", void 0, {
2530
- F: __dxlog_file12,
2559
+ F: __dxlog_file13,
2531
2560
  L: 164,
2532
2561
  S: this,
2533
2562
  C: (f, a) => f(...a)
@@ -2550,7 +2579,7 @@ var InvitationsHandler = class {
2550
2579
  const { timeout = INVITATION_TIMEOUT } = invitation;
2551
2580
  if (deviceProfile) {
2552
2581
  invariant9(invitation.kind === Invitation4.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
2553
- F: __dxlog_file12,
2582
+ F: __dxlog_file13,
2554
2583
  L: 197,
2555
2584
  S: this,
2556
2585
  A: [
@@ -2568,7 +2597,7 @@ var InvitationsHandler = class {
2568
2597
  invitationType: Invitation4.Type.DELEGATED,
2569
2598
  triedPeers: triedPeersIds.size
2570
2599
  }, {
2571
- F: __dxlog_file12,
2600
+ F: __dxlog_file13,
2572
2601
  L: 205,
2573
2602
  S: this,
2574
2603
  C: (f, a) => f(...a)
@@ -2595,7 +2624,7 @@ var InvitationsHandler = class {
2595
2624
  admitted,
2596
2625
  currentState: guardedState.current.state
2597
2626
  }, {
2598
- F: __dxlog_file12,
2627
+ F: __dxlog_file13,
2599
2628
  L: 233,
2600
2629
  S: this,
2601
2630
  C: (f, a) => f(...a)
@@ -2613,7 +2642,7 @@ var InvitationsHandler = class {
2613
2642
  log10.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.begin({
2614
2643
  id: traceId
2615
2644
  }), {
2616
- F: __dxlog_file12,
2645
+ F: __dxlog_file13,
2617
2646
  L: 245,
2618
2647
  S: this,
2619
2648
  C: (f, a) => f(...a)
@@ -2625,7 +2654,7 @@ var InvitationsHandler = class {
2625
2654
  log10("connected", {
2626
2655
  ...protocol.toJSON()
2627
2656
  }, {
2628
- F: __dxlog_file12,
2657
+ F: __dxlog_file13,
2629
2658
  L: 256,
2630
2659
  S: this,
2631
2660
  C: (f, a) => f(...a)
@@ -2634,7 +2663,7 @@ var InvitationsHandler = class {
2634
2663
  log10("introduce", {
2635
2664
  ...protocol.toJSON()
2636
2665
  }, {
2637
- F: __dxlog_file12,
2666
+ F: __dxlog_file13,
2638
2667
  L: 260,
2639
2668
  S: this,
2640
2669
  C: (f, a) => f(...a)
@@ -2647,7 +2676,7 @@ var InvitationsHandler = class {
2647
2676
  ...protocol.toJSON(),
2648
2677
  response: introductionResponse
2649
2678
  }, {
2650
- F: __dxlog_file12,
2679
+ F: __dxlog_file13,
2651
2680
  L: 265,
2652
2681
  S: this,
2653
2682
  C: (f, a) => f(...a)
@@ -2668,7 +2697,7 @@ var InvitationsHandler = class {
2668
2697
  log10("request admission", {
2669
2698
  ...protocol.toJSON()
2670
2699
  }, {
2671
- F: __dxlog_file12,
2700
+ F: __dxlog_file13,
2672
2701
  L: 291,
2673
2702
  S: this,
2674
2703
  C: (f, a) => f(...a)
@@ -2680,7 +2709,7 @@ var InvitationsHandler = class {
2680
2709
  log10("admitted by host", {
2681
2710
  ...protocol.toJSON()
2682
2711
  }, {
2683
- F: __dxlog_file12,
2712
+ F: __dxlog_file13,
2684
2713
  L: 302,
2685
2714
  S: this,
2686
2715
  C: (f, a) => f(...a)
@@ -2693,7 +2722,7 @@ var InvitationsHandler = class {
2693
2722
  log10.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.end({
2694
2723
  id: traceId
2695
2724
  }), {
2696
- F: __dxlog_file12,
2725
+ F: __dxlog_file13,
2697
2726
  L: 308,
2698
2727
  S: this,
2699
2728
  C: (f, a) => f(...a)
@@ -2703,7 +2732,7 @@ var InvitationsHandler = class {
2703
2732
  log10("timeout", {
2704
2733
  ...protocol.toJSON()
2705
2734
  }, {
2706
- F: __dxlog_file12,
2735
+ F: __dxlog_file13,
2707
2736
  L: 311,
2708
2737
  S: this,
2709
2738
  C: (f, a) => f(...a)
@@ -2711,7 +2740,7 @@ var InvitationsHandler = class {
2711
2740
  guardedState.set(extension, Invitation4.State.TIMEOUT);
2712
2741
  } else {
2713
2742
  log10("auth failed", err, {
2714
- F: __dxlog_file12,
2743
+ F: __dxlog_file13,
2715
2744
  L: 314,
2716
2745
  S: this,
2717
2746
  C: (f, a) => f(...a)
@@ -2723,7 +2752,7 @@ var InvitationsHandler = class {
2723
2752
  id: traceId,
2724
2753
  error: err
2725
2754
  }), {
2726
- F: __dxlog_file12,
2755
+ F: __dxlog_file13,
2727
2756
  L: 318,
2728
2757
  S: this,
2729
2758
  C: (f, a) => f(...a)
@@ -2739,7 +2768,7 @@ var InvitationsHandler = class {
2739
2768
  log10("timeout", {
2740
2769
  ...protocol.toJSON()
2741
2770
  }, {
2742
- F: __dxlog_file12,
2771
+ F: __dxlog_file13,
2743
2772
  L: 327,
2744
2773
  S: this,
2745
2774
  C: (f, a) => f(...a)
@@ -2747,7 +2776,7 @@ var InvitationsHandler = class {
2747
2776
  guardedState.set(extension, Invitation4.State.TIMEOUT);
2748
2777
  } else {
2749
2778
  log10("auth failed", err, {
2750
- F: __dxlog_file12,
2779
+ F: __dxlog_file13,
2751
2780
  L: 330,
2752
2781
  S: this,
2753
2782
  C: (f, a) => f(...a)
@@ -2765,7 +2794,7 @@ var InvitationsHandler = class {
2765
2794
  await ctx.dispose();
2766
2795
  } else {
2767
2796
  invariant9(invitation.swarmKey, void 0, {
2768
- F: __dxlog_file12,
2797
+ F: __dxlog_file13,
2769
2798
  L: 345,
2770
2799
  S: this,
2771
2800
  A: [
@@ -2865,7 +2894,7 @@ var InvitationsHandler = class {
2865
2894
  newState: stateToString(newState),
2866
2895
  oldState: stateToString(invitation.state)
2867
2896
  }, {
2868
- F: __dxlog_file12,
2897
+ F: __dxlog_file13,
2869
2898
  L: 439,
2870
2899
  S: this,
2871
2900
  C: (f, a) => f(...a)
@@ -2876,7 +2905,7 @@ var InvitationsHandler = class {
2876
2905
  newState: stateToString(newState),
2877
2906
  oldState: stateToString(invitation.state)
2878
2907
  }, {
2879
- F: __dxlog_file12,
2908
+ F: __dxlog_file13,
2880
2909
  L: 445,
2881
2910
  S: this,
2882
2911
  C: (f, a) => f(...a)
@@ -2895,7 +2924,7 @@ var InvitationsHandler = class {
2895
2924
  async _handleGuestOtpAuth(extension, setState, authenticated, options) {
2896
2925
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2897
2926
  log10("guest waiting for authentication code...", void 0, {
2898
- F: __dxlog_file12,
2927
+ F: __dxlog_file13,
2899
2928
  L: 470,
2900
2929
  S: this,
2901
2930
  C: (f, a) => f(...a)
@@ -2903,7 +2932,7 @@ var InvitationsHandler = class {
2903
2932
  setState(Invitation4.State.READY_FOR_AUTHENTICATION);
2904
2933
  const authCode = await authenticated.wait(options);
2905
2934
  log10("sending authentication request", void 0, {
2906
- F: __dxlog_file12,
2935
+ F: __dxlog_file13,
2907
2936
  L: 474,
2908
2937
  S: this,
2909
2938
  C: (f, a) => f(...a)
@@ -2922,7 +2951,7 @@ var InvitationsHandler = class {
2922
2951
  log10("retrying invalid code", {
2923
2952
  attempt
2924
2953
  }, {
2925
- F: __dxlog_file12,
2954
+ F: __dxlog_file13,
2926
2955
  L: 485,
2927
2956
  S: this,
2928
2957
  C: (f, a) => f(...a)
@@ -2940,7 +2969,7 @@ var InvitationsHandler = class {
2940
2969
  throw new Error("challenge missing in the introduction");
2941
2970
  }
2942
2971
  log10("sending authentication request", void 0, {
2943
- F: __dxlog_file12,
2972
+ F: __dxlog_file13,
2944
2973
  L: 504,
2945
2974
  S: this,
2946
2975
  C: (f, a) => f(...a)
@@ -3061,14 +3090,14 @@ var InvitationsServiceImpl = class {
3061
3090
  };
3062
3091
 
3063
3092
  // packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts
3064
- import { createAdmissionCredentials, createCancelDelegatedSpaceInvitationCredential, createDelegatedSpaceInvitationCredential, getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
3093
+ import { createCancelDelegatedSpaceInvitationCredential, createDelegatedSpaceInvitationCredential, getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
3065
3094
  import { writeMessages as writeMessages2 } from "@dxos/feed-store";
3066
3095
  import { invariant as invariant10 } from "@dxos/invariant";
3067
3096
  import { log as log11 } from "@dxos/log";
3068
3097
  import { AlreadyJoinedError as AlreadyJoinedError2, AuthorizationError, InvalidInvitationError, SpaceNotFoundError } from "@dxos/protocols";
3069
3098
  import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
3070
3099
  import { SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/halo/credentials";
3071
- var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
3100
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
3072
3101
  var SpaceInvitationProtocol = class {
3073
3102
  constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
3074
3103
  this._spaceManager = _spaceManager;
@@ -3102,79 +3131,43 @@ var SpaceInvitationProtocol = class {
3102
3131
  };
3103
3132
  }
3104
3133
  async admit(invitation, request, guestProfile) {
3105
- invariant10(this._spaceKey, void 0, {
3106
- F: __dxlog_file13,
3107
- L: 76,
3108
- S: this,
3109
- A: [
3110
- "this._spaceKey",
3111
- ""
3112
- ]
3113
- });
3114
- const space = this._spaceManager.spaces.get(this._spaceKey);
3115
- invariant10(space, void 0, {
3116
- F: __dxlog_file13,
3117
- L: 78,
3118
- S: this,
3119
- A: [
3120
- "space",
3121
- ""
3122
- ]
3123
- });
3124
- invariant10(request.space, void 0, {
3125
- F: __dxlog_file13,
3126
- L: 80,
3134
+ invariant10(this._spaceKey && request.space, void 0, {
3135
+ F: __dxlog_file14,
3136
+ L: 74,
3127
3137
  S: this,
3128
3138
  A: [
3129
- "request.space",
3139
+ "this._spaceKey && request.space",
3130
3140
  ""
3131
3141
  ]
3132
3142
  });
3133
- const { identityKey, deviceKey } = request.space;
3134
- if (space.inner.spaceState.getMemberRole(identityKey) !== SpaceMember2.Role.REMOVED) {
3135
- throw new AlreadyJoinedError2();
3136
- }
3137
3143
  log11("writing guest credentials", {
3138
3144
  host: this._signingContext.deviceKey,
3139
- guest: deviceKey
3145
+ guest: request.space.deviceKey
3140
3146
  }, {
3141
- F: __dxlog_file13,
3142
- L: 87,
3147
+ F: __dxlog_file14,
3148
+ L: 75,
3143
3149
  S: this,
3144
3150
  C: (f, a) => f(...a)
3145
3151
  });
3146
- 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);
3147
- invariant10(credentials[0].credential, void 0, {
3148
- F: __dxlog_file13,
3149
- L: 101,
3150
- S: this,
3151
- A: [
3152
- "credentials[0].credential",
3153
- ""
3154
- ]
3155
- });
3156
- const spaceMemberCredential = credentials[0].credential.credential;
3157
- invariant10(getCredentialAssertion2(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3158
- F: __dxlog_file13,
3159
- L: 103,
3160
- S: this,
3161
- A: [
3162
- "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
3163
- ""
3164
- ]
3152
+ const spaceMemberCredential = await this._spaceManager.admitMember({
3153
+ spaceKey: this._spaceKey,
3154
+ identityKey: request.space.identityKey,
3155
+ role: invitation.role ?? SpaceMember2.Role.ADMIN,
3156
+ profile: guestProfile,
3157
+ delegationCredentialId: invitation.delegationCredentialId
3165
3158
  });
3166
- await writeMessages2(space.inner.controlPipeline.writer, credentials);
3159
+ const space = this._spaceManager.spaces.get(this._spaceKey);
3167
3160
  return {
3168
3161
  space: {
3169
3162
  credential: spaceMemberCredential,
3170
- controlTimeframe: space.inner.controlPipeline.state.timeframe
3163
+ controlTimeframe: space?.inner.controlPipeline.state.timeframe
3171
3164
  }
3172
3165
  };
3173
3166
  }
3174
3167
  async delegate(invitation) {
3175
3168
  invariant10(this._spaceKey, void 0, {
3176
- F: __dxlog_file13,
3177
- L: 116,
3169
+ F: __dxlog_file14,
3170
+ L: 95,
3178
3171
  S: this,
3179
3172
  A: [
3180
3173
  "this._spaceKey",
@@ -3183,8 +3176,8 @@ var SpaceInvitationProtocol = class {
3183
3176
  });
3184
3177
  const space = this._spaceManager.spaces.get(this._spaceKey);
3185
3178
  invariant10(space, void 0, {
3186
- F: __dxlog_file13,
3187
- L: 118,
3179
+ F: __dxlog_file14,
3180
+ L: 97,
3188
3181
  S: this,
3189
3182
  A: [
3190
3183
  "space",
@@ -3193,8 +3186,8 @@ var SpaceInvitationProtocol = class {
3193
3186
  });
3194
3187
  if (invitation.authMethod === Invitation5.AuthMethod.KNOWN_PUBLIC_KEY) {
3195
3188
  invariant10(invitation.guestKeypair?.publicKey, void 0, {
3196
- F: __dxlog_file13,
3197
- L: 120,
3189
+ F: __dxlog_file14,
3190
+ L: 99,
3198
3191
  S: this,
3199
3192
  A: [
3200
3193
  "invitation.guestKeypair?.publicKey",
@@ -3206,8 +3199,8 @@ var SpaceInvitationProtocol = class {
3206
3199
  host: this._signingContext.deviceKey,
3207
3200
  id: invitation.invitationId
3208
3201
  }, {
3209
- F: __dxlog_file13,
3210
- L: 123,
3202
+ F: __dxlog_file14,
3203
+ L: 102,
3211
3204
  S: this,
3212
3205
  C: (f, a) => f(...a)
3213
3206
  });
@@ -3221,8 +3214,8 @@ var SpaceInvitationProtocol = class {
3221
3214
  guestKey: invitation.authMethod === Invitation5.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
3222
3215
  });
3223
3216
  invariant10(credential.credential, void 0, {
3224
- F: __dxlog_file13,
3225
- L: 143,
3217
+ F: __dxlog_file14,
3218
+ L: 122,
3226
3219
  S: this,
3227
3220
  A: [
3228
3221
  "credential.credential",
@@ -3236,8 +3229,8 @@ var SpaceInvitationProtocol = class {
3236
3229
  }
3237
3230
  async cancelDelegation(invitation) {
3238
3231
  invariant10(this._spaceKey, void 0, {
3239
- F: __dxlog_file13,
3240
- L: 149,
3232
+ F: __dxlog_file14,
3233
+ L: 128,
3241
3234
  S: this,
3242
3235
  A: [
3243
3236
  "this._spaceKey",
@@ -3245,8 +3238,8 @@ var SpaceInvitationProtocol = class {
3245
3238
  ]
3246
3239
  });
3247
3240
  invariant10(invitation.type === Invitation5.Type.DELEGATED && invitation.delegationCredentialId, void 0, {
3248
- F: __dxlog_file13,
3249
- L: 150,
3241
+ F: __dxlog_file14,
3242
+ L: 129,
3250
3243
  S: this,
3251
3244
  A: [
3252
3245
  "invitation.type === Invitation.Type.DELEGATED && invitation.delegationCredentialId",
@@ -3255,8 +3248,8 @@ var SpaceInvitationProtocol = class {
3255
3248
  });
3256
3249
  const space = this._spaceManager.spaces.get(this._spaceKey);
3257
3250
  invariant10(space, void 0, {
3258
- F: __dxlog_file13,
3259
- L: 152,
3251
+ F: __dxlog_file14,
3252
+ L: 131,
3260
3253
  S: this,
3261
3254
  A: [
3262
3255
  "space",
@@ -3267,15 +3260,15 @@ var SpaceInvitationProtocol = class {
3267
3260
  host: this._signingContext.deviceKey,
3268
3261
  id: invitation.invitationId
3269
3262
  }, {
3270
- F: __dxlog_file13,
3271
- L: 154,
3263
+ F: __dxlog_file14,
3264
+ L: 133,
3272
3265
  S: this,
3273
3266
  C: (f, a) => f(...a)
3274
3267
  });
3275
3268
  const credential = await createCancelDelegatedSpaceInvitationCredential(this._signingContext.credentialSigner, space.key, invitation.delegationCredentialId);
3276
3269
  invariant10(credential.credential, void 0, {
3277
- F: __dxlog_file13,
3278
- L: 161,
3270
+ F: __dxlog_file14,
3271
+ L: 140,
3279
3272
  S: this,
3280
3273
  A: [
3281
3274
  "credential.credential",
@@ -3313,8 +3306,8 @@ var SpaceInvitationProtocol = class {
3313
3306
  }
3314
3307
  async accept(response) {
3315
3308
  invariant10(response.space, void 0, {
3316
- F: __dxlog_file13,
3317
- L: 196,
3309
+ F: __dxlog_file14,
3310
+ L: 175,
3318
3311
  S: this,
3319
3312
  A: [
3320
3313
  "response.space",
@@ -3324,8 +3317,8 @@ var SpaceInvitationProtocol = class {
3324
3317
  const { credential, controlTimeframe, dataTimeframe } = response.space;
3325
3318
  const assertion = getCredentialAssertion2(credential);
3326
3319
  invariant10(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
3327
- F: __dxlog_file13,
3328
- L: 199,
3320
+ F: __dxlog_file14,
3321
+ L: 178,
3329
3322
  S: this,
3330
3323
  A: [
3331
3324
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -3333,8 +3326,8 @@ var SpaceInvitationProtocol = class {
3333
3326
  ]
3334
3327
  });
3335
3328
  invariant10(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
3336
- F: __dxlog_file13,
3337
- L: 200,
3329
+ F: __dxlog_file14,
3330
+ L: 179,
3338
3331
  S: this,
3339
3332
  A: [
3340
3333
  "credential.subject.id.equals(this._signingContext.identityKey)",
@@ -3368,7 +3361,7 @@ import { PublicKey as PublicKey8 } from "@dxos/keys";
3368
3361
  import { log as log12 } from "@dxos/log";
3369
3362
  import { Invitation as Invitation6 } from "@dxos/protocols/proto/dxos/client/services";
3370
3363
  import { SpaceMember as SpaceMember3 } from "@dxos/protocols/proto/dxos/halo/credentials";
3371
- var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
3364
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
3372
3365
  var InvitationsManager = class {
3373
3366
  constructor(_invitationsHandler, _getHandler, _metadataStore) {
3374
3367
  this._invitationsHandler = _invitationsHandler;
@@ -3411,7 +3404,7 @@ var InvitationsManager = class {
3411
3404
  await this._persistIfRequired(handler, stream, invitation);
3412
3405
  } catch (err) {
3413
3406
  log12.catch(err, void 0, {
3414
- F: __dxlog_file14,
3407
+ F: __dxlog_file15,
3415
3408
  L: 82,
3416
3409
  S: this,
3417
3410
  C: (f, a) => f(...a)
@@ -3434,7 +3427,7 @@ var InvitationsManager = class {
3434
3427
  const freshInvitations = persistentInvitations.filter((invitation) => !hasInvitationExpired(invitation));
3435
3428
  const loadTasks = freshInvitations.map((persistentInvitation) => {
3436
3429
  invariant11(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
3437
- F: __dxlog_file14,
3430
+ F: __dxlog_file15,
3438
3431
  L: 103,
3439
3432
  S: this,
3440
3433
  A: [
@@ -3453,7 +3446,7 @@ var InvitationsManager = class {
3453
3446
  };
3454
3447
  } catch (err) {
3455
3448
  log12.catch(err, void 0, {
3456
- F: __dxlog_file14,
3449
+ F: __dxlog_file15,
3457
3450
  L: 110,
3458
3451
  S: this,
3459
3452
  C: (f, a) => f(...a)
@@ -3485,13 +3478,13 @@ var InvitationsManager = class {
3485
3478
  }
3486
3479
  async authenticate({ invitationId, authCode }) {
3487
3480
  log12("authenticating...", void 0, {
3488
- F: __dxlog_file14,
3481
+ F: __dxlog_file15,
3489
3482
  L: 140,
3490
3483
  S: this,
3491
3484
  C: (f, a) => f(...a)
3492
3485
  });
3493
3486
  invariant11(invitationId, void 0, {
3494
- F: __dxlog_file14,
3487
+ F: __dxlog_file15,
3495
3488
  L: 141,
3496
3489
  S: this,
3497
3490
  A: [
@@ -3504,7 +3497,7 @@ var InvitationsManager = class {
3504
3497
  log12.warn("invalid invitation", {
3505
3498
  invitationId
3506
3499
  }, {
3507
- F: __dxlog_file14,
3500
+ F: __dxlog_file15,
3508
3501
  L: 144,
3509
3502
  S: this,
3510
3503
  C: (f, a) => f(...a)
@@ -3517,13 +3510,13 @@ var InvitationsManager = class {
3517
3510
  log12("cancelInvitation...", {
3518
3511
  invitationId
3519
3512
  }, {
3520
- F: __dxlog_file14,
3513
+ F: __dxlog_file15,
3521
3514
  L: 151,
3522
3515
  S: this,
3523
3516
  C: (f, a) => f(...a)
3524
3517
  });
3525
3518
  invariant11(invitationId, void 0, {
3526
- F: __dxlog_file14,
3519
+ F: __dxlog_file15,
3527
3520
  L: 152,
3528
3521
  S: this,
3529
3522
  A: [
@@ -3597,12 +3590,15 @@ var InvitationsManager = class {
3597
3590
  stream.error(err);
3598
3591
  void ctx.dispose();
3599
3592
  }
3593
+ }, {
3594
+ F: __dxlog_file15,
3595
+ L: 234
3600
3596
  });
3601
3597
  ctx.onDispose(() => {
3602
3598
  log12("complete", {
3603
3599
  ...handler.toJSON()
3604
3600
  }, {
3605
- F: __dxlog_file14,
3601
+ F: __dxlog_file15,
3606
3602
  L: 241,
3607
3603
  S: this,
3608
3604
  C: (f, a) => f(...a)
@@ -3635,7 +3631,7 @@ var InvitationsManager = class {
3635
3631
  log12("timeout", {
3636
3632
  ...handler.toJSON()
3637
3633
  }, {
3638
- F: __dxlog_file14,
3634
+ F: __dxlog_file15,
3639
3635
  L: 261,
3640
3636
  S: this,
3641
3637
  C: (f, a) => f(...a)
@@ -3646,7 +3642,7 @@ var InvitationsManager = class {
3646
3642
  });
3647
3643
  } else {
3648
3644
  log12.warn("auth failed", err, {
3649
- F: __dxlog_file14,
3645
+ F: __dxlog_file15,
3650
3646
  L: 264,
3651
3647
  S: this,
3652
3648
  C: (f, a) => f(...a)
@@ -3658,12 +3654,15 @@ var InvitationsManager = class {
3658
3654
  }
3659
3655
  void ctx.dispose();
3660
3656
  }
3657
+ }, {
3658
+ F: __dxlog_file15,
3659
+ L: 258
3661
3660
  });
3662
3661
  ctx.onDispose(() => {
3663
3662
  log12("complete", {
3664
3663
  ...handler.toJSON()
3665
3664
  }, {
3666
- F: __dxlog_file14,
3665
+ F: __dxlog_file15,
3667
3666
  L: 271,
3668
3667
  S: this,
3669
3668
  C: (f, a) => f(...a)
@@ -3708,7 +3707,7 @@ var InvitationsManager = class {
3708
3707
  await this._metadataStore.removeInvitation(invitation.invitationId);
3709
3708
  } catch (err) {
3710
3709
  log12.catch(err, void 0, {
3711
- F: __dxlog_file14,
3710
+ F: __dxlog_file15,
3712
3711
  L: 307,
3713
3712
  S: this,
3714
3713
  C: (f, a) => f(...a)
@@ -3725,10 +3724,10 @@ var InvitationsManager = class {
3725
3724
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
3726
3725
  import { Event as Event6, Mutex as Mutex2, scheduleTask as scheduleTask5, sleep as sleep3, synchronized, trackLeaks } from "@dxos/async";
3727
3726
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
3728
- import { Context as Context8, ContextDisposedError as ContextDisposedError3, cancelWithContext as cancelWithContext5 } from "@dxos/context";
3727
+ import { Context as Context8, ContextDisposedError as ContextDisposedError3, cancelWithContext as cancelWithContext4 } from "@dxos/context";
3729
3728
  import { timed, warnAfterTimeout } from "@dxos/debug";
3730
3729
  import { createMappedFeedWriter } from "@dxos/echo-pipeline";
3731
- import { SpaceDocVersion } from "@dxos/echo-protocol";
3730
+ import { SpaceDocVersion as SpaceDocVersion2 } from "@dxos/echo-protocol";
3732
3731
  import { failedInvariant } from "@dxos/invariant";
3733
3732
  import { PublicKey as PublicKey10 } from "@dxos/keys";
3734
3733
  import { log as log15 } from "@dxos/log";
@@ -3785,22 +3784,19 @@ var AutomergeSpaceState = class extends Resource2 {
3785
3784
  };
3786
3785
 
3787
3786
  // packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts
3788
- import { asyncTimeout as asyncTimeout2 } from "@dxos/async";
3789
- import { next as am } from "@dxos/automerge/automerge";
3790
- import { cancelWithContext as cancelWithContext4 } from "@dxos/context";
3791
3787
  import { convertLegacyReferences, convertLegacySpaceRootDoc, findInlineObjectOfType, migrateDocument } from "@dxos/echo-db";
3792
- import { AutomergeDocumentLoaderImpl } from "@dxos/echo-pipeline";
3788
+ import { SpaceDocVersion } from "@dxos/echo-protocol";
3793
3789
  import { TYPE_PROPERTIES } from "@dxos/echo-schema";
3794
3790
  import { invariant as invariant12 } from "@dxos/invariant";
3795
3791
  import { log as log13 } from "@dxos/log";
3796
3792
  import { CreateEpochRequest } from "@dxos/protocols/proto/dxos/client/services";
3797
- import { assignDeep } from "@dxos/util";
3798
- var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts";
3793
+ var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts";
3794
+ var LOAD_DOC_TIMEOUT = 1e4;
3799
3795
  var runEpochMigration = async (ctx, context) => {
3800
3796
  switch (context.migration) {
3801
3797
  case CreateEpochRequest.Migration.INIT_AUTOMERGE: {
3802
- const document = context.repo.create();
3803
- await context.repo.flush();
3798
+ const document = context.echoHost.createDoc();
3799
+ await context.echoHost.flush();
3804
3800
  return {
3805
3801
  newRoot: document.url
3806
3802
  };
@@ -3809,77 +3805,88 @@ var runEpochMigration = async (ctx, context) => {
3809
3805
  if (!context.currentRoot) {
3810
3806
  throw new Error("Space does not have an automerge root");
3811
3807
  }
3812
- const rootHandle = context.repo.find(context.currentRoot);
3813
- await cancelWithContext4(ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
3814
- const newRoot = context.repo.create(rootHandle.docSync());
3815
- await context.repo.flush();
3808
+ const rootHandle = await context.echoHost.loadDoc(ctx, context.currentRoot, {
3809
+ timeout: LOAD_DOC_TIMEOUT
3810
+ });
3811
+ const newRoot = context.echoHost.createDoc(rootHandle.docSync());
3812
+ await context.echoHost.flush();
3816
3813
  return {
3817
3814
  newRoot: newRoot.url
3818
3815
  };
3819
3816
  }
3820
3817
  case CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT: {
3821
3818
  log13.info("Fragmenting", void 0, {
3822
- F: __dxlog_file15,
3823
- L: 63,
3819
+ F: __dxlog_file16,
3820
+ L: 64,
3824
3821
  S: void 0,
3825
3822
  C: (f, a) => f(...a)
3826
3823
  });
3827
3824
  const currentRootUrl = context.currentRoot;
3828
- const rootHandle = context.repo.find(currentRootUrl);
3829
- await cancelWithContext4(ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
3825
+ const rootHandle = await context.echoHost.loadDoc(ctx, currentRootUrl, {
3826
+ timeout: LOAD_DOC_TIMEOUT
3827
+ });
3830
3828
  const objects = Object.entries(rootHandle.docSync().objects);
3831
3829
  const properties = findInlineObjectOfType(rootHandle.docSync(), TYPE_PROPERTIES);
3832
3830
  const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
3833
3831
  invariant12(properties, "Properties not found", {
3834
- F: __dxlog_file15,
3835
- L: 73,
3832
+ F: __dxlog_file16,
3833
+ L: 75,
3836
3834
  S: void 0,
3837
3835
  A: [
3838
3836
  "properties",
3839
3837
  "'Properties not found'"
3840
3838
  ]
3841
3839
  });
3842
- const newSpaceDoc = {
3840
+ const newRoot = context.echoHost.createDoc({
3843
3841
  ...rootHandle.docSync(),
3844
3842
  objects: Object.fromEntries([
3845
3843
  properties
3846
3844
  ])
3847
- };
3848
- const newRoot = context.repo.create(newSpaceDoc);
3845
+ });
3849
3846
  invariant12(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3850
- F: __dxlog_file15,
3851
- L: 78,
3847
+ F: __dxlog_file16,
3848
+ L: 82,
3852
3849
  S: void 0,
3853
3850
  A: [
3854
3851
  "typeof newRoot.url === 'string' && newRoot.url.length > 0",
3855
3852
  ""
3856
3853
  ]
3857
3854
  });
3858
- const docLoader = new AutomergeDocumentLoaderImpl(context.spaceId, context.repo, context.spaceKey);
3859
- await docLoader.loadSpaceRootDocHandle(ctx, {
3860
- rootUrl: newRoot.url
3861
- });
3862
- otherObjects.forEach(([key, value]) => {
3863
- const handle = docLoader.createDocumentForObject(key);
3864
- handle.change((doc) => {
3865
- assignDeep(doc, [
3866
- "objects",
3867
- key
3868
- ], value);
3855
+ const newLinks = [];
3856
+ for (const [id, objData] of otherObjects) {
3857
+ const handle = context.echoHost.createDoc({
3858
+ version: SpaceDocVersion.CURRENT,
3859
+ access: {
3860
+ spaceKey: context.spaceKey.toHex()
3861
+ },
3862
+ objects: {
3863
+ [id]: objData
3864
+ }
3869
3865
  });
3866
+ newLinks.push([
3867
+ id,
3868
+ handle.url
3869
+ ]);
3870
+ }
3871
+ newRoot.change((doc) => {
3872
+ doc.links ??= {};
3873
+ for (const [id, url] of newLinks) {
3874
+ doc.links[id] = url;
3875
+ }
3870
3876
  });
3871
- await context.repo.flush();
3877
+ await context.echoHost.flush();
3872
3878
  return {
3873
3879
  newRoot: newRoot.url
3874
3880
  };
3875
3881
  }
3876
3882
  case CreateEpochRequest.Migration.MIGRATE_REFERENCES_TO_DXN: {
3877
3883
  const currentRootUrl = context.currentRoot;
3878
- const rootHandle = context.repo.find(currentRootUrl);
3879
- await cancelWithContext4(ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
3884
+ const rootHandle = await context.echoHost.loadDoc(ctx, currentRootUrl, {
3885
+ timeout: LOAD_DOC_TIMEOUT
3886
+ });
3880
3887
  invariant12(rootHandle.docSync(), "Root doc not found", {
3881
- F: __dxlog_file15,
3882
- L: 100,
3888
+ F: __dxlog_file16,
3889
+ L: 115,
3883
3890
  S: void 0,
3884
3891
  A: [
3885
3892
  "rootHandle.docSync()",
@@ -3888,40 +3895,59 @@ var runEpochMigration = async (ctx, context) => {
3888
3895
  });
3889
3896
  const newRootContent = await convertLegacySpaceRootDoc(structuredClone(rootHandle.docSync()));
3890
3897
  for (const [id, url] of Object.entries(newRootContent.links ?? {})) {
3891
- const handle = context.repo.find(url);
3892
- await cancelWithContext4(ctx, asyncTimeout2(handle.whenReady(), 1e4));
3893
- invariant12(handle.docSync(), "Doc not found", {
3894
- F: __dxlog_file15,
3895
- L: 107,
3896
- S: void 0,
3897
- A: [
3898
- "handle.docSync()",
3899
- "'Doc not found'"
3900
- ]
3901
- });
3902
- const newDoc = await convertLegacyReferences(structuredClone(handle.docSync()));
3903
- const migratedDoc = migrateDocument(handle.docSync(), newDoc);
3904
- const newHandle = context.repo.import(am.save(migratedDoc));
3905
- newRootContent.links[id] = newHandle.url;
3898
+ try {
3899
+ const handle = await context.echoHost.loadDoc(ctx, url, {
3900
+ timeout: LOAD_DOC_TIMEOUT
3901
+ });
3902
+ invariant12(handle.docSync(), void 0, {
3903
+ F: __dxlog_file16,
3904
+ L: 122,
3905
+ S: void 0,
3906
+ A: [
3907
+ "handle.docSync()",
3908
+ ""
3909
+ ]
3910
+ });
3911
+ const newDoc = await convertLegacyReferences(structuredClone(handle.docSync()));
3912
+ const migratedDoc = migrateDocument(handle.docSync(), newDoc);
3913
+ const newHandle = context.echoHost.createDoc(migratedDoc, {
3914
+ preserveHistory: true
3915
+ });
3916
+ newRootContent.links[id] = newHandle.url;
3917
+ } catch (err) {
3918
+ log13.warn("Failed to migrate reference", {
3919
+ id,
3920
+ url,
3921
+ error: err
3922
+ }, {
3923
+ F: __dxlog_file16,
3924
+ L: 128,
3925
+ S: void 0,
3926
+ C: (f, a) => f(...a)
3927
+ });
3928
+ delete newRootContent.links[id];
3929
+ }
3906
3930
  }
3907
3931
  const migratedRoot = migrateDocument(rootHandle.docSync(), newRootContent);
3908
- const newRoot = context.repo.import(am.save(migratedRoot));
3909
- await context.repo.flush();
3932
+ const newRoot = context.echoHost.createDoc(migratedRoot, {
3933
+ preserveHistory: true
3934
+ });
3935
+ await context.echoHost.flush();
3910
3936
  return {
3911
3937
  newRoot: newRoot.url
3912
3938
  };
3913
3939
  }
3914
3940
  case CreateEpochRequest.Migration.REPLACE_AUTOMERGE_ROOT: {
3915
3941
  invariant12(context.newAutomergeRoot, void 0, {
3916
- F: __dxlog_file15,
3917
- L: 124,
3942
+ F: __dxlog_file16,
3943
+ L: 143,
3918
3944
  S: void 0,
3919
3945
  A: [
3920
3946
  "context.newAutomergeRoot",
3921
3947
  ""
3922
3948
  ]
3923
3949
  });
3924
- await context.repo.flush();
3950
+ await context.echoHost.flush();
3925
3951
  return {
3926
3952
  newRoot: context.newAutomergeRoot
3927
3953
  };
@@ -3939,14 +3965,17 @@ import { log as log14 } from "@dxos/log";
3939
3965
  import { schema as schema4 } from "@dxos/protocols";
3940
3966
  import { RpcExtension as RpcExtension3 } from "@dxos/teleport";
3941
3967
  import { ComplexMap as ComplexMap2, ComplexSet as ComplexSet4, entry } from "@dxos/util";
3942
- var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
3968
+ var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
3943
3969
  var DEFAULT_RETRY_TIMEOUT = 1e3;
3944
3970
  var DEFAULT_SUCCESS_DELAY = 1e3;
3945
3971
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
3946
3972
  var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
3947
3973
  var NotarizationPlugin = class {
3948
3974
  constructor() {
3949
- this._ctx = new Context7();
3975
+ this._ctx = new Context7(void 0, {
3976
+ F: __dxlog_file17,
3977
+ L: 62
3978
+ });
3950
3979
  this._extensionOpened = new Event5();
3951
3980
  this._extensions = /* @__PURE__ */ new Set();
3952
3981
  this._processedCredentials = new ComplexSet4(PublicKey9.hash);
@@ -3967,13 +3996,13 @@ var NotarizationPlugin = class {
3967
3996
  log14("notarize", {
3968
3997
  credentials
3969
3998
  }, {
3970
- F: __dxlog_file16,
3999
+ F: __dxlog_file17,
3971
4000
  L: 90,
3972
4001
  S: this,
3973
4002
  C: (f, a) => f(...a)
3974
4003
  });
3975
4004
  invariant13(credentials.every((credential) => credential.id), "Credentials must have an id", {
3976
- F: __dxlog_file16,
4005
+ F: __dxlog_file17,
3977
4006
  L: 91,
3978
4007
  S: this,
3979
4008
  A: [
@@ -3987,7 +4016,7 @@ var NotarizationPlugin = class {
3987
4016
  log14.warn("Notarization error", {
3988
4017
  err
3989
4018
  }, {
3990
- F: __dxlog_file16,
4019
+ F: __dxlog_file17,
3991
4020
  L: 99,
3992
4021
  S: this,
3993
4022
  C: (f, a) => f(...a)
@@ -4003,7 +4032,7 @@ var NotarizationPlugin = class {
4003
4032
  timeout,
4004
4033
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
4005
4034
  }, {
4006
- F: __dxlog_file16,
4035
+ F: __dxlog_file17,
4007
4036
  L: 111,
4008
4037
  S: this,
4009
4038
  C: (f, a) => f(...a)
@@ -4026,7 +4055,7 @@ var NotarizationPlugin = class {
4026
4055
  log14.info("Exhausted all peers to notarize with", {
4027
4056
  retryIn: retryTimeout
4028
4057
  }, {
4029
- F: __dxlog_file16,
4058
+ F: __dxlog_file17,
4030
4059
  L: 136,
4031
4060
  S: this,
4032
4061
  C: (f, a) => f(...a)
@@ -4040,7 +4069,7 @@ var NotarizationPlugin = class {
4040
4069
  peer: peer.localPeerId,
4041
4070
  credentialId: credentials.map((credential) => credential.id)
4042
4071
  }, {
4043
- F: __dxlog_file16,
4072
+ F: __dxlog_file17,
4044
4073
  L: 143,
4045
4074
  S: this,
4046
4075
  C: (f, a) => f(...a)
@@ -4049,7 +4078,7 @@ var NotarizationPlugin = class {
4049
4078
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
4050
4079
  });
4051
4080
  log14("success", void 0, {
4052
- F: __dxlog_file16,
4081
+ F: __dxlog_file17,
4053
4082
  L: 147,
4054
4083
  S: this,
4055
4084
  C: (f, a) => f(...a)
@@ -4058,7 +4087,7 @@ var NotarizationPlugin = class {
4058
4087
  } catch (err) {
4059
4088
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
4060
4089
  log14.info("error notarizing (recoverable)", err, {
4061
- F: __dxlog_file16,
4090
+ F: __dxlog_file17,
4062
4091
  L: 151,
4063
4092
  S: this,
4064
4093
  C: (f, a) => f(...a)
@@ -4076,7 +4105,7 @@ var NotarizationPlugin = class {
4076
4105
  errors.wait()
4077
4106
  ]);
4078
4107
  log14("done", void 0, {
4079
- F: __dxlog_file16,
4108
+ F: __dxlog_file17,
4080
4109
  L: 162,
4081
4110
  S: this,
4082
4111
  C: (f, a) => f(...a)
@@ -4098,7 +4127,7 @@ var NotarizationPlugin = class {
4098
4127
  }
4099
4128
  setWriter(writer) {
4100
4129
  invariant13(!this._writer, "Writer already set.", {
4101
- F: __dxlog_file16,
4130
+ F: __dxlog_file17,
4102
4131
  L: 181,
4103
4132
  S: this,
4104
4133
  A: [
@@ -4123,7 +4152,7 @@ var NotarizationPlugin = class {
4123
4152
  }
4124
4153
  for (const credential of request.credentials ?? []) {
4125
4154
  invariant13(credential.id, "Credential must have an id", {
4126
- F: __dxlog_file16,
4155
+ F: __dxlog_file17,
4127
4156
  L: 200,
4128
4157
  S: this,
4129
4158
  A: [
@@ -4143,7 +4172,7 @@ var NotarizationPlugin = class {
4143
4172
  log14("extension opened", {
4144
4173
  peer: extension.localPeerId
4145
4174
  }, {
4146
- F: __dxlog_file16,
4175
+ F: __dxlog_file17,
4147
4176
  L: 211,
4148
4177
  S: this,
4149
4178
  C: (f, a) => f(...a)
@@ -4155,7 +4184,7 @@ var NotarizationPlugin = class {
4155
4184
  log14("extension closed", {
4156
4185
  peer: extension.localPeerId
4157
4186
  }, {
4158
- F: __dxlog_file16,
4187
+ F: __dxlog_file17,
4159
4188
  L: 216,
4160
4189
  S: this,
4161
4190
  C: (f, a) => f(...a)
@@ -4272,10 +4301,13 @@ function _using_ctx() {
4272
4301
  }
4273
4302
  };
4274
4303
  }
4275
- var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
4304
+ var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
4276
4305
  var DataSpace = class {
4277
4306
  constructor(params) {
4278
- this._ctx = new Context8();
4307
+ this._ctx = new Context8(void 0, {
4308
+ F: __dxlog_file18,
4309
+ L: 84
4310
+ });
4279
4311
  this._notarizationPlugin = new NotarizationPlugin();
4280
4312
  this._cache = void 0;
4281
4313
  // TODO(dmaretskyi): Move into Space?
@@ -4309,7 +4341,7 @@ var DataSpace = class {
4309
4341
  log15("new state", {
4310
4342
  state: SpaceState2[this._state]
4311
4343
  }, {
4312
- F: __dxlog_file17,
4344
+ F: __dxlog_file18,
4313
4345
  L: 146,
4314
4346
  S: this,
4315
4347
  C: (f, a) => f(...a)
@@ -4364,12 +4396,15 @@ var DataSpace = class {
4364
4396
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
4365
4397
  await this._automergeSpaceState.open();
4366
4398
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
4367
- await this._inner.open(new Context8());
4399
+ await this._inner.open(new Context8(void 0, {
4400
+ F: __dxlog_file18,
4401
+ L: 215
4402
+ }));
4368
4403
  this._state = SpaceState2.CONTROL_ONLY;
4369
4404
  log15("new state", {
4370
4405
  state: SpaceState2[this._state]
4371
4406
  }, {
4372
- F: __dxlog_file17,
4407
+ F: __dxlog_file18,
4373
4408
  L: 217,
4374
4409
  S: this,
4375
4410
  C: (f, a) => f(...a)
@@ -4387,13 +4422,16 @@ var DataSpace = class {
4387
4422
  log15("new state", {
4388
4423
  state: SpaceState2[this._state]
4389
4424
  }, {
4390
- F: __dxlog_file17,
4425
+ F: __dxlog_file18,
4391
4426
  L: 231,
4392
4427
  S: this,
4393
4428
  C: (f, a) => f(...a)
4394
4429
  });
4395
4430
  await this._ctx.dispose();
4396
- this._ctx = new Context8();
4431
+ this._ctx = new Context8(void 0, {
4432
+ F: __dxlog_file18,
4433
+ L: 233
4434
+ });
4397
4435
  await this.authVerifier.close();
4398
4436
  await this._inner.close();
4399
4437
  await this._inner.spaceState.removeCredentialProcessor(this._automergeSpaceState);
@@ -4420,7 +4458,7 @@ var DataSpace = class {
4420
4458
  } catch (err) {
4421
4459
  if (err instanceof CancelledError || err instanceof ContextDisposedError3) {
4422
4460
  log15("data pipeline initialization cancelled", err, {
4423
- F: __dxlog_file17,
4461
+ F: __dxlog_file18,
4424
4462
  L: 265,
4425
4463
  S: this,
4426
4464
  C: (f, a) => f(...a)
@@ -4428,7 +4466,7 @@ var DataSpace = class {
4428
4466
  return;
4429
4467
  }
4430
4468
  log15.error("Error initializing data pipeline", err, {
4431
- F: __dxlog_file17,
4469
+ F: __dxlog_file18,
4432
4470
  L: 269,
4433
4471
  S: this,
4434
4472
  C: (f, a) => f(...a)
@@ -4437,7 +4475,7 @@ var DataSpace = class {
4437
4475
  log15("new state", {
4438
4476
  state: SpaceState2[this._state]
4439
4477
  }, {
4440
- F: __dxlog_file17,
4478
+ F: __dxlog_file18,
4441
4479
  L: 271,
4442
4480
  S: this,
4443
4481
  C: (f, a) => f(...a)
@@ -4457,7 +4495,7 @@ var DataSpace = class {
4457
4495
  log15("new state", {
4458
4496
  state: SpaceState2[this._state]
4459
4497
  }, {
4460
- F: __dxlog_file17,
4498
+ F: __dxlog_file18,
4461
4499
  L: 287,
4462
4500
  S: this,
4463
4501
  C: (f, a) => f(...a)
@@ -4474,7 +4512,7 @@ var DataSpace = class {
4474
4512
  log15("new state", {
4475
4513
  state: SpaceState2[this._state]
4476
4514
  }, {
4477
- F: __dxlog_file17,
4515
+ F: __dxlog_file18,
4478
4516
  L: 306,
4479
4517
  S: this,
4480
4518
  C: (f, a) => f(...a)
@@ -4490,7 +4528,7 @@ var DataSpace = class {
4490
4528
  this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
4491
4529
  await this._createWritableFeeds();
4492
4530
  log15("writable feeds created", void 0, {
4493
- F: __dxlog_file17,
4531
+ F: __dxlog_file18,
4494
4532
  L: 322,
4495
4533
  S: this,
4496
4534
  C: (f, a) => f(...a)
@@ -4553,7 +4591,7 @@ var DataSpace = class {
4553
4591
  space: this.key,
4554
4592
  rootUrl
4555
4593
  }, {
4556
- F: __dxlog_file17,
4594
+ F: __dxlog_file18,
4557
4595
  L: 388,
4558
4596
  S: this,
4559
4597
  C: (f, a) => f(...a)
@@ -4564,7 +4602,7 @@ var DataSpace = class {
4564
4602
  try {
4565
4603
  var _usingCtx = _using_ctx();
4566
4604
  await warnAfterTimeout(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
4567
- await cancelWithContext5(this._ctx, handle.whenReady());
4605
+ await cancelWithContext4(this._ctx, handle.whenReady());
4568
4606
  });
4569
4607
  if (this._ctx.disposed) {
4570
4608
  return;
@@ -4583,7 +4621,7 @@ var DataSpace = class {
4583
4621
  }
4584
4622
  const root = await this._echoHost.openSpaceRoot(handle.url);
4585
4623
  this._databaseRoot = root;
4586
- if (root.getVersion() !== SpaceDocVersion.CURRENT) {
4624
+ if (root.getVersion() !== SpaceDocVersion2.CURRENT) {
4587
4625
  if (this._state !== SpaceState2.REQUIRES_MIGRATION) {
4588
4626
  this._state = SpaceState2.REQUIRES_MIGRATION;
4589
4627
  this.stateUpdate.emit();
@@ -4607,8 +4645,8 @@ var DataSpace = class {
4607
4645
  rootUrl,
4608
4646
  err
4609
4647
  }, {
4610
- F: __dxlog_file17,
4611
- L: 431,
4648
+ F: __dxlog_file18,
4649
+ L: 433,
4612
4650
  S: this,
4613
4651
  C: (f, a) => f(...a)
4614
4652
  });
@@ -4636,7 +4674,7 @@ var DataSpace = class {
4636
4674
  return null;
4637
4675
  }
4638
4676
  const { newRoot } = await runEpochMigration(ctx, {
4639
- repo: this._echoHost.automergeRepo,
4677
+ echoHost: this._echoHost,
4640
4678
  spaceId: this.id,
4641
4679
  spaceKey: this.key,
4642
4680
  migration: options.migration,
@@ -4693,8 +4731,8 @@ var DataSpace = class {
4693
4731
  log15("new state", {
4694
4732
  state: SpaceState2[this._state]
4695
4733
  }, {
4696
- F: __dxlog_file17,
4697
- L: 512,
4734
+ F: __dxlog_file18,
4735
+ L: 514,
4698
4736
  S: this,
4699
4737
  C: (f, a) => f(...a)
4700
4738
  });
@@ -4753,21 +4791,23 @@ DataSpace = _ts_decorate4([
4753
4791
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
4754
4792
  import { Event as Event7, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
4755
4793
  import { PropertiesType } from "@dxos/client-protocol";
4756
- import { Context as Context9, cancelWithContext as cancelWithContext6 } from "@dxos/context";
4757
- import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
4794
+ import { Context as Context9, cancelWithContext as cancelWithContext5 } from "@dxos/context";
4795
+ import { getCredentialAssertion as getCredentialAssertion3, createAdmissionCredentials } from "@dxos/credentials";
4758
4796
  import { convertLegacyReferences as convertLegacyReferences2, findInlineObjectOfType as findInlineObjectOfType2 } from "@dxos/echo-db";
4759
4797
  import { AuthStatus } from "@dxos/echo-pipeline";
4760
- import { LEGACY_TYPE_PROPERTIES, SpaceDocVersion as SpaceDocVersion2, encodeReference } from "@dxos/echo-protocol";
4798
+ import { CredentialServerExtension } from "@dxos/echo-pipeline";
4799
+ import { LEGACY_TYPE_PROPERTIES, SpaceDocVersion as SpaceDocVersion3, encodeReference } from "@dxos/echo-protocol";
4761
4800
  import { TYPE_PROPERTIES as TYPE_PROPERTIES2, generateEchoId, getTypeReference } from "@dxos/echo-schema";
4801
+ import { writeMessages as writeMessages3 } from "@dxos/feed-store";
4762
4802
  import { invariant as invariant14 } from "@dxos/invariant";
4763
4803
  import { PublicKey as PublicKey11 } from "@dxos/keys";
4764
4804
  import { log as log16 } from "@dxos/log";
4765
- import { trace as Trace2 } from "@dxos/protocols";
4805
+ import { trace as Trace2, AlreadyJoinedError as AlreadyJoinedError3 } from "@dxos/protocols";
4766
4806
  import { Invitation as Invitation7, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
4767
4807
  import { SpaceMember as SpaceMember6 } from "@dxos/protocols/proto/dxos/halo/credentials";
4768
4808
  import { Gossip as Gossip2, Presence as Presence2 } from "@dxos/teleport-extension-gossip";
4769
4809
  import { trace as trace7 } from "@dxos/tracing";
4770
- import { ComplexMap as ComplexMap3, assignDeep as assignDeep2, deferFunction as deferFunction2, forEachAsync } from "@dxos/util";
4810
+ import { ComplexMap as ComplexMap3, assignDeep, deferFunction as deferFunction2, forEachAsync } from "@dxos/util";
4771
4811
 
4772
4812
  // packages/sdk/client-services/src/packlets/spaces/genesis.ts
4773
4813
  import { createCredential } from "@dxos/credentials";
@@ -4850,7 +4890,7 @@ function _ts_decorate5(decorators, target, key, desc) {
4850
4890
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4851
4891
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4852
4892
  }
4853
- var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
4893
+ var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
4854
4894
  var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
4855
4895
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
4856
4896
  var DEFAULT_SPACE_KEY = "__DEFAULT__";
@@ -4864,7 +4904,10 @@ var DataSpaceManager = class {
4864
4904
  this._echoHost = _echoHost;
4865
4905
  this._invitationsManager = _invitationsManager;
4866
4906
  this._params = _params;
4867
- this._ctx = new Context9();
4907
+ this._ctx = new Context9(void 0, {
4908
+ F: __dxlog_file19,
4909
+ L: 104
4910
+ });
4868
4911
  this.updated = new Event7();
4869
4912
  this._spaces = new ComplexMap3(PublicKey11.hash);
4870
4913
  this._isOpen = false;
@@ -4898,24 +4941,24 @@ var DataSpaceManager = class {
4898
4941
  }
4899
4942
  async open() {
4900
4943
  log16("open", void 0, {
4901
- F: __dxlog_file18,
4902
- L: 146,
4944
+ F: __dxlog_file19,
4945
+ L: 156,
4903
4946
  S: this,
4904
4947
  C: (f, a) => f(...a)
4905
4948
  });
4906
4949
  log16.trace("dxos.echo.data-space-manager.open", Trace2.begin({
4907
4950
  id: this._instanceId
4908
4951
  }), {
4909
- F: __dxlog_file18,
4910
- L: 147,
4952
+ F: __dxlog_file19,
4953
+ L: 157,
4911
4954
  S: this,
4912
4955
  C: (f, a) => f(...a)
4913
4956
  });
4914
4957
  log16("metadata loaded", {
4915
4958
  spaces: this._metadataStore.spaces.length
4916
4959
  }, {
4917
- F: __dxlog_file18,
4918
- L: 148,
4960
+ F: __dxlog_file19,
4961
+ L: 158,
4919
4962
  S: this,
4920
4963
  C: (f, a) => f(...a)
4921
4964
  });
@@ -4924,8 +4967,8 @@ var DataSpaceManager = class {
4924
4967
  log16("load space", {
4925
4968
  spaceMetadata
4926
4969
  }, {
4927
- F: __dxlog_file18,
4928
- L: 152,
4970
+ F: __dxlog_file19,
4971
+ L: 162,
4929
4972
  S: this,
4930
4973
  C: (f, a) => f(...a)
4931
4974
  });
@@ -4935,8 +4978,8 @@ var DataSpaceManager = class {
4935
4978
  spaceMetadata,
4936
4979
  err
4937
4980
  }, {
4938
- F: __dxlog_file18,
4939
- L: 155,
4981
+ F: __dxlog_file19,
4982
+ L: 165,
4940
4983
  S: this,
4941
4984
  C: (f, a) => f(...a)
4942
4985
  });
@@ -4947,16 +4990,16 @@ var DataSpaceManager = class {
4947
4990
  log16.trace("dxos.echo.data-space-manager.open", Trace2.end({
4948
4991
  id: this._instanceId
4949
4992
  }), {
4950
- F: __dxlog_file18,
4951
- L: 162,
4993
+ F: __dxlog_file19,
4994
+ L: 172,
4952
4995
  S: this,
4953
4996
  C: (f, a) => f(...a)
4954
4997
  });
4955
4998
  }
4956
4999
  async close() {
4957
5000
  log16("close", void 0, {
4958
- F: __dxlog_file18,
4959
- L: 167,
5001
+ F: __dxlog_file19,
5002
+ L: 177,
4960
5003
  S: this,
4961
5004
  C: (f, a) => f(...a)
4962
5005
  });
@@ -4972,8 +5015,8 @@ var DataSpaceManager = class {
4972
5015
  */
4973
5016
  async createSpace() {
4974
5017
  invariant14(this._isOpen, "Not open.", {
4975
- F: __dxlog_file18,
4976
- L: 181,
5018
+ F: __dxlog_file19,
5019
+ L: 191,
4977
5020
  S: this,
4978
5021
  A: [
4979
5022
  "this._isOpen",
@@ -4993,8 +5036,8 @@ var DataSpaceManager = class {
4993
5036
  log16("creating space...", {
4994
5037
  spaceKey
4995
5038
  }, {
4996
- F: __dxlog_file18,
4997
- L: 193,
5039
+ F: __dxlog_file19,
5040
+ L: 203,
4998
5041
  S: this,
4999
5042
  C: (f, a) => f(...a)
5000
5043
  });
@@ -5005,8 +5048,8 @@ var DataSpaceManager = class {
5005
5048
  await this._metadataStore.addSpace(metadata);
5006
5049
  const memberCredential = credentials[1];
5007
5050
  invariant14(getCredentialAssertion3(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
5008
- F: __dxlog_file18,
5009
- L: 203,
5051
+ F: __dxlog_file19,
5052
+ L: 213,
5010
5053
  S: this,
5011
5054
  A: [
5012
5055
  "getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -5023,11 +5066,11 @@ var DataSpaceManager = class {
5023
5066
  return false;
5024
5067
  }
5025
5068
  switch (space.databaseRoot.getVersion()) {
5026
- case SpaceDocVersion2.CURRENT: {
5069
+ case SpaceDocVersion3.CURRENT: {
5027
5070
  const [_, properties] = findInlineObjectOfType2(space.databaseRoot.docSync(), TYPE_PROPERTIES2) ?? [];
5028
5071
  return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
5029
5072
  }
5030
- case SpaceDocVersion2.LEGACY: {
5073
+ case SpaceDocVersion3.LEGACY: {
5031
5074
  const convertedDoc = await convertLegacyReferences2(space.databaseRoot.docSync());
5032
5075
  const [_, properties] = findInlineObjectOfType2(convertedDoc, LEGACY_TYPE_PROPERTIES) ?? [];
5033
5076
  return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
@@ -5037,8 +5080,8 @@ var DataSpaceManager = class {
5037
5080
  version: space.databaseRoot.getVersion(),
5038
5081
  spaceId: space.id
5039
5082
  }, {
5040
- F: __dxlog_file18,
5041
- L: 228,
5083
+ F: __dxlog_file19,
5084
+ L: 238,
5042
5085
  S: this,
5043
5086
  C: (f, a) => f(...a)
5044
5087
  });
@@ -5061,7 +5104,7 @@ var DataSpaceManager = class {
5061
5104
  };
5062
5105
  const propertiesId = generateEchoId();
5063
5106
  document.change((doc) => {
5064
- assignDeep2(doc, [
5107
+ assignDeep(doc, [
5065
5108
  "objects",
5066
5109
  propertiesId
5067
5110
  ], properties);
@@ -5072,8 +5115,8 @@ var DataSpaceManager = class {
5072
5115
  async _getSpaceRootDocument(space) {
5073
5116
  const automergeIndex = space.automergeSpaceState.rootUrl;
5074
5117
  invariant14(automergeIndex, void 0, {
5075
- F: __dxlog_file18,
5076
- L: 261,
5118
+ F: __dxlog_file19,
5119
+ L: 271,
5077
5120
  S: this,
5078
5121
  A: [
5079
5122
  "automergeIndex",
@@ -5089,14 +5132,14 @@ var DataSpaceManager = class {
5089
5132
  log16("accept space", {
5090
5133
  opts
5091
5134
  }, {
5092
- F: __dxlog_file18,
5093
- L: 270,
5135
+ F: __dxlog_file19,
5136
+ L: 280,
5094
5137
  S: this,
5095
5138
  C: (f, a) => f(...a)
5096
5139
  });
5097
5140
  invariant14(this._isOpen, "Not open.", {
5098
- F: __dxlog_file18,
5099
- L: 271,
5141
+ F: __dxlog_file19,
5142
+ L: 281,
5100
5143
  S: this,
5101
5144
  A: [
5102
5145
  "this._isOpen",
@@ -5104,8 +5147,8 @@ var DataSpaceManager = class {
5104
5147
  ]
5105
5148
  });
5106
5149
  invariant14(!this._spaces.has(opts.spaceKey), "Space already exists.", {
5107
- F: __dxlog_file18,
5108
- L: 272,
5150
+ F: __dxlog_file19,
5151
+ L: 282,
5109
5152
  S: this,
5110
5153
  A: [
5111
5154
  "!this._spaces.has(opts.spaceKey)",
@@ -5125,23 +5168,72 @@ var DataSpaceManager = class {
5125
5168
  this.updated.emit();
5126
5169
  return space;
5127
5170
  }
5171
+ async admitMember(options) {
5172
+ const space = this._spaceManager.spaces.get(options.spaceKey);
5173
+ invariant14(space, void 0, {
5174
+ F: __dxlog_file19,
5175
+ L: 302,
5176
+ S: this,
5177
+ A: [
5178
+ "space",
5179
+ ""
5180
+ ]
5181
+ });
5182
+ if (space.spaceState.getMemberRole(options.identityKey) !== SpaceMember6.Role.REMOVED) {
5183
+ throw new AlreadyJoinedError3();
5184
+ }
5185
+ const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, options.identityKey, space.key, space.genesisFeedKey, options.role, space.spaceState.membershipChainHeads, options.profile, options.delegationCredentialId);
5186
+ invariant14(credentials[0].credential, void 0, {
5187
+ F: __dxlog_file19,
5188
+ L: 321,
5189
+ S: this,
5190
+ A: [
5191
+ "credentials[0].credential",
5192
+ ""
5193
+ ]
5194
+ });
5195
+ const spaceMemberCredential = credentials[0].credential.credential;
5196
+ invariant14(getCredentialAssertion3(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
5197
+ F: __dxlog_file19,
5198
+ L: 323,
5199
+ S: this,
5200
+ A: [
5201
+ "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
5202
+ ""
5203
+ ]
5204
+ });
5205
+ await writeMessages3(space.controlPipeline.writer, credentials);
5206
+ return spaceMemberCredential;
5207
+ }
5128
5208
  /**
5129
5209
  * Wait until the space data pipeline is fully initialized.
5130
5210
  * Used by invitation handler.
5131
5211
  * TODO(dmaretskyi): Consider removing.
5132
5212
  */
5133
5213
  async waitUntilSpaceReady(spaceKey) {
5134
- await cancelWithContext6(this._ctx, this.updated.waitForCondition(() => {
5214
+ await cancelWithContext5(this._ctx, this.updated.waitForCondition(() => {
5135
5215
  const space = this._spaces.get(spaceKey);
5136
5216
  return !!space && space.state === SpaceState3.READY;
5137
5217
  }));
5138
5218
  }
5219
+ async requestSpaceAdmissionCredential(spaceKey) {
5220
+ return this._spaceManager.requestSpaceAdmissionCredential({
5221
+ spaceKey,
5222
+ identityKey: this._signingContext.identityKey,
5223
+ timeout: 15e3,
5224
+ swarmIdentity: {
5225
+ peerKey: this._signingContext.deviceKey,
5226
+ credentialProvider: createAuthProvider(this._signingContext.credentialSigner),
5227
+ credentialAuthenticator: async () => true
5228
+ }
5229
+ });
5230
+ }
5139
5231
  async _constructSpace(metadata) {
5140
5232
  log16("construct space", {
5141
5233
  metadata
5142
5234
  }, {
5143
- F: __dxlog_file18,
5144
- L: 306,
5235
+ F: __dxlog_file19,
5236
+ L: 358,
5145
5237
  S: this,
5146
5238
  C: (f, a) => f(...a)
5147
5239
  });
@@ -5169,6 +5261,7 @@ var DataSpaceManager = class {
5169
5261
  credentialAuthenticator: deferFunction2(() => dataSpace.authVerifier.verifier)
5170
5262
  },
5171
5263
  onAuthorizedConnection: (session) => {
5264
+ session.addExtension("dxos.mesh.teleport.admission-discovery", new CredentialServerExtension(space));
5172
5265
  session.addExtension("dxos.mesh.teleport.gossip", gossip.createExtension({
5173
5266
  remotePeerId: session.remotePeerId
5174
5267
  }));
@@ -5178,8 +5271,8 @@ var DataSpaceManager = class {
5178
5271
  },
5179
5272
  onAuthFailure: () => {
5180
5273
  log16.warn("auth failure", void 0, {
5181
- F: __dxlog_file18,
5182
- L: 343,
5274
+ F: __dxlog_file19,
5275
+ L: 396,
5183
5276
  S: this,
5184
5277
  C: (f, a) => f(...a)
5185
5278
  });
@@ -5211,8 +5304,8 @@ var DataSpaceManager = class {
5211
5304
  log16("before space ready", {
5212
5305
  space: space.key
5213
5306
  }, {
5214
- F: __dxlog_file18,
5215
- L: 370,
5307
+ F: __dxlog_file19,
5308
+ L: 423,
5216
5309
  S: this,
5217
5310
  C: (f, a) => f(...a)
5218
5311
  });
@@ -5222,8 +5315,8 @@ var DataSpaceManager = class {
5222
5315
  space: space.key,
5223
5316
  open: this._isOpen
5224
5317
  }, {
5225
- F: __dxlog_file18,
5226
- L: 373,
5318
+ F: __dxlog_file19,
5319
+ L: 426,
5227
5320
  S: this,
5228
5321
  C: (f, a) => f(...a)
5229
5322
  });
@@ -5241,8 +5334,8 @@ var DataSpaceManager = class {
5241
5334
  log16("before space close", {
5242
5335
  space: space.key
5243
5336
  }, {
5244
- F: __dxlog_file18,
5245
- L: 381,
5337
+ F: __dxlog_file19,
5338
+ L: 434,
5246
5339
  S: this,
5247
5340
  C: (f, a) => f(...a)
5248
5341
  });
@@ -5282,8 +5375,8 @@ var DataSpaceManager = class {
5282
5375
  peersOnline: presence.getPeersOnline().length,
5283
5376
  closedSessions
5284
5377
  }, {
5285
- F: __dxlog_file18,
5286
- L: 417,
5378
+ F: __dxlog_file19,
5379
+ L: 470,
5287
5380
  S: this,
5288
5381
  C: (f, a) => f(...a)
5289
5382
  });
@@ -5297,8 +5390,8 @@ var DataSpaceManager = class {
5297
5390
  log16("closing a session with a removed peer", {
5298
5391
  peerId: peerState.peerId
5299
5392
  }, {
5300
- F: __dxlog_file18,
5301
- L: 431,
5393
+ F: __dxlog_file19,
5394
+ L: 484,
5302
5395
  S: this,
5303
5396
  C: (f, a) => f(...a)
5304
5397
  });
@@ -5363,13 +5456,13 @@ import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTas
5363
5456
  import { Stream as Stream10 } from "@dxos/codec-protobuf";
5364
5457
  import { createAdmissionCredentials as createAdmissionCredentials2, getCredentialAssertion as getCredentialAssertion4 } from "@dxos/credentials";
5365
5458
  import { raise as raise2 } from "@dxos/debug";
5366
- import { writeMessages as writeMessages3 } from "@dxos/feed-store";
5459
+ import { writeMessages as writeMessages4 } from "@dxos/feed-store";
5367
5460
  import { invariant as invariant15 } from "@dxos/invariant";
5368
5461
  import { log as log17 } from "@dxos/log";
5369
5462
  import { ApiError, SpaceNotFoundError as SpaceNotFoundError2, encodeError, IdentityNotInitializedError, AuthorizationError as AuthorizationError2 } from "@dxos/protocols";
5370
5463
  import { SpaceMember as SpaceMember7, SpaceState as SpaceState4 } from "@dxos/protocols/proto/dxos/client/services";
5371
5464
  import { trace as trace8 } from "@dxos/tracing";
5372
- var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
5465
+ var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
5373
5466
  var SpacesServiceImpl = class {
5374
5467
  constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
5375
5468
  this._identityManager = _identityManager;
@@ -5413,8 +5506,8 @@ var SpacesServiceImpl = class {
5413
5506
  }
5414
5507
  const credentials = await createAdmissionCredentials2(identity.getIdentityCredentialSigner(), request.memberKey, space.key, space.genesisFeedKey, request.newRole, space.spaceState.membershipChainHeads);
5415
5508
  invariant15(credentials[0].credential, void 0, {
5416
- F: __dxlog_file19,
5417
- L: 98,
5509
+ F: __dxlog_file20,
5510
+ L: 102,
5418
5511
  S: this,
5419
5512
  A: [
5420
5513
  "credentials[0].credential",
@@ -5423,15 +5516,15 @@ var SpacesServiceImpl = class {
5423
5516
  });
5424
5517
  const spaceMemberCredential = credentials[0].credential.credential;
5425
5518
  invariant15(getCredentialAssertion4(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
5426
- F: __dxlog_file19,
5427
- L: 100,
5519
+ F: __dxlog_file20,
5520
+ L: 104,
5428
5521
  S: this,
5429
5522
  A: [
5430
5523
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
5431
5524
  ""
5432
5525
  ]
5433
5526
  });
5434
- await writeMessages3(space.controlPipeline.writer, credentials);
5527
+ await writeMessages4(space.controlPipeline.writer, credentials);
5435
5528
  }
5436
5529
  querySpaces() {
5437
5530
  return new Stream10(({ next, ctx }) => {
@@ -5441,8 +5534,8 @@ var SpacesServiceImpl = class {
5441
5534
  log17("update", {
5442
5535
  spaces
5443
5536
  }, {
5444
- F: __dxlog_file19,
5445
- L: 111,
5537
+ F: __dxlog_file20,
5538
+ L: 115,
5446
5539
  S: this,
5447
5540
  C: (f, a) => f(...a)
5448
5541
  });
@@ -5533,8 +5626,8 @@ var SpacesServiceImpl = class {
5533
5626
  });
5534
5627
  } else {
5535
5628
  invariant15(!credential.id, "Id on unsigned credentials is not allowed", {
5536
- F: __dxlog_file19,
5537
- L: 209,
5629
+ F: __dxlog_file20,
5630
+ L: 213,
5538
5631
  S: this,
5539
5632
  A: [
5540
5633
  "!credential.id",
@@ -5542,8 +5635,8 @@ var SpacesServiceImpl = class {
5542
5635
  ]
5543
5636
  });
5544
5637
  invariant15(this._identityManager.identity, "Identity is not available", {
5545
- F: __dxlog_file19,
5546
- L: 210,
5638
+ F: __dxlog_file20,
5639
+ L: 214,
5547
5640
  S: this,
5548
5641
  A: [
5549
5642
  "this._identityManager.identity",
@@ -5552,8 +5645,8 @@ var SpacesServiceImpl = class {
5552
5645
  });
5553
5646
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
5554
5647
  invariant15(credential.issuer.equals(signer.getIssuer()), void 0, {
5555
- F: __dxlog_file19,
5556
- L: 212,
5648
+ F: __dxlog_file20,
5649
+ L: 216,
5557
5650
  S: this,
5558
5651
  A: [
5559
5652
  "credential.issuer.equals(signer.getIssuer())",
@@ -5583,6 +5676,59 @@ var SpacesServiceImpl = class {
5583
5676
  epochCredential: credential ?? void 0
5584
5677
  };
5585
5678
  }
5679
+ async admitContact(request) {
5680
+ const dataSpaceManager = await this._getDataSpaceManager();
5681
+ await dataSpaceManager.admitMember({
5682
+ spaceKey: request.spaceKey,
5683
+ identityKey: request.contact.identityKey,
5684
+ role: request.role
5685
+ });
5686
+ }
5687
+ async joinBySpaceKey({ spaceKey }) {
5688
+ const dataSpaceManager = await this._getDataSpaceManager();
5689
+ const credential = await dataSpaceManager.requestSpaceAdmissionCredential(spaceKey);
5690
+ return this._joinByAdmission({
5691
+ credential
5692
+ });
5693
+ }
5694
+ async _joinByAdmission({ credential }) {
5695
+ const assertion = getCredentialAssertion4(credential);
5696
+ invariant15(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
5697
+ F: __dxlog_file20,
5698
+ L: 250,
5699
+ S: this,
5700
+ A: [
5701
+ "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
5702
+ "'Invalid credential'"
5703
+ ]
5704
+ });
5705
+ const myIdentity = this._identityManager.identity;
5706
+ invariant15(myIdentity && credential.subject.id.equals(myIdentity.identityKey), void 0, {
5707
+ F: __dxlog_file20,
5708
+ L: 252,
5709
+ S: this,
5710
+ A: [
5711
+ "myIdentity && credential.subject.id.equals(myIdentity.identityKey)",
5712
+ ""
5713
+ ]
5714
+ });
5715
+ const dataSpaceManager = await this._getDataSpaceManager();
5716
+ let dataSpace = dataSpaceManager.spaces.get(assertion.spaceKey);
5717
+ if (!dataSpace) {
5718
+ dataSpace = await dataSpaceManager.acceptSpace({
5719
+ spaceKey: assertion.spaceKey,
5720
+ genesisFeedKey: assertion.genesisFeedKey
5721
+ });
5722
+ await myIdentity.controlPipeline.writer.write({
5723
+ credential: {
5724
+ credential
5725
+ }
5726
+ });
5727
+ }
5728
+ return {
5729
+ space: this._serializeSpace(dataSpace)
5730
+ };
5731
+ }
5586
5732
  _serializeSpace(space) {
5587
5733
  return {
5588
5734
  id: space.id,
@@ -5600,7 +5746,8 @@ var SpacesServiceImpl = class {
5600
5746
  startDataTimeframe: void 0,
5601
5747
  currentDataTimeframe: void 0,
5602
5748
  targetDataTimeframe: void 0,
5603
- totalDataTimeframe: void 0
5749
+ totalDataTimeframe: void 0,
5750
+ spaceRootUrl: space.databaseRoot?.url
5604
5751
  },
5605
5752
  members: Array.from(space.inner.spaceState.members.values()).map((member) => {
5606
5753
  const peers = space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key));
@@ -5670,7 +5817,7 @@ function _ts_decorate6(decorators, target, key, desc) {
5670
5817
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5671
5818
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5672
5819
  }
5673
- var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
5820
+ var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
5674
5821
  var ServiceContext = class extends Resource3 {
5675
5822
  constructor(storage, level, networkManager, signalManager, _runtimeParams) {
5676
5823
  super();
@@ -5714,7 +5861,7 @@ var ServiceContext = class extends Resource3 {
5714
5861
  async _open(ctx) {
5715
5862
  await this._checkStorageVersion();
5716
5863
  log18("opening...", void 0, {
5717
- F: __dxlog_file20,
5864
+ F: __dxlog_file21,
5718
5865
  L: 149,
5719
5866
  S: this,
5720
5867
  C: (f, a) => f(...a)
@@ -5722,7 +5869,7 @@ var ServiceContext = class extends Resource3 {
5722
5869
  log18.trace("dxos.sdk.service-context.open", trace9.begin({
5723
5870
  id: this._instanceId
5724
5871
  }), {
5725
- F: __dxlog_file20,
5872
+ F: __dxlog_file21,
5726
5873
  L: 150,
5727
5874
  S: this,
5728
5875
  C: (f, a) => f(...a)
@@ -5740,7 +5887,7 @@ var ServiceContext = class extends Resource3 {
5740
5887
  log18("loaded persistent invitations", {
5741
5888
  count: loadedInvitations.invitations?.length
5742
5889
  }, {
5743
- F: __dxlog_file20,
5890
+ F: __dxlog_file21,
5744
5891
  L: 163,
5745
5892
  S: this,
5746
5893
  C: (f, a) => f(...a)
@@ -5748,13 +5895,13 @@ var ServiceContext = class extends Resource3 {
5748
5895
  log18.trace("dxos.sdk.service-context.open", trace9.end({
5749
5896
  id: this._instanceId
5750
5897
  }), {
5751
- F: __dxlog_file20,
5898
+ F: __dxlog_file21,
5752
5899
  L: 165,
5753
5900
  S: this,
5754
5901
  C: (f, a) => f(...a)
5755
5902
  });
5756
5903
  log18("opened", void 0, {
5757
- F: __dxlog_file20,
5904
+ F: __dxlog_file21,
5758
5905
  L: 166,
5759
5906
  S: this,
5760
5907
  C: (f, a) => f(...a)
@@ -5762,7 +5909,7 @@ var ServiceContext = class extends Resource3 {
5762
5909
  }
5763
5910
  async _close(ctx) {
5764
5911
  log18("closing...", void 0, {
5765
- F: __dxlog_file20,
5912
+ F: __dxlog_file21,
5766
5913
  L: 170,
5767
5914
  S: this,
5768
5915
  C: (f, a) => f(...a)
@@ -5779,7 +5926,7 @@ var ServiceContext = class extends Resource3 {
5779
5926
  await this.networkManager.close();
5780
5927
  await this.signalManager.close();
5781
5928
  log18("closed", void 0, {
5782
- F: __dxlog_file20,
5929
+ F: __dxlog_file21,
5783
5930
  L: 182,
5784
5931
  S: this,
5785
5932
  C: (f, a) => f(...a)
@@ -5787,13 +5934,16 @@ var ServiceContext = class extends Resource3 {
5787
5934
  }
5788
5935
  async createIdentity(params = {}) {
5789
5936
  const identity = await this.identityManager.createIdentity(params);
5790
- await this._initialize(new Context10());
5937
+ await this._initialize(new Context10(void 0, {
5938
+ F: __dxlog_file21,
5939
+ L: 187
5940
+ }));
5791
5941
  return identity;
5792
5942
  }
5793
5943
  getInvitationHandler(invitation) {
5794
5944
  const factory = this._handlerFactories.get(invitation.kind);
5795
5945
  invariant16(factory, `Unknown invitation kind: ${invitation.kind}`, {
5796
- F: __dxlog_file20,
5946
+ F: __dxlog_file21,
5797
5947
  L: 193,
5798
5948
  S: this,
5799
5949
  A: [
@@ -5813,7 +5963,10 @@ var ServiceContext = class extends Resource3 {
5813
5963
  }
5814
5964
  async _acceptIdentity(params) {
5815
5965
  const identity = await this.identityManager.acceptIdentity(params);
5816
- await this._initialize(new Context10());
5966
+ await this._initialize(new Context10(void 0, {
5967
+ F: __dxlog_file21,
5968
+ L: 209
5969
+ }));
5817
5970
  return identity;
5818
5971
  }
5819
5972
  async _checkStorageVersion() {
@@ -5825,7 +5978,7 @@ var ServiceContext = class extends Resource3 {
5825
5978
  // Called when identity is created.
5826
5979
  async _initialize(ctx) {
5827
5980
  log18("initializing spaces...", void 0, {
5828
- F: __dxlog_file20,
5981
+ F: __dxlog_file21,
5829
5982
  L: 224,
5830
5983
  S: this,
5831
5984
  C: (f, a) => f(...a)
@@ -5848,7 +6001,7 @@ var ServiceContext = class extends Resource3 {
5848
6001
  await this.dataSpaceManager.open();
5849
6002
  this._handlerFactories.set(Invitation8.Kind.SPACE, (invitation) => {
5850
6003
  invariant16(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
5851
- F: __dxlog_file20,
6004
+ F: __dxlog_file21,
5852
6005
  L: 249,
5853
6006
  S: this,
5854
6007
  A: [
@@ -5872,7 +6025,7 @@ var ServiceContext = class extends Resource3 {
5872
6025
  log18("dataSpaceManager not initialized yet, ignoring space admission", {
5873
6026
  details: assertion
5874
6027
  }, {
5875
- F: __dxlog_file20,
6028
+ F: __dxlog_file21,
5876
6029
  L: 265,
5877
6030
  S: this,
5878
6031
  C: (f, a) => f(...a)
@@ -5883,7 +6036,7 @@ var ServiceContext = class extends Resource3 {
5883
6036
  log18("space already exists, ignoring space admission", {
5884
6037
  details: assertion
5885
6038
  }, {
5886
- F: __dxlog_file20,
6039
+ F: __dxlog_file21,
5887
6040
  L: 269,
5888
6041
  S: this,
5889
6042
  C: (f, a) => f(...a)
@@ -5894,7 +6047,7 @@ var ServiceContext = class extends Resource3 {
5894
6047
  log18("accepting space recorded in halo", {
5895
6048
  details: assertion
5896
6049
  }, {
5897
- F: __dxlog_file20,
6050
+ F: __dxlog_file21,
5898
6051
  L: 274,
5899
6052
  S: this,
5900
6053
  C: (f, a) => f(...a)
@@ -5905,7 +6058,7 @@ var ServiceContext = class extends Resource3 {
5905
6058
  });
5906
6059
  } catch (err) {
5907
6060
  log18.catch(err, void 0, {
5908
- F: __dxlog_file20,
6061
+ F: __dxlog_file21,
5909
6062
  L: 280,
5910
6063
  S: this,
5911
6064
  C: (f, a) => f(...a)
@@ -5952,7 +6105,7 @@ var ServiceRegistry = class {
5952
6105
  };
5953
6106
 
5954
6107
  // packages/sdk/client-services/src/packlets/locks/browser.ts
5955
- import { asyncTimeout as asyncTimeout3, Trigger as Trigger9 } from "@dxos/async";
6108
+ import { asyncTimeout as asyncTimeout2, Trigger as Trigger9 } from "@dxos/async";
5956
6109
  import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
5957
6110
  import { log as log19, logInfo } from "@dxos/log";
5958
6111
  function _ts_decorate7(decorators, target, key, desc) {
@@ -5965,7 +6118,7 @@ function _ts_decorate7(decorators, target, key, desc) {
5965
6118
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5966
6119
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5967
6120
  }
5968
- var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
6121
+ var __dxlog_file22 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
5969
6122
  var Message;
5970
6123
  (function(Message2) {
5971
6124
  Message2["ACQUIRING"] = "acquiring";
@@ -5988,28 +6141,28 @@ var Lock = class {
5988
6141
  });
5989
6142
  try {
5990
6143
  log19("aquiring lock...", void 0, {
5991
- F: __dxlog_file21,
6144
+ F: __dxlog_file22,
5992
6145
  L: 42,
5993
6146
  S: this,
5994
6147
  C: (f, a) => f(...a)
5995
6148
  });
5996
- await asyncTimeout3(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
6149
+ await asyncTimeout2(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
5997
6150
  log19("acquired lock", void 0, {
5998
- F: __dxlog_file21,
6151
+ F: __dxlog_file22,
5999
6152
  L: 44,
6000
6153
  S: this,
6001
6154
  C: (f, a) => f(...a)
6002
6155
  });
6003
6156
  } catch {
6004
6157
  log19("stealing lock...", void 0, {
6005
- F: __dxlog_file21,
6158
+ F: __dxlog_file22,
6006
6159
  L: 46,
6007
6160
  S: this,
6008
6161
  C: (f, a) => f(...a)
6009
6162
  });
6010
6163
  await this._requestLock(true);
6011
6164
  log19("stolen lock", void 0, {
6012
- F: __dxlog_file21,
6165
+ F: __dxlog_file22,
6013
6166
  L: 48,
6014
6167
  S: this,
6015
6168
  C: (f, a) => f(...a)
@@ -6028,7 +6181,7 @@ var Lock = class {
6028
6181
  log19("requesting lock...", {
6029
6182
  steal
6030
6183
  }, {
6031
- F: __dxlog_file21,
6184
+ F: __dxlog_file22,
6032
6185
  L: 63,
6033
6186
  S: this,
6034
6187
  C: (f, a) => f(...a)
@@ -6042,14 +6195,14 @@ var Lock = class {
6042
6195
  this._releaseTrigger = new Trigger9();
6043
6196
  await this._releaseTrigger.wait();
6044
6197
  log19("releasing lock...", void 0, {
6045
- F: __dxlog_file21,
6198
+ F: __dxlog_file22,
6046
6199
  L: 72,
6047
6200
  S: this,
6048
6201
  C: (f, a) => f(...a)
6049
6202
  });
6050
6203
  await this._onRelease?.();
6051
6204
  log19("released lock", void 0, {
6052
- F: __dxlog_file21,
6205
+ F: __dxlog_file22,
6053
6206
  L: 74,
6054
6207
  S: this,
6055
6208
  C: (f, a) => f(...a)
@@ -6061,7 +6214,7 @@ var Lock = class {
6061
6214
  log19("recieved lock", {
6062
6215
  steal
6063
6216
  }, {
6064
- F: __dxlog_file21,
6217
+ F: __dxlog_file22,
6065
6218
  L: 81,
6066
6219
  S: this,
6067
6220
  C: (f, a) => f(...a)
@@ -6149,13 +6302,172 @@ var createLevel = async (config) => {
6149
6302
  return level;
6150
6303
  };
6151
6304
 
6305
+ // packages/sdk/client-services/src/packlets/storage/profile-archive.ts
6306
+ import { cbor } from "@dxos/automerge/automerge-repo";
6307
+ import { invariant as invariant17 } from "@dxos/invariant";
6308
+ import { log as log20 } from "@dxos/log";
6309
+ import { ProfileArchiveEntryType } from "@dxos/protocols";
6310
+ import { arrayToBuffer } from "@dxos/util";
6311
+ var __dxlog_file23 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/storage/profile-archive.ts";
6312
+ var encodeProfileArchive = (profile) => cbor.encode(profile);
6313
+ var decodeProfileArchive = (data) => cbor.decode(data);
6314
+ var exportProfileData = async ({ storage, level }) => {
6315
+ const archive = {
6316
+ storage: [],
6317
+ meta: {
6318
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
6319
+ }
6320
+ };
6321
+ {
6322
+ const directory = await storage.createDirectory();
6323
+ const files = await directory.list();
6324
+ log20.info("begin exporting files", {
6325
+ count: files.length
6326
+ }, {
6327
+ F: __dxlog_file23,
6328
+ L: 30,
6329
+ S: void 0,
6330
+ C: (f, a) => f(...a)
6331
+ });
6332
+ for (const filename of files) {
6333
+ const file = await directory.getOrCreateFile(filename);
6334
+ const { size } = await file.stat();
6335
+ const data = await file.read(0, size);
6336
+ archive.storage.push({
6337
+ type: ProfileArchiveEntryType.FILE,
6338
+ key: filename,
6339
+ value: data
6340
+ });
6341
+ }
6342
+ log20.info("done exporting files", {
6343
+ count: files.length
6344
+ }, {
6345
+ F: __dxlog_file23,
6346
+ L: 41,
6347
+ S: void 0,
6348
+ C: (f, a) => f(...a)
6349
+ });
6350
+ }
6351
+ {
6352
+ log20.info("begin exporting kv pairs", void 0, {
6353
+ F: __dxlog_file23,
6354
+ L: 45,
6355
+ S: void 0,
6356
+ C: (f, a) => f(...a)
6357
+ });
6358
+ const iter = await level.iterator({
6359
+ keyEncoding: "binary",
6360
+ valueEncoding: "binary"
6361
+ });
6362
+ let count = 0;
6363
+ for await (const [key, value] of iter) {
6364
+ archive.storage.push({
6365
+ type: ProfileArchiveEntryType.KEY_VALUE,
6366
+ key,
6367
+ value
6368
+ });
6369
+ count++;
6370
+ }
6371
+ log20.info("done exporting kv pairs", {
6372
+ count
6373
+ }, {
6374
+ F: __dxlog_file23,
6375
+ L: 56,
6376
+ S: void 0,
6377
+ C: (f, a) => f(...a)
6378
+ });
6379
+ }
6380
+ return archive;
6381
+ };
6382
+ var importProfileData = async ({ storage, level }, archive) => {
6383
+ let batch = level.batch();
6384
+ let count = 0;
6385
+ for (const entry2 of archive.storage) {
6386
+ switch (entry2.type) {
6387
+ case ProfileArchiveEntryType.FILE: {
6388
+ const directory = await storage.createDirectory();
6389
+ invariant17(typeof entry2.key === "string", "Invalid key type", {
6390
+ F: __dxlog_file23,
6391
+ L: 79,
6392
+ S: void 0,
6393
+ A: [
6394
+ "typeof entry.key === 'string'",
6395
+ "'Invalid key type'"
6396
+ ]
6397
+ });
6398
+ const file = await directory.getOrCreateFile(entry2.key);
6399
+ invariant17(entry2.value instanceof Uint8Array, "Invalid value type", {
6400
+ F: __dxlog_file23,
6401
+ L: 81,
6402
+ S: void 0,
6403
+ A: [
6404
+ "entry.value instanceof Uint8Array",
6405
+ "'Invalid value type'"
6406
+ ]
6407
+ });
6408
+ await file.write(0, arrayToBuffer(entry2.value));
6409
+ await file.close();
6410
+ break;
6411
+ }
6412
+ case ProfileArchiveEntryType.KEY_VALUE: {
6413
+ invariant17(entry2.key instanceof Uint8Array, "Invalid key type", {
6414
+ F: __dxlog_file23,
6415
+ L: 87,
6416
+ S: void 0,
6417
+ A: [
6418
+ "entry.key instanceof Uint8Array",
6419
+ "'Invalid key type'"
6420
+ ]
6421
+ });
6422
+ invariant17(entry2.value instanceof Uint8Array, "Invalid value type", {
6423
+ F: __dxlog_file23,
6424
+ L: 88,
6425
+ S: void 0,
6426
+ A: [
6427
+ "entry.value instanceof Uint8Array",
6428
+ "'Invalid value type'"
6429
+ ]
6430
+ });
6431
+ batch.put(entry2.key, entry2.value, {
6432
+ keyEncoding: "binary",
6433
+ valueEncoding: "binary"
6434
+ });
6435
+ break;
6436
+ }
6437
+ default:
6438
+ throw new Error(`Invalid entry type: ${entry2.type}`);
6439
+ }
6440
+ if (++count % 1e3 === 0) {
6441
+ await batch.write();
6442
+ batch = level.batch();
6443
+ log20.info("importing", {
6444
+ count,
6445
+ total: archive.storage.length,
6446
+ progress: `${(count / archive.storage.length * 100).toFixed()}%`
6447
+ }, {
6448
+ F: __dxlog_file23,
6449
+ L: 101,
6450
+ S: void 0,
6451
+ C: (f, a) => f(...a)
6452
+ });
6453
+ }
6454
+ }
6455
+ log20.info("committing changes..", void 0, {
6456
+ F: __dxlog_file23,
6457
+ L: 109,
6458
+ S: void 0,
6459
+ C: (f, a) => f(...a)
6460
+ });
6461
+ await batch.write();
6462
+ };
6463
+
6152
6464
  // packages/sdk/client-services/src/packlets/services/service-host.ts
6153
6465
  import { Event as Event9, synchronized as synchronized3 } from "@dxos/async";
6154
6466
  import { clientServiceBundle } from "@dxos/client-protocol";
6155
6467
  import { Context as Context11 } from "@dxos/context";
6156
- import { invariant as invariant18 } from "@dxos/invariant";
6157
- import { PublicKey as PublicKey16 } from "@dxos/keys";
6158
- import { log as log21 } from "@dxos/log";
6468
+ import { invariant as invariant19 } from "@dxos/invariant";
6469
+ import { PublicKey as PublicKey17 } from "@dxos/keys";
6470
+ import { log as log22 } from "@dxos/log";
6159
6471
  import { WebsocketSignalManager } from "@dxos/messaging";
6160
6472
  import { SwarmNetworkManager, createSimplePeerTransportFactory } from "@dxos/network-manager";
6161
6473
  import { trace as trace10 } from "@dxos/protocols";
@@ -6166,9 +6478,9 @@ import { WebsocketRpcClient } from "@dxos/websocket-rpc";
6166
6478
  // packages/sdk/client-services/src/packlets/devices/devices-service.ts
6167
6479
  import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
6168
6480
  import { Stream as Stream11 } from "@dxos/codec-protobuf";
6169
- import { invariant as invariant17 } from "@dxos/invariant";
6481
+ import { invariant as invariant18 } from "@dxos/invariant";
6170
6482
  import { Device as Device2, DeviceKind as DeviceKind2 } from "@dxos/protocols/proto/dxos/client/services";
6171
- var __dxlog_file22 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
6483
+ var __dxlog_file24 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
6172
6484
  var DevicesServiceImpl = class {
6173
6485
  constructor(_identityManager) {
6174
6486
  this._identityManager = _identityManager;
@@ -6185,8 +6497,8 @@ var DevicesServiceImpl = class {
6185
6497
  devices: []
6186
6498
  });
6187
6499
  } else {
6188
- invariant17(this._identityManager.identity?.presence, "presence not present", {
6189
- F: __dxlog_file22,
6500
+ invariant18(this._identityManager.identity?.presence, "presence not present", {
6501
+ F: __dxlog_file24,
6190
6502
  L: 32,
6191
6503
  S: this,
6192
6504
  A: [
@@ -6292,28 +6604,111 @@ var findConfigs = () => {
6292
6604
  return configs.map((r) => r.instance.deref()).filter(nonNullable);
6293
6605
  };
6294
6606
 
6295
- // packages/sdk/client-services/src/packlets/logging/logging-service.ts
6296
- import { Event as Event8 } from "@dxos/async";
6607
+ // packages/sdk/client-services/src/packlets/identity/contacts-service.ts
6608
+ import { EventSubscriptions as EventSubscriptions4, scheduleTask as scheduleTask7, UpdateScheduler as UpdateScheduler2 } from "@dxos/async";
6297
6609
  import { Stream as Stream12 } from "@dxos/codec-protobuf";
6298
6610
  import { PublicKey as PublicKey15 } from "@dxos/keys";
6299
- import { getContextFromEntry, log as log20 } from "@dxos/log";
6611
+ import { ComplexMap as ComplexMap4, ComplexSet as ComplexSet6 } from "@dxos/util";
6612
+ var ContactsServiceImpl = class {
6613
+ constructor(_identityManager, _spaceManager, _dataSpaceManagerProvider) {
6614
+ this._identityManager = _identityManager;
6615
+ this._spaceManager = _spaceManager;
6616
+ this._dataSpaceManagerProvider = _dataSpaceManagerProvider;
6617
+ }
6618
+ async getContacts() {
6619
+ const identity = this._identityManager.identity;
6620
+ if (identity == null) {
6621
+ return {
6622
+ contacts: []
6623
+ };
6624
+ }
6625
+ const contacts = [
6626
+ ...this._spaceManager.spaces.values()
6627
+ ].flatMap((s) => [
6628
+ ...s.spaceState.members.values()
6629
+ ].map((m) => [
6630
+ s.key,
6631
+ m
6632
+ ])).reduce((acc, v) => {
6633
+ const [spaceKey, memberInfo] = v;
6634
+ if (memberInfo.key.equals(identity.identityKey)) {
6635
+ return acc;
6636
+ }
6637
+ const existing = acc.get(memberInfo.key);
6638
+ if (existing != null) {
6639
+ existing.profile ??= memberInfo.profile;
6640
+ existing.commonSpaces?.push(spaceKey);
6641
+ } else {
6642
+ acc.set(memberInfo.key, {
6643
+ identityKey: memberInfo.key,
6644
+ profile: memberInfo.profile,
6645
+ commonSpaces: [
6646
+ spaceKey
6647
+ ]
6648
+ });
6649
+ }
6650
+ return acc;
6651
+ }, new ComplexMap4(PublicKey15.hash));
6652
+ return {
6653
+ contacts: [
6654
+ ...contacts.values()
6655
+ ]
6656
+ };
6657
+ }
6658
+ queryContacts() {
6659
+ const subscribedSpaceKeySet = new ComplexSet6(PublicKey15.hash);
6660
+ return new Stream12(({ next, ctx }) => {
6661
+ const pushUpdateTask = new UpdateScheduler2(ctx, async () => {
6662
+ const contacts = await this.getContacts();
6663
+ next(contacts);
6664
+ }, {
6665
+ maxFrequency: 2
6666
+ });
6667
+ scheduleTask7(ctx, async () => {
6668
+ const subscriptions = new EventSubscriptions4();
6669
+ ctx.onDispose(() => subscriptions.clear());
6670
+ const subscribeToSpaceAndUpdate = () => {
6671
+ const oldSetSize = subscribedSpaceKeySet.size;
6672
+ for (const space of this._spaceManager.spaces.values()) {
6673
+ if (!subscribedSpaceKeySet.has(space.key)) {
6674
+ subscriptions.add(space.stateUpdate.on(ctx, () => pushUpdateTask.trigger()));
6675
+ subscribedSpaceKeySet.add(space.key);
6676
+ }
6677
+ }
6678
+ if (oldSetSize !== subscribedSpaceKeySet.size) {
6679
+ pushUpdateTask.trigger();
6680
+ }
6681
+ };
6682
+ const unsubscribe = (await this._dataSpaceManagerProvider()).updated.on(ctx, subscribeToSpaceAndUpdate);
6683
+ ctx.onDispose(unsubscribe);
6684
+ subscribeToSpaceAndUpdate();
6685
+ });
6686
+ });
6687
+ }
6688
+ };
6689
+
6690
+ // packages/sdk/client-services/src/packlets/logging/logging-service.ts
6691
+ import { Event as Event8 } from "@dxos/async";
6692
+ import { Stream as Stream13 } from "@dxos/codec-protobuf";
6693
+ import { PublicKey as PublicKey16 } from "@dxos/keys";
6694
+ import { getContextFromEntry, log as log21 } from "@dxos/log";
6300
6695
  import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
6301
6696
  import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
6302
6697
  var LoggingServiceImpl = class {
6303
6698
  constructor() {
6304
6699
  this._logs = new Event8();
6305
6700
  this._started = Date.now();
6306
- this._sessionId = PublicKey15.random().toHex();
6701
+ this._sessionId = PublicKey16.random().toHex();
6307
6702
  this._logProcessor = (_config, entry2) => {
6308
6703
  this._logs.emit(entry2);
6309
6704
  };
6310
6705
  }
6311
6706
  async open() {
6312
- log20.runtimeConfig.processors.push(this._logProcessor);
6707
+ log21.runtimeConfig.processors.push(this._logProcessor);
6313
6708
  }
6314
6709
  async close() {
6315
- const index = log20.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
6316
- log20.runtimeConfig.processors.splice(index, 1);
6710
+ const index = log21.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
6711
+ log21.runtimeConfig.processors.splice(index, 1);
6317
6712
  }
6318
6713
  async controlMetrics({ reset, record }) {
6319
6714
  if (reset) {
@@ -6339,7 +6734,7 @@ var LoggingServiceImpl = class {
6339
6734
  stats: numericalValues(events, "duration")
6340
6735
  };
6341
6736
  };
6342
- return new Stream12(({ next }) => {
6737
+ return new Stream13(({ next }) => {
6343
6738
  const update = () => {
6344
6739
  const metrics = {
6345
6740
  timestamp: /* @__PURE__ */ new Date(),
@@ -6361,7 +6756,7 @@ var LoggingServiceImpl = class {
6361
6756
  });
6362
6757
  }
6363
6758
  queryLogs(request) {
6364
- return new Stream12(({ ctx, next }) => {
6759
+ return new Stream13(({ ctx, next }) => {
6365
6760
  const handler = (entry2) => {
6366
6761
  if (LOG_PROCESSING > 0) {
6367
6762
  return;
@@ -6417,14 +6812,14 @@ var shouldLog = (entry2, request) => {
6417
6812
  var LOG_PROCESSING = 0;
6418
6813
 
6419
6814
  // packages/sdk/client-services/src/packlets/network/network-service.ts
6420
- import { Stream as Stream13 } from "@dxos/codec-protobuf";
6815
+ import { Stream as Stream14 } from "@dxos/codec-protobuf";
6421
6816
  var NetworkServiceImpl = class {
6422
6817
  constructor(networkManager, signalManager) {
6423
6818
  this.networkManager = networkManager;
6424
6819
  this.signalManager = signalManager;
6425
6820
  }
6426
6821
  queryStatus() {
6427
- return new Stream13(({ next }) => {
6822
+ return new Stream14(({ next }) => {
6428
6823
  const update = () => {
6429
6824
  next({
6430
6825
  swarm: this.networkManager.connectionState,
@@ -6450,7 +6845,7 @@ var NetworkServiceImpl = class {
6450
6845
  };
6451
6846
 
6452
6847
  // packages/sdk/client-services/src/packlets/system/system-service.ts
6453
- import { Stream as Stream14 } from "@dxos/codec-protobuf";
6848
+ import { Stream as Stream15 } from "@dxos/codec-protobuf";
6454
6849
  import { GetDiagnosticsRequest as GetDiagnosticsRequest2 } from "@dxos/protocols/proto/dxos/client/services";
6455
6850
  import { jsonKeyReplacer as jsonKeyReplacer2 } from "@dxos/util";
6456
6851
  var SystemServiceImpl = class {
@@ -6486,7 +6881,7 @@ var SystemServiceImpl = class {
6486
6881
  }
6487
6882
  // TODO(burdon): Standardize interval option in stream request?
6488
6883
  queryStatus({ interval = 3e3 } = {}) {
6489
- return new Stream14(({ next }) => {
6884
+ return new Stream15(({ next }) => {
6490
6885
  const update = () => {
6491
6886
  next({
6492
6887
  status: this._getCurrentStatus()
@@ -6517,7 +6912,7 @@ function _ts_decorate8(decorators, target, key, desc) {
6517
6912
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6518
6913
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6519
6914
  }
6520
- var __dxlog_file23 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
6915
+ var __dxlog_file25 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
6521
6916
  var ClientServicesHost = class {
6522
6917
  constructor({
6523
6918
  config,
@@ -6550,7 +6945,10 @@ var ClientServicesHost = class {
6550
6945
  lockKey,
6551
6946
  onAcquire: () => {
6552
6947
  if (!this._opening) {
6553
- void this.open(new Context11());
6948
+ void this.open(new Context11(void 0, {
6949
+ F: __dxlog_file25,
6950
+ L: 121
6951
+ }));
6554
6952
  }
6555
6953
  },
6556
6954
  onRelease: () => this.close()
@@ -6605,25 +7003,25 @@ var ClientServicesHost = class {
6605
7003
  * Can only be called once.
6606
7004
  */
6607
7005
  initialize({ config, ...options }) {
6608
- invariant18(!this._open, "service host is open", {
6609
- F: __dxlog_file23,
6610
- L: 186,
7006
+ invariant19(!this._open, "service host is open", {
7007
+ F: __dxlog_file25,
7008
+ L: 187,
6611
7009
  S: this,
6612
7010
  A: [
6613
7011
  "!this._open",
6614
7012
  "'service host is open'"
6615
7013
  ]
6616
7014
  });
6617
- log21("initializing...", void 0, {
6618
- F: __dxlog_file23,
6619
- L: 187,
7015
+ log22("initializing...", void 0, {
7016
+ F: __dxlog_file25,
7017
+ L: 188,
6620
7018
  S: this,
6621
7019
  C: (f, a) => f(...a)
6622
7020
  });
6623
7021
  if (config) {
6624
- invariant18(!this._config, "config already set", {
6625
- F: __dxlog_file23,
6626
- L: 190,
7022
+ invariant19(!this._config, "config already set", {
7023
+ F: __dxlog_file25,
7024
+ L: 191,
6627
7025
  S: this,
6628
7026
  A: [
6629
7027
  "!this._config",
@@ -6636,9 +7034,9 @@ var ClientServicesHost = class {
6636
7034
  }
6637
7035
  }
6638
7036
  if (!options.signalManager) {
6639
- log21.warn("running signaling without telemetry metadata.", void 0, {
6640
- F: __dxlog_file23,
6641
- L: 198,
7037
+ log22.warn("running signaling without telemetry metadata.", void 0, {
7038
+ F: __dxlog_file25,
7039
+ L: 199,
6642
7040
  S: this,
6643
7041
  C: (f, a) => f(...a)
6644
7042
  });
@@ -6647,9 +7045,9 @@ var ClientServicesHost = class {
6647
7045
  iceServers: this._config?.get("runtime.services.ice")
6648
7046
  }), signalManager = new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
6649
7047
  this._signalManager = signalManager;
6650
- invariant18(!this._networkManager, "network manager already set", {
6651
- F: __dxlog_file23,
6652
- L: 209,
7048
+ invariant19(!this._networkManager, "network manager already set", {
7049
+ F: __dxlog_file25,
7050
+ L: 210,
6653
7051
  S: this,
6654
7052
  A: [
6655
7053
  "!this._networkManager",
@@ -6661,9 +7059,9 @@ var ClientServicesHost = class {
6661
7059
  transportFactory,
6662
7060
  signalManager
6663
7061
  });
6664
- log21("initialized", void 0, {
6665
- F: __dxlog_file23,
6666
- L: 216,
7062
+ log22("initialized", void 0, {
7063
+ F: __dxlog_file25,
7064
+ L: 217,
6667
7065
  S: this,
6668
7066
  C: (f, a) => f(...a)
6669
7067
  });
@@ -6672,45 +7070,45 @@ var ClientServicesHost = class {
6672
7070
  if (this._open) {
6673
7071
  return;
6674
7072
  }
6675
- const traceId = PublicKey16.random().toHex();
6676
- log21.trace("dxos.client-services.host.open", trace10.begin({
7073
+ const traceId = PublicKey17.random().toHex();
7074
+ log22.trace("dxos.client-services.host.open", trace10.begin({
6677
7075
  id: traceId
6678
7076
  }), {
6679
- F: __dxlog_file23,
6680
- L: 227,
7077
+ F: __dxlog_file25,
7078
+ L: 228,
6681
7079
  S: this,
6682
7080
  C: (f, a) => f(...a)
6683
7081
  });
6684
- invariant18(this._config, "config not set", {
6685
- F: __dxlog_file23,
6686
- L: 229,
7082
+ invariant19(this._config, "config not set", {
7083
+ F: __dxlog_file25,
7084
+ L: 230,
6687
7085
  S: this,
6688
7086
  A: [
6689
7087
  "this._config",
6690
7088
  "'config not set'"
6691
7089
  ]
6692
7090
  });
6693
- invariant18(this._storage, "storage not set", {
6694
- F: __dxlog_file23,
6695
- L: 230,
7091
+ invariant19(this._storage, "storage not set", {
7092
+ F: __dxlog_file25,
7093
+ L: 231,
6696
7094
  S: this,
6697
7095
  A: [
6698
7096
  "this._storage",
6699
7097
  "'storage not set'"
6700
7098
  ]
6701
7099
  });
6702
- invariant18(this._signalManager, "signal manager not set", {
6703
- F: __dxlog_file23,
6704
- L: 231,
7100
+ invariant19(this._signalManager, "signal manager not set", {
7101
+ F: __dxlog_file25,
7102
+ L: 232,
6705
7103
  S: this,
6706
7104
  A: [
6707
7105
  "this._signalManager",
6708
7106
  "'signal manager not set'"
6709
7107
  ]
6710
7108
  });
6711
- invariant18(this._networkManager, "network manager not set", {
6712
- F: __dxlog_file23,
6713
- L: 232,
7109
+ invariant19(this._networkManager, "network manager not set", {
7110
+ F: __dxlog_file25,
7111
+ L: 233,
6714
7112
  S: this,
6715
7113
  A: [
6716
7114
  "this._networkManager",
@@ -6718,11 +7116,11 @@ var ClientServicesHost = class {
6718
7116
  ]
6719
7117
  });
6720
7118
  this._opening = true;
6721
- log21("opening...", {
7119
+ log22("opening...", {
6722
7120
  lockKey: this._resourceLock?.lockKey
6723
7121
  }, {
6724
- F: __dxlog_file23,
6725
- L: 235,
7122
+ F: __dxlog_file25,
7123
+ L: 236,
6726
7124
  S: this,
6727
7125
  C: (f, a) => f(...a)
6728
7126
  });
@@ -6733,16 +7131,18 @@ var ClientServicesHost = class {
6733
7131
  await this._level.open();
6734
7132
  await this._loggingService.open();
6735
7133
  this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._runtimeParams);
7134
+ const dataSpaceManagerProvider = async () => {
7135
+ await this._serviceContext.initialized.wait();
7136
+ return this._serviceContext.dataSpaceManager;
7137
+ };
6736
7138
  const identityService = new IdentityServiceImpl(this._serviceContext.identityManager, this._serviceContext.keyring, () => this._serviceContext.dataSpaceManager, (params) => this._createIdentity(params), (profile) => this._serviceContext.broadcastProfileUpdate(profile));
6737
7139
  this._serviceRegistry.setServices({
6738
7140
  SystemService: this._systemService,
6739
7141
  IdentityService: identityService,
7142
+ ContactsService: new ContactsServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, dataSpaceManagerProvider),
6740
7143
  InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitationsManager),
6741
7144
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
6742
- SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, async () => {
6743
- await this._serviceContext.initialized.wait();
6744
- return this._serviceContext.dataSpaceManager;
6745
- }),
7145
+ SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, dataSpaceManagerProvider),
6746
7146
  DataService: this._serviceContext.echoHost.dataService,
6747
7147
  QueryService: this._serviceContext.echoHost.queryService,
6748
7148
  NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager, this._serviceContext.signalManager),
@@ -6772,19 +7172,19 @@ var ClientServicesHost = class {
6772
7172
  this._open = true;
6773
7173
  this._statusUpdate.emit();
6774
7174
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
6775
- log21("opened", {
7175
+ log22("opened", {
6776
7176
  deviceKey
6777
7177
  }, {
6778
- F: __dxlog_file23,
6779
- L: 314,
7178
+ F: __dxlog_file25,
7179
+ L: 322,
6780
7180
  S: this,
6781
7181
  C: (f, a) => f(...a)
6782
7182
  });
6783
- log21.trace("dxos.client-services.host.open", trace10.end({
7183
+ log22.trace("dxos.client-services.host.open", trace10.end({
6784
7184
  id: traceId
6785
7185
  }), {
6786
- F: __dxlog_file23,
6787
- L: 315,
7186
+ F: __dxlog_file25,
7187
+ L: 323,
6788
7188
  S: this,
6789
7189
  C: (f, a) => f(...a)
6790
7190
  });
@@ -6794,11 +7194,11 @@ var ClientServicesHost = class {
6794
7194
  return;
6795
7195
  }
6796
7196
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
6797
- log21("closing...", {
7197
+ log22("closing...", {
6798
7198
  deviceKey
6799
7199
  }, {
6800
- F: __dxlog_file23,
6801
- L: 326,
7200
+ F: __dxlog_file25,
7201
+ L: 334,
6802
7202
  S: this,
6803
7203
  C: (f, a) => f(...a)
6804
7204
  });
@@ -6812,44 +7212,44 @@ var ClientServicesHost = class {
6812
7212
  await this._level?.close();
6813
7213
  this._open = false;
6814
7214
  this._statusUpdate.emit();
6815
- log21("closed", {
7215
+ log22("closed", {
6816
7216
  deviceKey
6817
7217
  }, {
6818
- F: __dxlog_file23,
6819
- L: 335,
7218
+ F: __dxlog_file25,
7219
+ L: 343,
6820
7220
  S: this,
6821
7221
  C: (f, a) => f(...a)
6822
7222
  });
6823
7223
  }
6824
7224
  async reset() {
6825
- const traceId = PublicKey16.random().toHex();
6826
- log21.trace("dxos.sdk.client-services-host.reset", trace10.begin({
7225
+ const traceId = PublicKey17.random().toHex();
7226
+ log22.trace("dxos.sdk.client-services-host.reset", trace10.begin({
6827
7227
  id: traceId
6828
7228
  }), {
6829
- F: __dxlog_file23,
6830
- L: 340,
7229
+ F: __dxlog_file25,
7230
+ L: 348,
6831
7231
  S: this,
6832
7232
  C: (f, a) => f(...a)
6833
7233
  });
6834
- log21.info("resetting...", void 0, {
6835
- F: __dxlog_file23,
6836
- L: 342,
7234
+ log22.info("resetting...", void 0, {
7235
+ F: __dxlog_file25,
7236
+ L: 350,
6837
7237
  S: this,
6838
7238
  C: (f, a) => f(...a)
6839
7239
  });
6840
7240
  await this._serviceContext?.close();
6841
7241
  await this._storage.reset();
6842
- log21.info("reset", void 0, {
6843
- F: __dxlog_file23,
6844
- L: 345,
7242
+ log22.info("reset", void 0, {
7243
+ F: __dxlog_file25,
7244
+ L: 353,
6845
7245
  S: this,
6846
7246
  C: (f, a) => f(...a)
6847
7247
  });
6848
- log21.trace("dxos.sdk.client-services-host.reset", trace10.end({
7248
+ log22.trace("dxos.sdk.client-services-host.reset", trace10.end({
6849
7249
  id: traceId
6850
7250
  }), {
6851
- F: __dxlog_file23,
6852
- L: 346,
7251
+ F: __dxlog_file25,
7252
+ L: 354,
6853
7253
  S: this,
6854
7254
  C: (f, a) => f(...a)
6855
7255
  });
@@ -6915,8 +7315,12 @@ export {
6915
7315
  isLocked,
6916
7316
  createStorageObjects,
6917
7317
  createLevel,
7318
+ encodeProfileArchive,
7319
+ decodeProfileArchive,
7320
+ exportProfileData,
7321
+ importProfileData,
6918
7322
  ClientServicesHost,
6919
7323
  ClientServicesProviderResource,
6920
7324
  DiagnosticsCollector
6921
7325
  };
6922
- //# sourceMappingURL=chunk-2JCI5YEM.mjs.map
7326
+ //# sourceMappingURL=chunk-PA5DAU64.mjs.map