@dxos/client-services 0.6.12-staging.e11e696 → 0.6.13-main.09887cd

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 (68) hide show
  1. package/dist/lib/browser/{chunk-67FEJJ6J.mjs → chunk-XOKN3TE7.mjs} +1055 -768
  2. package/dist/lib/browser/chunk-XOKN3TE7.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/testing/index.mjs +8 -2
  6. package/dist/lib/browser/testing/index.mjs.map +3 -3
  7. package/dist/lib/node/{chunk-2KIDYJ7O.cjs → chunk-IFHGVXW2.cjs} +1062 -779
  8. package/dist/lib/node/chunk-IFHGVXW2.cjs.map +7 -0
  9. package/dist/lib/node/index.cjs +45 -45
  10. package/dist/lib/node/meta.json +1 -1
  11. package/dist/lib/node/testing/index.cjs +15 -9
  12. package/dist/lib/node/testing/index.cjs.map +3 -3
  13. package/dist/lib/node-esm/{chunk-36ZRRDQI.mjs → chunk-FTEPRZ23.mjs} +1047 -760
  14. package/dist/lib/node-esm/chunk-FTEPRZ23.mjs.map +7 -0
  15. package/dist/lib/node-esm/index.mjs +1 -1
  16. package/dist/lib/node-esm/meta.json +1 -1
  17. package/dist/lib/node-esm/testing/index.mjs +8 -2
  18. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  19. package/dist/types/src/packlets/identity/identity-manager.d.ts +11 -7
  20. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  21. package/dist/types/src/packlets/identity/identity.d.ts +3 -2
  22. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  23. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
  24. package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts +30 -0
  25. package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts.map +1 -0
  26. package/dist/types/src/packlets/invitations/invitation-guest-extenstion.d.ts +2 -1
  27. package/dist/types/src/packlets/invitations/invitation-guest-extenstion.d.ts.map +1 -1
  28. package/dist/types/src/packlets/invitations/invitation-host-extension.d.ts +2 -1
  29. package/dist/types/src/packlets/invitations/invitation-host-extension.d.ts.map +1 -1
  30. package/dist/types/src/packlets/invitations/invitation-state.d.ts +19 -0
  31. package/dist/types/src/packlets/invitations/invitation-state.d.ts.map +1 -0
  32. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +8 -8
  33. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  34. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  35. package/dist/types/src/packlets/services/service-context.d.ts +3 -3
  36. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  37. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +2 -0
  38. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  39. package/dist/types/src/packlets/spaces/data-space.d.ts +1 -0
  40. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  41. package/dist/types/src/packlets/spaces/spaces-service.d.ts +1 -1
  42. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  43. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  44. package/dist/types/src/version.d.ts +1 -1
  45. package/dist/types/src/version.d.ts.map +1 -1
  46. package/package.json +38 -38
  47. package/src/packlets/identity/identity-manager.test.ts +26 -10
  48. package/src/packlets/identity/identity-manager.ts +19 -19
  49. package/src/packlets/identity/identity.test.ts +2 -0
  50. package/src/packlets/identity/identity.ts +17 -12
  51. package/src/packlets/invitations/device-invitation-protocol.ts +5 -1
  52. package/src/packlets/invitations/edge-invitation-handler.ts +184 -0
  53. package/src/packlets/invitations/invitation-guest-extenstion.ts +8 -4
  54. package/src/packlets/invitations/invitation-host-extension.ts +8 -4
  55. package/src/packlets/invitations/invitation-state.ts +111 -0
  56. package/src/packlets/invitations/invitations-handler.test.ts +2 -2
  57. package/src/packlets/invitations/invitations-handler.ts +23 -92
  58. package/src/packlets/invitations/space-invitation-protocol.ts +4 -0
  59. package/src/packlets/services/service-context.ts +65 -45
  60. package/src/packlets/spaces/data-space-manager.ts +31 -3
  61. package/src/packlets/spaces/data-space.ts +5 -0
  62. package/src/packlets/spaces/edge-feed-replicator.test.ts +2 -0
  63. package/src/packlets/spaces/spaces-service.ts +6 -1
  64. package/src/packlets/testing/test-builder.ts +5 -1
  65. package/src/version.ts +1 -1
  66. package/dist/lib/browser/chunk-67FEJJ6J.mjs.map +0 -7
  67. package/dist/lib/node/chunk-2KIDYJ7O.cjs.map +0 -7
  68. package/dist/lib/node-esm/chunk-36ZRRDQI.mjs.map +0 -7
@@ -404,7 +404,7 @@ import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
404
404
  import { TRACE_PROCESSOR } from "@dxos/tracing";
405
405
 
406
406
  // packages/sdk/client-services/src/version.ts
407
- var DXOS_VERSION = "0.6.12-staging.e11e696";
407
+ var DXOS_VERSION = "0.6.13-main.09887cd";
408
408
 
409
409
  // packages/sdk/client-services/src/packlets/services/platform.ts
410
410
  import { Platform } from "@dxos/protocols/proto/dxos/client/services";
@@ -2020,6 +2020,7 @@ import { PublicKey as PublicKey5 } from "@dxos/keys";
2020
2020
  import { log as log8 } from "@dxos/log";
2021
2021
  import { AlreadyJoinedError, trace as Trace } from "@dxos/protocols";
2022
2022
  import { Invitation, SpaceState } from "@dxos/protocols/proto/dxos/client/services";
2023
+ import { EdgeReplicationSetting } from "@dxos/protocols/proto/dxos/echo/metadata";
2023
2024
  import { SpaceMember as SpaceMember3 } from "@dxos/protocols/proto/dxos/halo/credentials";
2024
2025
  import { Gossip, Presence } from "@dxos/teleport-extension-gossip";
2025
2026
  import { trace } from "@dxos/tracing";
@@ -2445,12 +2446,36 @@ var DataSpaceManager = class extends Resource4 {
2445
2446
  }
2446
2447
  });
2447
2448
  }
2449
+ async setSpaceEdgeReplicationSetting(spaceKey, setting) {
2450
+ const space = this._spaces.get(spaceKey);
2451
+ invariant5(space, "Space not found.", {
2452
+ F: __dxlog_file10,
2453
+ L: 399,
2454
+ S: this,
2455
+ A: [
2456
+ "space",
2457
+ "'Space not found.'"
2458
+ ]
2459
+ });
2460
+ await this._metadataStore.setSpaceEdgeReplicationSetting(spaceKey, setting);
2461
+ if (space.isOpen) {
2462
+ switch (setting) {
2463
+ case EdgeReplicationSetting.DISABLED:
2464
+ await this._echoEdgeReplicator?.disconnectFromSpace(space.id);
2465
+ break;
2466
+ case EdgeReplicationSetting.ENABLED:
2467
+ await this._echoEdgeReplicator?.connectToSpace(space.id);
2468
+ break;
2469
+ }
2470
+ }
2471
+ space.stateUpdate.emit();
2472
+ }
2448
2473
  async _constructSpace(metadata) {
2449
2474
  log8("construct space", {
2450
2475
  metadata
2451
2476
  }, {
2452
2477
  F: __dxlog_file10,
2453
- L: 398,
2478
+ L: 418,
2454
2479
  S: this,
2455
2480
  C: (f, a) => f(...a)
2456
2481
  });
@@ -2494,7 +2519,7 @@ var DataSpaceManager = class extends Resource4 {
2494
2519
  err
2495
2520
  }, {
2496
2521
  F: __dxlog_file10,
2497
- L: 440,
2522
+ L: 460,
2498
2523
  S: this,
2499
2524
  C: (f, a) => f(...a)
2500
2525
  });
@@ -2504,7 +2529,7 @@ var DataSpaceManager = class extends Resource4 {
2504
2529
  onAuthFailure: () => {
2505
2530
  log8.warn("auth failure", void 0, {
2506
2531
  F: __dxlog_file10,
2507
- L: 445,
2532
+ L: 465,
2508
2533
  S: this,
2509
2534
  C: (f, a) => f(...a)
2510
2535
  });
@@ -2537,7 +2562,7 @@ var DataSpaceManager = class extends Resource4 {
2537
2562
  space: space.key
2538
2563
  }, {
2539
2564
  F: __dxlog_file10,
2540
- L: 472,
2565
+ L: 492,
2541
2566
  S: this,
2542
2567
  C: (f, a) => f(...a)
2543
2568
  });
@@ -2548,7 +2573,7 @@ var DataSpaceManager = class extends Resource4 {
2548
2573
  open: this._lifecycleState === LifecycleState.OPEN
2549
2574
  }, {
2550
2575
  F: __dxlog_file10,
2551
- L: 475,
2576
+ L: 495,
2552
2577
  S: this,
2553
2578
  C: (f, a) => f(...a)
2554
2579
  });
@@ -2567,7 +2592,7 @@ var DataSpaceManager = class extends Resource4 {
2567
2592
  space: space.key
2568
2593
  }, {
2569
2594
  F: __dxlog_file10,
2570
- L: 483,
2595
+ L: 503,
2571
2596
  S: this,
2572
2597
  C: (f, a) => f(...a)
2573
2598
  });
@@ -2579,10 +2604,25 @@ var DataSpaceManager = class extends Resource4 {
2579
2604
  edgeFeatures: this._edgeFeatures
2580
2605
  });
2581
2606
  dataSpace.postOpen.append(async () => {
2582
- await this._echoEdgeReplicator?.connectToSpace(dataSpace.id);
2607
+ const setting = dataSpace.getEdgeReplicationSetting();
2608
+ if (setting === EdgeReplicationSetting.ENABLED) {
2609
+ await this._echoEdgeReplicator?.connectToSpace(dataSpace.id);
2610
+ } else if (this._echoEdgeReplicator) {
2611
+ log8("not connecting EchoEdgeReplicator because of EdgeReplicationSetting", {
2612
+ spaceId: dataSpace.id
2613
+ }, {
2614
+ F: __dxlog_file10,
2615
+ L: 516,
2616
+ S: this,
2617
+ C: (f, a) => f(...a)
2618
+ });
2619
+ }
2583
2620
  });
2584
2621
  dataSpace.preClose.append(async () => {
2585
- await this._echoEdgeReplicator?.disconnectFromSpace(dataSpace.id);
2622
+ const setting = dataSpace.getEdgeReplicationSetting();
2623
+ if (setting === EdgeReplicationSetting.ENABLED) {
2624
+ await this._echoEdgeReplicator?.disconnectFromSpace(dataSpace.id);
2625
+ }
2586
2626
  });
2587
2627
  presence.newPeer.on((peerState) => {
2588
2628
  if (dataSpace.state === SpaceState.SPACE_READY) {
@@ -2602,7 +2642,7 @@ var DataSpaceManager = class extends Resource4 {
2602
2642
  space: space.key
2603
2643
  }, {
2604
2644
  F: __dxlog_file10,
2605
- L: 515,
2645
+ L: 543,
2606
2646
  S: this,
2607
2647
  C: (f, a) => f(...a)
2608
2648
  });
@@ -2635,7 +2675,7 @@ var DataSpaceManager = class extends Resource4 {
2635
2675
  closedSessions
2636
2676
  }, {
2637
2677
  F: __dxlog_file10,
2638
- L: 541,
2678
+ L: 569,
2639
2679
  S: this,
2640
2680
  C: (f, a) => f(...a)
2641
2681
  });
@@ -2650,7 +2690,7 @@ var DataSpaceManager = class extends Resource4 {
2650
2690
  peerId: peerState.peerId
2651
2691
  }, {
2652
2692
  F: __dxlog_file10,
2653
- L: 555,
2693
+ L: 583,
2654
2694
  S: this,
2655
2695
  C: (f, a) => f(...a)
2656
2696
  });
@@ -2735,7 +2775,7 @@ var SpacesServiceImpl = class {
2735
2775
  await this._updateMetrics();
2736
2776
  return this._serializeSpace(space);
2737
2777
  }
2738
- async updateSpace({ spaceKey, state }) {
2778
+ async updateSpace({ spaceKey, state, edgeReplication }) {
2739
2779
  const dataSpaceManager = await this._getDataSpaceManager();
2740
2780
  const space = dataSpaceManager.spaces.get(spaceKey) ?? raise(new SpaceNotFoundError(spaceKey));
2741
2781
  if (state) {
@@ -2750,6 +2790,9 @@ var SpacesServiceImpl = class {
2750
2790
  throw new ApiError("Invalid space state");
2751
2791
  }
2752
2792
  }
2793
+ if (edgeReplication !== void 0) {
2794
+ await dataSpaceManager.setSpaceEdgeReplicationSetting(spaceKey, edgeReplication);
2795
+ }
2753
2796
  }
2754
2797
  async updateMemberRole(request) {
2755
2798
  const identity = this._requireIdentity();
@@ -2766,7 +2809,7 @@ var SpacesServiceImpl = class {
2766
2809
  const credentials = await createAdmissionCredentials2(identity.getIdentityCredentialSigner(), request.memberKey, space.key, space.genesisFeedKey, request.newRole, space.spaceState.membershipChainHeads);
2767
2810
  invariant6(credentials[0].credential, void 0, {
2768
2811
  F: __dxlog_file11,
2769
- L: 102,
2812
+ L: 106,
2770
2813
  S: this,
2771
2814
  A: [
2772
2815
  "credentials[0].credential",
@@ -2776,7 +2819,7 @@ var SpacesServiceImpl = class {
2776
2819
  const spaceMemberCredential = credentials[0].credential.credential;
2777
2820
  invariant6(getCredentialAssertion3(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2778
2821
  F: __dxlog_file11,
2779
- L: 104,
2822
+ L: 108,
2780
2823
  S: this,
2781
2824
  A: [
2782
2825
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2794,7 +2837,7 @@ var SpacesServiceImpl = class {
2794
2837
  ids: spaces.map((space) => space.id)
2795
2838
  }), {
2796
2839
  F: __dxlog_file11,
2797
- L: 115,
2840
+ L: 119,
2798
2841
  S: this,
2799
2842
  C: (f, a) => f(...a)
2800
2843
  });
@@ -2886,7 +2929,7 @@ var SpacesServiceImpl = class {
2886
2929
  } else {
2887
2930
  invariant6(!credential.id, "Id on unsigned credentials is not allowed", {
2888
2931
  F: __dxlog_file11,
2889
- L: 213,
2932
+ L: 217,
2890
2933
  S: this,
2891
2934
  A: [
2892
2935
  "!credential.id",
@@ -2895,7 +2938,7 @@ var SpacesServiceImpl = class {
2895
2938
  });
2896
2939
  invariant6(this._identityManager.identity, "Identity is not available", {
2897
2940
  F: __dxlog_file11,
2898
- L: 214,
2941
+ L: 218,
2899
2942
  S: this,
2900
2943
  A: [
2901
2944
  "this._identityManager.identity",
@@ -2905,7 +2948,7 @@ var SpacesServiceImpl = class {
2905
2948
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
2906
2949
  invariant6(credential.issuer.equals(signer.getIssuer()), void 0, {
2907
2950
  F: __dxlog_file11,
2908
- L: 216,
2951
+ L: 220,
2909
2952
  S: this,
2910
2953
  A: [
2911
2954
  "credential.issuer.equals(signer.getIssuer())",
@@ -2955,7 +2998,7 @@ var SpacesServiceImpl = class {
2955
2998
  const assertion = getCredentialAssertion3(credential);
2956
2999
  invariant6(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2957
3000
  F: __dxlog_file11,
2958
- L: 250,
3001
+ L: 254,
2959
3002
  S: this,
2960
3003
  A: [
2961
3004
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2965,7 +3008,7 @@ var SpacesServiceImpl = class {
2965
3008
  const myIdentity = this._identityManager.identity;
2966
3009
  invariant6(myIdentity && credential.subject.id.equals(myIdentity.identityKey), void 0, {
2967
3010
  F: __dxlog_file11,
2968
- L: 252,
3011
+ L: 256,
2969
3012
  S: this,
2970
3013
  A: [
2971
3014
  "myIdentity && credential.subject.id.equals(myIdentity.identityKey)",
@@ -3027,7 +3070,8 @@ var SpacesServiceImpl = class {
3027
3070
  }),
3028
3071
  creator: space.inner.spaceState.creator?.key,
3029
3072
  cache: space.cache,
3030
- metrics: space.metrics
3073
+ metrics: space.metrics,
3074
+ edgeReplication: space.getEdgeReplicationSetting()
3031
3075
  };
3032
3076
  }
3033
3077
  _requireIdentity() {
@@ -3074,7 +3118,7 @@ var Identity = class {
3074
3118
  deviceKey: params.deviceKey
3075
3119
  }, {
3076
3120
  F: __dxlog_file12,
3077
- L: 78,
3121
+ L: 79,
3078
3122
  S: this,
3079
3123
  C: (f, a) => f(...a)
3080
3124
  });
@@ -3115,10 +3159,13 @@ var Identity = class {
3115
3159
  await this.space.spaceState.addCredentialProcessor(this._deviceStateMachine);
3116
3160
  await this.space.spaceState.addCredentialProcessor(this._profileStateMachine);
3117
3161
  await this.space.spaceState.addCredentialProcessor(this._defaultSpaceStateMachine);
3162
+ await this.space.open(ctx);
3163
+ }
3164
+ async joinNetwork() {
3118
3165
  if (this._edgeFeedReplicator) {
3119
3166
  this.space.protocol.feedAdded.append(this._onFeedAdded);
3120
3167
  }
3121
- await this.space.open(ctx);
3168
+ await this.space.startProtocol();
3122
3169
  await this._edgeFeedReplicator?.open();
3123
3170
  }
3124
3171
  async close(ctx) {
@@ -3170,7 +3217,7 @@ var Identity = class {
3170
3217
  getIdentityCredentialSigner() {
3171
3218
  invariant7(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.", {
3172
3219
  F: __dxlog_file12,
3173
- L: 189,
3220
+ L: 191,
3174
3221
  S: this,
3175
3222
  A: [
3176
3223
  "this._deviceStateMachine.deviceCredentialChain",
@@ -3214,20 +3261,21 @@ var Identity = class {
3214
3261
  dataFeedKey
3215
3262
  }, {
3216
3263
  F: __dxlog_file12,
3217
- L: 214,
3264
+ L: 216,
3218
3265
  S: this,
3219
3266
  C: (f, a) => f(...a)
3220
3267
  });
3221
3268
  const signer = this.getIdentityCredentialSigner();
3269
+ const deviceCredential = await signer.createCredential({
3270
+ subject: deviceKey,
3271
+ assertion: {
3272
+ "@type": "dxos.halo.credentials.AuthorizedDevice",
3273
+ identityKey: this.identityKey,
3274
+ deviceKey
3275
+ }
3276
+ });
3222
3277
  await writeMessages3(this.controlPipeline.writer, [
3223
- await signer.createCredential({
3224
- subject: deviceKey,
3225
- assertion: {
3226
- "@type": "dxos.halo.credentials.AuthorizedDevice",
3227
- identityKey: this.identityKey,
3228
- deviceKey
3229
- }
3230
- }),
3278
+ deviceCredential,
3231
3279
  await signer.createCredential({
3232
3280
  subject: controlFeedKey,
3233
3281
  assertion: {
@@ -3253,6 +3301,7 @@ var Identity = class {
3253
3301
  credential
3254
3302
  }
3255
3303
  })));
3304
+ return deviceCredential;
3256
3305
  }
3257
3306
  };
3258
3307
  _ts_decorate4([
@@ -3301,7 +3350,6 @@ var IdentityManager = class {
3301
3350
  this._edgeFeatures = params.edgeFeatures;
3302
3351
  this._devicePresenceAnnounceInterval = params.devicePresenceAnnounceInterval ?? DEVICE_PRESENCE_ANNOUNCE_INTERVAL;
3303
3352
  this._devicePresenceOfflineTimeout = params.devicePresenceOfflineTimeout ?? DEVICE_PRESENCE_OFFLINE_TIMEOUT;
3304
- this._callbacks = params.callbacks;
3305
3353
  }
3306
3354
  get identity() {
3307
3355
  return this._identity;
@@ -3312,7 +3360,7 @@ var IdentityManager = class {
3312
3360
  id: traceId
3313
3361
  }), {
3314
3362
  F: __dxlog_file13,
3315
- L: 121,
3363
+ L: 116,
3316
3364
  S: this,
3317
3365
  C: (f, a) => f(...a)
3318
3366
  });
@@ -3321,7 +3369,7 @@ var IdentityManager = class {
3321
3369
  identityRecord
3322
3370
  }, {
3323
3371
  F: __dxlog_file13,
3324
- L: 124,
3372
+ L: 119,
3325
3373
  S: this,
3326
3374
  C: (f, a) => f(...a)
3327
3375
  });
@@ -3334,7 +3382,7 @@ var IdentityManager = class {
3334
3382
  displayName: this._identity.profileDocument?.displayName
3335
3383
  }, {
3336
3384
  F: __dxlog_file13,
3337
- L: 129,
3385
+ L: 124,
3338
3386
  S: this,
3339
3387
  C: (f, a) => f(...a)
3340
3388
  });
@@ -3344,7 +3392,7 @@ var IdentityManager = class {
3344
3392
  id: traceId
3345
3393
  }), {
3346
3394
  F: __dxlog_file13,
3347
- L: 136,
3395
+ L: 131,
3348
3396
  S: this,
3349
3397
  C: (f, a) => f(...a)
3350
3398
  });
@@ -3352,13 +3400,13 @@ var IdentityManager = class {
3352
3400
  async close() {
3353
3401
  await this._identity?.close(new Context4(void 0, {
3354
3402
  F: __dxlog_file13,
3355
- L: 140
3403
+ L: 135
3356
3404
  }));
3357
3405
  }
3358
3406
  async createIdentity({ displayName, deviceProfile } = {}) {
3359
3407
  invariant8(!this._identity, "Identity already exists.", {
3360
3408
  F: __dxlog_file13,
3361
- L: 145,
3409
+ L: 140,
3362
3410
  S: this,
3363
3411
  A: [
3364
3412
  "!this._identity",
@@ -3367,7 +3415,7 @@ var IdentityManager = class {
3367
3415
  });
3368
3416
  log11("creating identity...", void 0, {
3369
3417
  F: __dxlog_file13,
3370
- L: 146,
3418
+ L: 141,
3371
3419
  S: this,
3372
3420
  C: (f, a) => f(...a)
3373
3421
  });
@@ -3385,13 +3433,13 @@ var IdentityManager = class {
3385
3433
  const identity = await this._constructIdentity(identityRecord);
3386
3434
  await identity.open(new Context4(void 0, {
3387
3435
  F: __dxlog_file13,
3388
- L: 161
3436
+ L: 156
3389
3437
  }));
3390
3438
  {
3391
3439
  const generator = new CredentialGenerator(this._keyring, identityRecord.identityKey, identityRecord.deviceKey);
3392
3440
  invariant8(identityRecord.haloSpace.genesisFeedKey, "Genesis feed key is required.", {
3393
3441
  F: __dxlog_file13,
3394
- L: 165,
3442
+ L: 160,
3395
3443
  S: this,
3396
3444
  A: [
3397
3445
  "identityRecord.haloSpace.genesisFeedKey",
@@ -3400,7 +3448,7 @@ var IdentityManager = class {
3400
3448
  });
3401
3449
  invariant8(identityRecord.haloSpace.dataFeedKey, "Data feed key is required.", {
3402
3450
  F: __dxlog_file13,
3403
- L: 166,
3451
+ L: 161,
3404
3452
  S: this,
3405
3453
  A: [
3406
3454
  "identityRecord.haloSpace.dataFeedKey",
@@ -3439,7 +3487,7 @@ var IdentityManager = class {
3439
3487
  displayName: this._identity.profileDocument?.displayName
3440
3488
  }, {
3441
3489
  F: __dxlog_file13,
3442
- L: 208,
3490
+ L: 199,
3443
3491
  S: this,
3444
3492
  C: (f, a) => f(...a)
3445
3493
  });
@@ -3450,7 +3498,7 @@ var IdentityManager = class {
3450
3498
  profile: identity.profileDocument
3451
3499
  }, {
3452
3500
  F: __dxlog_file13,
3453
- L: 214,
3501
+ L: 205,
3454
3502
  S: this,
3455
3503
  C: (f, a) => f(...a)
3456
3504
  });
@@ -3480,20 +3528,20 @@ var IdentityManager = class {
3480
3528
  };
3481
3529
  }
3482
3530
  /**
3483
- * Accept an existing identity. Expects its device key to be authorized (now or later).
3531
+ * Prepare an identity object as the first step of acceptIdentity flow.
3484
3532
  */
3485
- async acceptIdentity(params) {
3533
+ async prepareIdentity(params) {
3486
3534
  log11("accepting identity", {
3487
3535
  params
3488
3536
  }, {
3489
3537
  F: __dxlog_file13,
3490
- L: 252,
3538
+ L: 244,
3491
3539
  S: this,
3492
3540
  C: (f, a) => f(...a)
3493
3541
  });
3494
3542
  invariant8(!this._identity, "Identity already exists.", {
3495
3543
  F: __dxlog_file13,
3496
- L: 253,
3544
+ L: 245,
3497
3545
  S: this,
3498
3546
  A: [
3499
3547
  "!this._identity",
@@ -3514,23 +3562,32 @@ var IdentityManager = class {
3514
3562
  const identity = await this._constructIdentity(identityRecord);
3515
3563
  await identity.open(new Context4(void 0, {
3516
3564
  F: __dxlog_file13,
3517
- L: 268
3565
+ L: 259
3518
3566
  }));
3567
+ return {
3568
+ identity,
3569
+ identityRecord
3570
+ };
3571
+ }
3572
+ /**
3573
+ * Accept an existing identity. Expects its device key to be authorized (now or later).
3574
+ */
3575
+ async acceptIdentity(identity, identityRecord, profile) {
3519
3576
  this._identity = identity;
3520
- await this._metadataStore.setIdentityRecord(identityRecord);
3521
3577
  await this._identity.ready();
3578
+ await this._metadataStore.setIdentityRecord(identityRecord);
3522
3579
  log11.trace("dxos.halo.identity", {
3523
- identityKey: identityRecord.identityKey,
3580
+ identityKey: this._identity.identityKey,
3524
3581
  displayName: this._identity.profileDocument?.displayName
3525
3582
  }, {
3526
3583
  F: __dxlog_file13,
3527
- L: 272,
3584
+ L: 273,
3528
3585
  S: this,
3529
3586
  C: (f, a) => f(...a)
3530
3587
  });
3531
3588
  await this.updateDeviceProfile({
3532
3589
  ...this.createDefaultDeviceProfile(),
3533
- ...params.deviceProfile
3590
+ ...profile
3534
3591
  });
3535
3592
  this.stateUpdate.emit();
3536
3593
  log11("accepted identity", {
@@ -3538,11 +3595,10 @@ var IdentityManager = class {
3538
3595
  deviceKey: identity.deviceKey
3539
3596
  }, {
3540
3597
  F: __dxlog_file13,
3541
- L: 282,
3598
+ L: 284,
3542
3599
  S: this,
3543
3600
  C: (f, a) => f(...a)
3544
3601
  });
3545
- return identity;
3546
3602
  }
3547
3603
  /**
3548
3604
  * Update the profile document of an existing identity.
@@ -3550,7 +3606,7 @@ var IdentityManager = class {
3550
3606
  async updateProfile(profile) {
3551
3607
  invariant8(this._identity, "Identity not initialized.", {
3552
3608
  F: __dxlog_file13,
3553
- L: 290,
3609
+ L: 291,
3554
3610
  S: this,
3555
3611
  A: [
3556
3612
  "this._identity",
@@ -3581,7 +3637,7 @@ var IdentityManager = class {
3581
3637
  async updateDeviceProfile(profile) {
3582
3638
  invariant8(this._identity, "Identity not initialized.", {
3583
3639
  F: __dxlog_file13,
3584
- L: 307,
3640
+ L: 308,
3585
3641
  S: this,
3586
3642
  A: [
3587
3643
  "this._identity",
@@ -3617,7 +3673,7 @@ var IdentityManager = class {
3617
3673
  async _constructIdentity(identityRecord) {
3618
3674
  invariant8(!this._identity, void 0, {
3619
3675
  F: __dxlog_file13,
3620
- L: 333,
3676
+ L: 334,
3621
3677
  S: this,
3622
3678
  A: [
3623
3679
  "!this._identity",
@@ -3628,7 +3684,7 @@ var IdentityManager = class {
3628
3684
  identityRecord
3629
3685
  }, {
3630
3686
  F: __dxlog_file13,
3631
- L: 334,
3687
+ L: 335,
3632
3688
  S: this,
3633
3689
  C: (f, a) => f(...a)
3634
3690
  });
@@ -3643,7 +3699,7 @@ var IdentityManager = class {
3643
3699
  });
3644
3700
  invariant8(identityRecord.haloSpace.controlFeedKey, void 0, {
3645
3701
  F: __dxlog_file13,
3646
- L: 347,
3702
+ L: 348,
3647
3703
  S: this,
3648
3704
  A: [
3649
3705
  "identityRecord.haloSpace.controlFeedKey",
@@ -3655,7 +3711,7 @@ var IdentityManager = class {
3655
3711
  });
3656
3712
  invariant8(identityRecord.haloSpace.dataFeedKey, void 0, {
3657
3713
  F: __dxlog_file13,
3658
- L: 351,
3714
+ L: 352,
3659
3715
  S: this,
3660
3716
  A: [
3661
3717
  "identityRecord.haloSpace.dataFeedKey",
@@ -3692,11 +3748,10 @@ var IdentityManager = class {
3692
3748
  identityKey: identityRecord.identityKey
3693
3749
  }, {
3694
3750
  F: __dxlog_file13,
3695
- L: 380,
3751
+ L: 381,
3696
3752
  S: this,
3697
3753
  C: (f, a) => f(...a)
3698
3754
  });
3699
- this._callbacks?.onIdentityConstruction?.(identity);
3700
3755
  if (identityRecord.haloSpace.controlTimeframe) {
3701
3756
  identity.controlPipeline.state.setTargetTimeframe(identityRecord.haloSpace.controlTimeframe);
3702
3757
  }
@@ -4082,13 +4137,14 @@ var DataSpace = class {
4082
4137
  F: __dxlog_file15,
4083
4138
  L: 244
4084
4139
  }));
4140
+ await this._inner.startProtocol();
4085
4141
  await this._edgeFeedReplicator?.open();
4086
4142
  this._state = SpaceState4.SPACE_CONTROL_ONLY;
4087
4143
  log13("new state", {
4088
4144
  state: SpaceState4[this._state]
4089
4145
  }, {
4090
4146
  F: __dxlog_file15,
4091
- L: 249,
4147
+ L: 250,
4092
4148
  S: this,
4093
4149
  C: (f, a) => f(...a)
4094
4150
  });
@@ -4108,14 +4164,14 @@ var DataSpace = class {
4108
4164
  state: SpaceState4[this._state]
4109
4165
  }, {
4110
4166
  F: __dxlog_file15,
4111
- L: 268,
4167
+ L: 269,
4112
4168
  S: this,
4113
4169
  C: (f, a) => f(...a)
4114
4170
  });
4115
4171
  await this._ctx.dispose();
4116
4172
  this._ctx = new Context5(void 0, {
4117
4173
  F: __dxlog_file15,
4118
- L: 270
4174
+ L: 271
4119
4175
  });
4120
4176
  if (this._edgeFeedReplicator) {
4121
4177
  this.inner.protocol.feedAdded.remove(this._onFeedAdded);
@@ -4148,7 +4204,7 @@ var DataSpace = class {
4148
4204
  if (err instanceof CancelledError || err instanceof ContextDisposedError) {
4149
4205
  log13("data pipeline initialization cancelled", err, {
4150
4206
  F: __dxlog_file15,
4151
- L: 308,
4207
+ L: 309,
4152
4208
  S: this,
4153
4209
  C: (f, a) => f(...a)
4154
4210
  });
@@ -4156,7 +4212,7 @@ var DataSpace = class {
4156
4212
  }
4157
4213
  log13.error("Error initializing data pipeline", err, {
4158
4214
  F: __dxlog_file15,
4159
- L: 312,
4215
+ L: 313,
4160
4216
  S: this,
4161
4217
  C: (f, a) => f(...a)
4162
4218
  });
@@ -4165,7 +4221,7 @@ var DataSpace = class {
4165
4221
  state: SpaceState4[this._state]
4166
4222
  }, {
4167
4223
  F: __dxlog_file15,
4168
- L: 314,
4224
+ L: 315,
4169
4225
  S: this,
4170
4226
  C: (f, a) => f(...a)
4171
4227
  });
@@ -4185,13 +4241,13 @@ var DataSpace = class {
4185
4241
  state: SpaceState4[this._state]
4186
4242
  }, {
4187
4243
  F: __dxlog_file15,
4188
- L: 330,
4244
+ L: 331,
4189
4245
  S: this,
4190
4246
  C: (f, a) => f(...a)
4191
4247
  });
4192
4248
  log13("initializing control pipeline", void 0, {
4193
4249
  F: __dxlog_file15,
4194
- L: 332,
4250
+ L: 333,
4195
4251
  S: this,
4196
4252
  C: (f, a) => f(...a)
4197
4253
  });
@@ -4200,21 +4256,21 @@ var DataSpace = class {
4200
4256
  const ready = this.stateUpdate.waitForCondition(() => this._state === SpaceState4.SPACE_READY);
4201
4257
  log13("initializing automerge root", void 0, {
4202
4258
  F: __dxlog_file15,
4203
- L: 340,
4259
+ L: 341,
4204
4260
  S: this,
4205
4261
  C: (f, a) => f(...a)
4206
4262
  });
4207
4263
  this._automergeSpaceState.startProcessingRootDocs();
4208
4264
  log13("waiting for space to be ready", void 0, {
4209
4265
  F: __dxlog_file15,
4210
- L: 344,
4266
+ L: 345,
4211
4267
  S: this,
4212
4268
  C: (f, a) => f(...a)
4213
4269
  });
4214
4270
  await ready;
4215
4271
  log13("space is ready", void 0, {
4216
4272
  F: __dxlog_file15,
4217
- L: 346,
4273
+ L: 347,
4218
4274
  S: this,
4219
4275
  C: (f, a) => f(...a)
4220
4276
  });
@@ -4226,7 +4282,7 @@ var DataSpace = class {
4226
4282
  state: SpaceState4[this._state]
4227
4283
  }, {
4228
4284
  F: __dxlog_file15,
4229
- L: 353,
4285
+ L: 354,
4230
4286
  S: this,
4231
4287
  C: (f, a) => f(...a)
4232
4288
  });
@@ -4243,7 +4299,7 @@ var DataSpace = class {
4243
4299
  await this._createWritableFeeds();
4244
4300
  log13("writable feeds created", void 0, {
4245
4301
  F: __dxlog_file15,
4246
- L: 370,
4302
+ L: 371,
4247
4303
  S: this,
4248
4304
  C: (f, a) => f(...a)
4249
4305
  });
@@ -4297,7 +4353,7 @@ var DataSpace = class {
4297
4353
  count: credentials.length
4298
4354
  }, {
4299
4355
  F: __dxlog_file15,
4300
- L: 428,
4356
+ L: 429,
4301
4357
  S: this,
4302
4358
  C: (f, a) => f(...a)
4303
4359
  });
@@ -4308,14 +4364,14 @@ var DataSpace = class {
4308
4364
  });
4309
4365
  log13("credentials notarized", void 0, {
4310
4366
  F: __dxlog_file15,
4311
- L: 432,
4367
+ L: 433,
4312
4368
  S: this,
4313
4369
  C: (f, a) => f(...a)
4314
4370
  });
4315
4371
  } catch (err) {
4316
4372
  log13.error("error notarizing credentials for feed admission", err, {
4317
4373
  F: __dxlog_file15,
4318
- L: 434,
4374
+ L: 435,
4319
4375
  S: this,
4320
4376
  C: (f, a) => f(...a)
4321
4377
  });
@@ -4330,7 +4386,7 @@ var DataSpace = class {
4330
4386
  rootUrl
4331
4387
  }, {
4332
4388
  F: __dxlog_file15,
4333
- L: 444,
4389
+ L: 445,
4334
4390
  S: this,
4335
4391
  C: (f, a) => f(...a)
4336
4392
  });
@@ -4382,7 +4438,7 @@ var DataSpace = class {
4382
4438
  err
4383
4439
  }, {
4384
4440
  F: __dxlog_file15,
4385
- L: 487,
4441
+ L: 488,
4386
4442
  S: this,
4387
4443
  C: (f, a) => f(...a)
4388
4444
  });
@@ -4472,12 +4528,15 @@ var DataSpace = class {
4472
4528
  state: SpaceState4[this._state]
4473
4529
  }, {
4474
4530
  F: __dxlog_file15,
4475
- L: 569,
4531
+ L: 570,
4476
4532
  S: this,
4477
4533
  C: (f, a) => f(...a)
4478
4534
  });
4479
4535
  this.stateUpdate.emit();
4480
4536
  }
4537
+ getEdgeReplicationSetting() {
4538
+ return this._metadataStore.getSpaceEdgeReplicationSetting(this.key);
4539
+ }
4481
4540
  };
4482
4541
  _ts_decorate6([
4483
4542
  trace5.info()
@@ -4529,6 +4588,7 @@ DataSpace = _ts_decorate6([
4529
4588
  ], DataSpace);
4530
4589
 
4531
4590
  // packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts
4591
+ import { getCredentialAssertion as getCredentialAssertion4 } from "@dxos/credentials";
4532
4592
  import { invariant as invariant10 } from "@dxos/invariant";
4533
4593
  import { AlreadyJoinedError as AlreadyJoinedError2 } from "@dxos/protocols";
4534
4594
  import { Invitation as Invitation2 } from "@dxos/protocols/proto/dxos/client/services";
@@ -4559,7 +4619,7 @@ var DeviceInvitationProtocol = class {
4559
4619
  async admit(_, request) {
4560
4620
  invariant10(request.device, void 0, {
4561
4621
  F: __dxlog_file16,
4562
- L: 50,
4622
+ L: 51,
4563
4623
  S: this,
4564
4624
  A: [
4565
4625
  "request.device",
@@ -4567,13 +4627,23 @@ var DeviceInvitationProtocol = class {
4567
4627
  ]
4568
4628
  });
4569
4629
  const identity = this._getIdentity();
4570
- await identity.admitDevice(request.device);
4630
+ const credential = await identity.admitDevice(request.device);
4631
+ invariant10(getCredentialAssertion4(credential)["@type"] === "dxos.halo.credentials.AuthorizedDevice", void 0, {
4632
+ F: __dxlog_file16,
4633
+ L: 54,
4634
+ S: this,
4635
+ A: [
4636
+ "getCredentialAssertion(credential)['@type'] === 'dxos.halo.credentials.AuthorizedDevice'",
4637
+ ""
4638
+ ]
4639
+ });
4571
4640
  return {
4572
4641
  device: {
4573
4642
  identityKey: identity.identityKey,
4574
4643
  haloSpaceKey: identity.haloSpaceKey,
4575
4644
  genesisFeedKey: identity.haloGenesisFeedKey,
4576
- controlTimeframe: identity.controlPipeline.state.timeframe
4645
+ controlTimeframe: identity.controlPipeline.state.timeframe,
4646
+ credential
4577
4647
  }
4578
4648
  };
4579
4649
  }
@@ -4605,7 +4675,7 @@ var DeviceInvitationProtocol = class {
4605
4675
  async accept(response, request) {
4606
4676
  invariant10(response.device, void 0, {
4607
4677
  F: __dxlog_file16,
4608
- L: 95,
4678
+ L: 98,
4609
4679
  S: this,
4610
4680
  A: [
4611
4681
  "response.device",
@@ -4615,7 +4685,7 @@ var DeviceInvitationProtocol = class {
4615
4685
  const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
4616
4686
  invariant10(request.device, void 0, {
4617
4687
  F: __dxlog_file16,
4618
- L: 98,
4688
+ L: 101,
4619
4689
  S: this,
4620
4690
  A: [
4621
4691
  "request.device",
@@ -4631,7 +4701,8 @@ var DeviceInvitationProtocol = class {
4631
4701
  controlFeedKey,
4632
4702
  dataFeedKey,
4633
4703
  controlTimeframe,
4634
- deviceProfile: profile
4704
+ deviceProfile: profile,
4705
+ authorizedDeviceCredential: response.device.credential
4635
4706
  });
4636
4707
  return {
4637
4708
  identityKey
@@ -4640,30 +4711,30 @@ var DeviceInvitationProtocol = class {
4640
4711
  };
4641
4712
 
4642
4713
  // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
4643
- import { Mutex as Mutex3, scheduleTask as scheduleTask6, TimeoutError as TimeoutError2 } from "@dxos/async";
4714
+ import { scheduleTask as scheduleTask7, TimeoutError as TimeoutError2 } from "@dxos/async";
4644
4715
  import { INVITATION_TIMEOUT } from "@dxos/client-protocol";
4645
4716
  import { ContextDisposedError as ContextDisposedError3 } from "@dxos/context";
4646
4717
  import { createKeyPair, sign } from "@dxos/crypto";
4647
- import { invariant as invariant14 } from "@dxos/invariant";
4718
+ import { invariant as invariant15 } from "@dxos/invariant";
4648
4719
  import { PublicKey as PublicKey11 } from "@dxos/keys";
4649
- import { log as log17 } from "@dxos/log";
4720
+ import { log as log19 } from "@dxos/log";
4650
4721
  import { createTeleportProtocolFactory } from "@dxos/network-manager";
4651
4722
  import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError3, trace as trace7 } from "@dxos/protocols";
4652
- import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
4723
+ import { Invitation as Invitation7 } from "@dxos/protocols/proto/dxos/client/services";
4653
4724
  import { AuthenticationResponse as AuthenticationResponse2 } from "@dxos/protocols/proto/dxos/halo/invitations";
4654
4725
  import { InvitationOptions as InvitationOptions4 } from "@dxos/protocols/proto/dxos/halo/invitations";
4655
4726
  import { trace as _trace } from "@dxos/tracing";
4656
4727
  import { ComplexSet as ComplexSet5 } from "@dxos/util";
4657
4728
 
4658
- // packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts
4659
- import { Trigger as Trigger5 } from "@dxos/async";
4660
- import { cancelWithContext as cancelWithContext4, Context as Context6 } from "@dxos/context";
4729
+ // packages/sdk/client-services/src/packlets/invitations/edge-invitation-handler.ts
4730
+ import { scheduleMicroTask as scheduleMicroTask3, scheduleTask as scheduleTask5 } from "@dxos/async";
4731
+ import { ed25519Signature } from "@dxos/crypto";
4661
4732
  import { invariant as invariant11 } from "@dxos/invariant";
4733
+ import { SpaceId as SpaceId2 } from "@dxos/keys";
4662
4734
  import { log as log14 } from "@dxos/log";
4663
- import { InvalidInvitationExtensionRoleError } from "@dxos/protocols";
4735
+ import { EdgeAuthChallengeError, EdgeCallFailedError as EdgeCallFailedError2 } from "@dxos/protocols";
4664
4736
  import { schema as schema3 } from "@dxos/protocols/proto";
4665
- import { InvitationOptions } from "@dxos/protocols/proto/dxos/halo/invitations";
4666
- import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
4737
+ import { Invitation as Invitation4 } from "@dxos/protocols/proto/dxos/client/services";
4667
4738
 
4668
4739
  // packages/sdk/client-services/src/packlets/invitations/utils.ts
4669
4740
  import { cancelWithContext as cancelWithContext3, ContextDisposedError as ContextDisposedError2 } from "@dxos/context";
@@ -4684,24 +4755,184 @@ var tryAcquireBeforeContextDisposed = async (ctx, mutex) => {
4684
4755
  })());
4685
4756
  };
4686
4757
 
4758
+ // packages/sdk/client-services/src/packlets/invitations/edge-invitation-handler.ts
4759
+ var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/edge-invitation-handler.ts";
4760
+ var DEFAULT_REQUEST_RETRY_INTERVAL_MS = 3e3;
4761
+ var DEFAULT_REQUEST_RETRY_JITTER_MS = 500;
4762
+ var EdgeInvitationHandler = class {
4763
+ constructor(config, _client, _callbacks) {
4764
+ this._client = _client;
4765
+ this._callbacks = _callbacks;
4766
+ this._retryInterval = config?.retryInterval ?? DEFAULT_REQUEST_RETRY_INTERVAL_MS;
4767
+ this._retryJitter = config?.retryJitter ?? DEFAULT_REQUEST_RETRY_JITTER_MS;
4768
+ }
4769
+ handle(ctx, guardedState, protocol, deviceProfile) {
4770
+ if (!this._client) {
4771
+ log14("edge disabled", void 0, {
4772
+ F: __dxlog_file17,
4773
+ L: 65,
4774
+ S: this,
4775
+ C: (f, a) => f(...a)
4776
+ });
4777
+ return;
4778
+ }
4779
+ const invitation = guardedState.current;
4780
+ const spaceId = invitation.spaceId;
4781
+ const canBeHandledByEdge = invitation.authMethod !== Invitation4.AuthMethod.SHARED_SECRET && invitation.type === Invitation4.Type.DELEGATED && invitation.kind === Invitation4.Kind.SPACE && spaceId != null && SpaceId2.isValid(spaceId);
4782
+ if (!canBeHandledByEdge) {
4783
+ log14("invitation could not be handled by edge", {
4784
+ invitation
4785
+ }, {
4786
+ F: __dxlog_file17,
4787
+ L: 79,
4788
+ S: this,
4789
+ C: (f, a) => f(...a)
4790
+ });
4791
+ return;
4792
+ }
4793
+ ctx.onDispose(() => {
4794
+ this._flowLock?.release();
4795
+ this._flowLock = void 0;
4796
+ });
4797
+ const tryHandleInvitation = async () => {
4798
+ const admissionRequest = await protocol.createAdmissionRequest(deviceProfile);
4799
+ if (admissionRequest.space) {
4800
+ try {
4801
+ await this._handleSpaceInvitationFlow(ctx, guardedState, admissionRequest.space, spaceId);
4802
+ } catch (error) {
4803
+ if (error instanceof EdgeCallFailedError2) {
4804
+ log14.info("join space with edge unsuccessful", {
4805
+ reason: error.message,
4806
+ retryable: error.isRetryable,
4807
+ after: error.retryAfterMs ?? this._calculateNextRetryMs()
4808
+ }, {
4809
+ F: __dxlog_file17,
4810
+ L: 95,
4811
+ S: this,
4812
+ C: (f, a) => f(...a)
4813
+ });
4814
+ if (error.isRetryable) {
4815
+ scheduleTask5(ctx, tryHandleInvitation, error.retryAfterMs ?? this._calculateNextRetryMs());
4816
+ }
4817
+ } else {
4818
+ log14.info("failed to handle invitation with edge", {
4819
+ error
4820
+ }, {
4821
+ F: __dxlog_file17,
4822
+ L: 104,
4823
+ S: this,
4824
+ C: (f, a) => f(...a)
4825
+ });
4826
+ scheduleTask5(ctx, tryHandleInvitation, this._calculateNextRetryMs());
4827
+ }
4828
+ }
4829
+ }
4830
+ };
4831
+ scheduleMicroTask3(ctx, tryHandleInvitation);
4832
+ }
4833
+ async _handleSpaceInvitationFlow(ctx, guardedState, admissionRequest, spaceId) {
4834
+ try {
4835
+ log14("edge invitation flow", void 0, {
4836
+ F: __dxlog_file17,
4837
+ L: 120,
4838
+ S: this,
4839
+ C: (f, a) => f(...a)
4840
+ });
4841
+ this._flowLock = await tryAcquireBeforeContextDisposed(ctx, guardedState.mutex);
4842
+ log14("edge invitation flow acquired the lock", void 0, {
4843
+ F: __dxlog_file17,
4844
+ L: 122,
4845
+ S: this,
4846
+ C: (f, a) => f(...a)
4847
+ });
4848
+ guardedState.set(this, Invitation4.State.CONNECTING);
4849
+ const response = await this._joinSpaceByInvitation(guardedState, spaceId, {
4850
+ identityKey: admissionRequest.identityKey.toHex(),
4851
+ invitationId: guardedState.current.invitationId
4852
+ });
4853
+ const admissionResponse = await this._mapToAdmissionResponse(response);
4854
+ await this._callbacks.onInvitationSuccess(admissionResponse, {
4855
+ space: admissionRequest
4856
+ });
4857
+ } catch (error) {
4858
+ guardedState.set(this, Invitation4.State.ERROR);
4859
+ throw error;
4860
+ } finally {
4861
+ this._flowLock?.release();
4862
+ this._flowLock = void 0;
4863
+ }
4864
+ }
4865
+ async _mapToAdmissionResponse(edgeResponse) {
4866
+ const credentialBytes = Buffer.from(edgeResponse.spaceMemberCredential, "base64");
4867
+ const codec = schema3.getCodecForType("dxos.halo.credentials.Credential");
4868
+ return {
4869
+ space: {
4870
+ credential: codec.decode(credentialBytes)
4871
+ }
4872
+ };
4873
+ }
4874
+ async _joinSpaceByInvitation(guardedState, spaceId, request) {
4875
+ invariant11(this._client, void 0, {
4876
+ F: __dxlog_file17,
4877
+ L: 157,
4878
+ S: this,
4879
+ A: [
4880
+ "this._client",
4881
+ ""
4882
+ ]
4883
+ });
4884
+ try {
4885
+ return await this._client.joinSpaceByInvitation(spaceId, request);
4886
+ } catch (error) {
4887
+ if (error instanceof EdgeAuthChallengeError) {
4888
+ guardedState.set(this, Invitation4.State.AUTHENTICATING);
4889
+ const publicKey = guardedState.current.guestKeypair?.publicKey;
4890
+ const privateKey = guardedState.current.guestKeypair?.privateKey;
4891
+ if (!privateKey || !publicKey) {
4892
+ throw error;
4893
+ }
4894
+ const signature = await ed25519Signature(privateKey, Buffer.from(error.challenge, "base64"));
4895
+ request.signature = Buffer.from(signature).toString("base64");
4896
+ return this._client.joinSpaceByInvitation(spaceId, request);
4897
+ } else {
4898
+ throw error;
4899
+ }
4900
+ }
4901
+ }
4902
+ hasFlowLock() {
4903
+ return this._flowLock != null;
4904
+ }
4905
+ _calculateNextRetryMs() {
4906
+ return this._retryInterval + Math.random() * this._retryJitter;
4907
+ }
4908
+ };
4909
+
4687
4910
  // packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts
4688
- var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts";
4911
+ import { Trigger as Trigger5 } from "@dxos/async";
4912
+ import { cancelWithContext as cancelWithContext4, Context as Context6 } from "@dxos/context";
4913
+ import { invariant as invariant12 } from "@dxos/invariant";
4914
+ import { log as log15 } from "@dxos/log";
4915
+ import { InvalidInvitationExtensionRoleError } from "@dxos/protocols";
4916
+ import { schema as schema4 } from "@dxos/protocols/proto";
4917
+ import { InvitationOptions } from "@dxos/protocols/proto/dxos/halo/invitations";
4918
+ import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
4919
+ var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts";
4689
4920
  var OPTIONS_TIMEOUT = 1e4;
4690
4921
  var InvitationGuestExtension = class extends RpcExtension2 {
4691
4922
  constructor(_invitationFlowMutex, _callbacks) {
4692
4923
  super({
4693
4924
  requested: {
4694
- InvitationHostService: schema3.getService("dxos.halo.invitations.InvitationHostService")
4925
+ InvitationHostService: schema4.getService("dxos.halo.invitations.InvitationHostService")
4695
4926
  },
4696
4927
  exposed: {
4697
- InvitationHostService: schema3.getService("dxos.halo.invitations.InvitationHostService")
4928
+ InvitationHostService: schema4.getService("dxos.halo.invitations.InvitationHostService")
4698
4929
  }
4699
4930
  });
4700
4931
  this._invitationFlowMutex = _invitationFlowMutex;
4701
4932
  this._callbacks = _callbacks;
4702
4933
  this._ctx = new Context6(void 0, {
4703
- F: __dxlog_file17,
4704
- L: 34
4934
+ F: __dxlog_file18,
4935
+ L: 38
4705
4936
  });
4706
4937
  this._remoteOptionsTrigger = new Trigger5();
4707
4938
  this._invitationFlowLock = null;
@@ -4713,9 +4944,9 @@ var InvitationGuestExtension = class extends RpcExtension2 {
4713
4944
  return {
4714
4945
  InvitationHostService: {
4715
4946
  options: async (options) => {
4716
- invariant11(!this._remoteOptions, "Remote options already set.", {
4717
- F: __dxlog_file17,
4718
- L: 64,
4947
+ invariant12(!this._remoteOptions, "Remote options already set.", {
4948
+ F: __dxlog_file18,
4949
+ L: 68,
4719
4950
  S: this,
4720
4951
  A: [
4721
4952
  "!this._remoteOptions",
@@ -4740,34 +4971,34 @@ var InvitationGuestExtension = class extends RpcExtension2 {
4740
4971
  async onOpen(context) {
4741
4972
  await super.onOpen(context);
4742
4973
  try {
4743
- log14("guest acquire lock", void 0, {
4744
- F: __dxlog_file17,
4745
- L: 85,
4974
+ log15("guest acquire lock", void 0, {
4975
+ F: __dxlog_file18,
4976
+ L: 89,
4746
4977
  S: this,
4747
4978
  C: (f, a) => f(...a)
4748
4979
  });
4749
4980
  this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
4750
- log14("guest lock acquired", void 0, {
4751
- F: __dxlog_file17,
4752
- L: 87,
4981
+ log15("guest lock acquired", void 0, {
4982
+ F: __dxlog_file18,
4983
+ L: 91,
4753
4984
  S: this,
4754
4985
  C: (f, a) => f(...a)
4755
4986
  });
4756
4987
  await cancelWithContext4(this._ctx, this.rpc.InvitationHostService.options({
4757
4988
  role: InvitationOptions.Role.GUEST
4758
4989
  }));
4759
- log14("options sent", void 0, {
4760
- F: __dxlog_file17,
4761
- L: 92,
4990
+ log15("options sent", void 0, {
4991
+ F: __dxlog_file18,
4992
+ L: 96,
4762
4993
  S: this,
4763
4994
  C: (f, a) => f(...a)
4764
4995
  });
4765
4996
  await cancelWithContext4(this._ctx, this._remoteOptionsTrigger.wait({
4766
4997
  timeout: OPTIONS_TIMEOUT
4767
4998
  }));
4768
- log14("options received", void 0, {
4769
- F: __dxlog_file17,
4770
- L: 94,
4999
+ log15("options received", void 0, {
5000
+ F: __dxlog_file18,
5001
+ L: 98,
4771
5002
  S: this,
4772
5003
  C: (f, a) => f(...a)
4773
5004
  });
@@ -4799,9 +5030,9 @@ var InvitationGuestExtension = class extends RpcExtension2 {
4799
5030
  if (this._invitationFlowLock != null) {
4800
5031
  this._invitationFlowLock.release();
4801
5032
  this._invitationFlowLock = null;
4802
- log14("invitation flow lock released", void 0, {
4803
- F: __dxlog_file17,
4804
- L: 127,
5033
+ log15("invitation flow lock released", void 0, {
5034
+ F: __dxlog_file18,
5035
+ L: 131,
4805
5036
  S: this,
4806
5037
  C: (f, a) => f(...a)
4807
5038
  });
@@ -4810,35 +5041,35 @@ var InvitationGuestExtension = class extends RpcExtension2 {
4810
5041
  };
4811
5042
 
4812
5043
  // packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts
4813
- import { Trigger as Trigger6, scheduleTask as scheduleTask5 } from "@dxos/async";
5044
+ import { Trigger as Trigger6, scheduleTask as scheduleTask6 } from "@dxos/async";
4814
5045
  import { cancelWithContext as cancelWithContext5, Context as Context7 } from "@dxos/context";
4815
5046
  import { randomBytes, verify } from "@dxos/crypto";
4816
- import { invariant as invariant12, InvariantViolation } from "@dxos/invariant";
5047
+ import { invariant as invariant13, InvariantViolation } from "@dxos/invariant";
4817
5048
  import { PublicKey as PublicKey9 } from "@dxos/keys";
4818
- import { log as log15 } from "@dxos/log";
5049
+ import { log as log16 } from "@dxos/log";
4819
5050
  import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError2, trace as trace6 } from "@dxos/protocols";
4820
- import { schema as schema4 } from "@dxos/protocols/proto";
4821
- import { Invitation as Invitation4 } from "@dxos/protocols/proto/dxos/client/services";
5051
+ import { schema as schema5 } from "@dxos/protocols/proto";
5052
+ import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
4822
5053
  import { AuthenticationResponse, InvitationOptions as InvitationOptions2 } from "@dxos/protocols/proto/dxos/halo/invitations";
4823
5054
  import { RpcExtension as RpcExtension3 } from "@dxos/teleport";
4824
- var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts";
5055
+ var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts";
4825
5056
  var OPTIONS_TIMEOUT2 = 1e4;
4826
5057
  var MAX_OTP_ATTEMPTS = 3;
4827
5058
  var InvitationHostExtension = class extends RpcExtension3 {
4828
5059
  constructor(_invitationFlowMutex, _callbacks) {
4829
5060
  super({
4830
5061
  requested: {
4831
- InvitationHostService: schema4.getService("dxos.halo.invitations.InvitationHostService")
5062
+ InvitationHostService: schema5.getService("dxos.halo.invitations.InvitationHostService")
4832
5063
  },
4833
5064
  exposed: {
4834
- InvitationHostService: schema4.getService("dxos.halo.invitations.InvitationHostService")
5065
+ InvitationHostService: schema5.getService("dxos.halo.invitations.InvitationHostService")
4835
5066
  }
4836
5067
  });
4837
5068
  this._invitationFlowMutex = _invitationFlowMutex;
4838
5069
  this._callbacks = _callbacks;
4839
5070
  this._ctx = new Context7(void 0, {
4840
- F: __dxlog_file18,
4841
- L: 53
5071
+ F: __dxlog_file19,
5072
+ L: 57
4842
5073
  });
4843
5074
  this._remoteOptionsTrigger = new Trigger6();
4844
5075
  this._challenge = void 0;
@@ -4857,9 +5088,9 @@ var InvitationHostExtension = class extends RpcExtension3 {
4857
5088
  // Perhaps in the future we will have more complex logic here.
4858
5089
  InvitationHostService: {
4859
5090
  options: async (options) => {
4860
- invariant12(!this._remoteOptions, "Remote options already set.", {
4861
- F: __dxlog_file18,
4862
- L: 102,
5091
+ invariant13(!this._remoteOptions, "Remote options already set.", {
5092
+ F: __dxlog_file19,
5093
+ L: 106,
4863
5094
  S: this,
4864
5095
  A: [
4865
5096
  "!this._remoteOptions",
@@ -4872,48 +5103,48 @@ var InvitationHostExtension = class extends RpcExtension3 {
4872
5103
  introduce: async (request) => {
4873
5104
  const { profile, invitationId } = request;
4874
5105
  const traceId = PublicKey9.random().toHex();
4875
- log15.trace("dxos.sdk.invitation-handler.host.introduce", trace6.begin({
5106
+ log16.trace("dxos.sdk.invitation-handler.host.introduce", trace6.begin({
4876
5107
  id: traceId
4877
5108
  }), {
4878
- F: __dxlog_file18,
4879
- L: 110,
5109
+ F: __dxlog_file19,
5110
+ L: 114,
4880
5111
  S: this,
4881
5112
  C: (f, a) => f(...a)
4882
5113
  });
4883
5114
  const invitation = this._requireActiveInvitation();
4884
- this._assertInvitationState(Invitation4.State.CONNECTED);
5115
+ this._assertInvitationState(Invitation5.State.CONNECTED);
4885
5116
  if (invitationId !== invitation?.invitationId) {
4886
- log15.warn("incorrect invitationId", {
5117
+ log16.warn("incorrect invitationId", {
4887
5118
  expected: invitation.invitationId,
4888
5119
  actual: invitationId
4889
5120
  }, {
4890
- F: __dxlog_file18,
4891
- L: 115,
5121
+ F: __dxlog_file19,
5122
+ L: 119,
4892
5123
  S: this,
4893
5124
  C: (f, a) => f(...a)
4894
5125
  });
4895
5126
  this._callbacks.onError(new Error("Incorrect invitationId."));
4896
- scheduleTask5(this._ctx, () => this.close());
5127
+ scheduleTask6(this._ctx, () => this.close());
4897
5128
  return {
4898
- authMethod: Invitation4.AuthMethod.NONE
5129
+ authMethod: Invitation5.AuthMethod.NONE
4899
5130
  };
4900
5131
  }
4901
- log15("guest introduced themselves", {
5132
+ log16("guest introduced themselves", {
4902
5133
  guestProfile: profile
4903
5134
  }, {
4904
- F: __dxlog_file18,
4905
- L: 124,
5135
+ F: __dxlog_file19,
5136
+ L: 128,
4906
5137
  S: this,
4907
5138
  C: (f, a) => f(...a)
4908
5139
  });
4909
5140
  this.guestProfile = profile;
4910
- this._callbacks.onStateUpdate(Invitation4.State.READY_FOR_AUTHENTICATION);
4911
- this._challenge = invitation.authMethod === Invitation4.AuthMethod.KNOWN_PUBLIC_KEY ? randomBytes(32) : void 0;
4912
- log15.trace("dxos.sdk.invitation-handler.host.introduce", trace6.end({
5141
+ this._callbacks.onStateUpdate(Invitation5.State.READY_FOR_AUTHENTICATION);
5142
+ this._challenge = invitation.authMethod === Invitation5.AuthMethod.KNOWN_PUBLIC_KEY ? randomBytes(32) : void 0;
5143
+ log16.trace("dxos.sdk.invitation-handler.host.introduce", trace6.end({
4913
5144
  id: traceId
4914
5145
  }), {
4915
- F: __dxlog_file18,
4916
- L: 130,
5146
+ F: __dxlog_file19,
5147
+ L: 134,
4917
5148
  S: this,
4918
5149
  C: (f, a) => f(...a)
4919
5150
  });
@@ -4924,34 +5155,34 @@ var InvitationHostExtension = class extends RpcExtension3 {
4924
5155
  },
4925
5156
  authenticate: async ({ authCode: code, signedChallenge }) => {
4926
5157
  const traceId = PublicKey9.random().toHex();
4927
- log15.trace("dxos.sdk.invitation-handler.host.authenticate", trace6.begin({
5158
+ log16.trace("dxos.sdk.invitation-handler.host.authenticate", trace6.begin({
4928
5159
  id: traceId
4929
5160
  }), {
4930
- F: __dxlog_file18,
4931
- L: 139,
5161
+ F: __dxlog_file19,
5162
+ L: 143,
4932
5163
  S: this,
4933
5164
  C: (f, a) => f(...a)
4934
5165
  });
4935
5166
  const invitation = this._requireActiveInvitation();
4936
- log15("received authentication request", {
5167
+ log16("received authentication request", {
4937
5168
  authCode: code
4938
5169
  }, {
4939
- F: __dxlog_file18,
4940
- L: 142,
5170
+ F: __dxlog_file19,
5171
+ L: 146,
4941
5172
  S: this,
4942
5173
  C: (f, a) => f(...a)
4943
5174
  });
4944
5175
  let status = AuthenticationResponse.Status.OK;
4945
5176
  this._assertInvitationState([
4946
- Invitation4.State.AUTHENTICATING,
4947
- Invitation4.State.READY_FOR_AUTHENTICATION
5177
+ Invitation5.State.AUTHENTICATING,
5178
+ Invitation5.State.READY_FOR_AUTHENTICATION
4948
5179
  ]);
4949
- this._callbacks.onStateUpdate(Invitation4.State.AUTHENTICATING);
5180
+ this._callbacks.onStateUpdate(Invitation5.State.AUTHENTICATING);
4950
5181
  switch (invitation.authMethod) {
4951
- case Invitation4.AuthMethod.NONE: {
4952
- log15("authentication not required", void 0, {
4953
- F: __dxlog_file18,
4954
- L: 150,
5182
+ case Invitation5.AuthMethod.NONE: {
5183
+ log16("authentication not required", void 0, {
5184
+ F: __dxlog_file19,
5185
+ L: 154,
4955
5186
  S: this,
4956
5187
  C: (f, a) => f(...a)
4957
5188
  });
@@ -4959,7 +5190,7 @@ var InvitationHostExtension = class extends RpcExtension3 {
4959
5190
  status: AuthenticationResponse.Status.OK
4960
5191
  };
4961
5192
  }
4962
- case Invitation4.AuthMethod.SHARED_SECRET: {
5193
+ case Invitation5.AuthMethod.SHARED_SECRET: {
4963
5194
  if (invitation.authCode) {
4964
5195
  if (this.authenticationRetry++ > MAX_OTP_ATTEMPTS) {
4965
5196
  status = AuthenticationResponse.Status.INVALID_OPT_ATTEMPTS;
@@ -4971,7 +5202,7 @@ var InvitationHostExtension = class extends RpcExtension3 {
4971
5202
  }
4972
5203
  break;
4973
5204
  }
4974
- case Invitation4.AuthMethod.KNOWN_PUBLIC_KEY: {
5205
+ case Invitation5.AuthMethod.KNOWN_PUBLIC_KEY: {
4975
5206
  if (!invitation.guestKeypair) {
4976
5207
  status = AuthenticationResponse.Status.INTERNAL_ERROR;
4977
5208
  break;
@@ -4985,11 +5216,11 @@ var InvitationHostExtension = class extends RpcExtension3 {
4985
5216
  break;
4986
5217
  }
4987
5218
  default: {
4988
- log15.error("invalid authentication method", {
5219
+ log16.error("invalid authentication method", {
4989
5220
  authMethod: invitation.authMethod
4990
5221
  }, {
4991
- F: __dxlog_file18,
4992
- L: 188,
5222
+ F: __dxlog_file19,
5223
+ L: 192,
4993
5224
  S: this,
4994
5225
  C: (f, a) => f(...a)
4995
5226
  });
@@ -5002,19 +5233,19 @@ var InvitationHostExtension = class extends RpcExtension3 {
5002
5233
  AuthenticationResponse.Status.INVALID_OTP
5003
5234
  ].includes(status)) {
5004
5235
  this._callbacks.onError(new Error(`Authentication failed, with status=${status}`));
5005
- scheduleTask5(this._ctx, () => this.close());
5236
+ scheduleTask6(this._ctx, () => this.close());
5006
5237
  return {
5007
5238
  status
5008
5239
  };
5009
5240
  }
5010
- log15.trace("dxos.sdk.invitation-handler.host.authenticate", trace6.end({
5241
+ log16.trace("dxos.sdk.invitation-handler.host.authenticate", trace6.end({
5011
5242
  id: traceId,
5012
5243
  data: {
5013
5244
  status
5014
5245
  }
5015
5246
  }), {
5016
- F: __dxlog_file18,
5017
- L: 200,
5247
+ F: __dxlog_file19,
5248
+ L: 204,
5018
5249
  S: this,
5019
5250
  C: (f, a) => f(...a)
5020
5251
  });
@@ -5024,28 +5255,28 @@ var InvitationHostExtension = class extends RpcExtension3 {
5024
5255
  },
5025
5256
  admit: async (request) => {
5026
5257
  const traceId = PublicKey9.random().toHex();
5027
- log15.trace("dxos.sdk.invitation-handler.host.admit", trace6.begin({
5258
+ log16.trace("dxos.sdk.invitation-handler.host.admit", trace6.begin({
5028
5259
  id: traceId
5029
5260
  }), {
5030
- F: __dxlog_file18,
5031
- L: 206,
5261
+ F: __dxlog_file19,
5262
+ L: 210,
5032
5263
  S: this,
5033
5264
  C: (f, a) => f(...a)
5034
5265
  });
5035
5266
  const invitation = this._requireActiveInvitation();
5036
5267
  try {
5037
5268
  if (isAuthenticationRequired(invitation)) {
5038
- this._assertInvitationState(Invitation4.State.AUTHENTICATING);
5269
+ this._assertInvitationState(Invitation5.State.AUTHENTICATING);
5039
5270
  if (!this.authenticationPassed) {
5040
5271
  throw new Error("Not authenticated");
5041
5272
  }
5042
5273
  }
5043
5274
  const response = await this._callbacks.admit(request);
5044
- log15.trace("dxos.sdk.invitation-handler.host.admit", trace6.end({
5275
+ log16.trace("dxos.sdk.invitation-handler.host.admit", trace6.end({
5045
5276
  id: traceId
5046
5277
  }), {
5047
- F: __dxlog_file18,
5048
- L: 220,
5278
+ F: __dxlog_file19,
5279
+ L: 224,
5049
5280
  S: this,
5050
5281
  C: (f, a) => f(...a)
5051
5282
  });
@@ -5061,36 +5292,36 @@ var InvitationHostExtension = class extends RpcExtension3 {
5061
5292
  async onOpen(context) {
5062
5293
  await super.onOpen(context);
5063
5294
  try {
5064
- log15("host acquire lock", void 0, {
5065
- F: __dxlog_file18,
5066
- L: 235,
5295
+ log16("host acquire lock", void 0, {
5296
+ F: __dxlog_file19,
5297
+ L: 239,
5067
5298
  S: this,
5068
5299
  C: (f, a) => f(...a)
5069
5300
  });
5070
5301
  this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
5071
- log15("host lock acquired", void 0, {
5072
- F: __dxlog_file18,
5073
- L: 237,
5302
+ log16("host lock acquired", void 0, {
5303
+ F: __dxlog_file19,
5304
+ L: 241,
5074
5305
  S: this,
5075
5306
  C: (f, a) => f(...a)
5076
5307
  });
5077
5308
  const lastState = this._requireActiveInvitation().state;
5078
- this._callbacks.onStateUpdate(Invitation4.State.CONNECTING);
5309
+ this._callbacks.onStateUpdate(Invitation5.State.CONNECTING);
5079
5310
  await this.rpc.InvitationHostService.options({
5080
5311
  role: InvitationOptions2.Role.HOST
5081
5312
  });
5082
- log15("options sent", void 0, {
5083
- F: __dxlog_file18,
5084
- L: 241,
5313
+ log16("options sent", void 0, {
5314
+ F: __dxlog_file19,
5315
+ L: 245,
5085
5316
  S: this,
5086
5317
  C: (f, a) => f(...a)
5087
5318
  });
5088
5319
  await cancelWithContext5(this._ctx, this._remoteOptionsTrigger.wait({
5089
5320
  timeout: OPTIONS_TIMEOUT2
5090
5321
  }));
5091
- log15("options received", void 0, {
5092
- F: __dxlog_file18,
5093
- L: 243,
5322
+ log16("options received", void 0, {
5323
+ F: __dxlog_file19,
5324
+ L: 247,
5094
5325
  S: this,
5095
5326
  C: (f, a) => f(...a)
5096
5327
  });
@@ -5102,7 +5333,7 @@ var InvitationHostExtension = class extends RpcExtension3 {
5102
5333
  remotePeerId: context.remotePeerId
5103
5334
  });
5104
5335
  }
5105
- this._callbacks.onStateUpdate(Invitation4.State.CONNECTED);
5336
+ this._callbacks.onStateUpdate(Invitation5.State.CONNECTED);
5106
5337
  this._callbacks.onOpen(this._ctx, context);
5107
5338
  } catch (err) {
5108
5339
  if (this._invitationFlowLock != null) {
@@ -5116,7 +5347,7 @@ var InvitationHostExtension = class extends RpcExtension3 {
5116
5347
  _requireActiveInvitation() {
5117
5348
  const invitation = this._callbacks.activeInvitation;
5118
5349
  if (invitation == null) {
5119
- scheduleTask5(this._ctx, () => this.close());
5350
+ scheduleTask6(this._ctx, () => this.close());
5120
5351
  throw new Error("Active invitation not found");
5121
5352
  }
5122
5353
  return invitation;
@@ -5127,7 +5358,7 @@ var InvitationHostExtension = class extends RpcExtension3 {
5127
5358
  stateOrMany
5128
5359
  ];
5129
5360
  if (!validStates.includes(invitation.state)) {
5130
- scheduleTask5(this._ctx, () => this.close());
5361
+ scheduleTask6(this._ctx, () => this.close());
5131
5362
  throw new InvariantViolation(`Expected ${stateToString(invitation.state)} to be one of [${validStates.map(stateToString).join(", ")}]`);
5132
5363
  }
5133
5364
  }
@@ -5142,55 +5373,150 @@ var InvitationHostExtension = class extends RpcExtension3 {
5142
5373
  if (this._invitationFlowLock != null) {
5143
5374
  this._invitationFlowLock?.release();
5144
5375
  this._invitationFlowLock = null;
5145
- log15("invitation flow lock released", void 0, {
5146
- F: __dxlog_file18,
5147
- L: 298,
5376
+ log16("invitation flow lock released", void 0, {
5377
+ F: __dxlog_file19,
5378
+ L: 302,
5148
5379
  S: this,
5149
5380
  C: (f, a) => f(...a)
5150
5381
  });
5151
5382
  }
5152
5383
  }
5153
5384
  };
5154
- var isAuthenticationRequired = (invitation) => invitation.authMethod !== Invitation4.AuthMethod.NONE;
5385
+ var isAuthenticationRequired = (invitation) => invitation.authMethod !== Invitation5.AuthMethod.NONE;
5155
5386
 
5156
- // packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts
5157
- import { invariant as invariant13 } from "@dxos/invariant";
5158
- import { PublicKey as PublicKey10 } from "@dxos/keys";
5159
- import { log as log16 } from "@dxos/log";
5160
- import { InvitationOptions as InvitationOptions3 } from "@dxos/protocols/proto/dxos/halo/invitations";
5161
- import { ComplexSet as ComplexSet4 } from "@dxos/util";
5162
- var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts";
5163
- var InvitationTopology = class {
5164
- constructor(_role) {
5165
- this._role = _role;
5166
- this._seenPeers = new ComplexSet4(PublicKey10.hash);
5167
- }
5168
- init(controller) {
5169
- invariant13(!this._controller, "Already initialized.", {
5170
- F: __dxlog_file19,
5171
- L: 42,
5172
- S: this,
5173
- A: [
5174
- "!this._controller",
5175
- "'Already initialized.'"
5176
- ]
5177
- });
5178
- this._controller = controller;
5179
- }
5180
- update() {
5181
- invariant13(this._controller, "Not initialized.", {
5182
- F: __dxlog_file19,
5183
- L: 47,
5184
- S: this,
5185
- A: [
5186
- "this._controller",
5187
- "'Not initialized.'"
5188
- ]
5189
- });
5190
- const { ownPeerId, candidates, connected, allPeers } = this._controller.getState();
5191
- if (this._role === InvitationOptions3.Role.GUEST) {
5192
- return;
5193
- }
5387
+ // packages/sdk/client-services/src/packlets/invitations/invitation-state.ts
5388
+ import { Mutex as Mutex3 } from "@dxos/async";
5389
+ import { log as log17 } from "@dxos/log";
5390
+ import { Invitation as Invitation6 } from "@dxos/protocols/proto/dxos/client/services";
5391
+ var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-state.ts";
5392
+ var createGuardedInvitationState = (ctx, invitation, stream) => {
5393
+ const mutex = new Mutex3();
5394
+ let lastActiveLockHolder = null;
5395
+ let currentInvitation = {
5396
+ ...invitation
5397
+ };
5398
+ const isStateChangeAllowed = (lockHolder) => {
5399
+ if (ctx.disposed || lockHolder !== null && mutex.isLocked() && !lockHolder.hasFlowLock()) {
5400
+ return false;
5401
+ }
5402
+ return lockHolder == null || lastActiveLockHolder !== lockHolder || isNonTerminalState(currentInvitation.state);
5403
+ };
5404
+ return {
5405
+ mutex,
5406
+ get current() {
5407
+ return currentInvitation;
5408
+ },
5409
+ // disposing context prevents any further state updates
5410
+ complete: (newState) => {
5411
+ currentInvitation = {
5412
+ ...currentInvitation,
5413
+ ...newState
5414
+ };
5415
+ stream.next(currentInvitation);
5416
+ return ctx.dispose();
5417
+ },
5418
+ set: (lockHolder, newState) => {
5419
+ if (isStateChangeAllowed(lockHolder)) {
5420
+ logStateUpdate(currentInvitation, lockHolder, newState);
5421
+ currentInvitation = {
5422
+ ...currentInvitation,
5423
+ state: newState
5424
+ };
5425
+ stream.next(currentInvitation);
5426
+ lastActiveLockHolder = lockHolder;
5427
+ return true;
5428
+ }
5429
+ return false;
5430
+ },
5431
+ error: (lockHolder, error) => {
5432
+ if (isStateChangeAllowed(lockHolder)) {
5433
+ logStateUpdate(currentInvitation, lockHolder, Invitation6.State.ERROR);
5434
+ currentInvitation = {
5435
+ ...currentInvitation,
5436
+ state: Invitation6.State.ERROR
5437
+ };
5438
+ stream.next(currentInvitation);
5439
+ stream.error(error);
5440
+ lastActiveLockHolder = lockHolder;
5441
+ return true;
5442
+ }
5443
+ return false;
5444
+ }
5445
+ };
5446
+ };
5447
+ var logStateUpdate = (invitation, actor, newState) => {
5448
+ if (isNonTerminalState(newState)) {
5449
+ log17("invitation state update", {
5450
+ actor: actor?.constructor.name,
5451
+ newState: stateToString(newState),
5452
+ oldState: stateToString(invitation.state)
5453
+ }, {
5454
+ F: __dxlog_file20,
5455
+ L: 89,
5456
+ S: void 0,
5457
+ C: (f, a) => f(...a)
5458
+ });
5459
+ } else {
5460
+ log17.info("invitation state update", {
5461
+ actor: actor?.constructor.name,
5462
+ newState: stateToString(newState),
5463
+ oldState: stateToString(invitation.state)
5464
+ }, {
5465
+ F: __dxlog_file20,
5466
+ L: 95,
5467
+ S: void 0,
5468
+ C: (f, a) => f(...a)
5469
+ });
5470
+ }
5471
+ };
5472
+ var isNonTerminalState = (currentState) => {
5473
+ return ![
5474
+ Invitation6.State.SUCCESS,
5475
+ Invitation6.State.ERROR,
5476
+ Invitation6.State.CANCELLED,
5477
+ Invitation6.State.TIMEOUT,
5478
+ Invitation6.State.EXPIRED
5479
+ ].includes(currentState);
5480
+ };
5481
+
5482
+ // packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts
5483
+ import { invariant as invariant14 } from "@dxos/invariant";
5484
+ import { PublicKey as PublicKey10 } from "@dxos/keys";
5485
+ import { log as log18 } from "@dxos/log";
5486
+ import { InvitationOptions as InvitationOptions3 } from "@dxos/protocols/proto/dxos/halo/invitations";
5487
+ import { ComplexSet as ComplexSet4 } from "@dxos/util";
5488
+ var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts";
5489
+ var InvitationTopology = class {
5490
+ constructor(_role) {
5491
+ this._role = _role;
5492
+ this._seenPeers = new ComplexSet4(PublicKey10.hash);
5493
+ }
5494
+ init(controller) {
5495
+ invariant14(!this._controller, "Already initialized.", {
5496
+ F: __dxlog_file21,
5497
+ L: 42,
5498
+ S: this,
5499
+ A: [
5500
+ "!this._controller",
5501
+ "'Already initialized.'"
5502
+ ]
5503
+ });
5504
+ this._controller = controller;
5505
+ }
5506
+ update() {
5507
+ invariant14(this._controller, "Not initialized.", {
5508
+ F: __dxlog_file21,
5509
+ L: 47,
5510
+ S: this,
5511
+ A: [
5512
+ "this._controller",
5513
+ "'Not initialized.'"
5514
+ ]
5515
+ });
5516
+ const { ownPeerId, candidates, connected, allPeers } = this._controller.getState();
5517
+ if (this._role === InvitationOptions3.Role.GUEST) {
5518
+ return;
5519
+ }
5194
5520
  if (connected.length > 0) {
5195
5521
  connected.forEach((c) => this._seenPeers.add(c));
5196
5522
  return;
@@ -5198,11 +5524,11 @@ var InvitationTopology = class {
5198
5524
  const firstUnknownPeer = candidates.find((peerId) => !this._seenPeers.has(peerId));
5199
5525
  this._seenPeers = new ComplexSet4(PublicKey10.hash, allPeers.filter((peerId) => this._seenPeers.has(peerId)));
5200
5526
  if (firstUnknownPeer != null) {
5201
- log16("invitation connect", {
5527
+ log18("invitation connect", {
5202
5528
  ownPeerId,
5203
5529
  remotePeerId: firstUnknownPeer
5204
5530
  }, {
5205
- F: __dxlog_file19,
5531
+ F: __dxlog_file21,
5206
5532
  L: 69,
5207
5533
  S: this,
5208
5534
  C: (f, a) => f(...a)
@@ -5212,8 +5538,8 @@ var InvitationTopology = class {
5212
5538
  }
5213
5539
  }
5214
5540
  async onOffer(peer) {
5215
- invariant13(this._controller, "Not initialized.", {
5216
- F: __dxlog_file19,
5541
+ invariant14(this._controller, "Not initialized.", {
5542
+ F: __dxlog_file21,
5217
5543
  L: 76,
5218
5544
  S: this,
5219
5545
  A: [
@@ -5232,20 +5558,21 @@ var InvitationTopology = class {
5232
5558
  };
5233
5559
 
5234
5560
  // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
5235
- var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts";
5561
+ var __dxlog_file22 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts";
5236
5562
  var metrics = _trace.metrics;
5237
5563
  var MAX_DELEGATED_INVITATION_HOST_TRIES = 3;
5238
5564
  var InvitationsHandler = class {
5239
5565
  /**
5240
5566
  * @internal
5241
5567
  */
5242
- constructor(_networkManager, _defaultTeleportParams) {
5568
+ constructor(_networkManager, _edgeClient, _connectionParams) {
5243
5569
  this._networkManager = _networkManager;
5244
- this._defaultTeleportParams = _defaultTeleportParams;
5570
+ this._edgeClient = _edgeClient;
5571
+ this._connectionParams = _connectionParams;
5245
5572
  }
5246
5573
  handleInvitationFlow(ctx, stream, protocol, invitation) {
5247
5574
  metrics.increment("dxos.invitation.created");
5248
- const guardedState = this._createGuardedState(ctx, invitation, stream);
5575
+ const guardedState = createGuardedInvitationState(ctx, invitation, stream);
5249
5576
  const createExtension = () => {
5250
5577
  const extension = new InvitationHostExtension(guardedState.mutex, {
5251
5578
  get activeInvitation() {
@@ -5258,9 +5585,9 @@ var InvitationsHandler = class {
5258
5585
  admit: async (admissionRequest) => {
5259
5586
  try {
5260
5587
  const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
5261
- invariant14(deviceKey, void 0, {
5262
- F: __dxlog_file20,
5263
- L: 94,
5588
+ invariant15(deviceKey, void 0, {
5589
+ F: __dxlog_file22,
5590
+ L: 100,
5264
5591
  S: this,
5265
5592
  A: [
5266
5593
  "deviceKey",
@@ -5282,44 +5609,44 @@ var InvitationsHandler = class {
5282
5609
  guardedState.error(extension, new ContextDisposedError3());
5283
5610
  }
5284
5611
  });
5285
- scheduleTask6(connectionCtx, async () => {
5612
+ scheduleTask7(connectionCtx, async () => {
5286
5613
  const traceId = PublicKey11.random().toHex();
5287
5614
  try {
5288
- log17.trace("dxos.sdk.invitations-handler.host.onOpen", trace7.begin({
5615
+ log19.trace("dxos.sdk.invitations-handler.host.onOpen", trace7.begin({
5289
5616
  id: traceId
5290
5617
  }), {
5291
- F: __dxlog_file20,
5292
- L: 119,
5618
+ F: __dxlog_file22,
5619
+ L: 125,
5293
5620
  S: this,
5294
5621
  C: (f, a) => f(...a)
5295
5622
  });
5296
- log17("connected", {
5623
+ log19("connected", {
5297
5624
  ...protocol.toJSON()
5298
5625
  }, {
5299
- F: __dxlog_file20,
5300
- L: 120,
5626
+ F: __dxlog_file22,
5627
+ L: 126,
5301
5628
  S: this,
5302
5629
  C: (f, a) => f(...a)
5303
5630
  });
5304
5631
  const deviceKey = await extension.completedTrigger.wait({
5305
5632
  timeout: invitation.timeout
5306
5633
  });
5307
- log17("admitted guest", {
5634
+ log19("admitted guest", {
5308
5635
  guest: deviceKey,
5309
5636
  ...protocol.toJSON()
5310
5637
  }, {
5311
- F: __dxlog_file20,
5312
- L: 122,
5638
+ F: __dxlog_file22,
5639
+ L: 128,
5313
5640
  S: this,
5314
5641
  C: (f, a) => f(...a)
5315
5642
  });
5316
- guardedState.set(extension, Invitation5.State.SUCCESS);
5643
+ guardedState.set(extension, Invitation7.State.SUCCESS);
5317
5644
  metrics.increment("dxos.invitation.success");
5318
- log17.trace("dxos.sdk.invitations-handler.host.onOpen", trace7.end({
5645
+ log19.trace("dxos.sdk.invitations-handler.host.onOpen", trace7.end({
5319
5646
  id: traceId
5320
5647
  }), {
5321
- F: __dxlog_file20,
5322
- L: 125,
5648
+ F: __dxlog_file22,
5649
+ L: 131,
5323
5650
  S: this,
5324
5651
  C: (f, a) => f(...a)
5325
5652
  });
@@ -5329,13 +5656,13 @@ var InvitationsHandler = class {
5329
5656
  }
5330
5657
  } catch (err) {
5331
5658
  if (err instanceof TimeoutError2) {
5332
- if (guardedState.set(extension, Invitation5.State.TIMEOUT)) {
5659
+ if (guardedState.set(extension, Invitation7.State.TIMEOUT)) {
5333
5660
  metrics.increment("dxos.invitation.timeout");
5334
- log17("timeout", {
5661
+ log19("timeout", {
5335
5662
  ...protocol.toJSON()
5336
5663
  }, {
5337
- F: __dxlog_file20,
5338
- L: 135,
5664
+ F: __dxlog_file22,
5665
+ L: 141,
5339
5666
  S: this,
5340
5667
  C: (f, a) => f(...a)
5341
5668
  });
@@ -5343,20 +5670,20 @@ var InvitationsHandler = class {
5343
5670
  } else {
5344
5671
  if (guardedState.error(extension, err)) {
5345
5672
  metrics.increment("dxos.invitation.failed");
5346
- log17.error("failed", err, {
5347
- F: __dxlog_file20,
5348
- L: 140,
5673
+ log19.error("failed", err, {
5674
+ F: __dxlog_file22,
5675
+ L: 146,
5349
5676
  S: this,
5350
5677
  C: (f, a) => f(...a)
5351
5678
  });
5352
5679
  }
5353
5680
  }
5354
- log17.trace("dxos.sdk.invitations-handler.host.onOpen", trace7.error({
5681
+ log19.trace("dxos.sdk.invitations-handler.host.onOpen", trace7.error({
5355
5682
  id: traceId,
5356
5683
  error: err
5357
5684
  }), {
5358
- F: __dxlog_file20,
5359
- L: 143,
5685
+ F: __dxlog_file22,
5686
+ L: 149,
5360
5687
  S: this,
5361
5688
  C: (f, a) => f(...a)
5362
5689
  });
@@ -5366,24 +5693,24 @@ var InvitationsHandler = class {
5366
5693
  },
5367
5694
  onError: (err) => {
5368
5695
  if (err instanceof InvalidInvitationExtensionRoleError3) {
5369
- log17("invalid role", {
5696
+ log19("invalid role", {
5370
5697
  ...err.context
5371
5698
  }, {
5372
- F: __dxlog_file20,
5373
- L: 151,
5699
+ F: __dxlog_file22,
5700
+ L: 157,
5374
5701
  S: this,
5375
5702
  C: (f, a) => f(...a)
5376
5703
  });
5377
5704
  return;
5378
5705
  }
5379
5706
  if (err instanceof TimeoutError2) {
5380
- if (guardedState.set(extension, Invitation5.State.TIMEOUT)) {
5707
+ if (guardedState.set(extension, Invitation7.State.TIMEOUT)) {
5381
5708
  metrics.increment("dxos.invitation.timeout");
5382
- log17("timeout", {
5709
+ log19("timeout", {
5383
5710
  err
5384
5711
  }, {
5385
- F: __dxlog_file20,
5386
- L: 157,
5712
+ F: __dxlog_file22,
5713
+ L: 163,
5387
5714
  S: this,
5388
5715
  C: (f, a) => f(...a)
5389
5716
  });
@@ -5391,9 +5718,9 @@ var InvitationsHandler = class {
5391
5718
  } else {
5392
5719
  if (guardedState.error(extension, err)) {
5393
5720
  metrics.increment("dxos.invitation.failed");
5394
- log17.error("failed", err, {
5395
- F: __dxlog_file20,
5396
- L: 162,
5721
+ log19.error("failed", err, {
5722
+ F: __dxlog_file22,
5723
+ L: 168,
5397
5724
  S: this,
5398
5725
  C: (f, a) => f(...a)
5399
5726
  });
@@ -5405,33 +5732,33 @@ var InvitationsHandler = class {
5405
5732
  };
5406
5733
  if (invitation.lifetime && invitation.created) {
5407
5734
  if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
5408
- log17.warn("invitation has already expired", void 0, {
5409
- F: __dxlog_file20,
5410
- L: 173,
5735
+ log19.warn("invitation has already expired", void 0, {
5736
+ F: __dxlog_file22,
5737
+ L: 179,
5411
5738
  S: this,
5412
5739
  C: (f, a) => f(...a)
5413
5740
  });
5414
5741
  } else {
5415
- scheduleTask6(ctx, async () => {
5742
+ scheduleTask7(ctx, async () => {
5416
5743
  await swarmConnection.close();
5417
- guardedState.set(null, Invitation5.State.EXPIRED);
5744
+ guardedState.set(null, Invitation7.State.EXPIRED);
5418
5745
  metrics.increment("dxos.invitation.expired");
5419
5746
  await ctx.dispose();
5420
5747
  }, invitation.created.getTime() + invitation.lifetime * 1e3 - Date.now());
5421
5748
  }
5422
5749
  }
5423
5750
  let swarmConnection;
5424
- scheduleTask6(ctx, async () => {
5751
+ scheduleTask7(ctx, async () => {
5425
5752
  swarmConnection = await this._joinSwarm(ctx, invitation, InvitationOptions4.Role.HOST, createExtension);
5426
- guardedState.set(null, Invitation5.State.CONNECTING);
5753
+ guardedState.set(null, Invitation7.State.CONNECTING);
5427
5754
  });
5428
5755
  }
5429
5756
  acceptInvitation(ctx, stream, protocol, invitation, otpEnteredTrigger, deviceProfile) {
5430
5757
  const { timeout = INVITATION_TIMEOUT } = invitation;
5431
5758
  if (deviceProfile) {
5432
- invariant14(invitation.kind === Invitation5.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
5433
- F: __dxlog_file20,
5434
- L: 207,
5759
+ invariant15(invitation.kind === Invitation7.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
5760
+ F: __dxlog_file22,
5761
+ L: 213,
5435
5762
  S: this,
5436
5763
  A: [
5437
5764
  "invitation.kind === Invitation.Kind.DEVICE",
@@ -5440,23 +5767,23 @@ var InvitationsHandler = class {
5440
5767
  });
5441
5768
  }
5442
5769
  const triedPeersIds = new ComplexSet5(PublicKey11.hash);
5443
- const guardedState = this._createGuardedState(ctx, invitation, stream);
5770
+ const guardedState = createGuardedInvitationState(ctx, invitation, stream);
5444
5771
  const shouldCancelInvitationFlow = (extension) => {
5445
5772
  const isLockedByAnotherConnection = guardedState.mutex.isLocked() && !extension.hasFlowLock();
5446
- log17("should cancel invitation flow", {
5773
+ log19("should cancel invitation flow", {
5447
5774
  isLockedByAnotherConnection,
5448
- invitationType: Invitation5.Type.DELEGATED,
5775
+ invitationType: Invitation7.Type.DELEGATED,
5449
5776
  triedPeers: triedPeersIds.size
5450
5777
  }, {
5451
- F: __dxlog_file20,
5452
- L: 215,
5778
+ F: __dxlog_file22,
5779
+ L: 221,
5453
5780
  S: this,
5454
5781
  C: (f, a) => f(...a)
5455
5782
  });
5456
5783
  if (isLockedByAnotherConnection) {
5457
5784
  return false;
5458
5785
  }
5459
- return invitation.type !== Invitation5.Type.DELEGATED || triedPeersIds.size >= MAX_DELEGATED_INVITATION_HOST_TRIES;
5786
+ return invitation.type !== Invitation7.Type.DELEGATED || triedPeersIds.size >= MAX_DELEGATED_INVITATION_HOST_TRIES;
5460
5787
  };
5461
5788
  let admitted = false;
5462
5789
  const createExtension = () => {
@@ -5471,12 +5798,12 @@ var InvitationsHandler = class {
5471
5798
  return;
5472
5799
  }
5473
5800
  connectionCtx.onDispose(async () => {
5474
- log17("extension disposed", {
5801
+ log19("extension disposed", {
5475
5802
  admitted,
5476
5803
  currentState: guardedState.current.state
5477
5804
  }, {
5478
- F: __dxlog_file20,
5479
- L: 243,
5805
+ F: __dxlog_file22,
5806
+ L: 249,
5480
5807
  S: this,
5481
5808
  C: (f, a) => f(...a)
5482
5809
  });
@@ -5487,35 +5814,35 @@ var InvitationsHandler = class {
5487
5814
  }
5488
5815
  }
5489
5816
  });
5490
- scheduleTask6(connectionCtx, async () => {
5817
+ scheduleTask7(connectionCtx, async () => {
5491
5818
  const traceId = PublicKey11.random().toHex();
5492
5819
  try {
5493
- log17.trace("dxos.sdk.invitations-handler.guest.onOpen", trace7.begin({
5820
+ log19.trace("dxos.sdk.invitations-handler.guest.onOpen", trace7.begin({
5494
5821
  id: traceId
5495
5822
  }), {
5496
- F: __dxlog_file20,
5497
- L: 255,
5823
+ F: __dxlog_file22,
5824
+ L: 261,
5498
5825
  S: this,
5499
5826
  C: (f, a) => f(...a)
5500
5827
  });
5501
- scheduleTask6(connectionCtx, () => {
5502
- guardedState.set(extension, Invitation5.State.TIMEOUT);
5828
+ scheduleTask7(connectionCtx, () => {
5829
+ guardedState.set(extension, Invitation7.State.TIMEOUT);
5503
5830
  extensionCtx.close();
5504
5831
  }, timeout);
5505
- log17("connected", {
5832
+ log19("connected", {
5506
5833
  ...protocol.toJSON()
5507
5834
  }, {
5508
- F: __dxlog_file20,
5509
- L: 266,
5835
+ F: __dxlog_file22,
5836
+ L: 272,
5510
5837
  S: this,
5511
5838
  C: (f, a) => f(...a)
5512
5839
  });
5513
- guardedState.set(extension, Invitation5.State.CONNECTED);
5514
- log17("introduce", {
5840
+ guardedState.set(extension, Invitation7.State.CONNECTED);
5841
+ log19("introduce", {
5515
5842
  ...protocol.toJSON()
5516
5843
  }, {
5517
- F: __dxlog_file20,
5518
- L: 270,
5844
+ F: __dxlog_file22,
5845
+ L: 276,
5519
5846
  S: this,
5520
5847
  C: (f, a) => f(...a)
5521
5848
  });
@@ -5523,33 +5850,33 @@ var InvitationsHandler = class {
5523
5850
  invitationId: invitation.invitationId,
5524
5851
  ...protocol.createIntroduction()
5525
5852
  });
5526
- log17("introduce response", {
5853
+ log19("introduce response", {
5527
5854
  ...protocol.toJSON(),
5528
5855
  response: introductionResponse
5529
5856
  }, {
5530
- F: __dxlog_file20,
5531
- L: 275,
5857
+ F: __dxlog_file22,
5858
+ L: 281,
5532
5859
  S: this,
5533
5860
  C: (f, a) => f(...a)
5534
5861
  });
5535
5862
  invitation.authMethod = introductionResponse.authMethod;
5536
5863
  if (isAuthenticationRequired(invitation)) {
5537
5864
  switch (invitation.authMethod) {
5538
- case Invitation5.AuthMethod.SHARED_SECRET:
5865
+ case Invitation7.AuthMethod.SHARED_SECRET:
5539
5866
  await this._handleGuestOtpAuth(extension, (state) => guardedState.set(extension, state), otpEnteredTrigger, {
5540
5867
  timeout
5541
5868
  });
5542
5869
  break;
5543
- case Invitation5.AuthMethod.KNOWN_PUBLIC_KEY:
5870
+ case Invitation7.AuthMethod.KNOWN_PUBLIC_KEY:
5544
5871
  await this._handleGuestKpkAuth(extension, (state) => guardedState.set(extension, state), invitation, introductionResponse);
5545
5872
  break;
5546
5873
  }
5547
5874
  }
5548
- log17("request admission", {
5875
+ log19("request admission", {
5549
5876
  ...protocol.toJSON()
5550
5877
  }, {
5551
- F: __dxlog_file20,
5552
- L: 301,
5878
+ F: __dxlog_file22,
5879
+ L: 307,
5553
5880
  S: this,
5554
5881
  C: (f, a) => f(...a)
5555
5882
  });
@@ -5557,54 +5884,54 @@ var InvitationsHandler = class {
5557
5884
  const admissionResponse = await extension.rpc.InvitationHostService.admit(admissionRequest);
5558
5885
  admitted = true;
5559
5886
  const result = await protocol.accept(admissionResponse, admissionRequest);
5560
- log17("admitted by host", {
5887
+ log19("admitted by host", {
5561
5888
  ...protocol.toJSON()
5562
5889
  }, {
5563
- F: __dxlog_file20,
5564
- L: 312,
5890
+ F: __dxlog_file22,
5891
+ L: 318,
5565
5892
  S: this,
5566
5893
  C: (f, a) => f(...a)
5567
5894
  });
5568
- await guardedState.complete({
5895
+ guardedState.complete({
5569
5896
  ...guardedState.current,
5570
5897
  ...result,
5571
- state: Invitation5.State.SUCCESS
5898
+ state: Invitation7.State.SUCCESS
5572
5899
  });
5573
- log17.trace("dxos.sdk.invitations-handler.guest.onOpen", trace7.end({
5900
+ log19.trace("dxos.sdk.invitations-handler.guest.onOpen", trace7.end({
5574
5901
  id: traceId
5575
5902
  }), {
5576
- F: __dxlog_file20,
5577
- L: 318,
5903
+ F: __dxlog_file22,
5904
+ L: 324,
5578
5905
  S: this,
5579
5906
  C: (f, a) => f(...a)
5580
5907
  });
5581
5908
  } catch (err) {
5582
5909
  if (err instanceof TimeoutError2) {
5583
- log17("timeout", {
5910
+ log19("timeout", {
5584
5911
  ...protocol.toJSON()
5585
5912
  }, {
5586
- F: __dxlog_file20,
5587
- L: 321,
5913
+ F: __dxlog_file22,
5914
+ L: 327,
5588
5915
  S: this,
5589
5916
  C: (f, a) => f(...a)
5590
5917
  });
5591
- guardedState.set(extension, Invitation5.State.TIMEOUT);
5918
+ guardedState.set(extension, Invitation7.State.TIMEOUT);
5592
5919
  } else {
5593
- log17("auth failed", err, {
5594
- F: __dxlog_file20,
5595
- L: 324,
5920
+ log19("auth failed", err, {
5921
+ F: __dxlog_file22,
5922
+ L: 330,
5596
5923
  S: this,
5597
5924
  C: (f, a) => f(...a)
5598
5925
  });
5599
5926
  guardedState.error(extension, err);
5600
5927
  }
5601
5928
  extensionCtx.close(err);
5602
- log17.trace("dxos.sdk.invitations-handler.guest.onOpen", trace7.error({
5929
+ log19.trace("dxos.sdk.invitations-handler.guest.onOpen", trace7.error({
5603
5930
  id: traceId,
5604
5931
  error: err
5605
5932
  }), {
5606
- F: __dxlog_file20,
5607
- L: 328,
5933
+ F: __dxlog_file22,
5934
+ L: 334,
5608
5935
  S: this,
5609
5936
  C: (f, a) => f(...a)
5610
5937
  });
@@ -5616,19 +5943,19 @@ var InvitationsHandler = class {
5616
5943
  return;
5617
5944
  }
5618
5945
  if (err instanceof TimeoutError2) {
5619
- log17("timeout", {
5946
+ log19("timeout", {
5620
5947
  ...protocol.toJSON()
5621
5948
  }, {
5622
- F: __dxlog_file20,
5623
- L: 337,
5949
+ F: __dxlog_file22,
5950
+ L: 343,
5624
5951
  S: this,
5625
5952
  C: (f, a) => f(...a)
5626
5953
  });
5627
- guardedState.set(extension, Invitation5.State.TIMEOUT);
5954
+ guardedState.set(extension, Invitation7.State.TIMEOUT);
5628
5955
  } else {
5629
- log17("auth failed", err, {
5630
- F: __dxlog_file20,
5631
- L: 340,
5956
+ log19("auth failed", err, {
5957
+ F: __dxlog_file22,
5958
+ L: 346,
5632
5959
  S: this,
5633
5960
  C: (f, a) => f(...a)
5634
5961
  });
@@ -5638,15 +5965,34 @@ var InvitationsHandler = class {
5638
5965
  });
5639
5966
  return extension;
5640
5967
  };
5641
- scheduleTask6(ctx, async () => {
5968
+ const edgeInvitationHandler = new EdgeInvitationHandler(this._connectionParams?.edgeInvitations, this._edgeClient, {
5969
+ onInvitationSuccess: async (admissionResponse, admissionRequest) => {
5970
+ const result = await protocol.accept(admissionResponse, admissionRequest);
5971
+ log19("admitted by edge", {
5972
+ ...protocol.toJSON()
5973
+ }, {
5974
+ F: __dxlog_file22,
5975
+ L: 358,
5976
+ S: this,
5977
+ C: (f, a) => f(...a)
5978
+ });
5979
+ guardedState.complete({
5980
+ ...guardedState.current,
5981
+ ...result,
5982
+ state: Invitation7.State.SUCCESS
5983
+ });
5984
+ }
5985
+ });
5986
+ edgeInvitationHandler.handle(ctx, guardedState, protocol, deviceProfile);
5987
+ scheduleTask7(ctx, async () => {
5642
5988
  const error = protocol.checkInvitation(invitation);
5643
5989
  if (error) {
5644
5990
  stream.error(error);
5645
5991
  await ctx.dispose();
5646
5992
  } else {
5647
- invariant14(invitation.swarmKey, void 0, {
5648
- F: __dxlog_file20,
5649
- L: 355,
5993
+ invariant15(invitation.swarmKey, void 0, {
5994
+ F: __dxlog_file22,
5995
+ L: 370,
5650
5996
  S: this,
5651
5997
  A: [
5652
5998
  "invitation.swarmKey",
@@ -5655,14 +6001,14 @@ var InvitationsHandler = class {
5655
6001
  });
5656
6002
  const timeoutInactive = () => {
5657
6003
  if (guardedState.mutex.isLocked()) {
5658
- scheduleTask6(ctx, timeoutInactive, timeout);
6004
+ scheduleTask7(ctx, timeoutInactive, timeout);
5659
6005
  } else {
5660
- guardedState.set(null, Invitation5.State.TIMEOUT);
6006
+ guardedState.set(null, Invitation7.State.TIMEOUT);
5661
6007
  }
5662
6008
  };
5663
- scheduleTask6(ctx, timeoutInactive, timeout);
6009
+ scheduleTask7(ctx, timeoutInactive, timeout);
5664
6010
  await this._joinSwarm(ctx, invitation, InvitationOptions4.Role.GUEST, createExtension);
5665
- guardedState.set(null, Invitation5.State.CONNECTING);
6011
+ guardedState.set(null, Invitation7.State.CONNECTING);
5666
6012
  }
5667
6013
  });
5668
6014
  }
@@ -5670,7 +6016,7 @@ var InvitationsHandler = class {
5670
6016
  let label;
5671
6017
  if (role === InvitationOptions4.Role.GUEST) {
5672
6018
  label = "invitation guest";
5673
- } else if (invitation.kind === Invitation5.Kind.DEVICE) {
6019
+ } else if (invitation.kind === Invitation7.Kind.DEVICE) {
5674
6020
  label = "invitation host for device";
5675
6021
  } else {
5676
6022
  label = `invitation host for space ${invitation.spaceKey?.truncate()}`;
@@ -5679,123 +6025,30 @@ var InvitationsHandler = class {
5679
6025
  topic: invitation.swarmKey,
5680
6026
  protocolProvider: createTeleportProtocolFactory(async (teleport) => {
5681
6027
  teleport.addExtension("dxos.halo.invitations", extensionFactory());
5682
- }, this._defaultTeleportParams),
6028
+ }, this._connectionParams?.teleport),
5683
6029
  topology: new InvitationTopology(role),
5684
6030
  label
5685
6031
  });
5686
6032
  ctx.onDispose(() => swarmConnection.close());
5687
6033
  return swarmConnection;
5688
6034
  }
5689
- /**
5690
- * A utility object for serializing invitation state changes by multiple concurrent
5691
- * invitation flow connections.
5692
- */
5693
- _createGuardedState(ctx, invitation, stream) {
5694
- const mutex = new Mutex3();
5695
- let lastActiveExtension = null;
5696
- let currentInvitation = {
5697
- ...invitation
5698
- };
5699
- const isStateChangeAllowed = (extension) => {
5700
- if (ctx.disposed || extension !== null && mutex.isLocked() && !extension.hasFlowLock()) {
5701
- return false;
5702
- }
5703
- return extension == null || lastActiveExtension !== extension || this._isNotTerminal(currentInvitation.state);
5704
- };
5705
- return {
5706
- mutex,
5707
- get current() {
5708
- return currentInvitation;
5709
- },
5710
- // disposing context prevents any further state updates
5711
- complete: (newState) => {
5712
- currentInvitation = {
5713
- ...currentInvitation,
5714
- ...newState
5715
- };
5716
- stream.next(currentInvitation);
5717
- return ctx.dispose();
5718
- },
5719
- set: (extension, newState) => {
5720
- if (isStateChangeAllowed(extension)) {
5721
- this._logStateUpdate(currentInvitation, extension, newState);
5722
- currentInvitation = {
5723
- ...currentInvitation,
5724
- state: newState
5725
- };
5726
- stream.next(currentInvitation);
5727
- lastActiveExtension = extension;
5728
- return true;
5729
- }
5730
- return false;
5731
- },
5732
- error: (extension, error) => {
5733
- if (isStateChangeAllowed(extension)) {
5734
- this._logStateUpdate(currentInvitation, extension, Invitation5.State.ERROR);
5735
- currentInvitation = {
5736
- ...currentInvitation,
5737
- state: Invitation5.State.ERROR
5738
- };
5739
- stream.next(currentInvitation);
5740
- stream.error(error);
5741
- lastActiveExtension = extension;
5742
- return true;
5743
- }
5744
- return false;
5745
- }
5746
- };
5747
- }
5748
- _logStateUpdate(invitation, actor, newState) {
5749
- if (this._isNotTerminal(newState)) {
5750
- log17("invitation state update", {
5751
- actor: actor?.constructor.name,
5752
- newState: stateToString(newState),
5753
- oldState: stateToString(invitation.state)
5754
- }, {
5755
- F: __dxlog_file20,
5756
- L: 460,
5757
- S: this,
5758
- C: (f, a) => f(...a)
5759
- });
5760
- } else {
5761
- log17("invitation state update", {
5762
- actor: actor?.constructor.name,
5763
- newState: stateToString(newState),
5764
- oldState: stateToString(invitation.state)
5765
- }, {
5766
- F: __dxlog_file20,
5767
- L: 466,
5768
- S: this,
5769
- C: (f, a) => f(...a)
5770
- });
5771
- }
5772
- }
5773
- _isNotTerminal(currentState) {
5774
- return ![
5775
- Invitation5.State.SUCCESS,
5776
- Invitation5.State.ERROR,
5777
- Invitation5.State.CANCELLED,
5778
- Invitation5.State.TIMEOUT,
5779
- Invitation5.State.EXPIRED
5780
- ].includes(currentState);
5781
- }
5782
6035
  async _handleGuestOtpAuth(extension, setState, authenticated, options) {
5783
6036
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
5784
- log17("guest waiting for authentication code...", void 0, {
5785
- F: __dxlog_file20,
5786
- L: 491,
6037
+ log19("guest waiting for authentication code...", void 0, {
6038
+ F: __dxlog_file22,
6039
+ L: 422,
5787
6040
  S: this,
5788
6041
  C: (f, a) => f(...a)
5789
6042
  });
5790
- setState(Invitation5.State.READY_FOR_AUTHENTICATION);
6043
+ setState(Invitation7.State.READY_FOR_AUTHENTICATION);
5791
6044
  const authCode = await authenticated.wait(options);
5792
- log17("sending authentication request", void 0, {
5793
- F: __dxlog_file20,
5794
- L: 495,
6045
+ log19("sending authentication request", void 0, {
6046
+ F: __dxlog_file22,
6047
+ L: 426,
5795
6048
  S: this,
5796
6049
  C: (f, a) => f(...a)
5797
6050
  });
5798
- setState(Invitation5.State.AUTHENTICATING);
6051
+ setState(Invitation7.State.AUTHENTICATING);
5799
6052
  const response = await extension.rpc.InvitationHostService.authenticate({
5800
6053
  authCode
5801
6054
  });
@@ -5806,11 +6059,11 @@ var InvitationsHandler = class {
5806
6059
  if (attempt === MAX_OTP_ATTEMPTS) {
5807
6060
  throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
5808
6061
  } else {
5809
- log17("retrying invalid code", {
6062
+ log19("retrying invalid code", {
5810
6063
  attempt
5811
6064
  }, {
5812
- F: __dxlog_file20,
5813
- L: 506,
6065
+ F: __dxlog_file22,
6066
+ L: 437,
5814
6067
  S: this,
5815
6068
  C: (f, a) => f(...a)
5816
6069
  });
@@ -5826,13 +6079,13 @@ var InvitationsHandler = class {
5826
6079
  if (introductionResponse.challenge == null) {
5827
6080
  throw new Error("challenge missing in the introduction");
5828
6081
  }
5829
- log17("sending authentication request", void 0, {
5830
- F: __dxlog_file20,
5831
- L: 525,
6082
+ log19("sending authentication request", void 0, {
6083
+ F: __dxlog_file22,
6084
+ L: 456,
5832
6085
  S: this,
5833
6086
  C: (f, a) => f(...a)
5834
6087
  });
5835
- setState(Invitation5.State.AUTHENTICATING);
6088
+ setState(Invitation7.State.AUTHENTICATING);
5836
6089
  const signature = sign(Buffer.from(introductionResponse.challenge), invitation.guestKeypair.privateKey);
5837
6090
  const response = await extension.rpc.InvitationHostService.authenticate({
5838
6091
  signedChallenge: signature
@@ -5948,14 +6201,14 @@ var InvitationsServiceImpl = class {
5948
6201
  };
5949
6202
 
5950
6203
  // packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts
5951
- import { createCancelDelegatedSpaceInvitationCredential, createDelegatedSpaceInvitationCredential, getCredentialAssertion as getCredentialAssertion4 } from "@dxos/credentials";
6204
+ import { createCancelDelegatedSpaceInvitationCredential, createDelegatedSpaceInvitationCredential, getCredentialAssertion as getCredentialAssertion5 } from "@dxos/credentials";
5952
6205
  import { writeMessages as writeMessages4 } from "@dxos/feed-store";
5953
- import { invariant as invariant15 } from "@dxos/invariant";
5954
- import { log as log18 } from "@dxos/log";
6206
+ import { invariant as invariant16 } from "@dxos/invariant";
6207
+ import { log as log20 } from "@dxos/log";
5955
6208
  import { AlreadyJoinedError as AlreadyJoinedError3, AuthorizationError as AuthorizationError2, InvalidInvitationError, SpaceNotFoundError as SpaceNotFoundError2 } from "@dxos/protocols";
5956
- import { Invitation as Invitation6 } from "@dxos/protocols/proto/dxos/client/services";
6209
+ import { Invitation as Invitation8 } from "@dxos/protocols/proto/dxos/client/services";
5957
6210
  import { SpaceMember as SpaceMember6 } from "@dxos/protocols/proto/dxos/halo/credentials";
5958
- var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
6211
+ var __dxlog_file23 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
5959
6212
  var SpaceInvitationProtocol = class {
5960
6213
  constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
5961
6214
  this._spaceManager = _spaceManager;
@@ -5983,27 +6236,47 @@ var SpaceInvitationProtocol = class {
5983
6236
  return void 0;
5984
6237
  }
5985
6238
  getInvitationContext() {
6239
+ invariant16(this._spaceKey, void 0, {
6240
+ F: __dxlog_file23,
6241
+ L: 63,
6242
+ S: this,
6243
+ A: [
6244
+ "this._spaceKey",
6245
+ ""
6246
+ ]
6247
+ });
6248
+ const space = this._spaceManager.spaces.get(this._spaceKey);
6249
+ invariant16(space, void 0, {
6250
+ F: __dxlog_file23,
6251
+ L: 65,
6252
+ S: this,
6253
+ A: [
6254
+ "space",
6255
+ ""
6256
+ ]
6257
+ });
5986
6258
  return {
5987
- kind: Invitation6.Kind.SPACE,
5988
- spaceKey: this._spaceKey
6259
+ kind: Invitation8.Kind.SPACE,
6260
+ spaceKey: this._spaceKey,
6261
+ spaceId: space.id
5989
6262
  };
5990
6263
  }
5991
6264
  async admit(invitation, request, guestProfile) {
5992
- invariant15(this._spaceKey && request.space, void 0, {
5993
- F: __dxlog_file21,
5994
- L: 74,
6265
+ invariant16(this._spaceKey && request.space, void 0, {
6266
+ F: __dxlog_file23,
6267
+ L: 78,
5995
6268
  S: this,
5996
6269
  A: [
5997
6270
  "this._spaceKey && request.space",
5998
6271
  ""
5999
6272
  ]
6000
6273
  });
6001
- log18("writing guest credentials", {
6274
+ log20("writing guest credentials", {
6002
6275
  host: this._signingContext.deviceKey,
6003
6276
  guest: request.space.deviceKey
6004
6277
  }, {
6005
- F: __dxlog_file21,
6006
- L: 75,
6278
+ F: __dxlog_file23,
6279
+ L: 79,
6007
6280
  S: this,
6008
6281
  C: (f, a) => f(...a)
6009
6282
  });
@@ -6023,9 +6296,9 @@ var SpaceInvitationProtocol = class {
6023
6296
  };
6024
6297
  }
6025
6298
  async delegate(invitation) {
6026
- invariant15(this._spaceKey, void 0, {
6027
- F: __dxlog_file21,
6028
- L: 95,
6299
+ invariant16(this._spaceKey, void 0, {
6300
+ F: __dxlog_file23,
6301
+ L: 99,
6029
6302
  S: this,
6030
6303
  A: [
6031
6304
  "this._spaceKey",
@@ -6033,19 +6306,19 @@ var SpaceInvitationProtocol = class {
6033
6306
  ]
6034
6307
  });
6035
6308
  const space = this._spaceManager.spaces.get(this._spaceKey);
6036
- invariant15(space, void 0, {
6037
- F: __dxlog_file21,
6038
- L: 97,
6309
+ invariant16(space, void 0, {
6310
+ F: __dxlog_file23,
6311
+ L: 101,
6039
6312
  S: this,
6040
6313
  A: [
6041
6314
  "space",
6042
6315
  ""
6043
6316
  ]
6044
6317
  });
6045
- if (invitation.authMethod === Invitation6.AuthMethod.KNOWN_PUBLIC_KEY) {
6046
- invariant15(invitation.guestKeypair?.publicKey, void 0, {
6047
- F: __dxlog_file21,
6048
- L: 99,
6318
+ if (invitation.authMethod === Invitation8.AuthMethod.KNOWN_PUBLIC_KEY) {
6319
+ invariant16(invitation.guestKeypair?.publicKey, void 0, {
6320
+ F: __dxlog_file23,
6321
+ L: 103,
6049
6322
  S: this,
6050
6323
  A: [
6051
6324
  "invitation.guestKeypair?.publicKey",
@@ -6053,12 +6326,12 @@ var SpaceInvitationProtocol = class {
6053
6326
  ]
6054
6327
  });
6055
6328
  }
6056
- log18("writing delegate space invitation", {
6329
+ log20("writing delegate space invitation", {
6057
6330
  host: this._signingContext.deviceKey,
6058
6331
  id: invitation.invitationId
6059
6332
  }, {
6060
- F: __dxlog_file21,
6061
- L: 102,
6333
+ F: __dxlog_file23,
6334
+ L: 106,
6062
6335
  S: this,
6063
6336
  C: (f, a) => f(...a)
6064
6337
  });
@@ -6069,11 +6342,11 @@ var SpaceInvitationProtocol = class {
6069
6342
  role: invitation.role ?? SpaceMember6.Role.ADMIN,
6070
6343
  expiresOn: invitation.lifetime ? new Date((invitation.created?.getTime() ?? Date.now()) + invitation.lifetime) : void 0,
6071
6344
  multiUse: invitation.multiUse ?? false,
6072
- guestKey: invitation.authMethod === Invitation6.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
6345
+ guestKey: invitation.authMethod === Invitation8.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
6073
6346
  });
6074
- invariant15(credential.credential, void 0, {
6075
- F: __dxlog_file21,
6076
- L: 122,
6347
+ invariant16(credential.credential, void 0, {
6348
+ F: __dxlog_file23,
6349
+ L: 126,
6077
6350
  S: this,
6078
6351
  A: [
6079
6352
  "credential.credential",
@@ -6086,18 +6359,18 @@ var SpaceInvitationProtocol = class {
6086
6359
  return credential.credential.credential.id;
6087
6360
  }
6088
6361
  async cancelDelegation(invitation) {
6089
- invariant15(this._spaceKey, void 0, {
6090
- F: __dxlog_file21,
6091
- L: 128,
6362
+ invariant16(this._spaceKey, void 0, {
6363
+ F: __dxlog_file23,
6364
+ L: 132,
6092
6365
  S: this,
6093
6366
  A: [
6094
6367
  "this._spaceKey",
6095
6368
  ""
6096
6369
  ]
6097
6370
  });
6098
- invariant15(invitation.type === Invitation6.Type.DELEGATED && invitation.delegationCredentialId, void 0, {
6099
- F: __dxlog_file21,
6100
- L: 129,
6371
+ invariant16(invitation.type === Invitation8.Type.DELEGATED && invitation.delegationCredentialId, void 0, {
6372
+ F: __dxlog_file23,
6373
+ L: 133,
6101
6374
  S: this,
6102
6375
  A: [
6103
6376
  "invitation.type === Invitation.Type.DELEGATED && invitation.delegationCredentialId",
@@ -6105,28 +6378,28 @@ var SpaceInvitationProtocol = class {
6105
6378
  ]
6106
6379
  });
6107
6380
  const space = this._spaceManager.spaces.get(this._spaceKey);
6108
- invariant15(space, void 0, {
6109
- F: __dxlog_file21,
6110
- L: 131,
6381
+ invariant16(space, void 0, {
6382
+ F: __dxlog_file23,
6383
+ L: 135,
6111
6384
  S: this,
6112
6385
  A: [
6113
6386
  "space",
6114
6387
  ""
6115
6388
  ]
6116
6389
  });
6117
- log18("cancelling delegated space invitation", {
6390
+ log20("cancelling delegated space invitation", {
6118
6391
  host: this._signingContext.deviceKey,
6119
6392
  id: invitation.invitationId
6120
6393
  }, {
6121
- F: __dxlog_file21,
6122
- L: 133,
6394
+ F: __dxlog_file23,
6395
+ L: 137,
6123
6396
  S: this,
6124
6397
  C: (f, a) => f(...a)
6125
6398
  });
6126
6399
  const credential = await createCancelDelegatedSpaceInvitationCredential(this._signingContext.credentialSigner, space.key, invitation.delegationCredentialId);
6127
- invariant15(credential.credential, void 0, {
6128
- F: __dxlog_file21,
6129
- L: 140,
6400
+ invariant16(credential.credential, void 0, {
6401
+ F: __dxlog_file23,
6402
+ L: 144,
6130
6403
  S: this,
6131
6404
  A: [
6132
6405
  "credential.credential",
@@ -6163,9 +6436,9 @@ var SpaceInvitationProtocol = class {
6163
6436
  };
6164
6437
  }
6165
6438
  async accept(response) {
6166
- invariant15(response.space, void 0, {
6167
- F: __dxlog_file21,
6168
- L: 175,
6439
+ invariant16(response.space, void 0, {
6440
+ F: __dxlog_file23,
6441
+ L: 179,
6169
6442
  S: this,
6170
6443
  A: [
6171
6444
  "response.space",
@@ -6173,19 +6446,19 @@ var SpaceInvitationProtocol = class {
6173
6446
  ]
6174
6447
  });
6175
6448
  const { credential, controlTimeframe, dataTimeframe } = response.space;
6176
- const assertion = getCredentialAssertion4(credential);
6177
- invariant15(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
6178
- F: __dxlog_file21,
6179
- L: 178,
6449
+ const assertion = getCredentialAssertion5(credential);
6450
+ invariant16(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
6451
+ F: __dxlog_file23,
6452
+ L: 182,
6180
6453
  S: this,
6181
6454
  A: [
6182
6455
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
6183
6456
  "'Invalid credential'"
6184
6457
  ]
6185
6458
  });
6186
- invariant15(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
6187
- F: __dxlog_file21,
6188
- L: 179,
6459
+ invariant16(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
6460
+ F: __dxlog_file23,
6461
+ L: 183,
6189
6462
  S: this,
6190
6463
  A: [
6191
6464
  "credential.subject.id.equals(this._signingContext.identityKey)",
@@ -6214,12 +6487,12 @@ import { AuthenticatingInvitation, AUTHENTICATION_CODE_LENGTH, CancellableInvita
6214
6487
  import { Context as Context8 } from "@dxos/context";
6215
6488
  import { generatePasscode } from "@dxos/credentials";
6216
6489
  import { hasInvitationExpired } from "@dxos/echo-pipeline";
6217
- import { invariant as invariant16 } from "@dxos/invariant";
6490
+ import { invariant as invariant17 } from "@dxos/invariant";
6218
6491
  import { PublicKey as PublicKey12 } from "@dxos/keys";
6219
- import { log as log19 } from "@dxos/log";
6220
- import { Invitation as Invitation7 } from "@dxos/protocols/proto/dxos/client/services";
6492
+ import { log as log21 } from "@dxos/log";
6493
+ import { Invitation as Invitation9 } from "@dxos/protocols/proto/dxos/client/services";
6221
6494
  import { SpaceMember as SpaceMember7 } from "@dxos/protocols/proto/dxos/halo/credentials";
6222
- var __dxlog_file22 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
6495
+ var __dxlog_file24 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
6223
6496
  var InvitationsManager = class {
6224
6497
  constructor(_invitationsHandler, _getHandler, _metadataStore) {
6225
6498
  this._invitationsHandler = _invitationsHandler;
@@ -6261,8 +6534,8 @@ var InvitationsManager = class {
6261
6534
  try {
6262
6535
  await this._persistIfRequired(handler, stream, invitation);
6263
6536
  } catch (err) {
6264
- log19.catch(err, void 0, {
6265
- F: __dxlog_file22,
6537
+ log21.catch(err, void 0, {
6538
+ F: __dxlog_file24,
6266
6539
  L: 82,
6267
6540
  S: this,
6268
6541
  C: (f, a) => f(...a)
@@ -6284,8 +6557,8 @@ var InvitationsManager = class {
6284
6557
  const persistentInvitations = this._metadataStore.getInvitations();
6285
6558
  const freshInvitations = persistentInvitations.filter((invitation) => !hasInvitationExpired(invitation));
6286
6559
  const loadTasks = freshInvitations.map((persistentInvitation) => {
6287
- invariant16(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
6288
- F: __dxlog_file22,
6560
+ invariant17(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
6561
+ F: __dxlog_file24,
6289
6562
  L: 103,
6290
6563
  S: this,
6291
6564
  A: [
@@ -6303,8 +6576,8 @@ var InvitationsManager = class {
6303
6576
  invitations: cInvitations.map((invitation) => invitation.get())
6304
6577
  };
6305
6578
  } catch (err) {
6306
- log19.catch(err, void 0, {
6307
- F: __dxlog_file22,
6579
+ log21.catch(err, void 0, {
6580
+ F: __dxlog_file24,
6308
6581
  L: 110,
6309
6582
  S: this,
6310
6583
  C: (f, a) => f(...a)
@@ -6335,14 +6608,14 @@ var InvitationsManager = class {
6335
6608
  return invitation;
6336
6609
  }
6337
6610
  async authenticate({ invitationId, authCode }) {
6338
- log19("authenticating...", void 0, {
6339
- F: __dxlog_file22,
6611
+ log21("authenticating...", void 0, {
6612
+ F: __dxlog_file24,
6340
6613
  L: 140,
6341
6614
  S: this,
6342
6615
  C: (f, a) => f(...a)
6343
6616
  });
6344
- invariant16(invitationId, void 0, {
6345
- F: __dxlog_file22,
6617
+ invariant17(invitationId, void 0, {
6618
+ F: __dxlog_file24,
6346
6619
  L: 141,
6347
6620
  S: this,
6348
6621
  A: [
@@ -6352,10 +6625,10 @@ var InvitationsManager = class {
6352
6625
  });
6353
6626
  const observable = this._acceptInvitations.get(invitationId);
6354
6627
  if (!observable) {
6355
- log19.warn("invalid invitation", {
6628
+ log21.warn("invalid invitation", {
6356
6629
  invitationId
6357
6630
  }, {
6358
- F: __dxlog_file22,
6631
+ F: __dxlog_file24,
6359
6632
  L: 144,
6360
6633
  S: this,
6361
6634
  C: (f, a) => f(...a)
@@ -6365,16 +6638,16 @@ var InvitationsManager = class {
6365
6638
  }
6366
6639
  }
6367
6640
  async cancelInvitation({ invitationId }) {
6368
- log19("cancelInvitation...", {
6641
+ log21("cancelInvitation...", {
6369
6642
  invitationId
6370
6643
  }, {
6371
- F: __dxlog_file22,
6644
+ F: __dxlog_file24,
6372
6645
  L: 151,
6373
6646
  S: this,
6374
6647
  C: (f, a) => f(...a)
6375
6648
  });
6376
- invariant16(invitationId, void 0, {
6377
- F: __dxlog_file22,
6649
+ invariant17(invitationId, void 0, {
6650
+ F: __dxlog_file24,
6378
6651
  L: 152,
6379
6652
  S: this,
6380
6653
  A: [
@@ -6387,7 +6660,7 @@ var InvitationsManager = class {
6387
6660
  if (created.get().persistent) {
6388
6661
  await this._metadataStore.removeInvitation(invitationId);
6389
6662
  }
6390
- if (created.get().type === Invitation7.Type.DELEGATED) {
6663
+ if (created.get().type === Invitation9.Type.DELEGATED) {
6391
6664
  const handler = this._getHandler(created.get());
6392
6665
  await handler.cancelDelegation(created.get());
6393
6666
  }
@@ -6421,8 +6694,8 @@ var InvitationsManager = class {
6421
6694
  }
6422
6695
  }
6423
6696
  _createInvitation(protocol, options) {
6424
- const { invitationId = PublicKey12.random().toHex(), type = Invitation7.Type.INTERACTIVE, authMethod = Invitation7.AuthMethod.SHARED_SECRET, state = Invitation7.State.INIT, timeout = INVITATION_TIMEOUT2, swarmKey = PublicKey12.random(), persistent = options?.authMethod !== Invitation7.AuthMethod.KNOWN_PUBLIC_KEY, created = /* @__PURE__ */ new Date(), guestKeypair = void 0, role = SpaceMember7.Role.ADMIN, lifetime = 86400, multiUse = false } = options ?? {};
6425
- const authCode = options?.authCode ?? (authMethod === Invitation7.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0);
6697
+ const { invitationId = PublicKey12.random().toHex(), type = Invitation9.Type.INTERACTIVE, authMethod = Invitation9.AuthMethod.SHARED_SECRET, state = Invitation9.State.INIT, timeout = INVITATION_TIMEOUT2, swarmKey = PublicKey12.random(), persistent = options?.authMethod !== Invitation9.AuthMethod.KNOWN_PUBLIC_KEY, created = /* @__PURE__ */ new Date(), guestKeypair = void 0, role = SpaceMember7.Role.ADMIN, lifetime = 86400, multiUse = false } = options ?? {};
6698
+ const authCode = options?.authCode ?? (authMethod === Invitation9.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0);
6426
6699
  return {
6427
6700
  invitationId,
6428
6701
  type,
@@ -6431,8 +6704,8 @@ var InvitationsManager = class {
6431
6704
  swarmKey,
6432
6705
  authCode,
6433
6706
  timeout,
6434
- persistent: persistent && type !== Invitation7.Type.DELEGATED,
6435
- guestKeypair: guestKeypair ?? (authMethod === Invitation7.AuthMethod.KNOWN_PUBLIC_KEY ? createAdmissionKeypair() : void 0),
6707
+ persistent: persistent && type !== Invitation9.Type.DELEGATED,
6708
+ guestKeypair: guestKeypair ?? (authMethod === Invitation9.AuthMethod.KNOWN_PUBLIC_KEY ? createAdmissionKeypair() : void 0),
6436
6709
  created,
6437
6710
  lifetime,
6438
6711
  role,
@@ -6449,14 +6722,14 @@ var InvitationsManager = class {
6449
6722
  void ctx.dispose();
6450
6723
  }
6451
6724
  }, {
6452
- F: __dxlog_file22,
6725
+ F: __dxlog_file24,
6453
6726
  L: 234
6454
6727
  });
6455
6728
  ctx.onDispose(() => {
6456
- log19("complete", {
6729
+ log21("complete", {
6457
6730
  ...handler.toJSON()
6458
6731
  }, {
6459
- F: __dxlog_file22,
6732
+ F: __dxlog_file24,
6460
6733
  L: 241,
6461
6734
  S: this,
6462
6735
  C: (f, a) => f(...a)
@@ -6469,7 +6742,7 @@ var InvitationsManager = class {
6469
6742
  onCancel: async () => {
6470
6743
  stream.next({
6471
6744
  ...invitation,
6472
- state: Invitation7.State.CANCELLED
6745
+ state: Invitation9.State.CANCELLED
6473
6746
  });
6474
6747
  await ctx.dispose();
6475
6748
  }
@@ -6486,41 +6759,41 @@ var InvitationsManager = class {
6486
6759
  const ctx = new Context8({
6487
6760
  onError: (err) => {
6488
6761
  if (err instanceof TimeoutError3) {
6489
- log19("timeout", {
6762
+ log21("timeout", {
6490
6763
  ...handler.toJSON()
6491
6764
  }, {
6492
- F: __dxlog_file22,
6765
+ F: __dxlog_file24,
6493
6766
  L: 261,
6494
6767
  S: this,
6495
6768
  C: (f, a) => f(...a)
6496
6769
  });
6497
6770
  stream.next({
6498
6771
  ...initialState,
6499
- state: Invitation7.State.TIMEOUT
6772
+ state: Invitation9.State.TIMEOUT
6500
6773
  });
6501
6774
  } else {
6502
- log19.warn("auth failed", err, {
6503
- F: __dxlog_file22,
6775
+ log21.warn("auth failed", err, {
6776
+ F: __dxlog_file24,
6504
6777
  L: 264,
6505
6778
  S: this,
6506
6779
  C: (f, a) => f(...a)
6507
6780
  });
6508
6781
  stream.next({
6509
6782
  ...initialState,
6510
- state: Invitation7.State.ERROR
6783
+ state: Invitation9.State.ERROR
6511
6784
  });
6512
6785
  }
6513
6786
  void ctx.dispose();
6514
6787
  }
6515
6788
  }, {
6516
- F: __dxlog_file22,
6789
+ F: __dxlog_file24,
6517
6790
  L: 258
6518
6791
  });
6519
6792
  ctx.onDispose(() => {
6520
- log19("complete", {
6793
+ log21("complete", {
6521
6794
  ...handler.toJSON()
6522
6795
  }, {
6523
- F: __dxlog_file22,
6796
+ F: __dxlog_file24,
6524
6797
  L: 271,
6525
6798
  S: this,
6526
6799
  C: (f, a) => f(...a)
@@ -6533,7 +6806,7 @@ var InvitationsManager = class {
6533
6806
  onCancel: async () => {
6534
6807
  stream.next({
6535
6808
  ...initialState,
6536
- state: Invitation7.State.CANCELLED
6809
+ state: Invitation9.State.CANCELLED
6537
6810
  });
6538
6811
  await ctx.dispose();
6539
6812
  },
@@ -6549,7 +6822,7 @@ var InvitationsManager = class {
6549
6822
  };
6550
6823
  }
6551
6824
  async _persistIfRequired(handler, changeStream, invitation) {
6552
- if (invitation.type === Invitation7.Type.DELEGATED && invitation.delegationCredentialId == null) {
6825
+ if (invitation.type === Invitation9.Type.DELEGATED && invitation.delegationCredentialId == null) {
6553
6826
  const delegationCredentialId = await handler.delegate(invitation);
6554
6827
  changeStream.next({
6555
6828
  ...invitation,
@@ -6564,8 +6837,8 @@ var InvitationsManager = class {
6564
6837
  try {
6565
6838
  await this._metadataStore.removeInvitation(invitation.invitationId);
6566
6839
  } catch (err) {
6567
- log19.catch(err, void 0, {
6568
- F: __dxlog_file22,
6840
+ log21.catch(err, void 0, {
6841
+ F: __dxlog_file24,
6569
6842
  L: 307,
6570
6843
  S: this,
6571
6844
  C: (f, a) => f(...a)
@@ -6582,14 +6855,14 @@ var InvitationsManager = class {
6582
6855
  // packages/sdk/client-services/src/packlets/locks/browser.ts
6583
6856
  import { asyncTimeout as asyncTimeout2, Trigger as Trigger8 } from "@dxos/async";
6584
6857
  import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
6585
- import { log as log20, logInfo as logInfo3 } from "@dxos/log";
6858
+ import { log as log22, logInfo as logInfo3 } from "@dxos/log";
6586
6859
  function _ts_decorate7(decorators, target, key, desc) {
6587
6860
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6588
6861
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
6589
6862
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6590
6863
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6591
6864
  }
6592
- var __dxlog_file23 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
6865
+ var __dxlog_file25 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
6593
6866
  var Message;
6594
6867
  (function(Message2) {
6595
6868
  Message2["ACQUIRING"] = "acquiring";
@@ -6611,29 +6884,29 @@ var Lock = class {
6611
6884
  message: "acquiring"
6612
6885
  });
6613
6886
  try {
6614
- log20("aquiring lock...", void 0, {
6615
- F: __dxlog_file23,
6887
+ log22("aquiring lock...", void 0, {
6888
+ F: __dxlog_file25,
6616
6889
  L: 42,
6617
6890
  S: this,
6618
6891
  C: (f, a) => f(...a)
6619
6892
  });
6620
6893
  await asyncTimeout2(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
6621
- log20("acquired lock", void 0, {
6622
- F: __dxlog_file23,
6894
+ log22("acquired lock", void 0, {
6895
+ F: __dxlog_file25,
6623
6896
  L: 44,
6624
6897
  S: this,
6625
6898
  C: (f, a) => f(...a)
6626
6899
  });
6627
6900
  } catch {
6628
- log20("stealing lock...", void 0, {
6629
- F: __dxlog_file23,
6901
+ log22("stealing lock...", void 0, {
6902
+ F: __dxlog_file25,
6630
6903
  L: 46,
6631
6904
  S: this,
6632
6905
  C: (f, a) => f(...a)
6633
6906
  });
6634
6907
  await this._requestLock(true);
6635
- log20("stolen lock", void 0, {
6636
- F: __dxlog_file23,
6908
+ log22("stolen lock", void 0, {
6909
+ F: __dxlog_file25,
6637
6910
  L: 48,
6638
6911
  S: this,
6639
6912
  C: (f, a) => f(...a)
@@ -6649,10 +6922,10 @@ var Lock = class {
6649
6922
  }
6650
6923
  }
6651
6924
  async _requestLock(steal = false) {
6652
- log20("requesting lock...", {
6925
+ log22("requesting lock...", {
6653
6926
  steal
6654
6927
  }, {
6655
- F: __dxlog_file23,
6928
+ F: __dxlog_file25,
6656
6929
  L: 63,
6657
6930
  S: this,
6658
6931
  C: (f, a) => f(...a)
@@ -6665,15 +6938,15 @@ var Lock = class {
6665
6938
  acquired.wake();
6666
6939
  this._releaseTrigger = new Trigger8();
6667
6940
  await this._releaseTrigger.wait();
6668
- log20("releasing lock...", void 0, {
6669
- F: __dxlog_file23,
6941
+ log22("releasing lock...", void 0, {
6942
+ F: __dxlog_file25,
6670
6943
  L: 72,
6671
6944
  S: this,
6672
6945
  C: (f, a) => f(...a)
6673
6946
  });
6674
6947
  await this._onRelease?.();
6675
- log20("released lock", void 0, {
6676
- F: __dxlog_file23,
6948
+ log22("released lock", void 0, {
6949
+ F: __dxlog_file25,
6677
6950
  L: 74,
6678
6951
  S: this,
6679
6952
  C: (f, a) => f(...a)
@@ -6682,10 +6955,10 @@ var Lock = class {
6682
6955
  await this._onRelease?.();
6683
6956
  });
6684
6957
  await acquired.wait();
6685
- log20("recieved lock", {
6958
+ log22("recieved lock", {
6686
6959
  steal
6687
6960
  }, {
6688
- F: __dxlog_file23,
6961
+ F: __dxlog_file25,
6689
6962
  L: 81,
6690
6963
  S: this,
6691
6964
  C: (f, a) => f(...a)
@@ -6777,19 +7050,19 @@ ClientRpcServer = _ts_decorate8([
6777
7050
  ], ClientRpcServer);
6778
7051
 
6779
7052
  // packages/sdk/client-services/src/packlets/services/service-context.ts
6780
- import { Mutex as Mutex4, scheduleMicroTask as scheduleMicroTask3, Trigger as Trigger9 } from "@dxos/async";
7053
+ import { Mutex as Mutex4, Trigger as Trigger9 } from "@dxos/async";
6781
7054
  import { Context as Context9, Resource as Resource6 } from "@dxos/context";
6782
- import { getCredentialAssertion as getCredentialAssertion5 } from "@dxos/credentials";
7055
+ import { getCredentialAssertion as getCredentialAssertion6 } from "@dxos/credentials";
6783
7056
  import { failUndefined as failUndefined2, warnAfterTimeout as warnAfterTimeout2 } from "@dxos/debug";
6784
7057
  import { EchoEdgeReplicator, EchoHost, MeshEchoReplicator, MetadataStore, SpaceManager, valueEncoding } from "@dxos/echo-pipeline";
6785
7058
  import { createChainEdgeIdentity, createEphemeralEdgeIdentity } from "@dxos/edge-client";
6786
7059
  import { FeedFactory, FeedStore } from "@dxos/feed-store";
6787
- import { invariant as invariant17 } from "@dxos/invariant";
7060
+ import { invariant as invariant18 } from "@dxos/invariant";
6788
7061
  import { Keyring } from "@dxos/keyring";
6789
7062
  import { PublicKey as PublicKey13 } from "@dxos/keys";
6790
- import { log as log21 } from "@dxos/log";
7063
+ import { log as log23 } from "@dxos/log";
6791
7064
  import { InvalidStorageVersionError, STORAGE_VERSION as STORAGE_VERSION2, trace as trace9 } from "@dxos/protocols";
6792
- import { Invitation as Invitation8 } from "@dxos/protocols/proto/dxos/client/services";
7065
+ import { Invitation as Invitation10 } from "@dxos/protocols/proto/dxos/client/services";
6793
7066
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
6794
7067
  import { trace as Trace3 } from "@dxos/tracing";
6795
7068
  import { safeInstanceof } from "@dxos/util";
@@ -6861,7 +7134,7 @@ function _using_ctx3() {
6861
7134
  }
6862
7135
  };
6863
7136
  }
6864
- var __dxlog_file24 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
7137
+ var __dxlog_file26 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
6865
7138
  var ServiceContext = class extends Resource6 {
6866
7139
  constructor(storage, level, networkManager, signalManager, _edgeConnection, _edgeHttpClient, _runtimeParams, _edgeFeatures) {
6867
7140
  super();
@@ -6907,58 +7180,15 @@ var ServiceContext = class extends Resource6 {
6907
7180
  devicePresenceOfflineTimeout: this._runtimeParams?.devicePresenceOfflineTimeout,
6908
7181
  devicePresenceAnnounceInterval: this._runtimeParams?.devicePresenceAnnounceInterval,
6909
7182
  edgeConnection: this._edgeConnection,
6910
- edgeFeatures: this._edgeFeatures,
6911
- callbacks: {
6912
- onIdentityConstruction: (identity) => {
6913
- if (this._edgeConnection) {
6914
- scheduleMicroTask3(this._ctx, async () => {
6915
- try {
6916
- var _usingCtx = _using_ctx3();
6917
- const _ = _usingCtx.u(await this._edgeIdentityUpdateMutex.acquire());
6918
- log21.info("Setting identity on edge connection", {
6919
- identity: identity.identityKey.toHex(),
6920
- oldIdentity: this._edgeConnection.identityKey,
6921
- swarms: this.networkManager.topics
6922
- }, {
6923
- F: __dxlog_file24,
6924
- L: 147,
6925
- S: this,
6926
- C: (f, a) => f(...a)
6927
- });
6928
- await warnAfterTimeout2(1e4, "Waiting for identity to be ready for edge connection", async () => {
6929
- await identity.ready();
6930
- });
6931
- invariant17(identity.deviceCredentialChain, void 0, {
6932
- F: __dxlog_file24,
6933
- L: 157,
6934
- S: this,
6935
- A: [
6936
- "identity.deviceCredentialChain",
6937
- ""
6938
- ]
6939
- });
6940
- this._edgeConnection.setIdentity(await createChainEdgeIdentity(identity.signer, identity.identityKey, identity.deviceKey, identity.deviceCredentialChain, []));
6941
- this.networkManager.setPeerInfo({
6942
- identityKey: identity.identityKey.toHex(),
6943
- peerKey: identity.deviceKey.toHex()
6944
- });
6945
- } catch (_) {
6946
- _usingCtx.e = _;
6947
- } finally {
6948
- _usingCtx.d();
6949
- }
6950
- });
6951
- }
6952
- }
6953
- }
7183
+ edgeFeatures: this._edgeFeatures
6954
7184
  });
6955
7185
  this.echoHost = new EchoHost({
6956
7186
  kv: this.level
6957
7187
  });
6958
7188
  this._meshReplicator = new MeshEchoReplicator();
6959
- this.invitations = new InvitationsHandler(this.networkManager, _runtimeParams?.invitationConnectionDefaultParams);
7189
+ this.invitations = new InvitationsHandler(this.networkManager, this._edgeHttpClient, _runtimeParams?.invitationConnectionDefaultParams);
6960
7190
  this.invitationsManager = new InvitationsManager(this.invitations, (invitation) => this.getInvitationHandler(invitation), this.metadataStore);
6961
- this._handlerFactories.set(Invitation8.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined2(), this._acceptIdentity.bind(this)));
7191
+ this._handlerFactories.set(Invitation10.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined2(), this._acceptIdentity.bind(this)));
6962
7192
  if (!this._runtimeParams?.disableP2pReplication) {
6963
7193
  this._meshReplicator = new MeshEchoReplicator();
6964
7194
  }
@@ -6970,24 +7200,23 @@ var ServiceContext = class extends Resource6 {
6970
7200
  }
6971
7201
  async _open(ctx) {
6972
7202
  await this._checkStorageVersion();
6973
- log21("opening...", void 0, {
6974
- F: __dxlog_file24,
6975
- L: 217,
7203
+ log23("opening...", void 0, {
7204
+ F: __dxlog_file26,
7205
+ L: 184,
6976
7206
  S: this,
6977
7207
  C: (f, a) => f(...a)
6978
7208
  });
6979
- log21.trace("dxos.sdk.service-context.open", trace9.begin({
7209
+ log23.trace("dxos.sdk.service-context.open", trace9.begin({
6980
7210
  id: this._instanceId
6981
7211
  }), {
6982
- F: __dxlog_file24,
6983
- L: 218,
7212
+ F: __dxlog_file26,
7213
+ L: 185,
6984
7214
  S: this,
6985
7215
  C: (f, a) => f(...a)
6986
7216
  });
6987
- if (this._edgeConnection) {
6988
- this._edgeConnection.setIdentity(await createEphemeralEdgeIdentity());
6989
- await this._edgeConnection.open();
6990
- }
7217
+ await this.identityManager.open(ctx);
7218
+ await this._setNetworkIdentity();
7219
+ await this._edgeConnection?.open();
6991
7220
  await this.signalManager.open();
6992
7221
  await this.networkManager.open();
6993
7222
  await this.echoHost.open(ctx);
@@ -6999,38 +7228,38 @@ var ServiceContext = class extends Resource6 {
6999
7228
  }
7000
7229
  await this.metadataStore.load();
7001
7230
  await this.spaceManager.open();
7002
- await this.identityManager.open(ctx);
7003
7231
  if (this.identityManager.identity) {
7232
+ await this.identityManager.identity.joinNetwork();
7004
7233
  await this._initialize(ctx);
7005
7234
  }
7006
7235
  const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
7007
- log21("loaded persistent invitations", {
7236
+ log23("loaded persistent invitations", {
7008
7237
  count: loadedInvitations.invitations?.length
7009
7238
  }, {
7010
- F: __dxlog_file24,
7011
- L: 245,
7239
+ F: __dxlog_file26,
7240
+ L: 213,
7012
7241
  S: this,
7013
7242
  C: (f, a) => f(...a)
7014
7243
  });
7015
- log21.trace("dxos.sdk.service-context.open", trace9.end({
7244
+ log23.trace("dxos.sdk.service-context.open", trace9.end({
7016
7245
  id: this._instanceId
7017
7246
  }), {
7018
- F: __dxlog_file24,
7019
- L: 247,
7247
+ F: __dxlog_file26,
7248
+ L: 215,
7020
7249
  S: this,
7021
7250
  C: (f, a) => f(...a)
7022
7251
  });
7023
- log21("opened", void 0, {
7024
- F: __dxlog_file24,
7025
- L: 248,
7252
+ log23("opened", void 0, {
7253
+ F: __dxlog_file26,
7254
+ L: 216,
7026
7255
  S: this,
7027
7256
  C: (f, a) => f(...a)
7028
7257
  });
7029
7258
  }
7030
7259
  async _close(ctx) {
7031
- log21("closing...", void 0, {
7032
- F: __dxlog_file24,
7033
- L: 252,
7260
+ log23("closing...", void 0, {
7261
+ F: __dxlog_file26,
7262
+ L: 220,
7034
7263
  S: this,
7035
7264
  C: (f, a) => f(...a)
7036
7265
  });
@@ -7046,26 +7275,28 @@ var ServiceContext = class extends Resource6 {
7046
7275
  await this.networkManager.close();
7047
7276
  await this.signalManager.close();
7048
7277
  await this._edgeConnection?.close();
7049
- log21("closed", void 0, {
7050
- F: __dxlog_file24,
7051
- L: 267,
7278
+ log23("closed", void 0, {
7279
+ F: __dxlog_file26,
7280
+ L: 235,
7052
7281
  S: this,
7053
7282
  C: (f, a) => f(...a)
7054
7283
  });
7055
7284
  }
7056
7285
  async createIdentity(params = {}) {
7057
7286
  const identity = await this.identityManager.createIdentity(params);
7287
+ await this._setNetworkIdentity();
7288
+ await identity.joinNetwork();
7058
7289
  await this._initialize(new Context9(void 0, {
7059
- F: __dxlog_file24,
7060
- L: 272
7290
+ F: __dxlog_file26,
7291
+ L: 242
7061
7292
  }));
7062
7293
  return identity;
7063
7294
  }
7064
7295
  getInvitationHandler(invitation) {
7065
7296
  const factory = this._handlerFactories.get(invitation.kind);
7066
- invariant17(factory, `Unknown invitation kind: ${invitation.kind}`, {
7067
- F: __dxlog_file24,
7068
- L: 278,
7297
+ invariant18(factory, `Unknown invitation kind: ${invitation.kind}`, {
7298
+ F: __dxlog_file26,
7299
+ L: 248,
7069
7300
  S: this,
7070
7301
  A: [
7071
7302
  "factory",
@@ -7083,10 +7314,15 @@ var ServiceContext = class extends Resource6 {
7083
7314
  }
7084
7315
  }
7085
7316
  async _acceptIdentity(params) {
7086
- const identity = await this.identityManager.acceptIdentity(params);
7317
+ const { identity, identityRecord } = await this.identityManager.prepareIdentity(params);
7318
+ await this._setNetworkIdentity({
7319
+ deviceCredential: params.authorizedDeviceCredential
7320
+ });
7321
+ await identity.joinNetwork();
7322
+ await this.identityManager.acceptIdentity(identity, identityRecord, params.deviceProfile);
7087
7323
  await this._initialize(new Context9(void 0, {
7088
- F: __dxlog_file24,
7089
- L: 294
7324
+ F: __dxlog_file26,
7325
+ L: 267
7090
7326
  }));
7091
7327
  return identity;
7092
7328
  }
@@ -7098,9 +7334,9 @@ var ServiceContext = class extends Resource6 {
7098
7334
  }
7099
7335
  // Called when identity is created.
7100
7336
  async _initialize(ctx) {
7101
- log21("initializing spaces...", void 0, {
7102
- F: __dxlog_file24,
7103
- L: 309,
7337
+ log23("initializing spaces...", void 0, {
7338
+ F: __dxlog_file26,
7339
+ L: 282,
7104
7340
  S: this,
7105
7341
  C: (f, a) => f(...a)
7106
7342
  });
@@ -7134,10 +7370,10 @@ var ServiceContext = class extends Resource6 {
7134
7370
  edgeFeatures: this._edgeFeatures
7135
7371
  });
7136
7372
  await this.dataSpaceManager.open();
7137
- this._handlerFactories.set(Invitation8.Kind.SPACE, (invitation) => {
7138
- invariant17(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
7139
- F: __dxlog_file24,
7140
- L: 339,
7373
+ this._handlerFactories.set(Invitation10.Kind.SPACE, (invitation) => {
7374
+ invariant18(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
7375
+ F: __dxlog_file26,
7376
+ L: 312,
7141
7377
  S: this,
7142
7378
  A: [
7143
7379
  "this.dataSpaceManager",
@@ -7149,7 +7385,7 @@ var ServiceContext = class extends Resource6 {
7149
7385
  this.initialized.wake();
7150
7386
  this._deviceSpaceSync = {
7151
7387
  processCredential: async (credential) => {
7152
- const assertion = getCredentialAssertion5(credential);
7388
+ const assertion = getCredentialAssertion6(credential);
7153
7389
  if (assertion["@type"] !== "dxos.halo.credentials.SpaceMember") {
7154
7390
  return;
7155
7391
  }
@@ -7157,33 +7393,33 @@ var ServiceContext = class extends Resource6 {
7157
7393
  return;
7158
7394
  }
7159
7395
  if (!this.dataSpaceManager) {
7160
- log21("dataSpaceManager not initialized yet, ignoring space admission", {
7396
+ log23("dataSpaceManager not initialized yet, ignoring space admission", {
7161
7397
  details: assertion
7162
7398
  }, {
7163
- F: __dxlog_file24,
7164
- L: 355,
7399
+ F: __dxlog_file26,
7400
+ L: 328,
7165
7401
  S: this,
7166
7402
  C: (f, a) => f(...a)
7167
7403
  });
7168
7404
  return;
7169
7405
  }
7170
7406
  if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
7171
- log21("space already exists, ignoring space admission", {
7407
+ log23("space already exists, ignoring space admission", {
7172
7408
  details: assertion
7173
7409
  }, {
7174
- F: __dxlog_file24,
7175
- L: 359,
7410
+ F: __dxlog_file26,
7411
+ L: 332,
7176
7412
  S: this,
7177
7413
  C: (f, a) => f(...a)
7178
7414
  });
7179
7415
  return;
7180
7416
  }
7181
7417
  try {
7182
- log21("accepting space recorded in halo", {
7418
+ log23("accepting space recorded in halo", {
7183
7419
  details: assertion
7184
7420
  }, {
7185
- F: __dxlog_file24,
7186
- L: 364,
7421
+ F: __dxlog_file26,
7422
+ L: 337,
7187
7423
  S: this,
7188
7424
  C: (f, a) => f(...a)
7189
7425
  });
@@ -7192,9 +7428,9 @@ var ServiceContext = class extends Resource6 {
7192
7428
  genesisFeedKey: assertion.genesisFeedKey
7193
7429
  });
7194
7430
  } catch (err) {
7195
- log21.catch(err, void 0, {
7196
- F: __dxlog_file24,
7197
- L: 370,
7431
+ log23.catch(err, void 0, {
7432
+ F: __dxlog_file26,
7433
+ L: 343,
7198
7434
  S: this,
7199
7435
  C: (f, a) => f(...a)
7200
7436
  });
@@ -7203,6 +7439,57 @@ var ServiceContext = class extends Resource6 {
7203
7439
  };
7204
7440
  await identity.space.spaceState.addCredentialProcessor(this._deviceSpaceSync);
7205
7441
  }
7442
+ async _setNetworkIdentity(params) {
7443
+ try {
7444
+ var _usingCtx = _using_ctx3();
7445
+ const _ = _usingCtx.u(await this._edgeIdentityUpdateMutex.acquire());
7446
+ let edgeIdentity;
7447
+ const identity = this.identityManager.identity;
7448
+ if (identity) {
7449
+ log23.info("Setting identity on edge connection", {
7450
+ identity: identity.identityKey.toHex(),
7451
+ swarms: this.networkManager.topics
7452
+ }, {
7453
+ F: __dxlog_file26,
7454
+ L: 357,
7455
+ S: this,
7456
+ C: (f, a) => f(...a)
7457
+ });
7458
+ if (params?.deviceCredential) {
7459
+ edgeIdentity = await createChainEdgeIdentity(identity.signer, identity.identityKey, identity.deviceKey, {
7460
+ credential: params.deviceCredential
7461
+ }, []);
7462
+ } else {
7463
+ await warnAfterTimeout2(1e4, "Waiting for identity to be ready for edge connection", async () => {
7464
+ await identity.ready();
7465
+ });
7466
+ invariant18(identity.deviceCredentialChain, void 0, {
7467
+ F: __dxlog_file26,
7468
+ L: 375,
7469
+ S: this,
7470
+ A: [
7471
+ "identity.deviceCredentialChain",
7472
+ ""
7473
+ ]
7474
+ });
7475
+ edgeIdentity = await createChainEdgeIdentity(identity.signer, identity.identityKey, identity.deviceKey, identity.deviceCredentialChain, []);
7476
+ }
7477
+ } else {
7478
+ edgeIdentity = await createEphemeralEdgeIdentity();
7479
+ }
7480
+ if (this._edgeConnection) {
7481
+ this._edgeConnection.setIdentity(edgeIdentity);
7482
+ }
7483
+ this.networkManager.setPeerInfo({
7484
+ identityKey: edgeIdentity.identityKey,
7485
+ peerKey: edgeIdentity.peerKey
7486
+ });
7487
+ } catch (_) {
7488
+ _usingCtx.e = _;
7489
+ } finally {
7490
+ _usingCtx.d();
7491
+ }
7492
+ }
7206
7493
  };
7207
7494
  _ts_decorate9([
7208
7495
  Trace3.span()
@@ -7315,11 +7602,11 @@ var createLevel = async (config) => {
7315
7602
 
7316
7603
  // packages/sdk/client-services/src/packlets/storage/profile-archive.ts
7317
7604
  import { cbor } from "@dxos/automerge/automerge-repo";
7318
- import { invariant as invariant18 } from "@dxos/invariant";
7319
- import { log as log22 } from "@dxos/log";
7605
+ import { invariant as invariant19 } from "@dxos/invariant";
7606
+ import { log as log24 } from "@dxos/log";
7320
7607
  import { ProfileArchiveEntryType } from "@dxos/protocols";
7321
7608
  import { arrayToBuffer as arrayToBuffer2 } from "@dxos/util";
7322
- var __dxlog_file25 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/storage/profile-archive.ts";
7609
+ var __dxlog_file27 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/storage/profile-archive.ts";
7323
7610
  var encodeProfileArchive = (profile) => cbor.encode(profile);
7324
7611
  var decodeProfileArchive = (data) => cbor.decode(data);
7325
7612
  var exportProfileData = async ({ storage, level }) => {
@@ -7332,10 +7619,10 @@ var exportProfileData = async ({ storage, level }) => {
7332
7619
  {
7333
7620
  const directory = await storage.createDirectory();
7334
7621
  const files = await directory.list();
7335
- log22.info("begin exporting files", {
7622
+ log24.info("begin exporting files", {
7336
7623
  count: files.length
7337
7624
  }, {
7338
- F: __dxlog_file25,
7625
+ F: __dxlog_file27,
7339
7626
  L: 30,
7340
7627
  S: void 0,
7341
7628
  C: (f, a) => f(...a)
@@ -7350,18 +7637,18 @@ var exportProfileData = async ({ storage, level }) => {
7350
7637
  value: data
7351
7638
  });
7352
7639
  }
7353
- log22.info("done exporting files", {
7640
+ log24.info("done exporting files", {
7354
7641
  count: files.length
7355
7642
  }, {
7356
- F: __dxlog_file25,
7643
+ F: __dxlog_file27,
7357
7644
  L: 41,
7358
7645
  S: void 0,
7359
7646
  C: (f, a) => f(...a)
7360
7647
  });
7361
7648
  }
7362
7649
  {
7363
- log22.info("begin exporting kv pairs", void 0, {
7364
- F: __dxlog_file25,
7650
+ log24.info("begin exporting kv pairs", void 0, {
7651
+ F: __dxlog_file27,
7365
7652
  L: 45,
7366
7653
  S: void 0,
7367
7654
  C: (f, a) => f(...a)
@@ -7379,10 +7666,10 @@ var exportProfileData = async ({ storage, level }) => {
7379
7666
  });
7380
7667
  count++;
7381
7668
  }
7382
- log22.info("done exporting kv pairs", {
7669
+ log24.info("done exporting kv pairs", {
7383
7670
  count
7384
7671
  }, {
7385
- F: __dxlog_file25,
7672
+ F: __dxlog_file27,
7386
7673
  L: 56,
7387
7674
  S: void 0,
7388
7675
  C: (f, a) => f(...a)
@@ -7397,8 +7684,8 @@ var importProfileData = async ({ storage, level }, archive) => {
7397
7684
  switch (entry2.type) {
7398
7685
  case ProfileArchiveEntryType.FILE: {
7399
7686
  const directory = await storage.createDirectory();
7400
- invariant18(typeof entry2.key === "string", "Invalid key type", {
7401
- F: __dxlog_file25,
7687
+ invariant19(typeof entry2.key === "string", "Invalid key type", {
7688
+ F: __dxlog_file27,
7402
7689
  L: 79,
7403
7690
  S: void 0,
7404
7691
  A: [
@@ -7407,8 +7694,8 @@ var importProfileData = async ({ storage, level }, archive) => {
7407
7694
  ]
7408
7695
  });
7409
7696
  const file = await directory.getOrCreateFile(entry2.key);
7410
- invariant18(entry2.value instanceof Uint8Array, "Invalid value type", {
7411
- F: __dxlog_file25,
7697
+ invariant19(entry2.value instanceof Uint8Array, "Invalid value type", {
7698
+ F: __dxlog_file27,
7412
7699
  L: 81,
7413
7700
  S: void 0,
7414
7701
  A: [
@@ -7421,8 +7708,8 @@ var importProfileData = async ({ storage, level }, archive) => {
7421
7708
  break;
7422
7709
  }
7423
7710
  case ProfileArchiveEntryType.KEY_VALUE: {
7424
- invariant18(entry2.key instanceof Uint8Array, "Invalid key type", {
7425
- F: __dxlog_file25,
7711
+ invariant19(entry2.key instanceof Uint8Array, "Invalid key type", {
7712
+ F: __dxlog_file27,
7426
7713
  L: 87,
7427
7714
  S: void 0,
7428
7715
  A: [
@@ -7430,8 +7717,8 @@ var importProfileData = async ({ storage, level }, archive) => {
7430
7717
  "'Invalid key type'"
7431
7718
  ]
7432
7719
  });
7433
- invariant18(entry2.value instanceof Uint8Array, "Invalid value type", {
7434
- F: __dxlog_file25,
7720
+ invariant19(entry2.value instanceof Uint8Array, "Invalid value type", {
7721
+ F: __dxlog_file27,
7435
7722
  L: 88,
7436
7723
  S: void 0,
7437
7724
  A: [
@@ -7451,20 +7738,20 @@ var importProfileData = async ({ storage, level }, archive) => {
7451
7738
  if (++count % 1e3 === 0) {
7452
7739
  await batch.write();
7453
7740
  batch = level.batch();
7454
- log22.info("importing", {
7741
+ log24.info("importing", {
7455
7742
  count,
7456
7743
  total: archive.storage.length,
7457
7744
  progress: `${(count / archive.storage.length * 100).toFixed()}%`
7458
7745
  }, {
7459
- F: __dxlog_file25,
7746
+ F: __dxlog_file27,
7460
7747
  L: 101,
7461
7748
  S: void 0,
7462
7749
  C: (f, a) => f(...a)
7463
7750
  });
7464
7751
  }
7465
7752
  }
7466
- log22.info("committing changes..", void 0, {
7467
- F: __dxlog_file25,
7753
+ log24.info("committing changes..", void 0, {
7754
+ F: __dxlog_file27,
7468
7755
  L: 109,
7469
7756
  S: void 0,
7470
7757
  C: (f, a) => f(...a)
@@ -7477,9 +7764,9 @@ import { Event as Event10, synchronized as synchronized3 } from "@dxos/async";
7477
7764
  import { clientServiceBundle } from "@dxos/client-protocol";
7478
7765
  import { Context as Context10 } from "@dxos/context";
7479
7766
  import { EdgeClient, EdgeHttpClient, createStubEdgeIdentity } from "@dxos/edge-client";
7480
- import { invariant as invariant20 } from "@dxos/invariant";
7767
+ import { invariant as invariant21 } from "@dxos/invariant";
7481
7768
  import { PublicKey as PublicKey17 } from "@dxos/keys";
7482
- import { log as log24 } from "@dxos/log";
7769
+ import { log as log26 } from "@dxos/log";
7483
7770
  import { EdgeSignalManager, WebsocketSignalManager } from "@dxos/messaging";
7484
7771
  import { SwarmNetworkManager, createIceProvider, createRtcTransportFactory } from "@dxos/network-manager";
7485
7772
  import { trace as trace10 } from "@dxos/protocols";
@@ -7490,9 +7777,9 @@ import { WebsocketRpcClient } from "@dxos/websocket-rpc";
7490
7777
  // packages/sdk/client-services/src/packlets/devices/devices-service.ts
7491
7778
  import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
7492
7779
  import { Stream as Stream11 } from "@dxos/codec-protobuf";
7493
- import { invariant as invariant19 } from "@dxos/invariant";
7780
+ import { invariant as invariant20 } from "@dxos/invariant";
7494
7781
  import { Device as Device2, DeviceKind as DeviceKind2 } from "@dxos/protocols/proto/dxos/client/services";
7495
- var __dxlog_file26 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
7782
+ var __dxlog_file28 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
7496
7783
  var DevicesServiceImpl = class {
7497
7784
  constructor(_identityManager) {
7498
7785
  this._identityManager = _identityManager;
@@ -7509,8 +7796,8 @@ var DevicesServiceImpl = class {
7509
7796
  devices: []
7510
7797
  });
7511
7798
  } else {
7512
- invariant19(this._identityManager.identity?.presence, "presence not present", {
7513
- F: __dxlog_file26,
7799
+ invariant20(this._identityManager.identity?.presence, "presence not present", {
7800
+ F: __dxlog_file28,
7514
7801
  L: 32,
7515
7802
  S: this,
7516
7803
  A: [
@@ -7570,7 +7857,7 @@ var DevicesServiceImpl = class {
7570
7857
  };
7571
7858
 
7572
7859
  // packages/sdk/client-services/src/packlets/identity/contacts-service.ts
7573
- import { EventSubscriptions as EventSubscriptions4, scheduleTask as scheduleTask7, UpdateScheduler as UpdateScheduler2 } from "@dxos/async";
7860
+ import { EventSubscriptions as EventSubscriptions4, scheduleTask as scheduleTask8, UpdateScheduler as UpdateScheduler2 } from "@dxos/async";
7574
7861
  import { Stream as Stream12 } from "@dxos/codec-protobuf";
7575
7862
  import { PublicKey as PublicKey15 } from "@dxos/keys";
7576
7863
  import { ComplexMap as ComplexMap5, ComplexSet as ComplexSet6 } from "@dxos/util";
@@ -7629,7 +7916,7 @@ var ContactsServiceImpl = class {
7629
7916
  }, {
7630
7917
  maxFrequency: 2
7631
7918
  });
7632
- scheduleTask7(ctx, async () => {
7919
+ scheduleTask8(ctx, async () => {
7633
7920
  const subscriptions = new EventSubscriptions4();
7634
7921
  ctx.onDispose(() => subscriptions.clear());
7635
7922
  const subscribeToSpaceAndUpdate = () => {
@@ -7656,7 +7943,7 @@ var ContactsServiceImpl = class {
7656
7943
  import { Event as Event9 } from "@dxos/async";
7657
7944
  import { Stream as Stream13 } from "@dxos/codec-protobuf";
7658
7945
  import { PublicKey as PublicKey16 } from "@dxos/keys";
7659
- import { getContextFromEntry, log as log23 } from "@dxos/log";
7946
+ import { getContextFromEntry, log as log25 } from "@dxos/log";
7660
7947
  import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
7661
7948
  import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
7662
7949
  var LoggingServiceImpl = class {
@@ -7669,11 +7956,11 @@ var LoggingServiceImpl = class {
7669
7956
  };
7670
7957
  }
7671
7958
  async open() {
7672
- log23.runtimeConfig.processors.push(this._logProcessor);
7959
+ log25.runtimeConfig.processors.push(this._logProcessor);
7673
7960
  }
7674
7961
  async close() {
7675
- const index = log23.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
7676
- log23.runtimeConfig.processors.splice(index, 1);
7962
+ const index = log25.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
7963
+ log25.runtimeConfig.processors.splice(index, 1);
7677
7964
  }
7678
7965
  async controlMetrics({ reset, record }) {
7679
7966
  if (reset) {
@@ -7873,7 +8160,7 @@ function _ts_decorate10(decorators, target, key, desc) {
7873
8160
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
7874
8161
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7875
8162
  }
7876
- var __dxlog_file27 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
8163
+ var __dxlog_file29 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
7877
8164
  var ClientServicesHost = class {
7878
8165
  constructor({
7879
8166
  config,
@@ -7912,7 +8199,7 @@ var ClientServicesHost = class {
7912
8199
  onAcquire: () => {
7913
8200
  if (!this._opening) {
7914
8201
  void this.open(new Context10(void 0, {
7915
- F: __dxlog_file27,
8202
+ F: __dxlog_file29,
7916
8203
  L: 133
7917
8204
  }));
7918
8205
  }
@@ -7969,8 +8256,8 @@ var ClientServicesHost = class {
7969
8256
  * Can only be called once.
7970
8257
  */
7971
8258
  initialize({ config, ...options }) {
7972
- invariant20(!this._open, "service host is open", {
7973
- F: __dxlog_file27,
8259
+ invariant21(!this._open, "service host is open", {
8260
+ F: __dxlog_file29,
7974
8261
  L: 199,
7975
8262
  S: this,
7976
8263
  A: [
@@ -7978,15 +8265,15 @@ var ClientServicesHost = class {
7978
8265
  "'service host is open'"
7979
8266
  ]
7980
8267
  });
7981
- log24("initializing...", void 0, {
7982
- F: __dxlog_file27,
8268
+ log26("initializing...", void 0, {
8269
+ F: __dxlog_file29,
7983
8270
  L: 200,
7984
8271
  S: this,
7985
8272
  C: (f, a) => f(...a)
7986
8273
  });
7987
8274
  if (config) {
7988
- invariant20(!this._config, "config already set", {
7989
- F: __dxlog_file27,
8275
+ invariant21(!this._config, "config already set", {
8276
+ F: __dxlog_file29,
7990
8277
  L: 203,
7991
8278
  S: this,
7992
8279
  A: [
@@ -8000,8 +8287,8 @@ var ClientServicesHost = class {
8000
8287
  }
8001
8288
  }
8002
8289
  if (!options.signalManager) {
8003
- log24.warn("running signaling without telemetry metadata.", void 0, {
8004
- F: __dxlog_file27,
8290
+ log26.warn("running signaling without telemetry metadata.", void 0, {
8291
+ F: __dxlog_file29,
8005
8292
  L: 211,
8006
8293
  S: this,
8007
8294
  C: (f, a) => f(...a)
@@ -8020,8 +8307,8 @@ var ClientServicesHost = class {
8020
8307
  edgeConnection: this._edgeConnection
8021
8308
  }) : new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
8022
8309
  this._signalManager = signalManager;
8023
- invariant20(!this._networkManager, "network manager already set", {
8024
- F: __dxlog_file27,
8310
+ invariant21(!this._networkManager, "network manager already set", {
8311
+ F: __dxlog_file29,
8025
8312
  L: 233,
8026
8313
  S: this,
8027
8314
  A: [
@@ -8038,8 +8325,8 @@ var ClientServicesHost = class {
8038
8325
  peerKey: this._edgeConnection.peerKey
8039
8326
  } : void 0
8040
8327
  });
8041
- log24("initialized", void 0, {
8042
- F: __dxlog_file27,
8328
+ log26("initialized", void 0, {
8329
+ F: __dxlog_file29,
8043
8330
  L: 246,
8044
8331
  S: this,
8045
8332
  C: (f, a) => f(...a)
@@ -8050,16 +8337,16 @@ var ClientServicesHost = class {
8050
8337
  return;
8051
8338
  }
8052
8339
  const traceId = PublicKey17.random().toHex();
8053
- log24.trace("dxos.client-services.host.open", trace10.begin({
8340
+ log26.trace("dxos.client-services.host.open", trace10.begin({
8054
8341
  id: traceId
8055
8342
  }), {
8056
- F: __dxlog_file27,
8343
+ F: __dxlog_file29,
8057
8344
  L: 257,
8058
8345
  S: this,
8059
8346
  C: (f, a) => f(...a)
8060
8347
  });
8061
- invariant20(this._config, "config not set", {
8062
- F: __dxlog_file27,
8348
+ invariant21(this._config, "config not set", {
8349
+ F: __dxlog_file29,
8063
8350
  L: 259,
8064
8351
  S: this,
8065
8352
  A: [
@@ -8067,8 +8354,8 @@ var ClientServicesHost = class {
8067
8354
  "'config not set'"
8068
8355
  ]
8069
8356
  });
8070
- invariant20(this._storage, "storage not set", {
8071
- F: __dxlog_file27,
8357
+ invariant21(this._storage, "storage not set", {
8358
+ F: __dxlog_file29,
8072
8359
  L: 260,
8073
8360
  S: this,
8074
8361
  A: [
@@ -8076,8 +8363,8 @@ var ClientServicesHost = class {
8076
8363
  "'storage not set'"
8077
8364
  ]
8078
8365
  });
8079
- invariant20(this._signalManager, "signal manager not set", {
8080
- F: __dxlog_file27,
8366
+ invariant21(this._signalManager, "signal manager not set", {
8367
+ F: __dxlog_file29,
8081
8368
  L: 261,
8082
8369
  S: this,
8083
8370
  A: [
@@ -8085,8 +8372,8 @@ var ClientServicesHost = class {
8085
8372
  "'signal manager not set'"
8086
8373
  ]
8087
8374
  });
8088
- invariant20(this._networkManager, "network manager not set", {
8089
- F: __dxlog_file27,
8375
+ invariant21(this._networkManager, "network manager not set", {
8376
+ F: __dxlog_file29,
8090
8377
  L: 262,
8091
8378
  S: this,
8092
8379
  A: [
@@ -8095,10 +8382,10 @@ var ClientServicesHost = class {
8095
8382
  ]
8096
8383
  });
8097
8384
  this._opening = true;
8098
- log24("opening...", {
8385
+ log26("opening...", {
8099
8386
  lockKey: this._resourceLock?.lockKey
8100
8387
  }, {
8101
- F: __dxlog_file27,
8388
+ F: __dxlog_file29,
8102
8389
  L: 265,
8103
8390
  S: this,
8104
8391
  C: (f, a) => f(...a)
@@ -8151,18 +8438,18 @@ var ClientServicesHost = class {
8151
8438
  this._open = true;
8152
8439
  this._statusUpdate.emit();
8153
8440
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
8154
- log24("opened", {
8441
+ log26("opened", {
8155
8442
  deviceKey
8156
8443
  }, {
8157
- F: __dxlog_file27,
8444
+ F: __dxlog_file29,
8158
8445
  L: 354,
8159
8446
  S: this,
8160
8447
  C: (f, a) => f(...a)
8161
8448
  });
8162
- log24.trace("dxos.client-services.host.open", trace10.end({
8449
+ log26.trace("dxos.client-services.host.open", trace10.end({
8163
8450
  id: traceId
8164
8451
  }), {
8165
- F: __dxlog_file27,
8452
+ F: __dxlog_file29,
8166
8453
  L: 355,
8167
8454
  S: this,
8168
8455
  C: (f, a) => f(...a)
@@ -8173,10 +8460,10 @@ var ClientServicesHost = class {
8173
8460
  return;
8174
8461
  }
8175
8462
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
8176
- log24("closing...", {
8463
+ log26("closing...", {
8177
8464
  deviceKey
8178
8465
  }, {
8179
- F: __dxlog_file27,
8466
+ F: __dxlog_file29,
8180
8467
  L: 366,
8181
8468
  S: this,
8182
8469
  C: (f, a) => f(...a)
@@ -8191,10 +8478,10 @@ var ClientServicesHost = class {
8191
8478
  await this._level?.close();
8192
8479
  this._open = false;
8193
8480
  this._statusUpdate.emit();
8194
- log24("closed", {
8481
+ log26("closed", {
8195
8482
  deviceKey
8196
8483
  }, {
8197
- F: __dxlog_file27,
8484
+ F: __dxlog_file29,
8198
8485
  L: 375,
8199
8486
  S: this,
8200
8487
  C: (f, a) => f(...a)
@@ -8202,32 +8489,32 @@ var ClientServicesHost = class {
8202
8489
  }
8203
8490
  async reset() {
8204
8491
  const traceId = PublicKey17.random().toHex();
8205
- log24.trace("dxos.sdk.client-services-host.reset", trace10.begin({
8492
+ log26.trace("dxos.sdk.client-services-host.reset", trace10.begin({
8206
8493
  id: traceId
8207
8494
  }), {
8208
- F: __dxlog_file27,
8495
+ F: __dxlog_file29,
8209
8496
  L: 380,
8210
8497
  S: this,
8211
8498
  C: (f, a) => f(...a)
8212
8499
  });
8213
- log24.info("resetting...", void 0, {
8214
- F: __dxlog_file27,
8500
+ log26.info("resetting...", void 0, {
8501
+ F: __dxlog_file29,
8215
8502
  L: 382,
8216
8503
  S: this,
8217
8504
  C: (f, a) => f(...a)
8218
8505
  });
8219
8506
  await this._serviceContext?.close();
8220
8507
  await this._storage.reset();
8221
- log24.info("reset", void 0, {
8222
- F: __dxlog_file27,
8508
+ log26.info("reset", void 0, {
8509
+ F: __dxlog_file29,
8223
8510
  L: 385,
8224
8511
  S: this,
8225
8512
  C: (f, a) => f(...a)
8226
8513
  });
8227
- log24.trace("dxos.sdk.client-services-host.reset", trace10.end({
8514
+ log26.trace("dxos.sdk.client-services-host.reset", trace10.end({
8228
8515
  id: traceId
8229
8516
  }), {
8230
- F: __dxlog_file27,
8517
+ F: __dxlog_file29,
8231
8518
  L: 386,
8232
8519
  S: this,
8233
8520
  C: (f, a) => f(...a)
@@ -8302,4 +8589,4 @@ export {
8302
8589
  importProfileData,
8303
8590
  ClientServicesHost
8304
8591
  };
8305
- //# sourceMappingURL=chunk-67FEJJ6J.mjs.map
8592
+ //# sourceMappingURL=chunk-XOKN3TE7.mjs.map