@dxos/client-services 0.5.9-main.a2de4fa → 0.5.9-main.a75fa71

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 (46) hide show
  1. package/dist/lib/browser/{chunk-7ZORW75D.mjs → chunk-DS5JZ6S4.mjs} +915 -520
  2. package/dist/lib/browser/chunk-DS5JZ6S4.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-VQ7KZOFD.cjs → chunk-NJ63ESAV.cjs} +950 -555
  9. package/dist/lib/node/chunk-NJ63ESAV.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/invitations-handler.d.ts.map +1 -1
  19. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  20. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  21. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +10 -1
  22. package/dist/types/src/packlets/spaces/data-space-manager.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/invitations-handler.ts +13 -5
  36. package/src/packlets/invitations/space-invitation-protocol.ts +11 -32
  37. package/src/packlets/services/service-host.ts +12 -4
  38. package/src/packlets/spaces/data-space-manager.ts +55 -2
  39. package/src/packlets/spaces/data-space.ts +1 -1
  40. package/src/packlets/spaces/epoch-migrations.ts +57 -38
  41. package/src/packlets/spaces/spaces-service.ts +38 -0
  42. package/src/packlets/storage/index.ts +1 -0
  43. package/src/packlets/storage/profile-archive.ts +97 -0
  44. package/src/version.ts +1 -1
  45. package/dist/lib/browser/chunk-7ZORW75D.mjs.map +0 -7
  46. package/dist/lib/node/chunk-VQ7KZOFD.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.a2de4fa";
362
+ var DXOS_VERSION = "0.5.9-main.a75fa71";
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: [
@@ -2859,16 +2888,29 @@ var InvitationsHandler = class {
2859
2888
  };
2860
2889
  }
2861
2890
  _logStateUpdate(invitation, actor, newState) {
2862
- log10("invitation state update", {
2863
- actor: actor?.constructor.name,
2864
- newState: stateToString(newState),
2865
- oldState: stateToString(invitation.state)
2866
- }, {
2867
- F: __dxlog_file12,
2868
- L: 438,
2869
- S: this,
2870
- C: (f, a) => f(...a)
2871
- });
2891
+ if (this._isNotTerminal(newState)) {
2892
+ log10("invitation state update", {
2893
+ actor: actor?.constructor.name,
2894
+ newState: stateToString(newState),
2895
+ oldState: stateToString(invitation.state)
2896
+ }, {
2897
+ F: __dxlog_file13,
2898
+ L: 439,
2899
+ S: this,
2900
+ C: (f, a) => f(...a)
2901
+ });
2902
+ } else {
2903
+ log10.info("invitation state update", {
2904
+ actor: actor?.constructor.name,
2905
+ newState: stateToString(newState),
2906
+ oldState: stateToString(invitation.state)
2907
+ }, {
2908
+ F: __dxlog_file13,
2909
+ L: 445,
2910
+ S: this,
2911
+ C: (f, a) => f(...a)
2912
+ });
2913
+ }
2872
2914
  }
2873
2915
  _isNotTerminal(currentState) {
2874
2916
  return ![
@@ -2882,16 +2924,16 @@ var InvitationsHandler = class {
2882
2924
  async _handleGuestOtpAuth(extension, setState, authenticated, options) {
2883
2925
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2884
2926
  log10("guest waiting for authentication code...", void 0, {
2885
- F: __dxlog_file12,
2886
- L: 462,
2927
+ F: __dxlog_file13,
2928
+ L: 470,
2887
2929
  S: this,
2888
2930
  C: (f, a) => f(...a)
2889
2931
  });
2890
2932
  setState(Invitation4.State.READY_FOR_AUTHENTICATION);
2891
2933
  const authCode = await authenticated.wait(options);
2892
2934
  log10("sending authentication request", void 0, {
2893
- F: __dxlog_file12,
2894
- L: 466,
2935
+ F: __dxlog_file13,
2936
+ L: 474,
2895
2937
  S: this,
2896
2938
  C: (f, a) => f(...a)
2897
2939
  });
@@ -2909,8 +2951,8 @@ var InvitationsHandler = class {
2909
2951
  log10("retrying invalid code", {
2910
2952
  attempt
2911
2953
  }, {
2912
- F: __dxlog_file12,
2913
- L: 477,
2954
+ F: __dxlog_file13,
2955
+ L: 485,
2914
2956
  S: this,
2915
2957
  C: (f, a) => f(...a)
2916
2958
  });
@@ -2927,8 +2969,8 @@ var InvitationsHandler = class {
2927
2969
  throw new Error("challenge missing in the introduction");
2928
2970
  }
2929
2971
  log10("sending authentication request", void 0, {
2930
- F: __dxlog_file12,
2931
- L: 496,
2972
+ F: __dxlog_file13,
2973
+ L: 504,
2932
2974
  S: this,
2933
2975
  C: (f, a) => f(...a)
2934
2976
  });
@@ -3048,14 +3090,14 @@ var InvitationsServiceImpl = class {
3048
3090
  };
3049
3091
 
3050
3092
  // packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts
3051
- import { createAdmissionCredentials, createCancelDelegatedSpaceInvitationCredential, createDelegatedSpaceInvitationCredential, getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
3093
+ import { createCancelDelegatedSpaceInvitationCredential, createDelegatedSpaceInvitationCredential, getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
3052
3094
  import { writeMessages as writeMessages2 } from "@dxos/feed-store";
3053
3095
  import { invariant as invariant10 } from "@dxos/invariant";
3054
3096
  import { log as log11 } from "@dxos/log";
3055
3097
  import { AlreadyJoinedError as AlreadyJoinedError2, AuthorizationError, InvalidInvitationError, SpaceNotFoundError } from "@dxos/protocols";
3056
3098
  import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
3057
3099
  import { SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/halo/credentials";
3058
- 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";
3059
3101
  var SpaceInvitationProtocol = class {
3060
3102
  constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
3061
3103
  this._spaceManager = _spaceManager;
@@ -3089,79 +3131,43 @@ var SpaceInvitationProtocol = class {
3089
3131
  };
3090
3132
  }
3091
3133
  async admit(invitation, request, guestProfile) {
3092
- invariant10(this._spaceKey, void 0, {
3093
- F: __dxlog_file13,
3094
- L: 76,
3095
- S: this,
3096
- A: [
3097
- "this._spaceKey",
3098
- ""
3099
- ]
3100
- });
3101
- const space = this._spaceManager.spaces.get(this._spaceKey);
3102
- invariant10(space, void 0, {
3103
- F: __dxlog_file13,
3104
- L: 78,
3105
- S: this,
3106
- A: [
3107
- "space",
3108
- ""
3109
- ]
3110
- });
3111
- invariant10(request.space, void 0, {
3112
- F: __dxlog_file13,
3113
- L: 80,
3134
+ invariant10(this._spaceKey && request.space, void 0, {
3135
+ F: __dxlog_file14,
3136
+ L: 74,
3114
3137
  S: this,
3115
3138
  A: [
3116
- "request.space",
3139
+ "this._spaceKey && request.space",
3117
3140
  ""
3118
3141
  ]
3119
3142
  });
3120
- const { identityKey, deviceKey } = request.space;
3121
- if (space.inner.spaceState.getMemberRole(identityKey) !== SpaceMember2.Role.REMOVED) {
3122
- throw new AlreadyJoinedError2();
3123
- }
3124
3143
  log11("writing guest credentials", {
3125
3144
  host: this._signingContext.deviceKey,
3126
- guest: deviceKey
3145
+ guest: request.space.deviceKey
3127
3146
  }, {
3128
- F: __dxlog_file13,
3129
- L: 87,
3147
+ F: __dxlog_file14,
3148
+ L: 75,
3130
3149
  S: this,
3131
3150
  C: (f, a) => f(...a)
3132
3151
  });
3133
- const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, invitation.role ?? SpaceMember2.Role.ADMIN, space.inner.spaceState.membershipChainHeads, guestProfile, invitation.delegationCredentialId);
3134
- invariant10(credentials[0].credential, void 0, {
3135
- F: __dxlog_file13,
3136
- L: 101,
3137
- S: this,
3138
- A: [
3139
- "credentials[0].credential",
3140
- ""
3141
- ]
3142
- });
3143
- const spaceMemberCredential = credentials[0].credential.credential;
3144
- invariant10(getCredentialAssertion2(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3145
- F: __dxlog_file13,
3146
- L: 103,
3147
- S: this,
3148
- A: [
3149
- "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
3150
- ""
3151
- ]
3152
+ const spaceMemberCredential = await this._spaceManager.admitMember({
3153
+ spaceKey: this._spaceKey,
3154
+ identityKey: request.space.identityKey,
3155
+ role: invitation.role ?? SpaceMember2.Role.ADMIN,
3156
+ profile: guestProfile,
3157
+ delegationCredentialId: invitation.delegationCredentialId
3152
3158
  });
3153
- await writeMessages2(space.inner.controlPipeline.writer, credentials);
3159
+ const space = this._spaceManager.spaces.get(this._spaceKey);
3154
3160
  return {
3155
3161
  space: {
3156
3162
  credential: spaceMemberCredential,
3157
- controlTimeframe: space.inner.controlPipeline.state.timeframe
3163
+ controlTimeframe: space?.inner.controlPipeline.state.timeframe
3158
3164
  }
3159
3165
  };
3160
3166
  }
3161
3167
  async delegate(invitation) {
3162
3168
  invariant10(this._spaceKey, void 0, {
3163
- F: __dxlog_file13,
3164
- L: 116,
3169
+ F: __dxlog_file14,
3170
+ L: 95,
3165
3171
  S: this,
3166
3172
  A: [
3167
3173
  "this._spaceKey",
@@ -3170,8 +3176,8 @@ var SpaceInvitationProtocol = class {
3170
3176
  });
3171
3177
  const space = this._spaceManager.spaces.get(this._spaceKey);
3172
3178
  invariant10(space, void 0, {
3173
- F: __dxlog_file13,
3174
- L: 118,
3179
+ F: __dxlog_file14,
3180
+ L: 97,
3175
3181
  S: this,
3176
3182
  A: [
3177
3183
  "space",
@@ -3180,8 +3186,8 @@ var SpaceInvitationProtocol = class {
3180
3186
  });
3181
3187
  if (invitation.authMethod === Invitation5.AuthMethod.KNOWN_PUBLIC_KEY) {
3182
3188
  invariant10(invitation.guestKeypair?.publicKey, void 0, {
3183
- F: __dxlog_file13,
3184
- L: 120,
3189
+ F: __dxlog_file14,
3190
+ L: 99,
3185
3191
  S: this,
3186
3192
  A: [
3187
3193
  "invitation.guestKeypair?.publicKey",
@@ -3193,8 +3199,8 @@ var SpaceInvitationProtocol = class {
3193
3199
  host: this._signingContext.deviceKey,
3194
3200
  id: invitation.invitationId
3195
3201
  }, {
3196
- F: __dxlog_file13,
3197
- L: 123,
3202
+ F: __dxlog_file14,
3203
+ L: 102,
3198
3204
  S: this,
3199
3205
  C: (f, a) => f(...a)
3200
3206
  });
@@ -3208,8 +3214,8 @@ var SpaceInvitationProtocol = class {
3208
3214
  guestKey: invitation.authMethod === Invitation5.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
3209
3215
  });
3210
3216
  invariant10(credential.credential, void 0, {
3211
- F: __dxlog_file13,
3212
- L: 143,
3217
+ F: __dxlog_file14,
3218
+ L: 122,
3213
3219
  S: this,
3214
3220
  A: [
3215
3221
  "credential.credential",
@@ -3223,8 +3229,8 @@ var SpaceInvitationProtocol = class {
3223
3229
  }
3224
3230
  async cancelDelegation(invitation) {
3225
3231
  invariant10(this._spaceKey, void 0, {
3226
- F: __dxlog_file13,
3227
- L: 149,
3232
+ F: __dxlog_file14,
3233
+ L: 128,
3228
3234
  S: this,
3229
3235
  A: [
3230
3236
  "this._spaceKey",
@@ -3232,8 +3238,8 @@ var SpaceInvitationProtocol = class {
3232
3238
  ]
3233
3239
  });
3234
3240
  invariant10(invitation.type === Invitation5.Type.DELEGATED && invitation.delegationCredentialId, void 0, {
3235
- F: __dxlog_file13,
3236
- L: 150,
3241
+ F: __dxlog_file14,
3242
+ L: 129,
3237
3243
  S: this,
3238
3244
  A: [
3239
3245
  "invitation.type === Invitation.Type.DELEGATED && invitation.delegationCredentialId",
@@ -3242,8 +3248,8 @@ var SpaceInvitationProtocol = class {
3242
3248
  });
3243
3249
  const space = this._spaceManager.spaces.get(this._spaceKey);
3244
3250
  invariant10(space, void 0, {
3245
- F: __dxlog_file13,
3246
- L: 152,
3251
+ F: __dxlog_file14,
3252
+ L: 131,
3247
3253
  S: this,
3248
3254
  A: [
3249
3255
  "space",
@@ -3254,15 +3260,15 @@ var SpaceInvitationProtocol = class {
3254
3260
  host: this._signingContext.deviceKey,
3255
3261
  id: invitation.invitationId
3256
3262
  }, {
3257
- F: __dxlog_file13,
3258
- L: 154,
3263
+ F: __dxlog_file14,
3264
+ L: 133,
3259
3265
  S: this,
3260
3266
  C: (f, a) => f(...a)
3261
3267
  });
3262
3268
  const credential = await createCancelDelegatedSpaceInvitationCredential(this._signingContext.credentialSigner, space.key, invitation.delegationCredentialId);
3263
3269
  invariant10(credential.credential, void 0, {
3264
- F: __dxlog_file13,
3265
- L: 161,
3270
+ F: __dxlog_file14,
3271
+ L: 140,
3266
3272
  S: this,
3267
3273
  A: [
3268
3274
  "credential.credential",
@@ -3300,8 +3306,8 @@ var SpaceInvitationProtocol = class {
3300
3306
  }
3301
3307
  async accept(response) {
3302
3308
  invariant10(response.space, void 0, {
3303
- F: __dxlog_file13,
3304
- L: 196,
3309
+ F: __dxlog_file14,
3310
+ L: 175,
3305
3311
  S: this,
3306
3312
  A: [
3307
3313
  "response.space",
@@ -3311,8 +3317,8 @@ var SpaceInvitationProtocol = class {
3311
3317
  const { credential, controlTimeframe, dataTimeframe } = response.space;
3312
3318
  const assertion = getCredentialAssertion2(credential);
3313
3319
  invariant10(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
3314
- F: __dxlog_file13,
3315
- L: 199,
3320
+ F: __dxlog_file14,
3321
+ L: 178,
3316
3322
  S: this,
3317
3323
  A: [
3318
3324
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -3320,8 +3326,8 @@ var SpaceInvitationProtocol = class {
3320
3326
  ]
3321
3327
  });
3322
3328
  invariant10(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
3323
- F: __dxlog_file13,
3324
- L: 200,
3329
+ F: __dxlog_file14,
3330
+ L: 179,
3325
3331
  S: this,
3326
3332
  A: [
3327
3333
  "credential.subject.id.equals(this._signingContext.identityKey)",
@@ -3355,7 +3361,7 @@ import { PublicKey as PublicKey8 } from "@dxos/keys";
3355
3361
  import { log as log12 } from "@dxos/log";
3356
3362
  import { Invitation as Invitation6 } from "@dxos/protocols/proto/dxos/client/services";
3357
3363
  import { SpaceMember as SpaceMember3 } from "@dxos/protocols/proto/dxos/halo/credentials";
3358
- 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";
3359
3365
  var InvitationsManager = class {
3360
3366
  constructor(_invitationsHandler, _getHandler, _metadataStore) {
3361
3367
  this._invitationsHandler = _invitationsHandler;
@@ -3398,7 +3404,7 @@ var InvitationsManager = class {
3398
3404
  await this._persistIfRequired(handler, stream, invitation);
3399
3405
  } catch (err) {
3400
3406
  log12.catch(err, void 0, {
3401
- F: __dxlog_file14,
3407
+ F: __dxlog_file15,
3402
3408
  L: 82,
3403
3409
  S: this,
3404
3410
  C: (f, a) => f(...a)
@@ -3421,7 +3427,7 @@ var InvitationsManager = class {
3421
3427
  const freshInvitations = persistentInvitations.filter((invitation) => !hasInvitationExpired(invitation));
3422
3428
  const loadTasks = freshInvitations.map((persistentInvitation) => {
3423
3429
  invariant11(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
3424
- F: __dxlog_file14,
3430
+ F: __dxlog_file15,
3425
3431
  L: 103,
3426
3432
  S: this,
3427
3433
  A: [
@@ -3440,7 +3446,7 @@ var InvitationsManager = class {
3440
3446
  };
3441
3447
  } catch (err) {
3442
3448
  log12.catch(err, void 0, {
3443
- F: __dxlog_file14,
3449
+ F: __dxlog_file15,
3444
3450
  L: 110,
3445
3451
  S: this,
3446
3452
  C: (f, a) => f(...a)
@@ -3472,13 +3478,13 @@ var InvitationsManager = class {
3472
3478
  }
3473
3479
  async authenticate({ invitationId, authCode }) {
3474
3480
  log12("authenticating...", void 0, {
3475
- F: __dxlog_file14,
3481
+ F: __dxlog_file15,
3476
3482
  L: 140,
3477
3483
  S: this,
3478
3484
  C: (f, a) => f(...a)
3479
3485
  });
3480
3486
  invariant11(invitationId, void 0, {
3481
- F: __dxlog_file14,
3487
+ F: __dxlog_file15,
3482
3488
  L: 141,
3483
3489
  S: this,
3484
3490
  A: [
@@ -3491,7 +3497,7 @@ var InvitationsManager = class {
3491
3497
  log12.warn("invalid invitation", {
3492
3498
  invitationId
3493
3499
  }, {
3494
- F: __dxlog_file14,
3500
+ F: __dxlog_file15,
3495
3501
  L: 144,
3496
3502
  S: this,
3497
3503
  C: (f, a) => f(...a)
@@ -3504,13 +3510,13 @@ var InvitationsManager = class {
3504
3510
  log12("cancelInvitation...", {
3505
3511
  invitationId
3506
3512
  }, {
3507
- F: __dxlog_file14,
3513
+ F: __dxlog_file15,
3508
3514
  L: 151,
3509
3515
  S: this,
3510
3516
  C: (f, a) => f(...a)
3511
3517
  });
3512
3518
  invariant11(invitationId, void 0, {
3513
- F: __dxlog_file14,
3519
+ F: __dxlog_file15,
3514
3520
  L: 152,
3515
3521
  S: this,
3516
3522
  A: [
@@ -3584,12 +3590,15 @@ var InvitationsManager = class {
3584
3590
  stream.error(err);
3585
3591
  void ctx.dispose();
3586
3592
  }
3593
+ }, {
3594
+ F: __dxlog_file15,
3595
+ L: 234
3587
3596
  });
3588
3597
  ctx.onDispose(() => {
3589
3598
  log12("complete", {
3590
3599
  ...handler.toJSON()
3591
3600
  }, {
3592
- F: __dxlog_file14,
3601
+ F: __dxlog_file15,
3593
3602
  L: 241,
3594
3603
  S: this,
3595
3604
  C: (f, a) => f(...a)
@@ -3622,7 +3631,7 @@ var InvitationsManager = class {
3622
3631
  log12("timeout", {
3623
3632
  ...handler.toJSON()
3624
3633
  }, {
3625
- F: __dxlog_file14,
3634
+ F: __dxlog_file15,
3626
3635
  L: 261,
3627
3636
  S: this,
3628
3637
  C: (f, a) => f(...a)
@@ -3633,7 +3642,7 @@ var InvitationsManager = class {
3633
3642
  });
3634
3643
  } else {
3635
3644
  log12.warn("auth failed", err, {
3636
- F: __dxlog_file14,
3645
+ F: __dxlog_file15,
3637
3646
  L: 264,
3638
3647
  S: this,
3639
3648
  C: (f, a) => f(...a)
@@ -3645,12 +3654,15 @@ var InvitationsManager = class {
3645
3654
  }
3646
3655
  void ctx.dispose();
3647
3656
  }
3657
+ }, {
3658
+ F: __dxlog_file15,
3659
+ L: 258
3648
3660
  });
3649
3661
  ctx.onDispose(() => {
3650
3662
  log12("complete", {
3651
3663
  ...handler.toJSON()
3652
3664
  }, {
3653
- F: __dxlog_file14,
3665
+ F: __dxlog_file15,
3654
3666
  L: 271,
3655
3667
  S: this,
3656
3668
  C: (f, a) => f(...a)
@@ -3695,7 +3707,7 @@ var InvitationsManager = class {
3695
3707
  await this._metadataStore.removeInvitation(invitation.invitationId);
3696
3708
  } catch (err) {
3697
3709
  log12.catch(err, void 0, {
3698
- F: __dxlog_file14,
3710
+ F: __dxlog_file15,
3699
3711
  L: 307,
3700
3712
  S: this,
3701
3713
  C: (f, a) => f(...a)
@@ -3712,10 +3724,10 @@ var InvitationsManager = class {
3712
3724
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
3713
3725
  import { Event as Event6, Mutex as Mutex2, scheduleTask as scheduleTask5, sleep as sleep3, synchronized, trackLeaks } from "@dxos/async";
3714
3726
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
3715
- 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";
3716
3728
  import { timed, warnAfterTimeout } from "@dxos/debug";
3717
3729
  import { createMappedFeedWriter } from "@dxos/echo-pipeline";
3718
- import { SpaceDocVersion } from "@dxos/echo-protocol";
3730
+ import { SpaceDocVersion as SpaceDocVersion2 } from "@dxos/echo-protocol";
3719
3731
  import { failedInvariant } from "@dxos/invariant";
3720
3732
  import { PublicKey as PublicKey10 } from "@dxos/keys";
3721
3733
  import { log as log15 } from "@dxos/log";
@@ -3772,22 +3784,19 @@ var AutomergeSpaceState = class extends Resource2 {
3772
3784
  };
3773
3785
 
3774
3786
  // packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts
3775
- import { asyncTimeout as asyncTimeout2 } from "@dxos/async";
3776
- import { next as am } from "@dxos/automerge/automerge";
3777
- import { cancelWithContext as cancelWithContext4 } from "@dxos/context";
3778
3787
  import { convertLegacyReferences, convertLegacySpaceRootDoc, findInlineObjectOfType, migrateDocument } from "@dxos/echo-db";
3779
- import { AutomergeDocumentLoaderImpl } from "@dxos/echo-pipeline";
3788
+ import { SpaceDocVersion } from "@dxos/echo-protocol";
3780
3789
  import { TYPE_PROPERTIES } from "@dxos/echo-schema";
3781
3790
  import { invariant as invariant12 } from "@dxos/invariant";
3782
3791
  import { log as log13 } from "@dxos/log";
3783
3792
  import { CreateEpochRequest } from "@dxos/protocols/proto/dxos/client/services";
3784
- import { assignDeep } from "@dxos/util";
3785
- var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts";
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;
3786
3795
  var runEpochMigration = async (ctx, context) => {
3787
3796
  switch (context.migration) {
3788
3797
  case CreateEpochRequest.Migration.INIT_AUTOMERGE: {
3789
- const document = context.repo.create();
3790
- await context.repo.flush();
3798
+ const document = context.echoHost.createDoc();
3799
+ await context.echoHost.flush();
3791
3800
  return {
3792
3801
  newRoot: document.url
3793
3802
  };
@@ -3796,77 +3805,88 @@ var runEpochMigration = async (ctx, context) => {
3796
3805
  if (!context.currentRoot) {
3797
3806
  throw new Error("Space does not have an automerge root");
3798
3807
  }
3799
- const rootHandle = context.repo.find(context.currentRoot);
3800
- await cancelWithContext4(ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
3801
- const newRoot = context.repo.create(rootHandle.docSync());
3802
- await context.repo.flush();
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();
3803
3813
  return {
3804
3814
  newRoot: newRoot.url
3805
3815
  };
3806
3816
  }
3807
3817
  case CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT: {
3808
3818
  log13.info("Fragmenting", void 0, {
3809
- F: __dxlog_file15,
3810
- L: 63,
3819
+ F: __dxlog_file16,
3820
+ L: 64,
3811
3821
  S: void 0,
3812
3822
  C: (f, a) => f(...a)
3813
3823
  });
3814
3824
  const currentRootUrl = context.currentRoot;
3815
- const rootHandle = context.repo.find(currentRootUrl);
3816
- await cancelWithContext4(ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
3825
+ const rootHandle = await context.echoHost.loadDoc(ctx, currentRootUrl, {
3826
+ timeout: LOAD_DOC_TIMEOUT
3827
+ });
3817
3828
  const objects = Object.entries(rootHandle.docSync().objects);
3818
3829
  const properties = findInlineObjectOfType(rootHandle.docSync(), TYPE_PROPERTIES);
3819
3830
  const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
3820
3831
  invariant12(properties, "Properties not found", {
3821
- F: __dxlog_file15,
3822
- L: 73,
3832
+ F: __dxlog_file16,
3833
+ L: 75,
3823
3834
  S: void 0,
3824
3835
  A: [
3825
3836
  "properties",
3826
3837
  "'Properties not found'"
3827
3838
  ]
3828
3839
  });
3829
- const newSpaceDoc = {
3840
+ const newRoot = context.echoHost.createDoc({
3830
3841
  ...rootHandle.docSync(),
3831
3842
  objects: Object.fromEntries([
3832
3843
  properties
3833
3844
  ])
3834
- };
3835
- const newRoot = context.repo.create(newSpaceDoc);
3845
+ });
3836
3846
  invariant12(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3837
- F: __dxlog_file15,
3838
- L: 78,
3847
+ F: __dxlog_file16,
3848
+ L: 82,
3839
3849
  S: void 0,
3840
3850
  A: [
3841
3851
  "typeof newRoot.url === 'string' && newRoot.url.length > 0",
3842
3852
  ""
3843
3853
  ]
3844
3854
  });
3845
- const docLoader = new AutomergeDocumentLoaderImpl(context.spaceId, context.repo, context.spaceKey);
3846
- await docLoader.loadSpaceRootDocHandle(ctx, {
3847
- rootUrl: newRoot.url
3848
- });
3849
- otherObjects.forEach(([key, value]) => {
3850
- const handle = docLoader.createDocumentForObject(key);
3851
- handle.change((doc) => {
3852
- assignDeep(doc, [
3853
- "objects",
3854
- key
3855
- ], value);
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
+ }
3856
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
+ }
3857
3876
  });
3858
- await context.repo.flush();
3877
+ await context.echoHost.flush();
3859
3878
  return {
3860
3879
  newRoot: newRoot.url
3861
3880
  };
3862
3881
  }
3863
3882
  case CreateEpochRequest.Migration.MIGRATE_REFERENCES_TO_DXN: {
3864
3883
  const currentRootUrl = context.currentRoot;
3865
- const rootHandle = context.repo.find(currentRootUrl);
3866
- await cancelWithContext4(ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
3884
+ const rootHandle = await context.echoHost.loadDoc(ctx, currentRootUrl, {
3885
+ timeout: LOAD_DOC_TIMEOUT
3886
+ });
3867
3887
  invariant12(rootHandle.docSync(), "Root doc not found", {
3868
- F: __dxlog_file15,
3869
- L: 100,
3888
+ F: __dxlog_file16,
3889
+ L: 115,
3870
3890
  S: void 0,
3871
3891
  A: [
3872
3892
  "rootHandle.docSync()",
@@ -3875,40 +3895,59 @@ var runEpochMigration = async (ctx, context) => {
3875
3895
  });
3876
3896
  const newRootContent = await convertLegacySpaceRootDoc(structuredClone(rootHandle.docSync()));
3877
3897
  for (const [id, url] of Object.entries(newRootContent.links ?? {})) {
3878
- const handle = context.repo.find(url);
3879
- await cancelWithContext4(ctx, asyncTimeout2(handle.whenReady(), 1e4));
3880
- invariant12(handle.docSync(), "Doc not found", {
3881
- F: __dxlog_file15,
3882
- L: 107,
3883
- S: void 0,
3884
- A: [
3885
- "handle.docSync()",
3886
- "'Doc not found'"
3887
- ]
3888
- });
3889
- const newDoc = await convertLegacyReferences(structuredClone(handle.docSync()));
3890
- const migratedDoc = migrateDocument(handle.docSync(), newDoc);
3891
- const newHandle = context.repo.import(am.save(migratedDoc));
3892
- newRootContent.links[id] = newHandle.url;
3893
- }
3894
- const migratedRoot = migrateDocument(rootHandle.docSync(), newRootContent);
3895
- const newRoot = context.repo.import(am.save(migratedRoot));
3896
- await context.repo.flush();
3897
- return {
3898
- newRoot: newRoot.url
3899
- };
3900
- }
3901
- case CreateEpochRequest.Migration.REPLACE_AUTOMERGE_ROOT: {
3902
- invariant12(context.newAutomergeRoot, void 0, {
3903
- F: __dxlog_file15,
3904
- L: 124,
3905
- S: void 0,
3898
+ try {
3899
+ const handle = await context.echoHost.loadDoc(ctx, url, {
3900
+ timeout: LOAD_DOC_TIMEOUT
3901
+ });
3902
+ invariant12(handle.docSync(), void 0, {
3903
+ F: __dxlog_file16,
3904
+ L: 122,
3905
+ S: void 0,
3906
+ A: [
3907
+ "handle.docSync()",
3908
+ ""
3909
+ ]
3910
+ });
3911
+ const newDoc = await convertLegacyReferences(structuredClone(handle.docSync()));
3912
+ const migratedDoc = migrateDocument(handle.docSync(), newDoc);
3913
+ const newHandle = context.echoHost.createDoc(migratedDoc, {
3914
+ preserveHistory: true
3915
+ });
3916
+ newRootContent.links[id] = newHandle.url;
3917
+ } catch (err) {
3918
+ log13.warn("Failed to migrate reference", {
3919
+ id,
3920
+ url,
3921
+ error: err
3922
+ }, {
3923
+ F: __dxlog_file16,
3924
+ L: 128,
3925
+ S: void 0,
3926
+ C: (f, a) => f(...a)
3927
+ });
3928
+ delete newRootContent.links[id];
3929
+ }
3930
+ }
3931
+ const migratedRoot = migrateDocument(rootHandle.docSync(), newRootContent);
3932
+ const newRoot = context.echoHost.createDoc(migratedRoot, {
3933
+ preserveHistory: true
3934
+ });
3935
+ await context.echoHost.flush();
3936
+ return {
3937
+ newRoot: newRoot.url
3938
+ };
3939
+ }
3940
+ case CreateEpochRequest.Migration.REPLACE_AUTOMERGE_ROOT: {
3941
+ invariant12(context.newAutomergeRoot, void 0, {
3942
+ F: __dxlog_file16,
3943
+ L: 143,
3944
+ S: void 0,
3906
3945
  A: [
3907
3946
  "context.newAutomergeRoot",
3908
3947
  ""
3909
3948
  ]
3910
3949
  });
3911
- await context.repo.flush();
3950
+ await context.echoHost.flush();
3912
3951
  return {
3913
3952
  newRoot: context.newAutomergeRoot
3914
3953
  };
@@ -3926,14 +3965,17 @@ import { log as log14 } from "@dxos/log";
3926
3965
  import { schema as schema4 } from "@dxos/protocols";
3927
3966
  import { RpcExtension as RpcExtension3 } from "@dxos/teleport";
3928
3967
  import { ComplexMap as ComplexMap2, ComplexSet as ComplexSet4, entry } from "@dxos/util";
3929
- 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";
3930
3969
  var DEFAULT_RETRY_TIMEOUT = 1e3;
3931
3970
  var DEFAULT_SUCCESS_DELAY = 1e3;
3932
3971
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
3933
3972
  var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
3934
3973
  var NotarizationPlugin = class {
3935
3974
  constructor() {
3936
- this._ctx = new Context7();
3975
+ this._ctx = new Context7(void 0, {
3976
+ F: __dxlog_file17,
3977
+ L: 62
3978
+ });
3937
3979
  this._extensionOpened = new Event5();
3938
3980
  this._extensions = /* @__PURE__ */ new Set();
3939
3981
  this._processedCredentials = new ComplexSet4(PublicKey9.hash);
@@ -3954,13 +3996,13 @@ var NotarizationPlugin = class {
3954
3996
  log14("notarize", {
3955
3997
  credentials
3956
3998
  }, {
3957
- F: __dxlog_file16,
3999
+ F: __dxlog_file17,
3958
4000
  L: 90,
3959
4001
  S: this,
3960
4002
  C: (f, a) => f(...a)
3961
4003
  });
3962
4004
  invariant13(credentials.every((credential) => credential.id), "Credentials must have an id", {
3963
- F: __dxlog_file16,
4005
+ F: __dxlog_file17,
3964
4006
  L: 91,
3965
4007
  S: this,
3966
4008
  A: [
@@ -3974,7 +4016,7 @@ var NotarizationPlugin = class {
3974
4016
  log14.warn("Notarization error", {
3975
4017
  err
3976
4018
  }, {
3977
- F: __dxlog_file16,
4019
+ F: __dxlog_file17,
3978
4020
  L: 99,
3979
4021
  S: this,
3980
4022
  C: (f, a) => f(...a)
@@ -3990,7 +4032,7 @@ var NotarizationPlugin = class {
3990
4032
  timeout,
3991
4033
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
3992
4034
  }, {
3993
- F: __dxlog_file16,
4035
+ F: __dxlog_file17,
3994
4036
  L: 111,
3995
4037
  S: this,
3996
4038
  C: (f, a) => f(...a)
@@ -4013,7 +4055,7 @@ var NotarizationPlugin = class {
4013
4055
  log14.info("Exhausted all peers to notarize with", {
4014
4056
  retryIn: retryTimeout
4015
4057
  }, {
4016
- F: __dxlog_file16,
4058
+ F: __dxlog_file17,
4017
4059
  L: 136,
4018
4060
  S: this,
4019
4061
  C: (f, a) => f(...a)
@@ -4027,7 +4069,7 @@ var NotarizationPlugin = class {
4027
4069
  peer: peer.localPeerId,
4028
4070
  credentialId: credentials.map((credential) => credential.id)
4029
4071
  }, {
4030
- F: __dxlog_file16,
4072
+ F: __dxlog_file17,
4031
4073
  L: 143,
4032
4074
  S: this,
4033
4075
  C: (f, a) => f(...a)
@@ -4036,7 +4078,7 @@ var NotarizationPlugin = class {
4036
4078
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
4037
4079
  });
4038
4080
  log14("success", void 0, {
4039
- F: __dxlog_file16,
4081
+ F: __dxlog_file17,
4040
4082
  L: 147,
4041
4083
  S: this,
4042
4084
  C: (f, a) => f(...a)
@@ -4045,7 +4087,7 @@ var NotarizationPlugin = class {
4045
4087
  } catch (err) {
4046
4088
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
4047
4089
  log14.info("error notarizing (recoverable)", err, {
4048
- F: __dxlog_file16,
4090
+ F: __dxlog_file17,
4049
4091
  L: 151,
4050
4092
  S: this,
4051
4093
  C: (f, a) => f(...a)
@@ -4063,7 +4105,7 @@ var NotarizationPlugin = class {
4063
4105
  errors.wait()
4064
4106
  ]);
4065
4107
  log14("done", void 0, {
4066
- F: __dxlog_file16,
4108
+ F: __dxlog_file17,
4067
4109
  L: 162,
4068
4110
  S: this,
4069
4111
  C: (f, a) => f(...a)
@@ -4085,7 +4127,7 @@ var NotarizationPlugin = class {
4085
4127
  }
4086
4128
  setWriter(writer) {
4087
4129
  invariant13(!this._writer, "Writer already set.", {
4088
- F: __dxlog_file16,
4130
+ F: __dxlog_file17,
4089
4131
  L: 181,
4090
4132
  S: this,
4091
4133
  A: [
@@ -4110,7 +4152,7 @@ var NotarizationPlugin = class {
4110
4152
  }
4111
4153
  for (const credential of request.credentials ?? []) {
4112
4154
  invariant13(credential.id, "Credential must have an id", {
4113
- F: __dxlog_file16,
4155
+ F: __dxlog_file17,
4114
4156
  L: 200,
4115
4157
  S: this,
4116
4158
  A: [
@@ -4130,7 +4172,7 @@ var NotarizationPlugin = class {
4130
4172
  log14("extension opened", {
4131
4173
  peer: extension.localPeerId
4132
4174
  }, {
4133
- F: __dxlog_file16,
4175
+ F: __dxlog_file17,
4134
4176
  L: 211,
4135
4177
  S: this,
4136
4178
  C: (f, a) => f(...a)
@@ -4142,7 +4184,7 @@ var NotarizationPlugin = class {
4142
4184
  log14("extension closed", {
4143
4185
  peer: extension.localPeerId
4144
4186
  }, {
4145
- F: __dxlog_file16,
4187
+ F: __dxlog_file17,
4146
4188
  L: 216,
4147
4189
  S: this,
4148
4190
  C: (f, a) => f(...a)
@@ -4259,10 +4301,13 @@ function _using_ctx() {
4259
4301
  }
4260
4302
  };
4261
4303
  }
4262
- 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";
4263
4305
  var DataSpace = class {
4264
4306
  constructor(params) {
4265
- this._ctx = new Context8();
4307
+ this._ctx = new Context8(void 0, {
4308
+ F: __dxlog_file18,
4309
+ L: 84
4310
+ });
4266
4311
  this._notarizationPlugin = new NotarizationPlugin();
4267
4312
  this._cache = void 0;
4268
4313
  // TODO(dmaretskyi): Move into Space?
@@ -4296,7 +4341,7 @@ var DataSpace = class {
4296
4341
  log15("new state", {
4297
4342
  state: SpaceState2[this._state]
4298
4343
  }, {
4299
- F: __dxlog_file17,
4344
+ F: __dxlog_file18,
4300
4345
  L: 146,
4301
4346
  S: this,
4302
4347
  C: (f, a) => f(...a)
@@ -4351,12 +4396,15 @@ var DataSpace = class {
4351
4396
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
4352
4397
  await this._automergeSpaceState.open();
4353
4398
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
4354
- await this._inner.open(new Context8());
4399
+ await this._inner.open(new Context8(void 0, {
4400
+ F: __dxlog_file18,
4401
+ L: 215
4402
+ }));
4355
4403
  this._state = SpaceState2.CONTROL_ONLY;
4356
4404
  log15("new state", {
4357
4405
  state: SpaceState2[this._state]
4358
4406
  }, {
4359
- F: __dxlog_file17,
4407
+ F: __dxlog_file18,
4360
4408
  L: 217,
4361
4409
  S: this,
4362
4410
  C: (f, a) => f(...a)
@@ -4374,13 +4422,16 @@ var DataSpace = class {
4374
4422
  log15("new state", {
4375
4423
  state: SpaceState2[this._state]
4376
4424
  }, {
4377
- F: __dxlog_file17,
4425
+ F: __dxlog_file18,
4378
4426
  L: 231,
4379
4427
  S: this,
4380
4428
  C: (f, a) => f(...a)
4381
4429
  });
4382
4430
  await this._ctx.dispose();
4383
- this._ctx = new Context8();
4431
+ this._ctx = new Context8(void 0, {
4432
+ F: __dxlog_file18,
4433
+ L: 233
4434
+ });
4384
4435
  await this.authVerifier.close();
4385
4436
  await this._inner.close();
4386
4437
  await this._inner.spaceState.removeCredentialProcessor(this._automergeSpaceState);
@@ -4407,7 +4458,7 @@ var DataSpace = class {
4407
4458
  } catch (err) {
4408
4459
  if (err instanceof CancelledError || err instanceof ContextDisposedError3) {
4409
4460
  log15("data pipeline initialization cancelled", err, {
4410
- F: __dxlog_file17,
4461
+ F: __dxlog_file18,
4411
4462
  L: 265,
4412
4463
  S: this,
4413
4464
  C: (f, a) => f(...a)
@@ -4415,7 +4466,7 @@ var DataSpace = class {
4415
4466
  return;
4416
4467
  }
4417
4468
  log15.error("Error initializing data pipeline", err, {
4418
- F: __dxlog_file17,
4469
+ F: __dxlog_file18,
4419
4470
  L: 269,
4420
4471
  S: this,
4421
4472
  C: (f, a) => f(...a)
@@ -4424,7 +4475,7 @@ var DataSpace = class {
4424
4475
  log15("new state", {
4425
4476
  state: SpaceState2[this._state]
4426
4477
  }, {
4427
- F: __dxlog_file17,
4478
+ F: __dxlog_file18,
4428
4479
  L: 271,
4429
4480
  S: this,
4430
4481
  C: (f, a) => f(...a)
@@ -4444,7 +4495,7 @@ var DataSpace = class {
4444
4495
  log15("new state", {
4445
4496
  state: SpaceState2[this._state]
4446
4497
  }, {
4447
- F: __dxlog_file17,
4498
+ F: __dxlog_file18,
4448
4499
  L: 287,
4449
4500
  S: this,
4450
4501
  C: (f, a) => f(...a)
@@ -4461,7 +4512,7 @@ var DataSpace = class {
4461
4512
  log15("new state", {
4462
4513
  state: SpaceState2[this._state]
4463
4514
  }, {
4464
- F: __dxlog_file17,
4515
+ F: __dxlog_file18,
4465
4516
  L: 306,
4466
4517
  S: this,
4467
4518
  C: (f, a) => f(...a)
@@ -4477,7 +4528,7 @@ var DataSpace = class {
4477
4528
  this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
4478
4529
  await this._createWritableFeeds();
4479
4530
  log15("writable feeds created", void 0, {
4480
- F: __dxlog_file17,
4531
+ F: __dxlog_file18,
4481
4532
  L: 322,
4482
4533
  S: this,
4483
4534
  C: (f, a) => f(...a)
@@ -4540,7 +4591,7 @@ var DataSpace = class {
4540
4591
  space: this.key,
4541
4592
  rootUrl
4542
4593
  }, {
4543
- F: __dxlog_file17,
4594
+ F: __dxlog_file18,
4544
4595
  L: 388,
4545
4596
  S: this,
4546
4597
  C: (f, a) => f(...a)
@@ -4551,7 +4602,7 @@ var DataSpace = class {
4551
4602
  try {
4552
4603
  var _usingCtx = _using_ctx();
4553
4604
  await warnAfterTimeout(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
4554
- await cancelWithContext5(this._ctx, handle.whenReady());
4605
+ await cancelWithContext4(this._ctx, handle.whenReady());
4555
4606
  });
4556
4607
  if (this._ctx.disposed) {
4557
4608
  return;
@@ -4570,7 +4621,7 @@ var DataSpace = class {
4570
4621
  }
4571
4622
  const root = await this._echoHost.openSpaceRoot(handle.url);
4572
4623
  this._databaseRoot = root;
4573
- if (root.getVersion() !== SpaceDocVersion.CURRENT) {
4624
+ if (root.getVersion() !== SpaceDocVersion2.CURRENT) {
4574
4625
  if (this._state !== SpaceState2.REQUIRES_MIGRATION) {
4575
4626
  this._state = SpaceState2.REQUIRES_MIGRATION;
4576
4627
  this.stateUpdate.emit();
@@ -4594,7 +4645,7 @@ var DataSpace = class {
4594
4645
  rootUrl,
4595
4646
  err
4596
4647
  }, {
4597
- F: __dxlog_file17,
4648
+ F: __dxlog_file18,
4598
4649
  L: 431,
4599
4650
  S: this,
4600
4651
  C: (f, a) => f(...a)
@@ -4623,7 +4674,7 @@ var DataSpace = class {
4623
4674
  return null;
4624
4675
  }
4625
4676
  const { newRoot } = await runEpochMigration(ctx, {
4626
- repo: this._echoHost.automergeRepo,
4677
+ echoHost: this._echoHost,
4627
4678
  spaceId: this.id,
4628
4679
  spaceKey: this.key,
4629
4680
  migration: options.migration,
@@ -4680,7 +4731,7 @@ var DataSpace = class {
4680
4731
  log15("new state", {
4681
4732
  state: SpaceState2[this._state]
4682
4733
  }, {
4683
- F: __dxlog_file17,
4734
+ F: __dxlog_file18,
4684
4735
  L: 512,
4685
4736
  S: this,
4686
4737
  C: (f, a) => f(...a)
@@ -4740,21 +4791,23 @@ DataSpace = _ts_decorate4([
4740
4791
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
4741
4792
  import { Event as Event7, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
4742
4793
  import { PropertiesType } from "@dxos/client-protocol";
4743
- import { Context as Context9, cancelWithContext as cancelWithContext6 } from "@dxos/context";
4744
- import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
4794
+ import { Context as Context9, cancelWithContext as cancelWithContext5 } from "@dxos/context";
4795
+ import { getCredentialAssertion as getCredentialAssertion3, createAdmissionCredentials } from "@dxos/credentials";
4745
4796
  import { convertLegacyReferences as convertLegacyReferences2, findInlineObjectOfType as findInlineObjectOfType2 } from "@dxos/echo-db";
4746
4797
  import { AuthStatus } from "@dxos/echo-pipeline";
4747
- 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";
4748
4800
  import { TYPE_PROPERTIES as TYPE_PROPERTIES2, generateEchoId, getTypeReference } from "@dxos/echo-schema";
4801
+ import { writeMessages as writeMessages3 } from "@dxos/feed-store";
4749
4802
  import { invariant as invariant14 } from "@dxos/invariant";
4750
4803
  import { PublicKey as PublicKey11 } from "@dxos/keys";
4751
4804
  import { log as log16 } from "@dxos/log";
4752
- import { trace as Trace2 } from "@dxos/protocols";
4805
+ import { trace as Trace2, AlreadyJoinedError as AlreadyJoinedError3 } from "@dxos/protocols";
4753
4806
  import { Invitation as Invitation7, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
4754
4807
  import { SpaceMember as SpaceMember6 } from "@dxos/protocols/proto/dxos/halo/credentials";
4755
4808
  import { Gossip as Gossip2, Presence as Presence2 } from "@dxos/teleport-extension-gossip";
4756
4809
  import { trace as trace7 } from "@dxos/tracing";
4757
- 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";
4758
4811
 
4759
4812
  // packages/sdk/client-services/src/packlets/spaces/genesis.ts
4760
4813
  import { createCredential } from "@dxos/credentials";
@@ -4837,7 +4890,7 @@ function _ts_decorate5(decorators, target, key, desc) {
4837
4890
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4838
4891
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4839
4892
  }
4840
- 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";
4841
4894
  var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
4842
4895
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
4843
4896
  var DEFAULT_SPACE_KEY = "__DEFAULT__";
@@ -4851,7 +4904,10 @@ var DataSpaceManager = class {
4851
4904
  this._echoHost = _echoHost;
4852
4905
  this._invitationsManager = _invitationsManager;
4853
4906
  this._params = _params;
4854
- this._ctx = new Context9();
4907
+ this._ctx = new Context9(void 0, {
4908
+ F: __dxlog_file19,
4909
+ L: 104
4910
+ });
4855
4911
  this.updated = new Event7();
4856
4912
  this._spaces = new ComplexMap3(PublicKey11.hash);
4857
4913
  this._isOpen = false;
@@ -4885,24 +4941,24 @@ var DataSpaceManager = class {
4885
4941
  }
4886
4942
  async open() {
4887
4943
  log16("open", void 0, {
4888
- F: __dxlog_file18,
4889
- L: 146,
4944
+ F: __dxlog_file19,
4945
+ L: 156,
4890
4946
  S: this,
4891
4947
  C: (f, a) => f(...a)
4892
4948
  });
4893
4949
  log16.trace("dxos.echo.data-space-manager.open", Trace2.begin({
4894
4950
  id: this._instanceId
4895
4951
  }), {
4896
- F: __dxlog_file18,
4897
- L: 147,
4952
+ F: __dxlog_file19,
4953
+ L: 157,
4898
4954
  S: this,
4899
4955
  C: (f, a) => f(...a)
4900
4956
  });
4901
4957
  log16("metadata loaded", {
4902
4958
  spaces: this._metadataStore.spaces.length
4903
4959
  }, {
4904
- F: __dxlog_file18,
4905
- L: 148,
4960
+ F: __dxlog_file19,
4961
+ L: 158,
4906
4962
  S: this,
4907
4963
  C: (f, a) => f(...a)
4908
4964
  });
@@ -4911,8 +4967,8 @@ var DataSpaceManager = class {
4911
4967
  log16("load space", {
4912
4968
  spaceMetadata
4913
4969
  }, {
4914
- F: __dxlog_file18,
4915
- L: 152,
4970
+ F: __dxlog_file19,
4971
+ L: 162,
4916
4972
  S: this,
4917
4973
  C: (f, a) => f(...a)
4918
4974
  });
@@ -4922,8 +4978,8 @@ var DataSpaceManager = class {
4922
4978
  spaceMetadata,
4923
4979
  err
4924
4980
  }, {
4925
- F: __dxlog_file18,
4926
- L: 155,
4981
+ F: __dxlog_file19,
4982
+ L: 165,
4927
4983
  S: this,
4928
4984
  C: (f, a) => f(...a)
4929
4985
  });
@@ -4934,16 +4990,16 @@ var DataSpaceManager = class {
4934
4990
  log16.trace("dxos.echo.data-space-manager.open", Trace2.end({
4935
4991
  id: this._instanceId
4936
4992
  }), {
4937
- F: __dxlog_file18,
4938
- L: 162,
4993
+ F: __dxlog_file19,
4994
+ L: 172,
4939
4995
  S: this,
4940
4996
  C: (f, a) => f(...a)
4941
4997
  });
4942
4998
  }
4943
4999
  async close() {
4944
5000
  log16("close", void 0, {
4945
- F: __dxlog_file18,
4946
- L: 167,
5001
+ F: __dxlog_file19,
5002
+ L: 177,
4947
5003
  S: this,
4948
5004
  C: (f, a) => f(...a)
4949
5005
  });
@@ -4959,8 +5015,8 @@ var DataSpaceManager = class {
4959
5015
  */
4960
5016
  async createSpace() {
4961
5017
  invariant14(this._isOpen, "Not open.", {
4962
- F: __dxlog_file18,
4963
- L: 181,
5018
+ F: __dxlog_file19,
5019
+ L: 191,
4964
5020
  S: this,
4965
5021
  A: [
4966
5022
  "this._isOpen",
@@ -4980,8 +5036,8 @@ var DataSpaceManager = class {
4980
5036
  log16("creating space...", {
4981
5037
  spaceKey
4982
5038
  }, {
4983
- F: __dxlog_file18,
4984
- L: 193,
5039
+ F: __dxlog_file19,
5040
+ L: 203,
4985
5041
  S: this,
4986
5042
  C: (f, a) => f(...a)
4987
5043
  });
@@ -4992,8 +5048,8 @@ var DataSpaceManager = class {
4992
5048
  await this._metadataStore.addSpace(metadata);
4993
5049
  const memberCredential = credentials[1];
4994
5050
  invariant14(getCredentialAssertion3(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4995
- F: __dxlog_file18,
4996
- L: 203,
5051
+ F: __dxlog_file19,
5052
+ L: 213,
4997
5053
  S: this,
4998
5054
  A: [
4999
5055
  "getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -5010,11 +5066,11 @@ var DataSpaceManager = class {
5010
5066
  return false;
5011
5067
  }
5012
5068
  switch (space.databaseRoot.getVersion()) {
5013
- case SpaceDocVersion2.CURRENT: {
5069
+ case SpaceDocVersion3.CURRENT: {
5014
5070
  const [_, properties] = findInlineObjectOfType2(space.databaseRoot.docSync(), TYPE_PROPERTIES2) ?? [];
5015
5071
  return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
5016
5072
  }
5017
- case SpaceDocVersion2.LEGACY: {
5073
+ case SpaceDocVersion3.LEGACY: {
5018
5074
  const convertedDoc = await convertLegacyReferences2(space.databaseRoot.docSync());
5019
5075
  const [_, properties] = findInlineObjectOfType2(convertedDoc, LEGACY_TYPE_PROPERTIES) ?? [];
5020
5076
  return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
@@ -5024,8 +5080,8 @@ var DataSpaceManager = class {
5024
5080
  version: space.databaseRoot.getVersion(),
5025
5081
  spaceId: space.id
5026
5082
  }, {
5027
- F: __dxlog_file18,
5028
- L: 228,
5083
+ F: __dxlog_file19,
5084
+ L: 238,
5029
5085
  S: this,
5030
5086
  C: (f, a) => f(...a)
5031
5087
  });
@@ -5048,7 +5104,7 @@ var DataSpaceManager = class {
5048
5104
  };
5049
5105
  const propertiesId = generateEchoId();
5050
5106
  document.change((doc) => {
5051
- assignDeep2(doc, [
5107
+ assignDeep(doc, [
5052
5108
  "objects",
5053
5109
  propertiesId
5054
5110
  ], properties);
@@ -5059,8 +5115,8 @@ var DataSpaceManager = class {
5059
5115
  async _getSpaceRootDocument(space) {
5060
5116
  const automergeIndex = space.automergeSpaceState.rootUrl;
5061
5117
  invariant14(automergeIndex, void 0, {
5062
- F: __dxlog_file18,
5063
- L: 261,
5118
+ F: __dxlog_file19,
5119
+ L: 271,
5064
5120
  S: this,
5065
5121
  A: [
5066
5122
  "automergeIndex",
@@ -5076,14 +5132,14 @@ var DataSpaceManager = class {
5076
5132
  log16("accept space", {
5077
5133
  opts
5078
5134
  }, {
5079
- F: __dxlog_file18,
5080
- L: 270,
5135
+ F: __dxlog_file19,
5136
+ L: 280,
5081
5137
  S: this,
5082
5138
  C: (f, a) => f(...a)
5083
5139
  });
5084
5140
  invariant14(this._isOpen, "Not open.", {
5085
- F: __dxlog_file18,
5086
- L: 271,
5141
+ F: __dxlog_file19,
5142
+ L: 281,
5087
5143
  S: this,
5088
5144
  A: [
5089
5145
  "this._isOpen",
@@ -5091,8 +5147,8 @@ var DataSpaceManager = class {
5091
5147
  ]
5092
5148
  });
5093
5149
  invariant14(!this._spaces.has(opts.spaceKey), "Space already exists.", {
5094
- F: __dxlog_file18,
5095
- L: 272,
5150
+ F: __dxlog_file19,
5151
+ L: 282,
5096
5152
  S: this,
5097
5153
  A: [
5098
5154
  "!this._spaces.has(opts.spaceKey)",
@@ -5112,23 +5168,72 @@ var DataSpaceManager = class {
5112
5168
  this.updated.emit();
5113
5169
  return space;
5114
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
+ }
5115
5208
  /**
5116
5209
  * Wait until the space data pipeline is fully initialized.
5117
5210
  * Used by invitation handler.
5118
5211
  * TODO(dmaretskyi): Consider removing.
5119
5212
  */
5120
5213
  async waitUntilSpaceReady(spaceKey) {
5121
- await cancelWithContext6(this._ctx, this.updated.waitForCondition(() => {
5214
+ await cancelWithContext5(this._ctx, this.updated.waitForCondition(() => {
5122
5215
  const space = this._spaces.get(spaceKey);
5123
5216
  return !!space && space.state === SpaceState3.READY;
5124
5217
  }));
5125
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
+ }
5126
5231
  async _constructSpace(metadata) {
5127
5232
  log16("construct space", {
5128
5233
  metadata
5129
5234
  }, {
5130
- F: __dxlog_file18,
5131
- L: 306,
5235
+ F: __dxlog_file19,
5236
+ L: 358,
5132
5237
  S: this,
5133
5238
  C: (f, a) => f(...a)
5134
5239
  });
@@ -5156,6 +5261,7 @@ var DataSpaceManager = class {
5156
5261
  credentialAuthenticator: deferFunction2(() => dataSpace.authVerifier.verifier)
5157
5262
  },
5158
5263
  onAuthorizedConnection: (session) => {
5264
+ session.addExtension("dxos.mesh.teleport.admission-discovery", new CredentialServerExtension(space));
5159
5265
  session.addExtension("dxos.mesh.teleport.gossip", gossip.createExtension({
5160
5266
  remotePeerId: session.remotePeerId
5161
5267
  }));
@@ -5165,8 +5271,8 @@ var DataSpaceManager = class {
5165
5271
  },
5166
5272
  onAuthFailure: () => {
5167
5273
  log16.warn("auth failure", void 0, {
5168
- F: __dxlog_file18,
5169
- L: 343,
5274
+ F: __dxlog_file19,
5275
+ L: 396,
5170
5276
  S: this,
5171
5277
  C: (f, a) => f(...a)
5172
5278
  });
@@ -5198,8 +5304,8 @@ var DataSpaceManager = class {
5198
5304
  log16("before space ready", {
5199
5305
  space: space.key
5200
5306
  }, {
5201
- F: __dxlog_file18,
5202
- L: 370,
5307
+ F: __dxlog_file19,
5308
+ L: 423,
5203
5309
  S: this,
5204
5310
  C: (f, a) => f(...a)
5205
5311
  });
@@ -5209,8 +5315,8 @@ var DataSpaceManager = class {
5209
5315
  space: space.key,
5210
5316
  open: this._isOpen
5211
5317
  }, {
5212
- F: __dxlog_file18,
5213
- L: 373,
5318
+ F: __dxlog_file19,
5319
+ L: 426,
5214
5320
  S: this,
5215
5321
  C: (f, a) => f(...a)
5216
5322
  });
@@ -5228,8 +5334,8 @@ var DataSpaceManager = class {
5228
5334
  log16("before space close", {
5229
5335
  space: space.key
5230
5336
  }, {
5231
- F: __dxlog_file18,
5232
- L: 381,
5337
+ F: __dxlog_file19,
5338
+ L: 434,
5233
5339
  S: this,
5234
5340
  C: (f, a) => f(...a)
5235
5341
  });
@@ -5269,8 +5375,8 @@ var DataSpaceManager = class {
5269
5375
  peersOnline: presence.getPeersOnline().length,
5270
5376
  closedSessions
5271
5377
  }, {
5272
- F: __dxlog_file18,
5273
- L: 417,
5378
+ F: __dxlog_file19,
5379
+ L: 470,
5274
5380
  S: this,
5275
5381
  C: (f, a) => f(...a)
5276
5382
  });
@@ -5284,8 +5390,8 @@ var DataSpaceManager = class {
5284
5390
  log16("closing a session with a removed peer", {
5285
5391
  peerId: peerState.peerId
5286
5392
  }, {
5287
- F: __dxlog_file18,
5288
- L: 431,
5393
+ F: __dxlog_file19,
5394
+ L: 484,
5289
5395
  S: this,
5290
5396
  C: (f, a) => f(...a)
5291
5397
  });
@@ -5350,13 +5456,13 @@ import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTas
5350
5456
  import { Stream as Stream10 } from "@dxos/codec-protobuf";
5351
5457
  import { createAdmissionCredentials as createAdmissionCredentials2, getCredentialAssertion as getCredentialAssertion4 } from "@dxos/credentials";
5352
5458
  import { raise as raise2 } from "@dxos/debug";
5353
- import { writeMessages as writeMessages3 } from "@dxos/feed-store";
5459
+ import { writeMessages as writeMessages4 } from "@dxos/feed-store";
5354
5460
  import { invariant as invariant15 } from "@dxos/invariant";
5355
5461
  import { log as log17 } from "@dxos/log";
5356
5462
  import { ApiError, SpaceNotFoundError as SpaceNotFoundError2, encodeError, IdentityNotInitializedError, AuthorizationError as AuthorizationError2 } from "@dxos/protocols";
5357
5463
  import { SpaceMember as SpaceMember7, SpaceState as SpaceState4 } from "@dxos/protocols/proto/dxos/client/services";
5358
5464
  import { trace as trace8 } from "@dxos/tracing";
5359
- 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";
5360
5466
  var SpacesServiceImpl = class {
5361
5467
  constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
5362
5468
  this._identityManager = _identityManager;
@@ -5400,8 +5506,8 @@ var SpacesServiceImpl = class {
5400
5506
  }
5401
5507
  const credentials = await createAdmissionCredentials2(identity.getIdentityCredentialSigner(), request.memberKey, space.key, space.genesisFeedKey, request.newRole, space.spaceState.membershipChainHeads);
5402
5508
  invariant15(credentials[0].credential, void 0, {
5403
- F: __dxlog_file19,
5404
- L: 98,
5509
+ F: __dxlog_file20,
5510
+ L: 102,
5405
5511
  S: this,
5406
5512
  A: [
5407
5513
  "credentials[0].credential",
@@ -5410,15 +5516,15 @@ var SpacesServiceImpl = class {
5410
5516
  });
5411
5517
  const spaceMemberCredential = credentials[0].credential.credential;
5412
5518
  invariant15(getCredentialAssertion4(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
5413
- F: __dxlog_file19,
5414
- L: 100,
5519
+ F: __dxlog_file20,
5520
+ L: 104,
5415
5521
  S: this,
5416
5522
  A: [
5417
5523
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
5418
5524
  ""
5419
5525
  ]
5420
5526
  });
5421
- await writeMessages3(space.controlPipeline.writer, credentials);
5527
+ await writeMessages4(space.controlPipeline.writer, credentials);
5422
5528
  }
5423
5529
  querySpaces() {
5424
5530
  return new Stream10(({ next, ctx }) => {
@@ -5428,8 +5534,8 @@ var SpacesServiceImpl = class {
5428
5534
  log17("update", {
5429
5535
  spaces
5430
5536
  }, {
5431
- F: __dxlog_file19,
5432
- L: 111,
5537
+ F: __dxlog_file20,
5538
+ L: 115,
5433
5539
  S: this,
5434
5540
  C: (f, a) => f(...a)
5435
5541
  });
@@ -5520,8 +5626,8 @@ var SpacesServiceImpl = class {
5520
5626
  });
5521
5627
  } else {
5522
5628
  invariant15(!credential.id, "Id on unsigned credentials is not allowed", {
5523
- F: __dxlog_file19,
5524
- L: 209,
5629
+ F: __dxlog_file20,
5630
+ L: 213,
5525
5631
  S: this,
5526
5632
  A: [
5527
5633
  "!credential.id",
@@ -5529,8 +5635,8 @@ var SpacesServiceImpl = class {
5529
5635
  ]
5530
5636
  });
5531
5637
  invariant15(this._identityManager.identity, "Identity is not available", {
5532
- F: __dxlog_file19,
5533
- L: 210,
5638
+ F: __dxlog_file20,
5639
+ L: 214,
5534
5640
  S: this,
5535
5641
  A: [
5536
5642
  "this._identityManager.identity",
@@ -5539,8 +5645,8 @@ var SpacesServiceImpl = class {
5539
5645
  });
5540
5646
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
5541
5647
  invariant15(credential.issuer.equals(signer.getIssuer()), void 0, {
5542
- F: __dxlog_file19,
5543
- L: 212,
5648
+ F: __dxlog_file20,
5649
+ L: 216,
5544
5650
  S: this,
5545
5651
  A: [
5546
5652
  "credential.issuer.equals(signer.getIssuer())",
@@ -5570,6 +5676,59 @@ var SpacesServiceImpl = class {
5570
5676
  epochCredential: credential ?? void 0
5571
5677
  };
5572
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
+ }
5573
5732
  _serializeSpace(space) {
5574
5733
  return {
5575
5734
  id: space.id,
@@ -5657,7 +5816,7 @@ function _ts_decorate6(decorators, target, key, desc) {
5657
5816
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5658
5817
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5659
5818
  }
5660
- var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
5819
+ var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
5661
5820
  var ServiceContext = class extends Resource3 {
5662
5821
  constructor(storage, level, networkManager, signalManager, _runtimeParams) {
5663
5822
  super();
@@ -5701,7 +5860,7 @@ var ServiceContext = class extends Resource3 {
5701
5860
  async _open(ctx) {
5702
5861
  await this._checkStorageVersion();
5703
5862
  log18("opening...", void 0, {
5704
- F: __dxlog_file20,
5863
+ F: __dxlog_file21,
5705
5864
  L: 149,
5706
5865
  S: this,
5707
5866
  C: (f, a) => f(...a)
@@ -5709,7 +5868,7 @@ var ServiceContext = class extends Resource3 {
5709
5868
  log18.trace("dxos.sdk.service-context.open", trace9.begin({
5710
5869
  id: this._instanceId
5711
5870
  }), {
5712
- F: __dxlog_file20,
5871
+ F: __dxlog_file21,
5713
5872
  L: 150,
5714
5873
  S: this,
5715
5874
  C: (f, a) => f(...a)
@@ -5727,7 +5886,7 @@ var ServiceContext = class extends Resource3 {
5727
5886
  log18("loaded persistent invitations", {
5728
5887
  count: loadedInvitations.invitations?.length
5729
5888
  }, {
5730
- F: __dxlog_file20,
5889
+ F: __dxlog_file21,
5731
5890
  L: 163,
5732
5891
  S: this,
5733
5892
  C: (f, a) => f(...a)
@@ -5735,13 +5894,13 @@ var ServiceContext = class extends Resource3 {
5735
5894
  log18.trace("dxos.sdk.service-context.open", trace9.end({
5736
5895
  id: this._instanceId
5737
5896
  }), {
5738
- F: __dxlog_file20,
5897
+ F: __dxlog_file21,
5739
5898
  L: 165,
5740
5899
  S: this,
5741
5900
  C: (f, a) => f(...a)
5742
5901
  });
5743
5902
  log18("opened", void 0, {
5744
- F: __dxlog_file20,
5903
+ F: __dxlog_file21,
5745
5904
  L: 166,
5746
5905
  S: this,
5747
5906
  C: (f, a) => f(...a)
@@ -5749,7 +5908,7 @@ var ServiceContext = class extends Resource3 {
5749
5908
  }
5750
5909
  async _close(ctx) {
5751
5910
  log18("closing...", void 0, {
5752
- F: __dxlog_file20,
5911
+ F: __dxlog_file21,
5753
5912
  L: 170,
5754
5913
  S: this,
5755
5914
  C: (f, a) => f(...a)
@@ -5766,7 +5925,7 @@ var ServiceContext = class extends Resource3 {
5766
5925
  await this.networkManager.close();
5767
5926
  await this.signalManager.close();
5768
5927
  log18("closed", void 0, {
5769
- F: __dxlog_file20,
5928
+ F: __dxlog_file21,
5770
5929
  L: 182,
5771
5930
  S: this,
5772
5931
  C: (f, a) => f(...a)
@@ -5774,13 +5933,16 @@ var ServiceContext = class extends Resource3 {
5774
5933
  }
5775
5934
  async createIdentity(params = {}) {
5776
5935
  const identity = await this.identityManager.createIdentity(params);
5777
- await this._initialize(new Context10());
5936
+ await this._initialize(new Context10(void 0, {
5937
+ F: __dxlog_file21,
5938
+ L: 187
5939
+ }));
5778
5940
  return identity;
5779
5941
  }
5780
5942
  getInvitationHandler(invitation) {
5781
5943
  const factory = this._handlerFactories.get(invitation.kind);
5782
5944
  invariant16(factory, `Unknown invitation kind: ${invitation.kind}`, {
5783
- F: __dxlog_file20,
5945
+ F: __dxlog_file21,
5784
5946
  L: 193,
5785
5947
  S: this,
5786
5948
  A: [
@@ -5800,7 +5962,10 @@ var ServiceContext = class extends Resource3 {
5800
5962
  }
5801
5963
  async _acceptIdentity(params) {
5802
5964
  const identity = await this.identityManager.acceptIdentity(params);
5803
- await this._initialize(new Context10());
5965
+ await this._initialize(new Context10(void 0, {
5966
+ F: __dxlog_file21,
5967
+ L: 209
5968
+ }));
5804
5969
  return identity;
5805
5970
  }
5806
5971
  async _checkStorageVersion() {
@@ -5812,7 +5977,7 @@ var ServiceContext = class extends Resource3 {
5812
5977
  // Called when identity is created.
5813
5978
  async _initialize(ctx) {
5814
5979
  log18("initializing spaces...", void 0, {
5815
- F: __dxlog_file20,
5980
+ F: __dxlog_file21,
5816
5981
  L: 224,
5817
5982
  S: this,
5818
5983
  C: (f, a) => f(...a)
@@ -5835,7 +6000,7 @@ var ServiceContext = class extends Resource3 {
5835
6000
  await this.dataSpaceManager.open();
5836
6001
  this._handlerFactories.set(Invitation8.Kind.SPACE, (invitation) => {
5837
6002
  invariant16(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
5838
- F: __dxlog_file20,
6003
+ F: __dxlog_file21,
5839
6004
  L: 249,
5840
6005
  S: this,
5841
6006
  A: [
@@ -5859,7 +6024,7 @@ var ServiceContext = class extends Resource3 {
5859
6024
  log18("dataSpaceManager not initialized yet, ignoring space admission", {
5860
6025
  details: assertion
5861
6026
  }, {
5862
- F: __dxlog_file20,
6027
+ F: __dxlog_file21,
5863
6028
  L: 265,
5864
6029
  S: this,
5865
6030
  C: (f, a) => f(...a)
@@ -5870,7 +6035,7 @@ var ServiceContext = class extends Resource3 {
5870
6035
  log18("space already exists, ignoring space admission", {
5871
6036
  details: assertion
5872
6037
  }, {
5873
- F: __dxlog_file20,
6038
+ F: __dxlog_file21,
5874
6039
  L: 269,
5875
6040
  S: this,
5876
6041
  C: (f, a) => f(...a)
@@ -5881,7 +6046,7 @@ var ServiceContext = class extends Resource3 {
5881
6046
  log18("accepting space recorded in halo", {
5882
6047
  details: assertion
5883
6048
  }, {
5884
- F: __dxlog_file20,
6049
+ F: __dxlog_file21,
5885
6050
  L: 274,
5886
6051
  S: this,
5887
6052
  C: (f, a) => f(...a)
@@ -5892,7 +6057,7 @@ var ServiceContext = class extends Resource3 {
5892
6057
  });
5893
6058
  } catch (err) {
5894
6059
  log18.catch(err, void 0, {
5895
- F: __dxlog_file20,
6060
+ F: __dxlog_file21,
5896
6061
  L: 280,
5897
6062
  S: this,
5898
6063
  C: (f, a) => f(...a)
@@ -5939,7 +6104,7 @@ var ServiceRegistry = class {
5939
6104
  };
5940
6105
 
5941
6106
  // packages/sdk/client-services/src/packlets/locks/browser.ts
5942
- import { asyncTimeout as asyncTimeout3, Trigger as Trigger9 } from "@dxos/async";
6107
+ import { asyncTimeout as asyncTimeout2, Trigger as Trigger9 } from "@dxos/async";
5943
6108
  import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
5944
6109
  import { log as log19, logInfo } from "@dxos/log";
5945
6110
  function _ts_decorate7(decorators, target, key, desc) {
@@ -5952,7 +6117,7 @@ function _ts_decorate7(decorators, target, key, desc) {
5952
6117
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5953
6118
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5954
6119
  }
5955
- var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
6120
+ var __dxlog_file22 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
5956
6121
  var Message;
5957
6122
  (function(Message2) {
5958
6123
  Message2["ACQUIRING"] = "acquiring";
@@ -5975,28 +6140,28 @@ var Lock = class {
5975
6140
  });
5976
6141
  try {
5977
6142
  log19("aquiring lock...", void 0, {
5978
- F: __dxlog_file21,
6143
+ F: __dxlog_file22,
5979
6144
  L: 42,
5980
6145
  S: this,
5981
6146
  C: (f, a) => f(...a)
5982
6147
  });
5983
- await asyncTimeout3(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
6148
+ await asyncTimeout2(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
5984
6149
  log19("acquired lock", void 0, {
5985
- F: __dxlog_file21,
6150
+ F: __dxlog_file22,
5986
6151
  L: 44,
5987
6152
  S: this,
5988
6153
  C: (f, a) => f(...a)
5989
6154
  });
5990
6155
  } catch {
5991
6156
  log19("stealing lock...", void 0, {
5992
- F: __dxlog_file21,
6157
+ F: __dxlog_file22,
5993
6158
  L: 46,
5994
6159
  S: this,
5995
6160
  C: (f, a) => f(...a)
5996
6161
  });
5997
6162
  await this._requestLock(true);
5998
6163
  log19("stolen lock", void 0, {
5999
- F: __dxlog_file21,
6164
+ F: __dxlog_file22,
6000
6165
  L: 48,
6001
6166
  S: this,
6002
6167
  C: (f, a) => f(...a)
@@ -6015,7 +6180,7 @@ var Lock = class {
6015
6180
  log19("requesting lock...", {
6016
6181
  steal
6017
6182
  }, {
6018
- F: __dxlog_file21,
6183
+ F: __dxlog_file22,
6019
6184
  L: 63,
6020
6185
  S: this,
6021
6186
  C: (f, a) => f(...a)
@@ -6029,14 +6194,14 @@ var Lock = class {
6029
6194
  this._releaseTrigger = new Trigger9();
6030
6195
  await this._releaseTrigger.wait();
6031
6196
  log19("releasing lock...", void 0, {
6032
- F: __dxlog_file21,
6197
+ F: __dxlog_file22,
6033
6198
  L: 72,
6034
6199
  S: this,
6035
6200
  C: (f, a) => f(...a)
6036
6201
  });
6037
6202
  await this._onRelease?.();
6038
6203
  log19("released lock", void 0, {
6039
- F: __dxlog_file21,
6204
+ F: __dxlog_file22,
6040
6205
  L: 74,
6041
6206
  S: this,
6042
6207
  C: (f, a) => f(...a)
@@ -6048,7 +6213,7 @@ var Lock = class {
6048
6213
  log19("recieved lock", {
6049
6214
  steal
6050
6215
  }, {
6051
- F: __dxlog_file21,
6216
+ F: __dxlog_file22,
6052
6217
  L: 81,
6053
6218
  S: this,
6054
6219
  C: (f, a) => f(...a)
@@ -6136,13 +6301,151 @@ var createLevel = async (config) => {
6136
6301
  return level;
6137
6302
  };
6138
6303
 
6304
+ // packages/sdk/client-services/src/packlets/storage/profile-archive.ts
6305
+ import { cbor } from "@dxos/automerge/automerge-repo";
6306
+ import { invariant as invariant17 } from "@dxos/invariant";
6307
+ import { log as log20 } from "@dxos/log";
6308
+ import { ProfileArchiveEntryType } from "@dxos/protocols";
6309
+ import { arrayToBuffer } from "@dxos/util";
6310
+ var __dxlog_file23 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/storage/profile-archive.ts";
6311
+ var encodeProfileArchive = (profile) => cbor.encode(profile);
6312
+ var decodeProfileArchive = (data) => cbor.decode(data);
6313
+ var exportProfileData = async ({ storage, level }) => {
6314
+ const archive = {
6315
+ storage: [],
6316
+ meta: {
6317
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
6318
+ }
6319
+ };
6320
+ {
6321
+ const directory = await storage.createDirectory();
6322
+ const files = await directory.list();
6323
+ log20.info("begin exporting files", {
6324
+ count: files.length
6325
+ }, {
6326
+ F: __dxlog_file23,
6327
+ L: 30,
6328
+ S: void 0,
6329
+ C: (f, a) => f(...a)
6330
+ });
6331
+ for (const filename of files) {
6332
+ const file = await directory.getOrCreateFile(filename);
6333
+ const { size } = await file.stat();
6334
+ const data = await file.read(0, size);
6335
+ archive.storage.push({
6336
+ type: ProfileArchiveEntryType.FILE,
6337
+ key: filename,
6338
+ value: data
6339
+ });
6340
+ }
6341
+ log20.info("done exporting files", {
6342
+ count: files.length
6343
+ }, {
6344
+ F: __dxlog_file23,
6345
+ L: 41,
6346
+ S: void 0,
6347
+ C: (f, a) => f(...a)
6348
+ });
6349
+ }
6350
+ {
6351
+ log20.info("begin exporting kv pairs", void 0, {
6352
+ F: __dxlog_file23,
6353
+ L: 45,
6354
+ S: void 0,
6355
+ C: (f, a) => f(...a)
6356
+ });
6357
+ const iter = await level.iterator({
6358
+ keyEncoding: "binary",
6359
+ valueEncoding: "binary"
6360
+ });
6361
+ let count = 0;
6362
+ for await (const [key, value] of iter) {
6363
+ archive.storage.push({
6364
+ type: ProfileArchiveEntryType.KEY_VALUE,
6365
+ key,
6366
+ value
6367
+ });
6368
+ count++;
6369
+ }
6370
+ log20.info("done exporting kv pairs", {
6371
+ count
6372
+ }, {
6373
+ F: __dxlog_file23,
6374
+ L: 56,
6375
+ S: void 0,
6376
+ C: (f, a) => f(...a)
6377
+ });
6378
+ }
6379
+ return archive;
6380
+ };
6381
+ var importProfileData = async ({ storage, level }, archive) => {
6382
+ const batch = level.batch();
6383
+ for (const entry2 of archive.storage) {
6384
+ switch (entry2.type) {
6385
+ case ProfileArchiveEntryType.FILE: {
6386
+ const directory = await storage.createDirectory();
6387
+ invariant17(typeof entry2.key === "string", "Invalid key type", {
6388
+ F: __dxlog_file23,
6389
+ L: 78,
6390
+ S: void 0,
6391
+ A: [
6392
+ "typeof entry.key === 'string'",
6393
+ "'Invalid key type'"
6394
+ ]
6395
+ });
6396
+ const file = await directory.getOrCreateFile(entry2.key);
6397
+ invariant17(entry2.value instanceof Uint8Array, "Invalid value type", {
6398
+ F: __dxlog_file23,
6399
+ L: 80,
6400
+ S: void 0,
6401
+ A: [
6402
+ "entry.value instanceof Uint8Array",
6403
+ "'Invalid value type'"
6404
+ ]
6405
+ });
6406
+ await file.write(0, arrayToBuffer(entry2.value));
6407
+ await file.close();
6408
+ break;
6409
+ }
6410
+ case ProfileArchiveEntryType.KEY_VALUE: {
6411
+ invariant17(entry2.key instanceof Uint8Array, "Invalid key type", {
6412
+ F: __dxlog_file23,
6413
+ L: 86,
6414
+ S: void 0,
6415
+ A: [
6416
+ "entry.key instanceof Uint8Array",
6417
+ "'Invalid key type'"
6418
+ ]
6419
+ });
6420
+ invariant17(entry2.value instanceof Uint8Array, "Invalid value type", {
6421
+ F: __dxlog_file23,
6422
+ L: 87,
6423
+ S: void 0,
6424
+ A: [
6425
+ "entry.value instanceof Uint8Array",
6426
+ "'Invalid value type'"
6427
+ ]
6428
+ });
6429
+ batch.put(entry2.key, entry2.value, {
6430
+ keyEncoding: "binary",
6431
+ valueEncoding: "binary"
6432
+ });
6433
+ break;
6434
+ }
6435
+ default:
6436
+ throw new Error(`Invalid entry type: ${entry2.type}`);
6437
+ }
6438
+ }
6439
+ await batch.write();
6440
+ };
6441
+
6139
6442
  // packages/sdk/client-services/src/packlets/services/service-host.ts
6140
6443
  import { Event as Event9, synchronized as synchronized3 } from "@dxos/async";
6141
6444
  import { clientServiceBundle } from "@dxos/client-protocol";
6142
6445
  import { Context as Context11 } from "@dxos/context";
6143
- import { invariant as invariant18 } from "@dxos/invariant";
6144
- import { PublicKey as PublicKey16 } from "@dxos/keys";
6145
- import { log as log21 } from "@dxos/log";
6446
+ import { invariant as invariant19 } from "@dxos/invariant";
6447
+ import { PublicKey as PublicKey17 } from "@dxos/keys";
6448
+ import { log as log22 } from "@dxos/log";
6146
6449
  import { WebsocketSignalManager } from "@dxos/messaging";
6147
6450
  import { SwarmNetworkManager, createSimplePeerTransportFactory } from "@dxos/network-manager";
6148
6451
  import { trace as trace10 } from "@dxos/protocols";
@@ -6153,9 +6456,9 @@ import { WebsocketRpcClient } from "@dxos/websocket-rpc";
6153
6456
  // packages/sdk/client-services/src/packlets/devices/devices-service.ts
6154
6457
  import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
6155
6458
  import { Stream as Stream11 } from "@dxos/codec-protobuf";
6156
- import { invariant as invariant17 } from "@dxos/invariant";
6459
+ import { invariant as invariant18 } from "@dxos/invariant";
6157
6460
  import { Device as Device2, DeviceKind as DeviceKind2 } from "@dxos/protocols/proto/dxos/client/services";
6158
- var __dxlog_file22 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
6461
+ var __dxlog_file24 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
6159
6462
  var DevicesServiceImpl = class {
6160
6463
  constructor(_identityManager) {
6161
6464
  this._identityManager = _identityManager;
@@ -6172,8 +6475,8 @@ var DevicesServiceImpl = class {
6172
6475
  devices: []
6173
6476
  });
6174
6477
  } else {
6175
- invariant17(this._identityManager.identity?.presence, "presence not present", {
6176
- F: __dxlog_file22,
6478
+ invariant18(this._identityManager.identity?.presence, "presence not present", {
6479
+ F: __dxlog_file24,
6177
6480
  L: 32,
6178
6481
  S: this,
6179
6482
  A: [
@@ -6279,28 +6582,111 @@ var findConfigs = () => {
6279
6582
  return configs.map((r) => r.instance.deref()).filter(nonNullable);
6280
6583
  };
6281
6584
 
6282
- // packages/sdk/client-services/src/packlets/logging/logging-service.ts
6283
- import { Event as Event8 } from "@dxos/async";
6585
+ // packages/sdk/client-services/src/packlets/identity/contacts-service.ts
6586
+ import { EventSubscriptions as EventSubscriptions4, scheduleTask as scheduleTask7, UpdateScheduler as UpdateScheduler2 } from "@dxos/async";
6284
6587
  import { Stream as Stream12 } from "@dxos/codec-protobuf";
6285
6588
  import { PublicKey as PublicKey15 } from "@dxos/keys";
6286
- import { getContextFromEntry, log as log20 } from "@dxos/log";
6589
+ import { ComplexMap as ComplexMap4, ComplexSet as ComplexSet6 } from "@dxos/util";
6590
+ var ContactsServiceImpl = class {
6591
+ constructor(_identityManager, _spaceManager, _dataSpaceManagerProvider) {
6592
+ this._identityManager = _identityManager;
6593
+ this._spaceManager = _spaceManager;
6594
+ this._dataSpaceManagerProvider = _dataSpaceManagerProvider;
6595
+ }
6596
+ async getContacts() {
6597
+ const identity = this._identityManager.identity;
6598
+ if (identity == null) {
6599
+ return {
6600
+ contacts: []
6601
+ };
6602
+ }
6603
+ const contacts = [
6604
+ ...this._spaceManager.spaces.values()
6605
+ ].flatMap((s) => [
6606
+ ...s.spaceState.members.values()
6607
+ ].map((m) => [
6608
+ s.key,
6609
+ m
6610
+ ])).reduce((acc, v) => {
6611
+ const [spaceKey, memberInfo] = v;
6612
+ if (memberInfo.key.equals(identity.identityKey)) {
6613
+ return acc;
6614
+ }
6615
+ const existing = acc.get(memberInfo.key);
6616
+ if (existing != null) {
6617
+ existing.profile ??= memberInfo.profile;
6618
+ existing.commonSpaces?.push(spaceKey);
6619
+ } else {
6620
+ acc.set(memberInfo.key, {
6621
+ identityKey: memberInfo.key,
6622
+ profile: memberInfo.profile,
6623
+ commonSpaces: [
6624
+ spaceKey
6625
+ ]
6626
+ });
6627
+ }
6628
+ return acc;
6629
+ }, new ComplexMap4(PublicKey15.hash));
6630
+ return {
6631
+ contacts: [
6632
+ ...contacts.values()
6633
+ ]
6634
+ };
6635
+ }
6636
+ queryContacts() {
6637
+ const subscribedSpaceKeySet = new ComplexSet6(PublicKey15.hash);
6638
+ return new Stream12(({ next, ctx }) => {
6639
+ const pushUpdateTask = new UpdateScheduler2(ctx, async () => {
6640
+ const contacts = await this.getContacts();
6641
+ next(contacts);
6642
+ }, {
6643
+ maxFrequency: 2
6644
+ });
6645
+ scheduleTask7(ctx, async () => {
6646
+ const subscriptions = new EventSubscriptions4();
6647
+ ctx.onDispose(() => subscriptions.clear());
6648
+ const subscribeToSpaceAndUpdate = () => {
6649
+ const oldSetSize = subscribedSpaceKeySet.size;
6650
+ for (const space of this._spaceManager.spaces.values()) {
6651
+ if (!subscribedSpaceKeySet.has(space.key)) {
6652
+ subscriptions.add(space.stateUpdate.on(ctx, () => pushUpdateTask.trigger()));
6653
+ subscribedSpaceKeySet.add(space.key);
6654
+ }
6655
+ }
6656
+ if (oldSetSize !== subscribedSpaceKeySet.size) {
6657
+ pushUpdateTask.trigger();
6658
+ }
6659
+ };
6660
+ const unsubscribe = (await this._dataSpaceManagerProvider()).updated.on(ctx, subscribeToSpaceAndUpdate);
6661
+ ctx.onDispose(unsubscribe);
6662
+ subscribeToSpaceAndUpdate();
6663
+ });
6664
+ });
6665
+ }
6666
+ };
6667
+
6668
+ // packages/sdk/client-services/src/packlets/logging/logging-service.ts
6669
+ import { Event as Event8 } from "@dxos/async";
6670
+ import { Stream as Stream13 } from "@dxos/codec-protobuf";
6671
+ import { PublicKey as PublicKey16 } from "@dxos/keys";
6672
+ import { getContextFromEntry, log as log21 } from "@dxos/log";
6287
6673
  import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
6288
6674
  import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
6289
6675
  var LoggingServiceImpl = class {
6290
6676
  constructor() {
6291
6677
  this._logs = new Event8();
6292
6678
  this._started = Date.now();
6293
- this._sessionId = PublicKey15.random().toHex();
6679
+ this._sessionId = PublicKey16.random().toHex();
6294
6680
  this._logProcessor = (_config, entry2) => {
6295
6681
  this._logs.emit(entry2);
6296
6682
  };
6297
6683
  }
6298
6684
  async open() {
6299
- log20.runtimeConfig.processors.push(this._logProcessor);
6685
+ log21.runtimeConfig.processors.push(this._logProcessor);
6300
6686
  }
6301
6687
  async close() {
6302
- const index = log20.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
6303
- log20.runtimeConfig.processors.splice(index, 1);
6688
+ const index = log21.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
6689
+ log21.runtimeConfig.processors.splice(index, 1);
6304
6690
  }
6305
6691
  async controlMetrics({ reset, record }) {
6306
6692
  if (reset) {
@@ -6326,7 +6712,7 @@ var LoggingServiceImpl = class {
6326
6712
  stats: numericalValues(events, "duration")
6327
6713
  };
6328
6714
  };
6329
- return new Stream12(({ next }) => {
6715
+ return new Stream13(({ next }) => {
6330
6716
  const update = () => {
6331
6717
  const metrics = {
6332
6718
  timestamp: /* @__PURE__ */ new Date(),
@@ -6348,7 +6734,7 @@ var LoggingServiceImpl = class {
6348
6734
  });
6349
6735
  }
6350
6736
  queryLogs(request) {
6351
- return new Stream12(({ ctx, next }) => {
6737
+ return new Stream13(({ ctx, next }) => {
6352
6738
  const handler = (entry2) => {
6353
6739
  if (LOG_PROCESSING > 0) {
6354
6740
  return;
@@ -6404,14 +6790,14 @@ var shouldLog = (entry2, request) => {
6404
6790
  var LOG_PROCESSING = 0;
6405
6791
 
6406
6792
  // packages/sdk/client-services/src/packlets/network/network-service.ts
6407
- import { Stream as Stream13 } from "@dxos/codec-protobuf";
6793
+ import { Stream as Stream14 } from "@dxos/codec-protobuf";
6408
6794
  var NetworkServiceImpl = class {
6409
6795
  constructor(networkManager, signalManager) {
6410
6796
  this.networkManager = networkManager;
6411
6797
  this.signalManager = signalManager;
6412
6798
  }
6413
6799
  queryStatus() {
6414
- return new Stream13(({ next }) => {
6800
+ return new Stream14(({ next }) => {
6415
6801
  const update = () => {
6416
6802
  next({
6417
6803
  swarm: this.networkManager.connectionState,
@@ -6437,7 +6823,7 @@ var NetworkServiceImpl = class {
6437
6823
  };
6438
6824
 
6439
6825
  // packages/sdk/client-services/src/packlets/system/system-service.ts
6440
- import { Stream as Stream14 } from "@dxos/codec-protobuf";
6826
+ import { Stream as Stream15 } from "@dxos/codec-protobuf";
6441
6827
  import { GetDiagnosticsRequest as GetDiagnosticsRequest2 } from "@dxos/protocols/proto/dxos/client/services";
6442
6828
  import { jsonKeyReplacer as jsonKeyReplacer2 } from "@dxos/util";
6443
6829
  var SystemServiceImpl = class {
@@ -6473,7 +6859,7 @@ var SystemServiceImpl = class {
6473
6859
  }
6474
6860
  // TODO(burdon): Standardize interval option in stream request?
6475
6861
  queryStatus({ interval = 3e3 } = {}) {
6476
- return new Stream14(({ next }) => {
6862
+ return new Stream15(({ next }) => {
6477
6863
  const update = () => {
6478
6864
  next({
6479
6865
  status: this._getCurrentStatus()
@@ -6504,7 +6890,7 @@ function _ts_decorate8(decorators, target, key, desc) {
6504
6890
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6505
6891
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6506
6892
  }
6507
- var __dxlog_file23 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
6893
+ var __dxlog_file25 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
6508
6894
  var ClientServicesHost = class {
6509
6895
  constructor({
6510
6896
  config,
@@ -6537,7 +6923,10 @@ var ClientServicesHost = class {
6537
6923
  lockKey,
6538
6924
  onAcquire: () => {
6539
6925
  if (!this._opening) {
6540
- void this.open(new Context11());
6926
+ void this.open(new Context11(void 0, {
6927
+ F: __dxlog_file25,
6928
+ L: 121
6929
+ }));
6541
6930
  }
6542
6931
  },
6543
6932
  onRelease: () => this.close()
@@ -6592,25 +6981,25 @@ var ClientServicesHost = class {
6592
6981
  * Can only be called once.
6593
6982
  */
6594
6983
  initialize({ config, ...options }) {
6595
- invariant18(!this._open, "service host is open", {
6596
- F: __dxlog_file23,
6597
- L: 186,
6984
+ invariant19(!this._open, "service host is open", {
6985
+ F: __dxlog_file25,
6986
+ L: 187,
6598
6987
  S: this,
6599
6988
  A: [
6600
6989
  "!this._open",
6601
6990
  "'service host is open'"
6602
6991
  ]
6603
6992
  });
6604
- log21("initializing...", void 0, {
6605
- F: __dxlog_file23,
6606
- L: 187,
6993
+ log22("initializing...", void 0, {
6994
+ F: __dxlog_file25,
6995
+ L: 188,
6607
6996
  S: this,
6608
6997
  C: (f, a) => f(...a)
6609
6998
  });
6610
6999
  if (config) {
6611
- invariant18(!this._config, "config already set", {
6612
- F: __dxlog_file23,
6613
- L: 190,
7000
+ invariant19(!this._config, "config already set", {
7001
+ F: __dxlog_file25,
7002
+ L: 191,
6614
7003
  S: this,
6615
7004
  A: [
6616
7005
  "!this._config",
@@ -6623,9 +7012,9 @@ var ClientServicesHost = class {
6623
7012
  }
6624
7013
  }
6625
7014
  if (!options.signalManager) {
6626
- log21.warn("running signaling without telemetry metadata.", void 0, {
6627
- F: __dxlog_file23,
6628
- L: 198,
7015
+ log22.warn("running signaling without telemetry metadata.", void 0, {
7016
+ F: __dxlog_file25,
7017
+ L: 199,
6629
7018
  S: this,
6630
7019
  C: (f, a) => f(...a)
6631
7020
  });
@@ -6634,9 +7023,9 @@ var ClientServicesHost = class {
6634
7023
  iceServers: this._config?.get("runtime.services.ice")
6635
7024
  }), signalManager = new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
6636
7025
  this._signalManager = signalManager;
6637
- invariant18(!this._networkManager, "network manager already set", {
6638
- F: __dxlog_file23,
6639
- L: 209,
7026
+ invariant19(!this._networkManager, "network manager already set", {
7027
+ F: __dxlog_file25,
7028
+ L: 210,
6640
7029
  S: this,
6641
7030
  A: [
6642
7031
  "!this._networkManager",
@@ -6648,9 +7037,9 @@ var ClientServicesHost = class {
6648
7037
  transportFactory,
6649
7038
  signalManager
6650
7039
  });
6651
- log21("initialized", void 0, {
6652
- F: __dxlog_file23,
6653
- L: 216,
7040
+ log22("initialized", void 0, {
7041
+ F: __dxlog_file25,
7042
+ L: 217,
6654
7043
  S: this,
6655
7044
  C: (f, a) => f(...a)
6656
7045
  });
@@ -6659,45 +7048,45 @@ var ClientServicesHost = class {
6659
7048
  if (this._open) {
6660
7049
  return;
6661
7050
  }
6662
- const traceId = PublicKey16.random().toHex();
6663
- log21.trace("dxos.client-services.host.open", trace10.begin({
7051
+ const traceId = PublicKey17.random().toHex();
7052
+ log22.trace("dxos.client-services.host.open", trace10.begin({
6664
7053
  id: traceId
6665
7054
  }), {
6666
- F: __dxlog_file23,
6667
- L: 227,
7055
+ F: __dxlog_file25,
7056
+ L: 228,
6668
7057
  S: this,
6669
7058
  C: (f, a) => f(...a)
6670
7059
  });
6671
- invariant18(this._config, "config not set", {
6672
- F: __dxlog_file23,
6673
- L: 229,
7060
+ invariant19(this._config, "config not set", {
7061
+ F: __dxlog_file25,
7062
+ L: 230,
6674
7063
  S: this,
6675
7064
  A: [
6676
7065
  "this._config",
6677
7066
  "'config not set'"
6678
7067
  ]
6679
7068
  });
6680
- invariant18(this._storage, "storage not set", {
6681
- F: __dxlog_file23,
6682
- L: 230,
7069
+ invariant19(this._storage, "storage not set", {
7070
+ F: __dxlog_file25,
7071
+ L: 231,
6683
7072
  S: this,
6684
7073
  A: [
6685
7074
  "this._storage",
6686
7075
  "'storage not set'"
6687
7076
  ]
6688
7077
  });
6689
- invariant18(this._signalManager, "signal manager not set", {
6690
- F: __dxlog_file23,
6691
- L: 231,
7078
+ invariant19(this._signalManager, "signal manager not set", {
7079
+ F: __dxlog_file25,
7080
+ L: 232,
6692
7081
  S: this,
6693
7082
  A: [
6694
7083
  "this._signalManager",
6695
7084
  "'signal manager not set'"
6696
7085
  ]
6697
7086
  });
6698
- invariant18(this._networkManager, "network manager not set", {
6699
- F: __dxlog_file23,
6700
- L: 232,
7087
+ invariant19(this._networkManager, "network manager not set", {
7088
+ F: __dxlog_file25,
7089
+ L: 233,
6701
7090
  S: this,
6702
7091
  A: [
6703
7092
  "this._networkManager",
@@ -6705,11 +7094,11 @@ var ClientServicesHost = class {
6705
7094
  ]
6706
7095
  });
6707
7096
  this._opening = true;
6708
- log21("opening...", {
7097
+ log22("opening...", {
6709
7098
  lockKey: this._resourceLock?.lockKey
6710
7099
  }, {
6711
- F: __dxlog_file23,
6712
- L: 235,
7100
+ F: __dxlog_file25,
7101
+ L: 236,
6713
7102
  S: this,
6714
7103
  C: (f, a) => f(...a)
6715
7104
  });
@@ -6720,16 +7109,18 @@ var ClientServicesHost = class {
6720
7109
  await this._level.open();
6721
7110
  await this._loggingService.open();
6722
7111
  this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._runtimeParams);
7112
+ const dataSpaceManagerProvider = async () => {
7113
+ await this._serviceContext.initialized.wait();
7114
+ return this._serviceContext.dataSpaceManager;
7115
+ };
6723
7116
  const identityService = new IdentityServiceImpl(this._serviceContext.identityManager, this._serviceContext.keyring, () => this._serviceContext.dataSpaceManager, (params) => this._createIdentity(params), (profile) => this._serviceContext.broadcastProfileUpdate(profile));
6724
7117
  this._serviceRegistry.setServices({
6725
7118
  SystemService: this._systemService,
6726
7119
  IdentityService: identityService,
7120
+ ContactsService: new ContactsServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, dataSpaceManagerProvider),
6727
7121
  InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitationsManager),
6728
7122
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
6729
- SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, async () => {
6730
- await this._serviceContext.initialized.wait();
6731
- return this._serviceContext.dataSpaceManager;
6732
- }),
7123
+ SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, dataSpaceManagerProvider),
6733
7124
  DataService: this._serviceContext.echoHost.dataService,
6734
7125
  QueryService: this._serviceContext.echoHost.queryService,
6735
7126
  NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager, this._serviceContext.signalManager),
@@ -6759,19 +7150,19 @@ var ClientServicesHost = class {
6759
7150
  this._open = true;
6760
7151
  this._statusUpdate.emit();
6761
7152
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
6762
- log21("opened", {
7153
+ log22("opened", {
6763
7154
  deviceKey
6764
7155
  }, {
6765
- F: __dxlog_file23,
6766
- L: 314,
7156
+ F: __dxlog_file25,
7157
+ L: 322,
6767
7158
  S: this,
6768
7159
  C: (f, a) => f(...a)
6769
7160
  });
6770
- log21.trace("dxos.client-services.host.open", trace10.end({
7161
+ log22.trace("dxos.client-services.host.open", trace10.end({
6771
7162
  id: traceId
6772
7163
  }), {
6773
- F: __dxlog_file23,
6774
- L: 315,
7164
+ F: __dxlog_file25,
7165
+ L: 323,
6775
7166
  S: this,
6776
7167
  C: (f, a) => f(...a)
6777
7168
  });
@@ -6781,11 +7172,11 @@ var ClientServicesHost = class {
6781
7172
  return;
6782
7173
  }
6783
7174
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
6784
- log21("closing...", {
7175
+ log22("closing...", {
6785
7176
  deviceKey
6786
7177
  }, {
6787
- F: __dxlog_file23,
6788
- L: 326,
7178
+ F: __dxlog_file25,
7179
+ L: 334,
6789
7180
  S: this,
6790
7181
  C: (f, a) => f(...a)
6791
7182
  });
@@ -6799,44 +7190,44 @@ var ClientServicesHost = class {
6799
7190
  await this._level?.close();
6800
7191
  this._open = false;
6801
7192
  this._statusUpdate.emit();
6802
- log21("closed", {
7193
+ log22("closed", {
6803
7194
  deviceKey
6804
7195
  }, {
6805
- F: __dxlog_file23,
6806
- L: 335,
7196
+ F: __dxlog_file25,
7197
+ L: 343,
6807
7198
  S: this,
6808
7199
  C: (f, a) => f(...a)
6809
7200
  });
6810
7201
  }
6811
7202
  async reset() {
6812
- const traceId = PublicKey16.random().toHex();
6813
- log21.trace("dxos.sdk.client-services-host.reset", trace10.begin({
7203
+ const traceId = PublicKey17.random().toHex();
7204
+ log22.trace("dxos.sdk.client-services-host.reset", trace10.begin({
6814
7205
  id: traceId
6815
7206
  }), {
6816
- F: __dxlog_file23,
6817
- L: 340,
7207
+ F: __dxlog_file25,
7208
+ L: 348,
6818
7209
  S: this,
6819
7210
  C: (f, a) => f(...a)
6820
7211
  });
6821
- log21.info("resetting...", void 0, {
6822
- F: __dxlog_file23,
6823
- L: 342,
7212
+ log22.info("resetting...", void 0, {
7213
+ F: __dxlog_file25,
7214
+ L: 350,
6824
7215
  S: this,
6825
7216
  C: (f, a) => f(...a)
6826
7217
  });
6827
7218
  await this._serviceContext?.close();
6828
7219
  await this._storage.reset();
6829
- log21.info("reset", void 0, {
6830
- F: __dxlog_file23,
6831
- L: 345,
7220
+ log22.info("reset", void 0, {
7221
+ F: __dxlog_file25,
7222
+ L: 353,
6832
7223
  S: this,
6833
7224
  C: (f, a) => f(...a)
6834
7225
  });
6835
- log21.trace("dxos.sdk.client-services-host.reset", trace10.end({
7226
+ log22.trace("dxos.sdk.client-services-host.reset", trace10.end({
6836
7227
  id: traceId
6837
7228
  }), {
6838
- F: __dxlog_file23,
6839
- L: 346,
7229
+ F: __dxlog_file25,
7230
+ L: 354,
6840
7231
  S: this,
6841
7232
  C: (f, a) => f(...a)
6842
7233
  });
@@ -6902,8 +7293,12 @@ export {
6902
7293
  isLocked,
6903
7294
  createStorageObjects,
6904
7295
  createLevel,
7296
+ encodeProfileArchive,
7297
+ decodeProfileArchive,
7298
+ exportProfileData,
7299
+ importProfileData,
6905
7300
  ClientServicesHost,
6906
7301
  ClientServicesProviderResource,
6907
7302
  DiagnosticsCollector
6908
7303
  };
6909
- //# sourceMappingURL=chunk-7ZORW75D.mjs.map
7304
+ //# sourceMappingURL=chunk-DS5JZ6S4.mjs.map