@dxos/client-services 0.5.1-main.f81ddc4 → 0.5.1-next.260c093

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