@dxos/client-services 0.5.1-main.c37e119 → 0.5.1-main.d27379b

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 (66) hide show
  1. package/dist/lib/browser/{chunk-RQIV4DQ6.mjs → chunk-WNEYCJRZ.mjs} +1297 -941
  2. package/dist/lib/browser/chunk-WNEYCJRZ.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -1
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/packlets/testing/index.mjs +29 -9
  6. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  7. package/dist/lib/node/{chunk-ND5EXSJK.cjs → chunk-QGN3CBJ4.cjs} +1461 -1113
  8. package/dist/lib/node/chunk-QGN3CBJ4.cjs.map +7 -0
  9. package/dist/lib/node/index.cjs +43 -43
  10. package/dist/lib/node/meta.json +1 -1
  11. package/dist/lib/node/packlets/testing/index.cjs +35 -15
  12. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  13. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +2 -1
  14. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
  15. package/dist/types/src/packlets/invitations/invitation-guest-extenstion.d.ts +39 -0
  16. package/dist/types/src/packlets/invitations/invitation-guest-extenstion.d.ts.map +1 -0
  17. package/dist/types/src/packlets/invitations/{invitation-extension.d.ts → invitation-host-extension.d.ts} +17 -31
  18. package/dist/types/src/packlets/invitations/invitation-host-extension.d.ts.map +1 -0
  19. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +6 -1
  20. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
  21. package/dist/types/src/packlets/invitations/invitation-topology.d.ts +37 -0
  22. package/dist/types/src/packlets/invitations/invitation-topology.d.ts.map +1 -0
  23. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +19 -10
  24. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  25. package/dist/types/src/packlets/invitations/invitations-handler.test.d.ts +2 -0
  26. package/dist/types/src/packlets/invitations/invitations-handler.test.d.ts.map +1 -0
  27. package/dist/types/src/packlets/invitations/invitations-manager.d.ts +2 -1
  28. package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -1
  29. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +1 -0
  30. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  31. package/dist/types/src/packlets/invitations/utils.d.ts +6 -0
  32. package/dist/types/src/packlets/invitations/utils.d.ts.map +1 -0
  33. package/dist/types/src/packlets/services/service-context.d.ts +8 -5
  34. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  35. package/dist/types/src/packlets/services/service-host.d.ts +1 -1
  36. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  37. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  38. package/dist/types/src/packlets/storage/level.d.ts +1 -2
  39. package/dist/types/src/packlets/storage/level.d.ts.map +1 -1
  40. package/dist/types/src/packlets/testing/invitation-utils.d.ts +2 -1
  41. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  42. package/dist/types/src/packlets/testing/test-builder.d.ts +2 -1
  43. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  44. package/dist/types/src/version.d.ts +1 -1
  45. package/package.json +36 -35
  46. package/src/packlets/invitations/device-invitation-protocol.ts +5 -1
  47. package/src/packlets/invitations/invitation-guest-extenstion.ts +126 -0
  48. package/src/packlets/invitations/{invitation-extension.ts → invitation-host-extension.ts} +99 -105
  49. package/src/packlets/invitations/invitation-protocol.ts +7 -1
  50. package/src/packlets/invitations/invitation-topology.ts +87 -0
  51. package/src/packlets/invitations/invitations-handler.test.ts +361 -0
  52. package/src/packlets/invitations/invitations-handler.ts +246 -149
  53. package/src/packlets/invitations/invitations-manager.ts +42 -3
  54. package/src/packlets/invitations/space-invitation-protocol.ts +19 -1
  55. package/src/packlets/invitations/utils.ts +27 -0
  56. package/src/packlets/services/automerge-host.test.ts +3 -1
  57. package/src/packlets/services/service-context.ts +7 -6
  58. package/src/packlets/services/service-host.ts +5 -6
  59. package/src/packlets/spaces/data-space.ts +2 -1
  60. package/src/packlets/storage/level.ts +2 -2
  61. package/src/packlets/testing/invitation-utils.ts +23 -3
  62. package/src/packlets/testing/test-builder.ts +6 -3
  63. package/src/version.ts +1 -1
  64. package/dist/lib/browser/chunk-RQIV4DQ6.mjs.map +0 -7
  65. package/dist/lib/node/chunk-ND5EXSJK.cjs.map +0 -7
  66. package/dist/types/src/packlets/invitations/invitation-extension.d.ts.map +0 -1
@@ -1196,13 +1196,16 @@ var DeviceInvitationProtocol = class {
1196
1196
  kind: Invitation.Kind.DEVICE
1197
1197
  };
1198
1198
  }
1199
- async delegate(invitation) {
1199
+ async delegate() {
1200
+ throw new Error("delegation not supported");
1201
+ }
1202
+ async cancelDelegation() {
1200
1203
  throw new Error("delegation not supported");
1201
1204
  }
1202
1205
  async admit(_, request) {
1203
1206
  invariant4(request.device, void 0, {
1204
1207
  F: __dxlog_file5,
1205
- L: 42,
1208
+ L: 46,
1206
1209
  S: this,
1207
1210
  A: [
1208
1211
  "request.device",
@@ -1248,7 +1251,7 @@ var DeviceInvitationProtocol = class {
1248
1251
  async accept(response, request) {
1249
1252
  invariant4(response.device, void 0, {
1250
1253
  F: __dxlog_file5,
1251
- L: 87,
1254
+ L: 91,
1252
1255
  S: this,
1253
1256
  A: [
1254
1257
  "response.device",
@@ -1258,7 +1261,7 @@ var DeviceInvitationProtocol = class {
1258
1261
  const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
1259
1262
  invariant4(request.device, void 0, {
1260
1263
  F: __dxlog_file5,
1261
- L: 90,
1264
+ L: 94,
1262
1265
  S: this,
1263
1266
  A: [
1264
1267
  "request.device",
@@ -1283,34 +1286,53 @@ var DeviceInvitationProtocol = class {
1283
1286
  };
1284
1287
 
1285
1288
  // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
1286
- import { PushStream, scheduleTask as scheduleTask2, TimeoutError, Trigger as Trigger3 } from "@dxos/async";
1287
- import { AuthenticatingInvitation, INVITATION_TIMEOUT } from "@dxos/client-protocol";
1288
- import { Context as Context5 } from "@dxos/context";
1289
+ import { Mutex, scheduleTask as scheduleTask3, TimeoutError } from "@dxos/async";
1290
+ import { INVITATION_TIMEOUT } from "@dxos/client-protocol";
1291
+ import { ContextDisposedError as ContextDisposedError2 } from "@dxos/context";
1289
1292
  import { createKeyPair, sign } from "@dxos/crypto";
1290
- import { invariant as invariant6 } from "@dxos/invariant";
1291
- import { PublicKey as PublicKey6 } from "@dxos/keys";
1292
- import { log as log5 } from "@dxos/log";
1293
- import { createTeleportProtocolFactory, StarTopology } from "@dxos/network-manager";
1294
- import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError2, trace as trace4 } from "@dxos/protocols";
1295
- import { Invitation as Invitation3 } from "@dxos/protocols/proto/dxos/client/services";
1293
+ import { invariant as invariant8 } from "@dxos/invariant";
1294
+ import { PublicKey as PublicKey7 } from "@dxos/keys";
1295
+ import { log as log7 } from "@dxos/log";
1296
+ import { createTeleportProtocolFactory } from "@dxos/network-manager";
1297
+ import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError3, trace as trace4 } from "@dxos/protocols";
1298
+ import { Invitation as Invitation4 } from "@dxos/protocols/proto/dxos/client/services";
1296
1299
  import { AuthenticationResponse as AuthenticationResponse2 } from "@dxos/protocols/proto/dxos/halo/invitations";
1300
+ import { Options as Options4 } from "@dxos/protocols/proto/dxos/halo/invitations";
1301
+ import { ComplexSet as ComplexSet3 } from "@dxos/util";
1297
1302
 
1298
- // packages/sdk/client-services/src/packlets/invitations/invitation-extension.ts
1303
+ // packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts
1299
1304
  import { Trigger as Trigger2 } from "@dxos/async";
1300
- import { cancelWithContext, Context as Context4 } from "@dxos/context";
1301
- import { randomBytes, verify } from "@dxos/crypto";
1305
+ import { cancelWithContext as cancelWithContext2, Context as Context4 } from "@dxos/context";
1302
1306
  import { invariant as invariant5 } from "@dxos/invariant";
1303
- import { PublicKey as PublicKey5 } from "@dxos/keys";
1304
1307
  import { log as log4 } from "@dxos/log";
1305
- import { InvalidInvitationExtensionRoleError, schema as schema2, trace as trace3 } from "@dxos/protocols";
1306
- import { Invitation as Invitation2 } from "@dxos/protocols/proto/dxos/client/services";
1307
- import { AuthenticationResponse, Options } from "@dxos/protocols/proto/dxos/halo/invitations";
1308
+ import { InvalidInvitationExtensionRoleError, schema as schema2 } from "@dxos/protocols";
1309
+ import { Options } from "@dxos/protocols/proto/dxos/halo/invitations";
1308
1310
  import { RpcExtension } from "@dxos/teleport";
1309
- var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-extension.ts";
1311
+
1312
+ // packages/sdk/client-services/src/packlets/invitations/utils.ts
1313
+ import { cancelWithContext, ContextDisposedError } from "@dxos/context";
1314
+ import { Invitation as Invitation2 } from "@dxos/protocols/proto/dxos/client/services";
1315
+ var stateToString = (state) => {
1316
+ return Object.entries(Invitation2.State).find(([key, val]) => val === state)?.[0] ?? "unknown";
1317
+ };
1318
+ var tryAcquireBeforeContextDisposed = async (ctx, mutex) => {
1319
+ let guard;
1320
+ return cancelWithContext(ctx, (async () => {
1321
+ guard = await mutex.acquire();
1322
+ if (ctx.disposed) {
1323
+ guard.release();
1324
+ guard = void 0;
1325
+ throw new ContextDisposedError();
1326
+ }
1327
+ return guard;
1328
+ })());
1329
+ };
1330
+
1331
+ // packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts
1332
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts";
1310
1333
  var OPTIONS_TIMEOUT = 1e4;
1311
- var MAX_OTP_ATTEMPTS = 3;
1312
- var InvitationHostExtension = class extends RpcExtension {
1313
- constructor(_callbacks) {
1334
+ var InvitationGuestExtension = class extends RpcExtension {
1335
+ constructor(_invitationFlowMutex, _callbacks) {
1314
1336
  super({
1315
1337
  requested: {
1316
1338
  InvitationHostService: schema2.getService("dxos.halo.invitations.InvitationHostService")
@@ -1319,15 +1341,152 @@ var InvitationHostExtension = class extends RpcExtension {
1319
1341
  InvitationHostService: schema2.getService("dxos.halo.invitations.InvitationHostService")
1320
1342
  }
1321
1343
  });
1344
+ this._invitationFlowMutex = _invitationFlowMutex;
1322
1345
  this._callbacks = _callbacks;
1323
1346
  this._ctx = new Context4();
1324
1347
  this._remoteOptionsTrigger = new Trigger2();
1348
+ this._invitationFlowLock = null;
1349
+ }
1350
+ hasFlowLock() {
1351
+ return this._invitationFlowLock != null;
1352
+ }
1353
+ async getHandlers() {
1354
+ return {
1355
+ InvitationHostService: {
1356
+ options: async (options) => {
1357
+ invariant5(!this._remoteOptions, "Remote options already set.", {
1358
+ F: __dxlog_file6,
1359
+ L: 63,
1360
+ S: this,
1361
+ A: [
1362
+ "!this._remoteOptions",
1363
+ "'Remote options already set.'"
1364
+ ]
1365
+ });
1366
+ this._remoteOptions = options;
1367
+ this._remoteOptionsTrigger.wake();
1368
+ },
1369
+ introduce: () => {
1370
+ throw new Error("Method not allowed.");
1371
+ },
1372
+ authenticate: () => {
1373
+ throw new Error("Method not allowed.");
1374
+ },
1375
+ admit: () => {
1376
+ throw new Error("Method not allowed.");
1377
+ }
1378
+ }
1379
+ };
1380
+ }
1381
+ async onOpen(context) {
1382
+ await super.onOpen(context);
1383
+ try {
1384
+ log4("guest acquire lock", void 0, {
1385
+ F: __dxlog_file6,
1386
+ L: 84,
1387
+ S: this,
1388
+ C: (f, a) => f(...a)
1389
+ });
1390
+ this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
1391
+ log4("guest lock acquired", void 0, {
1392
+ F: __dxlog_file6,
1393
+ L: 86,
1394
+ S: this,
1395
+ C: (f, a) => f(...a)
1396
+ });
1397
+ await cancelWithContext2(this._ctx, this.rpc.InvitationHostService.options({
1398
+ role: Options.Role.GUEST
1399
+ }));
1400
+ log4("options sent", void 0, {
1401
+ F: __dxlog_file6,
1402
+ L: 88,
1403
+ S: this,
1404
+ C: (f, a) => f(...a)
1405
+ });
1406
+ await cancelWithContext2(this._ctx, this._remoteOptionsTrigger.wait({
1407
+ timeout: OPTIONS_TIMEOUT
1408
+ }));
1409
+ log4("options received", void 0, {
1410
+ F: __dxlog_file6,
1411
+ L: 90,
1412
+ S: this,
1413
+ C: (f, a) => f(...a)
1414
+ });
1415
+ if (this._remoteOptions?.role !== Options.Role.HOST) {
1416
+ throw new InvalidInvitationExtensionRoleError(void 0, {
1417
+ expected: Options.Role.HOST,
1418
+ remoteOptions: this._remoteOptions,
1419
+ remotePeerId: context.remotePeerId
1420
+ });
1421
+ }
1422
+ this._callbacks.onOpen(this._ctx, context);
1423
+ } catch (err) {
1424
+ if (this._invitationFlowLock != null) {
1425
+ this._callbacks.onError(err);
1426
+ }
1427
+ if (!this._ctx.disposed) {
1428
+ context.close(err);
1429
+ }
1430
+ }
1431
+ }
1432
+ async onClose() {
1433
+ await this._destroy();
1434
+ }
1435
+ async onAbort() {
1436
+ await this._destroy();
1437
+ }
1438
+ async _destroy() {
1439
+ await this._ctx.dispose();
1440
+ if (this._invitationFlowLock != null) {
1441
+ this._invitationFlowLock.release();
1442
+ this._invitationFlowLock = null;
1443
+ log4("invitation flow lock released", void 0, {
1444
+ F: __dxlog_file6,
1445
+ L: 123,
1446
+ S: this,
1447
+ C: (f, a) => f(...a)
1448
+ });
1449
+ }
1450
+ }
1451
+ };
1452
+
1453
+ // packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts
1454
+ import { Trigger as Trigger3, scheduleTask as scheduleTask2 } from "@dxos/async";
1455
+ import { cancelWithContext as cancelWithContext3, Context as Context5 } from "@dxos/context";
1456
+ import { randomBytes, verify } from "@dxos/crypto";
1457
+ import { invariant as invariant6, InvariantViolation } from "@dxos/invariant";
1458
+ import { PublicKey as PublicKey5 } from "@dxos/keys";
1459
+ import { log as log5 } from "@dxos/log";
1460
+ import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError2, schema as schema3, trace as trace3 } from "@dxos/protocols";
1461
+ import { Invitation as Invitation3 } from "@dxos/protocols/proto/dxos/client/services";
1462
+ import { AuthenticationResponse, Options as Options2 } from "@dxos/protocols/proto/dxos/halo/invitations";
1463
+ import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
1464
+ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts";
1465
+ var OPTIONS_TIMEOUT2 = 1e4;
1466
+ var MAX_OTP_ATTEMPTS = 3;
1467
+ var InvitationHostExtension = class extends RpcExtension2 {
1468
+ constructor(_invitationFlowMutex, _callbacks) {
1469
+ super({
1470
+ requested: {
1471
+ InvitationHostService: schema3.getService("dxos.halo.invitations.InvitationHostService")
1472
+ },
1473
+ exposed: {
1474
+ InvitationHostService: schema3.getService("dxos.halo.invitations.InvitationHostService")
1475
+ }
1476
+ });
1477
+ this._invitationFlowMutex = _invitationFlowMutex;
1478
+ this._callbacks = _callbacks;
1479
+ this._ctx = new Context5();
1480
+ this._remoteOptionsTrigger = new Trigger3();
1325
1481
  this._challenge = void 0;
1326
- this.invitation = void 0;
1327
1482
  this.guestProfile = void 0;
1328
1483
  this.authenticationPassed = false;
1329
1484
  this.authenticationRetry = 0;
1330
- this.completedTrigger = new Trigger2();
1485
+ this.completedTrigger = new Trigger3();
1486
+ this._invitationFlowLock = null;
1487
+ }
1488
+ hasFlowLock() {
1489
+ return this._invitationFlowLock != null;
1331
1490
  }
1332
1491
  async getHandlers() {
1333
1492
  return {
@@ -1335,9 +1494,9 @@ var InvitationHostExtension = class extends RpcExtension {
1335
1494
  // Perhaps in the future we will have more complex logic here.
1336
1495
  InvitationHostService: {
1337
1496
  options: async (options) => {
1338
- invariant5(!this._remoteOptions, "Remote options already set.", {
1339
- F: __dxlog_file6,
1340
- L: 90,
1497
+ invariant6(!this._remoteOptions, "Remote options already set.", {
1498
+ F: __dxlog_file7,
1499
+ L: 101,
1341
1500
  S: this,
1342
1501
  A: [
1343
1502
  "!this._remoteOptions",
@@ -1350,90 +1509,86 @@ var InvitationHostExtension = class extends RpcExtension {
1350
1509
  introduce: async (request) => {
1351
1510
  const { profile, invitationId } = request;
1352
1511
  const traceId = PublicKey5.random().toHex();
1353
- log4.trace("dxos.sdk.invitation-handler.host.introduce", trace3.begin({
1512
+ log5.trace("dxos.sdk.invitation-handler.host.introduce", trace3.begin({
1354
1513
  id: traceId
1355
1514
  }), {
1356
- F: __dxlog_file6,
1357
- L: 99,
1515
+ F: __dxlog_file7,
1516
+ L: 110,
1358
1517
  S: this,
1359
1518
  C: (f, a) => f(...a)
1360
1519
  });
1361
- const invitation = await this._callbacks.resolveInvitation(request);
1362
- if (!invitation) {
1363
- log4.warn("invitation not found", {
1364
- invitationId
1520
+ const invitation = this._requireActiveInvitation();
1521
+ this._assertInvitationState(Invitation3.State.CONNECTED);
1522
+ if (invitationId !== invitation?.invitationId) {
1523
+ log5.warn("incorrect invitationId", {
1524
+ expected: invitation.invitationId,
1525
+ actual: invitationId
1365
1526
  }, {
1366
- F: __dxlog_file6,
1367
- L: 103,
1527
+ F: __dxlog_file7,
1528
+ L: 116,
1368
1529
  S: this,
1369
1530
  C: (f, a) => f(...a)
1370
1531
  });
1371
- this._callbacks.onError(new Error("Invitation not found."));
1532
+ this._callbacks.onError(new Error("Incorrect invitationId."));
1533
+ scheduleTask2(this._ctx, () => this.close());
1372
1534
  return {
1373
- authMethod: Invitation2.AuthMethod.NONE
1535
+ authMethod: Invitation3.AuthMethod.NONE
1374
1536
  };
1375
1537
  }
1376
- this.invitation = invitation;
1377
- log4("guest introduced itself", {
1538
+ log5("guest introduced themselves", {
1378
1539
  guestProfile: profile
1379
1540
  }, {
1380
- F: __dxlog_file6,
1381
- L: 112,
1541
+ F: __dxlog_file7,
1542
+ L: 125,
1382
1543
  S: this,
1383
1544
  C: (f, a) => f(...a)
1384
1545
  });
1385
1546
  this.guestProfile = profile;
1386
- this._callbacks.onStateUpdate({
1387
- ...this.invitation,
1388
- state: Invitation2.State.READY_FOR_AUTHENTICATION
1389
- });
1390
- this._challenge = this.invitation.authMethod === Invitation2.AuthMethod.KNOWN_PUBLIC_KEY ? randomBytes(32) : void 0;
1391
- log4.trace("dxos.sdk.invitation-handler.host.introduce", trace3.end({
1547
+ this._callbacks.onStateUpdate(Invitation3.State.READY_FOR_AUTHENTICATION);
1548
+ this._challenge = invitation.authMethod === Invitation3.AuthMethod.KNOWN_PUBLIC_KEY ? randomBytes(32) : void 0;
1549
+ log5.trace("dxos.sdk.invitation-handler.host.introduce", trace3.end({
1392
1550
  id: traceId
1393
1551
  }), {
1394
- F: __dxlog_file6,
1395
- L: 122,
1552
+ F: __dxlog_file7,
1553
+ L: 132,
1396
1554
  S: this,
1397
1555
  C: (f, a) => f(...a)
1398
1556
  });
1399
1557
  return {
1400
- authMethod: this.invitation.authMethod,
1558
+ authMethod: invitation.authMethod,
1401
1559
  challenge: this._challenge
1402
1560
  };
1403
1561
  },
1404
1562
  authenticate: async ({ authCode: code, signedChallenge }) => {
1405
1563
  const traceId = PublicKey5.random().toHex();
1406
- log4.trace("dxos.sdk.invitation-handler.host.authenticate", trace3.begin({
1564
+ log5.trace("dxos.sdk.invitation-handler.host.authenticate", trace3.begin({
1407
1565
  id: traceId
1408
1566
  }), {
1409
- F: __dxlog_file6,
1410
- L: 131,
1567
+ F: __dxlog_file7,
1568
+ L: 141,
1411
1569
  S: this,
1412
1570
  C: (f, a) => f(...a)
1413
1571
  });
1414
- log4("received authentication request", {
1572
+ const invitation = this._requireActiveInvitation();
1573
+ log5("received authentication request", {
1415
1574
  authCode: code
1416
1575
  }, {
1417
- F: __dxlog_file6,
1418
- L: 132,
1576
+ F: __dxlog_file7,
1577
+ L: 144,
1419
1578
  S: this,
1420
1579
  C: (f, a) => f(...a)
1421
1580
  });
1422
1581
  let status = AuthenticationResponse.Status.OK;
1423
- invariant5(this.invitation, "Invitation is not set.", {
1424
- F: __dxlog_file6,
1425
- L: 135,
1426
- S: this,
1427
- A: [
1428
- "this.invitation",
1429
- "'Invitation is not set.'"
1430
- ]
1431
- });
1432
- switch (this.invitation.authMethod) {
1433
- case Invitation2.AuthMethod.NONE: {
1434
- log4("authentication not required", void 0, {
1435
- F: __dxlog_file6,
1436
- L: 138,
1582
+ this._assertInvitationState([
1583
+ Invitation3.State.AUTHENTICATING,
1584
+ Invitation3.State.READY_FOR_AUTHENTICATION
1585
+ ]);
1586
+ this._callbacks.onStateUpdate(Invitation3.State.AUTHENTICATING);
1587
+ switch (invitation.authMethod) {
1588
+ case Invitation3.AuthMethod.NONE: {
1589
+ log5("authentication not required", void 0, {
1590
+ F: __dxlog_file7,
1591
+ L: 152,
1437
1592
  S: this,
1438
1593
  C: (f, a) => f(...a)
1439
1594
  });
@@ -1441,11 +1596,11 @@ var InvitationHostExtension = class extends RpcExtension {
1441
1596
  status: AuthenticationResponse.Status.OK
1442
1597
  };
1443
1598
  }
1444
- case Invitation2.AuthMethod.SHARED_SECRET: {
1445
- if (this.invitation.authCode) {
1599
+ case Invitation3.AuthMethod.SHARED_SECRET: {
1600
+ if (invitation.authCode) {
1446
1601
  if (this.authenticationRetry++ > MAX_OTP_ATTEMPTS) {
1447
1602
  status = AuthenticationResponse.Status.INVALID_OPT_ATTEMPTS;
1448
- } else if (code !== this.invitation.authCode) {
1603
+ } else if (code !== invitation.authCode) {
1449
1604
  status = AuthenticationResponse.Status.INVALID_OTP;
1450
1605
  } else {
1451
1606
  this.authenticationPassed = true;
@@ -1453,12 +1608,12 @@ var InvitationHostExtension = class extends RpcExtension {
1453
1608
  }
1454
1609
  break;
1455
1610
  }
1456
- case Invitation2.AuthMethod.KNOWN_PUBLIC_KEY: {
1457
- if (!this.invitation.guestKeypair) {
1611
+ case Invitation3.AuthMethod.KNOWN_PUBLIC_KEY: {
1612
+ if (!invitation.guestKeypair) {
1458
1613
  status = AuthenticationResponse.Status.INTERNAL_ERROR;
1459
1614
  break;
1460
1615
  }
1461
- const isSignatureValid = this._challenge && verify(this._challenge, Buffer.from(signedChallenge ?? []), this.invitation.guestKeypair.publicKey.asBuffer());
1616
+ const isSignatureValid = this._challenge && verify(this._challenge, Buffer.from(signedChallenge ?? []), invitation.guestKeypair.publicKey.asBuffer());
1462
1617
  if (isSignatureValid) {
1463
1618
  this.authenticationPassed = true;
1464
1619
  } else {
@@ -1467,11 +1622,11 @@ var InvitationHostExtension = class extends RpcExtension {
1467
1622
  break;
1468
1623
  }
1469
1624
  default: {
1470
- log4.error("invalid authentication method", {
1471
- authMethod: this.invitation.authMethod
1625
+ log5.error("invalid authentication method", {
1626
+ authMethod: invitation.authMethod
1472
1627
  }, {
1473
- F: __dxlog_file6,
1474
- L: 176,
1628
+ F: __dxlog_file7,
1629
+ L: 190,
1475
1630
  S: this,
1476
1631
  C: (f, a) => f(...a)
1477
1632
  });
@@ -1479,14 +1634,24 @@ var InvitationHostExtension = class extends RpcExtension {
1479
1634
  break;
1480
1635
  }
1481
1636
  }
1482
- log4.trace("dxos.sdk.invitation-handler.host.authenticate", trace3.end({
1637
+ if (![
1638
+ AuthenticationResponse.Status.OK,
1639
+ AuthenticationResponse.Status.INVALID_OTP
1640
+ ].includes(status)) {
1641
+ this._callbacks.onError(new Error(`Authentication failed, with status=${status}`));
1642
+ scheduleTask2(this._ctx, () => this.close());
1643
+ return {
1644
+ status
1645
+ };
1646
+ }
1647
+ log5.trace("dxos.sdk.invitation-handler.host.authenticate", trace3.end({
1483
1648
  id: traceId,
1484
1649
  data: {
1485
1650
  status
1486
1651
  }
1487
1652
  }), {
1488
- F: __dxlog_file6,
1489
- L: 182,
1653
+ F: __dxlog_file7,
1654
+ L: 202,
1490
1655
  S: this,
1491
1656
  C: (f, a) => f(...a)
1492
1657
  });
@@ -1496,33 +1661,28 @@ var InvitationHostExtension = class extends RpcExtension {
1496
1661
  },
1497
1662
  admit: async (request) => {
1498
1663
  const traceId = PublicKey5.random().toHex();
1499
- log4.trace("dxos.sdk.invitation-handler.host.admit", trace3.begin({
1664
+ log5.trace("dxos.sdk.invitation-handler.host.admit", trace3.begin({
1500
1665
  id: traceId
1501
1666
  }), {
1502
- F: __dxlog_file6,
1503
- L: 188,
1667
+ F: __dxlog_file7,
1668
+ L: 208,
1504
1669
  S: this,
1505
1670
  C: (f, a) => f(...a)
1506
1671
  });
1672
+ const invitation = this._requireActiveInvitation();
1507
1673
  try {
1508
- invariant5(this.invitation, "Invitation is not set.", {
1509
- F: __dxlog_file6,
1510
- L: 191,
1511
- S: this,
1512
- A: [
1513
- "this.invitation",
1514
- "'Invitation is not set.'"
1515
- ]
1516
- });
1517
- if (isAuthenticationRequired(this.invitation) && !this.authenticationPassed) {
1518
- throw new Error("Not authenticated");
1674
+ if (isAuthenticationRequired(invitation)) {
1675
+ this._assertInvitationState(Invitation3.State.AUTHENTICATING);
1676
+ if (!this.authenticationPassed) {
1677
+ throw new Error("Not authenticated");
1678
+ }
1519
1679
  }
1520
1680
  const response = await this._callbacks.admit(request);
1521
- log4.trace("dxos.sdk.invitation-handler.host.admit", trace3.end({
1681
+ log5.trace("dxos.sdk.invitation-handler.host.admit", trace3.end({
1522
1682
  id: traceId
1523
1683
  }), {
1524
- F: __dxlog_file6,
1525
- L: 199,
1684
+ F: __dxlog_file7,
1685
+ L: 222,
1526
1686
  S: this,
1527
1687
  C: (f, a) => f(...a)
1528
1688
  });
@@ -1538,149 +1698,204 @@ var InvitationHostExtension = class extends RpcExtension {
1538
1698
  async onOpen(context) {
1539
1699
  await super.onOpen(context);
1540
1700
  try {
1701
+ log5("host acquire lock", void 0, {
1702
+ F: __dxlog_file7,
1703
+ L: 237,
1704
+ S: this,
1705
+ C: (f, a) => f(...a)
1706
+ });
1707
+ this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
1708
+ log5("host lock acquired", void 0, {
1709
+ F: __dxlog_file7,
1710
+ L: 239,
1711
+ S: this,
1712
+ C: (f, a) => f(...a)
1713
+ });
1714
+ const lastState = this._requireActiveInvitation().state;
1715
+ this._callbacks.onStateUpdate(Invitation3.State.CONNECTING);
1541
1716
  await this.rpc.InvitationHostService.options({
1542
- role: Options.Role.HOST
1717
+ role: Options2.Role.HOST
1543
1718
  });
1544
- await cancelWithContext(this._ctx, this._remoteOptionsTrigger.wait({
1545
- timeout: OPTIONS_TIMEOUT
1719
+ log5("options sent", void 0, {
1720
+ F: __dxlog_file7,
1721
+ L: 243,
1722
+ S: this,
1723
+ C: (f, a) => f(...a)
1724
+ });
1725
+ await cancelWithContext3(this._ctx, this._remoteOptionsTrigger.wait({
1726
+ timeout: OPTIONS_TIMEOUT2
1546
1727
  }));
1547
- if (this._remoteOptions?.role !== Options.Role.GUEST) {
1548
- throw new InvalidInvitationExtensionRoleError(void 0, {
1549
- expected: Options.Role.GUEST,
1550
- remoteOptions: this._remoteOptions
1728
+ log5("options received", void 0, {
1729
+ F: __dxlog_file7,
1730
+ L: 245,
1731
+ S: this,
1732
+ C: (f, a) => f(...a)
1733
+ });
1734
+ if (this._remoteOptions?.role !== Options2.Role.GUEST) {
1735
+ this._callbacks.onStateUpdate(lastState);
1736
+ throw new InvalidInvitationExtensionRoleError2(void 0, {
1737
+ expected: Options2.Role.GUEST,
1738
+ remoteOptions: this._remoteOptions,
1739
+ remotePeerId: context.remotePeerId
1551
1740
  });
1552
1741
  }
1553
- this._callbacks.onOpen();
1742
+ this._callbacks.onStateUpdate(Invitation3.State.CONNECTED);
1743
+ this._callbacks.onOpen(this._ctx, context);
1554
1744
  } catch (err) {
1555
- this._callbacks.onError(err);
1745
+ if (this._invitationFlowLock != null) {
1746
+ this._callbacks.onError(err);
1747
+ }
1748
+ if (!this._ctx.disposed) {
1749
+ context.close(err);
1750
+ }
1556
1751
  }
1557
1752
  }
1558
- async onClose() {
1559
- await this._ctx.dispose();
1753
+ _requireActiveInvitation() {
1754
+ const invitation = this._callbacks.activeInvitation;
1755
+ if (invitation == null) {
1756
+ scheduleTask2(this._ctx, () => this.close());
1757
+ throw new Error("Active invitation not found");
1758
+ }
1759
+ return invitation;
1560
1760
  }
1561
- };
1562
- var InvitationGuestExtension = class extends RpcExtension {
1563
- constructor(_callbacks) {
1564
- super({
1565
- requested: {
1566
- InvitationHostService: schema2.getService("dxos.halo.invitations.InvitationHostService")
1567
- },
1568
- exposed: {
1569
- InvitationHostService: schema2.getService("dxos.halo.invitations.InvitationHostService")
1570
- }
1571
- });
1572
- this._callbacks = _callbacks;
1573
- this._ctx = new Context4();
1574
- this._remoteOptionsTrigger = new Trigger2();
1761
+ _assertInvitationState(stateOrMany) {
1762
+ const invitation = this._requireActiveInvitation();
1763
+ const validStates = Array.isArray(stateOrMany) ? stateOrMany : [
1764
+ stateOrMany
1765
+ ];
1766
+ if (!validStates.includes(invitation.state)) {
1767
+ scheduleTask2(this._ctx, () => this.close());
1768
+ throw new InvariantViolation(`Expected ${stateToString(invitation.state)} to be one of [${validStates.map(stateToString).join(", ")}]`);
1769
+ }
1575
1770
  }
1576
- async getHandlers() {
1577
- return {
1578
- InvitationHostService: {
1579
- options: async (options) => {
1580
- invariant5(!this._remoteOptions, "Remote options already set.", {
1581
- F: __dxlog_file6,
1582
- L: 266,
1583
- S: this,
1584
- A: [
1585
- "!this._remoteOptions",
1586
- "'Remote options already set.'"
1587
- ]
1588
- });
1589
- this._remoteOptions = options;
1590
- this._remoteOptionsTrigger.wake();
1591
- },
1592
- introduce: () => {
1593
- throw new Error("Method not allowed.");
1594
- },
1595
- authenticate: () => {
1596
- throw new Error("Method not allowed.");
1597
- },
1598
- admit: () => {
1599
- throw new Error("Method not allowed.");
1600
- }
1601
- }
1602
- };
1771
+ async onClose() {
1772
+ await this._destroy();
1603
1773
  }
1604
- async onOpen(context) {
1605
- await super.onOpen(context);
1606
- try {
1607
- log4("begin options", void 0, {
1608
- F: __dxlog_file6,
1609
- L: 287,
1610
- S: this,
1611
- C: (f, a) => f(...a)
1612
- });
1613
- await cancelWithContext(this._ctx, this.rpc.InvitationHostService.options({
1614
- role: Options.Role.GUEST
1615
- }));
1616
- await cancelWithContext(this._ctx, this._remoteOptionsTrigger.wait({
1617
- timeout: OPTIONS_TIMEOUT
1618
- }));
1619
- log4("end options", void 0, {
1620
- F: __dxlog_file6,
1621
- L: 290,
1774
+ async onAbort() {
1775
+ await this._destroy();
1776
+ }
1777
+ async _destroy() {
1778
+ await this._ctx.dispose();
1779
+ if (this._invitationFlowLock != null) {
1780
+ this._invitationFlowLock?.release();
1781
+ this._invitationFlowLock = null;
1782
+ log5("invitation flow lock released", void 0, {
1783
+ F: __dxlog_file7,
1784
+ L: 300,
1622
1785
  S: this,
1623
1786
  C: (f, a) => f(...a)
1624
1787
  });
1625
- if (this._remoteOptions?.role !== Options.Role.HOST) {
1626
- throw new InvalidInvitationExtensionRoleError(void 0, {
1627
- expected: Options.Role.HOST,
1628
- remoteOptions: this._remoteOptions
1629
- });
1630
- }
1631
- this._callbacks.onOpen(this._ctx);
1632
- } catch (err) {
1633
- log4("openError", err, {
1634
- F: __dxlog_file6,
1635
- L: 300,
1788
+ }
1789
+ }
1790
+ };
1791
+ var isAuthenticationRequired = (invitation) => invitation.authMethod !== Invitation3.AuthMethod.NONE;
1792
+
1793
+ // packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts
1794
+ import { invariant as invariant7 } from "@dxos/invariant";
1795
+ import { PublicKey as PublicKey6 } from "@dxos/keys";
1796
+ import { log as log6 } from "@dxos/log";
1797
+ import { Options as Options3 } from "@dxos/protocols/proto/dxos/halo/invitations";
1798
+ import { ComplexSet as ComplexSet2 } from "@dxos/util";
1799
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts";
1800
+ var InvitationTopology = class {
1801
+ constructor(_role) {
1802
+ this._role = _role;
1803
+ this._seenPeers = new ComplexSet2(PublicKey6.hash);
1804
+ }
1805
+ init(controller) {
1806
+ invariant7(!this._controller, "Already initialized.", {
1807
+ F: __dxlog_file8,
1808
+ L: 42,
1809
+ S: this,
1810
+ A: [
1811
+ "!this._controller",
1812
+ "'Already initialized.'"
1813
+ ]
1814
+ });
1815
+ this._controller = controller;
1816
+ }
1817
+ update() {
1818
+ invariant7(this._controller, "Not initialized.", {
1819
+ F: __dxlog_file8,
1820
+ L: 47,
1821
+ S: this,
1822
+ A: [
1823
+ "this._controller",
1824
+ "'Not initialized.'"
1825
+ ]
1826
+ });
1827
+ const { ownPeerId, candidates, connected, allPeers } = this._controller.getState();
1828
+ if (this._role === Options3.Role.GUEST) {
1829
+ return;
1830
+ }
1831
+ if (connected.length > 0) {
1832
+ connected.forEach((c) => this._seenPeers.add(c));
1833
+ return;
1834
+ }
1835
+ const firstUnknownPeer = candidates.find((peerId) => !this._seenPeers.has(peerId));
1836
+ this._seenPeers = new ComplexSet2(PublicKey6.hash, allPeers.filter((peerId) => this._seenPeers.has(peerId)));
1837
+ if (firstUnknownPeer != null) {
1838
+ log6("invitation connect", {
1839
+ ownPeerId,
1840
+ remotePeerId: firstUnknownPeer
1841
+ }, {
1842
+ F: __dxlog_file8,
1843
+ L: 69,
1636
1844
  S: this,
1637
1845
  C: (f, a) => f(...a)
1638
1846
  });
1639
- this._callbacks.onError(err);
1847
+ this._controller.connect(firstUnknownPeer);
1848
+ this._seenPeers.add(firstUnknownPeer);
1640
1849
  }
1641
1850
  }
1642
- async onClose() {
1643
- log4("onClose", void 0, {
1644
- F: __dxlog_file6,
1645
- L: 306,
1851
+ async onOffer(peer) {
1852
+ invariant7(this._controller, "Not initialized.", {
1853
+ F: __dxlog_file8,
1854
+ L: 76,
1646
1855
  S: this,
1647
- C: (f, a) => f(...a)
1856
+ A: [
1857
+ "this._controller",
1858
+ "'Not initialized.'"
1859
+ ]
1648
1860
  });
1649
- await this._ctx.dispose();
1861
+ return !this._seenPeers.has(peer);
1862
+ }
1863
+ async destroy() {
1864
+ this._seenPeers.clear();
1865
+ }
1866
+ toString() {
1867
+ return `InvitationTopology(${this._role === Options3.Role.GUEST ? "guest" : "host"})`;
1650
1868
  }
1651
1869
  };
1652
- var isAuthenticationRequired = (invitation) => invitation.authMethod !== Invitation2.AuthMethod.NONE;
1653
1870
 
1654
1871
  // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
1655
- var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts";
1872
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts";
1873
+ var MAX_DELEGATED_INVITATION_HOST_TRIES = 3;
1656
1874
  var InvitationsHandler = class {
1657
1875
  /**
1658
1876
  * @internal
1659
1877
  */
1660
- constructor(_networkManager) {
1878
+ constructor(_networkManager, _defaultTeleportParams) {
1661
1879
  this._networkManager = _networkManager;
1880
+ this._defaultTeleportParams = _defaultTeleportParams;
1662
1881
  }
1663
1882
  handleInvitationFlow(ctx, stream, protocol, invitation) {
1883
+ const guardedState = this._createGuardedState(ctx, invitation, stream);
1664
1884
  const createExtension = () => {
1665
- const extension = new InvitationHostExtension({
1666
- onStateUpdate: (invitation2) => {
1667
- stream.next({
1668
- ...invitation2,
1669
- state: Invitation3.State.READY_FOR_AUTHENTICATION
1670
- });
1885
+ const extension = new InvitationHostExtension(guardedState.mutex, {
1886
+ get activeInvitation() {
1887
+ return ctx.disposed ? null : guardedState.current;
1671
1888
  },
1672
- resolveInvitation: async ({ invitationId }) => {
1673
- if (invitationId && invitationId !== invitation.invitationId) {
1674
- return void 0;
1675
- }
1676
- return invitation;
1889
+ onStateUpdate: (newState) => {
1890
+ guardedState.set(extension, newState);
1891
+ return guardedState.current;
1677
1892
  },
1678
1893
  admit: async (admissionRequest) => {
1679
1894
  try {
1680
1895
  const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
1681
- invariant6(deviceKey, void 0, {
1682
- F: __dxlog_file7,
1683
- L: 87,
1896
+ invariant8(deviceKey, void 0, {
1897
+ F: __dxlog_file9,
1898
+ L: 90,
1684
1899
  S: this,
1685
1900
  A: [
1686
1901
  "deviceKey",
@@ -1691,123 +1906,128 @@ var InvitationsHandler = class {
1691
1906
  extension.completedTrigger.wake(deviceKey);
1692
1907
  return admissionResponse;
1693
1908
  } catch (err) {
1694
- stream.error(err);
1909
+ guardedState.error(extension, err);
1695
1910
  throw err;
1696
1911
  }
1697
1912
  },
1698
- onOpen: () => {
1699
- scheduleTask2(ctx, async () => {
1700
- const traceId = PublicKey6.random().toHex();
1913
+ onOpen: (connectionCtx, extensionsCtx) => {
1914
+ let admitted = false;
1915
+ connectionCtx.onDispose(() => {
1916
+ if (!admitted) {
1917
+ guardedState.error(extension, new ContextDisposedError2());
1918
+ }
1919
+ });
1920
+ scheduleTask3(connectionCtx, async () => {
1921
+ const traceId = PublicKey7.random().toHex();
1701
1922
  try {
1702
- log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace4.begin({
1923
+ log7.trace("dxos.sdk.invitations-handler.host.onOpen", trace4.begin({
1703
1924
  id: traceId
1704
1925
  }), {
1705
- F: __dxlog_file7,
1706
- L: 105,
1926
+ F: __dxlog_file9,
1927
+ L: 115,
1707
1928
  S: this,
1708
1929
  C: (f, a) => f(...a)
1709
1930
  });
1710
- log5("connected", {
1931
+ log7("connected", {
1711
1932
  ...protocol.toJSON()
1712
1933
  }, {
1713
- F: __dxlog_file7,
1714
- L: 106,
1934
+ F: __dxlog_file9,
1935
+ L: 116,
1715
1936
  S: this,
1716
1937
  C: (f, a) => f(...a)
1717
1938
  });
1718
- stream.next({
1719
- ...invitation,
1720
- state: Invitation3.State.CONNECTED
1721
- });
1722
1939
  const deviceKey = await extension.completedTrigger.wait({
1723
1940
  timeout: invitation.timeout
1724
1941
  });
1725
- log5("admitted guest", {
1942
+ log7("admitted guest", {
1726
1943
  guest: deviceKey,
1727
1944
  ...protocol.toJSON()
1728
1945
  }, {
1729
- F: __dxlog_file7,
1730
- L: 109,
1946
+ F: __dxlog_file9,
1947
+ L: 118,
1731
1948
  S: this,
1732
1949
  C: (f, a) => f(...a)
1733
1950
  });
1734
- stream.next({
1735
- ...invitation,
1736
- state: Invitation3.State.SUCCESS
1737
- });
1738
- log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace4.end({
1951
+ guardedState.set(extension, Invitation4.State.SUCCESS);
1952
+ log7.trace("dxos.sdk.invitations-handler.host.onOpen", trace4.end({
1739
1953
  id: traceId
1740
1954
  }), {
1741
- F: __dxlog_file7,
1742
- L: 111,
1955
+ F: __dxlog_file9,
1956
+ L: 120,
1743
1957
  S: this,
1744
1958
  C: (f, a) => f(...a)
1745
1959
  });
1960
+ admitted = true;
1961
+ if (!invitation.multiUse) {
1962
+ await ctx.dispose();
1963
+ }
1746
1964
  } catch (err) {
1747
1965
  if (err instanceof TimeoutError) {
1748
- log5("timeout", {
1749
- ...protocol.toJSON()
1750
- }, {
1751
- F: __dxlog_file7,
1752
- L: 114,
1753
- S: this,
1754
- C: (f, a) => f(...a)
1755
- });
1756
- stream.next({
1757
- ...invitation,
1758
- state: Invitation3.State.TIMEOUT
1759
- });
1966
+ if (guardedState.set(extension, Invitation4.State.TIMEOUT)) {
1967
+ log7("timeout", {
1968
+ ...protocol.toJSON()
1969
+ }, {
1970
+ F: __dxlog_file9,
1971
+ L: 129,
1972
+ S: this,
1973
+ C: (f, a) => f(...a)
1974
+ });
1975
+ }
1760
1976
  } else {
1761
- log5.error("failed", err, {
1762
- F: __dxlog_file7,
1763
- L: 117,
1764
- S: this,
1765
- C: (f, a) => f(...a)
1766
- });
1767
- stream.error(err);
1977
+ if (guardedState.error(extension, err)) {
1978
+ log7.error("failed", err, {
1979
+ F: __dxlog_file9,
1980
+ L: 133,
1981
+ S: this,
1982
+ C: (f, a) => f(...a)
1983
+ });
1984
+ }
1768
1985
  }
1769
- log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace4.error({
1986
+ log7.trace("dxos.sdk.invitations-handler.host.onOpen", trace4.error({
1770
1987
  id: traceId,
1771
1988
  error: err
1772
1989
  }), {
1773
- F: __dxlog_file7,
1774
- L: 120,
1990
+ F: __dxlog_file9,
1991
+ L: 136,
1775
1992
  S: this,
1776
1993
  C: (f, a) => f(...a)
1777
1994
  });
1778
- } finally {
1779
- if (!invitation.multiUse) {
1780
- await swarmConnection.close();
1781
- await ctx.dispose();
1782
- }
1995
+ extensionsCtx.close(err);
1783
1996
  }
1784
1997
  });
1785
1998
  },
1786
1999
  onError: (err) => {
1787
- if (err instanceof InvalidInvitationExtensionRoleError2) {
1788
- return;
1789
- }
1790
- if (err instanceof TimeoutError) {
1791
- log5("timeout", {
1792
- ...protocol.toJSON()
2000
+ if (err instanceof InvalidInvitationExtensionRoleError3) {
2001
+ log7("invalid role", {
2002
+ ...err.context
1793
2003
  }, {
1794
- F: __dxlog_file7,
1795
- L: 135,
2004
+ F: __dxlog_file9,
2005
+ L: 144,
1796
2006
  S: this,
1797
2007
  C: (f, a) => f(...a)
1798
2008
  });
1799
- stream.next({
1800
- ...invitation,
1801
- state: Invitation3.State.TIMEOUT
1802
- });
2009
+ return;
2010
+ }
2011
+ if (err instanceof TimeoutError) {
2012
+ if (guardedState.set(extension, Invitation4.State.TIMEOUT)) {
2013
+ log7("timeout", {
2014
+ err
2015
+ }, {
2016
+ F: __dxlog_file9,
2017
+ L: 149,
2018
+ S: this,
2019
+ C: (f, a) => f(...a)
2020
+ });
2021
+ }
1803
2022
  } else {
1804
- log5.error("failed", err, {
1805
- F: __dxlog_file7,
1806
- L: 138,
1807
- S: this,
1808
- C: (f, a) => f(...a)
1809
- });
1810
- stream.error(err);
2023
+ if (guardedState.error(extension, err)) {
2024
+ log7.error("failed", err, {
2025
+ F: __dxlog_file9,
2026
+ L: 153,
2027
+ S: this,
2028
+ C: (f, a) => f(...a)
2029
+ });
2030
+ }
1811
2031
  }
1812
2032
  }
1813
2033
  });
@@ -1815,58 +2035,32 @@ var InvitationsHandler = class {
1815
2035
  };
1816
2036
  if (invitation.lifetime && invitation.created) {
1817
2037
  if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
1818
- log5.warn("invitation has already expired", void 0, {
1819
- F: __dxlog_file7,
1820
- L: 149,
2038
+ log7.warn("invitation has already expired", void 0, {
2039
+ F: __dxlog_file9,
2040
+ L: 164,
1821
2041
  S: this,
1822
2042
  C: (f, a) => f(...a)
1823
2043
  });
1824
2044
  } else {
1825
- scheduleTask2(ctx, async () => {
2045
+ scheduleTask3(ctx, async () => {
1826
2046
  await swarmConnection.close();
1827
- stream.next({
1828
- ...invitation,
1829
- state: Invitation3.State.EXPIRED
1830
- });
2047
+ guardedState.set(null, Invitation4.State.EXPIRED);
1831
2048
  await ctx.dispose();
1832
2049
  }, invitation.created.getTime() + invitation.lifetime * 1e3 - Date.now());
1833
2050
  }
1834
2051
  }
1835
2052
  let swarmConnection;
1836
- const invitationLabel = "invitation host for " + (invitation.kind === Invitation3.Kind.DEVICE ? "device" : `space ${invitation.spaceKey?.truncate()}`);
1837
- scheduleTask2(ctx, async () => {
1838
- const topic = invitation.swarmKey;
1839
- swarmConnection = await this._networkManager.joinSwarm({
1840
- topic,
1841
- peerId: topic,
1842
- protocolProvider: createTeleportProtocolFactory(async (teleport) => {
1843
- teleport.addExtension("dxos.halo.invitations", createExtension());
1844
- }),
1845
- topology: new StarTopology(topic),
1846
- label: invitationLabel
1847
- });
1848
- ctx.onDispose(() => swarmConnection.close());
1849
- stream.next({
1850
- ...invitation,
1851
- state: Invitation3.State.CONNECTING
1852
- });
2053
+ scheduleTask3(ctx, async () => {
2054
+ swarmConnection = await this._joinSwarm(ctx, invitation, Options4.Role.HOST, createExtension);
2055
+ guardedState.set(null, Invitation4.State.CONNECTING);
1853
2056
  });
1854
2057
  }
1855
- acceptInvitation(protocol, invitation, deviceProfile) {
2058
+ acceptInvitation(ctx, stream, protocol, invitation, otpEnteredTrigger, deviceProfile) {
1856
2059
  const { timeout = INVITATION_TIMEOUT } = invitation;
1857
- invariant6(protocol, void 0, {
1858
- F: __dxlog_file7,
1859
- L: 191,
1860
- S: this,
1861
- A: [
1862
- "protocol",
1863
- ""
1864
- ]
1865
- });
1866
2060
  if (deviceProfile) {
1867
- invariant6(invitation.kind === Invitation3.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
1868
- F: __dxlog_file7,
1869
- L: 194,
2061
+ invariant8(invitation.kind === Invitation4.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
2062
+ F: __dxlog_file9,
2063
+ L: 197,
1870
2064
  S: this,
1871
2065
  A: [
1872
2066
  "invitation.kind === Invitation.Kind.DEVICE",
@@ -1874,142 +2068,117 @@ var InvitationsHandler = class {
1874
2068
  ]
1875
2069
  });
1876
2070
  }
1877
- const authenticated = new Trigger3();
1878
- let admitted = false;
1879
- let currentState;
1880
- const stream = new PushStream();
1881
- const setState = (newData) => {
1882
- invariant6(newData.state !== void 0, void 0, {
1883
- F: __dxlog_file7,
1884
- L: 205,
1885
- S: this,
1886
- A: [
1887
- "newData.state !== undefined",
1888
- ""
1889
- ]
1890
- });
1891
- currentState = newData.state;
1892
- stream.next({
1893
- ...invitation,
1894
- ...newData
1895
- });
1896
- };
1897
- const ctx = new Context5({
1898
- onError: (err) => {
1899
- if (err instanceof TimeoutError) {
1900
- log5("timeout", {
1901
- ...protocol.toJSON()
1902
- }, {
1903
- F: __dxlog_file7,
1904
- L: 213,
1905
- S: this,
1906
- C: (f, a) => f(...a)
1907
- });
1908
- setState({
1909
- state: Invitation3.State.TIMEOUT
1910
- });
1911
- } else {
1912
- log5.warn("auth failed", err, {
1913
- F: __dxlog_file7,
1914
- L: 216,
1915
- S: this,
1916
- C: (f, a) => f(...a)
1917
- });
1918
- stream.error(err);
1919
- }
1920
- void ctx.dispose();
1921
- }
1922
- });
1923
- ctx.onDispose(() => {
1924
- log5("complete", {
1925
- ...protocol.toJSON()
2071
+ const triedPeersIds = new ComplexSet3(PublicKey7.hash);
2072
+ const guardedState = this._createGuardedState(ctx, invitation, stream);
2073
+ const shouldCancelInvitationFlow = (extension) => {
2074
+ const isLockedByAnotherConnection = guardedState.mutex.isLocked() && !extension.hasFlowLock();
2075
+ log7("should cancel invitation flow", {
2076
+ isLockedByAnotherConnection,
2077
+ invitationType: Invitation4.Type.DELEGATED,
2078
+ triedPeers: triedPeersIds.size
1926
2079
  }, {
1927
- F: __dxlog_file7,
1928
- L: 224,
2080
+ F: __dxlog_file9,
2081
+ L: 205,
1929
2082
  S: this,
1930
2083
  C: (f, a) => f(...a)
1931
2084
  });
1932
- stream.complete();
1933
- });
2085
+ if (isLockedByAnotherConnection) {
2086
+ return false;
2087
+ }
2088
+ return invitation.type !== Invitation4.Type.DELEGATED || triedPeersIds.size >= MAX_DELEGATED_INVITATION_HOST_TRIES;
2089
+ };
2090
+ let admitted = false;
1934
2091
  const createExtension = () => {
1935
- let connectionCount = 0;
1936
- const extension = new InvitationGuestExtension({
1937
- onOpen: (extensionCtx) => {
1938
- extensionCtx.onDispose(async () => {
1939
- log5("extension disposed", {
1940
- currentState
2092
+ const extension = new InvitationGuestExtension(guardedState.mutex, {
2093
+ onStateUpdate: (newState) => {
2094
+ guardedState.set(extension, newState);
2095
+ },
2096
+ onOpen: (connectionCtx, extensionCtx) => {
2097
+ triedPeersIds.add(extensionCtx.remotePeerId);
2098
+ if (admitted) {
2099
+ extensionCtx.close();
2100
+ return;
2101
+ }
2102
+ connectionCtx.onDispose(async () => {
2103
+ log7("extension disposed", {
2104
+ admitted,
2105
+ currentState: guardedState.current.state
1941
2106
  }, {
1942
- F: __dxlog_file7,
1943
- L: 234,
2107
+ F: __dxlog_file9,
2108
+ L: 233,
1944
2109
  S: this,
1945
2110
  C: (f, a) => f(...a)
1946
2111
  });
1947
2112
  if (!admitted) {
1948
- stream.error(new Error("Remote peer disconnected."));
2113
+ guardedState.error(extension, new ContextDisposedError2());
2114
+ if (shouldCancelInvitationFlow(extension)) {
2115
+ await ctx.dispose();
2116
+ }
1949
2117
  }
1950
2118
  });
1951
- scheduleTask2(ctx, async () => {
1952
- const traceId = PublicKey6.random().toHex();
2119
+ scheduleTask3(connectionCtx, async () => {
2120
+ const traceId = PublicKey7.random().toHex();
1953
2121
  try {
1954
- log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace4.begin({
2122
+ log7.trace("dxos.sdk.invitations-handler.guest.onOpen", trace4.begin({
1955
2123
  id: traceId
1956
2124
  }), {
1957
- F: __dxlog_file7,
1958
- L: 243,
2125
+ F: __dxlog_file9,
2126
+ L: 245,
1959
2127
  S: this,
1960
2128
  C: (f, a) => f(...a)
1961
2129
  });
1962
- if (++connectionCount > 1) {
1963
- throw new Error(`multiple connections detected: ${connectionCount}`);
1964
- }
1965
- scheduleTask2(ctx, () => ctx.raise(new TimeoutError(timeout)), timeout);
1966
- log5("connected", {
2130
+ scheduleTask3(connectionCtx, () => {
2131
+ guardedState.set(extension, Invitation4.State.TIMEOUT);
2132
+ extensionCtx.close();
2133
+ }, timeout);
2134
+ log7("connected", {
1967
2135
  ...protocol.toJSON()
1968
2136
  }, {
1969
- F: __dxlog_file7,
1970
- L: 251,
2137
+ F: __dxlog_file9,
2138
+ L: 256,
1971
2139
  S: this,
1972
2140
  C: (f, a) => f(...a)
1973
2141
  });
1974
- setState({
1975
- state: Invitation3.State.CONNECTED
1976
- });
1977
- log5("introduce", {
2142
+ guardedState.set(extension, Invitation4.State.CONNECTED);
2143
+ log7("introduce", {
1978
2144
  ...protocol.toJSON()
1979
2145
  }, {
1980
- F: __dxlog_file7,
1981
- L: 255,
2146
+ F: __dxlog_file9,
2147
+ L: 260,
1982
2148
  S: this,
1983
2149
  C: (f, a) => f(...a)
1984
2150
  });
1985
- const introductionResponse = await extension.rpc.InvitationHostService.introduce(protocol.createIntroduction());
1986
- log5("introduce response", {
2151
+ const introductionResponse = await extension.rpc.InvitationHostService.introduce({
2152
+ invitationId: invitation.invitationId,
2153
+ ...protocol.createIntroduction()
2154
+ });
2155
+ log7("introduce response", {
1987
2156
  ...protocol.toJSON(),
1988
2157
  response: introductionResponse
1989
2158
  }, {
1990
- F: __dxlog_file7,
1991
- L: 259,
2159
+ F: __dxlog_file9,
2160
+ L: 265,
1992
2161
  S: this,
1993
2162
  C: (f, a) => f(...a)
1994
2163
  });
1995
2164
  invitation.authMethod = introductionResponse.authMethod;
1996
2165
  if (isAuthenticationRequired(invitation)) {
1997
2166
  switch (invitation.authMethod) {
1998
- case Invitation3.AuthMethod.SHARED_SECRET:
1999
- await this._handleGuestOtpAuth(extension, setState, authenticated, {
2167
+ case Invitation4.AuthMethod.SHARED_SECRET:
2168
+ await this._handleGuestOtpAuth(extension, (state) => guardedState.set(extension, state), otpEnteredTrigger, {
2000
2169
  timeout
2001
2170
  });
2002
2171
  break;
2003
- case Invitation3.AuthMethod.KNOWN_PUBLIC_KEY:
2004
- await this._handleGuestKpkAuth(extension, setState, invitation, introductionResponse);
2172
+ case Invitation4.AuthMethod.KNOWN_PUBLIC_KEY:
2173
+ await this._handleGuestKpkAuth(extension, (state) => guardedState.set(extension, state), invitation, introductionResponse);
2005
2174
  break;
2006
2175
  }
2007
2176
  }
2008
- log5("request admission", {
2177
+ log7("request admission", {
2009
2178
  ...protocol.toJSON()
2010
2179
  }, {
2011
- F: __dxlog_file7,
2012
- L: 275,
2180
+ F: __dxlog_file9,
2181
+ L: 291,
2013
2182
  S: this,
2014
2183
  C: (f, a) => f(...a)
2015
2184
  });
@@ -2017,158 +2186,225 @@ var InvitationsHandler = class {
2017
2186
  const admissionResponse = await extension.rpc.InvitationHostService.admit(admissionRequest);
2018
2187
  admitted = true;
2019
2188
  const result = await protocol.accept(admissionResponse, admissionRequest);
2020
- log5("admitted by host", {
2189
+ log7("admitted by host", {
2021
2190
  ...protocol.toJSON()
2022
2191
  }, {
2023
- F: __dxlog_file7,
2024
- L: 286,
2192
+ F: __dxlog_file9,
2193
+ L: 302,
2025
2194
  S: this,
2026
2195
  C: (f, a) => f(...a)
2027
2196
  });
2028
- setState({
2197
+ await guardedState.complete({
2198
+ ...guardedState.current,
2029
2199
  ...result,
2030
- target: invitation.target,
2031
- state: Invitation3.State.SUCCESS
2200
+ state: Invitation4.State.SUCCESS
2032
2201
  });
2033
- log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace4.end({
2202
+ log7.trace("dxos.sdk.invitations-handler.guest.onOpen", trace4.end({
2034
2203
  id: traceId
2035
2204
  }), {
2036
- F: __dxlog_file7,
2037
- L: 288,
2205
+ F: __dxlog_file9,
2206
+ L: 308,
2038
2207
  S: this,
2039
2208
  C: (f, a) => f(...a)
2040
2209
  });
2041
2210
  } catch (err) {
2042
2211
  if (err instanceof TimeoutError) {
2043
- log5("timeout", {
2212
+ log7("timeout", {
2044
2213
  ...protocol.toJSON()
2045
2214
  }, {
2046
- F: __dxlog_file7,
2047
- L: 291,
2215
+ F: __dxlog_file9,
2216
+ L: 311,
2048
2217
  S: this,
2049
2218
  C: (f, a) => f(...a)
2050
2219
  });
2051
- setState({
2052
- state: Invitation3.State.TIMEOUT
2053
- });
2220
+ guardedState.set(extension, Invitation4.State.TIMEOUT);
2054
2221
  } else {
2055
- log5("auth failed", err, {
2056
- F: __dxlog_file7,
2057
- L: 294,
2222
+ log7("auth failed", err, {
2223
+ F: __dxlog_file9,
2224
+ L: 314,
2058
2225
  S: this,
2059
2226
  C: (f, a) => f(...a)
2060
2227
  });
2061
- stream.error(err);
2228
+ guardedState.error(extension, err);
2062
2229
  }
2063
- log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace4.error({
2230
+ extensionCtx.close(err);
2231
+ log7.trace("dxos.sdk.invitations-handler.guest.onOpen", trace4.error({
2064
2232
  id: traceId,
2065
2233
  error: err
2066
2234
  }), {
2067
- F: __dxlog_file7,
2068
- L: 297,
2235
+ F: __dxlog_file9,
2236
+ L: 318,
2069
2237
  S: this,
2070
2238
  C: (f, a) => f(...a)
2071
2239
  });
2072
- } finally {
2073
- await ctx.dispose();
2074
2240
  }
2075
2241
  });
2076
2242
  },
2077
2243
  onError: (err) => {
2078
- if (err instanceof InvalidInvitationExtensionRoleError2) {
2244
+ if (err instanceof InvalidInvitationExtensionRoleError3) {
2079
2245
  return;
2080
2246
  }
2081
2247
  if (err instanceof TimeoutError) {
2082
- log5("timeout", {
2248
+ log7("timeout", {
2083
2249
  ...protocol.toJSON()
2084
2250
  }, {
2085
- F: __dxlog_file7,
2086
- L: 308,
2251
+ F: __dxlog_file9,
2252
+ L: 327,
2087
2253
  S: this,
2088
2254
  C: (f, a) => f(...a)
2089
2255
  });
2090
- setState({
2091
- state: Invitation3.State.TIMEOUT
2092
- });
2256
+ guardedState.set(extension, Invitation4.State.TIMEOUT);
2093
2257
  } else {
2094
- log5("auth failed", err, {
2095
- F: __dxlog_file7,
2096
- L: 311,
2258
+ log7("auth failed", err, {
2259
+ F: __dxlog_file9,
2260
+ L: 330,
2097
2261
  S: this,
2098
2262
  C: (f, a) => f(...a)
2099
2263
  });
2100
- stream.error(err);
2264
+ guardedState.error(extension, err);
2101
2265
  }
2102
2266
  }
2103
2267
  });
2104
2268
  return extension;
2105
2269
  };
2106
- scheduleTask2(ctx, async () => {
2270
+ scheduleTask3(ctx, async () => {
2107
2271
  const error = protocol.checkInvitation(invitation);
2108
2272
  if (error) {
2109
2273
  stream.error(error);
2274
+ await ctx.dispose();
2110
2275
  } else {
2111
- invariant6(invitation.swarmKey, void 0, {
2112
- F: __dxlog_file7,
2113
- L: 325,
2276
+ invariant8(invitation.swarmKey, void 0, {
2277
+ F: __dxlog_file9,
2278
+ L: 345,
2114
2279
  S: this,
2115
2280
  A: [
2116
2281
  "invitation.swarmKey",
2117
2282
  ""
2118
2283
  ]
2119
2284
  });
2120
- const topic = invitation.swarmKey;
2121
- const swarmConnection = await this._networkManager.joinSwarm({
2122
- topic,
2123
- peerId: PublicKey6.random(),
2124
- protocolProvider: createTeleportProtocolFactory(async (teleport) => {
2125
- teleport.addExtension("dxos.halo.invitations", createExtension());
2126
- }),
2127
- topology: new StarTopology(topic),
2128
- label: "invitation guest"
2129
- });
2130
- ctx.onDispose(() => swarmConnection.close());
2131
- setState({
2132
- state: Invitation3.State.CONNECTING
2133
- });
2285
+ await this._joinSwarm(ctx, invitation, Options4.Role.GUEST, createExtension);
2286
+ guardedState.set(null, Invitation4.State.CONNECTING);
2134
2287
  }
2135
2288
  });
2136
- const observable = new AuthenticatingInvitation({
2137
- initialInvitation: invitation,
2138
- subscriber: stream.observable,
2139
- onCancel: async () => {
2140
- setState({
2141
- state: Invitation3.State.CANCELLED
2142
- });
2143
- await ctx.dispose();
2289
+ }
2290
+ async _joinSwarm(ctx, invitation, role, extensionFactory) {
2291
+ let label;
2292
+ if (role === Options4.Role.GUEST) {
2293
+ label = "invitation guest";
2294
+ } else if (invitation.kind === Invitation4.Kind.DEVICE) {
2295
+ label = "invitation host for device";
2296
+ } else {
2297
+ label = `invitation host for space ${invitation.spaceKey?.truncate()}`;
2298
+ }
2299
+ const swarmConnection = await this._networkManager.joinSwarm({
2300
+ topic: invitation.swarmKey,
2301
+ peerId: PublicKey7.random(),
2302
+ protocolProvider: createTeleportProtocolFactory(async (teleport) => {
2303
+ teleport.addExtension("dxos.halo.invitations", extensionFactory());
2304
+ }, this._defaultTeleportParams),
2305
+ topology: new InvitationTopology(role),
2306
+ label
2307
+ });
2308
+ ctx.onDispose(() => swarmConnection.close());
2309
+ return swarmConnection;
2310
+ }
2311
+ /**
2312
+ * A utility object for serializing invitation state changes by multiple concurrent
2313
+ * invitation flow connections.
2314
+ */
2315
+ _createGuardedState(ctx, invitation, stream) {
2316
+ const mutex = new Mutex();
2317
+ let lastActiveExtension = null;
2318
+ let currentInvitation = {
2319
+ ...invitation
2320
+ };
2321
+ const isStateChangeAllowed = (extension) => {
2322
+ if (ctx.disposed || extension !== null && mutex.isLocked() && !extension.hasFlowLock()) {
2323
+ return false;
2324
+ }
2325
+ return extension == null || lastActiveExtension !== extension || this._isNotTerminal(currentInvitation.state);
2326
+ };
2327
+ return {
2328
+ mutex,
2329
+ get current() {
2330
+ return currentInvitation;
2144
2331
  },
2145
- onAuthenticate: async (code) => {
2146
- authenticated.wake(code);
2332
+ // disposing context prevents any further state updates
2333
+ complete: (newState) => {
2334
+ currentInvitation = {
2335
+ ...currentInvitation,
2336
+ ...newState
2337
+ };
2338
+ stream.next(currentInvitation);
2339
+ return ctx.dispose();
2340
+ },
2341
+ set: (extension, newState) => {
2342
+ if (isStateChangeAllowed(extension)) {
2343
+ this._logStateUpdate(currentInvitation, extension, newState);
2344
+ currentInvitation = {
2345
+ ...currentInvitation,
2346
+ state: newState
2347
+ };
2348
+ stream.next(currentInvitation);
2349
+ lastActiveExtension = extension;
2350
+ return true;
2351
+ }
2352
+ return false;
2353
+ },
2354
+ error: (extension, error) => {
2355
+ if (isStateChangeAllowed(extension)) {
2356
+ this._logStateUpdate(currentInvitation, extension, Invitation4.State.ERROR);
2357
+ currentInvitation = {
2358
+ ...currentInvitation,
2359
+ state: Invitation4.State.ERROR
2360
+ };
2361
+ stream.next(currentInvitation);
2362
+ stream.error(error);
2363
+ lastActiveExtension = extension;
2364
+ return true;
2365
+ }
2366
+ return false;
2147
2367
  }
2368
+ };
2369
+ }
2370
+ _logStateUpdate(invitation, actor, newState) {
2371
+ log7("invitation state update", {
2372
+ actor: actor?.constructor.name,
2373
+ newState: stateToString(newState),
2374
+ oldState: stateToString(invitation.state)
2375
+ }, {
2376
+ F: __dxlog_file9,
2377
+ L: 438,
2378
+ S: this,
2379
+ C: (f, a) => f(...a)
2148
2380
  });
2149
- return observable;
2381
+ }
2382
+ _isNotTerminal(currentState) {
2383
+ return ![
2384
+ Invitation4.State.SUCCESS,
2385
+ Invitation4.State.ERROR,
2386
+ Invitation4.State.CANCELLED,
2387
+ Invitation4.State.TIMEOUT,
2388
+ Invitation4.State.EXPIRED
2389
+ ].includes(currentState);
2150
2390
  }
2151
2391
  async _handleGuestOtpAuth(extension, setState, authenticated, options) {
2152
2392
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2153
- log5("guest waiting for authentication code...", void 0, {
2154
- F: __dxlog_file7,
2155
- L: 365,
2393
+ log7("guest waiting for authentication code...", void 0, {
2394
+ F: __dxlog_file9,
2395
+ L: 462,
2156
2396
  S: this,
2157
2397
  C: (f, a) => f(...a)
2158
2398
  });
2159
- setState({
2160
- state: Invitation3.State.READY_FOR_AUTHENTICATION
2161
- });
2399
+ setState(Invitation4.State.READY_FOR_AUTHENTICATION);
2162
2400
  const authCode = await authenticated.wait(options);
2163
- log5("sending authentication request", void 0, {
2164
- F: __dxlog_file7,
2165
- L: 369,
2401
+ log7("sending authentication request", void 0, {
2402
+ F: __dxlog_file9,
2403
+ L: 466,
2166
2404
  S: this,
2167
2405
  C: (f, a) => f(...a)
2168
2406
  });
2169
- setState({
2170
- state: Invitation3.State.AUTHENTICATING
2171
- });
2407
+ setState(Invitation4.State.AUTHENTICATING);
2172
2408
  const response = await extension.rpc.InvitationHostService.authenticate({
2173
2409
  authCode
2174
2410
  });
@@ -2179,11 +2415,11 @@ var InvitationsHandler = class {
2179
2415
  if (attempt === MAX_OTP_ATTEMPTS) {
2180
2416
  throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
2181
2417
  } else {
2182
- log5("retrying invalid code", {
2418
+ log7("retrying invalid code", {
2183
2419
  attempt
2184
2420
  }, {
2185
- F: __dxlog_file7,
2186
- L: 380,
2421
+ F: __dxlog_file9,
2422
+ L: 477,
2187
2423
  S: this,
2188
2424
  C: (f, a) => f(...a)
2189
2425
  });
@@ -2199,15 +2435,13 @@ var InvitationsHandler = class {
2199
2435
  if (introductionResponse.challenge == null) {
2200
2436
  throw new Error("challenge missing in the introduction");
2201
2437
  }
2202
- log5("sending authentication request", void 0, {
2203
- F: __dxlog_file7,
2204
- L: 399,
2438
+ log7("sending authentication request", void 0, {
2439
+ F: __dxlog_file9,
2440
+ L: 496,
2205
2441
  S: this,
2206
2442
  C: (f, a) => f(...a)
2207
2443
  });
2208
- setState({
2209
- state: Invitation3.State.AUTHENTICATING
2210
- });
2444
+ setState(Invitation4.State.AUTHENTICATING);
2211
2445
  const signature = sign(Buffer.from(introductionResponse.challenge), invitation.guestKeypair.privateKey);
2212
2446
  const response = await extension.rpc.InvitationHostService.authenticate({
2213
2447
  signedChallenge: signature
@@ -2220,7 +2454,7 @@ var InvitationsHandler = class {
2220
2454
  var createAdmissionKeypair = () => {
2221
2455
  const keypair = createKeyPair();
2222
2456
  return {
2223
- publicKey: PublicKey6.from(keypair.publicKey),
2457
+ publicKey: PublicKey7.from(keypair.publicKey),
2224
2458
  privateKey: keypair.secretKey
2225
2459
  };
2226
2460
  };
@@ -2323,14 +2557,14 @@ var InvitationsServiceImpl = class {
2323
2557
  };
2324
2558
 
2325
2559
  // packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts
2326
- import { createAdmissionCredentials, createDelegatedSpaceInvitationCredential, getCredentialAssertion } from "@dxos/credentials";
2560
+ import { createAdmissionCredentials, createCancelDelegatedSpaceInvitationCredential, createDelegatedSpaceInvitationCredential, getCredentialAssertion } from "@dxos/credentials";
2327
2561
  import { writeMessages as writeMessages2 } from "@dxos/feed-store";
2328
- import { invariant as invariant7 } from "@dxos/invariant";
2329
- import { log as log6 } from "@dxos/log";
2562
+ import { invariant as invariant9 } from "@dxos/invariant";
2563
+ import { log as log8 } from "@dxos/log";
2330
2564
  import { AlreadyJoinedError as AlreadyJoinedError2 } from "@dxos/protocols";
2331
- import { Invitation as Invitation4 } from "@dxos/protocols/proto/dxos/client/services";
2565
+ import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
2332
2566
  import { SpaceMember } from "@dxos/protocols/proto/dxos/halo/credentials";
2333
- var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
2567
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
2334
2568
  var SpaceInvitationProtocol = class {
2335
2569
  constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
2336
2570
  this._spaceManager = _spaceManager;
@@ -2346,14 +2580,14 @@ var SpaceInvitationProtocol = class {
2346
2580
  }
2347
2581
  getInvitationContext() {
2348
2582
  return {
2349
- kind: Invitation4.Kind.SPACE,
2583
+ kind: Invitation5.Kind.SPACE,
2350
2584
  spaceKey: this._spaceKey
2351
2585
  };
2352
2586
  }
2353
2587
  async admit(invitation, request, guestProfile) {
2354
- invariant7(this._spaceKey, void 0, {
2355
- F: __dxlog_file8,
2356
- L: 55,
2588
+ invariant9(this._spaceKey, void 0, {
2589
+ F: __dxlog_file10,
2590
+ L: 56,
2357
2591
  S: this,
2358
2592
  A: [
2359
2593
  "this._spaceKey",
@@ -2361,18 +2595,18 @@ var SpaceInvitationProtocol = class {
2361
2595
  ]
2362
2596
  });
2363
2597
  const space = await this._spaceManager.spaces.get(this._spaceKey);
2364
- invariant7(space, void 0, {
2365
- F: __dxlog_file8,
2366
- L: 57,
2598
+ invariant9(space, void 0, {
2599
+ F: __dxlog_file10,
2600
+ L: 58,
2367
2601
  S: this,
2368
2602
  A: [
2369
2603
  "space",
2370
2604
  ""
2371
2605
  ]
2372
2606
  });
2373
- invariant7(request.space, void 0, {
2374
- F: __dxlog_file8,
2375
- L: 59,
2607
+ invariant9(request.space, void 0, {
2608
+ F: __dxlog_file10,
2609
+ L: 60,
2376
2610
  S: this,
2377
2611
  A: [
2378
2612
  "request.space",
@@ -2380,19 +2614,19 @@ var SpaceInvitationProtocol = class {
2380
2614
  ]
2381
2615
  });
2382
2616
  const { identityKey, deviceKey } = request.space;
2383
- log6("writing guest credentials", {
2617
+ log8("writing guest credentials", {
2384
2618
  host: this._signingContext.deviceKey,
2385
2619
  guest: deviceKey
2386
2620
  }, {
2387
- F: __dxlog_file8,
2388
- L: 62,
2621
+ F: __dxlog_file10,
2622
+ L: 63,
2389
2623
  S: this,
2390
2624
  C: (f, a) => f(...a)
2391
2625
  });
2392
2626
  const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile, invitation.delegationCredentialId);
2393
- invariant7(credentials[0].credential, void 0, {
2394
- F: __dxlog_file8,
2395
- L: 74,
2627
+ invariant9(credentials[0].credential, void 0, {
2628
+ F: __dxlog_file10,
2629
+ L: 75,
2396
2630
  S: this,
2397
2631
  A: [
2398
2632
  "credentials[0].credential",
@@ -2400,9 +2634,9 @@ var SpaceInvitationProtocol = class {
2400
2634
  ]
2401
2635
  });
2402
2636
  const spaceMemberCredential = credentials[0].credential.credential;
2403
- invariant7(getCredentialAssertion(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2404
- F: __dxlog_file8,
2405
- L: 76,
2637
+ invariant9(getCredentialAssertion(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2638
+ F: __dxlog_file10,
2639
+ L: 77,
2406
2640
  S: this,
2407
2641
  A: [
2408
2642
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2418,29 +2652,29 @@ var SpaceInvitationProtocol = class {
2418
2652
  };
2419
2653
  }
2420
2654
  async delegate(invitation) {
2421
- invariant7(this._spaceKey, void 0, {
2422
- F: __dxlog_file8,
2423
- L: 89,
2655
+ invariant9(this._spaceKey, void 0, {
2656
+ F: __dxlog_file10,
2657
+ L: 90,
2424
2658
  S: this,
2425
2659
  A: [
2426
2660
  "this._spaceKey",
2427
2661
  ""
2428
2662
  ]
2429
2663
  });
2430
- const space = await this._spaceManager.spaces.get(this._spaceKey);
2431
- invariant7(space, void 0, {
2432
- F: __dxlog_file8,
2433
- L: 91,
2664
+ const space = this._spaceManager.spaces.get(this._spaceKey);
2665
+ invariant9(space, void 0, {
2666
+ F: __dxlog_file10,
2667
+ L: 92,
2434
2668
  S: this,
2435
2669
  A: [
2436
2670
  "space",
2437
2671
  ""
2438
2672
  ]
2439
2673
  });
2440
- if (invitation.authMethod === Invitation4.AuthMethod.KNOWN_PUBLIC_KEY) {
2441
- invariant7(invitation.guestKeypair?.publicKey, void 0, {
2442
- F: __dxlog_file8,
2443
- L: 93,
2674
+ if (invitation.authMethod === Invitation5.AuthMethod.KNOWN_PUBLIC_KEY) {
2675
+ invariant9(invitation.guestKeypair?.publicKey, void 0, {
2676
+ F: __dxlog_file10,
2677
+ L: 94,
2444
2678
  S: this,
2445
2679
  A: [
2446
2680
  "invitation.guestKeypair?.publicKey",
@@ -2448,27 +2682,80 @@ var SpaceInvitationProtocol = class {
2448
2682
  ]
2449
2683
  });
2450
2684
  }
2451
- log6("writing delegate space invitation", {
2685
+ log8("writing delegate space invitation", {
2686
+ host: this._signingContext.deviceKey,
2687
+ id: invitation.invitationId
2688
+ }, {
2689
+ F: __dxlog_file10,
2690
+ L: 97,
2691
+ S: this,
2692
+ C: (f, a) => f(...a)
2693
+ });
2694
+ const credential = await createDelegatedSpaceInvitationCredential(this._signingContext.credentialSigner, space.key, {
2695
+ invitationId: invitation.invitationId,
2696
+ authMethod: invitation.authMethod,
2697
+ swarmKey: invitation.swarmKey,
2698
+ role: SpaceMember.Role.ADMIN,
2699
+ expiresOn: invitation.lifetime ? new Date((invitation.created?.getTime() ?? Date.now()) + invitation.lifetime) : void 0,
2700
+ multiUse: invitation.multiUse ?? false,
2701
+ guestKey: invitation.authMethod === Invitation5.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
2702
+ });
2703
+ invariant9(credential.credential, void 0, {
2704
+ F: __dxlog_file10,
2705
+ L: 117,
2706
+ S: this,
2707
+ A: [
2708
+ "credential.credential",
2709
+ ""
2710
+ ]
2711
+ });
2712
+ await writeMessages2(space.inner.controlPipeline.writer, [
2713
+ credential
2714
+ ]);
2715
+ return credential.credential.credential.id;
2716
+ }
2717
+ async cancelDelegation(invitation) {
2718
+ invariant9(this._spaceKey, void 0, {
2719
+ F: __dxlog_file10,
2720
+ L: 123,
2721
+ S: this,
2722
+ A: [
2723
+ "this._spaceKey",
2724
+ ""
2725
+ ]
2726
+ });
2727
+ invariant9(invitation.type === Invitation5.Type.DELEGATED && invitation.delegationCredentialId, void 0, {
2728
+ F: __dxlog_file10,
2729
+ L: 124,
2730
+ S: this,
2731
+ A: [
2732
+ "invitation.type === Invitation.Type.DELEGATED && invitation.delegationCredentialId",
2733
+ ""
2734
+ ]
2735
+ });
2736
+ const space = this._spaceManager.spaces.get(this._spaceKey);
2737
+ invariant9(space, void 0, {
2738
+ F: __dxlog_file10,
2739
+ L: 126,
2740
+ S: this,
2741
+ A: [
2742
+ "space",
2743
+ ""
2744
+ ]
2745
+ });
2746
+ log8("cancelling delegated space invitation", {
2452
2747
  host: this._signingContext.deviceKey,
2453
2748
  id: invitation.invitationId
2454
2749
  }, {
2455
- F: __dxlog_file8,
2456
- L: 96,
2750
+ F: __dxlog_file10,
2751
+ L: 128,
2457
2752
  S: this,
2458
2753
  C: (f, a) => f(...a)
2459
2754
  });
2460
- const credential = await createDelegatedSpaceInvitationCredential(this._signingContext.credentialSigner, space.key, {
2461
- invitationId: invitation.invitationId,
2462
- authMethod: invitation.authMethod,
2463
- swarmKey: invitation.swarmKey,
2464
- role: SpaceMember.Role.ADMIN,
2465
- expiresOn: invitation.lifetime ? new Date((invitation.created?.getTime() ?? Date.now()) + invitation.lifetime) : void 0,
2466
- multiUse: invitation.multiUse ?? false,
2467
- guestKey: invitation.authMethod === Invitation4.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
2468
- });
2469
- invariant7(credential.credential, void 0, {
2470
- F: __dxlog_file8,
2471
- L: 116,
2755
+ const credential = await createCancelDelegatedSpaceInvitationCredential(this._signingContext.credentialSigner, space.key, invitation.delegationCredentialId);
2756
+ invariant9(credential.credential, void 0, {
2757
+ F: __dxlog_file10,
2758
+ L: 135,
2472
2759
  S: this,
2473
2760
  A: [
2474
2761
  "credential.credential",
@@ -2478,7 +2765,6 @@ var SpaceInvitationProtocol = class {
2478
2765
  await writeMessages2(space.inner.controlPipeline.writer, [
2479
2766
  credential
2480
2767
  ]);
2481
- return credential.credential.credential.id;
2482
2768
  }
2483
2769
  checkInvitation(invitation) {
2484
2770
  if (invitation.spaceKey && this._spaceManager.spaces.has(invitation.spaceKey)) {
@@ -2503,9 +2789,9 @@ var SpaceInvitationProtocol = class {
2503
2789
  };
2504
2790
  }
2505
2791
  async accept(response) {
2506
- invariant7(response.space, void 0, {
2507
- F: __dxlog_file8,
2508
- L: 149,
2792
+ invariant9(response.space, void 0, {
2793
+ F: __dxlog_file10,
2794
+ L: 167,
2509
2795
  S: this,
2510
2796
  A: [
2511
2797
  "response.space",
@@ -2514,18 +2800,18 @@ var SpaceInvitationProtocol = class {
2514
2800
  });
2515
2801
  const { credential, controlTimeframe, dataTimeframe } = response.space;
2516
2802
  const assertion = getCredentialAssertion(credential);
2517
- invariant7(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2518
- F: __dxlog_file8,
2519
- L: 152,
2803
+ invariant9(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2804
+ F: __dxlog_file10,
2805
+ L: 170,
2520
2806
  S: this,
2521
2807
  A: [
2522
2808
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
2523
2809
  "'Invalid credential'"
2524
2810
  ]
2525
2811
  });
2526
- invariant7(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
2527
- F: __dxlog_file8,
2528
- L: 153,
2812
+ invariant9(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
2813
+ F: __dxlog_file10,
2814
+ L: 171,
2529
2815
  S: this,
2530
2816
  A: [
2531
2817
  "credential.subject.id.equals(this._signingContext.identityKey)",
@@ -2549,16 +2835,16 @@ var SpaceInvitationProtocol = class {
2549
2835
  };
2550
2836
 
2551
2837
  // packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts
2552
- import { Event as Event3, PushStream as PushStream2 } from "@dxos/async";
2553
- import { AUTHENTICATION_CODE_LENGTH, CancellableInvitation, INVITATION_TIMEOUT as INVITATION_TIMEOUT2 } from "@dxos/client-protocol";
2838
+ import { Event as Event3, PushStream, TimeoutError as TimeoutError2, Trigger as Trigger4 } from "@dxos/async";
2839
+ import { AuthenticatingInvitation, AUTHENTICATION_CODE_LENGTH, CancellableInvitation, INVITATION_TIMEOUT as INVITATION_TIMEOUT2 } from "@dxos/client-protocol";
2554
2840
  import { Context as Context6 } from "@dxos/context";
2555
2841
  import { generatePasscode } from "@dxos/credentials";
2556
2842
  import { hasInvitationExpired } from "@dxos/echo-pipeline";
2557
- import { invariant as invariant8 } from "@dxos/invariant";
2558
- import { PublicKey as PublicKey7 } from "@dxos/keys";
2559
- import { log as log7 } from "@dxos/log";
2560
- import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
2561
- var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
2843
+ import { invariant as invariant10 } from "@dxos/invariant";
2844
+ import { PublicKey as PublicKey8 } from "@dxos/keys";
2845
+ import { log as log9 } from "@dxos/log";
2846
+ import { Invitation as Invitation6 } from "@dxos/protocols/proto/dxos/client/services";
2847
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
2562
2848
  var InvitationsManager = class {
2563
2849
  constructor(_invitationsHandler, _getHandler, _metadataStore) {
2564
2850
  this._invitationsHandler = _invitationsHandler;
@@ -2596,8 +2882,8 @@ var InvitationsManager = class {
2596
2882
  try {
2597
2883
  await this._persistIfRequired(handler, stream, invitation);
2598
2884
  } catch (err) {
2599
- log7.catch(err, void 0, {
2600
- F: __dxlog_file9,
2885
+ log9.catch(err, void 0, {
2886
+ F: __dxlog_file11,
2601
2887
  L: 76,
2602
2888
  S: this,
2603
2889
  C: (f, a) => f(...a)
@@ -2619,8 +2905,8 @@ var InvitationsManager = class {
2619
2905
  const persistentInvitations = this._metadataStore.getInvitations();
2620
2906
  const freshInvitations = persistentInvitations.filter((invitation) => !hasInvitationExpired(invitation));
2621
2907
  const loadTasks = freshInvitations.map((persistentInvitation) => {
2622
- invariant8(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
2623
- F: __dxlog_file9,
2908
+ invariant10(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
2909
+ F: __dxlog_file11,
2624
2910
  L: 97,
2625
2911
  S: this,
2626
2912
  A: [
@@ -2638,8 +2924,8 @@ var InvitationsManager = class {
2638
2924
  invitations: cInvitations.map((invitation) => invitation.get())
2639
2925
  };
2640
2926
  } catch (err) {
2641
- log7.catch(err, void 0, {
2642
- F: __dxlog_file9,
2927
+ log9.catch(err, void 0, {
2928
+ F: __dxlog_file11,
2643
2929
  L: 104,
2644
2930
  S: this,
2645
2931
  C: (f, a) => f(...a)
@@ -2659,7 +2945,8 @@ var InvitationsManager = class {
2659
2945
  return existingInvitation;
2660
2946
  }
2661
2947
  const handler = this._getHandler(options);
2662
- const invitation = this._invitationsHandler.acceptInvitation(handler, options, request.deviceProfile);
2948
+ const { ctx, invitation, stream, otpEnteredTrigger } = this._createObservableAcceptingInvitation(handler, options);
2949
+ this._invitationsHandler.acceptInvitation(ctx, stream, handler, options, otpEnteredTrigger, request.deviceProfile);
2663
2950
  this._acceptInvitations.set(invitation.get().invitationId, invitation);
2664
2951
  this.invitationAccepted.emit(invitation.get());
2665
2952
  this._onInvitationComplete(invitation, () => {
@@ -2669,15 +2956,15 @@ var InvitationsManager = class {
2669
2956
  return invitation;
2670
2957
  }
2671
2958
  async authenticate({ invitationId, authCode }) {
2672
- log7("authenticating...", void 0, {
2673
- F: __dxlog_file9,
2674
- L: 133,
2959
+ log9("authenticating...", void 0, {
2960
+ F: __dxlog_file11,
2961
+ L: 134,
2675
2962
  S: this,
2676
2963
  C: (f, a) => f(...a)
2677
2964
  });
2678
- invariant8(invitationId, void 0, {
2679
- F: __dxlog_file9,
2680
- L: 134,
2965
+ invariant10(invitationId, void 0, {
2966
+ F: __dxlog_file11,
2967
+ L: 135,
2681
2968
  S: this,
2682
2969
  A: [
2683
2970
  "invitationId",
@@ -2686,11 +2973,11 @@ var InvitationsManager = class {
2686
2973
  });
2687
2974
  const observable = this._acceptInvitations.get(invitationId);
2688
2975
  if (!observable) {
2689
- log7.warn("invalid invitation", {
2976
+ log9.warn("invalid invitation", {
2690
2977
  invitationId
2691
2978
  }, {
2692
- F: __dxlog_file9,
2693
- L: 137,
2979
+ F: __dxlog_file11,
2980
+ L: 138,
2694
2981
  S: this,
2695
2982
  C: (f, a) => f(...a)
2696
2983
  });
@@ -2699,17 +2986,17 @@ var InvitationsManager = class {
2699
2986
  }
2700
2987
  }
2701
2988
  async cancelInvitation({ invitationId }) {
2702
- log7("cancelInvitation...", {
2989
+ log9("cancelInvitation...", {
2703
2990
  invitationId
2704
2991
  }, {
2705
- F: __dxlog_file9,
2706
- L: 144,
2992
+ F: __dxlog_file11,
2993
+ L: 145,
2707
2994
  S: this,
2708
2995
  C: (f, a) => f(...a)
2709
2996
  });
2710
- invariant8(invitationId, void 0, {
2711
- F: __dxlog_file9,
2712
- L: 145,
2997
+ invariant10(invitationId, void 0, {
2998
+ F: __dxlog_file11,
2999
+ L: 146,
2713
3000
  S: this,
2714
3001
  A: [
2715
3002
  "invitationId",
@@ -2721,6 +3008,10 @@ var InvitationsManager = class {
2721
3008
  if (created.get().persistent) {
2722
3009
  await this._metadataStore.removeInvitation(invitationId);
2723
3010
  }
3011
+ if (created.get().type === Invitation6.Type.DELEGATED) {
3012
+ const handler = this._getHandler(created.get());
3013
+ await handler.cancelDelegation(created.get());
3014
+ }
2724
3015
  await created.cancel();
2725
3016
  this._createInvitations.delete(invitationId);
2726
3017
  this.removedCreated.emit(created.get());
@@ -2751,8 +3042,8 @@ var InvitationsManager = class {
2751
3042
  }
2752
3043
  }
2753
3044
  _createInvitation(protocol, options) {
2754
- const { invitationId = PublicKey7.random().toHex(), type = Invitation5.Type.INTERACTIVE, authMethod = Invitation5.AuthMethod.SHARED_SECRET, state = Invitation5.State.INIT, timeout = INVITATION_TIMEOUT2, swarmKey = PublicKey7.random(), persistent = options?.authMethod !== Invitation5.AuthMethod.KNOWN_PUBLIC_KEY, created = /* @__PURE__ */ new Date(), guestKeypair = void 0, lifetime = 86400, multiUse = false } = options ?? {};
2755
- const authCode = options?.authCode ?? (authMethod === Invitation5.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0);
3045
+ const { invitationId = PublicKey8.random().toHex(), type = Invitation6.Type.INTERACTIVE, authMethod = Invitation6.AuthMethod.SHARED_SECRET, state = Invitation6.State.INIT, timeout = INVITATION_TIMEOUT2, swarmKey = PublicKey8.random(), persistent = options?.authMethod !== Invitation6.AuthMethod.KNOWN_PUBLIC_KEY, created = /* @__PURE__ */ new Date(), guestKeypair = void 0, lifetime = 86400, multiUse = false } = options ?? {};
3046
+ const authCode = options?.authCode ?? (authMethod === Invitation6.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0);
2756
3047
  return {
2757
3048
  invitationId,
2758
3049
  type,
@@ -2761,8 +3052,8 @@ var InvitationsManager = class {
2761
3052
  swarmKey,
2762
3053
  authCode,
2763
3054
  timeout,
2764
- persistent: persistent && type !== Invitation5.Type.DELEGATED,
2765
- guestKeypair: guestKeypair ?? (authMethod === Invitation5.AuthMethod.KNOWN_PUBLIC_KEY ? createAdmissionKeypair() : void 0),
3055
+ persistent: persistent && type !== Invitation6.Type.DELEGATED,
3056
+ guestKeypair: guestKeypair ?? (authMethod === Invitation6.AuthMethod.KNOWN_PUBLIC_KEY ? createAdmissionKeypair() : void 0),
2766
3057
  created,
2767
3058
  lifetime,
2768
3059
  multiUse,
@@ -2771,7 +3062,7 @@ var InvitationsManager = class {
2771
3062
  };
2772
3063
  }
2773
3064
  _createObservableInvitation(handler, invitation) {
2774
- const stream = new PushStream2();
3065
+ const stream = new PushStream();
2775
3066
  const ctx = new Context6({
2776
3067
  onError: (err) => {
2777
3068
  stream.error(err);
@@ -2779,11 +3070,11 @@ var InvitationsManager = class {
2779
3070
  }
2780
3071
  });
2781
3072
  ctx.onDispose(() => {
2782
- log7("complete", {
3073
+ log9("complete", {
2783
3074
  ...handler.toJSON()
2784
3075
  }, {
2785
- F: __dxlog_file9,
2786
- L: 228,
3076
+ F: __dxlog_file11,
3077
+ L: 233,
2787
3078
  S: this,
2788
3079
  C: (f, a) => f(...a)
2789
3080
  });
@@ -2795,7 +3086,7 @@ var InvitationsManager = class {
2795
3086
  onCancel: async () => {
2796
3087
  stream.next({
2797
3088
  ...invitation,
2798
- state: Invitation5.State.CANCELLED
3089
+ state: Invitation6.State.CANCELLED
2799
3090
  });
2800
3091
  await ctx.dispose();
2801
3092
  }
@@ -2806,8 +3097,73 @@ var InvitationsManager = class {
2806
3097
  observableInvitation
2807
3098
  };
2808
3099
  }
3100
+ _createObservableAcceptingInvitation(handler, initialState) {
3101
+ const otpEnteredTrigger = new Trigger4();
3102
+ const stream = new PushStream();
3103
+ const ctx = new Context6({
3104
+ onError: (err) => {
3105
+ if (err instanceof TimeoutError2) {
3106
+ log9("timeout", {
3107
+ ...handler.toJSON()
3108
+ }, {
3109
+ F: __dxlog_file11,
3110
+ L: 253,
3111
+ S: this,
3112
+ C: (f, a) => f(...a)
3113
+ });
3114
+ stream.next({
3115
+ ...initialState,
3116
+ state: Invitation6.State.TIMEOUT
3117
+ });
3118
+ } else {
3119
+ log9.warn("auth failed", err, {
3120
+ F: __dxlog_file11,
3121
+ L: 256,
3122
+ S: this,
3123
+ C: (f, a) => f(...a)
3124
+ });
3125
+ stream.next({
3126
+ ...initialState,
3127
+ state: Invitation6.State.ERROR
3128
+ });
3129
+ }
3130
+ void ctx.dispose();
3131
+ }
3132
+ });
3133
+ ctx.onDispose(() => {
3134
+ log9("complete", {
3135
+ ...handler.toJSON()
3136
+ }, {
3137
+ F: __dxlog_file11,
3138
+ L: 263,
3139
+ S: this,
3140
+ C: (f, a) => f(...a)
3141
+ });
3142
+ stream.complete();
3143
+ });
3144
+ const invitation = new AuthenticatingInvitation({
3145
+ initialInvitation: initialState,
3146
+ subscriber: stream.observable,
3147
+ onCancel: async () => {
3148
+ stream.next({
3149
+ ...initialState,
3150
+ state: Invitation6.State.CANCELLED
3151
+ });
3152
+ await ctx.dispose();
3153
+ },
3154
+ onAuthenticate: async (code) => {
3155
+ otpEnteredTrigger.wake(code);
3156
+ }
3157
+ });
3158
+ return {
3159
+ ctx,
3160
+ invitation,
3161
+ stream,
3162
+ otpEnteredTrigger
3163
+ };
3164
+ }
2809
3165
  async _persistIfRequired(handler, changeStream, invitation) {
2810
- if (invitation.type === Invitation5.Type.DELEGATED && invitation.delegationCredentialId == null) {
3166
+ if (invitation.type === Invitation6.Type.DELEGATED && invitation.delegationCredentialId == null) {
2811
3167
  const delegationCredentialId = await handler.delegate(invitation);
2812
3168
  changeStream.next({
2813
3169
  ...invitation,
@@ -2822,9 +3178,9 @@ var InvitationsManager = class {
2822
3178
  try {
2823
3179
  await this._metadataStore.removeInvitation(invitation.invitationId);
2824
3180
  } catch (err) {
2825
- log7.catch(err, void 0, {
2826
- F: __dxlog_file9,
2827
- L: 260,
3181
+ log9.catch(err, void 0, {
3182
+ F: __dxlog_file11,
3183
+ L: 299,
2828
3184
  S: this,
2829
3185
  C: (f, a) => f(...a)
2830
3186
  });
@@ -2919,22 +3275,22 @@ ClientRpcServer = _ts_decorate3([
2919
3275
  ], ClientRpcServer);
2920
3276
 
2921
3277
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2922
- import { Event as Event6, asyncTimeout, scheduleTask as scheduleTask4, sleep as sleep2, synchronized, trackLeaks } from "@dxos/async";
3278
+ import { Event as Event6, asyncTimeout, scheduleTask as scheduleTask5, sleep as sleep2, synchronized, trackLeaks } from "@dxos/async";
2923
3279
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
2924
- import { cancelWithContext as cancelWithContext2, Context as Context8, ContextDisposedError } from "@dxos/context";
3280
+ import { cancelWithContext as cancelWithContext4, Context as Context8, ContextDisposedError as ContextDisposedError3 } from "@dxos/context";
2925
3281
  import { timed, warnAfterTimeout } from "@dxos/debug";
2926
3282
  import { createMappedFeedWriter } from "@dxos/echo-pipeline";
2927
3283
  import { AutomergeDocumentLoaderImpl } from "@dxos/echo-pipeline";
2928
3284
  import { TYPE_PROPERTIES } from "@dxos/echo-schema";
2929
- import { failedInvariant, invariant as invariant10 } from "@dxos/invariant";
2930
- import { PublicKey as PublicKey9 } from "@dxos/keys";
2931
- import { log as log9 } from "@dxos/log";
3285
+ import { failedInvariant, invariant as invariant12 } from "@dxos/invariant";
3286
+ import { PublicKey as PublicKey10 } from "@dxos/keys";
3287
+ import { log as log11 } from "@dxos/log";
2932
3288
  import { CancelledError, SystemError } from "@dxos/protocols";
2933
3289
  import { SpaceState, CreateEpochRequest } from "@dxos/protocols/proto/dxos/client/services";
2934
3290
  import { AdmittedFeed as AdmittedFeed3 } from "@dxos/protocols/proto/dxos/halo/credentials";
2935
3291
  import { Timeframe as Timeframe2 } from "@dxos/timeframe";
2936
3292
  import { trace as trace6 } from "@dxos/tracing";
2937
- import { ComplexSet as ComplexSet3, assignDeep } from "@dxos/util";
3293
+ import { ComplexSet as ComplexSet5, assignDeep } from "@dxos/util";
2938
3294
 
2939
3295
  // packages/sdk/client-services/src/packlets/spaces/automerge-space-state.ts
2940
3296
  import { Event as Event4 } from "@dxos/async";
@@ -2975,15 +3331,15 @@ var AutomergeSpaceState = class {
2975
3331
  };
2976
3332
 
2977
3333
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
2978
- import { DeferredTask, Event as Event5, scheduleTask as scheduleTask3, sleep, TimeoutError as TimeoutError2, Trigger as Trigger4 } from "@dxos/async";
3334
+ import { DeferredTask, Event as Event5, scheduleTask as scheduleTask4, sleep, TimeoutError as TimeoutError3, Trigger as Trigger5 } from "@dxos/async";
2979
3335
  import { Context as Context7, rejectOnDispose } from "@dxos/context";
2980
- import { invariant as invariant9 } from "@dxos/invariant";
2981
- import { PublicKey as PublicKey8 } from "@dxos/keys";
2982
- import { log as log8 } from "@dxos/log";
2983
- import { schema as schema3 } from "@dxos/protocols";
2984
- import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
2985
- import { ComplexMap as ComplexMap2, ComplexSet as ComplexSet2, entry } from "@dxos/util";
2986
- var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
3336
+ import { invariant as invariant11 } from "@dxos/invariant";
3337
+ import { PublicKey as PublicKey9 } from "@dxos/keys";
3338
+ import { log as log10 } from "@dxos/log";
3339
+ import { schema as schema4 } from "@dxos/protocols";
3340
+ import { RpcExtension as RpcExtension3 } from "@dxos/teleport";
3341
+ import { ComplexMap as ComplexMap2, ComplexSet as ComplexSet4, entry } from "@dxos/util";
3342
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
2987
3343
  var DEFAULT_RETRY_TIMEOUT = 1e3;
2988
3344
  var DEFAULT_SUCCESS_DELAY = 1e3;
2989
3345
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
@@ -2993,8 +3349,8 @@ var NotarizationPlugin = class {
2993
3349
  this._ctx = new Context7();
2994
3350
  this._extensionOpened = new Event5();
2995
3351
  this._extensions = /* @__PURE__ */ new Set();
2996
- this._processedCredentials = new ComplexSet2(PublicKey8.hash);
2997
- this._processCredentialsTriggers = new ComplexMap2(PublicKey8.hash);
3352
+ this._processedCredentials = new ComplexSet4(PublicKey9.hash);
3353
+ this._processCredentialsTriggers = new ComplexMap2(PublicKey9.hash);
2998
3354
  }
2999
3355
  get hasWriter() {
3000
3356
  return !!this._writer;
@@ -3008,16 +3364,16 @@ var NotarizationPlugin = class {
3008
3364
  * Request credentials to be notarized.
3009
3365
  */
3010
3366
  async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
3011
- log8("notarize", {
3367
+ log10("notarize", {
3012
3368
  credentials
3013
3369
  }, {
3014
- F: __dxlog_file10,
3370
+ F: __dxlog_file12,
3015
3371
  L: 90,
3016
3372
  S: this,
3017
3373
  C: (f, a) => f(...a)
3018
3374
  });
3019
- invariant9(credentials.every((credential) => credential.id), "Credentials must have an id", {
3020
- F: __dxlog_file10,
3375
+ invariant11(credentials.every((credential) => credential.id), "Credentials must have an id", {
3376
+ F: __dxlog_file12,
3021
3377
  L: 91,
3022
3378
  S: this,
3023
3379
  A: [
@@ -3025,13 +3381,13 @@ var NotarizationPlugin = class {
3025
3381
  "'Credentials must have an id'"
3026
3382
  ]
3027
3383
  });
3028
- const errors = new Trigger4();
3384
+ const errors = new Trigger5();
3029
3385
  const ctx = this._ctx.derive({
3030
3386
  onError: (err) => {
3031
- log8.warn("Notarization error", {
3387
+ log10.warn("Notarization error", {
3032
3388
  err
3033
3389
  }, {
3034
- F: __dxlog_file10,
3390
+ F: __dxlog_file12,
3035
3391
  L: 99,
3036
3392
  S: this,
3037
3393
  C: (f, a) => f(...a)
@@ -3042,18 +3398,18 @@ var NotarizationPlugin = class {
3042
3398
  });
3043
3399
  opCtx?.onDispose(() => ctx.dispose());
3044
3400
  if (timeout !== 0) {
3045
- scheduleTask3(ctx, () => {
3046
- log8.warn("Notarization timeout", {
3401
+ scheduleTask4(ctx, () => {
3402
+ log10.warn("Notarization timeout", {
3047
3403
  timeout,
3048
3404
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
3049
3405
  }, {
3050
- F: __dxlog_file10,
3406
+ F: __dxlog_file12,
3051
3407
  L: 111,
3052
3408
  S: this,
3053
3409
  C: (f, a) => f(...a)
3054
3410
  });
3055
3411
  void ctx.dispose();
3056
- errors.throw(new TimeoutError2(timeout, "Notarization timed out"));
3412
+ errors.throw(new TimeoutError3(timeout, "Notarization timed out"));
3057
3413
  }, timeout);
3058
3414
  }
3059
3415
  const allNotarized = Promise.all(credentials.map((credential) => this._waitUntilProcessed(credential.id)));
@@ -3067,24 +3423,24 @@ var NotarizationPlugin = class {
3067
3423
  ...this._extensions
3068
3424
  ].find((peer2) => !peersTried.has(peer2));
3069
3425
  if (!peer) {
3070
- log8.info("Exhausted all peers to notarize with", {
3426
+ log10.info("Exhausted all peers to notarize with", {
3071
3427
  retryIn: retryTimeout
3072
3428
  }, {
3073
- F: __dxlog_file10,
3429
+ F: __dxlog_file12,
3074
3430
  L: 136,
3075
3431
  S: this,
3076
3432
  C: (f, a) => f(...a)
3077
3433
  });
3078
3434
  peersTried.clear();
3079
- scheduleTask3(ctx, () => notarizeTask.schedule(), retryTimeout);
3435
+ scheduleTask4(ctx, () => notarizeTask.schedule(), retryTimeout);
3080
3436
  return;
3081
3437
  }
3082
3438
  peersTried.add(peer);
3083
- log8("try notarizing", {
3439
+ log10("try notarizing", {
3084
3440
  peer: peer.localPeerId,
3085
3441
  credentialId: credentials.map((credential) => credential.id)
3086
3442
  }, {
3087
- F: __dxlog_file10,
3443
+ F: __dxlog_file12,
3088
3444
  L: 143,
3089
3445
  S: this,
3090
3446
  C: (f, a) => f(...a)
@@ -3092,8 +3448,8 @@ var NotarizationPlugin = class {
3092
3448
  await peer.rpc.NotarizationService.notarize({
3093
3449
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
3094
3450
  });
3095
- log8("success", void 0, {
3096
- F: __dxlog_file10,
3451
+ log10("success", void 0, {
3452
+ F: __dxlog_file12,
3097
3453
  L: 147,
3098
3454
  S: this,
3099
3455
  C: (f, a) => f(...a)
@@ -3101,8 +3457,8 @@ var NotarizationPlugin = class {
3101
3457
  await sleep(successDelay);
3102
3458
  } catch (err) {
3103
3459
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
3104
- log8.info("error notarizing (recoverable)", err, {
3105
- F: __dxlog_file10,
3460
+ log10.info("error notarizing (recoverable)", err, {
3461
+ F: __dxlog_file12,
3106
3462
  L: 151,
3107
3463
  S: this,
3108
3464
  C: (f, a) => f(...a)
@@ -3119,8 +3475,8 @@ var NotarizationPlugin = class {
3119
3475
  allNotarized,
3120
3476
  errors.wait()
3121
3477
  ]);
3122
- log8("done", void 0, {
3123
- F: __dxlog_file10,
3478
+ log10("done", void 0, {
3479
+ F: __dxlog_file12,
3124
3480
  L: 162,
3125
3481
  S: this,
3126
3482
  C: (f, a) => f(...a)
@@ -3141,8 +3497,8 @@ var NotarizationPlugin = class {
3141
3497
  this._processCredentialsTriggers.delete(credential.id);
3142
3498
  }
3143
3499
  setWriter(writer) {
3144
- invariant9(!this._writer, "Writer already set.", {
3145
- F: __dxlog_file10,
3500
+ invariant11(!this._writer, "Writer already set.", {
3501
+ F: __dxlog_file12,
3146
3502
  L: 181,
3147
3503
  S: this,
3148
3504
  A: [
@@ -3156,7 +3512,7 @@ var NotarizationPlugin = class {
3156
3512
  if (this._processedCredentials.has(id)) {
3157
3513
  return;
3158
3514
  }
3159
- await entry(this._processCredentialsTriggers, id).orInsert(new Trigger4()).value.wait();
3515
+ await entry(this._processCredentialsTriggers, id).orInsert(new Trigger5()).value.wait();
3160
3516
  }
3161
3517
  /**
3162
3518
  * Requests from other peers to notarize credentials.
@@ -3166,8 +3522,8 @@ var NotarizationPlugin = class {
3166
3522
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
3167
3523
  }
3168
3524
  for (const credential of request.credentials ?? []) {
3169
- invariant9(credential.id, "Credential must have an id", {
3170
- F: __dxlog_file10,
3525
+ invariant11(credential.id, "Credential must have an id", {
3526
+ F: __dxlog_file12,
3171
3527
  L: 200,
3172
3528
  S: this,
3173
3529
  A: [
@@ -3184,10 +3540,10 @@ var NotarizationPlugin = class {
3184
3540
  createExtension() {
3185
3541
  const extension = new NotarizationTeleportExtension({
3186
3542
  onOpen: async () => {
3187
- log8("extension opened", {
3543
+ log10("extension opened", {
3188
3544
  peer: extension.localPeerId
3189
3545
  }, {
3190
- F: __dxlog_file10,
3546
+ F: __dxlog_file12,
3191
3547
  L: 211,
3192
3548
  S: this,
3193
3549
  C: (f, a) => f(...a)
@@ -3196,10 +3552,10 @@ var NotarizationPlugin = class {
3196
3552
  this._extensionOpened.emit();
3197
3553
  },
3198
3554
  onClose: async () => {
3199
- log8("extension closed", {
3555
+ log10("extension closed", {
3200
3556
  peer: extension.localPeerId
3201
3557
  }, {
3202
- F: __dxlog_file10,
3558
+ F: __dxlog_file12,
3203
3559
  L: 216,
3204
3560
  S: this,
3205
3561
  C: (f, a) => f(...a)
@@ -3211,14 +3567,14 @@ var NotarizationPlugin = class {
3211
3567
  return extension;
3212
3568
  }
3213
3569
  };
3214
- var NotarizationTeleportExtension = class extends RpcExtension2 {
3570
+ var NotarizationTeleportExtension = class extends RpcExtension3 {
3215
3571
  constructor(_params) {
3216
3572
  super({
3217
3573
  requested: {
3218
- NotarizationService: schema3.getService("dxos.mesh.teleport.notarization.NotarizationService")
3574
+ NotarizationService: schema4.getService("dxos.mesh.teleport.notarization.NotarizationService")
3219
3575
  },
3220
3576
  exposed: {
3221
- NotarizationService: schema3.getService("dxos.mesh.teleport.notarization.NotarizationService")
3577
+ NotarizationService: schema4.getService("dxos.mesh.teleport.notarization.NotarizationService")
3222
3578
  }
3223
3579
  });
3224
3580
  this._params = _params;
@@ -3253,7 +3609,7 @@ function _ts_decorate4(decorators, target, key, desc) {
3253
3609
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3254
3610
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3255
3611
  }
3256
- var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
3612
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
3257
3613
  var DataSpace = class {
3258
3614
  constructor(params) {
3259
3615
  this._ctx = new Context8();
@@ -3279,17 +3635,17 @@ var DataSpace = class {
3279
3635
  this._callbacks = params.callbacks ?? {};
3280
3636
  this._echoHost = params.echoHost;
3281
3637
  this.authVerifier = new TrustedKeySetAuthVerifier({
3282
- trustedKeysProvider: () => new ComplexSet3(PublicKey9.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => !member.removed).map((member) => member.key)),
3638
+ trustedKeysProvider: () => new ComplexSet5(PublicKey10.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => !member.removed).map((member) => member.key)),
3283
3639
  update: this._inner.stateUpdate,
3284
3640
  authTimeout: AUTH_TIMEOUT2
3285
3641
  });
3286
3642
  this._cache = params.cache;
3287
3643
  this._state = params.initialState;
3288
- log9("new state", {
3644
+ log11("new state", {
3289
3645
  state: SpaceState[this._state]
3290
3646
  }, {
3291
- F: __dxlog_file11,
3292
- L: 135,
3647
+ F: __dxlog_file13,
3648
+ L: 136,
3293
3649
  S: this,
3294
3650
  C: (f, a) => f(...a)
3295
3651
  });
@@ -3335,11 +3691,11 @@ var DataSpace = class {
3335
3691
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
3336
3692
  await this._inner.open(new Context8());
3337
3693
  this._state = SpaceState.CONTROL_ONLY;
3338
- log9("new state", {
3694
+ log11("new state", {
3339
3695
  state: SpaceState[this._state]
3340
3696
  }, {
3341
- F: __dxlog_file11,
3342
- L: 193,
3697
+ F: __dxlog_file13,
3698
+ L: 194,
3343
3699
  S: this,
3344
3700
  C: (f, a) => f(...a)
3345
3701
  });
@@ -3353,11 +3709,11 @@ var DataSpace = class {
3353
3709
  async _close() {
3354
3710
  await this._callbacks.beforeClose?.();
3355
3711
  this._state = SpaceState.CLOSED;
3356
- log9("new state", {
3712
+ log11("new state", {
3357
3713
  state: SpaceState[this._state]
3358
3714
  }, {
3359
- F: __dxlog_file11,
3360
- L: 207,
3715
+ F: __dxlog_file13,
3716
+ L: 208,
3361
3717
  S: this,
3362
3718
  C: (f, a) => f(...a)
3363
3719
  });
@@ -3381,32 +3737,32 @@ var DataSpace = class {
3381
3737
  * Initialize the data pipeline in a separate task.
3382
3738
  */
3383
3739
  initializeDataPipelineAsync() {
3384
- scheduleTask4(this._ctx, async () => {
3740
+ scheduleTask5(this._ctx, async () => {
3385
3741
  try {
3386
3742
  this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
3387
3743
  await this.initializeDataPipeline();
3388
3744
  } catch (err) {
3389
- if (err instanceof CancelledError || err instanceof ContextDisposedError) {
3390
- log9("data pipeline initialization cancelled", err, {
3391
- F: __dxlog_file11,
3392
- L: 240,
3745
+ if (err instanceof CancelledError || err instanceof ContextDisposedError3) {
3746
+ log11("data pipeline initialization cancelled", err, {
3747
+ F: __dxlog_file13,
3748
+ L: 241,
3393
3749
  S: this,
3394
3750
  C: (f, a) => f(...a)
3395
3751
  });
3396
3752
  return;
3397
3753
  }
3398
- log9.error("Error initializing data pipeline", err, {
3399
- F: __dxlog_file11,
3400
- L: 244,
3754
+ log11.error("Error initializing data pipeline", err, {
3755
+ F: __dxlog_file13,
3756
+ L: 245,
3401
3757
  S: this,
3402
3758
  C: (f, a) => f(...a)
3403
3759
  });
3404
3760
  this._state = SpaceState.ERROR;
3405
- log9("new state", {
3761
+ log11("new state", {
3406
3762
  state: SpaceState[this._state]
3407
3763
  }, {
3408
- F: __dxlog_file11,
3409
- L: 246,
3764
+ F: __dxlog_file13,
3765
+ L: 247,
3410
3766
  S: this,
3411
3767
  C: (f, a) => f(...a)
3412
3768
  });
@@ -3422,31 +3778,31 @@ var DataSpace = class {
3422
3778
  throw new SystemError("Invalid operation");
3423
3779
  }
3424
3780
  this._state = SpaceState.INITIALIZING;
3425
- log9("new state", {
3781
+ log11("new state", {
3426
3782
  state: SpaceState[this._state]
3427
3783
  }, {
3428
- F: __dxlog_file11,
3429
- L: 262,
3784
+ F: __dxlog_file13,
3785
+ L: 263,
3430
3786
  S: this,
3431
3787
  C: (f, a) => f(...a)
3432
3788
  });
3433
3789
  await this._initializeAndReadControlPipeline();
3434
3790
  await sleep2(1);
3435
3791
  this._automergeSpaceState.startProcessingRootDocs();
3436
- await cancelWithContext2(this._ctx, this.automergeSpaceState.ensureEpochInitialized());
3437
- log9("data pipeline ready", void 0, {
3438
- F: __dxlog_file11,
3439
- L: 274,
3792
+ await cancelWithContext4(this._ctx, this.automergeSpaceState.ensureEpochInitialized());
3793
+ log11("data pipeline ready", void 0, {
3794
+ F: __dxlog_file13,
3795
+ L: 275,
3440
3796
  S: this,
3441
3797
  C: (f, a) => f(...a)
3442
3798
  });
3443
3799
  await this._callbacks.beforeReady?.();
3444
3800
  this._state = SpaceState.READY;
3445
- log9("new state", {
3801
+ log11("new state", {
3446
3802
  state: SpaceState[this._state]
3447
3803
  }, {
3448
- F: __dxlog_file11,
3449
- L: 278,
3804
+ F: __dxlog_file13,
3805
+ L: 279,
3450
3806
  S: this,
3451
3807
  C: (f, a) => f(...a)
3452
3808
  });
@@ -3460,9 +3816,9 @@ var DataSpace = class {
3460
3816
  });
3461
3817
  this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
3462
3818
  await this._createWritableFeeds();
3463
- log9("writable feeds created", void 0, {
3464
- F: __dxlog_file11,
3465
- L: 294,
3819
+ log11("writable feeds created", void 0, {
3820
+ F: __dxlog_file13,
3821
+ L: 295,
3466
3822
  S: this,
3467
3823
  C: (f, a) => f(...a)
3468
3824
  });
@@ -3520,12 +3876,12 @@ var DataSpace = class {
3520
3876
  }
3521
3877
  }
3522
3878
  _onNewAutomergeRoot(rootUrl) {
3523
- log9("loading automerge root doc for space", {
3879
+ log11("loading automerge root doc for space", {
3524
3880
  space: this.key,
3525
3881
  rootUrl
3526
3882
  }, {
3527
- F: __dxlog_file11,
3528
- L: 360,
3883
+ F: __dxlog_file13,
3884
+ L: 361,
3529
3885
  S: this,
3530
3886
  C: (f, a) => f(...a)
3531
3887
  });
@@ -3534,7 +3890,7 @@ var DataSpace = class {
3534
3890
  queueMicrotask(async () => {
3535
3891
  try {
3536
3892
  await warnAfterTimeout(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
3537
- await cancelWithContext2(this._ctx, handle.whenReady());
3893
+ await cancelWithContext4(this._ctx, handle.whenReady());
3538
3894
  });
3539
3895
  if (this._ctx.disposed) {
3540
3896
  return;
@@ -3548,16 +3904,16 @@ var DataSpace = class {
3548
3904
  });
3549
3905
  }
3550
3906
  } catch (err) {
3551
- if (err instanceof ContextDisposedError) {
3907
+ if (err instanceof ContextDisposedError3) {
3552
3908
  return;
3553
3909
  }
3554
- log9.warn("error loading automerge root doc", {
3910
+ log11.warn("error loading automerge root doc", {
3555
3911
  space: this.key,
3556
3912
  rootUrl,
3557
3913
  err
3558
3914
  }, {
3559
- F: __dxlog_file11,
3560
- L: 383,
3915
+ F: __dxlog_file13,
3916
+ L: 384,
3561
3917
  S: this,
3562
3918
  C: (f, a) => f(...a)
3563
3919
  });
@@ -3608,11 +3964,11 @@ var DataSpace = class {
3608
3964
  {
3609
3965
  const currentRootUrl = this._automergeSpaceState.rootUrl;
3610
3966
  const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
3611
- await cancelWithContext2(this._ctx, asyncTimeout(rootHandle.whenReady(), 1e4));
3967
+ await cancelWithContext4(this._ctx, asyncTimeout(rootHandle.whenReady(), 1e4));
3612
3968
  const newRoot = this._echoHost.automergeRepo.create(rootHandle.docSync());
3613
- invariant10(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3614
- F: __dxlog_file11,
3615
- L: 433,
3969
+ invariant12(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3970
+ F: __dxlog_file13,
3971
+ L: 434,
3616
3972
  S: this,
3617
3973
  A: [
3618
3974
  "typeof newRoot.url === 'string' && newRoot.url.length > 0",
@@ -3629,21 +3985,21 @@ var DataSpace = class {
3629
3985
  break;
3630
3986
  case CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT:
3631
3987
  {
3632
- log9.info("Fragmenting", void 0, {
3633
- F: __dxlog_file11,
3634
- L: 445,
3988
+ log11.info("Fragmenting", void 0, {
3989
+ F: __dxlog_file13,
3990
+ L: 446,
3635
3991
  S: this,
3636
3992
  C: (f, a) => f(...a)
3637
3993
  });
3638
3994
  const currentRootUrl = this._automergeSpaceState.rootUrl;
3639
3995
  const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
3640
- await cancelWithContext2(this._ctx, asyncTimeout(rootHandle.whenReady(), 1e4));
3996
+ await cancelWithContext4(this._ctx, asyncTimeout(rootHandle.whenReady(), 1e4));
3641
3997
  const objects = Object.entries(rootHandle.docSync().objects);
3642
3998
  const properties = objects.find(([_, value]) => value.system.type?.itemId === TYPE_PROPERTIES);
3643
3999
  const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
3644
- invariant10(properties, "Properties not found", {
3645
- F: __dxlog_file11,
3646
- L: 455,
4000
+ invariant12(properties, "Properties not found", {
4001
+ F: __dxlog_file13,
4002
+ L: 456,
3647
4003
  S: this,
3648
4004
  A: [
3649
4005
  "properties",
@@ -3657,9 +4013,9 @@ var DataSpace = class {
3657
4013
  ])
3658
4014
  };
3659
4015
  const newRoot = this._echoHost.automergeRepo.create(newSpaceDoc);
3660
- invariant10(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3661
- F: __dxlog_file11,
3662
- L: 460,
4016
+ invariant12(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
4017
+ F: __dxlog_file13,
4018
+ L: 461,
3663
4019
  S: this,
3664
4020
  A: [
3665
4021
  "typeof newRoot.url === 'string' && newRoot.url.length > 0",
@@ -3724,11 +4080,11 @@ var DataSpace = class {
3724
4080
  await this._metadataStore.setSpaceState(this.key, SpaceState.INACTIVE);
3725
4081
  await this._close();
3726
4082
  this._state = SpaceState.INACTIVE;
3727
- log9("new state", {
4083
+ log11("new state", {
3728
4084
  state: SpaceState[this._state]
3729
4085
  }, {
3730
- F: __dxlog_file11,
3731
- L: 526,
4086
+ F: __dxlog_file13,
4087
+ L: 527,
3732
4088
  S: this,
3733
4089
  C: (f, a) => f(...a)
3734
4090
  });
@@ -3783,13 +4139,13 @@ DataSpace = _ts_decorate4([
3783
4139
 
3784
4140
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
3785
4141
  import { Event as Event7, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
3786
- import { Context as Context9, cancelWithContext as cancelWithContext3 } from "@dxos/context";
4142
+ import { Context as Context9, cancelWithContext as cancelWithContext5 } from "@dxos/context";
3787
4143
  import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
3788
- import { invariant as invariant11 } from "@dxos/invariant";
3789
- import { PublicKey as PublicKey10 } from "@dxos/keys";
3790
- import { log as log10 } from "@dxos/log";
4144
+ import { invariant as invariant13 } from "@dxos/invariant";
4145
+ import { PublicKey as PublicKey11 } from "@dxos/keys";
4146
+ import { log as log12 } from "@dxos/log";
3791
4147
  import { trace as trace7 } from "@dxos/protocols";
3792
- import { Invitation as Invitation6, SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
4148
+ import { Invitation as Invitation7, SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
3793
4149
  import { Gossip as Gossip2, Presence as Presence2 } from "@dxos/teleport-extension-gossip";
3794
4150
  import { ComplexMap as ComplexMap3, deferFunction as deferFunction2, forEachAsync } from "@dxos/util";
3795
4151
 
@@ -3874,7 +4230,7 @@ function _ts_decorate5(decorators, target, key, desc) {
3874
4230
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3875
4231
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3876
4232
  }
3877
- var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
4233
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
3878
4234
  var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
3879
4235
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
3880
4236
  var DataSpaceManager = class {
@@ -3888,9 +4244,9 @@ var DataSpaceManager = class {
3888
4244
  this._invitationsManager = _invitationsManager;
3889
4245
  this._ctx = new Context9();
3890
4246
  this.updated = new Event7();
3891
- this._spaces = new ComplexMap3(PublicKey10.hash);
4247
+ this._spaces = new ComplexMap3(PublicKey11.hash);
3892
4248
  this._isOpen = false;
3893
- this._instanceId = PublicKey10.random().toHex();
4249
+ this._instanceId = PublicKey11.random().toHex();
3894
4250
  const { spaceMemberPresenceAnnounceInterval = PRESENCE_ANNOUNCE_INTERVAL, spaceMemberPresenceOfflineTimeout = PRESENCE_OFFLINE_TIMEOUT } = params ?? {};
3895
4251
  this._spaceMemberPresenceAnnounceInterval = spaceMemberPresenceAnnounceInterval;
3896
4252
  this._spaceMemberPresenceOfflineTimeout = spaceMemberPresenceOfflineTimeout;
@@ -3900,45 +4256,45 @@ var DataSpaceManager = class {
3900
4256
  return this._spaces;
3901
4257
  }
3902
4258
  async open() {
3903
- log10("open", void 0, {
3904
- F: __dxlog_file12,
4259
+ log12("open", void 0, {
4260
+ F: __dxlog_file14,
3905
4261
  L: 102,
3906
4262
  S: this,
3907
4263
  C: (f, a) => f(...a)
3908
4264
  });
3909
- log10.trace("dxos.echo.data-space-manager.open", trace7.begin({
4265
+ log12.trace("dxos.echo.data-space-manager.open", trace7.begin({
3910
4266
  id: this._instanceId
3911
4267
  }), {
3912
- F: __dxlog_file12,
4268
+ F: __dxlog_file14,
3913
4269
  L: 103,
3914
4270
  S: this,
3915
4271
  C: (f, a) => f(...a)
3916
4272
  });
3917
- log10("metadata loaded", {
4273
+ log12("metadata loaded", {
3918
4274
  spaces: this._metadataStore.spaces.length
3919
4275
  }, {
3920
- F: __dxlog_file12,
4276
+ F: __dxlog_file14,
3921
4277
  L: 104,
3922
4278
  S: this,
3923
4279
  C: (f, a) => f(...a)
3924
4280
  });
3925
4281
  await forEachAsync(this._metadataStore.spaces, async (spaceMetadata) => {
3926
4282
  try {
3927
- log10("load space", {
4283
+ log12("load space", {
3928
4284
  spaceMetadata
3929
4285
  }, {
3930
- F: __dxlog_file12,
4286
+ F: __dxlog_file14,
3931
4287
  L: 108,
3932
4288
  S: this,
3933
4289
  C: (f, a) => f(...a)
3934
4290
  });
3935
4291
  await this._constructSpace(spaceMetadata);
3936
4292
  } catch (err) {
3937
- log10.error("Error loading space", {
4293
+ log12.error("Error loading space", {
3938
4294
  spaceMetadata,
3939
4295
  err
3940
4296
  }, {
3941
- F: __dxlog_file12,
4297
+ F: __dxlog_file14,
3942
4298
  L: 111,
3943
4299
  S: this,
3944
4300
  C: (f, a) => f(...a)
@@ -3952,18 +4308,18 @@ var DataSpaceManager = class {
3952
4308
  space.initializeDataPipelineAsync();
3953
4309
  }
3954
4310
  }
3955
- log10.trace("dxos.echo.data-space-manager.open", trace7.end({
4311
+ log12.trace("dxos.echo.data-space-manager.open", trace7.end({
3956
4312
  id: this._instanceId
3957
4313
  }), {
3958
- F: __dxlog_file12,
4314
+ F: __dxlog_file14,
3959
4315
  L: 124,
3960
4316
  S: this,
3961
4317
  C: (f, a) => f(...a)
3962
4318
  });
3963
4319
  }
3964
4320
  async close() {
3965
- log10("close", void 0, {
3966
- F: __dxlog_file12,
4321
+ log12("close", void 0, {
4322
+ F: __dxlog_file14,
3967
4323
  L: 129,
3968
4324
  S: this,
3969
4325
  C: (f, a) => f(...a)
@@ -3978,8 +4334,8 @@ var DataSpaceManager = class {
3978
4334
  * Creates a new space writing the genesis credentials to the control feed.
3979
4335
  */
3980
4336
  async createSpace() {
3981
- invariant11(this._isOpen, "Not open.", {
3982
- F: __dxlog_file12,
4337
+ invariant13(this._isOpen, "Not open.", {
4338
+ F: __dxlog_file14,
3983
4339
  L: 142,
3984
4340
  S: this,
3985
4341
  A: [
@@ -3997,10 +4353,10 @@ var DataSpaceManager = class {
3997
4353
  dataFeedKey,
3998
4354
  state: SpaceState2.ACTIVE
3999
4355
  };
4000
- log10("creating space...", {
4356
+ log12("creating space...", {
4001
4357
  spaceKey
4002
4358
  }, {
4003
- F: __dxlog_file12,
4359
+ F: __dxlog_file14,
4004
4360
  L: 154,
4005
4361
  S: this,
4006
4362
  C: (f, a) => f(...a)
@@ -4010,8 +4366,8 @@ var DataSpaceManager = class {
4010
4366
  const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRootUrl);
4011
4367
  await this._metadataStore.addSpace(metadata);
4012
4368
  const memberCredential = credentials[1];
4013
- invariant11(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4014
- F: __dxlog_file12,
4369
+ invariant13(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4370
+ F: __dxlog_file14,
4015
4371
  L: 163,
4016
4372
  S: this,
4017
4373
  A: [
@@ -4026,16 +4382,16 @@ var DataSpaceManager = class {
4026
4382
  }
4027
4383
  // TODO(burdon): Rename join space.
4028
4384
  async acceptSpace(opts) {
4029
- log10("accept space", {
4385
+ log12("accept space", {
4030
4386
  opts
4031
4387
  }, {
4032
- F: __dxlog_file12,
4388
+ F: __dxlog_file14,
4033
4389
  L: 175,
4034
4390
  S: this,
4035
4391
  C: (f, a) => f(...a)
4036
4392
  });
4037
- invariant11(this._isOpen, "Not open.", {
4038
- F: __dxlog_file12,
4393
+ invariant13(this._isOpen, "Not open.", {
4394
+ F: __dxlog_file14,
4039
4395
  L: 176,
4040
4396
  S: this,
4041
4397
  A: [
@@ -4043,8 +4399,8 @@ var DataSpaceManager = class {
4043
4399
  "'Not open.'"
4044
4400
  ]
4045
4401
  });
4046
- invariant11(!this._spaces.has(opts.spaceKey), "Space already exists.", {
4047
- F: __dxlog_file12,
4402
+ invariant13(!this._spaces.has(opts.spaceKey), "Space already exists.", {
4403
+ F: __dxlog_file14,
4048
4404
  L: 177,
4049
4405
  S: this,
4050
4406
  A: [
@@ -4070,16 +4426,16 @@ var DataSpaceManager = class {
4070
4426
  * TODO(dmaretskyi): Consider removing.
4071
4427
  */
4072
4428
  async waitUntilSpaceReady(spaceKey) {
4073
- await cancelWithContext3(this._ctx, this.updated.waitForCondition(() => {
4429
+ await cancelWithContext5(this._ctx, this.updated.waitForCondition(() => {
4074
4430
  const space = this._spaces.get(spaceKey);
4075
4431
  return !!space && space.state === SpaceState2.READY;
4076
4432
  }));
4077
4433
  }
4078
4434
  async _constructSpace(metadata) {
4079
- log10("construct space", {
4435
+ log12("construct space", {
4080
4436
  metadata
4081
4437
  }, {
4082
- F: __dxlog_file12,
4438
+ F: __dxlog_file14,
4083
4439
  L: 210,
4084
4440
  S: this,
4085
4441
  C: (f, a) => f(...a)
@@ -4116,8 +4472,8 @@ var DataSpaceManager = class {
4116
4472
  session.addExtension("dxos.mesh.teleport.automerge", this._echoHost.createReplicationExtension());
4117
4473
  },
4118
4474
  onAuthFailure: () => {
4119
- log10.warn("auth failure", void 0, {
4120
- F: __dxlog_file12,
4475
+ log12.warn("auth failure", void 0, {
4476
+ F: __dxlog_file14,
4121
4477
  L: 247,
4122
4478
  S: this,
4123
4479
  C: (f, a) => f(...a)
@@ -4142,21 +4498,21 @@ var DataSpaceManager = class {
4142
4498
  signingContext: this._signingContext,
4143
4499
  callbacks: {
4144
4500
  beforeReady: async () => {
4145
- log10("before space ready", {
4501
+ log12("before space ready", {
4146
4502
  space: space.key
4147
4503
  }, {
4148
- F: __dxlog_file12,
4504
+ F: __dxlog_file14,
4149
4505
  L: 269,
4150
4506
  S: this,
4151
4507
  C: (f, a) => f(...a)
4152
4508
  });
4153
4509
  },
4154
4510
  afterReady: async () => {
4155
- log10("after space ready", {
4511
+ log12("after space ready", {
4156
4512
  space: space.key,
4157
4513
  open: this._isOpen
4158
4514
  }, {
4159
- F: __dxlog_file12,
4515
+ F: __dxlog_file14,
4160
4516
  L: 272,
4161
4517
  S: this,
4162
4518
  C: (f, a) => f(...a)
@@ -4169,10 +4525,10 @@ var DataSpaceManager = class {
4169
4525
  }
4170
4526
  },
4171
4527
  beforeClose: async () => {
4172
- log10("before space close", {
4528
+ log12("before space close", {
4173
4529
  space: space.key
4174
4530
  }, {
4175
- F: __dxlog_file12,
4531
+ F: __dxlog_file14,
4176
4532
  L: 279,
4177
4533
  S: this,
4178
4534
  C: (f, a) => f(...a)
@@ -4208,8 +4564,8 @@ var DataSpaceManager = class {
4208
4564
  async _createDelegatedInvitations(space, invitations) {
4209
4565
  const tasks = invitations.map(([credentialId, invitation]) => {
4210
4566
  return this._invitationsManager.createInvitation({
4211
- type: Invitation6.Type.DELEGATED,
4212
- kind: Invitation6.Kind.SPACE,
4567
+ type: Invitation7.Type.DELEGATED,
4568
+ kind: Invitation7.Kind.SPACE,
4213
4569
  spaceKey: space.key,
4214
4570
  authMethod: invitation.authMethod,
4215
4571
  invitationId: invitation.invitationId,
@@ -4243,14 +4599,14 @@ DataSpaceManager = _ts_decorate5([
4243
4599
  ], DataSpaceManager);
4244
4600
 
4245
4601
  // packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
4246
- import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTask as scheduleTask5 } from "@dxos/async";
4602
+ import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTask as scheduleTask6 } from "@dxos/async";
4247
4603
  import { Stream as Stream10 } from "@dxos/codec-protobuf";
4248
4604
  import { raise as raise2 } from "@dxos/debug";
4249
- import { invariant as invariant12 } from "@dxos/invariant";
4250
- import { log as log11 } from "@dxos/log";
4605
+ import { invariant as invariant14 } from "@dxos/invariant";
4606
+ import { log as log13 } from "@dxos/log";
4251
4607
  import { ApiError, SpaceNotFoundError, encodeError } from "@dxos/protocols";
4252
4608
  import { SpaceMember as SpaceMember3, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
4253
- var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
4609
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
4254
4610
  var SpacesServiceImpl = class {
4255
4611
  constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
4256
4612
  this._identityManager = _identityManager;
@@ -4286,10 +4642,10 @@ var SpacesServiceImpl = class {
4286
4642
  const scheduler = new UpdateScheduler(ctx, async () => {
4287
4643
  const dataSpaceManager = await this._getDataSpaceManager();
4288
4644
  const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
4289
- log11("update", {
4645
+ log13("update", {
4290
4646
  spaces
4291
4647
  }, {
4292
- F: __dxlog_file13,
4648
+ F: __dxlog_file15,
4293
4649
  L: 77,
4294
4650
  S: this,
4295
4651
  C: (f, a) => f(...a)
@@ -4300,7 +4656,7 @@ var SpacesServiceImpl = class {
4300
4656
  }, {
4301
4657
  maxFrequency: false ? void 0 : 2
4302
4658
  });
4303
- scheduleTask5(ctx, async () => {
4659
+ scheduleTask6(ctx, async () => {
4304
4660
  const dataSpaceManager = await this._getDataSpaceManager();
4305
4661
  const subscriptions = new EventSubscriptions2();
4306
4662
  ctx.onDispose(() => subscriptions.clear());
@@ -4334,7 +4690,7 @@ var SpacesServiceImpl = class {
4334
4690
  }
4335
4691
  subscribeMessages({ spaceKey, channel }) {
4336
4692
  return new Stream10(({ ctx, next }) => {
4337
- scheduleTask5(ctx, async () => {
4693
+ scheduleTask6(ctx, async () => {
4338
4694
  const dataSpaceManager = await this._getDataSpaceManager();
4339
4695
  const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
4340
4696
  const handle = space.listen(getChannelId(channel), (message) => {
@@ -4353,7 +4709,7 @@ var SpacesServiceImpl = class {
4353
4709
  }
4354
4710
  };
4355
4711
  ctx.onDispose(() => space.spaceState.removeCredentialProcessor(processor));
4356
- scheduleTask5(ctx, async () => {
4712
+ scheduleTask6(ctx, async () => {
4357
4713
  await space.spaceState.addCredentialProcessor(processor);
4358
4714
  if (noTail) {
4359
4715
  close();
@@ -4371,8 +4727,8 @@ var SpacesServiceImpl = class {
4371
4727
  }
4372
4728
  });
4373
4729
  } else {
4374
- invariant12(!credential.id, "Id on unsigned credentials is not allowed", {
4375
- F: __dxlog_file13,
4730
+ invariant14(!credential.id, "Id on unsigned credentials is not allowed", {
4731
+ F: __dxlog_file15,
4376
4732
  L: 164,
4377
4733
  S: this,
4378
4734
  A: [
@@ -4380,8 +4736,8 @@ var SpacesServiceImpl = class {
4380
4736
  "'Id on unsigned credentials is not allowed'"
4381
4737
  ]
4382
4738
  });
4383
- invariant12(this._identityManager.identity, "Identity is not available", {
4384
- F: __dxlog_file13,
4739
+ invariant14(this._identityManager.identity, "Identity is not available", {
4740
+ F: __dxlog_file15,
4385
4741
  L: 165,
4386
4742
  S: this,
4387
4743
  A: [
@@ -4390,8 +4746,8 @@ var SpacesServiceImpl = class {
4390
4746
  ]
4391
4747
  });
4392
4748
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
4393
- invariant12(credential.issuer.equals(signer.getIssuer()), void 0, {
4394
- F: __dxlog_file13,
4749
+ invariant14(credential.issuer.equals(signer.getIssuer()), void 0, {
4750
+ F: __dxlog_file15,
4395
4751
  L: 167,
4396
4752
  S: this,
4397
4753
  A: [
@@ -4460,19 +4816,19 @@ var SpacesServiceImpl = class {
4460
4816
  var getChannelId = (channel) => `user-channel/${channel}`;
4461
4817
 
4462
4818
  // packages/sdk/client-services/src/packlets/services/service-context.ts
4463
- import { Trigger as Trigger5 } from "@dxos/async";
4819
+ import { Trigger as Trigger6 } from "@dxos/async";
4464
4820
  import { Context as Context10, Resource } from "@dxos/context";
4465
4821
  import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
4466
4822
  import { failUndefined as failUndefined2 } from "@dxos/debug";
4467
4823
  import { EchoHost } from "@dxos/echo-db";
4468
4824
  import { MetadataStore, SnapshotStore, SpaceManager, valueEncoding } from "@dxos/echo-pipeline";
4469
4825
  import { FeedFactory, FeedStore } from "@dxos/feed-store";
4470
- import { invariant as invariant13 } from "@dxos/invariant";
4826
+ import { invariant as invariant15 } from "@dxos/invariant";
4471
4827
  import { Keyring } from "@dxos/keyring";
4472
- import { PublicKey as PublicKey11 } from "@dxos/keys";
4473
- import { log as log12 } from "@dxos/log";
4828
+ import { PublicKey as PublicKey12 } from "@dxos/keys";
4829
+ import { log as log14 } from "@dxos/log";
4474
4830
  import { InvalidStorageVersionError, STORAGE_VERSION, trace as trace8 } from "@dxos/protocols";
4475
- import { Invitation as Invitation7 } from "@dxos/protocols/proto/dxos/client/services";
4831
+ import { Invitation as Invitation8 } from "@dxos/protocols/proto/dxos/client/services";
4476
4832
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
4477
4833
  import { trace as Trace2 } from "@dxos/tracing";
4478
4834
  import { safeInstanceof } from "@dxos/util";
@@ -4486,7 +4842,7 @@ function _ts_decorate6(decorators, target, key, desc) {
4486
4842
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4487
4843
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4488
4844
  }
4489
- var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
4845
+ var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
4490
4846
  var ServiceContext = class extends Resource {
4491
4847
  constructor(storage, level, networkManager, signalManager, _runtimeParams) {
4492
4848
  super();
@@ -4495,9 +4851,9 @@ var ServiceContext = class extends Resource {
4495
4851
  this.networkManager = networkManager;
4496
4852
  this.signalManager = signalManager;
4497
4853
  this._runtimeParams = _runtimeParams;
4498
- this.initialized = new Trigger5();
4854
+ this.initialized = new Trigger6();
4499
4855
  this._handlerFactories = /* @__PURE__ */ new Map();
4500
- this._instanceId = PublicKey11.random().toHex();
4856
+ this._instanceId = PublicKey12.random().toHex();
4501
4857
  this.metadataStore = new MetadataStore(storage.createDirectory("metadata"));
4502
4858
  this.snapshotStore = new SnapshotStore(storage.createDirectory("snapshots"));
4503
4859
  this.blobStore = new BlobStore(storage.createDirectory("blobs"));
@@ -4524,23 +4880,23 @@ var ServiceContext = class extends Resource {
4524
4880
  kv: this.level,
4525
4881
  storage: this.storage
4526
4882
  });
4527
- this.invitations = new InvitationsHandler(this.networkManager);
4883
+ this.invitations = new InvitationsHandler(this.networkManager, _runtimeParams?.invitationConnectionDefaultParams);
4528
4884
  this.invitationsManager = new InvitationsManager(this.invitations, (invitation) => this.getInvitationHandler(invitation), this.metadataStore);
4529
- this._handlerFactories.set(Invitation7.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined2(), this._acceptIdentity.bind(this)));
4885
+ this._handlerFactories.set(Invitation8.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined2(), this._acceptIdentity.bind(this)));
4530
4886
  }
4531
4887
  async _open(ctx) {
4532
4888
  await this._checkStorageVersion();
4533
- log12("opening...", void 0, {
4534
- F: __dxlog_file14,
4535
- L: 151,
4889
+ log14("opening...", void 0, {
4890
+ F: __dxlog_file16,
4891
+ L: 152,
4536
4892
  S: this,
4537
4893
  C: (f, a) => f(...a)
4538
4894
  });
4539
- log12.trace("dxos.sdk.service-context.open", trace8.begin({
4895
+ log14.trace("dxos.sdk.service-context.open", trace8.begin({
4540
4896
  id: this._instanceId
4541
4897
  }), {
4542
- F: __dxlog_file14,
4543
- L: 152,
4898
+ F: __dxlog_file16,
4899
+ L: 153,
4544
4900
  S: this,
4545
4901
  C: (f, a) => f(...a)
4546
4902
  });
@@ -4554,33 +4910,33 @@ var ServiceContext = class extends Resource {
4554
4910
  await this._initialize(ctx);
4555
4911
  }
4556
4912
  const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
4557
- log12("loaded persistent invitations", {
4913
+ log14("loaded persistent invitations", {
4558
4914
  count: loadedInvitations.invitations?.length
4559
4915
  }, {
4560
- F: __dxlog_file14,
4561
- L: 165,
4916
+ F: __dxlog_file16,
4917
+ L: 166,
4562
4918
  S: this,
4563
4919
  C: (f, a) => f(...a)
4564
4920
  });
4565
- log12.trace("dxos.sdk.service-context.open", trace8.end({
4921
+ log14.trace("dxos.sdk.service-context.open", trace8.end({
4566
4922
  id: this._instanceId
4567
4923
  }), {
4568
- F: __dxlog_file14,
4569
- L: 167,
4924
+ F: __dxlog_file16,
4925
+ L: 168,
4570
4926
  S: this,
4571
4927
  C: (f, a) => f(...a)
4572
4928
  });
4573
- log12("opened", void 0, {
4574
- F: __dxlog_file14,
4575
- L: 168,
4929
+ log14("opened", void 0, {
4930
+ F: __dxlog_file16,
4931
+ L: 169,
4576
4932
  S: this,
4577
4933
  C: (f, a) => f(...a)
4578
4934
  });
4579
4935
  }
4580
4936
  async _close(ctx) {
4581
- log12("closing...", void 0, {
4582
- F: __dxlog_file14,
4583
- L: 172,
4937
+ log14("closing...", void 0, {
4938
+ F: __dxlog_file16,
4939
+ L: 173,
4584
4940
  S: this,
4585
4941
  C: (f, a) => f(...a)
4586
4942
  });
@@ -4595,9 +4951,9 @@ var ServiceContext = class extends Resource {
4595
4951
  await this.echoHost.close(ctx);
4596
4952
  await this.networkManager.close();
4597
4953
  await this.signalManager.close();
4598
- log12("closed", void 0, {
4599
- F: __dxlog_file14,
4600
- L: 184,
4954
+ log14("closed", void 0, {
4955
+ F: __dxlog_file16,
4956
+ L: 185,
4601
4957
  S: this,
4602
4958
  C: (f, a) => f(...a)
4603
4959
  });
@@ -4609,9 +4965,9 @@ var ServiceContext = class extends Resource {
4609
4965
  }
4610
4966
  getInvitationHandler(invitation) {
4611
4967
  const factory = this._handlerFactories.get(invitation.kind);
4612
- invariant13(factory, `Unknown invitation kind: ${invitation.kind}`, {
4613
- F: __dxlog_file14,
4614
- L: 195,
4968
+ invariant15(factory, `Unknown invitation kind: ${invitation.kind}`, {
4969
+ F: __dxlog_file16,
4970
+ L: 196,
4615
4971
  S: this,
4616
4972
  A: [
4617
4973
  "factory",
@@ -4641,9 +4997,9 @@ var ServiceContext = class extends Resource {
4641
4997
  }
4642
4998
  // Called when identity is created.
4643
4999
  async _initialize(ctx) {
4644
- log12("initializing spaces...", void 0, {
4645
- F: __dxlog_file14,
4646
- L: 226,
5000
+ log14("initializing spaces...", void 0, {
5001
+ F: __dxlog_file16,
5002
+ L: 227,
4647
5003
  S: this,
4648
5004
  C: (f, a) => f(...a)
4649
5005
  });
@@ -4663,10 +5019,10 @@ var ServiceContext = class extends Resource {
4663
5019
  };
4664
5020
  this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.echoHost, this.invitationsManager, this._runtimeParams);
4665
5021
  await this.dataSpaceManager.open();
4666
- this._handlerFactories.set(Invitation7.Kind.SPACE, (invitation) => {
4667
- invariant13(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4668
- F: __dxlog_file14,
4669
- L: 251,
5022
+ this._handlerFactories.set(Invitation8.Kind.SPACE, (invitation) => {
5023
+ invariant15(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
5024
+ F: __dxlog_file16,
5025
+ L: 252,
4670
5026
  S: this,
4671
5027
  A: [
4672
5028
  "this.dataSpaceManager",
@@ -4686,33 +5042,33 @@ var ServiceContext = class extends Resource {
4686
5042
  return;
4687
5043
  }
4688
5044
  if (!this.dataSpaceManager) {
4689
- log12("dataSpaceManager not initialized yet, ignoring space admission", {
5045
+ log14("dataSpaceManager not initialized yet, ignoring space admission", {
4690
5046
  details: assertion
4691
5047
  }, {
4692
- F: __dxlog_file14,
4693
- L: 267,
5048
+ F: __dxlog_file16,
5049
+ L: 268,
4694
5050
  S: this,
4695
5051
  C: (f, a) => f(...a)
4696
5052
  });
4697
5053
  return;
4698
5054
  }
4699
5055
  if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
4700
- log12("space already exists, ignoring space admission", {
5056
+ log14("space already exists, ignoring space admission", {
4701
5057
  details: assertion
4702
5058
  }, {
4703
- F: __dxlog_file14,
4704
- L: 271,
5059
+ F: __dxlog_file16,
5060
+ L: 272,
4705
5061
  S: this,
4706
5062
  C: (f, a) => f(...a)
4707
5063
  });
4708
5064
  return;
4709
5065
  }
4710
5066
  try {
4711
- log12("accepting space recorded in halo", {
5067
+ log14("accepting space recorded in halo", {
4712
5068
  details: assertion
4713
5069
  }, {
4714
- F: __dxlog_file14,
4715
- L: 276,
5070
+ F: __dxlog_file16,
5071
+ L: 277,
4716
5072
  S: this,
4717
5073
  C: (f, a) => f(...a)
4718
5074
  });
@@ -4721,9 +5077,9 @@ var ServiceContext = class extends Resource {
4721
5077
  genesisFeedKey: assertion.genesisFeedKey
4722
5078
  });
4723
5079
  } catch (err) {
4724
- log12.catch(err, void 0, {
4725
- F: __dxlog_file14,
4726
- L: 282,
5080
+ log14.catch(err, void 0, {
5081
+ F: __dxlog_file16,
5082
+ L: 283,
4727
5083
  S: this,
4728
5084
  C: (f, a) => f(...a)
4729
5085
  });
@@ -4771,13 +5127,13 @@ var ServiceRegistry = class {
4771
5127
  // packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts
4772
5128
  import { getFirstStreamValue } from "@dxos/codec-protobuf";
4773
5129
  import { credentialTypeFilter } from "@dxos/credentials";
4774
- import { invariant as invariant14 } from "@dxos/invariant";
5130
+ import { invariant as invariant16 } from "@dxos/invariant";
4775
5131
  import { STORAGE_VERSION as STORAGE_VERSION2 } from "@dxos/protocols";
4776
5132
  import { SpaceMember as SpaceMember4 } from "@dxos/protocols/proto/dxos/client/services";
4777
5133
  import { TRACE_PROCESSOR } from "@dxos/tracing";
4778
5134
 
4779
5135
  // packages/sdk/client-services/src/version.ts
4780
- var DXOS_VERSION = "0.5.1-main.c37e119";
5136
+ var DXOS_VERSION = "0.5.1-main.d27379b";
4781
5137
 
4782
5138
  // packages/sdk/client-services/src/packlets/services/platform.ts
4783
5139
  import { Platform } from "@dxos/protocols/proto/dxos/client/services";
@@ -4810,7 +5166,7 @@ var getPlatform = () => {
4810
5166
  };
4811
5167
 
4812
5168
  // packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts
4813
- var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts";
5169
+ var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts";
4814
5170
  var DEFAULT_TIMEOUT = 1e3;
4815
5171
  var createDiagnostics = async (clientServices, serviceContext, config) => {
4816
5172
  const diagnostics = {
@@ -4825,8 +5181,8 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
4825
5181
  trace: TRACE_PROCESSOR.getDiagnostics()
4826
5182
  };
4827
5183
  {
4828
- invariant14(clientServices.LoggingService, "SystemService is not available.", {
4829
- F: __dxlog_file15,
5184
+ invariant16(clientServices.LoggingService, "SystemService is not available.", {
5185
+ F: __dxlog_file17,
4830
5186
  L: 108,
4831
5187
  S: void 0,
4832
5188
  A: [
@@ -4919,9 +5275,9 @@ var getSpaceStats = async (space) => {
4919
5275
  };
4920
5276
 
4921
5277
  // packages/sdk/client-services/src/packlets/diagnostics/browser-diagnostics-broadcast.ts
4922
- import { Trigger as Trigger6 } from "@dxos/async";
4923
- import { log as log13 } from "@dxos/log";
4924
- var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/browser-diagnostics-broadcast.ts";
5278
+ import { Trigger as Trigger7 } from "@dxos/async";
5279
+ import { log as log15 } from "@dxos/log";
5280
+ var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/browser-diagnostics-broadcast.ts";
4925
5281
  var CHANNEL_NAME = "dxos.diagnostics.broadcast";
4926
5282
  var MessageType;
4927
5283
  (function(MessageType2) {
@@ -4936,7 +5292,7 @@ var createCollectDiagnosticsBroadcastSender = () => {
4936
5292
  let expectedResponse = "probe-ack";
4937
5293
  let channel;
4938
5294
  try {
4939
- const trigger = new Trigger6();
5295
+ const trigger = new Trigger7();
4940
5296
  channel = new BroadcastChannel(CHANNEL_NAME);
4941
5297
  channel.onmessage = (msg) => {
4942
5298
  if (expectedResponse === msg.data.type) {
@@ -4989,8 +5345,8 @@ var createCollectDiagnosticsBroadcastHandler = (systemService) => {
4989
5345
  });
4990
5346
  }
4991
5347
  } catch (error) {
4992
- log13.catch(error, void 0, {
4993
- F: __dxlog_file16,
5348
+ log15.catch(error, void 0, {
5349
+ F: __dxlog_file18,
4994
5350
  L: 77,
4995
5351
  S: void 0,
4996
5352
  C: (f, a) => f(...a)
@@ -5021,11 +5377,11 @@ import { jsonKeyReplacer as jsonKeyReplacer2, nonNullable } from "@dxos/util";
5021
5377
  import { Event as Event9, synchronized as synchronized3 } from "@dxos/async";
5022
5378
  import { clientServiceBundle, defaultKey, Properties } from "@dxos/client-protocol";
5023
5379
  import { Context as Context11 } from "@dxos/context";
5024
- import { encodeReference } from "@dxos/echo-pipeline";
5380
+ import { encodeReference } from "@dxos/echo-protocol";
5025
5381
  import { getTypeReference } from "@dxos/echo-schema";
5026
- import { invariant as invariant16 } from "@dxos/invariant";
5027
- import { PublicKey as PublicKey14 } from "@dxos/keys";
5028
- import { log as log16 } from "@dxos/log";
5382
+ import { invariant as invariant18 } from "@dxos/invariant";
5383
+ import { PublicKey as PublicKey15 } from "@dxos/keys";
5384
+ import { log as log18 } from "@dxos/log";
5029
5385
  import { WebsocketSignalManager } from "@dxos/messaging";
5030
5386
  import { NetworkManager, createSimplePeerTransportFactory } from "@dxos/network-manager";
5031
5387
  import { trace as trace9 } from "@dxos/protocols";
@@ -5037,9 +5393,9 @@ import { WebsocketRpcClient } from "@dxos/websocket-rpc";
5037
5393
  // packages/sdk/client-services/src/packlets/devices/devices-service.ts
5038
5394
  import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
5039
5395
  import { Stream as Stream11 } from "@dxos/codec-protobuf";
5040
- import { invariant as invariant15 } from "@dxos/invariant";
5396
+ import { invariant as invariant17 } from "@dxos/invariant";
5041
5397
  import { Device as Device2, DeviceKind as DeviceKind2 } from "@dxos/protocols/proto/dxos/client/services";
5042
- var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
5398
+ var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
5043
5399
  var DevicesServiceImpl = class {
5044
5400
  constructor(_identityManager) {
5045
5401
  this._identityManager = _identityManager;
@@ -5056,8 +5412,8 @@ var DevicesServiceImpl = class {
5056
5412
  devices: []
5057
5413
  });
5058
5414
  } else {
5059
- invariant15(this._identityManager.identity?.presence, "presence not present", {
5060
- F: __dxlog_file17,
5415
+ invariant17(this._identityManager.identity?.presence, "presence not present", {
5416
+ F: __dxlog_file19,
5061
5417
  L: 32,
5062
5418
  S: this,
5063
5419
  A: [
@@ -5117,9 +5473,9 @@ var DevicesServiceImpl = class {
5117
5473
  };
5118
5474
 
5119
5475
  // packages/sdk/client-services/src/packlets/locks/browser.ts
5120
- import { asyncTimeout as asyncTimeout2, Trigger as Trigger7 } from "@dxos/async";
5476
+ import { asyncTimeout as asyncTimeout2, Trigger as Trigger8 } from "@dxos/async";
5121
5477
  import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
5122
- import { log as log14, logInfo } from "@dxos/log";
5478
+ import { log as log16, logInfo } from "@dxos/log";
5123
5479
  function _ts_decorate7(decorators, target, key, desc) {
5124
5480
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5125
5481
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -5130,7 +5486,7 @@ function _ts_decorate7(decorators, target, key, desc) {
5130
5486
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5131
5487
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5132
5488
  }
5133
- var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
5489
+ var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
5134
5490
  var Message;
5135
5491
  (function(Message2) {
5136
5492
  Message2["ACQUIRING"] = "acquiring";
@@ -5138,7 +5494,7 @@ var Message;
5138
5494
  var Lock = class {
5139
5495
  constructor({ lockKey, onAcquire, onRelease }) {
5140
5496
  this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
5141
- this._releaseTrigger = new Trigger7();
5497
+ this._releaseTrigger = new Trigger8();
5142
5498
  this._lockKey = lockKey;
5143
5499
  this._onAcquire = onAcquire;
5144
5500
  this._onRelease = onRelease;
@@ -5152,29 +5508,29 @@ var Lock = class {
5152
5508
  message: "acquiring"
5153
5509
  });
5154
5510
  try {
5155
- log14("aquiring lock...", void 0, {
5156
- F: __dxlog_file18,
5511
+ log16("aquiring lock...", void 0, {
5512
+ F: __dxlog_file20,
5157
5513
  L: 42,
5158
5514
  S: this,
5159
5515
  C: (f, a) => f(...a)
5160
5516
  });
5161
5517
  await asyncTimeout2(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
5162
- log14("acquired lock", void 0, {
5163
- F: __dxlog_file18,
5518
+ log16("acquired lock", void 0, {
5519
+ F: __dxlog_file20,
5164
5520
  L: 44,
5165
5521
  S: this,
5166
5522
  C: (f, a) => f(...a)
5167
5523
  });
5168
5524
  } catch {
5169
- log14("stealing lock...", void 0, {
5170
- F: __dxlog_file18,
5525
+ log16("stealing lock...", void 0, {
5526
+ F: __dxlog_file20,
5171
5527
  L: 46,
5172
5528
  S: this,
5173
5529
  C: (f, a) => f(...a)
5174
5530
  });
5175
5531
  await this._requestLock(true);
5176
- log14("stolen lock", void 0, {
5177
- F: __dxlog_file18,
5532
+ log16("stolen lock", void 0, {
5533
+ F: __dxlog_file20,
5178
5534
  L: 48,
5179
5535
  S: this,
5180
5536
  C: (f, a) => f(...a)
@@ -5190,31 +5546,31 @@ var Lock = class {
5190
5546
  }
5191
5547
  }
5192
5548
  async _requestLock(steal = false) {
5193
- log14("requesting lock...", {
5549
+ log16("requesting lock...", {
5194
5550
  steal
5195
5551
  }, {
5196
- F: __dxlog_file18,
5552
+ F: __dxlog_file20,
5197
5553
  L: 63,
5198
5554
  S: this,
5199
5555
  C: (f, a) => f(...a)
5200
5556
  });
5201
- const acquired = new Trigger7();
5557
+ const acquired = new Trigger8();
5202
5558
  void navigator.locks.request(this._lockKey, {
5203
5559
  steal
5204
5560
  }, async () => {
5205
5561
  await this._onAcquire?.();
5206
5562
  acquired.wake();
5207
- this._releaseTrigger = new Trigger7();
5563
+ this._releaseTrigger = new Trigger8();
5208
5564
  await this._releaseTrigger.wait();
5209
- log14("releasing lock...", void 0, {
5210
- F: __dxlog_file18,
5565
+ log16("releasing lock...", void 0, {
5566
+ F: __dxlog_file20,
5211
5567
  L: 72,
5212
5568
  S: this,
5213
5569
  C: (f, a) => f(...a)
5214
5570
  });
5215
5571
  await this._onRelease?.();
5216
- log14("released lock", void 0, {
5217
- F: __dxlog_file18,
5572
+ log16("released lock", void 0, {
5573
+ F: __dxlog_file20,
5218
5574
  L: 74,
5219
5575
  S: this,
5220
5576
  C: (f, a) => f(...a)
@@ -5223,10 +5579,10 @@ var Lock = class {
5223
5579
  await this._onRelease?.();
5224
5580
  });
5225
5581
  await acquired.wait();
5226
- log14("recieved lock", {
5582
+ log16("recieved lock", {
5227
5583
  steal
5228
5584
  }, {
5229
- F: __dxlog_file18,
5585
+ F: __dxlog_file20,
5230
5586
  L: 81,
5231
5587
  S: this,
5232
5588
  C: (f, a) => f(...a)
@@ -5243,25 +5599,25 @@ var isLocked = (lockPath) => {
5243
5599
  // packages/sdk/client-services/src/packlets/logging/logging-service.ts
5244
5600
  import { Event as Event8 } from "@dxos/async";
5245
5601
  import { Stream as Stream12 } from "@dxos/codec-protobuf";
5246
- import { PublicKey as PublicKey12 } from "@dxos/keys";
5247
- import { getContextFromEntry, log as log15 } from "@dxos/log";
5602
+ import { PublicKey as PublicKey13 } from "@dxos/keys";
5603
+ import { getContextFromEntry, log as log17 } from "@dxos/log";
5248
5604
  import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
5249
5605
  import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
5250
5606
  var LoggingServiceImpl = class {
5251
5607
  constructor() {
5252
5608
  this._logs = new Event8();
5253
5609
  this._started = Date.now();
5254
- this._sessionId = PublicKey12.random().toHex();
5610
+ this._sessionId = PublicKey13.random().toHex();
5255
5611
  this._logProcessor = (_config, entry2) => {
5256
5612
  this._logs.emit(entry2);
5257
5613
  };
5258
5614
  }
5259
5615
  async open() {
5260
- log15.runtimeConfig.processors.push(this._logProcessor);
5616
+ log17.runtimeConfig.processors.push(this._logProcessor);
5261
5617
  }
5262
5618
  async close() {
5263
- const index = log15.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
5264
- log15.runtimeConfig.processors.splice(index, 1);
5619
+ const index = log17.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
5620
+ log17.runtimeConfig.processors.splice(index, 1);
5265
5621
  }
5266
5622
  async controlMetrics({ reset, record }) {
5267
5623
  if (reset) {
@@ -5460,13 +5816,13 @@ var toStorageType = (type) => {
5460
5816
  };
5461
5817
 
5462
5818
  // packages/sdk/client-services/src/packlets/storage/level.ts
5463
- import { Level } from "level";
5464
5819
  import path from "@dxos/node-std/path";
5465
- import { PublicKey as PublicKey13 } from "@dxos/keys";
5820
+ import { PublicKey as PublicKey14 } from "@dxos/keys";
5821
+ import { createLevel as createKV } from "@dxos/kv-store";
5466
5822
  var createLevel = async (config) => {
5467
5823
  const persistent = isPersistent(config);
5468
- const storagePath = persistent ? path.join(getRootPath(config), "level") : `/tmp/dxos-${PublicKey13.random().toHex()}`;
5469
- const level = new Level(storagePath);
5824
+ const storagePath = persistent ? path.join(getRootPath(config), "level") : `/tmp/dxos-${PublicKey14.random().toHex()}`;
5825
+ const level = createKV(storagePath);
5470
5826
  await level.open();
5471
5827
  return level;
5472
5828
  };
@@ -5539,7 +5895,7 @@ function _ts_decorate8(decorators, target, key, desc) {
5539
5895
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5540
5896
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5541
5897
  }
5542
- var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
5898
+ var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
5543
5899
  var ClientServicesHost = class {
5544
5900
  constructor({
5545
5901
  config,
@@ -5627,25 +5983,25 @@ var ClientServicesHost = class {
5627
5983
  * Can only be called once.
5628
5984
  */
5629
5985
  initialize({ config, ...options }) {
5630
- invariant16(!this._open, "service host is open", {
5631
- F: __dxlog_file19,
5632
- L: 190,
5986
+ invariant18(!this._open, "service host is open", {
5987
+ F: __dxlog_file21,
5988
+ L: 189,
5633
5989
  S: this,
5634
5990
  A: [
5635
5991
  "!this._open",
5636
5992
  "'service host is open'"
5637
5993
  ]
5638
5994
  });
5639
- log16("initializing...", void 0, {
5640
- F: __dxlog_file19,
5641
- L: 191,
5995
+ log18("initializing...", void 0, {
5996
+ F: __dxlog_file21,
5997
+ L: 190,
5642
5998
  S: this,
5643
5999
  C: (f, a) => f(...a)
5644
6000
  });
5645
6001
  if (config) {
5646
- invariant16(!this._config, "config already set", {
5647
- F: __dxlog_file19,
5648
- L: 194,
6002
+ invariant18(!this._config, "config already set", {
6003
+ F: __dxlog_file21,
6004
+ L: 193,
5649
6005
  S: this,
5650
6006
  A: [
5651
6007
  "!this._config",
@@ -5658,9 +6014,9 @@ var ClientServicesHost = class {
5658
6014
  }
5659
6015
  }
5660
6016
  if (!options.signalManager) {
5661
- log16.warn("running signaling without telemetry metadata.", void 0, {
5662
- F: __dxlog_file19,
5663
- L: 202,
6017
+ log18.warn("running signaling without telemetry metadata.", void 0, {
6018
+ F: __dxlog_file21,
6019
+ L: 201,
5664
6020
  S: this,
5665
6021
  C: (f, a) => f(...a)
5666
6022
  });
@@ -5669,9 +6025,9 @@ var ClientServicesHost = class {
5669
6025
  iceServers: this._config?.get("runtime.services.ice")
5670
6026
  }), signalManager = new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
5671
6027
  this._signalManager = signalManager;
5672
- invariant16(!this._networkManager, "network manager already set", {
5673
- F: __dxlog_file19,
5674
- L: 213,
6028
+ invariant18(!this._networkManager, "network manager already set", {
6029
+ F: __dxlog_file21,
6030
+ L: 212,
5675
6031
  S: this,
5676
6032
  A: [
5677
6033
  "!this._networkManager",
@@ -5683,9 +6039,9 @@ var ClientServicesHost = class {
5683
6039
  transportFactory,
5684
6040
  signalManager
5685
6041
  });
5686
- log16("initialized", void 0, {
5687
- F: __dxlog_file19,
5688
- L: 220,
6042
+ log18("initialized", void 0, {
6043
+ F: __dxlog_file21,
6044
+ L: 219,
5689
6045
  S: this,
5690
6046
  C: (f, a) => f(...a)
5691
6047
  });
@@ -5694,45 +6050,45 @@ var ClientServicesHost = class {
5694
6050
  if (this._open) {
5695
6051
  return;
5696
6052
  }
5697
- const traceId = PublicKey14.random().toHex();
5698
- log16.trace("dxos.client-services.host.open", trace9.begin({
6053
+ const traceId = PublicKey15.random().toHex();
6054
+ log18.trace("dxos.client-services.host.open", trace9.begin({
5699
6055
  id: traceId
5700
6056
  }), {
5701
- F: __dxlog_file19,
5702
- L: 231,
6057
+ F: __dxlog_file21,
6058
+ L: 230,
5703
6059
  S: this,
5704
6060
  C: (f, a) => f(...a)
5705
6061
  });
5706
- invariant16(this._config, "config not set", {
5707
- F: __dxlog_file19,
5708
- L: 233,
6062
+ invariant18(this._config, "config not set", {
6063
+ F: __dxlog_file21,
6064
+ L: 232,
5709
6065
  S: this,
5710
6066
  A: [
5711
6067
  "this._config",
5712
6068
  "'config not set'"
5713
6069
  ]
5714
6070
  });
5715
- invariant16(this._storage, "storage not set", {
5716
- F: __dxlog_file19,
5717
- L: 234,
6071
+ invariant18(this._storage, "storage not set", {
6072
+ F: __dxlog_file21,
6073
+ L: 233,
5718
6074
  S: this,
5719
6075
  A: [
5720
6076
  "this._storage",
5721
6077
  "'storage not set'"
5722
6078
  ]
5723
6079
  });
5724
- invariant16(this._signalManager, "signal manager not set", {
5725
- F: __dxlog_file19,
5726
- L: 235,
6080
+ invariant18(this._signalManager, "signal manager not set", {
6081
+ F: __dxlog_file21,
6082
+ L: 234,
5727
6083
  S: this,
5728
6084
  A: [
5729
6085
  "this._signalManager",
5730
6086
  "'signal manager not set'"
5731
6087
  ]
5732
6088
  });
5733
- invariant16(this._networkManager, "network manager not set", {
5734
- F: __dxlog_file19,
5735
- L: 236,
6089
+ invariant18(this._networkManager, "network manager not set", {
6090
+ F: __dxlog_file21,
6091
+ L: 235,
5736
6092
  S: this,
5737
6093
  A: [
5738
6094
  "this._networkManager",
@@ -5740,19 +6096,19 @@ var ClientServicesHost = class {
5740
6096
  ]
5741
6097
  });
5742
6098
  this._opening = true;
5743
- log16("opening...", {
6099
+ log18("opening...", {
5744
6100
  lockKey: this._resourceLock?.lockKey
5745
6101
  }, {
5746
- F: __dxlog_file19,
5747
- L: 239,
6102
+ F: __dxlog_file21,
6103
+ L: 238,
5748
6104
  S: this,
5749
6105
  C: (f, a) => f(...a)
5750
6106
  });
6107
+ await this._resourceLock?.acquire();
5751
6108
  if (!this._level) {
5752
6109
  this._level = await createLevel(this._config.get("runtime.client.storage", {}));
5753
6110
  }
5754
6111
  await this._level.open();
5755
- await this._resourceLock?.acquire();
5756
6112
  await this._loggingService.open();
5757
6113
  this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._runtimeParams);
5758
6114
  this._serviceRegistry.setServices({
@@ -5792,19 +6148,19 @@ var ClientServicesHost = class {
5792
6148
  this._open = true;
5793
6149
  this._statusUpdate.emit();
5794
6150
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
5795
- log16("opened", {
6151
+ log18("opened", {
5796
6152
  deviceKey
5797
6153
  }, {
5798
- F: __dxlog_file19,
5799
- L: 315,
6154
+ F: __dxlog_file21,
6155
+ L: 314,
5800
6156
  S: this,
5801
6157
  C: (f, a) => f(...a)
5802
6158
  });
5803
- log16.trace("dxos.client-services.host.open", trace9.end({
6159
+ log18.trace("dxos.client-services.host.open", trace9.end({
5804
6160
  id: traceId
5805
6161
  }), {
5806
- F: __dxlog_file19,
5807
- L: 316,
6162
+ F: __dxlog_file21,
6163
+ L: 315,
5808
6164
  S: this,
5809
6165
  C: (f, a) => f(...a)
5810
6166
  });
@@ -5814,11 +6170,11 @@ var ClientServicesHost = class {
5814
6170
  return;
5815
6171
  }
5816
6172
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
5817
- log16("closing...", {
6173
+ log18("closing...", {
5818
6174
  deviceKey
5819
6175
  }, {
5820
- F: __dxlog_file19,
5821
- L: 327,
6176
+ F: __dxlog_file21,
6177
+ L: 326,
5822
6178
  S: this,
5823
6179
  C: (f, a) => f(...a)
5824
6180
  });
@@ -5832,44 +6188,44 @@ var ClientServicesHost = class {
5832
6188
  await this._level?.close();
5833
6189
  this._open = false;
5834
6190
  this._statusUpdate.emit();
5835
- log16("closed", {
6191
+ log18("closed", {
5836
6192
  deviceKey
5837
6193
  }, {
5838
- F: __dxlog_file19,
5839
- L: 336,
6194
+ F: __dxlog_file21,
6195
+ L: 335,
5840
6196
  S: this,
5841
6197
  C: (f, a) => f(...a)
5842
6198
  });
5843
6199
  }
5844
6200
  async reset() {
5845
- const traceId = PublicKey14.random().toHex();
5846
- log16.trace("dxos.sdk.client-services-host.reset", trace9.begin({
6201
+ const traceId = PublicKey15.random().toHex();
6202
+ log18.trace("dxos.sdk.client-services-host.reset", trace9.begin({
5847
6203
  id: traceId
5848
6204
  }), {
5849
- F: __dxlog_file19,
5850
- L: 341,
6205
+ F: __dxlog_file21,
6206
+ L: 340,
5851
6207
  S: this,
5852
6208
  C: (f, a) => f(...a)
5853
6209
  });
5854
- log16("resetting...", void 0, {
5855
- F: __dxlog_file19,
5856
- L: 343,
6210
+ log18("resetting...", void 0, {
6211
+ F: __dxlog_file21,
6212
+ L: 342,
5857
6213
  S: this,
5858
6214
  C: (f, a) => f(...a)
5859
6215
  });
5860
6216
  await this._serviceContext?.close();
5861
6217
  await this._storage.reset();
5862
- log16("reset", void 0, {
5863
- F: __dxlog_file19,
5864
- L: 346,
6218
+ log18("reset", void 0, {
6219
+ F: __dxlog_file21,
6220
+ L: 345,
5865
6221
  S: this,
5866
6222
  C: (f, a) => f(...a)
5867
6223
  });
5868
- log16.trace("dxos.sdk.client-services-host.reset", trace9.end({
6224
+ log18.trace("dxos.sdk.client-services-host.reset", trace9.end({
5869
6225
  id: traceId
5870
6226
  }), {
5871
- F: __dxlog_file19,
5872
- L: 347,
6227
+ F: __dxlog_file21,
6228
+ L: 346,
5873
6229
  S: this,
5874
6230
  C: (f, a) => f(...a)
5875
6231
  });
@@ -5880,9 +6236,9 @@ var ClientServicesHost = class {
5880
6236
  await this._serviceContext.initialized.wait();
5881
6237
  const space = await this._serviceContext.dataSpaceManager.createSpace();
5882
6238
  const automergeIndex = space.automergeSpaceState.rootUrl;
5883
- invariant16(automergeIndex, void 0, {
5884
- F: __dxlog_file19,
5885
- L: 359,
6239
+ invariant18(automergeIndex, void 0, {
6240
+ F: __dxlog_file21,
6241
+ L: 358,
5886
6242
  S: this,
5887
6243
  A: [
5888
6244
  "automergeIndex",
@@ -5902,7 +6258,7 @@ var ClientServicesHost = class {
5902
6258
  keys: []
5903
6259
  }
5904
6260
  };
5905
- const propertiesId = PublicKey14.random().toHex();
6261
+ const propertiesId = PublicKey15.random().toHex();
5906
6262
  document.change((doc) => {
5907
6263
  assignDeep2(doc, [
5908
6264
  "objects",
@@ -5932,7 +6288,7 @@ ClientServicesHost = _ts_decorate8([
5932
6288
  ], ClientServicesHost);
5933
6289
 
5934
6290
  // packages/sdk/client-services/src/packlets/services/util.ts
5935
- import { PublicKey as PublicKey15 } from "@dxos/keys";
6291
+ import { PublicKey as PublicKey16 } from "@dxos/keys";
5936
6292
  import { humanize } from "@dxos/util";
5937
6293
  var ClientServicesProviderResource = Symbol.for("dxos.resource.ClientServices");
5938
6294
 
@@ -6009,4 +6365,4 @@ export {
6009
6365
  ClientServicesHost,
6010
6366
  ClientServicesProviderResource
6011
6367
  };
6012
- //# sourceMappingURL=chunk-RQIV4DQ6.mjs.map
6368
+ //# sourceMappingURL=chunk-WNEYCJRZ.mjs.map